(widget_draw): support groups.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-10-30 12:40:20 +03:00
parent 540c3813ab
commit 4b3b49faad
14 changed files with 51 additions and 82 deletions

View File

@ -487,6 +487,8 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
w->pos_flags = pos_flags;
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
w->state |= WST_CONSTRUCT | WST_FOCUSED;
/* Temporary hack: dialog doesn't have an owner, own itself. */
w->owner = g;
new_d->color = colors;
new_d->help_ctx = help_ctx;
@ -555,7 +557,7 @@ do_refresh (void)
if (fast_refresh)
{
if (d != NULL)
dlg_draw (DIALOG (d->data));
widget_draw (WIDGET (d->data));
}
else
{
@ -565,36 +567,10 @@ do_refresh (void)
break;
/* back to top dialog */
for (; d != NULL; d = g_list_previous (d))
dlg_draw (DIALOG (d->data));
widget_draw (WIDGET (d->data));
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Redraw the widgets in reverse order, leaving the current widget
* as the last one
*/
void
dlg_draw (WDialog * h)
{
Widget *w = WIDGET (h);
WGroup *g = GROUP (h);
if (!widget_get_state (w, WST_ACTIVE))
return;
if (g->winch_pending)
{
g->winch_pending = FALSE;
send_message (w, NULL, MSG_RESIZE, 0, NULL);
}
send_message (w, NULL, MSG_DRAW, 0, NULL);
group_default_callback (w, NULL, MSG_DRAW, 0, NULL);
widget_update_cursor (w);
}
/* --------------------------------------------------------------------------------------------- */
void
@ -635,7 +611,7 @@ dlg_init (WDialog * h)
group_set_current_widget_next (g);
widget_set_state (wh, WST_ACTIVE, TRUE);
dlg_draw (h);
widget_draw (wh);
/* focus found widget */
if (g->current != NULL)
widget_set_state (WIDGET (g->current->data), WST_FOCUSED, TRUE);

View File

@ -119,8 +119,6 @@ void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
char *dlg_get_title (const WDialog * h, size_t len);
void dlg_draw (WDialog * h);
/* Default callback for dialogs */
cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);

View File

@ -385,13 +385,23 @@ group_default_resize (WGroup * g, WRect * r)
static void
group_draw (WGroup * g)
{
Widget *wg = WIDGET (g);
/* draw all widgets in Z-order, from first to last */
if (widget_get_state (WIDGET (g), WST_ACTIVE))
if (widget_get_state (wg, WST_ACTIVE))
{
GList *p;
if (g->winch_pending)
{
g->winch_pending = FALSE;
send_message (wg, NULL, MSG_RESIZE, 0, NULL);
}
for (p = g->widgets; p != NULL; p = g_list_next (p))
widget_draw (WIDGET (p->data));
widget_update_cursor (wg);
}
}
@ -557,7 +567,7 @@ group_remove_widget (void *w)
/* widget has been deleted at runtime */
if (widget_get_state (WIDGET (g), WST_ACTIVE))
{
dlg_draw (DIALOG (g)); /* FIXME */
group_draw (g);
group_select_current_widget (g);
}

View File

@ -411,7 +411,7 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
case WST_DISABLED:
ret = send_message (w, NULL, enable ? MSG_DISABLE : MSG_ENABLE, 0, NULL);
if (ret == MSG_HANDLED && widget_get_state (WIDGET (w->owner), WST_ACTIVE))
ret = send_message (w, NULL, MSG_DRAW, 0, NULL);
ret = widget_draw (w);
break;
case WST_FOCUSED:
@ -422,7 +422,7 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
ret = send_message (w, NULL, msg, 0, NULL);
if (ret == MSG_HANDLED && widget_get_state (WIDGET (w->owner), WST_ACTIVE))
{
send_message (w, NULL, MSG_DRAW, 0, NULL);
widget_draw (w);
/* Notify owner that focus was moved from one widget to another */
send_message (w->owner, w, MSG_CHANGED_FOCUS, 0, NULL);
}
@ -485,7 +485,7 @@ widget_set_size (Widget * w, int y, int x, int lines, int cols)
send_message (w, NULL, MSG_RESIZE, 0, &r);
if (w->owner != NULL && widget_get_state (WIDGET (w->owner), WST_ACTIVE))
send_message (w, NULL, MSG_DRAW, 0, NULL);
widget_draw (w);
}
/* --------------------------------------------------------------------------------------------- */
@ -558,16 +558,20 @@ widget_is_active (const void *w)
/* --------------------------------------------------------------------------------------------- */
void
cb_ret_t
widget_draw (Widget * w)
{
cb_ret_t ret = MSG_NOT_HANDLED;
if (w != NULL)
{
WGroup *g = w->owner;
if (g != NULL && widget_get_state (WIDGET (g), WST_ACTIVE))
w->callback (w, NULL, MSG_DRAW, 0, NULL);
ret = w->callback (w, NULL, MSG_DRAW, 0, NULL);
}
return ret;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -193,7 +193,7 @@ void widget_adjust_position (widget_pos_flags_t pos_flags, int *y, int *x, int *
void widget_set_size (Widget * w, int y, int x, int lines, int cols);
/* select color for widget in dependance of state */
void widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey);
void widget_draw (Widget * w);
cb_ret_t widget_draw (Widget * w);
void widget_erase (Widget * w);
gboolean widget_is_active (const void *w);
gboolean widget_overlapped (const Widget * a, const Widget * b);

View File

@ -1492,24 +1492,6 @@ edit_syntax_onoff_cb (void *data, void *user_data)
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Callback for the iteration of objects in the 'editors' array.
* Redraw editor object.
*
* @param data probably WEdit object
* @param user_data unused
*/
static void
edit_redraw_page_cb (void *data, void *user_data)
{
(void) user_data;
if (edit_widget_is_editor (CONST_WIDGET (data)))
((WEdit *) data)->force |= REDRAW_PAGE;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Insert autocompleted word into editor.
@ -1560,7 +1542,7 @@ edit_syntax_onoff_cmd (WDialog * h)
{
option_syntax_highlighting = !option_syntax_highlighting;
g_list_foreach (GROUP (h)->widgets, edit_syntax_onoff_cb, NULL);
dlg_draw (h);
widget_draw (WIDGET (h));
}
/* --------------------------------------------------------------------------------------------- */
@ -1574,8 +1556,7 @@ void
edit_show_tabs_tws_cmd (WDialog * h)
{
enable_show_tabs_tws = !enable_show_tabs_tws;
g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL);
dlg_draw (h);
widget_draw (WIDGET (h));
}
/* --------------------------------------------------------------------------------------------- */
@ -1589,8 +1570,7 @@ void
edit_show_margin_cmd (WDialog * h)
{
show_right_margin = !show_right_margin;
g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL);
dlg_draw (h);
widget_draw (WIDGET (h));
}
/* --------------------------------------------------------------------------------------------- */
@ -1605,8 +1585,7 @@ edit_show_numbers_cmd (WDialog * h)
{
option_line_state = !option_line_state;
option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0;
g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL);
dlg_draw (h);
widget_draw (WIDGET (h));
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -193,7 +193,7 @@ edit_restore_size (WEdit * edit)
edit->drag_state = MCEDIT_DRAG_NONE;
w->mouse.forced_capture = FALSE;
widget_set_size_rect (w, &edit->loc_prev);
dlg_draw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
}
/* --------------------------------------------------------------------------------------------- */
@ -233,7 +233,7 @@ edit_window_move (WEdit * edit, long command)
}
edit->force |= REDRAW_PAGE;
dlg_draw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
}
/* --------------------------------------------------------------------------------------------- */
@ -273,7 +273,7 @@ edit_window_resize (WEdit * edit, long command)
}
edit->force |= REDRAW_COMPLETELY;
dlg_draw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
}
/* --------------------------------------------------------------------------------------------- */
@ -1053,7 +1053,7 @@ edit_mouse_handle_move_resize (Widget * w, mouse_msg_t msg, mouse_event_t * even
edit->force |= REDRAW_COMPLETELY; /* Not really needed as WEdit's MSG_DRAW already does this. */
/* We draw the whole dialog because dragging/resizing exposes area beneath. */
dlg_draw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
}
/* --------------------------------------------------------------------------------------------- */
@ -1381,7 +1381,7 @@ edit_add_window (WDialog * h, int y, int x, int lines, int cols, const vfs_path_
group_add_widget_autopos (GROUP (h), w, WPOS_KEEP_ALL, NULL);
edit_set_buttonbar (edit, find_buttonbar (h));
dlg_draw (h);
widget_draw (WIDGET (h));
return TRUE;
}

View File

@ -698,7 +698,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+';
x_toggle ^= (1 << parm);
update_mode (g);
group_send_broadcast_msg (g, MSG_DRAW);
widget_draw (w);
break;
case XCTRL ('x'):
@ -715,7 +715,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+';
x_toggle ^= (1 << parm);
update_mode (g);
group_send_broadcast_msg (g, MSG_DRAW);
widget_draw (w);
break;
default:

View File

@ -354,7 +354,7 @@ sel_charset_button (WButton * button, int action)
cpname = _("7-bit ASCII"); /* FIXME */
button_set_text (button, cpname);
dlg_draw (DIALOG (WIDGET (button)->owner));
widget_draw (WIDGET (WIDGET (button)->owner));
}
return 0;
@ -485,7 +485,7 @@ task_cb (WButton * button, int action)
jobs_fill_listbox (bg_list);
/* This can be optimized to just redraw this widget :-) */
dlg_draw (DIALOG (WIDGET (button)->owner));
widget_draw (WIDGET (WIDGET (button)->owner));
return 0;
}

View File

@ -3155,7 +3155,7 @@ dirsize_status_update_cb (status_msg_t * sm)
{
widget_set_size (wd, wd->y, wd->x, wd->lines, WIDGET (dsm->count_size)->cols + 6);
dirsize_status_locate_buttons (dsm);
dlg_draw (sm->dlg);
widget_draw (wd);
/* TODO: ret rid of double redraw */
}

View File

@ -771,7 +771,7 @@ check_progress_buttons (file_op_context_t * ctx)
{
/* redraw dialog in case of Skip after Suspend */
place_progress_buttons (ui->op_dlg, FALSE);
dlg_draw (ui->op_dlg);
widget_draw (WIDGET (ui->op_dlg));
}
ctx->suspended = FALSE;
return FILE_SKIP;
@ -782,7 +782,7 @@ check_progress_buttons (file_op_context_t * ctx)
case FILE_SUSPEND:
ctx->suspended = !ctx->suspended;
place_progress_buttons (ui->op_dlg, ctx->suspended);
dlg_draw (ui->op_dlg);
widget_draw (WIDGET (ui->op_dlg));
MC_FALLTHROUGH;
default:
if (ctx->suspended)

View File

@ -1613,7 +1613,7 @@ start_stop (WButton * button, int action)
button_set_text (button, fbuts[is_start ? 3 : 2].text);
find_relocate_buttons (DIALOG (w->owner), FALSE);
dlg_draw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
return 0;
}

View File

@ -1502,6 +1502,7 @@ midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
case MSG_DRAW:
load_hint (TRUE);
group_default_callback (w, NULL, MSG_DRAW, 0, NULL);
/* We handle the special case of the output lines */
if (mc_global.tty.console_flag != '\0' && output_lines != 0)
{

View File

@ -617,7 +617,7 @@ help_help (WDialog * h)
{
currentpoint = p + 1; /* Skip the newline following the start of the node */
selected_item = NULL;
dlg_redraw (h);
widget_draw (WIDGET (h));
}
}
@ -640,7 +640,7 @@ help_index (WDialog * h)
currentpoint = new_item + 1; /* Skip the newline following the start of the node */
selected_item = NULL;
dlg_redraw (h);
widget_draw (WIDGET (h));
}
}
@ -655,7 +655,7 @@ help_back (WDialog * h)
if (history_ptr < 0)
history_ptr = HISTORY_SIZE - 1;
dlg_redraw (h); /* FIXME: unneeded? */
widget_draw (WIDGET (h)); /* FIXME: unneeded? */
}
/* --------------------------------------------------------------------------------------------- */
@ -854,7 +854,8 @@ help_handle_key (WDialog * h, int c)
if ((command == CK_IgnoreKey) || (help_execute_cmd (command) == MSG_NOT_HANDLED))
return MSG_NOT_HANDLED;
dlg_redraw (h);
widget_draw (WIDGET (h));
return MSG_HANDLED;
}
@ -1038,7 +1039,7 @@ help_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
move_forward (1);
/* Show the new node */
dlg_redraw (DIALOG (w->owner));
widget_draw (WIDGET (w->owner));
}
/* --------------------------------------------------------------------------------------------- */