From 55ccdb93e4ae4b606a4068cb37492c1ec3ed77a6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Oct 2006 19:26:48 +0000 Subject: [PATCH] COW cleanup patch (1583966): 1. perform deep comparison for the classes for which it makes sense in the ports where this wasn't done yet 2. remove (shallow) comparison operators for the classes for which it does not make sense (such as wxBitmap) 3. makes wxBitmap use COW on all ports 4. adds wxObject::IsRefTo() 5. centralizes and improves COW docs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42752 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/accel.tex | 39 ++++---------------- docs/latex/wx/animation.tex | 16 +++++---- docs/latex/wx/bitmap.tex | 35 ++---------------- docs/latex/wx/brush.tex | 15 ++++---- docs/latex/wx/cursor.tex | 22 +++--------- docs/latex/wx/font.tex | 14 +++----- docs/latex/wx/icon.tex | 40 ++------------------- docs/latex/wx/image.tex | 31 +--------------- docs/latex/wx/metafile.tex | 1 + docs/latex/wx/object.tex | 18 ++++++++++ docs/latex/wx/palette.tex | 17 +-------- docs/latex/wx/pen.tex | 14 +++----- docs/latex/wx/region.tex | 1 + docs/latex/wx/trefcount.tex | 36 +++++++++++++++++-- include/wx/bitmap.h | 2 -- include/wx/cocoa/bitmap.h | 5 --- include/wx/dcbuffer.h | 2 +- include/wx/dfb/bitmap.h | 2 -- include/wx/dfb/cursor.h | 2 -- include/wx/generic/accel.h | 7 ---- include/wx/generic/animate.h | 5 --- include/wx/generic/icon.h | 5 --- include/wx/generic/paletteg.h | 2 -- include/wx/gtk/animate.h | 5 --- include/wx/gtk/bitmap.h | 2 -- include/wx/gtk/cursor.h | 2 -- include/wx/gtk/region.h | 7 ++++ include/wx/gtk1/bitmap.h | 2 -- include/wx/gtk1/cursor.h | 2 -- include/wx/image.h | 5 --- include/wx/mac/carbon/accel.h | 5 --- include/wx/mac/carbon/bitmap.h | 3 -- include/wx/mac/carbon/brush.h | 5 ++- include/wx/mac/carbon/cursor.h | 3 -- include/wx/mac/carbon/icon.h | 2 -- include/wx/mac/carbon/metafile.h | 6 ---- include/wx/mac/carbon/palette.h | 3 -- include/wx/mac/carbon/pen.h | 25 +++++++++++-- include/wx/mac/classic/bitmap.h | 3 -- include/wx/mgl/bitmap.h | 2 -- include/wx/mgl/cursor.h | 2 -- include/wx/mgl/palette.h | 2 -- include/wx/motif/accel.h | 3 -- include/wx/motif/cursor.h | 5 --- include/wx/motif/icon.h | 5 --- include/wx/motif/palette.h | 3 -- include/wx/msw/accel.h | 4 --- include/wx/msw/bitmap.h | 3 -- include/wx/msw/cursor.h | 4 --- include/wx/msw/icon.h | 5 --- include/wx/msw/metafile.h | 6 ---- include/wx/msw/palette.h | 3 -- include/wx/msw/pen.h | 2 +- include/wx/object.h | 3 ++ include/wx/os2/accel.h | 5 --- include/wx/os2/bitmap.h | 6 ---- include/wx/os2/brush.h | 4 +-- include/wx/os2/cursor.h | 2 -- include/wx/os2/icon.h | 5 --- include/wx/os2/metafile.h | 6 ---- include/wx/os2/palette.h | 5 --- include/wx/os2/pen.h | 24 +++++++++++-- include/wx/palmos/accel.h | 7 ---- include/wx/palmos/bitmap.h | 3 -- include/wx/palmos/cursor.h | 4 --- include/wx/palmos/metafile.h | 6 ---- include/wx/palmos/palette.h | 3 -- include/wx/palmos/pen.h | 2 +- include/wx/variant.h | 41 +++++++++++++++------ include/wx/x11/bitmap.h | 2 -- include/wx/x11/cursor.h | 2 -- include/wx/x11/palette.h | 3 -- src/common/bmpbase.cpp | 4 +-- src/common/image.cpp | 2 +- src/common/wincmn.cpp | 2 +- src/dfb/bitmap.cpp | 8 ++--- src/dfb/cursor.cpp | 19 ---------- src/generic/paletteg.cpp | 10 ------ src/generic/wizard.cpp | 2 +- src/gtk/animate.cpp | 2 +- src/gtk/bitmap.cpp | 5 --- src/gtk/brush.cpp | 2 +- src/gtk/cursor.cpp | 10 ------ src/gtk/region.cpp | 62 ++++++++++++++------------------ src/gtk1/bitmap.cpp | 23 +++--------- src/gtk1/brush.cpp | 2 +- src/gtk1/cursor.cpp | 10 ------ src/mac/carbon/bitmap.cpp | 24 ++++--------- src/mac/carbon/brush.cpp | 21 +++++++++++ src/mac/classic/bitmap.cpp | 12 ++----- src/mgl/bitmap.cpp | 19 ++++------ src/mgl/brush.cpp | 13 ++++++- src/mgl/cursor.cpp | 10 ------ src/mgl/palette.cpp | 10 ------ src/mgl/pen.cpp | 21 ++++++++++- src/msw/accel.cpp | 10 ------ src/msw/brush.cpp | 2 +- src/msw/cursor.cpp | 10 ------ src/palmos/cursor.cpp | 5 --- src/x11/bitmap.cpp | 18 +++------- src/x11/brush.cpp | 2 +- src/x11/cursor.cpp | 10 ------ 102 files changed, 307 insertions(+), 636 deletions(-) diff --git a/docs/latex/wx/accel.tex b/docs/latex/wx/accel.tex index 304dbb3439..ce92692abf 100644 --- a/docs/latex/wx/accel.tex +++ b/docs/latex/wx/accel.tex @@ -85,6 +85,12 @@ initial accelerator table for a window. +\wxheading{Predefined objects} + +Objects: + +{\bf wxNullAcceleratorTable} + \wxheading{Example} {\small% @@ -150,6 +156,7 @@ and cmd values like you would construct wxAcceleratorEntry objects with.} \func{}{\destruct{wxAcceleratorTable}}{\void} Destroys the wxAcceleratorTable object. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxAcceleratorTable::IsOk}\label{wxacceleratortableisok} @@ -170,35 +177,3 @@ Assignment operator, using \helpref{reference counting}{trefcount}. \wxheading{Return value} Returns reference to this object. - -\membersection{wxAcceleratorTable::operator $==$}\label{wxacceleratortableequal} - -\func{bool}{operator $==$}{\param{const wxAcceleratorTable\& }{accel}} - -Equality operator. This operator tests whether the internal data pointers are -equal (a fast test). - -\wxheading{Parameters} - -\docparam{accel}{Accelerator table to compare with} - -\wxheading{Return value} - -Returns true if the accelerator tables were effectively equal, false otherwise. - -\membersection{wxAcceleratorTable::operator $!=$}\label{wxacceleratortablenotequal} - -\func{bool}{operator $!=$}{\param{const wxAcceleratorTable\& }{accel}} - -Inequality operator. This operator tests whether the internal data pointers are -unequal (a fast test). - -\wxheading{Parameters} - -\docparam{accel}{Accelerator table to compare with} - -\wxheading{Return value} - -Returns true if the accelerator tables were unequal, false otherwise. - - diff --git a/docs/latex/wx/animation.tex b/docs/latex/wx/animation.tex index 9e3e6df825..8b6c013d06 100644 --- a/docs/latex/wx/animation.tex +++ b/docs/latex/wx/animation.tex @@ -44,8 +44,7 @@ Default constructor. \func{}{wxAnimation}{\param{const wxAnimation\& }{anim}} -Copy constructor. -wxAnimation objects are reference counted so that this operation is very fast. +Copy constructor, uses \helpref{reference counting}{trefcount}. \func{}{wxAnimation}{\param{const wxString\& }{name}, \param{wxAnimationType}{ type = wxANIMATION\_TYPE\_ANY}} @@ -60,10 +59,8 @@ Loads an animation from a file. \func{}{\destruct{wxAnimation}}{\void} -Destroys the wxAnimation object and possibly the underlying animation data. -Because reference counting is used, the animation may not actually be -destroyed at this point - only when the reference count is zero will the -data be deleted. +Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxAnimation::GetDelay}\label{wxanimationgetdelay} @@ -151,3 +148,10 @@ Loads an animation from a file. \true if the operation succeeded, \false otherwise. + +\membersection{wxAnimation::operator $=$}\label{wxanimationassignment} + +\func{wxAnimation\&}{operator $=$}{\param{const wxAnimation\& }{brush}} + +Assignment operator, using \helpref{reference counting}{trefcount}. + diff --git a/docs/latex/wx/bitmap.tex b/docs/latex/wx/bitmap.tex index 57eb5c05d8..db2d9f7ac3 100644 --- a/docs/latex/wx/bitmap.tex +++ b/docs/latex/wx/bitmap.tex @@ -206,10 +206,8 @@ wxImage to a wxBitmap.} \func{}{\destruct{wxBitmap}}{\void} -Destroys the wxBitmap object and possibly the underlying bitmap data. -Because reference counting is used, the bitmap may not actually be -destroyed at this point - only when the reference count is zero will the -data be deleted. +Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. If the application omits to delete the bitmap explicitly, the bitmap will be destroyed automatically by wxWidgets when the application exits. @@ -595,33 +593,4 @@ Assignment operator, using \helpref{reference counting}{trefcount}. Returns 'this' object. -\membersection{wxBitmap::operator $==$}\label{wxbitmapequal} - -\func{bool}{operator $==$}{\param{const wxBitmap\& }{bitmap}} - -Equality operator. This operator tests whether the internal data pointers are -equal (a fast test). - -\wxheading{Parameters} - -\docparam{bitmap}{Bitmap to compare with 'this'} - -\wxheading{Return value} - -Returns true if the bitmaps were effectively equal, false otherwise. - -\membersection{wxBitmap::operator $!=$}\label{wxbitmapnotequal} - -\func{bool}{operator $!=$}{\param{const wxBitmap\& }{bitmap}} - -Inequality operator. This operator tests whether the internal data pointers are -unequal (a fast test). - -\wxheading{Parameters} - -\docparam{bitmap}{Bitmap to compare with 'this'} - -\wxheading{Return value} - -Returns true if the bitmaps were unequal, false otherwise. diff --git a/docs/latex/wx/brush.tex b/docs/latex/wx/brush.tex index 63faaac73e..1f00f00b40 100644 --- a/docs/latex/wx/brush.tex +++ b/docs/latex/wx/brush.tex @@ -135,12 +135,10 @@ If a stipple brush is created, the brush style will be set to wxSTIPPLE. \func{}{\destruct{wxBrush}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \wxheading{Remarks} -The destructor may not delete the underlying brush object of the native windowing -system, since wxBrush uses a reference counting system for efficiency. - Although all remaining brushes are deleted when the application exits, the application should try to clean up all brushes itself. This is because wxWidgets cannot know if a pointer to the brush object is stored in an @@ -300,18 +298,17 @@ Assignment operator, using \helpref{reference counting}{trefcount}. \func{bool}{operator $==$}{\param{const wxBrush\& }{brush}} -Equality operator. Two brushes are equal if they contain pointers -to the same underlying brush data. It does not compare each attribute, -so two independently-created brushes using the same parameters will -fail the test. +Equality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. \membersection{wxBrush::operator $!=$}\label{wxbrushnotequals} \func{bool}{operator $!=$}{\param{const wxBrush\& }{brush}} -Inequality operator. Two brushes are not equal if they contain pointers -to different underlying brush data. It does not compare each attribute. +Inequality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. + \section{\class{wxBrushList}}\label{wxbrushlist} diff --git a/docs/latex/wx/cursor.tex b/docs/latex/wx/cursor.tex index a27b660288..7a07cdd229 100644 --- a/docs/latex/wx/cursor.tex +++ b/docs/latex/wx/cursor.tex @@ -229,7 +229,10 @@ wxCursor down_cursor = wxCursor(down_bits, 32, 32, \func{}{\destruct{wxCursor}}{\void} -Destroys the cursor. A cursor can be reused for more +Destroys the cursor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. + +A cursor can be reused for more than one window, and does not get destroyed when the window is destroyed. wxWidgets destroys all cursors on application exit, although it is best to clean them up explicitly. @@ -246,20 +249,3 @@ Returns true if cursor data is present. Assignment operator, using \helpref{reference counting}{trefcount}. -\membersection{wxCursor::operator $==$}\label{wxcursorequals} - -\func{bool}{operator $==$}{\param{const wxCursor\& }{cursor}} - -Equality operator. Two cursors are equal if they contain pointers -to the same underlying cursor data. It does not compare each attribute, -so two independently-created cursors using the same parameters will -fail the test. - -\membersection{wxCursor::operator $!=$}\label{wxcursornotequals} - -\func{bool}{operator $!=$}{\param{const wxCursor\& }{cursor}} - -Inequality operator. Two cursors are not equal if they contain pointers -to different underlying cursor data. It does not compare each attribute. - - diff --git a/docs/latex/wx/font.tex b/docs/latex/wx/font.tex index 001deb8209..6d45292dec 100644 --- a/docs/latex/wx/font.tex +++ b/docs/latex/wx/font.tex @@ -248,12 +248,10 @@ and \helpref{wxDC::GetTextExtent}{wxdcgettextextent}. \func{}{\destruct{wxFont}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \wxheading{Remarks} -The destructor may not delete the underlying font object of the native windowing -system, since wxFont uses a reference counting system for efficiency. - Although all remaining fonts are deleted when the application exits, the application should try to clean up all fonts itself. This is because wxWidgets cannot know if a pointer to the font object is stored in an @@ -589,16 +587,14 @@ Assignment operator, using \helpref{reference counting}{trefcount}. \func{bool}{operator $==$}{\param{const wxFont\& }{font}} -Equality operator. Two fonts are equal if they contain pointers -to the same underlying font data. It does not compare each attribute, -so two independently-created fonts using the same parameters will -fail the test. +Equality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. \membersection{wxFont::operator $!=$}\label{wxfontnotequals} \func{bool}{operator $!=$}{\param{const wxFont\& }{font}} -Inequality operator. Two fonts are not equal if they contain pointers -to different underlying font data. It does not compare each attribute. +Inequality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. diff --git a/docs/latex/wx/icon.tex b/docs/latex/wx/icon.tex index e1df5b3e7d..b1a8b244a1 100644 --- a/docs/latex/wx/icon.tex +++ b/docs/latex/wx/icon.tex @@ -212,10 +212,8 @@ must have mask colour set. \func{}{\destruct{wxIcon}}{\void} -Destroys the wxIcon object and possibly the underlying icon data. -Because reference counting is used, the icon may not actually be -destroyed at this point - only when the reference count is zero will the -data be deleted. +Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. If the application omits to delete the icon explicitly, the icon will be destroyed automatically by wxWidgets when the application exits. @@ -355,9 +353,7 @@ Sets the width member (does not affect the icon data). \func{wxIcon\& }{operator $=$}{\param{const wxIcon\& }{icon}} -Assignment operator. This operator does not copy any data, but instead -passes a pointer to the data in {\it icon} and increments a reference -counter. It is a fast operation. +Assignment operator, using \helpref{reference counting}{trefcount}. \wxheading{Parameters} @@ -367,34 +363,4 @@ counter. It is a fast operation. Returns 'this' object. -\membersection{wxIcon::operator $==$}\label{wxiconequal} - -\func{bool}{operator $==$}{\param{const wxIcon\& }{icon}} - -Equality operator. This operator tests whether the internal data pointers are -equal (a fast test). - -\wxheading{Parameters} - -\docparam{icon}{Icon to compare with 'this'} - -\wxheading{Return value} - -Returns true if the icons were effectively equal, false otherwise. - -\membersection{wxIcon::operator $!=$}\label{wxiconnotequal} - -\func{bool}{operator $!=$}{\param{const wxIcon\& }{icon}} - -Inequality operator. This operator tests whether the internal data pointers are -unequal (a fast test). - -\wxheading{Parameters} - -\docparam{icon}{Icon to compare with 'this'} - -\wxheading{Return value} - -Returns true if the icons were unequal, false otherwise. - diff --git a/docs/latex/wx/image.tex b/docs/latex/wx/image.tex index 8920eea23c..a15f1a6f7b 100644 --- a/docs/latex/wx/image.tex +++ b/docs/latex/wx/image.tex @@ -224,6 +224,7 @@ platform-dependent bitmap} \func{}{\destruct{wxImage}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxImage::AddHandler}\label{wximageaddhandler} @@ -1300,36 +1301,6 @@ Assignment operator, using \helpref{reference counting}{trefcount}. Returns 'this' object. -\membersection{wxImage::operator $==$}\label{wximageequal} - -\constfunc{bool}{operator $==$}{\param{const wxImage\& }{image}} - -Equality operator. This operator tests whether the internal data pointers are -equal (a fast test). - -\wxheading{Parameters} - -\docparam{image}{Image to compare with 'this'} - -\wxheading{Return value} - -Returns true if the images were effectively equal, false otherwise. - - -\membersection{wxImage::operator $!=$}\label{wximagenotequal} - -\constfunc{bool}{operator $!=$}{\param{const wxImage\& }{image}} - -Inequality operator. This operator tests whether the internal data pointers are -unequal (a fast test). - -\wxheading{Parameters} - -\docparam{image}{Image to compare with 'this'} - -\wxheading{Return value} - -Returns true if the images were unequal, false otherwise. \section{\class{wxImageHandler}}\label{wximagehandler} diff --git a/docs/latex/wx/metafile.tex b/docs/latex/wx/metafile.tex index 111e5697f7..26c0c47202 100644 --- a/docs/latex/wx/metafile.tex +++ b/docs/latex/wx/metafile.tex @@ -33,6 +33,7 @@ using the \helpref{wxMetafile:IsOk}{wxmetafileisok} member. \func{}{\destruct{wxMetafile}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxMetafile::IsOk}\label{wxmetafileisok} diff --git a/docs/latex/wx/object.tex b/docs/latex/wx/object.tex index d7c65cee43..4332aa6a02 100644 --- a/docs/latex/wx/object.tex +++ b/docs/latex/wx/object.tex @@ -116,6 +116,13 @@ this one or is derived from it. bool tmp = obj->IsKindOf(CLASSINFO(wxFrame)); \end{verbatim} +\membersection{wxObject::IsRefTo}\label{wxobjectisrefto} + +\func{bool}{IsRefTo}{\param{const wxObject *}{ obj}} + +Returns \true if this object is referencing the \arg{obj}'s data. +Note that this function only does a {\tt shallow} comparison. + \membersection{wxObject::Ref}\label{wxobjectref} \func{void}{Ref}{\param{const wxObject\& }{clone}} @@ -165,6 +172,17 @@ The {\bf m\_refData} member is set to NULL. \helpref{wxObject::SetRefData}{wxobjectsetrefdata}, \helpref{wxObject::GetRefData}{wxobjectgetrefdata},\rtfsp \helpref{wxObjectRefData}{wxobjectrefdata} +\membersection{wxObject::UnShare}\label{wxobjectunshare} + +\func{void}{UnShare}{\void} + +Ensure that this object's data is not shared with any other object. + +if we have no +data, it is created using CreateRefData() below, if we have shared data +it is copied using CloneRefData(), otherwise nothing is done. + + \membersection{wxObject::operator new}\label{wxobjectnew} \func{void *}{new}{\param{size\_t }{size}, \param{const wxString\& }{filename = NULL}, \param{int}{ lineNum = 0}} diff --git a/docs/latex/wx/palette.tex b/docs/latex/wx/palette.tex index 3524bf599f..fca6264a1e 100644 --- a/docs/latex/wx/palette.tex +++ b/docs/latex/wx/palette.tex @@ -86,6 +86,7 @@ red, blue or green component. \func{}{\destruct{wxPalette}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxPalette::Create}\label{wxpalettecreate} @@ -182,19 +183,3 @@ Returns true if palette data is present. Assignment operator, using \helpref{reference counting}{trefcount}. -\membersection{wxPalette::operator $==$}\label{wxpaletteequals} - -\func{bool}{operator $==$}{\param{const wxPalette\& }{palette}} - -Equality operator. Two palettes are equal if they contain pointers -to the same underlying palette data. It does not compare each attribute, -so two independently-created palettes using the same parameters will -fail the test. - -\membersection{wxPalette::operator $!=$}\label{wxpalettenotequals} - -\func{bool}{operator $!=$}{\param{const wxPalette\& }{palette}} - -Inequality operator. Two palettes are not equal if they contain pointers -to different underlying palette data. It does not compare each attribute. - diff --git a/docs/latex/wx/pen.tex b/docs/latex/wx/pen.tex index 8f39b78099..e4353792b5 100644 --- a/docs/latex/wx/pen.tex +++ b/docs/latex/wx/pen.tex @@ -154,12 +154,10 @@ is found in the colour database. \func{}{\destruct{wxPen}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \wxheading{Remarks} -The destructor may not delete the underlying pen object of the native windowing -system, since wxBrush uses a reference counting system for efficiency. - Although all remaining pens are deleted when the application exits, the application should try to clean up all pens itself. This is because wxWidgets cannot know if a pointer to the pen object is stored in an @@ -335,17 +333,15 @@ Assignment operator, using \helpref{reference counting}{trefcount}. \func{bool}{operator $==$}{\param{const wxPen\& }{pen}} -Equality operator. Two pens are equal if they contain pointers -to the same underlying pen data. It does not compare each attribute, -so two independently-created pens using the same parameters will -fail the test. +Equality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. \membersection{wxPen::operator $!=$}\label{wxpennotequals} \func{bool}{operator $!=$}{\param{const wxPen\& }{pen}} -Inequality operator. Two pens are not equal if they contain pointers -to different underlying pen data. It does not compare each attribute. +Inequality operator. +See \helpref{reference-counted object comparison}{refcountequality} for more info. \section{\class{wxPenList}}\label{wxpenlist} diff --git a/docs/latex/wx/region.tex b/docs/latex/wx/region.tex index f12a867b8f..5b2cb77be1 100644 --- a/docs/latex/wx/region.tex +++ b/docs/latex/wx/region.tex @@ -65,6 +65,7 @@ Constructs a region using the non-transparent pixels of a bitmap. See \func{}{\destruct{wxRegion}}{\void} Destructor. +See \helpref{reference-counted object destruction}{refcountdestruct} for more info. \membersection{wxRegion::Clear}\label{wxregionclear} diff --git a/docs/latex/wx/trefcount.tex b/docs/latex/wx/trefcount.tex index 968ea172a7..eb280c5c78 100644 --- a/docs/latex/wx/trefcount.tex +++ b/docs/latex/wx/trefcount.tex @@ -1,6 +1,6 @@ \section{Reference counting}\label{trefcount} -\subsection{Reference counting and why you shouldn't care about it}\label{refcount} +\subsection{Why you shouldn't care about it}\label{refcount} Many wxWidgets objects use a technique known as \it{reference counting}, also known as {\it copy on write} (COW). @@ -19,22 +19,54 @@ is not seen from the outside of the class - in any case, the result of any operation on it is the same. \subsection{List of reference-counted wxWidgets classes}\label{refcountlist} +\subsection{Object comparison}\label{refcountequality} + +The $==$ and $!=$ operators of \helpref{wxWidgets COW objects}{refcountlist} +always do a {\tt deep} comparison. + +This means that the equality operator will return \true if two objects are +identic and not only if they share the same data. + +Note that wxWidgets follows the {\it STL philosophy}: when a comparison operator cannot +be implemented efficiently (like for e.g. wxImage's $==$ operator which would need to +compare pixel-by-pixel the entire image's data), it's not implemented at all. + +That's why not all reference-counted wxWidgets classes provide comparison operators. + +Also note that if you only need to do a {\tt shallow} comparison between two +\helpref{wxObject}{wxobject}-derived classes, you should not use the $==$ and $!=$ operators +but rather the \helpref{wxObject::IsRefTo}{wxobjectisrefto} function. + + +\subsection{Object destruction}\label{refcountdestruct} + +When a COW object destructor is called, it may not delete the data: if it's shared, +the destructor will just decrement the shared data's reference count without destroying it. + +Only when the destructor of the last object owning the data is called, the data is really +destroyed. As for all other COW-things, this happens transparently to the class users so +that you shouldn't care about it. + The following classes in wxWidgets have efficient (i.e. fast) assignment operators and copy constructors since they are reference-counted: \helpref{wxAcceleratorTable}{wxacceleratortable}\\ +\helpref{wxAnimation}{wxanimation}\\ +\helpref{wxBitmap}{wxbitmap}\\ \helpref{wxBrush}{wxbrush}\\ \helpref{wxCursor}{wxcursor}\\ \helpref{wxFont}{wxfont}\\ +\helpref{wxIcon}{wxicon}\\ \helpref{wxImage}{wximage}\\ \helpref{wxMetafile}{wxmetafile}\\ \helpref{wxPalette}{wxpalette}\\ \helpref{wxPen}{wxpen}\\ \helpref{wxRegion}{wxregion}\\ -\helpref{wxRegionIterator}{wxregioniterator}\\ \helpref{wxString}{wxstring} +Note that the list above reports the objects which are reference-counted in all ports of +wxWidgets; some ports may use this tecnique also for other classes. \subsection{Make your own reference-counted class}\label{wxobjectoverview} Reference counting can be implemented easily using \helpref{wxObject}{wxobject} diff --git a/include/wx/bitmap.h b/include/wx/bitmap.h index afafd31958..4153de3a39 100644 --- a/include/wx/bitmap.h +++ b/include/wx/bitmap.h @@ -127,8 +127,6 @@ public: wxBitmap(const char* const* bits); wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM); wxBitmap(const wxImage& image, int depth = -1); - bool operator == (const wxBitmap& bmp) const; - bool operator != (const wxBitmap& bmp) const; bool Create(int width, int height, int depth = -1); diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h index efd4480f02..0cd2cd66b1 100644 --- a/include/wx/cocoa/bitmap.h +++ b/include/wx/cocoa/bitmap.h @@ -132,11 +132,6 @@ public: int GetBitmapType() const; - inline bool operator == (const wxBitmap& bitmap) const - { return m_refData == bitmap.m_refData; } - inline bool operator != (const wxBitmap& bitmap) const - { return m_refData != bitmap.m_refData; } - // wxObjectRefData wxObjectRefData *CreateRefData() const; wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; diff --git a/include/wx/dcbuffer.h b/include/wx/dcbuffer.h index 1b12cc6f05..bce4780cc0 100644 --- a/include/wx/dcbuffer.h +++ b/include/wx/dcbuffer.h @@ -169,7 +169,7 @@ public: if (style & wxBUFFER_VIRTUAL_AREA) window->PrepareDC( m_paintdc ); - if( buffer != wxNullBitmap ) + if( buffer.IsOk() ) Init(&m_paintdc, buffer, style); else Init(&m_paintdc, window->GetClientSize(), style); diff --git a/include/wx/dfb/bitmap.h b/include/wx/dfb/bitmap.h index 0bbda585bf..affe69eaed 100644 --- a/include/wx/dfb/bitmap.h +++ b/include/wx/dfb/bitmap.h @@ -39,8 +39,6 @@ public: bool Ok() const { return IsOk(); } bool IsOk() const; - bool operator==(const wxBitmap& bmp) const; - bool operator!=(const wxBitmap& bmp) const { return !(*this == bmp); } bool Create(const wxIDirectFBSurfacePtr& surface); bool Create(int width, int height, int depth = -1); diff --git a/include/wx/dfb/cursor.h b/include/wx/dfb/cursor.h index 7ebd2e81d7..03efa522fa 100644 --- a/include/wx/dfb/cursor.h +++ b/include/wx/dfb/cursor.h @@ -34,8 +34,6 @@ public: bool Ok() const { return IsOk(); } bool IsOk() const; - bool operator==(const wxCursor& cursor) const; - bool operator!=(const wxCursor& cursor) const { return !(*this == cursor); } // implementation wxBitmap GetBitmap() const; diff --git a/include/wx/generic/accel.h b/include/wx/generic/accel.h index 17f7e44fa4..23022b061e 100644 --- a/include/wx/generic/accel.h +++ b/include/wx/generic/accel.h @@ -23,13 +23,6 @@ public: wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]); virtual ~wxAcceleratorTable(); -#if WXWIN_COMPATIBILITY_2_4 - bool operator==(const wxAcceleratorTable& accel) const - { return m_refData == accel.m_refData; } - bool operator!=(const wxAcceleratorTable& accel) const - { return !(*this == accel); } -#endif - bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index f0cf9bbf9f..fd7ee2a824 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -23,11 +23,6 @@ WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDL class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase { public: - bool operator == (const wxAnimation& anim) const - { return m_refData == anim.m_refData; } - bool operator != (const wxAnimation& anim) const - { return m_refData != anim.m_refData; } - virtual bool IsOk() const { return m_refData != NULL; } diff --git a/include/wx/generic/icon.h b/include/wx/generic/icon.h index 9a6976f691..03ffbbef90 100644 --- a/include/wx/generic/icon.h +++ b/include/wx/generic/icon.h @@ -44,11 +44,6 @@ public: { } - bool operator==(const wxIcon& icon) const - { return m_refData == icon.m_refData; } - bool operator!=(const wxIcon& icon) const - { return !(*this == icon); } - // create from bitmap (which should have a mask unless it's monochrome): // there shouldn't be any implicit bitmap -> icon conversion (i.e. no // ctors, assignment operators...), but it's ok to have such function diff --git a/include/wx/generic/paletteg.h b/include/wx/generic/paletteg.h index 63feb0a9d2..6ae9287a91 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(); - bool operator == ( const wxPalette& palette ) const; - bool operator != ( const wxPalette& palette ) const; virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const; diff --git a/include/wx/gtk/animate.h b/include/wx/gtk/animate.h index 56dd791cf9..d9dbe1b72a 100644 --- a/include/wx/gtk/animate.h +++ b/include/wx/gtk/animate.h @@ -33,11 +33,6 @@ public: wxAnimation& operator= (const wxAnimation&); - bool operator == (const wxAnimation& anim) const - { return m_pixbuf == anim.m_pixbuf; } - bool operator != (const wxAnimation& anim) const - { return m_pixbuf != anim.m_pixbuf; } - virtual bool IsOk() const { return m_pixbuf != NULL; } diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 1aadd87f6d..e84582519e 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -64,8 +64,6 @@ public: wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); } virtual ~wxBitmap(); - bool operator == ( const wxBitmap& bmp ) const; - bool operator != ( const wxBitmap& bmp ) const { return !(*this == bmp); } bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/gtk/cursor.h b/include/wx/gtk/cursor.h index f4e0f4b71c..44d03dd747 100644 --- a/include/wx/gtk/cursor.h +++ b/include/wx/gtk/cursor.h @@ -32,8 +32,6 @@ public: int hotSpotX=-1, int hotSpotY=-1, const char maskBits[] = NULL, const wxColour *fg = NULL, const wxColour *bg = NULL ); virtual ~wxCursor(); - bool operator == ( const wxCursor& cursor ) const; - bool operator != ( const wxCursor& cursor ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/gtk/region.h b/include/wx/gtk/region.h index 3aae6270c4..71f47a47aa 100644 --- a/include/wx/gtk/region.h +++ b/include/wx/gtk/region.h @@ -94,6 +94,7 @@ class WXDLLIMPEXP_CORE wxRegionIterator: public wxObject public: wxRegionIterator(); wxRegionIterator(const wxRegion& region); + ~wxRegionIterator(); void Reset() { m_current = 0u; } void Reset(const wxRegion& region); @@ -113,9 +114,15 @@ public: wxRect GetRect() const; private: + void Init(); + void CreateRects( const wxRegion& r ); + size_t m_current; wxRegion m_region; + wxRect *m_rects; + size_t m_numRects; + private: DECLARE_DYNAMIC_CLASS(wxRegionIterator) }; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 18e2f40f19..ecf23e1144 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -78,8 +78,6 @@ public: wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); } virtual ~wxBitmap(); - bool operator == ( const wxBitmap& bmp ) const; - bool operator != ( const wxBitmap& bmp ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/gtk1/cursor.h b/include/wx/gtk1/cursor.h index 30969ed9ef..eba3d24b1b 100644 --- a/include/wx/gtk1/cursor.h +++ b/include/wx/gtk1/cursor.h @@ -35,8 +35,6 @@ public: int hotSpotX=-1, int hotSpotY=-1, const char maskBits[] = NULL, const wxColour *fg = NULL, const wxColour *bg = NULL ); virtual ~wxCursor(); - bool operator == ( const wxCursor& cursor ) const; - bool operator != ( const wxCursor& cursor ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/image.h b/include/wx/image.h index 21e322bf2c..b1d7eea62a 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -392,11 +392,6 @@ public: // -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees void RotateHue(double angle); - bool operator == (const wxImage& image) const - { return m_refData == image.m_refData; } - bool operator != (const wxImage& image) const - { return m_refData != image.m_refData; } - static wxList& GetHandlers() { return sm_handlers; } static void AddHandler( wxImageHandler *handler ); static void InsertHandler( wxImageHandler *handler ); diff --git a/include/wx/mac/carbon/accel.h b/include/wx/mac/carbon/accel.h index 742b460190..cf0ce76927 100644 --- a/include/wx/mac/carbon/accel.h +++ b/include/wx/mac/carbon/accel.h @@ -24,11 +24,6 @@ public: virtual ~wxAcceleratorTable(); - bool operator == (const wxAcceleratorTable& accel) const - { return m_refData == accel.m_refData; } - bool operator != (const wxAcceleratorTable& accel) const - { return m_refData != accel.m_refData; } - bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/mac/carbon/bitmap.h b/include/wx/mac/carbon/bitmap.h index b2eb887ecd..865ee73a90 100644 --- a/include/wx/mac/carbon/bitmap.h +++ b/include/wx/mac/carbon/bitmap.h @@ -157,9 +157,6 @@ public: wxMask *GetMask() const; void SetMask(wxMask *mask) ; - inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } - inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } - static void InitStandardHandlers(); // raw bitmap access support functions, for internal use only diff --git a/include/wx/mac/carbon/brush.h b/include/wx/mac/carbon/brush.h index 349bde4603..49528efbea 100644 --- a/include/wx/mac/carbon/brush.h +++ b/include/wx/mac/carbon/brush.h @@ -44,10 +44,9 @@ public: virtual void MacSetTheme(short macThemeBrush) ; virtual void MacSetThemeBackground(unsigned long macThemeBackground , WXRECTPTR extent) ; - bool operator == (const wxBrush& brush) const - { return m_refData == brush.m_refData; } + bool operator == (const wxBrush& brush) const; bool operator != (const wxBrush& brush) const - { return m_refData != brush.m_refData; } + { return !(*this == brush); } wxMacBrushKind MacGetBrushKind() const ; diff --git a/include/wx/mac/carbon/cursor.h b/include/wx/mac/carbon/cursor.h index 2495246c57..0cc9a6800a 100644 --- a/include/wx/mac/carbon/cursor.h +++ b/include/wx/mac/carbon/cursor.h @@ -38,9 +38,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const ; - 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; } - void MacInstall() const ; void SetHCURSOR(WXHCURSOR cursor); diff --git a/include/wx/mac/carbon/icon.h b/include/wx/mac/carbon/icon.h index 34fe306a7e..2e9e0d0af9 100644 --- a/include/wx/mac/carbon/icon.h +++ b/include/wx/mac/carbon/icon.h @@ -36,8 +36,6 @@ public: bool LoadFile(const wxString& name ,wxBitmapType flags = wxBITMAP_TYPE_ICON_RESOURCE ) { return LoadFile( name , flags , -1 , -1 ) ; } - bool operator==(const wxIcon& icon) const { return m_refData == icon.m_refData; } - bool operator!=(const wxIcon& icon) const { return !(*this == icon); } // create from bitmap (which should have a mask unless it's monochrome): // there shouldn't be any implicit bitmap -> icon conversion (i.e. no diff --git a/include/wx/mac/carbon/metafile.h b/include/wx/mac/carbon/metafile.h index e23f826746..da46526593 100644 --- a/include/wx/mac/carbon/metafile.h +++ b/include/wx/mac/carbon/metafile.h @@ -57,12 +57,6 @@ public: // Implementation WXHMETAFILE GetHMETAFILE() const ; void SetHMETAFILE(WXHMETAFILE mf) ; - - // Operators - inline bool operator == (const wxMetafile& metafile) const { return m_refData == metafile.m_refData; } - inline bool operator != (const wxMetafile& metafile) const { return m_refData != metafile.m_refData; } - -protected: }; class WXDLLEXPORT wxMetafileDC: public wxDC diff --git a/include/wx/mac/carbon/palette.h b/include/wx/mac/carbon/palette.h index 538ca77eca..f64a6ec46e 100644 --- a/include/wx/mac/carbon/palette.h +++ b/include/wx/mac/carbon/palette.h @@ -47,9 +47,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const { return (m_refData != NULL) ; } - inline bool operator == (const wxPalette& palette) const { return m_refData == palette.m_refData; } - inline bool operator != (const wxPalette& palette) const { return m_refData != palette.m_refData; } - virtual int GetColoursCount() const; private: diff --git a/include/wx/mac/carbon/pen.h b/include/wx/mac/carbon/pen.h index 607bf38622..ff6f65f12c 100644 --- a/include/wx/mac/carbon/pen.h +++ b/include/wx/mac/carbon/pen.h @@ -28,6 +28,20 @@ public: wxPenRefData& operator=(const wxPenRefData& data); + bool operator==(const wxPenRefData& data) const + { + // 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.IsRefTo(&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; @@ -54,8 +68,15 @@ public: wxPen(const wxBitmap& stipple, int width); virtual ~wxPen(); - 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; } + inline bool operator == (const wxPen& pen) const + { + const wxPenRefData *penData = (wxPenRefData *)pen.m_refData; + + // an invalid pen is only equal to another invalid pen + return m_refData ? penData && *M_PENDATA == *penData : !penData; + } + + inline bool operator != (const wxPen& pen) const { return *(this == pen); } virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const { return (m_refData != NULL) ; } diff --git a/include/wx/mac/classic/bitmap.h b/include/wx/mac/classic/bitmap.h index b3997a4122..3a4a28f609 100644 --- a/include/wx/mac/classic/bitmap.h +++ b/include/wx/mac/classic/bitmap.h @@ -190,9 +190,6 @@ public: int GetBitmapType() const; - inline bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } - inline bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } - static void InitStandardHandlers(); // raw bitmap access support functions, for internal use only diff --git a/include/wx/mgl/bitmap.h b/include/wx/mgl/bitmap.h index 25a58396b5..f794945d54 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 operator == (const wxBitmap& bmp) const; - bool operator != (const wxBitmap& bmp) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/mgl/cursor.h b/include/wx/mgl/cursor.h index 9cbc07a306..1b3f118b3f 100644 --- a/include/wx/mgl/cursor.h +++ b/include/wx/mgl/cursor.h @@ -33,8 +33,6 @@ public: long flags = wxBITMAP_TYPE_CUR_RESOURCE, int hotSpotX = 0, int hotSpotY = 0); virtual ~wxCursor(); - bool operator == (const wxCursor& cursor) const; - bool operator != (const wxCursor& cursor) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/mgl/palette.h b/include/wx/mgl/palette.h index bc15c26da0..c8d46785cd 100644 --- a/include/wx/mgl/palette.h +++ b/include/wx/mgl/palette.h @@ -35,8 +35,6 @@ public: wxPalette(); wxPalette(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue); virtual ~wxPalette(); - bool operator == (const wxPalette& palette) const; - bool operator != (const wxPalette& palette) const; virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const; diff --git a/include/wx/motif/accel.h b/include/wx/motif/accel.h index 3de7ce7640..7753ac9d68 100644 --- a/include/wx/motif/accel.h +++ b/include/wx/motif/accel.h @@ -26,9 +26,6 @@ public: virtual ~wxAcceleratorTable(); - bool operator == (const wxAcceleratorTable& accel) const { return m_refData == accel.m_refData; } - bool operator != (const wxAcceleratorTable& accel) const { return m_refData != accel.m_refData; } - bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 11366cc4df..e30e1f0db4 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -42,11 +42,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const; - bool operator == (const wxCursor& cursor) const - { return m_refData == cursor.m_refData; } - bool operator != (const wxCursor& cursor) const - { return m_refData != cursor.m_refData; } - // Motif-specific. // Create/get a cursor for the current display WXCursor GetXCursor(WXDisplay* display) const; diff --git a/include/wx/motif/icon.h b/include/wx/motif/icon.h index c22eb5e562..0be2892759 100644 --- a/include/wx/motif/icon.h +++ b/include/wx/motif/icon.h @@ -55,11 +55,6 @@ public: // ctors, assignment operators...), but it's ok to have such function void CopyFromBitmap(const wxBitmap& bmp); - bool operator == (const wxIcon& icon) const - { return m_refData == icon.m_refData; } - bool operator != (const wxIcon& icon) const - { return !(*this == icon); } - DECLARE_DYNAMIC_CLASS(wxIcon) }; diff --git a/include/wx/motif/palette.h b/include/wx/motif/palette.h index 4d4ae78372..47b0ae7c05 100644 --- a/include/wx/motif/palette.h +++ b/include/wx/motif/palette.h @@ -61,9 +61,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const { return (m_refData != NULL) ; } - bool operator == (const wxPalette& palette) const { return m_refData == palette.m_refData; } - bool operator != (const wxPalette& palette) const { return m_refData != palette.m_refData; } - // Motif-specific WXColormap GetXColormap(WXDisplay* display = NULL) const; bool TransferBitmap(void *data, int depth, int size); diff --git a/include/wx/msw/accel.h b/include/wx/msw/accel.h index f65d24664f..236c044b0c 100644 --- a/include/wx/msw/accel.h +++ b/include/wx/msw/accel.h @@ -30,10 +30,6 @@ public: // initialize from array wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]); - bool operator==(const wxAcceleratorTable& accel) const; - bool operator!=(const wxAcceleratorTable& accel) const - { return !(*this == accel); } - bool Ok() const { return IsOk(); } bool IsOk() const; void SetHACCEL(WXHACCEL hAccel); diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 8c73d46b29..4a02193bed 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -139,9 +139,6 @@ public: wxBitmap GetMaskBitmap() const; void SetMask(wxMask *mask); - bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } - bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } - // these functions are internal and shouldn't be used, they risk to // disappear in the future bool HasAlpha() const; diff --git a/include/wx/msw/cursor.h b/include/wx/msw/cursor.h index 2e194f10f2..24fb71f1d7 100644 --- a/include/wx/msw/cursor.h +++ b/include/wx/msw/cursor.h @@ -32,10 +32,6 @@ public: wxCursor(int idCursor); virtual ~wxCursor(); - bool operator==(const wxCursor& cursor) const; - bool operator!=(const wxCursor& cursor) const - { return !(*this == cursor); } - // implementation only void SetHCURSOR(WXHCURSOR cursor) { SetHandle((WXHANDLE)cursor); } WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); } diff --git a/include/wx/msw/icon.h b/include/wx/msw/icon.h index 8682193961..c4b420937c 100644 --- a/include/wx/msw/icon.h +++ b/include/wx/msw/icon.h @@ -65,11 +65,6 @@ public: long type = wxBITMAP_TYPE_ICO_RESOURCE, int desiredWidth = -1, int desiredHeight = -1); - bool operator == (const wxIcon& icon) const - { return m_refData == icon.m_refData; } - bool operator != (const wxIcon& icon) const - { return m_refData != icon.m_refData; } - // implementation only from now on wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; } diff --git a/include/wx/msw/metafile.h b/include/wx/msw/metafile.h index bbfc7c71a8..3fb6377b42 100644 --- a/include/wx/msw/metafile.h +++ b/include/wx/msw/metafile.h @@ -68,12 +68,6 @@ public: int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; } void SetWindowsMappingMode(int mm); - // Operators - bool operator==(const wxMetafile& metafile) const - { return m_refData == metafile.m_refData; } - bool operator!=(const wxMetafile& metafile) const - { return m_refData != metafile.m_refData; } - private: DECLARE_DYNAMIC_CLASS(wxMetafile) }; diff --git a/include/wx/msw/palette.h b/include/wx/msw/palette.h index f302fa3574..561c8ae689 100644 --- a/include/wx/msw/palette.h +++ b/include/wx/msw/palette.h @@ -44,9 +44,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk(void) const { return (m_refData != NULL) ; } - inline bool operator == (const wxPalette& palette) const { return m_refData == palette.m_refData; } - inline bool operator != (const wxPalette& palette) const { return m_refData != palette.m_refData; } - virtual bool FreeResource(bool force = false); // implemetation diff --git a/include/wx/msw/pen.h b/include/wx/msw/pen.h index 57d5f1c0d6..d35cd47a2d 100644 --- a/include/wx/msw/pen.h +++ b/include/wx/msw/pen.h @@ -36,7 +36,7 @@ public: m_join == data.m_join && m_cap == data.m_cap && m_colour == data.m_colour && - (m_style != wxSTIPPLE || m_stipple == data.m_stipple) && + (m_style != wxSTIPPLE || m_stipple.IsRefTo(&data.m_stipple)) && (m_style != wxUSER_DASH || (m_nbDash == data.m_nbDash && memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); diff --git a/include/wx/object.h b/include/wx/object.h index c268f677b4..20f610714e 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -473,6 +473,9 @@ public: // Make sure this object has only one reference void UnShare() { AllocExclusive(); } + // Do a shallow comparison of our referenced data with the given object's refdata + bool IsRefTo(const wxObject *p) const { return m_refData == p->m_refData; } + protected: // ensure that our data is not shared with anybody else: if we have no // data, it is created using CreateRefData() below, if we have shared data diff --git a/include/wx/os2/accel.h b/include/wx/os2/accel.h index a0ee7448b3..819c857ee2 100644 --- a/include/wx/os2/accel.h +++ b/include/wx/os2/accel.h @@ -40,11 +40,6 @@ public: virtual ~wxAcceleratorTable(); - inline bool operator== (const wxAcceleratorTable& rAccel) const - { return m_refData == rAccel.m_refData; }; - inline bool operator!= (const wxAcceleratorTable& rAccel) const - { return m_refData != rAccel.m_refData; }; - bool Ok() const { return IsOk(); } bool IsOk() const; void SetHACCEL(WXHACCEL hAccel); diff --git a/include/wx/os2/bitmap.h b/include/wx/os2/bitmap.h index b19a965bd9..03802ca653 100644 --- a/include/wx/os2/bitmap.h +++ b/include/wx/os2/bitmap.h @@ -187,12 +187,6 @@ public: void SetMask(wxMask* pMask) ; - inline bool operator==(const wxBitmap& rBitmap) const - { return m_refData == rBitmap.m_refData; } - - inline bool operator!=(const wxBitmap& rBitmap) const - { return m_refData != rBitmap.m_refData; } - // Implementation public: inline void SetHBITMAP(WXHBITMAP hBmp) diff --git a/include/wx/os2/brush.h b/include/wx/os2/brush.h index c7657279d5..04b160e4f7 100644 --- a/include/wx/os2/brush.h +++ b/include/wx/os2/brush.h @@ -47,8 +47,8 @@ public: wxBrush(const wxBitmap& rStipple); virtual ~wxBrush(); - inline bool operator == (const wxBrush& rBrush) const { return m_refData == rBrush.m_refData; } - inline bool operator != (const wxBrush& rBrush) const { return m_refData != rBrush.m_refData; } + inline bool operator == (const wxBrush& rBrush) const; + inline bool operator != (const wxBrush& rBrush) const { return !(*this == rBrush); } virtual void SetColour(const wxColour& rColour); virtual void SetColour(unsigned char cRed, unsigned char cGreen, unsigned char cBrush); diff --git a/include/wx/os2/cursor.h b/include/wx/os2/cursor.h index e1595d8daf..0f465ccb55 100644 --- a/include/wx/os2/cursor.h +++ b/include/wx/os2/cursor.h @@ -48,8 +48,6 @@ public: ); wxCursor(int nCursorType); inline ~wxCursor() { } - inline bool operator == (const wxCursor& rCursor) const { return m_refData == rCursor.m_refData; } - inline bool operator != (const wxCursor& rCursor) const { return m_refData != rCursor.m_refData; } inline WXHCURSOR GetHCURSOR(void) const { return (M_CURSORDATA ? M_CURSORDATA->m_hCursor : 0); } inline void SetHCURSOR(WXHCURSOR hCursor) { SetHandle((WXHANDLE)hCursor); } diff --git a/include/wx/os2/icon.h b/include/wx/os2/icon.h index 9c254a8353..af4208791d 100644 --- a/include/wx/os2/icon.h +++ b/include/wx/os2/icon.h @@ -64,11 +64,6 @@ public: ,int nDesiredHeight = -1 ); - inline bool operator == (const wxIcon& rIcon) const - { return m_refData == rIcon.m_refData; } - inline bool operator != (const wxIcon& rIcon) const - { return m_refData != rIcon.m_refData; } - wxIconRefData *GetIconData() const { return (wxIconRefData *)m_refData; } inline void SetHICON(WXHICON hIcon) { SetHandle((WXHANDLE)hIcon); } diff --git a/include/wx/os2/metafile.h b/include/wx/os2/metafile.h index 41e256c552..66f2899ddf 100644 --- a/include/wx/os2/metafile.h +++ b/include/wx/os2/metafile.h @@ -66,12 +66,6 @@ public: void SetHMETAFILE(WXHANDLE mf) ; inline int GetWindowsMappingMode(void) { return M_METAFILEDATA->m_windowsMappingMode; } void SetWindowsMappingMode(int mm); - - // Operators - inline bool operator== (const wxMetafile& metafile) const - { return m_refData == metafile.m_refData; } - inline bool operator!= (const wxMetafile& metafile) const - { return m_refData != metafile.m_refData; } }; class WXDLLEXPORT wxMetafileDC: public wxDC diff --git a/include/wx/os2/palette.h b/include/wx/os2/palette.h index e7312893fd..f6d7f0f92e 100644 --- a/include/wx/os2/palette.h +++ b/include/wx/os2/palette.h @@ -62,11 +62,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk(void) const { return (m_refData != NULL) ; } - inline bool operator == (const wxPalette& rPalette) const - { return m_refData == rPalette.m_refData; } - inline bool operator != (const wxPalette& rPalette) const - { return m_refData != rPalette.m_refData; } - 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 233016dc12..d192842d2c 100644 --- a/include/wx/os2/pen.h +++ b/include/wx/os2/pen.h @@ -27,6 +27,20 @@ public: wxPenRefData(const wxPenRefData& rData); virtual ~wxPenRefData(); + bool operator==(const wxPenRefData& data) const + { + // we intentionally don't compare m_hPen fields here + return m_nStyle == data.m_nStyle && + m_nWidth == data.m_nWidth && + m_nJoin == data.m_nJoin && + m_nCap == data.m_nCap && + m_vColour == data.m_vColour && + (m_style != wxSTIPPLE || m_stipple.IsRefTo(&data.m_stipple)) && + (m_style != wxUSER_DASH || + (m_dash == data.m_dash && + memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); + } + protected: int m_nWidth; int m_nStyle; @@ -57,9 +71,15 @@ public: virtual ~wxPen(); inline bool operator == (const wxPen& rPen) const - { return m_refData == rPen.m_refData; } + { + const wxPenRefData *penData = (wxPenRefData *)pen.m_refData; + + // an invalid pen is only equal to another invalid pen + return m_refData ? penData && *M_PENDATA == *penData : !penData; + } + inline bool operator != (const wxPen& rPen) const - { return m_refData != rPen.m_refData; } + { return !(*this == rPen); } virtual bool Ok() const { return IsOk(); } virtual bool IsOk(void) const { return (m_refData != NULL); } diff --git a/include/wx/palmos/accel.h b/include/wx/palmos/accel.h index 5c9b415759..f47b035a5f 100644 --- a/include/wx/palmos/accel.h +++ b/include/wx/palmos/accel.h @@ -30,13 +30,6 @@ public: virtual ~wxAcceleratorTable(); -#if WXWIN_COMPATIBILITY_2_4 - bool operator==(const wxAcceleratorTable& accel) const - { return m_refData == accel.m_refData; } - bool operator!=(const wxAcceleratorTable& accel) const - { return !(*this == accel); } -#endif - bool Ok() const { return IsOk(); } bool IsOk() const; void SetHACCEL(WXHACCEL hAccel); diff --git a/include/wx/palmos/bitmap.h b/include/wx/palmos/bitmap.h index 983fcc0ce3..71f4d9bef9 100644 --- a/include/wx/palmos/bitmap.h +++ b/include/wx/palmos/bitmap.h @@ -132,9 +132,6 @@ public: wxMask *GetMask() const; void SetMask(wxMask *mask); - bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } - bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } - // these functions are internal and shouldn't be used, they risk to // disappear in the future bool HasAlpha() const; diff --git a/include/wx/palmos/cursor.h b/include/wx/palmos/cursor.h index ef083421ad..f4e8a90e0d 100644 --- a/include/wx/palmos/cursor.h +++ b/include/wx/palmos/cursor.h @@ -32,10 +32,6 @@ public: wxCursor(int idCursor); virtual ~wxCursor(); - bool operator==(const wxCursor& cursor) const; - bool operator!=(const wxCursor& cursor) const - { return !(*this == cursor); } - // implementation only void SetHCURSOR(WXHCURSOR cursor) { SetHandle((WXHANDLE)cursor); } WXHCURSOR GetHCURSOR() const { return (WXHCURSOR)GetHandle(); } diff --git a/include/wx/palmos/metafile.h b/include/wx/palmos/metafile.h index 82ab410b5b..71a94deb7a 100644 --- a/include/wx/palmos/metafile.h +++ b/include/wx/palmos/metafile.h @@ -68,12 +68,6 @@ public: int GetWindowsMappingMode() const { return M_METAFILEDATA->m_windowsMappingMode; } void SetWindowsMappingMode(int mm); - // Operators - bool operator==(const wxMetafile& metafile) const - { return m_refData == metafile.m_refData; } - bool operator!=(const wxMetafile& metafile) const - { return m_refData != metafile.m_refData; } - private: DECLARE_DYNAMIC_CLASS(wxMetafile) }; diff --git a/include/wx/palmos/palette.h b/include/wx/palmos/palette.h index 0229985a7a..690299c08c 100644 --- a/include/wx/palmos/palette.h +++ b/include/wx/palmos/palette.h @@ -44,9 +44,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk(void) const { return (m_refData != NULL) ; } - inline bool operator == (const wxPalette& palette) const { return m_refData == palette.m_refData; } - inline bool operator != (const wxPalette& palette) const { return m_refData != palette.m_refData; } - 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 fb190c5a4a..7ad901706c 100644 --- a/include/wx/palmos/pen.h +++ b/include/wx/palmos/pen.h @@ -36,7 +36,7 @@ public: m_join == data.m_join && m_cap == data.m_cap && m_colour == data.m_colour && - (m_style != wxSTIPPLE || m_stipple == data.m_stipple) && + (m_style != wxSTIPPLE || m_stipple.IsRefTo(&data.m_stipple)) && (m_style != wxUSER_DASH || (m_nbDash == data.m_nbDash && memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); diff --git a/include/wx/variant.h b/include/wx/variant.h index 37ecf447d3..d5483080e8 100644 --- a/include/wx/variant.h +++ b/include/wx/variant.h @@ -332,7 +332,7 @@ expdecl wxVariant& operator << ( wxVariant &variant, const classname &object ); #define IMPLEMENT_VARIANT_OBJECT(classname) \ IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname,EMPTY_PARAMETER_VALUE) -#define IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname,expdecl) \ +#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,expdecl) \ class classname##VariantData: public wxVariantData \ { \ public:\ @@ -355,15 +355,6 @@ private: \ \ IMPLEMENT_CLASS(classname##VariantData, wxVariantData)\ \ -bool classname##VariantData::Eq(wxVariantData& data) const \ -{\ - wxASSERT( wxIsKindOf((&data), classname##VariantData) );\ -\ - classname##VariantData & otherData = (classname##VariantData &) data;\ -\ - return (otherData.m_value == m_value);\ -}\ -\ wxString classname##VariantData::GetType() const\ {\ return m_value.GetClassInfo()->GetClassName();\ @@ -390,6 +381,36 @@ expdecl wxVariant& operator << ( wxVariant &variant, const classname &value )\ return variant;\ } +// implements a wxVariantData-derived class using for the Eq() method the operator== +// which must have been provided by "classname" +#define IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname,expdecl) \ +IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,expdecl) \ +\ +bool classname##VariantData::Eq(wxVariantData& data) const \ +{\ + wxASSERT( wxIsKindOf((&data), classname##VariantData) );\ +\ + classname##VariantData & otherData = (classname##VariantData &) data;\ +\ + return otherData.m_value == m_value;\ +}\ + + +// implements a wxVariantData-derived class using for the Eq() method a shallow +// comparison (through wxObject::IsRefTo function) +#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(classname,expdecl) \ +IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,expdecl) \ +\ +bool classname##VariantData::Eq(wxVariantData& data) const \ +{\ + wxASSERT( wxIsKindOf((&data), classname##VariantData) );\ +\ + classname##VariantData & otherData = (classname##VariantData &) data;\ +\ + return (otherData.m_value.IsRefTo(&m_value));\ +}\ + + // Since we want type safety wxVariant we need to fetch and dynamic_cast // in a seemingly safe way so the compiler can check, so we define // a dynamic_cast /wxDynamicCast analogue. diff --git a/include/wx/x11/bitmap.h b/include/wx/x11/bitmap.h index 9cf858f893..5a3ab7be0b 100644 --- a/include/wx/x11/bitmap.h +++ b/include/wx/x11/bitmap.h @@ -84,8 +84,6 @@ public: wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); virtual ~wxBitmap(); - bool operator == ( const wxBitmap& bmp ) const; - bool operator != ( const wxBitmap& bmp ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/x11/cursor.h b/include/wx/x11/cursor.h index 1b27f36a05..3a22621bd1 100644 --- a/include/wx/x11/cursor.h +++ b/include/wx/x11/cursor.h @@ -35,8 +35,6 @@ public: int hotSpotX=-1, int hotSpotY=-1, const char maskBits[]=0, wxColour *fg=0, wxColour *bg=0 ); virtual ~wxCursor(); - bool operator == ( const wxCursor& cursor ) const; - bool operator != ( const wxCursor& cursor ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/x11/palette.h b/include/wx/x11/palette.h index 8375bbd624..8babcd8f59 100644 --- a/include/wx/x11/palette.h +++ b/include/wx/x11/palette.h @@ -61,9 +61,6 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const { return (m_refData != NULL) ; } - bool operator == (const wxPalette& palette) const { return m_refData == palette.m_refData; } - bool operator != (const wxPalette& palette) const { return m_refData != palette.m_refData; } - // X-specific WXColormap GetXColormap(WXDisplay* display = NULL) const; bool TransferBitmap(void *data, int depth, int size); diff --git a/src/common/bmpbase.cpp b/src/common/bmpbase.cpp index 82bb30b7ab..8c940d21b0 100644 --- a/src/common/bmpbase.cpp +++ b/src/common/bmpbase.cpp @@ -28,8 +28,8 @@ // ---------------------------------------------------------------------------- #if wxUSE_VARIANT -IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLEXPORT) -IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon,WXDLLEXPORT) +IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT) +IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT) #endif // ---------------------------------------------------------------------------- diff --git a/src/common/image.cpp b/src/common/image.cpp index a2674529de..41d7b5e05c 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -49,7 +49,7 @@ #endif // HAS_FILE_STREAMS #if wxUSE_VARIANT -IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxImage,WXDLLEXPORT) +IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxImage,WXDLLEXPORT) #endif //----------------------------------------------------------------------------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 421497abad..d03c8cb878 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -1023,7 +1023,7 @@ bool wxWindowBase::SetCursor(const wxCursor& cursor) { // setting an invalid cursor is ok, it means that we don't have any special // cursor - if ( m_cursor == cursor ) + if ( m_cursor.IsRefTo(&cursor) ) { // no change return false; diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 59d158d517..8b57fb96de 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -194,12 +194,6 @@ bool wxBitmap::IsOk() const return (m_refData != NULL && M_BITMAP->m_surface); } -bool wxBitmap::operator==(const wxBitmap& bmp) const -{ - // FIXME: is this the right way to compare bitmaps? - return (m_refData == bmp.m_refData); -} - int wxBitmap::GetHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); @@ -236,6 +230,7 @@ void wxBitmap::SetMask(wxMask *mask) { wxCHECK_RET( Ok(), wxT("invalid bitmap") ); + AllocExclusive(); delete M_BITMAP->m_mask; M_BITMAP->m_mask = mask; } @@ -328,6 +323,7 @@ void wxBitmap::SetPalette(const wxPalette& palette) wxCHECK_RET( Ok(), wxT("invalid bitmap") ); wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") ); + AllocExclusive(); delete M_BITMAP->m_palette; M_BITMAP->m_palette = NULL; diff --git a/src/dfb/cursor.cpp b/src/dfb/cursor.cpp index 5f4ea9114b..c5465f52fc 100644 --- a/src/dfb/cursor.cpp +++ b/src/dfb/cursor.cpp @@ -68,25 +68,6 @@ bool wxCursor::IsOk() const return m_refData && M_CURSOR->m_bitmap.Ok(); } -bool wxCursor::operator==(const wxCursor& cursor) const -{ - if ( Ok() ) - { - if ( !cursor.Ok() ) - return false; - else if ( M_CURSOR->m_id != M_CURSOR_OF(cursor)->m_id ) - return false; - else if ( M_CURSOR->m_id == -1 ) // non-stock cursor - return (m_refData == cursor.m_refData); - else - return true; // IDs != -1 and are the same - } - else - { - return !cursor.Ok(); - } -} - wxObjectRefData *wxCursor::CreateRefData() const { return new wxCursorRefData; diff --git a/src/generic/paletteg.cpp b/src/generic/paletteg.cpp index 5d21a8b330..ac8cd8a83b 100644 --- a/src/generic/paletteg.cpp +++ b/src/generic/paletteg.cpp @@ -70,16 +70,6 @@ wxPalette::~wxPalette() { } -bool wxPalette::operator == (const wxPalette& palette) const -{ - return m_refData == palette.m_refData; -} - -bool wxPalette::operator != (const wxPalette& palette) const -{ - return m_refData != palette.m_refData; -} - bool wxPalette::IsOk() const { return (m_refData != NULL); diff --git a/src/generic/wizard.cpp b/src/generic/wizard.cpp index cb3b8d0f38..138f1c6680 100644 --- a/src/generic/wizard.cpp +++ b/src/generic/wizard.cpp @@ -631,7 +631,7 @@ bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) if ( !bmpPrev.Ok() ) bmpPrev = m_bitmap; - if ( bmp != bmpPrev ) + if ( !bmp.IsRefTo(&bmpPrev) ) m_statbmp->SetBitmap(bmp); } #endif // wxUSE_STATBMP diff --git a/src/gtk/animate.cpp b/src/gtk/animate.cpp index 23b88a192d..e2c1333636 100644 --- a/src/gtk/animate.cpp +++ b/src/gtk/animate.cpp @@ -213,7 +213,7 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id, PostCreation(size); SetBestSize(size); - if (anim != wxNullAnimation) + if (anim.IsOk()) SetAnimation(anim); // init the timer used for animation diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 522e383b89..37cf202e56 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -708,11 +708,6 @@ wxImage wxBitmap::ConvertToImage() const return image; } -bool wxBitmap::operator == ( const wxBitmap& bmp ) const -{ - return m_refData == bmp.m_refData; -} - bool wxBitmap::IsOk() const { return (m_refData != NULL) && diff --git a/src/gtk/brush.cpp b/src/gtk/brush.cpp index 2140078982..1cc7e69e1f 100644 --- a/src/gtk/brush.cpp +++ b/src/gtk/brush.cpp @@ -40,7 +40,7 @@ public: bool operator == (const wxBrushRefData& data) const { return (m_style == data.m_style && - m_stipple == data.m_stipple && + m_stipple.IsRefTo(&data.m_stipple) && m_colour == data.m_colour); } diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 26b1bc0629..aa71d2490f 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -310,16 +310,6 @@ wxCursor::~wxCursor() { } -bool wxCursor::operator == ( const wxCursor& cursor ) const -{ - return m_refData == cursor.m_refData; -} - -bool wxCursor::operator != ( const wxCursor& cursor ) const -{ - return m_refData != cursor.m_refData; -} - bool wxCursor::IsOk() const { return (m_refData != NULL); diff --git a/src/gtk/region.cpp b/src/gtk/region.cpp index 91eecba5e4..57b6b02ffc 100644 --- a/src/gtk/region.cpp +++ b/src/gtk/region.cpp @@ -336,30 +336,33 @@ GdkRegion *wxRegion::GetRegion() const // wxRegionIterator // ---------------------------------------------------------------------------- -class wxRIRefData: public wxObjectRefData +wxRegionIterator::wxRegionIterator() { -public: - wxRIRefData() { Init(); } - virtual ~wxRIRefData(); - - void CreateRects( const wxRegion& r ); - - void Init() { m_rects = NULL; m_numRects = 0; } + Init(); + Reset(); +} - wxRect *m_rects; - size_t m_numRects; -}; +wxRegionIterator::wxRegionIterator( const wxRegion& region ) +{ + Init(); + Reset(region); +} -wxRIRefData::~wxRIRefData() +void wxRegionIterator::Init() { - delete [] m_rects; + m_rects = NULL; + m_numRects = 0; } -void wxRIRefData::CreateRects( const wxRegion& region ) +wxRegionIterator::~wxRegionIterator() { - delete [] m_rects; + wxDELETEA(m_rects); +} - Init(); +void wxRegionIterator::CreateRects( const wxRegion& region ) +{ + wxDELETEA(m_rects); + m_numRects = 0; GdkRegion *gdkregion = region.GetRegion(); if (!gdkregion) @@ -386,28 +389,16 @@ void wxRIRefData::CreateRects( const wxRegion& region ) g_free( gdkrects ); } -wxRegionIterator::wxRegionIterator() -{ - m_refData = new wxRIRefData(); - Reset(); -} - -wxRegionIterator::wxRegionIterator( const wxRegion& region ) -{ - m_refData = new wxRIRefData(); - Reset(region); -} - void wxRegionIterator::Reset( const wxRegion& region ) { m_region = region; - ((wxRIRefData*)m_refData)->CreateRects(region); + CreateRects(region); Reset(); } bool wxRegionIterator::HaveRects() const { - return m_current < ((wxRIRefData*)m_refData)->m_numRects; + return m_current < m_numRects; } wxRegionIterator& wxRegionIterator::operator ++ () @@ -421,6 +412,7 @@ wxRegionIterator& wxRegionIterator::operator ++ () wxRegionIterator wxRegionIterator::operator ++ (int) { wxRegionIterator tmp = *this; + if (HaveRects()) ++m_current; @@ -431,35 +423,35 @@ wxCoord wxRegionIterator::GetX() const { wxCHECK_MSG( HaveRects(), 0, _T("invalid wxRegionIterator") ); - return ((wxRIRefData*)m_refData)->m_rects[m_current].x; + return m_rects[m_current].x; } wxCoord wxRegionIterator::GetY() const { wxCHECK_MSG( HaveRects(), 0, _T("invalid wxRegionIterator") ); - return ((wxRIRefData*)m_refData)->m_rects[m_current].y; + return m_rects[m_current].y; } wxCoord wxRegionIterator::GetW() const { wxCHECK_MSG( HaveRects(), 0, _T("invalid wxRegionIterator") ); - return ((wxRIRefData*)m_refData)->m_rects[m_current].width; + return m_rects[m_current].width; } wxCoord wxRegionIterator::GetH() const { wxCHECK_MSG( HaveRects(), 0, _T("invalid wxRegionIterator") ); - return ((wxRIRefData*)m_refData)->m_rects[m_current].height; + return m_rects[m_current].height; } wxRect wxRegionIterator::GetRect() const { wxRect r; if( HaveRects() ) - r = ((wxRIRefData*)m_refData)->m_rects[m_current]; + r = m_rects[m_current]; return r; } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 1e7534bcc2..9698b4640c 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -1066,16 +1066,6 @@ wxBitmap::~wxBitmap() { } -bool wxBitmap::operator == ( const wxBitmap& bmp ) const -{ - return m_refData == bmp.m_refData; -} - -bool wxBitmap::operator != ( const wxBitmap& bmp ) const -{ - return m_refData != bmp.m_refData; -} - bool wxBitmap::IsOk() const { return (m_refData != NULL) && @@ -1114,6 +1104,7 @@ void wxBitmap::SetMask( wxMask *mask ) { wxCHECK_RET( Ok(), wxT("invalid bitmap") ); + AllocExclusive(); if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; M_BMPDATA->m_mask = mask; @@ -1248,25 +1239,19 @@ void wxBitmap::SetPalette(const wxPalette& WXUNUSED(palette)) void wxBitmap::SetHeight( int height ) { - if (!m_refData) - m_refData = new wxBitmapRefData(); - + AllocExclusive(); M_BMPDATA->m_height = height; } void wxBitmap::SetWidth( int width ) { - if (!m_refData) - m_refData = new wxBitmapRefData(); - + AllocExclusive(); M_BMPDATA->m_width = width; } void wxBitmap::SetDepth( int depth ) { - if (!m_refData) - m_refData = new wxBitmapRefData(); - + AllocExclusive(); M_BMPDATA->m_bpp = depth; } diff --git a/src/gtk1/brush.cpp b/src/gtk1/brush.cpp index 392418c11e..25536d5518 100644 --- a/src/gtk1/brush.cpp +++ b/src/gtk1/brush.cpp @@ -41,7 +41,7 @@ public: bool operator == (const wxBrushRefData& data) const { return (m_style == data.m_style && - m_stipple == data.m_stipple && + m_stipple.IsRefTo(&data.m_stipple) && m_colour == data.m_colour); } diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index 4f4ab1af4a..bd1e6ca2bd 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -316,16 +316,6 @@ wxCursor::~wxCursor() { } -bool wxCursor::operator == ( const wxCursor& cursor ) const -{ - return m_refData == cursor.m_refData; -} - -bool wxCursor::operator != ( const wxCursor& cursor ) const -{ - return m_refData != cursor.m_refData; -} - bool wxCursor::IsOk() const { return (m_refData != NULL); diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 42031fe4ab..4c0a49334f 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -1281,33 +1281,25 @@ bool wxBitmap::HasAlpha() const void wxBitmap::SetWidth(int w) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetWidth(w); } void wxBitmap::SetHeight(int h) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetHeight(h); } void wxBitmap::SetDepth(int d) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetDepth(d); } void wxBitmap::SetOk(bool isOk) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetOk(isOk); } @@ -1321,18 +1313,14 @@ wxPalette *wxBitmap::GetPalette() const void wxBitmap::SetPalette(const wxPalette& palette) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->m_bitmapPalette = palette ; } #endif // wxUSE_PALETTE void wxBitmap::SetMask(wxMask *mask) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); // Remove existing mask if there is one. delete M_BITMAPDATA->m_bitmapMask; diff --git a/src/mac/carbon/brush.cpp b/src/mac/carbon/brush.cpp index 88dd4bc8de..c9dcbde97c 100644 --- a/src/mac/carbon/brush.cpp +++ b/src/mac/carbon/brush.cpp @@ -30,6 +30,18 @@ public: wxBrushRefData(const wxBrushRefData& data); virtual ~wxBrushRefData(); + bool operator == ( const wxBrushRefData& brush ) const + { + return m_style == brush.m_style && + m_stipple.IsRefTo(&data.m_stipple) && + m_colour == brush.m_colour && + m_macBrushKind == brush.m_macBrushKind && + m_macThemeBrush == brush.m_macThemeBrush && + m_macThemeBackground == brush.m_macThemeBackground && + m_macThemeBackgroundExtent == brush.m_macThemeBackgroundExtent; + } + + protected: wxMacBrushKind m_macBrushKind ; int m_style; @@ -233,3 +245,12 @@ wxMacBrushKind wxBrush::MacGetBrushKind() const { return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour); } + +bool wxBrush::operator == ( const wxBrush& brush ) const +{ + if (m_refData == brush.m_refData) return true; + + if (!m_refData || !brush.m_refData) return false; + + return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); +} diff --git a/src/mac/classic/bitmap.cpp b/src/mac/classic/bitmap.cpp index 768b729616..0605fc9175 100644 --- a/src/mac/classic/bitmap.cpp +++ b/src/mac/classic/bitmap.cpp @@ -999,25 +999,19 @@ wxMask *wxBitmap::GetMask() const void wxBitmap::SetWidth(int w) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->m_width = w; } void wxBitmap::SetHeight(int h) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->m_height = h; } void wxBitmap::SetDepth(int d) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->m_depth = d; } diff --git a/src/mgl/bitmap.cpp b/src/mgl/bitmap.cpp index a1a9c5695f..d8396837c4 100644 --- a/src/mgl/bitmap.cpp +++ b/src/mgl/bitmap.cpp @@ -267,16 +267,6 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) delete bdc; } -bool wxBitmap::operator == (const wxBitmap& bmp) const -{ - return (m_refData == bmp.m_refData); -} - -bool wxBitmap::operator != (const wxBitmap& bmp) const -{ - return (m_refData != bmp.m_refData); -} - bool wxBitmap::IsOk() const { return (m_refData != NULL && M_BMPDATA->m_bitmap != NULL); @@ -314,6 +304,7 @@ void wxBitmap::SetMask(wxMask *mask) { wxCHECK_RET( Ok(), wxT("invalid bitmap") ); + AllocExclusive(); delete M_BMPDATA->m_mask; M_BMPDATA->m_mask = mask; } @@ -357,6 +348,7 @@ void wxBitmap::SetMonoPalette(const wxColour& fg, const wxColour& bg) { wxCHECK_RET( Ok(), wxT("invalid bitmap") ); + AllocExclusive(); palette_t *mono = M_BMPDATA->m_bitmap->pal; wxCHECK_RET( M_BMPDATA->m_bpp == 1, wxT("bitmap is not 1bpp") ); @@ -482,6 +474,7 @@ void wxBitmap::SetPalette(const wxPalette& palette) wxCHECK_RET( Ok(), wxT("invalid bitmap") ); wxCHECK_RET( GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth") ); + AllocExclusive(); delete M_BMPDATA->m_palette; M_BMPDATA->m_palette = NULL; @@ -496,21 +489,21 @@ void wxBitmap::SetPalette(const wxPalette& palette) void wxBitmap::SetHeight(int height) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_height = height; } void wxBitmap::SetWidth(int width) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_width = width; } void wxBitmap::SetDepth(int depth) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_bpp = depth; } diff --git a/src/mgl/brush.cpp b/src/mgl/brush.cpp index 9415eea448..d97544d123 100644 --- a/src/mgl/brush.cpp +++ b/src/mgl/brush.cpp @@ -76,6 +76,13 @@ public: wxBrushRefData(); wxBrushRefData(const wxBrushRefData& data); + bool operator == (const wxBrushRefData& data) const + { + return (m_style == data.m_style && + m_stipple.IsRefTo(&data.m_stipple) && + m_colour == data.m_colour); + } + int m_style; wxColour m_colour; wxBitmap m_stipple; @@ -145,7 +152,11 @@ wxBrush::wxBrush(const wxBitmap &stippleBitmap) bool wxBrush::operator == (const wxBrush& brush) const { - return m_refData == brush.m_refData; + if (m_refData == brush.m_refData) return true; + + if (!m_refData || !brush.m_refData) return false; + + return *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData; } bool wxBrush::operator != (const wxBrush& brush) const diff --git a/src/mgl/cursor.cpp b/src/mgl/cursor.cpp index 709b59e34f..5b9c7899d1 100644 --- a/src/mgl/cursor.cpp +++ b/src/mgl/cursor.cpp @@ -175,16 +175,6 @@ wxCursor::~wxCursor() // wxObject unrefs data } -bool wxCursor::operator == (const wxCursor& cursor) const -{ - return (m_refData == cursor.m_refData); -} - -bool wxCursor::operator != (const wxCursor& cursor) const -{ - return (m_refData != cursor.m_refData); -} - bool wxCursor::IsOk() const { return (m_refData != NULL); diff --git a/src/mgl/palette.cpp b/src/mgl/palette.cpp index da815d8ab1..48717b498b 100644 --- a/src/mgl/palette.cpp +++ b/src/mgl/palette.cpp @@ -63,16 +63,6 @@ wxPalette::~wxPalette() { } -bool wxPalette::operator == (const wxPalette& palette) const -{ - return m_refData == palette.m_refData; -} - -bool wxPalette::operator != (const wxPalette& palette) const -{ - return m_refData != palette.m_refData; -} - bool wxPalette::IsOk(void) const { return (m_refData != NULL); diff --git a/src/mgl/pen.cpp b/src/mgl/pen.cpp index 4c63041cbf..5879052da5 100644 --- a/src/mgl/pen.cpp +++ b/src/mgl/pen.cpp @@ -33,6 +33,21 @@ class wxPenRefData: public wxObjectRefData wxPenRefData(); wxPenRefData(const wxPenRefData& data); + bool operator==(const wxPenRefData& data) const + { + // we intentionally don't compare m_hPen fields here + return m_style == data.m_style && + m_width == data.m_width && + m_pixPattern == data.m_pixPattern && + m_capStyle == data.m_capStyle && + m_joinStyle == data.m_joinStyle && + m_colour == data.m_colour && + (m_style != wxSTIPPLE || m_stipple.IsRefTo(&data.m_stipple)) && + (m_style != wxUSER_DASH || + (m_dash == data.m_dash && + memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxDash)) == 0)); + } + int m_width; int m_style; wxColour m_colour; @@ -109,7 +124,11 @@ wxPen::wxPen(const wxBitmap& stipple, int width) bool wxPen::operator == (const wxPen& pen) const { - return m_refData == pen.m_refData; + if (m_refData == pen.m_refData) return true; + + if (!m_refData || !pen.m_refData) return false; + + return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData ); } bool wxPen::operator != (const wxPen& pen) const diff --git a/src/msw/accel.cpp b/src/msw/accel.cpp index b1451eedfe..3b8355d057 100644 --- a/src/msw/accel.cpp +++ b/src/msw/accel.cpp @@ -130,16 +130,6 @@ wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[] M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0); } -bool wxAcceleratorTable::operator==(const wxAcceleratorTable& accel) const -{ - const wxAcceleratorRefData * - accelData = (wxAcceleratorRefData *)accel.m_refData; - - return m_refData ? (accelData && - M_ACCELDATA->m_hAccel == accelData->m_hAccel) - : !accelData; -} - bool wxAcceleratorTable::IsOk() const { return (M_ACCELDATA && (M_ACCELDATA->m_ok)); diff --git a/src/msw/brush.cpp b/src/msw/brush.cpp index 5e49333dc0..eb3c21d002 100644 --- a/src/msw/brush.cpp +++ b/src/msw/brush.cpp @@ -124,7 +124,7 @@ bool wxBrushRefData::operator==(const wxBrushRefData& data) const // don't compare HBRUSHes return m_style == data.m_style && m_colour == data.m_colour && - m_stipple == data.m_stipple; + m_stipple.IsRefTo(&data.m_stipple); } void wxBrushRefData::DoSetStipple(const wxBitmap& stipple) diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index cdc7992e51..998ec54bce 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -386,16 +386,6 @@ wxCursor::~wxCursor() // other wxCursor functions // ---------------------------------------------------------------------------- -bool wxCursor::operator==(const wxCursor& cursor) const -{ - if ( !m_refData ) - return !cursor.m_refData; - - return cursor.m_refData && - ((wxCursorRefData *)m_refData)->m_hCursor == - ((wxCursorRefData *)cursor.m_refData)->m_hCursor; -} - wxGDIImageRefData *wxCursor::CreateData() const { return new wxCursorRefData; diff --git a/src/palmos/cursor.cpp b/src/palmos/cursor.cpp index a51fcc0d0f..9bb3776db3 100644 --- a/src/palmos/cursor.cpp +++ b/src/palmos/cursor.cpp @@ -108,11 +108,6 @@ wxCursor::~wxCursor() // other wxCursor functions // ---------------------------------------------------------------------------- -bool wxCursor::operator==(const wxCursor& cursor) const -{ - return false; -} - wxGDIImageRefData *wxCursor::CreateData() const { return NULL; diff --git a/src/x11/bitmap.cpp b/src/x11/bitmap.cpp index 7e42116984..40f925df43 100644 --- a/src/x11/bitmap.cpp +++ b/src/x11/bitmap.cpp @@ -917,16 +917,6 @@ wxBitmap::~wxBitmap() { } -bool wxBitmap::operator == ( const wxBitmap& bmp ) const -{ - return m_refData == bmp.m_refData; -} - -bool wxBitmap::operator != ( const wxBitmap& bmp ) const -{ - return m_refData != bmp.m_refData; -} - bool wxBitmap::IsOk() const { return (m_refData != NULL); @@ -964,6 +954,7 @@ void wxBitmap::SetMask( wxMask *mask ) { wxCHECK_RET( Ok(), wxT("invalid bitmap") ); + AllocExclusive(); if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; M_BMPDATA->m_mask = mask; @@ -1070,6 +1061,7 @@ void wxBitmap::SetPalette(const wxPalette& palette) wxCHECK_RET(GetDepth() > 1 && GetDepth() <= 8, wxT("cannot set palette for bitmap of this depth")); + AllocExclusive(); delete M_BMPDATA->m_palette; M_BMPDATA->m_palette = NULL; @@ -1087,21 +1079,21 @@ wxPalette *wxBitmap::GetPalette() const void wxBitmap::SetHeight( int height ) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_height = height; } void wxBitmap::SetWidth( int width ) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_width = width; } void wxBitmap::SetDepth( int depth ) { - if (!m_refData) m_refData = new wxBitmapRefData(); + AllocExclusive(); M_BMPDATA->m_bpp = depth; } diff --git a/src/x11/brush.cpp b/src/x11/brush.cpp index 685c12b747..9aeb158115 100644 --- a/src/x11/brush.cpp +++ b/src/x11/brush.cpp @@ -42,7 +42,7 @@ public: bool operator == (const wxBrushRefData& data) const { return (m_style == data.m_style && - m_stipple == data.m_stipple && + m_stipple.IsRefTo(&data.m_stipple) && m_colour == data.m_colour); } diff --git a/src/x11/cursor.cpp b/src/x11/cursor.cpp index bd861353d6..fb29364b43 100644 --- a/src/x11/cursor.cpp +++ b/src/x11/cursor.cpp @@ -141,16 +141,6 @@ wxCursor::~wxCursor() { } -bool wxCursor::operator == ( const wxCursor& cursor ) const -{ - return m_refData == cursor.m_refData; -} - -bool wxCursor::operator != ( const wxCursor& cursor ) const -{ - return m_refData != cursor.m_refData; -} - bool wxCursor::IsOk() const { return (m_refData != NULL); -- 2.45.2