1
// MenuTheme.cc for FbTk
2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
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.
22
// $Id: MenuTheme.cc 4043 2005-06-03 07:25:48Z mathias $
24
#include "MenuTheme.hh"
30
#include "StringUtil.hh"
41
MenuTheme::MenuTheme(int screen_num):
42
FbTk::Theme(screen_num),
43
t_text(*this, "menu.title.textColor", "Menu.Title.TextColor"),
44
f_text(*this, "menu.frame.textColor", "Menu.Frame.TextColor"),
45
h_text(*this, "menu.hilite.textColor", "Menu.Hilite.TextColor"),
46
d_text(*this, "menu.frame.disableColor", "Menu.Frame.DisableColor"),
47
title(*this, "menu.title", "Menu.Title"),
48
frame(*this, "menu.frame", "Menu.Frame"),
49
hilite(*this, "menu.hilite", "Menu.Hilite"),
50
titlefont(*this, "menu.title.font", "Menu.Title.Font"),
51
framefont(*this, "menu.frame.font", "Menu.Frame.Font"),
52
framefont_justify(*this, "menu.frame.justify", "Menu.Frame.Justify"),
53
titlefont_justify(*this, "menu.title.justify", "Menu.Title.Justify"),
54
bullet_pos(*this, "menu.bullet.position", "Menu.Bullet.Position"),
55
m_bullet(*this, "menu.bullet", "Menu.Bullet"),
56
m_title_height(*this, "menu.titleHeight", "Menu.TitleHeight"),
57
m_item_height(*this, "menu.itemHeight", "Menu.ItemHeight"),
58
m_border_width(*this, "menu.borderWidth", "Menu.BorderWidth"),
59
m_bevel_width(*this, "menu.bevelWidth", "Menu.BevelWidth"),
60
m_border_color(*this, "menu.borderColor", "Menu.BorderColor"),
61
m_bullet_pixmap(*this, "menu.submenu.pixmap", "Menu.Submenu.Pixmap"),
62
m_selected_pixmap(*this, "menu.selected.pixmap", "Menu.Selected.Pixmap"),
63
m_unselected_pixmap(*this, "menu.unselected.pixmap", "Menu.Unselected.Pixmap"),
64
m_hl_bullet_pixmap(*this, "menu.hilite.submenu.pixmap", "Menu.Hilite.Submenu.Pixmap"),
65
m_hl_selected_pixmap(*this, "menu.hilite.selected.pixmap", "Menu.Hilite.Selected.Pixmap"),
66
m_hl_unselected_pixmap(*this, "menu.hilite.unselected.pixmap", "Menu.Hilite.Unselected.Pixmap"),
67
m_display(FbTk::App::instance()->display()),
68
t_text_gc(RootWindow(m_display, screen_num)),
69
f_text_gc(RootWindow(m_display, screen_num)),
70
h_text_gc(RootWindow(m_display, screen_num)),
71
d_text_gc(RootWindow(m_display, screen_num)),
72
hilite_gc(RootWindow(m_display, screen_num)),
74
m_menumode(DELAY_OPEN),
75
m_delayopen(0), // no delay as default
76
m_delayclose(0), // no delay as default
77
m_real_title_height(*m_title_height),
78
m_real_item_height(*m_item_height)
80
m_real_item_height = std::max(*m_item_height, frameFont().height() + 2*bevelWidth());
81
m_real_title_height = std::max(*m_title_height,
82
titleFont().height() + 2*bevelWidth());
84
m_real_item_height = m_real_item_height == 0 ? 1 : m_real_item_height;
85
m_real_title_height = m_real_title_height == 0 ? 1 : m_real_title_height;
92
t_text_gc.setForeground(*t_text);
93
f_text_gc.setForeground(*f_text);
94
h_text_gc.setForeground(*h_text);
95
d_text_gc.setForeground(*d_text);
96
hilite_gc.setForeground(hilite->color());
100
MenuTheme::~MenuTheme() {
104
void MenuTheme::reconfigTheme() {
105
// clamp to "normal" size
106
if (*m_bevel_width > 20)
108
if (*m_border_width > 20)
109
*m_border_width = 20;
111
m_real_item_height = std::max(*m_item_height, frameFont().height() + 2*bevelWidth());
112
m_real_title_height = std::max(*m_title_height,
113
titleFont().height() + 2*bevelWidth());
115
unsigned int minsize = 2*bevelWidth()+1;
116
m_real_item_height = m_real_item_height < minsize ? minsize: m_real_item_height;
117
m_real_title_height = m_real_title_height == minsize ? minsize : m_real_title_height;
118
unsigned int item_pm_height = itemHeight();
120
m_bullet_pixmap->scale(item_pm_height, item_pm_height);
121
m_selected_pixmap->scale(item_pm_height, item_pm_height);
122
m_unselected_pixmap->scale(item_pm_height, item_pm_height);
124
m_hl_bullet_pixmap->scale(item_pm_height, item_pm_height);
125
m_hl_selected_pixmap->scale(item_pm_height, item_pm_height);
126
m_hl_unselected_pixmap->scale(item_pm_height, item_pm_height);
128
t_text_gc.setForeground(*t_text);
129
f_text_gc.setForeground(*f_text);
130
h_text_gc.setForeground(*h_text);
131
d_text_gc.setForeground(*d_text);
132
hilite_gc.setForeground(hilite->color());
135
bool MenuTheme::fallback(ThemeItem_base &item) {
136
if (item.name() == "menu.borderWidth") {
137
return ThemeManager::instance().loadItem(item, "borderWidth", "BorderWidth");
138
} else if (item.name() == "menu.borderColor") {
139
return ThemeManager::instance().loadItem(item, "borderColor", "BorderColor");
140
} else if (item.name() == "menu.bevelWidth") {
141
return ThemeManager::instance().loadItem(item, "bevelWidth", "BevelWidth");
149
void ThemeItem<MenuTheme::BulletType>::setDefaultValue() {
150
m_value = MenuTheme::EMPTY;
154
void ThemeItem<MenuTheme::BulletType>::setFromString(const char *str) {
157
if (StringUtil::strcasestr(str, "empty") != 0)
158
m_value = MenuTheme::EMPTY;
159
else if (StringUtil::strcasestr(str, "square") != 0)
160
m_value = MenuTheme::SQUARE;
161
else if (StringUtil::strcasestr(str, "triangle") != 0)
162
m_value = MenuTheme::TRIANGLE;
163
else if (StringUtil::strcasestr(str, "diamond") != 0)
164
m_value = MenuTheme::DIAMOND;
170
void ThemeItem<MenuTheme::BulletType>::load(const std::string *name, const std::string *altname) {
171
// do nothing, we don't have anything extra to load
174
}; // end namespace FbTk