diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Screen.cc | 161 |
1 files changed, 65 insertions, 96 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 97596d8..9ec7130 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -183,7 +183,7 @@ int calcSquareDistance(int x1, int y1, int x2, int y2) { | |||
183 | 183 | ||
184 | class TabPlacementMenuItem: public FbTk::RadioMenuItem { | 184 | class TabPlacementMenuItem: public FbTk::RadioMenuItem { |
185 | public: | 185 | public: |
186 | TabPlacementMenuItem(FbTk::FbString & label, BScreen &screen, | 186 | TabPlacementMenuItem(const FbTk::FbString & label, BScreen &screen, |
187 | FbWinFrame::TabPlacement place, | 187 | FbWinFrame::TabPlacement place, |
188 | FbTk::RefCount<FbTk::Command<void> > &cmd): | 188 | FbTk::RefCount<FbTk::Command<void> > &cmd): |
189 | FbTk::RadioMenuItem(label, cmd), | 189 | FbTk::RadioMenuItem(label, cmd), |
@@ -208,6 +208,28 @@ void clampMenuDelay(int& delay) { | |||
208 | delay = FbTk::Util::clamp(delay, 0, 5000); | 208 | delay = FbTk::Util::clamp(delay, 0, 5000); |
209 | } | 209 | } |
210 | 210 | ||
211 | |||
212 | struct TabPlacementString { | ||
213 | FbWinFrame::TabPlacement placement; | ||
214 | const char* str; | ||
215 | }; | ||
216 | |||
217 | const TabPlacementString placement_strings[] = { | ||
218 | { FbWinFrame::TOPLEFT, "TopLeft" }, | ||
219 | { FbWinFrame::TOP, "Top" }, | ||
220 | { FbWinFrame::TOPRIGHT, "TopRight" }, | ||
221 | { FbWinFrame::BOTTOMLEFT, "BottomLeft" }, | ||
222 | { FbWinFrame::BOTTOM, "Bottom" }, | ||
223 | { FbWinFrame::BOTTOMRIGHT, "BottomRight" }, | ||
224 | { FbWinFrame::LEFTBOTTOM, "LeftBottom" }, | ||
225 | { FbWinFrame::LEFT, "Left" }, | ||
226 | { FbWinFrame::LEFTTOP, "LeftTop" }, | ||
227 | { FbWinFrame::RIGHTBOTTOM, "RightBottom" }, | ||
228 | { FbWinFrame::RIGHT, "Right" }, | ||
229 | { FbWinFrame::RIGHTTOP, "RightTop" } | ||
230 | }; | ||
231 | |||
232 | |||
211 | } // end anonymous namespace | 233 | } // end anonymous namespace |
212 | 234 | ||
213 | 235 | ||
@@ -217,77 +239,25 @@ namespace FbTk { | |||
217 | template<> | 239 | template<> |
218 | string FbTk::Resource<FbWinFrame::TabPlacement>:: | 240 | string FbTk::Resource<FbWinFrame::TabPlacement>:: |
219 | getString() const { | 241 | getString() const { |
220 | switch (m_value) { | 242 | |
221 | case FbWinFrame::TOPLEFT: | 243 | size_t i = (m_value == FbTk::Util::clamp(m_value, FbWinFrame::TOPLEFT, FbWinFrame::RIGHTTOP) |
222 | return string("TopLeft"); | 244 | ? m_value |
223 | break; | 245 | : FbWinFrame::DEFAULT) - 1; |
224 | case FbWinFrame::BOTTOMLEFT: | 246 | return placement_strings[i].str; |
225 | return string("BottomLeft"); | ||
226 | break; | ||
227 | case FbWinFrame::TOP: | ||
228 | return string("Top"); | ||
229 | break; | ||
230 | case FbWinFrame::BOTTOM: | ||
231 | return string("Bottom"); | ||
232 | break; | ||
233 | case FbWinFrame::TOPRIGHT: | ||
234 | return string("TopRight"); | ||
235 | break; | ||
236 | case FbWinFrame::BOTTOMRIGHT: | ||
237 | return string("BottomRight"); | ||
238 | break; | ||
239 | case FbWinFrame::LEFTTOP: | ||
240 | return string("LeftTop"); | ||
241 | break; | ||
242 | case FbWinFrame::LEFT: | ||
243 | return string("Left"); | ||
244 | break; | ||
245 | case FbWinFrame::LEFTBOTTOM: | ||
246 | return string("LeftBottom"); | ||
247 | break; | ||
248 | case FbWinFrame::RIGHTTOP: | ||
249 | return string("RightTop"); | ||
250 | break; | ||
251 | case FbWinFrame::RIGHT: | ||
252 | return string("Right"); | ||
253 | break; | ||
254 | case FbWinFrame::RIGHTBOTTOM: | ||
255 | return string("RightBottom"); | ||
256 | break; | ||
257 | } | ||
258 | //default string | ||
259 | return string("TopLeft"); | ||
260 | } | 247 | } |
261 | 248 | ||
262 | template<> | 249 | template<> |
263 | void FbTk::Resource<FbWinFrame::TabPlacement>:: | 250 | void FbTk::Resource<FbWinFrame::TabPlacement>:: |
264 | setFromString(const char *strval) { | 251 | setFromString(const char *strval) { |
265 | if (strcasecmp(strval, "TopLeft") == 0) | 252 | |
266 | m_value = FbWinFrame::TOPLEFT; | 253 | size_t i; |
267 | else if (strcasecmp(strval, "BottomLeft") == 0) | 254 | for (i = 0; i < sizeof(placement_strings)/sizeof(TabPlacementString); ++i) { |
268 | m_value = FbWinFrame::BOTTOMLEFT; | 255 | if (strcasecmp(strval, placement_strings[i].str) == 0) { |
269 | else if (strcasecmp(strval, "Top") == 0) | 256 | m_value = placement_strings[i].placement; |
270 | m_value = FbWinFrame::TOP; | 257 | return; |
271 | else if (strcasecmp(strval, "Bottom") == 0) | 258 | } |
272 | m_value = FbWinFrame::BOTTOM; | 259 | } |
273 | else if (strcasecmp(strval, "TopRight") == 0) | 260 | setDefaultValue(); |
274 | m_value = FbWinFrame::TOPRIGHT; | ||
275 | else if (strcasecmp(strval, "BottomRight") == 0) | ||
276 | m_value = FbWinFrame::BOTTOMRIGHT; | ||
277 | else if (strcasecmp(strval, "LeftTop") == 0) | ||
278 | m_value = FbWinFrame::LEFTTOP; | ||
279 | else if (strcasecmp(strval, "Left") == 0) | ||
280 | m_value = FbWinFrame::LEFT; | ||
281 | else if (strcasecmp(strval, "LeftBottom") == 0) | ||
282 | m_value = FbWinFrame::LEFTBOTTOM; | ||
283 | else if (strcasecmp(strval, "RightTop") == 0) | ||
284 | m_value = FbWinFrame::RIGHTTOP; | ||
285 | else if (strcasecmp(strval, "Right") == 0) | ||
286 | m_value = FbWinFrame::RIGHT; | ||
287 | else if (strcasecmp(strval, "RightBottom") == 0) | ||
288 | m_value = FbWinFrame::RIGHTBOTTOM; | ||
289 | else | ||
290 | setDefaultValue(); | ||
291 | } | 261 | } |
292 | 262 | ||
293 | } // end namespace FbTk | 263 | } // end namespace FbTk |
@@ -1650,40 +1620,39 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { | |||
1650 | tab_width_item->setCommand(save_and_reconftabs); | 1620 | tab_width_item->setCommand(save_and_reconftabs); |
1651 | tab_menu->insert(tab_width_item); | 1621 | tab_menu->insert(tab_width_item); |
1652 | 1622 | ||
1653 | |||
1654 | typedef pair<FbTk::FbString, FbWinFrame::TabPlacement> PlacementP; | ||
1655 | typedef list<PlacementP> Placements; | ||
1656 | Placements place_menu; | ||
1657 | |||
1658 | // menu is 3 wide, 5 down | 1623 | // menu is 3 wide, 5 down |
1659 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT)); | 1624 | struct PlacementP { |
1660 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP)); | 1625 | const FbTk::FbString label; |
1661 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT)); | 1626 | FbWinFrame::TabPlacement placement; |
1662 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM)); | 1627 | }; |
1663 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT)); | 1628 | static const PlacementP place_menu[] = { |
1664 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP)); | 1629 | |
1665 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1630 | { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT}, |
1666 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1631 | { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP}, |
1667 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1632 | { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT}, |
1668 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM)); | 1633 | { _FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM}, |
1669 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT)); | 1634 | { _FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT}, |
1670 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP)); | 1635 | { _FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP}, |
1671 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT)); | 1636 | { "", FbWinFrame::TOPLEFT}, |
1672 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM)); | 1637 | { "", FbWinFrame::TOPLEFT}, |
1673 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT)); | 1638 | { "", FbWinFrame::TOPLEFT}, |
1639 | { _FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM}, | ||
1640 | { _FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT}, | ||
1641 | { _FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP}, | ||
1642 | { _FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT}, | ||
1643 | { _FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM}, | ||
1644 | { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT} | ||
1645 | }; | ||
1674 | 1646 | ||
1675 | tabplacement_menu->setMinimumSublevels(3); | 1647 | tabplacement_menu->setMinimumSublevels(3); |
1676 | // create items in sub menu | 1648 | // create items in sub menu |
1677 | for (size_t i=0; i<15; ++i) { | 1649 | for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { |
1678 | FbTk::FbString &str = place_menu.front().first; | 1650 | const PlacementP& p = place_menu[i]; |
1679 | FbWinFrame::TabPlacement placement = place_menu.front().second; | 1651 | if (p.label == "") { |
1680 | if (str == "") { | 1652 | tabplacement_menu->insert(p.label); |
1681 | tabplacement_menu->insert(""); | ||
1682 | tabplacement_menu->setItemEnabled(i, false); | 1653 | tabplacement_menu->setItemEnabled(i, false); |
1683 | } else { | 1654 | } else |
1684 | tabplacement_menu->insert(new TabPlacementMenuItem(str, *this, placement, save_and_reconftabs)); | 1655 | tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); |
1685 | } | ||
1686 | place_menu.pop_front(); | ||
1687 | } | 1656 | } |
1688 | tabplacement_menu->updateMenu(); | 1657 | tabplacement_menu->updateMenu(); |
1689 | 1658 | ||