applied fix for 8 bit displays (already in the 2.2 branch since almost a year)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -29,6 +29,7 @@ public:
|
||||
~wxColourRefData();
|
||||
|
||||
void FreeColour();
|
||||
void AllocColour( GdkColormap* cmap );
|
||||
|
||||
public:
|
||||
GdkColor m_color;
|
||||
@@ -36,6 +37,26 @@ public:
|
||||
bool m_hasPixel;
|
||||
|
||||
friend class wxColour;
|
||||
|
||||
// reference counter for systems with <= 8-Bit display
|
||||
static gushort colMapAllocCounter[ 256 ];
|
||||
};
|
||||
|
||||
gushort wxColourRefData::colMapAllocCounter[ 256 ] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
wxColourRefData::wxColourRefData()
|
||||
@@ -66,13 +87,42 @@ void wxColourRefData::FreeColour()
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
// What happens if the colour has not been allocated
|
||||
// anew but has been found? RR.
|
||||
int idx = m_color.pixel;
|
||||
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
|
||||
|
||||
if (colMapAllocCounter[ idx ] == 0)
|
||||
gdk_colormap_free_colors( m_colormap, &m_color, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxColourRefData::AllocColour( GdkColormap *cmap )
|
||||
{
|
||||
if (m_hasPixel && (m_colormap == cmap))
|
||||
return;
|
||||
|
||||
FreeColour();
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#else
|
||||
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
|
||||
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
m_hasPixel = gdk_colormap_alloc_color( cmap, &m_color, FALSE, TRUE );
|
||||
int idx = m_color.pixel;
|
||||
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hasPixel = gdk_color_alloc( cmap, &m_color );
|
||||
}
|
||||
m_colormap = cmap;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define M_COLDATA ((wxColourRefData *)m_refData)
|
||||
@@ -83,6 +133,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
|
||||
|
||||
wxColour::wxColour()
|
||||
{
|
||||
m_refData = new wxColourRefData();
|
||||
}
|
||||
|
||||
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
|
||||
@@ -200,27 +251,7 @@ void wxColour::CalcPixel( GdkColormap *cmap )
|
||||
{
|
||||
if (!Ok()) return;
|
||||
|
||||
if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return;
|
||||
|
||||
M_COLDATA->FreeColour();
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
if ((cmap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(cmap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#else
|
||||
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
|
||||
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
|
||||
}
|
||||
|
||||
M_COLDATA->m_colormap = cmap;
|
||||
M_COLDATA->AllocColour( cmap );
|
||||
}
|
||||
|
||||
int wxColour::GetPixel() const
|
||||
|
@@ -29,6 +29,7 @@ public:
|
||||
~wxColourRefData();
|
||||
|
||||
void FreeColour();
|
||||
void AllocColour( GdkColormap* cmap );
|
||||
|
||||
public:
|
||||
GdkColor m_color;
|
||||
@@ -36,6 +37,26 @@ public:
|
||||
bool m_hasPixel;
|
||||
|
||||
friend class wxColour;
|
||||
|
||||
// reference counter for systems with <= 8-Bit display
|
||||
static gushort colMapAllocCounter[ 256 ];
|
||||
};
|
||||
|
||||
gushort wxColourRefData::colMapAllocCounter[ 256 ] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
wxColourRefData::wxColourRefData()
|
||||
@@ -66,13 +87,42 @@ void wxColourRefData::FreeColour()
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
// What happens if the colour has not been allocated
|
||||
// anew but has been found? RR.
|
||||
int idx = m_color.pixel;
|
||||
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
|
||||
|
||||
if (colMapAllocCounter[ idx ] == 0)
|
||||
gdk_colormap_free_colors( m_colormap, &m_color, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxColourRefData::AllocColour( GdkColormap *cmap )
|
||||
{
|
||||
if (m_hasPixel && (m_colormap == cmap))
|
||||
return;
|
||||
|
||||
FreeColour();
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#else
|
||||
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
|
||||
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
m_hasPixel = gdk_colormap_alloc_color( cmap, &m_color, FALSE, TRUE );
|
||||
int idx = m_color.pixel;
|
||||
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hasPixel = gdk_color_alloc( cmap, &m_color );
|
||||
}
|
||||
m_colormap = cmap;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define M_COLDATA ((wxColourRefData *)m_refData)
|
||||
@@ -83,6 +133,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
|
||||
|
||||
wxColour::wxColour()
|
||||
{
|
||||
m_refData = new wxColourRefData();
|
||||
}
|
||||
|
||||
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
|
||||
@@ -200,27 +251,7 @@ void wxColour::CalcPixel( GdkColormap *cmap )
|
||||
{
|
||||
if (!Ok()) return;
|
||||
|
||||
if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return;
|
||||
|
||||
M_COLDATA->FreeColour();
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
if ((cmap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(cmap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#else
|
||||
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
|
||||
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
|
||||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
|
||||
#endif
|
||||
{
|
||||
M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
|
||||
}
|
||||
|
||||
M_COLDATA->m_colormap = cmap;
|
||||
M_COLDATA->AllocColour( cmap );
|
||||
}
|
||||
|
||||
int wxColour::GetPixel() const
|
||||
|
Reference in New Issue
Block a user