From 0ef5b1dad1f5d18309d0fdc0b36ad383b58f1a2e Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Thu, 25 Sep 2008 17:56:07 +0000 Subject: [PATCH] provide backward-compat wxCursor(int) ctor; remove empty stubs of XBM ctor from all ports except gtk,motif; make all ports emit wxLogError on invalid bitmap types; implement wxCursor(const wxString&, ...) ctor on GTK (not tested yet) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55884 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/cursor.h | 13 ++++--- include/wx/cursor.h | 11 ++++++ include/wx/dfb/cursor.h | 12 +++--- include/wx/gtk/cursor.h | 10 ++++- include/wx/gtk1/cursor.h | 18 ++++++++- include/wx/mgl/cursor.h | 12 +++--- include/wx/motif/cursor.h | 16 ++++++-- include/wx/msw/cursor.h | 12 +++--- include/wx/os2/cursor.h | 15 +++---- include/wx/osx/carbon/cursor.h | 13 ++++--- include/wx/palmos/cursor.h | 11 +++--- include/wx/x11/cursor.h | 13 +++++-- interface/wx/cursor.h | 71 ++++++++++++++++++++-------------- src/dfb/cursor.cpp | 14 +------ src/gtk/cursor.cpp | 44 ++++++++++++++++++++- src/gtk1/cursor.cpp | 2 +- src/mgl/cursor.cpp | 16 ++------ src/motif/cursor.cpp | 9 +++-- src/msw/cursor.cpp | 21 ++-------- src/os2/cursor.cpp | 19 +++------ src/osx/carbon/cursor.cpp | 7 +--- src/palmos/cursor.cpp | 12 +----- src/x11/cursor.cpp | 12 +++--- 23 files changed, 216 insertions(+), 167 deletions(-) diff --git a/include/wx/cocoa/cursor.h b/include/wx/cocoa/cursor.h index df2c381ca1..f6b70f10c2 100644 --- a/include/wx/cocoa/cursor.h +++ b/include/wx/cocoa/cursor.h @@ -39,14 +39,13 @@ class WXDLLIMPEXP_CORE wxCursor: public wxBitmap public: wxCursor(); - wxCursor(const char bits[], int width, int height, - int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); - - wxCursor(const wxString& name, long flags = 0, + wxCursor(const wxString& name, wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); - wxCursor(wxStockCursor cursor_type); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif virtual ~wxCursor(); // FIXME: operator==() is wrong! @@ -55,6 +54,8 @@ public: WX_NSCursor GetNSCursor() const { return M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0; } +private: + void InitFromStock(wxStockCursor); DECLARE_DYNAMIC_CLASS(wxCursor) }; diff --git a/include/wx/cursor.h b/include/wx/cursor.h index 893f9fe575..f4c584fbcf 100644 --- a/include/wx/cursor.h +++ b/include/wx/cursor.h @@ -15,26 +15,37 @@ #include "wx/defs.h" #if defined(__WXPALMOS__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE #include "wx/palmos/cursor.h" #elif defined(__WXMSW__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE #include "wx/msw/cursor.h" #elif defined(__WXMOTIF__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XBM #include "wx/motif/cursor.h" #elif defined(__WXGTK20__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM #include "wx/gtk/cursor.h" #elif defined(__WXGTK__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM #include "wx/gtk1/cursor.h" #elif defined(__WXX11__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_XPM #include "wx/x11/cursor.h" #elif defined(__WXMGL__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE #include "wx/mgl/cursor.h" #elif defined(__WXDFB__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE #include "wx/dfb/cursor.h" #elif defined(__WXMAC__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_MACCURSOR_RESOURCE #include "wx/osx/cursor.h" #elif defined(__WXCOCOA__) + #define wxCURSOR_DEFAULT_TYPE 0 #include "wx/cocoa/cursor.h" #elif defined(__WXPM__) + #define wxCURSOR_DEFAULT_TYPE wxBITMAP_TYPE_CUR_RESOURCE #include "wx/os2/cursor.h" #endif diff --git a/include/wx/dfb/cursor.h b/include/wx/dfb/cursor.h index 118d856716..0a22bb67b8 100644 --- a/include/wx/dfb/cursor.h +++ b/include/wx/dfb/cursor.h @@ -24,18 +24,20 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: wxCursor() {} - wxCursor(wxStockCursor cursorId); - wxCursor(const char bits[], int width, int height, - int hotSpotX=-1, int hotSpotY=-1, - const char maskBits[]=0, wxColour *fg=0, wxColour *bg=0); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif wxCursor(const wxString& name, - long flags = wxBITMAP_TYPE_CUR_RESOURCE, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); // implementation wxBitmap GetBitmap() const; protected: + void InitFromStock(wxStockCursor); + // ref counting code virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/include/wx/gtk/cursor.h b/include/wx/gtk/cursor.h index 3d93d7b471..7c2021b8ad 100644 --- a/include/wx/gtk/cursor.h +++ b/include/wx/gtk/cursor.h @@ -24,7 +24,10 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: wxCursor(); - wxCursor( wxStockCursor cursorId ); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif #if wxUSE_IMAGE wxCursor( const wxImage & image ); #endif @@ -32,6 +35,9 @@ public: int hotSpotX = -1, int hotSpotY = -1, const char maskBits[] = NULL, const wxColour* fg = NULL, const wxColour* bg = NULL); + wxCursor(const wxString& name, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, + int hotSpotX = 0, int hotSpotY = 0); virtual ~wxCursor(); // implementation @@ -39,6 +45,8 @@ public: GdkCursor *GetCursor() const; protected: + void InitFromStock(wxStockCursor); + virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/include/wx/gtk1/cursor.h b/include/wx/gtk1/cursor.h index 361f3e997e..c4bd2ec334 100644 --- a/include/wx/gtk1/cursor.h +++ b/include/wx/gtk1/cursor.h @@ -25,13 +25,25 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: wxCursor(); - wxCursor( wxStockCursor cursorId ); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif #if wxUSE_IMAGE wxCursor( const wxImage & image ); #endif wxCursor( const char bits[], int width, int height, int hotSpotX=-1, int hotSpotY=-1, - const char maskBits[] = NULL, const wxColour *fg = NULL, const wxColour *bg = NULL ); + const char maskBits[] = NULL, + const wxColour* fg = NULL, const wxColour* bg = NULL); + + /* WARNING: the following ctor is missing: + + wxCursor(const wxString& name, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, + int hotSpotX = 0, int hotSpotY = 0); + */ + virtual ~wxCursor(); // implementation @@ -39,6 +51,8 @@ public: GdkCursor *GetCursor() const; protected: + void InitFromStock(wxStockCursor); + virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/include/wx/mgl/cursor.h b/include/wx/mgl/cursor.h index cb26186fad..df99b31b0e 100644 --- a/include/wx/mgl/cursor.h +++ b/include/wx/mgl/cursor.h @@ -24,12 +24,12 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject public: wxCursor(); - wxCursor(wxStockCursor cursorId); - wxCursor(const char bits[], int width, int height, - int hotSpotX=-1, int hotSpotY=-1, - const char maskBits[]=0, wxColour *fg=0, wxColour *bg=0); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif wxCursor(const wxString& name, - long flags = wxBITMAP_TYPE_CUR_RESOURCE, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); virtual ~wxCursor(); @@ -37,6 +37,8 @@ public: MGLCursor *GetMGLCursor() const; private: + void InitFromStock(wxStockCursor); + DECLARE_DYNAMIC_CLASS(wxCursor) }; diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 9372b60e2b..6bdf99270f 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -25,16 +25,22 @@ public: wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); + const char maskBits[] = NULL, + const wxColour* fg = NULL, const wxColour* bg = NULL); - wxCursor(const wxString& name, long flags = wxBITMAP_TYPE_XBM, - int hotSpotX = 0, int hotSpotY = 0); + wxCursor(const wxString& name, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, + int hotSpotX = 0, int hotSpotY = 0); #if wxUSE_IMAGE wxCursor(const wxImage& image); #endif - wxCursor(wxStockCursor id); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif + virtual ~wxCursor(); // Motif-specific. @@ -46,6 +52,8 @@ protected: virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: + void InitFromStock(wxStockCursor); + void Create(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, const char maskBits[] = NULL); diff --git a/include/wx/msw/cursor.h b/include/wx/msw/cursor.h index 4ed0a73b7f..19423ecffe 100644 --- a/include/wx/msw/cursor.h +++ b/include/wx/msw/cursor.h @@ -23,13 +23,13 @@ public: // constructors wxCursor(); wxCursor(const wxImage& image); - wxCursor(const char bits[], int width, int height, - int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); wxCursor(const wxString& name, - wxBitmapType flags = wxBITMAP_TYPE_CUR_RESOURCE, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); - wxCursor(wxStockCursor idCursor); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif virtual ~wxCursor(); // implementation only @@ -37,6 +37,8 @@ public: WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); } protected: + void InitFromStock(wxStockCursor); + virtual wxGDIImageRefData *CreateData() const; private: diff --git a/include/wx/os2/cursor.h b/include/wx/os2/cursor.h index 02956942e2..f00ca92c39 100644 --- a/include/wx/os2/cursor.h +++ b/include/wx/os2/cursor.h @@ -34,25 +34,22 @@ public: wxCursor(const wxImage& rImage); - wxCursor( const char acBits[] - ,int nWidth - ,int nHeight - ,int nHotSpotX = -1 - ,int nHotSpotY = -1 - ,const char zMaskBits[] = NULL - ); wxCursor( const wxString& rsName - ,long lFlags = wxBITMAP_TYPE_CUR_RESOURCE + ,wxBitmapType lType = wxCURSOR_DEFAULT_TYPE ,int nHotSpotX = 0 ,int nHotSpotY = 0 ); - wxCursor(wxStockCursor nCursorType); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif inline ~wxCursor() { } inline WXHCURSOR GetHCURSOR(void) const { return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } inline void SetHCURSOR(WXHCURSOR hCursor) { SetHandle((WXHANDLE)hCursor); } protected: + void InitFromStock(wxStockCursor); inline virtual wxGDIImageRefData* CreateData(void) const { return (new wxCursorRefData); } private: diff --git a/include/wx/osx/carbon/cursor.h b/include/wx/osx/carbon/cursor.h index 97c3a0a2df..fe0c01391c 100644 --- a/include/wx/osx/carbon/cursor.h +++ b/include/wx/osx/carbon/cursor.h @@ -20,17 +20,16 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject public: wxCursor(); - wxCursor(const char bits[], int width, int height, - int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); - wxCursor(const wxImage & image) ; wxCursor(const char* const* bits); wxCursor(const wxString& name, - wxBitmapType flags = wxBITMAP_TYPE_MACCURSOR_RESOURCE, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); - wxCursor(wxStockCursor cursor_type); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif virtual ~wxCursor(); bool CreateFromXpm(const char* const* bits); @@ -41,6 +40,8 @@ public: WXHCURSOR GetHCURSOR() const; private: + void InitFromStock(wxStockCursor); + virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/include/wx/palmos/cursor.h b/include/wx/palmos/cursor.h index 0281f344ec..a47aae3816 100644 --- a/include/wx/palmos/cursor.h +++ b/include/wx/palmos/cursor.h @@ -23,13 +23,13 @@ public: // constructors wxCursor(); wxCursor(const wxImage& image); - wxCursor(const char bits[], int width, int height, - int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); wxCursor(const wxString& name, - long flags = wxBITMAP_TYPE_CUR_RESOURCE, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); - wxCursor(wxStockCursor idCursor); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif virtual ~wxCursor(); // implementation only @@ -37,6 +37,7 @@ public: WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); } protected: + void InitFromStock(wxStockCursor); virtual wxGDIImageRefData *CreateData() const; private: diff --git a/include/wx/x11/cursor.h b/include/wx/x11/cursor.h index a674fe4696..f308332dfd 100644 --- a/include/wx/x11/cursor.h +++ b/include/wx/x11/cursor.h @@ -25,14 +25,17 @@ class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: wxCursor(); - wxCursor( wxStockCursor cursorId ); + wxCursor(wxStockCursor id) { InitFromStock(id); } +#if WXWIN_COMPATIBILITY_2_8 + wxCursor(int id) { InitFromStock((wxStockCursor)id); } +#endif #if wxUSE_IMAGE wxCursor( const wxImage & image ); #endif - wxCursor( const char bits[], int width, int height, - int hotSpotX=-1, int hotSpotY=-1, - const char maskBits[]=0, wxColour *fg=0, wxColour *bg=0 ); + wxCursor(const wxString& name, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, + int hotSpotX = 0, int hotSpotY = 0); virtual ~wxCursor(); // implementation @@ -40,6 +43,8 @@ public: WXCursor GetCursor() const; protected: + void InitFromStock(wxStockCursor); + virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/interface/wx/cursor.h b/interface/wx/cursor.h index ec30445c89..e60fa4b570 100644 --- a/interface/wx/cursor.h +++ b/interface/wx/cursor.h @@ -13,7 +13,7 @@ pointer is, with a picture that might indicate the interpretation of a 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 - different environments. Platform-specific methods for creating a wxCursor + different environments. Platform-specific methods for creating a wxCursor object are catered for, and this is an occasion where conditional compilation will probably be required (see wxIcon for an example). @@ -26,8 +26,8 @@ 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 - bits, and 1 is opaque and 0 is transparent for the mask. It works on - Windows and GTK+. + bits, and 1 is opaque and 0 is transparent for the mask. + It works on Windows and GTK+. @code static char down_bits[] = { 255, 255, 255, 255, 31, @@ -63,7 +63,7 @@ down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6); down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14); wxCursor down_cursor = wxCursor(down_image); - #else + #elif defined(__WXGTK__) or defined(__WXMOTIF__) wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14, down_mask, wxWHITE, wxBLACK); #endif @@ -78,8 +78,7 @@ - ::wxHOURGLASS_CURSOR - ::wxCROSS_CURSOR - @see wxBitmap, wxIcon, wxWindow::SetCursor(), wxSetCursor(), - ::wxStockCursor + @see wxBitmap, wxIcon, wxWindow::SetCursor(), wxSetCursor(), ::wxStockCursor */ class wxCursor : public wxBitmap { @@ -88,19 +87,18 @@ public: Default constructor. */ wxCursor(); + /** - Constructs a cursor by passing an array of bits (Motif and GTK+ only). - @a maskBits is used only under Motif and GTK+. The parameters @a fg and - @a bg are only present on GTK+, and force the cursor to use particular - background and foreground colours. + 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. If either @a hotSpotX or @a hotSpotY is -1, the hotspot will be the centre of the cursor image (Motif only). @param bits - An array of bits. - @param maskBits - Bits for a mask bitmap. + An array of XBM data bits. @param width Cursor width. @param height @@ -109,14 +107,19 @@ public: Hotspot x coordinate. @param hotSpotY Hotspot y coordinate. + @param maskBits + Bits for a mask bitmap. + + @onlyfor{wxgtk,wxmotif} */ wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL, - wxColour* fg = NULL, wxColour* bg = NULL); + const char maskBits[] = NULL); + /** Constructs a cursor by passing a string resource name or filename. + @note 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. @@ -125,20 +128,24 @@ public: loading from an icon file, to specify the cursor hotspot relative to the top left of the image. + @param cursorName + The name of the resource or the image file to load. + @param type - Icon type to load. Under Motif, type defaults to wxBITMAP_TYPE_XBM. - Under Windows, it defaults to wxBITMAP_TYPE_CUR_RESOURCE. Under - MacOS, it defaults to wxBITMAP_TYPE_MACCURSOR_RESOURCE. - Under X, the permitted cursor types are: - + Icon type to load. It defaults to wxCURSOR_DEFAULT_TYPE, + which is a #define associated to different values on different + platforms: + - under Windows, it defaults to wxBITMAP_TYPE_CUR_RESOURCE. + - under MacOS, it defaults to wxBITMAP_TYPE_MACCURSOR_RESOURCE. + - under GTK, it defaults to wxBITMAP_TYPE_XPM. + - under X11, it defaults to wxBITMAP_TYPE_XPM. + - under Motif, type defaults to wxBITMAP_TYPE_XBM. Under Windows, the permitted types are: - wxBITMAP_TYPE_CUR - Load a cursor from a .cur cursor file (only if USE_RESOURCE_LOADING_IN_MSW is enabled in setup.h). - - wxBITMAP_TYPE_CUR_RESOURCE - Load a Windows resource (as - specified in the .rc file). + - wxBITMAP_TYPE_CUR_RESOURCE - Load a Windows resource + (as specified in the .rc file). - wxBITMAP_TYPE_ICO - Load a cursor from a .ico icon file (only if USE_RESOURCE_LOADING_IN_MSW is enabled in setup.h). Specify @a hotSpotX and @a hotSpotY. @@ -147,8 +154,10 @@ public: @param hotSpotY Hotspot y coordinate. */ - wxCursor(const wxString& cursorName, long type, + wxCursor(const wxString& cursorName, + wxBitmapType type = wxCURSOR_DEFAULT_TYPE, int hotSpotX = 0, int hotSpotY = 0); + /** Constructs a cursor using a cursor identifier. @@ -156,24 +165,26 @@ public: A stock cursor identifier. See ::wxStockCursor. */ wxCursor(wxStockCursor cursorId); + /** 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. - In wxMSW the foreground will be white and the background black. If the - cursor is larger than 32x32 it is resized. + In wxMSW the foreground will be white and the background black. + If the cursor is larger than 32x32 it is resized. In wxGTK, colour cursors and alpha channel are supported (starting from GTK+ 2.2). Otherwise the two most frequent colors will be used for - foreground and background. In any case, the cursor will be displayed at - the size of the image. + foreground and background. In any case, the cursor will be displayed + at the size of the image. 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); + /** Copy constructor, uses @ref overview_refcount "reference counting". @@ -201,7 +212,7 @@ public: /** Assignment operator, using @ref overview_refcount "reference counting". */ - wxCursor operator =(const wxCursor& cursor); + wxCursor& operator =(const wxCursor& cursor); }; diff --git a/src/dfb/cursor.cpp b/src/dfb/cursor.cpp index a7dcccf3ec..9d9bf2e850 100644 --- a/src/dfb/cursor.cpp +++ b/src/dfb/cursor.cpp @@ -43,23 +43,13 @@ public: IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxObject) -wxCursor::wxCursor(wxStockCursor cursorId) +void wxCursor::InitFromStock(wxStockCursor cursorId) { #warning "FIXME -- implement the cursor as bitmaps (that's what DFB uses)" } -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[], - wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) ) -{ -#warning "FIXME" -} - wxCursor::wxCursor(const wxString& cursor_file, - long flags, + wxBitmapType type, int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) { #warning "FIXME" diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 21f9023d29..8c0eee4f3a 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -56,7 +56,7 @@ wxCursor::wxCursor() { } -wxCursor::wxCursor( wxStockCursor cursorId ) +void wxCursor::InitFromStock( wxStockCursor cursorId ) { m_refData = new wxCursorRefData(); @@ -122,9 +122,49 @@ wxCursor::wxCursor( wxStockCursor cursorId ) M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur ); } + +// used in the following two ctors extern GtkWidget *wxGetRootWindow(); -wxCursor::wxCursor(const char bits[], int width, int height, +wxCursor::wxCursor(const wxString& cursor_file, + wxBitmapType type, + int hotSpotX, int hotSpotY) +{ + /* TODO: test this code! */ + + // Must be an XBM file + if (type != wxBITMAP_TYPE_XPM) { + wxLogError("Invalid cursor bitmap type '%d'", type); + return; + } + + // load the XPM + GdkBitmap *mask = NULL; + GdkBitmap *data = gdk_pixmap_create_from_xpm( wxGetRootWindow()->window, + &mask, NULL, cursor_file.mb_str() ); + if (!data) + return; + + // check given hotspot + gint w, h; + gdk_drawable_get_size( data, &w, &h ); + if (hotSpotX < 0 || hotSpotX >= w) + hotSpotX = 0; + if (hotSpotY < 0 || hotSpotY >= h) + hotSpotY = 0; + + // create the real cursor + m_refData = new wxCursorRefData; + M_CURSORDATA->m_cursor = + gdk_cursor_new_from_pixmap( data, mask, + wxBLACK->GetColor(), wxWHITE->GetColor(), + hotSpotX, hotSpotY ); + + g_object_unref (data); + g_object_unref (mask); +} + +wxCursor::wxCursor(const char bits[], int width, int height, int hotSpotX, int hotSpotY, const char maskBits[], const wxColour *fg, const wxColour *bg) { diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index 64bd429662..942cf56c0e 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -61,7 +61,7 @@ wxCursor::wxCursor() } -wxCursor::wxCursor( wxStockCursor cursorId ) +void wxCursor::InitFromStock( wxStockCursor cursorId ) { m_refData = new wxCursorRefData(); diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index 0f5a9a3811..bcef548906 100644 --- a/src/mgl/cursor.cpp +++ b/src/mgl/cursor.cpp @@ -65,7 +65,7 @@ wxCursor::wxCursor() { } -wxCursor::wxCursor(wxStockCursor cursorId) +void wxCursor::InitFromStock(wxStockCursor cursorId) { if ( !gs_cursorsHash ) gs_cursorsHash = new wxCursorsHash; @@ -140,21 +140,11 @@ wxCursor::wxCursor(wxStockCursor cursorId) } } -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[], - wxColour * WXUNUSED(fg), wxColour * WXUNUSED(bg) ) -{ - //FIXME_MGL -} - wxCursor::wxCursor(const wxString& cursor_file, - long flags, + wxBitmapType type, int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY)) { - if ( flags == wxBITMAP_TYPE_CUR || flags == wxBITMAP_TYPE_CUR_RESOURCE ) + if ( type == wxBITMAP_TYPE_CUR || type == wxBITMAP_TYPE_CUR_RESOURCE ) { m_refData = new wxCursorRefData(); M_CURSORDATA->m_cursor = new MGLCursor(cursor_file.mb_str()); diff --git a/src/motif/cursor.cpp b/src/motif/cursor.cpp index 134c7e9596..41deb27462 100644 --- a/src/motif/cursor.cpp +++ b/src/motif/cursor.cpp @@ -244,11 +244,14 @@ wxCursor::wxCursor(const char bits[], int width, int height, Create(bits, width, height, hotSpotX, hotSpotY, maskBits); } -wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY) +wxCursor::wxCursor(const wxString& name, wxBitmapType type, int hotSpotX, int hotSpotY, + const wxColour* WXUNUSED(fg), const wxColour* WXUNUSED(bg)) { // Must be an XBM file - if (flags != wxBITMAP_TYPE_XBM) + if (type != wxBITMAP_TYPE_XBM) { + wxLogError("Invalid cursor bitmap type '%d'", type); return; + } m_refData = new wxCursorRefData; @@ -284,7 +287,7 @@ wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY) } // Cursors by stock number -wxCursor::wxCursor(wxStockCursor id) +void wxCursor::InitFromStock(wxStockCursor id) { m_refData = new wxCursorRefData; M_CURSORDATA->m_cursorId = id; diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index 4010f812f6..0583a2f209 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -219,25 +219,10 @@ wxCursor::wxCursor(const wxImage& image) } #endif // wxUSE_IMAGE -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[]) -{ -} - // MicroWin doesn't have support needed for the other ctors #ifdef __WXMICROWIN__ -wxCursor::wxCursor(const wxString& WXUNUSED(filename), - wxBitmapType WXUNUSED(kind), - int WXUNUSED(hotSpotX), - int WXUNUSED(hotSpotY)) -{ -} - -wxCursor::wxCursor(int WXUNUSED(cursor_type)) +wxCursor::InitFromStock(wxStockCursor WXUNUSED(cursor_type)) { } @@ -280,7 +265,7 @@ wxCursor::wxCursor(const wxString& filename, break; default: - wxFAIL_MSG( _T("unknown cursor resource type") ); + wxLogError( _T("unknown cursor resource type '%d'"), kind ); hcursor = NULL; } @@ -292,7 +277,7 @@ wxCursor::wxCursor(const wxString& filename, } // Cursors by stock number -wxCursor::wxCursor(wxStockCursor idCursor) +void wxCursor::InitFromStock(wxStockCursor idCursor) { // all wxWidgets standard cursors static const struct StdCursor diff --git a/src/os2/cursor.cpp b/src/os2/cursor.cpp index b932b204ef..7378c885e3 100644 --- a/src/os2/cursor.cpp +++ b/src/os2/cursor.cpp @@ -53,15 +53,6 @@ wxCursor::wxCursor(void) { } -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), - int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[]) -{ -} - wxCursor::wxCursor(const wxImage& rImage) { wxImage vImage32 = rImage.Scale(32,32); @@ -94,7 +85,7 @@ wxCursor::wxCursor(const wxImage& rImage) } // end of wxCursor::wxCursor wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile), - long lFlags, + wxBitmapType type, int WXUNUSED(nHotSpotX), int WXUNUSED(nHotSpotY) ) { @@ -103,17 +94,19 @@ wxCursor::wxCursor( const wxString& WXUNUSED(rsCursorFile), pRefData = new wxCursorRefData; m_refData = pRefData; pRefData->m_bDestroyCursor = false; - if (lFlags == wxBITMAP_TYPE_CUR_RESOURCE) + if (type == wxBITMAP_TYPE_CUR_RESOURCE) { pRefData->m_hCursor = (WXHCURSOR) ::WinLoadPointer( HWND_DESKTOP ,0 - ,(ULONG)lFlags // if OS/2 this should be the resource Id + ,(ULONG)type // if OS/2 this should be the resource Id ); } + else + wxLogError("Invalid cursor bitmap type '%d'", type); } // end of wxCursor::wxCursor // Cursors by stock number -wxCursor::wxCursor(wxStockCursor nCursorType) +void wxCursor::InitFromStock(wxStockCursor nCursorType) { wxCursorRefData* pRefData = new wxCursorRefData; diff --git a/src/osx/carbon/cursor.cpp b/src/osx/carbon/cursor.cpp index 89c524a32b..e7ce1b6ce5 100644 --- a/src/osx/carbon/cursor.cpp +++ b/src/osx/carbon/cursor.cpp @@ -274,11 +274,6 @@ wxCursor::wxCursor() { } -wxCursor::wxCursor(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), const char WXUNUSED(maskBits)[]) -{ -} - wxCursor::wxCursor( const wxImage &image ) { #if wxUSE_IMAGE @@ -556,7 +551,7 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX } // Cursors by stock number -wxCursor::wxCursor(wxStockCursor cursor_type) +wxCursor::InitFromStock(wxStockCursor cursor_type) { m_refData = new wxCursorRefData; #if wxOSX_USE_COCOA diff --git a/src/palmos/cursor.cpp b/src/palmos/cursor.cpp index ca22a20e54..0ca38c4933 100644 --- a/src/palmos/cursor.cpp +++ b/src/palmos/cursor.cpp @@ -80,23 +80,15 @@ wxCursor::wxCursor(const wxImage& image) } #endif -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), - int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[]) -{ -} - wxCursor::wxCursor(const wxString& filename, - long kind, + wxBitmapType kind, int hotSpotX, int hotSpotY) { } // Cursors by stock number -wxCursor::wxCursor(wxStockCursor idCursor) +void wxCursor::InitFromStock(wxStockCursor idCursor) { } diff --git a/src/x11/cursor.cpp b/src/x11/cursor.cpp index 2650afcfab..354e8dc8dd 100644 --- a/src/x11/cursor.cpp +++ b/src/x11/cursor.cpp @@ -66,7 +66,7 @@ wxCursor::wxCursor() } -wxCursor::wxCursor( wxStockCursor cursorId ) +void wxCursor::InitFromStock( wxStockCursor cursorId ) { m_refData = new wxCursorRefData(); @@ -124,13 +124,11 @@ wxCursor::wxCursor( wxStockCursor cursorId ) #endif } -wxCursor::wxCursor(const char WXUNUSED(bits)[], - int WXUNUSED(width), int WXUNUSED(height), - int WXUNUSED(hotSpotX), int WXUNUSED(hotSpotY), - const char WXUNUSED(maskBits)[], - wxColour *WXUNUSED(fg), wxColour *WXUNUSED(bg)) +wxCursor::wxCursor(const wxString& name, + wxBitmapType type, + int hotSpotX, int hotSpotY) { - wxFAIL_MSG( wxT("wxCursor creation from bits not yet implemented") ); + wxFAIL_MSG( wxT("wxCursor creation from file not yet implemented") ); } #if wxUSE_IMAGE -- 2.45.2