| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/os2/cursor.cpp |
| 3 | // Purpose: wxCursor class |
| 4 | // Author: David Webster |
| 5 | // Modified by: |
| 6 | // Created: 10/13/99 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) David Webster |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // For compilers that support precompilation, includes "wx.h". |
| 13 | #include "wx/wxprec.h" |
| 14 | |
| 15 | #include "wx/cursor.h" |
| 16 | |
| 17 | #ifndef WX_PRECOMP |
| 18 | #include <stdio.h> |
| 19 | #include "wx/list.h" |
| 20 | #include "wx/utils.h" |
| 21 | #include "wx/app.h" |
| 22 | #include "wx/icon.h" |
| 23 | #include "wx/image.h" |
| 24 | #include "wx/log.h" |
| 25 | #endif |
| 26 | |
| 27 | #include "wx/os2/private.h" |
| 28 | #include "wx/os2/wxrsc.h" |
| 29 | |
| 30 | #include "assert.h" |
| 31 | |
| 32 | IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) |
| 33 | |
| 34 | wxCursorRefData::wxCursorRefData(void) |
| 35 | { |
| 36 | m_nWidth = 32; |
| 37 | m_nHeight = 32; |
| 38 | m_hCursor = 0 ; |
| 39 | m_bDestroyCursor = false; |
| 40 | } |
| 41 | |
| 42 | void wxCursorRefData::Free() |
| 43 | { |
| 44 | if (m_hCursor) |
| 45 | { |
| 46 | if (m_bDestroyCursor) |
| 47 | ::WinDestroyPointer((HPOINTER)m_hCursor); |
| 48 | m_hCursor = 0; |
| 49 | } |
| 50 | } // end of wxCursorRefData::Free |
| 51 | |
| 52 | // Cursors |
| 53 | wxCursor::wxCursor(void) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | wxCursor::wxCursor(const wxImage& rImage) |
| 58 | { |
| 59 | wxImage vImage32 = rImage.Scale(32,32); |
| 60 | int nWidth = vImage32.GetWidth(); |
| 61 | int nHeight = vImage32.GetHeight(); |
| 62 | |
| 63 | // |
| 64 | // Need a bitmap handle somehow |
| 65 | // |
| 66 | HBITMAP hBitmap = wxBitmap(vImage32).GetHBITMAP(); |
| 67 | int nHotSpotX = vImage32.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); |
| 68 | int nHotSpotY = vImage32.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); |
| 69 | |
| 70 | if (nHotSpotX < 0 || nHotSpotX >= nWidth) |
| 71 | nHotSpotX = 0; |
| 72 | if (nHotSpotY < 0 || nHotSpotY >= nHeight) |
| 73 | nHotSpotY = 0; |
| 74 | |
| 75 | |
| 76 | wxCursorRefData* pRefData = new wxCursorRefData; |
| 77 | |
| 78 | m_refData = pRefData; |
| 79 | pRefData->m_hCursor = (WXHCURSOR) ::WinCreatePointer( HWND_DESKTOP |
| 80 | ,hBitmap |
| 81 | ,TRUE |
| 82 | ,nHotSpotY |
| 83 | ,nHotSpotX |
| 84 | ); |
| 85 | |
| 86 | } // end of wxCursor::wxCursor |
| 87 | |
| 88 | wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile), |
| 89 | wxBitmapType type, |
| 90 | int WXUNUSED(nHotSpotX), |
| 91 | int WXUNUSED(nHotSpotY) ) |
| 92 | { |
| 93 | wxCursorRefData* pRefData = new wxCursorRefData; |
| 94 | |
| 95 | pRefData = new wxCursorRefData; |
| 96 | m_refData = pRefData; |
| 97 | pRefData->m_bDestroyCursor = false; |
| 98 | if (type == wxBITMAP_TYPE_CUR_RESOURCE) |
| 99 | { |
| 100 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 101 | ,0 |
| 102 | ,(ULONG)type // if OS/2 this should be the resource Id |
| 103 | ); |
| 104 | } |
| 105 | else |
| 106 | wxLogError("Invalid cursor bitmap type '%d'", type); |
| 107 | } // end of wxCursor::wxCursor |
| 108 | |
| 109 | // Cursors by stock number |
| 110 | void wxCursor::InitFromStock(wxStockCursor nCursorType) |
| 111 | { |
| 112 | wxCursorRefData* pRefData = new wxCursorRefData; |
| 113 | |
| 114 | m_refData = pRefData; |
| 115 | switch (nCursorType) |
| 116 | { |
| 117 | case wxCURSOR_ARROWWAIT: |
| 118 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 119 | ,(ULONG)SPTR_WAIT |
| 120 | ,FALSE |
| 121 | ); |
| 122 | break; |
| 123 | |
| 124 | case wxCURSOR_WATCH: |
| 125 | case wxCURSOR_WAIT: |
| 126 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 127 | ,(ULONG)SPTR_WAIT |
| 128 | ,FALSE |
| 129 | ); |
| 130 | break; |
| 131 | |
| 132 | case wxCURSOR_IBEAM: |
| 133 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 134 | ,(ULONG)SPTR_TEXT |
| 135 | ,FALSE |
| 136 | ); |
| 137 | break; |
| 138 | |
| 139 | case wxCURSOR_CROSS: |
| 140 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 141 | ,(ULONG)SPTR_MOVE |
| 142 | ,FALSE |
| 143 | ); |
| 144 | break; |
| 145 | |
| 146 | case wxCURSOR_SIZENWSE: |
| 147 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 148 | ,(ULONG)SPTR_SIZENWSE |
| 149 | ,FALSE |
| 150 | ); |
| 151 | break; |
| 152 | |
| 153 | case wxCURSOR_SIZENESW: |
| 154 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 155 | ,(ULONG)SPTR_SIZENESW |
| 156 | ,FALSE |
| 157 | ); |
| 158 | break; |
| 159 | |
| 160 | case wxCURSOR_SIZEWE: |
| 161 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 162 | ,(ULONG)SPTR_SIZEWE |
| 163 | ,FALSE |
| 164 | ); |
| 165 | break; |
| 166 | |
| 167 | case wxCURSOR_SIZENS: |
| 168 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 169 | ,(ULONG)SPTR_SIZENS |
| 170 | ,FALSE |
| 171 | ); |
| 172 | break; |
| 173 | |
| 174 | case wxCURSOR_CHAR: |
| 175 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 176 | ,(ULONG)SPTR_ARROW |
| 177 | ,FALSE |
| 178 | ); |
| 179 | break; |
| 180 | |
| 181 | case wxCURSOR_HAND: |
| 182 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 183 | ,0 |
| 184 | ,(ULONG)wxCURSOR_HAND |
| 185 | ); |
| 186 | break; |
| 187 | |
| 188 | case wxCURSOR_BULLSEYE: |
| 189 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 190 | ,0 |
| 191 | ,(ULONG)wxCURSOR_BULLSEYE |
| 192 | ); |
| 193 | break; |
| 194 | |
| 195 | case wxCURSOR_PENCIL: |
| 196 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 197 | ,0 |
| 198 | ,(ULONG)wxCURSOR_PENCIL |
| 199 | ); |
| 200 | break; |
| 201 | |
| 202 | case wxCURSOR_MAGNIFIER: |
| 203 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 204 | ,0 |
| 205 | ,(ULONG)wxCURSOR_MAGNIFIER |
| 206 | ); |
| 207 | break; |
| 208 | |
| 209 | case wxCURSOR_NO_ENTRY: |
| 210 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 211 | ,(ULONG)SPTR_ILLEGAL |
| 212 | ,FALSE |
| 213 | ); |
| 214 | break; |
| 215 | |
| 216 | case wxCURSOR_LEFT_BUTTON: |
| 217 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 218 | ,(ULONG)SPTR_ARROW |
| 219 | ,FALSE |
| 220 | ); |
| 221 | break; |
| 222 | |
| 223 | case wxCURSOR_RIGHT_BUTTON: |
| 224 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 225 | ,(ULONG)SPTR_ARROW |
| 226 | ,FALSE |
| 227 | ); |
| 228 | break; |
| 229 | |
| 230 | case wxCURSOR_MIDDLE_BUTTON: |
| 231 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 232 | ,(ULONG)SPTR_ARROW |
| 233 | ,FALSE |
| 234 | ); |
| 235 | break; |
| 236 | |
| 237 | case wxCURSOR_SIZING: |
| 238 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 239 | ,(ULONG)SPTR_SIZE |
| 240 | ,FALSE |
| 241 | ); |
| 242 | break; |
| 243 | |
| 244 | case wxCURSOR_SPRAYCAN: |
| 245 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 246 | ,0 |
| 247 | ,(ULONG)WXCURSOR_ROLLER |
| 248 | ); |
| 249 | break; |
| 250 | |
| 251 | case wxCURSOR_PAINT_BRUSH: |
| 252 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 253 | ,0 |
| 254 | ,(ULONG)WXCURSOR_PBRUSH |
| 255 | ); |
| 256 | break; |
| 257 | |
| 258 | case wxCURSOR_POINT_LEFT: |
| 259 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 260 | ,0 |
| 261 | ,(ULONG)WXCURSOR_PLEFT |
| 262 | ); |
| 263 | break; |
| 264 | |
| 265 | case wxCURSOR_POINT_RIGHT: |
| 266 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 267 | ,0 |
| 268 | ,(ULONG)WXCURSOR_PRIGHT |
| 269 | ); |
| 270 | break; |
| 271 | |
| 272 | case wxCURSOR_QUESTION_ARROW: |
| 273 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 274 | ,0 |
| 275 | ,(ULONG)WXCURSOR_QARROW |
| 276 | ); |
| 277 | break; |
| 278 | |
| 279 | case wxCURSOR_BLANK: |
| 280 | pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP |
| 281 | ,0 |
| 282 | ,(ULONG)WXCURSOR_BLANK |
| 283 | ); |
| 284 | break; |
| 285 | |
| 286 | default: |
| 287 | case wxCURSOR_ARROW: |
| 288 | pRefData->m_hCursor = (WXHCURSOR) ::WinQuerySysPointer( HWND_DESKTOP |
| 289 | ,(ULONG)SPTR_ARROW |
| 290 | ,FALSE |
| 291 | ); |
| 292 | break; |
| 293 | } |
| 294 | // |
| 295 | // No need to destroy the stock cursors |
| 296 | // |
| 297 | ((wxCursorRefData *)m_refData)->m_bDestroyCursor = false; |
| 298 | } // end of wxCursor::wxCursor |
| 299 | |
| 300 | // Global cursor setting |
| 301 | void wxSetCursor(const wxCursor& cursor) |
| 302 | { |
| 303 | extern wxCursor *g_globalCursor; |
| 304 | |
| 305 | if ( cursor.IsOk() && cursor.GetHCURSOR() ) |
| 306 | { |
| 307 | // ::SetCursor((HCURSOR) cursor.GetHCURSOR()); |
| 308 | |
| 309 | if ( g_globalCursor ) |
| 310 | (*g_globalCursor) = cursor; |
| 311 | } |
| 312 | } |