diff options
author | rathnor <rathnor> | 2003-03-03 21:51:13 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2003-03-03 21:51:13 (GMT) |
commit | 19875e5a5ba474387971ede597cdc4aa7454d4c0 (patch) | |
tree | 99d672abcffa86d74734deacbd888eccde02ffd2 /src/ToolbarHandler.cc | |
parent | 824fd0db7a4b8117fecba9bb46053bdd38691803 (diff) | |
download | fluxbox_pavel-19875e5a5ba474387971ede597cdc4aa7454d4c0.zip fluxbox_pavel-19875e5a5ba474387971ede597cdc4aa7454d4c0.tar.bz2 |
Add code for toolbar modes
Diffstat (limited to 'src/ToolbarHandler.cc')
-rw-r--r-- | src/ToolbarHandler.cc | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/src/ToolbarHandler.cc b/src/ToolbarHandler.cc new file mode 100644 index 0000000..f05f399 --- /dev/null +++ b/src/ToolbarHandler.cc | |||
@@ -0,0 +1,295 @@ | |||
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.1 2003/03/03 21:51:09 rathnor 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 | namespace { | ||
45 | |||
46 | class ToolbarModeMenuItem : public FbTk::MenuItem { | ||
47 | public: | ||
48 | ToolbarModeMenuItem(const char *label, ToolbarHandler &handler, ToolbarHandler::ToolbarMode mode, FbTk::RefCount<FbTk::Command> &cmd): | ||
49 | FbTk::MenuItem(label, cmd), m_handler(handler), m_mode(mode) { | ||
50 | } | ||
51 | bool isEnabled() const { return m_handler.getMode() != m_mode; } | ||
52 | void click(int button, int time) { | ||
53 | m_handler.setMode(m_mode); | ||
54 | FbTk::MenuItem::click(button, time); | ||
55 | } | ||
56 | |||
57 | private: | ||
58 | ToolbarHandler &m_handler; | ||
59 | ToolbarHandler::ToolbarMode m_mode; | ||
60 | }; | ||
61 | |||
62 | void setupModeMenu(FbTk::Menu &menu, ToolbarHandler &handler) { | ||
63 | //I18n *i18n = I18n::instance(); | ||
64 | //using namespace FBNLS; | ||
65 | using namespace FbTk; | ||
66 | |||
67 | RefCount<Command> saverc_cmd(new SimpleCommand<Fluxbox>( | ||
68 | *Fluxbox::instance(), | ||
69 | &Fluxbox::save_rc)); | ||
70 | |||
71 | //TODO: nls | ||
72 | menu.insert(new ToolbarModeMenuItem("Off", handler, | ||
73 | ToolbarHandler::OFF, saverc_cmd)); | ||
74 | menu.insert(new ToolbarModeMenuItem("None", handler, | ||
75 | ToolbarHandler::NONE, saverc_cmd)); | ||
76 | menu.insert(new ToolbarModeMenuItem("Icons", handler, | ||
77 | ToolbarHandler::ICONS, saverc_cmd)); | ||
78 | menu.insert(new ToolbarModeMenuItem("Workspace Icons", handler, | ||
79 | ToolbarHandler::WORKSPACEICONS, saverc_cmd)); | ||
80 | menu.insert(new ToolbarModeMenuItem("Workspace", handler, | ||
81 | ToolbarHandler::WORKSPACE, saverc_cmd)); | ||
82 | menu.insert(new ToolbarModeMenuItem("All Windows", handler, | ||
83 | ToolbarHandler::ALLWINDOWS, saverc_cmd)); | ||
84 | menu.update(); | ||
85 | } | ||
86 | |||
87 | }; // end anonymous namespace | ||
88 | |||
89 | ToolbarHandler::ToolbarHandler(BScreen &screen, ToolbarMode mode) | ||
90 | : m_screen(screen), m_mode(mode), m_toolbar(0), m_current_workspace(0), | ||
91 | m_modemenu(*screen.menuTheme(), | ||
92 | screen.getScreenNumber(), *screen.getImageControl()), | ||
93 | m_toolbarmenu(*screen.menuTheme(), | ||
94 | screen.getScreenNumber(), *screen.getImageControl()) | ||
95 | { | ||
96 | m_modemenu.setInternalMenu(); | ||
97 | setupModeMenu(m_modemenu, *this); | ||
98 | setMode(mode, false); // the atomhandler part will initialise it shortly | ||
99 | } | ||
100 | |||
101 | void ToolbarHandler::setMode(ToolbarMode mode, bool initialise) { | ||
102 | if (mode < 0 || mode >= LASTMODE || (mode == m_mode && initialise)) return; | ||
103 | if (mode == OFF) { | ||
104 | m_toolbarmenu.removeAll(); | ||
105 | //TODO: nls | ||
106 | m_toolbarmenu.insert("Mode...", &m_modemenu); | ||
107 | m_toolbar.reset(0); | ||
108 | m_toolbarmenu.update(); | ||
109 | return; | ||
110 | } else if (!m_toolbar.get()) { | ||
111 | m_toolbarmenu.removeAll(); | ||
112 | |||
113 | m_toolbarmenu.insert("Mode...", &m_modemenu); | ||
114 | m_toolbar.reset(new Toolbar(m_screen, | ||
115 | *m_screen.layerManager().getLayer(m_screen.getToolbarLayerNum()), m_toolbarmenu)); | ||
116 | |||
117 | } | ||
118 | |||
119 | |||
120 | if (mode == NONE) { | ||
121 | // disableIconBar will clean up | ||
122 | m_toolbar->disableIconBar(); | ||
123 | } else { | ||
124 | // rebuild it | ||
125 | // be sure the iconbar is on | ||
126 | m_toolbar->enableIconBar(); | ||
127 | m_toolbar->delAllIcons(); | ||
128 | } | ||
129 | // reset Toolbar, and reload it (initForScreen) | ||
130 | m_mode = mode; | ||
131 | if (initialise) | ||
132 | initForScreen(m_screen); | ||
133 | } | ||
134 | |||
135 | void ToolbarHandler::initForScreen(BScreen &screen) { | ||
136 | if (&m_screen != &screen) return; | ||
137 | switch (m_mode) { | ||
138 | case OFF: | ||
139 | break; | ||
140 | case NONE: | ||
141 | break; | ||
142 | case ALLWINDOWS: | ||
143 | { | ||
144 | BScreen::Workspaces::const_iterator workspace_it = m_screen.getWorkspacesList().begin(); | ||
145 | BScreen::Workspaces::const_iterator workspace_it_end = m_screen.getWorkspacesList().end(); | ||
146 | for (; workspace_it != workspace_it_end; ++workspace_it) { | ||
147 | Workspace::Windows &wins = (*workspace_it)->getWindowList(); | ||
148 | Workspace::Windows::iterator wit = wins.begin(); | ||
149 | Workspace::Windows::iterator wit_end = wins.end(); | ||
150 | for (; wit != wit_end; ++wit) { | ||
151 | m_toolbar->addIcon(*wit); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | // fall through and add icons | ||
156 | case LASTMODE: | ||
157 | case ICONS: | ||
158 | { | ||
159 | BScreen::Icons &iconlist = m_screen.getIconList(); | ||
160 | BScreen::Icons::iterator iconit = iconlist.begin(); | ||
161 | BScreen::Icons::iterator iconit_end = iconlist.end(); | ||
162 | for(; iconit != iconit_end; ++iconit) { | ||
163 | m_toolbar->addIcon(*iconit); | ||
164 | } | ||
165 | } | ||
166 | break; | ||
167 | case WORKSPACE: | ||
168 | { | ||
169 | Workspace::Windows &wins = m_screen.getCurrentWorkspace()->getWindowList(); | ||
170 | Workspace::Windows::iterator wit = wins.begin(); | ||
171 | Workspace::Windows::iterator wit_end = wins.end(); | ||
172 | for (; wit != wit_end; ++wit) { | ||
173 | m_toolbar->addIcon(*wit); | ||
174 | } | ||
175 | } | ||
176 | // fall through and add icons for this workspace | ||
177 | case WORKSPACEICONS: | ||
178 | { | ||
179 | m_current_workspace = m_screen.getCurrentWorkspaceID(); | ||
180 | |||
181 | BScreen::Icons &wiconlist = m_screen.getIconList(); | ||
182 | BScreen::Icons::iterator iconit = wiconlist.begin(); | ||
183 | BScreen::Icons::iterator iconit_end = wiconlist.end(); | ||
184 | for(; iconit != iconit_end; ++iconit) { | ||
185 | if ((*iconit)->getWorkspaceNumber() == m_current_workspace) | ||
186 | m_toolbar->addIcon(*iconit); | ||
187 | } | ||
188 | } | ||
189 | break; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | void ToolbarHandler::setupWindow(FluxboxWindow &win) { | ||
194 | if (win.getScreen() != &m_screen) return; | ||
195 | switch (m_mode) { | ||
196 | case OFF: | ||
197 | case NONE: | ||
198 | break; | ||
199 | case WORKSPACE: | ||
200 | if (win.getWorkspaceNumber() == m_current_workspace) | ||
201 | m_toolbar->addIcon(&win); | ||
202 | break; | ||
203 | case WORKSPACEICONS: | ||
204 | if (win.getWorkspaceNumber() != m_current_workspace) | ||
205 | break; | ||
206 | // else fall through and add the icon | ||
207 | case LASTMODE: | ||
208 | case ICONS: | ||
209 | if (win.isIconic()) { | ||
210 | m_toolbar->addIcon(&win); | ||
211 | } | ||
212 | break; | ||
213 | case ALLWINDOWS: | ||
214 | m_toolbar->addIcon(&win); | ||
215 | break; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | void ToolbarHandler::updateWindowClose(FluxboxWindow &win) { | ||
220 | if (win.getScreen() != &m_screen) return; | ||
221 | // check status of window (in current workspace, etc) and remove if necessary | ||
222 | switch (m_mode) { | ||
223 | case OFF: | ||
224 | case NONE: | ||
225 | break; | ||
226 | case WORKSPACEICONS: | ||
227 | if (win.getWorkspaceNumber() != m_current_workspace) | ||
228 | break; | ||
229 | // else fall through and remove the icon | ||
230 | case LASTMODE: | ||
231 | case ICONS: | ||
232 | if (win.isIconic()) { | ||
233 | m_toolbar->delIcon(&win); | ||
234 | } | ||
235 | break; | ||
236 | case WORKSPACE: | ||
237 | if (win.getWorkspaceNumber() == m_current_workspace) | ||
238 | m_toolbar->delIcon(&win); | ||
239 | break; | ||
240 | case ALLWINDOWS: | ||
241 | m_toolbar->delIcon(&win); | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | void ToolbarHandler::updateState(FluxboxWindow &win) { | ||
247 | if (win.getScreen() != &m_screen) return; | ||
248 | |||
249 | // this function only relevant for icons | ||
250 | switch (m_mode) { | ||
251 | case OFF: | ||
252 | case NONE: | ||
253 | case ALLWINDOWS: | ||
254 | break; | ||
255 | case WORKSPACE: | ||
256 | case WORKSPACEICONS: | ||
257 | if (win.getWorkspaceNumber() != m_current_workspace) break; | ||
258 | // else fall through and do the same as icons (knowing it is the right ws) | ||
259 | case LASTMODE: | ||
260 | case ICONS: | ||
261 | // if the window is iconic (it mustn't have been before), then add it | ||
262 | // else remove it | ||
263 | if (win.isIconic()) { | ||
264 | if (!m_toolbar->containsIcon(win)) { | ||
265 | m_toolbar->addIcon(&win); | ||
266 | } | ||
267 | } else { | ||
268 | m_toolbar->delIcon(&win); | ||
269 | } | ||
270 | break; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | |||
275 | void ToolbarHandler::updateWorkspace(FluxboxWindow &win) { | ||
276 | if (win.getScreen() != &m_screen) return; | ||
277 | // don't care about current workspace except if in workspace mode | ||
278 | if (m_mode != WORKSPACE) return; | ||
279 | if (win.getWorkspaceNumber() == m_current_workspace) { | ||
280 | m_toolbar->addIcon(&win); | ||
281 | } else { | ||
282 | // relies on the fact that this runs but does nothing if window isn't contained. | ||
283 | m_toolbar->delIcon(&win); | ||
284 | } | ||
285 | } | ||
286 | |||
287 | void ToolbarHandler::updateCurrentWorkspace(BScreen &screen) { | ||
288 | if (&screen != &m_screen) return; | ||
289 | // if only displaying current workspace, update list | ||
290 | // otherwise ignore it | ||
291 | if (m_mode != WORKSPACE && m_mode != WORKSPACEICONS) return; | ||
292 | m_toolbar->delAllIcons(); | ||
293 | initForScreen(m_screen); | ||
294 | } | ||
295 | |||