]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/cursor.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCursor class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/cursor.h"
25 #include "wx/os2/private.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxCursor
, wxBitmap
)
32 wxCursorRefData::wxCursorRefData(void)
37 m_destroyCursor
= FALSE
;
40 wxCursorRefData::~wxCursorRefData(void)
42 // if ( m_hCursor && m_destroyCursor)
43 // ::DestroyCursor((HICON) m_hCursor);
47 wxCursor::wxCursor(void)
51 wxCursor::wxCursor(const char WXUNUSED(bits
)[], int WXUNUSED(width
), int WXUNUSED(height
),
52 int WXUNUSED(hotSpotX
), int WXUNUSED(hotSpotY
), const char WXUNUSED(maskBits
)[])
60 wxImage vImage32
= rImage
.Scale(32,32);
61 int nWidth
= vImage32
.GetWidth();
62 int nHeight
= vImage32
.GetHeight();
65 // Need a bitmap handle somehow
67 HBITMAP hBitmap
= wxBitmap(vImage32
).GetHBITMAP();
68 int nHotSpotX
= vImage32
.GetOptionInt(wxCUR_HOTSPOT_X
);
69 int nHotSpotY
= vImage32
.GetOptionInt(wxCUR_HOTSPOT_Y
);
71 if (nHotSpotX
< 0 || nHotSpotX
>= nWidth
)
73 if (nHotSpotY
< 0 || nHotSpotY
>= nHeight
)
77 wxCursorRefData
* pRefData
= new wxCursorRefData
;
80 pRefData
->m_hCursor
= (WXHCURSOR
) ::WinCreatePointer( HWND_DESKTOP
87 } // end of wxCursor::wxCursor
89 wxCursor::wxCursor(const wxString
& cursor_file
, long flags
, int hotSpotX
, int hotSpotY
)
91 m_refData
= new wxCursorRefData
;
93 M_CURSORDATA
->m_destroyCursor
= FALSE
;
94 M_CURSORDATA
->m_hCursor
= 0;
97 M_CURSORDATA->m_bOK = FALSE;
98 if (flags & wxBITMAP_TYPE_CUR_RESOURCE)
100 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, 0);
101 if (M_CURSORDATA->m_hCursor)
102 M_CURSORDATA->m_ok = TRUE;
104 M_CURSORDATA->m_ok = FALSE;
106 else if (flags & wxBITMAP_TYPE_CUR)
108 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
110 else if (flags & wxBITMAP_TYPE_ICO)
113 else if (flags & wxBITMAP_TYPE_BMP)
119 // Cursors by stock number
120 wxCursor::wxCursor(int cursor_type
)
122 m_refData
= new wxCursorRefData
;
128 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
131 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
134 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
136 case wxCURSOR_SIZENWSE:
137 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
139 case wxCURSOR_SIZENESW:
140 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
142 case wxCURSOR_SIZEWE:
143 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
145 case wxCURSOR_SIZENS:
146 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
150 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
155 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
158 case wxCURSOR_BULLSEYE:
160 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
163 case wxCURSOR_PENCIL:
165 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
168 case wxCURSOR_MAGNIFIER:
170 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
173 case wxCURSOR_NO_ENTRY:
175 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
178 case wxCURSOR_LEFT_BUTTON:
180 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
183 case wxCURSOR_RIGHT_BUTTON:
185 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
188 case wxCURSOR_MIDDLE_BUTTON:
190 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
193 case wxCURSOR_SIZING:
195 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
200 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
203 case wxCURSOR_SPRAYCAN:
205 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
208 case wxCURSOR_PAINT_BRUSH:
210 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
213 case wxCURSOR_POINT_LEFT:
215 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
218 case wxCURSOR_POINT_RIGHT:
220 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
223 case wxCURSOR_QUESTION_ARROW:
225 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
230 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
235 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
241 wxCursor::~wxCursor(void)
243 // FreeResource(TRUE);
246 bool wxCursor::FreeResource(bool WXUNUSED(force
))
248 // if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
250 // DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
251 // M_CURSORDATA->m_hCursor = 0;
256 void wxCursor::SetHCURSOR(WXHCURSOR cursor
)
259 m_refData
= new wxCursorRefData
;
261 M_CURSORDATA
->m_hCursor
= cursor
;
264 // Global cursor setting
265 void wxSetCursor(const wxCursor
& cursor
)
267 extern wxCursor
*g_globalCursor
;
269 if ( cursor
.Ok() && cursor
.GetHCURSOR() )
271 // ::SetCursor((HCURSOR) cursor.GetHCURSOR());
273 if ( g_globalCursor
)
274 (*g_globalCursor
) = cursor
;