summaryrefslogtreecommitdiff
path: root/src/FbTk/MenuTheme.hh
blob: d76c2fbbd56f82092333c3d42cd899d8f56abe26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// MenuTheme.hh for FbTk
// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
// 
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

// $Id$

#ifndef FBTK_MENUTHEME_HH
#define FBTK_MENUTHEME_HH

#include "Theme.hh"
#include "Color.hh"
#include "Font.hh"
#include "Shape.hh"
#include "Texture.hh"
#include "Text.hh"
#include "Subject.hh"
#include "PixmapWithMask.hh"
#include "GContext.hh"

namespace FbTk {

class MenuTheme:public Theme {
public:
    //!! TODO
    // this isn't actually used with a theme item
    // see setMenuMode() for more info
    enum MenuMode {CLICK_OPEN, DELAY_OPEN};

    enum BulletType { EMPTY, SQUARE, TRIANGLE, DIAMOND};
    MenuTheme(int screen_num);
    virtual ~MenuTheme();

    void reconfigTheme();

    bool fallback(ThemeItem_base &item);

    /**
       @name text colors
    */
    ///@{
    inline const Color &titleTextColor() const { return *t_text; }
    inline const Color &frameTextColor() const { return *f_text; }
    inline const Color &frameUnderlineColor() const { return *u_text; }
    inline const Color &highlightTextColor() const { return *h_text; }
    inline const Color &disableTextColor() const { return *d_text; }
    ///@}
    /**
       @name textures
    */
    ///@{
    inline const Texture &titleTexture() const { return *title; }
    inline const Texture &frameTexture() const { return *frame; }
    inline const Texture &hiliteTexture() const { return *hilite; }
    ///@}

    inline const PixmapWithMask &bulletPixmap() const { return *m_bullet_pixmap; }
    inline const PixmapWithMask &selectedPixmap() const { return *m_selected_pixmap; }
    inline const PixmapWithMask &unselectedPixmap() const { return *m_unselected_pixmap; }

    inline const PixmapWithMask &highlightBulletPixmap() const { return *m_hl_bullet_pixmap; }
    inline const PixmapWithMask &highlightSelectedPixmap() const { return *m_hl_selected_pixmap; }
    inline const PixmapWithMask &highlightUnselectedPixmap() const { return *m_hl_unselected_pixmap; }
    /**
       @name fonts
    */
    ///@{
    inline const Font &titleFont() const { return *titlefont; }
    inline Font &titleFont() { return *titlefont; }
    inline const Font &frameFont() const { return *framefont; }
    inline Font &frameFont() { return *framefont; }
    ///@}

    inline Justify frameFontJustify() const { return *framefont_justify; }
    inline Justify titleFontJustify() const { return *titlefont_justify; }
	
    /**
       @name graphic contexts
    */
    ///@{
    inline const GContext &titleTextGC() const { return t_text_gc; }
    inline const GContext &frameTextGC() const { return f_text_gc; }
    inline const GContext &frameUnderlineGC() const { return u_text_gc; }
    inline const GContext &hiliteTextGC() const { return h_text_gc; }
    inline const GContext &disableTextGC() const { return d_text_gc; }
    inline const GContext &hiliteGC() const { return hilite_gc; }
    inline GContext &titleTextGC() { return t_text_gc; }
    inline GContext &frameTextGC() { return f_text_gc; }
    inline GContext &frameUnderlineGC() { return u_text_gc; }
    inline GContext &hiliteTextGC() { return h_text_gc; }
    inline GContext &disableTextGC() { return d_text_gc; }
    inline GContext &hiliteGC() { return hilite_gc; }
    ///@}
    inline BulletType bullet() const { return *m_bullet; }
    inline Justify bulletPos() const { return *bullet_pos; }

    inline unsigned int titleHeight() const { return m_real_title_height; }
    inline unsigned int itemHeight() const { return m_real_item_height; }
    inline unsigned int borderWidth() const { return *m_border_width; }
    inline unsigned int bevelWidth() const { return *m_bevel_width; }

    inline unsigned char alpha() const { return m_alpha; }
    inline void setAlpha(unsigned char alpha) { m_alpha = alpha; }
    // this isn't actually a theme item
    // but we'll let it be here for now, until there's a better way to
    // get resources into menu
    inline void setMenuMode(MenuMode mode) { m_menumode = mode; }
    inline MenuMode menuMode() const { return m_menumode; }
    inline void setDelayOpen(int msec) { m_delayopen = msec; }
    inline void setDelayClose(int msec) { m_delayclose = msec; }
    inline int delayOpen() const { return m_delayopen; }
    inline int delayClose() const { return m_delayclose; }
    
    inline const Color &borderColor() const { return *m_border_color; }
    inline Shape::ShapePlace shapePlaces() const { return *m_shapeplace; }

    // special override
    inline void setSelectedPixmap(Pixmap pm, bool is_imagecached) {
        m_selected_pixmap->pixmap() = pm; 
        if (is_imagecached)
            m_selected_pixmap->pixmap().dontFree();
    }

    inline void setHighlightSelectedPixmap(Pixmap pm, bool is_imagecached) {
        m_hl_selected_pixmap->pixmap() = pm; 
        if (is_imagecached)
            m_hl_selected_pixmap->pixmap().dontFree();
    }

private:
    ThemeItem<Color> t_text, f_text, h_text, d_text, u_text;
    ThemeItem<Texture> title, frame, hilite;
    ThemeItem<Font> titlefont, framefont;
    ThemeItem<Justify> framefont_justify, titlefont_justify;
    ThemeItem<Justify> bullet_pos; 
    ThemeItem<BulletType> m_bullet;
    ThemeItem<Shape::ShapePlace> m_shapeplace;
    ThemeItem<unsigned int> m_title_height, m_item_height;
    ThemeItem<unsigned int> m_border_width;
    ThemeItem<unsigned int> m_bevel_width;
    ThemeItem<Color> m_border_color;
    ThemeItem<PixmapWithMask> m_bullet_pixmap, m_selected_pixmap, m_unselected_pixmap;
    ThemeItem<PixmapWithMask> m_hl_bullet_pixmap, m_hl_selected_pixmap, m_hl_unselected_pixmap;

    Display *m_display;
    GContext t_text_gc, f_text_gc, u_text_gc, h_text_gc, d_text_gc, hilite_gc;

    unsigned char m_alpha;
    MenuMode m_menumode;
    unsigned int m_delayopen; ///< in msec
    unsigned int m_delayclose; ///< in msec
    unsigned int m_real_title_height; ///< the calculated item height (from font and menu.titleHeight)
    unsigned int m_real_item_height; ///< the calculated item height (from font and menu.itemHeight)
};

} // end namespace FbTk

#endif // FBTK_MENUTHEME_HH