make MenuItem responsible for decision to close menu when clicked
This commit is contained in:
parent
c39af52bfc
commit
31df2d8bd6
8 changed files with 43 additions and 31 deletions
|
@ -34,11 +34,13 @@ public:
|
|||
FbTk::MenuItem(label, cmd), m_item(item) {
|
||||
FbTk::MenuItem::setSelected(m_item);
|
||||
setToggleItem(true);
|
||||
setCloseOnClick(false);
|
||||
}
|
||||
BoolMenuItem(const FbTk::FbString &label, bool &item):
|
||||
FbTk::MenuItem(label), m_item(item) {
|
||||
FbTk::MenuItem::setSelected(m_item);
|
||||
setToggleItem(true);
|
||||
setToggleItem(true);
|
||||
setCloseOnClick(false);
|
||||
}
|
||||
bool isSelected() const { return m_item; }
|
||||
// toggle state
|
||||
|
|
|
@ -199,15 +199,15 @@ Menu::~Menu() {
|
|||
}
|
||||
|
||||
int Menu::insert(const FbString &label, RefCount<Command> &cmd, int pos) {
|
||||
return insert(new MenuItem(label, cmd), pos);
|
||||
return insert(new MenuItem(label, cmd, this), pos);
|
||||
}
|
||||
|
||||
int Menu::insert(const FbString &label, int pos) {
|
||||
return insert(new MenuItem(label), pos);
|
||||
return insert(new MenuItem(label, *this), pos);
|
||||
}
|
||||
|
||||
int Menu::insert(const FbString &label, Menu *submenu, int pos) {
|
||||
return insert(new MenuItem(label, submenu), pos);
|
||||
return insert(new MenuItem(label, submenu, this), pos);
|
||||
}
|
||||
|
||||
int Menu::insert(MenuItem *item, int pos) {
|
||||
|
@ -516,15 +516,15 @@ void Menu::show() {
|
|||
raise();
|
||||
|
||||
if (shown && shown != this && shown != m_parent)
|
||||
shown->hide(true);
|
||||
shown->hide();
|
||||
shown = this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Menu::hide(bool force) {
|
||||
void Menu::hide() {
|
||||
|
||||
if (!isVisible() || m_torn && !force)
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
// if parent is visible, go to first parent and hide it
|
||||
|
@ -570,6 +570,9 @@ void Menu::redrawFrame(FbDrawable &drawable) {
|
|||
|
||||
void Menu::internal_hide(bool first) {
|
||||
|
||||
if (!first && m_torn)
|
||||
return;
|
||||
|
||||
if (validIndex(m_which_sub)) {
|
||||
MenuItem *tmp = menuitems[m_which_sub];
|
||||
tmp->submenu()->internal_hide(false);
|
||||
|
@ -815,8 +818,6 @@ void Menu::handleEvent(XEvent &event) {
|
|||
if (event.type == FocusOut) {
|
||||
if (s_focused == this)
|
||||
s_focused = 0;
|
||||
if (shown == this && !m_torn)
|
||||
hide();
|
||||
// I don't know why, but I get a FocusIn event when closing the menu with
|
||||
// the mouse over it -- probably an xorg bug, but it's easy to address here
|
||||
} else if (event.type == FocusIn && m_visible) {
|
||||
|
@ -1275,9 +1276,9 @@ void Menu::drawLine(int index, int size){
|
|||
item->drawLine(menu.frame, theme(), size, item_x, item_y, menu.item_w);
|
||||
}
|
||||
|
||||
void Menu::hideShownMenu(bool force) {
|
||||
void Menu::hideShownMenu() {
|
||||
if (shown)
|
||||
shown->hide(force);
|
||||
shown->hide();
|
||||
}
|
||||
|
||||
}; // end namespace FbTk
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
/// show menu
|
||||
virtual void show();
|
||||
/// hide menu
|
||||
virtual void hide(bool force = false);
|
||||
virtual void hide();
|
||||
virtual void clearWindow();
|
||||
#ifdef NOT_USED
|
||||
void setActiveIndex(int index) { m_active_index = index; }
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
inline unsigned char alpha() const { return theme().alpha(); }
|
||||
inline static Menu *shownMenu() { return shown; }
|
||||
inline static Menu *focused() { return s_focused; }
|
||||
static void hideShownMenu(bool force = true);
|
||||
static void hideShownMenu();
|
||||
/// @return menuitem at index
|
||||
inline const MenuItem *find(unsigned int index) const { return menuitems[index]; }
|
||||
inline MenuItem *find(unsigned int index) { return menuitems[index]; }
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace FbTk {
|
|||
|
||||
void MenuItem::click(int button, int time) {
|
||||
if (m_command.get() != 0) {
|
||||
if (m_menu && m_close_on_click)
|
||||
m_menu->hide();
|
||||
// we need a local variable, since the command may destroy this object
|
||||
RefCount<Command> tmp(m_command);
|
||||
tmp->execute();
|
||||
|
|
|
@ -47,15 +47,16 @@ public:
|
|||
m_submenu(0),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_close_on_click(true),
|
||||
m_toggle_item(false)
|
||||
{ }
|
||||
explicit MenuItem(
|
||||
const FbString &label)
|
||||
explicit MenuItem(const FbString &label)
|
||||
: m_label(label),
|
||||
m_menu(0),
|
||||
m_submenu(0),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_close_on_click(true),
|
||||
m_toggle_item(false)
|
||||
{ }
|
||||
|
||||
|
@ -65,26 +66,28 @@ public:
|
|||
m_submenu(0),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_close_on_click(true),
|
||||
m_toggle_item(false)
|
||||
{ }
|
||||
/// create a menu item with a specific command to be executed on click
|
||||
MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0):
|
||||
m_label(label),
|
||||
m_menu(menu),
|
||||
m_submenu(0),
|
||||
m_command(cmd),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_toggle_item(false) {
|
||||
|
||||
}
|
||||
MenuItem(const FbString &label, RefCount<Command> &cmd, Menu *menu = 0)
|
||||
: m_label(label),
|
||||
m_menu(menu),
|
||||
m_submenu(0),
|
||||
m_command(cmd),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_close_on_click(true),
|
||||
m_toggle_item(false)
|
||||
{ }
|
||||
|
||||
MenuItem(const FbString &label, Menu *submenu, Menu *host_menu = 0)
|
||||
: m_label(label)
|
||||
, m_menu(host_menu)
|
||||
, m_submenu(submenu)
|
||||
, m_enabled(true)
|
||||
, m_selected(false),
|
||||
: m_label(label),
|
||||
m_menu(host_menu),
|
||||
m_submenu(submenu),
|
||||
m_enabled(true),
|
||||
m_selected(false),
|
||||
m_close_on_click(true),
|
||||
m_toggle_item(false)
|
||||
{ }
|
||||
virtual ~MenuItem() { }
|
||||
|
@ -94,6 +97,7 @@ public:
|
|||
virtual void setEnabled(bool enabled) { m_enabled = enabled; }
|
||||
virtual void setLabel(const FbString &label) { m_label = label; }
|
||||
virtual void setToggleItem(bool val) { m_toggle_item = val; }
|
||||
void setCloseOnClick(bool val) { m_close_on_click = val; }
|
||||
void setIcon(const std::string &filename, int screen_num);
|
||||
virtual Menu *submenu() { return m_submenu; }
|
||||
/**
|
||||
|
@ -150,7 +154,7 @@ private:
|
|||
Menu *m_submenu; ///< a submenu, 0 if we don't have one
|
||||
RefCount<Command> m_command; ///< command to be executed
|
||||
bool m_enabled, m_selected;
|
||||
bool m_toggle_item;
|
||||
bool m_close_on_click, m_toggle_item;
|
||||
int m_index;
|
||||
|
||||
struct Icon {
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
FbTk::MenuItem(label, host_menu), m_org_label(FbTk::MenuItem::label()),
|
||||
m_max(max_val), m_min(min_val), m_res(res) {
|
||||
updateLabel();
|
||||
setCloseOnClick(false);
|
||||
}
|
||||
|
||||
/* Utility, but doesn't get found in anonymous namespace? */
|
||||
|
|
|
@ -40,6 +40,7 @@ RootCmdMenuItem::RootCmdMenuItem(const FbTk::FbString &label,
|
|||
setwp_cmd(new FbCommands::ExecuteCmd(prog + " \"" + m_filename + "\""));
|
||||
setCommand(setwp_cmd);
|
||||
setToggleItem(true);
|
||||
setCloseOnClick(false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ StyleMenuItem::StyleMenuItem(const FbTk::FbString &label, const std::string &fil
|
|||
SetStyleCmd(m_filename));
|
||||
setCommand(setstyle_cmd);
|
||||
setToggleItem(true);
|
||||
setCloseOnClick(false);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue