From 11274940f84133791c71aeb716f52bf090765c89 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 2 May 2004 20:51:36 +0000 Subject: menu instances that handles workspace and icon menu --- src/IconMenu.cc | 64 ++++++++++++++++++++++++++++ src/IconMenu.hh | 38 +++++++++++++++++ src/WorkspaceMenu.cc | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/WorkspaceMenu.hh | 40 ++++++++++++++++++ 4 files changed, 257 insertions(+) create mode 100644 src/IconMenu.cc create mode 100644 src/IconMenu.hh create mode 100644 src/WorkspaceMenu.cc create mode 100644 src/WorkspaceMenu.hh diff --git a/src/IconMenu.cc b/src/IconMenu.cc new file mode 100644 index 0000000..16d7b27 --- /dev/null +++ b/src/IconMenu.cc @@ -0,0 +1,64 @@ +// IconMenu.cc for Fluxbox +// Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: IconMenu.cc,v 1.1 2004/05/02 20:51:36 fluxgen Exp $ + +#include "IconMenu.hh" + +#include "Screen.hh" +#include "IconMenuItem.hh" +#include "fluxbox.hh" +#include "I18n.hh" + +static void updateItems(FbTk::Menu &menu, BScreen &screen) { + menu.removeAll(); + BScreen::Icons::iterator it = screen.getIconList().begin(); + BScreen::Icons::iterator it_end = screen.getIconList().end(); + for (; it != it_end; ++it) { + FluxboxWindow::ClientList::iterator client_it = (*it)->clientList().begin(); + FluxboxWindow::ClientList::iterator client_it_end = (*it)->clientList().end(); + for (; client_it != client_it_end; ++client_it) + menu.insert(new IconMenuItem(**client_it)); + } + menu.update(); +} + +IconMenu::IconMenu(BScreen &screen): + FbMenu(screen.menuTheme(), + screen.imageControl(), + *screen.layerManager(). + getLayer(Fluxbox::instance()->getMenuLayer())) { + + setLabel(I18n::instance()->getMessage(FBNLS::IconSet, + FBNLS::IconIcons, "Icons")); + screen.iconListSig().attach(this); + updateItems(*this, screen); +} + +void IconMenu::update(FbTk::Subject *subj) { + if (subj == 0) + FbTk::Menu::update(subj); + else if (typeid(*subj) == typeid(BScreen::ScreenSubject)) { + BScreen &screen = static_cast(subj)->screen(); + updateItems(*this, screen); + } else + FbTk::Menu::update(subj); +} diff --git a/src/IconMenu.hh b/src/IconMenu.hh new file mode 100644 index 0000000..a9cb045 --- /dev/null +++ b/src/IconMenu.hh @@ -0,0 +1,38 @@ +// IconMenu.hh for Fluxbox +// Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: IconMenu.hh,v 1.1 2004/05/02 20:51:36 fluxgen Exp $ + +#ifndef ICONMENU_HH +#define ICONMENU_HH + +#include "FbMenu.hh" + +class BScreen; + +class IconMenu: public FbMenu { +public: + explicit IconMenu(BScreen &screen); + virtual ~IconMenu() { } + void update(FbTk::Subject *subj); +}; + +#endif // ICONMENU_HH diff --git a/src/WorkspaceMenu.cc b/src/WorkspaceMenu.cc new file mode 100644 index 0000000..575ddeb --- /dev/null +++ b/src/WorkspaceMenu.cc @@ -0,0 +1,115 @@ +// WorkspaceMenu.cc for Fluxbox +// Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: WorkspaceMenu.cc,v 1.1 2004/05/02 20:51:36 fluxgen Exp $ + +#include "WorkspaceMenu.hh" + +#include "Screen.hh" +#include "fluxbox.hh" +#include "Workspace.hh" +#include "MenuCreator.hh" +#include "I18n.hh" + +#include "FbTk/SimpleCommand.hh" +#include "FbTk/RefCount.hh" +#include "FbTk/MenuItem.hh" + +WorkspaceMenu::WorkspaceMenu(BScreen &screen): + FbMenu(screen.menuTheme(), + screen.imageControl(), + *screen.layerManager(). + getLayer(Fluxbox::instance()->getMenuLayer())) { + + + init(screen); +} + +void WorkspaceMenu::update(FbTk::Subject *subj) { + if (subj != 0 && typeid(*subj) == typeid(BScreen::ScreenSubject)) { + BScreen::ScreenSubject &screen_subj = *static_cast(subj); + BScreen &screen = screen_subj.screen(); + if (subj == &screen.currentWorkspaceSig()) { + FbTk::MenuItem *item = 0; + for (unsigned int i = 2; i < numberOfItems(); ++i) { + item = find(i); + if (item && item->isSelected()) { + setItemSelected(i, false); + FbTk::Menu::update(i); + break; + } + } + setItemSelected(screen.currentWorkspace()->workspaceID() + 2, true); + FbTk::Menu::update(screen.currentWorkspace()->workspaceID() + 2); + } else if (subj == &screen.workspaceCountSig() || + subj == &screen.workspaceNamesSig()) { + while (numberOfItems() != 3) { + remove(2); + } + // for each workspace add workspace name and it's menu + // to our workspace menu + for (size_t workspace = 0; workspace < screen.getCount(); + ++workspace) { + Workspace *wkspc = screen.getWorkspace(workspace); + wkspc->menu().setInternalMenu(); + insert(wkspc->name().c_str(), &wkspc->menu(), numberOfItems() - 1); + } + + FbTk::Menu::update(-1); + } + } else { + FbTk::Menu::update(subj); + } +} + +void WorkspaceMenu::init(BScreen &screen) { + screen.currentWorkspaceSig().attach(this); + screen.workspaceCountSig().attach(this); + screen.workspaceNamesSig().attach(this); + I18n &i18n = *I18n::instance(); + using namespace FbTk; + using namespace FBNLS; + + removeAll(); + + setLabel(i18n.getMessage(WorkspacemenuSet, WorkspacemenuWorkspacesTitle, + "Workspace")); + RefCount new_workspace(new SimpleCommand(screen, &BScreen::addWorkspace)); + RefCount remove_last(new SimpleCommand(screen, &BScreen::removeLastWorkspace)); + insert(i18n.getMessage(WorkspacemenuSet, WorkspacemenuNewWorkspace, + "New Workspace"), + new_workspace); + insert(i18n.getMessage(WorkspacemenuSet, WorkspacemenuRemoveLast, + "Remove Last"), + remove_last); + // for each workspace add workspace name and it's menu to our workspace menu + for (size_t workspace = 0; workspace < screen.getCount(); ++workspace) { + Workspace *wkspc = screen.getWorkspace(workspace); + wkspc->menu().setInternalMenu(); + insert(wkspc->name().c_str(), &wkspc->menu()); + } + setItemSelected(screen.currentWorkspace()->workspaceID() + 2, true); + + insert(i18n.getMessage(IconSet, IconIcons, + "Icons"), + MenuCreator::createMenuType("iconmenu", screen.screenNumber())); + FbMenu::update(); +} diff --git a/src/WorkspaceMenu.hh b/src/WorkspaceMenu.hh new file mode 100644 index 0000000..77f1006 --- /dev/null +++ b/src/WorkspaceMenu.hh @@ -0,0 +1,40 @@ +// WorkspaceMenu.hh for Fluxbox +// Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: WorkspaceMenu.hh,v 1.1 2004/05/02 20:51:36 fluxgen Exp $ + +#ifndef WORKSPACEMENU_HH +#define WORKSPACEMENU_HH + +#include "FbMenu.hh" + +class BScreen; + +class WorkspaceMenu: public FbMenu { +public: + explicit WorkspaceMenu(BScreen &screen); + virtual ~WorkspaceMenu() { } + void update(FbTk::Subject *subj); +private: + void init(BScreen &screen); +}; + +#endif // WORKSPACEMENU_HH -- cgit v0.11.2