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
unsigned char m_blue;
unsigned char m_green;
+ void Init();
+
public:
WXCOLORREF m_pixel ;
void Set( const WXCOLORREF* color ) ;
// 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
unsigned char m_blue;
unsigned char m_green;
- // helper func
+ // ctors helpers
+ void Init();
void InitFromName(const wxString& colourName);
private:
// 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
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; }
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);
}
}
if ( !initColourFound )
{
- for ( i = 0; i < 16; i++ )
+ for ( i = 0; i < WXSIZEOF(customColours); i++ )
{
if ( customColours[i] == curr )
{
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;
}
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();
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
}
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);
}
}
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);
}
}
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()
{
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 ()
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);
}
}
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()
{
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 ()
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);
}
}
// 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();
}
}
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;
}
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)
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 ()
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);
+ }
}
M_COLDATA->m_color.pixel = 0;
}
-void wxColour::InitFromName( const wxString &colourName )
+/* static */
+wxColour wxColour::CreateByName(const wxString& name)
{
- wxColour* col;
- if ( (wxTheColourDatabase) && (col = wxTheColourDatabase->FindColourNoAdd(colourName)) )
+ wxColour col;
+
+ Display *dpy = wxGlobalDisplay();
+ WXColormap colormap = wxTheApp->GetMainColormap( dpy );
+ XColor xcol;
+ if ( XParseColor( dpy, (Colormap)colormap, name.mb_str(), &xcol ) )
{
- UnRef();
- if (col) Ref( *col );
+ wxColourRefData *refData = new wxColourRefData;
+ refData->m_colormap = colormap;
+ refData->m_color = xcol;
+ col.m_refData = refData;
}
- else
+
+ return col;
+}
+
+void wxColour::InitFromName( const wxString &colourName )
+{
+ // check the cache first
+ wxColour col;
+ if ( wxTheColourDatabase )
{
- 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()
+ col = wxTheColourDatabase->Find(colourName);
+ }
- //wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
+ if ( !col.Ok() )
+ {
+ col = CreateByName(colourName);
+ }
- delete m_refData;
- m_refData = (wxObjectRefData *) NULL;
- }
+ if ( col.Ok() )
+ {
+ *this = col;
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
}
}
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);
+ }
}
}