Ticket #2919: refactoring of focus/unfocus of widgets.

Initial step: add WOP_SELECTABLE option and set it up explicitly for
widgets that can be selected.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-06-07 15:03:20 +03:00
parent 9c3fe04114
commit 5ac1c5a3e0
13 changed files with 20 additions and 20 deletions

View File

@ -211,10 +211,9 @@ button_new (int y, int x, int action, button_flags_t flags, const char *text, bc
b->flags = flags;
b->text = parse_hotkey (text);
widget_init (w, y, x, 1, button_get_len (b), button_callback, button_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
b->selected = FALSE;
b->callback = callback;
widget_want_cursor (w, TRUE);
widget_want_hotkey (w, TRUE);
b->hotpos = (b->text.hotkey != NULL) ? str_term_width1 (b->text.start) : -1;
return b;

View File

@ -139,9 +139,8 @@ check_new (int y, int x, int state, const char *text)
c->text = parse_hotkey (text);
/* 4 is width of "[X] " */
widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
c->state = state ? C_BOOL : 0;
widget_want_cursor (w, TRUE);
widget_want_hotkey (w, TRUE);
return c;
}

View File

@ -853,7 +853,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback,
mouse_callback);
w->pos_flags = pos_flags;
w->options |= WOP_TOP_SELECT;
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
w->state |= WST_CONSTRUCT;
if (modal)

View File

@ -992,7 +992,7 @@ input_new (int y, int x, const int *colors, int width, const char *def_text,
in = g_new (WInput, 1);
w = WIDGET (in);
widget_init (w, y, x, 1, width, input_callback, input_mouse_callback);
w->options |= WOP_IS_INPUT | WOP_WANT_CURSOR;
w->options |= WOP_SELECTABLE | WOP_IS_INPUT | WOP_WANT_CURSOR;
in->color = colors;
in->first = TRUE;

View File

@ -563,6 +563,7 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn
l = g_new (WListbox, 1);
w = WIDGET (l);
widget_init (w, y, x, height, width, listbox_callback, listbox_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_WANT_HOTKEY;
l->list = NULL;
l->top = l->pos = 0;
@ -571,7 +572,6 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn
l->allow_duplicates = TRUE;
l->scrollbar = !mc_global.tty.slow_terminal;
l->focused = FALSE;
widget_want_hotkey (w, TRUE);
return l;
}

View File

@ -191,12 +191,11 @@ radio_new (int y, int x, int count, const char **texts)
/* 4 is width of "(*) " */
widget_init (w, y, x, count, 4 + wmax, radio_callback, radio_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
r->state = 1;
r->pos = 0;
r->sel = 0;
r->count = count;
widget_want_cursor (w, TRUE);
widget_want_hotkey (w, TRUE);
return r;
}

View File

@ -66,10 +66,11 @@ typedef enum
typedef enum
{
WOP_DEFAULT = (0 << 0),
WOP_WANT_HOTKEY = (1 << 1),
WOP_WANT_CURSOR = (1 << 2),
WOP_WANT_TAB = (1 << 3), /* Should the tab key be sent to the dialog? */
WOP_IS_INPUT = (1 << 4),
WOP_WANT_HOTKEY = (1 << 0),
WOP_WANT_CURSOR = (1 << 1),
WOP_WANT_TAB = (1 << 2), /* Should the tab key be sent to the dialog? */
WOP_IS_INPUT = (1 << 3),
WOP_SELECTABLE = (1 << 4),
WOP_TOP_SELECT = (1 << 5)
} widget_options_t;

View File

@ -3467,6 +3467,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
dview = g_new0 (WDiff, 1);
w = WIDGET (dview);
widget_init (w, 0, 0, LINES - 1, COLS, dview_callback, dview_mouse_callback);
w->options |= WOP_SELECTABLE;
add_widget (dview_dlg, dview);
add_widget (dview_dlg, buttonbar_new (TRUE));

View File

@ -2102,12 +2102,13 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
}
else
{
Widget *w;
edit = g_malloc0 (sizeof (WEdit));
to_free = TRUE;
widget_init (WIDGET (edit), y, x, lines, cols, NULL, NULL);
widget_want_cursor (WIDGET (edit), TRUE);
widget_set_options (WIDGET (edit), WOP_TOP_SELECT, TRUE);
w = WIDGET (edit);
widget_init (w, y, x, lines, cols, NULL, NULL);
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT | WOP_WANT_CURSOR;
edit->fullscreen = TRUE;
edit_save_size (edit);
}

View File

@ -4282,7 +4282,7 @@ panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath)
w = WIDGET (panel);
/* No know sizes of the panel at startup */
widget_init (w, 0, 0, 0, 0, panel_callback, panel_mouse_callback);
widget_set_options (w, WOP_TOP_SELECT, TRUE);
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
if (vpath != NULL)
{

View File

@ -1284,7 +1284,7 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel)
w = WIDGET (tree);
widget_init (w, y, x, lines, cols, tree_callback, tree_mouse_callback);
widget_set_options (w, WOP_TOP_SELECT, TRUE);
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
tree->is_panel = is_panel;
tree->selected_ptr = 0;

View File

@ -1023,7 +1023,7 @@ mousedispatch_new (int y, int x, int yl, int xl)
w = g_new0 (Widget, 1);
widget_init (w, y, x, yl, xl, md_callback, help_mouse_callback);
widget_want_cursor (w, TRUE);
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR;
return w;
}

View File

@ -195,7 +195,7 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
view = g_new0 (WView, 1);
w = WIDGET (view);
widget_init (w, y, x, lines, cols, mcview_callback, mcview_mouse_callback);
widget_set_options (w, WOP_TOP_SELECT, TRUE);
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
view->hex_mode = FALSE;
view->hexedit_mode = FALSE;