From e86d4e59c10a8110a5bcf714bca17a8eea65e8b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 30 May 2007 10:29:12 +0000 Subject: [PATCH] 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 --- include/wx/cocoa/colour.h | 6 +----- include/wx/colour.h | 8 ++------ include/wx/gtk/colour.h | 2 +- include/wx/gtk1/colour.h | 2 +- include/wx/x11/colour.h | 2 +- src/common/colourcmn.cpp | 8 ++++---- src/gtk/colour.cpp | 2 +- src/gtk1/colour.cpp | 4 ++-- src/x11/colour.cpp | 4 ++-- 9 files changed, 15 insertions(+), 23 deletions(-) diff --git a/include/wx/cocoa/colour.h b/include/wx/cocoa/colour.h index c1bbc340ed..48986eb46e 100644 --- a/include/wx/cocoa/colour.h +++ b/include/wx/cocoa/colour.h @@ -35,8 +35,7 @@ public: ChannelType alpha = wxALPHA_OPAQUE ) { 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); } + wxColour(const wxString& 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); } diff --git a/include/wx/colour.h b/include/wx/colour.h index 20b673b39a..b66b9b3608 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -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); }; diff --git a/include/wx/gtk/colour.h b/include/wx/gtk/colour.h index 01b49c45aa..88ac82e688 100644 --- a/include/wx/gtk/colour.h +++ b/include/wx/gtk/colour.h @@ -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) diff --git a/include/wx/gtk1/colour.h b/include/wx/gtk1/colour.h index c5006cf4fb..5912a753b3 100644 --- a/include/wx/gtk1/colour.h +++ b/include/wx/gtk1/colour.h @@ -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; } diff --git a/include/wx/x11/colour.h b/include/wx/x11/colour.h index 101055920a..27e64ac622 100644 --- a/include/wx/x11/colour.h +++ b/include/wx/x11/colour.h @@ -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) diff --git a/src/common/colourcmn.cpp b/src/common/colourcmn.cpp index 3d401098e3..2edc343a47 100644 --- a/src/common/colourcmn.cpp +++ b/src/common/colourcmn.cpp @@ -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), diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index 01c75ff342..fbdefc3b80 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -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 ) ) diff --git a/src/gtk1/colour.cpp b/src/gtk1/colour.cpp index 82712095cd..e5234be3d4 100644 --- a/src/gtk1/colour.cpp +++ b/src/gtk1/colour.cpp @@ -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(); diff --git a/src/x11/colour.cpp b/src/x11/colour.cpp index 2890656e0e..26dfeded95 100644 --- a/src/x11/colour.cpp +++ b/src/x11/colour.cpp @@ -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(); -- 2.47.2