From 31f491b01ee2fb4a60725f5e59ff1eafb45a6a1b Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 13 Nov 2002 02:27:00 +0000 Subject: [PATCH] * dlg.h: Remove Dlg_head argument from callback_fn - it's excessive and can be trivially derived from the widget. (default_proc): Remove Dlg_head argument. Change all callers. * widget.c (listbox_draw): Remove Dlg_head argument. --- src/ChangeLog | 5 ++++ src/command.c | 4 +-- src/dlg.c | 12 ++++---- src/dlg.h | 4 +-- src/help.c | 4 +-- src/info.c | 4 +-- src/menu.c | 4 +-- src/screen.c | 10 ++++--- src/tree.c | 16 ++++++----- src/view.c | 7 +++-- src/widget.c | 80 +++++++++++++++++++++++++++++---------------------- src/widget.h | 2 +- 12 files changed, 86 insertions(+), 66 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b15eecfe4..d2fb75af0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2002-11-12 Pavel Roskin + * dlg.h: Remove Dlg_head argument from callback_fn - it's + excessive and can be trivially derived from the widget. + (default_proc): Remove Dlg_head argument. Change all callers. + * widget.c (listbox_draw): Remove Dlg_head argument. + * dlg.h: Define dlg_cb_fn - dialog callback function. Improve typedefs for callbacks and use them everywhere. Clean up some unused defines. diff --git a/src/command.c b/src/command.c index 447275da9..f2111c37c 100644 --- a/src/command.c +++ b/src/command.c @@ -242,7 +242,7 @@ enter (WInput * cmdline) } static int -command_callback (Dlg_head * h, WInput * cmd, int msg, int par) +command_callback (WInput *cmd, int msg, int par) { switch (msg) { case WIDGET_FOCUS: @@ -255,7 +255,7 @@ command_callback (Dlg_head * h, WInput * cmd, int msg, int par) return enter (cmd); } } - return input_callback (h, cmd, msg, par); + return input_callback (cmd, msg, par); } WInput * diff --git a/src/dlg.c b/src/dlg.c index fdcd0cc27..698d01304 100644 --- a/src/dlg.c +++ b/src/dlg.c @@ -141,7 +141,7 @@ init_widget (Widget *w, int y, int x, int lines, int cols, } /* Default callback for widgets */ -int default_proc (Dlg_head *h, int Msg, int Par) +int default_proc (int Msg, int Par) { switch (Msg){ @@ -314,7 +314,7 @@ int add_widget (Dlg_head *where, void *what) int send_message (Dlg_head *h, Widget *w, int msg, int par) { - return (*(w->callback))(h, w, msg, par); + return (*(w->callback))(w, msg, par); } /* broadcast a message to all the widgets in a dialog that have @@ -514,7 +514,7 @@ void update_cursor (Dlg_head *h) do { if (p->widget->options & W_WANT_CURSOR) - if ((*p->widget->callback)(h, p->widget, WIDGET_CURSOR, 0)){ + if ((*p->widget->callback)(p->widget, WIDGET_CURSOR, 0)){ break; } p = p->next; @@ -626,7 +626,7 @@ static int dlg_try_hotkey (Dlg_head *h, int d_key) handled = 0; if (h->current->widget->options & W_WANT_HOTKEY) - handled = callback (h) (h, h->current->widget, WIDGET_HOTKEY, d_key); + handled = callback (h) (h->current->widget, WIDGET_HOTKEY, d_key); /* If not used, send hotkey to other widgets */ if (handled) @@ -638,7 +638,7 @@ static int dlg_try_hotkey (Dlg_head *h, int d_key) do { if (hot_cur->widget->options & W_WANT_HOTKEY) handled |= (*hot_cur->widget->callback) - (h, hot_cur->widget, WIDGET_HOTKEY, d_key); + (hot_cur->widget, WIDGET_HOTKEY, d_key); if (!handled) hot_cur = hot_cur->next; @@ -687,7 +687,7 @@ dlg_key_event (Dlg_head * h, int d_key) /* not used - then try widget_callback */ if (!handled) handled |= - callback (h) (h, h->current->widget, WIDGET_KEY, d_key); + callback (h) (h->current->widget, WIDGET_KEY, d_key); /* not used- try to use the unhandled case */ if (!handled) diff --git a/src/dlg.h b/src/dlg.h index 3f9db8099..dee13f29f 100644 --- a/src/dlg.h +++ b/src/dlg.h @@ -102,7 +102,7 @@ typedef struct Dlg_head { typedef void (*destroy_fn)(void *widget); /* Widget callback */ -typedef int (*callback_fn)(Dlg_head *h, void *widget, int Msg, int Par); +typedef int (*callback_fn)(void *widget, int Msg, int Par); /* Every Widget must have this as it's first element */ typedef struct Widget { @@ -178,7 +178,7 @@ void init_widget (Widget *w, int y, int x, int lines, int cols, int default_dlg_callback (Dlg_head *h, int id, int msg); /* Default callback for widgets */ -int default_proc (Dlg_head *h, int Msg, int Par); +int default_proc (int Msg, int Par); /* Default paint routine for dialogs */ void common_dialog_repaint (struct Dlg_head *h); diff --git a/src/help.c b/src/help.c index b188cf368..9aba7c0f3 100644 --- a/src/help.c +++ b/src/help.c @@ -586,9 +586,9 @@ static void prev_node_cmd (Dlg_head *h) help_callback (h, 0, DLG_DRAW); } -static int md_callback (Dlg_head *h, Widget *w, int msg, int par) +static int md_callback (Widget *w, int msg, int par) { - return default_proc (h, msg, par); + return default_proc (msg, par); } static Widget *mousedispatch_new (int y, int x, int yl, int xl) diff --git a/src/info.c b/src/info.c index 447ded9d1..4a7cd2598 100644 --- a/src/info.c +++ b/src/info.c @@ -229,7 +229,7 @@ static void info_destroy (WInfo *info) delete_hook (&select_file_hook, info_hook); } -static int info_callback (Dlg_head *h, WInfo *info, int msg, int par) +static int info_callback (WInfo *info, int msg, int par) { switch (msg){ @@ -246,7 +246,7 @@ static int info_callback (Dlg_head *h, WInfo *info, int msg, int par) case WIDGET_FOCUS: return 0; } - return default_proc (h, msg, par); + return default_proc (msg, par); } WInfo *info_new () diff --git a/src/menu.c b/src/menu.c index 7e410ba82..64ee85c0f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -343,7 +343,7 @@ static int menubar_handle_key (WMenu *menubar, int key) return 0; } -static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par) +static int menubar_callback (WMenu *menubar, int msg, int par) { switch (msg){ /* We do not want the focus unless we have been activated */ @@ -388,7 +388,7 @@ static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par) if (menubar_visible) menubar_draw (menubar); } - return default_proc (h, msg, par); + return default_proc (msg, par); } static int diff --git a/src/screen.c b/src/screen.c index a2d074e87..71f01b784 100644 --- a/src/screen.c +++ b/src/screen.c @@ -106,7 +106,7 @@ int filetype_mode = 1; /* The hook list for the select file function */ Hook *select_file_hook = 0; -static int panel_callback (Dlg_head *h, WPanel *p, int Msg, int Par); +static int panel_callback (WPanel *p, int Msg, int Par); static int panel_event (Gpm_Event *event, WPanel *panel); static void paint_frame (WPanel *panel); static char *panel_format (WPanel *panel); @@ -2155,8 +2155,10 @@ void user_file_menu_cmd (void) { } static int -panel_callback (Dlg_head *h, WPanel *panel, int msg, int par) +panel_callback (WPanel *panel, int msg, int par) { + Dlg_head *h = panel->widget.parent; + switch (msg){ case WIDGET_INIT: return 1; @@ -2188,7 +2190,7 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par) redraw_labels (h); /* Chain behaviour */ - default_proc (h, WIDGET_FOCUS, par); + default_proc (WIDGET_FOCUS, par); return 1; case WIDGET_UNFOCUS: @@ -2206,7 +2208,7 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par) return panel_key (panel, par); break; } - return default_proc (h, msg, par); + return default_proc (msg, par); } void diff --git a/src/tree.c b/src/tree.c index fba2b8b70..b65b2951b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -60,8 +60,7 @@ static int tree_navigation_flag; /* Forwards */ static void save_tree (WTree *tree); static void tree_rescan_cmd (WTree *tree); -static int tree_callback (Dlg_head *h, WTree *tree, int msg, int par); -#define tcallback (callback_fn) tree_callback +static int tree_callback (WTree *tree, int msg, int par); static tree_entry *back_ptr (tree_entry *ptr, int *count) { @@ -1002,8 +1001,10 @@ tree_frame (Dlg_head *h, WTree *tree) static int -tree_callback (Dlg_head *h, WTree *tree, int msg, int par) +tree_callback (WTree *tree, int msg, int par) { + Dlg_head *h = tree->widget.parent; + switch (msg) { case WIDGET_DRAW: tree_frame (h, tree); @@ -1049,7 +1050,7 @@ tree_callback (Dlg_head *h, WTree *tree, int msg, int par) show_tree (tree); return 1; } - return default_proc (h, msg, par); + return default_proc (msg, par); } WTree * @@ -1057,15 +1058,16 @@ tree_new (int is_panel, int y, int x, int lines, int cols) { WTree *tree = g_new (WTree, 1); - init_widget (&tree->widget, y, x, lines, cols, tcallback, - (destroy_fn) tree_destroy, (mouse_h) event_callback, NULL); + init_widget (&tree->widget, y, x, lines, cols, + (callback_fn) tree_callback, (destroy_fn) tree_destroy, + (mouse_h) event_callback, NULL); tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; - tree->search_buffer [0] = 0; + tree->search_buffer[0] = 0; tree->topdiff = tree->widget.lines / 2; tree->searching = 0; tree->done = 0; diff --git a/src/view.c b/src/view.c index 36fa6d925..05ba632ca 100644 --- a/src/view.c +++ b/src/view.c @@ -107,7 +107,7 @@ int altered_nroff_flag = 0; static const char hex_char[] = "0123456789ABCDEF"; /* Our callback */ -static int view_callback (Dlg_head * h, WView * view, int msg, int par); +static int view_callback (WView *view, int msg, int par); static int regexp_view_search (WView * view, char *pattern, char *string, int match_type); @@ -2485,9 +2485,10 @@ view_hook (void *v) } static int -view_callback (Dlg_head *h, WView *view, int msg, int par) +view_callback (WView *view, int msg, int par) { int i; + Dlg_head *h = view->widget.parent; switch (msg) { case WIDGET_INIT: @@ -2531,7 +2532,7 @@ view_callback (Dlg_head *h, WView *view, int msg, int par) return 1; } - return default_proc (h, msg, par); + return default_proc (msg, par); } WView * diff --git a/src/widget.c b/src/widget.c index 9545d1270..16c300b02 100644 --- a/src/widget.c +++ b/src/widget.c @@ -48,11 +48,12 @@ static int button_event (Gpm_Event *event, WButton *b); int quote = 0; static int -button_callback (Dlg_head *h, WButton *b, int Msg, int Par) +button_callback (WButton *b, int Msg, int Par) { char buf[BUF_SMALL]; int stop = 0; int off = 0; + Dlg_head *h = b->widget.parent; switch (Msg){ case WIDGET_INIT: @@ -60,7 +61,7 @@ button_callback (Dlg_head *h, WButton *b, int Msg, int Par) case WIDGET_HOTKEY: if (b->hotkey == Par || toupper(b->hotkey) == Par){ - button_callback (h, b, WIDGET_KEY, ' '); /* to make action */ + button_callback (b, WIDGET_KEY, ' '); /* to make action */ return 1; } else return 0; @@ -140,7 +141,7 @@ button_callback (Dlg_head *h, WButton *b, int Msg, int Par) return 1; break; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } static int @@ -150,7 +151,7 @@ button_event (Gpm_Event *event, WButton *b) Dlg_head *h=b->widget.parent; dlg_select_widget (h, b); if (event->type & GPM_UP){ - button_callback (h, b, WIDGET_KEY, ' '); + button_callback (b, WIDGET_KEY, ' '); (*h->callback) (h, ' ', DLG_POST_KEY); return MOU_NORMAL; } @@ -242,10 +243,11 @@ button_set_text (WButton *b, char *text) static int radio_event (Gpm_Event *event, WRadio *r); static int -radio_callback (Dlg_head *h, WRadio *r, int Msg, int Par) +radio_callback (WRadio *r, int Msg, int Par) { int i; - + Dlg_head *h = r->widget.parent; + switch (Msg) { case WIDGET_INIT: return 1; @@ -263,7 +265,7 @@ radio_callback (Dlg_head *h, WRadio *r, int Msg, int Par) if (c != lp) continue; r->pos = i; - radio_callback (h, r, WIDGET_KEY, ' '); /* Take action */ + radio_callback (r, WIDGET_KEY, ' '); /* Take action */ return 1; } } @@ -275,7 +277,7 @@ radio_callback (Dlg_head *h, WRadio *r, int Msg, int Par) case ' ': r->sel = r->pos; (*h->callback) (h, h->current->dlg_id, DLG_ACTION); - radio_callback (h, r, WIDGET_FOCUS, ' '); + radio_callback (r, WIDGET_FOCUS, ' '); return 1; case KEY_UP: @@ -297,7 +299,7 @@ radio_callback (Dlg_head *h, WRadio *r, int Msg, int Par) case WIDGET_CURSOR: (*h->callback) (h, h->current->dlg_id, DLG_ACTION); - radio_callback (h, r, WIDGET_FOCUS, ' '); + radio_callback (r, WIDGET_FOCUS, ' '); widget_move (&r->widget, r->pos, 1); break; @@ -326,7 +328,7 @@ radio_callback (Dlg_head *h, WRadio *r, int Msg, int Par) return 1; break; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } static int @@ -338,8 +340,8 @@ radio_event (Gpm_Event *event, WRadio *r) r->pos = event->y - 1; dlg_select_widget (h, r); if (event->type & GPM_UP){ - radio_callback (h, r, WIDGET_KEY, ' '); - radio_callback (h, r, WIDGET_FOCUS, 0); + radio_callback (r, WIDGET_KEY, ' '); + radio_callback (r, WIDGET_FOCUS, 0); (*h->callback) (h, ' ', DLG_POST_KEY); return MOU_NORMAL; } @@ -380,8 +382,10 @@ radio_new (int y, int x, int count, char **texts, int use_hotkey, char *tkname) static int check_event (Gpm_Event *event, WCheck *b); static int -check_callback (Dlg_head *h, WCheck *c, int Msg, int Par) +check_callback (WCheck *c, int Msg, int Par) { + Dlg_head *h = c->widget.parent; + switch (Msg) { case WIDGET_INIT: return 1; @@ -389,7 +393,7 @@ check_callback (Dlg_head *h, WCheck *c, int Msg, int Par) case WIDGET_HOTKEY: if (c->hotkey==Par || (c->hotkey>='a' && c->hotkey<='z' && c->hotkey-32==Par)){ - check_callback (h, c, WIDGET_KEY, ' '); /* make action */ + check_callback (c, WIDGET_KEY, ' '); /* make action */ return 1; } else return 0; @@ -400,7 +404,7 @@ check_callback (Dlg_head *h, WCheck *c, int Msg, int Par) c->state ^= C_BOOL; c->state ^= C_CHANGE; (*h->callback) (h, h->current->dlg_id, DLG_ACTION); - check_callback (h, c, WIDGET_FOCUS, ' '); + check_callback (c, WIDGET_FOCUS, ' '); return 1; case WIDGET_CURSOR: @@ -421,7 +425,7 @@ check_callback (Dlg_head *h, WCheck *c, int Msg, int Par) } return 1; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } static int @@ -432,8 +436,8 @@ check_event (Gpm_Event *event, WCheck *c) dlg_select_widget (h, c); if (event->type & GPM_UP){ - check_callback (h, c, WIDGET_KEY, ' '); - check_callback (h, c, WIDGET_FOCUS, 0); + check_callback (c, WIDGET_KEY, ' '); + check_callback (c, WIDGET_FOCUS, 0); (*h->callback) (h, ' ', DLG_POST_KEY); return MOU_NORMAL; } @@ -483,8 +487,10 @@ check_new (int y, int x, int state, char *text, char *tkname) /* Label widget */ static int -label_callback (Dlg_head *h, WLabel *l, int Msg, int Par) +label_callback (WLabel *l, int Msg, int Par) { + Dlg_head *h = l->widget.parent; + if (Msg == WIDGET_INIT) return 1; @@ -519,7 +525,7 @@ label_callback (Dlg_head *h, WLabel *l, int Msg, int Par) } return 1; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } void @@ -544,7 +550,7 @@ label_set_text (WLabel *label, char *text) label->text = 0; if (label->widget.parent) - label_callback (label->widget.parent, label, WIDGET_DRAW, 0); + label_callback (label, WIDGET_DRAW, 0); if (newcols < label->widget.cols) label->widget.cols = newcols; @@ -586,8 +592,9 @@ label_new (int y, int x, const char *text, char *tkname) #define gauge_len 47 static int -gauge_callback (Dlg_head *h, WGauge *g, int Msg, int Par) +gauge_callback (WGauge *g, int Msg, int Par) { + Dlg_head *h = g->widget.parent; if (Msg == WIDGET_INIT) return 1; @@ -625,7 +632,7 @@ gauge_callback (Dlg_head *h, WGauge *g, int Msg, int Par) } return 1; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } void @@ -638,7 +645,7 @@ gauge_set_value (WGauge *g, int max, int current) g->current = current; g->max = max; - gauge_callback (g->widget.parent, g, WIDGET_DRAW, 0); + gauge_callback (g, WIDGET_DRAW, 0); } void @@ -647,7 +654,7 @@ gauge_show (WGauge *g, int shown) if (g->shown == shown) return; g->shown = shown; - gauge_callback (g->widget.parent, g, WIDGET_DRAW, 0); + gauge_callback (g, WIDGET_DRAW, 0); } static void @@ -1516,8 +1523,10 @@ input_set_point (WInput *in, int pos) } int -input_callback (Dlg_head *h, WInput *in, int Msg, int Par) +input_callback (WInput *in, int Msg, int Par) { + Dlg_head *h = in->widget.parent; + switch (Msg){ case WIDGET_INIT: return 1; @@ -1552,7 +1561,7 @@ input_callback (Dlg_head *h, WInput *in, int Msg, int Par) return 1; } - return default_proc (h, Msg, Par); + return default_proc (Msg, Par); } static int @@ -1674,11 +1683,12 @@ listbox_drawscroll (WListbox *l) } static void -listbox_draw (WListbox *l, Dlg_head *h, int focused) +listbox_draw (WListbox *l, int focused) { WLEntry *e; int i; int sel_line; + Dlg_head *h = l->widget.parent; int normalc = NORMALC; int selc; char *text; @@ -1944,7 +1954,7 @@ listbox_key (WListbox *l, int key) static int listbox_event (Gpm_Event *event, WListbox *l); static int -listbox_callback (Dlg_head *h, WListbox *l, int msg, int par) +listbox_callback (WListbox *l, int msg, int par) { WLEntry *e; /* int selected_color; Never used */ @@ -1974,7 +1984,7 @@ listbox_callback (Dlg_head *h, WListbox *l, int msg, int par) case WIDGET_KEY: if ((ret_code = listbox_key (l, par))) - listbox_draw (l, h, 1); + listbox_draw (l, 1); return ret_code; case WIDGET_CURSOR: @@ -1984,10 +1994,10 @@ listbox_callback (Dlg_head *h, WListbox *l, int msg, int par) case WIDGET_FOCUS: case WIDGET_UNFOCUS: case WIDGET_DRAW: - listbox_draw (l, h, msg != WIDGET_UNFOCUS); + listbox_draw (l, msg != WIDGET_UNFOCUS); return 1; } - return default_proc (h, msg, par); + return default_proc (msg, par); } static int @@ -2017,7 +2027,7 @@ listbox_event (Gpm_Event *event, WListbox *l) /* We need to refresh ourselves since the dialog manager doesn't */ /* know about this event */ - listbox_callback (h, l, WIDGET_DRAW, 0); + listbox_callback (l, WIDGET_DRAW, 0); mc_refresh (); return MOU_REPEAT; } @@ -2191,7 +2201,7 @@ listbox_get_current (WListbox *l, char **string, char **extra) } static int -buttonbar_callback (Dlg_head *h, WButtonBar *bb, int msg, int par) +buttonbar_callback (WButtonBar *bb, int msg, int par) { int i; @@ -2229,7 +2239,7 @@ buttonbar_callback (Dlg_head *h, WButtonBar *bb, int msg, int par) attrset (SELECTED_COLOR); return 1; } - return default_proc (h, msg, par); + return default_proc (msg, par); } static void diff --git a/src/widget.h b/src/widget.h index 6d0d66a79..cc94ab6e7 100644 --- a/src/widget.h +++ b/src/widget.h @@ -164,7 +164,7 @@ void input_enable_update (WInput *in); void input_set_point (WInput *in, int pos); void input_show_cursor (WInput *in); void assign_text (WInput *in, char *text); -int input_callback (Dlg_head *h, WInput *in, int Msg, int Par); +int input_callback (WInput *in, int Msg, int Par); /* Labels */ void label_set_text (WLabel *label, char *text);