diff options
author | fluxgen <fluxgen> | 2003-06-24 16:27:18 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-06-24 16:27:18 (GMT) |
commit | 44fbcc447e957d63696e9e2654d9c52803474ebf (patch) | |
tree | f68476b388595fdb5b62b98be538e8972a723b4c /src/ToolbarHandler.cc | |
parent | 11a0b784b3c3143675ba6b666c57682f4f688e15 (diff) | |
download | fluxbox-44fbcc447e957d63696e9e2654d9c52803474ebf.zip fluxbox-44fbcc447e957d63696e9e2654d9c52803474ebf.tar.bz2 |
cleaning, moved toolbar mode resource here
Diffstat (limited to 'src/ToolbarHandler.cc')
-rw-r--r-- | src/ToolbarHandler.cc | 98 |
1 files changed, 77 insertions, 21 deletions
diff --git a/src/ToolbarHandler.cc b/src/ToolbarHandler.cc index a2b960f..d7cf8f0 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.16 2003/06/24 10:37:39 fluxgen Exp $ | 23 | // $Id: ToolbarHandler.cc,v 1.17 2003/06/24 16:27:18 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. |
@@ -41,6 +41,58 @@ | |||
41 | #include "IntResMenuItem.hh" | 41 | #include "IntResMenuItem.hh" |
42 | #include "BoolMenuItem.hh" | 42 | #include "BoolMenuItem.hh" |
43 | 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 | |||
44 | namespace { | 96 | namespace { |
45 | 97 | ||
46 | class ToolbarModeMenuItem : public FbTk::MenuItem { | 98 | class ToolbarModeMenuItem : public FbTk::MenuItem { |
@@ -50,7 +102,7 @@ public: | |||
50 | FbTk::RefCount<FbTk::Command> &cmd): | 102 | FbTk::RefCount<FbTk::Command> &cmd): |
51 | FbTk::MenuItem(label, cmd), m_handler(handler), m_mode(mode) { | 103 | FbTk::MenuItem(label, cmd), m_handler(handler), m_mode(mode) { |
52 | } | 104 | } |
53 | bool isEnabled() const { return m_handler.getMode() != m_mode; } | 105 | bool isEnabled() const { return m_handler.mode() != m_mode; } |
54 | void click(int button, int time) { | 106 | void click(int button, int time) { |
55 | m_handler.setMode(m_mode); | 107 | m_handler.setMode(m_mode); |
56 | FbTk::MenuItem::click(button, time); | 108 | FbTk::MenuItem::click(button, time); |
@@ -88,26 +140,29 @@ void setupModeMenu(FbTk::Menu &menu, ToolbarHandler &handler) { | |||
88 | 140 | ||
89 | }; // end anonymous namespace | 141 | }; // end anonymous namespace |
90 | 142 | ||
91 | ToolbarHandler::ToolbarHandler(BScreen &screen, ToolbarMode mode) | 143 | ToolbarHandler::ToolbarHandler(BScreen &screen) |
92 | : m_screen(screen), m_mode(mode), m_toolbar(0), m_current_workspace(0), | 144 | : m_screen(screen), |
145 | m_rc_mode(screen.resourceManager(), ToolbarHandler::ICONS, | ||
146 | screen.name() + ".toolbar.mode", screen.altName() + ".Toolbar.Mode"), | ||
147 | m_toolbar(0), | ||
148 | m_current_workspace(0), | ||
93 | m_modemenu(*screen.menuTheme(), | 149 | m_modemenu(*screen.menuTheme(), |
94 | screen.screenNumber(), screen.imageControl()), | 150 | screen.screenNumber(), screen.imageControl()), |
95 | m_toolbarmenu(*screen.menuTheme(), | 151 | m_toolbarmenu(*screen.menuTheme(), |
96 | screen.screenNumber(), screen.imageControl()) | 152 | screen.screenNumber(), screen.imageControl()) { |
97 | { | ||
98 | m_modemenu.setInternalMenu(); | 153 | m_modemenu.setInternalMenu(); |
99 | m_toolbarmenu.setInternalMenu(); | 154 | m_toolbarmenu.setInternalMenu(); |
100 | setupModeMenu(m_modemenu, *this); | 155 | setupModeMenu(m_modemenu, *this); |
101 | setMode(mode, false); // the atomhandler part will initialise it shortly | 156 | setMode(*m_rc_mode, false); // the atomhandler part will initialise it shortly |
102 | } | 157 | } |
103 | 158 | ||
104 | void ToolbarHandler::setMode(ToolbarMode mode, bool initialise) { | 159 | void ToolbarHandler::setMode(ToolbarMode newmode, bool initialise) { |
105 | if (mode < 0 || mode >= LASTMODE || (mode == m_mode && initialise)) | 160 | if (newmode < 0 || newmode >= LASTMODE || (newmode == mode() && initialise)) |
106 | return; | 161 | return; |
107 | 162 | ||
108 | m_screen.saveToolbarMode(mode); | 163 | *m_rc_mode = newmode; |
109 | if (mode == OFF) { | 164 | |
110 | m_mode = mode; | 165 | if (newmode == OFF) { |
111 | m_toolbarmenu.removeAll(); | 166 | m_toolbarmenu.removeAll(); |
112 | //TODO: nls | 167 | //TODO: nls |
113 | m_toolbarmenu.insert("Mode...", &m_modemenu); | 168 | m_toolbarmenu.insert("Mode...", &m_modemenu); |
@@ -127,7 +182,7 @@ void ToolbarHandler::setMode(ToolbarMode mode, bool initialise) { | |||
127 | } | 182 | } |
128 | 183 | ||
129 | 184 | ||
130 | if (mode == NONE) { | 185 | if (newmode == NONE) { |
131 | // disableIconBar will clean up | 186 | // disableIconBar will clean up |
132 | m_toolbar->disableIconBar(); | 187 | m_toolbar->disableIconBar(); |
133 | } else { | 188 | } else { |
@@ -136,8 +191,7 @@ void ToolbarHandler::setMode(ToolbarMode mode, bool initialise) { | |||
136 | m_toolbar->enableIconBar(); | 191 | m_toolbar->enableIconBar(); |
137 | m_toolbar->delAllIcons(); | 192 | m_toolbar->delAllIcons(); |
138 | } | 193 | } |
139 | // reset Toolbar, and reload it (initForScreen) | 194 | |
140 | m_mode = mode; | ||
141 | if (initialise) | 195 | if (initialise) |
142 | initForScreen(m_screen); | 196 | initForScreen(m_screen); |
143 | } | 197 | } |
@@ -145,7 +199,7 @@ void ToolbarHandler::setMode(ToolbarMode mode, bool initialise) { | |||
145 | void ToolbarHandler::initForScreen(BScreen &screen) { | 199 | void ToolbarHandler::initForScreen(BScreen &screen) { |
146 | if (&m_screen != &screen) | 200 | if (&m_screen != &screen) |
147 | return; | 201 | return; |
148 | switch (m_mode) { | 202 | switch (mode()) { |
149 | case OFF: | 203 | case OFF: |
150 | break; | 204 | break; |
151 | case NONE: | 205 | case NONE: |
@@ -207,7 +261,7 @@ void ToolbarHandler::setupWindow(FluxboxWindow &win) { | |||
207 | if (&win.screen() != &m_screen) | 261 | if (&win.screen() != &m_screen) |
208 | return; | 262 | return; |
209 | 263 | ||
210 | switch (m_mode) { | 264 | switch (mode()) { |
211 | case OFF: | 265 | case OFF: |
212 | case NONE: | 266 | case NONE: |
213 | break; | 267 | break; |
@@ -236,7 +290,7 @@ void ToolbarHandler::updateWindowClose(FluxboxWindow &win) { | |||
236 | return; | 290 | return; |
237 | 291 | ||
238 | // check status of window (in current workspace, etc) and remove if necessary | 292 | // check status of window (in current workspace, etc) and remove if necessary |
239 | switch (m_mode) { | 293 | switch (mode()) { |
240 | case OFF: | 294 | case OFF: |
241 | case NONE: | 295 | case NONE: |
242 | break; | 296 | break; |
@@ -265,7 +319,7 @@ void ToolbarHandler::updateState(FluxboxWindow &win) { | |||
265 | return; | 319 | return; |
266 | 320 | ||
267 | // this function only relevant for icons | 321 | // this function only relevant for icons |
268 | switch (m_mode) { | 322 | switch (mode()) { |
269 | case OFF: | 323 | case OFF: |
270 | case NONE: | 324 | case NONE: |
271 | case WORKSPACE: | 325 | case WORKSPACE: |
@@ -296,7 +350,9 @@ void ToolbarHandler::updateWorkspace(FluxboxWindow &win) { | |||
296 | return; | 350 | return; |
297 | 351 | ||
298 | // don't care about current workspace except if in workspace mode | 352 | // don't care about current workspace except if in workspace mode |
299 | if (!(m_mode == WORKSPACE || (m_mode == WORKSPACEICONS && win.isIconic()))) return; | 353 | if (!(mode() == WORKSPACE || |
354 | (mode() == WORKSPACEICONS && win.isIconic()))) | ||
355 | return; | ||
300 | 356 | ||
301 | if (win.workspaceNumber() == m_current_workspace) { | 357 | if (win.workspaceNumber() == m_current_workspace) { |
302 | //!! TODO | 358 | //!! TODO |
@@ -317,7 +373,7 @@ void ToolbarHandler::updateCurrentWorkspace(BScreen &screen) { | |||
317 | return; | 373 | return; |
318 | // if only displaying current workspace, update list | 374 | // if only displaying current workspace, update list |
319 | // otherwise ignore it | 375 | // otherwise ignore it |
320 | if (m_mode != WORKSPACE && m_mode != WORKSPACEICONS) | 376 | if (mode() != WORKSPACE && mode() != WORKSPACEICONS) |
321 | return; | 377 | return; |
322 | m_toolbar->delAllIcons(); | 378 | m_toolbar->delAllIcons(); |
323 | initForScreen(m_screen); | 379 | initForScreen(m_screen); |