diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-11 11:00:45 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-16 23:49:23 (GMT) |
commit | eb0eef14134ee667c60f75f53de4e24950f3c117 (patch) | |
tree | 58b35842e1f84666373478bca3386be037a7a019 /src/Slit.cc | |
parent | 3b7c1a3c220b7ccec0dee7804d36dabfe81449c4 (diff) | |
download | fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.zip fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.tar.bz2 |
Simplify FbTk::Resource template class
by outsourcing the conversion from string/lua to the specific type (and back) to a separate
class. This change touches a lot of files because the interface of FbTk::Resource changed
slightly. However, the changes are minor.
Diffstat (limited to 'src/Slit.cc')
-rw-r--r-- | src/Slit.cc | 109 |
1 files changed, 19 insertions, 90 deletions
diff --git a/src/Slit.cc b/src/Slit.cc index d248d99..5bd32ff 100644 --- a/src/Slit.cc +++ b/src/Slit.cc | |||
@@ -92,95 +92,24 @@ using std::dec; | |||
92 | namespace FbTk { | 92 | namespace FbTk { |
93 | 93 | ||
94 | template<> | 94 | template<> |
95 | string FbTk::Resource<Slit::Placement>::getString() const { | 95 | const EnumTraits<Slit::Placement>::Pair EnumTraits<Slit::Placement>::s_map[] = { |
96 | switch (m_value) { | 96 | { "TopLeft", Slit::TOPLEFT }, |
97 | case Slit::TOPLEFT: | 97 | { "LeftCenter", Slit::LEFTCENTER }, |
98 | return string("TopLeft"); | 98 | { "BottomLeft", Slit::BOTTOMLEFT }, |
99 | break; | 99 | { "TopCenter", Slit::TOPCENTER }, |
100 | case Slit::LEFTCENTER: | 100 | { "BottomCenter", Slit::BOTTOMCENTER }, |
101 | return string("LeftCenter"); | 101 | { "TopRight", Slit::TOPRIGHT }, |
102 | break; | 102 | { "RightCenter", Slit::RIGHTCENTER }, |
103 | case Slit::BOTTOMLEFT: | 103 | { "BottomRight", Slit::BOTTOMRIGHT }, |
104 | return string("BottomLeft"); | 104 | { "LeftTop", Slit::LEFTTOP }, |
105 | break; | 105 | { "RightTop", Slit::RIGHTTOP }, |
106 | case Slit::TOPCENTER: | 106 | { "LeftBottom", Slit::LEFTBOTTOM }, |
107 | return string("TopCenter"); | 107 | { "RightBottom", Slit::RIGHTBOTTOM }, |
108 | break; | 108 | { NULL, Slit::RIGHTBOTTOM }, |
109 | case Slit::BOTTOMCENTER: | 109 | }; |
110 | return string("BottomCenter"); | ||
111 | break; | ||
112 | case Slit::TOPRIGHT: | ||
113 | return string("TopRight"); | ||
114 | break; | ||
115 | case Slit::RIGHTCENTER: | ||
116 | return string("RightCenter"); | ||
117 | break; | ||
118 | case Slit::BOTTOMRIGHT: | ||
119 | return string("BottomRight"); | ||
120 | break; | ||
121 | case Slit::LEFTTOP: | ||
122 | return string("LeftTop"); | ||
123 | break; | ||
124 | case Slit::RIGHTTOP: | ||
125 | return string("RightTop"); | ||
126 | break; | ||
127 | case Slit::LEFTBOTTOM: | ||
128 | return string("LeftBottom"); | ||
129 | break; | ||
130 | case Slit::RIGHTBOTTOM: | ||
131 | return string("RightBottom"); | ||
132 | break; | ||
133 | } | ||
134 | //default string | ||
135 | return string("RightBottom"); | ||
136 | } | ||
137 | |||
138 | template<> | ||
139 | void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) { | ||
140 | if (strcasecmp(strval, "TopLeft")==0) | ||
141 | m_value = Slit::TOPLEFT; | ||
142 | else if (strcasecmp(strval, "LeftCenter")==0) | ||
143 | m_value = Slit::LEFTCENTER; | ||
144 | else if (strcasecmp(strval, "BottomLeft")==0) | ||
145 | m_value = Slit::BOTTOMLEFT; | ||
146 | else if (strcasecmp(strval, "TopCenter")==0) | ||
147 | m_value = Slit::TOPCENTER; | ||
148 | else if (strcasecmp(strval, "BottomCenter")==0) | ||
149 | m_value = Slit::BOTTOMCENTER; | ||
150 | else if (strcasecmp(strval, "TopRight")==0) | ||
151 | m_value = Slit::TOPRIGHT; | ||
152 | else if (strcasecmp(strval, "RightCenter")==0) | ||
153 | m_value = Slit::RIGHTCENTER; | ||
154 | else if (strcasecmp(strval, "BottomRight")==0) | ||
155 | m_value = Slit::BOTTOMRIGHT; | ||
156 | else if (strcasecmp(strval, "LeftTop")==0) | ||
157 | m_value = Slit::LEFTTOP; | ||
158 | else if (strcasecmp(strval, "LeftBottom")==0) | ||
159 | m_value = Slit::LEFTBOTTOM; | ||
160 | else if (strcasecmp(strval, "RightTop")==0) | ||
161 | m_value = Slit::RIGHTTOP; | ||
162 | else if (strcasecmp(strval, "RightBottom")==0) | ||
163 | m_value = Slit::RIGHTBOTTOM; | ||
164 | else | ||
165 | setDefaultValue(); | ||
166 | } | ||
167 | |||
168 | template<> | ||
169 | void FbTk::Resource<Slit::Placement>::setFromLua(lua::state &l) { | ||
170 | lua::stack_sentry s(l, -1); | ||
171 | if(l.isstring(-1)) | ||
172 | setFromString(l.tostring(-1).c_str()); | ||
173 | else | ||
174 | setDefaultValue(); | ||
175 | l.pop(); | ||
176 | } | ||
177 | |||
178 | template<> | ||
179 | void FbTk::Resource<Slit::Placement>::pushToLua(lua::state &l) const { | ||
180 | l.pushstring(getString()); | ||
181 | } | ||
182 | 110 | ||
183 | } // end namespace FbTk | 111 | } // end namespace FbTk |
112 | |||
184 | namespace { | 113 | namespace { |
185 | 114 | ||
186 | class SlitClientMenuItem: public FbTk::MenuItem{ | 115 | class SlitClientMenuItem: public FbTk::MenuItem{ |
@@ -273,7 +202,7 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) | |||
273 | scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"), | 202 | scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"), |
274 | m_rc_on_head(scr.resourceManager(), 0, | 203 | m_rc_on_head(scr.resourceManager(), 0, |
275 | scr.name() + ".slit.onhead", scr.altName() + ".Slit.onHead"), | 204 | scr.name() + ".slit.onhead", scr.altName() + ".Slit.onHead"), |
276 | m_rc_layernum(scr.resourceManager(), ResourceLayer(ResourceLayer::DOCK), | 205 | m_rc_layernum(scr.resourceManager(), ResourceLayer::DOCK, |
277 | scr.name() + ".slit.layer", scr.altName() + ".Slit.Layer") { | 206 | scr.name() + ".slit.layer", scr.altName() + ".Slit.Layer") { |
278 | 207 | ||
279 | _FB_USES_NLS; | 208 | _FB_USES_NLS; |
@@ -321,7 +250,7 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) | |||
321 | true)); | 250 | true)); |
322 | m_layermenu->setLabel(_FB_XTEXT(Slit, Layer, "Slit Layer", "Title of Slit Layer Menu")); | 251 | m_layermenu->setLabel(_FB_XTEXT(Slit, Layer, "Slit Layer", "Title of Slit Layer Menu")); |
323 | 252 | ||
324 | moveToLayer((*m_rc_layernum).getNum()); | 253 | moveToLayer(static_cast<int>(*m_rc_layernum)); |
325 | 254 | ||
326 | 255 | ||
327 | 256 | ||
@@ -1289,7 +1218,7 @@ void Slit::setupMenu() { | |||
1289 | 1218 | ||
1290 | void Slit::moveToLayer(int layernum) { | 1219 | void Slit::moveToLayer(int layernum) { |
1291 | m_layeritem->moveToLayer(layernum); | 1220 | m_layeritem->moveToLayer(layernum); |
1292 | *m_rc_layernum = layernum; | 1221 | *m_rc_layernum = static_cast<ResourceLayer::Type>(layernum); |
1293 | } | 1222 | } |
1294 | 1223 | ||
1295 | void Slit::saveOnHead(int head) { | 1224 | void Slit::saveOnHead(int head) { |