diff options
author | fluxgen <fluxgen> | 2004-09-12 14:01:03 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-09-12 14:01:03 (GMT) |
commit | 2fef25747f1010ad965ddb2a483da9a94732b530 (patch) | |
tree | df24763aa170023732a61016d370488a3f8d2d80 /src | |
parent | 7481146467aa5f12523ed5877e86c2d7cd07105d (diff) | |
download | fluxbox_lack-2fef25747f1010ad965ddb2a483da9a94732b530.zip fluxbox_lack-2fef25747f1010ad965ddb2a483da9a94732b530.tar.bz2 |
holds main resource functions
Diffstat (limited to 'src')
-rw-r--r-- | src/Resources.cc | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/src/Resources.cc b/src/Resources.cc new file mode 100644 index 0000000..9fd1dd6 --- /dev/null +++ b/src/Resources.cc | |||
@@ -0,0 +1,228 @@ | |||
1 | // holds main resource functions | ||
2 | |||
3 | #include "fluxbox.hh" | ||
4 | #include "FbTk/StringUtil.hh" | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <string> | ||
8 | |||
9 | using namespace std; | ||
10 | using namespace FbTk; | ||
11 | |||
12 | //----------------------------------------------------------------- | ||
13 | //---- accessors for int, bool, and some enums with Resource ------ | ||
14 | //----------------------------------------------------------------- | ||
15 | |||
16 | template<> | ||
17 | void FbTk::Resource<int>:: | ||
18 | setFromString(const char* strval) { | ||
19 | int val; | ||
20 | if (sscanf(strval, "%d", &val)==1) | ||
21 | *this = val; | ||
22 | } | ||
23 | |||
24 | template<> | ||
25 | void FbTk::Resource<std::string>:: | ||
26 | setFromString(const char *strval) { | ||
27 | *this = strval; | ||
28 | } | ||
29 | |||
30 | template<> | ||
31 | void FbTk::Resource<bool>:: | ||
32 | setFromString(char const *strval) { | ||
33 | *this = (bool)!strcasecmp(strval, "true"); | ||
34 | } | ||
35 | |||
36 | template<> | ||
37 | void FbTk::Resource<Fluxbox::TitlebarList>:: | ||
38 | setFromString(char const *strval) { | ||
39 | vector<std::string> val; | ||
40 | StringUtil::stringtok(val, strval); | ||
41 | int size=val.size(); | ||
42 | //clear old values | ||
43 | m_value.clear(); | ||
44 | |||
45 | for (int i=0; i<size; i++) { | ||
46 | if (strcasecmp(val[i].c_str(), "Maximize")==0) | ||
47 | m_value.push_back(Fluxbox::MAXIMIZE); | ||
48 | else if (strcasecmp(val[i].c_str(), "Minimize")==0) | ||
49 | m_value.push_back(Fluxbox::MINIMIZE); | ||
50 | else if (strcasecmp(val[i].c_str(), "Shade")==0) | ||
51 | m_value.push_back(Fluxbox::SHADE); | ||
52 | else if (strcasecmp(val[i].c_str(), "Stick")==0) | ||
53 | m_value.push_back(Fluxbox::STICK); | ||
54 | else if (strcasecmp(val[i].c_str(), "Menu")==0) | ||
55 | m_value.push_back(Fluxbox::MENU); | ||
56 | else if (strcasecmp(val[i].c_str(), "Close")==0) | ||
57 | m_value.push_back(Fluxbox::CLOSE); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | template<> | ||
62 | void FbTk::Resource<Fluxbox::TabsAttachArea>:: | ||
63 | setFromString(char const *strval) { | ||
64 | if (strcasecmp(strval, "Titlebar")==0) | ||
65 | m_value= Fluxbox::ATTACH_AREA_TITLEBAR; | ||
66 | else | ||
67 | m_value= Fluxbox::ATTACH_AREA_WINDOW; | ||
68 | } | ||
69 | |||
70 | template<> | ||
71 | void FbTk::Resource<unsigned int>:: | ||
72 | setFromString(const char *strval) { | ||
73 | if (sscanf(strval, "%ul", &m_value) != 1) | ||
74 | setDefaultValue(); | ||
75 | } | ||
76 | |||
77 | template<> | ||
78 | void FbTk::Resource<long long>:: | ||
79 | setFromString(const char *strval) { | ||
80 | if (sscanf(strval, "%ul", &m_value) != 1) | ||
81 | setDefaultValue(); | ||
82 | } | ||
83 | |||
84 | |||
85 | //----------------------------------------------------------------- | ||
86 | //---- manipulators for int, bool, and some enums with Resource --- | ||
87 | //----------------------------------------------------------------- | ||
88 | template<> | ||
89 | std::string FbTk::Resource<bool>:: | ||
90 | getString() { | ||
91 | return std::string(**this == true ? "true" : "false"); | ||
92 | } | ||
93 | |||
94 | template<> | ||
95 | std::string FbTk::Resource<int>:: | ||
96 | getString() { | ||
97 | char strval[256]; | ||
98 | sprintf(strval, "%d", **this); | ||
99 | return std::string(strval); | ||
100 | } | ||
101 | |||
102 | template<> | ||
103 | std::string FbTk::Resource<std::string>:: | ||
104 | getString() { return **this; } | ||
105 | |||
106 | |||
107 | template<> | ||
108 | std::string FbTk::Resource<Fluxbox::TitlebarList>:: | ||
109 | getString() { | ||
110 | string retval; | ||
111 | int size=m_value.size(); | ||
112 | for (int i=0; i<size; i++) { | ||
113 | switch (m_value[i]) { | ||
114 | case Fluxbox::SHADE: | ||
115 | retval.append("Shade"); | ||
116 | break; | ||
117 | case Fluxbox::MINIMIZE: | ||
118 | retval.append("Minimize"); | ||
119 | break; | ||
120 | case Fluxbox::MAXIMIZE: | ||
121 | retval.append("Maximize"); | ||
122 | break; | ||
123 | case Fluxbox::CLOSE: | ||
124 | retval.append("Close"); | ||
125 | break; | ||
126 | case Fluxbox::STICK: | ||
127 | retval.append("Stick"); | ||
128 | break; | ||
129 | case Fluxbox::MENU: | ||
130 | retval.append("Menu"); | ||
131 | break; | ||
132 | default: | ||
133 | break; | ||
134 | } | ||
135 | retval.append(" "); | ||
136 | } | ||
137 | |||
138 | return retval; | ||
139 | } | ||
140 | |||
141 | template<> | ||
142 | std::string FbTk::Resource<Fluxbox::TabsAttachArea>:: | ||
143 | getString() { | ||
144 | if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR) | ||
145 | return "Titlebar"; | ||
146 | else | ||
147 | return "Window"; | ||
148 | } | ||
149 | |||
150 | template<> | ||
151 | string FbTk::Resource<unsigned int>:: | ||
152 | getString() { | ||
153 | char tmpstr[128]; | ||
154 | sprintf(tmpstr, "%ul", m_value); | ||
155 | return string(tmpstr); | ||
156 | } | ||
157 | |||
158 | template<> | ||
159 | string FbTk::Resource<long long>:: | ||
160 | getString() { | ||
161 | char tmpstr[128]; | ||
162 | sprintf(tmpstr, "%ul", m_value); | ||
163 | return string(tmpstr); | ||
164 | } | ||
165 | |||
166 | template<> | ||
167 | void FbTk::Resource<Fluxbox::Layer>:: | ||
168 | setFromString(const char *strval) { | ||
169 | int tempnum = 0; | ||
170 | if (sscanf(strval, "%d", &tempnum) == 1) | ||
171 | m_value = tempnum; | ||
172 | else if (strcasecmp(strval, "Menu") == 0) | ||
173 | m_value = Fluxbox::instance()->getMenuLayer(); | ||
174 | else if (strcasecmp(strval, "AboveDock") == 0) | ||
175 | m_value = Fluxbox::instance()->getAboveDockLayer(); | ||
176 | else if (strcasecmp(strval, "Dock") == 0) | ||
177 | m_value = Fluxbox::instance()->getDockLayer(); | ||
178 | else if (strcasecmp(strval, "Top") == 0) | ||
179 | m_value = Fluxbox::instance()->getTopLayer(); | ||
180 | else if (strcasecmp(strval, "Normal") == 0) | ||
181 | m_value = Fluxbox::instance()->getNormalLayer(); | ||
182 | else if (strcasecmp(strval, "Bottom") == 0) | ||
183 | m_value = Fluxbox::instance()->getBottomLayer(); | ||
184 | else if (strcasecmp(strval, "Desktop") == 0) | ||
185 | m_value = Fluxbox::instance()->getDesktopLayer(); | ||
186 | else | ||
187 | setDefaultValue(); | ||
188 | } | ||
189 | |||
190 | |||
191 | template<> | ||
192 | string FbTk::Resource<Fluxbox::Layer>:: | ||
193 | getString() { | ||
194 | |||
195 | if (m_value.getNum() == Fluxbox::instance()->getMenuLayer()) | ||
196 | return string("Menu"); | ||
197 | else if (m_value.getNum() == Fluxbox::instance()->getAboveDockLayer()) | ||
198 | return string("AboveDock"); | ||
199 | else if (m_value.getNum() == Fluxbox::instance()->getDockLayer()) | ||
200 | return string("Dock"); | ||
201 | else if (m_value.getNum() == Fluxbox::instance()->getTopLayer()) | ||
202 | return string("Top"); | ||
203 | else if (m_value.getNum() == Fluxbox::instance()->getNormalLayer()) | ||
204 | return string("Normal"); | ||
205 | else if (m_value.getNum() == Fluxbox::instance()->getBottomLayer()) | ||
206 | return string("Bottom"); | ||
207 | else if (m_value.getNum() == Fluxbox::instance()->getDesktopLayer()) | ||
208 | return string("Desktop"); | ||
209 | else { | ||
210 | char tmpstr[128]; | ||
211 | sprintf(tmpstr, "%d", m_value.getNum()); | ||
212 | return string(tmpstr); | ||
213 | } | ||
214 | } | ||
215 | template<> | ||
216 | void FbTk::Resource<long>:: | ||
217 | setFromString(const char *strval) { | ||
218 | if (sscanf(strval, "%ld", &m_value) != 1) | ||
219 | setDefaultValue(); | ||
220 | } | ||
221 | |||
222 | template<> | ||
223 | string FbTk::Resource<long>:: | ||
224 | getString() { | ||
225 | char tmpstr[128]; | ||
226 | sprintf(tmpstr, "%ld", m_value); | ||
227 | return string(tmpstr); | ||
228 | } | ||