1
1

(widget_set_options): new function to set/reset widget options.

Adjust enable/disable widgets.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2012-09-09 16:36:50 +04:00
родитель 8b9fc35b95
Коммит 1206d156bf
8 изменённых файлов: 44 добавлений и 24 удалений

Просмотреть файл

@ -147,6 +147,7 @@ init_widget (Widget * w, int y, int x, int lines, int cols,
w->lines = lines;
w->callback = callback;
w->mouse = mouse_handler;
w->set_options = widget_default_set_options_callback;
w->owner = NULL;
/* Almost all widgets want to put the cursor in a suitable place */
@ -181,6 +182,42 @@ default_widget_callback (Widget * sender, widget_msg_t msg, int parm, void *data
/* --------------------------------------------------------------------------------------------- */
/**
* 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_callback (Widget *w, widget_options_t options, gboolean enable)
{
if (enable)
w->options |= options;
else
w->options &= ~options;
if (w->owner != NULL && (options & W_DISABLED) != 0)
send_message (w, NULL, WIDGET_DRAW, 0, NULL);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Apply 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_set_options (Widget *w, widget_options_t options, gboolean enable)
{
w->set_options (w, options, enable);
}
/* --------------------------------------------------------------------------------------------- */
void
widget_set_size (Widget * widget, int y, int x, int lines, int cols)
{

Просмотреть файл

@ -14,11 +14,9 @@
#define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x))
/* Sets/clear the specified flag in the options field */
#define widget_option(w,f,i) \
(w)->options = ((i) ? ((w)->options | (f)) : ((w)->options & (~(f))))
#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
#define widget_want_cursor(w,i) widget_set_options(w, W_WANT_CURSOR, i)
#define widget_want_hotkey(w,i) widget_set_options(w, W_WANT_HOTKEY, i)
#define widget_disable(w,i) widget_set_options(w, W_DISABLED, i)
/*** enums ***************************************************************************************/
@ -89,6 +87,7 @@ struct Widget
unsigned int id; /* Number of the widget, starting with 0 */
widget_cb_fn callback;
mouse_h mouse;
void (*set_options) (Widget *w, widget_options_t options, gboolean enable);
struct Dlg_head *owner;
};
@ -121,6 +120,8 @@ void init_widget (Widget * w, int y, int x, int lines, int cols,
widget_cb_fn callback, mouse_h mouse_handler);
/* Default callback for widgets */
cb_ret_t default_widget_callback (Widget * sender, widget_msg_t msg, int parm, void *data);
void widget_default_set_options_callback (Widget *w, widget_options_t options, gboolean enable);
void widget_set_options (Widget *w, widget_options_t options, 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 (struct Widget *w, gboolean focused, gboolean hotkey);

Просмотреть файл

@ -2228,11 +2228,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
}
w = WIDGET (edit);
w->y = y;
w->x = x;
w->lines = lines;
w->cols = cols;
init_widget (w, y, x, lines, cols, NULL, NULL);
edit_save_size (edit);
edit->fullscreen = TRUE;
edit->drag_state = MCEDIT_DRAG_NORMAL;

Просмотреть файл

@ -1240,7 +1240,6 @@ edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path
w = WIDGET (edit);
w->callback = edit_callback;
w->mouse = edit_event;
widget_want_cursor (w, TRUE);
add_widget (h, w);
dlg_redraw (h);

Просмотреть файл

@ -438,7 +438,6 @@ confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *
/* input */
w = dlg_find_by_id (h, sender->id - 1);
widget_disable (w, not_use);
send_message (w, NULL, WIDGET_DRAW, 0, NULL);
return MSG_HANDLED;
}

Просмотреть файл

@ -406,21 +406,14 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
gboolean disable = !(content_use_cbox->state & C_BOOL);
widget_disable (WIDGET (content_label), disable);
send_message (WIDGET (content_label), NULL, WIDGET_DRAW, 0, NULL);
widget_disable (WIDGET (in_with), disable);
send_message (WIDGET (in_with), NULL, WIDGET_DRAW, 0, NULL);
widget_disable (WIDGET (content_first_hit_cbox), disable);
send_message (WIDGET (content_first_hit_cbox), NULL, WIDGET_DRAW, 0, NULL);
widget_disable (WIDGET (content_regexp_cbox), disable);
send_message (WIDGET (content_regexp_cbox), NULL, WIDGET_DRAW, 0, NULL);
widget_disable (WIDGET (content_case_sens_cbox), disable);
send_message (WIDGET (content_case_sens_cbox), NULL, WIDGET_DRAW, 0, NULL);
#ifdef HAVE_CHARSET
widget_disable (WIDGET (content_all_charsets_cbox), disable);
send_message (WIDGET (content_all_charsets_cbox), NULL, WIDGET_DRAW, 0, NULL);
#endif
widget_disable (WIDGET (content_whole_words_cbox), disable);
send_message (WIDGET (content_whole_words_cbox), NULL, WIDGET_DRAW, 0, NULL);
return MSG_HANDLED;
}
@ -430,7 +423,6 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
gboolean disable = !(ignore_dirs_cbox->state & C_BOOL);
widget_disable (WIDGET (in_ignore), disable);
send_message (WIDGET (in_ignore), NULL, WIDGET_DRAW, 0, NULL);
return MSG_HANDLED;
}

Просмотреть файл

@ -412,9 +412,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
}
widget_disable (WIDGET (bleft_widget), eq);
send_message (WIDGET (bleft_widget), NULL, WIDGET_DRAW, 0, NULL);
widget_disable (WIDGET (bright_widget), eq);
send_message (WIDGET (bright_widget), NULL, WIDGET_DRAW, 0, NULL);
update_split (h);

Просмотреть файл

@ -84,11 +84,9 @@ configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
/* label */
w = dlg_find_by_id (h, sender->id - 1);
widget_disable (w, not_single);
send_message (w, NULL, WIDGET_DRAW, 0, NULL);
/* input */
w = dlg_find_by_id (h, sender->id - 2);
widget_disable (w, not_single);
send_message (w, NULL, WIDGET_DRAW, 0, NULL);
return MSG_HANDLED;
}