From 7d4f711204ab0b51d45eaff332708f529c11c9f5 Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 3 May 2005 13:53:25 +0000 Subject: fix some menu drawing issues --- ChangeLog | 3 +++ src/FbTk/Menu.cc | 7 +++++-- src/FbTk/MenuItem.hh | 22 ++++++++++++++++++++-- src/IntResMenuItem.cc | 14 ++++++++++++-- src/IntResMenuItem.hh | 2 +- src/Screen.cc | 6 +++--- src/Slit.cc | 2 +- src/ToggleMenu.hh | 7 ++----- src/Toolbar.cc | 4 ++-- 9 files changed, 49 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8c3321..c763691 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ (Format: Year/Month/Day) Changes for 0.9.13 *05/05/03: + * Fix drawing of no-title menus, plus updating of int menu items (Simon) + IntResMenuItem.hh/cc MenuItem.hh Menu.cc Screen.cc ToggleMenu.hh + Toolbar.cc Slit.cc * Code cleaning. (Henrik) Fluxbox::associateClient; creates tab and maps WinClient to label button. diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index fbf7e45..e0e3e7f 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -475,7 +475,7 @@ void Menu::updateMenu(int active_index) { } menu.frame.moveResize(0, ((m_title_vis) ? menu.title.y() + menu.title.height() + - menu.title.borderWidth()*2 : 1), + menu.title.borderWidth()*2 : 0), width(), menu.frame_h); if (m_title_vis && m_need_update) { @@ -927,6 +927,8 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { } m_moving = m_torn = true; + // clear current highlighted item + clearItem(m_active_index); if (m_which_sub >= 0) drawSubmenu(m_which_sub); @@ -1238,7 +1240,8 @@ void Menu::clearItem(int index, bool clear) { int item_x = (sbl * item_w), item_y = (i * item_h); bool highlight = (index == m_active_index); - if (highlight) { + // don't highlight if moving, doesn't work with alpha on + if (highlight && !m_moving) { highlightItem(index); return; } else if (clear) diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh index 20da8f7..b3b2f6b 100644 --- a/src/FbTk/MenuItem.hh +++ b/src/FbTk/MenuItem.hh @@ -42,6 +42,7 @@ class MenuItem { public: MenuItem() : m_label(""), + m_menu(0), m_submenu(0), m_enabled(true), m_selected(false), @@ -50,14 +51,25 @@ public: explicit MenuItem( const char *label) : m_label(label ? label : ""), + m_menu(0), + m_submenu(0), + m_enabled(true), + m_selected(false), + m_toggle_item(false) + { } + + MenuItem(const char *label, Menu &host_menu) + : m_label(label ? label : ""), + m_menu(&host_menu), m_submenu(0), m_enabled(true), m_selected(false), m_toggle_item(false) { } /// create a menu item with a specific command to be executed on click - MenuItem(const char *label, RefCount &cmd): + MenuItem(const char *label, RefCount &cmd, Menu *menu = 0): m_label(label ? label : ""), + m_menu(menu), m_submenu(0), m_command(cmd), m_enabled(true), @@ -66,8 +78,9 @@ public: } - MenuItem(const char *label, Menu *submenu) + MenuItem(const char *label, Menu *submenu, Menu *host_menu = 0) : m_label(label ? label : "") + , m_menu(host_menu) , m_submenu(submenu) , m_enabled(true) , m_selected(false), @@ -110,9 +123,13 @@ public: RefCount &command() { return m_command; } const RefCount &command() const { return m_command; } //@} + + void setMenu(Menu &menu) { m_menu = &menu; } + Menu *menu() { return m_menu; } private: std::string m_label; ///< label of this item + Menu *m_menu; ///< the menu we live in Menu *m_submenu; ///< a submenu, 0 if we don't have one RefCount m_command; ///< command to be executed bool m_enabled, m_selected; @@ -123,6 +140,7 @@ private: std::string filename; }; std::auto_ptr m_icon; + }; } // end namespace FbTk diff --git a/src/IntResMenuItem.cc b/src/IntResMenuItem.cc index a1595a6..30aead1 100644 --- a/src/IntResMenuItem.cc +++ b/src/IntResMenuItem.cc @@ -21,8 +21,11 @@ // $Id$ +#include "FbTk/Menu.hh" + #include "IntResMenuItem.hh" #include "PixmapWithMask.hh" + #ifdef HAVE_CSTDIO #include #else @@ -41,8 +44,8 @@ std::string appendIntValue(const std::string &label, int value) { }; -IntResMenuItem::IntResMenuItem(const char *label, FbTk::Resource &res, int min_val, int max_val): - FbTk::MenuItem(label), m_org_label(FbTk::MenuItem::label()), +IntResMenuItem::IntResMenuItem(const char *label, FbTk::Resource &res, int min_val, int max_val, FbTk::Menu &host_menu): + FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()), m_max(max_val), m_min(min_val), m_res(res) { setLabel(appendIntValue(m_org_label, *m_res).c_str()); } @@ -72,4 +75,11 @@ void IntResMenuItem::click(int button, int time) { setLabel(appendIntValue(m_org_label, *m_res).c_str()); // call other commands FbTk::MenuItem::click(button, time); + + // show new value, which for us means forcing a full menu update + // since the text is drawn onto the background! + if (menu()) { + menu()->frameWindow().updateBackground(false); + menu()->clearWindow(); + } } diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh index cfbdd54..7e82be1 100644 --- a/src/IntResMenuItem.hh +++ b/src/IntResMenuItem.hh @@ -30,7 +30,7 @@ /// Changes an resource integer value between min and max class IntResMenuItem: public FbTk::MenuItem { public: - IntResMenuItem(const char *label, FbTk::Resource &res, int min_val, int max_val); + IntResMenuItem(const char *label, FbTk::Resource &res, int min_val, int max_val, FbTk::Menu &host_menu); void click(int button, int time); diff --git a/src/Screen.cc b/src/Screen.cc index 36ab193..68ae3a4 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -1829,17 +1829,17 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { } FbTk::MenuItem *focused_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", "Transparency level of the focused window"), - resource.focused_alpha, 0, 255); + resource.focused_alpha, 0, 255, *alpha_menu); focused_alpha_item->setCommand(saverc_cmd); alpha_menu->insert(focused_alpha_item); FbTk::MenuItem *unfocused_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, UnfocusedAlpha, "Unfocused Window Alpha", "Transparency level of unfocused windows"), - resource.unfocused_alpha, 0, 255); + resource.unfocused_alpha, 0, 255, *alpha_menu); unfocused_alpha_item->setCommand(saverc_cmd); alpha_menu->insert(unfocused_alpha_item); FbTk::MenuItem *menu_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu"), - resource.menu_alpha, 0, 255); + resource.menu_alpha, 0, 255, *alpha_menu); menu_alpha_item->setCommand(saverc_cmd); alpha_menu->insert(menu_alpha_item); diff --git a/src/Slit.cc b/src/Slit.cc index 9221377..eb26320 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -1257,7 +1257,7 @@ void Slit::setupMenu() { FbTk::MenuItem *alpha_menuitem = new IntResMenuItem(_FBTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, - 0, 255); + 0, 255, m_slitmenu); // setup command for alpha value MacroCommand *alpha_macrocmd = new MacroCommand(); RefCount alpha_cmd(new SimpleCommand(*this, &Slit::updateAlpha)); diff --git a/src/ToggleMenu.hh b/src/ToggleMenu.hh index f506df8..794c016 100644 --- a/src/ToggleMenu.hh +++ b/src/ToggleMenu.hh @@ -48,11 +48,8 @@ public: // so that the last toggled item gets redrawn as // not toggled. if (ev.window == frameWindow()) { - // force full foreground update (by setting bg to same thing) - frameWindow().parentMoved(); -// for (size_t i = 0; i < numberOfItems(); ++i) { -// clearItem(i); -// } + // force full foreground update + frameWindow().updateBackground(false); } } diff --git a/src/Toolbar.cc b/src/Toolbar.cc index dad91aa..0f16140 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -796,7 +796,7 @@ void Toolbar::setupMenus() { MenuItem *toolbar_menuitem = new IntResMenuItem(_FBTEXT(Toolbar, WidthPercent, "Toolbar width percent", "Percentage of screen width taken by toolbar"), m_rc_width_percent, - 0, 100); // min/max value + 0, 100, menu()); // min/max value RefCommand reconfig_toolbar(new ToolbarCommand(*this, &Toolbar::reconfigure)); @@ -886,7 +886,7 @@ void Toolbar::setupMenus() { FbTk::MenuItem *alpha_menuitem = new IntResMenuItem(_FBTEXT(Common, Alpha, "Alpha", "Transparency level"), m_rc_alpha, - 0, 255); + 0, 255, menu()); // setup command for alpha value MacroCommand *alpha_macrocmd = new MacroCommand(); RefCount alpha_cmd(new SimpleCommand(*this, &Toolbar::updateAlpha)); -- cgit v0.11.2