nux-1.14.0
|
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 INPUTAREA_H 00024 #define INPUTAREA_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 #include "NuxGraphics/GraphicsDisplay.h" 00035 00036 namespace nux 00037 { 00038 class WindowCompositor; 00039 class InputArea; 00040 00041 typedef InputArea CoreArea; 00042 00043 class InputArea : public Area 00044 { 00045 public: 00046 NUX_DECLARE_OBJECT_TYPE (InputArea, Area); 00047 public: 00048 InputArea (NUX_FILE_LINE_PROTO); 00049 virtual ~InputArea(); 00050 00052 00059 bool ForceStartFocus (int x, int y); 00060 void ForceStopFocus (int x, int y); 00061 00062 virtual long OnEvent (Event &ievent, long TraverseInfo, long ProcessEventInfo); 00063 00065 00071 virtual void OnDraw (GraphicsEngine &GfxContext, bool force_draw); 00072 00073 virtual void OverlayDrawing (GraphicsEngine &GfxContext) {} 00074 00075 bool HasKeyboardFocus(); 00076 void SetKeyboardFocus (bool b); 00077 int GetMouseX(); 00078 int GetMouseY(); 00079 00080 bool HasMouseFocus(); 00081 bool MouseFocusOnOtherArea(); 00082 void CaptureMouseDownAnyWhereElse (bool b); 00083 bool IsCaptureMouseDownAnyWhereElse() const; 00084 00085 Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type); 00086 Area* FindKeyFocusArea(unsigned int key_symbol, 00087 unsigned long x11_key_code, 00088 unsigned long special_keys_state); 00089 00090 private: 00091 bool _dnd_enabled_as_source; 00092 bool _dnd_enabled_as_target; 00093 //bool m_EnableKeyboardInput; 00094 public: 00095 // void EnableKeyEntry(bool b) 00096 // { 00097 // m_EnableKeyboardInput = true; 00098 // } 00099 // 00100 // bool IsEnableKeyEntry() 00101 // { 00102 // return m_EnableKeyboardInput; //m_KeyboardHandler.IsEnableKeyEntry(); 00103 // } 00104 00105 // Override the virtual methods from Object Base 00106 // Here, we get a change to update the text of the keyboard handler. 00107 virtual void SetBaseString (const TCHAR *Caption); 00108 00109 void SetKeyboardReceiverIgnoreMouseDownOutside(bool ignore_mouse_down_outside); 00110 00111 bool KeyboardReceiverIgnoreMouseDownOutside(); 00112 00113 virtual bool IsArea() const 00114 { 00115 return true; 00116 } 00117 00118 // This method reset the mouse position inside the Area. This is necessary for areas that serve as Drag 00119 // when the area position is referred to (x_root, y_root) instead of being the system window coordinates (0, 0). 00120 void SetAreaMousePosition (int x, int y); 00121 00122 void GrabPointer (); 00123 void GrabKeyboard (); 00124 void UnGrabPointer (); 00125 void UnGrabKeyboard (); 00126 bool OwnsPointerGrab (); 00127 bool OwnsKeyboardGrab (); 00128 00130 00136 bool IsMouseOwner(); 00137 00139 00146 bool IsMouseInside(); 00147 00149 void EnableDoubleClick(bool double_click); 00150 00152 bool DoubleClickEnabled() const; 00153 00154 AreaEventProcessor _event_processor; 00155 00156 #if defined (NUX_OS_LINUX) 00157 void HandleDndEnter() {ProcessDndEnter ();} 00158 void HandleDndLeave() {ProcessDndLeave ();} 00159 #endif 00160 private: 00161 00163 00166 long ProcessEventInExclusiveMode (Event &ievent, long TraverseInfo, long ProcessEventInfo); 00167 00168 void HandleDndMove (Event &event); 00169 void HandleDndDrop (Event &event); 00170 00172 /* 00173 Color of the InputArea use to draw a colored quad when OnDraw() is called. 00174 */ 00175 Color m_AreaColor; 00176 00177 int _dnd_safety_x; 00178 int _dnd_safety_y; 00179 00180 protected: 00181 00182 bool _has_keyboard_focus; 00183 bool _capture_mouse_down_any_where_else; 00184 bool _double_click; 00185 00186 bool _keyboard_receiver_ignore_mouse_down_outside; 00187 00188 #if defined (NUX_OS_LINUX) 00189 // DnD support 00190 // Rather than being implemented with signals, DND support is implemented with protected virtual function. 00191 // This ensure that a class and it subclass don't process the same event more than once! 00192 00193 virtual void ProcessDndMove (int x, int y, std::list<char *>mimes); 00194 virtual void ProcessDndDrop (int x, int y); 00195 virtual void ProcessDndEnter (); 00196 virtual void ProcessDndLeave (); 00197 00198 void SendDndStatus (bool accept, DndAction action, Geometry region); 00199 void SendDndFinished (bool accepted, DndAction action); 00200 00201 void SetDndEnabled (bool as_source, bool as_target); 00202 00203 virtual bool DndSourceDragBegin (); 00204 virtual NBitmapData * DndSourceGetDragImage (); 00205 virtual std::list<const char *> DndSourceGetDragTypes (); 00206 virtual const char * DndSourceGetDataForType (const char *type, int *size, int *format); 00207 virtual void DndSourceDragFinished (DndAction result); 00208 00209 void StartDragAsSource (); 00210 00211 static NBitmapData * InnerDndSourceGetDragImage (void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragImage (); } 00212 static std::list<const char *> InnerDndSourceGetDragTypes (void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragTypes (); } 00213 static void InnerDndSourceDragFinished (DndAction result, void *data); 00214 00215 static const char * InnerDndSourceGetDataForType (const char *type, int *size, int *format, void *data) 00216 { return static_cast<InputArea *> (data)->DndSourceGetDataForType (type, size, format); } 00217 #endif 00218 00219 public: 00221 sigc::signal<void, int, int, int, int, unsigned long, unsigned long> mouse_move; // send the current position inside the area 00222 00224 00231 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_down; 00232 00234 00241 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_up; 00242 00244 00251 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_enter; 00252 00254 00261 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_leave; 00262 00264 00271 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_click; 00272 00274 00281 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_double_click; 00282 00284 00293 sigc::signal<void, int, int, int, int, unsigned long, unsigned long> mouse_drag; // send (current X, current Y, delta X, delta Y) 00294 00296 sigc::signal < void, 00297 int, // window x 00298 int, // window y 00299 int, // mouse wheel delta: +120/-120 correspond to one notch of the wheel 00300 unsigned long, // mouse state 00301 unsigned long // key state 00302 > mouse_wheel; // send (current X, current Y, delta X, delta Y) 00303 00305 sigc::signal<void, unsigned int, unsigned long, unsigned long> key_up; 00306 00308 sigc::signal<void> begin_key_focus; 00310 sigc::signal<void> end_key_focus; 00311 00312 sigc::signal < void, 00313 unsigned long , /*event type*/ 00314 unsigned long , /*event keysym*/ 00315 unsigned long , /*event state*/ 00316 const TCHAR* , /*character*/ 00317 unsigned short /*key repeat count*/ 00318 > key_down; 00319 00321 00331 sigc::signal<void, int, int, unsigned long, unsigned long> mouse_down_outside_pointer_grab_area; 00332 00333 sigc::signal<void, InputArea*> start_keyboard_grab; 00334 sigc::signal<void, InputArea*> end_keyboard_grab; 00335 00336 void DoSetFocused (bool focus); 00337 00338 protected: 00339 00340 virtual bool AcceptKeyNavFocus(); 00341 00342 // == Signals with 1 to 1 mapping to input device == 00343 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00344 virtual void EmitMouseUpSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00345 virtual void EmitMouseMoveSignal (int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state); 00346 virtual void EmitMouseWheelSignal (int x, int y, int wheel_delta, unsigned long mouse_button_state, unsigned long special_keys_state); 00347 virtual void EmitKeyDownSignal (unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state); 00348 virtual void EmitKeyUpSignal (unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state); 00349 virtual void EmitKeyEventSignal (unsigned long event_type, 00350 unsigned int key_symbol, 00351 unsigned long special_keys_state, 00352 const char* text, 00353 int key_repeat_count); 00354 00355 // == Interpreted signals == 00356 00357 // Mouse down + mouse move on an area 00358 virtual void EmitMouseDragSignal (int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state); 00359 virtual void EmitMouseEnterSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00360 virtual void EmitMouseLeaveSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00361 00362 virtual void EmitMouseClickSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00363 virtual void EmitMouseDoubleClickSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00364 00365 virtual void EmitStartKeyboardFocus(); 00366 virtual void EmitEndKeyboardFocus(); 00367 00368 virtual void EmitMouseDownOutsideArea (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); 00369 00370 friend class WindowCompositor; 00371 }; 00372 00373 } 00374 00375 #endif // INPUTAREA_H