Ticket #2257: added capability to interactive enable/disable widgets.

Added W_DISABLED flag for widget options.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-06-29 11:20:48 +04:00
parent 87b28f0811
commit a28edb691e
3 changed files with 72 additions and 27 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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