aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ToolbarHandler.cc112
-rw-r--r--src/ToolbarHandler.hh8
2 files changed, 10 insertions, 110 deletions
diff --git a/src/ToolbarHandler.cc b/src/ToolbarHandler.cc
index 59215e4..f6fd015 100644
--- a/src/ToolbarHandler.cc
+++ b/src/ToolbarHandler.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: ToolbarHandler.cc,v 1.27 2003/08/11 20:51:32 fluxgen Exp $ 23// $Id: ToolbarHandler.cc,v 1.28 2003/09/08 18:18:25 fluxgen Exp $
24 24
25/** 25/**
26 * The ToolbarHandler class acts as a rough interface to the toolbar. 26 * The ToolbarHandler class acts as a rough interface to the toolbar.
@@ -45,109 +45,9 @@
45 45
46using namespace std; 46using namespace std;
47 47
48template<>
49void FbTk::Resource<ToolbarHandler::ToolbarMode>::
50setFromString(const char *strval) {
51 if (strcasecmp(strval, "Off") == 0)
52 m_value = ToolbarHandler::OFF;
53 else if (strcasecmp(strval, "None") == 0)
54 m_value = ToolbarHandler::NONE;
55 else if (strcasecmp(strval, "Icons") == 0)
56 m_value = ToolbarHandler::ICONS;
57 else if (strcasecmp(strval, "WorkspaceIcons") == 0)
58 m_value = ToolbarHandler::WORKSPACEICONS;
59 else if (strcasecmp(strval, "Workspace") == 0)
60 m_value = ToolbarHandler::WORKSPACE;
61 else if (strcasecmp(strval, "AllWindows") == 0)
62 m_value = ToolbarHandler::ALLWINDOWS;
63 else
64 setDefaultValue();
65}
66
67
68template<>
69string FbTk::Resource<ToolbarHandler::ToolbarMode>::
70getString() {
71 switch (m_value) {
72 case ToolbarHandler::OFF:
73 return string("Off");
74 break;
75 case ToolbarHandler::NONE:
76 return string("None");
77 break;
78 case ToolbarHandler::LASTMODE:
79 case ToolbarHandler::ICONS:
80 return string("Icons");
81 break;
82 case ToolbarHandler::WORKSPACEICONS:
83 return string("WorkspaceIcons");
84 break;
85 case ToolbarHandler::WORKSPACE:
86 return string("Workspace");
87 break;
88 case ToolbarHandler::ALLWINDOWS:
89 return string("AllWindows");
90 break;
91 }
92 // default string
93 return string("Icons");
94}
95
96namespace {
97
98class ToolbarModeMenuItem : public FbTk::MenuItem {
99public:
100 ToolbarModeMenuItem(const char *label, ToolbarHandler &handler,
101 ToolbarHandler::ToolbarMode mode,
102 FbTk::RefCount<FbTk::Command> &cmd):
103 FbTk::MenuItem(label, cmd), m_handler(handler), m_mode(mode) {
104 }
105 bool isEnabled() const { return m_handler.mode() != m_mode; }
106 void click(int button, int time) {
107 m_handler.setMode(m_mode);
108 FbTk::MenuItem::click(button, time);
109 }
110
111private:
112 ToolbarHandler &m_handler;
113 ToolbarHandler::ToolbarMode m_mode;
114};
115
116void setupModeMenu(FbTk::Menu &menu, ToolbarHandler &handler) {
117 //I18n *i18n = I18n::instance();
118 //using namespace FBNLS;
119 using namespace FbTk;
120
121 // TODO: nls
122 menu.setLabel("Toolbar Mode");
123
124 RefCount<Command> saverc_cmd(new SimpleCommand<Fluxbox>(
125 *Fluxbox::instance(),
126 &Fluxbox::save_rc));
127
128 //TODO: nls
129 menu.insert(new ToolbarModeMenuItem("Off", handler,
130 ToolbarHandler::OFF, saverc_cmd));
131 menu.insert(new ToolbarModeMenuItem("None", handler,
132 ToolbarHandler::NONE, saverc_cmd));
133 menu.insert(new ToolbarModeMenuItem("Icons", handler,
134 ToolbarHandler::ICONS, saverc_cmd));
135 menu.insert(new ToolbarModeMenuItem("Workspace Icons", handler,
136 ToolbarHandler::WORKSPACEICONS, saverc_cmd));
137 menu.insert(new ToolbarModeMenuItem("Workspace", handler,
138 ToolbarHandler::WORKSPACE, saverc_cmd));
139 menu.insert(new ToolbarModeMenuItem("All Windows", handler,
140 ToolbarHandler::ALLWINDOWS, saverc_cmd));
141 menu.update();
142}
143
144}; // end anonymous namespace
145
146ToolbarHandler::ToolbarHandler(BScreen &screen) 48ToolbarHandler::ToolbarHandler(BScreen &screen)
147 : m_screen(screen), 49 : m_screen(screen),
148 // no need to lock since only one resource 50 // no need to lock since only one resource
149 m_rc_mode(screen.resourceManager(), ToolbarHandler::ICONS,
150 screen.name() + ".toolbar.mode", screen.altName() + ".Toolbar.Mode"),
151 m_toolbar(0), 51 m_toolbar(0),
152 m_current_workspace(0), 52 m_current_workspace(0),
153 m_modemenu(*screen.menuTheme(), 53 m_modemenu(*screen.menuTheme(),
@@ -156,8 +56,11 @@ ToolbarHandler::ToolbarHandler(BScreen &screen)
156 screen.screenNumber(), screen.imageControl()) { 56 screen.screenNumber(), screen.imageControl()) {
157 m_modemenu.setInternalMenu(); 57 m_modemenu.setInternalMenu();
158 m_toolbarmenu.setInternalMenu(); 58 m_toolbarmenu.setInternalMenu();
159 setupModeMenu(m_modemenu, *this); 59
160 setMode(*m_rc_mode, false); // the atomhandler part will initialise it shortly 60 m_mode = WORKSPACE;
61 m_toolbar.reset(new Toolbar(m_screen,
62 *m_screen.layerManager().getLayer(Fluxbox::instance()->getNormalLayer()),
63 m_toolbarmenu));
161 // now add this to the config menus for the screen 64 // now add this to the config menus for the screen
162 // (we only want it done once, so it can't go in initforscreen) 65 // (we only want it done once, so it can't go in initforscreen)
163 66
@@ -166,10 +69,9 @@ ToolbarHandler::ToolbarHandler(BScreen &screen)
166} 69}
167 70
168void ToolbarHandler::setMode(ToolbarMode newmode, bool initialise) { 71void ToolbarHandler::setMode(ToolbarMode newmode, bool initialise) {
169 if (newmode < 0 || newmode >= LASTMODE || (newmode == mode() && initialise)) 72 if (newmode < 0 || newmode >= LASTMODE)
170 return; 73 return;
171 74
172 *m_rc_mode = newmode;
173 75
174 if (newmode == OFF) { 76 if (newmode == OFF) {
175 m_toolbarmenu.removeAll(); 77 m_toolbarmenu.removeAll();
diff --git a/src/ToolbarHandler.hh b/src/ToolbarHandler.hh
index 599fd67..02d131d 100644
--- a/src/ToolbarHandler.hh
+++ b/src/ToolbarHandler.hh
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: ToolbarHandler.hh,v 1.7 2003/07/28 15:06:34 rathnor Exp $ 23// $Id: ToolbarHandler.hh,v 1.8 2003/09/08 18:18:25 fluxgen Exp $
24 24
25#ifndef TOOLBARHANDLER_HH 25#ifndef TOOLBARHANDLER_HH
26#define TOOLBARHANDLER_HH 26#define TOOLBARHANDLER_HH
@@ -49,7 +49,6 @@ public:
49 ~ToolbarHandler() { } 49 ~ToolbarHandler() { }
50 50
51 void setMode(ToolbarMode mode, bool initialise = true); 51 void setMode(ToolbarMode mode, bool initialise = true);
52 ToolbarMode mode() const { return *m_rc_mode; };
53 52
54 inline const Toolbar *toolbar() const { return m_toolbar.get(); } 53 inline const Toolbar *toolbar() const { return m_toolbar.get(); }
55 inline Toolbar *toolbar() { return m_toolbar.get(); } 54 inline Toolbar *toolbar() { return m_toolbar.get(); }
@@ -85,13 +84,12 @@ public:
85 84
86 inline BScreen &screen() { return m_screen; } 85 inline BScreen &screen() { return m_screen; }
87 inline const BScreen &screen() const { return m_screen; } 86 inline const BScreen &screen() const { return m_screen; }
88 87 ToolbarMode mode() const { return m_mode; }
89private: 88private:
90 BScreen &m_screen; 89 BScreen &m_screen;
91 FbTk::Resource<ToolbarMode> m_rc_mode;
92 std::auto_ptr<Toolbar> m_toolbar; 90 std::auto_ptr<Toolbar> m_toolbar;
93 unsigned int m_current_workspace; 91 unsigned int m_current_workspace;
94 92 ToolbarMode m_mode;
95 FbTk::Menu m_modemenu; 93 FbTk::Menu m_modemenu;
96 FbTk::Menu m_toolbarmenu; 94 FbTk::Menu m_toolbarmenu;
97}; 95};