From 1206d156bfdae8ae1e2a0be66fd81b09a814eb4a Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 9 Sep 2012 16:36:50 +0400 Subject: [PATCH] (widget_set_options): new function to set/reset widget options. Adjust enable/disable widgets. Signed-off-by: Andrew Borodin --- lib/widget/widget-common.c | 37 +++++++++++++++++++++++++++++++++++++ lib/widget/widget-common.h | 11 ++++++----- src/editor/edit.c | 6 +----- src/editor/editwidget.c | 1 - src/filemanager/boxes.c | 1 - src/filemanager/find.c | 8 -------- src/filemanager/layout.c | 2 -- src/filemanager/option.c | 2 -- 8 files changed, 44 insertions(+), 24 deletions(-) diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index 15f185e8a..4f0c3a8c6 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -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) { diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 030c525b9..8f55eba83 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -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); diff --git a/src/editor/edit.c b/src/editor/edit.c index 99093de77..0fac8d504 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -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; diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 364a8abf4..a3369ced8 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -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); diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 763322e2b..24a85b70e 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -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; } diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 4d835d0d7..75006d703 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -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; } diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index e89548201..684fc8d82 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -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); diff --git a/src/filemanager/option.c b/src/filemanager/option.c index d8bfa667f..ed5f03504 100644 --- a/src/filemanager/option.c +++ b/src/filemanager/option.c @@ -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; }