dragimag.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dragimag.h
  3. // Purpose: interface of wxDragImage
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDragImage
  9. This class is used when you wish to drag an object on the screen, and a
  10. simple cursor is not enough.
  11. On Windows, the Win32 API is used to achieve smooth dragging. On other
  12. platforms, wxGenericDragImage is used. Applications may also prefer to use
  13. wxGenericDragImage on Windows, too.
  14. To use this class, when you wish to start dragging an image, create a
  15. wxDragImage object and store it somewhere you can access it as the drag
  16. progresses. Call BeginDrag() to start, and EndDrag() to stop the drag. To
  17. move the image, initially call Show() and then Move(). If you wish to
  18. update the screen contents during the drag (for example, highlight an item
  19. as in the dragimag sample), first call Hide(), update the screen, call
  20. Move(), and then call Show().
  21. You can drag within one window, or you can use full-screen dragging either
  22. across the whole screen, or just restricted to one area of the screen to
  23. save resources. If you want the user to drag between two windows, then you
  24. will need to use full-screen dragging.
  25. If you wish to draw the image yourself, use wxGenericDragImage and override
  26. DoDrawImage() and GetImageRect().
  27. @library{wxcore}
  28. @category{dnd}
  29. @see @ref page_samples_dragimag
  30. */
  31. class wxDragImage : public wxObject
  32. {
  33. public:
  34. /**
  35. Default constructor.
  36. */
  37. wxDragImage();
  38. /**
  39. Constructs a drag image from a bitmap and optional cursor.
  40. @param image
  41. Bitmap to be used as the drag image. The bitmap can have a mask.
  42. @param cursor
  43. Optional cursor to combine with the image.
  44. */
  45. wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
  46. /**
  47. Constructs a drag image from an icon and optional cursor.
  48. @param image
  49. Icon to be used as the drag image.
  50. @param cursor
  51. Optional cursor to combine with the image.
  52. */
  53. wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
  54. /**
  55. Constructs a drag image from a text string and optional cursor.
  56. @param text
  57. Text used to construct a drag image.
  58. @param cursor
  59. Optional cursor to combine with the image.
  60. */
  61. wxDragImage(const wxString& text, const wxCursor& cursor = wxNullCursor);
  62. /**
  63. Constructs a drag image from the text in the given tree control item,
  64. and optional cursor.
  65. @param treeCtrl
  66. Tree control for constructing a tree drag image.
  67. @param id
  68. Tree control item id.
  69. */
  70. wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
  71. /**
  72. Constructs a drag image from the text in the given list control item,
  73. and optional cursor.
  74. @param listCtrl
  75. List control for constructing a list drag image.
  76. @param id
  77. List control item id.
  78. */
  79. wxDragImage(const wxListCtrl& listCtrl, long id);
  80. /**
  81. Start dragging the image, in a window or full screen.
  82. You need to then call Show() and Move() to show the image on the
  83. screen. Call EndDrag() when the drag has finished.
  84. Note that this call automatically calls CaptureMouse().
  85. @param hotspot
  86. The location of the drag position relative to the upper-left corner
  87. of the image.
  88. @param window
  89. The window that captures the mouse, and within which the dragging
  90. is limited unless fullScreen is @true.
  91. @param fullScreen
  92. If @true, specifies that the drag will be visible over the full
  93. screen, or over as much of the screen as is specified by rect. Note
  94. that the mouse will still be captured in window.
  95. @param rect
  96. If non-@NULL, specifies the rectangle (in screen coordinates) that
  97. bounds the dragging operation. Specifying this can make the
  98. operation more efficient by cutting down on the area under
  99. consideration, and it can also make a visual difference since the
  100. drag is clipped to this area.
  101. */
  102. bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
  103. bool fullScreen = false, wxRect* rect = NULL);
  104. /**
  105. Start dragging the image, using the first window to capture the mouse
  106. and the second to specify the bounding area. This form is equivalent to
  107. using the first form, but more convenient than working out the bounding
  108. rectangle explicitly.
  109. You need to then call Show() and Move() to show the image on the
  110. screen. Call EndDrag() when the drag has finished.
  111. Note that this call automatically calls CaptureMouse().
  112. @param hotspot
  113. The location of the drag position relative to the upper-left corner
  114. of the image.
  115. @param window
  116. The window that captures the mouse, and within which the dragging
  117. is limited.
  118. @param boundingWindow
  119. Specifies the area within which the drag occurs.
  120. */
  121. bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
  122. wxWindow* boundingWindow);
  123. /**
  124. Draws the image on the device context with top-left corner at the given
  125. position.
  126. This function is only available with wxGenericDragImage, to allow
  127. applications to draw their own image instead of using an actual bitmap.
  128. If you override this function, you must also override GetImageRect().
  129. */
  130. virtual bool DoDrawImage(wxDC& dc, const wxPoint& pos) const;
  131. /**
  132. Call this when the drag has finished.
  133. @note This function automatically releases mouse capture.
  134. */
  135. bool EndDrag();
  136. /**
  137. Returns the rectangle enclosing the image, assuming that the image is
  138. drawn with its top-left corner at the given point.
  139. This function is available in wxGenericDragImage only, and may be
  140. overridden (together with DoDrawImage()) to provide a virtual drawing
  141. capability.
  142. */
  143. virtual wxRect GetImageRect(const wxPoint& pos) const;
  144. /**
  145. Hides the image. You may wish to call this before updating the window
  146. contents (perhaps highlighting an item). Then call Move() and Show().
  147. */
  148. bool Hide();
  149. /**
  150. Call this to move the image to a new position. The image will only be
  151. shown if Show() has been called previously (for example at the start of
  152. the drag).
  153. @param pt
  154. The position in client coordinates (relative to the window
  155. specified in BeginDrag()).
  156. You can move the image either when the image is hidden or shown, but in
  157. general dragging will be smoother if you move the image when it is
  158. shown.
  159. */
  160. bool Move(const wxPoint& pt);
  161. /**
  162. Shows the image. Call this at least once when dragging.
  163. */
  164. bool Show();
  165. /**
  166. Override this if you wish to draw the window contents to the backing
  167. bitmap yourself. This can be desirable if you wish to avoid flicker by
  168. not having to redraw the updated window itself just before dragging,
  169. which can cause a flicker just as the drag starts. Instead, paint the
  170. drag image's backing bitmap to show the appropriate graphic @e minus
  171. the objects to be dragged, and leave the window itself to be updated by
  172. the drag image. This can provide eerily smooth, flicker-free drag
  173. behaviour.
  174. The default implementation copies the window contents to the backing
  175. bitmap. A new implementation will normally copy information from
  176. another source, such as from its own backing bitmap if it has one, or
  177. directly from internal data structures.
  178. This function is available in wxGenericDragImage only.
  179. */
  180. virtual bool UpdateBackingFromWindow(wxDC& windowDC, wxMemoryDC& destDC,
  181. const wxRect& sourceRect,
  182. const wxRect& destRect) const;
  183. };