Fixed some wxDragImage bugs
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9711 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -92,7 +92,7 @@ have a mask.}
|
|||||||
|
|
||||||
\docparam{cursor}{Optional cursor to combine with the image.}
|
\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.}
|
\docparam{treeCtrl}{Tree control for constructing a tree drag image.}
|
||||||
|
|
||||||
@@ -183,8 +183,7 @@ Call this to move the image to a new position. The image will only be shown if
|
|||||||
\helpref{wxDragImage::Show}{wxdragimageshow} has been called previously (for example
|
\helpref{wxDragImage::Show}{wxdragimageshow} has been called previously (for example
|
||||||
at the start of the drag).
|
at the start of the drag).
|
||||||
|
|
||||||
{\it pt} is the position in window coordinates (or screen coordinates if no
|
{\it pt} is the position in client coordinates (relative to the window specified in BeginDrag).
|
||||||
window was specified to BeginDrag.
|
|
||||||
|
|
||||||
You can move the image either when the image is hidden or shown, but in general dragging
|
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.
|
will be smoother if you move the image when it is shown.
|
||||||
|
@@ -97,35 +97,71 @@ public:
|
|||||||
// Ctors & dtor
|
// Ctors & dtor
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
wxGenericDragImage(const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
|
wxGenericDragImage(const wxCursor& cursor = wxNullCursor)
|
||||||
{
|
{
|
||||||
Init();
|
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();
|
Init();
|
||||||
|
|
||||||
Create(image, cursor, hotspot);
|
Create(image, cursor);
|
||||||
}
|
}
|
||||||
wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
|
|
||||||
|
// Deprecated version of the above
|
||||||
|
wxGenericDragImage(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
Create(image, cursor, hotspot);
|
Create(image, cursor, cursorHotspot);
|
||||||
}
|
}
|
||||||
wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor, const wxPoint& hotspot = wxPoint(0, 0))
|
|
||||||
|
wxGenericDragImage(const wxIcon& image, const wxCursor& cursor = wxNullCursor)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
Create(str, cursor, hotspot);
|
Create(image, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated version of the above
|
||||||
|
wxGenericDragImage(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(image, cursor, cursorHotspot);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGenericDragImage(const wxString& str, const wxCursor& cursor = wxNullCursor)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(str, cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated version of the above
|
||||||
|
wxGenericDragImage(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(str, cursor, cursorHotspot);
|
||||||
|
}
|
||||||
|
|
||||||
wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
|
wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
Create(treeCtrl, id);
|
Create(treeCtrl, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGenericDragImage(const wxListCtrl& listCtrl, long id)
|
wxGenericDragImage(const wxListCtrl& listCtrl, long id)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
@@ -145,16 +181,36 @@ public:
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
|
// 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
|
// 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
|
// 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
|
// 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
|
// Create a drag image for the given tree control item
|
||||||
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
|
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
|
||||||
@@ -211,7 +267,7 @@ protected:
|
|||||||
wxIcon m_icon;
|
wxIcon m_icon;
|
||||||
wxCursor m_cursor;
|
wxCursor m_cursor;
|
||||||
wxCursor m_oldCursor;
|
wxCursor m_oldCursor;
|
||||||
wxPoint m_hotspot;
|
// wxPoint m_hotspot;
|
||||||
wxPoint m_offset; // The hostpot value passed to BeginDrag
|
wxPoint m_offset; // The hostpot value passed to BeginDrag
|
||||||
wxPoint m_position;
|
wxPoint m_position;
|
||||||
bool m_isDirty;
|
bool m_isDirty;
|
||||||
|
@@ -23,9 +23,8 @@
|
|||||||
#include "wx/treectrl.h"
|
#include "wx/treectrl.h"
|
||||||
#include "wx/listctrl.h"
|
#include "wx/listctrl.h"
|
||||||
|
|
||||||
// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage,
|
// If 1, use a simple wxCursor instead of ImageList_SetDragCursorImage
|
||||||
// and some other simplifications
|
#define wxUSE_SIMPLER_DRAGIMAGE 0
|
||||||
#define wxUSE_SIMPLER_DRAGIMAGE 1
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
To use this class, create a wxDragImage when you start dragging, for example:
|
To use this class, create a wxDragImage when you start dragging, for example:
|
||||||
@@ -110,36 +109,65 @@ public:
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
wxDragImage();
|
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();
|
Init();
|
||||||
|
|
||||||
Create(image, cursor, cursorHotspot);
|
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();
|
Init();
|
||||||
|
|
||||||
Create(image, cursor, cursorHotspot);
|
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();
|
Init();
|
||||||
|
|
||||||
Create(str, cursor, cursorHotspot);
|
Create(str, cursor, cursorHotspot);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
|
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
Create(treeCtrl, id);
|
Create(treeCtrl, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDragImage(const wxListCtrl& listCtrl, long id)
|
wxDragImage(const wxListCtrl& listCtrl, long id)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
Create(listCtrl, id);
|
Create(listCtrl, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
~wxDragImage();
|
~wxDragImage();
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
@@ -149,13 +177,28 @@ public:
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Create a drag image from a bitmap and optional cursor
|
// 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
|
// 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
|
// 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
|
// Create a drag image for the given tree control item
|
||||||
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
|
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
|
||||||
@@ -209,7 +252,7 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxCursor m_cursor;
|
wxCursor m_cursor;
|
||||||
wxPoint m_cursorHotspot;
|
// wxPoint m_cursorHotspot; // Obsolete
|
||||||
wxPoint m_position;
|
wxPoint m_position;
|
||||||
wxWindow* m_window;
|
wxWindow* m_window;
|
||||||
wxRect m_boundingRect;
|
wxRect m_boundingRect;
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
// Under Windows, change this to 1
|
// Under Windows, change this to 1
|
||||||
// to use wxGenericDragImage
|
// to use wxGenericDragImage
|
||||||
|
|
||||||
#define wxUSE_GENERIC_DRAGIMAGE 0
|
#define wxUSE_GENERIC_DRAGIMAGE 1
|
||||||
|
|
||||||
#if wxUSE_GENERIC_DRAGIMAGE
|
#if wxUSE_GENERIC_DRAGIMAGE
|
||||||
#include "wx/generic/dragimgg.h"
|
#include "wx/generic/dragimgg.h"
|
||||||
@@ -131,10 +131,8 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
if (!m_draggedShape || !m_dragImage)
|
if (!m_draggedShape || !m_dragImage)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x),
|
m_draggedShape->SetPosition(m_draggedShape->GetPosition()
|
||||||
m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y));
|
+ event.GetPosition() - m_dragStartPos);
|
||||||
|
|
||||||
m_draggedShape->SetPosition(newPos);
|
|
||||||
|
|
||||||
m_dragImage->Hide();
|
m_dragImage->Hide();
|
||||||
m_dragImage->EndDrag();
|
m_dragImage->EndDrag();
|
||||||
@@ -165,9 +163,6 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
if (dx <= tolerance && dy <= tolerance)
|
if (dx <= tolerance && dy <= tolerance)
|
||||||
return;
|
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.
|
// Start the drag.
|
||||||
m_dragMode = TEST_DRAG_DRAGGING;
|
m_dragMode = TEST_DRAG_DRAGGING;
|
||||||
|
|
||||||
@@ -184,20 +179,16 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
{
|
{
|
||||||
case SHAPE_DRAG_BITMAP:
|
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));
|
||||||
m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND), hotSpot);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHAPE_DRAG_TEXT:
|
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));
|
||||||
m_dragImage = new wxDragImage("Dragging some test text", wxCursor(wxCURSOR_HAND), hotSpot);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHAPE_DRAG_ICON:
|
case SHAPE_DRAG_ICON:
|
||||||
{
|
{
|
||||||
wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y);
|
|
||||||
|
|
||||||
// Can anyone explain why this test is necessary,
|
// Can anyone explain why this test is necessary,
|
||||||
// to prevent a gcc error?
|
// to prevent a gcc error?
|
||||||
#ifdef __WXMOTIF__
|
#ifdef __WXMOTIF__
|
||||||
@@ -206,37 +197,34 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
wxIcon icon(wxICON(dragicon));
|
wxIcon icon(wxICON(dragicon));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND), hotSpot);
|
m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fullScreen = FALSE;
|
bool fullScreen = wxGetApp().GetUseScreen();
|
||||||
if (wxGetApp().GetUseScreen())
|
|
||||||
{
|
|
||||||
newPos = ClientToScreen(newPos);
|
|
||||||
fullScreen = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool retValue;
|
// The offset between the top-left of the shape image and the current shape position
|
||||||
|
wxPoint beginDragHotSpot = m_dragStartPos - m_draggedShape->GetPosition();
|
||||||
|
|
||||||
if (fullScreen)
|
// Now we do this inside the implementation: always assume
|
||||||
// This line uses the whole screen...
|
// coordinates relative to the capture window (client coordinates)
|
||||||
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);
|
|
||||||
|
|
||||||
if (!retValue)
|
//if (fullScreen)
|
||||||
|
// beginDragHotSpot -= ClientToScreen(wxPoint(0, 0));
|
||||||
|
|
||||||
|
if (!m_dragImage->BeginDrag(beginDragHotSpot, this, fullScreen))
|
||||||
{
|
{
|
||||||
delete m_dragImage;
|
delete m_dragImage;
|
||||||
m_dragImage = (wxDragImage*) NULL;
|
m_dragImage = (wxDragImage*) NULL;
|
||||||
m_dragMode = TEST_DRAG_NONE;
|
m_dragMode = TEST_DRAG_NONE;
|
||||||
}
|
|
||||||
m_dragImage->Move(newPos);
|
} else
|
||||||
|
{
|
||||||
|
m_dragImage->Move(event.GetPosition());
|
||||||
m_dragImage->Show();
|
m_dragImage->Show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (m_dragMode == TEST_DRAG_DRAGGING)
|
else if (m_dragMode == TEST_DRAG_DRAGGING)
|
||||||
{
|
{
|
||||||
// We're currently dragging. See if we're over another shape.
|
// We're currently dragging. See if we're over another shape.
|
||||||
@@ -272,16 +260,8 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
m_currentlyHighlighted->Draw(clientDC, wxINVERT);
|
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
|
// Move and show the image again
|
||||||
m_dragImage->Move(newPos);
|
m_dragImage->Move(event.GetPosition());
|
||||||
|
|
||||||
if (mustUnhighlightOld || mustHighlightNew)
|
if (mustUnhighlightOld || mustHighlightNew)
|
||||||
m_dragImage->Show();
|
m_dragImage->Show();
|
||||||
|
@@ -94,42 +94,39 @@ void wxGenericDragImage::Init()
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Create a drag image with a virtual image (need to override DoDrawImage, GetImageRect)
|
// 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_cursor = cursor;
|
||||||
m_hotspot = hotspot;
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image from a bitmap and optional cursor
|
// 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
|
// 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.
|
// as we drag. This currently will only work within one window.
|
||||||
|
|
||||||
m_cursor = cursor;
|
m_cursor = cursor;
|
||||||
m_hotspot = hotspot;
|
|
||||||
m_bitmap = image;
|
m_bitmap = image;
|
||||||
|
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image from an icon and optional cursor
|
// 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
|
// 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.
|
// as we drag. This currently will only work within one window.
|
||||||
|
|
||||||
m_cursor = cursor;
|
m_cursor = cursor;
|
||||||
m_hotspot = hotspot;
|
|
||||||
m_icon = image;
|
m_icon = image;
|
||||||
|
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image from a string and optional cursor
|
// 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));
|
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
|
||||||
|
|
||||||
@@ -170,7 +167,7 @@ bool wxGenericDragImage::Create(const wxString& str, const wxCursor& cursor, con
|
|||||||
bitmap = image.ConvertToBitmap();
|
bitmap = image.ConvertToBitmap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return Create(bitmap, cursor, hotspot);
|
return Create(bitmap, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image for the given tree control item
|
// Create a drag image for the given tree control item
|
||||||
@@ -319,15 +316,19 @@ bool wxGenericDragImage::Move(const wxPoint& pt)
|
|||||||
{
|
{
|
||||||
wxASSERT_MSG( (m_windowDC != (wxDC*) NULL), wxT("No window DC in wxGenericDragImage::Move()") );
|
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
|
// Erase at old position, then show at the current position
|
||||||
wxPoint oldPos = m_position;
|
wxPoint oldPos = m_position;
|
||||||
|
|
||||||
bool eraseOldImage = (m_isDirty && m_isShown);
|
bool eraseOldImage = (m_isDirty && m_isShown);
|
||||||
|
|
||||||
if (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)
|
if (m_isShown)
|
||||||
m_isDirty = TRUE;
|
m_isDirty = TRUE;
|
||||||
|
@@ -102,7 +102,7 @@ void wxDragImage::Init()
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Create a drag image from a bitmap and optional cursor
|
// 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 )
|
if ( m_hImageList )
|
||||||
ImageList_Destroy(GetHimageList());
|
ImageList_Destroy(GetHimageList());
|
||||||
@@ -146,13 +146,12 @@ bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wx
|
|||||||
wxLogError(_("Couldn't add an image to the image list."));
|
wxLogError(_("Couldn't add an image to the image list."));
|
||||||
}
|
}
|
||||||
m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
|
m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
|
||||||
m_cursorHotspot = cursorHotspot;
|
|
||||||
|
|
||||||
return (index != -1) ;
|
return (index != -1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image from an icon and optional cursor
|
// 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 )
|
if ( m_hImageList )
|
||||||
ImageList_Destroy(GetHimageList());
|
ImageList_Destroy(GetHimageList());
|
||||||
@@ -184,13 +183,12 @@ bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
|
m_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
|
||||||
m_cursorHotspot = cursorHotspot;
|
|
||||||
|
|
||||||
return (index != -1) ;
|
return (index != -1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image from a string and optional cursor
|
// 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));
|
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
|
||||||
|
|
||||||
@@ -226,7 +224,7 @@ bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPo
|
|||||||
image.SetMaskColour(255, 255, 255);
|
image.SetMaskColour(255, 255, 255);
|
||||||
bitmap = image.ConvertToBitmap();
|
bitmap = image.ConvertToBitmap();
|
||||||
|
|
||||||
return Create(bitmap, cursor, cursorHotspot);
|
return Create(bitmap, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a drag image for the given tree control item
|
// Create a drag image for the given tree control item
|
||||||
@@ -260,6 +258,7 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
|
|||||||
m_boundingRect = * rect;
|
m_boundingRect = * rect;
|
||||||
|
|
||||||
bool ret = (ImageList_BeginDrag(GetHimageList(), 0, hotspot.x, hotspot.y) != 0);
|
bool ret = (ImageList_BeginDrag(GetHimageList(), 0, hotspot.x, hotspot.y) != 0);
|
||||||
|
//bool ret = (ImageList_BeginDrag(GetHimageList(), 0, 0, 0) != 0);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
@@ -282,6 +281,21 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
|
|||||||
m_hCursorImageList = (WXHIMAGELIST) ImageList_Create(cxCursor, cyCursor, ILC_MASK, 1, 1);
|
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
|
// First add the cursor to the image list
|
||||||
HCURSOR hCursor = (HCURSOR) m_cursor.GetHCURSOR();
|
HCURSOR hCursor = (HCURSOR) m_cursor.GetHCURSOR();
|
||||||
int cursorIndex = ImageList_AddIcon((HIMAGELIST) m_hCursorImageList, (HICON) hCursor);
|
int cursorIndex = ImageList_AddIcon((HIMAGELIST) m_hCursorImageList, (HICON) hCursor);
|
||||||
@@ -290,18 +304,18 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
|
|||||||
|
|
||||||
if (cursorIndex != -1)
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
m_window = window;
|
|
||||||
|
|
||||||
#if !wxUSE_SIMPLER_DRAGIMAGE
|
#if !wxUSE_SIMPLER_DRAGIMAGE
|
||||||
if (m_cursor.Ok())
|
if (m_cursor.Ok())
|
||||||
::ShowCursor(FALSE);
|
::ShowCursor(FALSE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
m_window = window;
|
||||||
|
|
||||||
::SetCapture(GetHwndOf(window));
|
::SetCapture(GetHwndOf(window));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -376,6 +390,10 @@ bool wxDragImage::Move(const wxPoint& pt)
|
|||||||
// Subtract the (negative) values, i.e. add a small increment
|
// Subtract the (negative) values, i.e. add a small increment
|
||||||
pt2.x -= rect.left; pt2.y -= rect.top;
|
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);
|
bool ret = (ImageList_DragMove( pt2.x, pt2.y ) != 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user