/* -*-c++-*- header - Open Producer - Copyright (C) 2002 Don Burns
 * Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
 * as published by the Free Software Foundation.
 */
#ifndef _PRODUCER_RENDER_SURFACE_EVENTS_H
#define _PRODUCER_RENDER_SURFACE_EVENTS_H

#include <Producer/Export>
#include <Producer/Referenced>

#ifdef  _WIN32_IMPLEMENTATION

#include <deque>

#include <Producer/RenderSurface>
#include <Producer/Block>
#include <Producer/Keyboard>
#include <Producer/KeyboardMouse>

namespace Producer {


class Event :public Referenced {
    public:
        enum Type {
            KeyPress,
            KeyRelease,
            ButtonPress,
            DoubleButtonPress,
            ButtonRelease,
            MouseMotion, 
            MouseScroll,
            ButtonMotion,
            WindowConfig,
            Timer,
	    Shutdown,
        };

        enum Mask {
            KeyPressMask          = 0x001,
            KeyReleaseMask        = 0x002,
            ButtonPressMask       = 0x004,
            DoubleButtonPressMask = 0x008,
            ButtonReleaseMask     = 0x010,
            MouseMotionMask       = 0x020,
            MouseScrollMask       = 0x040,
            ButtonMotionMask      = 0x080,
            WindowConfigMask      = 0x100,
            TimerMask             = 0x200,
	        ShutdownMask          = 0x400
        };

        Event( Window win, Type type ) : _win(win), _type(type) {}
        virtual ~Event() {}
        Type type() { return _type; }
        Window window() { return _win; }
    protected:
        Window _win;
        Type _type;
};

typedef BlockingQueue <ref_ptr<Event> > EventQueue;

class KeyPressEvent : public Event
{
    public :  
        KeyPressEvent( Window win, unsigned short key ): Event(win, Event::KeyPress), _key( key ) {}
        virtual ~KeyPressEvent() {}
        unsigned short key() const { return _key; }
    private:
        unsigned short _key;
};

class KeyReleaseEvent : public Event
{
    public: 
        KeyReleaseEvent( Window win, unsigned short key ) : Event(win, Event::KeyRelease), _key(key) {}
        virtual ~KeyReleaseEvent() {}
        unsigned short key() const { return _key; }
    private:
        unsigned short _key;
}; 

class ButtonPressEvent : public Event
{
    public:
        ButtonPressEvent(Window win, unsigned int button, int mx, int my) : 
            Event(win, Event::ButtonPress), _button(button), _mx(mx), _my(my) {}
        virtual ~ButtonPressEvent() {}
        int mx() const { return _mx; }
        int my() const { return _my; }

        unsigned int button() const { return _button; }
    private:
        unsigned int _button;
        int _mx, _my;
};

class ButtonReleaseEvent : public Event
{
    public:
    ButtonReleaseEvent(Window win, unsigned int button, int mx, int my) : 
        Event(win, Event::ButtonRelease), _button(button), _mx(mx), _my(my) {}
    virtual ~ButtonReleaseEvent() {}
    int mx() const { return _mx; }
    int my() const { return _my; }

    unsigned int button() const { return _button; }
    private:
    unsigned int _button;
    int _mx, _my;
};

class DoubleButtonPressEvent : public Event
{
    public:
    DoubleButtonPressEvent(Window win, unsigned int button, int mx, int my) : 
        Event(win, Event::ButtonRelease), _button(button), _mx(mx), _my(my) {}
    virtual ~DoubleButtonPressEvent() {}
    int mx() const { return _mx; }
    int my() const { return _my; }

    unsigned int button() const { return _button; }
    private:
    unsigned int _button;
    int _mx, _my;
};

class MouseMotionEvent : public Event
{
    public:
    MouseMotionEvent( Window win, int mx, int my ) : Event(win, Event::MouseMotion), 
            _mx(mx), _my(my) {}
    virtual ~MouseMotionEvent() {}
    int mx() const { return _mx; }
    int my() const { return _my; }
    private:
    int _mx, _my;
};

class MouseScrollEvent : public Event
{
    public:
        MouseScrollEvent(Window win, KeyboardMouseCallback::ScrollingMotion scroll ) : 
            Event( win, Event::MouseScroll ), _scroll(scroll) {}

        virtual ~MouseScrollEvent() {}

        KeyboardMouseCallback::ScrollingMotion scrollingMotion() { return _scroll; }

    private:
        KeyboardMouseCallback::ScrollingMotion _scroll;
};

class WindowConfigEvent : public Event 
{
    public:
        WindowConfigEvent( Window win, int x, int y, unsigned int width, unsigned int height ):
            Event(win, Event::WindowConfig),
            _x(x), _y(y), _width(width), _height(height) {}
        virtual ~WindowConfigEvent() {}
        int x() const { return _x; }
        int y() const { return _y; }
        unsigned int winWidth() const { return _width; }
        unsigned int winHeight() const { return _height; }
    private:
        int _x, _y;
        unsigned int _width, _height;
};

class TimerEvent : public Event 
{
    public:
        TimerEvent(Window win, unsigned int id) : Event(win, Event::Timer), _id(id) {}
        virtual ~TimerEvent() {}
        unsigned int id() const { return _id; }
    private:
        unsigned int _id;
};

class ShutdownEvent : public Event
{
    public:
        ShutdownEvent(Window win): Event(win, Event::Shutdown) {}
};

}

#endif
#endif
