2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: cursor.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxCursor
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxCursor
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A cursor is a small bitmap usually used for denoting where the mouse
|
|
|
|
pointer is, with a picture that might indicate the interpretation of a
|
2008-04-14 01:36:08 -04:00
|
|
|
mouse click. As with icons, cursors in X and MS Windows are created in a
|
|
|
|
different manner. Therefore, separate cursors will be created for the
|
2008-09-25 13:56:07 -04:00
|
|
|
different environments. Platform-specific methods for creating a wxCursor
|
2008-04-14 01:36:08 -04:00
|
|
|
object are catered for, and this is an occasion where conditional
|
|
|
|
compilation will probably be required (see wxIcon for an example).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A single cursor object may be used in many windows (any subwindow type).
|
2008-04-14 01:36:08 -04:00
|
|
|
The wxWidgets convention is to set the cursor for a window, as in X, rather
|
|
|
|
than to set it globally as in MS Windows, although a global wxSetCursor()
|
|
|
|
function is also available for MS Windows use.
|
|
|
|
|
|
|
|
@section cursor_custom Creating a Custom Cursor
|
|
|
|
|
|
|
|
The following is an example of creating a cursor from 32x32 bitmap data
|
|
|
|
(down_bits) and a mask (down_mask) where 1 is black and 0 is white for the
|
2008-09-25 13:56:07 -04:00
|
|
|
bits, and 1 is opaque and 0 is transparent for the mask.
|
|
|
|
It works on Windows and GTK+.
|
2008-04-14 01:36:08 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
static char down_bits[] = { 255, 255, 255, 255, 31,
|
|
|
|
255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
|
|
|
|
31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
|
|
|
|
255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
|
|
|
|
255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
|
|
|
|
255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
|
|
255 };
|
|
|
|
|
|
|
|
static char down_mask[] = { 240, 1, 0, 0, 240, 1,
|
|
|
|
0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
|
|
|
|
0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
|
|
|
|
31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
|
|
|
|
240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
wxBitmap down_bitmap(down_bits, 32, 32);
|
|
|
|
wxBitmap down_mask_bitmap(down_mask, 32, 32);
|
|
|
|
|
|
|
|
down_bitmap.SetMask(new wxMask(down_mask_bitmap));
|
|
|
|
wxImage down_image = down_bitmap.ConvertToImage();
|
|
|
|
down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6);
|
|
|
|
down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14);
|
|
|
|
wxCursor down_cursor = wxCursor(down_image);
|
2008-09-25 13:56:07 -04:00
|
|
|
#elif defined(__WXGTK__) or defined(__WXMOTIF__)
|
2008-04-14 01:36:08 -04:00
|
|
|
wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
|
|
|
|
down_mask, wxWHITE, wxBLACK);
|
|
|
|
#endif
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{gdi}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@stdobjects
|
2008-04-14 01:36:08 -04:00
|
|
|
- ::wxNullCursor
|
|
|
|
- ::wxSTANDARD_CURSOR
|
|
|
|
- ::wxHOURGLASS_CURSOR
|
|
|
|
- ::wxCROSS_CURSOR
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 13:56:07 -04:00
|
|
|
@see wxBitmap, wxIcon, wxWindow::SetCursor(), wxSetCursor(), ::wxStockCursor
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-22 05:52:28 -05:00
|
|
|
class wxCursor : public wxGDIObject
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-14 01:36:08 -04:00
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxCursor();
|
2008-09-25 13:56:07 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
/**
|
2008-09-25 13:56:07 -04:00
|
|
|
Constructs a cursor by passing an array of bits (XBM data).
|
|
|
|
|
|
|
|
The parameters @a fg and @a bg have an effect only on GTK+, and force
|
|
|
|
the cursor to use particular background and foreground colours.
|
2008-04-14 01:36:08 -04:00
|
|
|
|
|
|
|
If either @a hotSpotX or @a hotSpotY is -1, the hotspot will be the
|
|
|
|
centre of the cursor image (Motif only).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param bits
|
2008-09-25 13:56:07 -04:00
|
|
|
An array of XBM data bits.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param width
|
2008-03-09 08:33:59 -04:00
|
|
|
Cursor width.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param height
|
2008-03-09 08:33:59 -04:00
|
|
|
Cursor height.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param hotSpotX
|
2009-05-16 06:42:48 -04:00
|
|
|
Hotspot x coordinate (relative to the top left of the image).
|
2008-03-08 09:43:31 -05:00
|
|
|
@param hotSpotY
|
2009-05-16 06:42:48 -04:00
|
|
|
Hotspot y coordinate (relative to the top left of the image).
|
2008-09-25 13:56:07 -04:00
|
|
|
@param maskBits
|
|
|
|
Bits for a mask bitmap.
|
|
|
|
|
|
|
|
@onlyfor{wxgtk,wxmotif}
|
2009-10-18 13:47:01 -04:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
In wxPerl use Wx::Cursor->newData(bits, width, height, hotSpotX = -1, hotSpotY = -1, maskBits = 0).
|
|
|
|
@endWxPerlOnly
|
2008-04-14 01:36:08 -04:00
|
|
|
*/
|
|
|
|
wxCursor(const char bits[], int width, int height,
|
|
|
|
int hotSpotX = -1, int hotSpotY = -1,
|
2008-09-25 13:56:07 -04:00
|
|
|
const char maskBits[] = NULL);
|
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
/**
|
|
|
|
Constructs a cursor by passing a string resource name or filename.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-05-16 06:42:48 -04:00
|
|
|
The arguments @a hotSpotX and @a hotSpotY are only used when there's no
|
|
|
|
hotspot info in the resource/image-file to load (e.g. when using
|
|
|
|
@c wxBITMAP_TYPE_ICO under wxMSW or @c wxBITMAP_TYPE_XPM under wxGTK).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-25 13:56:07 -04:00
|
|
|
@param cursorName
|
|
|
|
The name of the resource or the image file to load.
|
2008-04-14 01:36:08 -04:00
|
|
|
@param type
|
2009-05-16 06:42:48 -04:00
|
|
|
Icon type to load. It defaults to @c wxCURSOR_DEFAULT_TYPE,
|
2008-10-04 16:49:51 -04:00
|
|
|
which is a @#define associated to different values on different
|
2008-09-25 13:56:07 -04:00
|
|
|
platforms:
|
2009-05-16 06:42:48 -04:00
|
|
|
- under Windows, it defaults to @c wxBITMAP_TYPE_CUR_RESOURCE.
|
|
|
|
Other permitted types under Windows are @c wxBITMAP_TYPE_CUR
|
|
|
|
(to load a cursor from a .cur cursor file) and @c wxBITMAP_TYPE_ICO
|
|
|
|
(to load a cursor from a .ico icon file).
|
|
|
|
- under MacOS, it defaults to @c wxBITMAP_TYPE_MACCURSOR_RESOURCE;
|
|
|
|
when specifying a string resource name, first the color cursors 'crsr'
|
|
|
|
and then the black/white cursors 'CURS' in the resource chain are scanned
|
2010-10-25 17:52:19 -04:00
|
|
|
through. Note that resource forks are deprecated on OS X so this
|
|
|
|
is only available for legacy reasons and should not be used in
|
|
|
|
new code.
|
2009-05-16 06:42:48 -04:00
|
|
|
- under GTK, it defaults to @c wxBITMAP_TYPE_XPM.
|
|
|
|
See the wxCursor(const wxImage& image) ctor for more info.
|
|
|
|
- under X11, it defaults to @c wxBITMAP_TYPE_XPM.
|
|
|
|
- under Motif, it defaults to @c wxBITMAP_TYPE_XBM.
|
2008-04-14 01:36:08 -04:00
|
|
|
@param hotSpotX
|
2009-05-16 06:42:48 -04:00
|
|
|
Hotspot x coordinate (relative to the top left of the image).
|
2008-04-14 01:36:08 -04:00
|
|
|
@param hotSpotY
|
2009-05-16 06:42:48 -04:00
|
|
|
Hotspot y coordinate (relative to the top left of the image).
|
2008-04-14 01:36:08 -04:00
|
|
|
*/
|
2008-09-25 13:56:07 -04:00
|
|
|
wxCursor(const wxString& cursorName,
|
|
|
|
wxBitmapType type = wxCURSOR_DEFAULT_TYPE,
|
2008-04-14 01:36:08 -04:00
|
|
|
int hotSpotX = 0, int hotSpotY = 0);
|
2008-09-25 13:56:07 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
/**
|
|
|
|
Constructs a cursor using a cursor identifier.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param cursorId
|
2008-05-02 00:12:39 -04:00
|
|
|
A stock cursor identifier. See ::wxStockCursor.
|
2008-04-14 01:36:08 -04:00
|
|
|
*/
|
2008-05-02 00:12:39 -04:00
|
|
|
wxCursor(wxStockCursor cursorId);
|
2008-09-25 13:56:07 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
/**
|
|
|
|
Constructs a cursor from a wxImage. If cursor are monochrome on the
|
|
|
|
current platform, colors with the RGB elements all greater than 127
|
|
|
|
will be foreground, colors less than this background. The mask (if any)
|
|
|
|
will be used to specify the transparent area.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-09-25 13:56:07 -04:00
|
|
|
In wxMSW the foreground will be white and the background black.
|
|
|
|
If the cursor is larger than 32x32 it is resized.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
In wxGTK, colour cursors and alpha channel are supported (starting from
|
|
|
|
GTK+ 2.2). Otherwise the two most frequent colors will be used for
|
2008-09-25 13:56:07 -04:00
|
|
|
foreground and background. In any case, the cursor will be displayed
|
|
|
|
at the size of the image.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
In wxMac, if the cursor is larger than 16x16 it is resized and
|
|
|
|
currently only shown as black/white (mask respected).
|
|
|
|
*/
|
|
|
|
wxCursor(const wxImage& image);
|
2008-09-25 13:56:07 -04:00
|
|
|
|
2008-04-14 01:36:08 -04:00
|
|
|
/**
|
|
|
|
Copy constructor, uses @ref overview_refcount "reference counting".
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param cursor
|
2008-03-09 08:33:59 -04:00
|
|
|
Pointer or reference to a cursor to copy.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxCursor(const wxCursor& cursor);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-14 01:36:08 -04:00
|
|
|
Destroys the cursor. See
|
|
|
|
@ref overview_refcount_destruct "reference-counted object destruction"
|
|
|
|
for more info.
|
|
|
|
|
|
|
|
A cursor can be reused for more than one window, and does not get
|
|
|
|
destroyed when the window is destroyed. wxWidgets destroys all cursors
|
|
|
|
on application exit, although it is best to clean them up explicitly.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-22 15:01:17 -04:00
|
|
|
virtual ~wxCursor();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if cursor data is present.
|
|
|
|
*/
|
2008-10-13 07:09:56 -04:00
|
|
|
virtual bool IsOk() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-14 01:36:08 -04:00
|
|
|
Assignment operator, using @ref overview_refcount "reference counting".
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-25 13:56:07 -04:00
|
|
|
wxCursor& operator =(const wxCursor& cursor);
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
|
|
|
|
2008-05-02 00:12:39 -04:00
|
|
|
/**
|
|
|
|
@name Predefined cursors.
|
|
|
|
|
|
|
|
@see wxStockCursor
|
|
|
|
*/
|
2008-04-14 01:36:08 -04:00
|
|
|
//@{
|
|
|
|
wxCursor wxNullCursor;
|
|
|
|
wxCursor* wxSTANDARD_CURSOR;
|
|
|
|
wxCursor* wxHOURGLASS_CURSOR;
|
|
|
|
wxCursor* wxCROSS_CURSOR;
|
|
|
|
//@}
|
2008-03-10 11:24:38 -04:00
|
|
|
|