From e4e0070db51a18555a13d676e3f037fbd969811c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 27 Sep 2016 13:53:17 +0300 Subject: [PATCH] Ticket #2919: implement WGroup widget. WGroup is the base widget for complex objects such as windows, dialog windows, etc. Initial steps: * move widget list of dialog into WGroup class; * inherit WGroup from Widget; * inherit WDialog from WGroup. Signed-off-by: Andrew Borodin --- lib/widget.h | 5 +- lib/widget/Makefile.am | 1 + lib/widget/button.c | 5 +- lib/widget/dialog.c | 131 +++++++++++++++++++++--------------- lib/widget/dialog.h | 12 ++-- lib/widget/gauge.c | 2 +- lib/widget/group.h | 42 ++++++++++++ lib/widget/groupbox.c | 2 +- lib/widget/hline.c | 2 +- lib/widget/input.c | 11 +-- lib/widget/input_complete.c | 13 ++-- lib/widget/label.c | 2 +- lib/widget/listbox.c | 4 +- lib/widget/menu.c | 14 ++-- lib/widget/widget-common.c | 46 ++++++------- lib/widget/widget-common.h | 2 +- src/diffviewer/ydiff.c | 19 +++--- src/editor/editcmd.c | 15 +++-- src/editor/editoptions.c | 4 +- src/editor/editwidget.c | 53 ++++++++------- src/filemanager/achown.c | 15 +++-- src/filemanager/boxes.c | 4 +- src/filemanager/filegui.c | 3 +- src/filemanager/find.c | 8 +-- src/filemanager/hotlist.c | 2 +- src/filemanager/layout.c | 2 +- src/filemanager/panel.c | 11 +-- src/filemanager/tree.c | 12 ++-- src/learn.c | 2 +- src/viewer/actions_cmd.c | 2 +- src/viewer/display.c | 7 +- 31 files changed, 265 insertions(+), 188 deletions(-) create mode 100644 lib/widget/group.h diff --git a/lib/widget.h b/lib/widget.h index f5d4eaeb0..229c57552 100644 --- a/lib/widget.h +++ b/lib/widget.h @@ -9,13 +9,14 @@ /* main forward declarations */ struct Widget; typedef struct Widget Widget; -struct WDialog; -typedef struct WDialog WDialog; +struct WGroup; +typedef struct WGroup WGroup; /* Please note that the first element in all the widgets is a */ /* widget variable of type Widget. We abuse this fact everywhere */ #include "lib/widget/widget-common.h" +#include "lib/widget/group.h" #include "lib/widget/dialog.h" #include "lib/widget/history.h" #include "lib/widget/button.h" diff --git a/lib/widget/Makefile.am b/lib/widget/Makefile.am index 72d0b7392..876eb2f8c 100644 --- a/lib/widget/Makefile.am +++ b/lib/widget/Makefile.am @@ -8,6 +8,7 @@ libmcwidget_la_SOURCES = \ dialog.c dialog.h \ dialog-switch.c dialog-switch.h \ gauge.c gauge.h \ + group.h \ groupbox.c groupbox.h \ hline.c hline.h \ history.c history.h \ diff --git a/lib/widget/button.c b/lib/widget/button.c index aa57c0390..a32a7763d 100644 --- a/lib/widget/button.c +++ b/lib/widget/button.c @@ -62,7 +62,8 @@ cb_ret_t button_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WButton *b = BUTTON (w); - WDialog *h = w->owner; + WGroup *g = w->owner; + WDialog *h = DIALOG (g); int off = 0; switch (msg) @@ -74,7 +75,7 @@ button_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm * when hotkeys are sent to all widgets before the key is * handled by the current widget. */ - if (parm == '\n' && WIDGET (h->current->data) == w) + if (parm == '\n' && WIDGET (g->current->data) == w) { send_message (w, sender, MSG_KEY, ' ', data); return MSG_HANDLED; diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index d102db283..5d9be9cf9 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -97,7 +97,7 @@ dlg_get_next_or_prev_of (const GList * list, gboolean next) if (list != NULL) { - const WDialog *owner = CONST_WIDGET (list->data)->owner; + const WGroup *owner = CONST_WIDGET (list->data)->owner; if (owner != NULL) { @@ -124,9 +124,11 @@ dlg_get_next_or_prev_of (const GList * list, gboolean next) static void dlg_select_next_or_prev (WDialog * h, gboolean next) { - if (h->widgets != NULL && h->current != NULL) + WGroup *g = GROUP (h); + + if (g->widgets != NULL && g->current != NULL) { - GList *l = h->current; + GList *l = g->current; Widget *w; do @@ -135,7 +137,7 @@ dlg_select_next_or_prev (WDialog * h, gboolean next) w = WIDGET (l->data); } while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE)) - && l != h->current); + && l != g->current); widget_select (l->data); } @@ -152,14 +154,15 @@ static void dlg_broadcast_msg_to (WDialog * h, widget_msg_t msg, gboolean reverse, widget_options_t flags) { GList *p, *first; + WGroup *g = GROUP (h); - if (h->widgets == NULL) + if (g->widgets == NULL) return; - if (h->current == NULL) - h->current = h->widgets; + if (g->current == NULL) + g->current = g->widgets; - p = dlg_get_next_or_prev_of (h->current, !reverse); + p = dlg_get_next_or_prev_of (g->current, !reverse); first = p; do @@ -353,11 +356,11 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event) return mou; } - if (h->widgets == NULL) + if (GROUP (h)->widgets == NULL) return MOU_UNHANDLED; /* send the event to widgets in reverse Z-order */ - p = g_list_last (h->widgets); + p = g_list_last (GROUP (h)->widgets); do { Widget *w = WIDGET (p->data); @@ -384,23 +387,24 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event) static cb_ret_t dlg_try_hotkey (WDialog * h, int d_key) { + WGroup *g = GROUP (h); GList *hot_cur; Widget *current; cb_ret_t handled; int c; - if (h->widgets == NULL) + if (g->widgets == NULL) return MSG_NOT_HANDLED; - if (h->current == NULL) - h->current = h->widgets; + if (g->current == NULL) + g->current = g->widgets; /* * Explanation: we don't send letter hotkeys to other widgets if * the currently selected widget is an input line */ - current = WIDGET (h->current->data); + current = WIDGET (g->current->data); if (widget_get_state (current, WST_DISABLED)) return MSG_NOT_HANDLED; @@ -426,10 +430,10 @@ dlg_try_hotkey (WDialog * h, int d_key) if (handled == MSG_HANDLED) return MSG_HANDLED; - hot_cur = dlg_get_widget_next_of (h->current); + hot_cur = dlg_get_widget_next_of (g->current); /* send it to all widgets */ - while (h->current != hot_cur && handled == MSG_NOT_HANDLED) + while (g->current != hot_cur && handled == MSG_NOT_HANDLED) { current = WIDGET (hot_cur->data); @@ -452,16 +456,17 @@ dlg_try_hotkey (WDialog * h, int d_key) static void dlg_key_event (WDialog * h, int d_key) { + WGroup *g = GROUP (h); cb_ret_t handled; - if (h->widgets == NULL) + if (g->widgets == NULL) return; - if (h->current == NULL) - h->current = h->widgets; + if (g->current == NULL) + g->current = g->widgets; /* TAB used to cycle */ - if (!widget_get_options (WIDGET (h), WOP_WANT_TAB)) + if (!widget_get_options (WIDGET (g), WOP_WANT_TAB)) { if (d_key == '\t') { @@ -486,7 +491,7 @@ dlg_key_event (WDialog * h, int d_key) send_message (h, NULL, MSG_HOTKEY_HANDLED, 0, NULL); else /* not used - then try widget_callback */ - handled = send_message (h->current->data, NULL, MSG_KEY, d_key, NULL); + handled = send_message (g->current->data, NULL, MSG_KEY, d_key, NULL); /* not used- try to use the unhandled case */ if (handled == MSG_NOT_HANDLED) @@ -640,6 +645,7 @@ dlg_default_repaint (WDialog * h) void dlg_set_position (WDialog * h, int y, int x, int lines, int cols) { + WGroup *g = GROUP (h); Widget *wh = WIDGET (h); widget_shift_scale_t wss; @@ -658,11 +664,11 @@ dlg_set_position (WDialog * h, int y, int x, int lines, int cols) wh->cols = cols; /* dialog is empty */ - if (h->widgets == NULL) + if (g->widgets == NULL) return; - if (h->current == NULL) - h->current = h->widgets; + if (g->current == NULL) + g->current = g->widgets; /* values by which controls should be moved */ wss.shift_x = wh->x - ox; @@ -671,7 +677,7 @@ dlg_set_position (WDialog * h, int y, int x, int lines, int cols) wss.scale_y = wh->lines - ol; if (wss.shift_x != 0 || wss.shift_y != 0 || wss.scale_x != 0 || wss.scale_y != 0) - g_list_foreach (h->widgets, dlg_widget_set_position, &wss); + g_list_foreach (g->widgets, dlg_widget_set_position, &wss); } /* --------------------------------------------------------------------------------------------- */ @@ -809,6 +815,7 @@ dlg_erase (WDialog * h) unsigned long add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const void *before) { + WGroup *g = GROUP (h); Widget *wh = WIDGET (h); Widget *widget; GList *new_current; @@ -827,31 +834,31 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo widget->y = (wh->lines - widget->lines) / 2; widget->y += wh->y; - widget->owner = h; + widget->owner = g; widget->pos_flags = pos_flags; widget->id = h->widget_id++; - if (h->widgets == NULL || before == NULL) + if (g->widgets == NULL || before == NULL) { - h->widgets = g_list_append (h->widgets, widget); - new_current = g_list_last (h->widgets); + g->widgets = g_list_append (g->widgets, widget); + new_current = g_list_last (g->widgets); } else { GList *b; - b = g_list_find (h->widgets, before); + b = g_list_find (g->widgets, before); /* don't accept widget not from dialog. This shouldn't happen */ if (b == NULL) abort (); b = g_list_next (b); - h->widgets = g_list_insert_before (h->widgets, b, widget); + g->widgets = g_list_insert_before (g->widgets, b, widget); if (b != NULL) new_current = g_list_previous (b); else - new_current = g_list_last (h->widgets); + new_current = g_list_last (g->widgets); } /* widget has been added at runtime */ @@ -861,7 +868,7 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo widget_select (widget); } else - h->current = new_current; + g->current = new_current; return widget->id; } @@ -872,8 +879,10 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo unsigned long add_widget (WDialog * h, void *w) { + WGroup *g = GROUP (h); + return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, - h->current != NULL ? h->current->data : NULL); + g->current != NULL ? g->current->data : NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -890,6 +899,7 @@ add_widget_before (WDialog * h, void *w, void *before) void del_widget (void *w) { + WGroup *g; WDialog *h; GList *d; @@ -897,15 +907,16 @@ del_widget (void *w) if (w == NULL) abort (); - h = WIDGET (w)->owner; + g = WIDGET (w)->owner; + h = DIALOG (g); - d = g_list_find (h->widgets, w); - if (d == h->current) + d = g_list_find (g->widgets, w); + if (d == g->current) dlg_set_current_widget_next (h); - h->widgets = g_list_delete_link (h->widgets, d); - if (h->widgets == NULL) - h->current = NULL; + g->widgets = g_list_remove_link (g->widgets, d); + if (g->widgets == NULL) + g->current = NULL; /* widget has been deleted in runtime */ if (widget_get_state (WIDGET (h), WST_ACTIVE)) @@ -958,7 +969,8 @@ find_widget_type (const WDialog * h, widget_cb_fn callback) { GList *w; - w = g_list_find_custom (h->widgets, (gconstpointer) callback, dlg_find_widget_callback); + w = g_list_find_custom (CONST_GROUP (h)->widgets, (gconstpointer) callback, + dlg_find_widget_callback); return (w == NULL) ? NULL : WIDGET (w->data); } @@ -968,7 +980,9 @@ find_widget_type (const WDialog * h, widget_cb_fn callback) GList * dlg_find (const WDialog * h, const Widget * w) { - return (w->owner == NULL || w->owner != h) ? NULL : g_list_find (h->widgets, w); + const WGroup *g = CONST_GROUP (h); + + return (w->owner == NULL || w->owner != g) ? NULL : g_list_find (g->widgets, w); } /* --------------------------------------------------------------------------------------------- */ @@ -979,7 +993,7 @@ dlg_find_by_id (const WDialog * h, unsigned long id) { GList *w; - w = g_list_find_custom (h->widgets, GUINT_TO_POINTER (id), dlg_find_widget_by_id); + w = g_list_find_custom (CONST_GROUP (h)->widgets, GUINT_TO_POINTER (id), dlg_find_widget_by_id); return w != NULL ? WIDGET (w->data) : NULL; } @@ -1019,7 +1033,8 @@ dlg_select_next_widget (WDialog * h) void update_cursor (WDialog * h) { - GList *p = h->current; + WGroup *g = GROUP (h); + GList *p = g->current; if (p != NULL && widget_get_state (WIDGET (h), WST_ACTIVE)) { @@ -1031,7 +1046,7 @@ update_cursor (WDialog * h) do { p = dlg_get_widget_next_of (p); - if (p == h->current) + if (p == g->current) break; w = WIDGET (p->data); @@ -1081,6 +1096,7 @@ dlg_stop (WDialog * h) void dlg_init (WDialog * h) { + WGroup *g = GROUP (h); Widget *wh = WIDGET (h); if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL)) @@ -1101,15 +1117,15 @@ dlg_init (WDialog * h) } /* Select the first widget that takes focus */ - while (h->current != NULL && !widget_get_options (WIDGET (h->current->data), WOP_SELECTABLE) - && !widget_get_state (WIDGET (h->current->data), WST_DISABLED)) + while (g->current != NULL && !widget_get_options (WIDGET (g->current->data), WOP_SELECTABLE) + && !widget_get_state (WIDGET (g->current->data), WST_DISABLED)) dlg_set_current_widget_next (h); widget_set_state (wh, WST_ACTIVE, TRUE); dlg_draw (h); /* focus found widget */ - if (h->current != NULL) - widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE); + if (g->current != NULL) + widget_set_state (WIDGET (g->current->data), WST_FOCUSED, TRUE); h->ret_value = 0; } @@ -1146,7 +1162,8 @@ dlg_run_done (WDialog * h) if (widget_get_state (WIDGET (h), WST_CLOSED)) { - send_message (h, h->current == NULL ? NULL : WIDGET (h->current->data), MSG_END, 0, NULL); + send_message (h, GROUP (h)->current == NULL ? NULL : WIDGET (GROUP (h)->current->data), + MSG_END, 0, NULL); if (!widget_get_state (WIDGET (h), WST_MODAL)) dialog_switch_remove (h); } @@ -1174,10 +1191,12 @@ dlg_run (WDialog * h) void dlg_destroy (WDialog * h) { + WGroup *g = GROUP (h); + /* if some widgets have history, save all history at one moment here */ dlg_save_history (h); - g_list_foreach (h->widgets, (GFunc) widget_destroy, NULL); - g_list_free (h->widgets); + g_list_foreach (g->widgets, (GFunc) widget_destroy, NULL); + g_list_free (g->widgets); mc_event_group_del (h->event_group); g_free (h->event_group); g_free (h->title); @@ -1271,7 +1290,9 @@ dlg_get_title (const WDialog * h, size_t len) void dlg_set_current_widget_next (WDialog * h) { - h->current = dlg_get_next_or_prev_of (h->current, TRUE); + WGroup *g = GROUP (h); + + g->current = dlg_get_next_or_prev_of (g->current, TRUE); } /* --------------------------------------------------------------------------------------------- */ @@ -1285,7 +1306,9 @@ dlg_set_current_widget_next (WDialog * h) void dlg_set_current_widget_prev (WDialog * h) { - h->current = dlg_get_next_or_prev_of (h->current, FALSE); + WGroup *g = GROUP (h); + + g->current = dlg_get_next_or_prev_of (g->current, FALSE); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h index de425c31c..477351d5a 100644 --- a/lib/widget/dialog.h +++ b/lib/widget/dialog.h @@ -42,6 +42,8 @@ typedef enum /*** typedefs(not structures) ********************************************************************/ +typedef struct WDialog WDialog; + /* get string representation of shortcut assigned with command */ /* as menu is a widget of dialog, ask dialog about shortcut string */ typedef char *(*dlg_shortcut_str) (long command); @@ -58,7 +60,7 @@ typedef cb_ret_t (*menu_exec_fn) (int command); struct WDialog { - Widget widget; + WGroup group; /* base class */ /* Set by the user */ gboolean compact; /* Suppress spaces around the frame */ @@ -74,8 +76,6 @@ struct WDialog int mouse_status; /* For the autorepeat status of the mouse */ /* Internal variables */ - GList *widgets; /* widgets list */ - GList *current; /* Currently active widget */ unsigned long widget_id; /* maximum id of all widgets */ void *data; /* Data can be passed to dialog */ char *event_group; /* Name of event group for this dialog */ @@ -174,7 +174,7 @@ GList *dlg_get_widget_prev_of (GList * w); static inline unsigned long dlg_get_current_widget_id (const WDialog * h) { - return WIDGET (h->current->data)->id; + return WIDGET (GROUP (h)->current->data)->id; } /* --------------------------------------------------------------------------------------------- */ @@ -188,8 +188,8 @@ dlg_get_current_widget_id (const WDialog * h) static inline void dlg_select_current_widget (WDialog * h) { - if (h->current != NULL) - widget_select (WIDGET (h->current->data)); + if (GROUP (h)->current != NULL) + widget_select (WIDGET (GROUP (h)->current->data)); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/gauge.c b/lib/widget/gauge.c index d2ea56c21..ab67ab3b8 100644 --- a/lib/widget/gauge.c +++ b/lib/widget/gauge.c @@ -58,7 +58,7 @@ static cb_ret_t gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WGauge *g = GAUGE (w); - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); switch (msg) { diff --git a/lib/widget/group.h b/lib/widget/group.h new file mode 100644 index 000000000..00b6222c0 --- /dev/null +++ b/lib/widget/group.h @@ -0,0 +1,42 @@ +/* + * Widget group features module for Midnight Commander + */ + +/** \file group.h + * \brief Header: widget group features module + */ + +#ifndef MC__GROUP_H +#define MC__GROUP_H + +#include "lib/global.h" + +/*** typedefs(not structures) and defined constants **********************************************/ + +#define GROUP(x) ((WGroup *)(x)) +#define CONST_GROUP(x) ((const WGroup *)(x)) + +/*** enums ***************************************************************************************/ + +/*** typedefs(not structures) ********************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +struct WGroup +{ + Widget widget; + + /* Group members */ + GList *widgets; /* widgets list */ + GList *current; /* Currently active widget */ +}; + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ +/*** inline functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +#endif /* MC__GROUP_H */ diff --git a/lib/widget/groupbox.c b/lib/widget/groupbox.c index e5ff62fe6..2b369639b 100644 --- a/lib/widget/groupbox.c +++ b/lib/widget/groupbox.c @@ -61,7 +61,7 @@ groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void { case MSG_DRAW: { - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); gboolean disabled; diff --git a/lib/widget/hline.c b/lib/widget/hline.c index 3c925e4fb..4c7109adf 100644 --- a/lib/widget/hline.c +++ b/lib/widget/hline.c @@ -57,7 +57,7 @@ static cb_ret_t hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WHLine *l = HLINE (w); - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); switch (msg) { diff --git a/lib/widget/input.c b/lib/widget/input.c index 6f3b1e230..2d27c28b0 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -874,7 +874,7 @@ input_save_history (const gchar * event_group_name, const gchar * event_name, (void) event_group_name; (void) event_name; - if (!in->is_password && (WIDGET (in)->owner->ret_value != B_CANCEL)) + if (!in->is_password && (DIALOG (WIDGET (in)->owner)->ret_value != B_CANCEL)) { ev_history_load_save_t *ev = (ev_history_load_save_t *) data; @@ -1042,15 +1042,16 @@ cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WInput *in = INPUT (w); + WDialog *h = DIALOG (w->owner); cb_ret_t v; switch (msg) { case MSG_INIT: /* subscribe to "history_load" event */ - mc_event_add (w->owner->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w, NULL); + mc_event_add (h->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); + mc_event_add (h->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; @@ -1099,9 +1100,9 @@ input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d case MSG_DESTROY: /* unsubscribe from "history_load" event */ - mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w); + mc_event_del (h->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w); /* unsubscribe from "history_save" event */ - mc_event_del (w->owner->event_group, MCEVENT_HISTORY_SAVE, input_save_history, w); + mc_event_del (h->event_group, MCEVENT_HISTORY_SAVE, input_save_history, w); input_destroy (in); return MSG_HANDLED; diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index d28b50e40..b1054196f 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -1019,6 +1019,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d { static int bl = 0; + WGroup *g = GROUP (w); WDialog *h = DIALOG (w); switch (msg) @@ -1057,17 +1058,17 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d new_end = str_get_prev_char (&input->buffer[end]) - input->buffer; - for (i = 0, e = listbox_get_first_link (LISTBOX (h->current->data)); + for (i = 0, e = listbox_get_first_link (LISTBOX (g->current->data)); e != NULL; i++, e = g_list_next (e)) { WLEntry *le = LENTRY (e->data); if (strncmp (input->buffer + start, le->text, new_end - start) == 0) { - listbox_select_entry (LISTBOX (h->current->data), i); + listbox_select_entry (LISTBOX (g->current->data), i); end = new_end; input_handle_char (input, parm); - widget_draw (WIDGET (h->current->data)); + widget_draw (WIDGET (g->current->data)); break; } } @@ -1111,7 +1112,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d break; } - for (i = 0, e = listbox_get_first_link (LISTBOX (h->current->data)); + for (i = 0, e = listbox_get_first_link (LISTBOX (g->current->data)); e != NULL; i++, e = g_list_next (e)) { WLEntry *le = LENTRY (e->data); @@ -1122,7 +1123,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d if (need_redraw == 0) { need_redraw = 1; - listbox_select_entry (LISTBOX (h->current->data), i); + listbox_select_entry (LISTBOX (g->current->data), i); last_text = le->text; } else @@ -1173,7 +1174,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d if (need_redraw == 2) { insert_text (input, last_text, low); - widget_draw (WIDGET (h->current->data)); + widget_draw (WIDGET (g->current->data)); } else if (need_redraw == 1) { diff --git a/lib/widget/label.c b/lib/widget/label.c index 485bac5be..a67b6d7ba 100644 --- a/lib/widget/label.c +++ b/lib/widget/label.c @@ -60,7 +60,7 @@ static cb_ret_t label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WLabel *l = LABEL (w); - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); switch (msg) { diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 389812ccf..05be8c556 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -131,7 +131,7 @@ static void listbox_draw (WListbox * l, gboolean focused) { Widget *w = WIDGET (l); - const WDialog *h = w->owner; + const WDialog *h = DIALOG (w->owner); gboolean disabled; int normalc, selc; int length = 0; @@ -423,7 +423,7 @@ listbox_do_action (WListbox * l) if (action == LISTBOX_DONE) { - WDialog *h = WIDGET (l)->owner; + WDialog *h = DIALOG (WIDGET (l)->owner); h->ret_value = B_ENTER; dlg_stop (h); diff --git a/lib/widget/menu.c b/lib/widget/menu.c index eb31c168a..d80293fef 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -257,7 +257,7 @@ menubar_draw (const WMenuBar * menubar) static void menubar_remove (WMenuBar * menubar) { - WDialog *h; + WGroup *g; if (!menubar->is_dropped) return; @@ -266,15 +266,15 @@ menubar_remove (WMenuBar * menubar) of overlapped widgets. This is useful in multi-window editor. In general, menubar should be a special object, not an ordinary widget in the current dialog. */ - h = WIDGET (menubar)->owner; - h->current = g_list_find (h->widgets, dlg_find_by_id (h, menubar->previous_widget)); + g = WIDGET (menubar)->owner; + g->current = g_list_find (g->widgets, dlg_find_by_id (DIALOG (g), menubar->previous_widget)); menubar->is_dropped = FALSE; do_refresh (); menubar->is_dropped = TRUE; /* restore current widget */ - h->current = g_list_find (h->widgets, menubar); + g->current = g_list_find (g->widgets, menubar); } /* --------------------------------------------------------------------------------------------- */ @@ -317,7 +317,7 @@ menubar_finish (WMenuBar * menubar) * an "invisible" menubar get the first chance to respond to mouse events. */ widget_set_bottom (w); - dlg_select_by_id (w->owner, menubar->previous_widget); + dlg_select_by_id (DIALOG (w->owner), menubar->previous_widget); do_refresh (); } @@ -974,7 +974,7 @@ menubar_add_menu (WMenuBar * menubar, menu_t * menu) { if (menu != NULL) { - menu_arrange (menu, WIDGET (menubar)->owner->get_shortcut); + menu_arrange (menu, DIALOG (WIDGET (menubar)->owner)->get_shortcut); menubar->menu = g_list_append (menubar->menu, menu); } @@ -1065,7 +1065,7 @@ menubar_activate (WMenuBar * menubar, gboolean dropped, int which) if (which >= 0) menubar->selected = (guint) which; - menubar->previous_widget = dlg_get_current_widget_id (w->owner); + menubar->previous_widget = dlg_get_current_widget_id (DIALOG (w->owner)); /* Bring it to the top so it receives all mouse events before any other widget. * See also comment in menubar_finish(). */ diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index 46d76d355..661ef0361 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -74,19 +74,19 @@ widget_do_focus (Widget * w, gboolean enable) static void widget_focus (Widget * w) { - WDialog *h = DIALOG (w->owner); + WGroup *g = w->owner; - if (h == NULL) + if (g == NULL) return; - if (WIDGET (h->current->data) != w) + if (WIDGET (g->current->data) != w) { - widget_do_focus (WIDGET (h->current->data), FALSE); + widget_do_focus (WIDGET (g->current->data), FALSE); /* Test if focus lost was allowed and focus has really been loose */ - if (h->current == NULL || !widget_get_state (WIDGET (h->current->data), WST_FOCUSED)) + if (g->current == NULL || !widget_get_state (WIDGET (g->current->data), WST_FOCUSED)) { widget_do_focus (w, TRUE); - h->current = dlg_find (h, w); + g->current = dlg_find (DIALOG (g), w); } } else if (!widget_get_state (w, WST_FOCUSED)) @@ -101,13 +101,13 @@ widget_focus (Widget * w) static void widget_reorder (GList * l, gboolean set_top) { - WDialog *h = WIDGET (l->data)->owner; + WGroup *g = WIDGET (l->data)->owner; - h->widgets = g_list_remove_link (h->widgets, l); + g->widgets = g_list_remove_link (g->widgets, l); if (set_top) - h->widgets = g_list_concat (h->widgets, l); + g->widgets = g_list_concat (g->widgets, l); else - h->widgets = g_list_concat (l, h->widgets); + g->widgets = g_list_concat (l, g->widgets); } /* --------------------------------------------------------------------------------------------- */ @@ -441,7 +441,7 @@ widget_set_size (Widget * widget, int y, int x, int lines, int cols) void widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) { - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); int color; if (widget_get_state (w, WST_DISABLED)) @@ -494,9 +494,9 @@ widget_draw (Widget * w) { if (w != NULL) { - WDialog *h = w->owner; + WGroup *g = w->owner; - if (h != NULL && widget_get_state (WIDGET (h), WST_ACTIVE)) + if (g != NULL && widget_get_state (WIDGET (g), WST_ACTIVE)) w->callback (w, NULL, MSG_DRAW, 0, NULL); } } @@ -512,21 +512,21 @@ widget_draw (Widget * w) void widget_replace (Widget * old_w, Widget * new_w) { - WDialog *h = old_w->owner; + WGroup *g = old_w->owner; gboolean should_focus = FALSE; GList *holder; - if (h->widgets == NULL) + if (g->widgets == NULL) return; - if (h->current == NULL) - h->current = h->widgets; + if (g->current == NULL) + g->current = g->widgets; /* locate widget position in the list */ - if (old_w == h->current->data) - holder = h->current; + if (old_w == g->current->data) + holder = g->current; else - holder = g_list_find (h->widgets, old_w); + holder = g_list_find (g->widgets, old_w); /* if old widget is focused, we should focus the new one... */ if (widget_get_state (old_w, WST_FOCUSED)) @@ -549,7 +549,7 @@ widget_replace (Widget * old_w, Widget * new_w) } /* replace widget */ - new_w->owner = h; + new_w->owner = g; new_w->id = old_w->id; holder->data = new_w; @@ -580,7 +580,7 @@ widget_select (Widget * w) if (!widget_get_options (w, WOP_SELECTABLE)) return; - h = w->owner; + h = DIALOG (w->owner); if (h != NULL) { if (widget_get_options (w, WOP_TOP_SELECT)) @@ -603,7 +603,7 @@ widget_select (Widget * w) void widget_set_bottom (Widget * w) { - widget_reorder (dlg_find (w->owner, w), FALSE); + widget_reorder (dlg_find (DIALOG (w->owner), w), FALSE); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 9c3c4cc30..c5d6b5456 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -134,7 +134,7 @@ struct Widget unsigned int id; /* Number of the widget, starting with 0 */ widget_cb_fn callback; widget_mouse_cb_fn mouse_callback; - WDialog *owner; + WGroup *owner; /* Mouse-related fields. */ struct { diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 58e668954..d51049902 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -2882,7 +2882,7 @@ dview_update (WDiff * dview) static void dview_edit (WDiff * dview, diff_place_t ord) { - WDialog *h; + Widget *h; gboolean h_modal; int linenum, lineofs; @@ -2892,13 +2892,13 @@ dview_edit (WDiff * dview, diff_place_t ord) return; } - h = WIDGET (dview)->owner; - h_modal = widget_get_state (WIDGET (h), WST_MODAL); + h = WIDGET (WIDGET (dview)->owner); + h_modal = widget_get_state (h, WST_MODAL); get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs); /* disallow edit file in several editors */ - widget_set_state (WIDGET (h), WST_MODAL, TRUE); + widget_set_state (h, WST_MODAL, TRUE); { vfs_path_t *tmp_vpath; @@ -2908,7 +2908,7 @@ dview_edit (WDiff * dview, diff_place_t ord) vfs_path_free (tmp_vpath); } - widget_set_state (WIDGET (h), WST_MODAL, h_modal); + widget_set_state (h, WST_MODAL, h_modal); dview_redo (dview); dview_update (dview); } @@ -2965,13 +2965,10 @@ dview_goto_cmd (WDiff * dview, diff_place_t ord) static void dview_labels (WDiff * dview) { - Widget *d; - WDialog *h; + Widget *d = WIDGET (dview); WButtonBar *b; - d = WIDGET (dview); - h = d->owner; - b = find_buttonbar (h); + b = find_buttonbar (DIALOG (d->owner)); buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, d); buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), diff_map, d); @@ -3306,7 +3303,7 @@ static cb_ret_t dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WDiff *dview = (WDiff *) w; - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); cb_ret_t i; switch (msg) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 5fb694903..3d74e7e1b 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1559,7 +1559,7 @@ void edit_syntax_onoff_cmd (WDialog * h) { option_syntax_highlighting = !option_syntax_highlighting; - g_list_foreach (h->widgets, edit_syntax_onoff_cb, NULL); + g_list_foreach (GROUP (h)->widgets, edit_syntax_onoff_cb, NULL); dlg_draw (h); } @@ -1574,7 +1574,7 @@ void edit_show_tabs_tws_cmd (WDialog * h) { enable_show_tabs_tws = !enable_show_tabs_tws; - g_list_foreach (h->widgets, edit_redraw_page_cb, NULL); + g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL); dlg_draw (h); } @@ -1589,7 +1589,7 @@ void edit_show_margin_cmd (WDialog * h) { show_right_margin = !show_right_margin; - g_list_foreach (h->widgets, edit_redraw_page_cb, NULL); + g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL); dlg_draw (h); } @@ -1605,7 +1605,7 @@ edit_show_numbers_cmd (WDialog * h) { option_line_state = !option_line_state; option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0; - g_list_foreach (h->widgets, edit_redraw_page_cb, NULL); + g_list_foreach (GROUP (h)->widgets, edit_redraw_page_cb, NULL); dlg_draw (h); } @@ -2262,7 +2262,8 @@ edit_close_cmd (WEdit * edit) if (ret) { - WDialog *h = WIDGET (edit)->owner; + WGroup *g = WIDGET (edit)->owner; + WDialog *h = DIALOG (g); if (edit->locked != 0) unlock_file (edit->filename_vpath); @@ -2270,8 +2271,8 @@ edit_close_cmd (WEdit * edit) del_widget (edit); widget_destroy (WIDGET (edit)); - if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) - edit = (WEdit *) h->current->data; + if (edit_widget_is_editor (CONST_WIDGET (g->current->data))) + edit = (WEdit *) (g->current->data); else { edit = find_editor (h); diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c index 0dcbc1bcb..bbd4d7521 100644 --- a/src/editor/editoptions.c +++ b/src/editor/editoptions.c @@ -197,7 +197,7 @@ edit_options_dialog (WDialog * h) old_syntax_hl = option_syntax_highlighting; if (!option_cursor_beyond_eol) - g_list_foreach (h->widgets, edit_reset_over_col, NULL); + g_list_foreach (GROUP (h)->widgets, edit_reset_over_col, NULL); if (p != NULL) { @@ -233,7 +233,7 @@ edit_options_dialog (WDialog * h) /* Load or unload syntax rules if the option has changed */ if (option_syntax_highlighting != old_syntax_hl) - g_list_foreach (h->widgets, edit_reload_syntax, NULL); + g_list_foreach (GROUP (h)->widgets, edit_reload_syntax, NULL); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index d47a1c798..aea15090f 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -193,7 +193,7 @@ edit_restore_size (WEdit * edit) edit->drag_state = MCEDIT_DRAG_NONE; w->mouse.forced_capture = FALSE; widget_set_size (w, edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev); - dlg_draw (w->owner); + dlg_draw (DIALOG (w->owner)); } /* --------------------------------------------------------------------------------------------- */ @@ -233,7 +233,7 @@ edit_window_move (WEdit * edit, long command) } edit->force |= REDRAW_PAGE; - dlg_draw (w->owner); + dlg_draw (DIALOG (w->owner)); } /* --------------------------------------------------------------------------------------------- */ @@ -273,7 +273,7 @@ edit_window_resize (WEdit * edit, long command) } edit->force |= REDRAW_COMPLETELY; - dlg_draw (w->owner); + dlg_draw (DIALOG (w->owner)); } /* --------------------------------------------------------------------------------------------- */ @@ -295,7 +295,9 @@ get_hotkey (int n) static void edit_window_list (const WDialog * h) { - const size_t dlg_num = g_list_length (h->widgets) - 2; /* 2 = skip menu and buttonbar */ + const WGroup *g = CONST_GROUP (h); + const size_t offset = 2; /* skip menu and buttonbar */ + const size_t dlg_num = g_list_length (g->widgets) - offset; int lines, cols; Listbox *listbox; GList *w; @@ -307,7 +309,7 @@ edit_window_list (const WDialog * h) listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); - for (w = h->widgets; w != NULL; w = g_list_next (w)) + for (w = g->widgets; w != NULL; w = g_list_next (w)) if (edit_widget_is_editor (CONST_WIDGET (w->data))) { WEdit *e = (WEdit *) w->data; @@ -325,7 +327,7 @@ edit_window_list (const WDialog * h) g_free (fname); } - selected = run_listbox_with_data (listbox, h->current->data); + selected = run_listbox_with_data (listbox, g->current->data); if (selected != NULL) widget_select (WIDGET (selected)); } @@ -379,6 +381,7 @@ edit_get_title (const WDialog * h, size_t len) static cb_ret_t edit_dialog_command_execute (WDialog * h, long command) { + WGroup *g = GROUP (h); Widget *wh = WIDGET (h); cb_ret_t ret = MSG_HANDLED; @@ -401,8 +404,8 @@ edit_dialog_command_execute (WDialog * h, long command) break; case CK_Close: /* if there are no opened files anymore, close MC editor */ - if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) && - edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) + if (edit_widget_is_editor (CONST_WIDGET (g->current->data)) && + edit_close_cmd ((WEdit *) g->current->data) && find_editor (h) == NULL) dlg_stop (h); break; case CK_Help: @@ -416,7 +419,7 @@ edit_dialog_command_execute (WDialog * h, long command) case CK_Cancel: /* don't close editor due to SIGINT, but stop move/resize window */ { - Widget *w = WIDGET (h->current->data); + Widget *w = WIDGET (g->current->data); if (edit_widget_is_editor (w) && ((WEdit *) w)->drag_state != MCEDIT_DRAG_NONE) edit_restore_size ((WEdit *) w); @@ -450,8 +453,8 @@ edit_dialog_command_execute (WDialog * h, long command) break; case CK_WindowMove: case CK_WindowResize: - if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) - edit_handle_move_resize ((WEdit *) h->current->data, command); + if (edit_widget_is_editor (CONST_WIDGET (g->current->data))) + edit_handle_move_resize ((WEdit *) g->current->data, command); break; case CK_WindowList: edit_window_list (h); @@ -618,7 +621,7 @@ edit_quit (WDialog * h) widget_set_state (WIDGET (h), WST_ACTIVE, TRUE); /* check window state and get modified files */ - for (l = h->widgets; l != NULL; l = g_list_next (l)) + for (l = GROUP (h)->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (CONST_WIDGET (l->data))) { e = (WEdit *) l->data; @@ -746,6 +749,7 @@ 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) { + WGroup *g = GROUP (w); WDialog *h = DIALOG (w); switch (msg) @@ -776,14 +780,14 @@ edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v /* We forward any commands coming from the menu, and which haven't been handled by the dialog, to the focused WEdit window. */ if (result == MSG_NOT_HANDLED && sender == WIDGET (find_menubar (h))) - result = send_message (h->current->data, NULL, MSG_ACTION, parm, NULL); + result = send_message (g->current->data, NULL, MSG_ACTION, parm, NULL); return result; } case MSG_KEY: { - Widget *we = WIDGET (h->current->data); + Widget *we = WIDGET (g->current->data); cb_ret_t ret = MSG_NOT_HANDLED; if (edit_widget_is_editor (we)) @@ -834,7 +838,7 @@ edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v case MSG_IDLE: widget_idle (w, FALSE); - return send_message (h->current->data, NULL, MSG_IDLE, 0, NULL); + return send_message (g->current->data, NULL, MSG_IDLE, 0, NULL); default: return dlg_default_callback (w, sender, msg, parm, data); @@ -857,6 +861,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) if (msg == MSG_MOUSE_DOWN && event->y == 0) { + WGroup *g = GROUP (w); WDialog *h = DIALOG (w); WMenuBar *b; @@ -871,7 +876,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) int x; /* Try find top fullscreen window */ - for (l = h->widgets; l != NULL; l = g_list_next (l)) + for (l = g->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (CONST_WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) top = l; @@ -883,7 +888,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) { WEdit *e = (WEdit *) top->data; - if (top != h->current) + if (top != g->current) { /* Window is not active. Activate it */ widget_select (WIDGET (e)); @@ -917,7 +922,7 @@ edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da switch (msg) { case MSG_FOCUS: - edit_set_buttonbar (e, find_buttonbar (w->owner)); + edit_set_buttonbar (e, find_buttonbar (DIALOG (w->owner))); return MSG_HANDLED; case MSG_DRAW: @@ -1029,7 +1034,7 @@ edit_mouse_handle_move_resize (Widget * w, mouse_msg_t msg, mouse_event_t * even edit->force |= REDRAW_COMPLETELY; /* Not really needed as WEdit's MSG_DRAW already does this. */ /* We draw the whole dialog because dragging/resizing exposes area beneath. */ - dlg_draw (w->owner); + dlg_draw (DIALOG (w->owner)); } /* --------------------------------------------------------------------------------------------- */ @@ -1260,8 +1265,10 @@ edit_get_file_name (const WEdit * edit) WEdit * find_editor (const WDialog * h) { - if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) - return (WEdit *) h->current->data; + const WGroup *g = CONST_GROUP (h); + + if (edit_widget_is_editor (CONST_WIDGET (g->current->data))) + return (WEdit *) g->current->data; return (WEdit *) find_widget_type (h, edit_callback); } @@ -1284,8 +1291,6 @@ edit_widget_is_editor (const Widget * w) void edit_update_screen (WEdit * e) { - WDialog *h = WIDGET (e)->owner; - edit_scroll_screen_over_cursor (e); edit_update_curs_col (e); edit_status (e, widget_get_state (WIDGET (e), WST_FOCUSED)); @@ -1300,7 +1305,7 @@ edit_update_screen (WEdit * e) edit_render_keypress (e); } - widget_draw (WIDGET (find_buttonbar (h))); + widget_draw (WIDGET (find_buttonbar (DIALOG (WIDGET (e)->owner)))); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index 4a47ea519..db253739a 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -320,11 +320,11 @@ advanced_chown_info_update (void) /* --------------------------------------------------------------------------------------------- */ static void -update_mode (WDialog * h) +update_mode (WGroup * g) { - print_flags (h); + print_flags (DIALOG (g)); advanced_chown_info_update (); - widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE); + widget_set_state (WIDGET (g->current->data), WST_FOCUSED, TRUE); } /* --------------------------------------------------------------------------------------------- */ @@ -368,7 +368,7 @@ perm_button_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v update_mode (w->owner); send_message (w, NULL, MSG_KEY, KEY_RIGHT, NULL); if (b->hotpos == 2) - dlg_select_next_widget (w->owner); + dlg_select_next_widget (DIALOG (w->owner)); break; case XCTRL ('f'): @@ -528,7 +528,7 @@ user_group_button_cb (WButton * button, int action) do { - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); Widget *wh = WIDGET (h); gboolean is_owner = (f_pos == BUTTONS_PERM - 2); @@ -658,6 +658,7 @@ user_group_button_cb (WButton * button, int action) static cb_ret_t advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { + WGroup *g = GROUP (w); WDialog *h = DIALOG (w); int i = 0; @@ -684,7 +685,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm for (i = 0; i < 3; i++) ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+'; x_toggle ^= (1 << parm); - update_mode (h); + update_mode (g); dlg_broadcast_msg (h, MSG_DRAW); break; @@ -701,7 +702,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm for (i = 0; i < 3; i++) ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+'; x_toggle ^= (1 << parm); - update_mode (h); + update_mode (g); dlg_broadcast_msg (h, MSG_DRAW); break; diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 252c241a6..8e7dd41e9 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -355,7 +355,7 @@ sel_charset_button (WButton * button, int action) cpname = _("7-bit ASCII"); /* FIXME */ button_set_text (button, cpname); - dlg_draw (WIDGET (button)->owner); + dlg_draw (DIALOG (WIDGET (button)->owner)); } return 0; @@ -484,7 +484,7 @@ task_cb (WButton * button, int action) jobs_fill_listbox (bg_list); /* This can be optimized to just redraw this widget :-) */ - dlg_draw (WIDGET (button)->owner); + dlg_draw (DIALOG (WIDGET (button)->owner)); return 0; } diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 236741832..5d9e74b17 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -411,7 +411,8 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode) #define ADD_LABEL(i) \ add_widget_autopos (ui->replace_dlg, W(i), dlg_widgets[i].pos_flags, \ - ui->replace_dlg->current != NULL ? ui->replace_dlg->current->data : NULL) + GROUP (ui->replace_dlg)->current != NULL ? \ + GROUP (ui->replace_dlg)->current->data : NULL) #define NEW_BUTTON(i) \ W(i) = WIDGET (button_new (dlg_widgets[i].y, dlg_widgets[i].x, \ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 810435d0d..5e1f17b29 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -523,9 +523,9 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi return MSG_HANDLED; case MSG_POST_KEY: - if (h->current->data == in_name) + if (GROUP (h)->current->data == in_name) find_toggle_enable_params (); - else if (h->current->data == in_with) + else if (GROUP (h)->current->data == in_with) { content_is_empty = input_is_empty (in_with); find_toggle_enable_content (); @@ -1594,8 +1594,8 @@ start_stop (WButton * button, int action) status_update (is_start ? _("Stopped") : _("Searching")); button_set_text (button, fbuts[is_start ? 3 : 2].text); - find_relocate_buttons (w->owner, FALSE); - dlg_draw (w->owner); + find_relocate_buttons (DIALOG (w->owner), FALSE); + dlg_draw (DIALOG (w->owner)); return 0; } diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index e8c394f7f..766a00a55 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -621,7 +621,7 @@ hotlist_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void static lcback_ret_t hotlist_listbox_callback (WListbox * list) { - WDialog *dlg = WIDGET (list)->owner; + WDialog *dlg = DIALOG (WIDGET (list)->owner); if (!listbox_is_empty (list)) { diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 2d2fa35cc..7b7174007 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -279,7 +279,7 @@ b_left_right_cback (WButton * button, int action) panels_layout.left_panel_size--; } - update_split (WIDGET (button)->owner); + update_split (DIALOG (WIDGET (button)->owner)); layout_change (); do_refresh (); return 0; diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 5f6c3ee85..21ea31dbf 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -3633,15 +3633,16 @@ static cb_ret_t panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WPanel *panel = PANEL (w); + WDialog *h = DIALOG (w->owner); WButtonBar *bb; switch (msg) { case MSG_INIT: /* subscribe to "history_load" event */ - mc_event_add (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w, NULL); + mc_event_add (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w, NULL); /* subscribe to "history_save" event */ - mc_event_add (w->owner->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w, NULL); + mc_event_add (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w, NULL); return MSG_HANDLED; case MSG_DRAW: @@ -3676,7 +3677,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d update_xterm_title_path (); select_item (panel); - bb = find_buttonbar (w->owner); + bb = find_buttonbar (h); midnight_set_buttonbar (bb); widget_draw (WIDGET (bb)); return MSG_HANDLED; @@ -3697,9 +3698,9 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d case MSG_DESTROY: vfs_stamp_path (panel->cwd_vpath); /* unsubscribe from "history_load" event */ - mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w); + mc_event_del (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w); /* unsubscribe from "history_save" event */ - mc_event_del (w->owner->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w); + mc_event_del (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w); panel_destroy (panel); free_my_statfs (); return MSG_HANDLED; diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 928a40a08..9a0e55df4 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -249,7 +249,7 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) else { /* Show full name of selected directory */ - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); @@ -265,7 +265,7 @@ static void show_tree (WTree * tree) { Widget *w = WIDGET (tree); - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); tree_entry *current; int i, j; int topsublevel = 0; @@ -591,7 +591,7 @@ tree_chdir_sel (WTree * tree) } else { - WDialog *h = WIDGET (tree)->owner; + WDialog *h = DIALOG (WIDGET (tree)->owner); h->ret_value = B_ENTER; dlg_stop (h); @@ -975,7 +975,7 @@ tree_toggle_navig (WTree * tree) tree_navigation_flag = !tree_navigation_flag; - b = find_buttonbar (WIDGET (tree)->owner); + b = find_buttonbar (DIALOG (WIDGET (tree)->owner)); buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") : Q_ ("ButtonBar|Dynamc"), tree_map, WIDGET (tree)); @@ -1044,7 +1044,7 @@ tree_execute_cmd (WTree * tree, long command) break; case CK_Quit: if (!tree->is_panel) - dlg_stop (WIDGET (tree)->owner); + dlg_stop (DIALOG (WIDGET (tree)->owner)); return res; default: res = MSG_NOT_HANDLED; @@ -1147,7 +1147,7 @@ static cb_ret_t tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WTree *tree = (WTree *) w; - WDialog *h = w->owner; + WDialog *h = DIALOG (w->owner); WButtonBar *b; switch (msg) diff --git a/src/learn.c b/src/learn.c index a91b39644..18d05d043 100644 --- a/src/learn.c +++ b/src/learn.c @@ -138,7 +138,7 @@ learn_move (gboolean right) totalcols = (learn_total - 1) / ROWS + 1; for (i = 0; i < learn_total; i++) - if (learnkeys[i].button == WIDGET (learn_dlg->current->data)) + if (learnkeys[i].button == WIDGET (GROUP (learn_dlg)->current->data)) { if (right) { diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index ca2f57183..c244bf6a4 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -577,7 +577,7 @@ mcview_execute_cmd (WView * view, long command) break; case CK_Quit: if (!mcview_is_in_panel (view)) - dlg_stop (WIDGET (view)->owner); + dlg_stop (DIALOG (WIDGET (view)->owner)); break; case CK_Cancel: /* don't close viewer due to SIGINT */ diff --git a/src/viewer/display.c b/src/viewer/display.c index a0e6a4efb..1cb9077e9 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -78,10 +78,11 @@ static enum ruler_type static void mcview_set_buttonbar (WView * view) { - WDialog *h = WIDGET (view)->owner; - WButtonBar *b = find_buttonbar (h); + WDialog *h = DIALOG (WIDGET (view)->owner); + WButtonBar *b; const global_keymap_t *keymap = view->mode_flags.hex ? viewer_hex_map : viewer_map; + b = find_buttonbar (h); buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, WIDGET (view)); if (view->mode_flags.hex) @@ -204,7 +205,7 @@ mcview_update (WView * view) { view->dpy_bbar_dirty = FALSE; mcview_set_buttonbar (view); - widget_draw (WIDGET (find_buttonbar (WIDGET (view)->owner))); + widget_draw (WIDGET (find_buttonbar (DIALOG (WIDGET (view)->owner)))); } if (view->dirty > dirt_limit)