~ubuntu-branches/ubuntu/precise/fluxbox/precise

« back to all changes in this revision

Viewing changes to src/FbTk/MenuTheme.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// MenuTheme.cc for FbTk
2
 
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot 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: MenuTheme.cc 4043 2005-06-03 07:25:48Z mathias $
23
 
 
24
 
#include "MenuTheme.hh"
25
 
 
26
 
#include "Color.hh"
27
 
#include "Texture.hh"
28
 
#include "Font.hh"
29
 
#include "App.hh"
30
 
#include "StringUtil.hh"
31
 
 
32
 
#ifdef HAVE_CSTDIO
33
 
  #include <cstdio>
34
 
#else
35
 
  #include <stdio.h>
36
 
#endif
37
 
#include <algorithm>
38
 
 
39
 
namespace FbTk {
40
 
 
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)),
73
 
    m_alpha(255),
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)
79
 
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());
83
 
 
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;
86
 
 
87
 
    // set default values
88
 
    *m_border_width = 0;
89
 
    *m_bevel_width = 0;
90
 
    *m_border_width = 0;
91
 
 
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());
97
 
 
98
 
}
99
 
 
100
 
MenuTheme::~MenuTheme() {
101
 
 
102
 
}
103
 
 
104
 
void MenuTheme::reconfigTheme() {
105
 
    // clamp to "normal" size
106
 
    if (*m_bevel_width > 20)
107
 
        *m_bevel_width = 20;
108
 
    if (*m_border_width > 20)
109
 
        *m_border_width = 20;
110
 
 
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());
114
 
 
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();
119
 
 
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);
123
 
 
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);
127
 
 
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());
133
 
}
134
 
 
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");
142
 
    }
143
 
 
144
 
    return false;
145
 
}
146
 
 
147
 
 
148
 
template <>
149
 
void ThemeItem<MenuTheme::BulletType>::setDefaultValue() {
150
 
    m_value = MenuTheme::EMPTY;
151
 
}
152
 
 
153
 
template <>
154
 
void ThemeItem<MenuTheme::BulletType>::setFromString(const char *str) {
155
 
 
156
 
    // do nothing
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;
165
 
    else
166
 
        setDefaultValue();
167
 
}
168
 
 
169
 
template <>
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
172
 
}
173
 
 
174
 
}; // end namespace  FbTk