#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:
////////////////////////////////////////////////////////////////////////////
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)
{
////////////////////////////////////////////////////////////////////////////
// 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);
// 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;
// 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"
// 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;
}
{
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;
}
////////////////////////////////////////////////////////////////////////////
// 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());
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());
}
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));
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
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);
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));
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;
{
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;