Change WDialog::data from void* to union{void*, int}

...to use data of type other than pointer w/o extra type cast.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-02-23 11:53:17 +03:00
parent c5466cd494
commit 584fb9815c
4 changed files with 13 additions and 7 deletions

View File

@ -427,7 +427,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
new_d->colors = colors;
new_d->help_ctx = help_ctx;
new_d->compact = compact;
new_d->data = NULL;
new_d->data.p = NULL;
if (modal)
{

View File

@ -69,10 +69,16 @@ struct WDialog
int ret_value; /* Result of dlg_run() */
/* Internal variables */
void *data; /* Data can be passed to dialog */
char *event_group; /* Name of event group for this dialog */
Widget *bg; /* WFrame or WBackground */
/* Data can be passed to dialog */
union
{
void *p;
int i;
} data;
dlg_shortcut_str get_shortcut; /* Shortcut string */
dlg_title_str get_title; /* useless for modal dialogs */
};

View File

@ -73,10 +73,10 @@ history_dlg_reposition (WDialog * dlg_head)
WRect r;
/* guard checks */
if ((dlg_head == NULL) || (dlg_head->data == NULL))
if (dlg_head == NULL || dlg_head->data.p == NULL)
return MSG_NOT_HANDLED;
data = (history_dlg_data *) dlg_head->data;
data = (history_dlg_data *) dlg_head->data.p;
y = data->y;
he = data->count + 2;
@ -227,7 +227,7 @@ history_show (history_descriptor_t * hd)
query_dlg =
dlg_create (TRUE, 0, 0, 4, 4, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, history_dlg_callback,
NULL, "[History-query]", _("History"));
query_dlg->data = &hist_data;
query_dlg->data.p = &hist_data;
/* this call makes list stick to all sides of dialog, effectively make
it be resized with dialog */

View File

@ -189,7 +189,7 @@ skin_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
case MSG_RESIZE:
{
WDialog *d = DIALOG (w);
const WRect *wd = &WIDGET (d->data)->rect;
const WRect *wd = &WIDGET (d->data.p)->rect;
WRect r = w->rect;
r.y = wd->y + (wd->lines - r.lines) / 2;
@ -221,7 +221,7 @@ sel_skin_button (WButton * button, int action)
dlg_create (TRUE, 0, 0, 13, 24, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, skin_dlg_callback,
NULL, "[Appearance]", _("Skins"));
/* use Appearance dialog for positioning */
skin_dlg->data = WIDGET (button)->owner;
skin_dlg->data.p = WIDGET (button)->owner;
/* set dialog location before all */
send_message (skin_dlg, NULL, MSG_RESIZE, 0, NULL);