diff options
author | fluxgen <fluxgen> | 2006-02-12 08:05:34 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-02-12 08:05:34 (GMT) |
commit | ab26593cddf2fc0004da8048e28216792ed433ef (patch) | |
tree | 4add528920b7358c3355507362c4b12a933b2638 /src | |
parent | e85b2f3f5b091bac8101bc90ba04e575b845758e (diff) | |
download | fluxbox_pavel-ab26593cddf2fc0004da8048e28216792ed433ef.zip fluxbox_pavel-ab26593cddf2fc0004da8048e28216792ed433ef.tar.bz2 |
added static validColorString function, returns true if the color string is in valid color format
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Color.cc | 17 | ||||
-rw-r--r-- | src/FbTk/Color.hh | 5 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/FbTk/Color.cc b/src/FbTk/Color.cc index 7d050d3..dd80bd3 100644 --- a/src/FbTk/Color.cc +++ b/src/FbTk/Color.cc | |||
@@ -31,11 +31,9 @@ | |||
31 | using namespace std; | 31 | using namespace std; |
32 | 32 | ||
33 | namespace { | 33 | namespace { |
34 | unsigned char maxValue(unsigned short colval) { | ||
35 | if (colval == 65535) | ||
36 | return 0xFF; | ||
37 | 34 | ||
38 | return static_cast<unsigned char>(colval/0xFF); | 35 | inline unsigned char maxValue(unsigned short colval) { |
36 | return colval == 65535 ? 0xFF : static_cast<unsigned char>(colval/0xFF); | ||
39 | } | 37 | } |
40 | 38 | ||
41 | }; | 39 | }; |
@@ -106,6 +104,17 @@ bool Color::setFromString(const char *color_string, int screen) { | |||
106 | return true; | 104 | return true; |
107 | } | 105 | } |
108 | 106 | ||
107 | bool Color::validColorString(const char *color_string, int screen) { | ||
108 | XColor color; | ||
109 | Display *disp = App::instance()->display(); | ||
110 | Colormap colm = DefaultColormap(disp, screen); | ||
111 | // trim white space | ||
112 | string color_string_tmp = color_string; | ||
113 | StringUtil::removeFirstWhitespace(color_string_tmp); | ||
114 | StringUtil::removeTrailingWhitespace(color_string_tmp); | ||
115 | |||
116 | return XParseColor(disp, colm, color_string_tmp.c_str(), &color) != 0; | ||
117 | } | ||
109 | 118 | ||
110 | Color &Color::operator = (const Color &col_copy) { | 119 | Color &Color::operator = (const Color &col_copy) { |
111 | // check for aliasing | 120 | // check for aliasing |
diff --git a/src/FbTk/Color.hh b/src/FbTk/Color.hh index b17dd95..7536d89 100644 --- a/src/FbTk/Color.hh +++ b/src/FbTk/Color.hh | |||
@@ -54,7 +54,10 @@ public: | |||
54 | inline unsigned short green() const { return m_green; } | 54 | inline unsigned short green() const { return m_green; } |
55 | inline unsigned short blue() const { return m_blue; } | 55 | inline unsigned short blue() const { return m_blue; } |
56 | inline unsigned long pixel() const { return m_pixel; } | 56 | inline unsigned long pixel() const { return m_pixel; } |
57 | 57 | ||
58 | /// @return true if the color name in color_string is resolved, else false | ||
59 | static bool validColorString(const char *color_string, int screen); | ||
60 | |||
58 | private: | 61 | private: |
59 | void free(); | 62 | void free(); |
60 | void copy(const Color &col); | 63 | void copy(const Color &col); |