Back to index

nux  3.0.0
InputArea.h
Go to the documentation of this file.
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 
00028 #if defined(NUX_OS_WINDOWS)
00029   #include "NuxGraphics/Events.h"
00030 #elif defined(NUX_OS_LINUX)
00031   #include "NuxGraphics/Events.h"
00032 #endif
00033 #include "NuxGraphics/GraphicsDisplay.h"
00034 
00035 namespace nux
00036 {
00037   class WindowCompositor;
00038   class InputArea;
00039 
00040   typedef InputArea CoreArea;
00041 
00042   class InputArea : public Area
00043   {
00044   public:
00045     NUX_DECLARE_OBJECT_TYPE(InputArea, Area);
00046   public:
00047     InputArea(NUX_FILE_LINE_PROTO);
00048     virtual ~InputArea();
00049 
00051 
00057     virtual void OnDraw(GraphicsEngine &graphics_engine, bool force_draw);
00058 
00059     virtual void OverlayDrawing(GraphicsEngine &graphics_engine) {}
00060 
00061     bool HasKeyboardFocus();
00062 
00063     bool MouseFocusOnOtherArea();
00064     void CaptureMouseDownAnyWhereElse(bool b);
00065     bool IsCaptureMouseDownAnyWhereElse() const;
00066 
00067     Area* FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type);
00068     Area* FindKeyFocusArea(unsigned int key_symbol,
00069                           unsigned long x11_key_code,
00070                           unsigned long special_keys_state);
00071 
00072     virtual bool AcceptKeyNavFocus() const;
00073     
00074   protected:
00075 
00076   private:
00077     bool _dnd_enabled_as_source;
00078     bool _dnd_enabled_as_target;
00079   public:
00080     // Override the virtual methods from Object Base
00081     // Here, we get a change to update the text of the keyboard handler.
00082     virtual void SetBaseString(const char *Caption);
00083 
00084     void SetKeyboardReceiverIgnoreMouseDownOutside(bool ignore_mouse_down_outside);
00085 
00086     void SetAcceptKeyNavFocusOnMouseDown(bool accept);
00087     void SetAcceptKeyNavFocusOnMouseEnter(bool accept);
00088 
00089     bool KeyboardReceiverIgnoreMouseDownOutside();
00090 
00091     virtual bool IsArea() const
00092     {
00093       return true;
00094     }
00095 
00096     void GrabPointer();
00097     void GrabKeyboard();
00098     void UnGrabPointer();
00099     void UnGrabKeyboard();
00100     bool OwnsPointerGrab();
00101     bool OwnsKeyboardGrab();
00102 
00104 
00110     bool IsMouseOwner();
00111 
00113 
00121     bool IsMouseInside();
00122 
00124     void EnableDoubleClick(bool double_click);
00125 
00127     bool DoubleClickEnabled() const;
00128 
00129     bool mouse_in_;
00130 
00131 #if defined(NUX_OS_LINUX)
00132     void HandleDndEnter() {ProcessDndEnter();}
00133     void HandleDndLeave() {ProcessDndLeave();}
00134 #endif
00135   private:
00136 
00138 
00141     long ProcessEventInExclusiveMode(Event &event, long TraverseInfo, long ProcessEventInfo);
00142 
00143     void HandleDndMove  (Event &event);
00144     void HandleDndDrop  (Event &event);
00145 
00147     /*
00148         Color of the InputArea use to draw a colored quad when OnDraw() is called.
00149     */
00150     Color area_color_;
00151     
00152     int _dnd_safety_x;
00153     int _dnd_safety_y;
00154 
00155   protected:
00156     bool _capture_mouse_down_any_where_else;
00157     bool _double_click;     
00158 
00159     bool _keyboard_receiver_ignore_mouse_down_outside;
00160 
00161     bool accept_key_nav_focus_on_mouse_down_;
00162     bool accept_key_nav_focus_on_mouse_enter_;
00163 
00164 
00165 #if defined(NUX_OS_LINUX)
00166     // DnD support
00167     // Rather than being implemented with signals, DND support is implemented with protected virtual function.
00168     // This ensure that a class and it subclass don't process the same event more than once!
00169 
00170     virtual void ProcessDndMove  (int x, int y, std::list<char *>mimes);
00171     virtual void ProcessDndDrop  (int x, int y);
00172     virtual void ProcessDndEnter();
00173     virtual void ProcessDndLeave();
00174 
00175     void SendDndStatus(bool accept, DndAction action, Geometry region);
00176     void SendDndFinished(bool accepted, DndAction action);
00177     
00178     void SetDndEnabled(bool as_source, bool as_target);
00179     
00180     virtual bool                    DndSourceDragBegin      ();
00181     virtual NBitmapData *           DndSourceGetDragImage   ();
00182     virtual std::list<const char *> DndSourceGetDragTypes   ();
00183     virtual const char *            DndSourceGetDataForType(const char *type, int *size, int *format);
00184     virtual void                    DndSourceDragFinished   (DndAction result);
00185     
00186     void StartDragAsSource();
00187     
00188     static NBitmapData *           InnerDndSourceGetDragImage(void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragImage();       }
00189     static std::list<const char *> InnerDndSourceGetDragTypes(void *data) { return static_cast<InputArea *> (data)->DndSourceGetDragTypes();       }
00190     static void                    InnerDndSourceDragFinished(DndAction result, void *data);
00191     
00192     static const char * InnerDndSourceGetDataForType(const char *type, int *size, int *format, void *data) 
00193       { return static_cast<InputArea *> (data)->DndSourceGetDataForType(type, size, format); }
00194 #endif
00195 
00196   public:
00198     sigc::signal<void, int, int, int, int, unsigned long, unsigned long> mouse_move;  // send the current position inside the area
00199     
00201 
00208     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_down;
00209     
00211 
00218     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_up;
00219     
00221 
00228     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_enter;
00229     
00231 
00238     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_leave;
00239     
00241 
00248     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_click;
00249     
00251 
00258     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_double_click;
00259     
00261 
00270     sigc::signal<void, int, int, int, int, unsigned long, unsigned long> mouse_drag; // send(current X, current Y, delta X, delta Y)
00271 
00273     sigc::signal < void,
00274          int,            // window x
00275          int,            // window y
00276          int,            // mouse wheel delta: +120/-120 correspond to one notch of the wheel
00277          unsigned long,  // mouse state
00278          unsigned long   // key state
00279          > mouse_wheel; // send(current X, current Y, delta X, delta Y)
00280 
00282     sigc::signal<void, unsigned int, unsigned long, unsigned long> key_up;
00283 
00285     sigc::signal<void> begin_key_focus;
00287     sigc::signal<void> end_key_focus;
00288 
00289     sigc::signal < void,
00290          unsigned long       ,   /*event type*/
00291          unsigned long       ,   /*event keysym*/
00292          unsigned long       ,   /*event state*/
00293          const char*        ,   /*character*/
00294          unsigned short          /*key repeat count*/
00295          > key_down;
00296 
00298 
00308     sigc::signal<void, int, int, unsigned long, unsigned long> mouse_down_outside_pointer_grab_area;
00309 
00310     sigc::signal<void, InputArea*> start_keyboard_grab;
00311     sigc::signal<void, InputArea*> end_keyboard_grab;
00312 
00313     protected:
00314 
00315       virtual bool AcceptKeyNavFocus();
00316       virtual bool AcceptKeyNavFocusOnMouseDown() const;
00317       virtual bool AcceptKeyNavFocusOnMouseEnter() const;
00318 
00319       // == Signals with 1 to 1 mapping to input device ==
00320       virtual void EmitMouseDownSignal        (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00321       virtual void EmitMouseUpSignal          (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00322       virtual void EmitMouseMoveSignal        (int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state);
00323       virtual void EmitMouseWheelSignal       (int x, int y, int wheel_delta, unsigned long mouse_button_state, unsigned long special_keys_state);
00324       virtual void EmitKeyDownSignal          (unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state);
00325       virtual void EmitKeyUpSignal            (unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state);
00326       virtual void EmitKeyEventSignal         (unsigned long event_type,
00327                                               unsigned int key_symbol,
00328                                               unsigned long special_keys_state,
00329                                               const char* text,
00330                                               int key_repeat_count);
00331 
00332       // == Interpreted signals ==
00333 
00334       // Mouse down + mouse move on an area
00335       virtual void EmitMouseDragSignal        (int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state);
00336       virtual void EmitMouseEnterSignal       (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00337       virtual void EmitMouseLeaveSignal       (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00338 
00339       virtual void EmitMouseClickSignal       (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00340       virtual void EmitMouseDoubleClickSignal(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00341 
00342       virtual void EmitMouseDownOutsideArea   (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
00343 
00344       friend class WindowCompositor;
00345   };
00346 
00347 }
00348 
00349 #endif // INPUTAREA_H