src/FbTk/MenuTheme.cc (raw)
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.cc 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$ #include "MenuTheme.hh" #include "Color.hh" #include "Texture.hh" #include "Font.hh" #include "App.hh" #include "StringUtil.hh" #ifdef HAVE_CSTDIO #include <cstdio> #else #include <stdio.h> #endif #include <algorithm> namespace FbTk { MenuTheme::MenuTheme(int screen_num): FbTk::Theme(screen_num), t_text(*this, "menu.title.textColor", "Menu.Title.TextColor"), f_text(*this, "menu.frame.textColor", "Menu.Frame.TextColor"), h_text(*this, "menu.hilite.textColor", "Menu.Hilite.TextColor"), d_text(*this, "menu.frame.disableColor", "Menu.Frame.DisableColor"), title(*this, "menu.title", "Menu.Title"), frame(*this, "menu.frame", "Menu.Frame"), hilite(*this, "menu.hilite", "Menu.Hilite"), titlefont(*this, "menu.title.font", "Menu.Title.Font"), framefont(*this, "menu.frame.font", "Menu.Frame.Font"), framefont_justify(*this, "menu.frame.justify", "Menu.Frame.Justify"), titlefont_justify(*this, "menu.title.justify", "Menu.Title.Justify"), bullet_pos(*this, "menu.bullet.position", "Menu.Bullet.Position"), m_bullet(*this, "menu.bullet", "Menu.Bullet"), m_title_height(*this, "menu.titleHeight", "Menu.TitleHeight"), m_item_height(*this, "menu.itemHeight", "Menu.ItemHeight"), m_border_width(*this, "menu.borderWidth", "Menu.BorderWidth"), m_bevel_width(*this, "menu.bevelWidth", "Menu.BevelWidth"), m_border_color(*this, "menu.borderColor", "Menu.BorderColor"), m_bullet_pixmap(*this, "menu.submenu.pixmap", "Menu.Submenu.Pixmap"), m_selected_pixmap(*this, "menu.selected.pixmap", "Menu.Selected.Pixmap"), m_unselected_pixmap(*this, "menu.unselected.pixmap", "Menu.Unselected.Pixmap"), m_hl_bullet_pixmap(*this, "menu.hilite.submenu.pixmap", "Menu.Hilite.Submenu.Pixmap"), m_hl_selected_pixmap(*this, "menu.hilite.selected.pixmap", "Menu.Hilite.Selected.Pixmap"), m_hl_unselected_pixmap(*this, "menu.hilite.unselected.pixmap", "Menu.Hilite.Unselected.Pixmap"), m_display(FbTk::App::instance()->display()), t_text_gc(RootWindow(m_display, screen_num)), f_text_gc(RootWindow(m_display, screen_num)), h_text_gc(RootWindow(m_display, screen_num)), d_text_gc(RootWindow(m_display, screen_num)), hilite_gc(RootWindow(m_display, screen_num)), m_alpha(255), m_menumode(DELAY_OPEN), m_delayopen(0), // no delay as default m_delayclose(0), // no delay as default m_real_title_height(*m_title_height), m_real_item_height(*m_item_height) { m_real_item_height = std::max(*m_item_height, frameFont().height() + 2*bevelWidth()); m_real_title_height = std::max(*m_title_height, titleFont().height() + 2*bevelWidth()); m_real_item_height = m_real_item_height == 0 ? 1 : m_real_item_height; m_real_title_height = m_real_title_height == 0 ? 1 : m_real_title_height; // set default values *m_border_width = 0; *m_bevel_width = 0; *m_border_width = 0; t_text_gc.setForeground(*t_text); f_text_gc.setForeground(*f_text); h_text_gc.setForeground(*h_text); d_text_gc.setForeground(*d_text); hilite_gc.setForeground(hilite->color()); } MenuTheme::~MenuTheme() { } void MenuTheme::reconfigTheme() { // clamp to "normal" size if (*m_bevel_width > 20) *m_bevel_width = 20; if (*m_border_width > 20) *m_border_width = 20; m_real_item_height = std::max(*m_item_height, frameFont().height() + 2*bevelWidth()); m_real_title_height = std::max(*m_title_height, titleFont().height() + 2*bevelWidth()); unsigned int minsize = 2*bevelWidth()+1; m_real_item_height = m_real_item_height < minsize ? minsize: m_real_item_height; m_real_title_height = m_real_title_height == minsize ? minsize : m_real_title_height; unsigned int item_pm_height = itemHeight(); m_bullet_pixmap->scale(item_pm_height, item_pm_height); m_selected_pixmap->scale(item_pm_height, item_pm_height); m_unselected_pixmap->scale(item_pm_height, item_pm_height); m_hl_bullet_pixmap->scale(item_pm_height, item_pm_height); m_hl_selected_pixmap->scale(item_pm_height, item_pm_height); m_hl_unselected_pixmap->scale(item_pm_height, item_pm_height); t_text_gc.setForeground(*t_text); f_text_gc.setForeground(*f_text); h_text_gc.setForeground(*h_text); d_text_gc.setForeground(*d_text); hilite_gc.setForeground(hilite->color()); } bool MenuTheme::fallback(ThemeItem_base &item) { if (item.name() == "menu.borderWidth") { return ThemeManager::instance().loadItem(item, "borderWidth", "BorderWidth"); } else if (item.name() == "menu.borderColor") { return ThemeManager::instance().loadItem(item, "borderColor", "BorderColor"); } else if (item.name() == "menu.bevelWidth") { return ThemeManager::instance().loadItem(item, "bevelWidth", "BevelWidth"); } return false; } template <> void ThemeItem<MenuTheme::BulletType>::setDefaultValue() { m_value = MenuTheme::EMPTY; } template <> void ThemeItem<MenuTheme::BulletType>::setFromString(const char *str) { // do nothing if (StringUtil::strcasestr(str, "empty") != 0) m_value = MenuTheme::EMPTY; else if (StringUtil::strcasestr(str, "square") != 0) m_value = MenuTheme::SQUARE; else if (StringUtil::strcasestr(str, "triangle") != 0) m_value = MenuTheme::TRIANGLE; else if (StringUtil::strcasestr(str, "diamond") != 0) m_value = MenuTheme::DIAMOND; else setDefaultValue(); } template <> void ThemeItem<MenuTheme::BulletType>::load(const std::string *name, const std::string *altname) { // do nothing, we don't have anything extra to load } }; // end namespace FbTk |