]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/cursor.h
few details fixed
[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$
6// Licence: wxWindows license
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
16 different environments. Platform-specific methods for creating a wxCursor
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
29 bits, and 1 is opaque and 0 is transparent for the mask. It works on
30 Windows and GTK+.
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);
66 #else
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
3d2cf884
BP
81 @see wxBitmap, wxIcon, wxWindow::SetCursor(), wxSetCursor(),
82 ::wxStockCursor
23324ae1
FM
83*/
84class wxCursor : public wxBitmap
85{
86public:
23324ae1 87 /**
dc215c81
BP
88 Default constructor.
89 */
90 wxCursor();
91 /**
92 Constructs a cursor by passing an array of bits (Motif and GTK+ only).
93 @a maskBits is used only under Motif and GTK+. The parameters @a fg and
94 @a bg are only present on GTK+, and force the cursor to use particular
95 background and foreground colours.
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
4cc4bfaf 101 An array of bits.
7c913512 102 @param maskBits
4cc4bfaf 103 Bits for a mask bitmap.
7c913512 104 @param width
4cc4bfaf 105 Cursor width.
7c913512 106 @param height
4cc4bfaf 107 Cursor height.
7c913512 108 @param hotSpotX
4cc4bfaf 109 Hotspot x coordinate.
7c913512 110 @param hotSpotY
4cc4bfaf 111 Hotspot y coordinate.
dc215c81
BP
112 */
113 wxCursor(const char bits[], int width, int height,
114 int hotSpotX = -1, int hotSpotY = -1,
115 const char maskBits[] = NULL,
116 wxColour* fg = NULL, wxColour* bg = NULL);
117 /**
118 Constructs a cursor by passing a string resource name or filename.
3c4f71cc 119
dc215c81
BP
120 On MacOS when specifying a string resource name, first the color
121 cursors 'crsr' and then the black/white cursors 'CURS' in the resource
122 chain are scanned through.
3c4f71cc 123
dc215c81
BP
124 @a hotSpotX and @a hotSpotY are currently only used under Windows when
125 loading from an icon file, to specify the cursor hotspot relative to
126 the top left of the image.
3c4f71cc 127
dc215c81
BP
128 @param type
129 Icon type to load. Under Motif, type defaults to wxBITMAP_TYPE_XBM.
130 Under Windows, it defaults to wxBITMAP_TYPE_CUR_RESOURCE. Under
131 MacOS, it defaults to wxBITMAP_TYPE_MACCURSOR_RESOURCE.
132 Under X, the permitted cursor types are:
133 <ul>
134 <li>wxBITMAP_TYPE_XBM - Load an X bitmap file.</li>
135 </ul>
4cc4bfaf 136 Under Windows, the permitted types are:
dc215c81
BP
137 - wxBITMAP_TYPE_CUR - Load a cursor from a .cur cursor file (only
138 if USE_RESOURCE_LOADING_IN_MSW is enabled in
139 setup.h).
140 - wxBITMAP_TYPE_CUR_RESOURCE - Load a Windows resource (as
141 specified in the .rc file).
142 - wxBITMAP_TYPE_ICO - Load a cursor from a .ico icon file (only if
143 USE_RESOURCE_LOADING_IN_MSW is enabled in
144 setup.h). Specify @a hotSpotX and @a hotSpotY.
145 @param hotSpotX
146 Hotspot x coordinate.
147 @param hotSpotY
148 Hotspot y coordinate.
149 */
150 wxCursor(const wxString& cursorName, long type,
151 int hotSpotX = 0, int hotSpotY = 0);
152 /**
153 Constructs a cursor using a cursor identifier.
3c4f71cc 154
7c913512 155 @param cursorId
3d2cf884 156 A stock cursor identifier. See ::wxStockCursor.
dc215c81 157 */
3d2cf884 158 wxCursor(wxStockCursor cursorId);
dc215c81
BP
159 /**
160 Constructs a cursor from a wxImage. If cursor are monochrome on the
161 current platform, colors with the RGB elements all greater than 127
162 will be foreground, colors less than this background. The mask (if any)
163 will be used to specify the transparent area.
3c4f71cc 164
dc215c81
BP
165 In wxMSW the foreground will be white and the background black. If the
166 cursor is larger than 32x32 it is resized.
3c4f71cc 167
dc215c81
BP
168 In wxGTK, colour cursors and alpha channel are supported (starting from
169 GTK+ 2.2). Otherwise the two most frequent colors will be used for
170 foreground and background. In any case, the cursor will be displayed at
171 the size of the image.
3c4f71cc 172
dc215c81
BP
173 In wxMac, if the cursor is larger than 16x16 it is resized and
174 currently only shown as black/white (mask respected).
175 */
176 wxCursor(const wxImage& image);
177 /**
178 Copy constructor, uses @ref overview_refcount "reference counting".
3c4f71cc 179
7c913512 180 @param cursor
4cc4bfaf 181 Pointer or reference to a cursor to copy.
23324ae1 182 */
7c913512 183 wxCursor(const wxCursor& cursor);
23324ae1
FM
184
185 /**
dc215c81
BP
186 Destroys the cursor. See
187 @ref overview_refcount_destruct "reference-counted object destruction"
188 for more info.
189
190 A cursor can be reused for more than one window, and does not get
191 destroyed when the window is destroyed. wxWidgets destroys all cursors
192 on application exit, although it is best to clean them up explicitly.
23324ae1
FM
193 */
194 ~wxCursor();
195
196 /**
197 Returns @true if cursor data is present.
198 */
328f5751 199 bool IsOk() const;
23324ae1
FM
200
201 /**
dc215c81 202 Assignment operator, using @ref overview_refcount "reference counting".
23324ae1
FM
203 */
204 wxCursor operator =(const wxCursor& cursor);
205};
e54c96f1 206
e54c96f1 207
3d2cf884
BP
208/**
209 @name Predefined cursors.
210
211 @see wxStockCursor
212*/
dc215c81
BP
213//@{
214wxCursor wxNullCursor;
215wxCursor* wxSTANDARD_CURSOR;
216wxCursor* wxHOURGLASS_CURSOR;
217wxCursor* wxCROSS_CURSOR;
218//@}
e54c96f1 219