* dlg.c (widget_redraw): Remove.

* widget.c (find_buttonbar): Use find_widget_type().  Make
global.
(define_label): Remove paneletc argument.  Change all callers.
(define_label_data): Likewise.
(redraw_labels): Likewise.  Use find_buttonbar().
* view.c (view_adjust_size): Use find_buttonbar().
This commit is contained in:
Pavel Roskin 2002-11-12 23:33:15 +00:00
parent b0481b41bf
commit eb53b3e975
10 changed files with 85 additions and 103 deletions

View File

@ -1,5 +1,13 @@
2002-11-12 Pavel Roskin <proski@gnu.org> 2002-11-12 Pavel Roskin <proski@gnu.org>
* dlg.c (widget_redraw): Remove.
* widget.c (find_buttonbar): Use find_widget_type(). Make
global.
(define_label): Remove paneletc argument. Change all callers.
(define_label_data): Likewise.
(redraw_labels): Likewise. Use find_buttonbar().
* view.c (view_adjust_size): Use find_buttonbar().
* menu.h: Remove "*" from the definition of the type "Menu" * menu.h: Remove "*" from the definition of the type "Menu"
for consistency with other types. Change all dependencies. for consistency with other types. Change all dependencies.
(menubar_event): Make static. (menubar_event): Make static.

View File

@ -924,18 +924,6 @@ void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new)
} while (p != h->current); } while (p != h->current);
} }
void widget_redraw (Dlg_head *h, Widget_Item *w)
{
Widget_Item *save = h->current;
if (!h->current)
return;
h->current = w;
(*w->widget->callback)(h, h->current->widget, WIDGET_DRAW, 0);
h->current = save;
}
/* Returns the index of h->current from h->first */ /* Returns the index of h->current from h->first */
int dlg_item_number (Dlg_head *h) int dlg_item_number (Dlg_head *h)
{ {

View File

@ -114,11 +114,12 @@ typedef struct Widget {
#define W_IS_INPUT 16 #define W_IS_INPUT 16
#define W_PANEL_HIDDEN 32 #define W_PANEL_HIDDEN 32
/* Items in the circular buffer. Each item refers to a widget. */
typedef struct Widget_Item { typedef struct Widget_Item {
int dlg_id; int dlg_id;
struct Widget_Item *next; /* next in circle buffer */ struct Widget_Item *next;
struct Widget_Item *prev; /* previous in circle buffer */ struct Widget_Item *prev;
Widget *widget; /* point to the component */ Widget *widget;
} Widget_Item; } Widget_Item;
/* draw box in window */ /* draw box in window */
@ -189,7 +190,6 @@ extern Dlg_head *current_dlg;
int send_message (Dlg_head *h, Widget *w, int msg, int par); int send_message (Dlg_head *h, Widget *w, int msg, int par);
int send_message_to (Dlg_head *h, Widget *w, int msg, int par); int send_message_to (Dlg_head *h, Widget *w, int msg, int par);
void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new); void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
void widget_redraw (Dlg_head *h, Widget_Item *w);
int dlg_overlap (Widget *a, Widget *b); int dlg_overlap (Widget *a, Widget *b);
void widget_erase (Widget *); void widget_erase (Widget *);
void dlg_erase (Dlg_head *h); void dlg_erase (Dlg_head *h);

View File

@ -810,20 +810,19 @@ interactive_display (char *filename, char *node)
add_widget (whelp, help_bar); add_widget (whelp, help_bar);
add_widget (whelp, md); add_widget (whelp, md);
define_label_data (whelp, (Widget *) NULL, 1, _("Help"), define_label_data (whelp, 1, _("Help"), (buttonbarfn) help_help_cmd,
(buttonbarfn) help_help_cmd, whelp);
define_label_data (whelp, (Widget *) NULL, 2, _("Index"),
(buttonbarfn) help_index_cmd, whelp);
define_label_data (whelp, (Widget *) NULL, 3, _("Prev"),
(buttonbarfn) prev_node_cmd, whelp);
define_label (whelp, (Widget *) NULL, 4, "", 0);
define_label (whelp, (Widget *) NULL, 5, "", 0);
define_label (whelp, (Widget *) NULL, 6, "", 0);
define_label (whelp, (Widget *) NULL, 7, "", 0);
define_label (whelp, (Widget *) NULL, 8, "", 0);
define_label (whelp, (Widget *) NULL, 9, "", 0);
define_label_data (whelp, (Widget *) NULL, 10, _("Quit"), quit_cmd,
whelp); whelp);
define_label_data (whelp, 2, _("Index"), (buttonbarfn) help_index_cmd,
whelp);
define_label_data (whelp, 3, _("Prev"), (buttonbarfn) prev_node_cmd,
whelp);
define_label (whelp, 4, "", 0);
define_label (whelp, 5, "", 0);
define_label (whelp, 6, "", 0);
define_label (whelp, 7, "", 0);
define_label (whelp, 8, "", 0);
define_label (whelp, 9, "", 0);
define_label_data (whelp, 10, _("Quit"), quit_cmd, whelp);
run_dlg (whelp); run_dlg (whelp);
interactive_display_finish (); interactive_display_finish ();

View File

@ -1410,14 +1410,12 @@ suspend_cmd (void)
} }
static void static void
init_labels (Widget *paneletc) init_labels (void)
{ {
define_label (midnight_dlg, paneletc, 1, _("Help"), help_cmd); define_label (midnight_dlg, 1, _("Help"), help_cmd);
define_label (midnight_dlg, paneletc, 2, _("Menu"), define_label (midnight_dlg, 2, _("Menu"), user_file_menu_cmd);
user_file_menu_cmd); define_label (midnight_dlg, 9, _("PullDn"), menu_cmd);
define_label (midnight_dlg, paneletc, 9, _("PullDn"), menu_cmd); define_label (midnight_dlg, 10, _("Quit"), (voidfn) quit_cmd);
define_label (midnight_dlg, paneletc, 10, _("Quit"),
(voidfn) quit_cmd);
} }
static const key_map ctl_x_map[] = { static const key_map ctl_x_map[] = {
@ -1877,8 +1875,7 @@ setup_panels_and_run_mc (void)
add_widget (midnight_dlg, get_panel_widget (second)); add_widget (midnight_dlg, get_panel_widget (second));
add_widget (midnight_dlg, the_menubar); add_widget (midnight_dlg, the_menubar);
init_labels (get_panel_widget (0)); init_labels ();
init_labels (get_panel_widget (1));
/* Run the Midnight Commander if no file was specified in the command line */ /* Run the Midnight Commander if no file was specified in the command line */
run_dlg (midnight_dlg); run_dlg (midnight_dlg);

View File

@ -2177,15 +2177,15 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
show_dir (panel); show_dir (panel);
select_item (panel); select_item (panel);
define_label (h, (Widget *)panel, 1, _("Help"), help_cmd); define_label (h, 1, _("Help"), help_cmd);
define_label (h, (Widget *)panel, 2, _("Menu"), user_file_menu_cmd); define_label (h, 2, _("Menu"), user_file_menu_cmd);
define_label (h, (Widget *)panel, 3, _("View"), view_panel_cmd); define_label (h, 3, _("View"), view_panel_cmd);
define_label (h, (Widget *)panel, 4, _("Edit"), edit_panel_cmd); define_label (h, 4, _("Edit"), edit_panel_cmd);
define_label (h, (Widget *)panel, 5, _("Copy"), copy_cmd); define_label (h, 5, _("Copy"), copy_cmd);
define_label (h, (Widget *)panel, 6, _("RenMov"), ren_cmd); define_label (h, 6, _("RenMov"), ren_cmd);
define_label (h, (Widget *)panel, 7, _("Mkdir"), mkdir_panel_cmd); define_label (h, 7, _("Mkdir"), mkdir_panel_cmd);
define_label (h, (Widget *)panel, 8, _("Delete"), delete_cmd); define_label (h, 8, _("Delete"), delete_cmd);
redraw_labels (h, (Widget *)panel); redraw_labels (h);
/* Chain behaviour */ /* Chain behaviour */
default_proc (h, WIDGET_FOCUS, par); default_proc (h, WIDGET_FOCUS, par);

View File

@ -782,8 +782,8 @@ tree_toggle_navig (WTree *tree)
static void static void
set_navig_label (WTree *tree) set_navig_label (WTree *tree)
{ {
define_label_data (tree->widget.parent, (Widget *) tree, define_label_data (tree->widget.parent, 4,
4, tree_navigation_flag ? _("Static") : _("Dynamc"), tree_navigation_flag ? _("Static") : _("Dynamc"),
(buttonbarfn) tree_toggle_navig, tree); (buttonbarfn) tree_toggle_navig, tree);
} }
@ -1015,26 +1015,26 @@ tree_callback (Dlg_head *h, WTree *tree, int msg, int par)
case WIDGET_FOCUS: case WIDGET_FOCUS:
tree->active = 1; tree->active = 1;
define_label (h, (Widget *)tree, 1, _("Help"), (voidfn) tree_help_cmd); define_label (h, 1, _("Help"), (voidfn) tree_help_cmd);
define_label_data (h, (Widget *)tree, define_label_data (h, 2, _("Rescan"),
2, _("Rescan"), (buttonbarfn)tree_rescan_cmd, tree); (buttonbarfn) tree_rescan_cmd, tree);
define_label_data (h, (Widget *)tree, define_label_data (h, 3, _("Forget"),
3, _("Forget"), (buttonbarfn)tree_forget_cmd, tree); (buttonbarfn) tree_forget_cmd, tree);
define_label_data (h, (Widget *)tree, define_label_data (h, 5, _("Copy"), (buttonbarfn) tree_copy_cmd,
5, _("Copy"), (buttonbarfn) tree_copy_cmd, tree); tree);
define_label_data (h, (Widget *)tree, define_label_data (h, 6, _("RenMov"), (buttonbarfn) tree_move_cmd,
6, _("RenMov"), (buttonbarfn) tree_move_cmd, tree); tree);
#if 0 #if 0
/* FIXME: mkdir is currently defunct */ /* FIXME: mkdir is currently defunct */
define_label_data (h, (Widget *)tree, define_label_data (h, 7, _("Mkdir"), (buttonbarfn) tree_mkdir_cmd,
7, _("Mkdir"), (buttonbarfn) tree_mkdir_cmd, tree); tree);
#else #else
define_label (h, (Widget *)tree, 7, "", 0); define_label (h, 7, "", 0);
#endif #endif
define_label_data (h, (Widget *)tree, define_label_data (h, 8, _("Rmdir"), (buttonbarfn) tree_rmdir_cmd,
8, _("Rmdir"), (buttonbarfn) tree_rmdir_cmd, tree); tree);
set_navig_label (tree); set_navig_label (tree);
redraw_labels (h, (Widget *)tree); redraw_labels (h);
/* FIXME: Should find a better way of only displaying the /* FIXME: Should find a better way of only displaying the

View File

@ -1091,11 +1091,10 @@ view_update (WView *view, gboolean update_gui)
} }
static inline void static inline void
my_define (Dlg_head *h, int idx, char *text, my_define (Dlg_head *h, int idx, char *text, void (*fn) (WView *),
void (*fn) (WView *), WView *view) WView *view)
{ {
define_label_data (h, (Widget *) view, idx, text, (buttonbarfn) fn, define_label_data (h, idx, text, (buttonbarfn) fn, view);
view);
} }
/* If the last parameter is nonzero, it means we want get the count of lines /* If the last parameter is nonzero, it means we want get the count of lines
@ -2044,7 +2043,7 @@ view_labels (WView *view)
{ {
Dlg_head *h = view->widget.parent; Dlg_head *h = view->widget.parent;
define_label (h, (Widget *) view, 1, _("Help"), view_help_cmd); define_label (h, 1, _("Help"), view_help_cmd);
my_define (h, 10, _("Quit"), view_quit_cmd, view); my_define (h, 10, _("Quit"), view_quit_cmd, view);
my_define (h, 4, view->hex_mode ? _("Ascii") : _("Hex"), my_define (h, 4, view->hex_mode ? _("Ascii") : _("Hex"),
@ -2074,7 +2073,7 @@ view_labels (WView *view)
my_define (h, 3, _("Quit"), view_quit_cmd, view); my_define (h, 3, _("Quit"), view_quit_cmd, view);
} }
redraw_labels (h, (Widget *) view); redraw_labels (h);
} }
/* Both views */ /* Both views */
@ -2399,7 +2398,7 @@ view_adjust_size (Dlg_head *h)
/* Look up the viewer and the buttonbar, we assume only two widgets here */ /* Look up the viewer and the buttonbar, we assume only two widgets here */
view = (WView *) find_widget_type (h, (callback_fn) view_callback); view = (WView *) find_widget_type (h, (callback_fn) view_callback);
bar = (WButtonBar *) view->widget.parent->current->next->widget; bar = find_buttonbar (h);
widget_set_size (&view->widget, 0, 0, LINES - 1, COLS); widget_set_size (&view->widget, 0, 0, LINES - 1, COLS);
widget_set_size (&bar->widget, LINES - 1, 0, 1, COLS); widget_set_size (&bar->widget, LINES - 1, 0, 1, COLS);

View File

@ -2288,29 +2288,23 @@ set_label_text (WButtonBar * bb, int index, char *text)
bb->labels[index - 1].text = g_strdup (text); bb->labels[index - 1].text = g_strdup (text);
} }
/* paneletc is either the panel widget, or info or view or tree widget */ /* Find ButtonBar widget in the dialog */
static WButtonBar * WButtonBar *
find_buttonbar (Dlg_head * h, Widget * paneletc) find_buttonbar (Dlg_head *h)
{ {
WButtonBar *bb; WButtonBar *bb;
Widget_Item *item;
int i;
bb = 0; bb = (WButtonBar *) find_widget_type (h, (callback_fn)
for (i = 0, item = h->current; i < h->count; i++, item = item->next) { buttonbar_callback);
if (item->widget->callback == (callback_fn) buttonbar_callback) {
bb = (WButtonBar *) item->widget;
break;
}
}
return bb; return bb;
} }
void void
define_label_data (Dlg_head * h, Widget * paneletc, int idx, char *text, define_label_data (Dlg_head *h, int idx, char *text, buttonbarfn cback,
buttonbarfn cback, void *data) void *data)
{ {
WButtonBar *bb = find_buttonbar (h, paneletc); WButtonBar *bb = find_buttonbar (h);
if (!bb) if (!bb)
return; return;
@ -2320,23 +2314,20 @@ define_label_data (Dlg_head * h, Widget * paneletc, int idx, char *text,
} }
void void
define_label (Dlg_head * h, Widget * paneletc, int idx, char *text, define_label (Dlg_head *h, int idx, char *text, void (*cback) (void))
void (*cback) (void))
{ {
define_label_data (h, paneletc, idx, text, (buttonbarfn) cback, 0); define_label_data (h, idx, text, (buttonbarfn) cback, 0);
} }
/* Redraw labels of the buttonbar */
void void
redraw_labels (Dlg_head *h, Widget *paneletc) redraw_labels (Dlg_head *h)
{ {
Widget_Item *item; WButtonBar *bb = find_buttonbar (h);
int i;
for (i = 0, item = h->current; i < h->count; i++, item = item->next){ if (!bb)
if (item->widget->callback == (callback_fn) buttonbar_callback){
widget_redraw (h, item);
return; return;
}
} send_message (h, (Widget *) bb, WIDGET_DRAW, 0);
} }

View File

@ -8,7 +8,6 @@
/* Please note that the first element in all the widgets is a */ /* Please note that the first element in all the widgets is a */
/* widget variable of type Widget. We abuse this fact everywhere */ /* widget variable of type Widget. We abuse this fact everywhere */
/* Widget_Items */
#define HIDDEN_BUTTON 0 #define HIDDEN_BUTTON 0
#define NARROW_BUTTON 1 #define NARROW_BUTTON 1
@ -202,11 +201,12 @@ char *listbox_add_item (WListbox *l, enum append_pos pos, int
/* Buttonbar routines */ /* Buttonbar routines */
WButtonBar *buttonbar_new (int visible); WButtonBar *buttonbar_new (int visible);
WButtonBar *find_buttonbar (Dlg_head *h);
typedef void (*voidfn)(void); typedef void (*voidfn)(void);
void define_label (Dlg_head *, Widget *paneletc, int index, char *text, voidfn); void define_label (Dlg_head *, int index, char *text, voidfn);
void define_label_data (Dlg_head *h, Widget *paneletc, int idx, char *text, void define_label_data (Dlg_head *h, int idx, char *text,
buttonbarfn cback, void *data); buttonbarfn cback, void *data);
void redraw_labels (Dlg_head *h, Widget *paneletc); void redraw_labels (Dlg_head *h);
void buttonbar_hint (WButtonBar *bb, char *s); void buttonbar_hint (WButtonBar *bb, char *s);
#endif /* __WIDGET_H */ #endif /* __WIDGET_H */