Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
events.hh
Go to the documentation of this file.
00001 /* Rapicorn
00002  * Copyright (C) 2005 Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * A copy of the GNU Lesser General Public License should ship along
00015  * with this library; if not, see http://www.gnu.org/copyleft/.
00016  */
00017 #ifndef __RAPICORN_EVENT_HH__
00018 #define __RAPICORN_EVENT_HH__
00019 
00020 #include <ui/primitives.hh>
00021 
00022 namespace Rapicorn {
00023 
00024 enum ModifierState {
00025   MOD_0         = 0,
00026   MOD_SHIFT     = 1 << 0,
00027   MOD_CAPS_LOCK = 1 << 1,
00028   MOD_CONTROL   = 1 << 2,
00029   MOD_ALT       = 1 << 3,
00030   MOD_MOD1      = MOD_ALT,
00031   MOD_MOD2      = 1 << 4,
00032   MOD_MOD3      = 1 << 5,
00033   MOD_MOD4      = 1 << 6,
00034   MOD_MOD5      = 1 << 7,
00035   MOD_BUTTON1   = 1 << 8,
00036   MOD_BUTTON2   = 1 << 9,
00037   MOD_BUTTON3   = 1 << 10,
00038   MOD_KEY_MASK  = (MOD_SHIFT | MOD_CONTROL | MOD_ALT),
00039   MOD_MASK      = 0x07ff,
00040 };
00041 
00042 enum KeyValue {
00043 #include <ui/keycodes.hh>
00044 };
00045 unichar      key_value_to_unichar     (uint32 keysym);
00046 bool         key_value_is_modifier    (uint32 keysym);
00047 bool         key_value_is_accelerator (uint32 keysym);
00048 FocusDirType key_value_to_focus_dir   (uint32 keysym);
00049 bool         key_value_is_focus_dir   (uint32 keysym);
00050 
00051 typedef enum {
00052   EVENT_NONE,
00053   MOUSE_ENTER,
00054   MOUSE_MOVE,
00055   MOUSE_LEAVE,
00056   BUTTON_PRESS,
00057   BUTTON_2PRESS,
00058   BUTTON_3PRESS,
00059   BUTTON_CANCELED,
00060   BUTTON_RELEASE,
00061   BUTTON_2RELEASE,
00062   BUTTON_3RELEASE,
00063   FOCUS_IN,
00064   FOCUS_OUT,
00065   KEY_PRESS,
00066   KEY_CANCELED,
00067   KEY_RELEASE,
00068   SCROLL_UP,          /* button4 */
00069   SCROLL_DOWN,        /* button5 */
00070   SCROLL_LEFT,        /* button6 */
00071   SCROLL_RIGHT,       /* button7 */
00072   CANCEL_EVENTS,
00073   WIN_SIZE,
00074   WIN_DRAW,
00075   WIN_DELETE,
00076   EVENT_LAST
00077 } EventType;
00078 const char* string_from_event_type (EventType etype);
00079 
00080 struct EventContext;
00081 class Event : public Deletable, protected NonCopyable {
00082 protected:
00083   explicit        Event (EventType, const EventContext&);
00084 public:
00085   virtual        ~Event();
00086   const EventType type;
00087   uint32          time;
00088   bool            synthesized;
00089   ModifierState   modifiers;
00090   ModifierState   key_state; /* modifiers & MOD_KEY_MASK */
00091   double          x, y;
00092 };
00093 typedef Event EventMouse;
00094 class EventButton : public Event {
00095 protected:
00096   explicit        EventButton (EventType, const EventContext&, uint);
00097 public:
00098   virtual        ~EventButton();
00099   /* button press/release */
00100   uint          button; /* 1, 2, 3 */
00101 };
00102 typedef Event EventScroll;
00103 typedef Event EventFocus;
00104 class EventKey : public Event {
00105 protected:
00106   explicit        EventKey (EventType, const EventContext&, uint32, const String &);
00107 public:
00108   virtual        ~EventKey();
00109   /* key press/release */
00110   uint32          key;  /* of type KeyValue */
00111   String          key_name;
00112 };
00113 struct EventWinSize : public Event {
00114 protected:
00115   explicit        EventWinSize (EventType, const EventContext&, uint, double, double);
00116 public:
00117   virtual        ~EventWinSize();
00118   uint            draw_stamp;
00119   double          width, height;
00120 };
00121 struct EventWinDraw : public Event {
00122 protected:
00123   explicit          EventWinDraw (EventType, const EventContext&, uint, const std::vector<Rect> &);
00124 public:
00125   virtual          ~EventWinDraw();
00126   uint              draw_stamp;
00127   Rect              bbox; /* bounding box */
00128   std::vector<Rect> rectangles;
00129 };
00130 typedef Event EventWinDelete;
00131 struct EventContext {
00132   uint32        time;
00133   bool          synthesized;
00134   ModifierState modifiers;
00135   double        x, y;
00136   explicit      EventContext ();
00137   explicit      EventContext (const Event&);
00138   EventContext& operator=    (const Event&);
00139 };
00140 
00141 Event*          create_event_transformed  (const Event        &event,
00142                                            const Affine       &affine);
00143 Event*          create_event_cancellation (const EventContext &econtext);
00144 EventMouse*     create_event_mouse        (EventType           type,
00145                                            const EventContext &econtext);
00146 EventButton*    create_event_button       (EventType           type,
00147                                            const EventContext &econtext,
00148                                            uint                button);
00149 EventScroll*    create_event_scroll       (EventType           type,
00150                                            const EventContext &econtext);
00151 EventFocus*     create_event_focus        (EventType           type,
00152                                            const EventContext &econtext);
00153 EventKey*       create_event_key          (EventType           type,
00154                                            const EventContext &econtext,
00155                                            uint32              key,
00156                                            const char         *name);
00157 EventWinSize*   create_event_win_size     (const EventContext &econtext,
00158                                            uint                draw_stamp,
00159                                            double              width,
00160                                            double              height);
00161 EventWinDraw*   create_event_win_draw     (const EventContext &econtext,
00162                                            uint                draw_stamp,
00163                                            const std::vector<Rect> &rects);
00164 EventWinDelete* create_event_win_delete   (const EventContext &econtext);
00165 
00166 } // Rapicorn
00167 
00168 #endif  /* __RAPICORN_EVENT_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines