aboutsummaryrefslogtreecommitdiff
path: root/src/Toolbar.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-06-11 11:00:45 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:52:46 (GMT)
commit8c208459910f1dddcfdeb00567b990eebfc218b8 (patch)
tree47c442f906124306a52e13641d28fc6cd1ac513e /src/Toolbar.cc
parent60cd98604ae0ee62d64e3bc852898f69dae221d4 (diff)
downloadfluxbox_pavel-8c208459910f1dddcfdeb00567b990eebfc218b8.zip
fluxbox_pavel-8c208459910f1dddcfdeb00567b990eebfc218b8.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/Toolbar.cc')
-rw-r--r--src/Toolbar.cc81
1 files changed, 18 insertions, 63 deletions
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index fe4c591..603ed08 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -84,69 +84,24 @@ using std::list;
84 84
85using FbTk::STLUtil::forAll; 85using FbTk::STLUtil::forAll;
86 86
87namespace {
88
89struct ToolbarPlacementString {
90 Toolbar::Placement placement;
91 const char* str;
92};
93
94const ToolbarPlacementString placement_strings[] = {
95 { Toolbar::TOPLEFT, "TopLeft" },
96 { Toolbar::TOPCENTER, "TopCenter" },
97 { Toolbar::TOPRIGHT, "TopRight" },
98 { Toolbar::BOTTOMLEFT, "BottomLeft" },
99 { Toolbar::BOTTOMCENTER, "BottomCenter" },
100 { Toolbar::BOTTOMRIGHT, "BottomRight" },
101 { Toolbar::LEFTBOTTOM, "LeftBottom" },
102 { Toolbar::LEFTCENTER, "LeftCenter" },
103 { Toolbar::LEFTTOP, "LeftTop" },
104 { Toolbar::RIGHTBOTTOM, "RightBottom" },
105 { Toolbar::RIGHTCENTER, "RightCenter" },
106 { Toolbar::RIGHTTOP, "RightTop" }
107};
108
109}
110
111namespace FbTk { 87namespace FbTk {
112 88
113template<> 89template<>
114string FbTk::Resource<Toolbar::Placement>:: 90const EnumTraits<Toolbar::Placement>::Pair EnumTraits<Toolbar::Placement>::s_map[] = {
115getString() const { 91 { "TopLeft", Toolbar::TOPLEFT },
116 92 { "TopCenter", Toolbar::TOPCENTER },
117 size_t i = (m_value == FbTk::Util::clamp(m_value, Toolbar::TOPLEFT, Toolbar::RIGHTTOP) 93 { "TopRight", Toolbar::TOPRIGHT },
118 ? m_value 94 { "BottomLeft", Toolbar::BOTTOMLEFT },
119 : Toolbar::DEFAULT) - Toolbar::TOPLEFT; 95 { "BottomCenter", Toolbar::BOTTOMCENTER },
120 return placement_strings[i].str; 96 { "BottomRight", Toolbar::BOTTOMRIGHT },
121} 97 { "LeftBottom", Toolbar::LEFTBOTTOM },
122 98 { "LeftCenter", Toolbar::LEFTCENTER },
123template<> 99 { "LeftTop", Toolbar::LEFTTOP },
124void FbTk::Resource<Toolbar::Placement>:: 100 { "RightBottom", Toolbar::RIGHTBOTTOM },
125setFromString(const char *strval) { 101 { "RightCenter", Toolbar::RIGHTCENTER },
126 size_t i; 102 { "RightTop", Toolbar::RIGHTTOP },
127 for (i = 0; i < sizeof(placement_strings)/sizeof(ToolbarPlacementString); ++i) { 103 { NULL, Toolbar::RIGHTTOP }
128 if (strcasecmp(strval, placement_strings[i].str) == 0) { 104};
129 m_value = placement_strings[i].placement;
130 return;
131 }
132 }
133 setDefaultValue();
134}
135
136template<>
137void FbTk::Resource<Toolbar::Placement>::setFromLua(lua::state &l) {
138 lua::stack_sentry s(l, -1);
139 if(l.isstring(-1))
140 setFromString(l.tostring(-1).c_str());
141 else
142 setDefaultValue();
143 l.pop();
144}
145
146template<>
147void FbTk::Resource<Toolbar::Placement>::pushToLua(lua::state &l) const {
148 l.pushstring(getString());
149}
150 105
151} // end namespace FbTk 106} // end namespace FbTk
152 107
@@ -230,7 +185,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width):
230 scrn.name() + ".toolbar.widthPercent", scrn.altName() + ".Toolbar.WidthPercent"), 185 scrn.name() + ".toolbar.widthPercent", scrn.altName() + ".Toolbar.WidthPercent"),
231 m_rc_alpha(scrn.resourceManager(), 255, 186 m_rc_alpha(scrn.resourceManager(), 255,
232 scrn.name() + ".toolbar.alpha", scrn.altName() + ".Toolbar.Alpha"), 187 scrn.name() + ".toolbar.alpha", scrn.altName() + ".Toolbar.Alpha"),
233 m_rc_layernum(scrn.resourceManager(), ResourceLayer(ResourceLayer::DOCK), 188 m_rc_layernum(scrn.resourceManager(), ResourceLayer::DOCK,
234 scrn.name() + ".toolbar.layer", scrn.altName() + ".Toolbar.Layer"), 189 scrn.name() + ".toolbar.layer", scrn.altName() + ".Toolbar.Layer"),
235 m_rc_on_head(scrn.resourceManager(), 1, 190 m_rc_on_head(scrn.resourceManager(), 1,
236 scrn.name() + ".toolbar.onhead", scrn.altName() + ".Toolbar.onHead"), 191 scrn.name() + ".toolbar.onhead", scrn.altName() + ".Toolbar.onHead"),
@@ -255,7 +210,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width):
255 FbTk::MemFun(*this, &Toolbar::screenChanged)); 210 FbTk::MemFun(*this, &Toolbar::screenChanged));
256 211
257 212
258 moveToLayer((*m_rc_layernum).getNum()); 213 moveToLayer(static_cast<int>(*m_rc_layernum));
259 214
260 m_layermenu.setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); 215 m_layermenu.setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu"));
261 m_placementmenu.setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); 216 m_placementmenu.setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu"));
@@ -785,7 +740,7 @@ void Toolbar::toggleHidden() {
785 740
786void Toolbar::moveToLayer(int layernum) { 741void Toolbar::moveToLayer(int layernum) {
787 m_layeritem.moveToLayer(layernum); 742 m_layeritem.moveToLayer(layernum);
788 *m_rc_layernum = layernum; 743 *m_rc_layernum = static_cast<ResourceLayer::Type>(layernum);
789} 744}
790 745
791void Toolbar::setupMenus(bool skip_new_placement) { 746void Toolbar::setupMenus(bool skip_new_placement) {