]> git.saurik.com Git - wxWidgets.git/blame - src/os2/cursor.cpp
fixed a few warnings
[wxWidgets.git] / src / os2 / cursor.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: cursor.cpp
3// Purpose: wxCursor class
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
37f214d5
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
37f214d5
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
37f214d5
DW
15#ifndef WX_PRECOMP
16#include <stdio.h>
17#include "wx/setup.h"
18#include "wx/list.h"
19#include "wx/utils.h"
20#include "wx/app.h"
0e320a79
DW
21#include "wx/cursor.h"
22#include "wx/icon.h"
37f214d5
DW
23#endif
24
25#include "wx/os2/private.h"
b9b1d6c8 26#include "wx/image.h"
37f214d5
DW
27
28#include "assert.h"
0e320a79 29
0e320a79 30IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
0e320a79 31
37f214d5 32wxCursorRefData::wxCursorRefData(void)
0e320a79 33{
43543d98
DW
34 m_nWidth = 32;
35 m_nHeight = 32;
37f214d5
DW
36 m_hCursor = 0 ;
37 m_destroyCursor = FALSE;
0e320a79
DW
38}
39
37f214d5 40wxCursorRefData::~wxCursorRefData(void)
0e320a79 41{
37f214d5
DW
42// if ( m_hCursor && m_destroyCursor)
43// ::DestroyCursor((HICON) m_hCursor);
0e320a79
DW
44}
45
46// Cursors
37f214d5 47wxCursor::wxCursor(void)
0e320a79
DW
48{
49}
50
51wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height),
52 int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[])
53{
54}
55
b9b1d6c8
DW
56wxCursor::wxCursor(
57 const wxImage& rImage
58)
59{
60 wxImage vImage32 = rImage.Scale(32,32);
61 int nWidth = vImage32.GetWidth();
62 int nHeight = vImage32.GetHeight();
63
64 //
65 // Need a bitmap handle somehow
66 //
67 HBITMAP hBitmap = wxBitmap(vImage32).GetHBITMAP();
68 int nHotSpotX = vImage32.GetOptionInt(wxCUR_HOTSPOT_X);
69 int nHotSpotY = vImage32.GetOptionInt(wxCUR_HOTSPOT_Y);
70
71 if (nHotSpotX < 0 || nHotSpotX >= nWidth)
72 nHotSpotX = 0;
73 if (nHotSpotY < 0 || nHotSpotY >= nHeight)
74 nHotSpotY = 0;
75
76
77 wxCursorRefData* pRefData = new wxCursorRefData;
78
79 m_refData = pRefData;
80 pRefData->m_hCursor = (WXHCURSOR) ::WinCreatePointer( HWND_DESKTOP
81 ,hBitmap
82 ,TRUE
83 ,nHotSpotY
84 ,nHotSpotX
85 );
86
87} // end of wxCursor::wxCursor
88
0e320a79
DW
89wxCursor::wxCursor(const wxString& cursor_file, long flags, int hotSpotX, int hotSpotY)
90{
37f214d5 91 m_refData = new wxCursorRefData;
0e320a79 92
37f214d5
DW
93 M_CURSORDATA->m_destroyCursor = FALSE;
94 M_CURSORDATA->m_hCursor = 0;
37f214d5
DW
95// TODO:
96/*
43543d98 97 M_CURSORDATA->m_bOK = FALSE;
37f214d5
DW
98 if (flags & wxBITMAP_TYPE_CUR_RESOURCE)
99 {
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;
103 else
104 M_CURSORDATA->m_ok = FALSE;
105 }
106 else if (flags & wxBITMAP_TYPE_CUR)
107 {
108 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadImage(wxGetInstance(), cursor_file, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
109 }
110 else if (flags & wxBITMAP_TYPE_ICO)
111 {
112 }
113 else if (flags & wxBITMAP_TYPE_BMP)
114 {
115 }
116*/
0e320a79
DW
117}
118
119// Cursors by stock number
120wxCursor::wxCursor(int cursor_type)
121{
122 m_refData = new wxCursorRefData;
37f214d5
DW
123// TODO:
124/*
0e320a79
DW
125 switch (cursor_type)
126 {
127 case wxCURSOR_WAIT:
37f214d5 128 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_WAIT);
0e320a79
DW
129 break;
130 case wxCURSOR_IBEAM:
37f214d5 131 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_IBEAM);
0e320a79
DW
132 break;
133 case wxCURSOR_CROSS:
37f214d5 134 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_CROSS);
0e320a79
DW
135 break;
136 case wxCURSOR_SIZENWSE:
37f214d5 137 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENWSE);
0e320a79
DW
138 break;
139 case wxCURSOR_SIZENESW:
37f214d5 140 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENESW);
0e320a79
DW
141 break;
142 case wxCURSOR_SIZEWE:
37f214d5 143 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZEWE);
0e320a79
DW
144 break;
145 case wxCURSOR_SIZENS:
37f214d5 146 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_SIZENS);
0e320a79
DW
147 break;
148 case wxCURSOR_CHAR:
149 {
37f214d5 150 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
0e320a79
DW
151 break;
152 }
153 case wxCURSOR_HAND:
154 {
37f214d5 155 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_HAND"));
0e320a79
DW
156 break;
157 }
158 case wxCURSOR_BULLSEYE:
159 {
37f214d5 160 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BULLSEYE"));
0e320a79
DW
161 break;
162 }
163 case wxCURSOR_PENCIL:
164 {
37f214d5 165 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PENCIL"));
0e320a79
DW
166 break;
167 }
168 case wxCURSOR_MAGNIFIER:
169 {
37f214d5 170 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_MAGNIFIER"));
0e320a79
DW
171 break;
172 }
173 case wxCURSOR_NO_ENTRY:
174 {
37f214d5 175 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_NO_ENTRY"));
0e320a79
DW
176 break;
177 }
178 case wxCURSOR_LEFT_BUTTON:
179 {
37f214d5 180 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
0e320a79
DW
181 break;
182 }
183 case wxCURSOR_RIGHT_BUTTON:
184 {
37f214d5 185 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
0e320a79
DW
186 break;
187 }
188 case wxCURSOR_MIDDLE_BUTTON:
189 {
37f214d5 190 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
0e320a79
DW
191 break;
192 }
193 case wxCURSOR_SIZING:
194 {
37f214d5 195 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_SIZING"));
0e320a79
DW
196 break;
197 }
198 case wxCURSOR_WATCH:
199 {
37f214d5 200 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_WATCH"));
0e320a79
DW
201 break;
202 }
203 case wxCURSOR_SPRAYCAN:
204 {
37f214d5 205 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_ROLLER"));
0e320a79
DW
206 break;
207 }
208 case wxCURSOR_PAINT_BRUSH:
209 {
37f214d5 210 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PBRUSH"));
0e320a79
DW
211 break;
212 }
213 case wxCURSOR_POINT_LEFT:
214 {
37f214d5 215 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PLEFT"));
0e320a79
DW
216 break;
217 }
218 case wxCURSOR_POINT_RIGHT:
219 {
37f214d5 220 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_PRIGHT"));
0e320a79
DW
221 break;
222 }
223 case wxCURSOR_QUESTION_ARROW:
224 {
37f214d5 225 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_QARROW"));
0e320a79
DW
226 break;
227 }
228 case wxCURSOR_BLANK:
229 {
37f214d5 230 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor(wxGetInstance(), wxT("wxCURSOR_BLANK"));
0e320a79
DW
231 break;
232 }
233 default:
234 case wxCURSOR_ARROW:
37f214d5 235 M_CURSORDATA->m_hCursor = (WXHCURSOR) LoadCursor((HINSTANCE) NULL, IDC_ARROW);
0e320a79
DW
236 break;
237 }
238*/
37f214d5 239}
0e320a79 240
37f214d5
DW
241wxCursor::~wxCursor(void)
242{
243// FreeResource(TRUE);
0e320a79
DW
244}
245
37f214d5 246bool wxCursor::FreeResource(bool WXUNUSED(force))
0e320a79 247{
37f214d5
DW
248// if (M_CURSORDATA && M_CURSORDATA->m_hCursor && M_CURSORDATA->m_destroyCursor)
249// {
250// DestroyCursor((HCURSOR) M_CURSORDATA->m_hCursor);
251// M_CURSORDATA->m_hCursor = 0;
252// }
253 return TRUE;
254}
255
256void wxCursor::SetHCURSOR(WXHCURSOR cursor)
257{
258 if ( !M_CURSORDATA )
259 m_refData = new wxCursorRefData;
260
261 M_CURSORDATA->m_hCursor = cursor;
0e320a79
DW
262}
263
264// Global cursor setting
265void wxSetCursor(const wxCursor& cursor)
266{
37f214d5 267 extern wxCursor *g_globalCursor;
0e320a79 268
37f214d5
DW
269 if ( cursor.Ok() && cursor.GetHCURSOR() )
270 {
271// ::SetCursor((HCURSOR) cursor.GetHCURSOR());
272
273 if ( g_globalCursor )
274 (*g_globalCursor) = cursor;
275 }
276}
0e320a79 277