1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/msw/dragimag.h 
   3 // Purpose:     wxDragImage class: a kind of a cursor, that can cope 
   4 //              with more sophisticated images 
   5 // Author:      Julian Smart 
   9 // Copyright:   (c) Julian Smart 
  10 // Licence:     wxWindows licence 
  11 ///////////////////////////////////////////////////////////////////////////// 
  13 #ifndef _WX_DRAGIMAG_H_ 
  14 #define _WX_DRAGIMAG_H_ 
  17 #pragma interface "dragimag.h" 
  20 #include "wx/bitmap.h" 
  22 #include "wx/cursor.h" 
  23 #include "wx/treectrl.h" 
  24 #include "wx/listctrl.h" 
  26 // If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage 
  27 #define wxUSE_SIMPLER_DRAGIMAGE 0 
  30   To use this class, create a wxDragImage when you start dragging, for example: 
  32   void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event) 
  35     ::UpdateWindow((HWND) GetHWND()); // We need to implement this in wxWindows 
  40     m_dragImage = new wxDragImage(* this, itemId); 
  41     m_dragImage->BeginDrag(wxPoint(0, 0), this); 
  42     m_dragImage->Move(pt, this); 
  43     m_dragImage->Show(this); 
  47   In your OnMouseMove function, hide the image, do any display updating required, 
  48   then move and show the image again: 
  50   void MyTreeCtrl::OnMouseMove(wxMouseEvent& event) 
  52     if (m_dragMode == MY_TREE_DRAG_NONE) 
  58     // Prevent screen corruption by hiding the image 
  60         m_dragImage->Hide(this); 
  62     // Do some updating of the window, such as highlighting the drop target 
  67         ::UpdateWindow((HWND) GetHWND()); 
  70     // Move and show the image again 
  71     m_dragImage->Move(event.GetPosition(), this); 
  72     m_dragImage->Show(this); 
  75  Eventually we end the drag and delete the drag image. 
  77  void MyTreeCtrl::OnLeftUp(wxMouseEvent& event) 
  81     // End the drag and delete the drag image 
  84         m_dragImage->EndDrag(this); 
  93  Notes for Unix version: 
  94  Can we simply use cursors instead, creating a cursor dynamically, setting it into the window 
  95  in BeginDrag, and restoring the old cursor in EndDrag? 
  96  For a really bog-standard implementation, we could simply use a normal dragging cursor 
 104 class WXDLLEXPORT wxDragImage
: public wxObject
 
 109     //////////////////////////////////////////////////////////////////////////// 
 112     wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor 
= wxNullCursor
) 
 116         Create(image
, cursor
); 
 119     // Deprecated form of the above 
 120     wxDragImage(const wxBitmap
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
) 
 124         Create(image
, cursor
, cursorHotspot
); 
 127     wxDragImage(const wxIcon
& image
, const wxCursor
& cursor 
= wxNullCursor
) 
 131         Create(image
, cursor
); 
 134     // Deprecated form of the above 
 135     wxDragImage(const wxIcon
& image
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
) 
 139         Create(image
, cursor
, cursorHotspot
); 
 142     wxDragImage(const wxString
& str
, const wxCursor
& cursor 
= wxNullCursor
) 
 149     // Deprecated form of the above 
 150     wxDragImage(const wxString
& str
, const wxCursor
& cursor
, const wxPoint
& cursorHotspot
) 
 154         Create(str
, cursor
, cursorHotspot
); 
 158     wxDragImage(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
) 
 162         Create(treeCtrl
, id
); 
 167     wxDragImage(const wxListCtrl
& listCtrl
, long id
) 
 171         Create(listCtrl
, id
); 
 178     //////////////////////////////////////////////////////////////////////////// 
 181     //////////////////////////////////////////////////////////////////////////// 
 183     // Create a drag image from a bitmap and optional cursor 
 184     bool Create(const wxBitmap
& image
, const wxCursor
& cursor 
= wxNullCursor
); 
 185     bool Create(const wxBitmap
& image
, const wxCursor
& cursor
, const wxPoint
& WXUNUSED(cursorHotspot
)) 
 187         wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument.")); 
 188         return Create(image
, cursor
); 
 191     // Create a drag image from an icon and optional cursor 
 192     bool Create(const wxIcon
& image
, const wxCursor
& cursor 
= wxNullCursor
); 
 193     bool Create(const wxIcon
& image
, const wxCursor
& cursor
, const wxPoint
& WXUNUSED(cursorHotspot
)) 
 195         wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument.")); 
 196         return Create(image
, cursor
); 
 199     // Create a drag image from a string and optional cursor 
 200     bool Create(const wxString
& str
, const wxCursor
& cursor 
= wxNullCursor
); 
 201     bool Create(const wxString
& str
, const wxCursor
& cursor
, const wxPoint
& WXUNUSED(cursorHotspot
)) 
 203         wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument.")); 
 204         return Create(str
, cursor
); 
 208     // Create a drag image for the given tree control item 
 209     bool Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
); 
 213     // Create a drag image for the given list control item 
 214     bool Create(const wxListCtrl
& listCtrl
, long id
); 
 217     // Begin drag. hotspot is the location of the drag position relative to the upper-left 
 218     // corner of the image. 
 219     bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
, bool fullScreen 
= FALSE
, wxRect
* rect 
= (wxRect
*) NULL
); 
 221     // Begin drag. hotspot is the location of the drag position relative to the upper-left 
 222     // corner of the image. This is full screen only. fullScreenRect gives the 
 223     // position of the window on the screen, to restrict the drag to. 
 224     bool BeginDrag(const wxPoint
& hotspot
, wxWindow
* window
, wxWindow
* fullScreenRect
); 
 229     // Move the image: call from OnMouseMove. Pt is in window client coordinates if window 
 230     // is non-NULL, or in screen coordinates if NULL. 
 231     bool Move(const wxPoint
& pt
); 
 240     //////////////////////////////////////////////////////////////////////////// 
 242     // Initialize variables 
 245     // Returns the native image list handle 
 246     WXHIMAGELIST 
GetHIMAGELIST() const { return m_hImageList
; } 
 248 #if !wxUSE_SIMPLER_DRAGIMAGE 
 249     // Returns the native image list handle for the cursor 
 250     WXHIMAGELIST 
GetCursorHIMAGELIST() const { return m_hCursorImageList
; } 
 254     WXHIMAGELIST    m_hImageList
; 
 256 #if wxUSE_SIMPLER_DRAGIMAGE 
 257     wxCursor        m_oldCursor
; 
 259     WXHIMAGELIST    m_hCursorImageList
; 
 263 //    wxPoint         m_cursorHotspot; // Obsolete 
 266     wxRect          m_boundingRect
; 
 270     DECLARE_DYNAMIC_CLASS(wxDragImage
) 
 271     DECLARE_NO_COPY_CLASS(wxDragImage
)