~macslow/nux/nux.fix-839476

« back to all changes in this revision

Viewing changes to Nux/BaseArea.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 22:11:16 UTC
  • Revision ID: neil.patel@canonical.com-20100901221116-4hb351fcg6s5nka0
Initial Nux integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it 
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but 
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public 
 
12
 * License for more details.
 
13
 * 
 
14
 * You should have received a copy of both the GNU Lesser General Public 
 
15
 * License version 3 along with this program.  If not, see 
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef BASEAREA_H
 
24
#define BASEAREA_H
 
25
 
 
26
#include "BaseObject.h"
 
27
#include "MouseHandler.h"
 
28
 
 
29
#if defined(INL_OS_WINDOWS)
 
30
    #include "NuxGraphics/Gfx_Events.h"
 
31
#elif defined(INL_OS_LINUX)
 
32
    #include "NuxGraphics/GfxEventsX11.h"
 
33
#endif
 
34
 
 
35
 
 
36
#define INPUT
 
37
#define OUTPUT
 
38
 
 
39
#define FOCUSNONE -1
 
40
 
 
41
NAMESPACE_BEGIN_GUI
 
42
 
 
43
////////////////////////////////////////////////////////////////////////////
 
44
// Base Area
 
45
////////////////////////////////////////////////////////////////////////////
 
46
 
 
47
class BaseArea;
 
48
typedef BaseArea CoreArea;
 
49
 
 
50
class BaseArea : public BaseObject //public sigc::trackable
 
51
{
 
52
public:
 
53
    DECLARE_OBJECT_TYPE(BaseArea, BaseObject);
 
54
public:
 
55
    BaseArea();
 
56
    virtual ~BaseArea();
 
57
 
 
58
    void Deselect()
 
59
    {
 
60
        m_MouseEventCurrent.MouseIn = false;
 
61
    }
 
62
    
 
63
    void ForceStartFocus(int x, int y);
 
64
    void ForceStopFocus(int x, int y);
 
65
 
 
66
    virtual long OnEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
 
67
 
 
68
    //! Draw CoreArea.
 
69
    /*!
 
70
        Draw a colored quad using m_AreaColor.
 
71
        Override this function to define a custom drawing function. 
 
72
        If force_draw is true then the system requests that all objects redraw themselves completely.
 
73
        \param force_draw.
 
74
    */
 
75
    virtual void OnDraw(GraphicsContext& GfxContext, bool force_draw);
 
76
 
 
77
    virtual void OverlayDrawing(GraphicsContext& GfxContext) {}
 
78
 
 
79
    bool HasKeyboardFocus();
 
80
    void SetKeyboardFocus(bool b);
 
81
    int GetMouseX();
 
82
    int GetMouseY();
 
83
    bool IsMouseInside();
 
84
    bool HasMouseFocus();
 
85
    bool MouseFocusOnOtherArea();
 
86
    void CaptureMouseDownAnyWhereElse(bool b);
 
87
    bool IsCaptureMouseDownAnyWhereElse() const;
 
88
 
 
89
private:
 
90
    //bool m_EnableKeyboardInput;
 
91
public:
 
92
//    void EnableKeyEntry(bool b)
 
93
//    {
 
94
//        m_EnableKeyboardInput = true;
 
95
//    }
 
96
//
 
97
//    bool IsEnableKeyEntry()
 
98
//    {
 
99
//        return m_EnableKeyboardInput; //m_KeyboardHandler.IsEnableKeyEntry();
 
100
//    }
 
101
 
 
102
    // Override the virtual methods from Object Base
 
103
    // Here, we get a change to update the text of the keyboard handler.
 
104
    virtual void SetBaseString(const TCHAR* Caption);
 
105
 
 
106
    void EnableDoubleClick(bool b);
 
107
    bool IsDoubleClickEnabled();
 
108
    void EnableUserKeyboardProcessing(bool b);
 
109
    bool IsUserKeyboardProcessingEnabled();
 
110
 
 
111
    virtual bool IsArea() const {return true;}
 
112
 
 
113
    unsigned short getKeyState(int nVirtKey);
 
114
 
 
115
    // This method reset the mouse position inside the Area. This is necessary for areas that serve as Drag 
 
116
    // when the area position is reffered to (x_root, y_root) instead of being the system window coordinates (0, 0).
 
117
    void SetAreaMousePosition(int x, int y);
 
118
 
 
119
private:
 
120
 
 
121
    //! Color of the CoreArea
 
122
    /*
 
123
        Color of the CoreArea use to draw a colored quad when OnDraw() is called.
 
124
    */
 
125
    Color m_AreaColor;
 
126
 
 
127
protected:
 
128
    struct MouseEvent m_MouseEventPrevious;
 
129
    struct MouseEvent m_MouseEventCurrent;
 
130
 
 
131
    BaseMouseHandler m_EventHandler;
 
132
 
 
133
    bool m_hasKeyboardFocus;
 
134
    bool m_CaptureMouseDownAnyWhereElse;
 
135
    bool m_EnableDoubleClick;
 
136
    bool m_EnableUserKeyboardProcessing;
 
137
 
 
138
public:
 
139
    sigc::signal<void, int, int, int, int, unsigned long, unsigned long> OnMouseMove;  // send the current position inside the area
 
140
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseDown;
 
141
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseUp;
 
142
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseEnter;
 
143
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseLeave;
 
144
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseClick;
 
145
    sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseDoubleClick;
 
146
    sigc::signal<void, int, int, int, int, unsigned long, unsigned long> OnMouseDrag; // send (current X, current Y, delta X, delta Y)
 
147
 
 
148
    sigc::signal<void, 
 
149
        int,            // window x
 
150
        int,            // window y
 
151
        int,            // mouse wheel delta: +120/-120 correspond to one notch of the wheel
 
152
        unsigned long,  // mouse state
 
153
        unsigned long   // key state
 
154
    > OnMouseWheel; // send (current X, current Y, delta X, delta Y)
 
155
 
 
156
    sigc::signal<void, unsigned int, unsigned long, unsigned long> OnKeyPressed;
 
157
    sigc::signal<void, unsigned int, unsigned long, unsigned long> OnKeyReleased;
 
158
    sigc::signal<void> OnValidateKeyboardEntry;
 
159
    
 
160
    //! Signal emitted when the area gets the mouse focus. This is the result of a mouse down event.
 
161
    sigc::signal<void> OnStartMouseFocus;
 
162
    //! Signal emitted when the mouse is released. The area that had the mouse focus receives this signal.
 
163
    //! Note that the area may still have the keyboard focus after OnEndMouseFocus is emitted.
 
164
    sigc::signal<void> OnEndMouseFocus;
 
165
 
 
166
    //! Signal emitted when the area gets the keyboard focus. The is a result of a mouse down event or a call to ForceStartFocus.
 
167
    sigc::signal<void> OnStartFocus;
 
168
    //! Signal emitted when the area looses the keyboard focus.
 
169
    sigc::signal<void> OnEndFocus;
 
170
 
 
171
    sigc::signal<void,
 
172
        GraphicsContext&    ,    /*Graphics Context for text operation*/
 
173
        unsigned long       ,    /*event type*/
 
174
        unsigned long       ,    /*event keysym*/
 
175
        unsigned long       ,    /*event state*/
 
176
        const char*         ,    /*character*/
 
177
        bool                ,    /*true if the key is repeated more than once*/
 
178
        unsigned short           /*key repeat count*/
 
179
    > OnKeyEvent;
 
180
 
 
181
    sigc::signal<void, int, int, unsigned long, unsigned long> OnCaptureMouseDownAnyWhereElse;
 
182
};
 
183
 
 
184
NAMESPACE_END_GUI
 
185
 
 
186
#endif // BASEAREA_H