
#ifndef __WFX_GUI_WINDOWMANAGER_H__
#define __WFX_GUI_WINDOWMANAGER_H__

#include <WFX/WFXIncludes.h>

#include <WFX/util/Singleton.h>

#include <WFX/input/InputHandler.h>
#include <WFX/input/MouseListener.h>
#include <WFX/input/KeyboardListener.h>
#include <WFX/input/JoystickListener.h>

#include <WFX/renderer/Renderable.h>
#include <WFX/renderer/Renderer.h>

#include <WFX/gui/Window.h>
#include <WFX/gui/GuiFocusListener.h>

namespace WFX {

    namespace gui {

        /**
         * The Window manager
         * this class manages any gui components and is the main interface
         * to most gui functionality
         */
        class WindowManager : public WFX::util::Singleton<WindowManager>,
                              public WFX::renderer::Renderable,
                              public WFX::input::MouseListener,
                              public WFX::input::KeyboardListener,
                              public WFX::input::JoystickListener {
            public:
                /**
                 * Ctor
                 */
                WindowManager();
                virtual ~WindowManager() {}

                /** add a toplevel window */
                void addWindow(Window* w);

                /** 
                 * add a FocusListener 
                 * 
                 * FocusListeners may be grouped to activate/deactivate groups
                 * of listeners
                 */
                void addFocusListener(GuiFocusListener* l);
                /** removes the FocusListener */
                void removeFocusListener(GuiFocusListener* l);
                /** sets current FocusListener */
                void setCurrentListener(GuiFocusListener* l);
               
                /** render gui */
                void render(WFX::renderer::Renderer* r);

                /** actives input listening */
                void activateInput();
                
                //implement mouselistener
                void mouseMoved(WFX::input::MouseMotionEvent e);
                void mouseButtonPressed(WFX::input::MouseButtonEvent e);
                void mouseButtonReleased(WFX::input::MouseButtonEvent e);
                //implement keyobardlistener
                void keyPressed(WFX::input::KeyEvent k);
                void keyReleased(WFX::input::KeyEvent k);
                //implement joysticklistener
                void buttonPressed(WFX::input::JoystickButtonEvent e);
                void buttonReleased(WFX::input::JoystickButtonEvent e);
                void axisEvent(WFX::input::JoystickAxisEvent e);
               
            protected:
                /** toplevel window list */
                std::list<Window*> Windows;
                
                /** GuiFocusListeners */
                std::list<GuiFocusListener*> FocusListeners;
                /** currently highlighted actionlistener */
                GuiFocusListener* CurrentListener;
                
                /** nextitem key */
                WFX::input::WFXKey KeyNextItem;
                /** previous item key */
                WFX::input::WFXKey KeyPrevItem;
                /** select key */
                WFX::input::WFXKey KeySelect;


            private:
                /**
                 * selects the next Focuslistener
                 */
                void selListener(bool b);
                

        };

    }

}


#endif //include guard


