\docparam{cursor}{Optional cursor to combine with the image.}
-\docparam{hotspot}{Optional position of the hotspot in the given cursor. This parameter is deprecated.}
+\docparam{hotspot}{This parameter is deprecated.}
\docparam{treeCtrl}{Tree control for constructing a tree drag image.}
\helpref{wxDragImage::Show}{wxdragimageshow} has been called previously (for example
at the start of the drag).
-{\it pt} is the position in window coordinates (or screen coordinates if no
-window was specified to BeginDrag.
+{\it pt} is the position in client coordinates (relative to the window specified in BeginDrag).
You can move the image either when the image is hidden or shown, but in general dragging
will be smoother if you move the image when it is shown.
// Ctors & dtor
////////////////////////////////////////////////////////////////////////////
- wxGenericDragImage(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+ wxGenericDragImage(const wxCursor& cursor = wxNullCursor)
{
Init();
- Create(cursor, hotspot);
+ Create(cursor);
}
- wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+
+ // Deprecated version of the above
+ wxGenericDragImage(const wxCursor& cursor, const wxPoint& cursorHotspot)
+ {
+ Init();
+ Create(cursor, cursorHotspot);
+ }
+
+ wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
+ {
+ Init();
+
+ Create(image, cursor);
+ }
+
+ // Deprecated version of the above
+ wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
+ {
+ Init();
+
+ Create(image, cursor, cursorHotspot);
+ }
+
+ wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
+ {
+ Init();
+
+ Create(image, cursor);
+ }
+
+ // Deprecated version of the above
+ wxGenericDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
{
Init();
- Create(image, cursor, hotspot);
+ Create(image, cursor, cursorHotspot);
}
- wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+
+ wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
{
Init();
- Create(image, cursor, hotspot);
+ Create(str, cursor);
}
- wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
+
+ // Deprecated version of the above
+ wxGenericDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
{
Init();
- Create(str, cursor, hotspot);
+ Create(str, cursor, cursorHotspot);
}
+
wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
{
Init();
Create(treeCtrl, id);
}
+
wxGenericDragImage(const wxListCtrl& listCtrl, long id)
{
Init();
////////////////////////////////////////////////////////////////////////////
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
- bool Create(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0));
+ bool Create(const wxCursor& cursor = wxNullCursor);
+ bool Create(const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(cursor);
+ }
// 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);
+ bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(image, cursor);
+ }
// 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);
+ bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(image, cursor);
+ }
// 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);
+ bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(str, cursor);
+ }
// Create a drag image for the given tree control item
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
wxIcon m_icon;
wxCursor m_cursor;
wxCursor m_oldCursor;
- wxPoint m_hotspot;
+// wxPoint m_hotspot;
wxPoint m_offset; // The hostpot value passed to BeginDrag
wxPoint m_position;
bool m_isDirty;
#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
+// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
+#define wxUSE_SIMPLER_DRAGIMAGE 0
/*
To use this class, create a wxDragImage when you start dragging, for example:
////////////////////////////////////////////////////////////////////////////
wxDragImage();
- wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
+ wxDragImage(const wxBitmap& image, const wxCursor& cursor = wxNullCursor)
+ {
+ Init();
+
+ Create(image, cursor);
+ }
+
+ // Deprecated form of the above
+ wxDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
{
Init();
Create(image, cursor, cursorHotspot);
}
- wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
+
+ wxDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
+ {
+ Init();
+
+ Create(image, cursor);
+ }
+
+ // Deprecated form of the above
+ wxDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
{
Init();
Create(image, cursor, cursorHotspot);
}
- wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0))
+
+ wxDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
+ {
+ Init();
+
+ Create(str, cursor);
+ }
+
+ // Deprecated form of the above
+ wxDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
{
Init();
Create(str, cursor, cursorHotspot);
}
+
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
{
Init();
Create(treeCtrl, id);
}
+
wxDragImage(const wxListCtrl& listCtrl, long id)
{
Init();
Create(listCtrl, id);
}
+
~wxDragImage();
// Attributes
////////////////////////////////////////////////////////////////////////////
// Create a drag image from a bitmap and optional cursor
- bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
+ bool Create(const wxBitmap& image, const wxCursor& cursor = wxNullCursor);
+ bool Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(image, cursor);
+ }
// Create a drag image from an icon and optional cursor
- bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
+ bool Create(const wxIcon& image, const wxCursor& cursor = wxNullCursor);
+ bool Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(image, cursor);
+ }
// Create a drag image from a string and optional cursor
- bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& cursorHotspot = wxPoint(0, 0));
+ bool Create(const wxString& str, const wxCursor& cursor = wxNullCursor);
+ bool Create(const wxString& str, const wxCursor& cursor, const wxPoint& WXUNUSED(cursorHotspot))
+ {
+ wxLogDebug(wxT("wxDragImage::Create: use of a cursor hotspot is now deprecated. Please omit this argument."));
+ return Create(str, cursor);
+ }
// Create a drag image for the given tree control item
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
#endif
wxCursor m_cursor;
- wxPoint m_cursorHotspot;
+// wxPoint m_cursorHotspot; // Obsolete
wxPoint m_position;
wxWindow* m_window;
wxRect m_boundingRect;
// Under Windows, change this to 1
// to use wxGenericDragImage
-#define wxUSE_GENERIC_DRAGIMAGE 0
+#define wxUSE_GENERIC_DRAGIMAGE 1
#if wxUSE_GENERIC_DRAGIMAGE
#include "wx/generic/dragimgg.h"
if (!m_draggedShape || !m_dragImage)
return;
- wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x),
- m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y));
-
- m_draggedShape->SetPosition(newPos);
+ m_draggedShape->SetPosition(m_draggedShape->GetPosition()
+ + event.GetPosition() - m_dragStartPos);
m_dragImage->Hide();
m_dragImage->EndDrag();
if (dx <= tolerance && dy <= tolerance)
return;
- wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x),
- m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y));
-
// Start the drag.
m_dragMode = TEST_DRAG_DRAGGING;
{
case SHAPE_DRAG_BITMAP:
{
- wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y);
- m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND), hotSpot);
+ m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND));
break;
}
case SHAPE_DRAG_TEXT:
{
- wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y);
- m_dragImage = new wxDragImage("Dragging some test text", wxCursor(wxCURSOR_HAND), hotSpot);
+ m_dragImage = new wxDragImage("Dragging some test text", wxCursor(wxCURSOR_HAND));
break;
}
case SHAPE_DRAG_ICON:
{
- wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y);
-
// Can anyone explain why this test is necessary,
// to prevent a gcc error?
#ifdef __WXMOTIF__
wxIcon icon(wxICON(dragicon));
#endif
- m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND), hotSpot);
+ m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND));
break;
}
}
- bool fullScreen = FALSE;
- if (wxGetApp().GetUseScreen())
- {
- newPos = ClientToScreen(newPos);
- fullScreen = TRUE;
- }
-
- bool retValue;
+ bool fullScreen = wxGetApp().GetUseScreen();
- if (fullScreen)
- // This line uses the whole screen...
- retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, TRUE);
- // while this line restricts dragging to the parent frame.
- // retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, GetParent());
- else
- retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this);
+ // The offset between the top-left of the shape image and the current shape position
+ wxPoint beginDragHotSpot = m_dragStartPos - m_draggedShape->GetPosition();
+
+ // Now we do this inside the implementation: always assume
+ // coordinates relative to the capture window (client coordinates)
- if (!retValue)
+ //if (fullScreen)
+ // beginDragHotSpot -= ClientToScreen(wxPoint(0, 0));
+
+ if (!m_dragImage->BeginDrag(beginDragHotSpot, this, fullScreen))
{
delete m_dragImage;
m_dragImage = (wxDragImage*) NULL;
m_dragMode = TEST_DRAG_NONE;
+
+ } else
+ {
+ m_dragImage->Move(event.GetPosition());
+ m_dragImage->Show();
}
- m_dragImage->Move(newPos);
- m_dragImage->Show();
}
else if (m_dragMode == TEST_DRAG_DRAGGING)
{
m_currentlyHighlighted->Draw(clientDC, wxINVERT);
}
- wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x),
- m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y));
-
- if (wxGetApp().GetUseScreen())
- {
- newPos = ClientToScreen(newPos);
- }
-
// Move and show the image again
- m_dragImage->Move(newPos);
+ m_dragImage->Move(event.GetPosition());
if (mustUnhighlightOld || mustHighlightNew)
m_dragImage->Show();
////////////////////////////////////////////////////////////////////////////
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
-bool wxGenericDragImage::Create(const wxCursor& cursor, const wxPoint& hotspot)
+bool wxGenericDragImage::Create(const wxCursor& cursor)
{
m_cursor = cursor;
- m_hotspot = hotspot;
return TRUE;
}
// Create a drag image from a bitmap and optional cursor
-bool wxGenericDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxGenericDragImage::Create(const wxBitmap& image, const wxCursor& cursor)
{
// We don't have to combine the cursor explicitly since we simply show the cursor
// as we drag. This currently will only work within one window.
m_cursor = cursor;
- m_hotspot = hotspot;
m_bitmap = image;
return TRUE ;
}
// Create a drag image from an icon and optional cursor
-bool wxGenericDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxGenericDragImage::Create(const wxIcon& image, const wxCursor& cursor)
{
// We don't have to combine the cursor explicitly since we simply show the cursor
// as we drag. This currently will only work within one window.
m_cursor = cursor;
- m_hotspot = hotspot;
m_icon = image;
return TRUE ;
}
// Create a drag image from a string and optional cursor
-bool wxGenericDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPoint& hotspot)
+bool wxGenericDragImage::Create(const wxString& str, const wxCursor& cursor)
{
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
bitmap = image.ConvertToBitmap();
#endif
- return Create(bitmap, cursor, hotspot);
+ return Create(bitmap, cursor);
}
// Create a drag image for the given tree control item
{
wxASSERT_MSG( (m_windowDC != (wxDC*) NULL), wxT("No window DC in wxGenericDragImage::Move()") );
+ wxPoint pt2(pt);
+ if (m_fullScreen)
+ pt2 = m_window->ClientToScreen(pt);
+
// Erase at old position, then show at the current position
wxPoint oldPos = m_position;
bool eraseOldImage = (m_isDirty && m_isShown);
if (m_isShown)
- RedrawImage(oldPos - m_offset, pt - m_offset, eraseOldImage, TRUE);
+ RedrawImage(oldPos - m_offset, pt2 - m_offset, eraseOldImage, TRUE);
- m_position = pt;
+ m_position = pt2;
if (m_isShown)
m_isDirty = TRUE;
////////////////////////////////////////////////////////////////////////////
// Create a drag image from a bitmap and optional cursor
-bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
+bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor)
{
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_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& cursorHotspot)
+bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor)
{
if ( m_hImageList )
ImageList_Destroy(GetHimageList());
}
m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
- 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& cursorHotspot)
+bool wxDragImage::Create(const wxString& str, const wxCursor& cursor)
{
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
image.SetMaskColour(255, 255, 255);
bitmap = image.ConvertToBitmap();
- return Create(bitmap, cursor, cursorHotspot);
+ return Create(bitmap, cursor);
}
// Create a drag image for the given tree control item
m_boundingRect = * rect;
bool ret = (ImageList_BeginDrag(GetHimageList(), 0, hotspot.x, hotspot.y) != 0);
+ //bool ret = (ImageList_BeginDrag(GetHimageList(), 0, 0, 0) != 0);
if (!ret)
{
m_hCursorImageList = (WXHIMAGELIST) ImageList_Create(cxCursor, cyCursor, ILC_MASK, 1, 1);
}
+ // See if we can find the cursor hotspot
+ wxPoint curHotSpot(hotspot);
+
+#if 0
+ ICONINFO iconInfo;
+ if (::GetIconInfo((HICON) (HCURSOR) m_cursor.GetHCURSOR(), & iconInfo) != 0)
+ {
+ curHotSpot.x -= iconInfo.xHotspot;
+ curHotSpot.y -= iconInfo.yHotspot;
+ }
+#endif
+ wxString msg;
+ msg.Printf("Hotspot = %d, %d", curHotSpot.x, curHotSpot.y);
+ wxLogDebug(msg);
+
// First add the cursor to the image list
HCURSOR hCursor = (HCURSOR) m_cursor.GetHCURSOR();
int cursorIndex = ImageList_AddIcon((HIMAGELIST) m_hCursorImageList, (HICON) hCursor);
if (cursorIndex != -1)
{
- ImageList_SetDragCursorImage((HIMAGELIST) m_hCursorImageList, cursorIndex, m_cursorHotspot.x, m_cursorHotspot.y);
+ ImageList_SetDragCursorImage((HIMAGELIST) m_hCursorImageList, cursorIndex, curHotSpot.x, curHotSpot.y);
}
#endif
}
- m_window = window;
-
#if !wxUSE_SIMPLER_DRAGIMAGE
if (m_cursor.Ok())
::ShowCursor(FALSE);
#endif
+ m_window = window;
+
::SetCapture(GetHwndOf(window));
return TRUE;
// Subtract the (negative) values, i.e. add a small increment
pt2.x -= rect.left; pt2.y -= rect.top;
}
+ else if (m_window && m_fullScreen)
+ {
+ pt2 = m_window->ClientToScreen(pt2);
+ }
bool ret = (ImageList_DragMove( pt2.x, pt2.y ) != 0);