diff options
Diffstat (limited to 'src/Screen.cc')
-rw-r--r-- | src/Screen.cc | 162 |
1 files changed, 66 insertions, 96 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 0677a14..daa87dc 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 |
@@ -1649,41 +1619,41 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { | |||
1649 | tab_width_item->setCommand(save_and_reconftabs); | 1619 | tab_width_item->setCommand(save_and_reconftabs); |
1650 | tab_menu->insert(tab_width_item); | 1620 | tab_menu->insert(tab_width_item); |
1651 | 1621 | ||
1652 | |||
1653 | typedef pair<FbTk::FbString, FbWinFrame::TabPlacement> PlacementP; | ||
1654 | typedef list<PlacementP> Placements; | ||
1655 | Placements place_menu; | ||
1656 | |||
1657 | // menu is 3 wide, 5 down | 1622 | // menu is 3 wide, 5 down |
1658 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT)); | 1623 | struct PlacementP { |
1659 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP)); | 1624 | const FbTk::FbString label; |
1660 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT)); | 1625 | FbWinFrame::TabPlacement placement; |
1661 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM)); | 1626 | }; |
1662 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT)); | 1627 | static const PlacementP place_menu[] = { |
1663 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP)); | 1628 | |
1664 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1629 | { _FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), FbWinFrame::TOPLEFT}, |
1665 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1630 | { _FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), FbWinFrame::LEFTTOP}, |
1666 | place_menu.push_back(PlacementP("", FbWinFrame::TOPLEFT)); | 1631 | { _FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), FbWinFrame::LEFT}, |
1667 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM)); | 1632 | { _FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), FbWinFrame::LEFTBOTTOM}, |
1668 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT)); | 1633 | { _FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), FbWinFrame::BOTTOMLEFT}, |
1669 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP)); | 1634 | { _FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), FbWinFrame::TOP}, |
1670 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT)); | 1635 | { "", FbWinFrame::TOPLEFT}, |
1671 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM)); | 1636 | { "", FbWinFrame::TOPLEFT}, |
1672 | place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT)); | 1637 | { "", FbWinFrame::TOPLEFT}, |
1638 | { _FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), FbWinFrame::BOTTOM}, | ||
1639 | { _FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), FbWinFrame::TOPRIGHT}, | ||
1640 | { _FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), FbWinFrame::RIGHTTOP}, | ||
1641 | { _FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), FbWinFrame::RIGHT}, | ||
1642 | { _FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), FbWinFrame::RIGHTBOTTOM}, | ||
1643 | { _FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), FbWinFrame::BOTTOMRIGHT} | ||
1644 | }; | ||
1673 | 1645 | ||
1674 | tabplacement_menu->setMinimumSublevels(3); | 1646 | tabplacement_menu->setMinimumSublevels(3); |
1675 | // create items in sub menu | 1647 | // create items in sub menu |
1676 | for (size_t i=0; i<15; ++i) { | 1648 | for (size_t i=0; i< sizeof(place_menu)/sizeof(PlacementP); ++i) { |
1677 | FbTk::FbString &str = place_menu.front().first; | 1649 | const PlacementP& p = place_menu[i]; |
1678 | FbWinFrame::TabPlacement placement = place_menu.front().second; | 1650 | if (p.label == "") { |
1679 | if (str == "") { | 1651 | tabplacement_menu->insert(p.label); |
1680 | tabplacement_menu->insert(""); | ||
1681 | tabplacement_menu->setItemEnabled(i, false); | 1652 | tabplacement_menu->setItemEnabled(i, false); |
1682 | } else { | 1653 | } else |
1683 | tabplacement_menu->insert(new TabPlacementMenuItem(str, *this, placement, save_and_reconftabs)); | 1654 | tabplacement_menu->insert(new TabPlacementMenuItem(p.label, *this, p.placement, save_and_reconftabs)); |
1684 | } | ||
1685 | place_menu.pop_front(); | ||
1686 | } | 1655 | } |
1656 | |||
1687 | tabplacement_menu->updateMenu(); | 1657 | tabplacement_menu->updateMenu(); |
1688 | 1658 | ||
1689 | menu.insert(tabmenu_label, tab_menu); | 1659 | menu.insert(tabmenu_label, tab_menu); |