projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make JPEG callbacks extern "C" to fix Sun CC warnings
[wxWidgets.git]
/
src
/
common
/
colourcmn.cpp
diff --git
a/src/common/colourcmn.cpp
b/src/common/colourcmn.cpp
index efd9cad8906106dddc4827b1888c1448a49d0c9b..a6626f91e2d0bb00b4ef83ff76ca99defd5aa007 100644
(file)
--- a/
src/common/colourcmn.cpp
+++ b/
src/common/colourcmn.cpp
@@
-19,38
+19,50
@@
#include "wx/colour.h"
#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"
+ #include "wx/wxcrtvararg.h"
+#endif
+#if wxUSE_VARIANT
+IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLEXPORT)
+#endif
// ============================================================================
// wxString <-> wxColour conversions
// ============================================================================
// ============================================================================
// wxString <-> wxColour conversions
// ============================================================================
-bool wxColourBase::FromString(const wx
Char *
str)
+bool wxColourBase::FromString(const wx
String&
str)
{
{
- if ( str
== NULL || str[0] == wxT('\0')
)
+ if ( str
.empty()
)
return false; // invalid or empty string
if ( wxStrncmp(str, wxT("RGB"), 3) == 0 ||
wxStrncmp(str, wxT("rgb"), 3) == 0 )
{
return false; // invalid or empty string
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;
int red, green, blue;
- if (wxSscanf(
&str[3]
, wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
+ if (wxSscanf(
str.wx_str() + 3
, wxT("(%d, %d, %d)"), &red, &green, &blue) != 3)
return false;
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;
}
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.wx_str() + 1, wxT("%lx
"), &tmp) != 1)
return false;
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 ?
{
}
else if (wxTheColourDatabase) // a colour name ?
{
@@
-99,7
+111,17
@@
wxString wxColourBase::GetAsString(long flags) const
return colName;
}
return colName;
}
+#if WXWIN_COMPATIBILITY_2_6
+
+// static
wxColour wxColourBase::CreateByName(const wxString& name)
{
return wxColour(name);
}
wxColour wxColourBase::CreateByName(const wxString& name)
{
return wxColour(name);
}
+
+void wxColourBase::InitFromName(const wxString& col)
+{
+ Set(col);
+}
+
+#endif // WXWIN_COMPATIBILITY_2_6