]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/cursor.h
Recognize VC12 (a.k.a. MSVS 2013) and define __VISUALC12__ for it.
[wxWidgets.git] / interface / wx / cursor.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: cursor.h
e54c96f1 3// Purpose: interface of wxCursor
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxCursor
7c913512 11
23324ae1
FM
12 A cursor is a small bitmap usually used for denoting where the mouse
13 pointer is, with a picture that might indicate the interpretation of a
dc215c81
BP
14 mouse click. As with icons, cursors in X and MS Windows are created in a
15 different manner. Therefore, separate cursors will be created for the
0ef5b1da 16 different environments. Platform-specific methods for creating a wxCursor
dc215c81
BP
17 object are catered for, and this is an occasion where conditional
18 compilation will probably be required (see wxIcon for an example).
7c913512 19
23324ae1 20 A single cursor object may be used in many windows (any subwindow type).
dc215c81
BP
21 The wxWidgets convention is to set the cursor for a window, as in X, rather
22 than to set it globally as in MS Windows, although a global wxSetCursor()
23 function is also available for MS Windows use.
24
25 @section cursor_custom Creating a Custom Cursor
26
27 The following is an example of creating a cursor from 32x32 bitmap data
28 (down_bits) and a mask (down_mask) where 1 is black and 0 is white for the
0ef5b1da
FM
29 bits, and 1 is opaque and 0 is transparent for the mask.
30 It works on Windows and GTK+.
dc215c81
BP
31
32 @code
33 static char down_bits[] = { 255, 255, 255, 255, 31,
34 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
35 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
36 255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
37 255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
38 255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
39 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
40 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
41 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
42 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
43 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
44 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
45 255 };
46
47 static char down_mask[] = { 240, 1, 0, 0, 240, 1,
48 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
49 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
50 31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
51 240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0 };
56
57 #ifdef __WXMSW__
58 wxBitmap down_bitmap(down_bits, 32, 32);
59 wxBitmap down_mask_bitmap(down_mask, 32, 32);
60
61 down_bitmap.SetMask(new wxMask(down_mask_bitmap));
62 wxImage down_image = down_bitmap.ConvertToImage();
63 down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6);
64 down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14);
65 wxCursor down_cursor = wxCursor(down_image);
0ef5b1da 66 #elif defined(__WXGTK__) or defined(__WXMOTIF__)
dc215c81
BP
67 wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
68 down_mask, wxWHITE, wxBLACK);
69 #endif
70 @endcode
7c913512 71
23324ae1
FM
72 @library{wxcore}
73 @category{gdi}
7c913512 74
23324ae1 75 @stdobjects
dc215c81
BP
76 - ::wxNullCursor
77 - ::wxSTANDARD_CURSOR
78 - ::wxHOURGLASS_CURSOR
79 - ::wxCROSS_CURSOR
7c913512 80
0ef5b1da 81 @see wxBitmap, wxIcon, wxWindow::SetCursor(), wxSetCursor(), ::wxStockCursor
23324ae1 82*/
956f3da3 83class wxCursor : public wxGDIObject
23324ae1
FM
84{
85public:
23324ae1 86 /**
dc215c81
BP
87 Default constructor.
88 */
89 wxCursor();
0ef5b1da 90
dc215c81 91 /**
0ef5b1da
FM
92 Constructs a cursor by passing an array of bits (XBM data).
93
94 The parameters @a fg and @a bg have an effect only on GTK+, and force
95 the cursor to use particular background and foreground colours.
dc215c81
BP
96
97 If either @a hotSpotX or @a hotSpotY is -1, the hotspot will be the
98 centre of the cursor image (Motif only).
3c4f71cc 99
7c913512 100 @param bits
0ef5b1da 101 An array of XBM data bits.
7c913512 102 @param width
4cc4bfaf 103 Cursor width.
7c913512 104 @param height
4cc4bfaf 105 Cursor height.
7c913512 106 @param hotSpotX
d6764050 107 Hotspot x coordinate (relative to the top left of the image).
7c913512 108 @param hotSpotY
d6764050 109 Hotspot y coordinate (relative to the top left of the image).
0ef5b1da
FM
110 @param maskBits
111 Bits for a mask bitmap.
112
113 @onlyfor{wxgtk,wxmotif}
1058f652
MB
114
115 @beginWxPerlOnly
116 In wxPerl use Wx::Cursor->newData(bits, width, height, hotSpotX = -1, hotSpotY = -1, maskBits = 0).
117 @endWxPerlOnly
dc215c81
BP
118 */
119 wxCursor(const char bits[], int width, int height,
120 int hotSpotX = -1, int hotSpotY = -1,
0ef5b1da
FM
121 const char maskBits[] = NULL);
122
dc215c81
BP
123 /**
124 Constructs a cursor by passing a string resource name or filename.
3c4f71cc 125
d6764050
FM
126 The arguments @a hotSpotX and @a hotSpotY are only used when there's no
127 hotspot info in the resource/image-file to load (e.g. when using
128 @c wxBITMAP_TYPE_ICO under wxMSW or @c wxBITMAP_TYPE_XPM under wxGTK).
3c4f71cc 129
0ef5b1da
FM
130 @param cursorName
131 The name of the resource or the image file to load.
dc215c81 132 @param type
d6764050 133 Icon type to load. It defaults to @c wxCURSOR_DEFAULT_TYPE,
76e9224e 134 which is a @#define associated to different values on different
0ef5b1da 135 platforms:
d6764050
FM
136 - under Windows, it defaults to @c wxBITMAP_TYPE_CUR_RESOURCE.
137 Other permitted types under Windows are @c wxBITMAP_TYPE_CUR
72bd600b
VZ
138 (to load a cursor from a .cur cursor file), @c wxBITMAP_TYPE_ICO
139 (to load a cursor from a .ico icon file) and @c wxBITMAP_TYPE_ANI
140 (to load a cursor from a .ani icon file).
d6764050
FM
141 - under MacOS, it defaults to @c wxBITMAP_TYPE_MACCURSOR_RESOURCE;
142 when specifying a string resource name, first the color cursors 'crsr'
143 and then the black/white cursors 'CURS' in the resource chain are scanned
cc721f7d
VZ
144 through. Note that resource forks are deprecated on OS X so this
145 is only available for legacy reasons and should not be used in
146 new code.
d6764050
FM
147 - under GTK, it defaults to @c wxBITMAP_TYPE_XPM.
148 See the wxCursor(const wxImage& image) ctor for more info.
149 - under X11, it defaults to @c wxBITMAP_TYPE_XPM.
150 - under Motif, it defaults to @c wxBITMAP_TYPE_XBM.
dc215c81 151 @param hotSpotX
d6764050 152 Hotspot x coordinate (relative to the top left of the image).
dc215c81 153 @param hotSpotY
d6764050 154 Hotspot y coordinate (relative to the top left of the image).
dc215c81 155 */
0ef5b1da
FM
156 wxCursor(const wxString& cursorName,
157 wxBitmapType type = wxCURSOR_DEFAULT_TYPE,
dc215c81 158 int hotSpotX = 0, int hotSpotY = 0);
0ef5b1da 159
dc215c81
BP
160 /**
161 Constructs a cursor using a cursor identifier.
3c4f71cc 162
7c913512 163 @param cursorId
3d2cf884 164 A stock cursor identifier. See ::wxStockCursor.
dc215c81 165 */
3d2cf884 166 wxCursor(wxStockCursor cursorId);
0ef5b1da 167
dc215c81
BP
168 /**
169 Constructs a cursor from a wxImage. If cursor are monochrome on the
170 current platform, colors with the RGB elements all greater than 127
171 will be foreground, colors less than this background. The mask (if any)
172 will be used to specify the transparent area.
3c4f71cc 173
0ef5b1da
FM
174 In wxMSW the foreground will be white and the background black.
175 If the cursor is larger than 32x32 it is resized.
3c4f71cc 176
dc215c81
BP
177 In wxGTK, colour cursors and alpha channel are supported (starting from
178 GTK+ 2.2). Otherwise the two most frequent colors will be used for
0ef5b1da
FM
179 foreground and background. In any case, the cursor will be displayed
180 at the size of the image.
3c4f71cc 181
3ecb578a 182 Under wxMac (Cocoa), large cursors are supported.
bb65ca31
VZ
183
184 Notice that the @a image can define the cursor hot spot. To set it you
185 need to use wxImage::SetOption() with @c wxIMAGE_OPTION_CUR_HOTSPOT_X
186 or @c wxIMAGE_OPTION_CUR_HOTSPOT_Y, e.g.
187 @code
188 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX);
189 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotY);
190 @endcode
dc215c81
BP
191 */
192 wxCursor(const wxImage& image);
0ef5b1da 193
dc215c81
BP
194 /**
195 Copy constructor, uses @ref overview_refcount "reference counting".
3c4f71cc 196
7c913512 197 @param cursor
4cc4bfaf 198 Pointer or reference to a cursor to copy.
23324ae1 199 */
7c913512 200 wxCursor(const wxCursor& cursor);
23324ae1
FM
201
202 /**
dc215c81
BP
203 Destroys the cursor. See
204 @ref overview_refcount_destruct "reference-counted object destruction"
205 for more info.
206
207 A cursor can be reused for more than one window, and does not get
208 destroyed when the window is destroyed. wxWidgets destroys all cursors
209 on application exit, although it is best to clean them up explicitly.
23324ae1 210 */
b7e94bd7 211 virtual ~wxCursor();
23324ae1
FM
212
213 /**
214 Returns @true if cursor data is present.
215 */
0004982c 216 virtual bool IsOk() const;
23324ae1
FM
217
218 /**
dc215c81 219 Assignment operator, using @ref overview_refcount "reference counting".
23324ae1 220 */
0ef5b1da 221 wxCursor& operator =(const wxCursor& cursor);
23324ae1 222};
e54c96f1 223
e54c96f1 224
3d2cf884
BP
225/**
226 @name Predefined cursors.
227
228 @see wxStockCursor
229*/
dc215c81
BP
230//@{
231wxCursor wxNullCursor;
232wxCursor* wxSTANDARD_CURSOR;
233wxCursor* wxHOURGLASS_CURSOR;
234wxCursor* wxCROSS_CURSOR;
235//@}
e54c96f1 236