X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23aa4f09d26bd1eb5df7f7170276744a293cbe19..52130557bfa9d969c7c274bebbf7afc2e496321d:/src/msw/dragimag.cpp diff --git a/src/msw/dragimag.cpp b/src/msw/dragimag.cpp index 8c6749eb92..1ce8b4e548 100644 --- a/src/msw/dragimag.cpp +++ b/src/msw/dragimag.cpp @@ -6,15 +6,24 @@ // Created: 08/04/99 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "dragimag.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#include "wx/msw/private.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -38,13 +47,25 @@ #include "wx/msw/dragimag.h" #include "wx/msw/private.h" -#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) +#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) #include #endif -#if !USE_SHARED_LIBRARY +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + IMPLEMENT_DYNAMIC_CLASS(wxDragImage, wxObject) -#endif + +#define GetHimageList() ((HIMAGELIST) m_hImageList) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxDragImage ctors/dtor +// ---------------------------------------------------------------------------- wxDragImage::wxDragImage() { @@ -53,9 +74,8 @@ wxDragImage::wxDragImage() wxDragImage::~wxDragImage() { - if ( m_hImageList ) - ImageList_Destroy((HIMAGELIST) m_hImageList); - m_hImageList = 0; + if ( m_hImageList ) + ImageList_Destroy(GetHimageList()); } @@ -69,24 +89,24 @@ wxDragImage::~wxDragImage() // Create a drag image from a bitmap and optional cursor bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wxPoint& hotspot) { - if ( m_hImageList ) - ImageList_Destroy((HIMAGELIST) m_hImageList); - m_hImageList = 0; + if ( m_hImageList ) + ImageList_Destroy(GetHimageList()); + m_hImageList = 0; - UINT flags = 0; + UINT flags = 0; bool mask = TRUE; // ? - if ( mask ) - flags |= ILC_MASK; + if ( mask ) + flags |= ILC_MASK; - m_hImageList = (WXHIMAGELIST) ImageList_Create(image.GetWidth(), image.GetHeight(), flags, 1, 1); + m_hImageList = (WXHIMAGELIST) ImageList_Create(image.GetWidth(), image.GetHeight(), flags, 1, 1); - HBITMAP hBitmap1 = (HBITMAP) image.GetHBITMAP(); - HBITMAP hBitmap2 = 0; - if ( image.GetMask() ) - hBitmap2 = (HBITMAP) image.GetMask()->GetMaskBitmap(); + HBITMAP hBitmap1 = (HBITMAP) image.GetHBITMAP(); + HBITMAP hBitmap2 = 0; + if ( image.GetMask() ) + hBitmap2 = (HBITMAP) image.GetMask()->GetMaskBitmap(); - int index = ImageList_Add((HIMAGELIST) m_hImageList, hBitmap1, hBitmap2); - if ( index == -1 ) + int index = ImageList_Add(GetHimageList(), hBitmap1, hBitmap2); + if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } @@ -96,25 +116,25 @@ bool wxDragImage::Create(const wxBitmap& image, const wxCursor& cursor, const wx 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) { - if ( m_hImageList ) - ImageList_Destroy((HIMAGELIST) m_hImageList); - m_hImageList = 0; + if ( m_hImageList ) + ImageList_Destroy(GetHimageList()); + m_hImageList = 0; - UINT flags = 0; + UINT flags = 0; bool mask = TRUE; // ? - if ( mask ) - flags |= ILC_MASK; + if ( mask ) + flags |= ILC_MASK; - m_hImageList = (WXHIMAGELIST) ImageList_Create(image.GetWidth(), image.GetHeight(), flags, 1, 1); + m_hImageList = (WXHIMAGELIST) ImageList_Create(image.GetWidth(), image.GetHeight(), flags, 1, 1); - HICON hIcon = (HICON) image.GetHICON(); + HICON hIcon = (HICON) image.GetHICON(); - int index = ImageList_AddIcon((HIMAGELIST) m_hImageList, hIcon); - if ( index == -1 ) + int index = ImageList_AddIcon(GetHimageList(), hIcon); + if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } @@ -124,7 +144,7 @@ bool wxDragImage::Create(const wxIcon& image, const wxCursor& cursor, const wxPo 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) { @@ -152,8 +172,8 @@ bool wxDragImage::Create(const wxString& str, const wxCursor& cursor, const wxPo // Create a drag image for the given tree control item bool wxDragImage::Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) { - if ( m_hImageList ) - ImageList_Destroy((HIMAGELIST) m_hImageList); + if ( m_hImageList ) + ImageList_Destroy(GetHimageList()); m_hImageList = (WXHIMAGELIST) TreeView_CreateDragImage((HWND) treeCtrl.GetHWND(), (HTREEITEM) (WXHTREEITEM) id); return TRUE; } @@ -161,8 +181,8 @@ bool wxDragImage::Create(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) // Create a drag image for the given list control item bool wxDragImage::Create(const wxListCtrl& listCtrl, long id) { - if ( m_hImageList ) - ImageList_Destroy((HIMAGELIST) m_hImageList); + if ( m_hImageList ) + ImageList_Destroy(GetHimageList()); POINT pt; pt.x = 0; pt.y = 0; m_hImageList = (WXHIMAGELIST) ListView_CreateDragImage((HWND) listCtrl.GetHWND(), id, & pt); @@ -170,52 +190,60 @@ bool wxDragImage::Create(const wxListCtrl& listCtrl, long id) } // Begin drag -bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* WXUNUSED(window)) +bool wxDragImage::BeginDrag(const wxPoint& hotspot, wxWindow* window) { - wxASSERT_MSG( (m_hImageList != 0), _T("Image list must not be null in BeginDrag.")); - - bool ret = (ImageList_BeginDrag((HIMAGELIST) m_hImageList, 0, hotspot.x, hotspot.y) != 0); + wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in BeginDrag.")); - wxASSERT_MSG( (ret), _T("BeginDrag failed.")); + bool ret = (ImageList_BeginDrag(GetHimageList(), 0, hotspot.x, hotspot.y) != 0); if (!ret) + { + wxFAIL_MSG( _T("BeginDrag failed.") ); + return FALSE; + } if (m_cursor.Ok()) { // First add the cursor to the image list - int cursorIndex = ImageList_AddIcon((HIMAGELIST) m_hImageList, (HICON) m_cursor.GetHCURSOR()); + int cursorIndex = ImageList_AddIcon(GetHimageList(), (HICON) m_cursor.GetHCURSOR()); - wxASSERT_MSG( (cursorIndex != -1), _T("ImageList_AddIcon failed in BeginDrag.")); + wxASSERT_MSG( (cursorIndex != -1), wxT("ImageList_AddIcon failed in BeginDrag.")); if (cursorIndex != -1) { - ImageList_SetDragCursorImage((HIMAGELIST) m_hImageList, cursorIndex, m_hotspot.x, m_hotspot.y); + ImageList_SetDragCursorImage(GetHimageList(), cursorIndex, m_hotspot.x, m_hotspot.y); } } ::ShowCursor(FALSE); + ::SetCapture(GetHwndOf(window)); return TRUE; } - + // End drag bool wxDragImage::EndDrag(wxWindow* WXUNUSED(window)) { - wxASSERT_MSG( (m_hImageList != 0), _T("Image list must not be null in EndDrag.")); + wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in EndDrag.")); ImageList_EndDrag(); + if ( !::ReleaseCapture() ) + { + wxLogLastError("ReleaseCapture"); + } + ::ShowCursor(TRUE); return TRUE; } - + // Move the image: call from OnMouseMove. Pt is in window client coordinates if window // is non-NULL, or in screen coordinates if NULL. bool wxDragImage::Move(const wxPoint& pt, wxWindow* window) { - wxASSERT_MSG( (m_hImageList != 0), _T("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? bool ret = (ImageList_DragMove( pt.x, pt.y ) != 0); @@ -227,7 +255,7 @@ bool wxDragImage::Move(const wxPoint& pt, wxWindow* window) bool wxDragImage::Show(wxWindow* window) { - wxASSERT_MSG( (m_hImageList != 0), _T("Image list must not be null in Show.")); + wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in Show.")); HWND hWnd = 0; if (window) @@ -240,7 +268,7 @@ bool wxDragImage::Show(wxWindow* window) bool wxDragImage::Hide(wxWindow* window) { - wxASSERT_MSG( (m_hImageList != 0), _T("Image list must not be null in Hide.")); + wxASSERT_MSG( (m_hImageList != 0), wxT("Image list must not be null in Hide.")); HWND hWnd = 0; if (window)