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 <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-09-27 13:53:17 +03:00
parent afb09f7cd7
commit e4e0070db5
31 changed files with 265 additions and 188 deletions

View File

@ -9,13 +9,14 @@
/* main forward declarations */ /* main forward declarations */
struct Widget; struct Widget;
typedef struct Widget Widget; typedef struct Widget Widget;
struct WDialog; struct WGroup;
typedef struct WDialog WDialog; typedef struct WGroup WGroup;
/* Please note that the first element in all the widgets is a */ /* Please note that the first element in all the widgets is a */
/* widget variable of type Widget. We abuse this fact everywhere */ /* widget variable of type Widget. We abuse this fact everywhere */
#include "lib/widget/widget-common.h" #include "lib/widget/widget-common.h"
#include "lib/widget/group.h"
#include "lib/widget/dialog.h" #include "lib/widget/dialog.h"
#include "lib/widget/history.h" #include "lib/widget/history.h"
#include "lib/widget/button.h" #include "lib/widget/button.h"

View File

@ -8,6 +8,7 @@ libmcwidget_la_SOURCES = \
dialog.c dialog.h \ dialog.c dialog.h \
dialog-switch.c dialog-switch.h \ dialog-switch.c dialog-switch.h \
gauge.c gauge.h \ gauge.c gauge.h \
group.h \
groupbox.c groupbox.h \ groupbox.c groupbox.h \
hline.c hline.h \ hline.c hline.h \
history.c history.h \ history.c history.h \

View File

@ -62,7 +62,8 @@ cb_ret_t
button_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) button_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WButton *b = BUTTON (w); WButton *b = BUTTON (w);
WDialog *h = w->owner; WGroup *g = w->owner;
WDialog *h = DIALOG (g);
int off = 0; int off = 0;
switch (msg) 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 * when hotkeys are sent to all widgets before the key is
* handled by the current widget. * 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); send_message (w, sender, MSG_KEY, ' ', data);
return MSG_HANDLED; return MSG_HANDLED;

View File

@ -97,7 +97,7 @@ dlg_get_next_or_prev_of (const GList * list, gboolean next)
if (list != NULL) if (list != NULL)
{ {
const WDialog *owner = CONST_WIDGET (list->data)->owner; const WGroup *owner = CONST_WIDGET (list->data)->owner;
if (owner != NULL) if (owner != NULL)
{ {
@ -124,9 +124,11 @@ dlg_get_next_or_prev_of (const GList * list, gboolean next)
static void static void
dlg_select_next_or_prev (WDialog * h, gboolean next) 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; Widget *w;
do do
@ -135,7 +137,7 @@ dlg_select_next_or_prev (WDialog * h, gboolean next)
w = WIDGET (l->data); w = WIDGET (l->data);
} }
while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE)) while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE))
&& l != h->current); && l != g->current);
widget_select (l->data); 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) dlg_broadcast_msg_to (WDialog * h, widget_msg_t msg, gboolean reverse, widget_options_t flags)
{ {
GList *p, *first; GList *p, *first;
WGroup *g = GROUP (h);
if (h->widgets == NULL) if (g->widgets == NULL)
return; return;
if (h->current == NULL) if (g->current == NULL)
h->current = h->widgets; 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; first = p;
do do
@ -353,11 +356,11 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event)
return mou; return mou;
} }
if (h->widgets == NULL) if (GROUP (h)->widgets == NULL)
return MOU_UNHANDLED; return MOU_UNHANDLED;
/* send the event to widgets in reverse Z-order */ /* send the event to widgets in reverse Z-order */
p = g_list_last (h->widgets); p = g_list_last (GROUP (h)->widgets);
do do
{ {
Widget *w = WIDGET (p->data); Widget *w = WIDGET (p->data);
@ -384,23 +387,24 @@ dlg_mouse_event (WDialog * h, Gpm_Event * event)
static cb_ret_t static cb_ret_t
dlg_try_hotkey (WDialog * h, int d_key) dlg_try_hotkey (WDialog * h, int d_key)
{ {
WGroup *g = GROUP (h);
GList *hot_cur; GList *hot_cur;
Widget *current; Widget *current;
cb_ret_t handled; cb_ret_t handled;
int c; int c;
if (h->widgets == NULL) if (g->widgets == NULL)
return MSG_NOT_HANDLED; return MSG_NOT_HANDLED;
if (h->current == NULL) if (g->current == NULL)
h->current = h->widgets; g->current = g->widgets;
/* /*
* Explanation: we don't send letter hotkeys to other widgets if * Explanation: we don't send letter hotkeys to other widgets if
* the currently selected widget is an input line * 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)) if (widget_get_state (current, WST_DISABLED))
return MSG_NOT_HANDLED; return MSG_NOT_HANDLED;
@ -426,10 +430,10 @@ dlg_try_hotkey (WDialog * h, int d_key)
if (handled == MSG_HANDLED) if (handled == MSG_HANDLED)
return 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 */ /* 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); current = WIDGET (hot_cur->data);
@ -452,16 +456,17 @@ dlg_try_hotkey (WDialog * h, int d_key)
static void static void
dlg_key_event (WDialog * h, int d_key) dlg_key_event (WDialog * h, int d_key)
{ {
WGroup *g = GROUP (h);
cb_ret_t handled; cb_ret_t handled;
if (h->widgets == NULL) if (g->widgets == NULL)
return; return;
if (h->current == NULL) if (g->current == NULL)
h->current = h->widgets; g->current = g->widgets;
/* TAB used to cycle */ /* 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') 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); send_message (h, NULL, MSG_HOTKEY_HANDLED, 0, NULL);
else else
/* not used - then try widget_callback */ /* 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 */ /* not used- try to use the unhandled case */
if (handled == MSG_NOT_HANDLED) if (handled == MSG_NOT_HANDLED)
@ -640,6 +645,7 @@ dlg_default_repaint (WDialog * h)
void void
dlg_set_position (WDialog * h, int y, int x, int lines, int cols) dlg_set_position (WDialog * h, int y, int x, int lines, int cols)
{ {
WGroup *g = GROUP (h);
Widget *wh = WIDGET (h); Widget *wh = WIDGET (h);
widget_shift_scale_t wss; 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; wh->cols = cols;
/* dialog is empty */ /* dialog is empty */
if (h->widgets == NULL) if (g->widgets == NULL)
return; return;
if (h->current == NULL) if (g->current == NULL)
h->current = h->widgets; g->current = g->widgets;
/* values by which controls should be moved */ /* values by which controls should be moved */
wss.shift_x = wh->x - ox; 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; wss.scale_y = wh->lines - ol;
if (wss.shift_x != 0 || wss.shift_y != 0 || wss.scale_x != 0 || wss.scale_y != 0) 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 unsigned long
add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const void *before) 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 *wh = WIDGET (h);
Widget *widget; Widget *widget;
GList *new_current; 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->lines - widget->lines) / 2;
widget->y += wh->y; widget->y += wh->y;
widget->owner = h; widget->owner = g;
widget->pos_flags = pos_flags; widget->pos_flags = pos_flags;
widget->id = h->widget_id++; 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); g->widgets = g_list_append (g->widgets, widget);
new_current = g_list_last (h->widgets); new_current = g_list_last (g->widgets);
} }
else else
{ {
GList *b; 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 */ /* don't accept widget not from dialog. This shouldn't happen */
if (b == NULL) if (b == NULL)
abort (); abort ();
b = g_list_next (b); 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) if (b != NULL)
new_current = g_list_previous (b); new_current = g_list_previous (b);
else else
new_current = g_list_last (h->widgets); new_current = g_list_last (g->widgets);
} }
/* widget has been added at runtime */ /* 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); widget_select (widget);
} }
else else
h->current = new_current; g->current = new_current;
return widget->id; return widget->id;
} }
@ -872,8 +879,10 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo
unsigned long unsigned long
add_widget (WDialog * h, void *w) add_widget (WDialog * h, void *w)
{ {
WGroup *g = GROUP (h);
return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, 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 void
del_widget (void *w) del_widget (void *w)
{ {
WGroup *g;
WDialog *h; WDialog *h;
GList *d; GList *d;
@ -897,15 +907,16 @@ del_widget (void *w)
if (w == NULL) if (w == NULL)
abort (); abort ();
h = WIDGET (w)->owner; g = WIDGET (w)->owner;
h = DIALOG (g);
d = g_list_find (h->widgets, w); d = g_list_find (g->widgets, w);
if (d == h->current) if (d == g->current)
dlg_set_current_widget_next (h); dlg_set_current_widget_next (h);
h->widgets = g_list_delete_link (h->widgets, d); g->widgets = g_list_remove_link (g->widgets, d);
if (h->widgets == NULL) if (g->widgets == NULL)
h->current = NULL; g->current = NULL;
/* widget has been deleted in runtime */ /* widget has been deleted in runtime */
if (widget_get_state (WIDGET (h), WST_ACTIVE)) if (widget_get_state (WIDGET (h), WST_ACTIVE))
@ -958,7 +969,8 @@ find_widget_type (const WDialog * h, widget_cb_fn callback)
{ {
GList *w; 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); return (w == NULL) ? NULL : WIDGET (w->data);
} }
@ -968,7 +980,9 @@ find_widget_type (const WDialog * h, widget_cb_fn callback)
GList * GList *
dlg_find (const WDialog * h, const Widget * w) 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; 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; return w != NULL ? WIDGET (w->data) : NULL;
} }
@ -1019,7 +1033,8 @@ dlg_select_next_widget (WDialog * h)
void void
update_cursor (WDialog * h) 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)) if (p != NULL && widget_get_state (WIDGET (h), WST_ACTIVE))
{ {
@ -1031,7 +1046,7 @@ update_cursor (WDialog * h)
do do
{ {
p = dlg_get_widget_next_of (p); p = dlg_get_widget_next_of (p);
if (p == h->current) if (p == g->current)
break; break;
w = WIDGET (p->data); w = WIDGET (p->data);
@ -1081,6 +1096,7 @@ dlg_stop (WDialog * h)
void void
dlg_init (WDialog * h) dlg_init (WDialog * h)
{ {
WGroup *g = GROUP (h);
Widget *wh = WIDGET (h); Widget *wh = WIDGET (h);
if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL)) 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 */ /* Select the first widget that takes focus */
while (h->current != NULL && !widget_get_options (WIDGET (h->current->data), WOP_SELECTABLE) while (g->current != NULL && !widget_get_options (WIDGET (g->current->data), WOP_SELECTABLE)
&& !widget_get_state (WIDGET (h->current->data), WST_DISABLED)) && !widget_get_state (WIDGET (g->current->data), WST_DISABLED))
dlg_set_current_widget_next (h); dlg_set_current_widget_next (h);
widget_set_state (wh, WST_ACTIVE, TRUE); widget_set_state (wh, WST_ACTIVE, TRUE);
dlg_draw (h); dlg_draw (h);
/* focus found widget */ /* focus found widget */
if (h->current != NULL) if (g->current != NULL)
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE); widget_set_state (WIDGET (g->current->data), WST_FOCUSED, TRUE);
h->ret_value = 0; h->ret_value = 0;
} }
@ -1146,7 +1162,8 @@ dlg_run_done (WDialog * h)
if (widget_get_state (WIDGET (h), WST_CLOSED)) 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)) if (!widget_get_state (WIDGET (h), WST_MODAL))
dialog_switch_remove (h); dialog_switch_remove (h);
} }
@ -1174,10 +1191,12 @@ dlg_run (WDialog * h)
void void
dlg_destroy (WDialog * h) dlg_destroy (WDialog * h)
{ {
WGroup *g = GROUP (h);
/* if some widgets have history, save all history at one moment here */ /* if some widgets have history, save all history at one moment here */
dlg_save_history (h); dlg_save_history (h);
g_list_foreach (h->widgets, (GFunc) widget_destroy, NULL); g_list_foreach (g->widgets, (GFunc) widget_destroy, NULL);
g_list_free (h->widgets); g_list_free (g->widgets);
mc_event_group_del (h->event_group); mc_event_group_del (h->event_group);
g_free (h->event_group); g_free (h->event_group);
g_free (h->title); g_free (h->title);
@ -1271,7 +1290,9 @@ dlg_get_title (const WDialog * h, size_t len)
void void
dlg_set_current_widget_next (WDialog * h) 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 void
dlg_set_current_widget_prev (WDialog * h) 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);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -42,6 +42,8 @@ typedef enum
/*** typedefs(not structures) ********************************************************************/ /*** typedefs(not structures) ********************************************************************/
typedef struct WDialog WDialog;
/* get string representation of shortcut assigned with command */ /* get string representation of shortcut assigned with command */
/* as menu is a widget of dialog, ask dialog about shortcut string */ /* as menu is a widget of dialog, ask dialog about shortcut string */
typedef char *(*dlg_shortcut_str) (long command); typedef char *(*dlg_shortcut_str) (long command);
@ -58,7 +60,7 @@ typedef cb_ret_t (*menu_exec_fn) (int command);
struct WDialog struct WDialog
{ {
Widget widget; WGroup group; /* base class */
/* Set by the user */ /* Set by the user */
gboolean compact; /* Suppress spaces around the frame */ gboolean compact; /* Suppress spaces around the frame */
@ -74,8 +76,6 @@ struct WDialog
int mouse_status; /* For the autorepeat status of the mouse */ int mouse_status; /* For the autorepeat status of the mouse */
/* Internal variables */ /* Internal variables */
GList *widgets; /* widgets list */
GList *current; /* Currently active widget */
unsigned long widget_id; /* maximum id of all widgets */ unsigned long widget_id; /* maximum id of all widgets */
void *data; /* Data can be passed to dialog */ void *data; /* Data can be passed to dialog */
char *event_group; /* Name of event group for this 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 static inline unsigned long
dlg_get_current_widget_id (const WDialog * h) 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 static inline void
dlg_select_current_widget (WDialog * h) dlg_select_current_widget (WDialog * h)
{ {
if (h->current != NULL) if (GROUP (h)->current != NULL)
widget_select (WIDGET (h->current->data)); widget_select (WIDGET (GROUP (h)->current->data));
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -58,7 +58,7 @@ static cb_ret_t
gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WGauge *g = GAUGE (w); WGauge *g = GAUGE (w);
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
switch (msg) switch (msg)
{ {

42
lib/widget/group.h Normal file
View File

@ -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 */

View File

@ -61,7 +61,7 @@ groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
{ {
case MSG_DRAW: case MSG_DRAW:
{ {
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
gboolean disabled; gboolean disabled;

View File

@ -57,7 +57,7 @@ static cb_ret_t
hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WHLine *l = HLINE (w); WHLine *l = HLINE (w);
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
switch (msg) switch (msg)
{ {

View File

@ -874,7 +874,7 @@ input_save_history (const gchar * event_group_name, const gchar * event_name,
(void) event_group_name; (void) event_group_name;
(void) event_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; 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) input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WInput *in = INPUT (w); WInput *in = INPUT (w);
WDialog *h = DIALOG (w->owner);
cb_ret_t v; cb_ret_t v;
switch (msg) switch (msg)
{ {
case MSG_INIT: case MSG_INIT:
/* subscribe to "history_load" event */ /* 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 */ /* 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) if (in->label != NULL)
widget_set_state (WIDGET (in->label), WST_DISABLED, widget_get_state (w, WST_DISABLED)); widget_set_state (WIDGET (in->label), WST_DISABLED, widget_get_state (w, WST_DISABLED));
return MSG_HANDLED; return MSG_HANDLED;
@ -1099,9 +1100,9 @@ input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
case MSG_DESTROY: case MSG_DESTROY:
/* unsubscribe from "history_load" event */ /* 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 */ /* 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); input_destroy (in);
return MSG_HANDLED; return MSG_HANDLED;

View File

@ -1019,6 +1019,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
{ {
static int bl = 0; static int bl = 0;
WGroup *g = GROUP (w);
WDialog *h = DIALOG (w); WDialog *h = DIALOG (w);
switch (msg) 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; 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)) e != NULL; i++, e = g_list_next (e))
{ {
WLEntry *le = LENTRY (e->data); WLEntry *le = LENTRY (e->data);
if (strncmp (input->buffer + start, le->text, new_end - start) == 0) 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; end = new_end;
input_handle_char (input, parm); input_handle_char (input, parm);
widget_draw (WIDGET (h->current->data)); widget_draw (WIDGET (g->current->data));
break; break;
} }
} }
@ -1111,7 +1112,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
break; 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)) e != NULL; i++, e = g_list_next (e))
{ {
WLEntry *le = LENTRY (e->data); 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) if (need_redraw == 0)
{ {
need_redraw = 1; need_redraw = 1;
listbox_select_entry (LISTBOX (h->current->data), i); listbox_select_entry (LISTBOX (g->current->data), i);
last_text = le->text; last_text = le->text;
} }
else else
@ -1173,7 +1174,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
if (need_redraw == 2) if (need_redraw == 2)
{ {
insert_text (input, last_text, low); insert_text (input, last_text, low);
widget_draw (WIDGET (h->current->data)); widget_draw (WIDGET (g->current->data));
} }
else if (need_redraw == 1) else if (need_redraw == 1)
{ {

View File

@ -60,7 +60,7 @@ static cb_ret_t
label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WLabel *l = LABEL (w); WLabel *l = LABEL (w);
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
switch (msg) switch (msg)
{ {

View File

@ -131,7 +131,7 @@ static void
listbox_draw (WListbox * l, gboolean focused) listbox_draw (WListbox * l, gboolean focused)
{ {
Widget *w = WIDGET (l); Widget *w = WIDGET (l);
const WDialog *h = w->owner; const WDialog *h = DIALOG (w->owner);
gboolean disabled; gboolean disabled;
int normalc, selc; int normalc, selc;
int length = 0; int length = 0;
@ -423,7 +423,7 @@ listbox_do_action (WListbox * l)
if (action == LISTBOX_DONE) if (action == LISTBOX_DONE)
{ {
WDialog *h = WIDGET (l)->owner; WDialog *h = DIALOG (WIDGET (l)->owner);
h->ret_value = B_ENTER; h->ret_value = B_ENTER;
dlg_stop (h); dlg_stop (h);

View File

@ -257,7 +257,7 @@ menubar_draw (const WMenuBar * menubar)
static void static void
menubar_remove (WMenuBar * menubar) menubar_remove (WMenuBar * menubar)
{ {
WDialog *h; WGroup *g;
if (!menubar->is_dropped) if (!menubar->is_dropped)
return; return;
@ -266,15 +266,15 @@ menubar_remove (WMenuBar * menubar)
of overlapped widgets. This is useful in multi-window editor. of overlapped widgets. This is useful in multi-window editor.
In general, menubar should be a special object, not an ordinary widget In general, menubar should be a special object, not an ordinary widget
in the current dialog. */ in the current dialog. */
h = WIDGET (menubar)->owner; g = WIDGET (menubar)->owner;
h->current = g_list_find (h->widgets, dlg_find_by_id (h, menubar->previous_widget)); g->current = g_list_find (g->widgets, dlg_find_by_id (DIALOG (g), menubar->previous_widget));
menubar->is_dropped = FALSE; menubar->is_dropped = FALSE;
do_refresh (); do_refresh ();
menubar->is_dropped = TRUE; menubar->is_dropped = TRUE;
/* restore current widget */ /* 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. */ * an "invisible" menubar get the first chance to respond to mouse events. */
widget_set_bottom (w); 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 (); do_refresh ();
} }
@ -974,7 +974,7 @@ menubar_add_menu (WMenuBar * menubar, menu_t * menu)
{ {
if (menu != NULL) 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); menubar->menu = g_list_append (menubar->menu, menu);
} }
@ -1065,7 +1065,7 @@ menubar_activate (WMenuBar * menubar, gboolean dropped, int which)
if (which >= 0) if (which >= 0)
menubar->selected = (guint) which; 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. /* Bring it to the top so it receives all mouse events before any other widget.
* See also comment in menubar_finish(). */ * See also comment in menubar_finish(). */

View File

@ -74,19 +74,19 @@ widget_do_focus (Widget * w, gboolean enable)
static void static void
widget_focus (Widget * w) widget_focus (Widget * w)
{ {
WDialog *h = DIALOG (w->owner); WGroup *g = w->owner;
if (h == NULL) if (g == NULL)
return; 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 */ /* 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); 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)) else if (!widget_get_state (w, WST_FOCUSED))
@ -101,13 +101,13 @@ widget_focus (Widget * w)
static void static void
widget_reorder (GList * l, gboolean set_top) 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) if (set_top)
h->widgets = g_list_concat (h->widgets, l); g->widgets = g_list_concat (g->widgets, l);
else 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 void
widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey)
{ {
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
int color; int color;
if (widget_get_state (w, WST_DISABLED)) if (widget_get_state (w, WST_DISABLED))
@ -494,9 +494,9 @@ widget_draw (Widget * w)
{ {
if (w != NULL) 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); w->callback (w, NULL, MSG_DRAW, 0, NULL);
} }
} }
@ -512,21 +512,21 @@ widget_draw (Widget * w)
void void
widget_replace (Widget * old_w, Widget * new_w) widget_replace (Widget * old_w, Widget * new_w)
{ {
WDialog *h = old_w->owner; WGroup *g = old_w->owner;
gboolean should_focus = FALSE; gboolean should_focus = FALSE;
GList *holder; GList *holder;
if (h->widgets == NULL) if (g->widgets == NULL)
return; return;
if (h->current == NULL) if (g->current == NULL)
h->current = h->widgets; g->current = g->widgets;
/* locate widget position in the list */ /* locate widget position in the list */
if (old_w == h->current->data) if (old_w == g->current->data)
holder = h->current; holder = g->current;
else 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 old widget is focused, we should focus the new one... */
if (widget_get_state (old_w, WST_FOCUSED)) if (widget_get_state (old_w, WST_FOCUSED))
@ -549,7 +549,7 @@ widget_replace (Widget * old_w, Widget * new_w)
} }
/* replace widget */ /* replace widget */
new_w->owner = h; new_w->owner = g;
new_w->id = old_w->id; new_w->id = old_w->id;
holder->data = new_w; holder->data = new_w;
@ -580,7 +580,7 @@ widget_select (Widget * w)
if (!widget_get_options (w, WOP_SELECTABLE)) if (!widget_get_options (w, WOP_SELECTABLE))
return; return;
h = w->owner; h = DIALOG (w->owner);
if (h != NULL) if (h != NULL)
{ {
if (widget_get_options (w, WOP_TOP_SELECT)) if (widget_get_options (w, WOP_TOP_SELECT))
@ -603,7 +603,7 @@ widget_select (Widget * w)
void void
widget_set_bottom (Widget * w) widget_set_bottom (Widget * w)
{ {
widget_reorder (dlg_find (w->owner, w), FALSE); widget_reorder (dlg_find (DIALOG (w->owner), w), FALSE);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -134,7 +134,7 @@ struct Widget
unsigned int id; /* Number of the widget, starting with 0 */ unsigned int id; /* Number of the widget, starting with 0 */
widget_cb_fn callback; widget_cb_fn callback;
widget_mouse_cb_fn mouse_callback; widget_mouse_cb_fn mouse_callback;
WDialog *owner; WGroup *owner;
/* Mouse-related fields. */ /* Mouse-related fields. */
struct struct
{ {

View File

@ -2882,7 +2882,7 @@ dview_update (WDiff * dview)
static void static void
dview_edit (WDiff * dview, diff_place_t ord) dview_edit (WDiff * dview, diff_place_t ord)
{ {
WDialog *h; Widget *h;
gboolean h_modal; gboolean h_modal;
int linenum, lineofs; int linenum, lineofs;
@ -2892,13 +2892,13 @@ dview_edit (WDiff * dview, diff_place_t ord)
return; return;
} }
h = WIDGET (dview)->owner; h = WIDGET (WIDGET (dview)->owner);
h_modal = widget_get_state (WIDGET (h), WST_MODAL); h_modal = widget_get_state (h, WST_MODAL);
get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs); get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs);
/* disallow edit file in several editors */ /* 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; vfs_path_t *tmp_vpath;
@ -2908,7 +2908,7 @@ dview_edit (WDiff * dview, diff_place_t ord)
vfs_path_free (tmp_vpath); 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_redo (dview);
dview_update (dview); dview_update (dview);
} }
@ -2965,13 +2965,10 @@ dview_goto_cmd (WDiff * dview, diff_place_t ord)
static void static void
dview_labels (WDiff * dview) dview_labels (WDiff * dview)
{ {
Widget *d; Widget *d = WIDGET (dview);
WDialog *h;
WButtonBar *b; WButtonBar *b;
d = WIDGET (dview); b = find_buttonbar (DIALOG (d->owner));
h = d->owner;
b = find_buttonbar (h);
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, d); buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, d);
buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), 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) dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WDiff *dview = (WDiff *) w; WDiff *dview = (WDiff *) w;
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
cb_ret_t i; cb_ret_t i;
switch (msg) switch (msg)

View File

@ -1559,7 +1559,7 @@ void
edit_syntax_onoff_cmd (WDialog * h) edit_syntax_onoff_cmd (WDialog * h)
{ {
option_syntax_highlighting = !option_syntax_highlighting; 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); dlg_draw (h);
} }
@ -1574,7 +1574,7 @@ void
edit_show_tabs_tws_cmd (WDialog * h) edit_show_tabs_tws_cmd (WDialog * h)
{ {
enable_show_tabs_tws = !enable_show_tabs_tws; 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); dlg_draw (h);
} }
@ -1589,7 +1589,7 @@ void
edit_show_margin_cmd (WDialog * h) edit_show_margin_cmd (WDialog * h)
{ {
show_right_margin = !show_right_margin; 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); dlg_draw (h);
} }
@ -1605,7 +1605,7 @@ edit_show_numbers_cmd (WDialog * h)
{ {
option_line_state = !option_line_state; option_line_state = !option_line_state;
option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0; 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); dlg_draw (h);
} }
@ -2262,7 +2262,8 @@ edit_close_cmd (WEdit * edit)
if (ret) if (ret)
{ {
WDialog *h = WIDGET (edit)->owner; WGroup *g = WIDGET (edit)->owner;
WDialog *h = DIALOG (g);
if (edit->locked != 0) if (edit->locked != 0)
unlock_file (edit->filename_vpath); unlock_file (edit->filename_vpath);
@ -2270,8 +2271,8 @@ edit_close_cmd (WEdit * edit)
del_widget (edit); del_widget (edit);
widget_destroy (WIDGET (edit)); widget_destroy (WIDGET (edit));
if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) if (edit_widget_is_editor (CONST_WIDGET (g->current->data)))
edit = (WEdit *) h->current->data; edit = (WEdit *) (g->current->data);
else else
{ {
edit = find_editor (h); edit = find_editor (h);

View File

@ -197,7 +197,7 @@ edit_options_dialog (WDialog * h)
old_syntax_hl = option_syntax_highlighting; old_syntax_hl = option_syntax_highlighting;
if (!option_cursor_beyond_eol) 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) if (p != NULL)
{ {
@ -233,7 +233,7 @@ edit_options_dialog (WDialog * h)
/* Load or unload syntax rules if the option has changed */ /* Load or unload syntax rules if the option has changed */
if (option_syntax_highlighting != old_syntax_hl) 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);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -193,7 +193,7 @@ edit_restore_size (WEdit * edit)
edit->drag_state = MCEDIT_DRAG_NONE; edit->drag_state = MCEDIT_DRAG_NONE;
w->mouse.forced_capture = FALSE; w->mouse.forced_capture = FALSE;
widget_set_size (w, edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev); 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; 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; edit->force |= REDRAW_COMPLETELY;
dlg_draw (w->owner); dlg_draw (DIALOG (w->owner));
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -295,7 +295,9 @@ get_hotkey (int n)
static void static void
edit_window_list (const WDialog * h) 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; int lines, cols;
Listbox *listbox; Listbox *listbox;
GList *w; GList *w;
@ -307,7 +309,7 @@ edit_window_list (const WDialog * h)
listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); 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))) if (edit_widget_is_editor (CONST_WIDGET (w->data)))
{ {
WEdit *e = (WEdit *) w->data; WEdit *e = (WEdit *) w->data;
@ -325,7 +327,7 @@ edit_window_list (const WDialog * h)
g_free (fname); g_free (fname);
} }
selected = run_listbox_with_data (listbox, h->current->data); selected = run_listbox_with_data (listbox, g->current->data);
if (selected != NULL) if (selected != NULL)
widget_select (WIDGET (selected)); widget_select (WIDGET (selected));
} }
@ -379,6 +381,7 @@ edit_get_title (const WDialog * h, size_t len)
static cb_ret_t static cb_ret_t
edit_dialog_command_execute (WDialog * h, long command) edit_dialog_command_execute (WDialog * h, long command)
{ {
WGroup *g = GROUP (h);
Widget *wh = WIDGET (h); Widget *wh = WIDGET (h);
cb_ret_t ret = MSG_HANDLED; cb_ret_t ret = MSG_HANDLED;
@ -401,8 +404,8 @@ edit_dialog_command_execute (WDialog * h, long command)
break; break;
case CK_Close: case CK_Close:
/* if there are no opened files anymore, close MC editor */ /* if there are no opened files anymore, close MC editor */
if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) && if (edit_widget_is_editor (CONST_WIDGET (g->current->data)) &&
edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) edit_close_cmd ((WEdit *) g->current->data) && find_editor (h) == NULL)
dlg_stop (h); dlg_stop (h);
break; break;
case CK_Help: case CK_Help:
@ -416,7 +419,7 @@ edit_dialog_command_execute (WDialog * h, long command)
case CK_Cancel: case CK_Cancel:
/* don't close editor due to SIGINT, but stop move/resize window */ /* 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) if (edit_widget_is_editor (w) && ((WEdit *) w)->drag_state != MCEDIT_DRAG_NONE)
edit_restore_size ((WEdit *) w); edit_restore_size ((WEdit *) w);
@ -450,8 +453,8 @@ edit_dialog_command_execute (WDialog * h, long command)
break; break;
case CK_WindowMove: case CK_WindowMove:
case CK_WindowResize: case CK_WindowResize:
if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) if (edit_widget_is_editor (CONST_WIDGET (g->current->data)))
edit_handle_move_resize ((WEdit *) h->current->data, command); edit_handle_move_resize ((WEdit *) g->current->data, command);
break; break;
case CK_WindowList: case CK_WindowList:
edit_window_list (h); edit_window_list (h);
@ -618,7 +621,7 @@ edit_quit (WDialog * h)
widget_set_state (WIDGET (h), WST_ACTIVE, TRUE); widget_set_state (WIDGET (h), WST_ACTIVE, TRUE);
/* check window state and get modified files */ /* 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))) if (edit_widget_is_editor (CONST_WIDGET (l->data)))
{ {
e = (WEdit *) l->data; e = (WEdit *) l->data;
@ -746,6 +749,7 @@ edit_update_cursor (WEdit * edit, const mouse_event_t * event)
static cb_ret_t static cb_ret_t
edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WGroup *g = GROUP (w);
WDialog *h = DIALOG (w); WDialog *h = DIALOG (w);
switch (msg) 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 /* We forward any commands coming from the menu, and which haven't been
handled by the dialog, to the focused WEdit window. */ handled by the dialog, to the focused WEdit window. */
if (result == MSG_NOT_HANDLED && sender == WIDGET (find_menubar (h))) 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; return result;
} }
case MSG_KEY: case MSG_KEY:
{ {
Widget *we = WIDGET (h->current->data); Widget *we = WIDGET (g->current->data);
cb_ret_t ret = MSG_NOT_HANDLED; cb_ret_t ret = MSG_NOT_HANDLED;
if (edit_widget_is_editor (we)) 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: case MSG_IDLE:
widget_idle (w, FALSE); 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: default:
return dlg_default_callback (w, sender, msg, parm, data); 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) if (msg == MSG_MOUSE_DOWN && event->y == 0)
{ {
WGroup *g = GROUP (w);
WDialog *h = DIALOG (w); WDialog *h = DIALOG (w);
WMenuBar *b; WMenuBar *b;
@ -871,7 +876,7 @@ edit_dialog_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
int x; int x;
/* Try find top fullscreen window */ /* 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)) if (edit_widget_is_editor (CONST_WIDGET (l->data))
&& ((WEdit *) l->data)->fullscreen) && ((WEdit *) l->data)->fullscreen)
top = l; 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; WEdit *e = (WEdit *) top->data;
if (top != h->current) if (top != g->current)
{ {
/* Window is not active. Activate it */ /* Window is not active. Activate it */
widget_select (WIDGET (e)); widget_select (WIDGET (e));
@ -917,7 +922,7 @@ edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da
switch (msg) switch (msg)
{ {
case MSG_FOCUS: case MSG_FOCUS:
edit_set_buttonbar (e, find_buttonbar (w->owner)); edit_set_buttonbar (e, find_buttonbar (DIALOG (w->owner)));
return MSG_HANDLED; return MSG_HANDLED;
case MSG_DRAW: 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. */ 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. */ /* 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 * WEdit *
find_editor (const WDialog * h) find_editor (const WDialog * h)
{ {
if (edit_widget_is_editor (CONST_WIDGET (h->current->data))) const WGroup *g = CONST_GROUP (h);
return (WEdit *) h->current->data;
if (edit_widget_is_editor (CONST_WIDGET (g->current->data)))
return (WEdit *) g->current->data;
return (WEdit *) find_widget_type (h, edit_callback); return (WEdit *) find_widget_type (h, edit_callback);
} }
@ -1284,8 +1291,6 @@ edit_widget_is_editor (const Widget * w)
void void
edit_update_screen (WEdit * e) edit_update_screen (WEdit * e)
{ {
WDialog *h = WIDGET (e)->owner;
edit_scroll_screen_over_cursor (e); edit_scroll_screen_over_cursor (e);
edit_update_curs_col (e); edit_update_curs_col (e);
edit_status (e, widget_get_state (WIDGET (e), WST_FOCUSED)); edit_status (e, widget_get_state (WIDGET (e), WST_FOCUSED));
@ -1300,7 +1305,7 @@ edit_update_screen (WEdit * e)
edit_render_keypress (e); edit_render_keypress (e);
} }
widget_draw (WIDGET (find_buttonbar (h))); widget_draw (WIDGET (find_buttonbar (DIALOG (WIDGET (e)->owner))));
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -320,11 +320,11 @@ advanced_chown_info_update (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void static void
update_mode (WDialog * h) update_mode (WGroup * g)
{ {
print_flags (h); print_flags (DIALOG (g));
advanced_chown_info_update (); 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); update_mode (w->owner);
send_message (w, NULL, MSG_KEY, KEY_RIGHT, NULL); send_message (w, NULL, MSG_KEY, KEY_RIGHT, NULL);
if (b->hotpos == 2) if (b->hotpos == 2)
dlg_select_next_widget (w->owner); dlg_select_next_widget (DIALOG (w->owner));
break; break;
case XCTRL ('f'): case XCTRL ('f'):
@ -528,7 +528,7 @@ user_group_button_cb (WButton * button, int action)
do do
{ {
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
Widget *wh = WIDGET (h); Widget *wh = WIDGET (h);
gboolean is_owner = (f_pos == BUTTONS_PERM - 2); gboolean is_owner = (f_pos == BUTTONS_PERM - 2);
@ -658,6 +658,7 @@ user_group_button_cb (WButton * button, int action)
static cb_ret_t static cb_ret_t
advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WGroup *g = GROUP (w);
WDialog *h = DIALOG (w); WDialog *h = DIALOG (w);
int i = 0; 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++) for (i = 0; i < 3; i++)
ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+'; ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+';
x_toggle ^= (1 << parm); x_toggle ^= (1 << parm);
update_mode (h); update_mode (g);
dlg_broadcast_msg (h, MSG_DRAW); dlg_broadcast_msg (h, MSG_DRAW);
break; break;
@ -701,7 +702,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+'; ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+';
x_toggle ^= (1 << parm); x_toggle ^= (1 << parm);
update_mode (h); update_mode (g);
dlg_broadcast_msg (h, MSG_DRAW); dlg_broadcast_msg (h, MSG_DRAW);
break; break;

View File

@ -355,7 +355,7 @@ sel_charset_button (WButton * button, int action)
cpname = _("7-bit ASCII"); /* FIXME */ cpname = _("7-bit ASCII"); /* FIXME */
button_set_text (button, cpname); button_set_text (button, cpname);
dlg_draw (WIDGET (button)->owner); dlg_draw (DIALOG (WIDGET (button)->owner));
} }
return 0; return 0;
@ -484,7 +484,7 @@ task_cb (WButton * button, int action)
jobs_fill_listbox (bg_list); jobs_fill_listbox (bg_list);
/* This can be optimized to just redraw this widget :-) */ /* This can be optimized to just redraw this widget :-) */
dlg_draw (WIDGET (button)->owner); dlg_draw (DIALOG (WIDGET (button)->owner));
return 0; return 0;
} }

View File

@ -411,7 +411,8 @@ overwrite_query_dialog (file_op_context_t * ctx, enum OperationMode mode)
#define ADD_LABEL(i) \ #define ADD_LABEL(i) \
add_widget_autopos (ui->replace_dlg, W(i), dlg_widgets[i].pos_flags, \ 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) \ #define NEW_BUTTON(i) \
W(i) = WIDGET (button_new (dlg_widgets[i].y, dlg_widgets[i].x, \ W(i) = WIDGET (button_new (dlg_widgets[i].y, dlg_widgets[i].x, \

View File

@ -523,9 +523,9 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
return MSG_HANDLED; return MSG_HANDLED;
case MSG_POST_KEY: case MSG_POST_KEY:
if (h->current->data == in_name) if (GROUP (h)->current->data == in_name)
find_toggle_enable_params (); 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); content_is_empty = input_is_empty (in_with);
find_toggle_enable_content (); find_toggle_enable_content ();
@ -1594,8 +1594,8 @@ start_stop (WButton * button, int action)
status_update (is_start ? _("Stopped") : _("Searching")); status_update (is_start ? _("Stopped") : _("Searching"));
button_set_text (button, fbuts[is_start ? 3 : 2].text); button_set_text (button, fbuts[is_start ? 3 : 2].text);
find_relocate_buttons (w->owner, FALSE); find_relocate_buttons (DIALOG (w->owner), FALSE);
dlg_draw (w->owner); dlg_draw (DIALOG (w->owner));
return 0; return 0;
} }

View File

@ -621,7 +621,7 @@ hotlist_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
static lcback_ret_t static lcback_ret_t
hotlist_listbox_callback (WListbox * list) hotlist_listbox_callback (WListbox * list)
{ {
WDialog *dlg = WIDGET (list)->owner; WDialog *dlg = DIALOG (WIDGET (list)->owner);
if (!listbox_is_empty (list)) if (!listbox_is_empty (list))
{ {

View File

@ -279,7 +279,7 @@ b_left_right_cback (WButton * button, int action)
panels_layout.left_panel_size--; panels_layout.left_panel_size--;
} }
update_split (WIDGET (button)->owner); update_split (DIALOG (WIDGET (button)->owner));
layout_change (); layout_change ();
do_refresh (); do_refresh ();
return 0; return 0;

View File

@ -3633,15 +3633,16 @@ static cb_ret_t
panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WPanel *panel = PANEL (w); WPanel *panel = PANEL (w);
WDialog *h = DIALOG (w->owner);
WButtonBar *bb; WButtonBar *bb;
switch (msg) switch (msg)
{ {
case MSG_INIT: case MSG_INIT:
/* subscribe to "history_load" event */ /* 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 */ /* 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; return MSG_HANDLED;
case MSG_DRAW: 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 (); update_xterm_title_path ();
select_item (panel); select_item (panel);
bb = find_buttonbar (w->owner); bb = find_buttonbar (h);
midnight_set_buttonbar (bb); midnight_set_buttonbar (bb);
widget_draw (WIDGET (bb)); widget_draw (WIDGET (bb));
return MSG_HANDLED; return MSG_HANDLED;
@ -3697,9 +3698,9 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
case MSG_DESTROY: case MSG_DESTROY:
vfs_stamp_path (panel->cwd_vpath); vfs_stamp_path (panel->cwd_vpath);
/* unsubscribe from "history_load" event */ /* 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 */ /* 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); panel_destroy (panel);
free_my_statfs (); free_my_statfs ();
return MSG_HANDLED; return MSG_HANDLED;

View File

@ -249,7 +249,7 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
else else
{ {
/* Show full name of selected directory */ /* 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_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));
tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols);
@ -265,7 +265,7 @@ static void
show_tree (WTree * tree) show_tree (WTree * tree)
{ {
Widget *w = WIDGET (tree); Widget *w = WIDGET (tree);
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
tree_entry *current; tree_entry *current;
int i, j; int i, j;
int topsublevel = 0; int topsublevel = 0;
@ -591,7 +591,7 @@ tree_chdir_sel (WTree * tree)
} }
else else
{ {
WDialog *h = WIDGET (tree)->owner; WDialog *h = DIALOG (WIDGET (tree)->owner);
h->ret_value = B_ENTER; h->ret_value = B_ENTER;
dlg_stop (h); dlg_stop (h);
@ -975,7 +975,7 @@ tree_toggle_navig (WTree * tree)
tree_navigation_flag = !tree_navigation_flag; tree_navigation_flag = !tree_navigation_flag;
b = find_buttonbar (WIDGET (tree)->owner); b = find_buttonbar (DIALOG (WIDGET (tree)->owner));
buttonbar_set_label (b, 4, buttonbar_set_label (b, 4,
tree_navigation_flag ? Q_ ("ButtonBar|Static") : Q_ ("ButtonBar|Dynamc"), tree_navigation_flag ? Q_ ("ButtonBar|Static") : Q_ ("ButtonBar|Dynamc"),
tree_map, WIDGET (tree)); tree_map, WIDGET (tree));
@ -1044,7 +1044,7 @@ tree_execute_cmd (WTree * tree, long command)
break; break;
case CK_Quit: case CK_Quit:
if (!tree->is_panel) if (!tree->is_panel)
dlg_stop (WIDGET (tree)->owner); dlg_stop (DIALOG (WIDGET (tree)->owner));
return res; return res;
default: default:
res = MSG_NOT_HANDLED; 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) tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{ {
WTree *tree = (WTree *) w; WTree *tree = (WTree *) w;
WDialog *h = w->owner; WDialog *h = DIALOG (w->owner);
WButtonBar *b; WButtonBar *b;
switch (msg) switch (msg)

View File

@ -138,7 +138,7 @@ learn_move (gboolean right)
totalcols = (learn_total - 1) / ROWS + 1; totalcols = (learn_total - 1) / ROWS + 1;
for (i = 0; i < learn_total; i++) 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) if (right)
{ {

View File

@ -577,7 +577,7 @@ mcview_execute_cmd (WView * view, long command)
break; break;
case CK_Quit: case CK_Quit:
if (!mcview_is_in_panel (view)) if (!mcview_is_in_panel (view))
dlg_stop (WIDGET (view)->owner); dlg_stop (DIALOG (WIDGET (view)->owner));
break; break;
case CK_Cancel: case CK_Cancel:
/* don't close viewer due to SIGINT */ /* don't close viewer due to SIGINT */

View File

@ -78,10 +78,11 @@ static enum ruler_type
static void static void
mcview_set_buttonbar (WView * view) mcview_set_buttonbar (WView * view)
{ {
WDialog *h = WIDGET (view)->owner; WDialog *h = DIALOG (WIDGET (view)->owner);
WButtonBar *b = find_buttonbar (h); WButtonBar *b;
const global_keymap_t *keymap = view->mode_flags.hex ? viewer_hex_map : viewer_map; 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)); buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, WIDGET (view));
if (view->mode_flags.hex) if (view->mode_flags.hex)
@ -204,7 +205,7 @@ mcview_update (WView * view)
{ {
view->dpy_bbar_dirty = FALSE; view->dpy_bbar_dirty = FALSE;
mcview_set_buttonbar (view); 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) if (view->dirty > dirt_limit)