Added missing test in wxObject::Ref() for already
equal objects (same m_refData). Implemented new ref counting for wxBrush, wxPen and wxColour (in addition to wxRegion). Also inlined some more functions and implemented real comparisons. Corrected refresh code to update GTK's window-less widgets if overdrawn after a wxWindow::Refresh(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13999 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -22,36 +22,36 @@
|
||||
class wxBrushRefData: public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
wxBrushRefData();
|
||||
wxBrushRefData( const wxBrushRefData& data );
|
||||
|
||||
int m_style;
|
||||
wxBitmap m_stipple;
|
||||
wxColour m_colour;
|
||||
wxBrushRefData()
|
||||
{
|
||||
m_style = 0;
|
||||
}
|
||||
|
||||
wxBrushRefData( const wxBrushRefData& data )
|
||||
{
|
||||
m_style = data.m_style;
|
||||
m_stipple = data.m_stipple;
|
||||
m_colour = data.m_colour;
|
||||
}
|
||||
|
||||
bool operator == (const wxBrushRefData& data) const
|
||||
{
|
||||
return (m_style == data.m_style &&
|
||||
m_stipple == data.m_stipple &&
|
||||
m_colour == data.m_colour);
|
||||
}
|
||||
|
||||
int m_style;
|
||||
wxColour m_colour;
|
||||
wxBitmap m_stipple;
|
||||
};
|
||||
|
||||
wxBrushRefData::wxBrushRefData()
|
||||
{
|
||||
m_style = 0;
|
||||
}
|
||||
|
||||
wxBrushRefData::wxBrushRefData( const wxBrushRefData& data )
|
||||
{
|
||||
m_style = data.m_style;
|
||||
m_stipple = data.m_stipple;
|
||||
m_colour = data.m_colour;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
|
||||
|
||||
wxBrush::wxBrush()
|
||||
{
|
||||
}
|
||||
|
||||
wxBrush::wxBrush( const wxColour &colour, int style )
|
||||
{
|
||||
m_refData = new wxBrushRefData();
|
||||
@@ -72,36 +72,28 @@ wxBrush::wxBrush( const wxBitmap &stippleBitmap )
|
||||
M_BRUSHDATA->m_style = wxSTIPPLE;
|
||||
}
|
||||
|
||||
wxBrush::wxBrush( const wxBrush &brush )
|
||||
{
|
||||
Ref( brush );
|
||||
}
|
||||
|
||||
wxBrush::~wxBrush()
|
||||
{
|
||||
// m_refData unrefed in ~wxObject
|
||||
}
|
||||
|
||||
wxBrush& wxBrush::operator = ( const wxBrush& brush )
|
||||
wxObjectRefData *wxBrush::CreateRefData() const
|
||||
{
|
||||
if ( m_refData != brush.m_refData )
|
||||
Ref( brush );
|
||||
return new wxBrushRefData;
|
||||
}
|
||||
|
||||
return *this;
|
||||
wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
|
||||
{
|
||||
return new wxBrushRefData(*(wxBrushRefData *)data);
|
||||
}
|
||||
|
||||
bool wxBrush::operator == ( const wxBrush& brush ) const
|
||||
{
|
||||
return m_refData == brush.m_refData;
|
||||
}
|
||||
|
||||
bool wxBrush::operator != ( const wxBrush& brush ) const
|
||||
{
|
||||
return m_refData != brush.m_refData;
|
||||
}
|
||||
|
||||
bool wxBrush::Ok() const
|
||||
{
|
||||
return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
|
||||
if (m_refData == brush.m_refData) return TRUE;
|
||||
|
||||
if (!m_refData || !brush.m_refData) return FALSE;
|
||||
|
||||
return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
|
||||
}
|
||||
|
||||
int wxBrush::GetStyle() const
|
||||
@@ -139,25 +131,29 @@ wxBitmap *wxBrush::GetStipple() const
|
||||
|
||||
void wxBrush::SetColour( const wxColour& col )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_BRUSHDATA->m_colour = col;
|
||||
}
|
||||
|
||||
void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_BRUSHDATA->m_colour.Set( r, g, b );
|
||||
}
|
||||
|
||||
void wxBrush::SetStyle( int style )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_BRUSHDATA->m_style = style;
|
||||
}
|
||||
|
||||
void wxBrush::SetStipple( const wxBitmap& stipple )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_BRUSHDATA->m_stipple = stipple;
|
||||
if (M_BRUSHDATA->m_stipple.GetMask())
|
||||
{
|
||||
@@ -169,17 +165,3 @@ void wxBrush::SetStipple( const wxBitmap& stipple )
|
||||
}
|
||||
}
|
||||
|
||||
void wxBrush::Unshare()
|
||||
{
|
||||
if (!m_refData)
|
||||
{
|
||||
m_refData = new wxBrushRefData();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
|
||||
UnRef();
|
||||
m_refData = ref;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,13 +25,34 @@
|
||||
class wxColourRefData: public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
wxColourRefData();
|
||||
~wxColourRefData();
|
||||
wxColourRefData()
|
||||
{
|
||||
m_color.red = 0;
|
||||
m_color.green = 0;
|
||||
m_color.blue = 0;
|
||||
m_color.pixel = 0;
|
||||
m_colormap = (GdkColormap *) NULL;
|
||||
m_hasPixel = FALSE;
|
||||
}
|
||||
|
||||
~wxColourRefData()
|
||||
{
|
||||
FreeColour();
|
||||
}
|
||||
|
||||
bool operator == (const wxColourRefData& data) const
|
||||
{
|
||||
return (m_colormap == data.m_colormap &&
|
||||
m_hasPixel == data.m_hasPixel &&
|
||||
m_color.red == data.m_color.red &&
|
||||
m_color.green == data.m_color.green &&
|
||||
m_color.blue == data.m_color.blue &&
|
||||
m_color.pixel == data.m_color.pixel);
|
||||
}
|
||||
|
||||
void FreeColour();
|
||||
void AllocColour( GdkColormap* cmap );
|
||||
|
||||
public:
|
||||
GdkColor m_color;
|
||||
GdkColormap *m_colormap;
|
||||
bool m_hasPixel;
|
||||
@@ -59,21 +80,6 @@ gushort wxColourRefData::colMapAllocCounter[ 256 ] =
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
wxColourRefData::wxColourRefData()
|
||||
{
|
||||
m_color.red = 0;
|
||||
m_color.green = 0;
|
||||
m_color.blue = 0;
|
||||
m_color.pixel = 0;
|
||||
m_colormap = (GdkColormap *) NULL;
|
||||
m_hasPixel = FALSE;
|
||||
}
|
||||
|
||||
wxColourRefData::~wxColourRefData()
|
||||
{
|
||||
FreeColour();
|
||||
}
|
||||
|
||||
void wxColourRefData::FreeColour()
|
||||
{
|
||||
if (m_colormap)
|
||||
@@ -131,10 +137,6 @@ void wxColourRefData::AllocColour( GdkColormap *cmap )
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
|
||||
|
||||
wxColour::wxColour()
|
||||
{
|
||||
}
|
||||
|
||||
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
|
||||
{
|
||||
m_refData = new wxColourRefData();
|
||||
@@ -173,28 +175,15 @@ void wxColour::InitFromName( const wxString &colourName )
|
||||
}
|
||||
}
|
||||
|
||||
wxColour::wxColour( const wxColour& col )
|
||||
{
|
||||
Ref( col );
|
||||
}
|
||||
|
||||
wxColour::~wxColour()
|
||||
{
|
||||
}
|
||||
|
||||
wxColour& wxColour::operator = ( const wxColour& col )
|
||||
{
|
||||
if (*this == col) return (*this);
|
||||
Ref( col );
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxColour::operator == ( const wxColour& col ) const
|
||||
{
|
||||
if (m_refData == col.m_refData) return TRUE;
|
||||
|
||||
if (!m_refData) return FALSE;
|
||||
if (!col.m_refData) return FALSE;
|
||||
if (!m_refData || !col.m_refData) return FALSE;
|
||||
|
||||
GdkColor *own = &(((wxColourRefData*)m_refData)->m_color);
|
||||
GdkColor *other = &(((wxColourRefData*)col.m_refData)->m_color);
|
||||
@@ -205,14 +194,20 @@ bool wxColour::operator == ( const wxColour& col ) const
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxColour::operator != ( const wxColour& col) const
|
||||
wxObjectRefData *wxColour::CreateRefData() const
|
||||
{
|
||||
return !(*this == col);
|
||||
return new wxColourRefData;
|
||||
}
|
||||
|
||||
wxObjectRefData *wxColour::CloneRefData(const wxObjectRefData *data) const
|
||||
{
|
||||
return new wxColourRefData(*(wxColourRefData *)data);
|
||||
}
|
||||
|
||||
void wxColour::Set( unsigned char red, unsigned char green, unsigned char blue )
|
||||
{
|
||||
UnRef();
|
||||
AllocExclusive();
|
||||
|
||||
m_refData = new wxColourRefData();
|
||||
M_COLDATA->m_color.red = ((unsigned short)red) << SHIFT;
|
||||
M_COLDATA->m_color.green = ((unsigned short)green) << SHIFT;
|
||||
@@ -241,11 +236,6 @@ unsigned char wxColour::Blue() const
|
||||
return (unsigned char)(M_COLDATA->m_color.blue >> SHIFT);
|
||||
}
|
||||
|
||||
bool wxColour::Ok() const
|
||||
{
|
||||
return (m_refData != NULL);
|
||||
}
|
||||
|
||||
void wxColour::CalcPixel( GdkColormap *cmap )
|
||||
{
|
||||
if (!Ok()) return;
|
||||
|
146
src/gtk1/pen.cpp
146
src/gtk1/pen.cpp
@@ -23,43 +23,48 @@
|
||||
class wxPenRefData: public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
|
||||
wxPenRefData();
|
||||
wxPenRefData( const wxPenRefData& data );
|
||||
|
||||
int m_width;
|
||||
int m_style;
|
||||
int m_joinStyle;
|
||||
int m_capStyle;
|
||||
wxColour m_colour;
|
||||
int m_countDashes;
|
||||
wxGTKDash *m_dash;
|
||||
};
|
||||
|
||||
wxPenRefData::wxPenRefData()
|
||||
{
|
||||
m_width = 1;
|
||||
m_style = wxSOLID;
|
||||
m_joinStyle = wxJOIN_ROUND;
|
||||
m_capStyle = wxCAP_ROUND;
|
||||
m_dash = (wxGTKDash*) NULL;
|
||||
m_countDashes = 0;
|
||||
}
|
||||
|
||||
wxPenRefData::wxPenRefData( const wxPenRefData& data )
|
||||
{
|
||||
m_style = data.m_style;
|
||||
m_width = data.m_width;
|
||||
m_joinStyle = data.m_joinStyle;
|
||||
m_capStyle = data.m_capStyle;
|
||||
m_colour = data.m_colour;
|
||||
m_countDashes = data.m_countDashes;
|
||||
wxPenRefData()
|
||||
{
|
||||
m_width = 1;
|
||||
m_style = wxSOLID;
|
||||
m_joinStyle = wxJOIN_ROUND;
|
||||
m_capStyle = wxCAP_ROUND;
|
||||
m_dash = (wxGTKDash*) NULL;
|
||||
m_countDashes = 0;
|
||||
}
|
||||
|
||||
wxPenRefData( const wxPenRefData& data )
|
||||
{
|
||||
m_style = data.m_style;
|
||||
m_width = data.m_width;
|
||||
m_joinStyle = data.m_joinStyle;
|
||||
m_capStyle = data.m_capStyle;
|
||||
m_colour = data.m_colour;
|
||||
m_countDashes = data.m_countDashes;
|
||||
/*
|
||||
if (data.m_dash) TODO
|
||||
m_dash = new
|
||||
if (data.m_dash) TODO
|
||||
m_dash = new
|
||||
*/
|
||||
m_dash = data.m_dash;
|
||||
}
|
||||
m_dash = data.m_dash;
|
||||
}
|
||||
|
||||
bool operator == (const wxPenRefData& data) const
|
||||
{
|
||||
return (m_style == data.m_style &&
|
||||
m_width == data.m_width &&
|
||||
m_joinStyle == data.m_joinStyle &&
|
||||
m_capStyle == data.m_capStyle &&
|
||||
m_colour == data.m_colour);
|
||||
}
|
||||
|
||||
int m_width;
|
||||
int m_style;
|
||||
int m_joinStyle;
|
||||
int m_capStyle;
|
||||
wxColour m_colour;
|
||||
int m_countDashes;
|
||||
wxGTKDash *m_dash;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -67,10 +72,6 @@ wxPenRefData::wxPenRefData( const wxPenRefData& data )
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
|
||||
|
||||
wxPen::wxPen()
|
||||
{
|
||||
}
|
||||
|
||||
wxPen::wxPen( const wxColour &colour, int width, int style )
|
||||
{
|
||||
m_refData = new wxPenRefData();
|
||||
@@ -79,73 +80,77 @@ wxPen::wxPen( const wxColour &colour, int width, int style )
|
||||
M_PENDATA->m_colour = colour;
|
||||
}
|
||||
|
||||
wxPen::wxPen( const wxPen& pen )
|
||||
{
|
||||
Ref( pen );
|
||||
}
|
||||
|
||||
wxPen::~wxPen()
|
||||
{
|
||||
// m_refData unrefed in ~wxObject
|
||||
}
|
||||
|
||||
wxPen& wxPen::operator = ( const wxPen& pen )
|
||||
wxObjectRefData *wxPen::CreateRefData() const
|
||||
{
|
||||
if ( m_refData != pen.m_refData )
|
||||
Ref( pen );
|
||||
return new wxPenRefData;
|
||||
}
|
||||
|
||||
return *this;
|
||||
wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
|
||||
{
|
||||
return new wxPenRefData(*(wxPenRefData *)data);
|
||||
}
|
||||
|
||||
bool wxPen::operator == ( const wxPen& pen ) const
|
||||
{
|
||||
return m_refData == pen.m_refData;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
void wxPen::SetColour( const wxColour &colour )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_colour = colour;
|
||||
}
|
||||
|
||||
void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_countDashes = number_of_dashes;
|
||||
M_PENDATA->m_dash = (wxGTKDash *)dash; /* TODO */
|
||||
}
|
||||
|
||||
void wxPen::SetColour( int red, int green, int blue )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_colour.Set( red, green, blue );
|
||||
}
|
||||
|
||||
void wxPen::SetCap( int capStyle )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_capStyle = capStyle;
|
||||
}
|
||||
|
||||
void wxPen::SetJoin( int joinStyle )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_joinStyle = joinStyle;
|
||||
}
|
||||
|
||||
void wxPen::SetStyle( int style )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_style = style;
|
||||
}
|
||||
|
||||
void wxPen::SetWidth( int width )
|
||||
{
|
||||
Unshare();
|
||||
AllocExclusive();
|
||||
|
||||
M_PENDATA->m_width = width;
|
||||
}
|
||||
|
||||
@@ -200,22 +205,3 @@ wxColour &wxPen::GetColour() const
|
||||
return M_PENDATA->m_colour;
|
||||
}
|
||||
|
||||
bool wxPen::Ok() const
|
||||
{
|
||||
return (m_refData != NULL);
|
||||
}
|
||||
|
||||
void wxPen::Unshare()
|
||||
{
|
||||
if (!m_refData)
|
||||
{
|
||||
m_refData = new wxPenRefData();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
|
||||
UnRef();
|
||||
m_refData = ref;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -133,22 +133,22 @@ wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const
|
||||
{
|
||||
return new wxRegionRefData(*(wxRegionRefData *)data);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxRegion comparison
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxRegion::operator==( const wxRegion& region )
|
||||
{
|
||||
if (m_refData == region.m_refData) return TRUE;
|
||||
|
||||
if (!m_refData || !region.m_refData) return FALSE;
|
||||
|
||||
// compare the regions themselves, not the pointers to ref data!
|
||||
return gdk_region_equal(M_REGIONDATA->m_region,
|
||||
M_REGIONDATA_OF(region)->m_region);
|
||||
}
|
||||
|
||||
bool wxRegion::operator != ( const wxRegion& region )
|
||||
{
|
||||
return !(*this == region);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxRegion operations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -805,30 +805,6 @@ static int gtk_window_expose_callback( GtkWidget *widget,
|
||||
if (gdk_event->count == 0)
|
||||
win->GtkSendPaintEvents();
|
||||
|
||||
// The following code will result in all window-less widgets
|
||||
// being redrawn if the wxWindows class is given a chance to
|
||||
// paint *anything* because it will then be allowed to paint
|
||||
// over the window-less widgets.
|
||||
GList *children = pizza->children;
|
||||
while (children)
|
||||
{
|
||||
GtkPizzaChild *child = (GtkPizzaChild*) children->data;
|
||||
children = children->next;
|
||||
|
||||
GdkEventExpose child_event = *gdk_event;
|
||||
|
||||
if (GTK_WIDGET_NO_WINDOW (child->widget) &&
|
||||
GTK_WIDGET_DRAWABLE (child->widget) /* &&
|
||||
gtk_widget_intersect (child->widget, &gdk_event->area, &child_event.area)*/ )
|
||||
{
|
||||
child_event.area.x = child->widget->allocation.x;
|
||||
child_event.area.y = child->widget->allocation.y;
|
||||
child_event.area.width = child->widget->allocation.width;
|
||||
child_event.area.height = child->widget->allocation.height;
|
||||
gtk_widget_event (child->widget, (GdkEvent*) &child_event);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -3439,9 +3415,38 @@ void wxWindowGTK::GtkSendPaintEvents()
|
||||
paint_event.SetEventObject( this );
|
||||
GetEventHandler()->ProcessEvent( paint_event );
|
||||
|
||||
m_updateRegion.Clear();
|
||||
|
||||
m_clipPaintRegion = FALSE;
|
||||
|
||||
GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
|
||||
if (g_list_length(pizza->children) > 0)
|
||||
{
|
||||
// The following code will result in all window-less widgets
|
||||
// being redrawn because the wxWindows class is allowed to
|
||||
// paint over the window-less widgets.
|
||||
GList *children = pizza->children;
|
||||
while (children)
|
||||
{
|
||||
GtkPizzaChild *child = (GtkPizzaChild*) children->data;
|
||||
children = children->next;
|
||||
|
||||
if (GTK_WIDGET_NO_WINDOW (child->widget) &&
|
||||
GTK_WIDGET_DRAWABLE (child->widget))
|
||||
{
|
||||
// Get intersection of widget area and update region
|
||||
wxRegion region( m_updateRegion );
|
||||
region.Intersect( child->widget->allocation.x,
|
||||
child->widget->allocation.y,
|
||||
child->widget->allocation.width,
|
||||
child->widget->allocation.height );
|
||||
|
||||
// Redraw the whole widget anyway
|
||||
if (!region.IsEmpty())
|
||||
gtk_widget_draw( child->widget, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_updateRegion.Clear();
|
||||
}
|
||||
|
||||
void wxWindowGTK::Clear()
|
||||
|
Reference in New Issue
Block a user