]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/colourcmn.cpp
don't leave pixels due to rounding errors in wxBoxSizer, allocate the extra pixels...
[wxWidgets.git] / src / common / colourcmn.cpp
index 114dd597a6b989b0014e56bc313fc9cc91e8dee5..a77017922fdc686a894c852fe1169226d0649df3 100644 (file)
 
 #ifndef WX_PRECOMP
     #include "wx/log.h"
+    #include "wx/utils.h"
+    #include "wx/gdicmn.h"
 #endif
 
-#include "wx/gdicmn.h"
-
+#if wxUSE_VARIANT
+IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
+#endif
 
 // ============================================================================
 // wxString <-> wxColour conversions
@@ -38,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 ?
     {