From 8f884a0dccd6b642f35c441ac9bfc87a6d5b4d35 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2007 17:54:20 +0000 Subject: [PATCH] Fix Ok/IsOk() mess in wxGDIObject-derived classes; also added wxGDIObject::Create/CloneGDIRefData() and implemented them for (almost) all ports git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50727 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/animate.h | 2 +- include/wx/bitmap.h | 3 - include/wx/cocoa/bitmap.h | 16 ++- include/wx/cocoa/brush.h | 12 +- include/wx/cocoa/colour.h | 2 +- include/wx/cocoa/cursor.h | 42 +++---- include/wx/cocoa/font.h | 13 +- include/wx/cocoa/icon.h | 15 ++- include/wx/cocoa/pen.h | 21 ++-- include/wx/colour.h | 20 ++- include/wx/dfb/bitmap.h | 12 +- include/wx/dfb/brush.h | 11 +- include/wx/dfb/cursor.h | 11 +- include/wx/dfb/font.h | 5 +- include/wx/dfb/pen.h | 8 +- include/wx/dfb/region.h | 5 +- include/wx/font.h | 8 +- include/wx/gdiobj.h | 46 +++++-- include/wx/generic/colour.h | 2 +- include/wx/generic/paletteg.h | 6 +- include/wx/generic/region.h | 4 +- include/wx/gtk/bitmap.h | 12 +- include/wx/gtk/brush.h | 12 +- include/wx/gtk/colour.h | 6 +- include/wx/gtk/cursor.h | 14 ++- include/wx/gtk/font.h | 4 +- include/wx/gtk/pen.h | 12 +- include/wx/gtk/region.h | 5 +- include/wx/gtk1/bitmap.h | 12 +- include/wx/gtk1/brush.h | 12 +- include/wx/gtk1/colour.h | 10 +- include/wx/gtk1/cursor.h | 12 +- include/wx/gtk1/font.h | 5 +- include/wx/gtk1/pen.h | 12 +- include/wx/gtk1/region.h | 5 +- include/wx/iconbndl.h | 6 +- include/wx/mac/carbon/bitmap.h | 19 ++- include/wx/mac/carbon/brush.h | 17 ++- include/wx/mac/carbon/colour.h | 2 +- include/wx/mac/carbon/cursor.h | 36 +++--- include/wx/mac/carbon/font.h | 19 +-- include/wx/mac/carbon/icon.h | 9 +- include/wx/mac/carbon/metafile.h | 27 ++-- include/wx/mac/carbon/palette.h | 32 ++--- include/wx/mac/carbon/pen.h | 61 +++++----- include/wx/mac/carbon/region.h | 3 + include/wx/mgl/bitmap.h | 2 - include/wx/mgl/brush.h | 15 +-- include/wx/mgl/cursor.h | 7 +- include/wx/mgl/font.h | 4 +- include/wx/mgl/palette.h | 8 +- include/wx/mgl/pen.h | 10 +- include/wx/mgl/region.h | 5 +- include/wx/motif/colour.h | 2 +- include/wx/motif/cursor.h | 16 +-- include/wx/motif/font.h | 7 +- include/wx/msw/bitmap.h | 2 +- include/wx/msw/brush.h | 10 +- include/wx/msw/colour.h | 2 +- include/wx/msw/enhmeta.h | 13 +- include/wx/msw/font.h | 4 +- include/wx/msw/gdiimage.h | 18 ++- include/wx/msw/metafile.h | 10 +- include/wx/msw/palette.h | 49 ++++---- include/wx/msw/pen.h | 7 +- include/wx/msw/region.h | 4 +- include/wx/os2/bitmap.h | 5 +- include/wx/os2/brush.h | 3 - include/wx/os2/colour.h | 2 +- include/wx/os2/gdiimage.h | 6 +- include/wx/os2/metafile.h | 4 +- include/wx/os2/palette.h | 3 - include/wx/os2/pen.h | 3 - include/wx/os2/region.h | 4 +- include/wx/palette.h | 2 - include/wx/palmos/brush.h | 10 +- include/wx/palmos/enhmeta.h | 6 +- include/wx/palmos/gdiimage.h | 6 +- include/wx/palmos/metafile.h | 7 +- include/wx/palmos/palette.h | 3 - include/wx/palmos/pen.h | 3 - include/wx/palmos/region.h | 4 +- include/wx/private/fontmgr.h | 2 +- include/wx/region.h | 3 - include/wx/x11/bitmap.h | 7 +- include/wx/x11/brush.h | 17 +-- include/wx/x11/colour.h | 15 +-- include/wx/x11/cursor.h | 20 ++- include/wx/x11/font.h | 3 + include/wx/x11/palette.h | 13 +- include/wx/x11/pen.h | 11 +- include/wx/x11/region.h | 5 +- src/cocoa/bitmap.mm | 11 +- src/cocoa/brush.mm | 4 +- src/cocoa/font.mm | 41 +++---- src/cocoa/icon.mm | 17 ++- src/cocoa/pen.mm | 4 +- src/common/fontcmn.cpp | 5 - src/common/gdicmn.cpp | 2 +- src/common/iconbndl.cpp | 11 +- src/dfb/bitmap.cpp | 13 +- src/dfb/brush.cpp | 13 +- src/dfb/cursor.cpp | 13 +- src/dfb/font.cpp | 4 +- src/dfb/pen.cpp | 13 +- src/dfb/region.cpp | 4 +- src/generic/paletteg.cpp | 33 +++-- src/generic/regiong.cpp | 14 +-- src/gtk/bitmap.cpp | 17 +-- src/gtk/brush.cpp | 10 +- src/gtk/colour.cpp | 2 +- src/gtk/cursor.cpp | 20 +-- src/gtk/font.cpp | 8 +- src/gtk/pen.cpp | 8 +- src/gtk/region.cpp | 8 +- src/gtk1/bitmap.cpp | 14 +-- src/gtk1/brush.cpp | 8 +- src/gtk1/colour.cpp | 7 +- src/gtk1/cursor.cpp | 18 +-- src/gtk1/font.cpp | 14 ++- src/gtk1/pen.cpp | 4 +- src/gtk1/region.cpp | 10 +- src/mac/carbon/bitmap.cpp | 117 +++++++++--------- src/mac/carbon/brush.cpp | 4 +- src/mac/carbon/colour.cpp | 5 - src/mac/carbon/cursor.cpp | 55 +++++++-- src/mac/carbon/font.cpp | 148 +++++++++++----------- src/mac/carbon/icon.cpp | 75 +++++++----- src/mac/carbon/metafile.cpp | 19 ++- src/mac/carbon/palette.cpp | 62 +++++++--- src/mac/carbon/pen.cpp | 93 +++++++------- src/mac/carbon/region.cpp | 10 ++ src/mgl/bitmap.cpp | 7 +- src/mgl/brush.cpp | 15 +-- src/mgl/cursor.cpp | 5 - src/mgl/font.cpp | 4 +- src/mgl/palette.cpp | 5 - src/mgl/pen.cpp | 9 +- src/mgl/region.cpp | 4 +- src/motif/cursor.cpp | 14 ++- src/motif/font.cpp | 10 ++ src/msw/bitmap.cpp | 11 +- src/msw/brush.cpp | 4 +- src/msw/enhmeta.cpp | 15 +++ src/msw/font.cpp | 4 +- src/msw/metafile.cpp | 10 ++ src/msw/palette.cpp | 203 ++++++++++++++++++------------- src/msw/pen.cpp | 4 +- src/msw/region.cpp | 4 +- src/os2/bitmap.cpp | 4 +- src/os2/region.cpp | 4 +- src/palmos/brush.cpp | 4 +- src/palmos/region.cpp | 4 +- src/x11/bitmap.cpp | 13 +- src/x11/brush.cpp | 6 +- src/x11/colour.cpp | 12 +- src/x11/cursor.cpp | 12 +- src/x11/font.cpp | 14 ++- src/x11/palette.cpp | 10 ++ src/x11/pen.cpp | 6 +- src/x11/region.cpp | 8 +- 161 files changed, 1229 insertions(+), 1124 deletions(-) diff --git a/include/wx/animate.h b/include/wx/animate.h index 7722660469..ff555336b8 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -31,7 +31,7 @@ extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxAnimationCtrlNameStr[]; // wxAnimationBase // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_ADV wxAnimationBase : public wxGDIObject +class WXDLLIMPEXP_ADV wxAnimationBase : public wxObject { public: wxAnimationBase() {} diff --git a/include/wx/bitmap.h b/include/wx/bitmap.h index 1e39569846..bd81349e36 100644 --- a/include/wx/bitmap.h +++ b/include/wx/bitmap.h @@ -133,9 +133,6 @@ public: static void InitStandardHandlers(); */ - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const = 0; - virtual int GetHeight() const = 0; virtual int GetWidth() const = 0; virtual int GetDepth() const = 0; diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h index 9fc1b1e937..79d0c6279d 100644 --- a/include/wx/cocoa/bitmap.h +++ b/include/wx/cocoa/bitmap.h @@ -64,7 +64,6 @@ protected: // ======================================================================== class WXDLLEXPORT wxBitmap: public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxBitmap) // ------------------------------------------------------------------------ // initialization // ------------------------------------------------------------------------ @@ -116,8 +115,6 @@ public: // get the given part of bitmap wxBitmap GetSubBitmap( const wxRect& rect ) const; - bool Ok() const { return IsOk(); } - bool IsOk() const; int GetWidth() const; int GetHeight() const; int GetDepth() const; @@ -140,10 +137,6 @@ public: int GetBitmapType() const; - // wxObjectRefData - wxObjectRefData *CreateRefData() const; - wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; - // wxCocoa WX_NSBitmapImageRep GetNSBitmapImageRep(); void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep); @@ -151,6 +144,12 @@ public: static void InitStandardHandlers() { } static void CleanUpHandlers() { } + +protected: + wxGDIRefData *CreateGDIRefData() const; + wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + + DECLARE_DYNAMIC_CLASS(wxBitmap) }; class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase @@ -158,5 +157,4 @@ class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase DECLARE_ABSTRACT_CLASS(wxBitmapHandler) }; -#endif - // __WX_COCOA_BITMAP_H__ +#endif // __WX_COCOA_BITMAP_H__ diff --git a/include/wx/cocoa/brush.h b/include/wx/cocoa/brush.h index 31db6fc5c4..facbc7194d 100644 --- a/include/wx/cocoa/brush.h +++ b/include/wx/cocoa/brush.h @@ -52,16 +52,12 @@ public: virtual int GetStyle() const; wxBitmap *GetStipple() const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const - { return (m_refData != NULL); } - - // wxObjectRefData - wxObjectRefData *CreateRefData() const; - wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; - // wxCocoa WX_NSColor GetNSColor(); + +protected: + wxGDIRefData *CreateGDIRefData() const; + wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; }; #endif // __WX_COCOA_BRUSH_H__ diff --git a/include/wx/cocoa/colour.h b/include/wx/cocoa/colour.h index dbdc52ae62..f0d7af4271 100644 --- a/include/wx/cocoa/colour.h +++ b/include/wx/cocoa/colour.h @@ -50,7 +50,7 @@ public: virtual ~wxColour(); // accessors - bool IsOk() const { return m_cocoaNSColor; } + virtual bool IsOk() const { return m_cocoaNSColor; } WX_NSColor GetNSColor() { return m_cocoaNSColor; } unsigned char Red() const { return m_red; } diff --git a/include/wx/cocoa/cursor.h b/include/wx/cocoa/cursor.h index f7c5b65ab0..474d1b8062 100644 --- a/include/wx/cocoa/cursor.h +++ b/include/wx/cocoa/cursor.h @@ -14,12 +14,8 @@ #include "wx/bitmap.h" -class WXDLLEXPORT wxCursorRefData: public wxObjectRefData +class WXDLLEXPORT wxCursorRefData : public wxGDIRefData { - DECLARE_NO_COPY_CLASS(wxCursorRefData) - - friend class WXDLLIMPEXP_FWD_CORE wxBitmap; - friend class WXDLLIMPEXP_FWD_CORE wxCursor; public: wxCursorRefData(); virtual ~wxCursorRefData(); @@ -27,6 +23,11 @@ public: protected: int m_width, m_height; WX_NSCursor m_hCursor; + + friend class WXDLLIMPEXP_FWD_CORE wxBitmap; + friend class WXDLLIMPEXP_FWD_CORE wxCursor; + + DECLARE_NO_COPY_CLASS(wxCursorRefData) }; #define M_CURSORDATA ((wxCursorRefData *)m_refData) @@ -35,31 +36,26 @@ protected: // Cursor class WXDLLEXPORT wxCursor: public wxBitmap { - DECLARE_DYNAMIC_CLASS(wxCursor) - public: - wxCursor(); - - wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); + wxCursor(); - wxCursor(const wxString& name, long flags = 0, - int hotSpotX = 0, int hotSpotY = 0); + wxCursor(const char bits[], int width, int height, + int hotSpotX = -1, int hotSpotY = -1, + const char maskBits[] = NULL); - wxCursor(int cursor_type); - virtual ~wxCursor(); + wxCursor(const wxString& name, long flags = 0, + int hotSpotX = 0, int hotSpotY = 0); - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return m_refData ; } + wxCursor(int cursor_type); + virtual ~wxCursor(); - inline bool operator == (const wxCursor& cursor) const { return m_refData == cursor.m_refData; } - inline bool operator != (const wxCursor& cursor) const { return m_refData != cursor.m_refData; } + // FIXME: operator==() is wrong! + bool operator==(const wxCursor& cursor) const { return m_refData == cursor.m_refData; } + bool operator!=(const wxCursor& cursor) const { return !(*this == cursor); } - inline WX_NSCursor GetNSCursor() const - { - return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); - } + WX_NSCursor GetNSCursor() const { return M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0; } + DECLARE_DYNAMIC_CLASS(wxCursor) }; extern WXDLLEXPORT void wxSetCursor(const wxCursor& cursor); diff --git a/include/wx/cocoa/font.h b/include/wx/cocoa/font.h index 1b6698e89e..f19d666288 100644 --- a/include/wx/cocoa/font.h +++ b/include/wx/cocoa/font.h @@ -110,15 +110,6 @@ public: virtual bool RealizeResource(); protected: - /*! @abstract Helper method for COW. - @discussion - wxFont can be considered a mutable holder of an immutable opaque implementation object. - All methods that mutate the font should first call Unshare() to ensure that mutating - the implementation object does not cause another wxFont that happened to share the - same ref data to mutate. - */ - void Unshare(); - /*! @abstract Internal constructor with ref data @discussion Takes ownership of @a refData. That is, it is assumed that refData has either just been @@ -128,6 +119,10 @@ protected: explicit wxFont(wxFontRefData *refData) { Create(refData); } bool Create(wxFontRefData *refData); + + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxFont) }; diff --git a/include/wx/cocoa/icon.h b/include/wx/cocoa/icon.h index 8e4214f31d..478e2271b8 100644 --- a/include/wx/cocoa/icon.h +++ b/include/wx/cocoa/icon.h @@ -18,9 +18,8 @@ // ======================================================================== // wxIcon // ======================================================================== -class WXDLLEXPORT wxIcon: public wxGDIObject +class WXDLLEXPORT wxIcon : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxIcon) public: wxIcon(); @@ -49,14 +48,18 @@ public: // ctors, assignment operators...), but it's ok to have such function void CopyFromBitmap(const wxBitmap& bmp); - bool Ok() const { return IsOk(); } - bool IsOk() const; int GetWidth() const; int GetHeight() const; WX_NSImage GetNSImage() const; bool CreateFromXpm(const char **bits); + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + +private: + DECLARE_DYNAMIC_CLASS(wxIcon) }; -#endif - // _WX_COCOA_ICON_H__ +#endif // _WX_COCOA_ICON_H__ diff --git a/include/wx/cocoa/pen.h b/include/wx/cocoa/pen.h index 7599f775a7..b6137473ee 100644 --- a/include/wx/cocoa/pen.h +++ b/include/wx/cocoa/pen.h @@ -23,24 +23,15 @@ class WXDLLIMPEXP_FWD_CORE wxBitmap; // ======================================================================== class WXDLLEXPORT wxPen: public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxPen) public: wxPen(); wxPen(const wxColour& col, int width = 1, int style = wxSOLID); wxPen(const wxBitmap& stipple, int width); virtual ~wxPen(); - // wxObjectRefData - wxObjectRefData *CreateRefData() const; - wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; - - inline bool operator == (const wxPen& pen) const - { return m_refData == pen.m_refData; } - inline bool operator != (const wxPen& pen) const - { return m_refData != pen.m_refData; } - - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return (m_refData != NULL) ; } + // FIXME: operator==() is wrong + bool operator==(const wxPen& pen) const { return m_refData == pen.m_refData; } + bool operator!=(const wxPen& pen) const { return !(*this == pen); } void SetColour(const wxColour& col) ; void SetColour(unsigned char r, unsigned char g, unsigned char b) ; @@ -62,6 +53,12 @@ public: WX_NSColor GetNSColor(); int GetCocoaLineDash(const CGFloat **pattern); + +protected: + wxGDIRefData *CreateGDIRefData() const; + wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + + DECLARE_DYNAMIC_CLASS(wxPen) }; #endif // __WX_COCOA_PEN_H__ diff --git a/include/wx/colour.h b/include/wx/colour.h index afe6371475..ee2c023f90 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -92,9 +92,6 @@ public: // accessors // --------- - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const = 0; - virtual ChannelType Red() const = 0; virtual ChannelType Green() const = 0; virtual ChannelType Blue() const = 0; @@ -119,6 +116,23 @@ protected: InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0; virtual bool FromString(const wxString& s); + + // wxColour doesn't use reference counted data (at least not in all ports) + // so provide stubs for the functions which need to be defined if we do use + // them + virtual wxGDIRefData *CreateGDIRefData() const + { + wxFAIL_MSG( "must be overridden if used" ); + + return NULL; + } + + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const + { + wxFAIL_MSG( "must be overridden if used" ); + + return NULL; + } }; diff --git a/include/wx/dfb/bitmap.h b/include/wx/dfb/bitmap.h index 28bd0b0f28..7ac7cf2b2e 100644 --- a/include/wx/dfb/bitmap.h +++ b/include/wx/dfb/bitmap.h @@ -21,12 +21,12 @@ wxDFB_DECLARE_INTERFACE(IDirectFBSurface); // wxBitmap //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase +class WXDLLIMPEXP_CORE wxBitmapHandler : public wxBitmapHandlerBase { DECLARE_ABSTRACT_CLASS(wxBitmapHandler) }; -class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase +class WXDLLIMPEXP_CORE wxBitmap : public wxBitmapBase { public: wxBitmap() {} @@ -39,9 +39,6 @@ public: wxBitmap(const wxImage& image, int depth = -1); #endif - bool Ok() const { return IsOk(); } - bool IsOk() const; - bool Create(const wxIDirectFBSurfacePtr& surface); bool Create(int width, int height, int depth = -1); @@ -86,9 +83,8 @@ public: wxIDirectFBSurfacePtr GetDirectFBSurface() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; bool CreateWithFormat(int width, int height, int dfbFormat); diff --git a/include/wx/dfb/brush.h b/include/wx/dfb/brush.h index 8398b46da4..926df84299 100644 --- a/include/wx/dfb/brush.h +++ b/include/wx/dfb/brush.h @@ -28,20 +28,18 @@ class WXDLLIMPEXP_FWD_CORE wxBrush; // wxBrush //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxBrush: public wxBrushBase +class WXDLLIMPEXP_CORE wxBrush : public wxBrushBase { public: wxBrush() {} wxBrush(const wxColour &colour, int style = wxSOLID); wxBrush(const wxBitmap &stippleBitmap); - bool Ok() const { return IsOk(); } - bool IsOk() const; bool operator==(const wxBrush& brush) const; bool operator!=(const wxBrush& brush) const { return !(*this == brush); } virtual int GetStyle() const; - wxColour &GetColour() const; + wxColour& GetColour() const; wxBitmap *GetStipple() const; void SetColour(const wxColour& col); @@ -50,9 +48,8 @@ public: void SetStipple(const wxBitmap& stipple); protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxBrush) }; diff --git a/include/wx/dfb/cursor.h b/include/wx/dfb/cursor.h index a56b1f1afe..102fab41a9 100644 --- a/include/wx/dfb/cursor.h +++ b/include/wx/dfb/cursor.h @@ -11,7 +11,7 @@ #ifndef _WX_DFB_CURSOR_H_ #define _WX_DFB_CURSOR_H_ -#include "wx/object.h" +#include "wx/gdiobj.h" #include "wx/gdicmn.h" class WXDLLIMPEXP_FWD_CORE wxBitmap; @@ -20,7 +20,7 @@ class WXDLLIMPEXP_FWD_CORE wxBitmap; // wxCursor //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxCursor: public wxObject +class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: wxCursor() {} @@ -32,16 +32,13 @@ public: long flags = wxBITMAP_TYPE_CUR_RESOURCE, int hotSpotX = 0, int hotSpotY = 0); - bool Ok() const { return IsOk(); } - bool IsOk() const; - // implementation wxBitmap GetBitmap() const; protected: // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxCursor) }; diff --git a/include/wx/dfb/font.h b/include/wx/dfb/font.h index d408ea043b..a3441e48cc 100644 --- a/include/wx/dfb/font.h +++ b/include/wx/dfb/font.h @@ -71,9 +71,8 @@ public: wxIDirectFBFontPtr GetDirectFBFont(bool antialiased) const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxFont) diff --git a/include/wx/dfb/pen.h b/include/wx/dfb/pen.h index 9648f98e85..965b2afcbf 100644 --- a/include/wx/dfb/pen.h +++ b/include/wx/dfb/pen.h @@ -57,13 +57,9 @@ public: wxDash* GetDash() const; wxBitmap *GetStipple() const; - bool Ok() const { return IsOk(); } - bool IsOk() const; - protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxPen) }; diff --git a/include/wx/dfb/region.h b/include/wx/dfb/region.h index 591cb4394f..3d96a7e718 100644 --- a/include/wx/dfb/region.h +++ b/include/wx/dfb/region.h @@ -40,9 +40,8 @@ public: wxRect AsRect() const { return GetBox(); } protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/include/wx/font.h b/include/wx/font.h index 9b87cafd11..3b808ac2bd 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -155,13 +155,9 @@ public: // from the string representation of wxNativeFontInfo static wxFont *New(const wxString& strNativeFontDesc); - // was the font successfully created? - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - // comparison - bool operator == (const wxFont& font) const; - bool operator != (const wxFont& font) const; + bool operator==(const wxFont& font) const; + bool operator!=(const wxFont& font) const { return !(*this == font); } // accessors: get the font characteristics virtual int GetPointSize() const = 0; diff --git a/include/wx/gdiobj.h b/include/wx/gdiobj.h index ebe3319753..fc2e0756d7 100644 --- a/include/wx/gdiobj.h +++ b/include/wx/gdiobj.h @@ -20,21 +20,35 @@ // the same native GDI object // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_FWD_CORE wxGDIRefData: public wxObjectRefData { }; +class WXDLLIMPEXP_FWD_CORE wxGDIRefData : public wxObjectRefData +{ +public: + // override this in the derived classes to check if this data object is + // really fully initialized + virtual bool IsOk() const { return true; } +}; // ---------------------------------------------------------------------------- -// wxGDIObject +// wxGDIObject: base class for bitmaps, pens, brushes, ... // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxGDIObject: public wxObject +class WXDLLIMPEXP_CORE wxGDIObject : public wxObject { public: + // checks if the object can be used + bool IsOk() const + { + // the cast here is safe because the derived classes always create + // wxGDIRefData objects + return m_refData && wx_static_cast(wxGDIRefData *, m_refData)->IsOk(); + } + + // don't use in the new code, use IsOk() instead bool IsNull() const { return m_refData == NULL; } - // older version, for backwards compat + // older version, for backwards compatibility only (but not deprecated + // because it's still widely used) bool Ok() const { return IsOk(); } - - virtual bool IsOk() const { return (m_refData != NULL) ; } #if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXPALMOS__) // Creates the resource @@ -49,8 +63,24 @@ public: virtual WXHANDLE GetResourceHandle() const { return 0; } #endif // defined(__WXMSW__) || defined(__WXPM__) +protected: + // replace base class functions using wxObjectRefData with our own which + // use wxGDIRefData to ensure that we always work with data objects of the + // correct type (i.e. derived from wxGDIRefData) + virtual wxObjectRefData *CreateRefData() const + { + return CreateGDIRefData(); + } + + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const + { + return CloneGDIRefData(wx_static_cast(const wxGDIRefData *, data)); + } + + virtual wxGDIRefData *CreateGDIRefData() const = 0; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const = 0; + DECLARE_DYNAMIC_CLASS(wxGDIObject) }; -#endif - // _WX_GDIOBJ_H_BASE_ +#endif // _WX_GDIOBJ_H_BASE_ diff --git a/include/wx/generic/colour.h b/include/wx/generic/colour.h index feb4928550..c0d26dad03 100644 --- a/include/wx/generic/colour.h +++ b/include/wx/generic/colour.h @@ -33,7 +33,7 @@ public: virtual ~wxColour(); // accessors - bool IsOk() const { return m_isInit; } + virtual bool IsOk() const { return m_isInit; } unsigned char Red() const { return m_red; } unsigned char Green() const { return m_green; } diff --git a/include/wx/generic/paletteg.h b/include/wx/generic/paletteg.h index a8ecde7185..4d3ccc308d 100644 --- a/include/wx/generic/paletteg.h +++ b/include/wx/generic/paletteg.h @@ -33,8 +33,6 @@ public: wxPalette(); wxPalette( int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue ); virtual ~wxPalette(); - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const; bool Create( int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); int GetPixel( unsigned char red, unsigned char green, unsigned char blue ) const; @@ -42,6 +40,10 @@ public: virtual int GetColoursCount() const; +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxPalette) }; diff --git a/include/wx/generic/region.h b/include/wx/generic/region.h index e82714abcd..7a6dc2473f 100644 --- a/include/wx/generic/region.h +++ b/include/wx/generic/region.h @@ -26,8 +26,8 @@ public: virtual bool IsEmpty() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 98bc4a8bee..5cc7ed1c1c 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -66,14 +66,12 @@ public: wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); } #endif // wxUSE_IMAGE virtual ~wxBitmap(); - bool Ok() const { return IsOk(); } - bool IsOk() const; bool Create(int width, int height, int depth = -1); - int GetHeight() const; - int GetWidth() const; - int GetDepth() const; + virtual int GetHeight() const; + virtual int GetWidth() const; + virtual int GetDepth() const; #if wxUSE_IMAGE wxImage ConvertToImage() const; @@ -127,8 +125,8 @@ protected: bool CreateFromImage(const wxImage& image, int depth); #endif // wxUSE_IMAGE - virtual wxObjectRefData* CreateRefData() const; - virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const; + virtual wxGDIRefData* CreateGDIRefData() const; + virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const; private: #if wxUSE_IMAGE diff --git a/include/wx/gtk/brush.h b/include/wx/gtk/brush.h index e0bfc9ff5d..f733ecea5f 100644 --- a/include/wx/gtk/brush.h +++ b/include/wx/gtk/brush.h @@ -26,11 +26,8 @@ public: wxBrush( const wxBitmap &stippleBitmap ); virtual ~wxBrush(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxBrush& brush ) const; - bool operator != (const wxBrush& brush) const { return !(*this == brush); } + bool operator==(const wxBrush& brush) const; + bool operator!=(const wxBrush& brush) const { return !(*this == brush); } virtual int GetStyle() const; wxColour &GetColour() const; @@ -42,9 +39,8 @@ public: void SetStipple( const wxBitmap& stipple ); protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxBrush) }; diff --git a/include/wx/gtk/colour.h b/include/wx/gtk/colour.h index 4c98208518..07121726d6 100644 --- a/include/wx/gtk/colour.h +++ b/include/wx/gtk/colour.h @@ -27,10 +27,8 @@ public: virtual ~wxColour(); - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxColour& col ) const; - bool operator != ( const wxColour& col ) const { return !(*this == col); } + bool operator==(const wxColour& col) const; + bool operator!=(const wxColour& col) const { return !(*this == col); } unsigned char Red() const; unsigned char Green() const; diff --git a/include/wx/gtk/cursor.h b/include/wx/gtk/cursor.h index d940c1f204..8269c07048 100644 --- a/include/wx/gtk/cursor.h +++ b/include/wx/gtk/cursor.h @@ -10,7 +10,7 @@ #ifndef _WX_GTK_CURSOR_H_ #define _WX_GTK_CURSOR_H_ -#include "wx/object.h" +#include "wx/gdiobj.h" class WXDLLIMPEXP_FWD_CORE wxColour; class WXDLLIMPEXP_FWD_CORE wxImage; @@ -19,10 +19,9 @@ class WXDLLIMPEXP_FWD_CORE wxImage; // wxCursor //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxCursor: public wxObject +class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: - wxCursor(); wxCursor( int cursorId ); #if wxUSE_IMAGE @@ -30,15 +29,18 @@ public: #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 ); virtual ~wxCursor(); - bool Ok() const { return IsOk(); } - bool IsOk() const; // implementation GdkCursor *GetCursor() const; +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxCursor) }; diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index 11ceb4335f..253c5cf11f 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -84,8 +84,8 @@ protected: // common part of all ctors void Init(); - virtual wxObjectRefData* CreateRefData() const; - virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const; + virtual wxGDIRefData* CreateGDIRefData() const; + virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const; private: DECLARE_DYNAMIC_CLASS(wxFont) diff --git a/include/wx/gtk/pen.h b/include/wx/gtk/pen.h index b273d2c6df..f4ccb5f9ab 100644 --- a/include/wx/gtk/pen.h +++ b/include/wx/gtk/pen.h @@ -27,11 +27,8 @@ public: wxPen( const wxColour &colour, int width = 1, int style = wxSOLID ); virtual ~wxPen(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxPen& pen ) const; - bool operator != (const wxPen& pen) const { return !(*this == pen); } + bool operator==(const wxPen& pen) const; + bool operator!=(const wxPen& pen) const { return !(*this == pen); } void SetColour( const wxColour &colour ); void SetColour( unsigned char red, unsigned char green, unsigned char blue ); @@ -51,9 +48,8 @@ public: wxDash* GetDash() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxPen) }; diff --git a/include/wx/gtk/region.h b/include/wx/gtk/region.h index 26caf77531..846f1946cf 100644 --- a/include/wx/gtk/region.h +++ b/include/wx/gtk/region.h @@ -63,9 +63,8 @@ public: GdkRegion *GetRegion() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index e41dbc4b61..090b72e73c 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -78,14 +78,12 @@ public: wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); } virtual ~wxBitmap(); - bool Ok() const { return IsOk(); } - bool IsOk() const; bool Create(int width, int height, int depth = -1); - int GetHeight() const; - int GetWidth() const; - int GetDepth() const; + virtual int GetHeight() const; + virtual int GetWidth() const; + virtual int GetDepth() const; wxImage ConvertToImage() const; @@ -134,8 +132,8 @@ public: protected: bool CreateFromImage(const wxImage& image, int depth); - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: // to be called from CreateFromImage only! diff --git a/include/wx/gtk1/brush.h b/include/wx/gtk1/brush.h index 64bf2802f3..2f7def8807 100644 --- a/include/wx/gtk1/brush.h +++ b/include/wx/gtk1/brush.h @@ -36,11 +36,8 @@ public: wxBrush( const wxBitmap &stippleBitmap ); virtual ~wxBrush(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxBrush& brush ) const; - bool operator != (const wxBrush& brush) const { return !(*this == brush); } + bool operator==(const wxBrush& brush) const; + bool operator!=(const wxBrush& brush) const { return !(*this == brush); } virtual int GetStyle() const; wxColour &GetColour() const; @@ -52,9 +49,8 @@ public: void SetStipple( const wxBitmap& stipple ); private: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxBrush) }; diff --git a/include/wx/gtk1/colour.h b/include/wx/gtk1/colour.h index ae9e22fdcd..4d4950fbba 100644 --- a/include/wx/gtk1/colour.h +++ b/include/wx/gtk1/colour.h @@ -45,10 +45,8 @@ public: virtual bool FromString(const wxString& str); - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxColour& col ) const; - bool operator != ( const wxColour& col ) const { return !(*this == col); } + bool operator==(const wxColour& col) const; + bool operator!=(const wxColour& col) const { return !(*this == col); } unsigned char Red() const; unsigned char Green() const; @@ -62,8 +60,8 @@ public: protected: // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; virtual void InitRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); diff --git a/include/wx/gtk1/cursor.h b/include/wx/gtk1/cursor.h index eba3d24b1b..2612a6c8d2 100644 --- a/include/wx/gtk1/cursor.h +++ b/include/wx/gtk1/cursor.h @@ -10,8 +10,7 @@ #ifndef __GTKCURSORH__ #define __GTKCURSORH__ -#include "wx/defs.h" -#include "wx/object.h" +#include "wx/gdiobj.h" #include "wx/gdicmn.h" #if wxUSE_IMAGE @@ -22,10 +21,9 @@ // wxCursor //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxCursor: public wxObject +class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: - wxCursor(); wxCursor( int cursorId ); #if wxUSE_IMAGE @@ -35,13 +33,15 @@ public: int hotSpotX=-1, int hotSpotY=-1, const char maskBits[] = NULL, const wxColour *fg = NULL, const wxColour *bg = NULL ); virtual ~wxCursor(); - bool Ok() const { return IsOk(); } - bool IsOk() const; // implementation GdkCursor *GetCursor() const; +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxCursor) }; diff --git a/include/wx/gtk1/font.h b/include/wx/gtk1/font.h index 6936e530f3..62250ef33b 100644 --- a/include/wx/gtk1/font.h +++ b/include/wx/gtk1/font.h @@ -91,9 +91,10 @@ public: GdkFont* GetInternalFont(float scale = 1.0) const; - // no data :-) - protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info ); private: diff --git a/include/wx/gtk1/pen.h b/include/wx/gtk1/pen.h index f196a8165d..877e31f635 100644 --- a/include/wx/gtk1/pen.h +++ b/include/wx/gtk1/pen.h @@ -40,11 +40,8 @@ public: wxPen( const wxColour &colour, int width = 1, int style = wxSOLID ); virtual ~wxPen(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxPen& pen ) const; - bool operator != (const wxPen& pen) const { return !(*this == pen); } + bool operator==(const wxPen& pen) const; + bool operator!=(const wxPen& pen) const { return !(*this == pen); } void SetColour( const wxColour &colour ); void SetColour( unsigned char red, unsigned char green, unsigned char blue ); @@ -64,9 +61,8 @@ public: wxDash* GetDash() const; private: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxPen) }; diff --git a/include/wx/gtk1/region.h b/include/wx/gtk1/region.h index 17166be6bf..6704c3e4c8 100644 --- a/include/wx/gtk1/region.h +++ b/include/wx/gtk1/region.h @@ -63,9 +63,8 @@ public: GdkRegion *GetRegion() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/include/wx/iconbndl.h b/include/wx/iconbndl.h index d7e037b23b..1892c30a1c 100644 --- a/include/wx/iconbndl.h +++ b/include/wx/iconbndl.h @@ -46,8 +46,6 @@ public: wxIconBundle& operator=(const wxIconBundle& ic) { if ( this != &ic) Ref(ic); return *this; } - virtual bool IsOk() const; - // adds all the icons contained in the file to the collection, // if the collection already contains icons with the same @@ -87,8 +85,8 @@ public: bool IsEmpty() const { return GetIconCount() == 0; } protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: // delete all icons diff --git a/include/wx/mac/carbon/bitmap.h b/include/wx/mac/carbon/bitmap.h index 588cf8285b..96664c2129 100644 --- a/include/wx/mac/carbon/bitmap.h +++ b/include/wx/mac/carbon/bitmap.h @@ -47,7 +47,7 @@ public: // Construct a mask from a mono bitmap (black meaning show pixels, white meaning transparent) wxMask(const wxBitmap& bitmap); - + // implementation helper only : construct a mask from a 32 bit memory buffer wxMask(const wxMemoryBuffer& buf, int width , int height , int bytesPerRow ) ; @@ -61,10 +61,10 @@ public: void Init() ; - // a 8 bit depth mask + // a 8 bit depth mask void* GetRawAccess() const; int GetBytesPerRow() const { return m_bytesPerRow ; } - // renders/updates native representation when necessary + // renders/updates native representation when necessary void RealizeNative() ; WXHBITMAP GetHBITMAP() const ; @@ -134,8 +134,6 @@ public: // copies the contents and mask of the given (colour) icon to the bitmap virtual bool CopyFromIcon(const wxIcon& icon); - bool Ok() const { return IsOk(); } - bool IsOk() const; int GetWidth() const; int GetHeight() const; int GetDepth() const; @@ -163,7 +161,7 @@ public: bool HasAlpha() const; void UseAlpha(); - // returns the 'native' implementation, a GWorldPtr for the content and one for the mask + // returns the 'native' implementation, a GWorldPtr for the content and one for the mask WXHBITMAP GetHBITMAP( WXHBITMAP * mask = NULL ) const; // returns a CGImageRef which must released after usage with CGImageRelease @@ -181,9 +179,8 @@ public: void EndRawAccess() ; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; }; -#endif - // _WX_BITMAP_H_ + +#endif // _WX_BITMAP_H_ diff --git a/include/wx/mac/carbon/brush.h b/include/wx/mac/carbon/brush.h index 424bcf603e..e66a86f8d6 100644 --- a/include/wx/mac/carbon/brush.h +++ b/include/wx/mac/carbon/brush.h @@ -21,7 +21,7 @@ class WXDLLIMPEXP_FWD_CORE wxBrush; // Brush class WXDLLEXPORT wxBrush: public wxBrushBase { - public: +public: wxBrush(); wxBrush(const wxColour& col, int style = wxSOLID); wxBrush(const wxBitmap& stipple); @@ -32,20 +32,19 @@ class WXDLLEXPORT wxBrush: public wxBrushBase virtual void SetStyle(int style) ; virtual void SetStipple(const wxBitmap& stipple) ; - bool operator == (const wxBrush& brush) const; - bool operator != (const wxBrush& brush) const - { return !(*this == brush); } + bool operator==(const wxBrush& brush) const; + bool operator!=(const wxBrush& brush) const { return !(*this == brush); } const wxColour& GetColour() const ; virtual int GetStyle() const ; wxBitmap *GetStipple() const ; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: - DECLARE_DYNAMIC_CLASS(wxBrush) + DECLARE_DYNAMIC_CLASS(wxBrush) }; -#endif - // _WX_BRUSH_H_ +#endif // _WX_BRUSH_H_ diff --git a/include/wx/mac/carbon/colour.h b/include/wx/mac/carbon/colour.h index 7dbf363764..b98d292dfd 100644 --- a/include/wx/mac/carbon/colour.h +++ b/include/wx/mac/carbon/colour.h @@ -34,7 +34,7 @@ public: virtual ~wxColour(); // accessors - bool IsOk() const; + virtual bool IsOk() const { return m_cgColour; } ChannelType Red() const { return m_red; } ChannelType Green() const { return m_green; } diff --git a/include/wx/mac/carbon/cursor.h b/include/wx/mac/carbon/cursor.h index 7cbe319bc6..9e1d4e0a55 100644 --- a/include/wx/mac/carbon/cursor.h +++ b/include/wx/mac/carbon/cursor.h @@ -15,38 +15,40 @@ #include "wx/bitmap.h" // Cursor -class WXDLLEXPORT wxCursor: public wxGDIObject +class WXDLLEXPORT wxCursor : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxCursor) - public: - wxCursor(); + wxCursor(); - wxCursor(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, - const char maskBits[] = NULL); + 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 **bits) ; wxCursor(char **bits) ; wxCursor(const wxString& name, long flags = wxBITMAP_TYPE_MACCURSOR_RESOURCE, - int hotSpotX = 0, int hotSpotY = 0); + int hotSpotX = 0, int hotSpotY = 0); - wxCursor(int cursor_type); - virtual ~wxCursor(); + wxCursor(int cursor_type); + virtual ~wxCursor(); - bool CreateFromXpm(const char **bits) ; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const ; + bool CreateFromXpm(const char **bits) ; void MacInstall() const ; - void SetHCURSOR(WXHCURSOR cursor); - inline WXHCURSOR GetHCURSOR() const ; -private : + void SetHCURSOR(WXHCURSOR cursor); + WXHCURSOR GetHCURSOR() const; + +private: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + void CreateFromImage(const wxImage & image) ; + + DECLARE_DYNAMIC_CLASS(wxCursor) }; extern WXDLLEXPORT void wxSetCursor(const wxCursor& cursor); -#endif - // _WX_CURSOR_H_ +#endif // _WX_CURSOR_H_ diff --git a/include/wx/mac/carbon/font.h b/include/wx/mac/carbon/font.h index 9863e0325d..6266ea102c 100644 --- a/include/wx/mac/carbon/font.h +++ b/include/wx/mac/carbon/font.h @@ -52,11 +52,11 @@ public: bool MacCreateFromThemeFont( wxUint16 themeFontID ) ; #if wxMAC_USE_CORE_TEXT - bool MacCreateFromUIFont( wxUint32 coreTextFontType ); + bool MacCreateFromUIFont( wxUint32 coreTextFontType ); bool MacCreateFromCTFontDescriptor( const void * ctFontDescriptor, int pointSize = 0 ); bool MacCreateFromCTFont( const void * ctFont ); #endif - + virtual ~wxFont(); // implement base class pure virtuals @@ -88,13 +88,13 @@ public: virtual bool GetNoAntiAliasing() const ; // Mac-specific, risks to change, don't use in portable code - + #if wxMAC_USE_ATSU_TEXT // 'old' Quickdraw accessors short MacGetFontNum() const; short MacGetFontSize() const; wxByte MacGetFontStyle() const; - + // 'new' ATSUI accessors wxUint32 MacGetATSUFontID() const; wxUint32 MacGetATSUAdditionalQDStyles() const; @@ -107,14 +107,17 @@ public: const void * MacGetCTFontDescriptor() const; #endif #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT - void* MacGetATSUStyle() const ; + void* MacGetATSUStyle() const ; #endif - + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: void Unshare(); DECLARE_DYNAMIC_CLASS(wxFont) }; -#endif - // _WX_FONT_H_ +#endif // _WX_FONT_H_ diff --git a/include/wx/mac/carbon/icon.h b/include/wx/mac/carbon/icon.h index 5e786bca58..ead16ba56b 100644 --- a/include/wx/mac/carbon/icon.h +++ b/include/wx/mac/carbon/icon.h @@ -15,7 +15,7 @@ #include "wx/bitmap.h" // Icon -class WXDLLEXPORT wxIcon: public wxGDIObject +class WXDLLEXPORT wxIcon : public wxGDIObject { public: wxIcon(); @@ -45,8 +45,6 @@ public: // ctors, assignment operators...), but it's ok to have such function void CopyFromBitmap(const wxBitmap& bmp); - bool Ok() const { return IsOk(); } - bool IsOk() const; int GetWidth() const; int GetHeight() const; int GetDepth() const; @@ -57,6 +55,11 @@ public: WXHICON GetHICON() const ; +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + +private: DECLARE_DYNAMIC_CLASS(wxIcon) }; diff --git a/include/wx/mac/carbon/metafile.h b/include/wx/mac/carbon/metafile.h index 4188807b8a..694e45fb28 100644 --- a/include/wx/mac/carbon/metafile.h +++ b/include/wx/mac/carbon/metafile.h @@ -37,9 +37,8 @@ class wxMetafileRefData ; #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) -class WXDLLEXPORT wxMetafile: public wxGDIObject +class WXDLLEXPORT wxMetafile : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxMetafile) public: wxMetafile(const wxString& file = wxEmptyString); virtual ~wxMetafile(void); @@ -49,8 +48,6 @@ public: virtual bool SetClipboard(int width = 0, int height = 0); virtual bool Play(wxDC *dc); - bool Ok() const { return IsOk(); } - bool IsOk() const ; wxSize GetSize() const; int GetWidth() const { return GetSize().x; } @@ -65,6 +62,12 @@ public: // backwards compatibility void SetPICT(void* pictHandle) ; #endif + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + + DECLARE_DYNAMIC_CLASS(wxMetafile) }; @@ -89,7 +92,7 @@ protected: virtual void DoGetSize(int *width, int *height) const; wxMetafile* m_metaFile; - + private: DECLARE_CLASS(wxMetafileDCImpl) DECLARE_NO_COPY_CLASS(wxMetafileDCImpl) @@ -105,19 +108,19 @@ class WXDLLEXPORT wxMetafileDC: public wxDC const wxString& description = wxEmptyString ) : wxDC( new wxMetafileDCImpl( this, filename, width, height, description) ) { } - - wxMetafile *GetMetafile() const + + wxMetafile *GetMetafile() const { return ((wxMetafileDCImpl*)m_pimpl)->GetMetaFile(); } - + wxMetafile *Close() { return ((wxMetafileDCImpl*)m_pimpl)->Close(); } - + private: DECLARE_CLASS(wxMetafileDC) DECLARE_NO_COPY_CLASS(wxMetafileDC) }; - - + + /* * Pass filename of existing non-placeable metafile, and bounding box. * Adds a placeable metafile header, sets the mapping mode to anisotropic, @@ -141,7 +144,7 @@ class WXDLLEXPORT wxMetafileDataObject : public wxDataObjectSimple { public: // ctors - wxMetafileDataObject() + wxMetafileDataObject() : wxDataObjectSimple(wxDF_METAFILE) { }; wxMetafileDataObject(const wxMetafile& metafile) : wxDataObjectSimple(wxDF_METAFILE), m_metafile(metafile) { } diff --git a/include/wx/mac/carbon/palette.h b/include/wx/mac/carbon/palette.h index 0532aed4e1..b7429d9200 100644 --- a/include/wx/mac/carbon/palette.h +++ b/include/wx/mac/carbon/palette.h @@ -12,27 +12,11 @@ #ifndef _WX_PALETTE_H_ #define _WX_PALETTE_H_ -#include "wx/colour.h" #include "wx/gdiobj.h" -class WXDLLIMPEXP_FWD_CORE wxPalette; - -class WXDLLEXPORT wxPaletteRefData: public wxGDIRefData -{ - DECLARE_NO_COPY_CLASS(wxPaletteRefData) - - friend class WXDLLIMPEXP_FWD_CORE wxPalette; -public: - wxPaletteRefData(); - virtual ~wxPaletteRefData(); -protected: - wxColour* m_palette; - wxInt32 m_count ; -}; - #define M_PALETTEDATA ((wxPaletteRefData *)m_refData) -class WXDLLEXPORT wxPalette: public wxPaletteBase +class WXDLLEXPORT wxPalette : public wxPaletteBase { public: wxPalette(); @@ -40,18 +24,18 @@ public: wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); virtual ~wxPalette(); bool Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); - + int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; bool GetRGB(int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return (m_refData != NULL) ; } - virtual int GetColoursCount() const; - + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxPalette) }; -#endif - // _WX_PALETTE_H_ +#endif // _WX_PALETTE_H_ diff --git a/include/wx/mac/carbon/pen.h b/include/wx/mac/carbon/pen.h index 69eae585d3..ee28813e40 100644 --- a/include/wx/mac/carbon/pen.h +++ b/include/wx/mac/carbon/pen.h @@ -16,48 +16,51 @@ #include "wx/colour.h" #include "wx/bitmap.h" -class WXDLLIMPEXP_FWD_CORE wxPen; - // Pen -class WXDLLEXPORT wxPen: public wxGDIObject +class WXDLLEXPORT wxPen : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxPen) public: - wxPen(); - wxPen(const wxColour& col, int width = 1, int style = wxSOLID); - wxPen(const wxBitmap& stipple, int width); - virtual ~wxPen(); + wxPen(); + wxPen(const wxColour& col, int width = 1, int style = wxSOLID); + wxPen(const wxBitmap& stipple, int width); + virtual ~wxPen(); + + bool operator==(const wxPen& pen) const; + bool operator!=(const wxPen& pen) const { return !(*this == pen); } - bool operator == (const wxPen& pen) const; - bool operator != (const wxPen& pen) const { return !(*this == pen); } + // Override in order to recreate the pen + void SetColour(const wxColour& col) ; + void SetColour(unsigned char r, unsigned char g, unsigned char b) ; - // Override in order to recreate the pen - void SetColour(const wxColour& col) ; - void SetColour(unsigned char r, unsigned char g, unsigned char b) ; + void SetWidth(int width) ; + void SetStyle(int style) ; + void SetStipple(const wxBitmap& stipple) ; + void SetDashes(int nb_dashes, const wxDash *dash) ; + void SetJoin(int join) ; + void SetCap(int cap) ; - void SetWidth(int width) ; - void SetStyle(int style) ; - void SetStipple(const wxBitmap& stipple) ; - void SetDashes(int nb_dashes, const wxDash *dash) ; - void SetJoin(int join) ; - void SetCap(int cap) ; + wxColour& GetColour() const ; + int GetWidth() const; + int GetStyle() const; + int GetJoin() const; + int GetCap() const; + int GetDashes(wxDash **ptr) const; - wxColour& GetColour() const ; - int GetWidth() const; - int GetStyle() const; - int GetJoin() const; - int GetCap() const; - int GetDashes(wxDash **ptr) const; + wxBitmap *GetStipple() const ; - wxBitmap *GetStipple() const ; + // Implementation -// Implementation + // Useful helper: create the brush resource + bool RealizeResource(); - // Useful helper: create the brush resource - bool RealizeResource(); +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: void Unshare(); + + DECLARE_DYNAMIC_CLASS(wxPen) }; #endif diff --git a/include/wx/mac/carbon/region.h b/include/wx/mac/carbon/region.h index ba2a0ae5d0..f04cdef8d9 100644 --- a/include/wx/mac/carbon/region.h +++ b/include/wx/mac/carbon/region.h @@ -43,6 +43,9 @@ public: const WXHRGN GetWXHRGN() const ; protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + virtual bool DoIsEqual(const wxRegion& region) const; virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; diff --git a/include/wx/mgl/bitmap.h b/include/wx/mgl/bitmap.h index ab6806b3e9..60bfc1c335 100644 --- a/include/wx/mgl/bitmap.h +++ b/include/wx/mgl/bitmap.h @@ -38,8 +38,6 @@ public: wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_RESOURCE); wxBitmap(const wxImage& image, int depth = -1); virtual ~wxBitmap() {} - bool Ok() const { return IsOk(); } - bool IsOk() const; bool Create(int width, int height, int depth = -1); diff --git a/include/wx/mgl/brush.h b/include/wx/mgl/brush.h index 97fccfdd1a..afb78bafa5 100644 --- a/include/wx/mgl/brush.h +++ b/include/wx/mgl/brush.h @@ -27,17 +27,15 @@ class WXDLLIMPEXP_FWD_CORE wxBrush; // wxBrush //----------------------------------------------------------------------------- -class WXDLLEXPORT wxBrush: public wxBrushBase +class WXDLLEXPORT wxBrush : public wxBrushBase { public: wxBrush() {} wxBrush(const wxColour &colour, int style = wxSOLID); wxBrush(const wxBitmap &stippleBitmap); - virtual ~wxBrush() {} - bool operator == (const wxBrush& brush) const; - bool operator != (const wxBrush& brush) const; - bool Ok() const { return IsOk(); } - bool IsOk() const; + + bool operator==(const wxBrush& brush) const; + bool operator!=(const wxBrush& brush) const; virtual int GetStyle() const; wxColour &GetColour() const; @@ -54,9 +52,8 @@ public: void* GetPixPattern() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxBrush) diff --git a/include/wx/mgl/cursor.h b/include/wx/mgl/cursor.h index 1b3f118b3f..7e2ebb3c51 100644 --- a/include/wx/mgl/cursor.h +++ b/include/wx/mgl/cursor.h @@ -10,8 +10,7 @@ #ifndef __WX_CURSOR_H__ #define __WX_CURSOR_H__ -#include "wx/defs.h" -#include "wx/object.h" +#include "wx/gdiobj.h" #include "wx/gdicmn.h" class MGLCursor; @@ -20,7 +19,7 @@ class MGLCursor; // wxCursor //----------------------------------------------------------------------------- -class WXDLLEXPORT wxCursor: public wxObject +class WXDLLEXPORT wxCursor : public wxGDIObject { public: @@ -33,8 +32,6 @@ public: long flags = wxBITMAP_TYPE_CUR_RESOURCE, int hotSpotX = 0, int hotSpotY = 0); virtual ~wxCursor(); - bool Ok() const { return IsOk(); } - bool IsOk() const; // implementation MGLCursor *GetMGLCursor() const; diff --git a/include/wx/mgl/font.h b/include/wx/mgl/font.h index a8f9a25fbe..7d9c9ba172 100644 --- a/include/wx/mgl/font.h +++ b/include/wx/mgl/font.h @@ -87,8 +87,8 @@ public: protected: // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxFont) diff --git a/include/wx/mgl/palette.h b/include/wx/mgl/palette.h index 459403fc40..72fb6178ca 100644 --- a/include/wx/mgl/palette.h +++ b/include/wx/mgl/palette.h @@ -27,16 +27,12 @@ struct palette_t; // wxPalette //----------------------------------------------------------------------------- -class WXDLLEXPORT wxPalette: public wxPaletteBase +class WXDLLEXPORT wxPalette : public wxPaletteBase { - DECLARE_DYNAMIC_CLASS(wxPalette) - public: wxPalette(); wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); virtual ~wxPalette(); - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const; bool Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; @@ -46,6 +42,8 @@ public: virtual int GetColoursCount() const; palette_t *GetMGLpalette_t() const; + + DECLARE_DYNAMIC_CLASS(wxPalette) }; #endif // __WX_PALETTE_H__ diff --git a/include/wx/mgl/pen.h b/include/wx/mgl/pen.h index 6dd307ae0c..c8dfd2b533 100644 --- a/include/wx/mgl/pen.h +++ b/include/wx/mgl/pen.h @@ -27,7 +27,7 @@ class WXDLLIMPEXP_FWD_CORE wxPen; // wxPen //----------------------------------------------------------------------------- -class WXDLLEXPORT wxPen: public wxGDIObject +class WXDLLEXPORT wxPen : public wxGDIObject { public: wxPen() {} @@ -56,16 +56,12 @@ public: wxDash* GetDash() const; wxBitmap *GetStipple() const; - bool Ok() const { return IsOk(); } - bool IsOk() const; - // implementation: void* GetPixPattern() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxPen) diff --git a/include/wx/mgl/region.h b/include/wx/mgl/region.h index f1ae0e3e46..838ba5e118 100644 --- a/include/wx/mgl/region.h +++ b/include/wx/mgl/region.h @@ -44,9 +44,8 @@ public: const MGLRegion& GetMGLRegion() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/include/wx/motif/colour.h b/include/wx/motif/colour.h index 9c8bb43a42..a74c97321f 100644 --- a/include/wx/motif/colour.h +++ b/include/wx/motif/colour.h @@ -36,7 +36,7 @@ public: // accessors - bool IsOk() const {return m_isInit; } + virtual bool IsOk() const {return m_isInit; } unsigned char Red() const { return m_red; } unsigned char Green() const { return m_green; } unsigned char Blue() const { return m_blue; } diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 11a68c5364..ccb7837598 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -12,16 +12,14 @@ #ifndef _WX_CURSOR_H_ #define _WX_CURSOR_H_ -#include "wx/object.h" +#include "wx/gdiobj.h" #include "wx/gdicmn.h" class WXDLLIMPEXP_FWD_CORE wxImage; // Cursor -class WXDLLEXPORT wxCursor: public wxObject +class WXDLLEXPORT wxCursor : public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxCursor) - public: wxCursor(); @@ -39,12 +37,14 @@ public: wxCursor(wxStockCursor id); virtual ~wxCursor(); - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const; - // Motif-specific. // Create/get a cursor for the current display WXCursor GetXCursor(WXDisplay* display) const; + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: void Create(const char bits[], int width, int height, int hotSpotX = -1, int hotSpotY = -1, @@ -53,6 +53,8 @@ private: // Make a cursor from standard id WXCursor MakeCursor(WXDisplay* display, wxStockCursor id) const; + + DECLARE_DYNAMIC_CLASS(wxCursor) }; extern WXDLLEXPORT void wxSetCursor(const wxCursor& cursor); diff --git a/include/wx/motif/font.h b/include/wx/motif/font.h index 69f0a5cea8..bd8eff6b26 100644 --- a/include/wx/motif/font.h +++ b/include/wx/motif/font.h @@ -107,7 +107,11 @@ public: // like the function above but does a copy for XmFontList WXFontType GetFontTypeC(WXDisplay* display) const; static WXString GetFontTag(); + protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info ); void Unshare(); @@ -116,5 +120,4 @@ private: DECLARE_DYNAMIC_CLASS(wxFont) }; -#endif -// _WX_FONT_H_ +#endif // _WX_FONT_H_ diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 8c239785af..176eb45edb 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -176,7 +176,7 @@ public: protected: virtual wxGDIImageRefData *CreateData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // creates an uninitialized bitmap, called from Create()s above bool DoCreate(int w, int h, int depth, WXHDC hdc); diff --git a/include/wx/msw/brush.h b/include/wx/msw/brush.h index 6e21585ad1..5cac035628 100644 --- a/include/wx/msw/brush.h +++ b/include/wx/msw/brush.h @@ -42,19 +42,15 @@ public: virtual int GetStyle() const; wxBitmap *GetStipple() const; - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - // return the HBRUSH for this brush virtual WXHANDLE GetResourceHandle() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxBrush) }; -#endif - // _WX_BRUSH_H_ +#endif // _WX_BRUSH_H_ diff --git a/include/wx/msw/colour.h b/include/wx/msw/colour.h index 64adfe9c3f..1476009227 100644 --- a/include/wx/msw/colour.h +++ b/include/wx/msw/colour.h @@ -36,7 +36,7 @@ public: // accessors // --------- - bool IsOk() const { return m_isInit; } + virtual bool IsOk() const { return m_isInit; } unsigned char Red() const { return m_red; } unsigned char Green() const { return m_green; } diff --git a/include/wx/msw/enhmeta.h b/include/wx/msw/enhmeta.h index f03827e52b..2e894bbbb5 100644 --- a/include/wx/msw/enhmeta.h +++ b/include/wx/msw/enhmeta.h @@ -13,6 +13,7 @@ #define _WX_MSW_ENHMETA_H_ #include "wx/dc.h" +#include "wx/gdiobj.h" #if wxUSE_DRAG_AND_DROP #include "wx/dataobj.h" @@ -22,12 +23,12 @@ // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxEnhMetaFile : public wxObject +class WXDLLEXPORT wxEnhMetaFile : public wxGDIObject { public: wxEnhMetaFile(const wxString& file = wxEmptyString) : m_filename(file) { Init(); } - wxEnhMetaFile(const wxEnhMetaFile& metafile) : wxObject() + wxEnhMetaFile(const wxEnhMetaFile& metafile) : wxGDIObject() { Init(); Assign(metafile); } wxEnhMetaFile& operator=(const wxEnhMetaFile& metafile) { Free(); Assign(metafile); return *this; } @@ -39,8 +40,7 @@ public: bool Play(wxDC *dc, wxRect *rectBound = (wxRect *)NULL); // accessors - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_hMF != 0; } + virtual bool IsOk() const { return m_hMF != 0; } wxSize GetSize() const; int GetWidth() const { return GetSize().x; } @@ -62,6 +62,11 @@ protected: void Free(); void Assign(const wxEnhMetaFile& mf); + // we don't use these functions (but probably should) but have to implement + // them as they're pure virtual in the base class + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: wxString m_filename; WXHANDLE m_hMF; diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index 2437e22f4a..206f2ba65a 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -135,8 +135,8 @@ protected: virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info); // implement wxObject virtuals which are used by AllocExclusive() - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxFont) diff --git a/include/wx/msw/gdiimage.h b/include/wx/msw/gdiimage.h index b22ff3ceaa..2a085f319f 100644 --- a/include/wx/msw/gdiimage.h +++ b/include/wx/msw/gdiimage.h @@ -51,7 +51,7 @@ public: } // accessors - bool IsOk() const { return m_handle != 0; } + virtual bool IsOk() const { return m_handle != 0; } void SetSize(int w, int h) { m_width = w; m_height = h; } @@ -154,9 +154,6 @@ public: void SetHandle(WXHANDLE handle) { AllocExclusive(); GetGDIImageData()->m_handle = handle; } - bool Ok() const { return IsOk(); } - bool IsOk() const { return GetHandle() != 0; } - int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; } int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; } int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; } @@ -180,8 +177,17 @@ protected: // create the data for the derived class here virtual wxGDIImageRefData *CreateData() const = 0; - // implement the wxObject method in terms of our, more specific, one - virtual wxObjectRefData *CreateRefData() const { return CreateData(); } + // implement the wxGDIObject method in terms of our, more specific, one + virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); } + + // we can't [efficiently] clone objects of this class + virtual wxGDIRefData * + CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const + { + wxFAIL_MSG( _T("must be implemented if used") ); + + return NULL; + } static wxGDIImageHandlerList ms_handlers; }; diff --git a/include/wx/msw/metafile.h b/include/wx/msw/metafile.h index 8ac8a37734..a74416887e 100644 --- a/include/wx/msw/metafile.h +++ b/include/wx/msw/metafile.h @@ -27,15 +27,18 @@ class WXDLLIMPEXP_FWD_CORE wxMetafile; class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData { - friend class WXDLLIMPEXP_FWD_CORE wxMetafile; public: wxMetafileRefData(); virtual ~wxMetafileRefData(); + virtual bool IsOk() const { return m_metafile != 0; } + public: WXHANDLE m_metafile; int m_windowsMappingMode; int m_width, m_height; + + friend class WXDLLIMPEXP_FWD_CORE wxMetafile; }; #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) @@ -51,8 +54,6 @@ public: virtual bool SetClipboard(int width = 0, int height = 0); virtual bool Play(wxDC *dc); - bool Ok() const { return IsOk(); } - bool IsOk() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; // set/get the size of metafile for clipboard operations wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); } @@ -96,6 +97,9 @@ public: protected: virtual void DoGetSize(int *width, int *height) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + int m_windowsMappingMode; wxMetafile* m_metaFile; diff --git a/include/wx/msw/palette.h b/include/wx/msw/palette.h index bbeab7e7dd..ee404a1881 100644 --- a/include/wx/msw/palette.h +++ b/include/wx/msw/palette.h @@ -14,45 +14,38 @@ #include "wx/gdiobj.h" -class WXDLLIMPEXP_FWD_CORE wxPalette; - -class WXDLLEXPORT wxPaletteRefData: public wxGDIRefData +class WXDLLEXPORT wxPalette : public wxPaletteBase { - friend class WXDLLIMPEXP_FWD_CORE wxPalette; public: - wxPaletteRefData(void); - virtual ~wxPaletteRefData(void); -protected: - WXHPALETTE m_hPalette; -}; + wxPalette() { } + wxPalette(int n, + unsigned char *red, unsigned char *green, unsigned char *blue) + { + Create(n, red, green, blue); + } -#define M_PALETTEDATA ((wxPaletteRefData *)m_refData) - -class WXDLLEXPORT wxPalette: public wxPaletteBase -{ -public: - wxPalette(); - wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); - virtual ~wxPalette(void); - bool Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); - - int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; - bool GetRGB(int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const; + bool Create(int n, + unsigned char *red, unsigned char *green, unsigned char *blue); virtual int GetColoursCount() const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk(void) const { return (m_refData != NULL) ; } + int + GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; - virtual bool FreeResource(bool force = false); + bool + GetRGB(int pixel, + unsigned char *red, unsigned char *green, unsigned char *blue) const; // implemetation - inline WXHPALETTE GetHPALETTE(void) const { return (M_PALETTEDATA ? M_PALETTEDATA->m_hPalette : 0); } + WXHPALETTE GetHPALETTE() const; void SetHPALETTE(WXHPALETTE pal); - + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxPalette) }; -#endif - // _WX_PALETTE_H_ +#endif // _WX_PALETTE_H_ diff --git a/include/wx/msw/pen.h b/include/wx/msw/pen.h index 95c50c06ab..448c58e69e 100644 --- a/include/wx/msw/pen.h +++ b/include/wx/msw/pen.h @@ -30,9 +30,6 @@ public: bool operator==(const wxPen& pen) const; bool operator!=(const wxPen& pen) const { return !(*this == pen); } - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return (m_refData != NULL); } - // Override in order to recreate the pen void SetColour(const wxColour& col); void SetColour(unsigned char r, unsigned char g, unsigned char b); @@ -61,8 +58,8 @@ public: virtual bool IsFree() const; protected: - virtual wxObjectRefData* CreateRefData() const; - virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const; + virtual wxGDIRefData* CreateGDIRefData() const; + virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const; // same as FreeResource() + RealizeResource() bool Recreate(); diff --git a/include/wx/msw/region.h b/include/wx/msw/region.h index 97203acb3f..a52b9f15d4 100644 --- a/include/wx/msw/region.h +++ b/include/wx/msw/region.h @@ -43,8 +43,8 @@ public: WXHRGN GetHRGN() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; virtual bool DoIsEqual(const wxRegion& region) const; virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; diff --git a/include/wx/os2/bitmap.h b/include/wx/os2/bitmap.h index ef7f919bb8..ff7fccded8 100644 --- a/include/wx/os2/bitmap.h +++ b/include/wx/os2/bitmap.h @@ -216,9 +216,8 @@ protected: bool CreateFromImage(const wxImage& image, int depth); - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: bool CopyFromIconOrCursor(const wxGDIImage& rIcon); diff --git a/include/wx/os2/brush.h b/include/wx/os2/brush.h index 9743686938..4d62415e98 100644 --- a/include/wx/os2/brush.h +++ b/include/wx/os2/brush.h @@ -68,9 +68,6 @@ public: inline wxBitmap* GetStipple(void) const { return (M_BRUSHDATA ? & M_BRUSHDATA->m_vStipple : 0); }; inline int GetPS(void) const { return (M_BRUSHDATA ? M_BRUSHDATA->m_hBrush : 0); }; - inline virtual bool Ok() const { return IsOk(); } - inline virtual bool IsOk(void) const { return (m_refData != NULL) ; } - // // Implementation // diff --git a/include/wx/os2/colour.h b/include/wx/os2/colour.h index 02b7fc00df..90e1fe0290 100644 --- a/include/wx/os2/colour.h +++ b/include/wx/os2/colour.h @@ -34,7 +34,7 @@ public: virtual ~wxColour(); // Accessors - bool IsOk(void) const {return m_bIsInit; } + virtual bool IsOk(void) const { return m_bIsInit; } unsigned char Red(void) const { return m_cRed; } unsigned char Green(void) const { return m_cGreen; } diff --git a/include/wx/os2/gdiimage.h b/include/wx/os2/gdiimage.h index 7269022b2b..de43fec73a 100644 --- a/include/wx/os2/gdiimage.h +++ b/include/wx/os2/gdiimage.h @@ -41,7 +41,7 @@ public: } // accessors - bool IsOk() const + virtual bool IsOk() const { if (m_hHandle == 0) return false; @@ -187,9 +187,6 @@ public: pData->m_hHandle = hHandle; } - bool Ok() const { return IsOk(); } - bool IsOk() const { return GetHandle() != 0; } - int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_nWidth; } int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_nHeight; } int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_nDepth; } @@ -232,6 +229,7 @@ public: protected: // create the data for the derived class here virtual wxGDIImageRefData* CreateData() const = 0; + virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); } static wxGDIImageHandlerList ms_handlers; }; diff --git a/include/wx/os2/metafile.h b/include/wx/os2/metafile.h index 55cf236972..6a79199a78 100644 --- a/include/wx/os2/metafile.h +++ b/include/wx/os2/metafile.h @@ -39,6 +39,8 @@ public: wxMetafileRefData(void); virtual ~wxMetafileRefData(void); + virtual bool IsOk() const { return m_metafile != 0; } + public: WXHANDLE m_metafile; int m_windowsMappingMode; @@ -58,8 +60,6 @@ public: virtual bool SetClipboard(int width = 0, int height = 0); virtual bool Play(wxDC *dc); - inline bool Ok() const { return IsOk(); } - inline bool IsOk(void) const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; // Implementation inline WXHANDLE GetHMETAFILE(void) { return M_METAFILEDATA->m_metafile; } diff --git a/include/wx/os2/palette.h b/include/wx/os2/palette.h index 3f094805f2..ba3109be26 100644 --- a/include/wx/os2/palette.h +++ b/include/wx/os2/palette.h @@ -59,9 +59,6 @@ public: ,unsigned char* pBlue ) const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk(void) const { return (m_refData != NULL) ; } - virtual bool FreeResource(bool bForce = false); inline WXHPALETTE GetHPALETTE(void) const { return (M_PALETTEDATA ? M_PALETTEDATA->m_hPalette : 0); } diff --git a/include/wx/os2/pen.h b/include/wx/os2/pen.h index a036a152a0..86ce52baf8 100644 --- a/include/wx/os2/pen.h +++ b/include/wx/os2/pen.h @@ -81,9 +81,6 @@ public: inline bool operator != (const wxPen& rPen) const { return !(*this == rPen); } - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk(void) const { return (m_refData != NULL); } - // // Override in order to recreate the pen // diff --git a/include/wx/os2/region.h b/include/wx/os2/region.h index 22a48dc188..882315fcec 100644 --- a/include/wx/os2/region.h +++ b/include/wx/os2/region.h @@ -64,8 +64,8 @@ public: void SetPS(HPS hPS); protected: - virtual wxObjectRefData* CreateData(void) const; - virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const; + virtual wxGDIRefData* CreateData(void) const; + virtual wxGDIRefData* CloneData(const wxGDIRefData* pData) const; virtual bool DoIsEqual(const wxRegion& region) const; virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; diff --git a/include/wx/palette.h b/include/wx/palette.h index 8f2e85363d..491838d3cd 100644 --- a/include/wx/palette.h +++ b/include/wx/palette.h @@ -25,8 +25,6 @@ class WXDLLEXPORT wxPaletteBase: public wxGDIObject public: virtual ~wxPaletteBase() { } - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const = 0; virtual int GetColoursCount() const { wxFAIL_MSG( _T("not implemented") ); return 0; } }; diff --git a/include/wx/palmos/brush.h b/include/wx/palmos/brush.h index 6d45ab0298..495ea2e649 100644 --- a/include/wx/palmos/brush.h +++ b/include/wx/palmos/brush.h @@ -42,19 +42,15 @@ public: virtual int GetStyle() const; wxBitmap *GetStipple() const; - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - // return the HBRUSH for this brush virtual WXHANDLE GetResourceHandle() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxBrush) }; -#endif - // _WX_BRUSH_H_ +#endif // _WX_BRUSH_H_ diff --git a/include/wx/palmos/enhmeta.h b/include/wx/palmos/enhmeta.h index c7cd751477..1501435442 100644 --- a/include/wx/palmos/enhmeta.h +++ b/include/wx/palmos/enhmeta.h @@ -13,6 +13,7 @@ #define _WX_PALMOS_ENHMETA_H_ #include "wx/dc.h" +#include "wx/gdiobj.h" #if wxUSE_DRAG_AND_DROP #include "wx/dataobj.h" @@ -22,7 +23,7 @@ // wxEnhMetaFile: encapsulation of Win32 HENHMETAFILE // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxEnhMetaFile : public wxObject +class WXDLLEXPORT wxEnhMetaFile : public wxGDIObject { public: wxEnhMetaFile(const wxString& file = wxEmptyString) : m_filename(file) @@ -39,8 +40,7 @@ public: bool Play(wxDC *dc, wxRect *rectBound = (wxRect *)NULL); // accessors - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_hMF != 0; } + virtual bool IsOk() const { return m_hMF != 0; } wxSize GetSize() const; int GetWidth() const { return GetSize().x; } diff --git a/include/wx/palmos/gdiimage.h b/include/wx/palmos/gdiimage.h index 5c2bfcdeba..3d5253328b 100644 --- a/include/wx/palmos/gdiimage.h +++ b/include/wx/palmos/gdiimage.h @@ -41,7 +41,7 @@ public: } // accessors - bool IsOk() const { return m_handle != 0; } + virtual bool IsOk() const { return m_handle != 0; } void SetSize(int w, int h) { m_width = w; m_height = h; } @@ -147,9 +147,6 @@ public: void SetHandle(WXHANDLE handle) { EnsureHasData(); GetGDIImageData()->m_handle = handle; } - bool Ok() const { return IsOk(); } - bool IsOk() const { return GetHandle() != 0; } - int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; } int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; } int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; } @@ -172,6 +169,7 @@ public: protected: // create the data for the derived class here virtual wxGDIImageRefData *CreateData() const = 0; + virtual wxGDIRefData *CreateGDIRefData() const { return CreateData(); } static wxGDIImageHandlerList ms_handlers; }; diff --git a/include/wx/palmos/metafile.h b/include/wx/palmos/metafile.h index ccbb807c26..3a0c60eb8a 100644 --- a/include/wx/palmos/metafile.h +++ b/include/wx/palmos/metafile.h @@ -27,15 +27,18 @@ class WXDLLIMPEXP_FWD_CORE wxMetafile; class WXDLLEXPORT wxMetafileRefData: public wxGDIRefData { - friend class WXDLLIMPEXP_FWD_CORE wxMetafile; public: wxMetafileRefData(); virtual ~wxMetafileRefData(); + virtual bool IsOk() const { return m_metafile != 0; } + public: WXHANDLE m_metafile; int m_windowsMappingMode; int m_width, m_height; + + friend class WXDLLIMPEXP_FWD_CORE wxMetafile; }; #define M_METAFILEDATA ((wxMetafileRefData *)m_refData) @@ -51,8 +54,6 @@ public: virtual bool SetClipboard(int width = 0, int height = 0); virtual bool Play(wxDC *dc); - bool Ok() const { return IsOk(); } - bool IsOk() const { return (M_METAFILEDATA && (M_METAFILEDATA->m_metafile != 0)); }; // set/get the size of metafile for clipboard operations wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); } diff --git a/include/wx/palmos/palette.h b/include/wx/palmos/palette.h index 668e05116f..86c6a6970f 100644 --- a/include/wx/palmos/palette.h +++ b/include/wx/palmos/palette.h @@ -41,9 +41,6 @@ public: int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; bool GetRGB(int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk(void) const { return (m_refData != NULL) ; } - virtual bool FreeResource(bool force = false); inline WXHPALETTE GetHPALETTE(void) const { return (M_PALETTEDATA ? M_PALETTEDATA->m_hPalette : 0); } diff --git a/include/wx/palmos/pen.h b/include/wx/palmos/pen.h index 41a7146509..91731fcf51 100644 --- a/include/wx/palmos/pen.h +++ b/include/wx/palmos/pen.h @@ -89,9 +89,6 @@ public: bool operator!=(const wxPen& pen) const { return !(*this == pen); } - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return (m_refData != NULL); } - // Override in order to recreate the pen void SetColour(const wxColour& col); void SetColour(unsigned char r, unsigned char g, unsigned char b); diff --git a/include/wx/palmos/region.h b/include/wx/palmos/region.h index 5e973f8073..ce0586c21b 100644 --- a/include/wx/palmos/region.h +++ b/include/wx/palmos/region.h @@ -44,8 +44,8 @@ public: WXHRGN GetHRGN() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; virtual bool DoIsEqual(const wxRegion& region) const; virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; diff --git a/include/wx/private/fontmgr.h b/include/wx/private/fontmgr.h index f01604dd1e..78ab862ae3 100644 --- a/include/wx/private/fontmgr.h +++ b/include/wx/private/fontmgr.h @@ -201,7 +201,7 @@ protected: /// wxFontMgrFontRefData implementation using wxFontsManager classes -class wxFontMgrFontRefData : public wxObjectRefData +class wxFontMgrFontRefData : public wxGDIRefData { public: wxFontMgrFontRefData(int size = wxDEFAULT, diff --git a/include/wx/region.h b/include/wx/region.h index eede02e617..e2c82500b4 100644 --- a/include/wx/region.h +++ b/include/wx/region.h @@ -82,9 +82,6 @@ public: // accessors // --------- - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - // Is region empty? virtual bool IsEmpty() const = 0; bool Empty() const { return IsEmpty(); } diff --git a/include/wx/x11/bitmap.h b/include/wx/x11/bitmap.h index 6c404b6a8e..29572c4870 100644 --- a/include/wx/x11/bitmap.h +++ b/include/wx/x11/bitmap.h @@ -84,9 +84,6 @@ public: wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); virtual ~wxBitmap(); - bool Ok() const { return IsOk(); } - bool IsOk() const; - static void InitStandardHandlers(); bool Create(int width, int height, int depth = -1); @@ -138,8 +135,8 @@ public: WXDisplay *GetDisplay() const; protected: - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; private: DECLARE_DYNAMIC_CLASS(wxBitmap) diff --git a/include/wx/x11/brush.h b/include/wx/x11/brush.h index ce581ab06d..93ec215aca 100644 --- a/include/wx/x11/brush.h +++ b/include/wx/x11/brush.h @@ -26,7 +26,7 @@ class WXDLLIMPEXP_FWD_CORE wxBitmap; // wxBrush //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxBrush: public wxBrushBase +class WXDLLIMPEXP_CORE wxBrush : public wxBrushBase { public: wxBrush() { } @@ -35,11 +35,8 @@ public: wxBrush( const wxBitmap &stippleBitmap ); virtual ~wxBrush(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxBrush& brush ) const; - bool operator != (const wxBrush& brush) const { return !(*this == brush); } + bool operator==(const wxBrush& brush) const; + bool operator!=(const wxBrush& brush) const { return !(*this == brush); } virtual int GetStyle() const; wxColour &GetColour() const; @@ -51,12 +48,10 @@ public: void SetStipple( const wxBitmap& stipple ); protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxBrush) }; -#endif -// _WX_BRUSH_H_ +#endif // _WX_BRUSH_H_ diff --git a/include/wx/x11/colour.h b/include/wx/x11/colour.h index 249520c8e4..411665e88e 100644 --- a/include/wx/x11/colour.h +++ b/include/wx/x11/colour.h @@ -44,10 +44,8 @@ public: virtual ~wxColour(); - bool IsOk() const { return m_refData != NULL; } - - bool operator == ( const wxColour& col ) const; - bool operator != ( const wxColour& col ) const { return !(*this == col); } + bool operator==(const wxColour& col) const; + bool operator!=(const wxColour& col) const { return !(*this == col); } unsigned char Red() const; unsigned char Green() const; @@ -60,9 +58,8 @@ public: WXColor *GetColor() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; virtual void InitRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); @@ -73,6 +70,4 @@ private: DECLARE_DYNAMIC_CLASS(wxColour) }; -#endif - -// _WX_COLOUR_H_ +#endif // _WX_COLOUR_H_ diff --git a/include/wx/x11/cursor.h b/include/wx/x11/cursor.h index 3a22621bd1..51e6c60a5f 100644 --- a/include/wx/x11/cursor.h +++ b/include/wx/x11/cursor.h @@ -12,40 +12,38 @@ #ifndef _WX_CURSOR_H_ #define _WX_CURSOR_H_ -#include "wx/bitmap.h" +#include "wx/gdiobj.h" -#if wxUSE_IMAGE -#include "wx/image.h" -#endif +class WXDLLIMPEXP_FWD_CORE wxImage; //----------------------------------------------------------------------------- // wxCursor //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxCursor: public wxObject +class WXDLLIMPEXP_CORE wxCursor : public wxGDIObject { public: - wxCursor(); wxCursor( int cursorId ); #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 ); virtual ~wxCursor(); - bool Ok() const { return IsOk(); } - bool IsOk() const; // implementation WXCursor GetCursor() const; +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxCursor) }; - -#endif - // _WX_CURSOR_H_ +#endif // _WX_CURSOR_H_ diff --git a/include/wx/x11/font.h b/include/wx/x11/font.h index 09152d540d..6a2db7f310 100644 --- a/include/wx/x11/font.h +++ b/include/wx/x11/font.h @@ -101,6 +101,9 @@ public: #endif protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; + virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info ); void Unshare(); diff --git a/include/wx/x11/palette.h b/include/wx/x11/palette.h index bb33a74b9b..60d43c87b7 100644 --- a/include/wx/x11/palette.h +++ b/include/wx/x11/palette.h @@ -12,7 +12,6 @@ #ifndef _WX_PALETTE_H_ #define _WX_PALETTE_H_ -#include "wx/gdiobj.h" #include "wx/list.h" class WXDLLIMPEXP_FWD_CORE wxPalette; @@ -45,7 +44,7 @@ protected: #define M_PALETTEDATA ((wxPaletteRefData *)m_refData) -class WXDLLEXPORT wxPalette: public wxPaletteBase +class WXDLLEXPORT wxPalette : public wxPaletteBase { DECLARE_DYNAMIC_CLASS(wxPalette) @@ -58,16 +57,16 @@ public: int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const; bool GetRGB(int pixel, unsigned char *red, unsigned char *green, unsigned char *blue) const; - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const { return (m_refData != NULL) ; } - // X-specific WXColormap GetXColormap(WXDisplay* display = NULL) const; bool TransferBitmap(void *data, int depth, int size); bool TransferBitmap8(unsigned char *data, unsigned long size, void *dest, unsigned int bpp); unsigned long *GetXPixArray(WXDisplay* display, int *pix_array_n); void PutXColormap(WXDisplay* display, WXColormap cmap, bool destroyable); + +protected: + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; }; -#endif -// _WX_PALETTE_H_ +#endif // _WX_PALETTE_H_ diff --git a/include/wx/x11/pen.h b/include/wx/x11/pen.h index ccb6310eb5..e7d259bc9d 100644 --- a/include/wx/x11/pen.h +++ b/include/wx/x11/pen.h @@ -38,9 +38,6 @@ public: wxPen( const wxBitmap &stipple, int width ); virtual ~wxPen(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_refData != NULL; } - bool operator == ( const wxPen& pen ) const; bool operator != (const wxPen& pen) const { return !(*this == pen); } @@ -64,12 +61,10 @@ public: wxBitmap* GetStipple() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; DECLARE_DYNAMIC_CLASS(wxPen) }; -#endif -// _WX_PEN_H_ +#endif // _WX_PEN_H_ diff --git a/include/wx/x11/region.h b/include/wx/x11/region.h index ec257864a1..1ba0e898a1 100644 --- a/include/wx/x11/region.h +++ b/include/wx/x11/region.h @@ -61,9 +61,8 @@ public: WXRegion *GetX11Region() const; protected: - // ref counting code - virtual wxObjectRefData *CreateRefData() const; - virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual wxGDIRefData *CreateGDIRefData() const; + virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; // wxRegionBase pure virtuals virtual bool DoIsEqual(const wxRegion& region) const; diff --git a/src/cocoa/bitmap.mm b/src/cocoa/bitmap.mm index 05553108c4..7d04461049 100644 --- a/src/cocoa/bitmap.mm +++ b/src/cocoa/bitmap.mm @@ -46,6 +46,8 @@ public: wxBitmapRefData( const wxBitmapRefData& data ); virtual ~wxBitmapRefData(); + virtual bool IsOk() const { return m_ok; } + protected: int m_width; int m_height; @@ -145,12 +147,12 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } -wxObjectRefData *wxBitmap::CreateRefData() const +wxGDIRefData *wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBitmapRefData(*(wxBitmapRefData*)data); } @@ -254,11 +256,6 @@ void wxBitmap::SetMask(wxMask *mask) M_BITMAPDATA->m_bitmapMask = mask ; } -bool wxBitmap::IsOk() const -{ - return m_refData && M_BITMAPDATA->m_ok; -} - wxPalette* wxBitmap::GetPalette() const { if(!m_refData) diff --git a/src/cocoa/brush.mm b/src/cocoa/brush.mm index eef0553a90..6a1bce5e7f 100644 --- a/src/cocoa/brush.mm +++ b/src/cocoa/brush.mm @@ -159,12 +159,12 @@ wxBrush::wxBrush(const wxBitmap& stipple) m_refData = new wxBrushRefData(stipple); } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/cocoa/font.mm b/src/cocoa/font.mm index e18a4768b3..bac3a57df9 100644 --- a/src/cocoa/font.mm +++ b/src/cocoa/font.mm @@ -319,7 +319,7 @@ bool wxFont::Create(wxFontRefData *refData) { UnRef(); m_refData = refData; - + return m_refData != NULL; } @@ -327,10 +327,20 @@ bool wxFont::Create(const wxNativeFontInfo& nativeFontInfo) { UnRef(); m_refData = new wxFontRefData(nativeFontInfo); - + return true; } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + void wxFont::SetEncoding(wxFontEncoding) { } @@ -398,24 +408,9 @@ bool wxFont::RealizeResource() return false; } -void wxFont::Unshare() -{ - // Don't change shared data - if (!m_refData) - { - m_refData = new wxFontRefData(); - } - else - { - wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); - UnRef(); - m_refData = ref; - } -} - void wxFont::SetPointSize(int pointSize) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.pointSize = pointSize; @@ -424,7 +419,7 @@ void wxFont::SetPointSize(int pointSize) void wxFont::SetFamily(int family) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.family = static_cast(family); @@ -433,7 +428,7 @@ void wxFont::SetFamily(int family) void wxFont::SetStyle(int style) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.style = static_cast(style); @@ -442,7 +437,7 @@ void wxFont::SetStyle(int style) void wxFont::SetWeight(int weight) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.weight = static_cast(weight); @@ -451,7 +446,7 @@ void wxFont::SetWeight(int weight) bool wxFont::SetFaceName(const wxString& faceName) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.faceName = faceName; @@ -462,7 +457,7 @@ bool wxFont::SetFaceName(const wxString& faceName) void wxFont::SetUnderlined(bool underlined) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_info.underlined = underlined; diff --git a/src/cocoa/icon.mm b/src/cocoa/icon.mm index 91b059ba59..cfc23d3cd7 100644 --- a/src/cocoa/icon.mm +++ b/src/cocoa/icon.mm @@ -32,6 +32,8 @@ public: wxIconRefData( const wxIconRefData& data ); virtual ~wxIconRefData(); + virtual bool IsOk() const { return m_ok; } + protected: int m_width; int m_height; @@ -98,6 +100,16 @@ wxIcon::~wxIcon() { } +wxGDIRefData *wxIcon::CreateGDIRefData() const +{ + return new wxIconRefData; +} + +wxGDIRefData *wxIcon::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxIconRefData(*wx_static_cast(const wxIconRefData *, data)); +} + bool wxIcon::CreateFromXpm(const char **xpm) { wxBitmap bitmap(xpm); @@ -126,11 +138,6 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bitmap) M_ICONDATA->m_quality = 0; } -bool wxIcon::IsOk() const -{ - return m_refData && M_ICONDATA->m_ok; -} - int wxIcon::GetWidth() const { if(!m_refData) diff --git a/src/cocoa/pen.mm b/src/cocoa/pen.mm index b5e6e36065..5920dc035a 100644 --- a/src/cocoa/pen.mm +++ b/src/cocoa/pen.mm @@ -266,12 +266,12 @@ wxPen::wxPen(const wxBitmap& stipple, int width) m_refData = new wxPenRefData(wxNullColour,width,wxSTIPPLE,stipple); } -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 8a9063f5b3..5ac8cce15e 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -341,11 +341,6 @@ bool wxFontBase::operator==(const wxFont& font) const ); } -bool wxFontBase::operator!=(const wxFont& font) const -{ - return !(*this == font); -} - wxString wxFontBase::GetFamilyString() const { wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index fb3f055d0e..fa208d6fa2 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -34,7 +34,7 @@ #endif -IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject) +IMPLEMENT_ABSTRACT_CLASS(wxGDIObject, wxObject) WXDLLIMPEXP_DATA_CORE(wxBrushList*) wxTheBrushList; diff --git a/src/common/iconbndl.cpp b/src/common/iconbndl.cpp index 2d3074716b..11b113004f 100644 --- a/src/common/iconbndl.cpp +++ b/src/common/iconbndl.cpp @@ -51,6 +51,8 @@ class WXDLLEXPORT wxIconBundleRefData : public wxGDIRefData public: // default and copy ctors and assignment operators are ok + virtual bool IsOk() const { return !m_icons.empty(); } + protected: wxIconArray m_icons; @@ -84,12 +86,12 @@ wxIconBundle::wxIconBundle(const wxIcon& icon) AddIcon(icon); } -wxObjectRefData *wxIconBundle::CreateRefData() const +wxGDIRefData *wxIconBundle::CreateGDIRefData() const { return new wxIconBundleRefData; } -wxObjectRefData *wxIconBundle::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxIconBundle::CloneGDIRefData(const wxGDIRefData *data) const { return new wxIconBundleRefData(*wx_static_cast(const wxIconBundleRefData *, data)); } @@ -99,11 +101,6 @@ void wxIconBundle::DeleteIcons() UnRef(); } -bool wxIconBundle::IsOk() const -{ - return M_ICONBUNDLEDATA && !M_ICONBUNDLEDATA->m_icons.IsEmpty(); -} - void wxIconBundle::AddIcon(const wxString& file, long type) { #ifdef __WXMAC__ diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 0c245df509..26b3ada098 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -246,7 +246,7 @@ static DFBSurfacePixelFormat DepthToFormat(int depth) // wxBitmapRefData //----------------------------------------------------------------------------- -class wxBitmapRefData: public wxObjectRefData +class wxBitmapRefData: public wxGDIRefData { public: wxBitmapRefData() @@ -275,6 +275,8 @@ public: #endif } + virtual bool IsOk() const { return m_surface; } + wxIDirectFBSurfacePtr m_surface; wxMask *m_mask; #if wxUSE_PALETTE @@ -458,11 +460,6 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) wxFAIL_MSG( "not implemented" ); } -bool wxBitmap::IsOk() const -{ - return (m_refData != NULL && M_BITMAP->m_surface); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); @@ -644,12 +641,12 @@ wxIDirectFBSurfacePtr wxBitmap::GetDirectFBSurface() const return M_BITMAP->m_surface; } -wxObjectRefData *wxBitmap::CreateRefData() const +wxGDIRefData *wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBitmapRefData(*(wxBitmapRefData *)data); } diff --git a/src/dfb/brush.cpp b/src/dfb/brush.cpp index 93209e3362..6d310fc0bd 100644 --- a/src/dfb/brush.cpp +++ b/src/dfb/brush.cpp @@ -26,7 +26,7 @@ // wxBrush //----------------------------------------------------------------------------- -class wxBrushRefData: public wxObjectRefData +class wxBrushRefData : public wxGDIRefData { public: wxBrushRefData(const wxColour& clr = wxNullColour, int style = wxSOLID) @@ -41,6 +41,8 @@ public: m_style = data.m_style; } + virtual bool IsOk() const { return m_colour.IsOk(); } + void SetStyle(int style) { if ( style != wxSOLID && style != wxTRANSPARENT ) @@ -80,11 +82,6 @@ bool wxBrush::operator==(const wxBrush& brush) const return m_refData == brush.m_refData; } -bool wxBrush::IsOk() const -{ - return ((m_refData) && M_BRUSHDATA->m_colour.Ok()); -} - int wxBrush::GetStyle() const { if (m_refData == NULL) @@ -136,12 +133,12 @@ void wxBrush::SetStipple(const wxBitmap& WXUNUSED(stipple)) wxFAIL_MSG( wxT("brushes with stipple bitmaps not implemented") ); } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/dfb/cursor.cpp b/src/dfb/cursor.cpp index c5465f52fc..0751f9ae4e 100644 --- a/src/dfb/cursor.cpp +++ b/src/dfb/cursor.cpp @@ -22,12 +22,14 @@ // wxCursorRefData //----------------------------------------------------------------------------- -class wxCursorRefData: public wxObjectRefData +class wxCursorRefData : public wxGDIRefData { public: wxCursorRefData(const wxBitmap& bmp = wxNullBitmap, int id = -1) : m_id(id), m_bitmap(bmp) {} + virtual bool IsOk() const { return m_bitmap.IsOk(); } + int m_id; wxBitmap m_bitmap; }; @@ -63,17 +65,12 @@ wxCursor::wxCursor(const wxString& cursor_file, #warning "FIXME" } -bool wxCursor::IsOk() const -{ - return m_refData && M_CURSOR->m_bitmap.Ok(); -} - -wxObjectRefData *wxCursor::CreateRefData() const +wxGDIRefData *wxCursor::CreateGDIRefData() const { return new wxCursorRefData; } -wxObjectRefData *wxCursor::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { return new wxCursorRefData(*(wxCursorRefData *)data); } diff --git a/src/dfb/font.cpp b/src/dfb/font.cpp index 4bf8087c5b..206c11b14d 100644 --- a/src/dfb/font.cpp +++ b/src/dfb/font.cpp @@ -60,12 +60,12 @@ bool wxFont::Create(int pointSize, return true; } -wxObjectRefData *wxFont::CreateRefData() const +wxGDIRefData *wxFont::CreateGDIRefData() const { return new wxFontRefData; } -wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const { return new wxFontRefData(*(wxFontRefData *)data); } diff --git a/src/dfb/pen.cpp b/src/dfb/pen.cpp index 799f99cf0c..21d36f623e 100644 --- a/src/dfb/pen.cpp +++ b/src/dfb/pen.cpp @@ -26,7 +26,7 @@ // wxPen //----------------------------------------------------------------------------- -class wxPenRefData: public wxObjectRefData +class wxPenRefData : public wxGDIRefData { public: wxPenRefData(const wxColour& clr = wxNullColour, int style = wxSOLID) @@ -38,6 +38,8 @@ public: wxPenRefData(const wxPenRefData& data) : m_style(data.m_style), m_colour(data.m_colour) {} + virtual bool IsOk() const { return m_colour.IsOk(); } + void SetStyle(int style) { if ( style != wxSOLID && style != wxTRANSPARENT ) @@ -189,17 +191,12 @@ wxBitmap *wxPen::GetStipple() const return NULL; } -bool wxPen::IsOk() const -{ - return ((m_refData) && M_PENDATA->m_colour.Ok()); -} - -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/dfb/region.cpp b/src/dfb/region.cpp index f4bc68dcf9..f49cf3c88b 100644 --- a/src/dfb/region.cpp +++ b/src/dfb/region.cpp @@ -45,12 +45,12 @@ public: // wxRegion //----------------------------------------------------------------------------- -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/generic/paletteg.cpp b/src/generic/paletteg.cpp index ac8cd8a83b..760e6039f5 100644 --- a/src/generic/paletteg.cpp +++ b/src/generic/paletteg.cpp @@ -28,12 +28,12 @@ struct wxPaletteEntry unsigned char red, green, blue; }; -class wxPaletteRefData: public wxObjectRefData +class wxPaletteRefData : public wxGDIRefData { - public: - - wxPaletteRefData(void); - virtual ~wxPaletteRefData(void); +public: + wxPaletteRefData(); + wxPaletteRefData(const wxPaletteRefData& palette); + virtual ~wxPaletteRefData(); int m_count; wxPaletteEntry *m_entries; @@ -45,6 +45,14 @@ wxPaletteRefData::wxPaletteRefData() m_entries = NULL; } +wxPaletteRefData::wxPaletteRefData(const wxPaletteRefData& palette) +{ + m_count = palette.m_count; + m_entries = new wxPaletteEntry[m_count]; + for ( int i = 0; i < m_count; i++ ) + m_entries[i] = palette.m_entries[i]; +} + wxPaletteRefData::~wxPaletteRefData() { delete[] m_entries; @@ -70,11 +78,6 @@ wxPalette::~wxPalette() { } -bool wxPalette::IsOk() const -{ - return (m_refData != NULL); -} - int wxPalette::GetColoursCount() const { if (m_refData) @@ -142,4 +145,14 @@ bool wxPalette::GetRGB(int pixel, return true; } +wxGDIRefData *wxPalette::CreateGDIRefData() const +{ + return new wxPaletteRefData; +} + +wxGDIRefData *wxPalette::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPaletteRefData(*wx_static_cast(const wxPaletteRefData *, data)); +} + #endif // wxUSE_PALETTE diff --git a/src/generic/regiong.cpp b/src/generic/regiong.cpp index 845df56ce0..9511c83df2 100644 --- a/src/generic/regiong.cpp +++ b/src/generic/regiong.cpp @@ -176,12 +176,12 @@ protected: // wxRegionRefData // ======================================================================== -class wxRegionRefData : public wxObjectRefData, +class wxRegionRefData : public wxGDIRefData, public REGION { public: wxRegionRefData() - : wxObjectRefData(), + : wxGDIRefData(), REGION() { size = 1; @@ -194,7 +194,7 @@ public: } wxRegionRefData(const wxPoint& topLeft, const wxPoint& bottomRight) - : wxObjectRefData(), + : wxGDIRefData(), REGION() { rects = (BOX*)malloc(sizeof(BOX)); @@ -208,7 +208,7 @@ public: } wxRegionRefData(const wxRect& rect) - : wxObjectRefData(), + : wxGDIRefData(), REGION(rect) { rects = (BOX*)malloc(sizeof(BOX)); @@ -216,7 +216,7 @@ public: } wxRegionRefData(const wxRegionRefData& refData) - : wxObjectRefData(), + : wxGDIRefData(), REGION() { size = refData.size; @@ -276,12 +276,12 @@ void wxRegionGeneric::Clear() UnRef(); } -wxObjectRefData *wxRegionGeneric::CreateRefData() const +wxGDIRefData *wxRegionGeneric::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegionGeneric::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegionGeneric::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 663c9ec721..91aa96accf 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -181,12 +181,14 @@ GdkBitmap *wxMask::GetBitmap() const // wxBitmap //----------------------------------------------------------------------------- -class wxBitmapRefData: public wxObjectRefData +class wxBitmapRefData: public wxGDIRefData { public: wxBitmapRefData(); virtual ~wxBitmapRefData(); + virtual bool IsOk() const { return m_pixmap || m_pixbuf; } + GdkPixmap *m_pixmap; GdkPixbuf *m_pixbuf; wxMask *m_mask; @@ -597,15 +599,6 @@ wxImage wxBitmap::ConvertToImage() const #endif // wxUSE_IMAGE -bool wxBitmap::IsOk() const -{ - return (m_refData != NULL) && - ( - M_BMPDATA->m_pixbuf || - M_BMPDATA->m_pixmap - ); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); @@ -930,12 +923,12 @@ bool wxBitmap::HasAlpha() const gdk_pixbuf_get_has_alpha(M_BMPDATA->m_pixbuf); } -wxObjectRefData* wxBitmap::CreateRefData() const +wxGDIRefData* wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const +wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const { const wxBitmapRefData* oldRef = wx_static_cast(const wxBitmapRefData*, data); wxBitmapRefData* newRef = new wxBitmapRefData; diff --git a/src/gtk/brush.cpp b/src/gtk/brush.cpp index 4c54c10897..0106125d9a 100644 --- a/src/gtk/brush.cpp +++ b/src/gtk/brush.cpp @@ -21,7 +21,7 @@ // wxBrush //----------------------------------------------------------------------------- -class wxBrushRefData: public wxObjectRefData +class wxBrushRefData: public wxGDIRefData { public: wxBrushRefData() @@ -30,7 +30,7 @@ public: } wxBrushRefData( const wxBrushRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_style = data.m_style; m_stipple = data.m_stipple; @@ -80,17 +80,17 @@ wxBrush::~wxBrush() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } -bool wxBrush::operator == ( const wxBrush& brush ) const +bool wxBrush::operator==(const wxBrush& brush) const { if (m_refData == brush.m_refData) return true; diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index b08a6b4ab4..b2bb1b993a 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -20,7 +20,7 @@ // wxColour //----------------------------------------------------------------------------- -class wxColourRefData: public wxObjectRefData +class wxColourRefData : public wxGDIRefData { public: wxColourRefData(guint16 red, guint16 green, guint16 blue, guint16 alpha) diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 265b98cd3b..0e778d1f8c 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -25,13 +25,14 @@ // wxCursor //----------------------------------------------------------------------------- -class wxCursorRefData: public wxObjectRefData +class wxCursorRefData: public wxGDIRefData { - public: - +public: wxCursorRefData(); virtual ~wxCursorRefData(); + virtual bool IsOk() const { return m_cursor != NULL; } + GdkCursor *m_cursor; }; @@ -360,14 +361,19 @@ wxCursor::~wxCursor() { } -bool wxCursor::IsOk() const +GdkCursor *wxCursor::GetCursor() const { - return (m_refData != NULL); + return M_CURSORDATA->m_cursor; } -GdkCursor *wxCursor::GetCursor() const +wxGDIRefData *wxCursor::CreateGDIRefData() const { - return M_CURSORDATA->m_cursor; + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); } //----------------------------------------------------------------------------- diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 94cc8e66d5..77e2511b41 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -51,7 +51,7 @@ WX_DECLARE_HASH_MAP(int, GdkFont *, wxIntegerHash, wxIntegerEqual, // wxFontRefData // ---------------------------------------------------------------------------- -class wxFontRefData : public wxObjectRefData +class wxFontRefData : public wxGDIRefData { public: // from broken down font parameters, also default ctor @@ -239,7 +239,7 @@ void wxFontRefData::InitFromNative() } wxFontRefData::wxFontRefData( const wxFontRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_pointSize = data.m_pointSize; m_family = data.m_family; @@ -551,12 +551,12 @@ void wxFont::SetNoAntiAliasing( bool no ) M_FONTDATA->SetNoAntiAliasing( no ); } -wxObjectRefData* wxFont::CreateRefData() const +wxGDIRefData* wxFont::CreateGDIRefData() const { return new wxFontRefData; } -wxObjectRefData* wxFont::CloneRefData(const wxObjectRefData* data) const +wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const { return new wxFontRefData(*wx_static_cast(const wxFontRefData*, data)); } diff --git a/src/gtk/pen.cpp b/src/gtk/pen.cpp index 498f38025d..917abb974c 100644 --- a/src/gtk/pen.cpp +++ b/src/gtk/pen.cpp @@ -22,7 +22,7 @@ // wxPen //----------------------------------------------------------------------------- -class wxPenRefData: public wxObjectRefData +class wxPenRefData: public wxGDIRefData { public: wxPenRefData() @@ -36,7 +36,7 @@ public: } wxPenRefData( const wxPenRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_style = data.m_style; m_width = data.m_width; @@ -101,12 +101,12 @@ wxPen::~wxPen() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/gtk/region.cpp b/src/gtk/region.cpp index 964ae16316..a18c324df8 100644 --- a/src/gtk/region.cpp +++ b/src/gtk/region.cpp @@ -32,7 +32,7 @@ // wxRegionRefData: private class containing the information about the region // ---------------------------------------------------------------------------- -class wxRegionRefData : public wxObjectRefData +class wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() @@ -41,7 +41,7 @@ public: } wxRegionRefData(const wxRegionRefData& refData) - : wxObjectRefData() + : wxGDIRefData() { m_region = gdk_region_copy(refData.m_region); } @@ -119,12 +119,12 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index e0ceb53c45..daa51e4dc5 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -224,7 +224,7 @@ GdkBitmap *wxMask::GetBitmap() const // wxBitmap //----------------------------------------------------------------------------- -class wxBitmapRefData: public wxObjectRefData +class wxBitmapRefData : public wxGDIRefData { public: wxBitmapRefData(); @@ -232,6 +232,8 @@ public: bool Create(int width, int height, int bpp); virtual ~wxBitmapRefData(); + virtual bool IsOk() const { return m_pixmap || m_bitmap; } + GdkPixmap *m_pixmap; GdkBitmap *m_bitmap; wxMask *m_mask; @@ -360,12 +362,12 @@ wxBitmap::wxBitmap( int width, int height, int depth ) Create( width, height, depth ); } -wxObjectRefData *wxBitmap::CreateRefData() const +wxGDIRefData *wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data)); } @@ -1137,12 +1139,6 @@ wxBitmap::~wxBitmap() { } -bool wxBitmap::IsOk() const -{ - return (m_refData != NULL) && - (M_BMPDATA->m_bitmap || M_BMPDATA->m_pixmap); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); diff --git a/src/gtk1/brush.cpp b/src/gtk1/brush.cpp index 3b9330bb1a..b07c208e2f 100644 --- a/src/gtk1/brush.cpp +++ b/src/gtk1/brush.cpp @@ -22,7 +22,7 @@ // wxBrush //----------------------------------------------------------------------------- -class wxBrushRefData: public wxObjectRefData +class wxBrushRefData: public wxGDIRefData { public: wxBrushRefData() @@ -31,7 +31,7 @@ public: } wxBrushRefData( const wxBrushRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_style = data.m_style; m_stipple = data.m_stipple; @@ -81,12 +81,12 @@ wxBrush::~wxBrush() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/gtk1/colour.cpp b/src/gtk1/colour.cpp index e5234be3d4..60d6b17e66 100644 --- a/src/gtk1/colour.cpp +++ b/src/gtk1/colour.cpp @@ -26,7 +26,7 @@ // wxColour //----------------------------------------------------------------------------- -class wxColourRefData: public wxObjectRefData +class wxColourRefData : public wxGDIRefData { public: wxColourRefData() @@ -40,7 +40,6 @@ public: } wxColourRefData(const wxColourRefData& data) - : wxObjectRefData() { m_color = data.m_color; m_colormap = data.m_colormap; @@ -159,12 +158,12 @@ bool wxColour::operator == ( const wxColour& col ) const own->green == other->green; } -wxObjectRefData *wxColour::CreateRefData() const +wxGDIRefData *wxColour::CreateGDIRefData() const { return new wxColourRefData; } -wxObjectRefData *wxColour::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxColour::CloneGDIRefData(const wxGDIRefData *data) const { return new wxColourRefData(*(wxColourRefData *)data); } diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index bd1e6ca2bd..3b14510edb 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -31,10 +31,9 @@ extern bool g_isIdle; // wxCursor //----------------------------------------------------------------------------- -class wxCursorRefData: public wxObjectRefData +class wxCursorRefData : public wxGDIRefData { - public: - +public: wxCursorRefData(); virtual ~wxCursorRefData(); @@ -316,14 +315,19 @@ wxCursor::~wxCursor() { } -bool wxCursor::IsOk() const +GdkCursor *wxCursor::GetCursor() const { - return (m_refData != NULL); + return M_CURSORDATA->m_cursor; } -GdkCursor *wxCursor::GetCursor() const +wxGDIRefData *wxCursor::CreateGDIRefData() const { - return M_CURSORDATA->m_cursor; + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); } //----------------------------------------------------------------------------- diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index a8524ccd8b..097519952e 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -54,7 +54,7 @@ WX_DECLARE_HASH_MAP(int, GdkFont *, wxIntegerHash, wxIntegerEqual, // wxFontRefData // ---------------------------------------------------------------------------- -class wxFontRefData : public wxObjectRefData +class wxFontRefData : public wxGDIRefData { public: // from broken down font parameters, also default ctor @@ -291,7 +291,7 @@ void wxFontRefData::InitFromNative() } wxFontRefData::wxFontRefData( const wxFontRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_pointSize = data.m_pointSize; m_family = data.m_family; @@ -536,6 +536,16 @@ wxFont::~wxFont() { } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- diff --git a/src/gtk1/pen.cpp b/src/gtk1/pen.cpp index 53464758d1..0b93bea8c1 100644 --- a/src/gtk1/pen.cpp +++ b/src/gtk1/pen.cpp @@ -101,12 +101,12 @@ wxPen::~wxPen() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/gtk1/region.cpp b/src/gtk1/region.cpp index acad6e5f64..b8f140cb72 100644 --- a/src/gtk1/region.cpp +++ b/src/gtk1/region.cpp @@ -49,7 +49,7 @@ private: // wxRegionRefData: private class containing the information about the region // ---------------------------------------------------------------------------- -class wxRegionRefData : public wxObjectRefData +class wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() @@ -58,7 +58,7 @@ public: } wxRegionRefData(const wxRegionRefData& refData) - : wxObjectRefData() + : wxGDIRefData() { m_region = gdk_regions_union(wxGdkRegion(), refData.m_region); } @@ -136,12 +136,12 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } @@ -380,7 +380,7 @@ struct _XRegion { }; -class wxRIRefData: public wxObjectRefData +class wxRIRefData : public wxGDIRefData { public: wxRIRefData() { Init(); } diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 3304fdacec..22ed227e5e 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -51,58 +51,58 @@ public: wxBitmapRefData(int width , int height , int depth); wxBitmapRefData(); wxBitmapRefData(const wxBitmapRefData &tocopy); - + virtual ~wxBitmapRefData(); - + + virtual bool IsOk() const { return m_ok; } + void Free(); - bool Ok() const { return IsOk(); } - bool IsOk() const { return m_ok; } void SetOk( bool isOk) { m_ok = isOk; } - + void SetWidth( int width ) { m_width = width; } void SetHeight( int height ) { m_height = height; } void SetDepth( int depth ) { m_depth = depth; } - + int GetWidth() const { return m_width; } int GetHeight() const { return m_height; } int GetDepth() const { return m_depth; } - + void *GetRawAccess() const; void *BeginRawAccess(); void EndRawAccess(); - + bool HasAlpha() const { return m_hasAlpha; } void UseAlpha( bool useAlpha ); - + public: #if wxUSE_PALETTE wxPalette m_bitmapPalette; #endif // wxUSE_PALETTE - + wxMask * m_bitmapMask; // Optional mask CGImageRef CreateCGImage() const; - + // returns true if the bitmap has a size that // can be natively transferred into a true icon // if no is returned GetIconRef will still produce // an icon but it will be generated via a PICT and // rescaled to 16 x 16 bool HasNativeSize(); - + // caller should increase ref count if needed longer // than the bitmap exists IconRef GetIconRef(); - + // returns a Pict from the bitmap content PicHandle GetPictHandle(); - + CGContextRef GetBitmapContext() const; - + int GetBytesPerRow() const { return m_bytesPerRow; } private : bool Create(int width , int height , int depth); void Init(); - + int m_width; int m_height; int m_bytesPerRow; @@ -112,10 +112,10 @@ public: int m_rawAccessCount; bool m_ok; mutable CGImageRef m_cgImageRef; - + IconRef m_iconRef; PicHandle m_pictHandle; - + CGContextRef m_hBitmap; }; @@ -243,8 +243,8 @@ void wxBitmapRefData::Init() wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) { Init(); - Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth); - + Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth); + if (tocopy.m_bitmapMask) m_bitmapMask = new wxMask(*tocopy.m_bitmapMask); else if (tocopy.m_hasAlpha) @@ -306,13 +306,13 @@ void wxBitmapRefData::UseAlpha( bool use ) void *wxBitmapRefData::GetRawAccess() const { - wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ; + wxCHECK_MSG( IsOk(), NULL , wxT("invalid bitmap") ) ; return m_memBuf.GetData() ; } void *wxBitmapRefData::BeginRawAccess() { - wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ) ; + wxCHECK_MSG( IsOk(), NULL, wxT("invalid bitmap") ) ; wxASSERT( m_rawAccessCount == 0 ) ; wxASSERT_MSG( m_pictHandle == NULL && m_iconRef == NULL , wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ; @@ -332,7 +332,7 @@ void *wxBitmapRefData::BeginRawAccess() void wxBitmapRefData::EndRawAccess() { - wxCHECK_RET( Ok() , wxT("invalid bitmap") ) ; + wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ; wxASSERT( m_rawAccessCount == 1 ) ; --m_rawAccessCount ; @@ -487,30 +487,30 @@ IconRef wxBitmapRefData::GetIconRef() #endif { // setup the header properly - + Handle data = NULL ; Handle maskdata = NULL ; unsigned char * maskptr = NULL ; unsigned char * ptr = NULL ; size_t datasize, masksize ; - + datasize = sz * sz * 4 ; data = NewHandle( datasize ) ; HLock( data ) ; ptr = (unsigned char*) *data ; memset( ptr , 0, datasize ) ; - + masksize = sz * sz ; maskdata = NewHandle( masksize ) ; HLock( maskdata ) ; maskptr = (unsigned char*) *maskdata ; memset( maskptr , 0 , masksize ) ; - + bool hasAlpha = HasAlpha() ; wxMask *mask = m_bitmapMask ; unsigned char * sourcePtr = (unsigned char*) GetRawAccess() ; unsigned char * masksourcePtr = mask ? (unsigned char*) mask->GetRawAccess() : NULL ; - + for ( int y = 0 ; y < h ; ++y, sourcePtr += m_bytesPerRow , masksourcePtr += mask ? mask->GetBytesPerRow() : 0 ) { unsigned char * source = sourcePtr; @@ -518,19 +518,19 @@ IconRef wxBitmapRefData::GetIconRef() unsigned char * dest = ptr + y * sz * 4 ; unsigned char * maskdest = maskptr + y * sz ; unsigned char a, r, g, b; - + for ( int x = 0 ; x < w ; ++x ) { a = *source ++ ; r = *source ++ ; g = *source ++ ; b = *source ++ ; - + *dest++ = 0 ; *dest++ = r ; *dest++ = g ; *dest++ = b ; - + if ( mask ) *maskdest++ = 0xFF - *masksource++ ; else if ( hasAlpha ) @@ -539,13 +539,13 @@ IconRef wxBitmapRefData::GetIconRef() *maskdest++ = 0xFF ; } } - + OSStatus err = SetIconFamilyData( iconFamily, dataType , data ) ; wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; - + err = SetIconFamilyData( iconFamily, maskType , maskdata ) ; wxASSERT_MSG( err == noErr , wxT("Error when adding mask") ) ; - + HUnlock( data ) ; HUnlock( maskdata ) ; DisposeHandle( data ) ; @@ -634,7 +634,7 @@ CGImageRef wxBitmapRefData::CreateCGImage() const int h = m_height ; CGImageAlphaInfo alphaInfo = kCGImageAlphaNoneSkipFirst ; wxMemoryBuffer membuf; - + if ( m_bitmapMask ) { alphaInfo = kCGImageAlphaFirst ; @@ -663,10 +663,10 @@ CGImageRef wxBitmapRefData::CreateCGImage() const alphaInfo = kCGImageAlphaFirst ; #endif } - + membuf = m_memBuf; } - + CGDataProviderRef dataProvider = NULL ; if ( m_depth == 1 ) { @@ -685,10 +685,10 @@ CGImageRef wxBitmapRefData::CreateCGImage() const } } maskBuf.UngetWriteBuf( m_width * m_height ); - + dataProvider = wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf ); - + image = ::CGImageMaskCreate( w, h, 8, 8, m_width , dataProvider, NULL, false ); } else @@ -843,7 +843,7 @@ bool wxBitmap::CopyFromIcon(const wxIcon& icon) *destination++ = ( (*source++) * a + 127 ) / 255; *destination++ = ( (*source++) * a + 127 ) / 255; *destination++ = ( (*source++) * a + 127 ) / 255; -#else +#else *destination++ = *source++ ; *destination++ = *source++ ; *destination++ = *source++ ; @@ -943,12 +943,12 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } -wxObjectRefData* wxBitmap::CreateRefData() const +wxGDIRefData* wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const +wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const { return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data)); } @@ -984,7 +984,7 @@ CGImageRef wxBitmap::CreateCGImage() const IconRef wxBitmap::GetIconRef() const { wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ; - + return M_BITMAPDATA->GetIconRef() ; } @@ -1066,7 +1066,7 @@ bool wxBitmap::Create(int w, int h, int d) m_refData = new wxBitmapRefData( w , h , d ); - return M_BITMAPDATA->Ok() ; + return M_BITMAPDATA->IsOk() ; } bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) @@ -1122,17 +1122,17 @@ bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height wxBitmap::wxBitmap(const wxImage& image, int depth) { wxCHECK_RET( image.Ok(), wxT("invalid image") ); - + // width and height of the device-dependent bitmap int width = image.GetWidth(); int height = image.GetHeight(); - + m_refData = new wxBitmapRefData( width , height , depth ) ; - + // Create picture - + bool hasAlpha = false ; - + if ( image.HasMask() ) { // takes precedence, don't mix with alpha info @@ -1141,10 +1141,10 @@ wxBitmap::wxBitmap(const wxImage& image, int depth) { hasAlpha = image.HasAlpha() ; } - + if ( hasAlpha ) UseAlpha() ; - + unsigned char* destinationstart = (unsigned char*) BeginRawAccess() ; register unsigned char* data = image.GetData(); if ( destinationstart != NULL && data != NULL ) @@ -1159,7 +1159,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth) { const unsigned char a = *alpha++; *destination++ = a ; - + #if wxMAC_USE_PREMULTIPLIED_ALPHA *destination++ = ((*data++) * a + 127) / 255 ; *destination++ = ((*data++) * a + 127) / 255 ; @@ -1179,7 +1179,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth) } } } - + EndRawAccess() ; } if ( image.HasMask() ) @@ -1320,11 +1320,6 @@ bool wxBitmap::SaveFile( const wxString& filename, return success; } -bool wxBitmap::IsOk() const -{ - return (M_BITMAPDATA && M_BITMAPDATA->Ok()); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); @@ -1496,10 +1491,10 @@ void wxMask::RealizeNative() CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray(); // from MouseTracking sample : - // Ironically, due to a bug in CGImageCreateWithMask, you cannot use + // Ironically, due to a bug in CGImageCreateWithMask, you cannot use // CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) at this point! - - m_maskBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, colorspace, + + m_maskBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, colorspace, kCGImageAlphaNone ); CGColorSpaceRelease( colorspace ); wxASSERT_MSG( m_maskBitmap , wxT("Unable to create CGBitmapContext context") ) ; diff --git a/src/mac/carbon/brush.cpp b/src/mac/carbon/brush.cpp index 876415261f..f571682680 100644 --- a/src/mac/carbon/brush.cpp +++ b/src/mac/carbon/brush.cpp @@ -117,12 +117,12 @@ bool wxBrush::operator==(const wxBrush& brush) const return m_refData ? (brushData && *M_BRUSHDATA == *brushData) : !brushData; } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(const wxBrushRefData *)data); } diff --git a/src/mac/carbon/colour.cpp b/src/mac/carbon/colour.cpp index 225e31e179..137ff6c36d 100644 --- a/src/mac/carbon/colour.cpp +++ b/src/mac/carbon/colour.cpp @@ -54,11 +54,6 @@ wxColour& wxColour::operator=(CGColorRef col) return *this; } -bool wxColour::IsOk() const -{ - return m_cgColour; -} - void wxColour::InitRGBA (ChannelType r, ChannelType g, ChannelType b, ChannelType a) { m_red = r; diff --git a/src/mac/carbon/cursor.cpp b/src/mac/carbon/cursor.cpp index e8f6425947..7326c9ca8a 100644 --- a/src/mac/carbon/cursor.cpp +++ b/src/mac/carbon/cursor.cpp @@ -29,14 +29,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject) class WXDLLEXPORT wxCursorRefData: public wxGDIRefData { - friend class wxCursor; - - DECLARE_NO_COPY_CLASS(wxCursorRefData) - public: wxCursorRefData(); + wxCursorRefData(const wxCursorRefData& cursor); virtual ~wxCursorRefData(); + virtual bool IsOk() const + { + if ( m_hCursor != NULL ) + return true; +#if !wxMAC_USE_COCOA + if ( m_themeCursor != -1 ) + return true; +#endif + + return false; + } + protected: #if wxMAC_USE_COCOA WX_NSCursor m_hCursor; @@ -47,6 +56,10 @@ protected: bool m_isColorCursor; long m_themeCursor; #endif + + friend class wxCursor; + + DECLARE_NO_ASSIGN_CLASS(wxCursorRefData) }; #define M_CURSORDATA wx_static_cast(wxCursorRefData*, m_refData) @@ -208,6 +221,21 @@ wxCursorRefData::wxCursorRefData() #endif } +wxCursorRefData::wxCursorRefData(const wxCursorRefData& cursor) +{ + // FIXME: need to copy the cursor + m_hCursor = NULL; + +#if wxMAC_USE_COCOA + wxUnusedVar(cursor); +#else + m_disposeHandle = false; + m_releaseHandle = false; + m_isColorCursor = cursor.m_isColorCursor; + m_themeCursor = cursor.m_themeCursor; +#endif +} + wxCursorRefData::~wxCursorRefData() { #if wxMAC_USE_COCOA @@ -258,6 +286,16 @@ wxCursor::wxCursor(char **bits) (void) CreateFromXpm((const char **)bits); } +wxGDIRefData *wxCursor::CreateGDIRefData() const +{ + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); +} + bool wxCursor::CreateFromXpm(const char **bits) { #if wxUSE_IMAGE @@ -277,15 +315,6 @@ WXHCURSOR wxCursor::GetHCURSOR() const return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } -bool wxCursor::IsOk() const -{ -#if wxMAC_USE_COCOA - return GetHCURSOR() != NULL; -#else - return (m_refData != NULL && ( M_CURSORDATA->m_hCursor != NULL || M_CURSORDATA->m_themeCursor != -1 ) ) ; -#endif -} - #if !wxMAC_USE_COCOA short GetCTabIndex( CTabHandle colors , RGBColor *col ) { diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index 4df05442ea..0f06f3d96d 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -59,7 +59,7 @@ public: { Init(size, family, style, weight, underlined, faceName, encoding); } - + #if wxMAC_USE_CORE_TEXT wxFontRefData( wxUint32 coreTextFontType ); wxFontRefData( CTFontRef font ); @@ -72,69 +72,69 @@ public: bool GetNoAntiAliasing() const { return m_noAA; } - void SetPointSize( int size ) + void SetPointSize( int size ) { m_pointSize = size; MacInvalidateNativeFont(); } - + int GetPointSize() const { return m_pointSize; } - - void SetFamily( int family ) + + void SetFamily( int family ) { m_family = family; MacInvalidateNativeFont(); } - - + + int GetFamily() const { return m_family; } - - void SetStyle( int style ) + + void SetStyle( int style ) { m_style = style; MacInvalidateNativeFont(); } - - + + int GetStyle() const { return m_style; } - - void SetWeight( int weight ) + + void SetWeight( int weight ) { m_weight = weight; MacInvalidateNativeFont(); } - - + + int GetWeight() const { return m_weight; } - - void SetUnderlined( bool u ) + + void SetUnderlined( bool u ) { m_underlined = u; MacInvalidateNativeFont(); } - + bool GetUnderlined() const { return m_underlined; } - - void SetFaceName( const wxString& facename ) + + void SetFaceName( const wxString& facename ) { m_faceName = facename; MacInvalidateNativeFont(); } - + const wxString& GetFaceName() const { return m_faceName; } - - void SetEncoding( wxFontEncoding encoding ) + + void SetEncoding( wxFontEncoding encoding ) { m_encoding = encoding; MacInvalidateNativeFont(); - } - - wxFontEncoding GetEncoding() const { return m_encoding; } - + } + + wxFontEncoding GetEncoding() const { return m_encoding; } + void MacInvalidateNativeFont(); - + void MacFindFont(); - + protected: // common part of all ctors void Init(int size, @@ -147,7 +147,7 @@ protected: #if wxMAC_USE_CORE_TEXT void Init( CTFontRef font ); -#endif +#endif // font characterstics int m_pointSize; int m_family; @@ -256,24 +256,24 @@ void wxFontRefData::MacInvalidateNativeFont() #if wxMAC_USE_CORE_TEXT -/* from Core Text Manual Common Operations */ +/* from Core Text Manual Common Operations */ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, CTFontSymbolicTraits iTraits ) { CTFontDescriptorRef descriptor = NULL; CFMutableDictionaryRef attributes; - + assert(iFamilyName != NULL); // Create a mutable dictionary to hold our attributes. attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); check(attributes != NULL); - - if (attributes != NULL) { + + if (attributes != NULL) { // Add a family name to our attributes. CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, iFamilyName); - - + + if ( iTraits ) { CFMutableDictionaryRef traits; CFNumberRef symTraits; @@ -282,17 +282,17 @@ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, symTraits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &iTraits); check(symTraits != NULL); - + if (symTraits != NULL) { // Create a dictionary to hold our traits values. traits = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); check(traits != NULL); - + if (traits != NULL) { // Add the symbolic traits value to the traits dictionary. CFDictionaryAddValue(traits, kCTFontSymbolicTrait, symTraits); - + // Add the traits attribute to our attributes. CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits); CFRelease(traits); @@ -303,7 +303,7 @@ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, // Create the font descriptor with our attributes and input size. descriptor = CTFontDescriptorCreateWithAttributes(attributes); check(descriptor != NULL); - + CFRelease(attributes); } // Return our font descriptor. @@ -331,7 +331,7 @@ wxFontRefData::wxFontRefData( CTFontDescriptorRef fontdescriptor, int size ) if ( size == 0 ) { wxCFRef< CFNumberRef > value( (CFNumberRef) CTFontDescriptorCopyAttribute( fontdescriptor, kCTFontSizeAttribute ) ); - + float fsize; if ( CFNumberGetValue( value , kCFNumberFloatType , &fsize ) ) { @@ -361,9 +361,9 @@ void wxFontRefData::MacFindFont() { m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, 0.0, NULL )); } - + if ( m_ctFont ) - { + { wxCFStringRef name( CTFontCopyFamilyName( m_ctFont ) ); m_faceName = name.AsString(); m_pointSize = CTFontGetSize(m_ctFont) ; @@ -386,16 +386,16 @@ void wxFontRefData::MacFindFont() case wxDECORATIVE : m_faceName = wxT("Times"); break ; - + case wxSWISS : m_faceName = wxT("Lucida Grande"); break ; - + case wxMODERN : case wxTELETYPE: m_faceName = wxT("Monaco"); break ; - + default: m_faceName = wxT("Times"); break ; @@ -404,12 +404,12 @@ void wxFontRefData::MacFindFont() wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() ); CTFontSymbolicTraits traits = 0; - + if (m_weight == wxBOLD) traits |= kCTFontBoldTrait; if (m_style == wxITALIC || m_style == wxSLANT) traits |= kCTFontItalicTrait; - + m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) ); m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) ); @@ -439,7 +439,7 @@ void wxFontRefData::MacFindFont() }; Boolean kTrue = true ; Boolean kFalse = false ; - + Fixed atsuSize = IntToFixed( m_pointSize ); ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = @@ -451,7 +451,7 @@ void wxFontRefData::MacFindFont() (m_style == wxITALIC || m_style == wxSLANT) ? &kTrue : &kFalse , (m_underlined) ? &kTrue : &kFalse , }; - + if ( m_macATSUStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); @@ -508,16 +508,16 @@ void wxFontRefData::MacFindFont() case wxDECORATIVE : m_faceName = wxT("Times"); break ; - + case wxSWISS : m_faceName = wxT("Lucida Grande"); break ; - + case wxMODERN : case wxTELETYPE: m_faceName = wxT("Monaco"); break ; - + default: m_faceName = wxT("Times"); break ; @@ -550,7 +550,7 @@ void wxFontRefData::MacFindFont() m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); } } - + m_macFontStyle = 0; if (m_weight == wxBOLD) m_macFontStyle |= bold; @@ -560,25 +560,25 @@ void wxFontRefData::MacFindFont() m_macFontStyle |= underline; m_macFontSize = m_pointSize ; } - + // we try to get as much styles as possible into ATSU - - + + // ATSUFontID and FMFont are equivalent FMFontStyle intrinsicStyle = 0 ; status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); - + if ( m_macATSUStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); m_macATSUStyle = NULL ; } - + status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); - + ATSUAttributeTag atsuTags[] = { kATSUFontTag , @@ -601,10 +601,10 @@ void wxFontRefData::MacFindFont() sizeof( Boolean ) , sizeof( Boolean ) , }; - + Boolean kTrue = true ; Boolean kFalse = false ; - + Fixed atsuSize = IntToFixed( m_macFontSize ); ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = @@ -618,12 +618,12 @@ void wxFontRefData::MacFindFont() (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , }; - + status = ::ATSUSetAttributes( (ATSUStyle)m_macATSUStyle, sizeof(atsuTags) / sizeof(ATSUAttributeTag) , atsuTags, atsuSizes, atsuValues); - + wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); return; } @@ -682,10 +682,10 @@ bool wxFont::MacCreateFromUIFont(wxUint32 ctFontType ) bool wxFont::MacCreateFromCTFontDescriptor( const void * ctFontDescriptor , int size ) { UnRef(); - + m_refData = new wxFontRefData((CTFontDescriptorRef)ctFontDescriptor, size);; RealizeResource(); - + return true; } @@ -751,11 +751,21 @@ void wxFont::Unshare() } } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + void wxFont::SetPointSize(int pointSize) { if ( M_FONTDATA->GetPointSize() == pointSize ) return; - + Unshare(); M_FONTDATA->SetPointSize( pointSize ); @@ -945,7 +955,7 @@ wxUint16 wxFont::MacGetThemeFontID() const void * wxFont::MacGetATSUStyle() const { wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); - + return M_FONTDATA->m_macATSUStyle; } #endif @@ -962,7 +972,7 @@ const void * wxFont::MacGetCTFont() const const void * wxFont::MacGetCTFontDescriptor() const { wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); - + return (CTFontDescriptorRef)(M_FONTDATA->m_ctFontDescriptor); } diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 87c0ceb969..004b47fc6e 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -26,21 +26,25 @@ IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) class WXDLLEXPORT wxIconRefData : public wxGDIRefData { public: - wxIconRefData(); + wxIconRefData() { Init(); } wxIconRefData( WXHICON iconref, int desiredWidth, int desiredHeight ); virtual ~wxIconRefData() { Free(); } - - void Init(); + + virtual bool IsOk() const { return m_iconRef != NULL; } + virtual void Free(); - + void SetWidth( int width ) { m_width = width; } void SetHeight( int height ) { m_height = height; } - + int GetWidth() const { return m_width; } int GetHeight() const { return m_height; } - + WXHICON GetHICON() const { return (WXHICON) m_iconRef; } - private : + +private: + void Init(); + IconRef m_iconRef; int m_width; int m_height; @@ -50,7 +54,7 @@ public: wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight ) { m_iconRef = MAC_WXHICON( icon ) ; - + // Standard sizes SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ; SetHeight( desiredHeight == -1 ? 32 : desiredHeight ) ; @@ -59,6 +63,8 @@ wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight void wxIconRefData::Init() { m_iconRef = NULL ; + m_width = + m_height = 0; } void wxIconRefData::Free() @@ -117,6 +123,16 @@ wxIcon::~wxIcon() { } +wxGDIRefData *wxIcon::CreateGDIRefData() const +{ + return new wxIconRefData; +} + +wxGDIRefData *wxIcon::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxIconRefData(*wx_static_cast(const wxIconRefData *, data)); +} + WXHICON wxIcon::GetHICON() const { wxASSERT( Ok() ) ; @@ -155,11 +171,6 @@ void wxIcon::SetHeight( int WXUNUSED(height) ) { } -bool wxIcon::IsOk() const -{ - return m_refData != NULL ; -} - bool wxIcon::LoadFile( const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight ) @@ -200,34 +211,34 @@ bool wxIcon::LoadFile( } else { - IconRef iconRef = NULL ; - - // first look in the resource fork - if ( iconRef == NULL ) - { - Str255 theName ; - - wxMacStringToPascal( filename , theName ) ; - Handle resHandle = GetNamedResource( 'icns' , theName ) ; - if ( resHandle != 0L ) - { - IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ; + IconRef iconRef = NULL ; + + // first look in the resource fork + if ( iconRef == NULL ) + { + Str255 theName ; + + wxMacStringToPascal( filename , theName ) ; + Handle resHandle = GetNamedResource( 'icns' , theName ) ; + if ( resHandle != 0L ) + { + IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ; HLock((Handle) iconFamily); OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef ); HUnlock((Handle) iconFamily); wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") ); ReleaseResource( resHandle ) ; - } - } + } + } if ( iconRef == NULL ) { // TODO add other attempts to load it from files etc here } - if ( iconRef ) - { - m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ; - return true ; - } + if ( iconRef ) + { + m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ; + return true ; + } } if ( theId != 0 ) diff --git a/src/mac/carbon/metafile.cpp b/src/mac/carbon/metafile.cpp index 7d09ee1033..73d5b77f9a 100644 --- a/src/mac/carbon/metafile.cpp +++ b/src/mac/carbon/metafile.cpp @@ -37,17 +37,25 @@ IMPLEMENT_ABSTRACT_CLASS(wxMetafileDCImpl, wxGCDCImpl) #define M_METAFILEREFDATA( a ) ((wxMetafileRefData*)(a).GetRefData()) -class wxMetafileRefData: public wxGDIRefData +class wxMetafileRefData : public wxGDIRefData { public: + // default ctor needed for CreateGDIRefData(), must be initialized later + wxMetafileRefData() { Init(); } + // creates a metafile from memory, assumes ownership wxMetafileRefData(CFDataRef data); + // prepares a recording metafile wxMetafileRefData( int width, int height); + // prepares a metafile to be read from a file (if filename is not empty) wxMetafileRefData( const wxString& filename); + virtual ~wxMetafileRefData(); + virtual bool IsOk() const { return m_data != NULL; } + void Init(); int GetWidth() const { return m_width; } @@ -162,9 +170,14 @@ wxMetaFile::~wxMetaFile() { } -bool wxMetaFile::IsOk() const +wxGDIRefData *wxMetaFile::CreateGDIRefData() const +{ + return new wxMetafileRefData; +} + +wxGDIRefData *wxMetaFile::CloneGDIRefData(const wxGDIRefData *data) const { - return (M_METAFILEDATA && (M_METAFILEDATA->GetData() != NULL)); + return new wxMetafileRefData(*wx_static_cast(const wxMetafileRefData *, data)); } WXHMETAFILE wxMetaFile::GetHMETAFILE() const diff --git a/src/mac/carbon/palette.cpp b/src/mac/carbon/palette.cpp index cb5ca9487b..99727e0d52 100644 --- a/src/mac/carbon/palette.cpp +++ b/src/mac/carbon/palette.cpp @@ -17,25 +17,51 @@ IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) -/* - * Palette - * - */ +// ============================================================================ +// wxPaletteRefData +// ============================================================================ + +class WXDLLEXPORT wxPaletteRefData: public wxGDIRefData +{ +public: + wxPaletteRefData(); + wxPaletteRefData(const wxPaletteRefData& data); + virtual ~wxPaletteRefData(); + + virtual bool IsOk() const { return m_count > 0; } + +protected: + wxColour* m_palette; + wxInt32 m_count; + + friend class WXDLLIMPEXP_FWD_CORE wxPalette; + + DECLARE_NO_ASSIGN_CLASS(wxPaletteRefData) +}; wxPaletteRefData::wxPaletteRefData() { - m_palette = NULL ; - m_count = 0 ; + m_palette = NULL; + m_count = 0; +} + +wxPaletteRefData::wxPaletteRefData(const wxPaletteRefData& data) +{ + m_count = data.m_count; + m_palette = new wxColour[m_count]; + for ( wxInt32 i = 0; i < m_count; i++ ) + m_palette[i] = data.m_palette[i]; } wxPaletteRefData::~wxPaletteRefData() { - if (m_palette != NULL) { - delete[] m_palette ; - m_palette = NULL; - } + delete[] m_palette; } +// ============================================================================ +// wxPalette +// ============================================================================ + wxPalette::wxPalette() { } @@ -111,10 +137,18 @@ int wxPalette::GetColoursCount() const { if (m_refData) return M_PALETTEDATA->m_count; - - return 0; + + return 0; +} + +wxGDIRefData *wxPalette::CreateGDIRefData() const +{ + return new wxPaletteRefData; } +wxGDIRefData *wxPalette::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPaletteRefData(*wx_static_cast(const wxPaletteRefData *, data)); +} -#endif -// wxUSE_PALETTE +#endif // wxUSE_PALETTE diff --git a/src/mac/carbon/pen.cpp b/src/mac/carbon/pen.cpp index d0644b2468..5fa47f2a9a 100644 --- a/src/mac/carbon/pen.cpp +++ b/src/mac/carbon/pen.cpp @@ -19,9 +19,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) -class WXDLLEXPORT wxPenRefData: public wxGDIRefData +class WXDLLEXPORT wxPenRefData : public wxGDIRefData { - friend class WXDLLIMPEXP_FWD_CORE wxPen; public: wxPenRefData(); wxPenRefData(const wxPenRefData& data); @@ -33,28 +32,30 @@ public: { // we intentionally don't compare m_hPen fields here return m_style == data.m_style && - m_width == data.m_width && - m_join == data.m_join && - m_cap == data.m_cap && - m_colour == data.m_colour && - (m_style != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) && - (m_style != wxUSER_DASH || - (m_nbDash == data.m_nbDash && - memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); + m_width == data.m_width && + m_join == data.m_join && + m_cap == data.m_cap && + m_colour == data.m_colour && + (m_style != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) && + (m_style != wxUSER_DASH || + (m_nbDash == data.m_nbDash && + memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); } protected: - int m_width; - int m_style; - int m_join ; - int m_cap ; - wxBitmap m_stipple ; - int m_nbDash ; - wxDash * m_dash ; - wxColour m_colour; -/* TODO: implementation - WXHPEN m_hPen; -*/ + int m_width; + int m_style; + int m_join ; + int m_cap ; + wxBitmap m_stipple ; + int m_nbDash ; + wxDash * m_dash ; + wxColour m_colour; + /* TODO: implementation + WXHPEN m_hPen; + */ + + friend class WXDLLIMPEXP_FWD_CORE wxPen; }; wxPenRefData::wxPenRefData() @@ -126,7 +127,17 @@ wxPen::wxPen(const wxBitmap& stipple, int Width) RealizeResource(); } -bool wxPen::operator == (const wxPen& pen) const +wxGDIRefData *wxPen::CreateGDIRefData() const +{ + return new wxPenRefData; +} + +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPenRefData(*wx_static_cast(const wxPenRefData *, data)); +} + +bool wxPen::operator==(const wxPen& pen) const { const wxPenRefData *penData = (wxPenRefData *)pen.m_refData; @@ -134,39 +145,39 @@ bool wxPen::operator == (const wxPen& pen) const return m_refData ? penData && *M_PENDATA == *penData : !penData; } -wxColour& wxPen::GetColour() const -{ - return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); +wxColour& wxPen::GetColour() const +{ + return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); } -int wxPen::GetWidth() const -{ - return (M_PENDATA ? M_PENDATA->m_width : 0); +int wxPen::GetWidth() const +{ + return (M_PENDATA ? M_PENDATA->m_width : 0); } -int wxPen::GetStyle() const -{ - return (M_PENDATA ? M_PENDATA->m_style : 0); +int wxPen::GetStyle() const +{ + return (M_PENDATA ? M_PENDATA->m_style : 0); } -int wxPen::GetJoin() const -{ - return (M_PENDATA ? M_PENDATA->m_join : 0); +int wxPen::GetJoin() const +{ + return (M_PENDATA ? M_PENDATA->m_join : 0); } -int wxPen::GetCap() const -{ - return (M_PENDATA ? M_PENDATA->m_cap : 0); +int wxPen::GetCap() const +{ + return (M_PENDATA ? M_PENDATA->m_cap : 0); } -int wxPen::GetDashes(wxDash **ptr) const +int wxPen::GetDashes(wxDash **ptr) const { *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0); } -wxBitmap *wxPen::GetStipple() const -{ - return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); +wxBitmap *wxPen::GetStipple() const +{ + return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); } void wxPen::Unshare() diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index 69e0e80e82..d08fd4984c 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -160,6 +160,16 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } +wxGDIRefData *wxRegion::CreateGDIRefData() const +{ + return new wxRegionRefData; +} + +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxRegionRefData(*wx_static_cast(const wxRegionRefData *, data)); +} + //----------------------------------------------------------------------------- //# Modify region //----------------------------------------------------------------------------- diff --git a/src/mgl/bitmap.cpp b/src/mgl/bitmap.cpp index 1c424417fe..c280b0b0ac 100644 --- a/src/mgl/bitmap.cpp +++ b/src/mgl/bitmap.cpp @@ -60,6 +60,8 @@ public: wxBitmapRefData(); virtual ~wxBitmapRefData(); + virtual bool IsOk() const { return m_bitmap != NULL; } + int m_width; int m_height; int m_bpp; @@ -267,11 +269,6 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) delete bdc; } -bool wxBitmap::IsOk() const -{ - return (m_refData != NULL && M_BMPDATA->m_bitmap != NULL); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); diff --git a/src/mgl/brush.cpp b/src/mgl/brush.cpp index b151db8a0a..b8f6073f38 100644 --- a/src/mgl/brush.cpp +++ b/src/mgl/brush.cpp @@ -70,13 +70,15 @@ void wxBitmapToPixPattern(const wxBitmap& bitmap, // wxBrush //----------------------------------------------------------------------------- -class wxBrushRefData: public wxObjectRefData +class wxBrushRefData : public wxGDIRefData { public: wxBrushRefData(); wxBrushRefData(const wxBrushRefData& data); - bool operator == (const wxBrushRefData& data) const + virtual bool IsOk() const { return m_colour.IsOk(); } + + bool operator==(const wxBrushRefData& data) const { return (m_style == data.m_style && m_stipple.IsSameAs(data.m_stipple) && @@ -164,11 +166,6 @@ bool wxBrush::operator != (const wxBrush& brush) const return m_refData != brush.m_refData; } -bool wxBrush::IsOk() const -{ - return ((m_refData) && M_BRUSHDATA->m_colour.Ok()); -} - int wxBrush::GetStyle() const { if (m_refData == NULL) @@ -252,12 +249,12 @@ void wxBrush::SetStipple(const wxBitmap& stipple) M_BRUSHDATA->m_style = wxSTIPPLE; } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index 5b9c7899d1..b43d0b254b 100644 --- a/src/mgl/cursor.cpp +++ b/src/mgl/cursor.cpp @@ -175,11 +175,6 @@ wxCursor::~wxCursor() // wxObject unrefs data } -bool wxCursor::IsOk() const -{ - return (m_refData != NULL); -} - MGLCursor *wxCursor::GetMGLCursor() const { return M_CURSORDATA->m_cursor; diff --git a/src/mgl/font.cpp b/src/mgl/font.cpp index d3a5afe21a..db17cb1c01 100644 --- a/src/mgl/font.cpp +++ b/src/mgl/font.cpp @@ -57,12 +57,12 @@ bool wxFont::Create(int pointSize, return true; } -wxObjectRefData *wxFont::CreateRefData() const +wxGDIRefData *wxFont::CreateGDIRefData() const { return new wxFontRefData; } -wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const { return new wxFontRefData(*(wxFontRefData *)data); } diff --git a/src/mgl/palette.cpp b/src/mgl/palette.cpp index 48717b498b..92536bb350 100644 --- a/src/mgl/palette.cpp +++ b/src/mgl/palette.cpp @@ -63,11 +63,6 @@ wxPalette::~wxPalette() { } -bool wxPalette::IsOk(void) const -{ - return (m_refData != NULL); -} - bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, diff --git a/src/mgl/pen.cpp b/src/mgl/pen.cpp index 83ad3603da..203faed261 100644 --- a/src/mgl/pen.cpp +++ b/src/mgl/pen.cpp @@ -257,17 +257,12 @@ void* wxPen::GetPixPattern() const } -bool wxPen::IsOk() const -{ - return (m_refData != NULL); -} - -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/mgl/region.cpp b/src/mgl/region.cpp index 2604513a1e..6245737375 100644 --- a/src/mgl/region.cpp +++ b/src/mgl/region.cpp @@ -57,12 +57,12 @@ public: // wxRegion //----------------------------------------------------------------------------- -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/motif/cursor.cpp b/src/motif/cursor.cpp index 6d32080afd..134c7e9596 100644 --- a/src/motif/cursor.cpp +++ b/src/motif/cursor.cpp @@ -49,15 +49,16 @@ WX_DECLARE_LIST(wxXCursor, wxXCursorList); #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxXCursorList) -class WXDLLEXPORT wxCursorRefData: public wxObjectRefData +class WXDLLEXPORT wxCursorRefData: public wxGDIRefData { - friend class wxCursor; public: wxCursorRefData(); virtual ~wxCursorRefData(); wxXCursorList m_cursors; // wxXCursor objects, one per display wxStockCursor m_cursorId; // wxWidgets standard cursor id + + friend class wxCursor; }; #define M_CURSORDATA ((wxCursorRefData *)m_refData) @@ -293,9 +294,14 @@ wxCursor::~wxCursor() { } -bool wxCursor::IsOk() const +wxGDIRefData *wxCursor::CreateGDIRefData() const +{ + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const { - return m_refData != NULL; + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); } // Motif-specific: create/get a cursor for the current display diff --git a/src/motif/font.cpp b/src/motif/font.cpp index fc503f190f..15bc878ed7 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -344,6 +344,16 @@ wxFont::~wxFont() { } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + // ---------------------------------------------------------------------------- // change the font attributes // ---------------------------------------------------------------------------- diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index d06251a599..222cb4c40b 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -211,7 +211,7 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) m_bitmapMask = new wxMask(*data.m_bitmapMask); // FIXME: we don't copy m_hBitmap currently but we should, see wxBitmap:: - // CloneRefData() + // CloneGDIRefData() wxASSERT_MSG( !data.m_isDIB, _T("can't copy bitmap locked for raw access!") ); @@ -250,7 +250,7 @@ wxGDIImageRefData *wxBitmap::CreateData() const return new wxBitmapRefData; } -wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const +wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *dataOrig) const { const wxBitmapRefData * data = wx_static_cast(const wxBitmapRefData *, dataOrig); @@ -277,16 +277,17 @@ wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const self->m_refData = new wxBitmapRefData(*data); } + wxBitmapRefData * const + selfdata = wx_static_cast(wxBitmapRefData *, m_refData); + // copy also the mask wxMask * const maskSrc = data->GetMask(); if ( maskSrc ) { - wxBitmapRefData *selfdata = wx_static_cast(wxBitmapRefData *, m_refData); - selfdata->SetMask(new wxMask(*maskSrc)); } - return m_refData; + return selfdata; } bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon, diff --git a/src/msw/brush.cpp b/src/msw/brush.cpp index 8f0e645b31..b5edb43205 100644 --- a/src/msw/brush.cpp +++ b/src/msw/brush.cpp @@ -252,12 +252,12 @@ bool wxBrush::operator==(const wxBrush& brush) const return m_refData ? (brushData && *M_BRUSHDATA == *brushData) : !brushData; } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(const wxBrushRefData *)data); } diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index fe4d384aca..d2c39001f7 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -69,6 +69,21 @@ static inline const wxChar *GetMetaFileName(const wxString& fn) // wxEnhMetaFile // ---------------------------------------------------------------------------- +wxGDIRefData *wxEnhMetaFile::CreateGDIRefData() const +{ + wxFAIL_MSG( _T("must be implemented if used") ); + + return NULL; +} + +wxGDIRefData * +wxEnhMetaFile::CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const +{ + wxFAIL_MSG( _T("must be implemented if used") ); + + return NULL; +} + void wxEnhMetaFile::Init() { if ( m_filename.empty() ) diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 024e43d3ae..f2ff677d8a 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -895,12 +895,12 @@ wxFont::~wxFont() // real implementation // ---------------------------------------------------------------------------- -wxObjectRefData *wxFont::CreateRefData() const +wxGDIRefData *wxFont::CreateGDIRefData() const { return new wxFontRefData(); } -wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const { return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); } diff --git a/src/msw/metafile.cpp b/src/msw/metafile.cpp index 2186f3ef18..3076145d20 100644 --- a/src/msw/metafile.cpp +++ b/src/msw/metafile.cpp @@ -94,6 +94,16 @@ wxMetafile::~wxMetafile() { } +wxGDIRefData *wxMetafile::CreateGDIRefData() const +{ + return new wxMetafileRefData; +} + +wxGDIRefData *wxMetafile::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxMetafileRefData(wx_static_cast(wxMetafileRefData *, data)); +} + bool wxMetafile::SetClipboard(int width, int height) { #if !wxUSE_CLIPBOARD diff --git a/src/msw/palette.cpp b/src/msw/palette.cpp index 989ff48e22..570f4d96c8 100644 --- a/src/msw/palette.cpp +++ b/src/msw/palette.cpp @@ -20,115 +20,142 @@ #include "wx/palette.h" -#ifndef WX_PRECOMP -#endif - #include "wx/msw/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) - -/* - * Palette - * - */ +// ============================================================================ +// wxPaletteRefData +// ============================================================================ -wxPaletteRefData::wxPaletteRefData(void) +class WXDLLEXPORT wxPaletteRefData: public wxGDIRefData { - m_hPalette = 0; -} +public: + wxPaletteRefData() { Init(); } -wxPaletteRefData::~wxPaletteRefData(void) -{ - if ( m_hPalette ) - ::DeleteObject((HPALETTE) m_hPalette); -} + wxPaletteRefData(int n, + unsigned char *red, + unsigned char *green, + unsigned char *blue) + { + Init(); + + LOGPALETTE *pPal = Alloc(n); + if ( !pPal ) + return; + + for ( int i = 0; i < n; i++ ) + { + pPal->palPalEntry[i].peRed = red[i]; + pPal->palPalEntry[i].peGreen = green[i]; + pPal->palPalEntry[i].peBlue = blue[i]; + pPal->palPalEntry[i].peFlags = 0; + } + + m_hPalette = ::CreatePalette(pPal); + free(pPal); + } -wxPalette::wxPalette() -{ -} + wxPaletteRefData(const wxPaletteRefData& data) + { + Init(); -wxPalette::wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) -{ - Create(n, red, green, blue); -} + const UINT n = data.GetEntries(); + if ( !n ) + return; -wxPalette::~wxPalette(void) -{ -// FreeResource(true); -} + LOGPALETTE *pPal = Alloc(n); + if ( !pPal ) + return; -bool wxPalette::FreeResource(bool WXUNUSED(force)) -{ - if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) + if ( ::GetPaletteEntries(data.m_hPalette, 0, n, pPal->palPalEntry) ) + m_hPalette = ::CreatePalette(pPal); + + free(pPal); + } + + virtual ~wxPaletteRefData() { - DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette); + if ( m_hPalette ) + ::DeleteObject(m_hPalette); } - return true; -} + virtual bool IsOk() const { return m_hPalette != 0; } -int wxPalette::GetColoursCount() const -{ - if ( M_PALETTEDATA && M_PALETTEDATA->m_hPalette) + UINT GetEntries() const { - return ::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, 0, 0, NULL ); + return ::GetPaletteEntries(m_hPalette, 0, 0, NULL); } - return 0; -} +private: + // caller must free() the pointer + static LOGPALETTE *Alloc(UINT numEntries) + { + LOGPALETTE *pPal = (LOGPALETTE *) + malloc(sizeof(LOGPALETTE) + numEntries*sizeof(PALETTEENTRY)); + if ( pPal ) + { + pPal->palVersion = 0x300; + pPal->palNumEntries = numEntries; + } + + return pPal; + } -bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) -{ - UnRef(); + void Init() { m_hPalette = 0; } -#if defined(__WXMICROWIN__) + HPALETTE m_hPalette; - return false; + friend class WXDLLIMPEXP_FWD_CORE wxPalette; +}; -#else +// ============================================================================ +// wxPalette +// ============================================================================ - m_refData = new wxPaletteRefData; +IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) - NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + - (WORD)n * sizeof(PALETTEENTRY)); - if (!npPal) - return false; +#define M_PALETTEDATA ((wxPaletteRefData *)m_refData) - npPal->palVersion = 0x300; - npPal->palNumEntries = (WORD)n; +bool wxPalette::Create(int n, + unsigned char *red, + unsigned char *green, + unsigned char *blue) +{ + m_refData = new wxPaletteRefData(n, red, green, blue); - int i; - for (i = 0; i < n; i ++) - { - npPal->palPalEntry[i].peRed = red[i]; - npPal->palPalEntry[i].peGreen = green[i]; - npPal->palPalEntry[i].peBlue = blue[i]; - npPal->palPalEntry[i].peFlags = 0; - } - M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal); - LocalFree((HANDLE)npPal); - return true; + return IsOk(); +} -#endif +wxGDIRefData *wxPalette::CreateGDIRefData() const +{ + return new wxPaletteRefData; } -int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const +wxGDIRefData *wxPalette::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPaletteRefData(*wx_static_cast(const wxPaletteRefData *, data)); +} + +int wxPalette::GetColoursCount() const +{ + return IsOk() ? M_PALETTEDATA->GetEntries() : 0; +} + +int wxPalette::GetPixel(unsigned char red, + unsigned char green, + unsigned char blue) const { -#ifdef __WXMICROWIN__ - return wxNOT_FOUND; -#else if ( !m_refData ) return wxNOT_FOUND; - return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue)); -#endif + return ::GetNearestPaletteIndex(M_PALETTEDATA->m_hPalette, + PALETTERGB(red, green, blue)); } -bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const +bool wxPalette::GetRGB(int index, + unsigned char *red, + unsigned char *green, + unsigned char *blue) const { -#ifdef __WXMICROWIN__ - return false; -#else if ( !m_refData ) return false; @@ -136,24 +163,26 @@ bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsi return false; PALETTEENTRY entry; - if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry)) - { - *red = entry.peRed; - *green = entry.peGreen; - *blue = entry.peBlue; - return true; - } - else + if ( !::GetPaletteEntries(M_PALETTEDATA->m_hPalette, index, 1, &entry) ) return false; -#endif + + *red = entry.peRed; + *green = entry.peGreen; + *blue = entry.peBlue; + + return true; +} + +WXHPALETTE wxPalette::GetHPALETTE() const +{ + return M_PALETTEDATA ? (WXHPALETTE)M_PALETTEDATA->m_hPalette : 0; } void wxPalette::SetHPALETTE(WXHPALETTE pal) { - if ( !m_refData ) - m_refData = new wxPaletteRefData; + AllocExclusive(); - M_PALETTEDATA->m_hPalette = pal; + M_PALETTEDATA->m_hPalette = (HPALETTE)pal; } #endif // wxUSE_PALETTE diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index a43d02b14d..9df28c6731 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -469,12 +469,12 @@ bool wxPen::IsFree() const return M_PENDATA && !M_PENDATA->HasHPEN(); } -wxObjectRefData* wxPen::CreateRefData() const +wxGDIRefData* wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData* wxPen::CloneRefData(const wxObjectRefData* data) const +wxGDIRefData* wxPen::CloneGDIRefData(const wxGDIRefData* data) const { return new wxPenRefData(*wx_static_cast(const wxPenRefData*, data)); } diff --git a/src/msw/region.cpp b/src/msw/region.cpp index 51aff2b707..329f150d01 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -143,12 +143,12 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/os2/bitmap.cpp b/src/os2/bitmap.cpp index 068ccb0294..8b3dbb8fea 100644 --- a/src/os2/bitmap.cpp +++ b/src/os2/bitmap.cpp @@ -94,12 +94,12 @@ void wxBitmapRefData::Free() // wxBitmap creation // ---------------------------------------------------------------------------- -wxObjectRefData* wxBitmap::CreateRefData() const +wxGDIRefData* wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const +wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const { return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data)); } diff --git a/src/os2/region.cpp b/src/os2/region.cpp index 92849e1384..eff2107d60 100644 --- a/src/os2/region.cpp +++ b/src/os2/region.cpp @@ -233,12 +233,12 @@ wxRegion::~wxRegion() { } // end of wxRegion::~wxRegion -wxObjectRefData *wxRegion::CreateData() const +wxGDIRefData *wxRegion::CreateData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } diff --git a/src/palmos/brush.cpp b/src/palmos/brush.cpp index 9cee09616c..6018ae35b2 100644 --- a/src/palmos/brush.cpp +++ b/src/palmos/brush.cpp @@ -71,12 +71,12 @@ bool wxBrush::operator==(const wxBrush& brush) const return false; } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return NULL; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return NULL; } diff --git a/src/palmos/region.cpp b/src/palmos/region.cpp index 46c1839b40..ae6ffff148 100644 --- a/src/palmos/region.cpp +++ b/src/palmos/region.cpp @@ -73,12 +73,12 @@ wxRegion::~wxRegion() { } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return NULL; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return NULL; } diff --git a/src/x11/bitmap.cpp b/src/x11/bitmap.cpp index ba6ebacd0e..856f0288b8 100644 --- a/src/x11/bitmap.cpp +++ b/src/x11/bitmap.cpp @@ -227,7 +227,7 @@ bool wxMask::Create( const wxBitmap& bitmap ) // wxBitmap //----------------------------------------------------------------------------- -class wxBitmapRefData: public wxObjectRefData +class wxBitmapRefData : public wxGDIRefData { public: wxBitmapRefData(); @@ -237,6 +237,8 @@ public: // shouldn't be called more than once as it doesn't free the existing data bool Create(int width, int height, int depth); + virtual bool IsOk() const { return m_pixmap || m_bitmap; } + Pixmap m_pixmap; Pixmap m_bitmap; Display *m_display; @@ -430,12 +432,12 @@ wxBitmap::wxBitmap(const char* const* bits) Create(bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); } -wxObjectRefData *wxBitmap::CreateRefData() const +wxGDIRefData *wxBitmap::CreateGDIRefData() const { return new wxBitmapRefData; } -wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data)); } @@ -934,11 +936,6 @@ wxBitmap::~wxBitmap() { } -bool wxBitmap::IsOk() const -{ - return (m_refData != NULL); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); diff --git a/src/x11/brush.cpp b/src/x11/brush.cpp index 3eeb858046..7ac5842b35 100644 --- a/src/x11/brush.cpp +++ b/src/x11/brush.cpp @@ -24,7 +24,7 @@ // wxBrush //----------------------------------------------------------------------------- -class wxBrushRefData: public wxObjectRefData +class wxBrushRefData : public wxGDIRefData { public: wxBrushRefData() @@ -82,12 +82,12 @@ wxBrush::~wxBrush() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxBrush::CreateRefData() const +wxGDIRefData *wxBrush::CreateGDIRefData() const { return new wxBrushRefData; } -wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const { return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/x11/colour.cpp b/src/x11/colour.cpp index 26dfeded95..df120d904b 100644 --- a/src/x11/colour.cpp +++ b/src/x11/colour.cpp @@ -25,7 +25,7 @@ // wxColour //----------------------------------------------------------------------------- -class wxColourRefData: public wxObjectRefData +class wxColourRefData : public wxGDIRefData { public: wxColourRefData() @@ -37,8 +37,8 @@ public: m_colormap = (WXColormap *) NULL; m_hasPixel = false; } - wxColourRefData(const wxColourRefData& data): - wxObjectRefData() + + wxColourRefData(const wxColourRefData& data) { m_color = data.m_color; m_colormap = data.m_colormap; @@ -50,7 +50,7 @@ public: FreeColour(); } - bool operator == (const wxColourRefData& data) const + bool operator==(const wxColourRefData& data) const { return (m_colormap == data.m_colormap && m_hasPixel == data.m_hasPixel && @@ -162,12 +162,12 @@ bool wxColour::operator == ( const wxColour& col ) const } -wxObjectRefData *wxColour::CreateRefData() const +wxGDIRefData *wxColour::CreateGDIRefData() const { return new wxColourRefData; } -wxObjectRefData *wxColour::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxColour::CloneGDIRefData(const wxGDIRefData *data) const { return new wxColourRefData(*(wxColourRefData *)data); } diff --git a/src/x11/cursor.cpp b/src/x11/cursor.cpp index 1e1efbc681..f1b2a9dc89 100644 --- a/src/x11/cursor.cpp +++ b/src/x11/cursor.cpp @@ -19,6 +19,7 @@ #include "wx/utils.h" #include "wx/icon.h" #include "wx/gdicmn.h" + #include "wx/image.h" #endif #include "wx/x11/private.h" @@ -31,7 +32,7 @@ // wxCursor //----------------------------------------------------------------------------- -class wxCursorRefData: public wxObjectRefData +class wxCursorRefData: public wxGDIRefData { public: @@ -143,9 +144,14 @@ wxCursor::~wxCursor() { } -bool wxCursor::IsOk() const +wxGDIRefData *wxCursor::CreateGDIRefData() const { - return (m_refData != NULL); + return new wxCursorRefData; +} + +wxGDIRefData *wxCursor::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxCursorRefData(*wx_static_cast(const wxCursorRefData *, data)); } WXCursor wxCursor::GetCursor() const diff --git a/src/x11/font.cpp b/src/x11/font.cpp index 3b0f09338f..0855e067a3 100644 --- a/src/x11/font.cpp +++ b/src/x11/font.cpp @@ -93,7 +93,7 @@ wxXFont::~wxXFont() // wxFontRefData // ---------------------------------------------------------------------------- -class wxFontRefData: public wxObjectRefData +class wxFontRefData: public wxGDIRefData { friend class wxFont; @@ -402,7 +402,7 @@ void wxFontRefData::InitFromNative() } wxFontRefData::wxFontRefData( const wxFontRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_pointSize = data.m_pointSize; m_family = data.m_family; @@ -686,6 +686,16 @@ wxFont::~wxFont() { } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + // ---------------------------------------------------------------------------- // change the font attributes // ---------------------------------------------------------------------------- diff --git a/src/x11/palette.cpp b/src/x11/palette.cpp index 8d7852654f..79f2767556 100644 --- a/src/x11/palette.cpp +++ b/src/x11/palette.cpp @@ -170,6 +170,16 @@ bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *gre return true; } +wxGDIRefData *wxPalette::CreateGDIRefData() const +{ + return new wxPaletteRefData; +} + +wxGDIRefData *wxPalette::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPaletteRefData(*wx_static_cast(const wxPaletteRefData *, data)); +} + int wxPalette::GetPixel(unsigned char WXUNUSED(red), unsigned char WXUNUSED(green), unsigned char WXUNUSED(blue)) const diff --git a/src/x11/pen.cpp b/src/x11/pen.cpp index 23cf2ca01e..079472dbdf 100644 --- a/src/x11/pen.cpp +++ b/src/x11/pen.cpp @@ -24,7 +24,7 @@ // wxPen //----------------------------------------------------------------------------- -class wxPenRefData: public wxObjectRefData +class wxPenRefData : public wxGDIRefData { public: wxPenRefData() @@ -91,12 +91,12 @@ wxPen::~wxPen() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxPen::CreateRefData() const +wxGDIRefData *wxPen::CreateGDIRefData() const { return new wxPenRefData; } -wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const { return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/x11/region.cpp b/src/x11/region.cpp index bf46762fe0..f912e633ba 100644 --- a/src/x11/region.cpp +++ b/src/x11/region.cpp @@ -31,7 +31,7 @@ // wxRegionRefData: private class containing the information about the region // ---------------------------------------------------------------------------- -class wxRegionRefData : public wxObjectRefData +class wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() @@ -115,12 +115,12 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } @@ -361,7 +361,7 @@ struct _XRegion { _XBox *rects, extents; }; -class wxRIRefData: public wxObjectRefData +class wxRIRefData: public wxGDIRefData { public: -- 2.45.2