aboutsummaryrefslogtreecommitdiff
path: root/src/LayerMenu.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/LayerMenu.hh')
-rw-r--r--src/LayerMenu.hh112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/LayerMenu.hh b/src/LayerMenu.hh
new file mode 100644
index 0000000..1afedb5
--- /dev/null
+++ b/src/LayerMenu.hh
@@ -0,0 +1,112 @@
1// LayerMenu.hh for Fluxbox - fluxbox toolkit
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: LayerMenu.hh,v 1.7 2003/12/10 23:08:03 fluxgen Exp $
24
25#ifndef LAYERMENU_HH
26#define LAYERMENU_HH
27
28#include "MenuItem.hh"
29#include "FbMenu.hh"
30#include "RefCount.hh"
31#include "SimpleCommand.hh"
32
33#include "fluxbox.hh"
34
35// provides a generic way for giving an object a layer menu
36
37/// this class holds the layermenu items
38template <typename ItemType>
39class LayerMenuItem : public FbTk::MenuItem {
40public:
41 LayerMenuItem(const char *label, ItemType *object, int layernum,
42 FbTk::RefCount<FbTk::Command> &cmd):
43 FbTk::MenuItem(label,cmd), m_object(object), m_layernum(layernum) {}
44 LayerMenuItem(const char *label, ItemType *object, int layernum):
45 FbTk::MenuItem(label), m_object(object), m_layernum(layernum) {}
46
47 bool isEnabled() const { return m_object->layerItem().getLayerNum() != m_layernum; } ;
48 void click(int button, int time) {
49 m_object->moveToLayer(m_layernum);
50 FbTk::MenuItem::click(button, time);
51 }
52
53private:
54 ItemType *m_object;
55 int m_layernum;
56};
57
58
59/// Create a layer menu inside from the given menu
60template <typename ItemType>
61class LayerMenu : public FbMenu {
62public:
63 LayerMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
64 FbTk::XLayer &layer, ItemType *item, bool save_rc);
65
66private:
67 ItemType *m_object;
68};
69
70
71template <typename ItemType>
72LayerMenu<ItemType>::LayerMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
73 FbTk::XLayer &layer, ItemType *item, bool save_rc):
74 FbMenu(tm, imgctrl, layer),
75 m_object(item)
76{
77
78 Fluxbox *fluxbox = Fluxbox::instance();
79
80 struct {
81 int set;
82 int base;
83 const char *default_str;
84 int layernum;
85 } layer_menuitems[] = {
86 //TODO: nls
87 {0, 0, "Above Dock", fluxbox->getAboveDockLayer()},
88 {0, 0, "Dock", fluxbox->getDockLayer()},
89 {0, 0, "Top", fluxbox->getTopLayer()},
90 {0, 0, "Normal", fluxbox->getNormalLayer()},
91 {0, 0, "Bottom", fluxbox->getBottomLayer()},
92 {0, 0, "Desktop", fluxbox->getDesktopLayer()},
93 };
94
95 FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
96 *Fluxbox::instance(),
97 &Fluxbox::save_rc));
98
99 for (size_t i=0; i < 6; ++i) {
100 // TODO: fetch nls string
101 if (save_rc) {
102 insert(new LayerMenuItem<ItemType>(layer_menuitems[i].default_str,
103 m_object, layer_menuitems[i].layernum, saverc_cmd));
104 } else {
105 insert(new LayerMenuItem<ItemType>(layer_menuitems[i].default_str,
106 m_object, layer_menuitems[i].layernum));
107 }
108 }
109 update();
110}
111
112#endif // LAYERMENU_HH