ubit
uevent.hpp
1 /************************************************************************
2  *
3  * uevent.hpp
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef uevent_hpp
18 #define uevent_hpp 1
19 #include <ubit/ubox.hpp>
20 #include <ubit/ugeom.hpp>
21 #include <ubit/ukey.hpp>
22 namespace ubit {
23 
24  class UDataContext;
25 
30  class UEvent {
31  public:
32  UEvent(const UCond& c, UObject* source, UObject* aux = null);
33 
34  virtual ~UEvent();
35 
36  const UCond& getCond() const {return *cond;}
41  virtual UObject* getSource() const {return source;}
43 
44  virtual UObject* getAux() const {return aux;}
46 
48  virtual UInputEvent* toInputEvent() {return null;}
49  virtual UMouseEvent* toMouseEvent() {return null;}
50  virtual UKeyEvent* toKeyEvent() {return null;}
51  virtual UWheelEvent* toWheelEvent() {return null;}
52  virtual UViewEvent* toViewEvent() {return null;}
53  virtual UPaintEvent* toPaintEvent() {return null;}
54  virtual UResizeEvent* toResizeEvent() {return null;}
55  virtual UTimerEvent* toTimerEvent() {return null;}
56  virtual UWinEvent* toWinEvent() {return null;}
57  virtual UMessageEvent* toMessageEvent(){return null;}
58  virtual USysWMEvent* toSysWMEvent() {return null;}
59  virtual UUserEvent* toUserEvent() {return null;}
60 
61  void setCond(const UCond&);
62 
63  protected:
64  const UCond* cond; // event condition
65  UObject* source; // the object that produced this event
66  UObject* aux; // auxilliary data
67  };
68 
69 
70  // =============================================================================
75  class UInputEvent : public UEvent, public UModifier {
76  public:
77  UInputEvent(const UCond&, UView* source_view, UEventFlow*,
78  unsigned long when, int state);
79 
80  virtual UInputEvent* toInputEvent() {return this;}
81 
82  virtual UElem* getSource() const;
84 
85  UView* getView() const {return source_view;}
91  UView* getViewOf(const UBox& box) const;
96  unsigned long getWhen() const {return when;}
98 
99  virtual int getModifiers() const;
113  bool isShiftDown() const;
114  bool isControlDown() const;
115  bool isMetaDown() const;
116  bool isAltDown() const;
117  bool isAltGraphDown() const;
118 
119  UWin* getWin() const;
121 
122  UView* getWinView() const;
124 
125  UEventFlow* getFlow() const {return eflow;}
132  UDisp* getDisp() const;
139  bool dontCloseMenu() const {return modes.DONT_CLOSE_MENU;}
141 
142  // - - - Impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
143 #ifndef NO_DOC
144  protected:
145  friend class UElem;
146  friend class UEventFlow;
147  friend class UView;
148  friend class UFlowView;
149  friend class UViewFind;
150 
151  struct Modes {
152  unsigned PROPAGATE:1;
153  unsigned IS_MDRAG:1;
154  unsigned IS_FIRST_MDRAG:1;
155  unsigned IS_BROWSING:1;
156  unsigned DONT_CLOSE_MENU:1;
157  unsigned SOURCE_IN_MENU:1;
158  } modes;
159 
160  int state;
161  unsigned long when;
162  UView* source_view; // the view that contains the mouse
163  UEventFlow* eflow; // the event flow that produced this event
164  UElem* event_observer;
165 #endif
166  };
167 
168  // =============================================================================
172  class UMouseEvent : public UInputEvent {
173  public:
174  UMouseEvent(const UCond&, UView* source, UEventFlow*, unsigned long time, int state,
175  const UPoint& pos, const UPoint& abs_pos, int btn);
176 
177  virtual UMouseEvent* toMouseEvent() {return this;}
178 
179  float getX() const {return pos.x;}
181 
182  float getY() const {return pos.y;}
184 
185  const UPoint& getPos() const {return pos;}
187 
188  const UPoint& getScreenPos() const {return abs_pos;}
190 
191  UPoint getPosIn(const UView& view) const;
193 
194  UPoint getPosIn(const UBox& parent_box) const;
199  UPoint getPosAndViewIn(const UBox& parent, UView*& parent_view) const;
204  int getClickCount() const {return click_count;}
206 
207  int getButton() const {return button;}
234  int getButtons() const;
241  void translatePos(float x, float y);
243 
244  void propagate() {modes.PROPAGATE = true;}
246 
247  void setFirstDrag(bool s) {modes.IS_FIRST_MDRAG = s;}
248  bool isFirstDrag() const {return modes.IS_FIRST_MDRAG;}
249  bool isBrowsing() const {return modes.IS_BROWSING;}
250 
251  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
252 
253  UStr* getStr();
255 
256  UStr* getStr(UDataContext&);
258 
259  UData* getData();
261 
262  UData* getData(UDataContext&);
270  // - - - Impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
271 #ifndef NO_DOC
272  protected:
273  friend class UEventFlow;
274  friend class UElem;
275  friend class UView;
276  friend class UFlowView;
277  int button, click_count;
278  UPoint pos, abs_pos;
279 #endif
280  };
281 
282  // =============================================================================
286  class UWheelEvent : public UMouseEvent {
287  public:
288  enum {WHEEL_DELTA = 120};
289 
290  UWheelEvent(const UCond&, UView* source, UEventFlow*,
291  unsigned long time, int state,
292  const UPoint& pos, const UPoint& abs_pos,
293  int wheel_btn, int wheel_delta);
294 
295  virtual UWheelEvent* toWheelEvent() {return this;}
296 
297  bool isVertical() const {return (button & 1) == 0;}
298 
299  int getWheelDelta() const {return delta;}
308  private:
309  int delta;
310  };
311 
312  // =============================================================================
316  class UKeyEvent : public UInputEvent {
317  public:
318  UKeyEvent(const UCond&, UView* source, UEventFlow*,
319  unsigned long time, int state,
320  int keycode, short keychar);
321 
322  virtual UKeyEvent* toKeyEvent() {return this;}
323 
324  short getKeyChar() const {return keychar;}
326 
327  int getKeyCode() const {return keycode;}
329 
330  virtual void setKeyChar(short keychar);
335  virtual void setKeyCode(int keycode);
337 
338  private:
339  friend class UElem;
340  int keycode;
341  short keychar;
342  };
343 
344  // =============================================================================
347  class UViewEvent : public UEvent {
348  public:
349  UViewEvent(const UCond&, UView* source_view);
350  virtual UViewEvent* toViewEvent() {return this;}
351 
352  UBox* getSource() const;
354 
355  UView* getView() const {return source_view;}
357 
358  UDisp* getDisp() const;
365  protected:
366  UView* source_view;
367  };
368 
369  // =============================================================================
377  class UPaintEvent : public UViewEvent {
378  public:
379  UPaintEvent(const UCond&, UView* source_view, const URect* win_clip = null);
380 
381  virtual UPaintEvent* toPaintEvent() {return this;}
382 
383  bool isClipSet() {return is_clip_set;}
385 
386  void getClip(URect& r) const;
392  const URect getClip() const {URect r; getClip(r); return r;}
394 
395 #ifndef NO_DOC
396  virtual bool setSourceAndProps(UView*);
397  void setContext(UUpdateContext& c) {current_context = &c;}
398 
399  protected:
400  friend class UBox;
401  friend class UDisp;
402  friend class UGraph;
403 
404  bool is_clip_set; // is redraw_clip valid ?
405  URect redraw_clip; // in window coordinates!
406  UUpdateContext* current_context;
407  UView* layout_view;
408 
409  virtual void setProps(const class UViewContext&);
410 #endif
411  };
412 
413  // =============================================================================
418  class UResizeEvent : public UViewEvent {
419  public:
420  UResizeEvent(const UCond&, UView* source_view);
421  virtual UResizeEvent* toResizeEvent() {return this;}
422  };
423 
424  // =============================================================================
425 
426  class UWinEvent : public UEvent {
427  public:
428  UWinEvent(const UCond&, UView* source_view, int type, int state);
429 
430  virtual UWinEvent* toWinEvent() {return this;}
431 
432  UView* getView() const {return source_view;}
433  int getType() const {return type;}
434  int getState() const {return state;}
435 
436  private:
437  UView* source_view;
438  int type, state;
439  };
440 
441  // =============================================================================
444  class USysWMEvent : public UEvent {
445  public:
446  USysWMEvent(const UCond&, UView* source_view, void* system_event);
447 
448  virtual USysWMEvent* toSysWMEvent() {return this;}
449 
450  UView* getView() const {return source_view;}
451  void* getSysEvent() {return sys_event;}
452 
453  private:
454  UView* source_view;
455  void* sys_event;
456  };
457 
458  // =============================================================================
462  class UMessageEvent : public UEvent {
463  public:
464  UMessageEvent(const UCond&, UMessagePort* port);
465 
466  virtual UMessageEvent* toMessageEvent() {return this;}
467 
468  //virtual UObject* getSource() const {return (UObject*)port;}
469 
470  const UStr* getMessage() const;
472 
473  UMessagePort* getMessagePort() const {return (UMessagePort*)source;}
475 
476  private:
477  friend class UMessagePortMap;
478  //UMessagePort* port;
479  };
480 
481  // =============================================================================
485  class UTimerEvent : public UEvent {
486  public:
487  UTimerEvent(const UCond&, UTimer* timer, unsigned long when);
488 
489  virtual UTimerEvent* toTimerEvent() {return this;}
490 
491  //virtual UObject* getSource() const {return (UObject*)timer;}
492  UTimer* getTimer() const {return (UTimer*)source;}
493  unsigned long getWhen() const {return when;}
494 
495  protected:
496  //UTimer* timer;
497  unsigned long when;
498  };
499 
500  // =============================================================================
504  class UUserEvent : public UEvent {
505  public:
506  UUserEvent(const UCond&, UObject* source, int type, void* data);
507 
508  virtual UUserEvent* toUserEvent() {return this;}
509 
510  //virtual UObject* getSource() const {return source;}
511  int getType() const {return type;}
512  void* getData() const {return data;}
513 
514  private:
515  //UObject* source;
516  int type;
517  void* data;
518  };
519 
520  /* ==================================================== [(c)Elc] ======= */
524  class UDataContext {
525  public:
526  UDataContext();
527  ~UDataContext();
528 
529  URect getBounds() const;
531 
532  // - - impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
533 # ifndef NO_DOC
534  //private:
535  friend class UBox;
536  friend class UView;
537  friend class UFlowView;
538  friend class UEdit;
539  friend class USelection;
540 
541  URect win_clip;
542  // in the case of multine UStr objects, the region does not contain the entire
543  // string but just the line that is beneath the mouse
544 
545  bool exact_match;
546  // true if this data object is exactly located under the Mouse.
547  // false if this data is the last data object before the Mouse position
548 
549  long strpos, strpos2;
550  // strpos = position of the mouse in the string if data is an UStr.
551 
552  UChildIter it, it2;
553  // points to the data object that is located under the mouse when calling
554  // UMouseEvent::getData() or UMouseEvent::getStr().
555 
556  UData* data;
557  UView* source_view;
558  UPoint win_eventpos;
559 
560  void set(UUpdateContext&, UData*, UChildIter data_iter, UChildIter end_iter,
561  const URect&, int _strpos, bool exact_match);
562  void merge(UUpdateContext&, UData*, UChildIter data_iter, UChildIter end_iter,
563  const URect&, bool exact_match);
564 # endif
565  };
566 
567 }
568 #endif
569 
information on UData objects that are being retrieved by UEvent::getData() or UEvent::getStr().
Definition: uevent.hpp:524
keyboard events
Definition: uevent.hpp:316
Definition: uviewImpl.hpp:92
bool dontCloseMenu() const
impl.
Definition: uevent.hpp:139
float getX() const
returns the X coordinate of the mouse in getView().
Definition: uevent.hpp:179
float getY() const
returns the Y coordinate of the mouse in getView().
Definition: uevent.hpp:182
text selection.
Definition: uselection.hpp:25
a UTimer object fires callbacks after a given delay.
Definition: utimer.hpp:45
UMessagePort * getMessagePort() const
returns the corresponding messagge port.
Definition: uevent.hpp:473
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
bool isClipSet()
true if the clipping zone is vaild.
Definition: uevent.hpp:383
const UPoint & getScreenPos() const
returns the screen coordinates of the mouse.
Definition: uevent.hpp:188
int getWheelDelta() const
returns the amount of wheel movement.
Definition: uevent.hpp:299
Ubit Event class.
Definition: uevent.hpp:30
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
Display Context.
Definition: udisp.hpp:44
int getClickCount() const
returns the number of mouse clicks.
Definition: uevent.hpp:204
Base class for Ubit conditions.
Definition: ucond.hpp:29
UEventFlow * getFlow() const
returns the Event Flow that received this event (for two-handed interaction or groupware).
Definition: uevent.hpp:125
short getKeyChar() const
returns the typed character (in ISO Latin).
Definition: uevent.hpp:324
UView * getView() const
returns the view of getSource() that received this event.
Definition: uevent.hpp:355
Text editing and caret controller.
Definition: uedit.hpp:30
Impl.
Definition: umessage.hpp:50
Base class for Viewable Objects.
Definition: udata.hpp:31
Paint event.
Definition: uevent.hpp:377
Definition: uevent.hpp:151
int getButton() const
returns the button that was just pressed or released.
Definition: uevent.hpp:207
const UPoint & getPos() const
returns the coordinates of the mouse in getView().
Definition: uevent.hpp:185
virtual UInputEvent * toInputEvent()
dynamic cast: returns &#39;this&#39; converted to the requested class or null.
Definition: uevent.hpp:80
const URect getClip() const
shortcut for getClip(URect& r).
Definition: uevent.hpp:392
lightweight general purpose container.
Definition: uelem.hpp:44
unsigned long getWhen() const
returns the time when this event was produced.
Definition: uevent.hpp:96
view event: base class for UPaintEvent and UResizeEvent.
Definition: uevent.hpp:347
int getKeyCode() const
returns the key code (
Definition: uevent.hpp:327
Definition: uevent.hpp:426
wheel events
Definition: uevent.hpp:286
Definition: uview.hpp:335
Modifier masks.
Definition: ukey.hpp:27
Event Flow.
Definition: ueventflow.hpp:34
UView * getView() const
returns the object&#39;s view that received this event.
Definition: uevent.hpp:85
Platform-dependent window manager events.
Definition: uevent.hpp:444
Box View.
Definition: uview.hpp:65
User events.
Definition: uevent.hpp:504
Definition: uupdatecontext.hpp:32
Ubit Message Port.
Definition: umessage.hpp:36
Definition: uhardfont.hpp:31
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
const UCond & getCond() const
returns the event condition that detected this event.
Definition: uevent.hpp:36
void propagate()
propagates events in children:
Definition: uevent.hpp:244
Base class for windows and menus.
Definition: uwin.hpp:47
timer event.
Definition: uevent.hpp:485
Definition: uviewImpl.hpp:78
virtual UObject * getSource() const
returns the object that received this event.
Definition: uevent.hpp:41
Resize event.
Definition: uevent.hpp:418
virtual UObject * getAux() const
returns auxilliary data.
Definition: uevent.hpp:44
Ubit String.
Definition: ustr.hpp:72
mouse events
Definition: uevent.hpp:172
virtual UInputEvent * toInputEvent()
dynamic cast: returns &#39;this&#39; converted to the requested class or null.
Definition: uevent.hpp:48
Ubit Message events.
Definition: uevent.hpp:462
Base class of most Ubit objects (SEE DETAILS!).
Definition: uobject.hpp:113