forgot to svn add the files
simonb simonb
3 files changed,
336 insertions(+),
0 deletions(-)
A
src/AlphaMenu.cc
@@ -0,0 +1,99 @@
+// AlphaMenu.cc 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$ + +#include "AlphaMenu.hh" + +#include "Window.hh" +#include "Screen.hh" +#include "Workspace.hh" +#include "WindowCmd.hh" +#include "fluxbox.hh" +#include "Layer.hh" +#include "IntResMenuItem.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) +{ + + _FB_USES_NLS; + + // build menu... + + 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); + insert(usedefault_item); + + const FbTk::FbString focused_alpha_label = + _FB_XTEXT(Configmenu, FocusedAlpha, + "Focused Window Alpha", + "Transparency level of the focused window"); + + FbTk::MenuItem *focused_alpha_item = + new IntResMenuItem< ObjectResource<AlphaObject, int> >(focused_alpha_label, m_focused_alpha_resource, 0, 255, *this); + insert(focused_alpha_item); + + const FbTk::FbString unfocused_alpha_label = + _FB_XTEXT(Configmenu, UnfocusedAlpha, + "Unfocused Window Alpha", + "Transparency level of unfocused windows"); + + FbTk::MenuItem *unfocused_alpha_item = + new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); + insert(unfocused_alpha_item); + + updateMenu(); +} + + +void AlphaMenu::move(int x, int y) { + FbTk::Menu::move(x, y); + + if (isVisible()) { + ((AlphaMenuSelectItem *)find(0))->updateLabel(); + ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); + ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel(); + frameWindow().updateBackground(false); + FbTk::Menu::clearWindow(); + } +} + +void AlphaMenu::show() { + ((AlphaMenuSelectItem *)find(0))->updateLabel(); + ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); + ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel(); + frameWindow().updateBackground(false); + FbTk::Menu::clearWindow(); + + FbTk::Menu::show(); +}
A
src/AlphaMenu.hh
@@ -0,0 +1,92 @@
+// AlphaMenu.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 ALPHAMENU_HH +#define ALPHAMENU_HH + +#include "ToggleMenu.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 setUseDefaultAlpha(bool use_default) = 0; + + virtual ~AlphaObject() {}; +}; + + +class AlphaMenu : public ToggleMenu { +public: + AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, + FbTk::XLayer &layer, AlphaObject &object); + + // we override these to update the menu when the active window changes + void move(int x, int y); + void show(); + + ObjectResource<AlphaObject, int> m_focused_alpha_resource; + ObjectResource<AlphaObject, int> 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) { + setToggleItem(true); + } + + bool isSelected() const { return m_object->getUseDefaultAlpha(); } + void click(int button, int time) { + bool newval = !m_object->getUseDefaultAlpha(); + m_object->setUseDefaultAlpha(newval); + // items 1 and 2 (the focused/unfocused values) are only enabled if we don't use default values + m_parent.setItemEnabled(1, !newval); + m_parent.setItemEnabled(2, !newval); + m_parent.show(); // cheat to refreshing the window + FbTk::MenuItem::click(button, time); + } + + void updateLabel() { + bool val = m_object->getUseDefaultAlpha(); + m_parent.setItemEnabled(1, !val); + m_parent.setItemEnabled(2, !val); + m_parent.updateMenu(); + } + +private: + AlphaObject *m_object; + AlphaMenu &m_parent; +}; + +#endif // ALPHAMENU_HH
A
src/ObjectResource.hh
@@ -0,0 +1,145 @@
+// 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 <typename ObjectType, typename ValueType> +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<ObjectType, ValueType>& 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<ObjectType, ValueType>& operator += (const ValueType newvalue) { + ObjectType * obj = getObject(); + if (obj && !m_istoggle) + (obj->*m_set)((operator*)()+newvalue); + return *this; + } + + ObjectResource<ObjectType, ValueType>& 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<int> in IntResMenuItem + ObjectResource<ObjectType, ValueType>& 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