]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/colourcmn.cpp
removed TTN_NEEDTEXT handlers, we don't use tooltips on demand
[wxWidgets.git] / src / common / colourcmn.cpp
index 5770961fb0569b6d215c9b443878c30eb50450b7..3969790771510fde07ba214fc63e4c8601769740 100644 (file)
 
 #include "wx/colour.h"
 
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+    #include "wx/utils.h"
+#endif
+
+#include "wx/gdicmn.h"
 
 
 // ============================================================================
@@ -33,12 +39,16 @@ 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 )
     {
@@ -56,7 +66,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())
@@ -93,7 +106,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