aboutsummaryrefslogtreecommitdiff
path: root/src/LayerMenu.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/LayerMenu.hh')
-rw-r--r--src/LayerMenu.hh115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/LayerMenu.hh b/src/LayerMenu.hh
new file mode 100644
index 0000000..6b13179
--- /dev/null
+++ b/src/LayerMenu.hh
@@ -0,0 +1,115 @@
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.4 2003/05/15 11:17:27 fluxgen Exp $
24
25#ifndef LAYERMENU_HH
26#define LAYERMENU_HH
27
28#include "MenuItem.hh"
29#include "FbMenu.hh"
30#include "FbCommands.hh"
31#include "RefCount.hh"
32#include "SimpleCommand.hh"
33
34#include "fluxbox.hh"
35
36// provides a generic way for giving an object a layer menu
37
38/// this class holds the layermenu items
39template <typename ItemType>
40class LayerMenuItem : public FbTk::MenuItem {
41public:
42 LayerMenuItem(const char *label, ItemType *object, int layernum,
43 FbTk::RefCount<FbTk::Command> &cmd):
44 FbTk::MenuItem(label,cmd), m_object(object), m_layernum(layernum) {}
45 LayerMenuItem(const char *label, ItemType *object, int layernum):
46 FbTk::MenuItem(label), m_object(object), m_layernum(layernum) {}
47
48 bool isEnabled() const { return m_object->layerItem().getLayerNum() != m_layernum; } ;
49 void click(int button, int time) {
50 m_object->moveToLayer(m_layernum);
51 FbTk::MenuItem::click(button, time);
52 }
53
54private:
55 ItemType *m_object;
56 int m_layernum;
57};
58
59
60/// Create a layer menu inside from the given menu
61template <typename ItemType>
62class LayerMenu : public FbMenu {
63public:
64 LayerMenu(FbTk::MenuTheme &tm, int screen_num, FbTk::ImageControl &imgctrl,
65 FbTk::XLayer &layer, ItemType *item, bool save_rc);
66
67private:
68 ItemType *m_object;
69};
70
71
72template <typename ItemType>
73LayerMenu<ItemType>::LayerMenu(FbTk::MenuTheme &tm, int screen_num, FbTk::ImageControl &imgctrl,
74 FbTk::XLayer &layer, ItemType *item, bool save_rc):
75 FbMenu(tm, screen_num, imgctrl, layer),
76 m_object(item)
77{
78
79 Fluxbox *fluxbox = Fluxbox::instance();
80
81 struct {
82 int set;
83 int base;
84 const char *default_str;
85 int layernum;
86 } layer_menuitems[] = {
87 //TODO: nls
88 {0, 0, "Above Dock", fluxbox->getAboveDockLayer()},
89 {0, 0, "Dock", fluxbox->getDockLayer()},
90 {0, 0, "Top", fluxbox->getTopLayer()},
91 {0, 0, "Normal", fluxbox->getNormalLayer()},
92 {0, 0, "Bottom", fluxbox->getBottomLayer()},
93 {0, 0, "Desktop", fluxbox->getDesktopLayer()},
94 };
95
96 FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
97 *Fluxbox::instance(),
98 &Fluxbox::save_rc));
99
100 for (size_t i=0; i < 6; ++i) {
101 // TODO: fetch nls string
102 if (save_rc) {
103 insert(new LayerMenuItem<ItemType>(
104 layer_menuitems[i].default_str,
105 m_object, layer_menuitems[i].layernum, saverc_cmd));
106 } else {
107 insert(new LayerMenuItem<ItemType>(
108 layer_menuitems[i].default_str,
109 m_object, layer_menuitems[i].layernum));
110 }
111 }
112 update();
113}
114
115#endif // LAYERMENU_HH