summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2004-09-12 14:01:03 (GMT)
committerfluxgen <fluxgen>2004-09-12 14:01:03 (GMT)
commit2fef25747f1010ad965ddb2a483da9a94732b530 (patch)
treedf24763aa170023732a61016d370488a3f8d2d80
parent7481146467aa5f12523ed5877e86c2d7cd07105d (diff)
downloadfluxbox_lack-2fef25747f1010ad965ddb2a483da9a94732b530.zip
fluxbox_lack-2fef25747f1010ad965ddb2a483da9a94732b530.tar.bz2
holds main resource functions
-rw-r--r--src/Resources.cc228
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
9using namespace std;
10using namespace FbTk;
11
12//-----------------------------------------------------------------
13//---- accessors for int, bool, and some enums with Resource ------
14//-----------------------------------------------------------------
15
16template<>
17void FbTk::Resource<int>::
18setFromString(const char* strval) {
19 int val;
20 if (sscanf(strval, "%d", &val)==1)
21 *this = val;
22}
23
24template<>
25void FbTk::Resource<std::string>::
26setFromString(const char *strval) {
27 *this = strval;
28}
29
30template<>
31void FbTk::Resource<bool>::
32setFromString(char const *strval) {
33 *this = (bool)!strcasecmp(strval, "true");
34}
35
36template<>
37void FbTk::Resource<Fluxbox::TitlebarList>::
38setFromString(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
61template<>
62void FbTk::Resource<Fluxbox::TabsAttachArea>::
63setFromString(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
70template<>
71void FbTk::Resource<unsigned int>::
72setFromString(const char *strval) {
73 if (sscanf(strval, "%ul", &m_value) != 1)
74 setDefaultValue();
75}
76
77template<>
78void FbTk::Resource<long long>::
79setFromString(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//-----------------------------------------------------------------
88template<>
89std::string FbTk::Resource<bool>::
90getString() {
91 return std::string(**this == true ? "true" : "false");
92}
93
94template<>
95std::string FbTk::Resource<int>::
96getString() {
97 char strval[256];
98 sprintf(strval, "%d", **this);
99 return std::string(strval);
100}
101
102template<>
103std::string FbTk::Resource<std::string>::
104getString() { return **this; }
105
106
107template<>
108std::string FbTk::Resource<Fluxbox::TitlebarList>::
109getString() {
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
141template<>
142std::string FbTk::Resource<Fluxbox::TabsAttachArea>::
143getString() {
144 if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR)
145 return "Titlebar";
146 else
147 return "Window";
148}
149
150template<>
151string FbTk::Resource<unsigned int>::
152getString() {
153 char tmpstr[128];
154 sprintf(tmpstr, "%ul", m_value);
155 return string(tmpstr);
156}
157
158template<>
159string FbTk::Resource<long long>::
160getString() {
161 char tmpstr[128];
162 sprintf(tmpstr, "%ul", m_value);
163 return string(tmpstr);
164}
165
166template<>
167void FbTk::Resource<Fluxbox::Layer>::
168setFromString(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
191template<>
192string FbTk::Resource<Fluxbox::Layer>::
193getString() {
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}
215template<>
216void FbTk::Resource<long>::
217setFromString(const char *strval) {
218 if (sscanf(strval, "%ld", &m_value) != 1)
219 setDefaultValue();
220}
221
222template<>
223string FbTk::Resource<long>::
224getString() {
225 char tmpstr[128];
226 sprintf(tmpstr, "%ld", m_value);
227 return string(tmpstr);
228}