mousemanager.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/mousemanager.h
  3. // Purpose: documentation of wxMouseEventsManager class
  4. // Author: Vadim Zeitlin
  5. // Created: 2009-04-20
  6. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. /**
  10. @class wxMouseEventsManager
  11. Helper for handling mouse input events in windows containing multiple
  12. items.
  13. This class handles mouse events and synthesizes high-level notifications
  14. such as clicks and drag events from low level mouse button presses and
  15. mouse movement events. It is useful because handling the mouse events is
  16. less obvious than might seem at a first glance: for example, clicks on an
  17. object should only be generated if the mouse was both pressed and released
  18. over it and not just released (so it requires storing the previous state)
  19. and dragging shouldn't start before the mouse moves away far enough.
  20. This class encapsulates all these dull details for controls containing
  21. multiple items which can be identified by a positive integer index and you
  22. just need to implement its pure virtual functions to use it.
  23. Notice that this class supposes that all items can be identified by an
  24. integer "index" but it doesn't need to be an ordinal index of the item
  25. (although this is the most common case) -- it can be any value which can
  26. be used to uniquely identify an item.
  27. @library{wxcore}
  28. @category{events}
  29. */
  30. class wxMouseEventsManager : public wxEvtHandler
  31. {
  32. public:
  33. /**
  34. Default constructor.
  35. You must call Create() to finish initializing the mouse events manager.
  36. If possible, avoid the use of this constructor in favour of the other
  37. one which fully initializes the mouse events manager immediately.
  38. */
  39. wxMouseEventsManager();
  40. /**
  41. Constructor creates the manager for the window.
  42. A mouse event manager is always associated with a window and must be
  43. destroyed by the window when it is destroyed (it doesn't need to be
  44. allocated on the heap however).
  45. */
  46. wxMouseEventsManager(wxWindow *win);
  47. /**
  48. Finishes initialization of the object created using default
  49. constructor.
  50. Currently always returns @true.
  51. */
  52. bool Create(wxWindow *win);
  53. protected:
  54. /**
  55. Must be overridden to return the item at the given position.
  56. @param pos
  57. The position to test, in physical coordinates.
  58. @return
  59. The index of the item at the given position or wxNOT_FOUND if there
  60. is no item there.
  61. */
  62. virtual int MouseHitTest(const wxPoint& pos) = 0;
  63. /**
  64. Must be overridden to react to mouse clicks.
  65. This method is called when the user clicked (i.e. pressed and released
  66. mouse over the @e same item) and should normally generate a
  67. notification about this click and return true if it was handled or
  68. false otherwise, determining whether the original mouse event is
  69. skipped or not.
  70. @param item
  71. The item which was clicked.
  72. @return
  73. @true if the mouse event was processed and @false otherwise.
  74. */
  75. virtual bool MouseClicked(int item) = 0;
  76. /**
  77. Must be overridden to allow or deny dragging of the item.
  78. This method is called when the user attempts to start dragging the
  79. given item.
  80. @param item
  81. The item which is going to be dragged.
  82. @param pos
  83. The position from where it is being dragged.
  84. @return
  85. @true to allow the item to be dragged (in which case
  86. MouseDragging() and MouseDragEnd() will be called later, unless
  87. MouseDragCancelled() is called instead) or @false to forbid it.
  88. */
  89. virtual bool MouseDragBegin(int item, const wxPoint& pos) = 0;
  90. /**
  91. Must be overridden to provide feed back while an item is being dragged.
  92. This method is called while the item is being dragged and should
  93. normally update the feedback shown on screen (usually this is done
  94. using wxOverlay).
  95. Notice that this method will never be called for the items for which
  96. MouseDragBegin() returns @false. Consequently, if MouseDragBegin()
  97. always returns @false you can do nothing in this method.
  98. @param item
  99. The item being dragged.
  100. @param pos
  101. The current position of the item.
  102. @see MouseDragEnd()
  103. */
  104. virtual void MouseDragging(int item, const wxPoint& pos) = 0;
  105. /**
  106. Must be overridden to handle item drop.
  107. This method is called when the mouse is released after dragging the
  108. item. Normally the item should be positioned at the new location.
  109. @param item
  110. The item which was dragged and now dropped.
  111. @param pos
  112. The position at which the item was dropped.
  113. @see MouseDragBegin(), MouseDragging()
  114. */
  115. virtual void MouseDragEnd(int item, const wxPoint& pos) = 0;
  116. /**
  117. Must be overridden to handle cancellation of mouse dragging.
  118. This method is called when mouse capture is lost while dragging the
  119. item and normally should remove the visual feedback drawn by
  120. MouseDragging() as well as reset any internal variables set in
  121. MouseDragBegin().
  122. @see wxMouseCaptureLostEvent
  123. */
  124. virtual void MouseDragCancelled(int item) = 0;
  125. /**
  126. May be overridden to update the state of an item when it is pressed.
  127. This method is called when the item is becomes pressed and can be used
  128. to change its appearance when this happens. It is mostly useful for
  129. button-like items and doesn't need to be overridden if the items
  130. shouldn't change their appearance when pressed.
  131. @param item
  132. The item being pressed.
  133. */
  134. virtual void MouseClickBegin(int item);
  135. /**
  136. Must be overridden to reset the item appearance changed by
  137. MouseClickBegin().
  138. This method is called if the mouse capture was lost while the item was
  139. pressed and must be overridden to restore the default item appearance
  140. if it was changed in MouseClickBegin().
  141. @see MouseDragCancelled(), wxMouseCaptureLostEvent
  142. */
  143. virtual void MouseClickCancelled(int item);
  144. };