]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dragimag.cpp
55757f2ea6ac8c9bc6a00a636a7864f27dfb9800
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDragImage
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dragimag.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if defined(__WIN95__)
28 #include "wx/window.h"
29 #include "wx/dcclient.h"
30 #include "wx/dcscreen.h"
31 #include "wx/dcmemory.h"
32 #include "wx/settings.h"
38 #include "wx/msw/dragimag.h"
39 #include "wx/msw/private.h"
41 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
45 IMPLEMENT_DYNAMIC_CLASS(wxDragImage
, wxObject
)
47 wxDragImage::wxDragImage()
52 wxDragImage::~wxDragImage()
55 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
61 ////////////////////////////////////////////////////////////////////////////
65 ////////////////////////////////////////////////////////////////////////////
67 // Create a drag image from a bitmap and optional cursor
68 bool wxDragImage::Create(const wxBitmap
& image
, const wxCursor
& cursor
, const wxPoint
& hotspot
)
71 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
75 bool mask
= TRUE
; // ?
79 m_hImageList
= (WXHIMAGELIST
) ImageList_Create(image
.GetWidth(), image
.GetHeight(), flags
, 1, 1);
81 HBITMAP hBitmap1
= (HBITMAP
) image
.GetHBITMAP();
83 if ( image
.GetMask() )
84 hBitmap2
= (HBITMAP
) image
.GetMask()->GetMaskBitmap();
86 int index
= ImageList_Add((HIMAGELIST
) m_hImageList
, hBitmap1
, hBitmap2
);
89 wxLogError(_("Couldn't add an image to the image list."));
92 m_cursor
= cursor
; // Can only combine with drag image after calling BeginDrag.
95 return (index
!= -1) ;
98 // Create a drag image from an icon and optional cursor
99 bool wxDragImage::Create(const wxIcon
& image
, const wxCursor
& cursor
, const wxPoint
& hotspot
)
102 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
106 bool mask
= TRUE
; // ?
110 m_hImageList
= (WXHIMAGELIST
) ImageList_Create(image
.GetWidth(), image
.GetHeight(), flags
, 1, 1);
112 HICON hIcon
= (HICON
) image
.GetHICON();
114 int index
= ImageList_AddIcon((HIMAGELIST
) m_hImageList
, hIcon
);
117 wxLogError(_("Couldn't add an image to the image list."));
120 m_cursor
= cursor
; // Can only combine with drag image after calling BeginDrag.
123 return (index
!= -1) ;
126 // Create a drag image from a string and optional cursor
127 bool wxDragImage::Create(const wxString
& str
, const wxCursor
& cursor
, const wxPoint
& hotspot
)
129 wxFont
font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
134 dc
.GetTextExtent(str
, & w
, & h
);
138 wxBitmap
bitmap((int) w
, (int) h
);
139 dc2
.SelectObject(bitmap
);
141 dc2
.SetBackground(* wxWHITE_BRUSH
);
143 dc2
.DrawText(str
, 0, 0);
145 dc2
.SelectObject(wxNullBitmap
);
147 return Create(bitmap
, cursor
, hotspot
);
150 // Create a drag image for the given tree control item
151 bool wxDragImage::Create(const wxTreeCtrl
& treeCtrl
, wxTreeItemId
& id
)
154 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
155 m_hImageList
= (WXHIMAGELIST
) TreeView_CreateDragImage((HWND
) treeCtrl
.GetHWND(), (HTREEITEM
) (WXHTREEITEM
) id
);
159 // Create a drag image for the given list control item
160 bool wxDragImage::Create(const wxListCtrl
& listCtrl
, long id
)
163 ImageList_Destroy((HIMAGELIST
) m_hImageList
);
166 m_hImageList
= (WXHIMAGELIST
) ListView_CreateDragImage((HWND
) listCtrl
.GetHWND(), id
, & pt
);
171 bool wxDragImage::BeginDrag(const wxPoint
& hotspot
, wxWindow
* WXUNUSED(window
))
173 wxASSERT_MSG( (m_hImageList
!= 0), wxT("Image list must not be null in BeginDrag."));
175 bool ret
= (ImageList_BeginDrag((HIMAGELIST
) m_hImageList
, 0, hotspot
.x
, hotspot
.y
) != 0);
177 wxASSERT_MSG( (ret
), wxT("BeginDrag failed."));
184 // First add the cursor to the image list
185 int cursorIndex
= ImageList_AddIcon((HIMAGELIST
) m_hImageList
, (HICON
) m_cursor
.GetHCURSOR());
187 wxASSERT_MSG( (cursorIndex
!= -1), wxT("ImageList_AddIcon failed in BeginDrag."));
189 if (cursorIndex
!= -1)
191 ImageList_SetDragCursorImage((HIMAGELIST
) m_hImageList
, cursorIndex
, m_hotspot
.x
, m_hotspot
.y
);
201 bool wxDragImage::EndDrag(wxWindow
* WXUNUSED(window
))
203 wxASSERT_MSG( (m_hImageList
!= 0), wxT("Image list must not be null in EndDrag."));
212 // Move the image: call from OnMouseMove. Pt is in window client coordinates if window
213 // is non-NULL, or in screen coordinates if NULL.
214 bool wxDragImage::Move(const wxPoint
& pt
, wxWindow
* window
)
216 wxASSERT_MSG( (m_hImageList
!= 0), wxT("Image list must not be null in Move."));
218 // TODO: what coordinates are these in: window, client, or screen?
219 bool ret
= (ImageList_DragMove( pt
.x
, pt
.y
) != 0);
226 bool wxDragImage::Show(wxWindow
* window
)
228 wxASSERT_MSG( (m_hImageList
!= 0), wxT("Image list must not be null in Show."));
232 hWnd
= (HWND
) window
->GetHWND();
234 bool ret
= (ImageList_DragEnter( hWnd
, m_position
.x
, m_position
.y
) != 0);
239 bool wxDragImage::Hide(wxWindow
* window
)
241 wxASSERT_MSG( (m_hImageList
!= 0), wxT("Image list must not be null in Hide."));
245 hWnd
= (HWND
) window
->GetHWND();
247 bool ret
= (ImageList_DragLeave( hWnd
) != 0);