From 05d7f3c84e394fc95d9a269065acf75a8629f08f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 20 Jun 2012 15:09:44 +0400 Subject: [PATCH] Aggressive use WIDGET macro. Signed-off-by: Andrew Borodin --- lib/widget/button.c | 21 ++++---- lib/widget/buttonbar.c | 26 +++++----- lib/widget/buttonbar.h | 2 +- lib/widget/check.c | 16 +++--- lib/widget/dialog-switch.c | 2 +- lib/widget/dialog.c | 48 +++++++++--------- lib/widget/dialog.h | 5 +- lib/widget/gauge.c | 16 +++--- lib/widget/groupbox.c | 8 +-- lib/widget/hline.c | 14 +++--- lib/widget/input.c | 36 +++++++------- lib/widget/input_complete.c | 8 +-- lib/widget/label.c | 34 +++++++------ lib/widget/listbox.c | 62 +++++++++++++---------- lib/widget/menu.c | 74 +++++++++++++++------------- lib/widget/quick.c | 27 +++++----- lib/widget/radio.c | 23 +++++---- lib/widget/widget-common.h | 2 +- src/diffviewer/ydiff.c | 39 ++++++++------- src/editor/edit.c | 51 ++++++++++--------- src/editor/editcmd.c | 10 ++-- src/editor/editcmd_dialogs.c | 4 +- src/editor/editdraw.c | 67 +++++++++++++------------ src/editor/editoptions.c | 2 +- src/editor/editwidget.c | 76 ++++++++++++++-------------- src/filemanager/achown.c | 6 +-- src/filemanager/boxes.c | 24 ++++----- src/filemanager/chmod.c | 6 +-- src/filemanager/cmd.c | 2 +- src/filemanager/command.c | 2 +- src/filemanager/find.c | 54 ++++++++++---------- src/filemanager/hotlist.c | 2 +- src/filemanager/info.c | 70 +++++++++++++------------- src/filemanager/layout.c | 68 ++++++++++++------------- src/filemanager/midnight.c | 34 ++++++------- src/filemanager/option.c | 4 +- src/filemanager/panel.c | 115 +++++++++++++++++++++++-------------------- src/filemanager/tree.c | 78 ++++++++++++++++------------- src/help.c | 12 ++--- src/learn.c | 10 ++-- src/viewer/actions_cmd.c | 10 ++-- src/viewer/display.c | 50 ++++++++++--------- src/viewer/lib.c | 4 +- src/viewer/mcviewer.c | 9 ++-- src/viewer/move.c | 2 +- 45 files changed, 654 insertions(+), 581 deletions(-) diff --git a/lib/widget/button.c b/lib/widget/button.c index da3ba03ed..39218831d 100644 --- a/lib/widget/button.c +++ b/lib/widget/button.c @@ -60,7 +60,7 @@ button_callback (Widget * w, widget_msg_t msg, int parm) WButton *b = (WButton *) w; int stop = 0; int off = 0; - Dlg_head *h = b->widget.owner; + Dlg_head *h = w->owner; switch (msg) { @@ -71,7 +71,7 @@ button_callback (Widget * w, 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 == &b->widget) + if (parm == '\n' && WIDGET (h->current->data) == WIDGET (b)) { button_callback (w, WIDGET_KEY, ' '); return MSG_HANDLED; @@ -120,7 +120,7 @@ button_callback (Widget * w, widget_msg_t msg, int parm) off = 0; break; } - widget_move (&b->widget, 0, b->hotpos + off); + widget_move (w, 0, b->hotpos + off); return MSG_HANDLED; case WIDGET_UNFOCUS: @@ -182,7 +182,7 @@ button_callback (Widget * w, widget_msg_t msg, int parm) static int button_event (Gpm_Event * event, void *data) { - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -208,17 +208,18 @@ WButton * button_new (int y, int x, int action, button_flags_t flags, const char *text, bcback_fn callback) { WButton *b; + Widget *w; b = g_new (WButton, 1); + w = WIDGET (b); + b->action = action; b->flags = flags; b->text = parse_hotkey (text); - - init_widget (&b->widget, y, x, 1, button_get_len (b), button_callback, button_event); - + init_widget (w, y, x, 1, button_get_len (b), button_callback, button_event); b->selected = FALSE; b->callback = callback; - widget_want_hotkey (b->widget, TRUE); + widget_want_hotkey (w, TRUE); b->hotpos = (b->text.hotkey != NULL) ? str_term_width1 (b->text.start) : -1; return b; @@ -241,8 +242,8 @@ button_set_text (WButton * b, const char *text) { release_hotkey (b->text); b->text = parse_hotkey (text); - b->widget.cols = button_get_len (b); - dlg_redraw (b->widget.owner); + WIDGET (b)->cols = button_get_len (b); + dlg_redraw (WIDGET (b)->owner); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/buttonbar.c b/lib/widget/buttonbar.c index 879781df4..55fb4b17b 100644 --- a/lib/widget/buttonbar.c +++ b/lib/widget/buttonbar.c @@ -148,11 +148,11 @@ static gboolean buttonbar_call (WButtonBar * bb, int i) { cb_ret_t ret = MSG_NOT_HANDLED; + Widget *w = WIDGET (bb); if ((bb != NULL) && (bb->labels[i].command != CK_IgnoreKey)) - ret = bb->widget.owner->callback (bb->widget.owner, - (Widget *) bb, DLG_ACTION, - bb->labels[i].command, bb->labels[i].receiver); + ret = w->owner->callback (w->owner, w, DLG_ACTION, + bb->labels[i].command, bb->labels[i].receiver); return ret; } @@ -180,10 +180,10 @@ buttonbar_callback (Widget * w, widget_msg_t msg, int parm) if (bb->visible) { buttonbar_init_button_positions (bb); - widget_move (&bb->widget, 0, 0); + widget_move (w, 0, 0); tty_setcolor (DEFAULT_COLOR); - tty_printf ("%-*s", bb->widget.cols, ""); - widget_move (&bb->widget, 0, 0); + tty_printf ("%-*s", w->cols, ""); + widget_move (w, 0, 0); for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) { @@ -218,7 +218,7 @@ buttonbar_callback (Widget * w, widget_msg_t msg, int parm) static int buttonbar_event (Gpm_Event * event, void *data) { - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -246,14 +246,16 @@ WButtonBar * buttonbar_new (gboolean visible) { WButtonBar *bb; + Widget *w; bb = g_new0 (WButtonBar, 1); + w = WIDGET (bb); + init_widget (w, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); - init_widget (&bb->widget, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); - bb->widget.pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; + w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; bb->visible = visible; - widget_want_hotkey (bb->widget, 1); - widget_want_cursor (bb->widget, 0); + widget_want_hotkey (w, TRUE); + widget_want_cursor (w, FALSE); return bb; } @@ -277,7 +279,7 @@ buttonbar_set_label (WButtonBar * bb, int idx, const char *text, set_label_text (bb, idx, text); bb->labels[idx - 1].command = command; - bb->labels[idx - 1].receiver = (Widget *) receiver; + bb->labels[idx - 1].receiver = WIDGET (receiver); } } diff --git a/lib/widget/buttonbar.h b/lib/widget/buttonbar.h index e64fdb3be..821783956 100644 --- a/lib/widget/buttonbar.h +++ b/lib/widget/buttonbar.h @@ -49,7 +49,7 @@ static inline void buttonbar_redraw (WButtonBar * bb) { if (bb != NULL) - send_message ((Widget *) bb, WIDGET_DRAW, 0); + send_message (WIDGET (bb), WIDGET_DRAW, 0); } static inline void diff --git a/lib/widget/check.c b/lib/widget/check.c index 95bf167c4..6e57548ec 100644 --- a/lib/widget/check.c +++ b/lib/widget/check.c @@ -57,7 +57,7 @@ static cb_ret_t check_callback (Widget * w, widget_msg_t msg, int parm) { WCheck *c = (WCheck *) w; - Dlg_head *h = c->widget.owner; + Dlg_head *h = w->owner; switch (msg) { @@ -82,14 +82,14 @@ check_callback (Widget * w, widget_msg_t msg, int parm) return MSG_HANDLED; case WIDGET_CURSOR: - widget_move (&c->widget, 0, 1); + widget_move (c, 0, 1); return MSG_HANDLED; case WIDGET_FOCUS: case WIDGET_UNFOCUS: case WIDGET_DRAW: widget_selectcolor (w, msg == WIDGET_FOCUS, FALSE); - widget_move (&c->widget, 0, 0); + widget_move (c, 0, 0); tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] "); hotkey_draw (w, c->text, msg == WIDGET_FOCUS); return MSG_HANDLED; @@ -108,7 +108,7 @@ check_callback (Widget * w, widget_msg_t msg, int parm) static int check_event (Gpm_Event * event, void *data) { - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -135,13 +135,17 @@ WCheck * check_new (int y, int x, int state, const char *text) { WCheck *c; + Widget *w; c = g_new (WCheck, 1); + w = WIDGET (c); c->text = parse_hotkey (text); - init_widget (&c->widget, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event); + init_widget (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event); /* 4 is width of "[X] " */ c->state = state ? C_BOOL : 0; - widget_want_hotkey (c->widget, TRUE); + widget_want_hotkey (w, TRUE); return c; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c index becc9ebdf..4e2f31b42 100644 --- a/lib/widget/dialog-switch.c +++ b/lib/widget/dialog-switch.c @@ -246,7 +246,7 @@ dialog_switch_list (void) dlg = (Dlg_head *) h->data; if ((dlg != NULL) && (dlg->get_title != NULL)) - title = dlg->get_title (dlg, listbox->list->widget.cols - 2); /* FIXME! */ + title = dlg->get_title (dlg, WIDGET (listbox->list)->cols - 2); else title = g_strdup (""); diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index a6c5870d7..54f1aae24 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -137,7 +137,7 @@ dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t msg, gboolean reverse, int flag do { - Widget *w = (Widget *) p->data; + Widget *w = WIDGET (p->data); if (reverse) p = dlg_widget_prev (h, p); @@ -183,7 +183,7 @@ dlg_unfocus (Dlg_head * h) /* we can unfocus disabled widget */ if ((h->current != NULL) && (h->state == DLG_CONSTRUCT || h->state == DLG_ACTIVE)) { - Widget *current = (Widget *) h->current->data; + Widget *current = WIDGET (h->current->data); if (send_message (current, WIDGET_UNFOCUS, 0) == MSG_HANDLED) { @@ -215,7 +215,7 @@ dlg_find_widget_callback (const void *a, const void *b) static void do_select_widget (Dlg_head * h, GList * w, select_dir_t dir) { - Widget *w0 = (Widget *) h->current->data; + Widget *w0 = WIDGET (h->current->data); if (!dlg_unfocus (h)) return; @@ -244,12 +244,12 @@ do_select_widget (Dlg_head * h, GList * w, select_dir_t dir) break; } } - while (h->current != w /* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */ ); + while (h->current != w /* && (WIDGET (h->current->data)->options & W_DISABLED) == 0 */ ); - if (dlg_overlap (w0, (Widget *) h->current->data)) + if (dlg_overlap (w0, WIDGET (h->current->data))) { - send_message ((Widget *) h->current->data, WIDGET_DRAW, 0); - send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0); + send_message (WIDGET (h->current->data), WIDGET_DRAW, 0); + send_message (WIDGET (h->current->data), WIDGET_FOCUS, 0); } } @@ -387,7 +387,7 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event) item = starting_widget; do { - Widget *widget = (Widget *) item->data; + Widget *widget = WIDGET (item->data); if ((h->flags & DLG_REVERSE) == 0) item = dlg_widget_prev (h, item); @@ -430,7 +430,7 @@ dlg_try_hotkey (Dlg_head * h, int d_key) * the currently selected widget is an input line */ - current = (Widget *) h->current->data; + current = WIDGET (h->current->data); if ((current->options & W_DISABLED) != 0) return MSG_NOT_HANDLED; @@ -461,7 +461,7 @@ dlg_try_hotkey (Dlg_head * h, int d_key) /* send it to all widgets */ while (h->current != hot_cur && handled == MSG_NOT_HANDLED) { - current = (Widget *) hot_cur->data; + current = WIDGET (hot_cur->data); if ((current->options & W_WANT_HOTKEY) != 0 && (current->options & W_DISABLED) == 0) handled = send_message (current, WIDGET_HOTKEY, d_key); @@ -515,7 +515,7 @@ dlg_key_event (Dlg_head * h, int d_key) h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL); else /* not used - then try widget_callback */ - handled = send_message ((Widget *) h->current->data, WIDGET_KEY, d_key); + handled = send_message (WIDGET (h->current->data), WIDGET_KEY, d_key); /* not used- try to use the unhandled case */ if (handled == MSG_NOT_HANDLED) @@ -580,7 +580,7 @@ frontend_run_dlg (Dlg_head * h) static int dlg_find_widget_by_id (gconstpointer a, gconstpointer b) { - Widget *w = (Widget *) a; + Widget *w = WIDGET (a); unsigned long id = GPOINTER_TO_UINT (b); return w->id == id ? 0 : 1; @@ -677,7 +677,7 @@ dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2) 2. control sticks to two sides of one direction - it should be sized */ - Widget *c = (Widget *) w->data; + Widget *c = WIDGET (w->data); int x = c->x; int y = c->y; int cols = c->cols; @@ -782,7 +782,7 @@ create_dlg (gboolean modal, int y1, int x1, int lines, int cols, new_d = g_new0 (Dlg_head, 1); w = WIDGET (new_d); init_widget (w, y1, x1, lines, cols, NULL, mouse_handler); - widget_want_cursor (*w, FALSE); + widget_want_cursor (w, FALSE); new_d->state = DLG_CONSTRUCT; new_d->modal = modal; @@ -865,7 +865,7 @@ set_idle_proc (Dlg_head * d, int enable) unsigned long add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags, const void *before) { - Widget *widget = (Widget *) w; + Widget *widget = WIDGET (w); /* Don't accept 0 widgets */ if (w == NULL) @@ -959,7 +959,7 @@ add_widget_before (Dlg_head * h, void *w, void *before) void del_widget (void *w) { - Dlg_head *h = ((Widget *) w)->owner; + Dlg_head *h = WIDGET (w)->owner; GList *d; /* Don't accept NULL widget. This shouldn't happen */ @@ -1029,7 +1029,7 @@ dlg_focus (Dlg_head * h) /* cannot focus disabled widget */ if ((h->current != NULL) && (h->state == DLG_CONSTRUCT || h->state == DLG_ACTIVE)) { - Widget *current = (Widget *) h->current->data; + Widget *current = WIDGET (h->current->data); if (((current->options & W_DISABLED) == 0) && (send_message (current, WIDGET_FOCUS, 0) == MSG_HANDLED)) @@ -1063,7 +1063,7 @@ find_widget_type (const Dlg_head * h, callback_fn callback) w = g_list_find_custom (h->widgets, callback, dlg_find_widget_callback); - return (w == NULL) ? NULL : (Widget *) w->data; + return (w == NULL) ? NULL : WIDGET (w->data); } /* --------------------------------------------------------------------------------------------- */ @@ -1075,7 +1075,7 @@ dlg_find_by_id (const Dlg_head * h, unsigned long id) GList *w; w = g_list_find_custom (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; } /* --------------------------------------------------------------------------------------------- */ @@ -1099,7 +1099,7 @@ dlg_select_by_id (const Dlg_head * h, unsigned long id) void dlg_select_widget (void *w) { - const Widget *widget = (Widget *) w; + Widget *widget = WIDGET (w); Dlg_head *h = widget->owner; do_select_widget (h, g_list_find (h->widgets, widget), SELECT_EXACT); @@ -1114,7 +1114,7 @@ dlg_select_widget (void *w) void dlg_set_top_widget (void *w) { - Widget *widget = (Widget *) w; + Widget *widget = WIDGET (w); Dlg_head *h = widget->owner; GList *l; @@ -1166,7 +1166,7 @@ update_cursor (Dlg_head * h) { Widget *w; - w = (Widget *) p->data; + w = WIDGET (p->data); if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0)) send_message (w, WIDGET_CURSOR, 0); @@ -1177,7 +1177,7 @@ update_cursor (Dlg_head * h) if (p == h->current) break; - w = (Widget *) p->data; + w = WIDGET (p->data); if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0)) if (send_message (w, WIDGET_CURSOR, 0) == MSG_HANDLED) @@ -1282,7 +1282,7 @@ dlg_run_done (Dlg_head * h) if (h->state == DLG_CLOSED) { - h->callback (h, (Widget *) h->current->data, DLG_END, 0, NULL); + h->callback (h, WIDGET (h->current->data), DLG_END, 0, NULL); if (!h->modal) dialog_switch_remove (h); } diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h index bbdd20d78..a137701c2 100644 --- a/lib/widget/dialog.h +++ b/lib/widget/dialog.h @@ -219,8 +219,7 @@ void update_cursor (Dlg_head * h); static inline gboolean dlg_widget_active (void *w) { - Widget *w1 = (Widget *) w; - return ((Widget *) w1->owner->current->data == w1); + return (w == WIDGET (w)->owner->current->data); } /* --------------------------------------------------------------------------------------------- */ @@ -228,7 +227,7 @@ dlg_widget_active (void *w) static inline unsigned long dlg_get_current_widget_id (const struct Dlg_head *h) { - return ((Widget *) h->current->data)->id; + return WIDGET (h->current->data)->id; } #endif /* MC__DIALOG_H */ diff --git a/lib/widget/gauge.c b/lib/widget/gauge.c index f9c302a7b..9d865de3a 100644 --- a/lib/widget/gauge.c +++ b/lib/widget/gauge.c @@ -62,7 +62,7 @@ static cb_ret_t gauge_callback (Widget * w, widget_msg_t msg, int parm) { WGauge *g = (WGauge *) w; - Dlg_head *h = g->widget.owner; + Dlg_head *h = w->owner; if (msg == WIDGET_INIT) return MSG_HANDLED; @@ -73,7 +73,7 @@ gauge_callback (Widget * w, widget_msg_t msg, int parm) if (msg == WIDGET_DRAW) { - widget_move (&g->widget, 0, 0); + widget_move (w, 0, 0); tty_setcolor (h->color[DLG_COLOR_NORMAL]); if (!g->shown) tty_printf ("%*s", gauge_len, ""); @@ -129,9 +129,11 @@ WGauge * gauge_new (int y, int x, gboolean shown, int max, int current) { WGauge *g; + Widget *w; g = g_new (WGauge, 1); - init_widget (&g->widget, y, x, 1, gauge_len, gauge_callback, NULL); + w = WIDGET (g); + init_widget (w, y, x, 1, gauge_len, gauge_callback, NULL); g->shown = shown; if (max == 0) @@ -140,8 +142,8 @@ gauge_new (int y, int x, gboolean shown, int max, int current) g->current = current; g->from_left_to_right = TRUE; - widget_want_cursor (g->widget, FALSE); - widget_want_hotkey (g->widget, FALSE); + widget_want_cursor (w, FALSE); + widget_want_hotkey (w, FALSE); return g; } @@ -158,7 +160,7 @@ gauge_set_value (WGauge * g, int max, int current) max = 1; /* I do not like division by zero :) */ g->current = current; g->max = max; - gauge_callback ((Widget *) g, WIDGET_DRAW, 0); + gauge_callback (WIDGET (g), WIDGET_DRAW, 0); } /* --------------------------------------------------------------------------------------------- */ @@ -169,7 +171,7 @@ gauge_show (WGauge * g, gboolean shown) if (g->shown != shown) { g->shown = shown; - gauge_callback ((Widget *) g, WIDGET_DRAW, 0); + gauge_callback (WIDGET (g), WIDGET_DRAW, 0); } } diff --git a/lib/widget/groupbox.c b/lib/widget/groupbox.c index ced9004d6..47079f0b0 100644 --- a/lib/widget/groupbox.c +++ b/lib/widget/groupbox.c @@ -99,12 +99,14 @@ WGroupbox * groupbox_new (int y, int x, int height, int width, const char *title) { WGroupbox *g; + Widget *w; g = g_new (WGroupbox, 1); - init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL); + w = WIDGET (g); + init_widget (w, y, x, height, width, groupbox_callback, NULL); - widget_want_cursor (g->widget, FALSE); - widget_want_hotkey (g->widget, FALSE); + widget_want_cursor (w, FALSE); + widget_want_hotkey (w, FALSE); /* Strip existing spaces, add one space before and after the title */ if (title != NULL) diff --git a/lib/widget/hline.c b/lib/widget/hline.c index 5d2551b60..2d61f3f19 100644 --- a/lib/widget/hline.c +++ b/lib/widget/hline.c @@ -57,7 +57,7 @@ static cb_ret_t hline_callback (Widget * w, widget_msg_t msg, int parm) { WHLine *l = (WHLine *) w; - Dlg_head *h = l->widget.owner; + Dlg_head *h = w->owner; switch (msg) { @@ -65,9 +65,9 @@ hline_callback (Widget * w, widget_msg_t msg, int parm) case WIDGET_RESIZED: if (l->auto_adjust_cols) { - Widget *wo = WIDGET (w->owner); + Widget *wo = WIDGET (h); - if (((w->owner->flags & DLG_COMPACT) != 0)) + if (((h->flags & DLG_COMPACT) != 0)) { w->x = wo->x; w->cols = wo->cols; @@ -113,14 +113,16 @@ WHLine * hline_new (int y, int x, int width) { WHLine *l; + Widget *w; int lines = 1; l = g_new (WHLine, 1); - init_widget (&l->widget, y, x, lines, width, hline_callback, NULL); + w = WIDGET (l); + init_widget (w, y, x, lines, width, hline_callback, NULL); l->auto_adjust_cols = (width < 0); l->transparent = FALSE; - widget_want_cursor (l->widget, FALSE); - widget_want_hotkey (l->widget, FALSE); + widget_want_cursor (w, FALSE); + widget_want_hotkey (w, FALSE); return l; } diff --git a/lib/widget/input.c b/lib/widget/input.c index 9624c4e38..3a6e880d3 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -73,7 +73,7 @@ const global_keymap_t *input_map = NULL; #define should_show_history_button(in) \ (in->history != NULL && in->field_width > HISTORY_BUTTON_WIDTH * 2 + 1 \ - && in->widget.owner != NULL) + && WIDGET (in)->owner != NULL) /*** file scope type declarations ****************************************************************/ @@ -103,7 +103,7 @@ static void draw_history_button (WInput * in) { char c; - gboolean disabled = (((Widget *) in)->options & W_DISABLED) != 0; + gboolean disabled = (WIDGET (in)->options & W_DISABLED) != 0; if (g_list_next (in->history_current) == NULL) c = '^'; @@ -112,12 +112,12 @@ draw_history_button (WInput * in) else c = '|'; - widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH); + widget_move (in, 0, in->field_width - HISTORY_BUTTON_WIDTH); tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]); #ifdef LARGE_HISTORY_BUTTON tty_print_string ("[ ]"); - widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1); + widget_move (in, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1); #endif tty_print_char (c); @@ -195,8 +195,7 @@ do_show_hist (WInput * in) len = get_history_length (in->history); - r = history_show (&in->history, &in->widget, - g_list_position (in->history_current, in->history)); + r = history_show (&in->history, WIDGET (in), g_list_position (in->history_current, in->history)); if (r != NULL) { input_assign_text (in, r); @@ -880,7 +879,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 && (WIDGET (in)->owner->ret_value != B_CANCEL)) { ev_history_load_save_t *ev = (ev_history_load_save_t *) data; @@ -930,7 +929,7 @@ static int input_event (Gpm_Event * event, void *data) { WInput *in = (WInput *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -991,10 +990,12 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex const char *histname, input_complete_t completion_flags) { WInput *in; + Widget *w; in = g_new (WInput, 1); - init_widget (&in->widget, y, x, 1, width, input_callback, input_event); - in->widget.options |= W_IS_INPUT; + w = WIDGET (in); + init_widget (w, y, x, 1, width, input_callback, input_event); + w->options |= W_IS_INPUT; memmove (in->color, input_colors, sizeof (input_colors_t)); @@ -1084,8 +1085,7 @@ input_callback (Widget * w, widget_msg_t msg, int parm) return MSG_HANDLED; case WIDGET_CURSOR: - widget_move (&in->widget, 0, str_term_width2 (in->buffer, in->point) - - in->term_first_shown); + widget_move (in, 0, str_term_width2 (in->buffer, in->point) - in->term_first_shown); return MSG_HANDLED; case WIDGET_DESTROY: @@ -1124,8 +1124,8 @@ input_get_default_colors (void) void input_set_origin (WInput * in, int x, int field_width) { - in->widget.x = x; - in->field_width = in->widget.cols = field_width; + WIDGET (in)->x = x; + in->field_width = WIDGET (in)->cols = field_width; input_update (in, FALSE); } @@ -1271,14 +1271,14 @@ input_update (WInput * in, gboolean clear_first) if (has_history != 0) draw_history_button (in); - if ((((Widget *) in)->options & W_DISABLED) != 0) + if ((WIDGET (in)->options & W_DISABLED) != 0) tty_setcolor (DISABLED_COLOR); else if (in->first) tty_setcolor (in->color[WINPUTC_UNCHANGED]); else tty_setcolor (in->color[WINPUTC_MAIN]); - widget_move (&in->widget, 0, 0); + widget_move (in, 0, 0); if (!in->is_password) { @@ -1298,7 +1298,7 @@ input_update (WInput * in, gboolean clear_first) tty_setcolor (in->color[WINPUTC_MARK]); if (m1 < in->term_first_shown) { - widget_move (&in->widget, 0, 0); + widget_move (in, 0, 0); tty_print_string (str_term_substring (in->buffer, in->term_first_shown, m2 - in->term_first_shown)); @@ -1307,7 +1307,7 @@ input_update (WInput * in, gboolean clear_first) { int sel_width; - widget_move (&in->widget, 0, m1 - in->term_first_shown); + widget_move (in, 0, m1 - in->term_first_shown); sel_width = min (m2 - m1, (in->field_width - has_history) - (str_term_width2 (in->buffer, m1) - diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index d3be3f1e4..134dbdb89 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -1100,7 +1100,7 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da listbox_select_entry ((WListbox *) h->current->data, i); end = new_end; input_handle_char (input, parm); - send_message ((Widget *) h->current->data, WIDGET_DRAW, 0); + send_message (WIDGET (h->current->data), WIDGET_DRAW, 0); break; } } @@ -1203,7 +1203,7 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da if (need_redraw == 2) { insert_text (input, last_text, low); - send_message ((Widget *) h->current->data, WIDGET_DRAW, 0); + send_message (WIDGET (h->current->data), WIDGET_DRAW, 0); } else if (need_redraw == 1) { @@ -1290,8 +1290,8 @@ complete_engine (WInput * in, int what_to_do) if (i > maxlen) maxlen = i; } - start_x = in->widget.x; - start_y = in->widget.y; + start_x = WIDGET (in)->x; + start_y = WIDGET (in)->y; if (start_y - 2 >= count) { y = start_y - 2 - count; diff --git a/lib/widget/label.c b/lib/widget/label.c index f26a7050a..14506f35c 100644 --- a/lib/widget/label.c +++ b/lib/widget/label.c @@ -60,7 +60,7 @@ static cb_ret_t label_callback (Widget * w, widget_msg_t msg, int parm) { WLabel *l = (WLabel *) w; - Dlg_head *h = l->widget.owner; + Dlg_head *h = w->owner; switch (msg) { @@ -97,8 +97,8 @@ label_callback (Widget * w, widget_msg_t msg, int parm) q[0] = '\0'; } - widget_move (&l->widget, y, 0); - tty_print_string (str_fit_to_term (p, l->widget.cols, J_LEFT)); + widget_move (w, y, 0); + tty_print_string (str_fit_to_term (p, w->cols, J_LEFT)); if (q == NULL) break; @@ -127,6 +127,7 @@ WLabel * label_new (int y, int x, const char *text) { WLabel *l; + Widget *w; int cols = 1; int lines = 1; @@ -134,12 +135,14 @@ label_new (int y, int x, const char *text) str_msg_term_size (text, &lines, &cols); l = g_new (WLabel, 1); - init_widget (&l->widget, y, x, lines, cols, label_callback, NULL); + w = WIDGET (l); + init_widget (w, y, x, lines, cols, label_callback, NULL); + l->text = g_strdup (text); l->auto_adjust_cols = TRUE; l->transparent = FALSE; - widget_want_cursor (l->widget, FALSE); - widget_want_hotkey (l->widget, FALSE); + widget_want_cursor (w, FALSE); + widget_want_hotkey (w, FALSE); return l; } @@ -149,7 +152,8 @@ label_new (int y, int x, const char *text) void label_set_text (WLabel * label, const char *text) { - int newcols = label->widget.cols; + Widget *w = WIDGET (label); + int newcols = w->cols; int newlines; if (label->text != NULL && text != NULL && strcmp (label->text, text) == 0) @@ -165,18 +169,18 @@ label_set_text (WLabel * label, const char *text) if (label->auto_adjust_cols) { str_msg_term_size (text, &newlines, &newcols); - if (newcols > label->widget.cols) - label->widget.cols = newcols; - if (newlines > label->widget.lines) - label->widget.lines = newlines; + if (newcols > w->cols) + w->cols = newcols; + if (newlines > w->lines) + w->lines = newlines; } } - if (label->widget.owner != NULL) - label_callback ((Widget *) label, WIDGET_DRAW, 0); + if (w->owner != NULL) + label_callback (w, WIDGET_DRAW, 0); - if (newcols < label->widget.cols) - label->widget.cols = newcols; + if (newcols < w->cols) + w->cols = newcols; } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 3e475ef43..10a28217a 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -83,31 +83,32 @@ listbox_entry_free (void *data) static void listbox_drawscroll (WListbox * l) { - const int max_line = l->widget.lines - 1; + Widget *w = WIDGET (l); + int max_line = w->lines - 1; int line = 0; int i; /* Are we at the top? */ - widget_move (&l->widget, 0, l->widget.cols); + widget_move (w, 0, w->cols); if (l->top == 0) tty_print_one_vline (TRUE); else tty_print_char ('^'); /* Are we at the bottom? */ - widget_move (&l->widget, max_line, l->widget.cols); - if ((l->top + l->widget.lines == l->count) || (l->widget.lines >= l->count)) + widget_move (w, max_line, w->cols); + if ((l->top + w->lines == l->count) || (w->lines >= l->count)) tty_print_one_vline (TRUE); else tty_print_char ('v'); /* Now draw the nice relative pointer */ if (l->count != 0) - line = 1 + ((l->pos * (l->widget.lines - 2)) / l->count); + line = 1 + ((l->pos * (w->lines - 2)) / l->count); for (i = 1; i < max_line; i++) { - widget_move (&l->widget, i, l->widget.cols); + widget_move (w, i, w->cols); if (i != line) tty_print_one_vline (TRUE); else @@ -120,8 +121,9 @@ listbox_drawscroll (WListbox * l) static void listbox_draw (WListbox * l, gboolean focused) { - const Dlg_head *h = l->widget.owner; - const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0; + Widget *w = WIDGET (l); + const Dlg_head *h = w->owner; + const gboolean disabled = (w->options & W_DISABLED) != 0; const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; /* *INDENT-OFF* */ int selc = disabled @@ -140,7 +142,7 @@ listbox_draw (WListbox * l, gboolean focused) /* pos = (le == NULL) ? 0 : g_list_position (l->list, le); */ pos = (le == NULL) ? 0 : l->top; - for (i = 0; i < l->widget.lines; i++) + for (i = 0; i < w->lines; i++) { const char *text; @@ -153,7 +155,7 @@ listbox_draw (WListbox * l, gboolean focused) else tty_setcolor (normalc); - widget_move (&l->widget, i, 1); + widget_move (l, i, 1); if ((i > 0 && pos >= l->count) || (l->list == NULL) || (le == NULL)) text = ""; @@ -165,12 +167,12 @@ listbox_draw (WListbox * l, gboolean focused) pos++; } - tty_print_string (str_fit_to_term (text, l->widget.cols - 2, J_LEFT_FIT)); + tty_print_string (str_fit_to_term (text, w->cols - 2, J_LEFT_FIT)); } l->cursor_y = sel_line; - if (l->scrollbar && (l->count > l->widget.lines)) + if (l->scrollbar && (l->count > w->lines)) { tty_setcolor (normalc); listbox_drawscroll (l); @@ -239,6 +241,7 @@ listbox_execute_cmd (WListbox * l, unsigned long command) { cb_ret_t ret = MSG_HANDLED; int i; + Widget *w = WIDGET (l); switch (command) { @@ -255,18 +258,18 @@ listbox_execute_cmd (WListbox * l, unsigned long command) listbox_select_last (l); break; case CK_PageUp: - for (i = 0; (i < l->widget.lines - 1) && (l->pos > 0); i++) + for (i = 0; (i < w->lines - 1) && (l->pos > 0); i++) listbox_back (l); break; case CK_PageDown: - for (i = 0; (i < l->widget.lines - 1) && (l->pos < l->count - 1); i++) + for (i = 0; (i < w->lines - 1) && (l->pos < l->count - 1); i++) listbox_fwd (l); break; case CK_Delete: if (l->deletable) { gboolean is_last = (l->pos + 1 >= l->count); - gboolean is_more = (l->top + l->widget.lines >= l->count); + gboolean is_more = (l->top + w->lines >= l->count); listbox_remove_current (l); if ((l->top > 0) && (is_last || is_more)) @@ -306,7 +309,7 @@ listbox_key (WListbox * l, int key) listbox_select_entry (l, key - '0'); /* need scroll to item? */ - if (abs (oldpos - l->pos) > l->widget.lines) + if (abs (oldpos - l->pos) > WIDGET (l)->lines) l->top = l->pos; return MSG_HANDLED; @@ -365,7 +368,7 @@ static cb_ret_t listbox_callback (Widget * w, widget_msg_t msg, int parm) { WListbox *l = (WListbox *) w; - Dlg_head *h = l->widget.owner; + Dlg_head *h = w->owner; cb_ret_t ret_code; switch (msg) @@ -411,7 +414,7 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm) return listbox_execute_cmd (l, parm); case WIDGET_CURSOR: - widget_move (&l->widget, l->cursor_y, 0); + widget_move (l, l->cursor_y, 0); h->callback (h, w, DLG_ACTION, l->pos, NULL); return MSG_HANDLED; @@ -439,7 +442,7 @@ static int listbox_event (Gpm_Event * event, void *data) { WListbox *l = (WListbox *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -516,12 +519,14 @@ WListbox * listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback) { WListbox *l; + Widget *w; if (height <= 0) height = 1; l = g_new (WListbox, 1); - init_widget (&l->widget, y, x, height, width, listbox_callback, listbox_event); + w = WIDGET (l); + init_widget (w, y, x, height, width, listbox_callback, listbox_event); l->list = NULL; l->top = l->pos = 0; @@ -530,8 +535,8 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn l->callback = callback; l->allow_duplicates = TRUE; l->scrollbar = !mc_global.tty.slow_terminal; - widget_want_hotkey (l->widget, TRUE); - widget_want_cursor (l->widget, FALSE); + widget_want_hotkey (w, TRUE); + widget_want_cursor (w, FALSE); return l; } @@ -573,8 +578,10 @@ listbox_select_first (WListbox * l) void listbox_select_last (WListbox * l) { + int lines = WIDGET (l)->lines; + l->pos = l->count - 1; - l->top = l->count > l->widget.lines ? l->count - l->widget.lines : 0; + l->top = l->count > lines ? l->count - lines : 0; } /* --------------------------------------------------------------------------------------------- */ @@ -600,8 +607,13 @@ listbox_select_entry (WListbox * l, int dest) l->pos = dest; if (!top_seen) l->top = l->pos; - else if (l->pos - l->top >= l->widget.lines) - l->top = l->pos - l->widget.lines + 1; + else + { + int lines = WIDGET (l)->lines; + + if (l->pos - l->top >= lines) + l->top = l->pos - lines + 1; + } return; } } diff --git a/lib/widget/menu.c b/lib/widget/menu.c index abf64382e..61b32c928 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -100,26 +100,24 @@ menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut) static void menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) { + Widget *w = WIDGET (menubar); const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const menu_entry_t *entry = g_list_nth_data (menu->entries, idx); const int y = 2 + idx; int x = menu->start_x; - if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols) - x = menubar->widget.cols - menu->max_entry_len - 4; + if (x + menu->max_entry_len + 4 > (gsize) w->cols) + x = w->cols - menu->max_entry_len - 4; if (entry == NULL) { /* menu separator */ tty_setcolor (MENU_ENTRY_COLOR); - widget_move (&menubar->widget, y, x - 1); + widget_move (w, y, x - 1); tty_print_alt_char (ACS_LTEE, FALSE); - - tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x, - ACS_HLINE, menu->max_entry_len + 3); - - widget_move (&menubar->widget, y, x + menu->max_entry_len + 3); + tty_draw_hline (w->y + y, w->x + x, ACS_HLINE, menu->max_entry_len + 3); + widget_move (w, y, x + menu->max_entry_len + 3); tty_print_alt_char (ACS_RTEE, FALSE); } else @@ -128,7 +126,7 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) /* menu text */ tty_setcolor (color); - widget_move (&menubar->widget, y, x); + widget_move (w, y, x); tty_print_char ((unsigned char) entry->first_letter); tty_getyx (&yt, &xt); tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2); /* clear line */ @@ -146,12 +144,12 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) if (entry->shortcut != NULL) { - widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3); + widget_move (w, y, x + menu->max_hotkey_len + 3); tty_print_string (entry->shortcut); } /* move cursor to the start of entry text */ - widget_move (&menubar->widget, y, x + 1); + widget_move (w, y, x + 1); } } @@ -160,18 +158,17 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color) static void menubar_draw_drop (WMenuBar * menubar) { + Widget *w = WIDGET (menubar); const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected); const unsigned int count = g_list_length (menu->entries); int column = menu->start_x - 1; unsigned int i; - if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols) - column = menubar->widget.cols - menu->max_entry_len - 5; + if (column + menu->max_entry_len + 5 > (gsize) w->cols) + column = w->cols - menu->max_entry_len - 5; tty_setcolor (MENU_ENTRY_COLOR); - draw_box (menubar->widget.owner, - menubar->widget.y + 1, menubar->widget.x + column, - count + 2, menu->max_entry_len + 5, FALSE); + draw_box (w->owner, w->y + 1, w->x + column, count + 2, menu->max_entry_len + 5, FALSE); for (i = 0; i < count; i++) menubar_paint_idx (menubar, i, @@ -196,11 +193,12 @@ menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey) static void menubar_draw (WMenuBar * menubar) { + Widget *w = WIDGET (menubar); GList *i; /* First draw the complete menubar */ tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR); - tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols); + tty_draw_hline (w->y, w->x, ' ', w->cols); /* Now each one of the entries */ for (i = menubar->menu; i != NULL; i = g_list_next (i)) @@ -209,7 +207,7 @@ menubar_draw (WMenuBar * menubar) gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i)); menubar_set_color (menubar, is_selected, FALSE); - widget_move (&menubar->widget, 0, menu->start_x); + widget_move (w, 0, menu->start_x); tty_print_char (' '); tty_print_string (menu->text.start); @@ -230,7 +228,7 @@ menubar_draw (WMenuBar * menubar) if (menubar->is_dropped) menubar_draw_drop (menubar); else - widget_move (&menubar->widget, 0, + widget_move (w, 0, ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x); } @@ -248,7 +246,7 @@ 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 = menubar->widget.owner; + h = WIDGET (menubar)->owner; h->current = g_list_find (h->widgets, dlg_find_by_id (h, menubar->previous_widget)); menubar->is_dropped = FALSE; @@ -287,12 +285,14 @@ menubar_right (WMenuBar * menubar) static void menubar_finish (WMenuBar * menubar) { + Widget *w = WIDGET (menubar); + menubar->is_dropped = FALSE; menubar->is_active = FALSE; - menubar->widget.lines = 1; - widget_want_hotkey (menubar->widget, 0); + w->lines = 1; + widget_want_hotkey (w, 0); - dlg_select_by_id (menubar->widget.owner, menubar->previous_widget); + dlg_select_by_id (w->owner, menubar->previous_widget); do_refresh (); } @@ -316,10 +316,11 @@ menubar_execute (WMenuBar * menubar) if ((entry != NULL) && (entry->command != CK_IgnoreKey)) { + Widget *w = WIDGET (menubar); + mc_global.widget.is_right = (menubar->selected != 0); menubar_finish (menubar); - menubar->widget.owner->callback (menubar->widget.owner, &menubar->widget, - DLG_ACTION, entry->command, NULL); + w->owner->callback (w->owner, w, DLG_ACTION, entry->command, NULL); do_refresh (); } } @@ -555,10 +556,10 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm) return MSG_NOT_HANDLED; /* Trick to get all the mouse events */ - menubar->widget.lines = LINES; + w->lines = LINES; /* Trick to get all of the hotkeys */ - widget_want_hotkey (menubar->widget, 1); + widget_want_hotkey (w, 1); menubar_draw (menubar); return MSG_HANDLED; @@ -608,7 +609,7 @@ static int menubar_event (Gpm_Event * event, void *data) { WMenuBar *menubar = (WMenuBar *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); gboolean was_active = TRUE; int left_x, right_x, bottom_y; Menu *menu; @@ -688,10 +689,10 @@ menubar_event (Gpm_Event * event, void *data) menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected); left_x = menu->start_x; right_x = left_x + menu->max_entry_len + 3; - if (right_x > menubar->widget.cols) + if (right_x > w->cols) { - left_x = menubar->widget.cols - menu->max_entry_len - 3; - right_x = menubar->widget.cols; + left_x = w->cols - menu->max_entry_len - 3; + right_x = w->cols; } bottom_y = g_list_length (menu->entries) + 3; @@ -813,11 +814,14 @@ WMenuBar * menubar_new (int y, int x, int cols, GList * menu) { WMenuBar *menubar; + Widget *w; menubar = g_new0 (WMenuBar, 1); - init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event); - widget_want_cursor (menubar->widget, FALSE); + w = WIDGET (menubar); + init_widget (w, y, x, 1, cols, menubar_callback, menubar_event); + menubar->is_visible = TRUE; /* by default */ + widget_want_cursor (w, FALSE); menubar_set_menu (menubar, menu); return menubar; @@ -849,7 +853,7 @@ menubar_add_menu (WMenuBar * menubar, Menu * menu) { if (menu != NULL) { - menu_arrange (menu, menubar->widget.owner->get_shortcut); + menu_arrange (menu, WIDGET (menubar)->owner->get_shortcut); menubar->menu = g_list_append (menubar->menu, menu); } @@ -872,7 +876,7 @@ menubar_arrange (WMenuBar * menubar) if (menubar->menu == NULL) return; - gap = menubar->widget.cols - 2; + gap = WIDGET (menubar)->cols - 2; /* First, calculate gap between items... */ for (i = menubar->menu; i != NULL; i = g_list_next (i)) diff --git a/lib/widget/quick.c b/lib/widget/quick.c index fe4a3ec0d..3182fa5b1 100644 --- a/lib/widget/quick.c +++ b/lib/widget/quick.c @@ -90,16 +90,15 @@ quick_dialog_skip (QuickDialog * qd, int nskip) switch (qw->widget_type) { case quick_checkbox: - qw->widget = - (Widget *) check_new (ypos, xpos, *qw->u.checkbox.state, - I18N (qw->u.checkbox.text)); + qw->widget = WIDGET (check_new (ypos, xpos, *qw->u.checkbox.state, + I18N (qw->u.checkbox.text))); break; case quick_button: - qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action, - (qw->u.button.action == - B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON, - I18N (qw->u.button.text), qw->u.button.callback); + qw->widget = WIDGET (button_new (ypos, xpos, qw->u.button.action, + qw->u.button.action == B_ENTER ? + DEFPUSH_BUTTON : NORMAL_BUTTON, + I18N (qw->u.button.text), qw->u.button.callback)); break; case quick_input: @@ -111,19 +110,19 @@ quick_dialog_skip (QuickDialog * qd, int nskip) in->completion_flags |= INPUT_COMPLETE_CD; if ((qw->u.input.flags & 4) != 0) in->strip_password = TRUE; - qw->widget = (Widget *) in; + qw->widget = WIDGET (in); *qw->u.input.result = NULL; break; case quick_label: - qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text)); + qw->widget = WIDGET (label_new (ypos, xpos, I18N (qw->u.label.text))); break; case quick_groupbox: - qw->widget = (Widget *) groupbox_new (ypos, xpos, - qw->u.groupbox.height, - qw->u.groupbox.width, - I18N (qw->u.groupbox.title)); + qw->widget = WIDGET (groupbox_new (ypos, xpos, + qw->u.groupbox.height, + qw->u.groupbox.width, + I18N (qw->u.groupbox.title))); break; case quick_radio: @@ -143,7 +142,7 @@ quick_dialog_skip (QuickDialog * qd, int nskip) r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items); r->pos = r->sel = *qw->u.radio.value; - qw->widget = (Widget *) r; + qw->widget = WIDGET (r); g_strfreev (items); break; } diff --git a/lib/widget/radio.c b/lib/widget/radio.c index 7656cbf33..a3e5b230e 100644 --- a/lib/widget/radio.c +++ b/lib/widget/radio.c @@ -58,7 +58,7 @@ radio_callback (Widget * w, widget_msg_t msg, int parm) { WRadio *r = (WRadio *) w; int i; - Dlg_head *h = r->widget.owner; + Dlg_head *h = w->owner; switch (msg) { @@ -113,7 +113,7 @@ radio_callback (Widget * w, widget_msg_t msg, int parm) case WIDGET_CURSOR: h->callback (h, w, DLG_ACTION, 0, NULL); radio_callback (w, WIDGET_FOCUS, ' '); - widget_move (&r->widget, r->pos, 1); + widget_move (r, r->pos, 1); return MSG_HANDLED; case WIDGET_UNFOCUS: @@ -124,8 +124,8 @@ radio_callback (Widget * w, widget_msg_t msg, int parm) const gboolean focused = (i == r->pos && msg == WIDGET_FOCUS); widget_selectcolor (w, focused, FALSE); - widget_move (&r->widget, i, 0); - tty_draw_hline (r->widget.y + i, r->widget.x, ' ', r->widget.cols); + widget_move (r, i, 0); + tty_draw_hline (w->y + i, w->x, ' ', w->cols); tty_print_string ((r->sel == i) ? "(*) " : "( ) "); hotkey_draw (w, r->texts[i], focused); } @@ -147,7 +147,7 @@ radio_callback (Widget * w, widget_msg_t msg, int parm) static int radio_event (Gpm_Event * event, void *data) { - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; @@ -179,28 +179,31 @@ WRadio * radio_new (int y, int x, int count, const char **texts) { WRadio *r; + Widget *w; int i, wmax = 0; r = g_new (WRadio, 1); + w = WIDGET (r); + /* Compute the longest string */ r->texts = g_new (hotkey_t, count); for (i = 0; i < count; i++) { - int w; + int width; r->texts[i] = parse_hotkey (texts[i]); - w = hotkey_width (r->texts[i]); - wmax = max (w, wmax); + width = hotkey_width (r->texts[i]); + wmax = max (width, wmax); } - init_widget (&r->widget, y, x, count, 4 + wmax, radio_callback, radio_event); + init_widget (w, y, x, count, 4 + wmax, radio_callback, radio_event); /* 4 is width of "(*) " */ r->state = 1; r->pos = 0; r->sel = 0; r->count = count; - widget_want_hotkey (r->widget, TRUE); + widget_want_hotkey (w, TRUE); return r; } diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 772e439c6..e181ddd7a 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -15,7 +15,7 @@ #define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x)) /* Sets/clear the specified flag in the options field */ #define widget_option(w,f,i) \ - w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f)))) + (w)->options = ((i) ? ((w)->options | (f)) : ((w)->options & (~(f)))) #define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i)) #define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i)) #define widget_disable(w,i) widget_option((w), W_DISABLED, (i)) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index b9eaa5e8f..ff3a2c432 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -2877,7 +2877,7 @@ dview_edit (WDiff * dview, diff_place_t ord) return; } - h = ((Widget *) dview)->owner; + h = WIDGET (dview)->owner; h_modal = h->modal; get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs); @@ -2943,19 +2943,21 @@ dview_goto_cmd (WDiff * dview, diff_place_t ord) static void dview_labels (WDiff * dview) { + Widget *d; Dlg_head *h; WButtonBar *b; - h = dview->widget.owner; + d = WIDGET (dview); + h = d->owner; b = find_buttonbar (h); - buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 5, Q_ ("ButtonBar|Merge"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 9, Q_ ("ButtonBar|Options"), diff_map, (Widget *) dview); - buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), diff_map, (Widget *) dview); + 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, 4, Q_ ("ButtonBar|Edit"), diff_map, d); + buttonbar_set_label (b, 5, Q_ ("ButtonBar|Merge"), diff_map, d); + buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), diff_map, d); + buttonbar_set_label (b, 9, Q_ ("ButtonBar|Options"), diff_map, d); + buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), diff_map, d); } /* --------------------------------------------------------------------------------------------- */ @@ -3312,7 +3314,7 @@ static cb_ret_t dview_callback (Widget * w, widget_msg_t msg, int parm) { WDiff *dview = (WDiff *) w; - Dlg_head *h = dview->widget.owner; + Dlg_head *h = w->owner; cb_ret_t i; switch (msg) @@ -3365,8 +3367,8 @@ dview_adjust_size (Dlg_head * h) /* Look up the viewer and the buttonbar, we assume only two widgets here */ dview = (WDiff *) find_widget_type (h, dview_callback); bar = find_buttonbar (h); - widget_set_size (&dview->widget, 0, 0, LINES - 1, COLS); - widget_set_size ((Widget *) bar, LINES - 1, 0, 1, COLS); + widget_set_size (WIDGET (dview), 0, 0, LINES - 1, COLS); + widget_set_size (WIDGET (bar), LINES - 1, 0, 1, COLS); dview_compute_areas (dview); } @@ -3389,10 +3391,10 @@ dview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, v if (sender == NULL) return dview_execute_cmd (NULL, parm); /* message from buttonbar */ - if (sender == (Widget *) find_buttonbar (h)) + if (sender == WIDGET (find_buttonbar (h))) { if (data != NULL) - return send_message ((Widget *) data, WIDGET_COMMAND, parm); + return send_message (WIDGET (data), WIDGET_COMMAND, parm); dview = (WDiff *) find_widget_type (h, dview_callback); return dview_execute_cmd (dview, parm); @@ -3443,6 +3445,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char { int error; WDiff *dview; + Widget *w; Dlg_head *dview_dlg; /* Create dialog and widgets, put them on the dialog */ @@ -3451,11 +3454,9 @@ diff_view (const char *file1, const char *file2, const char *label1, const char "[Diff Viewer]", NULL, DLG_WANT_TAB); dview = g_new0 (WDiff, 1); - - init_widget (&dview->widget, 0, 0, LINES - 1, COLS, - (callback_fn) dview_callback, (mouse_h) dview_event); - - widget_want_cursor (dview->widget, 0); + w = WIDGET (dview); + init_widget (w, 0, 0, LINES - 1, COLS, (callback_fn) dview_callback, (mouse_h) dview_event); + widget_want_cursor (w, FALSE); add_widget (dview_dlg, dview); add_widget (dview_dlg, buttonbar_new (TRUE)); diff --git a/src/editor/edit.c b/src/editor/edit.c index 27ad1c4c9..b4169e28a 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -515,7 +515,7 @@ edit_load_position (WEdit * edit) book_mark_restore (edit, BOOK_MARK_COLOR); edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1)); - edit_move_display (edit, line - (edit->widget.lines / 2)); + edit_move_display (edit, line - (WIDGET (edit)->lines / 2)); } /* --------------------------------------------------------------------------------------------- */ @@ -906,7 +906,7 @@ static void edit_end_page (WEdit * edit) { edit_update_curs_row (edit); - edit_move_down (edit, edit->widget.lines - edit->curs_row - 1, 0); + edit_move_down (edit, WIDGET (edit)->lines - edit->curs_row - 1, 0); } @@ -938,7 +938,7 @@ edit_move_to_bottom (WEdit * edit) edit_move_down (edit, edit->total_lines - edit->curs_row, 0); edit->start_display = edit->last_byte; edit->start_line = edit->total_lines; - edit_scroll_upward (edit, edit->widget.lines - 1); + edit_scroll_upward (edit, WIDGET (edit)->lines - 1); edit->force |= REDRAW_PAGE; } } @@ -1624,7 +1624,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack break; /* count lines if searching downward */ if (inc > 0 && a == '\n') - if (n++ >= edit->widget.lines - edit->curs_row) /* out of screen */ + if (n++ >= WIDGET (edit)->lines - edit->curs_row) /* out of screen */ break; } /* count bracket depth */ @@ -1807,7 +1807,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry) edit_cursor_move (edit, curs - edit->curs1); edit->force |= REDRAW_PAGE; - send_message ((Widget *) edit, WIDGET_DRAW, 0); + send_message (WIDGET (edit), WIDGET_DRAW, 0); } /* --------------------------------------------------------------------------------------------- */ @@ -2187,6 +2187,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f long line) { gboolean to_free = FALSE; + Widget *w; option_auto_syntax = 1; /* Resetting to auto on every invokation */ option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0; @@ -2226,13 +2227,15 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f to_free = TRUE; } - edit->drag_state = MCEDIT_DRAG_NORMAL; - edit->widget.y = y; - edit->widget.x = x; - edit->widget.lines = lines; - edit->widget.cols = cols; + w = WIDGET (edit); + + w->y = y; + w->x = x; + w->lines = lines; + w->cols = cols; edit_save_size (edit); edit->fullscreen = TRUE; + edit->drag_state = MCEDIT_DRAG_NORMAL; edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; edit->stat1.st_uid = getuid (); @@ -2352,14 +2355,16 @@ edit_clean (WEdit * edit) gboolean edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line) { + Widget *w = WIDGET (edit); WEdit *e; - int y = edit->widget.y; - int x = edit->widget.x; - int lines = edit->widget.lines; - int columns = edit->widget.cols; + + int y = w->y; + int x = w->x; + int lines = w->lines; + int columns = w->cols; e = g_malloc0 (sizeof (WEdit)); - e->widget = edit->widget; + *WIDGET (e) = *w; if (edit_init (e, y, x, lines, columns, filename_vpath, line) == NULL) { @@ -3154,7 +3159,7 @@ edit_scroll_downward (WEdit * edit, long i) { long lines_below; - lines_below = edit->total_lines - edit->start_line - (edit->widget.lines - 1); + lines_below = edit->total_lines - edit->start_line - (WIDGET (edit)->lines - 1); if (lines_below > 0) { if (i > lines_below) @@ -3531,6 +3536,8 @@ edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_inse void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) { + Widget *w = WIDGET (edit); + if (command == CK_WindowFullscreen) { edit_toggle_fullscreen (edit); @@ -3817,13 +3824,13 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit->column_highlight = 1; case CK_PageUp: case CK_MarkPageUp: - edit_move_up (edit, edit->widget.lines - 1, 1); + edit_move_up (edit, w->lines - 1, 1); break; case CK_MarkColumnPageDown: edit->column_highlight = 1; case CK_PageDown: case CK_MarkPageDown: - edit_move_down (edit, edit->widget.lines - 1, 1); + edit_move_down (edit, w->lines - 1, 1); break; case CK_MarkColumnLeft: edit->column_highlight = 1; @@ -4000,8 +4007,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) if (p->next != NULL) { p = p->next; - if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line) - edit_move_display (edit, p->line - edit->widget.lines / 2); + if (p->line >= edit->start_line + w->lines || p->line < edit->start_line) + edit_move_display (edit, p->line - w->lines / 2); edit_move_to_line (edit, p->line); } } @@ -4017,8 +4024,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) p = p->prev; if (p->line >= 0) { - if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line) - edit_move_display (edit, p->line - edit->widget.lines / 2); + if (p->line >= edit->start_line + w->lines || p->line < edit->start_line) + edit_move_display (edit, p->line - w->lines / 2); edit_move_to_line (edit, p->line); } } diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index dbdeccec9..7abb112a0 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -2206,14 +2206,14 @@ edit_close_cmd (WEdit * edit) if (ret) { - Dlg_head *h = ((Widget *) edit)->owner; + Dlg_head *h = WIDGET (edit)->owner; if (edit->locked != 0) unlock_file (edit->filename_vpath); del_widget (edit); - if (edit_widget_is_editor ((Widget *) h->current->data)) + if (edit_widget_is_editor (WIDGET (h->current->data))) edit = (WEdit *) h->current->data; else { @@ -2667,7 +2667,7 @@ edit_replace_cmd (WEdit * edit, int again) long l; int prompt; - l = (long) (edit->curs_row - edit->widget.lines / 3); + l = edit->curs_row - WIDGET (edit)->lines / 3; if (l > 0) edit_scroll_downward (edit, l); if (l < 0) @@ -3072,7 +3072,7 @@ edit_goto_cmd (WEdit * edit) line = l; if (l < 0) l = edit->total_lines + l + 2; - edit_move_display (edit, l - edit->widget.lines / 2 - 1); + edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1); edit_move_to_line (edit, l - 1); edit->force |= REDRAW_COMPLETELY; g_free (f); @@ -3409,7 +3409,7 @@ edit_select_codepage_cmd (WEdit * edit) edit_set_codeset (edit); edit->force = REDRAW_PAGE; - send_message ((Widget *) edit, WIDGET_DRAW, 0); + send_message (WIDGET (edit), WIDGET_DRAW, 0); } #endif diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index 0c0b5c75e..e7b884016 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -628,10 +628,10 @@ editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text quick_widgets[6].u.label.text = repl_to; if (xpos == -1) - xpos = (edit->widget.cols - dlg_width) / 2; + xpos = (WIDGET (edit)->cols - dlg_width) / 2; if (ypos == -1) - ypos = edit->widget.lines * 2 / 3; + ypos = WIDGET (edit)->lines * 2 / 3; { QuickDialog Quick_input = { diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 7f55ab789..cf9ca0ff4 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -385,6 +385,8 @@ static inline void print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, long end_col, struct line_s line[], char *status, int bookmarked) { + Widget *w = WIDGET (edit); + struct line_s *p; int x = start_col_real; @@ -408,25 +410,25 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real, len = end_col + 1 - start_col; wrap_start = option_word_wrap_line_length + edit->start_col; - if (len > 0 && edit->widget.y + y >= 0) + if (len > 0 && w->y + y >= 0) { if (!show_right_margin || wrap_start > end_col) - tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); + tty_draw_hline (w->y + y, w->x + x1, ' ', len); else if (wrap_start < 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); - tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len); + tty_draw_hline (w->y + y, w->x + x1, ' ', len); } else { if (wrap_start > 0) - tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start); + tty_draw_hline (w->y + y, w->x + x1, ' ', wrap_start); len -= wrap_start; if (len > 0) { tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR); - tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len); + tty_draw_hline (w->y + y, w->x + x1 + wrap_start, ' ', len); } } } @@ -843,9 +845,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, static long prev_curs_row = 0; static off_t prev_curs = 0; - Widget *w = (Widget *) edit; - Dlg_head *h = w->owner; - Widget *wh = WIDGET (h); + Widget *w = WIDGET (edit); + Widget *wh = WIDGET (w->owner); long row = 0, curs_row; int force = edit->force; @@ -970,7 +971,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, } } - if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1) + if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1) { row = curs_row + 1; b = edit_bol (edit, edit->curs1); @@ -1052,22 +1053,24 @@ edit_status (WEdit * edit, gboolean active) void edit_scroll_screen_over_cursor (WEdit * edit) { + Widget *w = WIDGET (edit); + long p; long outby; int b_extreme, t_extreme, l_extreme, r_extreme; - if (edit->widget.lines <= 0 || edit->widget.cols <= 0) + if (w->lines <= 0 || w->cols <= 0) return; - edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET; - edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; + w->lines -= EDIT_TEXT_VERTICAL_OFFSET; + w->cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; if (!edit->fullscreen) { - edit->widget.x++; - edit->widget.cols -= 2; - edit->widget.y++; - edit->widget.lines -= 2; + w->x++; + w->cols -= 2; + w->y++; + w->lines -= 2; } r_extreme = EDIT_RIGHT_EXTREME; @@ -1076,39 +1079,39 @@ edit_scroll_screen_over_cursor (WEdit * edit) t_extreme = EDIT_TOP_EXTREME; if (edit->found_len != 0) { - b_extreme = max (edit->widget.lines / 4, b_extreme); - t_extreme = max (edit->widget.lines / 4, t_extreme); + b_extreme = max (w->lines / 4, b_extreme); + t_extreme = max (w->lines / 4, t_extreme); } - if (b_extreme + t_extreme + 1 > edit->widget.lines) + if (b_extreme + t_extreme + 1 > w->lines) { int n; n = b_extreme + t_extreme; if (n == 0) n = 1; - b_extreme = (b_extreme * (edit->widget.lines - 1)) / n; - t_extreme = (t_extreme * (edit->widget.lines - 1)) / n; + b_extreme = (b_extreme * (w->lines - 1)) / n; + t_extreme = (t_extreme * (w->lines - 1)) / n; } - if (l_extreme + r_extreme + 1 > edit->widget.cols) + if (l_extreme + r_extreme + 1 > w->cols) { int n; n = l_extreme + t_extreme; if (n == 0) n = 1; - l_extreme = (l_extreme * (edit->widget.cols - 1)) / n; - r_extreme = (r_extreme * (edit->widget.cols - 1)) / n; + l_extreme = (l_extreme * (w->cols - 1)) / n; + r_extreme = (r_extreme * (w->cols - 1)) / n; } p = edit_get_col (edit) + edit->over_col; edit_update_curs_row (edit); - outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len); + outby = p + edit->start_col - w->cols + 1 + (r_extreme + edit->found_len); if (outby > 0) edit_scroll_right (edit, outby); outby = l_extreme - p - edit->start_col; if (outby > 0) edit_scroll_left (edit, outby); p = edit->curs_row; - outby = p - edit->widget.lines + 1 + b_extreme; + outby = p - w->lines + 1 + b_extreme; if (outby > 0) edit_scroll_downward (edit, outby); outby = t_extreme - p; @@ -1116,14 +1119,14 @@ edit_scroll_screen_over_cursor (WEdit * edit) edit_scroll_upward (edit, outby); edit_update_curs_row (edit); - edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET; - edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; + w->lines += EDIT_TEXT_VERTICAL_OFFSET; + w->cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; if (!edit->fullscreen) { - edit->widget.x--; - edit->widget.cols += 2; - edit->widget.y--; - edit->widget.lines += 2; + w->x--; + w->cols += 2; + w->y--; + w->lines += 2; } } diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c index e58846b86..c6a08f6ac 100644 --- a/src/editor/editoptions.c +++ b/src/editor/editoptions.c @@ -106,7 +106,7 @@ edit_reload_syntax (void *data, void *user_data) { (void) user_data; - if (edit_widget_is_editor ((Widget *) data)) + if (edit_widget_is_editor (WIDGET (data))) { WEdit *edit = (WEdit *) data; edit_load_syntax (edit, NULL, edit->syntax_type); diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 59d4da187..6dbb56ac6 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -232,9 +232,8 @@ static void edit_restore_size (WEdit * edit) { edit->drag_state = MCEDIT_DRAG_NORMAL; - widget_set_size ((Widget *) edit, edit->y_prev, edit->x_prev, - edit->lines_prev, edit->cols_prev); - dlg_redraw (((Widget *) edit)->owner); + widget_set_size (WIDGET (edit), edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev); + dlg_redraw (WIDGET (edit)->owner); } /* --------------------------------------------------------------------------------------------- */ @@ -350,7 +349,7 @@ edit_window_list (const Dlg_head * h) listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]"); for (w = h->widgets; w != NULL; w = g_list_next (w)) - if (edit_widget_is_editor ((Widget *) w->data)) + if (edit_widget_is_editor (WIDGET (w->data))) { WEdit *e = (WEdit *) w->data; char *fname; @@ -367,7 +366,7 @@ edit_window_list (const Dlg_head * h) } listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++), - str_term_trim (fname, listbox->list->widget.cols - 2), NULL); + str_term_trim (fname, WIDGET (listbox->list)->cols - 2), NULL); g_free (fname); } @@ -436,7 +435,7 @@ static int edit_event (Gpm_Event * event, void *data) { WEdit *edit = (WEdit *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); Gpm_Event local; if (!mouse_global_in_widget (event, w)) @@ -460,13 +459,13 @@ edit_event (Gpm_Event * event, void *data) /* click on the top line (move) */ int dx = edit->fullscreen ? 0 : 2; - if (local.x == edit->widget.cols - dx - 1) + if (local.x == w->cols - dx - 1) { edit_dialog_callback (w->owner, NULL, DLG_ACTION, CK_Close, NULL); return MOU_NORMAL; } - if (local.x == edit->widget.cols - dx - 4) + if (local.x == w->cols - dx - 4) { edit_toggle_fullscreen (edit); return MOU_NORMAL; @@ -691,7 +690,7 @@ edit_dialog_event (Gpm_Event * event, void *data) /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) - if (edit_widget_is_editor ((Widget *) l->data) && ((WEdit *) l->data)->fullscreen) + if (edit_widget_is_editor (WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ @@ -750,7 +749,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command) break; case CK_Close: /* if there are no opened files anymore, close MC editor */ - if (edit_widget_is_editor ((Widget *) h->current->data) && + if (edit_widget_is_editor (WIDGET (h->current->data)) && edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL) dlg_stop (h); break; @@ -764,7 +763,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command) case CK_Quit: case CK_Cancel: { - Widget *w = (Widget *) h->current->data; + Widget *w = WIDGET (h->current->data); if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL) dlg_stop (h); @@ -798,7 +797,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command) break; case CK_WindowMove: case CK_WindowResize: - if (edit_widget_is_editor ((Widget *) h->current->data)) + if (edit_widget_is_editor (WIDGET (h->current->data))) edit_handle_move_resize ((WEdit *) h->current->data, command); break; case CK_WindowList: @@ -840,7 +839,7 @@ edit_quit (Dlg_head * h) h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ for (l = h->widgets; l != NULL; l = g_list_next (l)) - if (edit_widget_is_editor ((Widget *) l->data)) + if (edit_widget_is_editor (WIDGET (l->data))) { e = (WEdit *) l->data; @@ -870,13 +869,13 @@ static inline void edit_set_buttonbar (WEdit * edit, WButtonBar * bb) { buttonbar_set_label (bb, 1, Q_ ("ButtonBar|Help"), editor_map, NULL); - buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 5, Q_ ("ButtonBar|Copy"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 6, Q_ ("ButtonBar|Move"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, (Widget *) edit); - buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, (Widget *) edit); + buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 5, Q_ ("ButtonBar|Copy"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 6, Q_ ("ButtonBar|Move"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, WIDGET (edit)); + buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, WIDGET (edit)); buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, NULL); buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, NULL); } @@ -909,8 +908,8 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo /* dlg_set_size() is surplus for this case */ wh->lines = LINES; wh->cols = COLS; - widget_set_size (&buttonbar->widget, wh->lines - 1, wh->x, 1, wh->cols); - widget_set_size (&menubar->widget, wh->y, wh->x, 1, wh->cols); + widget_set_size (WIDGET (buttonbar), wh->lines - 1, wh->x, 1, wh->cols); + widget_set_size (WIDGET (menubar), wh->y, wh->x, 1, wh->cols); menubar_arrange (menubar); g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL); return MSG_HANDLED; @@ -921,19 +920,19 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo return edit_dialog_command_execute (h, parm); /* message from menu */ menubar = find_menubar (h); - if (sender == (Widget *) menubar) + if (sender == WIDGET (menubar)) { if (edit_dialog_command_execute (h, parm) == MSG_HANDLED) return MSG_HANDLED; /* try send command to the current window */ - return send_message ((Widget *) h->current->data, WIDGET_COMMAND, parm); + return send_message (WIDGET (h->current->data), WIDGET_COMMAND, parm); } /* message from buttonbar */ buttonbar = find_buttonbar (h); - if (sender == (Widget *) buttonbar) + if (sender == WIDGET (buttonbar)) { if (data != NULL) - return send_message ((Widget *) data, WIDGET_COMMAND, parm); + return send_message (WIDGET (data), WIDGET_COMMAND, parm); return edit_dialog_command_execute (h, parm); } return MSG_NOT_HANDLED; @@ -990,7 +989,7 @@ edit_callback (Widget * w, widget_msg_t msg, int parm) switch (msg) { case WIDGET_FOCUS: - edit_set_buttonbar (e, find_buttonbar (e->widget.owner)); + edit_set_buttonbar (e, find_buttonbar (w->owner)); /* fall through */ case WIDGET_DRAW: @@ -1152,7 +1151,7 @@ edit_get_file_name (const WEdit * edit) WEdit * find_editor (const Dlg_head * h) { - if (edit_widget_is_editor ((Widget *) h->current->data)) + if (edit_widget_is_editor (WIDGET (h->current->data))) return (WEdit *) h->current->data; return (WEdit *) find_widget_type (h, edit_callback); } @@ -1176,11 +1175,12 @@ edit_widget_is_editor (const Widget * w) void edit_update_screen (WEdit * e) { + Dlg_head *h = WIDGET (e)->owner; + edit_scroll_screen_over_cursor (e); edit_update_curs_col (e); - edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 && - (void *) e == ((Widget *) e)->owner->current->data); + edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 && (void *) e == h->current->data); /* pop all events for this window for internal handling */ if (!is_idle ()) @@ -1192,7 +1192,7 @@ edit_update_screen (WEdit * e) edit_render_keypress (e); } - buttonbar_redraw (find_buttonbar (((Widget *) e)->owner)); + buttonbar_redraw (find_buttonbar (h)); } /* --------------------------------------------------------------------------------------------- */ @@ -1205,10 +1205,12 @@ edit_update_screen (WEdit * e) void edit_save_size (WEdit * edit) { - edit->y_prev = edit->widget.y; - edit->x_prev = edit->widget.x; - edit->lines_prev = edit->widget.lines; - edit->cols_prev = edit->widget.cols; + Widget *w = WIDGET (edit); + + edit->y_prev = w->y; + edit->x_prev = w->x; + edit->lines_prev = w->lines; + edit->cols_prev = w->cols; } /* --------------------------------------------------------------------------------------------- */ @@ -1236,10 +1238,10 @@ edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path if (edit == NULL) return FALSE; - w = (Widget *) edit; + w = WIDGET (edit); w->callback = edit_callback; w->mouse = edit_event; - widget_want_cursor (*w, TRUE); + widget_want_cursor (w, TRUE); add_widget (h, w); dlg_redraw (h); diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index c8bf48d64..57bf8dd1a 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -269,7 +269,7 @@ update_mode (Dlg_head * h) tty_setcolor (COLOR_NORMAL); widget_move (h, BY + 2, 9); tty_printf ("%12o", get_mode ()); - send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0); + send_message (WIDGET (h->current->data), WIDGET_FOCUS, 0); } /* --------------------------------------------------------------------------------------------- */ @@ -545,7 +545,7 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, x_toggle ^= (1 << parm); update_mode (h); dlg_broadcast_msg (h, WIDGET_DRAW, FALSE); - send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0); + send_message (WIDGET (h->current->data), WIDGET_FOCUS, 0); break; case XCTRL ('x'): @@ -561,7 +561,7 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, x_toggle ^= (1 << parm); update_mode (h); dlg_broadcast_msg (h, WIDGET_DRAW, FALSE); - send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0); + send_message (WIDGET (h->current->data), WIDGET_FOCUS, 0); break; case 'x': diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 67c225a17..8d376aea1 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -187,32 +187,32 @@ display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void * { display_radio->pos = display_radio->sel = 3; dlg_select_widget (display_radio); /* force redraw */ - h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL); + h->callback (h, WIDGET (display_radio), DLG_ACTION, 0, NULL); return MSG_HANDLED; } return MSG_NOT_HANDLED; case DLG_ACTION: - if (sender == (Widget *) display_radio) + if (sender == WIDGET (display_radio)) { if (!(display_check_status->state & C_BOOL)) input_assign_text (display_mini_status, displays_status[display_radio->sel]); input_update (display_mini_status, FALSE); input_update (display_user_format, FALSE); - widget_disable (display_user_format->widget, display_radio->sel != 3); + widget_disable (WIDGET (display_user_format), display_radio->sel != 3); return MSG_HANDLED; } - if (sender == (Widget *) display_check_status) + if (sender == WIDGET (display_check_status)) { if (display_check_status->state & C_BOOL) { - widget_disable (display_mini_status->widget, FALSE); + widget_disable (WIDGET (display_mini_status), FALSE); input_assign_text (display_mini_status, displays_status[3]); } else { - widget_disable (display_mini_status->widget, TRUE); + widget_disable (WIDGET (display_mini_status), TRUE); input_assign_text (display_mini_status, displays_status[display_radio->sel]); } input_update (display_mini_status, FALSE); @@ -289,8 +289,8 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status) /* buttons */ dlg_width = max (dlg_width, b_len + 6); gap = (dlg_width - 6 - b_len) / 3; - ok_button->widget.x = 3 + gap; - cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2; + WIDGET (ok_button)->x = 3 + gap; + WIDGET (cancel_button)->x = WIDGET (ok_button)->x + ok_len + gap + 2; } displays_status = _status; @@ -411,7 +411,7 @@ tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *dat return MSG_HANDLED; case DLG_ACTION: - return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm); + return send_message (WIDGET (find_tree (h)), WIDGET_COMMAND, parm); default: return default_dlg_callback (h, sender, msg, parm, data); @@ -437,7 +437,7 @@ confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void * /* input */ w = dlg_find_by_id (h, sender->id - 1); - widget_disable (*w, not_use); + widget_disable (w, not_use); send_message (w, WIDGET_DRAW, 0); return MSG_HANDLED; @@ -916,8 +916,8 @@ tree_box (const char *current_dir) bar = buttonbar_new (TRUE); add_widget (dlg, bar); /* restore ButtonBar coordinates after add_widget() */ - ((Widget *) bar)->x = 0; - ((Widget *) bar)->y = LINES - 1; + WIDGET (bar)->x = 0; + WIDGET (bar)->y = LINES - 1; if (run_dlg (dlg) == B_ENTER) val = vfs_path_to_str (tree_selected_name (mytree)); diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index 189389216..a25e5aed0 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -195,8 +195,8 @@ chmod_toggle_select (Dlg_head * h, int Id) static void chmod_refresh (Dlg_head * h) { - int y = file_gb->widget.y + 1; - int x = file_gb->widget.x + 2; + int y = WIDGET (file_gb)->y + 1; + int x = WIDGET (file_gb)->x + 2; common_dialog_repaint (h); @@ -237,7 +237,7 @@ chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da /* whether action was sent by checkbox? */ for (i = 0; i < check_perm_num; i++) - if (sender == (Widget *) check_perm[i].check) + if (sender == WIDGET (check_perm[i].check)) { sender_is_checkbox = TRUE; break; diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index eba8950e3..6a2977518 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -1579,7 +1579,7 @@ single_dirsize_cmd (void) } if (panels_options.mark_moves_down) - send_message ((Widget *) panel, WIDGET_COMMAND, CK_Down); + send_message (WIDGET (panel), WIDGET_COMMAND, CK_Down); recalculate_panel_summary (panel); diff --git a/src/filemanager/command.c b/src/filemanager/command.c index 4deefddf0..09deedcae 100644 --- a/src/filemanager/command.c +++ b/src/filemanager/command.c @@ -482,7 +482,7 @@ command_new (int y, int x, int cols) INPUT_COMPLETE_SHELL_ESC); /* Add our hooks */ - cmd->widget.callback = command_callback; + WIDGET (cmd)->callback = command_callback; return cmd; } diff --git a/src/filemanager/find.c b/src/filemanager/find.c index e002c0478..4cd6411a2 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -401,36 +401,36 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void switch (msg) { case DLG_ACTION: - if (sender == (Widget *) content_use_cbox) + if (sender == WIDGET (content_use_cbox)) { gboolean disable = !(content_use_cbox->state & C_BOOL); - widget_disable (content_label->widget, disable); - send_message ((Widget *) content_label, WIDGET_DRAW, 0); - widget_disable (in_with->widget, disable); - send_message ((Widget *) in_with, WIDGET_DRAW, 0); - widget_disable (content_first_hit_cbox->widget, disable); - send_message ((Widget *) content_first_hit_cbox, WIDGET_DRAW, 0); - widget_disable (content_regexp_cbox->widget, disable); - send_message ((Widget *) content_regexp_cbox, WIDGET_DRAW, 0); - widget_disable (content_case_sens_cbox->widget, disable); - send_message ((Widget *) content_case_sens_cbox, WIDGET_DRAW, 0); + widget_disable (WIDGET (content_label), disable); + send_message (WIDGET (content_label), WIDGET_DRAW, 0); + widget_disable (WIDGET (in_with), disable); + send_message (WIDGET (in_with), WIDGET_DRAW, 0); + widget_disable (WIDGET (content_first_hit_cbox), disable); + send_message (WIDGET (content_first_hit_cbox), WIDGET_DRAW, 0); + widget_disable (WIDGET (content_regexp_cbox), disable); + send_message (WIDGET (content_regexp_cbox), WIDGET_DRAW, 0); + widget_disable (WIDGET (content_case_sens_cbox), disable); + send_message (WIDGET (content_case_sens_cbox), WIDGET_DRAW, 0); #ifdef HAVE_CHARSET - widget_disable (content_all_charsets_cbox->widget, disable); - send_message ((Widget *) content_all_charsets_cbox, WIDGET_DRAW, 0); + widget_disable (WIDGET (content_all_charsets_cbox), disable); + send_message (WIDGET (content_all_charsets_cbox), WIDGET_DRAW, 0); #endif - widget_disable (content_whole_words_cbox->widget, disable); - send_message ((Widget *) content_whole_words_cbox, WIDGET_DRAW, 0); + widget_disable (WIDGET (content_whole_words_cbox), disable); + send_message (WIDGET (content_whole_words_cbox), WIDGET_DRAW, 0); return MSG_HANDLED; } - if (sender == (Widget *) ignore_dirs_cbox) + if (sender == WIDGET (ignore_dirs_cbox)) { gboolean disable = !(ignore_dirs_cbox->state & C_BOOL); - widget_disable (in_ignore->widget, disable); - send_message ((Widget *) in_ignore, WIDGET_DRAW, 0); + widget_disable (WIDGET (in_ignore), disable); + send_message (WIDGET (in_ignore), WIDGET_DRAW, 0); return MSG_HANDLED; } @@ -563,31 +563,31 @@ find_parameters (char **start_dir, ssize_t * start_dir_len, content_first_hit_cbox = check_new (cbox_position--, FIND_X / 2 + 1, options.content_first_hit, content_first_hit_label); - widget_disable (content_first_hit_cbox->widget, disable); + widget_disable (WIDGET (content_first_hit_cbox), disable); add_widget (find_dlg, content_first_hit_cbox); content_whole_words_cbox = check_new (cbox_position--, FIND_X / 2 + 1, options.content_whole_words, content_whole_words_label); - widget_disable (content_whole_words_cbox->widget, disable); + widget_disable (WIDGET (content_whole_words_cbox), disable); add_widget (find_dlg, content_whole_words_cbox); #ifdef HAVE_CHARSET content_all_charsets_cbox = check_new (cbox_position--, FIND_X / 2 + 1, options.content_all_charsets, content_all_charsets_label); - widget_disable (content_all_charsets_cbox->widget, disable); + widget_disable (WIDGET (content_all_charsets_cbox), disable); add_widget (find_dlg, content_all_charsets_cbox); #endif content_case_sens_cbox = check_new (cbox_position--, FIND_X / 2 + 1, options.content_case_sens, content_case_label); - widget_disable (content_case_sens_cbox->widget, disable); + widget_disable (WIDGET (content_case_sens_cbox), disable); add_widget (find_dlg, content_case_sens_cbox); content_regexp_cbox = check_new (cbox_position--, FIND_X / 2 + 1, options.content_regexp, content_regexp_label); - widget_disable (content_regexp_cbox->widget, disable); + widget_disable (WIDGET (content_regexp_cbox), disable); add_widget (find_dlg, content_regexp_cbox); cbox_position = FIND_Y - 6; @@ -618,11 +618,11 @@ find_parameters (char **start_dir, ssize_t * start_dir_len, in_with = input_new (8, FIND_X / 2 + 1, input_get_default_colors (), FIND_X / 2 - 4, INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, INPUT_COMPLETE_DEFAULT); - widget_disable (in_with->widget, disable); + widget_disable (WIDGET (in_with), disable); add_widget (find_dlg, in_with); content_label = label_new (7, FIND_X / 2 + 1, _("Content:")); - widget_disable (content_label->widget, disable); + widget_disable (WIDGET (content_label), disable); add_widget (find_dlg, content_label); in_name = input_new (8, 3, input_get_default_colors (), @@ -633,7 +633,7 @@ find_parameters (char **start_dir, ssize_t * start_dir_len, in_ignore = input_new (5, 3, input_get_default_colors (), FIND_X - 6, options.ignore_dirs != NULL ? options.ignore_dirs : "", "ignoredirs", INPUT_COMPLETE_DEFAULT); - widget_disable (in_ignore->widget, !options.ignore_dirs_enable); + widget_disable (WIDGET (in_ignore), !options.ignore_dirs_enable); add_widget (find_dlg, in_ignore); ignore_dirs_cbox = @@ -868,7 +868,7 @@ find_add_match (const char *dir, const char *file) /* Don't scroll */ if (matches == 0) listbox_select_first (find_list); - send_message (&find_list->widget, WIDGET_DRAW, 0); + send_message (WIDGET (find_list), WIDGET_DRAW, 0); matches++; found_num_update (); diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index 9ff550ba8..799fb3327 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -631,7 +631,7 @@ hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void * static lcback_ret_t l_call (WListbox * list) { - Dlg_head *dlg = list->widget.owner; + Dlg_head *dlg = WIDGET (list)->owner; if (list->count != 0) { diff --git a/src/filemanager/info.c b/src/filemanager/info.c index b57dd8b76..35ebf3e2a 100644 --- a/src/filemanager/info.c +++ b/src/filemanager/info.c @@ -73,32 +73,34 @@ static struct my_statfs myfs_stats; /* --------------------------------------------------------------------------------------------- */ static void -info_box (struct WInfo *info) +info_box (WInfo *info) { + Widget *w = WIDGET (info); + const char *title = _("Information"); const int len = str_term_width1 (title); tty_set_normal_attrs (); tty_setcolor (NORMAL_COLOR); - widget_erase (&info->widget); - draw_box (info->widget.owner, info->widget.y, info->widget.x, - info->widget.lines, info->widget.cols, FALSE); + widget_erase (w); + draw_box (w->owner, w->y, w->x, w->lines, w->cols, FALSE); - widget_move (&info->widget, 0, (info->widget.cols - len - 2) / 2); + widget_move (w, 0, (w->cols - len - 2) / 2); tty_printf (" %s ", title); - widget_move (&info->widget, 2, 0); + widget_move (w, 2, 0); tty_print_alt_char (ACS_LTEE, FALSE); - widget_move (&info->widget, 2, info->widget.cols - 1); + widget_move (w, 2, w->cols - 1); tty_print_alt_char (ACS_RTEE, FALSE); - tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2); + tty_draw_hline (w->y + 2, w->x + 1, ACS_HLINE, w->cols - 2); } /* --------------------------------------------------------------------------------------------- */ static void -info_show_info (struct WInfo *info) +info_show_info (WInfo *info) { + Widget *w = WIDGET (info); static int i18n_adjust = 0; static const char *file_label; GString *buff; @@ -110,7 +112,7 @@ info_show_info (struct WInfo *info) info_box (info); tty_setcolor (MARKED_COLOR); - widget_move (&info->widget, 1, 3); + widget_move (w, 1, 3); tty_printf (_("Midnight Commander %s"), VERSION); if (!info->ready) @@ -142,14 +144,14 @@ info_show_info (struct WInfo *info) buff = g_string_new (""); - switch (info->widget.lines - 2) + switch (w->lines - 2) { /* Note: all cases are fall-throughs */ default: case 16: - widget_move (&info->widget, 16, 3); + widget_move (w, 16, 3); if (myfs_stats.nfree == 0 && myfs_stats.nodes == 0) tty_print_string (_("No node information")); else @@ -160,7 +162,7 @@ info_show_info (struct WInfo *info) (int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes)); case 15: - widget_move (&info->widget, 15, 3); + widget_move (w, 15, 3); if (myfs_stats.avail == 0 && myfs_stats.total == 0) tty_print_string (_("No space information")); else @@ -175,36 +177,36 @@ info_show_info (struct WInfo *info) } case 14: - widget_move (&info->widget, 14, 3); + widget_move (w, 14, 3); tty_printf (_("Type: %s"), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs")); if (myfs_stats.type != 0xffff && myfs_stats.type != -1) tty_printf (" (%Xh)", myfs_stats.type); case 13: - widget_move (&info->widget, 13, 3); + widget_move (w, 13, 3); str_printf (buff, _("Device: %s"), - str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust)); + str_trunc (myfs_stats.device, w->cols - i18n_adjust)); tty_print_string (buff->str); g_string_set_size (buff, 0); case 12: - widget_move (&info->widget, 12, 3); + widget_move (w, 12, 3); str_printf (buff, _("Filesystem: %s"), - str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust)); + str_trunc (myfs_stats.mpoint, w->cols - i18n_adjust)); tty_print_string (buff->str); g_string_set_size (buff, 0); case 11: - widget_move (&info->widget, 11, 3); + widget_move (w, 11, 3); str_printf (buff, _("Accessed: %s"), file_date (st.st_atime)); tty_print_string (buff->str); g_string_set_size (buff, 0); case 10: - widget_move (&info->widget, 10, 3); + widget_move (w, 10, 3); str_printf (buff, _("Modified: %s"), file_date (st.st_mtime)); tty_print_string (buff->str); g_string_set_size (buff, 0); case 9: - widget_move (&info->widget, 9, 3); + widget_move (w, 9, 3); /* The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.). */ /* TRANSLATORS: Time of last status change as in stat(2) man. */ @@ -213,7 +215,7 @@ info_show_info (struct WInfo *info) g_string_set_size (buff, 0); case 8: - widget_move (&info->widget, 8, 3); + widget_move (w, 8, 3); #ifdef HAVE_STRUCT_STAT_ST_RDEV if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode)) tty_printf (_("Dev. type: major %lu, minor %lu"), @@ -231,29 +233,29 @@ info_show_info (struct WInfo *info) } case 7: - widget_move (&info->widget, 7, 3); + widget_move (w, 7, 3); tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid)); case 6: - widget_move (&info->widget, 6, 3); + widget_move (w, 6, 3); tty_printf (_("Links: %d"), (int) st.st_nlink); case 5: - widget_move (&info->widget, 5, 3); + widget_move (w, 5, 3); tty_printf (_("Mode: %s (%04o)"), string_perm (st.st_mode), (unsigned) st.st_mode & 07777); case 4: - widget_move (&info->widget, 4, 3); + widget_move (w, 4, 3); tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino); case 3: { const char *fname; - widget_move (&info->widget, 3, 2); + widget_move (w, 3, 2); fname = current_panel->dir.list[current_panel->selected].fname; - str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust)); + str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); tty_print_string (buff->str); } @@ -276,7 +278,7 @@ info_hook (void *data) other_widget = get_panel_widget (get_current_index ()); if (!other_widget) return; - if (dlg_overlap (&info->widget, other_widget)) + if (dlg_overlap (WIDGET (info), other_widget)) return; info->ready = 1; @@ -323,12 +325,14 @@ info_callback (Widget * w, widget_msg_t msg, int parm) WInfo * info_new (int y, int x, int lines, int cols) { - struct WInfo *info = g_new (struct WInfo, 1); - - init_widget (&info->widget, y, x, lines, cols, info_callback, NULL); + WInfo *info; + Widget *w; + info = g_new (struct WInfo, 1); + w = WIDGET (info); + init_widget (w, y, x, lines, cols, info_callback, NULL); /* We do not want the cursor */ - widget_want_cursor (info->widget, 0); + widget_want_cursor (w, FALSE); return info; } diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 724610571..518aa783f 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -233,7 +233,7 @@ update_split (const Dlg_head * h) check_options[6].widget->state = _panels_layout.horizontal_equal ? 1 : 0; else check_options[6].widget->state = _panels_layout.vertical_equal ? 1 : 0; - send_message ((Widget *) check_options[6].widget, WIDGET_DRAW, 0); + send_message (WIDGET (check_options[6].widget), WIDGET_DRAW, 0); tty_setcolor (check_options[6].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL); @@ -275,7 +275,7 @@ b_left_right_cback (WButton * button, int action) _panels_layout.left_panel_size--; } - update_split (button->widget.owner); + update_split (WIDGET (button)->owner); return 0; } @@ -373,7 +373,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d return MSG_HANDLED; case DLG_ACTION: - if (sender == (Widget *) radio_widget) + if (sender == WIDGET (radio_widget)) { if (_panels_layout.horizontal_split != radio_widget->sel) { @@ -396,7 +396,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d return MSG_HANDLED; } - if (sender == (Widget *) check_options[6].widget) + if (sender == WIDGET (check_options[6].widget)) { int eq; @@ -411,10 +411,10 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d eq = _panels_layout.vertical_equal; } - widget_disable (bleft_widget->widget, eq); - send_message ((Widget *) bleft_widget, WIDGET_DRAW, 0); - widget_disable (bright_widget->widget, eq); - send_message ((Widget *) bright_widget, WIDGET_DRAW, 0); + widget_disable (WIDGET (bleft_widget), eq); + send_message (WIDGET (bleft_widget), WIDGET_DRAW, 0); + widget_disable (WIDGET (bright_widget), eq); + send_message (WIDGET (bright_widget), WIDGET_DRAW, 0); update_split (h); @@ -541,17 +541,17 @@ init_layout (void) const int disabled = mc_global.tty.console_flag != '\0' ? 0 : W_DISABLED; Widget *w; - w = (Widget *) button_new (9, output_lines_label_len + 5 + 5, B_MINUS, - NARROW_BUTTON, "&-", bminus_cback); + w = WIDGET (button_new (9, output_lines_label_len + 5 + 5, B_MINUS, + NARROW_BUTTON, "&-", bminus_cback)); w->options |= disabled; add_widget (layout_dlg, w); - w = (Widget *) button_new (9, output_lines_label_len + 5, B_PLUS, - NARROW_BUTTON, "&+", bplus_cback); + w = WIDGET (button_new (9, output_lines_label_len + 5, B_PLUS, + NARROW_BUTTON, "&+", bplus_cback)); w->options |= disabled; add_widget (layout_dlg, w); - w = (Widget *) groupbox_new (8, 3, 3, l1, title2); + w = WIDGET (groupbox_new (8, 3, 3, l1, title2)); w->options |= disabled; add_widget (layout_dlg, w); } @@ -561,11 +561,11 @@ init_layout (void) /* "Panel split" groupbox */ bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback); - widget_disable (bright_widget->widget, equal_split); + widget_disable (WIDGET (bright_widget), equal_split); add_widget (layout_dlg, bright_widget); bleft_widget = button_new (6, 8, B_2LEFT, NARROW_BUTTON, "&<", b_left_right_cback); - widget_disable (bleft_widget->widget, equal_split); + widget_disable (WIDGET (bleft_widget), equal_split); add_widget (layout_dlg, bleft_widget); check_options[6].widget = check_new (5, 5, XTRACT (6)); @@ -599,17 +599,17 @@ panel_do_cols (int idx) static Widget * restore_into_right_dir_panel (int idx, Widget * from_widget) { - Widget *new_widget = NULL; + WPanel *new_widget; const char *saved_dir = panels[idx].last_saved_dir; gboolean last_was_panel = (from_widget && get_display_type (idx) != view_listing); const char *p_name = get_nth_panel_name (idx); if (last_was_panel) - new_widget = (Widget *) panel_new_with_dir (p_name, saved_dir); + new_widget = panel_new_with_dir (p_name, saved_dir); else - new_widget = (Widget *) panel_new (p_name); + new_widget = panel_new (p_name); - return new_widget; + return WIDGET (new_widget); } /* --------------------------------------------------------------------------------------------- */ @@ -714,7 +714,7 @@ setup_panels (void) panel_do_cols (0); panel_do_cols (1); - widget_set_size (&the_menubar->widget, 0, 0, 1, COLS); + widget_set_size (WIDGET (the_menubar), 0, 0, 1, COLS); if (command_prompt) { @@ -725,12 +725,12 @@ setup_panels (void) } else { - widget_set_size (&cmdline->widget, 0, 0, 0, 0); + widget_set_size (WIDGET (cmdline), 0, 0, 0, 0); input_set_origin (cmdline, 0, 0); - widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0); + widget_set_size (WIDGET (the_prompt), LINES, COLS, 0, 0); } - widget_set_size (&the_bar->widget, LINES - 1, 0, mc_global.keybar_visible, COLS); + widget_set_size (WIDGET (the_bar), LINES - 1, 0, mc_global.keybar_visible, COLS); buttonbar_set_visible (the_bar, mc_global.keybar_visible); /* Output window */ @@ -743,9 +743,9 @@ setup_panels (void) } if (mc_global.message_visible) - widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS); + widget_set_size (WIDGET (the_hint), height + start_y, 0, 1, COLS); else - widget_set_size (&the_hint->widget, 0, 0, 0, 0); + widget_set_size (WIDGET (the_hint), 0, 0, 0, 0); update_xterm_title_path (); } @@ -831,10 +831,10 @@ setup_cmdline (void) y = LINES - 1 - mc_global.keybar_visible; - widget_set_size ((Widget *) the_prompt, y, 0, 1, prompt_len); + widget_set_size (WIDGET (the_prompt), y, 0, 1, prompt_len); label_set_text (the_prompt, mc_prompt); - widget_set_size ((Widget *) cmdline, y, prompt_len, 1, COLS - prompt_len); - input_set_origin ((WInput *) cmdline, prompt_len, COLS - prompt_len); + widget_set_size (WIDGET (cmdline), y, prompt_len, 1, COLS - prompt_len); + input_set_origin (cmdline, prompt_len, COLS - prompt_len); } /* --------------------------------------------------------------------------------------------- */ @@ -982,15 +982,15 @@ set_display_type (int num, panel_view_mode_t type) break; case view_info: - new_widget = (Widget *) info_new (y, x, lines, cols); + new_widget = WIDGET (info_new (y, x, lines, cols)); break; case view_tree: - new_widget = (Widget *) tree_new (y, x, lines, cols, TRUE); + new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE)); break; case view_quick: - new_widget = (Widget *) mcview_new (y, x, lines, cols, TRUE); + new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE)); the_other_panel = (WPanel *) panels[the_other].widget; if (the_other_panel != NULL) file_name = the_other_panel->dir.list[the_other_panel->selected].fname; @@ -1199,7 +1199,7 @@ get_panel_widget (int idx) int get_current_index (void) { - if (panels[0].widget == ((Widget *) current_panel)) + if (panels[0].widget == WIDGET (current_panel)) return 0; else return 1; @@ -1227,7 +1227,7 @@ get_other_panel (void) panel_view_mode_t get_current_type (void) { - if (panels[0].widget == (Widget *) current_panel) + if (panels[0].widget == WIDGET (current_panel)) return panels[0].type; else return panels[1].type; @@ -1239,7 +1239,7 @@ get_current_type (void) panel_view_mode_t get_other_type (void) { - if (panels[0].widget == (Widget *) current_panel) + if (panels[0].widget == WIDGET (current_panel)) return panels[1].type; else return panels[0].type; diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 5e28efc3f..2ee9b599b 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -541,7 +541,7 @@ print_vfs_message (const gchar * event_group_name, const gchar * event_name, if (mc_global.midnight_shutdown) return TRUE; - if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner) + if (!mc_global.message_visible || the_hint == NULL || WIDGET (the_hint)->owner == NULL) { int col, row; @@ -672,7 +672,7 @@ create_panels (void) the_hint = label_new (0, 0, 0); the_hint->transparent = 1; the_hint->auto_adjust_cols = 0; - the_hint->widget.cols = COLS; + WIDGET (the_hint)->cols = COLS; the_menubar = menubar_new (0, 0, COLS, NULL); } @@ -1094,10 +1094,10 @@ static void update_dirty_panels (void) { if (get_current_type () == view_listing && current_panel->dirty) - send_message ((Widget *) current_panel, WIDGET_DRAW, 0); + send_message (WIDGET (current_panel), WIDGET_DRAW, 0); if (get_other_type () == view_listing && other_panel->dirty) - send_message ((Widget *) other_panel, WIDGET_DRAW, 0); + send_message (WIDGET (other_panel), WIDGET_DRAW, 0); } /* --------------------------------------------------------------------------------------------- */ @@ -1110,7 +1110,7 @@ midnight_execute_cmd (Widget * sender, unsigned long command) (void) sender; /* stop quick search before executing any command */ - send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop); + send_message (WIDGET (current_panel), WIDGET_COMMAND, CK_SearchStop); switch (command) { @@ -1238,10 +1238,10 @@ midnight_execute_cmd (Widget * sender, unsigned long command) break; case CK_History: /* show the history of command line widget */ - send_message (&cmdline->widget, WIDGET_COMMAND, CK_History); + send_message (WIDGET (cmdline), WIDGET_COMMAND, CK_History); break; case CK_PanelInfo: - if (sender == (Widget *) the_menubar) + if (sender == WIDGET (the_menubar)) info_cmd (); /* menu */ else info_cmd_no_menu (); /* shortcut or buttonbar */ @@ -1292,7 +1292,7 @@ midnight_execute_cmd (Widget * sender, unsigned long command) hotlist_cmd (); break; case CK_PanelQuickView: - if (sender == (Widget *) the_menubar) + if (sender == WIDGET (the_menubar)) quick_view_cmd (); /* menu */ else quick_cmd_no_menu (); /* shortcut or buttonabr */ @@ -1465,7 +1465,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void if (cmdline->buffer[i] != '\0') { - send_message ((Widget *) cmdline, WIDGET_KEY, parm); + send_message (WIDGET (cmdline), WIDGET_KEY, parm); return MSG_HANDLED; } @@ -1544,7 +1544,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void if ((get_current_type () == view_listing) && current_panel->searching) { current_panel->dirty = 1; /* FIXME: unneeded? */ - send_message ((Widget *) current_panel, WIDGET_COMMAND, CK_SearchStop); + send_message (WIDGET (current_panel), WIDGET_COMMAND, CK_SearchStop); } return MSG_HANDLED; @@ -1564,7 +1564,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void v = midnight_execute_cmd (NULL, command); if (v == MSG_NOT_HANDLED && command_prompt) - v = send_message ((Widget *) cmdline, WIDGET_KEY, parm); + v = send_message (WIDGET (cmdline), WIDGET_KEY, parm); return v; } @@ -1579,13 +1579,13 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void if (sender == NULL) return midnight_execute_cmd (NULL, parm); /* message from menu */ - if (sender == (Widget *) the_menubar) + if (sender == WIDGET (the_menubar)) return midnight_execute_cmd (sender, parm); /* message from buttonbar */ - if (sender == (Widget *) the_bar) + if (sender == WIDGET (the_bar)) { if (data != NULL) - return send_message ((Widget *) data, WIDGET_COMMAND, parm); + return send_message (WIDGET (data), WIDGET_COMMAND, parm); return midnight_execute_cmd (sender, parm); } return MSG_NOT_HANDLED; @@ -1611,7 +1611,7 @@ midnight_event (Gpm_Event * event, void *data) { /* menubar */ if (menubar_visible || the_menubar->is_active) - ret = ((Widget *) the_menubar)->mouse (event, the_menubar); + ret = WIDGET (the_menubar)->mouse (event, the_menubar); else { Widget *w; @@ -1628,7 +1628,7 @@ midnight_event (Gpm_Event * event, void *data) } if (ret == MOU_UNHANDLED) - ret = ((Widget *) the_menubar)->mouse (event, the_menubar); + ret = WIDGET (the_menubar)->mouse (event, the_menubar); } } @@ -1676,7 +1676,7 @@ load_hint (gboolean force) { char *hint; - if (the_hint->widget.owner == NULL) + if (WIDGET (the_hint)->owner == NULL) return; if (!mc_global.message_visible) diff --git a/src/filemanager/option.c b/src/filemanager/option.c index 28240d394..1aaf8ba25 100644 --- a/src/filemanager/option.c +++ b/src/filemanager/option.c @@ -83,11 +83,11 @@ configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void /* label */ w = dlg_find_by_id (h, sender->id - 1); - widget_disable (*w, not_single); + widget_disable (w, not_single); send_message (w, WIDGET_DRAW, 0); /* input */ w = dlg_find_by_id (h, sender->id - 2); - widget_disable (*w, not_single); + widget_disable (w, not_single); send_message (w, WIDGET_DRAW, 0); return MSG_HANDLED; diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 1d522005b..46e1d86b2 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -322,7 +322,7 @@ extern int saving_setup; #define STATUS 5 /* This macro extracts the number of available lines in a panel */ -#define llines(p) (p->widget.lines - 3 - (panels_options.show_mini_info ? 2 : 0)) +#define llines(p) (WIDGET (p)->lines - 3 - (panels_options.show_mini_info ? 2 : 0)) /*** file scope type declarations ****************************************************************/ @@ -884,6 +884,8 @@ format_file (char *dest, int limit, WPanel * panel, int file_index, int width, i static void repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) { + Widget *w = WIDGET (panel); + int second_column = 0; int width; int offset = 0; @@ -893,7 +895,7 @@ repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) gboolean panel_is_split = !isstatus && panel->split; int fln = 0; - width = panel->widget.cols - 2; + width = w->cols - 2; if (panel_is_split) { @@ -903,8 +905,7 @@ repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) if (second_column != 0) { offset = 1 + width; - /*width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1; */ - width = panel->widget.cols - offset - 2; + width = w->cols - offset - 2; } } @@ -922,7 +923,7 @@ repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) ypos = pos; ypos += 2; - widget_move (&panel->widget, ypos, offset + 1); + widget_move (w, ypos, offset + 1); } ret_frm = format_file (buffer, sizeof (buffer), panel, file_index, width, attr, isstatus, &fln); @@ -951,13 +952,13 @@ repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) width = fln; } } - widget_move (&panel->widget, ypos, offset); + widget_move (w, ypos, offset); tty_setcolor (NORMAL_COLOR); tty_print_string (panel_filename_scroll_left_char); if ((ret_frm & FILENAME_SCROLL_RIGHT) != 0) { - widget_move (&panel->widget, ypos, offset + 1 + width); + widget_move (w, ypos, offset + 1 + width); tty_setcolor (NORMAL_COLOR); tty_print_string (panel_filename_scroll_right_char); } @@ -969,16 +970,18 @@ repaint_file (WPanel * panel, int file_index, int mv, int attr, int isstatus) static void display_mini_info (WPanel * panel) { + Widget *w = WIDGET (panel); + if (!panels_options.show_mini_info) return; - widget_move (&panel->widget, llines (panel) + 3, 1); + widget_move (w, llines (panel) + 3, 1); if (panel->searching) { tty_setcolor (INPUT_COLOR); tty_print_char ('/'); - tty_print_string (str_fit_to_term (panel->search_buffer, panel->widget.cols - 3, J_LEFT)); + tty_print_string (str_fit_to_term (panel->search_buffer, w->cols - 3, J_LEFT)); return; } @@ -999,11 +1002,10 @@ display_mini_info (WPanel * panel) { link_target[len] = 0; tty_print_string ("-> "); - tty_print_string (str_fit_to_term (link_target, panel->widget.cols - 5, J_LEFT_FIT)); + tty_print_string (str_fit_to_term (link_target, w->cols - 5, J_LEFT_FIT)); } else - tty_print_string (str_fit_to_term (_(""), - panel->widget.cols - 2, J_LEFT)); + tty_print_string (str_fit_to_term (_(""), w->cols - 2, J_LEFT)); } else if (strcmp (panel->dir.list[panel->selected].fname, "..") == 0) { @@ -1011,7 +1013,7 @@ display_mini_info (WPanel * panel) * while loading directory (do_load_dir() and do_reload_dir()), * the actual stat info about ".." directory isn't got; * so just don't display incorrect info about ".." directory */ - tty_print_string (str_fit_to_term (_("UP--DIR"), panel->widget.cols - 2, J_LEFT)); + tty_print_string (str_fit_to_term (_("UP--DIR"), w->cols - 2, J_LEFT)); } else /* Default behavior */ @@ -1050,6 +1052,8 @@ paint_dir (WPanel * panel) static void display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only) { + Widget *w = WIDGET (panel); + char buffer[BUF_SMALL], b_bytes[BUF_SMALL], *buf; int cols; @@ -1057,7 +1061,7 @@ display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only) return; buf = size_only ? b_bytes : buffer; - cols = panel->widget.cols - 2; + cols = w->cols - 2; /* * This is a trick to use two ngettext() calls in one sentence. @@ -1076,13 +1080,13 @@ display_total_marked_size (WPanel * panel, int y, int x, gboolean size_only) if (x < 0) /* center in panel */ - x = (panel->widget.cols - str_term_width1 (buf)) / 2 - 1; + x = (w->cols - str_term_width1 (buf)) / 2 - 1; /* - * y == llines (panel) + 2 for mini_info_separator - * y == panel->widget.lines - 1 for panel bottom frame + * y == llines (panel) + 2 for mini_info_separator + * y == w->lines - 1 for panel bottom frame */ - widget_move (&panel->widget, y, x); + widget_move (w, y, x); tty_setcolor (MARKED_COLOR); tty_printf (" %s ", buf); } @@ -1094,11 +1098,11 @@ mini_info_separator (WPanel * panel) { if (panels_options.show_mini_info) { + Widget *w = WIDGET (panel); const int y = llines (panel) + 2; tty_setcolor (NORMAL_COLOR); - tty_draw_hline (panel->widget.y + y, panel->widget.x + 1, - ACS_HLINE, panel->widget.cols - 2); + tty_draw_hline (w->y + y, w->x + 1, ACS_HLINE, w->cols - 2); /* Status displays total marked size. * Centered in panel, full format. */ display_total_marked_size (panel, y, -1, FALSE); @@ -1139,7 +1143,9 @@ show_free_space (WPanel * panel) if (myfs_stats.avail != 0 || myfs_stats.total != 0) { + Widget *w = WIDGET (panel); char buffer1[6], buffer2[6], tmp[BUF_SMALL]; + size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1, panels_options.kilobyte_si); size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1, @@ -1147,8 +1153,7 @@ show_free_space (WPanel * panel) g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2, myfs_stats.total == 0 ? 0 : (int) (100 * (long double) myfs_stats.avail / myfs_stats.total)); - widget_move (&panel->widget, panel->widget.lines - 1, - panel->widget.cols - 2 - (int) strlen (tmp)); + widget_move (w, w->lines - 1, w->cols - 2 - (int) strlen (tmp)); tty_setcolor (NORMAL_COLOR); tty_print_string (tmp); } @@ -1242,32 +1247,34 @@ panel_get_encoding_info_str (WPanel * panel) static void show_dir (WPanel * panel) { + Widget *w = WIDGET (panel); + gchar *tmp; + set_colors (panel); - draw_box (panel->widget.owner, - panel->widget.y, panel->widget.x, panel->widget.lines, panel->widget.cols, FALSE); + draw_box (w->owner, w->y, w->x, w->lines, w->cols, FALSE); if (panels_options.show_mini_info) { - widget_move (&panel->widget, llines (panel) + 2, 0); + widget_move (w, llines (panel) + 2, 0); tty_print_alt_char (ACS_LTEE, FALSE); - widget_move (&panel->widget, llines (panel) + 2, panel->widget.cols - 1); + widget_move (w, llines (panel) + 2, w->cols - 1); tty_print_alt_char (ACS_RTEE, FALSE); } - widget_move (&panel->widget, 0, 1); + widget_move (w, 0, 1); tty_print_string (panel_history_prev_item_sign); tmp = panels_options.show_dot_files ? panel_hiddenfiles_sign_show : panel_hiddenfiles_sign_hide; tmp = g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_sign, panel_history_next_item_sign); - widget_move (&panel->widget, 0, panel->widget.cols - 6); + widget_move (w, 0, w->cols - 6); tty_print_string (tmp); g_free (tmp); - widget_move (&panel->widget, 0, 3); + widget_move (w, 0, 3); if (panel->is_panelized) tty_printf (" %s ", _("Panelize")); @@ -1278,7 +1285,7 @@ show_dir (WPanel * panel) if (tmp != NULL) { tty_printf ("%s", tmp); - widget_move (&panel->widget, 0, 3 + strlen (tmp)); + widget_move (w, 0, 3 + strlen (tmp)); g_free (tmp); } } @@ -1289,7 +1296,7 @@ show_dir (WPanel * panel) tmp = panel_correct_path_to_show (panel); tty_printf (" %s ", - str_term_trim (tmp, min (max (panel->widget.cols - 12, 0), panel->widget.cols))); + str_term_trim (tmp, min (max (w->cols - 12, 0), w->cols))); g_free (tmp); if (!panels_options.show_mini_info) @@ -1305,7 +1312,7 @@ show_dir (WPanel * panel) size_trunc_sep (panel->dir.list[panel->selected].st.st_size, panels_options.kilobyte_si)); tty_setcolor (NORMAL_COLOR); - widget_move (&panel->widget, panel->widget.lines - 1, 4); + widget_move (w, w->lines - 1, 4); tty_print_string (buffer); } } @@ -1313,7 +1320,7 @@ show_dir (WPanel * panel) { /* Show total size of marked files * In the bottom of panel, display size only. */ - display_total_marked_size (panel, panel->widget.lines - 1, 2, TRUE); + display_total_marked_size (panel, w->lines - 1, 2, TRUE); } } @@ -1415,7 +1422,7 @@ panel_load_history (const gchar * event_group_name, const gchar * event_name, (void) event_group_name; (void) event_name; - if (ev->receiver == NULL || ev->receiver == (Widget *) p) + if (ev->receiver == NULL || ev->receiver == WIDGET (p)) { if (ev->cfg != NULL) p->dir_history = history_load (ev->cfg, p->hist_name); @@ -1512,7 +1519,7 @@ panel_paint_sort_info (WPanel * panel) char *str; str = g_strdup_printf ("%s%s", sort_sign, Q_ (panel->sort_info.sort_field->hotkey)); - widget_move (&panel->widget, 1, 1); + widget_move (panel, 1, 1); tty_print_string (str); g_free (str); } @@ -1545,15 +1552,17 @@ panel_get_title_without_hotkey (const char *title) static void paint_frame (WPanel * panel) { + Widget *w = WIDGET (panel); + int side, width; GString *format_txt; adjust_top_file (panel); - widget_erase (&panel->widget); + widget_erase (w); show_dir (panel); - widget_move (&panel->widget, 1, 1); + widget_move (w, 1, 1); for (side = 0; side <= panel->split; side++) { @@ -1563,12 +1572,12 @@ paint_frame (WPanel * panel) { tty_setcolor (NORMAL_COLOR); tty_print_one_vline (TRUE); - width = panel->widget.cols - panel->widget.cols / 2 - 1; + width = w->cols - w->cols / 2 - 1; } else if (panel->split) - width = panel->widget.cols / 2 - 3; + width = w->cols / 2 - 3; else - width = panel->widget.cols - 2; + width = w->cols - 2; format_txt = g_string_new (""); for (format = panel->format; format; format = format->next) @@ -1654,7 +1663,7 @@ parse_panel_size (WPanel * panel, const char *format, int isstatus) } if (!isstatus) - panel_update_cols (&(panel->widget), panel->frame_size); + panel_update_cols (WIDGET (panel), panel->frame_size); return skip_separators (format); } @@ -1838,7 +1847,7 @@ use_display_format (WPanel * panel, const char *format, char **error, int isstat panel->dirty = 1; /* Status needn't to be split */ - usable_columns = ((panel->widget.cols - 2) / ((isstatus) + usable_columns = ((WIDGET (panel)->cols - 2) / ((isstatus) ? 1 : (panel->split + 1))) - (!isstatus && panel->split); @@ -2489,7 +2498,7 @@ do_search (WPanel * panel, int c_code) unselect_item (panel); panel->selected = sel; select_item (panel); - send_message ((Widget *) panel, WIDGET_DRAW, 0); + send_message (WIDGET (panel), WIDGET_DRAW, 0); } else if (c_code != KEY_BACKSPACE) { @@ -3154,7 +3163,7 @@ directory_history_list (WPanel * panel) pos = g_list_position (panel->dir_history_current, panel->dir_history); - s = history_show (&panel->dir_history, &panel->widget, pos); + s = history_show (&panel->dir_history, WIDGET (panel), pos); if (s != NULL) { vfs_path_t *s_vpath; @@ -3452,7 +3461,7 @@ panel_callback (Widget * w, widget_msg_t msg, int parm) paint_dir (panel); panel->dirty = 0; - bb = find_buttonbar (panel->widget.owner); + bb = find_buttonbar (w->owner); midnight_set_buttonbar (bb); buttonbar_redraw (bb); return MSG_HANDLED; @@ -3595,14 +3604,14 @@ static int panel_event (Gpm_Event * event, void *data) { WPanel *panel = (WPanel *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); const int lines = llines (panel); const gboolean is_active = dlg_widget_active (panel); const gboolean mouse_down = (event->type & GPM_DOWN) != 0; Gpm_Event local; - if (!mouse_global_in_widget (event, (Widget *) data)) + if (!mouse_global_in_widget (event, WIDGET (data))) return MOU_UNHANDLED; local = mouse_get_local (event, w); @@ -3822,7 +3831,7 @@ do_select (WPanel * panel, int i) { panel->dirty = 1; panel->selected = i; - panel->top_file = panel->selected - (panel->widget.lines - 2) / 2; + panel->top_file = panel->selected - (WIDGET (panel)->lines - 2) / 2; if (panel->top_file < 0) panel->top_file = 0; } @@ -4022,17 +4031,17 @@ WPanel * panel_new_with_dir (const char *panel_name, const char *wpath) { WPanel *panel; + Widget *w; char *section; int i, err; char *curdir = NULL; panel = g_new0 (WPanel, 1); - + w = WIDGET (panel); /* No know sizes of the panel at startup */ - init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event); - + init_widget (w, 0, 0, 0, 0, panel_callback, panel_event); /* We do not want the cursor */ - widget_want_cursor (panel->widget, 0); + widget_want_cursor (w, FALSE); if (wpath != NULL) { @@ -4239,7 +4248,7 @@ set_panel_formats (WPanel * p) } panel_format_modified (p); - panel_update_cols (&(p->widget), p->frame_size); + panel_update_cols (WIDGET (p), p->frame_size); if (retcode) message (D_ERROR, _("Warning"), diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 11480d274..3a8229b4d 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -82,7 +82,8 @@ int xtree_mode = 0; /*** file scope macro definitions ****************************************************************/ -#define tlines(t) (t->is_panel ? t->widget.lines - 2 - (panels_options.show_mini_info ? 2 : 0) : t->widget.lines) +#define tlines(t) (t->is_panel ? WIDGET (t)->lines - 2 - \ + (panels_options.show_mini_info ? 2 : 0) : WIDGET (t)->lines) /* Use the color of the parent widget for the unselected entries */ #define TREE_NORMALC(h) (h->color[DLG_COLOR_NORMAL]) @@ -223,7 +224,7 @@ load_tree (WTree * tree) static void tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) { - Dlg_head *h = tree->widget.owner; + Widget *w = WIDGET (tree); int line; /* Show mini info */ @@ -240,8 +241,8 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) { /* Show search string */ tty_setcolor (INPUT_COLOR); - tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); - widget_move (&tree->widget, line, 1); + tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); + widget_move (w, line, 1); tty_print_char (PATH_SEP); tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT)); tty_print_char (' '); @@ -249,11 +250,12 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) else { /* Show full name of selected directory */ + Dlg_head *h = w->owner; char *tmp_path; tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); - tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols); - widget_move (&tree->widget, line, 1); + tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols); + widget_move (w, line, 1); tmp_path = vfs_path_to_str (tree->selected_ptr->name); tty_print_string (str_fit_to_term (tmp_path, tree_cols, J_LEFT_FIT)); g_free (tmp_path); @@ -265,7 +267,8 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols) static void show_tree (WTree * tree) { - Dlg_head *h = tree->widget.owner; + Widget *w = WIDGET (tree); + Dlg_head *h = w->owner; tree_entry *current; int i, j, topsublevel; int x = 0, y = 0; @@ -273,9 +276,9 @@ show_tree (WTree * tree) /* Initialize */ tree_lines = tlines (tree); - tree_cols = tree->widget.cols; + tree_cols = w->cols; - widget_move ((Widget *) tree, y, x); + widget_move (w, y, x); if (tree->is_panel) { tree_cols -= 2; @@ -341,7 +344,7 @@ show_tree (WTree * tree) tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h)); /* Move to the beginning of the line */ - tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols); + tty_draw_hline (w->y + y + i, w->x + x, ' ', tree_cols); if (current == NULL) continue; @@ -633,7 +636,7 @@ static int tree_event (Gpm_Event * event, void *data) { WTree *tree = (WTree *) data; - Widget *w = (Widget *) data; + Widget *w = WIDGET (data); Gpm_Event local; if (!mouse_global_in_widget (event, w)) @@ -1040,9 +1043,9 @@ static void tree_toggle_navig (WTree * tree) { tree_navigation_flag = !tree_navigation_flag; - buttonbar_set_label (find_buttonbar (tree->widget.owner), 4, + buttonbar_set_label (find_buttonbar (WIDGET (tree)->owner), 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") - : Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree); + : Q_ ("ButtonBar|Dynamc"), tree_map, WIDGET (tree)); } /* --------------------------------------------------------------------------------------------- */ @@ -1107,7 +1110,7 @@ tree_execute_cmd (WTree * tree, unsigned long command) break; case CK_Quit: if (!tree->is_panel) - dlg_stop (((Widget *) tree)->owner); + dlg_stop (WIDGET (tree)->owner); return res; default: res = MSG_NOT_HANDLED; @@ -1174,25 +1177,26 @@ tree_key (WTree * tree, int key) static void tree_frame (Dlg_head * h, WTree * tree) { + Widget *w = WIDGET (tree); + tty_setcolor (NORMAL_COLOR); - widget_erase ((Widget *) tree); + widget_erase (w); if (tree->is_panel) { const char *title = _("Directory tree"); const int len = str_term_width1 (title); - draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE); + draw_box (h, w->y, w->x, w->lines, w->cols, FALSE); - widget_move (&tree->widget, 0, (tree->widget.cols - len - 2) / 2); + widget_move (w, 0, (w->cols - len - 2) / 2); tty_printf (" %s ", title); if (panels_options.show_mini_info) - widget_move (&tree->widget, tlines (tree) + 1, 0); + widget_move (w, tlines (tree) + 1, 0); tty_print_alt_char (ACS_LTEE, FALSE); - widget_move (&tree->widget, tlines (tree) + 1, tree->widget.cols - 1); + widget_move (w, tlines (tree) + 1, w->cols - 1); tty_print_alt_char (ACS_RTEE, FALSE); - tty_draw_hline (tree->widget.y + tlines (tree) + 1, - tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2); + tty_draw_hline (w->y + tlines (tree) + 1, w->x + 1, ACS_HLINE, w->cols - 2); } } @@ -1202,7 +1206,7 @@ static cb_ret_t tree_callback (Widget * w, widget_msg_t msg, int parm) { WTree *tree = (WTree *) w; - Dlg_head *h = tree->widget.owner; + Dlg_head *h = w->owner; WButtonBar *b = find_buttonbar (h); switch (msg) @@ -1214,20 +1218,20 @@ tree_callback (Widget * w, widget_msg_t msg, int parm) case WIDGET_FOCUS: tree->active = 1; - buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, (Widget *) tree); - buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, (Widget *) tree); - buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, (Widget *) tree); + buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, w); + buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, w); + buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, w); buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") - : Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree); - buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, (Widget *) tree); - buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, (Widget *) tree); + : Q_ ("ButtonBar|Dynamc"), tree_map, w); + buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, w); + buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, w); #if 0 /* FIXME: mkdir is currently defunct */ - buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, (Widget *) tree); + buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, w); #else - buttonbar_clear_label (b, 7, (Widget *) tree); + buttonbar_clear_label (b, 7, WIDGET (tree)); #endif - buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, (Widget *) tree); + buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, w); buttonbar_redraw (b); /* FIXME: Should find a better way of only displaying the @@ -1267,9 +1271,13 @@ tree_callback (Widget * w, widget_msg_t msg, int parm) WTree * tree_new (int y, int x, int lines, int cols, gboolean is_panel) { - WTree *tree = g_new (WTree, 1); + WTree *tree; + Widget *w; + + tree = g_new (WTree, 1); + w = WIDGET (tree); - init_widget (&tree->widget, y, x, lines, cols, tree_callback, tree_event); + init_widget (w, y, x, lines, cols, tree_callback, tree_event); tree->is_panel = is_panel; tree->selected_ptr = 0; @@ -1277,12 +1285,12 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel) tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; - tree->topdiff = tree->widget.lines / 2; + tree->topdiff = w->lines / 2; tree->searching = 0; tree->active = 0; /* We do not want to keep the cursor */ - widget_want_cursor (tree->widget, 0); + widget_want_cursor (w, FALSE); load_tree (tree); return tree; } diff --git a/src/help.c b/src/help.c index f2552cb9b..0b5a4056a 100644 --- a/src/help.c +++ b/src/help.c @@ -603,7 +603,7 @@ help_show (Dlg_head * h, const char *paint_start) static int help_event (Gpm_Event * event, void *vp) { - Widget *w = (Widget *) vp; + Widget *w = WIDGET (vp); GSList *current_area; Gpm_Event local; @@ -951,7 +951,7 @@ help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *dat help_lines = min (LINES - 4, max (2 * LINES / 3, 18)); dlg_set_size (h, help_lines + 4, HELP_WINDOW_WIDTH + 4); bb = find_buttonbar (h); - widget_set_size (&bb->widget, LINES - 1, 0, 1, COLS); + widget_set_size (WIDGET (bb), LINES - 1, 0, 1, COLS); return MSG_HANDLED; case DLG_DRAW: @@ -967,10 +967,10 @@ help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *dat if (sender == NULL) return help_execute_cmd (parm); /* message from buttonbar */ - if (sender == (Widget *) find_buttonbar (h)) + if (sender == WIDGET (find_buttonbar (h))) { if (data != NULL) - return send_message ((Widget *) data, WIDGET_COMMAND, parm); + return send_message (WIDGET (data), WIDGET_COMMAND, parm); return help_execute_cmd (parm); } return MSG_NOT_HANDLED; @@ -1129,8 +1129,8 @@ help_interactive_display (const gchar * event_group_name, const gchar * event_na } help_bar = buttonbar_new (TRUE); - help_bar->widget.y -= WIDGET (whelp)->y; - help_bar->widget.x -= WIDGET (whelp)->x; + WIDGET (help_bar)->y -= WIDGET (whelp)->y; + WIDGET (help_bar)->x -= WIDGET (whelp)->x; md = mousedispatch_new (1, 1, help_lines, HELP_WINDOW_WIDTH - 2); diff --git a/src/learn.c b/src/learn.c index 191b5f5a2..9d4f7614a 100644 --- a/src/learn.c +++ b/src/learn.c @@ -166,7 +166,7 @@ learn_move (int 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 (learn_dlg->current->data)) { if (right) { @@ -324,9 +324,11 @@ init_learn (void) learnkeys[i].ok = 0; learnkeys[i].sequence = NULL; g_snprintf (buffer, sizeof (buffer), "%-16s", _(key->longname)); - add_widget (learn_dlg, learnkeys[i].button = (Widget *) - button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button)); - add_widget (learn_dlg, learnkeys[i].label = (Widget *) label_new (y, x + 19, "")); + learnkeys[i].button = + WIDGET (button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button)); + add_widget (learn_dlg, learnkeys[i].button); + learnkeys[i].label = WIDGET (label_new (y, x + 19, "")); + add_widget (learn_dlg, learnkeys[i].label); if (i % 13) y--; else diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 6317c72cb..7d3d8cc32 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -497,7 +497,7 @@ mcview_execute_cmd (mcview_t * view, unsigned long command) break; case CK_Quit: if (!mcview_is_in_panel (view)) - dlg_stop (view->widget.owner); + dlg_stop (WIDGET (view)->owner); break; case CK_Cancel: /* don't close viewer due to SIGINT */ @@ -560,8 +560,8 @@ mcview_adjust_size (Dlg_head * h) view = (mcview_t *) find_widget_type (h, mcview_callback); b = find_buttonbar (h); - widget_set_size (&view->widget, 0, 0, LINES - 1, COLS); - widget_set_size (&b->widget, LINES - 1, 0, 1, COLS); + widget_set_size (WIDGET (view), 0, 0, LINES - 1, COLS); + widget_set_size (WIDGET (b), LINES - 1, 0, 1, COLS); mcview_compute_areas (view); mcview_update_bytes_per_line (view); @@ -648,10 +648,10 @@ mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, if (sender == NULL) return mcview_execute_cmd (NULL, parm); /* message from buttonbar */ - if (sender == (Widget *) find_buttonbar (h)) + if (sender == WIDGET (find_buttonbar (h))) { if (data != NULL) - return send_message ((Widget *) data, WIDGET_COMMAND, parm); + return send_message (WIDGET (data), WIDGET_COMMAND, parm); view = (mcview_t *) find_widget_type (h, mcview_callback); return mcview_execute_cmd (view, parm); diff --git a/src/viewer/display.c b/src/viewer/display.c index 45381022d..69cb61406 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -80,48 +80,48 @@ static enum ruler_type static void mcview_set_buttonbar (mcview_t * view) { - Dlg_head *h = view->widget.owner; + Dlg_head *h = WIDGET (view)->owner; WButtonBar *b = find_buttonbar (h); const global_keymap_t *keymap = view->hex_mode ? viewer_hex_map : viewer_map; - buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, (Widget *) view); + buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, WIDGET (view)); if (view->hex_mode) { if (view->hexedit_mode) - buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, (Widget *) view); + buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, WIDGET (view)); else if (view->datasource == DS_FILE) - buttonbar_set_label (b, 2, Q_ ("ButtonBar|Edit"), keymap, (Widget *) view); + buttonbar_set_label (b, 2, Q_ ("ButtonBar|Edit"), keymap, WIDGET (view)); else - buttonbar_set_label (b, 2, "", keymap, (Widget *) view); + buttonbar_set_label (b, 2, "", keymap, WIDGET (view)); - buttonbar_set_label (b, 4, Q_ ("ButtonBar|Ascii"), keymap, (Widget *) view); - buttonbar_set_label (b, 6, Q_ ("ButtonBar|Save"), keymap, (Widget *) view); - buttonbar_set_label (b, 7, Q_ ("ButtonBar|HxSrch"), keymap, (Widget *) view); + buttonbar_set_label (b, 4, Q_ ("ButtonBar|Ascii"), keymap, WIDGET (view)); + buttonbar_set_label (b, 6, Q_ ("ButtonBar|Save"), keymap, WIDGET (view)); + buttonbar_set_label (b, 7, Q_ ("ButtonBar|HxSrch"), keymap, WIDGET (view)); } else { buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap") - : Q_ ("ButtonBar|Wrap"), keymap, (Widget *) view); - buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, (Widget *) view); - buttonbar_set_label (b, 6, "", keymap, (Widget *) view); - buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, (Widget *) view); + : Q_ ("ButtonBar|Wrap"), keymap, WIDGET (view)); + buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, WIDGET (view)); + buttonbar_set_label (b, 6, "", keymap, WIDGET (view)); + buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, WIDGET (view)); } - buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, (Widget *) view); + buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, WIDGET (view)); buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") - : Q_ ("ButtonBar|Parse"), keymap, (Widget *) view); + : Q_ ("ButtonBar|Parse"), keymap, WIDGET (view)); if (mcview_is_in_panel (view)) - buttonbar_set_label (b, 10, "", keymap, (Widget *) view); + buttonbar_set_label (b, 10, "", keymap, WIDGET (view)); else { /* don't override some panel buttonbar keys */ - buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view); + buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); buttonbar_set_label (b, 9, view->text_nroff_mode ? Q_ ("ButtonBar|Unform") - : Q_ ("ButtonBar|Format"), keymap, (Widget *) view); - buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, (Widget *) view); + : Q_ ("ButtonBar|Format"), keymap, WIDGET (view)); + buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); } } @@ -140,7 +140,7 @@ mcview_display_status (mcview_t * view) return; tty_setcolor (STATUSBAR_COLOR); - tty_draw_hline (view->widget.y + top, view->widget.x + left, ' ', width); + tty_draw_hline (WIDGET (view)->y + top, WIDGET (view)->x + left, ' ', width); file_label = view->filename_vpath != NULL ? @@ -189,7 +189,7 @@ mcview_update (mcview_t * view) { view->dpy_bbar_dirty = FALSE; mcview_set_buttonbar (view); - buttonbar_redraw (find_buttonbar (view->widget.owner)); + buttonbar_redraw (find_buttonbar (WIDGET (view)->owner)); } if (view->dirty > dirt_limit) @@ -259,8 +259,8 @@ mcview_compute_areas (mcview_t * view) view_area.top = view->dpy_frame_size; view_area.left = view->dpy_frame_size; - view_area.height = mcview_dimen_doz (view->widget.lines, 2 * view->dpy_frame_size); - view_area.width = mcview_dimen_doz (view->widget.cols, 2 * view->dpy_frame_size); + view_area.height = mcview_dimen_doz (WIDGET (view)->lines, 2 * view->dpy_frame_size); + view_area.width = mcview_dimen_doz (WIDGET (view)->cols, 2 * view->dpy_frame_size); /* Most coordinates of the areas equal those of the whole viewer */ view->status_area = view_area; @@ -344,10 +344,12 @@ mcview_display_toggle_ruler (mcview_t * view) void mcview_display_clean (mcview_t * view) { + Widget *w = WIDGET (view); + tty_setcolor (NORMAL_COLOR); - widget_erase ((Widget *) view); + widget_erase (w); if (view->dpy_frame_size != 0) - tty_draw_box (view->widget.y, view->widget.x, view->widget.lines, view->widget.cols, FALSE); + tty_draw_box (w->y, w->x, w->lines, w->cols, FALSE); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 7f20ce68b..375a88cfd 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -140,13 +140,13 @@ mcview_toggle_hex_mode (mcview_t * view) { view->hex_cursor = view->dpy_start; view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line); - widget_want_cursor (view->widget, 1); + widget_want_cursor (WIDGET (view), TRUE); } else { view->dpy_start = mcview_bol (view, view->hex_cursor, 0); view->hex_cursor = view->dpy_start; - widget_want_cursor (view->widget, 0); + widget_want_cursor (WIDGET (view), FALSE); } mcview_altered_hex_mode = 1; view->dpy_bbar_dirty = TRUE; diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 4ba824dda..95d39c107 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -90,7 +90,7 @@ do_mcview_event (mcview_t * view, Gpm_Event * event, int *result) { screen_dimen y, x; Gpm_Event local; - Widget *w = (Widget *) view; + Widget *w = WIDGET (view); /* rest of the upper frame - call menu */ if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) != 0 && @@ -181,7 +181,7 @@ mcview_event (Gpm_Event * event, void *data) mcview_t *view = (mcview_t *) data; int result; - if (!mouse_global_in_widget (event, (Widget *) data)) + if (!mouse_global_in_widget (event, WIDGET (data))) return MOU_UNHANDLED; if (do_mcview_event (view, event, &result)) @@ -196,9 +196,10 @@ mcview_event (Gpm_Event * event, void *data) mcview_t * mcview_new (int y, int x, int lines, int cols, gboolean is_panel) { - mcview_t *view = g_new0 (mcview_t, 1); + mcview_t *view; - init_widget (&view->widget, y, x, lines, cols, mcview_callback, mcview_event); + view = g_new0 (mcview_t, 1); + init_widget (WIDGET (view), y, x, lines, cols, mcview_callback, mcview_event); view->hex_mode = FALSE; view->hexedit_mode = FALSE; diff --git a/src/viewer/move.c b/src/viewer/move.c index f30206128..23ab02265 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -480,7 +480,7 @@ mcview_place_cursor (mcview_t * view) screen_dimen col = view->cursor_col; if (!view->hexview_in_text && view->hexedit_lownibble) col++; - widget_move (&view->widget, top + view->cursor_row, left + col); + widget_move (view, top + view->cursor_row, left + col); } /* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT