X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6b5d2431fc188c03bd43ef69b5ad3197646c9289..0b1cc7bffb94ebfb4bc988b9a7320b96ea0cfcda:/src/common/colourcmn.cpp?ds=inline diff --git a/src/common/colourcmn.cpp b/src/common/colourcmn.cpp index 7cc62a7a7f..a77017922f 100644 --- a/src/common/colourcmn.cpp +++ b/src/common/colourcmn.cpp @@ -19,10 +19,15 @@ #include "wx/colour.h" -#include "wx/gdicmn.h" -#include "wx/log.h" - +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/utils.h" + #include "wx/gdicmn.h" +#endif +#if wxUSE_VARIANT +IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT) +#endif // ============================================================================ // wxString <-> wxColour conversions @@ -36,21 +41,27 @@ bool wxColourBase::FromString(const wxChar *str) if ( wxStrncmp(str, wxT("RGB"), 3) == 0 || wxStrncmp(str, wxT("rgb"), 3) == 0 ) { - // RGB specification CSS-like + // CSS-like RGB specification + // 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) return false; - Set((unsigned char)red, (unsigned char)green, (unsigned char)blue); + Set((unsigned char)wxClip(red,0,255), + (unsigned char)wxClip(green,0,255), + (unsigned char)wxClip(blue,0,255)); } else if ( str[0] == wxT('#') && wxStrlen(str) == 7 ) { // hexadecimal prefixed with # (HTML syntax) unsigned long tmp; - if (wxSscanf(&str[1], wxT("%lX"), &tmp) != 1) + if (wxSscanf(&str[1], wxT("%lx"), &tmp) != 1) return false; - Set(tmp); // set from packed long + Set((unsigned char)(tmp >> 16), + (unsigned char)(tmp >> 8), + (unsigned char)tmp); } else if (wxTheColourDatabase) // a colour name ? { @@ -59,7 +70,10 @@ bool wxColourBase::FromString(const wxChar *str) // because this place can be called from constructor // and 'this' could not be available yet wxColour clr = wxTheColourDatabase->Find(str); - Set((unsigned char)clr.Red(), (unsigned char)clr.Green(), (unsigned char)clr.Blue()); + if (clr.Ok()) + Set((unsigned char)clr.Red(), + (unsigned char)clr.Green(), + (unsigned char)clr.Blue()); } if (Ok()) @@ -96,7 +110,17 @@ wxString wxColourBase::GetAsString(long flags) const return colName; } +#if WXWIN_COMPATIBILITY_2_6 + +// static wxColour wxColourBase::CreateByName(const wxString& name) { return wxColour(name); } + +void wxColourBase::InitFromName(const wxString& col) +{ + Set(col); +} + +#endif // WXWIN_COMPATIBILITY_2_6