* 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>
* 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"
for consistency with other types. Change all dependencies.
(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);
}
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 */
int dlg_item_number (Dlg_head *h)
{

View File

@ -114,11 +114,12 @@ typedef struct Widget {
#define W_IS_INPUT 16
#define W_PANEL_HIDDEN 32
/* Items in the circular buffer. Each item refers to a widget. */
typedef struct Widget_Item {
int dlg_id;
struct Widget_Item *next; /* next in circle buffer */
struct Widget_Item *prev; /* previous in circle buffer */
Widget *widget; /* point to the component */
struct Widget_Item *next;
struct Widget_Item *prev;
Widget *widget;
} Widget_Item;
/* 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_to (Dlg_head *h, Widget *w, int msg, int par);
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);
void widget_erase (Widget *);
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, md);
define_label_data (whelp, (Widget *) NULL, 1, _("Help"),
(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,
define_label_data (whelp, 1, _("Help"), (buttonbarfn) help_help_cmd,
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);
interactive_display_finish ();

View File

@ -1410,14 +1410,12 @@ suspend_cmd (void)
}
static void
init_labels (Widget *paneletc)
init_labels (void)
{
define_label (midnight_dlg, paneletc, 1, _("Help"), help_cmd);
define_label (midnight_dlg, paneletc, 2, _("Menu"),
user_file_menu_cmd);
define_label (midnight_dlg, paneletc, 9, _("PullDn"), menu_cmd);
define_label (midnight_dlg, paneletc, 10, _("Quit"),
(voidfn) quit_cmd);
define_label (midnight_dlg, 1, _("Help"), help_cmd);
define_label (midnight_dlg, 2, _("Menu"), user_file_menu_cmd);
define_label (midnight_dlg, 9, _("PullDn"), menu_cmd);
define_label (midnight_dlg, 10, _("Quit"), (voidfn) quit_cmd);
}
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, the_menubar);
init_labels (get_panel_widget (0));
init_labels (get_panel_widget (1));
init_labels ();
/* Run the Midnight Commander if no file was specified in the command line */
run_dlg (midnight_dlg);

View File

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

View File

@ -782,8 +782,8 @@ tree_toggle_navig (WTree *tree)
static void
set_navig_label (WTree *tree)
{
define_label_data (tree->widget.parent, (Widget *) tree,
4, tree_navigation_flag ? _("Static") : _("Dynamc"),
define_label_data (tree->widget.parent, 4,
tree_navigation_flag ? _("Static") : _("Dynamc"),
(buttonbarfn) tree_toggle_navig, tree);
}
@ -1004,7 +1004,7 @@ tree_frame (Dlg_head *h, WTree *tree)
static int
tree_callback (Dlg_head *h, WTree *tree, int msg, int par)
{
switch (msg){
switch (msg) {
case WIDGET_DRAW:
tree_frame (h, tree);
show_tree (tree);
@ -1015,26 +1015,26 @@ tree_callback (Dlg_head *h, WTree *tree, int msg, int par)
case WIDGET_FOCUS:
tree->active = 1;
define_label (h, (Widget *)tree, 1, _("Help"), (voidfn) tree_help_cmd);
define_label_data (h, (Widget *)tree,
2, _("Rescan"), (buttonbarfn)tree_rescan_cmd, tree);
define_label_data (h, (Widget *)tree,
3, _("Forget"), (buttonbarfn)tree_forget_cmd, tree);
define_label_data (h, (Widget *)tree,
5, _("Copy"), (buttonbarfn) tree_copy_cmd, tree);
define_label_data (h, (Widget *)tree,
6, _("RenMov"), (buttonbarfn) tree_move_cmd, tree);
define_label (h, 1, _("Help"), (voidfn) tree_help_cmd);
define_label_data (h, 2, _("Rescan"),
(buttonbarfn) tree_rescan_cmd, tree);
define_label_data (h, 3, _("Forget"),
(buttonbarfn) tree_forget_cmd, tree);
define_label_data (h, 5, _("Copy"), (buttonbarfn) tree_copy_cmd,
tree);
define_label_data (h, 6, _("RenMov"), (buttonbarfn) tree_move_cmd,
tree);
#if 0
/* FIXME: mkdir is currently defunct */
define_label_data (h, (Widget *)tree,
7, _("Mkdir"), (buttonbarfn) tree_mkdir_cmd, tree);
define_label_data (h, 7, _("Mkdir"), (buttonbarfn) tree_mkdir_cmd,
tree);
#else
define_label (h, (Widget *)tree, 7, "", 0);
define_label (h, 7, "", 0);
#endif
define_label_data (h, (Widget *)tree,
8, _("Rmdir"), (buttonbarfn) tree_rmdir_cmd, tree);
define_label_data (h, 8, _("Rmdir"), (buttonbarfn) tree_rmdir_cmd,
tree);
set_navig_label (tree);
redraw_labels (h, (Widget *)tree);
redraw_labels (h);
/* 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
my_define (Dlg_head *h, int idx, char *text,
void (*fn) (WView *), WView *view)
my_define (Dlg_head *h, int idx, char *text, void (*fn) (WView *),
WView *view)
{
define_label_data (h, (Widget *) view, idx, text, (buttonbarfn) fn,
view);
define_label_data (h, idx, text, (buttonbarfn) fn, view);
}
/* 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;
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, 4, view->hex_mode ? _("Ascii") : _("Hex"),
@ -2074,7 +2073,7 @@ view_labels (WView *view)
my_define (h, 3, _("Quit"), view_quit_cmd, view);
}
redraw_labels (h, (Widget *) view);
redraw_labels (h);
}
/* 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 */
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 (&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);
}
/* paneletc is either the panel widget, or info or view or tree widget */
static WButtonBar *
find_buttonbar (Dlg_head * h, Widget * paneletc)
/* Find ButtonBar widget in the dialog */
WButtonBar *
find_buttonbar (Dlg_head *h)
{
WButtonBar *bb;
Widget_Item *item;
int i;
bb = 0;
for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
if (item->widget->callback == (callback_fn) buttonbar_callback) {
bb = (WButtonBar *) item->widget;
break;
}
}
bb = (WButtonBar *) find_widget_type (h, (callback_fn)
buttonbar_callback);
return bb;
}
void
define_label_data (Dlg_head * h, Widget * paneletc, int idx, char *text,
buttonbarfn cback, void *data)
define_label_data (Dlg_head *h, int idx, char *text, buttonbarfn cback,
void *data)
{
WButtonBar *bb = find_buttonbar (h, paneletc);
WButtonBar *bb = find_buttonbar (h);
if (!bb)
return;
@ -2320,23 +2314,20 @@ define_label_data (Dlg_head * h, Widget * paneletc, int idx, char *text,
}
void
define_label (Dlg_head * h, Widget * paneletc, int idx, char *text,
void (*cback) (void))
define_label (Dlg_head *h, int idx, char *text, 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
redraw_labels (Dlg_head *h, Widget *paneletc)
redraw_labels (Dlg_head *h)
{
Widget_Item *item;
int i;
WButtonBar *bb = find_buttonbar (h);
for (i = 0, item = h->current; i < h->count; i++, item = item->next){
if (item->widget->callback == (callback_fn) buttonbar_callback){
widget_redraw (h, item);
return;
}
}
if (!bb)
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 */
/* widget variable of type Widget. We abuse this fact everywhere */
/* Widget_Items */
#define HIDDEN_BUTTON 0
#define NARROW_BUTTON 1
@ -202,11 +201,12 @@ char *listbox_add_item (WListbox *l, enum append_pos pos, int
/* Buttonbar routines */
WButtonBar *buttonbar_new (int visible);
WButtonBar *find_buttonbar (Dlg_head *h);
typedef void (*voidfn)(void);
void define_label (Dlg_head *, Widget *paneletc, int index, char *text, voidfn);
void define_label_data (Dlg_head *h, Widget *paneletc, int idx, char *text,
void define_label (Dlg_head *, int index, char *text, voidfn);
void define_label_data (Dlg_head *h, int idx, char *text,
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);
#endif /* __WIDGET_H */