diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AlphaMenu.cc | 99 | ||||
-rw-r--r-- | src/AlphaMenu.hh | 92 | ||||
-rw-r--r-- | src/ObjectResource.hh | 145 |
3 files changed, 336 insertions, 0 deletions
diff --git a/src/AlphaMenu.cc b/src/AlphaMenu.cc new file mode 100644 index 0000000..8985fc7 --- /dev/null +++ b/src/AlphaMenu.cc | |||
@@ -0,0 +1,99 @@ | |||
1 | // AlphaMenu.cc for Fluxbox | ||
2 | // Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
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$ | ||
24 | |||
25 | #include "AlphaMenu.hh" | ||
26 | |||
27 | #include "Window.hh" | ||
28 | #include "Screen.hh" | ||
29 | #include "Workspace.hh" | ||
30 | #include "WindowCmd.hh" | ||
31 | #include "fluxbox.hh" | ||
32 | #include "Layer.hh" | ||
33 | #include "IntResMenuItem.hh" | ||
34 | |||
35 | #include "FbTk/I18n.hh" | ||
36 | #include "Window.hh" | ||
37 | #include "WindowCmd.hh" | ||
38 | |||
39 | AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, | ||
40 | FbTk::XLayer &layer, AlphaObject &object): | ||
41 | ToggleMenu(tm, imgctrl, layer), | ||
42 | m_focused_alpha_resource(&object, &AlphaObject::getFocusedAlpha, &AlphaObject::setFocusedAlpha, 255), | ||
43 | m_unfocused_alpha_resource(&object, &AlphaObject::getUnfocusedAlpha, &AlphaObject::setUnfocusedAlpha, 255) | ||
44 | { | ||
45 | |||
46 | _FB_USES_NLS; | ||
47 | |||
48 | // build menu... | ||
49 | |||
50 | const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, | ||
51 | "Use Defaults", | ||
52 | "Default transparency settings for this window"); | ||
53 | FbTk::MenuItem *usedefault_item = | ||
54 | new AlphaMenuSelectItem(usedefault_label, &object, *this); | ||
55 | insert(usedefault_item); | ||
56 | |||
57 | const FbTk::FbString focused_alpha_label = | ||
58 | _FB_XTEXT(Configmenu, FocusedAlpha, | ||
59 | "Focused Window Alpha", | ||
60 | "Transparency level of the focused window"); | ||
61 | |||
62 | FbTk::MenuItem *focused_alpha_item = | ||
63 | new IntResMenuItem< ObjectResource<AlphaObject, int> >(focused_alpha_label, m_focused_alpha_resource, 0, 255, *this); | ||
64 | insert(focused_alpha_item); | ||
65 | |||
66 | const FbTk::FbString unfocused_alpha_label = | ||
67 | _FB_XTEXT(Configmenu, UnfocusedAlpha, | ||
68 | "Unfocused Window Alpha", | ||
69 | "Transparency level of unfocused windows"); | ||
70 | |||
71 | FbTk::MenuItem *unfocused_alpha_item = | ||
72 | new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); | ||
73 | insert(unfocused_alpha_item); | ||
74 | |||
75 | updateMenu(); | ||
76 | } | ||
77 | |||
78 | |||
79 | void AlphaMenu::move(int x, int y) { | ||
80 | FbTk::Menu::move(x, y); | ||
81 | |||
82 | if (isVisible()) { | ||
83 | ((AlphaMenuSelectItem *)find(0))->updateLabel(); | ||
84 | ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); | ||
85 | ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel(); | ||
86 | frameWindow().updateBackground(false); | ||
87 | FbTk::Menu::clearWindow(); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | void AlphaMenu::show() { | ||
92 | ((AlphaMenuSelectItem *)find(0))->updateLabel(); | ||
93 | ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); | ||
94 | ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel(); | ||
95 | frameWindow().updateBackground(false); | ||
96 | FbTk::Menu::clearWindow(); | ||
97 | |||
98 | FbTk::Menu::show(); | ||
99 | } | ||
diff --git a/src/AlphaMenu.hh b/src/AlphaMenu.hh new file mode 100644 index 0000000..78dda9a --- /dev/null +++ b/src/AlphaMenu.hh | |||
@@ -0,0 +1,92 @@ | |||
1 | // AlphaMenu.hh for Fluxbox | ||
2 | // Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
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$ | ||
24 | |||
25 | #ifndef ALPHAMENU_HH | ||
26 | #define ALPHAMENU_HH | ||
27 | |||
28 | #include "ToggleMenu.hh" | ||
29 | #include "FbTk/MenuItem.hh" | ||
30 | #include "ObjectResource.hh" | ||
31 | |||
32 | class AlphaObject { | ||
33 | public: | ||
34 | |||
35 | virtual int getFocusedAlpha() const = 0; | ||
36 | virtual int getUnfocusedAlpha() const = 0; | ||
37 | virtual bool getUseDefaultAlpha() const = 0; | ||
38 | |||
39 | virtual void setFocusedAlpha(int alpha) = 0; | ||
40 | virtual void setUnfocusedAlpha(int alpha) = 0; | ||
41 | virtual void setUseDefaultAlpha(bool use_default) = 0; | ||
42 | |||
43 | virtual ~AlphaObject() {}; | ||
44 | }; | ||
45 | |||
46 | |||
47 | class AlphaMenu : public ToggleMenu { | ||
48 | public: | ||
49 | AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, | ||
50 | FbTk::XLayer &layer, AlphaObject &object); | ||
51 | |||
52 | // we override these to update the menu when the active window changes | ||
53 | void move(int x, int y); | ||
54 | void show(); | ||
55 | |||
56 | ObjectResource<AlphaObject, int> m_focused_alpha_resource; | ||
57 | ObjectResource<AlphaObject, int> m_unfocused_alpha_resource; | ||
58 | |||
59 | }; | ||
60 | |||
61 | class AlphaMenuSelectItem : public FbTk::MenuItem { | ||
62 | |||
63 | public: | ||
64 | AlphaMenuSelectItem(const FbTk::FbString &label, AlphaObject *object, AlphaMenu &parent): | ||
65 | FbTk::MenuItem(label), m_object(object), m_parent(parent) { | ||
66 | setToggleItem(true); | ||
67 | } | ||
68 | |||
69 | bool isSelected() const { return m_object->getUseDefaultAlpha(); } | ||
70 | void click(int button, int time) { | ||
71 | bool newval = !m_object->getUseDefaultAlpha(); | ||
72 | m_object->setUseDefaultAlpha(newval); | ||
73 | // items 1 and 2 (the focused/unfocused values) are only enabled if we don't use default values | ||
74 | m_parent.setItemEnabled(1, !newval); | ||
75 | m_parent.setItemEnabled(2, !newval); | ||
76 | m_parent.show(); // cheat to refreshing the window | ||
77 | FbTk::MenuItem::click(button, time); | ||
78 | } | ||
79 | |||
80 | void updateLabel() { | ||
81 | bool val = m_object->getUseDefaultAlpha(); | ||
82 | m_parent.setItemEnabled(1, !val); | ||
83 | m_parent.setItemEnabled(2, !val); | ||
84 | m_parent.updateMenu(); | ||
85 | } | ||
86 | |||
87 | private: | ||
88 | AlphaObject *m_object; | ||
89 | AlphaMenu &m_parent; | ||
90 | }; | ||
91 | |||
92 | #endif // ALPHAMENU_HH | ||
diff --git a/src/ObjectResource.hh b/src/ObjectResource.hh new file mode 100644 index 0000000..44e52b6 --- /dev/null +++ b/src/ObjectResource.hh | |||
@@ -0,0 +1,145 @@ | |||
1 | // ObjectResource.hh for Fluxbox | ||
2 | // Copyright (c) 2007 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
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$ | ||
24 | |||
25 | #ifndef OBJECTRESOURCE_HH | ||
26 | #define OBJECTRESOURCE_HH | ||
27 | |||
28 | /* This is a generic resource that can be used as an accessor to a value in an object. | ||
29 | The constructors allow to select between: | ||
30 | 1a. giving an object of ObjectType, OR | ||
31 | 1b. giving a function returning an object of ObjectType | ||
32 | |||
33 | 2a. a function that sets a value | ||
34 | 2b. a function that toggles a value | ||
35 | */ | ||
36 | |||
37 | template <typename ObjectType, typename ValueType> | ||
38 | class ObjectResource { | ||
39 | public: | ||
40 | typedef ValueType (ObjectType::* getResourceType)() const; | ||
41 | typedef void (ObjectType::* setResourceType)(ValueType); | ||
42 | typedef void (ObjectType::* toggleResourceType)(); | ||
43 | typedef ObjectType* (*getResourceObject)(); | ||
44 | |||
45 | ObjectResource(ObjectType *object, getResourceType get, setResourceType set, ValueType a_default) : | ||
46 | m_get(get), m_set(set), m_istoggle(false), m_object(object), | ||
47 | m_default(a_default), m_use_accessor(false) { | ||
48 | } | ||
49 | |||
50 | ObjectResource(ObjectType *object, getResourceType get, toggleResourceType toggle, ValueType a_default) : | ||
51 | m_get(get), m_toggle(toggle), m_istoggle(true), m_object(object), | ||
52 | m_default(a_default), m_use_accessor(false) { | ||
53 | } | ||
54 | |||
55 | ObjectResource(getResourceObject object_accessor, getResourceType get, setResourceType set, ValueType a_default) : | ||
56 | m_get(get), m_set(set), m_istoggle(false), m_object_accessor(object_accessor), | ||
57 | m_default(a_default), m_use_accessor(true) { | ||
58 | } | ||
59 | |||
60 | ObjectResource(getResourceObject object_accessor, getResourceType get, toggleResourceType toggle, ValueType a_default) : | ||
61 | m_get(get), m_toggle(toggle), m_istoggle(true), m_object_accessor(object_accessor), | ||
62 | m_default(a_default), m_use_accessor(true) { | ||
63 | } | ||
64 | |||
65 | ObjectResource<ObjectType, ValueType>& operator = (const ValueType newvalue) { | ||
66 | ObjectType * obj = getObject(); | ||
67 | if (!obj) | ||
68 | return *this; | ||
69 | |||
70 | if (m_istoggle) { | ||
71 | if (newvalue != (operator*)()) | ||
72 | (obj->*m_toggle)(); | ||
73 | } else { | ||
74 | (obj->*m_set)(newvalue); | ||
75 | } | ||
76 | return *this; | ||
77 | } | ||
78 | |||
79 | ObjectResource<ObjectType, ValueType>& operator += (const ValueType newvalue) { | ||
80 | ObjectType * obj = getObject(); | ||
81 | if (obj && !m_istoggle) | ||
82 | (obj->*m_set)((operator*)()+newvalue); | ||
83 | return *this; | ||
84 | } | ||
85 | |||
86 | ObjectResource<ObjectType, ValueType>& operator -= (const ValueType newvalue) { | ||
87 | ObjectType * obj = getObject(); | ||
88 | if (obj && !m_istoggle) | ||
89 | (obj->*m_set)((operator*)()-newvalue); | ||
90 | return *this; | ||
91 | } | ||
92 | |||
93 | // this is a touch dirty, but it makes us compatible with FbTk::Resource<int> in IntResMenuItem | ||
94 | ObjectResource<ObjectType, ValueType>& get() { | ||
95 | return *this; | ||
96 | } | ||
97 | |||
98 | ValueType operator*() { | ||
99 | ObjectType * obj = getObject(); | ||
100 | if (!obj) | ||
101 | return m_default; | ||
102 | |||
103 | return (obj->*m_get)(); | ||
104 | } | ||
105 | |||
106 | const ValueType operator*() const { | ||
107 | ObjectType * obj = getObject(); | ||
108 | if (!obj) | ||
109 | return m_default; | ||
110 | |||
111 | return (obj->*m_get)(); | ||
112 | } | ||
113 | |||
114 | private: | ||
115 | // choose one get and one set function | ||
116 | |||
117 | ObjectType * getObject() { | ||
118 | if (m_use_accessor) | ||
119 | return (*m_object_accessor)(); | ||
120 | else | ||
121 | return m_object; | ||
122 | } | ||
123 | |||
124 | getResourceType m_get; | ||
125 | |||
126 | union { | ||
127 | setResourceType m_set; | ||
128 | toggleResourceType m_toggle; | ||
129 | }; | ||
130 | |||
131 | bool m_istoggle; | ||
132 | |||
133 | union { | ||
134 | ObjectType *m_object; | ||
135 | getResourceObject m_object_accessor; | ||
136 | }; | ||
137 | |||
138 | // default is only used when object isn't set (saves crashes) | ||
139 | ValueType m_default; | ||
140 | |||
141 | bool m_use_accessor; | ||
142 | }; | ||
143 | |||
144 | |||
145 | #endif // OBJECTRESOURCE_HH | ||