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:
// ctors
// default
wxColour();
wxColour() { Init(); }
// 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 )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ Set(colRGB); }
// implicit conversion from the colour name
wxColour( const wxString &colourName )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ InitFromName(colourName); }
wxColour( const wxChar *colourName )
: m_isInit(FALSE), m_red(0), m_blue(0), m_green(0)
{ InitFromName(colourName); }
// copy ctors and assignment operators
@ -86,6 +84,8 @@ private:
unsigned char m_blue;
unsigned char m_green;
void Init();
public:
WXCOLORREF m_pixel ;
void Set( const WXCOLORREF* color ) ;

View File

@ -25,7 +25,8 @@ public:
// default
wxColour();
// 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); }
// implicit conversion from the colour name
@ -74,7 +75,8 @@ private:
unsigned char m_blue;
unsigned char m_green;
// helper func
// ctors helpers
void Init();
void InitFromName(const wxString& colourName);
private:

View File

@ -28,7 +28,8 @@ public:
// default
wxColour();
// 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); }
// implicit conversion from the colour name

View File

@ -53,6 +53,9 @@ public:
wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); }
#endif
// Get colour from name or wxNullColour
static wxColour CreateByName(const wxString& name);
wxColour( const wxColour& col ) { Ref(col); }
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++)
{
wxColour *col = wxTheColourDatabase->FindColour(wxColourDialogNames[i]);
if (col)
standardColours[i].Set(col->Red(), col->Green(), col->Blue());
wxColour col = wxTheColourDatabase->Find(wxColourDialogNames[i]);
if (col.Ok())
standardColours[i].Set(col.Red(), col.Green(), col.Blue());
else
standardColours[i].Set(0, 0, 0);
}
for (i = 0; i < 16; i++)
for (i = 0; i < WXSIZEOF(customColours); i++)
{
customColours[i] = colourData.GetCustomColour(i);
}
@ -333,7 +333,7 @@ void wxGenericColourDialog::InitializeColours(void)
}
if ( !initColourFound )
{
for ( i = 0; i < 16; i++ )
for ( i = 0; i < WXSIZEOF(customColours); i++ )
{
if ( customColours[i] == curr )
{

View File

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

View File

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

View File

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

View File

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

View File

@ -130,15 +130,12 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour)
{
float r = 0.0;
float g = 0.0;
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
wxColour col = wxTheColourDatabase->Find(colour);
if (col.Ok())
{
r = (float)(col->Red()/256.0);
g = (float)(col->Green()/256.0);
b = (float)(col->Blue()/256.0);
float r = (float)(col.Red()/256.0);
float g = (float)(col.Green()/256.0);
float b = (float)(col.Blue()/256.0);
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;
}
wxColour::wxColour ()
void wxColour::Init()
{
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 ) ;
}
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)
: wxObject()
{
@ -84,25 +76,17 @@ wxColour& wxColour::operator =(const wxColour& col)
return *this;
}
void wxColour::InitFromName(const wxString& col)
void wxColour::InitFromName(const wxString& name)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (col);
if (the_colour)
wxColour col = wxTheColourDatabase->Find(name);
if ( col.Ok() )
{
m_red = the_colour->Red ();
m_green = the_colour->Green ();
m_blue = the_colour->Blue ();
m_isInit = TRUE;
*this = col;
}
else
{
m_red = 0;
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
Init();
}
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
wxColour::~wxColour ()

View File

@ -97,15 +97,12 @@ void wxGLContext::Update()
void wxGLContext::SetColour(const wxChar *colour)
{
float r = 0.0;
float g = 0.0;
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
wxColour col = wxTheColourDatabase->Find(colour);
if (col.Ok())
{
r = (float)(col->Red()/256.0);
g = (float)(col->Green()/256.0);
b = (float)(col->Blue()/256.0);
float r = (float)(col.Red()/256.0);
float g = (float)(col.Green()/256.0);
float b = (float)(col.Blue()/256.0);
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;
}
wxColour::wxColour ()
void wxColour::Init()
{
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 ) ;
}
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)
: wxObject()
{
@ -84,25 +76,17 @@ wxColour& wxColour::operator =(const wxColour& col)
return *this;
}
void wxColour::InitFromName(const wxString& col)
void wxColour::InitFromName(const wxString& name)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (col);
if (the_colour)
wxColour col = wxTheColourDatabase->Find(name);
if ( col.Ok() )
{
m_red = the_colour->Red ();
m_green = the_colour->Green ();
m_blue = the_colour->Blue ();
m_isInit = TRUE;
*this = col;
}
else
{
m_red = 0;
m_green = 0;
m_blue = 0;
m_isInit = FALSE;
Init();
}
wxComposeRGBColor( &m_pixel , m_red , m_blue , m_green ) ;
}
wxColour::~wxColour ()

View File

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

View File

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

View File

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

View File

@ -134,17 +134,14 @@ void wxGLContext::SetCurrent()
void wxGLContext::SetColour(const wxChar *colour)
{
float r = 0.0;
float g = 0.0;
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{
r = (float)(col->Red()/256.0);
g = (float)(col->Green()/256.0);
b = (float)(col->Blue()/256.0);
glColor3f( r, g, b);
}
wxColour col = wxTheColourDatabase->Find(colour);
if (col.Ok())
{
float r = (float)(col.Red()/256.0);
float g = (float)(col.Green()/256.0);
float 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;
}
/* 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 )
{
wxColour* col;
if ( (wxTheColourDatabase) && (col = wxTheColourDatabase->FindColourNoAdd(colourName)) )
// check the cache first
wxColour col;
if ( wxTheColourDatabase )
{
UnRef();
if (col) Ref( *col );
col = wxTheColourDatabase->Find(colourName);
}
if ( !col.Ok() )
{
col = CreateByName(colourName);
}
if ( col.Ok() )
{
*this = col;
}
else
{
m_refData = new wxColourRefData();
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;
}
wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
}
}

View File

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