diff options
Diffstat (limited to 'src/ToolbarHandler.cc')
-rw-r--r-- | src/ToolbarHandler.cc | 323 |
1 files changed, 323 insertions, 0 deletions
diff --git a/src/ToolbarHandler.cc b/src/ToolbarHandler.cc new file mode 100644 index 0000000..59215e4 --- /dev/null +++ b/src/ToolbarHandler.cc | |||
@@ -0,0 +1,323 @@ | |||
1 | // ToolbarHandler for fluxbox | ||
2 | // Copyright (c) 2003 Simon Bowden (rathnor at fluxbox.org) | ||
3 | // and Henrik Kinnunen (fluxgen at fluxbox.org) | ||
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: ToolbarHandler.cc,v 1.27 2003/08/11 20:51:32 fluxgen Exp $ | ||
24 | |||
25 | /** | ||
26 | * The ToolbarHandler class acts as a rough interface to the toolbar. | ||
27 | * It deals with whether it should be there or not, so anything that | ||
28 | * always needs to be accessible must come through the handler. | ||
29 | */ | ||
30 | |||
31 | #include "ToolbarHandler.hh" | ||
32 | #include "Window.hh" | ||
33 | #include "Screen.hh" | ||
34 | #include "Workspace.hh" | ||
35 | #include "MenuItem.hh" | ||
36 | #include "Menu.hh" | ||
37 | #include "FbCommands.hh" | ||
38 | #include "RefCount.hh" | ||
39 | #include "SimpleCommand.hh" | ||
40 | #include "MacroCommand.hh" | ||
41 | #include "IntResMenuItem.hh" | ||
42 | #include "BoolMenuItem.hh" | ||
43 | |||
44 | #include <string> | ||
45 | |||
46 | using namespace std; | ||
47 | |||
48 | template<> | ||
49 | void FbTk::Resource<ToolbarHandler::ToolbarMode>:: | ||
50 | setFromString(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 | |||
68 | template<> | ||
69 | string FbTk::Resource<ToolbarHandler::ToolbarMode>:: | ||
70 | getString() { | ||
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 | |||
96 | namespace { | ||
97 | |||
98 | class ToolbarModeMenuItem : public FbTk::MenuItem { | ||
99 | public: | ||
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 | |||
111 | private: | ||
112 | ToolbarHandler &m_handler; | ||
113 | ToolbarHandler::ToolbarMode m_mode; | ||
114 | }; | ||
115 | |||
116 | void 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 | |||
146 | ToolbarHandler::ToolbarHandler(BScreen &screen) | ||
147 | : m_screen(screen), | ||
148 | // 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), | ||
152 | m_current_workspace(0), | ||
153 | m_modemenu(*screen.menuTheme(), | ||
154 | screen.screenNumber(), screen.imageControl()), | ||
155 | m_toolbarmenu(*screen.menuTheme(), | ||
156 | screen.screenNumber(), screen.imageControl()) { | ||
157 | m_modemenu.setInternalMenu(); | ||
158 | m_toolbarmenu.setInternalMenu(); | ||
159 | setupModeMenu(m_modemenu, *this); | ||
160 | setMode(*m_rc_mode, false); // the atomhandler part will initialise it shortly | ||
161 | // now add this to the config menus for the screen | ||
162 | // (we only want it done once, so it can't go in initforscreen) | ||
163 | |||
164 | screen.addConfigMenu("Toolbar", m_toolbarmenu); | ||
165 | enableUpdate(); | ||
166 | } | ||
167 | |||
168 | void ToolbarHandler::setMode(ToolbarMode newmode, bool initialise) { | ||
169 | if (newmode < 0 || newmode >= LASTMODE || (newmode == mode() && initialise)) | ||
170 | return; | ||
171 | |||
172 | *m_rc_mode = newmode; | ||
173 | |||
174 | if (newmode == OFF) { | ||
175 | m_toolbarmenu.removeAll(); | ||
176 | //TODO: nls | ||
177 | m_toolbarmenu.insert("Mode...", &m_modemenu); | ||
178 | m_toolbar.reset(0); | ||
179 | m_toolbarmenu.update(); | ||
180 | |||
181 | return; | ||
182 | } else if (!m_toolbar.get()) { | ||
183 | m_toolbarmenu.removeAll(); | ||
184 | m_toolbar.reset(new Toolbar(m_screen, | ||
185 | *m_screen.layerManager().getLayer(Fluxbox::instance()->getNormalLayer()), m_toolbarmenu)); | ||
186 | m_toolbar->reconfigure(); | ||
187 | |||
188 | m_toolbarmenu.insert("Mode...", &m_modemenu); | ||
189 | m_toolbarmenu.update(); | ||
190 | } | ||
191 | |||
192 | |||
193 | if (newmode == NONE) { | ||
194 | //!! TODO disable iconbar | ||
195 | } else { | ||
196 | // rebuild it | ||
197 | // be sure the iconbar is on | ||
198 | //!! TODO enable iconbar | ||
199 | } | ||
200 | |||
201 | if (initialise) | ||
202 | initForScreen(m_screen); | ||
203 | } | ||
204 | |||
205 | void ToolbarHandler::initForScreen(BScreen &screen) { | ||
206 | if (&m_screen != &screen) | ||
207 | return; | ||
208 | |||
209 | switch (mode()) { | ||
210 | case OFF: | ||
211 | break; | ||
212 | case NONE: | ||
213 | break; | ||
214 | case ALLWINDOWS: | ||
215 | //!! TODO: change iconbar mode | ||
216 | |||
217 | // fall through and add icons | ||
218 | case LASTMODE: | ||
219 | case ICONS: | ||
220 | //!! TODO: update iconbar mode | ||
221 | break; | ||
222 | case WORKSPACE: | ||
223 | //!! TODO: update iconbar mode | ||
224 | |||
225 | // fall through and add icons for this workspace | ||
226 | case WORKSPACEICONS: | ||
227 | //!! TODO: update iconbar mode | ||
228 | break; | ||
229 | } | ||
230 | |||
231 | } | ||
232 | |||
233 | void ToolbarHandler::setupFrame(FluxboxWindow &win) { | ||
234 | if (&win.screen() != &m_screen) | ||
235 | return; | ||
236 | |||
237 | switch (mode()) { | ||
238 | case OFF: | ||
239 | case NONE: | ||
240 | break; | ||
241 | case WORKSPACE: | ||
242 | break; | ||
243 | case WORKSPACEICONS: | ||
244 | break; | ||
245 | // else fall through and add the icon | ||
246 | case LASTMODE: | ||
247 | case ICONS: | ||
248 | break; | ||
249 | case ALLWINDOWS: | ||
250 | break; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | void ToolbarHandler::updateFrameClose(FluxboxWindow &win) { | ||
255 | if (&win.screen() != &m_screen) | ||
256 | return; | ||
257 | |||
258 | // check status of window (in current workspace, etc) and remove if necessary | ||
259 | switch (mode()) { | ||
260 | case OFF: | ||
261 | case NONE: | ||
262 | break; | ||
263 | case WORKSPACEICONS: | ||
264 | if (win.workspaceNumber() != m_current_workspace) | ||
265 | break; | ||
266 | // else fall through and remove the icon | ||
267 | case LASTMODE: | ||
268 | case ICONS: | ||
269 | break; | ||
270 | case WORKSPACE: | ||
271 | break; | ||
272 | case ALLWINDOWS: | ||
273 | break; | ||
274 | } | ||
275 | } | ||
276 | |||
277 | void ToolbarHandler::updateState(FluxboxWindow &win) { | ||
278 | if (&win.screen() != &m_screen) | ||
279 | return; | ||
280 | |||
281 | // this function only relevant for icons | ||
282 | switch (mode()) { | ||
283 | case OFF: | ||
284 | case NONE: | ||
285 | case WORKSPACE: | ||
286 | case ALLWINDOWS: | ||
287 | break; | ||
288 | case WORKSPACEICONS: | ||
289 | if (win.workspaceNumber() != m_current_workspace) | ||
290 | break; | ||
291 | // else fall through and do the same as icons (knowing it is the right ws) | ||
292 | case LASTMODE: | ||
293 | case ICONS: | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | |||
299 | void ToolbarHandler::updateWorkspace(FluxboxWindow &win) { | ||
300 | if (&win.screen() != &m_screen) | ||
301 | return; | ||
302 | |||
303 | // don't care about current workspace except if in workspace mode | ||
304 | if (!(mode() == WORKSPACE || | ||
305 | (mode() == WORKSPACEICONS && win.isIconic()))) | ||
306 | return; | ||
307 | |||
308 | if (win.workspaceNumber() == m_current_workspace) { | ||
309 | |||
310 | } else { | ||
311 | |||
312 | } | ||
313 | } | ||
314 | |||
315 | void ToolbarHandler::updateCurrentWorkspace(BScreen &screen) { | ||
316 | if (&screen != &m_screen || mode() == OFF) | ||
317 | return; | ||
318 | |||
319 | if (mode() != NONE) | ||
320 | initForScreen(m_screen); | ||
321 | |||
322 | } | ||
323 | |||