From a28edb691e5c3f89f67e1e41c2eae34cdb17c399 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 29 Jun 2010 11:20:48 +0400 Subject: [PATCH] Ticket #2257: added capability to interactive enable/disable widgets. Added W_DISABLED flag for widget options. Signed-off-by: Andrew Borodin --- src/dialog.c | 68 +++++++++++++++++++++++++++++++++++++--------------- src/dialog.h | 10 ++++---- src/widget.c | 21 ++++++++++++---- 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/dialog.c b/src/dialog.c index 5585363c0..d209a88f4 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -456,24 +456,39 @@ dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse) int dlg_focus (Dlg_head * h) { - if ((h->current != NULL) - && (send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0) == MSG_HANDLED)) + /* cannot focus disabled widget ... */ + + if (h->current != NULL) { - h->callback (h, (Widget *) h->current->data, DLG_FOCUS, 0, NULL); - return 1; + Widget *current = (Widget *) h->current->data; + + if (((current->options & W_DISABLED) == 0) + && (send_message (current, WIDGET_FOCUS, 0) == MSG_HANDLED)) + { + h->callback (h, current, DLG_FOCUS, 0, NULL); + return 1; + } } + return 0; } static int dlg_unfocus (Dlg_head * h) { - if ((h->current != NULL) - && (send_message ((Widget *) h->current->data, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) + /* ... but can unfocus disabled widget */ + + if (h->current != NULL) { - h->callback (h, (Widget *) h->current->data, DLG_UNFOCUS, 0, NULL); - return 1; + Widget *current = (Widget *) h->current->data; + + if (send_message (current, WIDGET_UNFOCUS, 0) == MSG_HANDLED) + { + h->callback (h, current, DLG_UNFOCUS, 0, NULL); + return 1; + } } + return 0; } @@ -566,7 +581,7 @@ do_select_widget (Dlg_head * h, GList * w, select_dir_t dir) return; } } - while (h->current != w); + while (h->current != w /* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */); if (dlg_overlap (w0, (Widget *) h->current->data)) { @@ -625,8 +640,12 @@ update_cursor (Dlg_head * h) if (p != NULL) { - if (((Widget *) (p->data))->options & W_WANT_CURSOR) - send_message ((Widget *) p->data, WIDGET_CURSOR, 0); + Widget *w; + + w = (Widget *) p->data; + + if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0)) + send_message (w, WIDGET_CURSOR, 0); else do { @@ -637,8 +656,10 @@ update_cursor (Dlg_head * h) if (p == h->current) break; - if (((Widget *) (p->data))->options & W_WANT_CURSOR) - if (send_message ((Widget *) p->data, WIDGET_CURSOR, 0) == MSG_HANDLED) + w = (Widget *) p->data; + + if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0)) + if (send_message (w, WIDGET_CURSOR, 0) == MSG_HANDLED) break; } while (TRUE); @@ -781,7 +802,8 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event) if (item == NULL) item = h->widgets; - if ((x > widget->x) && (x <= widget->x + widget->cols) + if (((widget->options & W_DISABLED) == 0) + && (x > widget->x) && (x <= widget->x + widget->cols) && (y > widget->y) && (y <= widget->y + widget->lines)) { new_event = *event; @@ -801,6 +823,7 @@ static cb_ret_t dlg_try_hotkey (Dlg_head * h, int d_key) { GList *hot_cur; + Widget *current; cb_ret_t handled; int c; @@ -815,7 +838,12 @@ dlg_try_hotkey (Dlg_head * h, int d_key) * the currently selected widget is an input line */ - if (((Widget *) h->current->data)->options & W_IS_INPUT) + current = (Widget *) h->current->data; + + if ((current->options & W_DISABLED) != 0) + return MSG_NOT_HANDLED; + + if (current->options & W_IS_INPUT) { /* skip ascii control characters, anything else can valid character in * some encoding */ @@ -829,8 +857,8 @@ dlg_try_hotkey (Dlg_head * h, int d_key) d_key = g_ascii_tolower (c); handled = MSG_NOT_HANDLED; - if (((Widget *) h->current->data)->options & W_WANT_HOTKEY) - handled = send_message ((Widget *) h->current->data, WIDGET_HOTKEY, d_key); + if ((current->options & W_WANT_HOTKEY) != 0) + handled = send_message (current, WIDGET_HOTKEY, d_key); /* If not used, send hotkey to other widgets */ if (handled == MSG_HANDLED) @@ -843,8 +871,10 @@ dlg_try_hotkey (Dlg_head * h, int d_key) /* send it to all widgets */ while (h->current != hot_cur && handled == MSG_NOT_HANDLED) { - if (((Widget *) hot_cur->data)->options & W_WANT_HOTKEY) - handled = send_message ((Widget *) hot_cur->data, WIDGET_HOTKEY, d_key); + current = (Widget *) hot_cur->data; + + if ((current->options & W_WANT_HOTKEY) != 0) + handled = send_message (current, WIDGET_HOTKEY, d_key); if (handled == MSG_NOT_HANDLED) { diff --git a/src/dialog.h b/src/dialog.h index cefa5e48c..d9471db9e 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -180,7 +180,8 @@ typedef enum W_WANT_HOTKEY = (1 << 1), W_WANT_CURSOR = (1 << 2), W_WANT_IDLE = (1 << 3), - W_IS_INPUT = (1 << 4) + W_IS_INPUT = (1 << 4), + W_DISABLED = (1 << 5) /* Widget cannot be selected */ } widget_options_t; /* Flags for widget repositioning on dialog resize */ @@ -301,10 +302,11 @@ void do_refresh (void); /* Sets/clear the specified flag in the options field */ #define widget_option(w,f,i) \ - w.options = ((i) ? (w.options | (f)) : (w.options & (~(f)))) + w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f)))) -#define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i) -#define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i) +#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i)) +#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i)) +#define widget_disable(w,i) widget_option((w), W_DISABLED, (i)) /* Used in load_prompt() */ void update_cursor (Dlg_head * h); diff --git a/src/widget.c b/src/widget.c index 5ef99169e..4d585e285 100644 --- a/src/widget.c +++ b/src/widget.c @@ -67,11 +67,24 @@ static void widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) { Dlg_head *h = w->owner; + int color; - tty_setcolor (hotkey - ? (focused - ? DLG_HOT_FOCUSC (h) - : DLG_HOT_NORMALC (h)) : (focused ? DLG_FOCUSC (h) : DLG_NORMALC (h))); + if (hotkey) + { + if (focused) + color = DLG_HOT_FOCUSC (h); + else + color = DLG_HOT_NORMALC (h); + } + else + { + if (focused) + color = DLG_FOCUSC (h); + else + color = DLG_NORMALC (h); + } + + tty_setcolor (color); } struct hotkey_t