diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index d6cbfa4ac..5206f9760 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -247,7 +247,7 @@ do_select_widget (WDialog * h, GList * w, select_dir_t dir) break; } } - while (h->current != w /* && (WIDGET (h->current->data)->options & WOP_DISABLED) == 0 */ ); + while (h->current != w); if (widget_overlapped (w0, WIDGET (h->current->data))) { @@ -405,7 +405,7 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event) { Widget *w = WIDGET (p->data); - if ((w->options & WOP_DISABLED) == 0 && w->mouse_callback != NULL) + if (!widget_get_options (w, WOP_DISABLED) && w->mouse_callback != NULL) { /* put global cursor position to the widget */ int ret; @@ -445,10 +445,10 @@ dlg_try_hotkey (WDialog * h, int d_key) current = WIDGET (h->current->data); - if ((current->options & WOP_DISABLED) != 0) + if (widget_get_options (current, WOP_DISABLED)) return MSG_NOT_HANDLED; - if ((current->options & WOP_IS_INPUT) != 0) + if (widget_get_options (current, WOP_IS_INPUT)) { /* skip ascii control characters, anything else can valid character in * some encoding */ @@ -462,7 +462,7 @@ dlg_try_hotkey (WDialog * h, int d_key) d_key = g_ascii_tolower (c); handled = MSG_NOT_HANDLED; - if ((current->options & WOP_WANT_HOTKEY) != 0) + if (widget_get_options (current, WOP_WANT_HOTKEY)) handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL); /* If not used, send hotkey to other widgets */ @@ -476,7 +476,8 @@ dlg_try_hotkey (WDialog * h, int d_key) { current = WIDGET (hot_cur->data); - if ((current->options & WOP_WANT_HOTKEY) != 0 && (current->options & WOP_DISABLED) == 0) + if (widget_get_options (current, WOP_WANT_HOTKEY) + && !widget_get_options (current, WOP_DISABLED)) handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL); if (handled == MSG_NOT_HANDLED) @@ -569,7 +570,7 @@ frontend_dlg_run (WDialog * h) if (idle_hook) execute_hooks (idle_hook); - while ((WIDGET (h)->options & WOP_WANT_IDLE) != 0 && is_idle ()) + while (widget_get_options (WIDGET (h), WOP_WANT_IDLE) && is_idle ()) send_message (h, NULL, MSG_IDLE, 0, NULL); /* Allow terminating the dialog from the idle handler */ @@ -1048,7 +1049,7 @@ dlg_focus (WDialog * h) { Widget *current = WIDGET (h->current->data); - if (((current->options & WOP_DISABLED) == 0) + if (!widget_get_options (current, WOP_DISABLED)) && (send_message (current, NULL, MSG_FOCUS, 0, NULL) == MSG_HANDLED)) { send_message (h, current, MSG_FOCUS, 0, NULL); @@ -1166,7 +1167,7 @@ update_cursor (WDialog * h) w = WIDGET (p->data); - if (((w->options & WOP_DISABLED) == 0) && ((w->options & WOP_WANT_CURSOR) != 0)) + if (!widget_get_options (w, WOP_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR)) send_message (w, NULL, MSG_CURSOR, 0, NULL); else do @@ -1177,9 +1178,9 @@ update_cursor (WDialog * h) w = WIDGET (p->data); - if (((w->options & WOP_DISABLED) == 0) && ((w->options & WOP_WANT_CURSOR) != 0)) - if (send_message (w, NULL, MSG_CURSOR, 0, NULL) == MSG_HANDLED) - break; + if (!widget_get_options (w, WOP_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR) + && send_message (w, NULL, MSG_CURSOR, 0, NULL) == MSG_HANDLED) + break; } while (TRUE); } diff --git a/lib/widget/groupbox.c b/lib/widget/groupbox.c index cf5561c8c..67882ff4f 100644 --- a/lib/widget/groupbox.c +++ b/lib/widget/groupbox.c @@ -71,7 +71,7 @@ groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void gboolean disabled; - disabled = (w->options & WOP_DISABLED) != 0; + disabled = widget_get_options (w, WOP_DISABLED); tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]); tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE); diff --git a/lib/widget/input.c b/lib/widget/input.c index 95cb11061..80e9e5b4c 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -103,7 +103,7 @@ static void draw_history_button (WInput * in) { char c; - gboolean disabled = (WIDGET (in)->options & WOP_DISABLED) != 0; + gboolean disabled; if (g_list_next (in->history.current) == NULL) c = '^'; @@ -113,6 +113,7 @@ draw_history_button (WInput * in) c = '|'; widget_move (in, 0, WIDGET (in)->cols - HISTORY_BUTTON_WIDTH); + disabled = widget_get_options (WIDGET (in), WOP_DISABLED); tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]); #ifdef LARGE_HISTORY_BUTTON @@ -1295,7 +1296,7 @@ input_update (WInput * in, gboolean clear_first) if (has_history != 0) draw_history_button (in); - if ((w->options & WOP_DISABLED) != 0) + if (widget_get_options (w, WOP_DISABLED)) tty_setcolor (DISABLED_COLOR); else if (in->first) tty_setcolor (in->color[WINPUTC_UNCHANGED]); diff --git a/lib/widget/label.c b/lib/widget/label.c index c4dddec8a..6d7541a42 100644 --- a/lib/widget/label.c +++ b/lib/widget/label.c @@ -81,7 +81,7 @@ label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d if (l->text == NULL) return MSG_HANDLED; - disabled = (w->options & WOP_DISABLED) != 0; + disabled = widget_get_options (w, WOP_DISABLED); if (l->transparent) tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR); diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 5c141f18a..a5967a284 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -132,22 +132,24 @@ listbox_draw (WListbox * l, gboolean focused) { Widget *w = WIDGET (l); const WDialog *h = w->owner; - const gboolean disabled = (w->options & WOP_DISABLED) != 0; - const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; - /* *INDENT-OFF* */ - int selc = disabled - ? DISABLED_COLOR - : focused - ? h->color[DLG_COLOR_HOT_FOCUS] - : h->color[DLG_COLOR_FOCUS]; - /* *INDENT-ON* */ - + gboolean disabled; + int normalc, selc; int length = 0; GList *le = NULL; int pos; int i; int sel_line = -1; + disabled = widget_get_options (w, WOP_DISABLED); + normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; + /* *INDENT-OFF* */ + selc = disabled + ? DISABLED_COLOR + : focused + ? h->color[DLG_COLOR_HOT_FOCUS] + : h->color[DLG_COLOR_FOCUS]; + /* *INDENT-ON* */ + if (l->list != NULL) { length = g_queue_get_length (l->list); diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index 2bf844375..81876c32f 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -241,7 +241,7 @@ widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) WDialog *h = w->owner; int color; - if ((w->options & WOP_DISABLED) != 0) + if (widget_get_options (w, WOP_DISABLED)) color = DISABLED_COLOR; else if (hotkey) { diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index c169bfc88..49311fc48 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -185,6 +185,21 @@ send_message (void *w, void *sender, widget_msg_t msg, int parm, void *data) return ret; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Check whether one or several option flags are set or not. + * @param w widget + * @param options widget option flags + * + * @return TRUE if all requested option flags are set, FALSE otherwise. + */ + +static inline gboolean +widget_get_options (const Widget * w, widget_options_t options) +{ + return ((w->options & options) == options); +} + /* --------------------------------------------------------------------------------------------- */ #endif /* MC__WIDGET_INTERNAL_H */ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 94b29b4ad..65efa6637 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -955,7 +955,7 @@ check_find_events (WDialog * h) /* dialog terminated */ return FIND_ABORT; } - if ((WIDGET (h)->options & WOP_WANT_IDLE) == 0) + if (!widget_get_options (WIDGET (h), WOP_WANT_IDLE)) { /* searching suspended */ return FIND_SUSPEND;