use wxString instead of wxChar* in wxColour::Set/FromString

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46239 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-05-30 10:29:12 +00:00
parent 092793cb6d
commit e86d4e59c1
9 changed files with 15 additions and 23 deletions

View File

@@ -36,7 +36,6 @@ public:
{ Init(); Set(red, green, blue, alpha); }
wxColour(unsigned long colRGB) { Init(); Set(colRGB); }
wxColour(const wxString& colourName) { Init(); Set(colourName); }
wxColour(const wxChar *colourName) { Init(); Set(colourName); }
// initialization using existing NSColor
wxColour( WX_NSColor aColor );
@@ -80,9 +79,6 @@ public:
unsigned char alpha = wxALPHA_OPAQUE)
{ wxColourBase::Set(red, green, blue, alpha); }
bool Set(const wxChar *str)
{ return wxColourBase::Set(str); }
bool Set(const wxString &str)
{ return wxColourBase::Set(str); }

View File

@@ -27,8 +27,7 @@ class WXDLLEXPORT wxColour;
ChannelType alpha = wxALPHA_OPAQUE ) \
{ Set(red, green, blue, alpha); } \
wxColour( unsigned long colRGB ) { Set(colRGB); } \
wxColour(const wxString &colourName) { Set(colourName); } \
wxColour(const wxChar *colourName) { Set(colourName); }
wxColour(const wxString& colourName) { Set(colourName); }
// flags for wxColour -> wxString conversion (see wxColour::GetAsString)
@@ -74,9 +73,6 @@ public:
{ InitRGBA(red,green,blue, alpha); }
// implemented in colourcmn.cpp
bool Set(const wxChar *str)
{ return FromString(str); }
bool Set(const wxString &str)
{ return FromString(str); }
@@ -120,7 +116,7 @@ protected:
virtual void
InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
virtual bool FromString(const wxChar *s);
virtual bool FromString(const wxString& s);
};

View File

@@ -53,7 +53,7 @@ protected:
virtual void
InitRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
virtual bool FromString(const wxChar *str);
virtual bool FromString(const wxString& str);
private:
DECLARE_DYNAMIC_CLASS(wxColour)

View File

@@ -43,7 +43,7 @@ public:
virtual ~wxColour();
virtual bool FromString(const wxChar *str);
virtual bool FromString(const wxString& str);
bool Ok() const { return IsOk(); }
bool IsOk() const { return m_refData != NULL; }

View File

@@ -68,7 +68,7 @@ protected:
virtual void
InitRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
virtual bool FromString(const wxChar *str);
virtual bool FromString(const wxString& str);
private:
DECLARE_DYNAMIC_CLASS(wxColour)

View File

@@ -34,9 +34,9 @@ IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
// wxString <-> wxColour conversions
// ============================================================================
bool wxColourBase::FromString(const wxChar *str)
bool wxColourBase::FromString(const wxString& str)
{
if ( str == NULL || str[0] == wxT('\0'))
if ( str.empty() )
return false; // invalid or empty string
if ( wxStrncmp(str, wxT("RGB"), 3) == 0 ||
@@ -46,7 +46,7 @@ bool wxColourBase::FromString(const wxChar *str)
// according to http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
// values outside 0-255 range are allowed but should be clipped
int red, green, blue;
if (wxSscanf(&str[3], wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
if (wxSscanf(str.substr(3), wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
return false;
Set((unsigned char)wxClip(red,0,255),
@@ -57,7 +57,7 @@ bool wxColourBase::FromString(const wxChar *str)
{
// hexadecimal prefixed with # (HTML syntax)
unsigned long tmp;
if (wxSscanf(&str[1], wxT("%lx"), &tmp) != 1)
if (wxSscanf(str.substr(1), wxT("%lx"), &tmp) != 1)
return false;
Set((unsigned char)(tmp >> 16),

View File

@@ -180,7 +180,7 @@ const GdkColor *wxColour::GetColor() const
return &M_COLDATA->m_color;
}
bool wxColour::FromString(const wxChar *str)
bool wxColour::FromString(const wxString& str)
{
GdkColor colGDK;
if ( gdk_color_parse( wxGTK_CONV_SYS( str ), &colGDK ) )

View File

@@ -225,10 +225,10 @@ GdkColor *wxColour::GetColor() const
return &M_COLDATA->m_color;
}
bool wxColour::FromString(const wxChar *str)
bool wxColour::FromString(const wxString& str)
{
GdkColor colGDK;
if ( gdk_color_parse( str, &colGDK ) )
if ( gdk_color_parse( wxGTK_CONV(str), &colGDK ) )
{
UnRef();

View File

@@ -245,12 +245,12 @@ WXColor *wxColour::GetColor() const
return (WXColor*) &M_COLDATA->m_color;
}
bool wxColour::FromString(const wxChar *name)
bool wxColour::FromString(const wxString& name)
{
Display *dpy = wxGlobalDisplay();
WXColormap colormap = wxTheApp->GetMainColormap( dpy );
XColor xcol;
if ( XParseColor( dpy, (Colormap)colormap, wxConvertWX2MB(name), &xcol ) )
if ( XParseColor( dpy, (Colormap)colormap, name.mbc_str(), &xcol ) )
{
UnRef();