From b5c354b994bc06667abe35e2d528c0f025703c4e Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Thu, 27 Dec 2007 13:55:24 -0800 Subject: architecture astronomy --- src/AlphaMenu.cc | 29 +++++----- src/AlphaMenu.hh | 36 ++++-------- src/BoolMenuItem.hh | 90 ----------------------------- src/FbTk/Accessor.hh | 85 +++++++++++++++++++++++++++ src/FbTk/BoolMenuItem.hh | 62 ++++++++++++++++++++ src/FbTk/DefaultValue.hh | 54 +++++------------- src/FbTk/IntMenuItem.hh | 102 +++++++++++++++++++++++++++++++++ src/FbTk/Makefile.am | 3 +- src/FbTk/Resource.hh | 19 ++++--- src/FbWinFrame.cc | 4 +- src/FbWinFrame.hh | 5 +- src/IconbarTool.cc | 6 +- src/IntResMenuItem.hh | 100 -------------------------------- src/Makefile.am | 3 +- src/MenuCreator.cc | 55 +++--------------- src/ObjectResource.hh | 145 ----------------------------------------------- src/Screen.cc | 55 +++++++++--------- src/Slit.cc | 14 ++--- src/Toolbar.cc | 20 +++---- src/Window.cc | 22 +++++-- src/Window.hh | 11 +++- src/WindowCmd.hh | 45 +++++++++++++++ 22 files changed, 435 insertions(+), 530 deletions(-) delete mode 100644 src/BoolMenuItem.hh create mode 100644 src/FbTk/Accessor.hh create mode 100644 src/FbTk/BoolMenuItem.hh create mode 100644 src/FbTk/IntMenuItem.hh delete mode 100644 src/IntResMenuItem.hh delete mode 100644 src/ObjectResource.hh diff --git a/src/AlphaMenu.cc b/src/AlphaMenu.cc index 8cd225a..fdea426 100644 --- a/src/AlphaMenu.cc +++ b/src/AlphaMenu.cc @@ -25,24 +25,27 @@ #include "AlphaMenu.hh" #include "Window.hh" +#include "WindowCmd.hh" #include "Screen.hh" #include "Workspace.hh" #include "WindowCmd.hh" #include "fluxbox.hh" #include "Layer.hh" -#include "IntResMenuItem.hh" +#include "FbTk/IntMenuItem.hh" #include "FbTk/I18n.hh" #include "Window.hh" -#include "WindowCmd.hh" AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, - FbTk::XLayer &layer, AlphaObject &object): - ToggleMenu(tm, imgctrl, layer), - m_focused_alpha_resource(&object, &AlphaObject::getFocusedAlpha, &AlphaObject::setFocusedAlpha, 255), - m_unfocused_alpha_resource(&object, &AlphaObject::getUnfocusedAlpha, &AlphaObject::setUnfocusedAlpha, 255) + FbTk::XLayer &layer): + ToggleMenu(tm, imgctrl, layer) { + static WindowAccessor m_focused_alpha((WindowAccessor::Getter)&FluxboxWindow::getFocusedAlpha, + (WindowAccessor::Setter)&FluxboxWindow::setFocusedAlpha, 255); + static WindowAccessor m_unfocused_alpha((WindowAccessor::Getter)&FluxboxWindow::getUnfocusedAlpha, + (WindowAccessor::Setter)&FluxboxWindow::setUnfocusedAlpha, 255); + _FB_USES_NLS; // build menu... @@ -53,7 +56,7 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, "Transparency level of the focused window"); FbTk::MenuItem *focused_alpha_item = - new IntResMenuItem< ObjectResource >(focused_alpha_label, m_focused_alpha_resource, 0, 255, *this); + new FbTk::IntMenuItem(focused_alpha_label, m_focused_alpha, 0, 255, *this); insert(focused_alpha_item); const FbTk::FbString unfocused_alpha_label = @@ -62,14 +65,14 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, "Transparency level of unfocused windows"); FbTk::MenuItem *unfocused_alpha_item = - new IntResMenuItem< ObjectResource >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); + new FbTk::IntMenuItem(unfocused_alpha_label, m_unfocused_alpha, 0, 255, *this); insert(unfocused_alpha_item); const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, "Use Defaults", "Default transparency settings for this window"); FbTk::MenuItem *usedefault_item = - new AlphaMenuSelectItem(usedefault_label, &object, *this); + new AlphaMenuSelectItem(usedefault_label, *this); insert(usedefault_item); updateMenu(); @@ -81,8 +84,8 @@ void AlphaMenu::move(int x, int y) { if (isVisible()) { // TODO: hardcoding the indices is a bad idea - ((IntResMenuItem< ObjectResource >*)find(0))->updateLabel(); - ((IntResMenuItem< ObjectResource >*)find(1))->updateLabel(); + ((FbTk::IntMenuItem *)find(0))->updateLabel(); + ((FbTk::IntMenuItem *)find(1))->updateLabel(); frameWindow().updateBackground(false); FbTk::Menu::clearWindow(); } @@ -90,8 +93,8 @@ void AlphaMenu::move(int x, int y) { void AlphaMenu::show() { // TODO: hardcoding the indices is a bad idea - ((IntResMenuItem< ObjectResource >*)find(0))->updateLabel(); - ((IntResMenuItem< ObjectResource >*)find(1))->updateLabel(); + ((FbTk::IntMenuItem *)find(0))->updateLabel(); + ((FbTk::IntMenuItem *)find(1))->updateLabel(); frameWindow().updateBackground(false); FbTk::Menu::clearWindow(); diff --git a/src/AlphaMenu.hh b/src/AlphaMenu.hh index 70f9c50..19df646 100644 --- a/src/AlphaMenu.hh +++ b/src/AlphaMenu.hh @@ -26,56 +26,40 @@ #define ALPHAMENU_HH #include "ToggleMenu.hh" +#include "WindowCmd.hh" #include "FbTk/MenuItem.hh" -#include "ObjectResource.hh" - -class AlphaObject { -public: - - virtual int getFocusedAlpha() const = 0; - virtual int getUnfocusedAlpha() const = 0; - virtual bool getUseDefaultAlpha() const = 0; - - virtual void setFocusedAlpha(int alpha) = 0; - virtual void setUnfocusedAlpha(int alpha) = 0; - virtual void setDefaultAlpha() = 0; - - virtual ~AlphaObject() {}; -}; - class AlphaMenu : public ToggleMenu { public: AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, - FbTk::XLayer &layer, AlphaObject &object); + FbTk::XLayer &layer); // we override these to update the menu when the active window changes void move(int x, int y); void show(); - - ObjectResource m_focused_alpha_resource; - ObjectResource m_unfocused_alpha_resource; - }; class AlphaMenuSelectItem : public FbTk::MenuItem { public: - AlphaMenuSelectItem(const FbTk::FbString &label, AlphaObject *object, AlphaMenu &parent): - FbTk::MenuItem(label), m_object(object), m_parent(parent) { + AlphaMenuSelectItem(const FbTk::FbString &label, AlphaMenu &parent): + FbTk::MenuItem(label), m_parent(parent) { setToggleItem(true); setCloseOnClick(false); } - bool isSelected() const { return m_object->getUseDefaultAlpha(); } + bool isSelected() const { + static ConstWindowAccessor s_is_default(&FluxboxWindow::getUseDefaultAlpha, true); + return s_is_default; + } void click(int button, int time, unsigned int mods) { - m_object->setDefaultAlpha(); + static WindowCmd s_set_default(&FluxboxWindow::setDefaultAlpha); + s_set_default.execute(); m_parent.show(); // cheat to refreshing the window FbTk::MenuItem::click(button, time, mods); } private: - AlphaObject *m_object; AlphaMenu &m_parent; }; diff --git a/src/BoolMenuItem.hh b/src/BoolMenuItem.hh deleted file mode 100644 index 03f6fb3..0000000 --- a/src/BoolMenuItem.hh +++ /dev/null @@ -1,90 +0,0 @@ -// BoolMenuItem.hh for Fluxbox Window Manager -// Copyright (c) 2003 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// 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$ - -#ifndef BOOLMENUITEM_HH -#define BOOLMENUITEM_HH - -#include "MenuItem.hh" - -/// a bool menu item -class BoolMenuItem: public FbTk::MenuItem { -public: - BoolMenuItem(const FbTk::FbString &label, bool &item, - FbTk::RefCount &cmd): - FbTk::MenuItem(label, cmd), m_item(item) { - FbTk::MenuItem::setSelected(m_item); - setToggleItem(true); - setCloseOnClick(false); - } - BoolMenuItem(const FbTk::FbString &label, bool &item): - FbTk::MenuItem(label), m_item(item) { - FbTk::MenuItem::setSelected(m_item); - setToggleItem(true); - setCloseOnClick(false); - } - bool isSelected() const { return m_item; } - // toggle state - void click(int button, int time, unsigned int mods) { - setSelected(!m_item); - FbTk::MenuItem::click(button, time, mods); - } - void setSelected(bool value) { - m_item = value; - FbTk::MenuItem::setSelected(m_item); - } -private: - bool &m_item; -}; - -/// a bool menu item -template -class BoolResMenuItem: public FbTk::MenuItem { -public: - BoolResMenuItem(const FbTk::FbString &label, Type &res, - FbTk::RefCount &cmd): - FbTk::MenuItem(label, cmd), m_res(res) { - FbTk::MenuItem::setSelected(*m_res); - setToggleItem(true); - setCloseOnClick(false); - } - BoolResMenuItem(const FbTk::FbString &label, Type &res): - FbTk::MenuItem(label), m_res(res) { - FbTk::MenuItem::setSelected(*m_res); - setToggleItem(true); - setCloseOnClick(false); - } - bool isSelected() const { return *m_res; } - // toggle state - void click(int button, int time, unsigned int mods) { - setSelected(!*m_res); - FbTk::MenuItem::click(button, time, mods); - } - void setSelected(bool value) { - m_res = value; - FbTk::MenuItem::setSelected(*m_res); - } -private: - Type &m_res; -}; - -#endif // BOOLMENUITEM_HH diff --git a/src/FbTk/Accessor.hh b/src/FbTk/Accessor.hh new file mode 100644 index 0000000..88db1aa --- /dev/null +++ b/src/FbTk/Accessor.hh @@ -0,0 +1,85 @@ +// Accessor.hh +// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org) +// +// 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. + +#ifndef FBTK_ACCESSOR_HH +#define FBTK_ACCESSOR_HH + +namespace FbTk { + +// base class for objects that act like data type T +template +class Accessor { +public: + virtual Accessor &operator =(const T &val) = 0; + virtual operator T() const = 0; +}; + +// essentially just a reference +template +class SimpleAccessor: public Accessor { +public: + SimpleAccessor(T &val): m_val(val) { } + inline Accessor &operator =(const T &val) { m_val = val; return *this; } + inline operator T() const { return m_val; } + +private: + T &m_val; +}; + +// use object methods as an accessor +template +class ObjectAccessor: public Accessor { +public: + typedef T (Receiver:: *Getter)() const; + typedef void (Receiver:: *Setter)(T &); + ObjectAccessor(Receiver &r, Getter g, Setter s): + m_receiver(r), m_getter(g), m_setter(s) { } + + inline operator T() const { return (m_receiver.*m_getter)(); } + inline Accessor &operator =(const T &val) { + (m_receiver.*m_setter)(val); return *this; + } + +private: + Receiver &m_receiver; + Getter m_getter; + Setter m_setter; +}; + +// same as above but with no set method +template +class ConstObjectAccessor: public Accessor { +public: + typedef T (Receiver:: *Getter)() const; + ConstObjectAccessor(const Receiver &r, Getter g): + m_receiver(r), m_getter(g) { } + + inline operator T() const { return (m_receiver.*m_getter)(); } + inline Accessor &operator =(const T &val) { return *this; } + +private: + const Receiver &m_receiver; + Getter m_getter; +}; + +}; // end namespace FbTk + +#endif // FBTK_ACCESSOR_HH diff --git a/src/FbTk/BoolMenuItem.hh b/src/FbTk/BoolMenuItem.hh new file mode 100644 index 0000000..2e8b2c3 --- /dev/null +++ b/src/FbTk/BoolMenuItem.hh @@ -0,0 +1,62 @@ +// BoolMenuItem.hh for FbTk +// Copyright (c) 2003 - 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) +// +// 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. + +#ifndef FBTK_BOOLMENUITEM_HH +#define FBTK_BOOLMENUITEM_HH + +#include "MenuItem.hh" +#include "Accessor.hh" + +namespace FbTk { + +/// a bool menu item +class BoolMenuItem: public FbTk::MenuItem { +public: + BoolMenuItem(const FbTk::FbString &label, Accessor &item, + FbTk::RefCount &cmd): + FbTk::MenuItem(label, cmd), m_item(item) { + FbTk::MenuItem::setSelected(m_item); + setToggleItem(true); + setCloseOnClick(false); + } + BoolMenuItem(const FbTk::FbString &label, Accessor &item): + FbTk::MenuItem(label), m_item(item) { + FbTk::MenuItem::setSelected(m_item); + setToggleItem(true); + setCloseOnClick(false); + } + bool isSelected() const { return m_item; } + // toggle state + void click(int button, int time, unsigned int mods) { + setSelected(!m_item); + FbTk::MenuItem::click(button, time, mods); + } + void setSelected(bool value) { + m_item = value; + FbTk::MenuItem::setSelected(m_item); + } +private: + Accessor &m_item; +}; + +}; // end namespace FbTk + +#endif // FBTK_BOOLMENUITEM_HH diff --git a/src/FbTk/DefaultValue.hh b/src/FbTk/DefaultValue.hh index 4e7eb49..95b534a 100644 --- a/src/FbTk/DefaultValue.hh +++ b/src/FbTk/DefaultValue.hh @@ -22,58 +22,32 @@ #ifndef FBTK_DEFAULTVALUE_HH #define FBTK_DEFAULTVALUE_HH -namespace FbTk { - -// classes for overriding default values without having to listen for changes -template -class DefaultValue { -public: - DefaultValue(const T &def): - m_default(def), m_actual(def), m_use_default(true) { } +#include "Accessor.hh" - inline const T &get() const { return m_use_default ? m_default : m_actual; } - inline void set(const T &val) { m_use_default = false; m_actual = val; } - inline void restoreDefault() { m_use_default = true; } - inline bool isDefault() const { return m_use_default; } - - inline DefaultValue &operator =(const T &val) { - set(val); return *this; - } +namespace FbTk { - inline operator T() const { return get(); } +// class for overriding default values and restoring them later -private: - const T &m_default; - T m_actual; - bool m_use_default; -}; - -// designed for use with built-in types T, thus no need to return references -template -class DefaultAccessor { +// Ret = type of value that gets returned +// Def = type of default value -- may be Accessor &, for example +template +class DefaultValue: public Accessor { public: - typedef T (Receiver:: *Accessor)() const; - DefaultAccessor(const Receiver &r, Accessor a): - m_receiver(r), m_accessor(a), m_actual((r.*a)()), - m_use_default(true) { } + DefaultValue(const Def def): + m_default(def), m_actual(def), m_use_default(true) { } - inline const T get() const { - return m_use_default ? (m_receiver.*m_accessor)() : m_actual; - } - inline void set(const T &val) { m_use_default = false; m_actual = val; } inline void restoreDefault() { m_use_default = true; } inline bool isDefault() const { return m_use_default; } - inline DefaultAccessor &operator =(const T &val) { - set(val); return *this; + inline DefaultValue &operator =(const Ret &val) { + m_use_default = false; m_actual = val; return *this; } - inline operator T() const { return get(); } + inline operator Ret() const { return m_use_default ? m_default : m_actual; } private: - const Receiver &m_receiver; - Accessor m_accessor; - T m_actual; + const Def m_default; + Ret m_actual; bool m_use_default; }; diff --git a/src/FbTk/IntMenuItem.hh b/src/FbTk/IntMenuItem.hh new file mode 100644 index 0000000..6246787 --- /dev/null +++ b/src/FbTk/IntMenuItem.hh @@ -0,0 +1,102 @@ +// IntMenuItem.hh for FbTk +// Copyright (c) 2003-2007 Henrik Kinnunen (fluxgen at fluxbox dot org) +// +// 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. + +#ifndef FBTK_INTMENUITEM_HH +#define FBTK_INTMENUITEM_HH + +#include "MenuItem.hh" +#include "Accessor.hh" + +#include + +namespace FbTk { + +/// Changes an resource integer value between min and max +class IntMenuItem: public FbTk::MenuItem { +public: + IntMenuItem(const FbTk::FbString &label, Accessor &res, + int min_val, int max_val, FbTk::Menu &host_menu) : + FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), + m_max(max_val), m_min(min_val), m_res(res) { + updateLabel(); + setCloseOnClick(false); + } + + /* Utility, but doesn't get found in anonymous namespace? */ + std::string appendIntValue(const std::string &label, int value) { + char *buff = new char[label.size() + 16]; + sprintf(buff, "%s: %d", label.c_str(), value); + std::string ret(buff); + delete [] buff; + return ret; + } + + void click(int button, int time, unsigned int mods) { + static int last_time = -201; + int inc_val = 1; + // check double click + //!! TODO: must have some sort of "global" double click time in FbTk + if (time - last_time <= 200) + inc_val = 5; + + last_time = time; + + // make sure values stay within bounds _before_ we try to set m_res + // otherwise, this may cause bugs (say, with casting to unsigned char) + if ((button == 4 || button == 3) && m_res < m_max) { // up + if (m_res + inc_val < m_max) + m_res = m_res + inc_val; + else + m_res = m_max; + } else if ((button == 5 || button == 1) && m_res > m_min) { // down + if (m_res - inc_val >= m_min) + m_res = m_res - inc_val; + else + m_res = m_min; + } + + // update label + updateLabel(); + // call other commands + FbTk::MenuItem::click(button, time, mods); + + // show new value, which for us means forcing a full menu update + // since the text is drawn onto the background! + if (menu()) { + menu()->frameWindow().updateBackground(false); + menu()->clearWindow(); + } + } + + void updateLabel() { + setLabel(appendIntValue(m_org_label, m_res)); + } + +private: + std::string m_org_label; ///< original label + const int m_max; ///< maximum value the integer can have + const int m_min; ///< minimum value the integer can have + Accessor &m_res; ///< resource item to be changed +}; + +}; // end namespace FbTk + +#endif // FBTK_INTMENUITEM_HH diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index 0de5475..e3e5d76 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am @@ -16,7 +16,7 @@ imlib2_SOURCE= ImageImlib2.hh ImageImlib2.cc endif libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ - ObjectRegistry.hh DefaultValue.hh \ + ObjectRegistry.hh Accessor.hh DefaultValue.hh \ FileUtil.hh FileUtil.cc \ EventHandler.hh EventManager.hh EventManager.cc \ FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \ @@ -25,6 +25,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ LogicCommands.hh LogicCommands.cc \ MacroCommand.hh MacroCommand.cc \ Menu.hh Menu.cc MenuItem.hh MenuItem.cc \ + BoolMenuItem.hh IntMenuItem.hh \ MultiButtonMenuItem.hh MultiButtonMenuItem.cc \ MenuTheme.hh MenuTheme.cc NotCopyable.hh \ RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \ diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 55eeddc..20ce3ba 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh @@ -25,6 +25,7 @@ #define FBTK_RESOURCE_HH #include "NotCopyable.hh" +#include "Accessor.hh" #include #include @@ -160,23 +161,22 @@ private: /// Real resource class /** - * usage: Resource someresource(resourcemanager, 10, "someresourcename", "somealternativename"); \n - * and then implement setFromString and getString \n - * example: \n - * template <> \n - * void Resource::setFromString(const char *str) { \n - * *(*this) = atoi(str); \n + * usage: Resource someresource(resourcemanager, 10, "someresourcename", "somealternativename"); + * and then implement setFromString and getString + * example: + * template <> + * void Resource::setFromString(const char *str) { + * *(*this) = atoi(str); * } */ template -class Resource:public Resource_base -{ +class Resource:public Resource_base, public Accessor { public: typedef T Type; Resource(ResourceManager &rm, T val, const std::string &name, const std::string &altname): Resource_base(name, altname), - m_value(val), m_defaultval(val), + m_value(val), m_defaultval(val), m_rm(rm) { m_rm.addResource(*this); // add this to resource handler } @@ -192,6 +192,7 @@ public: /// @return string value of resource std::string getString() const; + inline operator T() const { return m_value; } inline T& get() { return m_value; } inline T& operator*() { return m_value; } inline const T& operator*() const { return m_value; } diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index a0de468..2c59798 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -95,8 +95,8 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr m_button_size(1), m_height_before_shade(1), m_shaded(false), - m_focused_alpha(theme, &FbWinFrameTheme::focusedAlpha), - m_unfocused_alpha(theme, &FbWinFrameTheme::unfocusedAlpha), + m_focused_alpha(AlphaAcc(theme, &FbWinFrameTheme::focusedAlpha)), + m_unfocused_alpha(AlphaAcc(theme, &FbWinFrameTheme::unfocusedAlpha)), m_themelistener(*this), m_shape(m_window, theme.shapePlace()), m_disable_themeshape(false) { diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index ea0a179..7b561ee 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -400,8 +400,9 @@ private: unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade bool m_shaded; ///< wheter we're shaded or not /// alpha values - FbTk::DefaultAccessor m_focused_alpha; - FbTk::DefaultAccessor m_unfocused_alpha; + typedef FbTk::ConstObjectAccessor AlphaAcc; + FbTk::DefaultValue m_focused_alpha; + FbTk::DefaultValue m_unfocused_alpha; class ThemeListener: public FbTk::Observer { public: diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 99907c7..294754c 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -32,7 +32,6 @@ #include "IconButton.hh" #include "Workspace.hh" #include "FbMenu.hh" -#include "BoolMenuItem.hh" #include "FbTk/ObjectRegistry.hh" #include "WinClient.hh" #include "FocusControl.hh" @@ -43,6 +42,7 @@ #include "FbTk/I18n.hh" #include "FbTk/Menu.hh" #include "FbTk/MenuItem.hh" +#include "FbTk/BoolMenuItem.hh" #include "FbTk/RefCount.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/ImageControl.hh" @@ -288,9 +288,9 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, save_and_reconfig->add(reconfig); save_and_reconfig->add(save); RefCount s_and_reconfig(save_and_reconfig); - m_menu.insert(new BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, + m_menu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), - *m_rc_use_pixmap, s_and_reconfig)); + m_rc_use_pixmap, s_and_reconfig)); m_menu.updateMenu(); // must be internal menu, otherwise toolbar main menu tries to delete it. m_menu.setInternalMenu(); diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh deleted file mode 100644 index 3de4b5f..0000000 --- a/src/IntResMenuItem.hh +++ /dev/null @@ -1,100 +0,0 @@ -// IntResMenuItem.hh for Fluxbox Window Manager -// Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// 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$ - -#ifndef INTRESMENUITEM_HH -#define INTRESMENUITEM_HH - -#include "MenuItem.hh" -#include "Resource.hh" - -#include - -/// Changes an resource integer value between min and max -template -class IntResMenuItem: public FbTk::MenuItem { -public: - IntResMenuItem(const FbTk::FbString &label, Type &res, int min_val, int max_val, FbTk::Menu &host_menu) : - FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), - m_max(max_val), m_min(min_val), m_res(res) { - updateLabel(); - setCloseOnClick(false); - } - - /* Utility, but doesn't get found in anonymous namespace? */ - std::string appendIntValue(const std::string &label, int value) { - char *buff = new char[label.size() + 16]; - sprintf(buff, "%s: %d", label.c_str(), value); - std::string ret(buff); - delete [] buff; - return ret; - } - - void click(int button, int time, unsigned int mods) { - static int last_time = -201; - int inc_val = 1; - // check double click - //!! TODO: must have some sort of "global" double click time in FbTk - if (time - last_time <= 200) - inc_val = 5; - - last_time = time; - - // make sure values stay within bounds _before_ we try to set m_res - // otherwise, this may cause bugs (say, with casting to unsigned char) - if ((button == 4 || button == 3) && *m_res < m_max) { // up - if (*m_res + inc_val < m_max) - m_res.get() += inc_val; - else - m_res.get() = m_max; - } else if ((button == 5 || button == 1) && *m_res > m_min) { // down - if (*m_res - inc_val >= m_min) - m_res.get() -= inc_val; - else - m_res.get() = m_min; - } - - // update label - updateLabel(); - // call other commands - FbTk::MenuItem::click(button, time, mods); - - // show new value, which for us means forcing a full menu update - // since the text is drawn onto the background! - if (menu()) { - menu()->frameWindow().updateBackground(false); - menu()->clearWindow(); - } - } - - void updateLabel() { - setLabel(appendIntValue(m_org_label, *m_res)); - } - -private: - std::string m_org_label; ///< original label - const int m_max; ///< maximum value the integer can have - const int m_min; ///< minimum value the integer can have - Type &m_res; ///< resource item to be changed -}; - -#endif // INTRESMENUITEM_HH diff --git a/src/Makefile.am b/src/Makefile.am index cc54242..e6f21d3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -96,7 +96,6 @@ TOOLBAR_SOURCE = Toolbar.hh Toolbar.cc \ endif fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \ - BoolMenuItem.hh \ FbAtoms.hh FbAtoms.cc FbWinFrame.hh FbWinFrame.cc \ FbWinFrameTheme.hh FbWinFrameTheme.cc \ fluxbox.cc fluxbox.hh \ @@ -111,7 +110,7 @@ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \ Workspace.cc Workspace.hh \ FbCommands.hh FbCommands.cc LayerMenu.hh LayerMenu.cc \ Layer.hh \ - IntResMenuItem.hh FbMenu.hh FbMenu.cc \ + FbMenu.hh FbMenu.cc \ WinClient.hh WinClient.cc \ Strut.hh \ Xinerama.hh \ diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index 48f3151..df6f829 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -37,7 +37,6 @@ #include "SendToMenu.hh" #include "AlphaMenu.hh" #include "Layer.hh" -#include "BoolMenuItem.hh" #include "FbMenuParser.hh" #include "StyleMenuItem.hh" @@ -45,6 +44,7 @@ #include "FbTk/I18n.hh" #include "FbTk/MultiButtonMenuItem.hh" +#include "FbTk/BoolMenuItem.hh" #include "FbTk/RefCount.hh" #include "FbTk/MacroCommand.hh" #include "FbTk/SimpleCommand.hh" @@ -157,7 +157,7 @@ private: FbTk::Menu *m_menu; }; -class MenuContext: public LayerObject, public AlphaObject { +class MenuContext: public LayerObject { public: void moveToLayer(int layer_number) { if (WindowCmd::window() == 0) @@ -170,42 +170,6 @@ public: return WindowCmd::window()->layerItem().getLayerNum(); } - int getFocusedAlpha() const { - if (WindowCmd::window() == 0) - return 255; - return WindowCmd::window()->getFocusedAlpha(); - } - - int getUnfocusedAlpha() const { - if (WindowCmd::window() == 0) - return 255; - return WindowCmd::window()->getUnfocusedAlpha(); - } - - bool getUseDefaultAlpha() const { - if (WindowCmd::window() == 0) - return true; - return WindowCmd::window()->getUseDefaultAlpha(); - } - - void setFocusedAlpha(int alpha) { - if (WindowCmd::window() == 0) - return; - WindowCmd::window()->setFocusedAlpha(alpha); - } - - void setUnfocusedAlpha(int alpha) { - if (WindowCmd::window() == 0) - return; - WindowCmd::window()->setUnfocusedAlpha(alpha); - } - - void setDefaultAlpha() { - if (WindowCmd::window() == 0) - return; - WindowCmd::window()->setDefaultAlpha(); - } - }; static void translateMenuItem(Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); @@ -551,8 +515,8 @@ bool MenuCreator::createWindowMenuItem(const string &type, static MenuContext context; if (type == "shade") { - static ObjectResource res(&WindowCmd::window, &FluxboxWindow::isShaded, &FluxboxWindow::shade, false); - menu.insert(new BoolResMenuItem >( + static WindowAccessor res(&FluxboxWindow::isShaded, &FluxboxWindow::setShaded, false); + menu.insert(new FbTk::BoolMenuItem( label.empty()?_FB_XTEXT(Windowmenu, Shade, "Shade", "Shade the window"):label, res)); @@ -575,8 +539,8 @@ bool MenuCreator::createWindowMenuItem(const string &type, maximize_item->setCommand(3, maximize_horiz_cmd); menu.insert(maximize_item); } else if (type == "iconify") { - static ObjectResource res(&WindowCmd::window, &FluxboxWindow::isIconic, &FluxboxWindow::toggleIconic, false); - menu.insert(new BoolResMenuItem >( + static WindowAccessor res(&FluxboxWindow::isIconic, &FluxboxWindow::setIconic, false); + menu.insert(new FbTk::BoolMenuItem( label.empty() ? _FB_XTEXT(Windowmenu, Iconify, "Iconify", "Iconify the window") : @@ -607,8 +571,8 @@ bool MenuCreator::createWindowMenuItem(const string &type, label, raise_cmd); } else if (type == "stick") { - static ObjectResource res(&WindowCmd::window, &FluxboxWindow::isStuck, &FluxboxWindow::stick, false); - menu.insert(new BoolResMenuItem >( + static WindowAccessor res(&FluxboxWindow::isStuck, &FluxboxWindow::setStuck, false); + menu.insert(new FbTk::BoolMenuItem( label.empty() ? _FB_XTEXT(Windowmenu, Stick, "Stick", "Stick the window"): @@ -625,8 +589,7 @@ bool MenuCreator::createWindowMenuItem(const string &type, "Menu containing various transparency options"): label, new AlphaMenu(screen->menuTheme(), screen->imageControl(), - *screen->layerManager().getLayer(Layer::MENU), - context)); + *screen->layerManager().getLayer(Layer::MENU))); } #endif // HAVE_XRENDER } else if (type == "extramenus") { diff --git a/src/ObjectResource.hh b/src/ObjectResource.hh deleted file mode 100644 index 44e52b6..0000000 --- a/src/ObjectResource.hh +++ /dev/null @@ -1,145 +0,0 @@ -// ObjectResource.hh for Fluxbox -// Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) -// and Simon Bowden (rathnor 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$ - -#ifndef OBJECTRESOURCE_HH -#define OBJECTRESOURCE_HH - -/* This is a generic resource that can be used as an accessor to a value in an object. - The constructors allow to select between: - 1a. giving an object of ObjectType, OR - 1b. giving a function returning an object of ObjectType - - 2a. a function that sets a value - 2b. a function that toggles a value - */ - -template -class ObjectResource { -public: - typedef ValueType (ObjectType::* getResourceType)() const; - typedef void (ObjectType::* setResourceType)(ValueType); - typedef void (ObjectType::* toggleResourceType)(); - typedef ObjectType* (*getResourceObject)(); - - ObjectResource(ObjectType *object, getResourceType get, setResourceType set, ValueType a_default) : - m_get(get), m_set(set), m_istoggle(false), m_object(object), - m_default(a_default), m_use_accessor(false) { - } - - ObjectResource(ObjectType *object, getResourceType get, toggleResourceType toggle, ValueType a_default) : - m_get(get), m_toggle(toggle), m_istoggle(true), m_object(object), - m_default(a_default), m_use_accessor(false) { - } - - ObjectResource(getResourceObject object_accessor, getResourceType get, setResourceType set, ValueType a_default) : - m_get(get), m_set(set), m_istoggle(false), m_object_accessor(object_accessor), - m_default(a_default), m_use_accessor(true) { - } - - ObjectResource(getResourceObject object_accessor, getResourceType get, toggleResourceType toggle, ValueType a_default) : - m_get(get), m_toggle(toggle), m_istoggle(true), m_object_accessor(object_accessor), - m_default(a_default), m_use_accessor(true) { - } - - ObjectResource& operator = (const ValueType newvalue) { - ObjectType * obj = getObject(); - if (!obj) - return *this; - - if (m_istoggle) { - if (newvalue != (operator*)()) - (obj->*m_toggle)(); - } else { - (obj->*m_set)(newvalue); - } - return *this; - } - - ObjectResource& operator += (const ValueType newvalue) { - ObjectType * obj = getObject(); - if (obj && !m_istoggle) - (obj->*m_set)((operator*)()+newvalue); - return *this; - } - - ObjectResource& operator -= (const ValueType newvalue) { - ObjectType * obj = getObject(); - if (obj && !m_istoggle) - (obj->*m_set)((operator*)()-newvalue); - return *this; - } - - // this is a touch dirty, but it makes us compatible with FbTk::Resource in IntResMenuItem - ObjectResource& get() { - return *this; - } - - ValueType operator*() { - ObjectType * obj = getObject(); - if (!obj) - return m_default; - - return (obj->*m_get)(); - } - - const ValueType operator*() const { - ObjectType * obj = getObject(); - if (!obj) - return m_default; - - return (obj->*m_get)(); - } - -private: - // choose one get and one set function - - ObjectType * getObject() { - if (m_use_accessor) - return (*m_object_accessor)(); - else - return m_object; - } - - getResourceType m_get; - - union { - setResourceType m_set; - toggleResourceType m_toggle; - }; - - bool m_istoggle; - - union { - ObjectType *m_object; - getResourceObject m_object_accessor; - }; - - // default is only used when object isn't set (saves crashes) - ValueType m_default; - - bool m_use_accessor; -}; - - -#endif // OBJECTRESOURCE_HH diff --git a/src/Screen.cc b/src/Screen.cc index 97ce70b..c304b7e 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -47,8 +47,8 @@ #include "SlitTheme.hh" // menu items -#include "BoolMenuItem.hh" -#include "IntResMenuItem.hh" +#include "FbTk/BoolMenuItem.hh" +#include "FbTk/IntMenuItem.hh" #include "FocusModelMenuItem.hh" // menus @@ -1576,7 +1576,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { "Method used to give focus to windows"); FbTk::Menu *focus_menu = createMenu(focusmenu_label); -#define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) +#define _BOOLITEM(m,a, b, c, d, e, f) (m).insert(new FbTk::BoolMenuItem(_FB_XTEXT(a, b, c, d), e, f)) #define _FOCUSITEM(a, b, c, d, e) \ @@ -1599,19 +1599,19 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { focusControl(), FocusControl::MOUSETABFOCUS, save_and_reconfigure)); try { - focus_menu->insert(new BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, + focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, "Focus New Windows", "Focus newly created windows"), - *m_resource_manager.getResource(name() + ".focusNewWindows"), + m_resource_manager.getResource(name() + ".focusNewWindows"), saverc_cmd)); } catch (FbTk::ResourceException e) { cerr<insert(new BoolMenuItem(_FB_XTEXT(Configmenu, + focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, AutoRaise, "Auto Raise", "Auto Raise windows on sloppy"), - *resource.auto_raise, + resource.auto_raise, save_and_reconfigure)); focus_menu->updateMenu(); @@ -1628,17 +1628,17 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { _BOOLITEM(*maxmenu, Configmenu, FullMax, "Full Maximization", "Maximise over slit, toolbar, etc", - *resource.full_max, saverc_cmd); + resource.full_max, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxIgnoreInc, "Ignore Resize Increment", "Maximizing Ignores Resize Increment (e.g. xterm)", - *resource.max_ignore_inc, saverc_cmd); + resource.max_ignore_inc, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxDisableMove, "Disable Moving", "Don't Allow Moving While Maximized", - *resource.max_disable_move, saverc_cmd); + resource.max_disable_move, saverc_cmd); _BOOLITEM(*maxmenu, Configmenu, MaxDisableResize, "Disable Resizing", "Don't Allow Resizing While Maximized", - *resource.max_disable_resize, saverc_cmd); + resource.max_disable_resize, saverc_cmd); maxmenu->updateMenu(); menu.insert(maxmenu_label, maxmenu); @@ -1658,16 +1658,16 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { _BOOLITEM(*tab_menu,Configmenu, TabsInTitlebar, "Tabs in Titlebar", "Tabs in Titlebar", - *resource.default_internal_tabs, save_and_reconftabs); - tab_menu->insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, + resource.default_internal_tabs, save_and_reconftabs); + tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, "Maximize Over", "Maximize over this thing when maximizing"), - *resource.max_over_tabs, save_and_reconfigure)); - tab_menu->insert(new BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, + resource.max_over_tabs, save_and_reconfigure)); + tab_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Toolbar, ShowIcons, "Show Pictures", "chooses if little icons are shown next to title in the iconbar"), - *resource.tabs_use_pixmap, save_and_reconfigure)); + resource.tabs_use_pixmap, save_and_reconfigure)); FbTk::MenuItem *tab_width_item = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Configmenu, ExternalTabWidth, + new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, ExternalTabWidth, "External Tab Width", "Width of external-style tabs"), resource.tab_width, 10, 3000, /* silly number */ @@ -1715,10 +1715,11 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::Menu *alpha_menu = createMenu(alphamenu_label); if (FbTk::Transparent::haveComposite(true)) { - alpha_menu->insert(new BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, + static FbTk::SimpleAccessor s_pseudo(Fluxbox::instance()->getPseudoTrans()); + alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), - Fluxbox::instance()->getPseudoTrans(), save_and_reconfigure)); + s_pseudo, save_and_reconfigure)); } // in order to save system resources, don't save or reconfigure alpha @@ -1727,7 +1728,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { new ::DelayedCmd(save_and_reconfigure)); FbTk::MenuItem *focused_alpha_item = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Configmenu, FocusedAlpha, + new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", "Transparency level of the focused window"), resource.focused_alpha, 0, 255, *alpha_menu); @@ -1735,7 +1736,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { alpha_menu->insert(focused_alpha_item); FbTk::MenuItem *unfocused_alpha_item = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Configmenu, + new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, UnfocusedAlpha, "Unfocused Window Alpha", "Transparency level of unfocused windows"), @@ -1745,7 +1746,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { alpha_menu->insert(unfocused_alpha_item); FbTk::MenuItem *menu_alpha_item = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Configmenu, MenuAlpha, + new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu"), resource.menu_alpha, 0, 255, *alpha_menu); menu_alpha_item->setCommand(delayed_save_and_reconf); @@ -1763,21 +1764,21 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { _BOOLITEM(menu, Configmenu, ImageDithering, "Image Dithering", "Image Dithering", - *resource.image_dither, save_and_reconfigure); + resource.image_dither, save_and_reconfigure); _BOOLITEM(menu, Configmenu, OpaqueMove, "Opaque Window Moving", "Window Moving with whole window visible (as opposed to outline moving)", - *resource.opaque_move, saverc_cmd); + resource.opaque_move, saverc_cmd); _BOOLITEM(menu, Configmenu, WorkspaceWarping, "Workspace Warping", "Workspace Warping - dragging windows to the edge and onto the next workspace", - *resource.workspace_warping, saverc_cmd); + resource.workspace_warping, saverc_cmd); _BOOLITEM(menu, Configmenu, DecorateTransient, "Decorate Transient Windows", "Decorate Transient Windows", - *resource.decorate_transient, saverc_cmd); + resource.decorate_transient, saverc_cmd); _BOOLITEM(menu, Configmenu, ClickRaises, "Click Raises", "Click Raises", - *resource.click_raises, saverc_cmd); + resource.click_raises, saverc_cmd); #undef _BOOLITEM diff --git a/src/Slit.cc b/src/Slit.cc index 7716813..7dfd2f4 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -38,7 +38,6 @@ #include "Screen.hh" #include "ImageControl.hh" #include "RefCount.hh" -#include "BoolMenuItem.hh" #include "EventManager.hh" #include "SimpleCommand.hh" #include "MacroCommand.hh" @@ -50,7 +49,6 @@ #include "FbTk/Theme.hh" #include "FbMenu.hh" #include "Transparent.hh" -#include "IntResMenuItem.hh" #ifdef XINERAMA #include "Xinerama.hh" @@ -63,6 +61,8 @@ #include "FbTk/MenuSeparator.hh" #include "FbTk/StringUtil.hh" #include "FbTk/I18n.hh" +#include "FbTk/BoolMenuItem.hh" +#include "FbTk/IntMenuItem.hh" #ifdef HAVE_SYS_STAT_H #include @@ -1268,17 +1268,17 @@ void Slit::setupMenu() { } #endif //XINERAMA - m_slitmenu.insert(new BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), - *m_rc_auto_hide, + m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "This thing automatically hides when not close by"), + m_rc_auto_hide, save_and_reconfigure_slit)); - m_slitmenu.insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), - *m_rc_maximize_over, + m_slitmenu.insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver,"Maximize Over", "Maximize over this thing when maximizing"), + m_rc_maximize_over, save_and_reconfigure_slit)); // this saves resources and clears the slit window to update alpha value FbTk::MenuItem *alpha_menuitem = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), + new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, 0, 255, m_slitmenu); // setup command for alpha value diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 2e3afd5..0b52702 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -36,8 +36,6 @@ #include "Keys.hh" #include "Screen.hh" #include "WindowCmd.hh" -#include "IntResMenuItem.hh" -#include "BoolMenuItem.hh" #ifdef XINERAMA #include "Xinerama.hh" @@ -54,6 +52,8 @@ #include "FbTk/SimpleCommand.hh" #include "FbTk/StringUtil.hh" #include "FbTk/Transparent.hh" +#include "FbTk/BoolMenuItem.hh" +#include "FbTk/IntMenuItem.hh" // use GNU extensions @@ -835,17 +835,17 @@ void Toolbar::setupMenus(bool skip_new_placement) { visible_macro->add(reconfig_toolbar); visible_macro->add(save_resources); RefCommand toggle_visible_cmd(visible_macro); - menu().insert(new BoolMenuItem(_FB_XTEXT(Common, Visible, + menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, Visible, "Visible", "Whether this item is visible"), - *m_rc_visible, toggle_visible_cmd)); + m_rc_visible, toggle_visible_cmd)); - menu().insert(new BoolMenuItem(_FB_XTEXT(Common, AutoHide, + menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, AutoHide, "Auto hide", "Toggle auto hide of toolbar"), - *m_rc_auto_hide, + m_rc_auto_hide, reconfig_toolbar_and_save_resource)); MenuItem *toolbar_menuitem = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Toolbar, WidthPercent, + new FbTk::IntMenuItem(_FB_XTEXT(Toolbar, WidthPercent, "Toolbar width percent", "Percentage of screen width taken by toolbar"), m_rc_width_percent, @@ -855,10 +855,10 @@ void Toolbar::setupMenus(bool skip_new_placement) { toolbar_menuitem->setCommand(reconfig_toolbar_and_save_resource); menu().insert(toolbar_menuitem); - menu().insert(new BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, + menu().insert(new FbTk::BoolMenuItem(_FB_XTEXT(Common, MaximizeOver, "Maximize Over", "Maximize over this thing when maximizing"), - *m_rc_maximize_over, + m_rc_maximize_over, reconfig_toolbar_and_save_resource)); menu().insert(_FB_XTEXT(Menu, Layer, "Layer...", "Title of Layer menu"), &layerMenu()); #ifdef XINERAMA @@ -922,7 +922,7 @@ void Toolbar::setupMenus(bool skip_new_placement) { // this saves resources and clears the slit window to update alpha value FbTk::MenuItem *alpha_menuitem = - new IntResMenuItem< FbTk::Resource >(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), + new FbTk::IntMenuItem(_FB_XTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, 0, 255, menu()); // setup command for alpha value diff --git a/src/Window.cc b/src/Window.cc index 8126e9e..909d8db 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -264,8 +264,8 @@ FluxboxWindow::FluxboxWindow(WinClient &client, FbWinFrameTheme &tm, m_toggled_decos(false), m_icon_hidden(false), m_focus_hidden(false), - m_focus_new(screen().focusControl(), &FocusControl::focusNew), - m_mouse_focus(screen().focusControl(), &FocusControl::isMouseFocus), + m_focus_new(BoolAcc(screen().focusControl(), &FocusControl::focusNew)), + m_mouse_focus(BoolAcc(screen().focusControl(), &FocusControl::isMouseFocus)), m_click_focus(true), m_old_pos_x(0), m_old_pos_y(0), m_old_width(1), m_old_height(1), @@ -1745,17 +1745,18 @@ void FluxboxWindow::shade() { } void FluxboxWindow::shadeOn() { - if (!shaded) shade(); - } void FluxboxWindow::shadeOff() { - if (shaded) shade(); +} +void FluxboxWindow::setShaded(bool val) { + if (val != shaded) + shade(); } void FluxboxWindow::stick() { @@ -1783,6 +1784,17 @@ void FluxboxWindow::stick() { } +void FluxboxWindow::setStuck(bool val) { + if (val != stuck) + stick(); +} + +void FluxboxWindow::setIconic(bool val) { + if (val && isIconic()) + deiconify(); + if (!val && !isIconic()) + iconify(); +} void FluxboxWindow::raise() { if (isIconic()) diff --git a/src/Window.hh b/src/Window.hh index 490c178..fc44610 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -270,10 +270,16 @@ public: void shadeOn(); /// unshades window void shadeOff(); + /// sets shaded state + void setShaded(bool val); /// toggles sticky void stick(); + /// sets stuck state + void setStuck(bool val); /// toggles iconic void toggleIconic(); + /// sets iconic state + void setIconic(bool val); void raise(); void lower(); void tempRaise(); @@ -611,10 +617,11 @@ private: bool m_icon_hidden; ///< if the window is in the iconbar bool m_focus_hidden; ///< if the window is in the NextWindow list + typedef FbTk::ConstObjectAccessor BoolAcc; /// if the window is normally focused when mapped - FbTk::DefaultAccessor m_focus_new; + FbTk::DefaultValue m_focus_new; /// if the window is focused with EnterNotify - FbTk::DefaultAccessor m_mouse_focus; + FbTk::DefaultValue m_mouse_focus; bool m_click_focus; ///< if the window is focused by clicking int m_old_pos_x, m_old_pos_y; ///< old position so we can restore from maximized unsigned int m_old_width, m_old_height; ///< old size so we can restore from maximized state diff --git a/src/WindowCmd.hh b/src/WindowCmd.hh index 17a4e86..d1754e9 100644 --- a/src/WindowCmd.hh +++ b/src/WindowCmd.hh @@ -25,6 +25,7 @@ #define WINDOWCMD_HH #include "FbTk/Command.hh" +#include "FbTk/Accessor.hh" #include "Window.hh" #include "WinClient.hh" @@ -64,5 +65,49 @@ private: Action m_action; }; +/// accesses values in current window +template +class WindowAccessor: public FbTk::Accessor { +public: + typedef Ret (FluxboxWindow:: *Getter)() const; + typedef void (FluxboxWindow:: *Setter)(Ret); + WindowAccessor(Getter g, Setter s, Def def): + m_getter(g), m_setter(s), m_def(def) { } + + inline operator Ret() const { + FluxboxWindow *fbwin = WindowCmd::window(); + return fbwin ? (fbwin->*m_getter)() : m_def; + } + inline FbTk::Accessor &operator =(const Ret &val) { + FluxboxWindow *fbwin = WindowCmd::window(); + if (fbwin) + (fbwin->*m_setter)(val); + return *this; + } + +private: + Getter m_getter; + Setter m_setter; + Def m_def; +}; + +/// same as above but only reads +template +class ConstWindowAccessor: public FbTk::Accessor { +public: + typedef Ret (FluxboxWindow:: *Getter)() const; + ConstWindowAccessor(Getter g, Def def): + m_getter(g), m_def(def) { } + + inline operator Ret() const { + FluxboxWindow *fbwin = WindowCmd::window(); + return fbwin ? (fbwin->*m_getter)() : m_def; + } + inline FbTk::Accessor &operator =(const Ret &val) { return *this; } + +private: + Getter m_getter; + Def m_def; +}; #endif // WINDOWCMD_HH -- cgit v0.11.2