aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuTheme.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/MenuTheme.cc')
-rw-r--r--src/FbTk/MenuTheme.cc159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/FbTk/MenuTheme.cc b/src/FbTk/MenuTheme.cc
new file mode 100644
index 0000000..82a6a51
--- /dev/null
+++ b/src/FbTk/MenuTheme.cc
@@ -0,0 +1,159 @@
1// MenuTheme.cc for FbTk
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net)
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: MenuTheme.cc,v 1.6 2003/02/23 01:00:48 fluxgen Exp $
23
24#include "MenuTheme.hh"
25
26#include "Color.hh"
27#include "Texture.hh"
28#include "Font.hh"
29#include "App.hh"
30//TODO change this
31#include "../StringUtil.hh"
32#include <cstdio>
33
34namespace FbTk {
35
36MenuTheme::MenuTheme(int screen_num):
37 FbTk::Theme(screen_num),
38 t_text(*this, "menu.title.textColor", "Menu.Title.TextColor"),
39 f_text(*this, "menu.frame.textColor", "Menu.Frame.TextColor"),
40 h_text(*this, "menu.hilite.textColor", "Menu.Hilite.TextColor"),
41 d_text(*this, "menu.frame.disableColor", "Menu.Frame.DisableColor"),
42 title(*this, "menu.title", "Menu.Title"),
43 frame(*this, "menu.frame", "Menu.Frame"),
44 hilite(*this, "menu.hilite", "Menu.Hilite"),
45 titlefont(*this, "menu.title.font", "Menu.Title.Font"),
46 framefont(*this, "menu.frame.font", "Menu.Frame.Font"),
47 framefont_justify(*this, "menu.frame.justify", "Menu.Frame.Justify"),
48 titlefont_justify(*this, "menu.title.justify", "Menu.Title.Justify"),
49 bullet_pos(*this, "menu.bullet.position", "Menu.Bullet.Position"),
50 m_bullet(*this, "menu.bullet", "Menu.Bullet"),
51 m_border_width(*this, "borderWidth", "BorderWidth"),
52 m_bevel_width(*this, "bevelWidth", "BevelWidth"),
53 m_border_color(*this, "borderColor", "BorderColor"),
54 m_display(FbTk::App::instance()->display()) {
55
56 Window rootwindow = RootWindow(m_display, screen_num);
57
58 XGCValues gcv;
59 unsigned long gc_value_mask = GCForeground;
60 gcv.foreground = t_text->pixel();
61
62 t_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv);
63
64 gcv.foreground = f_text->pixel();
65
66 f_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv);
67
68 gcv.foreground = h_text->pixel();
69 h_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv);
70
71 gcv.foreground = d_text->pixel();
72 d_text_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv);
73
74 gcv.foreground = hilite->color().pixel();
75 hilite_gc = XCreateGC(m_display, rootwindow, gc_value_mask, &gcv);
76}
77
78MenuTheme::~MenuTheme() {
79 XFreeGC(m_display, t_text_gc);
80 XFreeGC(m_display, f_text_gc);
81 XFreeGC(m_display, h_text_gc);
82 XFreeGC(m_display, d_text_gc);
83 XFreeGC(m_display, hilite_gc);
84}
85
86void MenuTheme::reconfigTheme() {
87
88 XGCValues gcv;
89 unsigned long gc_value_mask = GCForeground;
90
91 gcv.foreground = t_text->pixel();
92
93 XChangeGC(m_display, t_text_gc,
94 gc_value_mask, &gcv);
95
96 gcv.foreground = f_text->pixel();
97
98 XChangeGC(m_display, f_text_gc,
99 gc_value_mask, &gcv);
100
101 gcv.foreground = h_text->pixel();
102 XChangeGC(m_display, h_text_gc,
103 gc_value_mask, &gcv);
104
105 gcv.foreground = d_text->pixel();
106 XChangeGC(m_display, d_text_gc,
107 gc_value_mask, &gcv);
108
109 gcv.foreground = hilite->color().pixel();
110 XChangeGC(m_display, hilite_gc,
111 gc_value_mask, &gcv);
112
113 // notify any listeners
114 m_theme_change_sig.notify();
115}
116
117
118template <>
119void ThemeItem<MenuTheme::BulletType>::setDefaultValue() {
120 m_value = MenuTheme::EMPTY;
121}
122
123template <>
124void ThemeItem<MenuTheme::BulletType>::setFromString(const char *str) {
125
126 // do nothing
127 if (StringUtil::strcasestr(str, "empty") != 0)
128 m_value = MenuTheme::EMPTY;
129 else if (StringUtil::strcasestr(str, "square") != 0)
130 m_value = MenuTheme::SQUARE;
131 else if (StringUtil::strcasestr(str, "triangle") != 0)
132 m_value = MenuTheme::TRIANGLE;
133 else if (StringUtil::strcasestr(str, "diamond") != 0)
134 m_value = MenuTheme::DIAMOND;
135 else
136 setDefaultValue();
137}
138
139template <>
140void ThemeItem<MenuTheme::BulletType>::load() {
141 // do nothing, we don't have anything extra to load
142}
143
144template <>
145void ThemeItem<unsigned int>::setDefaultValue() {
146 m_value = 0;
147}
148
149template <>
150void ThemeItem<unsigned int>::setFromString(const char *str) {
151 sscanf(str, "%d", &m_value);
152}
153
154template <>
155void ThemeItem<unsigned int>::load() {
156}
157
158
159}; // end namespace FbTk