From 47f9b7719470d592eb0762464de13547fd7d1240 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 22 Jun 2016 14:30:49 +0300 Subject: [PATCH] WMenuBar: remove WMenuBar::is_active. Use WST_FOCUSED instead. Signed-off-by: Andrew Borodin --- lib/widget/menu.c | 35 +++++++++++++++++++++-------------- lib/widget/menu.h | 1 - src/editor/editwidget.c | 2 +- src/filemanager/midnight.c | 4 ++-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/widget/menu.c b/lib/widget/menu.c index 3d2e3c1d5..264810bd5 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -198,7 +198,7 @@ menubar_draw_drop (WMenuBar * menubar) static void menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey) { - if (!menubar->is_active) + if (!widget_get_state (WIDGET (menubar), WST_FOCUSED)) tty_setcolor (MENU_INACTIVE_COLOR); else if (current) tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR); @@ -215,7 +215,7 @@ menubar_draw (WMenuBar * menubar) GList *i; /* First draw the complete menubar */ - tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR); + tty_setcolor (widget_get_state (w, WST_FOCUSED) ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR); tty_draw_hline (w->y, w->x, ' ', w->cols); /* Now each one of the entries */ @@ -304,8 +304,8 @@ menubar_finish (WMenuBar * menubar) { Widget *w = WIDGET (menubar); + widget_set_state (w, WST_FOCUSED, FALSE); menubar->is_dropped = FALSE; - menubar->is_active = FALSE; w->lines = 1; widget_want_hotkey (w, FALSE); widget_set_options (w, WOP_SELECTABLE, FALSE); @@ -578,7 +578,7 @@ menubar_refresh (WMenuBar * menubar) { Widget *w = WIDGET (menubar); - if (!menubar->is_active) + if (!widget_get_state (w, WST_FOCUSED)) return FALSE; /* Trick to get all the mouse events */ @@ -591,6 +591,15 @@ menubar_refresh (WMenuBar * menubar) /* --------------------------------------------------------------------------------------------- */ +static void +menubar_free_menu (WMenuBar * menubar) +{ + if (menubar->menu != NULL) + g_list_free_full (menubar->menu, (GDestroyNotify) destroy_menu); +} + +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { @@ -608,12 +617,12 @@ menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void return MSG_NOT_HANDLED; case MSG_UNFOCUS: - return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED; + return widget_get_state (w, WST_FOCUSED) ? MSG_NOT_HANDLED : MSG_HANDLED; /* We don't want the buttonbar to activate while using the menubar */ case MSG_HOTKEY: case MSG_KEY: - if (menubar->is_active) + if (widget_get_state (w, WST_FOCUSED)) { menubar_handle_key (menubar, parm); return MSG_HANDLED; @@ -635,7 +644,7 @@ menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void return MSG_HANDLED; case MSG_DESTROY: - menubar_set_menu (menubar, NULL); + menubar_free_menu (menubar); return MSG_HANDLED; default: @@ -795,7 +804,7 @@ menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) case MSG_MOUSE_SCROLL_DOWN: was_drag = FALSE; - if (menubar->is_active) + if (widget_get_state (w, WST_FOCUSED)) { if (event->y == 0) { @@ -918,15 +927,13 @@ void menubar_set_menu (WMenuBar * menubar, GList * menu) { /* delete previous menu */ - if (menubar->menu != NULL) - g_list_free_full (menubar->menu, (GDestroyNotify) destroy_menu); - + menubar_free_menu (menubar); /* add new menu */ - menubar->is_active = FALSE; menubar->is_dropped = FALSE; menubar->menu = menu; menubar->selected = 0; menubar_arrange (menubar); + widget_set_state (WIDGET (menubar), WST_FOCUSED, FALSE); } /* --------------------------------------------------------------------------------------------- */ @@ -1018,11 +1025,11 @@ menubar_activate (WMenuBar * menubar, gboolean dropped, int which) { Widget *w = WIDGET (menubar); - if (!menubar->is_active) + if (!widget_get_state (w, WST_FOCUSED)) { widget_set_options (w, WOP_SELECTABLE, TRUE); - menubar->is_active = TRUE; + widget_set_state (w, WST_FOCUSED, TRUE); /* FIXME: unneeded? */ menubar->is_dropped = dropped; if (which >= 0) menubar->selected = (guint) which; diff --git a/lib/widget/menu.h b/lib/widget/menu.h index 6a2ec0e46..5d9323517 100644 --- a/lib/widget/menu.h +++ b/lib/widget/menu.h @@ -31,7 +31,6 @@ typedef struct WMenuBar Widget widget; gboolean is_visible; /* If the menubar is visible */ - gboolean is_active; /* If the menubar is in use */ gboolean is_dropped; /* If the menubar has dropped */ GList *menu; /* The actual menus */ guint selected; /* Selected menu on the top bar */ diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 478983de2..2d4917b6c 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -880,7 +880,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) b = find_menubar (h); - if (!b->is_active) + if (!widget_get_state (WIDGET (b), WST_FOCUSED)) { /* menubar */ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 40c8ba71b..db9c17d17 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -1449,7 +1449,7 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void } /* FIXME: should handle all menu shortcuts before this point */ - if (the_menubar->is_active) + if (widget_get_state (WIDGET (the_menubar), WST_FOCUSED)) return MSG_NOT_HANDLED; if (parm == '\t') @@ -1550,7 +1550,7 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void } case MSG_POST_KEY: - if (!the_menubar->is_active) + if (!widget_get_state (WIDGET (the_menubar), WST_FOCUSED)) update_dirty_panels (); return MSG_HANDLED;