replaced all occurences of wxColourDatabase::FindColour() with Find(); minor code cleanup here and there

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24231 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-10-18 23:51:01 +00:00
parent 5d398dbae0
commit 564a150b1f
19 changed files with 158 additions and 223 deletions

View File

@@ -25,19 +25,17 @@ class WXDLLEXPORT wxColour: public wxObject
public: public:
// ctors // ctors
// default // default
wxColour(); wxColour() { Init(); }
// from RGB // from RGB
wxColour( unsigned char red, unsigned char green, unsigned char blue ); wxColour( unsigned char red, unsigned char green, unsigned char blue )
{ Set(red, green, blue); }
wxColour( unsigned long colRGB ) wxColour( unsigned long colRGB )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ Set(colRGB); } { Set(colRGB); }
// implicit conversion from the colour name // implicit conversion from the colour name
wxColour( const wxString &colourName ) wxColour( const wxString &colourName )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ InitFromName(colourName); } { InitFromName(colourName); }
wxColour( const wxChar *colourName ) wxColour( const wxChar *colourName )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ InitFromName(colourName); } { InitFromName(colourName); }
// copy ctors and assignment operators // copy ctors and assignment operators
@@ -86,6 +84,8 @@ private:
unsigned char m_blue; unsigned char m_blue;
unsigned char m_green; unsigned char m_green;
void Init();
public: public:
WXCOLORREF m_pixel ; WXCOLORREF m_pixel ;
void Set( const WXCOLORREF* color ) ; void Set( const WXCOLORREF* color ) ;

View File

@@ -25,7 +25,8 @@ public:
// default // default
wxColour(); wxColour();
// from RGB // from RGB
wxColour(unsigned char red, unsigned char green, unsigned char blue); wxColour(unsigned char red, unsigned char green, unsigned char blue)
{ Set(red, green, blue); }
wxColour(unsigned long colRGB) { Set(colRGB); } wxColour(unsigned long colRGB) { Set(colRGB); }
// implicit conversion from the colour name // implicit conversion from the colour name
@@ -74,7 +75,8 @@ private:
unsigned char m_blue; unsigned char m_blue;
unsigned char m_green; unsigned char m_green;
// helper func // ctors helpers
void Init();
void InitFromName(const wxString& colourName); void InitFromName(const wxString& colourName);
private: private:

View File

@@ -28,7 +28,8 @@ public:
// default // default
wxColour(); wxColour();
// from RGB // from RGB
wxColour( unsigned char red, unsigned char green, unsigned char blue ); wxColour( unsigned char red, unsigned char green, unsigned char blue )
{ Set(red, green, blue); }
wxColour( unsigned long colRGB ) { Set(colRGB); } wxColour( unsigned long colRGB ) { Set(colRGB); }
// implicit conversion from the colour name // implicit conversion from the colour name

View File

@@ -53,6 +53,9 @@ public:
wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); } wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); }
#endif #endif
// Get colour from name or wxNullColour
static wxColour CreateByName(const wxString& name);
wxColour( const wxColour& col ) { Ref(col); } wxColour( const wxColour& col ) { Ref(col); }
wxColour& operator = ( const wxColour& col ) { Ref(col); return *this; } wxColour& operator = ( const wxColour& col ) { Ref(col); return *this; }

View File

@@ -304,14 +304,14 @@ void wxGenericColourDialog::InitializeColours(void)
for (i = 0; i < WXSIZEOF(wxColourDialogNames); i++) for (i = 0; i < WXSIZEOF(wxColourDialogNames); i++)
{ {
wxColour *col = wxTheColourDatabase->FindColour(wxColourDialogNames[i]); wxColour col = wxTheColourDatabase->Find(wxColourDialogNames[i]);
if (col) if (col.Ok())
standardColours[i].Set(col->Red(), col->Green(), col->Blue()); standardColours[i].Set(col.Red(), col.Green(), col.Blue());
else else
standardColours[i].Set(0, 0, 0); standardColours[i].Set(0, 0, 0);
} }
for (i = 0; i < 16; i++) for (i = 0; i < WXSIZEOF(customColours); i++)
{ {
customColours[i] = colourData.GetCustomColour(i); customColours[i] = colourData.GetCustomColour(i);
} }
@@ -333,7 +333,7 @@ void wxGenericColourDialog::InitializeColours(void)
} }
if ( !initColourFound ) if ( !initColourFound )
{ {
for ( i = 0; i < 16; i++ ) for ( i = 0; i < WXSIZEOF(customColours); i++ )
{ {
if ( customColours[i] == curr ) if ( customColours[i] == curr )
{ {

View File

@@ -343,8 +343,9 @@ void wxFileData::MakeItem( wxListItem &item )
if (IsLink()) if (IsLink())
{ {
wxColour *dg = wxTheColourDatabase->FindColour( _T("MEDIUM GREY") ); wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") );
item.SetTextColour(*dg); if ( dg.Ok() )
item.SetTextColour(dg);
} }
item.m_data = (long)this; item.m_data = (long)this;
} }

View File

@@ -339,11 +339,11 @@ void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
m_previewer->SetFont(dialogFont); m_previewer->SetFont(dialogFont);
if (colourChoice->GetStringSelection() != wxT("")) if (colourChoice->GetStringSelection() != wxT(""))
{ {
wxColour *col = wxTheColourDatabase->FindColour(colourChoice->GetStringSelection()); wxColour col = wxTheColourDatabase->Find(colourChoice->GetStringSelection());
if (col) if (col.Ok())
{ {
m_fontData.m_fontColour = *col; m_fontData.m_fontColour = col;
m_previewer->SetForegroundColour(*col); m_previewer->SetForegroundColour(col);
} }
} }
m_previewer->Refresh(); m_previewer->Refresh();

View File

@@ -677,11 +677,11 @@ void wxSashWindow::InitColours()
m_lightShadowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); m_lightShadowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
m_hilightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT); m_hilightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT);
#else #else
m_faceColour = *(wxTheColourDatabase->FindColour("LIGHT GREY")); m_faceColour = wxTheColourDatabase->Find("LIGHT GREY");
m_mediumShadowColour = *(wxTheColourDatabase->FindColour("GREY")); m_mediumShadowColour = wxTheColourDatabase->Find("GREY");
m_darkShadowColour = *(wxTheColourDatabase->FindColour("BLACK")); m_darkShadowColour = wxTheColourDatabase->Find("BLACK");
m_lightShadowColour = *(wxTheColourDatabase->FindColour("LIGHT GREY")); m_lightShadowColour = wxTheColourDatabase->Find("LIGHT GREY");
m_hilightColour = *(wxTheColourDatabase->FindColour("WHITE")); m_hilightColour = wxTheColourDatabase->Find("WHITE");
#endif #endif
} }

View File

@@ -130,15 +130,12 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
float r = 0.0; wxColour col = wxTheColourDatabase->Find(colour);
float g = 0.0; if (col.Ok())
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{ {
r = (float)(col->Red()/256.0); float r = (float)(col.Red()/256.0);
g = (float)(col->Green()/256.0); float g = (float)(col.Green()/256.0);
b = (float)(col->Blue()/256.0); float b = (float)(col.Blue()/256.0);
glColor3f( r, g, b); glColor3f( r, g, b);
} }
} }

View File

@@ -130,15 +130,12 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
float r = 0.0; wxColour col = wxTheColourDatabase->Find(colour);
float g = 0.0; if (col.Ok())
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{ {
r = (float)(col->Red()/256.0); float r = (float)(col.Red()/256.0);
g = (float)(col->Green()/256.0); float g = (float)(col.Green()/256.0);
b = (float)(col->Blue()/256.0); float b = (float)(col.Blue()/256.0);
glColor3f( r, g, b); glColor3f( r, g, b);
} }
} }

View File

@@ -33,24 +33,16 @@ static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green
col->green = (green << 8) + green; col->green = (green << 8) + green;
} }
wxColour::wxColour () void wxColour::Init()
{ {
m_isInit = FALSE; m_isInit = FALSE;
m_red = m_blue = m_green = 0; m_red =
m_blue =
m_green = 0;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ; wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
} }
wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
wxColour::wxColour (const wxColour& col) wxColour::wxColour (const wxColour& col)
: wxObject() : wxObject()
{ {
@@ -84,25 +76,17 @@ wxColour& wxColour::operator =(const wxColour& col)
return *this; return *this;
} }
void wxColour::InitFromName(const wxString& col) void wxColour::InitFromName(const wxString& name)
{ {
wxColour *the_colour = wxTheColourDatabase->FindColour (col); wxColour col = wxTheColourDatabase->Find(name);
if (the_colour) if ( col.Ok() )
{ {
m_red = the_colour->Red (); *this = col;
m_green = the_colour->Green ();
m_blue = the_colour->Blue ();
m_isInit = TRUE;
} }
else else
{ {
m_red = 0; Init();
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
} }
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
} }
wxColour::~wxColour () wxColour::~wxColour ()

View File

@@ -97,15 +97,12 @@ void wxGLContext::Update()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
float r = 0.0; wxColour col = wxTheColourDatabase->Find(colour);
float g = 0.0; if (col.Ok())
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{ {
r = (float)(col->Red()/256.0); float r = (float)(col.Red()/256.0);
g = (float)(col->Green()/256.0); float g = (float)(col.Green()/256.0);
b = (float)(col->Blue()/256.0); float b = (float)(col.Blue()/256.0);
glColor3f( r, g, b); glColor3f( r, g, b);
} }
} }

View File

@@ -33,24 +33,16 @@ static void wxComposeRGBColor( WXCOLORREF* color , int red, int blue, int green
col->green = (green << 8) + green; col->green = (green << 8) + green;
} }
wxColour::wxColour () void wxColour::Init()
{ {
m_isInit = FALSE; m_isInit = FALSE;
m_red = m_blue = m_green = 0; m_red =
m_blue =
m_green = 0;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ; wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
} }
wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
wxColour::wxColour (const wxColour& col) wxColour::wxColour (const wxColour& col)
: wxObject() : wxObject()
{ {
@@ -84,25 +76,17 @@ wxColour& wxColour::operator =(const wxColour& col)
return *this; return *this;
} }
void wxColour::InitFromName(const wxString& col) void wxColour::InitFromName(const wxString& name)
{ {
wxColour *the_colour = wxTheColourDatabase->FindColour (col); wxColour col = wxTheColourDatabase->Find(name);
if (the_colour) if ( col.Ok() )
{ {
m_red = the_colour->Red (); *this = col;
m_green = the_colour->Green ();
m_blue = the_colour->Blue ();
m_isInit = TRUE;
} }
else else
{ {
m_red = 0; Init();
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
} }
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
} }
wxColour::~wxColour () wxColour::~wxColour ()

View File

@@ -97,15 +97,12 @@ void wxGLContext::Update()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
float r = 0.0; wxColour col = wxTheColourDatabase->Find(colour);
float g = 0.0; if (col.Ok())
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{ {
r = (float)(col->Red()/256.0); float r = (float)(col.Red()/256.0);
g = (float)(col->Green()/256.0); float g = (float)(col.Green()/256.0);
b = (float)(col->Blue()/256.0); float b = (float)(col.Blue()/256.0);
glColor3f( r, g, b); glColor3f( r, g, b);
} }
} }

View File

@@ -27,53 +27,38 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
// Colour // Colour
wxColour::wxColour() void wxColour::Init()
{ {
m_red = m_blue = m_green = 0; m_red =
m_isInit = FALSE; m_blue =
} m_green = 0;
m_isInit = FALSE;
wxColour::wxColour(unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
} }
wxColour::wxColour(const wxColour& col) wxColour::wxColour(const wxColour& col)
{ {
m_red = col.m_red; *this = col;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
} }
wxColour& wxColour::operator =(const wxColour& col) wxColour& wxColour::operator =(const wxColour& col)
{ {
m_red = col.m_red; m_red = col.m_red;
m_green = col.m_green; m_green = col.m_green;
m_blue = col.m_blue; m_blue = col.m_blue;
m_isInit = col.m_isInit; m_isInit = col.m_isInit;
return *this; return *this;
} }
void wxColour::InitFromName(const wxString& col) void wxColour::InitFromName(const wxString& name)
{ {
wxColour *the_colour = wxTheColourDatabase->FindColour (col); wxColour *col = wxTheColourDatabase->Find(name);
if (the_colour) if ( col.Ok() )
{ {
m_red = the_colour->Red(); *this = col;
m_green = the_colour->Green();
m_blue = the_colour->Blue();
m_isInit = TRUE;
} }
else else
{ {
m_red = 0; Init();
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
} }
} }
@@ -83,8 +68,8 @@ wxColour::~wxColour()
void wxColour::Set(unsigned char r, unsigned char g, unsigned char b) void wxColour::Set(unsigned char r, unsigned char g, unsigned char b)
{ {
m_red = r; m_red = r;
m_green = g; m_green = g;
m_blue = b; m_blue = b;
m_isInit = TRUE; m_isInit = TRUE;
} }

View File

@@ -37,26 +37,15 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
wxColour::wxColour () wxColour::wxColour ()
{ {
m_isInit = FALSE; m_isInit = FALSE;
m_red = m_blue = m_green = 0; m_red =
m_pixel = -1; m_blue =
} m_green = 0;
wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
m_pixel = -1; m_pixel = -1;
} }
wxColour::wxColour (const wxColour& col) wxColour::wxColour (const wxColour& col)
{ {
m_red = col.m_red; *this = col;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
m_pixel = col.m_pixel;
} }
wxColour& wxColour::operator =(const wxColour& col) wxColour& wxColour::operator =(const wxColour& col)
@@ -69,24 +58,9 @@ wxColour& wxColour::operator =(const wxColour& col)
return *this; return *this;
} }
void wxColour::InitFromName(const wxString& col) void wxColour::InitFromName(const wxString& name)
{ {
wxColour *the_colour = wxTheColourDatabase->FindColour (col); *this = wxTheColourDatabase->Find(name);
if (the_colour)
{
m_red = the_colour->Red ();
m_green = the_colour->Green ();
m_blue = the_colour->Blue ();
m_pixel = the_colour->m_pixel;
m_isInit = TRUE;
}
else
{
m_red = 0;
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
}
} }
wxColour::~wxColour () wxColour::~wxColour ()

View File

@@ -134,17 +134,14 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
float r = 0.0; wxColour col = wxTheColourDatabase->Find(colour);
float g = 0.0; if (col.Ok())
float b = 0.0; {
wxColour *col = wxTheColourDatabase->FindColour(colour); float r = (float)(col.Red()/256.0);
if (col) float g = (float)(col.Green()/256.0);
{ float b = (float)(col.Blue()/256.0);
r = (float)(col->Red()/256.0); glColor3f( r, g, b);
g = (float)(col->Green()/256.0); }
b = (float)(col->Blue()/256.0);
glColor3f( r, g, b);
}
} }

View File

@@ -155,34 +155,46 @@ wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
M_COLDATA->m_color.pixel = 0; M_COLDATA->m_color.pixel = 0;
} }
/* static */
wxColour wxColour::CreateByName(const wxString& name)
{
wxColour col;
Display *dpy = wxGlobalDisplay();
WXColormap colormap = wxTheApp->GetMainColormap( dpy );
XColor xcol;
if ( XParseColor( dpy, (Colormap)colormap, name.mb_str(), &xcol ) )
{
wxColourRefData *refData = new wxColourRefData;
refData->m_colormap = colormap;
refData->m_color = xcol;
col.m_refData = refData;
}
return col;
}
void wxColour::InitFromName( const wxString &colourName ) void wxColour::InitFromName( const wxString &colourName )
{ {
wxColour* col; // check the cache first
if ( (wxTheColourDatabase) && (col = wxTheColourDatabase->FindColourNoAdd(colourName)) ) wxColour col;
if ( wxTheColourDatabase )
{ {
UnRef(); col = wxTheColourDatabase->Find(colourName);
if (col) Ref( *col ); }
if ( !col.Ok() )
{
col = CreateByName(colourName);
}
if ( col.Ok() )
{
*this = col;
} }
else else
{ {
m_refData = new wxColourRefData(); wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
M_COLDATA->m_colormap = wxTheApp->GetMainColormap( wxGlobalDisplay() );
if (!XParseColor( wxGlobalDisplay(), (Colormap) M_COLDATA->m_colormap, colourName.mb_str(), &M_COLDATA->m_color ))
{
// VZ: asserts are good in general but this one is triggered by
// calling wxColourDatabase::FindColour() with an
// unrecognized colour name and this can't be avoided from the
// user code, so don't give it here
//
// a better solution would be to changed code in FindColour()
//wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
delete m_refData;
m_refData = (wxObjectRefData *) NULL;
}
} }
} }

View File

@@ -138,28 +138,32 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour) void wxGLContext::SetColour(const wxChar *colour)
{ {
wxColour *the_colour = wxTheColourDatabase->FindColour(colour); wxColour the_colour = wxTheColourDatabase->Find(colour);
if(the_colour) { if(the_colour.Ok())
GLboolean b; {
glGetBooleanv(GL_RGBA_MODE, &b); GLboolean b;
if(b) { glGetBooleanv(GL_RGBA_MODE, &b);
glColor3ub(the_colour->Red(), if(b)
the_colour->Green(), {
the_colour->Blue()); glColor3ub(the_colour.Red(),
} else { the_colour.Green(),
the_colour.Blue());
}
else
{
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
the_colour->AllocColour(m_window->GetXDisplay()); the_colour.AllocColour(m_window->GetXDisplay());
#else #else
the_colour->CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay())); the_colour.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
#endif #endif
GLint pix = (GLint)the_colour->GetPixel(); GLint pix = (GLint)the_colour.GetPixel();
if(pix == -1) if(pix == -1)
{ {
wxLogError(wxT("wxGLCanvas: cannot allocate color\n")); wxLogError(wxT("wxGLCanvas: cannot allocate color\n"));
return; return;
} }
glIndexi(pix); glIndexi(pix);
} }
} }
} }