]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented Chuck Messenger's naming and simplification improvements,
authorJulian Smart <julian@anthemion.co.uk>
Tue, 10 Apr 2001 13:44:03 +0000 (13:44 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 10 Apr 2001 13:44:03 +0000 (13:44 +0000)
plus Move coordinate correction

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9701 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/dragimag.h
samples/dragimag/dragimag.cpp
src/msw/dragimag.cpp

index 12281325144399218733d94a1ad26cf9726d20fc..f4a469088ed45a140bb35915a4c1d7b2d2772c6c 100644 (file)
 #include "wx/treectrl.h"
 #include "wx/listctrl.h"
 
+// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage,
+// and some other simplifications
+#define wxUSE_SIMPLER_DRAGIMAGE 1
+
 /*
   To use this class, create a wxDragImage when you start dragging, for example:
 
@@ -106,23 +110,23 @@ public:
     ////////////////////////////////////////////////////////////////////////////
 
     wxDragImage();
-    wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+    wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
     {
         Init();
 
-        Create(image, cursor, hotspot);
+        Create(image, cursor, cursorHotspot);
     }
-    wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+    wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
     {
         Init();
 
-        Create(image, cursor, hotspot);
+        Create(image, cursor, cursorHotspot);
     }
-    wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+    wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
     {
         Init();
 
-        Create(str, cursor, hotspot);
+        Create(str, cursor, cursorHotspot);
     }
     wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
     {
@@ -145,13 +149,13 @@ public:
     ////////////////////////////////////////////////////////////////////////////
 
     // Create a drag image from a bitmap and optional cursor
-    bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
+    bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
 
     // Create a drag image from an icon and optional cursor
-    bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
+    bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
 
     // Create a drag image from a string and optional cursor
-    bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
+    bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
 
     // Create a drag image for the given tree control item
     bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
@@ -190,14 +194,22 @@ public:
     // Returns the native image list handle
     WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
 
+#if !wxUSE_SIMPLER_DRAGIMAGE
     // Returns the native image list handle for the cursor
     WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
+#endif
 
 protected:
     WXHIMAGELIST    m_hImageList;
+
+#if wxUSE_SIMPLER_DRAGIMAGE
+    wxCursor        m_oldCursor;
+#else
     WXHIMAGELIST    m_hCursorImageList;
+#endif
+
     wxCursor        m_cursor;
-    wxPoint         m_hotspot;
+    wxPoint         m_cursorHotspot;
     wxPoint         m_position;
     wxWindow*       m_window;
     wxRect          m_boundingRect;
index 208dae675ed615ed9d0a650514e04b23297e7875..f3b41863460c217129178e0050c93b6d02b06cde 100644 (file)
@@ -25,7 +25,7 @@
 // Under Windows, change this to 1
 // to use wxGenericDragImage
 
-#define wxUSE_GENERIC_DRAGIMAGE 1
+#define wxUSE_GENERIC_DRAGIMAGE 0
 
 #if wxUSE_GENERIC_DRAGIMAGE
 #include "wx/generic/dragimgg.h"
@@ -201,11 +201,11 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
                     // Can anyone explain why this test is necessary,
                     // to prevent a gcc error?
 #ifdef __WXMOTIF__
-                   wxIcon icon(dragicon_xpm);
+                    wxIcon icon(dragicon_xpm);
 #else
-                   wxIcon icon(wxICON(dragicon));
+                    wxIcon icon(wxICON(dragicon));
 #endif
-
+                    
                     m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND), hotSpot);
                     break;
                 }
index d60e69d88554fc1afa5a27b8e79d905e5e3b0f55..acffef371a5117d4714c776e494198ba9aa099e8 100644 (file)
@@ -78,14 +78,18 @@ wxDragImage::~wxDragImage()
 {
     if ( m_hImageList )
         ImageList_Destroy(GetHimageList());
+#if !wxUSE_SIMPLER_DRAGIMAGE
     if ( m_hCursorImageList )
         ImageList_Destroy((HIMAGELIST) m_hCursorImageList);
+#endif
 }
 
 void wxDragImage::Init()
 {
     m_hImageList = 0;
+#if !wxUSE_SIMPLER_DRAGIMAGE
     m_hCursorImageList = 0;
+#endif
     m_window = (wxWindow*) NULL;
     m_fullScreen = FALSE;
 }
@@ -98,7 +102,7 @@ void wxDragImage::Init()
 ////////////////////////////////////////////////////////////////////////////
 
 // Create a drag image from a bitmap and optional cursor
-bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
 {
     if ( m_hImageList )
         ImageList_Destroy(GetHimageList());
@@ -142,13 +146,13 @@ bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wx
         wxLogError(_("Couldn't add an image to the image list."));
     }
     m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
-    m_hotspot = hotspot;
+    m_cursorHotspot = cursorHotspot;
 
     return (index != -1) ;
 }
 
 // Create a drag image from an icon and optional cursor
-bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
 {
     if ( m_hImageList )
         ImageList_Destroy(GetHimageList());
@@ -180,13 +184,13 @@ bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPo
     }
 
     m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
-    m_hotspot = hotspot;
+    m_cursorHotspot = cursorHotspot;
 
     return (index != -1) ;
 }
 
 // Create a drag image from a string and optional cursor
-bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
 {
     wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
 
@@ -222,7 +226,7 @@ bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPo
     image.SetMaskColour(255, 255, 255);
     bitmap = image.ConvertToBitmap();
 
-    return Create(bitmap, cursor, hotspot);
+    return Create(bitmap, cursor, cursorHotspot);
 }
 
 // Create a drag image for the given tree control item
@@ -266,6 +270,10 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
 
     if (m_cursor.Ok())
     {
+#if wxUSE_SIMPLER_DRAGIMAGE
+           m_oldCursor = window->GetCursor();
+           window->SetCursor(m_cursor);
+#else
         if (!m_hCursorImageList)
         {           
             int cxCursor = GetSystemMetrics(SM_CXCURSOR); 
@@ -282,12 +290,17 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
 
         if (cursorIndex != -1)
         {
-            ImageList_SetDragCursorImage((HIMAGELIST) m_hCursorImageList, cursorIndex, m_hotspot.x, m_hotspot.y);
+            ImageList_SetDragCursorImage((HIMAGELIST) m_hCursorImageList, cursorIndex, m_cursorHotspot.x, m_cursorHotspot.y);
         }
+#endif
     }
 
     m_window = window;
-    ::ShowCursor(FALSE);
+
+#if !wxUSE_SIMPLER_DRAGIMAGE
+    if (m_cursor.Ok())
+        ::ShowCursor(FALSE);
+#endif
 
     ::SetCapture(GetHwndOf(window));
 
@@ -327,7 +340,13 @@ bool wxDragImage::EndDrag()
         wxLogLastError(wxT("ReleaseCapture"));
     }
 
+#if wxUSE_SIMPLER_DRAGIMAGE
+    if (m_cursor.Ok() && m_oldCursor.Ok())
+           m_window->SetCursor(m_oldCursor);
+#else
     ::ShowCursor(TRUE);
+#endif
+
     m_window = (wxWindow*) NULL;
 
     return TRUE;
@@ -339,8 +358,26 @@ bool wxDragImage::Move(const wxPoint& pt)
 {
     wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in Move."));
 
-    // TODO: what coordinates are these in: window, client, or screen?
-    bool ret = (ImageList_DragMove( pt.x, pt.y ) != 0);
+    // These are in window, not client coordinates.
+    // So need to convert to client coordinates.
+    wxPoint pt2(pt);
+    if (m_window)
+    {
+        RECT rect;
+        rect.left = 0; rect.top = 0;
+        rect.right = 0; rect.bottom = 0;
+        DWORD style = ::GetWindowLong((HWND) m_window->GetHWND(), GWL_STYLE);
+#ifdef __WIN32__
+        DWORD exStyle = ::GetWindowLong((HWND) m_window->GetHWND(), GWL_EXSTYLE);
+        ::AdjustWindowRectEx(& rect, style, FALSE, exStyle);
+#else
+        ::AdjustWindowRect(& rect, style, FALSE);
+#endif
+        // Subtract the (negative) values, i.e. add a small increment
+        pt2.x -= rect.left; pt2.y -= rect.top;
+    }
+
+    bool ret = (ImageList_DragMove( pt2.x, pt2.y ) != 0);
 
     m_position = pt;