mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Join widget_state_t and dlg_state_t.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
0a2877edef
commit
4b72fb5f5e
@ -72,7 +72,7 @@ dialog_switch_suspend (void *data, void *user_data)
|
||||
(void) user_data;
|
||||
|
||||
if (data != mc_current->data)
|
||||
DIALOG (data)->state = DLG_SUSPENDED;
|
||||
widget_set_state (WIDGET (data), WST_SUSPENDED, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -95,7 +95,7 @@ dialog_switch_goto (GList * dlg)
|
||||
else
|
||||
{
|
||||
/* switch from editor, viewer, etc to another dialog */
|
||||
old->state = DLG_SUSPENDED;
|
||||
widget_set_state (WIDGET (old), WST_SUSPENDED, TRUE);
|
||||
|
||||
if (DIALOG (dlg->data) != midnight_dlg)
|
||||
/* switch to another editor, viewer, etc */
|
||||
@ -104,7 +104,7 @@ dialog_switch_goto (GList * dlg)
|
||||
else
|
||||
{
|
||||
/* switch to panels */
|
||||
midnight_dlg->state = DLG_ACTIVE;
|
||||
widget_set_state (WIDGET (midnight_dlg), WST_ACTIVE, TRUE);
|
||||
do_refresh ();
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,8 @@ dlg_resize_cb (void *data, void *user_data)
|
||||
WDialog *d = data;
|
||||
|
||||
(void) user_data;
|
||||
if (d->state == DLG_ACTIVE)
|
||||
|
||||
if (widget_get_state (WIDGET (d), WST_ACTIVE))
|
||||
send_message (d, NULL, MSG_RESIZE, 0, NULL);
|
||||
else
|
||||
d->winch_pending = TRUE;
|
||||
@ -170,7 +171,7 @@ dialog_switch_remove (WDialog * h)
|
||||
|
||||
/* resume forced the current screen */
|
||||
if (mc_current != NULL)
|
||||
DIALOG (mc_current->data)->state = DLG_ACTIVE;
|
||||
widget_set_state (WIDGET (mc_current->data), WST_ACTIVE, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -273,11 +274,12 @@ dialog_switch_process_pending (void)
|
||||
while (dialog_switch_pending)
|
||||
{
|
||||
WDialog *h = DIALOG (mc_current->data);
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
dialog_switch_pending = FALSE;
|
||||
h->state = DLG_SUSPENDED;
|
||||
widget_set_state (wh, WST_SUSPENDED, TRUE);
|
||||
ret = dlg_run (h);
|
||||
if (h->state == DLG_CLOSED)
|
||||
if (widget_get_state (wh, WST_CLOSED))
|
||||
{
|
||||
dlg_destroy (h);
|
||||
|
||||
|
@ -182,14 +182,20 @@ static gboolean
|
||||
dlg_unfocus (WDialog * h)
|
||||
{
|
||||
/* we can unfocus disabled widget */
|
||||
if ((h->current != NULL) && (h->state == DLG_CONSTRUCT || h->state == DLG_ACTIVE))
|
||||
if (h->current != NULL)
|
||||
{
|
||||
Widget *current = WIDGET (h->current->data);
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
if (send_message (current, NULL, MSG_UNFOCUS, 0, NULL) == MSG_HANDLED)
|
||||
if (widget_get_state (wh, WST_CONSTRUCT) || widget_get_state (wh, WST_ACTIVE))
|
||||
{
|
||||
send_message (h, current, MSG_UNFOCUS, 0, NULL);
|
||||
return TRUE;
|
||||
Widget *current = WIDGET (h->current->data);
|
||||
|
||||
if (send_message (current, NULL, MSG_UNFOCUS, 0, NULL) == MSG_HANDLED)
|
||||
{
|
||||
send_message (h, current, MSG_UNFOCUS, 0, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -547,6 +553,7 @@ dlg_key_event (WDialog * h, int d_key)
|
||||
static void
|
||||
frontend_dlg_run (WDialog * h)
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
Gpm_Event event;
|
||||
|
||||
event.x = -1;
|
||||
@ -558,7 +565,7 @@ frontend_dlg_run (WDialog * h)
|
||||
return;
|
||||
}
|
||||
|
||||
while (h->state == DLG_ACTIVE)
|
||||
while (widget_get_state (wh, WST_ACTIVE))
|
||||
{
|
||||
int d_key;
|
||||
|
||||
@ -570,11 +577,11 @@ frontend_dlg_run (WDialog * h)
|
||||
if (idle_hook)
|
||||
execute_hooks (idle_hook);
|
||||
|
||||
while (widget_get_state (WIDGET (h), WST_IDLE) && is_idle ())
|
||||
send_message (h, NULL, MSG_IDLE, 0, NULL);
|
||||
while (widget_get_state (wh, WST_IDLE) && is_idle ())
|
||||
send_message (wh, NULL, MSG_IDLE, 0, NULL);
|
||||
|
||||
/* Allow terminating the dialog from the idle handler */
|
||||
if (h->state != DLG_ACTIVE)
|
||||
if (!widget_get_state (wh, WST_ACTIVE))
|
||||
break;
|
||||
}
|
||||
|
||||
@ -586,7 +593,7 @@ frontend_dlg_run (WDialog * h)
|
||||
|
||||
dlg_process_event (h, d_key, &event);
|
||||
|
||||
if (h->state == DLG_CLOSED)
|
||||
if (widget_get_state (wh, WST_CLOSED))
|
||||
send_message (h, NULL, MSG_VALIDATE, 0, NULL);
|
||||
}
|
||||
}
|
||||
@ -616,7 +623,7 @@ dlg_set_top_or_bottom_widget (void *w, gboolean set_top)
|
||||
abort (); /* widget is not in dialog, this should not happen */
|
||||
|
||||
/* unfocus prevoius widget and focus current one before widget reordering */
|
||||
if (set_top && h->state == DLG_ACTIVE)
|
||||
if (set_top && widget_get_state (WIDGET (h), WST_ACTIVE))
|
||||
do_select_widget (h, l, SELECT_EXACT);
|
||||
|
||||
/* widget reordering */
|
||||
@ -639,7 +646,7 @@ dlg_default_repaint (WDialog * h)
|
||||
|
||||
int space;
|
||||
|
||||
if (h->state != DLG_ACTIVE)
|
||||
if (!widget_get_state (wh, WST_ACTIVE))
|
||||
return;
|
||||
|
||||
space = (h->flags & DLG_COMPACT) ? 0 : 1;
|
||||
@ -826,8 +833,8 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
|
||||
widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback,
|
||||
mouse_callback);
|
||||
widget_want_cursor (w, FALSE);
|
||||
w->state |= WST_CONSTRUCT;
|
||||
|
||||
new_d->state = DLG_CONSTRUCT;
|
||||
new_d->modal = modal;
|
||||
new_d->color = colors;
|
||||
new_d->help_ctx = help_ctx;
|
||||
@ -885,12 +892,10 @@ dlg_set_default_colors (void)
|
||||
void
|
||||
dlg_erase (WDialog * h)
|
||||
{
|
||||
if ((h != NULL) && (h->state == DLG_ACTIVE))
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
if (wh != NULL && widget_get_state (wh, WST_ACTIVE))
|
||||
tty_fill_region (wh->y, wh->x, wh->lines, wh->cols, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -946,7 +951,7 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo
|
||||
}
|
||||
|
||||
/* widget has been added in runtime */
|
||||
if (h->state == DLG_ACTIVE)
|
||||
if (widget_get_state (wh, WST_ACTIVE))
|
||||
{
|
||||
send_message (widget, NULL, MSG_INIT, 0, NULL);
|
||||
send_message (widget, NULL, MSG_DRAW, 0, NULL);
|
||||
@ -999,7 +1004,7 @@ del_widget (void *w)
|
||||
g_list_free_1 (d);
|
||||
|
||||
/* widget has been deleted in runtime */
|
||||
if (h->state == DLG_ACTIVE)
|
||||
if (widget_get_state (WIDGET (h), WST_ACTIVE))
|
||||
{
|
||||
dlg_redraw (h);
|
||||
dlg_focus (h);
|
||||
@ -1046,15 +1051,20 @@ gboolean
|
||||
dlg_focus (WDialog * h)
|
||||
{
|
||||
/* cannot focus disabled widget */
|
||||
if ((h->current != NULL) && (h->state == DLG_CONSTRUCT || h->state == DLG_ACTIVE))
|
||||
if (h->current != NULL)
|
||||
{
|
||||
Widget *current = WIDGET (h->current->data);
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
if (!widget_get_state (current, WST_DISABLED)
|
||||
&& (send_message (current, NULL, MSG_FOCUS, 0, NULL) == MSG_HANDLED))
|
||||
if (widget_get_state (wh, WST_CONSTRUCT) || widget_get_state (wh, WST_ACTIVE))
|
||||
{
|
||||
send_message (h, current, MSG_FOCUS, 0, NULL);
|
||||
return TRUE;
|
||||
Widget *current = WIDGET (h->current->data);
|
||||
|
||||
if (!widget_get_state (current, WST_DISABLED)
|
||||
&& (send_message (current, NULL, MSG_FOCUS, 0, NULL) == MSG_HANDLED))
|
||||
{
|
||||
send_message (h, current, MSG_FOCUS, 0, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1162,7 +1172,7 @@ update_cursor (WDialog * h)
|
||||
{
|
||||
GList *p = h->current;
|
||||
|
||||
if ((p != NULL) && (h->state == DLG_ACTIVE))
|
||||
if (p != NULL && widget_get_state (WIDGET (h), WST_ACTIVE))
|
||||
{
|
||||
Widget *w;
|
||||
|
||||
@ -1196,7 +1206,7 @@ update_cursor (WDialog * h)
|
||||
void
|
||||
dlg_redraw (WDialog * h)
|
||||
{
|
||||
if (h->state != DLG_ACTIVE)
|
||||
if (!widget_get_state (WIDGET (h), WST_ACTIVE))
|
||||
return;
|
||||
|
||||
if (h->winch_pending)
|
||||
@ -1215,7 +1225,7 @@ dlg_redraw (WDialog * h)
|
||||
void
|
||||
dlg_stop (WDialog * h)
|
||||
{
|
||||
h->state = DLG_CLOSED;
|
||||
widget_set_state (WIDGET (h), WST_CLOSED, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1224,6 +1234,8 @@ dlg_stop (WDialog * h)
|
||||
void
|
||||
dlg_init (WDialog * h)
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
if (top_dlg != NULL && DIALOG (top_dlg->data)->modal)
|
||||
h->modal = TRUE;
|
||||
|
||||
@ -1231,7 +1243,7 @@ dlg_init (WDialog * h)
|
||||
top_dlg = g_list_prepend (top_dlg, h);
|
||||
|
||||
/* Initialize dialog manager and widgets */
|
||||
if (h->state == DLG_CONSTRUCT)
|
||||
if (widget_get_state (wh, WST_CONSTRUCT))
|
||||
{
|
||||
if (!h->modal)
|
||||
dialog_switch_add (h);
|
||||
@ -1241,7 +1253,7 @@ dlg_init (WDialog * h)
|
||||
dlg_read_history (h);
|
||||
}
|
||||
|
||||
h->state = DLG_ACTIVE;
|
||||
widget_set_state (wh, WST_ACTIVE, TRUE);
|
||||
|
||||
/* first send MSG_DRAW to dialog itself and all widgets... */
|
||||
dlg_redraw (h);
|
||||
@ -1279,7 +1291,7 @@ dlg_run_done (WDialog * h)
|
||||
{
|
||||
top_dlg = g_list_remove (top_dlg, h);
|
||||
|
||||
if (h->state == DLG_CLOSED)
|
||||
if (widget_get_state (WIDGET (h), WST_CLOSED))
|
||||
{
|
||||
send_message (h, h->current->data, MSG_END, 0, NULL);
|
||||
if (!h->modal)
|
||||
|
@ -39,15 +39,6 @@ typedef enum
|
||||
DLG_WANT_TAB = (1 << 3) /* Should the tab key be sent to the dialog? */
|
||||
} dlg_flags_t;
|
||||
|
||||
/* Dialog state */
|
||||
typedef enum
|
||||
{
|
||||
DLG_CONSTRUCT = 0, /* Dialog has been constructed but not run yet */
|
||||
DLG_ACTIVE = 1, /* Dialog is visible and active */
|
||||
DLG_SUSPENDED = 2, /* Dialog is suspended */
|
||||
DLG_CLOSED = 3 /* Dialog is closed */
|
||||
} dlg_state_t;
|
||||
|
||||
/* Dialog color constants */
|
||||
typedef enum
|
||||
{
|
||||
@ -90,7 +81,6 @@ struct WDialog
|
||||
int ret_value; /* Result of dlg_run() */
|
||||
|
||||
/* Internal flags */
|
||||
dlg_state_t state;
|
||||
gboolean fullscreen; /* Parents dialogs don't need refresh */
|
||||
gboolean winch_pending; /* SIGWINCH signal has been got. Resize dialog after rise */
|
||||
int mouse_status; /* For the autorepeat status of the mouse */
|
||||
|
@ -1260,7 +1260,7 @@ input_update (WInput * in, gboolean clear_first)
|
||||
return;
|
||||
|
||||
/* don't draw widget not put into dialog */
|
||||
if (w->owner == NULL || w->owner->state != DLG_ACTIVE)
|
||||
if (w->owner == NULL || !widget_get_state (WIDGET (w->owner), WST_ACTIVE))
|
||||
return;
|
||||
|
||||
if (should_show_history_button (in))
|
||||
|
@ -226,6 +226,19 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
|
||||
else
|
||||
w->state &= ~state;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
/* exclusive bits */
|
||||
if ((state & WST_CONSTRUCT) != 0)
|
||||
w->state &= ~(WST_ACTIVE | WST_SUSPENDED | WST_CLOSED);
|
||||
else if ((state & WST_ACTIVE) != 0)
|
||||
w->state &= ~(WST_CONSTRUCT | WST_SUSPENDED | WST_CLOSED);
|
||||
else if ((state & WST_SUSPENDED) != 0)
|
||||
w->state &= ~(WST_CONSTRUCT | WST_ACTIVE | WST_CLOSED);
|
||||
else if ((state & WST_CLOSED) != 0)
|
||||
w->state &= ~(WST_CONSTRUCT | WST_ACTIVE | WST_SUSPENDED);
|
||||
}
|
||||
|
||||
if (w->owner == NULL)
|
||||
return FALSE;
|
||||
|
||||
@ -317,7 +330,7 @@ widget_redraw (Widget * w)
|
||||
{
|
||||
WDialog *h = w->owner;
|
||||
|
||||
if (h != NULL && h->state == DLG_ACTIVE)
|
||||
if (h != NULL && widget_get_state (WIDGET (h), WST_ACTIVE))
|
||||
w->callback (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,12 @@ typedef enum
|
||||
{
|
||||
WST_DEFAULT = (0 << 0),
|
||||
WST_DISABLED = (1 << 0), /* Widget cannot be selected */
|
||||
WST_IDLE = (1 << 1) /* @FIXME@: we want more correct name here */
|
||||
WST_IDLE = (1 << 1), /* @FIXME@: we want more correct name here */
|
||||
|
||||
WST_CONSTRUCT = (1 << 15), /* Dialog has been constructed but not run yet */
|
||||
WST_ACTIVE = (1 << 16), /* Dialog is visible and active */
|
||||
WST_SUSPENDED = (1 << 17), /* Dialog is suspended */
|
||||
WST_CLOSED = (1 << 18) /* Dialog is closed */
|
||||
} widget_state_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
|
@ -648,7 +648,7 @@ status_msg_common_update (status_msg_t * sm)
|
||||
if (sm->dlg == NULL)
|
||||
return B_ENTER;
|
||||
|
||||
if (sm->dlg->state != DLG_ACTIVE)
|
||||
if (widget_get_state (WIDGET (sm->dlg), WST_CONSTRUCT))
|
||||
{
|
||||
/* dialog is not shown yet */
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
/*
|
||||
File difference viewer
|
||||
|
||||
Copyright (C) 2007-2016
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
@ -3388,7 +3390,7 @@ dview_adjust_size (WDialog * h)
|
||||
static cb_ret_t
|
||||
dview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WDiff *dview = (WDiff *) data;
|
||||
WDiff *dview;
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
@ -3406,9 +3408,10 @@ dview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
|
||||
|
||||
case MSG_VALIDATE:
|
||||
dview = (WDiff *) find_widget_type (h, dview_callback);
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
/* don't stop the dialog before final decision */
|
||||
widget_set_state (w, WST_ACTIVE, TRUE);
|
||||
if (dview_ok_to_exit (dview))
|
||||
h->state = DLG_CLOSED;
|
||||
dlg_stop (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
@ -3475,7 +3478,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
||||
if (error == 0)
|
||||
dlg_run (dview_dlg);
|
||||
|
||||
if ((error != 0) || (dview_dlg->state == DLG_CLOSED))
|
||||
if (error != 0 || widget_get_state (WIDGET (dview_dlg), WST_CLOSED))
|
||||
dlg_destroy (dview_dlg);
|
||||
|
||||
return error == 0 ? 1 : 0;
|
||||
|
@ -641,7 +641,8 @@ edit_quit (WDialog * h)
|
||||
GList *l;
|
||||
WEdit *e = NULL;
|
||||
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
/* don't stop the dialog before final decision */
|
||||
widget_set_state (WIDGET (h), WST_ACTIVE, TRUE);
|
||||
|
||||
for (l = h->widgets; l != NULL; l = g_list_next (l))
|
||||
if (edit_widget_is_editor (CONST_WIDGET (l->data)))
|
||||
@ -665,7 +666,7 @@ edit_quit (WDialog * h)
|
||||
|
||||
/* no editors in dialog at all or no any file required to be saved */
|
||||
if (e == NULL || l == NULL)
|
||||
h->state = DLG_CLOSED;
|
||||
dlg_stop (h);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1249,7 +1250,7 @@ edit_files (const GList * files)
|
||||
if (ok)
|
||||
dlg_run (edit_dlg);
|
||||
|
||||
if (!ok || edit_dlg->state == DLG_CLOSED)
|
||||
if (!ok || widget_get_state (WIDGET (edit_dlg), WST_CLOSED))
|
||||
dlg_destroy (edit_dlg);
|
||||
|
||||
return ok;
|
||||
|
@ -498,7 +498,8 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
|
||||
if (!(file_pattern_cbox->state & C_BOOL)
|
||||
&& (in_name->buffer[0] != '\0') && !find_check_regexp (in_name->buffer))
|
||||
{
|
||||
h->state = DLG_ACTIVE; /* Don't stop the dialog */
|
||||
/* Don't stop the dialog */
|
||||
widget_set_state (WIDGET (h), WST_ACTIVE, TRUE);
|
||||
message (D_ERROR, MSG_ERROR, _("Malformed regular expression"));
|
||||
dlg_select_widget (in_name);
|
||||
return MSG_HANDLED;
|
||||
@ -508,7 +509,8 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
|
||||
if ((content_regexp_cbox->state & C_BOOL) && (in_with->buffer[0] != '\0')
|
||||
&& !find_check_regexp (in_with->buffer))
|
||||
{
|
||||
h->state = DLG_ACTIVE; /* Don't stop the dialog */
|
||||
/* Don't stop the dialog */
|
||||
widget_set_state (WIDGET (h), WST_ACTIVE, TRUE);
|
||||
message (D_ERROR, MSG_ERROR, _("Malformed regular expression"));
|
||||
dlg_select_widget (in_with);
|
||||
return MSG_HANDLED;
|
||||
|
@ -138,10 +138,10 @@ static gboolean ctl_x_map_enabled = FALSE;
|
||||
static void
|
||||
stop_dialogs (void)
|
||||
{
|
||||
midnight_dlg->state = DLG_CLOSED;
|
||||
dlg_stop (midnight_dlg);
|
||||
|
||||
if ((top_dlg != NULL) && (top_dlg->data != NULL))
|
||||
DIALOG (top_dlg->data)->state = DLG_CLOSED;
|
||||
dlg_stop (DIALOG (top_dlg->data));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -732,9 +732,10 @@ mcview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
|
||||
|
||||
case MSG_VALIDATE:
|
||||
view = (WView *) find_widget_type (h, mcview_callback);
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
/* don't stop the dialog before final decision */
|
||||
widget_set_state (WIDGET (h), WST_ACTIVE, TRUE);
|
||||
if (mcview_ok_to_quit (view))
|
||||
h->state = DLG_CLOSED;
|
||||
dlg_stop (h);
|
||||
else
|
||||
mcview_update (view);
|
||||
return MSG_HANDLED;
|
||||
|
@ -249,9 +249,9 @@ mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_lin
|
||||
if (succeeded)
|
||||
dlg_run (view_dlg);
|
||||
else
|
||||
view_dlg->state = DLG_CLOSED;
|
||||
dlg_stop (view_dlg);
|
||||
|
||||
if (view_dlg->state == DLG_CLOSED)
|
||||
if (widget_get_state (WIDGET (view_dlg), WST_CLOSED))
|
||||
dlg_destroy (view_dlg);
|
||||
|
||||
return succeeded;
|
||||
|
Loading…
Reference in New Issue
Block a user