mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Move WOP_DISABLED option to widget_state_t flags
...and rename to WST_DISABLED. * Widget::state: new field. * (widget_set_state): new function. * (widget_set_options): symplify. * (input_set_options): remove. * MSG_ENABLE, MSG_DISABLE: new messages. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
a9fcd6c4c6
commit
b337287336
@ -405,7 +405,7 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event)
|
||||
{
|
||||
Widget *w = WIDGET (p->data);
|
||||
|
||||
if (!widget_get_options (w, WOP_DISABLED) && w->mouse_callback != NULL)
|
||||
if (!widget_get_state (w, WST_DISABLED) && w->mouse_callback != NULL)
|
||||
{
|
||||
/* put global cursor position to the widget */
|
||||
int ret;
|
||||
@ -445,7 +445,7 @@ dlg_try_hotkey (WDialog * h, int d_key)
|
||||
|
||||
current = WIDGET (h->current->data);
|
||||
|
||||
if (widget_get_options (current, WOP_DISABLED))
|
||||
if (widget_get_state (current, WST_DISABLED))
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
if (widget_get_options (current, WOP_IS_INPUT))
|
||||
@ -477,7 +477,7 @@ dlg_try_hotkey (WDialog * h, int d_key)
|
||||
current = WIDGET (hot_cur->data);
|
||||
|
||||
if (widget_get_options (current, WOP_WANT_HOTKEY)
|
||||
&& !widget_get_options (current, WOP_DISABLED))
|
||||
&& !widget_get_state (current, WST_DISABLED))
|
||||
handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL);
|
||||
|
||||
if (handled == MSG_NOT_HANDLED)
|
||||
@ -1049,7 +1049,7 @@ dlg_focus (WDialog * h)
|
||||
{
|
||||
Widget *current = WIDGET (h->current->data);
|
||||
|
||||
if (!widget_get_options (current, WOP_DISABLED))
|
||||
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);
|
||||
@ -1167,7 +1167,7 @@ update_cursor (WDialog * h)
|
||||
|
||||
w = WIDGET (p->data);
|
||||
|
||||
if (!widget_get_options (w, WOP_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR))
|
||||
if (!widget_get_state (w, WST_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR))
|
||||
send_message (w, NULL, MSG_CURSOR, 0, NULL);
|
||||
else
|
||||
do
|
||||
@ -1178,7 +1178,7 @@ update_cursor (WDialog * h)
|
||||
|
||||
w = WIDGET (p->data);
|
||||
|
||||
if (!widget_get_options (w, WOP_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR)
|
||||
if (!widget_get_state (w, WST_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR)
|
||||
&& send_message (w, NULL, MSG_CURSOR, 0, NULL) == MSG_HANDLED)
|
||||
break;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
|
||||
gboolean disabled;
|
||||
|
||||
disabled = widget_get_options (w, WOP_DISABLED);
|
||||
disabled = widget_get_state (w, WST_DISABLED);
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]);
|
||||
tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE);
|
||||
|
||||
|
@ -113,7 +113,7 @@ draw_history_button (WInput * in)
|
||||
c = '|';
|
||||
|
||||
widget_move (in, 0, WIDGET (in)->cols - HISTORY_BUTTON_WIDTH);
|
||||
disabled = widget_get_options (WIDGET (in), WOP_DISABLED);
|
||||
disabled = widget_get_state (WIDGET (in), WST_DISABLED);
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]);
|
||||
|
||||
#ifdef LARGE_HISTORY_BUTTON
|
||||
@ -968,25 +968,6 @@ input_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback for applying new options to input widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
static void
|
||||
input_set_options (Widget * w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
WInput *in = INPUT (w);
|
||||
|
||||
widget_default_set_options (w, options, enable);
|
||||
if (in->label != NULL)
|
||||
widget_set_options (WIDGET (in->label), options, enable);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1012,7 +993,6 @@ input_new (int y, int x, const int *colors, int width, const char *def_text,
|
||||
w = WIDGET (in);
|
||||
widget_init (w, y, x, 1, width, input_callback, input_mouse_callback);
|
||||
w->options |= WOP_IS_INPUT;
|
||||
w->set_options = input_set_options;
|
||||
|
||||
in->color = colors;
|
||||
in->first = TRUE;
|
||||
@ -1066,6 +1046,8 @@ input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
||||
mc_event_add (w->owner->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w, NULL);
|
||||
/* subscribe to "history_save" event */
|
||||
mc_event_add (w->owner->event_group, MCEVENT_HISTORY_SAVE, input_save_history, w, NULL);
|
||||
if (in->label != NULL)
|
||||
widget_set_state (WIDGET (in->label), WST_DISABLED, widget_get_state (w, WST_DISABLED));
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_KEY:
|
||||
@ -1103,6 +1085,12 @@ input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
||||
input_update (in, FALSE);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_ENABLE:
|
||||
case MSG_DISABLE:
|
||||
if (in->label != NULL)
|
||||
widget_set_state (WIDGET (in->label), WST_DISABLED, msg == MSG_DISABLE);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_CURSOR:
|
||||
widget_move (in, 0, str_term_width2 (in->buffer, in->point) - in->term_first_shown);
|
||||
return MSG_HANDLED;
|
||||
@ -1296,7 +1284,7 @@ input_update (WInput * in, gboolean clear_first)
|
||||
if (has_history != 0)
|
||||
draw_history_button (in);
|
||||
|
||||
if (widget_get_options (w, WOP_DISABLED))
|
||||
if (widget_get_state (w, WST_DISABLED))
|
||||
tty_setcolor (DISABLED_COLOR);
|
||||
else if (in->first)
|
||||
tty_setcolor (in->color[WINPUTC_UNCHANGED]);
|
||||
|
@ -81,7 +81,7 @@ label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
||||
if (l->text == NULL)
|
||||
return MSG_HANDLED;
|
||||
|
||||
disabled = widget_get_options (w, WOP_DISABLED);
|
||||
disabled = widget_get_state (w, WST_DISABLED);
|
||||
|
||||
if (l->transparent)
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR);
|
||||
|
@ -140,7 +140,7 @@ listbox_draw (WListbox * l, gboolean focused)
|
||||
int i;
|
||||
int sel_line = -1;
|
||||
|
||||
disabled = widget_get_options (w, WOP_DISABLED);
|
||||
disabled = widget_get_state (w, WST_DISABLED);
|
||||
normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL];
|
||||
/* *INDENT-OFF* */
|
||||
selc = disabled
|
||||
|
@ -90,6 +90,7 @@ quick_create_labeled_input (GArray * widgets, int *y, int x, quick_widget_t * qu
|
||||
label.quick_widget = g_new0 (quick_widget_t, 1);
|
||||
label.quick_widget->widget_type = quick_label;
|
||||
label.quick_widget->options = quick_widget->options;
|
||||
label.quick_widget->state = quick_widget->state;
|
||||
/* FIXME: this should be turned in depend of label_location */
|
||||
label.quick_widget->pos_flags = quick_widget->pos_flags;
|
||||
|
||||
@ -562,6 +563,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
|
||||
|
||||
/* add widget into dialog */
|
||||
item->widget->options |= item->quick_widget->options; /* FIXME: cannot reset flags, setup only */
|
||||
item->widget->state |= item->quick_widget->state; /* FIXME: cannot reset flags, setup only */
|
||||
id = add_widget_autopos (dd, item->widget, item->quick_widget->pos_flags, NULL);
|
||||
if (item->quick_widget->id != NULL)
|
||||
*item->quick_widget->id = id;
|
||||
|
@ -269,6 +269,7 @@ struct quick_widget_t
|
||||
quick_t widget_type;
|
||||
|
||||
widget_options_t options;
|
||||
widget_state_t state;
|
||||
widget_pos_flags_t pos_flags;
|
||||
unsigned long *id;
|
||||
|
||||
|
@ -147,7 +147,6 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
|
||||
w->pos_flags = WPOS_KEEP_DEFAULT;
|
||||
w->callback = callback;
|
||||
w->mouse_callback = mouse_callback;
|
||||
w->set_options = widget_default_set_options;
|
||||
w->owner = NULL;
|
||||
w->mouse.forced_capture = FALSE;
|
||||
w->mouse.capture = FALSE;
|
||||
@ -156,6 +155,7 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
|
||||
|
||||
/* Almost all widgets want to put the cursor in a suitable place */
|
||||
w->options = WOP_WANT_CURSOR;
|
||||
w->state = WST_DEFAULT;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -174,6 +174,8 @@ widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
|
||||
case MSG_INIT:
|
||||
case MSG_FOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_ENABLE:
|
||||
case MSG_DISABLE:
|
||||
case MSG_DRAW:
|
||||
case MSG_DESTROY:
|
||||
case MSG_CURSOR:
|
||||
@ -187,38 +189,60 @@ widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback for applying new options to widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
void
|
||||
widget_default_set_options (Widget * w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
if (enable)
|
||||
w->options |= options;
|
||||
else
|
||||
w->options &= ~options;
|
||||
|
||||
if (w->owner != NULL && (options & WOP_DISABLED) != 0)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Apply new options to widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param options widget option flags to modify. Several flags per call can be modified.
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
void
|
||||
widget_set_options (Widget * w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
w->set_options (w, options, enable);
|
||||
if (enable)
|
||||
w->options |= options;
|
||||
else
|
||||
w->options &= ~options;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Modify state of widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param state widget state flag to modify
|
||||
* @param enable specifies whether to turn the flag on (TRUE) or off (FALSE).
|
||||
* Only one flag per call can be modified.
|
||||
* @return TRUE if set was handled successfully, FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
widget_set_state (Widget * w, widget_state_t state, gboolean enable)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
|
||||
if (enable)
|
||||
w->state |= state;
|
||||
else
|
||||
w->state &= ~state;
|
||||
|
||||
if (w->owner == NULL)
|
||||
return FALSE;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case WST_DISABLED:
|
||||
if (send_message (w, NULL, enable ? MSG_DISABLE : MSG_ENABLE, 0, NULL) != MSG_HANDLED)
|
||||
ret = FALSE;
|
||||
if (ret)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -241,7 +265,7 @@ widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey)
|
||||
WDialog *h = w->owner;
|
||||
int color;
|
||||
|
||||
if (widget_get_options (w, WOP_DISABLED))
|
||||
if (widget_get_state (w, WST_DISABLED))
|
||||
color = DISABLED_COLOR;
|
||||
else if (hotkey)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define widget_want_cursor(w,i) widget_set_options(w, WOP_WANT_CURSOR, i)
|
||||
#define widget_want_hotkey(w,i) widget_set_options(w, WOP_WANT_HOTKEY, i)
|
||||
#define widget_want_idle(w,i) widget_set_options(w, WOP_WANT_IDLE, i)
|
||||
#define widget_disable(w,i) widget_set_options(w, WOP_DISABLED, i)
|
||||
#define widget_disable(w,i) widget_set_state(w, WST_DISABLED, i)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
@ -29,6 +29,8 @@ typedef enum
|
||||
MSG_INIT = 0, /* Initialize widget */
|
||||
MSG_FOCUS, /* Draw widget in focused state or widget has got focus */
|
||||
MSG_UNFOCUS, /* Draw widget in unfocused state or widget has been unfocused */
|
||||
MSG_ENABLE, /* Change state to enabled */
|
||||
MSG_DISABLE, /* Change state to disabled */
|
||||
MSG_DRAW, /* Draw widget on screen */
|
||||
MSG_KEY, /* Sent to widgets on key press */
|
||||
MSG_HOTKEY, /* Sent to widget to catch preprocess key */
|
||||
@ -66,14 +68,14 @@ typedef enum
|
||||
WOP_WANT_HOTKEY = (1 << 1),
|
||||
WOP_WANT_CURSOR = (1 << 2),
|
||||
WOP_WANT_IDLE = (1 << 3),
|
||||
WOP_IS_INPUT = (1 << 4),
|
||||
WOP_DISABLED = (1 << 5) /* Widget cannot be selected */
|
||||
WOP_IS_INPUT = (1 << 4)
|
||||
} widget_options_t;
|
||||
|
||||
/* Widget state */
|
||||
typedef enum
|
||||
{
|
||||
WST_DEFAULT = (0 << 0),
|
||||
WST_DISABLED = (1 << 0) /* Widget cannot be selected */
|
||||
} widget_state_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
@ -109,12 +111,12 @@ struct Widget
|
||||
{
|
||||
int x, y;
|
||||
int cols, lines;
|
||||
widget_options_t options;
|
||||
widget_pos_flags_t pos_flags; /* repositioning flags */
|
||||
widget_options_t options;
|
||||
widget_state_t state;
|
||||
unsigned int id; /* Number of the widget, starting with 0 */
|
||||
widget_cb_fn callback;
|
||||
widget_mouse_cb_fn mouse_callback;
|
||||
void (*set_options) (Widget * w, widget_options_t options, gboolean enable);
|
||||
WDialog *owner;
|
||||
/* Mouse-related fields. */
|
||||
struct
|
||||
@ -159,8 +161,8 @@ void widget_init (Widget * w, int y, int x, int lines, int cols,
|
||||
/* Default callback for widgets */
|
||||
cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
|
||||
void *data);
|
||||
void widget_default_set_options (Widget * w, widget_options_t options, gboolean enable);
|
||||
void widget_set_options (Widget * w, widget_options_t options, gboolean enable);
|
||||
gboolean widget_set_state (Widget * w, widget_state_t state, gboolean enable);
|
||||
void widget_set_size (Widget * widget, 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);
|
||||
|
@ -538,15 +538,15 @@ configure_box (void)
|
||||
g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
|
||||
|
||||
#ifndef USE_INTERNAL_EDIT
|
||||
quick_widgets[17].options = WOP_DISABLED;
|
||||
quick_widgets[17].state = WST_DISABLED;
|
||||
#endif
|
||||
|
||||
if (!old_esc_mode)
|
||||
quick_widgets[10].options = quick_widgets[11].options = WOP_DISABLED;
|
||||
quick_widgets[10].state = quick_widgets[11].state = WST_DISABLED;
|
||||
|
||||
#ifndef HAVE_POSIX_FALLOCATE
|
||||
mc_global.vfs.preallocate_space = FALSE;
|
||||
quick_widgets[7].options = WOP_DISABLED;
|
||||
quick_widgets[7].state = WST_DISABLED;
|
||||
#endif
|
||||
|
||||
if (quick_dialog (&qdlg) == B_ENTER)
|
||||
@ -761,13 +761,13 @@ panel_listing_box (WPanel * panel, int num, char **userp, char **minip, int *use
|
||||
g_snprintf (panel_brief_cols_in, sizeof (panel_brief_cols_in), "%d", panel->brief_cols);
|
||||
|
||||
if ((int) panel->list_type != panel_listing_brief_idx)
|
||||
quick_widgets[4].options = WOP_DISABLED;
|
||||
quick_widgets[4].state = WST_DISABLED;
|
||||
|
||||
if ((int) panel->list_type != panel_listing_user_idx)
|
||||
quick_widgets[6].options = WOP_DISABLED;
|
||||
quick_widgets[6].state = WST_DISABLED;
|
||||
|
||||
if (!mini_user_status)
|
||||
quick_widgets[9].options = WOP_DISABLED;
|
||||
quick_widgets[9].state = WST_DISABLED;
|
||||
|
||||
if (quick_dialog (&qdlg) == B_CANCEL)
|
||||
result = -1;
|
||||
@ -1109,7 +1109,7 @@ configure_vfs (void)
|
||||
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
if (!ftpfs_always_use_proxy)
|
||||
quick_widgets[5].options = WOP_DISABLED;
|
||||
quick_widgets[5].state = WST_DISABLED;
|
||||
#endif
|
||||
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
|
@ -538,21 +538,23 @@ init_layout (void)
|
||||
|
||||
/* "Console output" groupbox */
|
||||
{
|
||||
const int disabled = mc_global.tty.console_flag != '\0' ? 0 : WOP_DISABLED;
|
||||
widget_state_t disabled;
|
||||
Widget *w;
|
||||
|
||||
disabled = mc_global.tty.console_flag != '\0' ? 0 : WST_DISABLED;
|
||||
|
||||
w = WIDGET (groupbox_new (8, 3, 3, l1, title2));
|
||||
w->options |= disabled;
|
||||
w->state |= disabled;
|
||||
add_widget (layout_dlg, w);
|
||||
|
||||
w = WIDGET (button_new (9, output_lines_label_len + 5, B_PLUS,
|
||||
NARROW_BUTTON, "&+", bplus_cback));
|
||||
w->options |= disabled;
|
||||
w->state |= disabled;
|
||||
add_widget (layout_dlg, w);
|
||||
|
||||
w = WIDGET (button_new (9, output_lines_label_len + 5 + 5, B_MINUS,
|
||||
NARROW_BUTTON, "&-", bminus_cback));
|
||||
w->options |= disabled;
|
||||
w->state |= disabled;
|
||||
add_widget (layout_dlg, w);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user