1
// Resources.cc for Fluxbox Window Manager
2
// Copyright (c) 2004 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
// $Id: Resources.cc 3995 2005-05-06 18:04:14Z mathias $
25
// holds main resource functions
28
#include "FbTk/StringUtil.hh"
36
//-----------------------------------------------------------------
37
//---- accessors for int, bool, and some enums with Resource ------
38
//-----------------------------------------------------------------
43
void FbTk::Resource<int>::
44
setFromString(const char* strval) {
46
if (sscanf(strval, "%d", &val)==1)
51
void FbTk::Resource<std::string>::
52
setFromString(const char *strval) {
57
void FbTk::Resource<bool>::
58
setFromString(char const *strval) {
59
*this = (bool)!strcasecmp(strval, "true");
63
void FbTk::Resource<Fluxbox::TitlebarList>::
64
setFromString(char const *strval) {
65
vector<std::string> val;
66
StringUtil::stringtok(val, strval);
71
for (int i=0; i<size; i++) {
72
if (strcasecmp(val[i].c_str(), "Maximize")==0)
73
m_value.push_back(Fluxbox::MAXIMIZE);
74
else if (strcasecmp(val[i].c_str(), "Minimize")==0)
75
m_value.push_back(Fluxbox::MINIMIZE);
76
else if (strcasecmp(val[i].c_str(), "Shade")==0)
77
m_value.push_back(Fluxbox::SHADE);
78
else if (strcasecmp(val[i].c_str(), "Stick")==0)
79
m_value.push_back(Fluxbox::STICK);
80
else if (strcasecmp(val[i].c_str(), "MenuIcon")==0)
81
m_value.push_back(Fluxbox::MENUICON);
82
else if (strcasecmp(val[i].c_str(), "Close")==0)
83
m_value.push_back(Fluxbox::CLOSE);
88
void FbTk::Resource<Fluxbox::TabsAttachArea>::
89
setFromString(char const *strval) {
90
if (strcasecmp(strval, "Titlebar")==0)
91
m_value= Fluxbox::ATTACH_AREA_TITLEBAR;
93
m_value= Fluxbox::ATTACH_AREA_WINDOW;
97
void FbTk::Resource<unsigned int>::
98
setFromString(const char *strval) {
99
if (sscanf(strval, "%ul", &m_value) != 1)
104
void FbTk::Resource<long long>::
105
setFromString(const char *strval) {
106
if (sscanf(strval, "%llu", &m_value) != 1)
111
//-----------------------------------------------------------------
112
//---- manipulators for int, bool, and some enums with Resource ---
113
//-----------------------------------------------------------------
115
std::string FbTk::Resource<bool>::
117
return std::string(**this == true ? "true" : "false");
121
std::string FbTk::Resource<int>::
124
sprintf(strval, "%d", **this);
125
return std::string(strval);
129
std::string FbTk::Resource<std::string>::
130
getString() { return **this; }
134
std::string FbTk::Resource<Fluxbox::TitlebarList>::
137
int size=m_value.size();
138
for (int i=0; i<size; i++) {
139
switch (m_value[i]) {
141
retval.append("Shade");
143
case Fluxbox::MINIMIZE:
144
retval.append("Minimize");
146
case Fluxbox::MAXIMIZE:
147
retval.append("Maximize");
150
retval.append("Close");
153
retval.append("Stick");
155
case Fluxbox::MENUICON:
156
retval.append("MenuIcon");
168
std::string FbTk::Resource<Fluxbox::TabsAttachArea>::
170
if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR)
177
string FbTk::Resource<unsigned int>::
180
sprintf(tmpstr, "%ul", m_value);
181
return string(tmpstr);
185
string FbTk::Resource<long long>::
188
sprintf(tmpstr, "%llu", (unsigned long long) m_value);
189
return string(tmpstr);
193
void FbTk::Resource<Fluxbox::Layer>::
194
setFromString(const char *strval) {
196
if (sscanf(strval, "%d", &tempnum) == 1)
198
else if (strcasecmp(strval, "Menu") == 0)
199
m_value = Fluxbox::instance()->getMenuLayer();
200
else if (strcasecmp(strval, "AboveDock") == 0)
201
m_value = Fluxbox::instance()->getAboveDockLayer();
202
else if (strcasecmp(strval, "Dock") == 0)
203
m_value = Fluxbox::instance()->getDockLayer();
204
else if (strcasecmp(strval, "Top") == 0)
205
m_value = Fluxbox::instance()->getTopLayer();
206
else if (strcasecmp(strval, "Normal") == 0)
207
m_value = Fluxbox::instance()->getNormalLayer();
208
else if (strcasecmp(strval, "Bottom") == 0)
209
m_value = Fluxbox::instance()->getBottomLayer();
210
else if (strcasecmp(strval, "Desktop") == 0)
211
m_value = Fluxbox::instance()->getDesktopLayer();
218
string FbTk::Resource<Fluxbox::Layer>::
221
if (m_value.getNum() == Fluxbox::instance()->getMenuLayer())
222
return string("Menu");
223
else if (m_value.getNum() == Fluxbox::instance()->getAboveDockLayer())
224
return string("AboveDock");
225
else if (m_value.getNum() == Fluxbox::instance()->getDockLayer())
226
return string("Dock");
227
else if (m_value.getNum() == Fluxbox::instance()->getTopLayer())
228
return string("Top");
229
else if (m_value.getNum() == Fluxbox::instance()->getNormalLayer())
230
return string("Normal");
231
else if (m_value.getNum() == Fluxbox::instance()->getBottomLayer())
232
return string("Bottom");
233
else if (m_value.getNum() == Fluxbox::instance()->getDesktopLayer())
234
return string("Desktop");
237
sprintf(tmpstr, "%d", m_value.getNum());
238
return string(tmpstr);
242
void FbTk::Resource<long>::
243
setFromString(const char *strval) {
244
if (sscanf(strval, "%ld", &m_value) != 1)
249
string FbTk::Resource<long>::
252
sprintf(tmpstr, "%ld", m_value);
253
return string(tmpstr);