aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Theme.hh
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-12-02 19:34:54 (GMT)
committerfluxgen <fluxgen>2002-12-02 19:34:54 (GMT)
commitc8aff5576a187f3921a0db998cd5a47173b28742 (patch)
tree17a3e25a6429caa7ff24052368c03da2182bb20a /src/FbTk/Theme.hh
parent3d18945fb5b660cef4ff32668c15f2b565f4e230 (diff)
downloadfluxbox-c8aff5576a187f3921a0db998cd5a47173b28742.zip
fluxbox-c8aff5576a187f3921a0db998cd5a47173b28742.tar.bz2
theme classes
Diffstat (limited to 'src/FbTk/Theme.hh')
-rw-r--r--src/FbTk/Theme.hh162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/FbTk/Theme.hh b/src/FbTk/Theme.hh
new file mode 100644
index 0000000..bd02666
--- /dev/null
+++ b/src/FbTk/Theme.hh
@@ -0,0 +1,162 @@
1// Theme.hh for FbTk - Fluxbox ToolKit
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen at linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: Theme.hh,v 1.1 2002/12/02 19:34:51 fluxgen Exp $
23
24// holds ThemeItem, Theme and ThemeManager
25
26
27#include <string>
28#include <list>
29#include <string>
30
31#include "../XrmDatabaseHelper.hh"
32
33namespace FbTk {
34
35class Theme;
36/**
37 base class for themeitem, holds name and altname
38 */
39class ThemeItem_base {
40public:
41 ThemeItem_base(const std::string &name, const std::string &altname):
42 m_name(name), m_altname(altname) { }
43 virtual ~ThemeItem_base() { }
44 virtual void setFromString(const char *str) = 0;
45 virtual void setDefaultValue() = 0;
46 virtual void load() = 0; // if it needs to load additional stuff
47 const std::string &name() const { return m_name; }
48 const std::string &altName() const { return m_altname; }
49private:
50 std::string m_name, m_altname;
51};
52
53/**
54 template ThemeItem class for things like Texture and Color
55*/
56template <typename T>
57class ThemeItem:public ThemeItem_base {
58public:
59 ThemeItem(FbTk::Theme &tm, const std::string &name, const std::string &altname);
60 virtual ~ThemeItem();
61 /// specialized
62 void setDefaultValue();
63 /// specialized
64 void setFromString(const char *strval);
65 /// specialized
66 void load();
67 /**
68 @name access operators
69 */
70 /**@{*/
71 inline T& operator*() { return m_value; }
72 inline const T& operator*() const { return m_value; }
73 inline T *operator->() { return &m_value; }
74 inline const T *operator->() const { return &m_value; }
75 /**@}*/
76private:
77
78 T m_value;
79 FbTk::Theme &m_tm;
80};
81
82
83
84/**
85 Hold themeitems. Use this to create a Theme set
86*/
87class Theme {
88public:
89 explicit Theme(int screen_num); // create a theme for a specific screen
90 virtual ~Theme();
91 virtual void reconfigTheme() = 0;
92 int screenNum() const { return m_screen_num; }
93 std::list<ThemeItem_base *> &itemList() { return m_themeitems; }
94 const std::list<ThemeItem_base *> &itemList() const { return m_themeitems; }
95 /// add ThemeItem
96 template <typename T>
97 void add(ThemeItem<T> &item);
98 /// remove ThemeItem
99 template <typename T>
100 void remove(ThemeItem<T> &item);
101private:
102 const int m_screen_num;
103 typedef std::list<ThemeItem_base *> ItemList;
104 ItemList m_themeitems;
105};
106
107
108/**
109 singleton theme manager
110*/
111class ThemeManager {
112public:
113 static ThemeManager &instance();
114 bool load(const char *filename);
115 std::string resourceValue(const std::string &name, const std::string &altname);
116 void loadTheme(Theme &tm);
117private:
118 ThemeManager();
119 ~ThemeManager() { }
120
121 friend class FbTk::Theme; // so only theme can register itself in constructor
122 /// @return false if screen_num if out of
123 // range or theme already registered, else true
124 bool registerTheme(FbTk::Theme &tm);
125 /// @return false if theme isn't registred in the manager
126 bool unregisterTheme(FbTk::Theme &tm);
127 /// map each theme manager to a screen
128 typedef std::list<FbTk::Theme *> ThemeList;
129 ThemeList m_themelist;
130 const int m_max_screens;
131 XrmDatabaseHelper m_database;
132};
133
134
135
136template <typename T>
137ThemeItem<T>::ThemeItem(FbTk::Theme &tm,
138 const std::string &name, const std::string &altname):
139 ThemeItem_base(name, altname),
140 m_tm(tm) {
141 tm.add(*this);
142}
143
144template <typename T>
145ThemeItem<T>::~ThemeItem() {
146 m_tm.remove(*this);
147}
148
149template <typename T>
150void Theme::add(ThemeItem<T> &item) {
151 m_themeitems.push_back(&item);
152 m_themeitems.unique();
153}
154
155template <typename T>
156void Theme::remove(ThemeItem<T> &item) {
157 m_themeitems.remove(&item);
158}
159
160}; // end namespace FbTk
161
162