nux-0.9.46
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef BASEAREA_H 00024 #define BASEAREA_H 00025 00026 #include "Area.h" 00027 #include "MouseHandler.h" 00028 00029 #if defined(NUX_OS_WINDOWS) 00030 #include "NuxGraphics/Events.h" 00031 #elif defined(NUX_OS_LINUX) 00032 #include "NuxGraphics/Events.h" 00033 #endif 00034 00035 #include "NuxGraphics/GraphicsDisplay.h" 00036 00037 00038 #define FOCUSNONE -1 00039 00040 namespace nux 00041 { 00042 class InputArea; 00043 typedef InputArea CoreArea; 00044 00045 class InputArea : public Area 00046 { 00047 public: 00048 NUX_DECLARE_OBJECT_TYPE (InputArea, Area); 00049 public: 00050 InputArea (NUX_FILE_LINE_PROTO); 00051 virtual ~InputArea(); 00052 00054 00061 bool ForceStartFocus (int x, int y); 00062 void ForceStopFocus (int x, int y); 00063 00064 virtual long OnEvent (Event &ievent, long TraverseInfo, long ProcessEventInfo); 00065 00067 00073 virtual void OnDraw (GraphicsEngine &GfxContext, bool force_draw); 00074 00075 virtual void OverlayDrawing (GraphicsEngine &GfxContext) {} 00076 00077 bool HasKeyboardFocus(); 00078 void SetKeyboardFocus (bool b); 00079 int GetMouseX(); 00080 int GetMouseY(); 00081 bool IsMouseInside(); 00082 bool HasMouseFocus(); 00083 bool MouseFocusOnOtherArea(); 00084 void CaptureMouseDownAnyWhereElse (bool b); 00085 bool IsCaptureMouseDownAnyWhereElse() const; 00086 00094 void EnableEventDebugTrace (bool enable); 00095 00102 bool GetEventDebugTrace () const; 00103 00104 private: 00105 bool _dnd_enabled_as_source; 00106 bool _dnd_enabled_as_target; 00107 //bool m_EnableKeyboardInput; 00108 public: 00109 // void EnableKeyEntry(bool b) 00110 // { 00111 // m_EnableKeyboardInput = true; 00112 // } 00113 // 00114 // bool IsEnableKeyEntry() 00115 // { 00116 // return m_EnableKeyboardInput; //m_KeyboardHandler.IsEnableKeyEntry(); 00117 // } 00118 00120 00125 void EnableKeyboardFocusOnMouseDown (bool enable); 00126 00128 00131 bool GetKeyboardFocusOnMouseDown () const; 00132 00133 // Override the virtual methods from Object Base 00134 // Here, we get a change to update the text of the keyboard handler. 00135 virtual void SetBaseString (const TCHAR *Caption); 00136 00138 void EnableDoubleClick (bool b); 00139 00141 bool IsDoubleClickEnabled(); 00142 void EnableUserKeyboardProcessing (bool b); 00143 bool IsUserKeyboardProcessingEnabled(); 00144 00145 virtual bool IsArea() const 00146 { 00147 return true; 00148 } 00149 00150 unsigned short getKeyState (int nVirtKey); 00151 00152 // This method reset the mouse position inside the Area. This is necessary for areas that serve as Drag 00153 // when the area position is reffered to (x_root, y_root) instead of being the system window coordinates (0, 0). 00154 void SetAreaMousePosition (int x, int y); 00155 00156 void GrabPointer (); 00157 void GrabKeyboard (); 00158 void UnGrabPointer (); 00159 void UnGrabKeyboard (); 00160 bool OwnsPointerGrab (); 00161 bool OwnsKeyboardGrab (); 00162 00163 #if defined (NUX_OS_LINUX) 00164 void HandleDndEnter () { ProcessDndEnter (); } 00165 void HandleDndLeave () { ProcessDndLeave (); } 00166 #endif 00167 private: 00168 00170 00173 long ProcessEventInExclusiveMode (Event &ievent, long TraverseInfo, long ProcessEventInfo); 00174 00175 void HandleDndMove (Event &event); 00176 void HandleDndDrop (Event &event); 00177 00179 /* 00180 Color of the InputArea use to draw a colored quad when OnDraw() is called. 00181 */ 00182 Color m_AreaColor; 00183 00184 int _dnd_safety_x; 00185 int _dnd_safety_y; 00186 00187 protected: 00188 AreaEventProcessor _event_processor; 00189 00190 bool _has_keyboard_focus; 00191 bool _capture_mouse_down_any_where_else; 00192 bool _double_click; 00193 bool _print_event_debug_trace; 00194 00195 bool _enable_keyboard_focus_on_mouse_down; 00196 00197 #if defined (NUX_OS_LINUX) 00198 // DnD support 00199 // Rather than being implemented with signals, DND support is implemented with protected virtual function. 00200 // This ensure that a class and it subclass don't process the same event more than once! 00201 00202 virtual void ProcessDndMove (int x, int y, std::list<char *>mimes); 00203 virtual void ProcessDndDrop (int x, int y); 00204 virtual void ProcessDndEnter (); 00205 virtual void ProcessDndLeave (); 00206 00207 void SendDndStatus (bool accept, DndAction action, Geometry region); 00208 void SendDndFinished (bool accepted, DndAction action); 00209 00210 void SetDndEnabled (bool as_source, bool as_target); 00211 00212 virtual void DndSourceDragBegin (); 00213 virtual NBitmapData * DndSourceGetDragImage (); 00214 virtual std::list<const char *> DndSourceGetDragTypes (); 00215 virtual const char * DndSourceGetDataForType (const char *type, int *size, int *format); 00216 virtual void DndSourceDragFinished (DndAction result); 00217 00218 void StartDragAsSource (); 00219 00220 static NBitmapData * InnerDndSourceGetDragImage (void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragImage (); } 00221 static std::list<const char *> InnerDndSourceGetDragTypes (void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragTypes (); } 00222 static void InnerDndSourceDragFinished (DndAction result, void *data); 00223 00224 static const char * InnerDndSourceGetDataForType (const char *type, int *size, int *format, void *data) 00225 { return static_cast<InputArea *> (data)->DndSourceGetDataForType (type, size, format); } 00226 #endif 00227 00228 public: 00230 sigc::signal<void, int, int, int, int, unsigned long, unsigned long> OnMouseMove; // send the current position inside the area 00231 00233 00240 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseDown; 00241 00243 00250 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseUp; 00251 00253 00260 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseEnter; 00261 00263 00270 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseLeave; 00271 00273 00280 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseClick; 00281 00283 00290 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseDoubleClick; 00291 00293 00302 sigc::signal<void, int, int, int, int, unsigned long, unsigned long> OnMouseDrag; // send (current X, current Y, delta X, delta Y) 00303 00305 sigc::signal < void, 00306 int, // window x 00307 int, // window y 00308 int, // mouse wheel delta: +120/-120 correspond to one notch of the wheel 00309 unsigned long, // mouse state 00310 unsigned long // key state 00311 > OnMouseWheel; // send (current X, current Y, delta X, delta Y) 00312 00314 sigc::signal<void, unsigned int, unsigned long, unsigned long> OnKeyPressed; 00315 00317 sigc::signal<void, unsigned int, unsigned long, unsigned long> OnKeyReleased; 00318 00320 sigc::signal<void> OnStartMouseFocus; 00323 sigc::signal<void> OnEndMouseFocus; 00324 00326 sigc::signal<void> OnStartFocus; 00328 sigc::signal<void> OnEndFocus; 00329 00331 //sigc::signal<void, Time> OnTakeFocus; 00332 00333 sigc::signal < void, 00334 GraphicsEngine & , /*Graphics Context for text operation*/ 00335 unsigned long , /*event type*/ 00336 unsigned long , /*event keysym*/ 00337 unsigned long , /*event state*/ 00338 const TCHAR* , /*character*/ 00339 unsigned short /*key repeat count*/ 00340 > OnKeyEvent; 00341 00343 00353 sigc::signal<void, int, int, unsigned long, unsigned long> OnMouseDownOutsideArea; 00354 00355 void DoSetFocused (bool focus); 00356 }; 00357 00358 } 00359 00360 #endif // BASEAREA_H