Implemented Chuck Messenger's naming and simplification improvements,

plus Move coordinate correction


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9701 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2001-04-10 13:44:03 +00:00
parent db400410d8
commit 6ea5c52d29
3 changed files with 73 additions and 24 deletions

View File

@@ -23,6 +23,10 @@
#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,
// and some other simplifications
#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:
@@ -106,23 +110,23 @@ public:
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
wxDragImage(); 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(); 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(); 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(); Init();
Create(str, cursor, hotspot); Create(str, cursor, cursorHotspot);
} }
wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) wxDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id)
{ {
@@ -145,13 +149,13 @@ 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& 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 // 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 // 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 // Create a drag image for the given tree control item
bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id); bool Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
@@ -190,14 +194,22 @@ public:
// Returns the native image list handle // Returns the native image list handle
WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; } WXHIMAGELIST GetHIMAGELIST() const { return m_hImageList; }
#if !wxUSE_SIMPLER_DRAGIMAGE
// Returns the native image list handle for the cursor // Returns the native image list handle for the cursor
WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; } WXHIMAGELIST GetCursorHIMAGELIST() const { return m_hCursorImageList; }
#endif
protected: protected:
WXHIMAGELIST m_hImageList; WXHIMAGELIST m_hImageList;
#if wxUSE_SIMPLER_DRAGIMAGE
wxCursor m_oldCursor;
#else
WXHIMAGELIST m_hCursorImageList; WXHIMAGELIST m_hCursorImageList;
#endif
wxCursor m_cursor; wxCursor m_cursor;
wxPoint m_hotspot; wxPoint m_cursorHotspot;
wxPoint m_position; wxPoint m_position;
wxWindow* m_window; wxWindow* m_window;
wxRect m_boundingRect; wxRect m_boundingRect;

View File

@@ -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 1 #define wxUSE_GENERIC_DRAGIMAGE 0
#if wxUSE_GENERIC_DRAGIMAGE #if wxUSE_GENERIC_DRAGIMAGE
#include "wx/generic/dragimgg.h" #include "wx/generic/dragimgg.h"
@@ -201,11 +201,11 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
// 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__
wxIcon icon(dragicon_xpm); wxIcon icon(dragicon_xpm);
#else #else
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), hotSpot);
break; break;
} }

View File

@@ -78,14 +78,18 @@ wxDragImage::~wxDragImage()
{ {
if ( m_hImageList ) if ( m_hImageList )
ImageList_Destroy(GetHimageList()); ImageList_Destroy(GetHimageList());
#if !wxUSE_SIMPLER_DRAGIMAGE
if ( m_hCursorImageList ) if ( m_hCursorImageList )
ImageList_Destroy((HIMAGELIST) m_hCursorImageList); ImageList_Destroy((HIMAGELIST) m_hCursorImageList);
#endif
} }
void wxDragImage::Init() void wxDragImage::Init()
{ {
m_hImageList = 0; m_hImageList = 0;
#if !wxUSE_SIMPLER_DRAGIMAGE
m_hCursorImageList = 0; m_hCursorImageList = 0;
#endif
m_window = (wxWindow*) NULL; m_window = (wxWindow*) NULL;
m_fullScreen = FALSE; m_fullScreen = FALSE;
} }
@@ -98,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& hotspot) bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
{ {
if ( m_hImageList ) if ( m_hImageList )
ImageList_Destroy(GetHimageList()); 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.")); 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_hotspot = hotspot; 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& hotspot) bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPoint& cursorHotspot)
{ {
if ( m_hImageList ) if ( m_hImageList )
ImageList_Destroy(GetHimageList()); 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_cursor = cursor; // Can only combine with drag image after calling BeginDrag.
m_hotspot = hotspot; 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& hotspot) bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPoint& cursorHotspot)
{ {
wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); 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); image.SetMaskColour(255, 255, 255);
bitmap = image.ConvertToBitmap(); bitmap = image.ConvertToBitmap();
return Create(bitmap, cursor, hotspot); return Create(bitmap, cursor, cursorHotspot);
} }
// Create a drag image for the given tree control item // 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 (m_cursor.Ok())
{ {
#if wxUSE_SIMPLER_DRAGIMAGE
m_oldCursor = window->GetCursor();
window->SetCursor(m_cursor);
#else
if (!m_hCursorImageList) if (!m_hCursorImageList)
{ {
int cxCursor = GetSystemMetrics(SM_CXCURSOR); int cxCursor = GetSystemMetrics(SM_CXCURSOR);
@@ -282,12 +290,17 @@ bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window, bool fullS
if (cursorIndex != -1) 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; m_window = window;
::ShowCursor(FALSE);
#if !wxUSE_SIMPLER_DRAGIMAGE
if (m_cursor.Ok())
::ShowCursor(FALSE);
#endif
::SetCapture(GetHwndOf(window)); ::SetCapture(GetHwndOf(window));
@@ -327,7 +340,13 @@ bool wxDragImage::EndDrag()
wxLogLastError(wxT("ReleaseCapture")); wxLogLastError(wxT("ReleaseCapture"));
} }
#if wxUSE_SIMPLER_DRAGIMAGE
if (m_cursor.Ok() && m_oldCursor.Ok())
m_window->SetCursor(m_oldCursor);
#else
::ShowCursor(TRUE); ::ShowCursor(TRUE);
#endif
m_window = (wxWindow*) NULL; m_window = (wxWindow*) NULL;
return TRUE; 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.")); wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in Move."));
// TODO: what coordinates are these in: window, client, or screen? // These are in window, not client coordinates.
bool ret = (ImageList_DragMove( pt.x, pt.y ) != 0); // 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; m_position = pt;