]> git.saurik.com Git - wxWidgets.git/commitdiff
wxDropSource now has 3 custom cursors for copy/move/nothing
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 1999 19:34:11 +0000 (19:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 1999 19:34:11 +0000 (19:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dnd.h
include/wx/msw/ole/dropsrc.h
samples/dnd/dnd.cpp
src/msw/ole/dropsrc.cpp

index 5ba516ade525f6705fb28621e3aeed174cbade9b..0d113904ec00d431dd801c97b3a77866d54e7922 100644 (file)
@@ -45,7 +45,13 @@ inline WXDLLEXPORT bool wxIsDragResultOk(wxDragResult res)
 class WXDLLEXPORT wxDropSourceBase
 {
 public:
-    wxDropSourceBase() { m_data = (wxDataObject *)NULL; }
+    wxDropSourceBase(const wxCursor &cursorCopy = wxNullCursor,
+                     const wxCursor &cursorMove = wxNullCursor,
+                     const wxCursor &cursorStop = wxNullCursor)
+        : m_cursorCopy(cursorCopy),
+          m_cursorMove(cursorMove),
+          m_cursorStop(cursorStop)
+        { m_data = (wxDataObject *)NULL; }
     virtual ~wxDropSourceBase() { }
 
     // set the data which is transfered by drag and drop
@@ -55,21 +61,42 @@ public:
     wxDataObject *GetDataObject()
       { return m_data; }
 
+    // set the icon corresponding to given drag result
+    void SetCursor(wxDragResult res, const wxCursor& cursor)
+    {
+        if ( res == wxDragCopy )
+            m_cursorCopy = cursor;
+        else if ( res == wxDragMove )
+            m_cursorMove = cursor;
+        else
+            m_cursorStop = cursor;
+    }
+
     // start drag action, see enum wxDragResult for return value description
     //
     // if bAllowMove is TRUE, data can be moved, if not - only copied
     virtual wxDragResult DoDragDrop(bool bAllowMove = FALSE) = 0;
 
     // override to give feedback depending on the current operation result
-    // "effect"
-    virtual bool GiveFeedback( wxDragResult WXUNUSED(effect),
-                               bool WXUNUSED(bScrolling) )
+    // "effect" and return TRUE if you did something, FALSE to let the library
+    // give the default feedback
+    virtual bool GiveFeedback(wxDragResult WXUNUSED(effect)) { return FALSE; }
+
+protected:
+    const wxCursor& GetCursor(wxDragResult res) const
     {
-        return TRUE;
+        if ( res == wxDragCopy )
+            return m_cursorCopy;
+        else if ( res == wxDragMove )
+            return m_cursorMove;
+        else
+            return m_cursorStop;
     }
 
-protected:
     wxDataObject *m_data;
+
+    // the cursors to use for feedback
+    wxCursor      m_cursorCopy, m_cursorMove, m_cursorStop;
 };
 
 // ----------------------------------------------------------------------------
index 36badcc6a12c0719892943043c603a77d58023f1..079514324b7b0dffa6ed14bac4b1385e037e8ea2 100644 (file)
@@ -41,12 +41,14 @@ public:
     // NB: the "wxWindow *win" parameter is unused and is here only for wxGTK
     //     compatibility, as well as both icon parameters
     wxDropSource(wxWindow *win = NULL,
-            const wxIcon &go = wxNullIcon,
-            const wxIcon &stop = wxNullIcon );
+                 const wxCursor &cursorCopy = wxNullCursor,
+                 const wxCursor &cursorMove = wxNullCursor,
+                 const wxCursor &cursorStop = wxNullCursor);
     wxDropSource(wxDataObject& data,
-            wxWindow *win = NULL,
-            const wxIcon &go = wxNullIcon,
-            const wxIcon &stop = wxNullIcon );
+                 wxWindow *win = NULL,
+                 const wxCursor &cursorCopy = wxNullCursor,
+                 const wxCursor &cursorMove = wxNullCursor,
+                 const wxCursor &cursorStop = wxNullCursor);
 
     virtual ~wxDropSource();
 
@@ -57,7 +59,7 @@ public:
     // overridable: you may give some custom UI feedback during d&d operation
     // in this function (it's called on each mouse move, so it shouldn't be
     // too slow). Just return false if you want default feedback.
-    virtual bool GiveFeedback(wxDragResult effect, bool bScrolling);
+    virtual bool GiveFeedback(wxDragResult effect);
 
 protected:
     void Init();
index aadb950d73633199cff6444da612df5e6971c0bb..7b1cc72b94999d5122c65a1ed5f952be739ca280 100644 (file)
@@ -871,7 +871,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
     {
         // start drag operation
         wxTextDataObject textData(m_strText);
-        wxDropSource source(textData, this, wxICON(mondrian));
+        wxDropSource source(textData, this,
+                            wxCURSOR_PENCIL,            // for copy
+                            wxCURSOR_SPRAYCAN,          // for move
+                            wxCURSOR_QUESTION_ARROW);   // for nothing
 
         const char *pc;
 
@@ -1253,7 +1256,7 @@ void DnDShapeFrame::OnDrag(wxMouseEvent& event)
 
     // start drag operation
     DnDShapeDataObject shapeData(m_shape);
-    wxDropSource source(shapeData, this, wxICON(mondrian));
+    wxDropSource source(shapeData, this);
 
     const char *pc = NULL;
     switch ( source.DoDragDrop(TRUE) )
index 3ddecc92ea70d20bf2748a4c0dcc61734428a48c..e71864e064d9aa98b0a194979b3f9501eb11582e 100644 (file)
@@ -140,8 +140,7 @@ STDMETHODIMP wxIDropSource::GiveFeedback(DWORD dwEffect)
   else
     effect = wxDragNone;
 
-  if ( m_pDropSource->GiveFeedback(effect,
-                                   (dwEffect & DROPEFFECT_SCROLL) != 0 ) )
+  if ( m_pDropSource->GiveFeedback(effect) )
     return S_OK;
 
   return DRAGDROP_S_USEDEFAULTCURSORS;
@@ -156,29 +155,33 @@ STDMETHODIMP wxIDropSource::GiveFeedback(DWORD dwEffect)
 // common part of all ctors
 void wxDropSource::Init()
 {
-  m_pIDropSource = new wxIDropSource(this);
-  m_pIDropSource->AddRef();
+    m_pIDropSource = new wxIDropSource(this);
+    m_pIDropSource->AddRef();
 }
 
 wxDropSource::wxDropSource(wxWindow* WXUNUSED(win),
-                           const wxIcon & WXUNUSED(go),
-                           const wxIcon & WXUNUSED(stop))
+                           const wxCursor &cursorCopy,
+                           const wxCursor &cursorMove,
+                           const wxCursor &cursorStop)
+            : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
 {
-  Init();
+    Init();
 }
 
 wxDropSource::wxDropSource(wxDataObject& data,
                            wxWindow* WXUNUSED(win),
-                           const wxIcon & WXUNUSED(go),
-                           const wxIcon & WXUNUSED(stop))
+                           const wxCursor &cursorCopy,
+                           const wxCursor &cursorMove,
+                           const wxCursor &cursorStop)
+            : wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
 {
-  Init();
-  SetData(data);
+    Init();
+    SetData(data);
 }
 
 wxDropSource::~wxDropSource()
 {
-  m_pIDropSource->Release();
+    m_pIDropSource->Release();
 }
 
 // Name    : DoDragDrop
@@ -223,7 +226,8 @@ wxDragResult wxDropSource::DoDragDrop(bool bAllowMove)
       wxLogError(wxT("Drag & drop operation failed."));
     }
     else {
-      wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."), hr);
+      wxLogDebug(wxT("Unexpected success return code %08lx from DoDragDrop."),
+                 hr);
     }
 
     return wxDragError;
@@ -234,11 +238,20 @@ wxDragResult wxDropSource::DoDragDrop(bool bAllowMove)
 // Purpose : visually inform the user about d&d operation state
 // Returns : bool: true if we do all ourselves or false for default feedback
 // Params  : [in] DragResult effect - what would happen if we dropped now
-//           [in] bool bScrolling   - true if target is scrolling
 // Notes   : here we just leave this stuff for default implementation
-bool wxDropSource::GiveFeedback(wxDragResult effect, bool bScrolling)
+bool wxDropSource::GiveFeedback(wxDragResult effect)
 {
-  return FALSE;
+    const wxCursor& cursor = GetCursor(effect);
+    if ( cursor.Ok() )
+    {
+        ::SetCursor((HCURSOR)cursor.GetHCURSOR());
+
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 #endif  //USE_DRAG_AND_DROP