mcedit: refactoring of MSG_RESIZE handling.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-10-10 10:21:33 +03:00
parent 297391fd60
commit 5ca0dbab01

View File

@ -178,31 +178,6 @@ edit_help (void)
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Callback for the iteration of objects in the 'editors' array.
* Resize the editor window.
*
* @param data probably WEdit object
* @param user_data unused
*/
static void
edit_dialog_resize_cb (void *data, void *user_data)
{
Widget *w = WIDGET (data);
(void) user_data;
if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen)
{
Widget *wh = WIDGET (w->owner);
w->lines = wh->lines - 2;
w->cols = wh->cols;
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Restore saved window size.
@ -771,8 +746,6 @@ edit_update_cursor (WEdit * edit, const mouse_event_t * event)
static cb_ret_t
edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
WMenuBar *menubar;
WButtonBar *buttonbar;
WDialog *h = DIALOG (w);
switch (msg)
@ -788,15 +761,8 @@ edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v
return MSG_HANDLED;
case MSG_RESIZE:
menubar = find_menubar (h);
buttonbar = find_buttonbar (h);
/* dlg_set_size() is surplus for this case */
w->lines = LINES;
w->cols = COLS;
widget_set_size (WIDGET (buttonbar), w->lines - 1, w->x, 1, w->cols);
widget_set_size (WIDGET (menubar), w->y, w->x, 1, w->cols);
menubar_arrange (menubar);
g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL);
dlg_default_callback (w, NULL, MSG_RESIZE, 0, NULL);
menubar_arrange (find_menubar (h));
return MSG_HANDLED;
case MSG_ACTION:
@ -1222,6 +1188,7 @@ edit_files (const GList * files)
static gboolean made_directory = FALSE;
WDialog *edit_dlg;
WMenuBar *menubar;
Widget *w;
const GList *file;
gboolean ok = FALSE;
@ -1252,10 +1219,12 @@ edit_files (const GList * files)
edit_dlg->get_title = edit_get_title;
menubar = menubar_new (NULL, TRUE);
add_widget (edit_dlg, menubar);
w = WIDGET (menubar);
add_widget_autopos (edit_dlg, w, w->pos_flags, NULL);
edit_init_menu (menubar);
add_widget (edit_dlg, buttonbar_new (TRUE));
w = WIDGET (buttonbar_new (TRUE));
add_widget_autopos (edit_dlg, w, w->pos_flags, NULL);
for (file = files; file != NULL; file = g_list_next (file))
{
@ -1381,7 +1350,7 @@ edit_add_window (WDialog * h, int y, int x, int lines, int cols, const vfs_path_
w->callback = edit_callback;
w->mouse_callback = edit_mouse_callback;
add_widget (h, w);
add_widget_autopos (h, w, WPOS_KEEP_ALL, NULL);
edit_set_buttonbar (edit, find_buttonbar (h));
dlg_redraw (h);
@ -1517,18 +1486,25 @@ edit_handle_move_resize (WEdit * edit, long command)
void
edit_toggle_fullscreen (WEdit * edit)
{
Widget *w = WIDGET (edit);
edit->fullscreen = !edit->fullscreen;
edit->force = REDRAW_COMPLETELY;
if (!edit->fullscreen)
{
edit_restore_size (edit);
/* do not follow screen size on resize */
w->pos_flags = WPOS_KEEP_DEFAULT;
}
else
{
Widget *w = WIDGET (edit);
Widget *h = WIDGET (w->owner);
edit_save_size (edit);
widget_set_size (w, h->y + 1, h->x, h->lines - 2, h->cols);
/* follow screen size on resize */
w->pos_flags = WPOS_KEEP_ALL;
edit->force |= REDRAW_PAGE;
edit_update_screen (edit);
}