]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/cursor.tex
added wxDataViewModel::HasContainerColumns
[wxWidgets.git] / docs / latex / wx / cursor.tex
1 \section{\class{wxCursor}}\label{wxcursor}
2
3 A cursor is a small bitmap usually used for denoting where the mouse
4 pointer is, with a picture that might indicate the interpretation of a
5 mouse click. As with icons, cursors in X and MS Windows are created
6 in a different manner. Therefore, separate cursors will be created for the
7 different environments. Platform-specific methods for creating a {\bf
8 wxCursor} object are catered for, and this is an occasion where
9 conditional compilation will probably be required (see \helpref{wxIcon}{wxicon} for
10 an example).
11
12 A single cursor object may be used in many windows (any subwindow type).
13 The wxWidgets convention is to set the cursor for a window, as in X,
14 rather than to set it globally as in MS Windows, although a
15 global \helpref{::wxSetCursor}{wxsetcursor} is also available for MS Windows use.
16
17 \wxheading{Derived from}
18
19 \helpref{wxBitmap}{wxbitmap}\\
20 \helpref{wxGDIObject}{wxgdiobject}\\
21 \helpref{wxObject}{wxobject}
22
23 \wxheading{Include files}
24
25 <wx/cursor.h>
26
27 \wxheading{Library}
28
29 \helpref{wxCore}{librarieslist}
30
31 \wxheading{Predefined objects}
32
33 Objects:
34
35 {\bf wxNullCursor}
36
37 Pointers:
38
39 {\bf wxSTANDARD\_CURSOR\\
40 wxHOURGLASS\_CURSOR\\
41 wxCROSS\_CURSOR}
42
43 \wxheading{See also}
44
45 \helpref{wxBitmap}{wxbitmap}, \helpref{wxIcon}{wxicon}, \helpref{wxWindow::SetCursor}{wxwindowsetcursor},\rtfsp
46 \helpref{::wxSetCursor}{wxsetcursor}
47
48 \latexignore{\rtfignore{\wxheading{Members}}}
49
50 \membersection{wxCursor::wxCursor}\label{wxcursorctor}
51
52 \func{}{wxCursor}{\void}
53
54 Default constructor.
55
56 \func{}{wxCursor}{\param{const char}{ bits[]}, \param{int }{width},
57 \param{int }{ height}, \param{int }{hotSpotX=-1}, \param{int }{hotSpotY=-1}, \param{const char }{maskBits[]=NULL},
58 \param{wxColour*}{ fg=NULL}, \param{wxColour*}{ bg=NULL}}
59
60 Constructs a cursor by passing an array of bits (Motif and GTK+ only). {\it maskBits} is used only under
61 Motif and GTK+. The parameters {\it fg} and {\it bg} are only present on GTK+, and force the
62 cursor to use particular background and foreground colours.
63
64 If either {\it hotSpotX} or {\it hotSpotY} is -1, the hotspot will be the centre of the cursor image (Motif only).
65
66 \func{}{wxCursor}{\param{const wxString\& }{cursorName}, \param{long }{type}, \param{int }{hotSpotX=0}, \param{int }{hotSpotY=0}}
67
68 Constructs a cursor by passing a string resource name or filename.
69
70 On MacOS when specifying a string resource name, first the color cursors 'crsr' and then the black/white cursors 'CURS' in the resource chain are scanned through.
71
72 {\it hotSpotX} and {\it hotSpotY} are currently only used under Windows when loading from an
73 icon file, to specify the cursor hotspot relative to the top left of the image.
74
75 \func{}{wxCursor}{\param{int}{ cursorId}}
76
77 Constructs a cursor using a cursor identifier.
78
79 \func{}{wxCursor}{\param{const wxImage\&}{ image}}
80
81 Constructs a cursor from a wxImage. If cursor are monochrome on the current
82 platform, colors with the RGB elements all greater than 127 will be foreground,
83 colors less than this background. The mask (if any) will be used to specify the
84 transparent area.
85
86 In wxMSW the foreground will be white and the background black. If the cursor
87 is larger than 32x32 it is resized.
88
89 In wxGTK, colour cursors and alpha channel are supported (starting from GTK+
90 2.2). Otherwise the two most frequent colors will be used for foreground and
91 background. In any case, the cursor will be displayed at the size of the image.
92
93 In wxMac, if the cursor is larger than 16x16 it is resized and currently only
94 shown as black/white (mask respected).
95
96 \func{}{wxCursor}{\param{const wxCursor\&}{ cursor}}
97
98 Copy constructor, uses \helpref{reference counting}{trefcount}.
99
100 \wxheading{Parameters}
101
102 \docparam{bits}{An array of bits.}
103
104 \docparam{maskBits}{Bits for a mask bitmap.}
105
106 \docparam{width}{Cursor width.}
107
108 \docparam{height}{Cursor height.}
109
110 \docparam{hotSpotX}{Hotspot x coordinate.}
111
112 \docparam{hotSpotY}{Hotspot y coordinate.}
113
114 \docparam{type}{Icon type to load. Under Motif, {\it type} defaults to {\bf wxBITMAP\_TYPE\_XBM}. Under Windows,
115 it defaults to {\bf wxBITMAP\_TYPE\_CUR\_RESOURCE}. Under MacOS, it defaults to {\bf wxBITMAP\_TYPE\_MACCURSOR\_RESOURCE}.
116
117 Under X, the permitted cursor types are:
118
119 \twocolwidtha{6cm}
120 \begin{twocollist}\itemsep=0pt
121 \twocolitem{\windowstyle{wxBITMAP\_TYPE\_XBM}}{Load an X bitmap file.}
122 \end{twocollist}
123
124 Under Windows, the permitted types are:
125
126 \twocolwidtha{6cm}
127 \begin{twocollist}\itemsep=0pt
128 \twocolitem{\windowstyle{wxBITMAP\_TYPE\_CUR}}{Load a cursor from a .cur cursor file (only if USE\_RESOURCE\_LOADING\_IN\_MSW
129 is enabled in setup.h).}
130 \twocolitem{\windowstyle{wxBITMAP\_TYPE\_CUR\_RESOURCE}}{Load a Windows resource (as specified in the .rc file).}
131 \twocolitem{\windowstyle{wxBITMAP\_TYPE\_ICO}}{Load a cursor from a .ico icon file (only if USE\_RESOURCE\_LOADING\_IN\_MSW
132 is enabled in setup.h). Specify {\it hotSpotX} and {\it hotSpotY}.}
133 \end{twocollist}}
134
135 \docparam{cursorId}{A stock cursor identifier. May be one of:
136
137 \twocolwidtha{6cm}
138 \begin{twocollist}\itemsep=0pt
139 \twocolitem{{\bf wxCURSOR\_ARROW}}{A standard arrow cursor.}
140 \twocolitem{{\bf wxCURSOR\_RIGHT\_ARROW}}{A standard arrow cursor
141 pointing to the right.}
142 \twocolitem{{\bf wxCURSOR\_BLANK}}{Transparent cursor.}
143 \twocolitem{{\bf wxCURSOR\_BULLSEYE}}{Bullseye cursor.}
144 \twocolitem{{\bf wxCURSOR\_CHAR}}{Rectangular character cursor.}
145 \twocolitem{{\bf wxCURSOR\_CROSS}}{A cross cursor.}
146 \twocolitem{{\bf wxCURSOR\_HAND}}{A hand cursor.}
147 \twocolitem{{\bf wxCURSOR\_IBEAM}}{An I-beam cursor (vertical line).}
148 \twocolitem{{\bf wxCURSOR\_LEFT\_BUTTON}}{Represents a mouse with the left button depressed.}
149 \twocolitem{{\bf wxCURSOR\_MAGNIFIER}}{A magnifier icon.}
150 \twocolitem{{\bf wxCURSOR\_MIDDLE\_BUTTON}}{Represents a mouse with the middle button depressed.}
151 \twocolitem{{\bf wxCURSOR\_NO\_ENTRY}}{A no-entry sign cursor.}
152 \twocolitem{{\bf wxCURSOR\_PAINT\_BRUSH}}{A paintbrush cursor.}
153 \twocolitem{{\bf wxCURSOR\_PENCIL}}{A pencil cursor.}
154 \twocolitem{{\bf wxCURSOR\_POINT\_LEFT}}{A cursor that points left.}
155 \twocolitem{{\bf wxCURSOR\_POINT\_RIGHT}}{A cursor that points right.}
156 \twocolitem{{\bf wxCURSOR\_QUESTION\_ARROW}}{An arrow and question mark.}
157 \twocolitem{{\bf wxCURSOR\_RIGHT\_BUTTON}}{Represents a mouse with the right button depressed.}
158 \twocolitem{{\bf wxCURSOR\_SIZENESW}}{A sizing cursor pointing NE-SW.}
159 \twocolitem{{\bf wxCURSOR\_SIZENS}}{A sizing cursor pointing N-S.}
160 \twocolitem{{\bf wxCURSOR\_SIZENWSE}}{A sizing cursor pointing NW-SE.}
161 \twocolitem{{\bf wxCURSOR\_SIZEWE}}{A sizing cursor pointing W-E.}
162 \twocolitem{{\bf wxCURSOR\_SIZING}}{A general sizing cursor.}
163 \twocolitem{{\bf wxCURSOR\_SPRAYCAN}}{A spraycan cursor.}
164 \twocolitem{{\bf wxCURSOR\_WAIT}}{A wait cursor.}
165 \twocolitem{{\bf wxCURSOR\_WATCH}}{A watch cursor.}
166 \twocolitem{{\bf wxCURSOR\_ARROWWAIT}}{A cursor with both an arrow and
167 an hourglass, (windows.)}
168 \end{twocollist}\twocolwidtha{5cm}
169
170 Note that not all cursors are available on all platforms.}
171
172 \docparam{cursor}{Pointer or reference to a cursor to copy.}
173
174 \pythonnote{Constructors supported by wxPython are:\par
175 \indented{2cm}{\begin{twocollist}
176 \twocolitem{{\bf wxCursor(name, flags, hotSpotX=0,
177 hotSpotY=0)}}{Constructs a cursor from a filename}
178 \twocolitem{{\bf wxStockCursor(id)}}{Constructs a stock cursor }
179 \end{twocollist}}
180 }
181
182 \perlnote{Constructors supported by wxPerl are:\par
183 \begin{itemize}
184 \item{Wx::Cursor->new( name, type, hotSpotX = 0, hotSpotY = 0 )}
185 \item{Wx::Cursor->new( id )}
186 \item{Wx::Cursor->new( image )}
187 \item{Wx::Cursor->newData( bits, width, height, hotSpotX = -1, hotSpotY = -1, maskBits = 0 )}
188 \end{itemize}
189 }
190
191 \wxheading{Example}
192
193 The following is an example of creating a
194 cursor from 32x32 bitmap data ({\tt down\_bits}) and a mask
195 ({\tt down\_mask}) where 1 is black and 0 is white for
196 the bits, and 1 is opaque and 0 is transparent for
197 the mask. It works on Windows and GTK+.
198
199 \begin{verbatim}
200 static char down_bits[] = { 255, 255, 255, 255, 31,
201 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
202 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
203 255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
204 255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
205 255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
206 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
207 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
208 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
209 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
210 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
211 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
212 255 };
213
214 static char down_mask[] = { 240, 1, 0, 0, 240, 1,
215 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
216 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
217 31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
218 240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0 };
223
224 #ifdef __WXMSW__
225 wxBitmap down_bitmap(down_bits, 32, 32);
226 wxBitmap down_mask_bitmap(down_mask, 32, 32);
227
228 down_bitmap.SetMask(new wxMask(down_mask_bitmap));
229 wxImage down_image = down_bitmap.ConvertToImage();
230 down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6);
231 down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14);
232 wxCursor down_cursor = wxCursor(down_image);
233 #else
234 wxCursor down_cursor = wxCursor(down_bits, 32, 32,
235 6, 14, down_mask, wxWHITE, wxBLACK);
236 #endif
237 \end{verbatim}
238
239 \membersection{wxCursor::\destruct{wxCursor}}\label{wxcursordtor}
240
241 \func{}{\destruct{wxCursor}}{\void}
242
243 Destroys the cursor.
244 See \helpref{reference-counted object destruction}{refcountdestruct} for more info.
245
246 A cursor can be reused for more
247 than one window, and does not get destroyed when the window is
248 destroyed. wxWidgets destroys all cursors on application exit, although
249 it is best to clean them up explicitly.
250
251 \membersection{wxCursor::IsOk}\label{wxcursorisok}
252
253 \constfunc{bool}{IsOk}{\void}
254
255 Returns true if cursor data is present.
256
257 \membersection{wxCursor::operator $=$}\label{wxcursorassignment}
258
259 \func{wxCursor\&}{operator $=$}{\param{const wxCursor\& }{cursor}}
260
261 Assignment operator, using \helpref{reference counting}{trefcount}.
262