ButtonBar optimizations.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-11-06 16:19:52 +03:00
parent 6b71dc9f12
commit 8224a26cf4
10 changed files with 114 additions and 134 deletions

View File

@ -724,7 +724,7 @@ edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end,
edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
if (edit->force & REDRAW_COMPLETELY)
buttonbar_redraw (edit->widget.parent);
buttonbar_redraw (find_buttonbar (edit->widget.parent));
render_edit_text (edit, row_start, col_start, row_end, col_end);
/*
* edit->force != 0 means a key was pending and the redraw

View File

@ -161,13 +161,13 @@ static void
edit_adjust_size (Dlg_head *h)
{
WEdit *edit;
WButtonBar *edit_bar;
WButtonBar *b;
edit = (WEdit *) find_widget_type (h, edit_callback);
edit_bar = find_buttonbar (h);
b = find_buttonbar (h);
widget_set_size (&edit->widget, 0, 0, LINES - 1, COLS);
widget_set_size ((Widget *) edit_bar, LINES - 1, 0, 1, COLS);
widget_set_size (&b->widget , LINES - 1, 0, 1, COLS);
widget_set_size (&edit_menubar->widget, 0, 0, 1, COLS);
#ifdef RESIZABLE_MENUBAR
@ -248,15 +248,6 @@ edit_get_file_name (const WEdit *edit)
return edit->filename;
}
static void edit_my_define (Dlg_head * h, int idx, const char *text,
void (*fn) (WEdit *), WEdit * edit)
{
text = edit->labels[idx - 1]? edit->labels[idx - 1] : text;
/* function-cast ok */
buttonbar_set_label_data (h, idx, text, (buttonbarfn) fn, edit);
}
static void cmd_F1 (WEdit * edit)
{
send_message ((Widget *) edit, WIDGET_KEY, KEY_F (1));
@ -310,22 +301,20 @@ static void cmd_F10 (WEdit * edit)
}
static void
edit_labels (WEdit *edit)
edit_set_buttonbar (WEdit *edit)
{
Dlg_head *h = edit->widget.parent;
WButtonBar *bb = find_buttonbar (edit->widget.parent);
edit_my_define (h, 1, Q_("ButtonBar|Help"), cmd_F1, edit);
edit_my_define (h, 2, Q_("ButtonBar|Save"), cmd_F2, edit);
edit_my_define (h, 3, Q_("ButtonBar|Mark"), cmd_F3, edit);
edit_my_define (h, 4, Q_("ButtonBar|Replac"), cmd_F4, edit);
edit_my_define (h, 5, Q_("ButtonBar|Copy"), cmd_F5, edit);
edit_my_define (h, 6, Q_("ButtonBar|Move"), cmd_F6, edit);
edit_my_define (h, 7, Q_("ButtonBar|Search"), cmd_F7, edit);
edit_my_define (h, 8, Q_("ButtonBar|Delete"), cmd_F8, edit);
edit_my_define (h, 9, Q_("ButtonBar|PullDn"), edit_menu_cmd, edit);
edit_my_define (h, 10, Q_("ButtonBar|Quit"), cmd_F10, edit);
buttonbar_redraw (h);
buttonbar_set_label_data (bb, 1, Q_("ButtonBar|Help"), (buttonbarfn) cmd_F1, edit);
buttonbar_set_label_data (bb, 2, Q_("ButtonBar|Save"), (buttonbarfn) cmd_F2, edit);
buttonbar_set_label_data (bb, 3, Q_("ButtonBar|Mark"), (buttonbarfn) cmd_F3, edit);
buttonbar_set_label_data (bb, 4, Q_("ButtonBar|Replac"), (buttonbarfn) cmd_F4, edit);
buttonbar_set_label_data (bb, 5, Q_("ButtonBar|Copy"), (buttonbarfn) cmd_F5, edit);
buttonbar_set_label_data (bb, 6, Q_("ButtonBar|Move"), (buttonbarfn) cmd_F6, edit);
buttonbar_set_label_data (bb, 7, Q_("ButtonBar|Search"), (buttonbarfn) cmd_F7, edit);
buttonbar_set_label_data (bb, 8, Q_("ButtonBar|Delete"), (buttonbarfn) cmd_F8, edit);
buttonbar_set_label_data (bb, 9, Q_("ButtonBar|PullDn"), (buttonbarfn) edit_menu_cmd, edit);
buttonbar_set_label_data (bb, 10, Q_("ButtonBar|Quit"), (buttonbarfn) cmd_F10, edit);
}
void edit_update_screen (WEdit * e)
@ -354,7 +343,7 @@ edit_callback (Widget *w, widget_msg_t msg, int parm)
switch (msg) {
case WIDGET_INIT:
e->force |= REDRAW_COMPLETELY;
edit_labels (e);
edit_set_buttonbar (e);
return MSG_HANDLED;
case WIDGET_DRAW:

View File

@ -884,16 +884,16 @@ interactive_display (const char *filename, const char *node)
add_widget (whelp, md);
add_widget (whelp, help_bar);
buttonbar_set_label_data (whelp, 1, Q_("ButtonBar|Help"), help_help_cmd, whelp);
buttonbar_set_label_data (whelp, 2, Q_("ButtonBar|Index"), help_index_cmd, whelp);
buttonbar_set_label_data (whelp, 3, Q_("ButtonBar|Prev"), prev_node_cmd, whelp);
buttonbar_clear_label (whelp, 4);
buttonbar_clear_label (whelp, 5);
buttonbar_clear_label (whelp, 6);
buttonbar_clear_label (whelp, 7);
buttonbar_clear_label (whelp, 8);
buttonbar_clear_label (whelp, 9);
buttonbar_set_label_data (whelp, 10, Q_("ButtonBar|Quit"), help_quit_cmd, whelp);
buttonbar_set_label_data (help_bar, 1, Q_("ButtonBar|Help"), help_help_cmd, whelp);
buttonbar_set_label_data (help_bar, 2, Q_("ButtonBar|Index"), help_index_cmd, whelp);
buttonbar_set_label_data (help_bar, 3, Q_("ButtonBar|Prev"), prev_node_cmd, whelp);
buttonbar_clear_label (help_bar, 4);
buttonbar_clear_label (help_bar, 5);
buttonbar_clear_label (help_bar, 6);
buttonbar_clear_label (help_bar, 7);
buttonbar_clear_label (help_bar, 8);
buttonbar_clear_label (help_bar, 9);
buttonbar_set_label_data (help_bar, 10, Q_("ButtonBar|Quit"), help_quit_cmd, whelp);
run_dlg (whelp);
interactive_display_finish ();

View File

@ -1110,13 +1110,19 @@ copy_other_tagged (void)
copy_tagged (other_panel);
}
static void
init_labels (void)
void
midnight_set_buttonbar (WButtonBar *b)
{
buttonbar_set_label (midnight_dlg, 1, Q_("ButtonBar|Help"), help_cmd);
buttonbar_set_label (midnight_dlg, 2, Q_("ButtonBar|Menu"), user_file_menu_cmd);
buttonbar_set_label (midnight_dlg, 9, Q_("ButtonBar|PullDn"), menu_cmd);
buttonbar_set_label (midnight_dlg, 10, Q_("ButtonBar|Quit"), quit_cmd);
buttonbar_set_label (b, 1, Q_("ButtonBar|Help"), help_cmd);
buttonbar_set_label (b, 2, Q_("ButtonBar|Menu"), user_file_menu_cmd);
buttonbar_set_label (b, 3, Q_("ButtonBar|View"), view_cmd);
buttonbar_set_label (b, 4, Q_("ButtonBar|Edit"), edit_cmd);
buttonbar_set_label (b, 5, Q_("ButtonBar|Copy"), copy_cmd);
buttonbar_set_label (b, 6, Q_("ButtonBar|RenMov"), rename_cmd);
buttonbar_set_label (b, 7, Q_("ButtonBar|Mkdir"), mkdir_cmd);
buttonbar_set_label (b, 8, Q_("ButtonBar|Delete"), delete_cmd);
buttonbar_set_label (b, 9, Q_("ButtonBar|PullDn"), menu_cmd);
buttonbar_set_label (b, 10, Q_("ButtonBar|Quit"), quit_cmd);
}
static gboolean ctl_x_map_enabled = FALSE;
@ -1799,9 +1805,9 @@ setup_panels_and_run_mc (void)
add_widget (midnight_dlg, the_hint);
add_widget (midnight_dlg, cmdline);
add_widget (midnight_dlg, the_prompt);
add_widget (midnight_dlg, the_bar);
init_labels ();
add_widget (midnight_dlg, the_bar);
midnight_set_buttonbar (the_bar);
if (boot_current_is_left)
dlg_select_widget (get_panel_widget (0));

View File

@ -24,6 +24,10 @@ enum { pause_never, pause_on_dumb_terminals, pause_always };
void subshell_chdir (const char *command);
struct WButtonBar;
void midnight_set_buttonbar (struct WButtonBar *b);
/* See main.c for details on these variables */
extern int mark_moves_down;
extern int auto_menu;

View File

@ -2817,7 +2817,7 @@ static cb_ret_t
panel_callback (Widget *w, widget_msg_t msg, int parm)
{
WPanel *panel = (WPanel *) w;
Dlg_head *h = panel->widget.parent;
WButtonBar *bb;
switch (msg) {
case WIDGET_DRAW:
@ -2841,15 +2841,9 @@ panel_callback (Widget *w, widget_msg_t msg, int parm)
paint_dir (panel);
panel->dirty = 0;
buttonbar_set_label (h, 1, Q_("ButtonBar|Help"), help_cmd);
buttonbar_set_label (h, 2, Q_("ButtonBar|Menu"), user_file_menu_cmd);
buttonbar_set_label (h, 3, Q_("ButtonBar|View"), view_cmd);
buttonbar_set_label (h, 4, Q_("ButtonBar|Edit"), edit_cmd);
buttonbar_set_label (h, 5, Q_("ButtonBar|Copy"), copy_cmd);
buttonbar_set_label (h, 6, Q_("ButtonBar|RenMov"), rename_cmd);
buttonbar_set_label (h, 7, Q_("ButtonBar|Mkdir"), mkdir_cmd);
buttonbar_set_label (h, 8, Q_("ButtonBar|Delete"), delete_cmd);
buttonbar_redraw (h);
bb = find_buttonbar (panel->widget.parent);
midnight_set_buttonbar (bb);
buttonbar_redraw (bb);
return MSG_HANDLED;
case WIDGET_UNFOCUS:

View File

@ -757,7 +757,7 @@ static void
tree_toggle_navig (WTree *tree)
{
tree_navigation_flag = !tree_navigation_flag;
buttonbar_set_label_data (tree->widget.parent, 4,
buttonbar_set_label_data (find_buttonbar (tree->widget.parent), 4,
tree_navigation_flag ? Q_("ButtonBar|Static")
: Q_("ButtonBar|Dynamc"),
tree_toggle_f4, tree);
@ -1022,6 +1022,7 @@ tree_callback (Widget *w, widget_msg_t msg, int parm)
{
WTree *tree = (WTree *) w;
Dlg_head *h = tree->widget.parent;
WButtonBar *b = find_buttonbar (h);
switch (msg) {
case WIDGET_DRAW:
@ -1034,22 +1035,22 @@ tree_callback (Widget *w, widget_msg_t msg, int parm)
case WIDGET_FOCUS:
tree->active = 1;
buttonbar_set_label_data (h, 1, Q_("ButtonBar|Help"), tree_help, tree);
buttonbar_set_label_data (h, 2, Q_("ButtonBar|Rescan"), tree_rescan, tree);
buttonbar_set_label_data (h, 3, Q_("ButtonBar|Forget"), tree_forget, tree);
buttonbar_set_label_data (h, 4, tree_navigation_flag ? Q_("ButtonBar|Static")
buttonbar_set_label_data (b, 1, Q_("ButtonBar|Help"), tree_help, tree);
buttonbar_set_label_data (b, 2, Q_("ButtonBar|Rescan"), tree_rescan, tree);
buttonbar_set_label_data (b, 3, Q_("ButtonBar|Forget"), tree_forget, tree);
buttonbar_set_label_data (b, 4, tree_navigation_flag ? Q_("ButtonBar|Static")
: Q_("ButtonBar|Dynamc"),
tree_toggle_f4, tree);
buttonbar_set_label_data (h, 5, Q_("ButtonBar|Copy"), tree_copy_cmd, tree);
buttonbar_set_label_data (h, 6, Q_("ButtonBar|RenMov"), tree_move_cmd, tree);
buttonbar_set_label_data (b, 5, Q_("ButtonBar|Copy"), tree_copy_cmd, tree);
buttonbar_set_label_data (b, 6, Q_("ButtonBar|RenMov"), tree_move_cmd, tree);
#if 0
/* FIXME: mkdir is currently defunct */
buttonbar_set_label_data (h, 7, Q_("ButtonBar|Mkdir"), tree_mkdir, tree);
buttonbar_set_label_data (b, 7, Q_("ButtonBar|Mkdir"), tree_mkdir, tree);
#else
buttonbar_clear_label (h, 7);
buttonbar_clear_label (b, 7);
#endif
buttonbar_set_label_data (h, 8, Q_("ButtonBar|Rmdir"), tree_rmdir, tree);
buttonbar_redraw (h);
buttonbar_set_label_data (b, 8, Q_("ButtonBar|Rmdir"), tree_rmdir, tree);
buttonbar_redraw (b);
/* FIXME: Should find a better way of only displaying the
currently selected item */

View File

@ -70,56 +70,57 @@ mcview_labels (mcview_t * view)
{
const char *text;
Dlg_head *h = view->widget.parent;
WButtonBar *b = find_buttonbar (h);
buttonbar_set_label (h, 1, Q_ ("ButtonBar|Help"), mcview_help_cmd);
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), mcview_help_cmd);
if (view->hex_mode) {
if (view->hexedit_mode)
buttonbar_set_label_data (h, 2, Q_ ("ButtonBar|View"),
buttonbar_set_label_data (b, 2, Q_ ("ButtonBar|View"),
(buttonbarfn) mcview_toggle_hexedit_mode_cmd, view);
else if (view->datasource == DS_FILE)
buttonbar_set_label_data (h, 2, Q_ ("ButtonBar|Edit"),
buttonbar_set_label_data (b, 2, Q_ ("ButtonBar|Edit"),
(buttonbarfn) mcview_toggle_hexedit_mode_cmd, view);
else
buttonbar_clear_label (h, 2);
buttonbar_clear_label (b, 2);
buttonbar_set_label_data (h, 4, Q_ ("ButtonBar|Ascii"),
buttonbar_set_label_data (b, 4, Q_ ("ButtonBar|Ascii"),
(buttonbarfn) mcview_toggle_hex_mode_cmd, view);
buttonbar_set_label_data (h, 5, Q_ ("ButtonBar|Goto"),
buttonbar_set_label_data (b, 5, Q_ ("ButtonBar|Goto"),
(buttonbarfn) mcview_moveto_addr_cmd, view);
buttonbar_set_label_data (h, 6, Q_ ("ButtonBar|Save"),
buttonbar_set_label_data (b, 6, Q_ ("ButtonBar|Save"),
(buttonbarfn) mcview_hexedit_save_changes_cmd, view);
buttonbar_set_label_data (h, 7, Q_ ("ButtonBar|HxSrch"),
buttonbar_set_label_data (b, 7, Q_ ("ButtonBar|HxSrch"),
(buttonbarfn) mcview_search_cmd, view);
} else {
text = view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap") : Q_ ("ButtonBar|Wrap");
buttonbar_set_label_data (h, 2, text,
buttonbar_set_label_data (b, 2, text,
(buttonbarfn) mcview_toggle_wrap_mode_cmd, view);
buttonbar_set_label_data (h, 4, Q_ ("ButtonBar|Hex"),
buttonbar_set_label_data (b, 4, Q_ ("ButtonBar|Hex"),
(buttonbarfn) mcview_toggle_hex_mode_cmd, view);
buttonbar_set_label_data (h, 5, Q_ ("ButtonBar|Line"),
buttonbar_set_label_data (b, 5, Q_ ("ButtonBar|Line"),
(buttonbarfn) mcview_moveto_line_cmd, view);
buttonbar_clear_label (h, 6);
buttonbar_set_label_data (h, 7, Q_ ("ButtonBar|Search"),
buttonbar_clear_label (b, 6);
buttonbar_set_label_data (b, 7, Q_ ("ButtonBar|Search"),
(buttonbarfn) mcview_search_cmd, view);
}
/* don't override the key to access the main menu */
if (!mcview_is_in_panel (view)) {
buttonbar_set_label_data (h, 3, Q_ ("ButtonBar|Quit"),
buttonbar_set_label_data (b, 3, Q_ ("ButtonBar|Quit"),
(buttonbarfn) mcview_quit_cmd, view);
text = view->text_nroff_mode ? Q_ ("ButtonBar|Unform") : Q_ ("ButtonBar|Format");
buttonbar_set_label_data (h, 9, text,
buttonbar_set_label_data (b, 9, text,
(buttonbarfn) mcview_toggle_nroff_mode_cmd, view);
}
text = view->magic_mode ? Q_ ("ButtonBar|Raw") : Q_ ("ButtonBar|Parse");
buttonbar_set_label_data (h, 8, text,
buttonbar_set_label_data (b, 8, text,
(buttonbarfn) mcview_toggle_magic_mode_cmd, view);
buttonbar_set_label_data (h, 10, Q_ ("ButtonBar|Quit"),
buttonbar_set_label_data (b, 10, Q_ ("ButtonBar|Quit"),
(buttonbarfn) mcview_quit_cmd, view);
}
@ -201,7 +202,7 @@ mcview_update (mcview_t * view)
if (view->dpy_bbar_dirty) {
view->dpy_bbar_dirty = FALSE;
mcview_labels (view);
buttonbar_redraw (view->widget.parent);
buttonbar_redraw (find_buttonbar (view->widget.parent));
}
if (view->dirty > dirt_limit) {
@ -394,16 +395,17 @@ mcview_display_ruler (mcview_t * view)
/* --------------------------------------------------------------------------------------------- */
void
mcview_adjust_size (Dlg_head * h)
mcview_adjust_size (Dlg_head *h)
{
mcview_t *view;
WButtonBar *bar;
WButtonBar *b;
/* Look up the viewer and the buttonbar, we assume only two widgets here */
view = (mcview_t *) find_widget_type (h, mcview_callback);
bar = find_buttonbar (h);
b = find_buttonbar (h);
widget_set_size (&view->widget, 0, 0, LINES - 1, COLS);
widget_set_size ((Widget *) bar, LINES - 1, 0, 1, COLS);
widget_set_size (&b->widget , LINES - 1, 0, 1, COLS);
mcview_compute_areas (view);
mcview_update_bytes_per_line (view);

View File

@ -2790,7 +2790,7 @@ buttonbar_new (gboolean visible)
}
static void
set_label_text (WButtonBar * bb, int lc_index, const char *text)
set_label_text (WButtonBar *bb, int lc_index, const char *text)
{
g_free (bb->labels[lc_index - 1].text);
bb->labels[lc_index - 1].text = g_strdup (text);
@ -2800,52 +2800,40 @@ set_label_text (WButtonBar * bb, int lc_index, const char *text)
WButtonBar *
find_buttonbar (const Dlg_head *h)
{
WButtonBar *bb;
bb = (WButtonBar *) find_widget_type (h, buttonbar_callback);
return bb;
return (WButtonBar *) find_widget_type (h, buttonbar_callback);
}
void
buttonbar_clear_label (Dlg_head *h, int idx)
buttonbar_clear_label (WButtonBar *bb, int idx)
{
WButtonBar *bb = find_buttonbar (h);
if (!bb)
return;
if (bb != NULL) {
set_label_text (bb, idx, "");
bb->labels[idx - 1].tag = BBFUNC_NONE;
}
}
void
buttonbar_set_label_data (Dlg_head *h, int idx, const char *text,
buttonbar_set_label_data (WButtonBar *bb, int idx, const char *text,
buttonbarfn cback, void *data)
{
WButtonBar *bb = find_buttonbar (h);
if (!bb)
return;
if (bb != NULL) {
assert (cback != (buttonbarfn) NULL);
set_label_text (bb, idx, text);
bb->labels[idx - 1].tag = BBFUNC_PTR;
bb->labels[idx - 1].u.fn_ptr = cback;
bb->labels[idx - 1].data = data;
}
}
void
buttonbar_set_label (Dlg_head *h, int idx, const char *text, voidfn cback)
buttonbar_set_label (WButtonBar *bb, int idx, const char *text, voidfn cback)
{
WButtonBar *bb = find_buttonbar (h);
if (!bb)
return;
if (bb != NULL) {
assert (cback != (voidfn) NULL);
set_label_text (bb, idx, text);
bb->labels[idx - 1].tag = BBFUNC_VOID;
bb->labels[idx - 1].u.fn_void = cback;
}
}
void
@ -2855,13 +2843,9 @@ buttonbar_set_visible (WButtonBar *bb, gboolean visible)
}
void
buttonbar_redraw (Dlg_head *h)
buttonbar_redraw (WButtonBar *bb)
{
WButtonBar *bb = find_buttonbar (h);
if (!bb)
return;
if (bb != NULL)
send_message ((Widget *) bb, WIDGET_DRAW, 0);
}

View File

@ -255,12 +255,12 @@ char *listbox_add_item (WListbox *l, enum append_pos pos, int
WButtonBar *find_buttonbar (const Dlg_head *h);
void buttonbar_clear_label (Dlg_head *, int idx);
void buttonbar_set_label (Dlg_head *, int index, const char *text, voidfn);
void buttonbar_set_label_data (Dlg_head *h, int idx, const char *text,
void buttonbar_clear_label (WButtonBar *bb, int idx);
void buttonbar_set_label (WButtonBar *bb, int index, const char *text, voidfn cback);
void buttonbar_set_label_data (WButtonBar *bb, int idx, const char *text,
buttonbarfn cback, void *data);
void buttonbar_set_visible (WButtonBar *bb, gboolean visible);
void buttonbar_redraw (Dlg_head *h);
void buttonbar_redraw (WButtonBar *bb);
void free_completions (WInput *in);
void complete (WInput *in);