From 1e32a51d2d90946fef8c07542aa79d26fd66fcca Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 7 Dec 2009 21:22:16 +0300 Subject: [PATCH] Optimization of DLG_RESIZE message handling. Signed-off-by: Andrew Borodin --- edit/editwidget.c | 49 +++++++++++++--------------------------- src/layout.c | 31 +++++++++---------------- src/main.c | 5 ++++ src/viewer/actions_cmd.c | 21 +++++++++++++++++ src/viewer/display.c | 19 ---------------- src/viewer/internal.h | 1 - 6 files changed, 53 insertions(+), 73 deletions(-) diff --git a/edit/editwidget.c b/edit/editwidget.c index a0fa0ce11..33175d488 100644 --- a/edit/editwidget.c +++ b/edit/editwidget.c @@ -157,24 +157,6 @@ edit_event (Gpm_Event *event, void *data) return MOU_NORMAL; } -static void -edit_adjust_size (Dlg_head *h) -{ - WEdit *edit; - WButtonBar *b; - - edit = (WEdit *) find_widget_type (h, edit_callback); - b = find_buttonbar (h); - - widget_set_size (&edit->widget, 0, 0, LINES - 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 - menubar_arrange (edit_menubar); -#endif -} - static cb_ret_t edit_command_execute (WEdit *edit, unsigned long command) { @@ -187,11 +169,9 @@ edit_command_execute (WEdit *edit, unsigned long command) return MSG_HANDLED; } -static void -edit_set_buttonbar (WEdit *edit) +static inline void +edit_set_buttonbar (WEdit *edit, WButtonBar *bb) { - WButtonBar *bb = find_buttonbar (edit->widget.parent); - buttonbar_set_label (bb, 1, Q_("ButtonBar|Help"), 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); @@ -214,14 +194,26 @@ edit_dialog_callback (Dlg_head *h, Widget *sender, WButtonBar *buttonbar; edit = (WEdit *) find_widget_type (h, edit_callback); + menubar = find_menubar (h); + buttonbar = find_buttonbar (h); switch (msg) { case DLG_INIT: - edit_set_buttonbar (edit); + edit_set_buttonbar (edit, buttonbar); return MSG_HANDLED; case DLG_RESIZE: - edit_adjust_size (h); + widget_set_size (&edit->widget, 0, 0, LINES - 1, COLS); + widget_set_size (&buttonbar->widget , LINES - 1, 0, 1, COLS); + widget_set_size (&menubar->widget, 0, 0, 1, COLS); + menubar_arrange (menubar); + return MSG_HANDLED; + + case DLG_ACTION: + if (sender == (Widget *) menubar) + return send_message ((Widget *) edit, WIDGET_COMMAND, parm); + if (sender == (Widget *) buttonbar) + return send_message ((Widget *) edit, WIDGET_COMMAND, parm); return MSG_HANDLED; case DLG_VALIDATE: @@ -229,15 +221,6 @@ edit_dialog_callback (Dlg_head *h, Widget *sender, h->running = 1; return MSG_HANDLED; - case DLG_ACTION: - menubar = find_menubar (h); - if (sender == (Widget *) menubar) - return send_message ((Widget *) edit, WIDGET_COMMAND, parm); - buttonbar = find_buttonbar (h); - if (sender == (Widget *) buttonbar) - return send_message ((Widget *) edit, WIDGET_COMMAND, parm); - return MSG_HANDLED; - default: return default_dlg_callback (h, sender, msg, parm, data); } diff --git a/src/layout.c b/src/layout.c index 2a96283e6..9418a8223 100644 --- a/src/layout.c +++ b/src/layout.c @@ -198,9 +198,6 @@ static const char *output_lines_label; static WButton *bleft_widget, *bright_widget; -/* Declarations for static functions */ -static void low_level_change_screen_size (void); - static void _check_split (void) { if (_horizontal_split){ @@ -696,17 +693,7 @@ setup_panels (void) update_xterm_title_path (); } -void -sigwinch_handler (int dummy) -{ - (void) dummy; -#if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */ - low_level_change_screen_size (); -#endif - winch_flag = 1; -} - -static void +static inline void low_level_change_screen_size (void) { #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 @@ -732,6 +719,16 @@ low_level_change_screen_size (void) #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ } +void +sigwinch_handler (int dummy) +{ + (void) dummy; +#if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */ + low_level_change_screen_size (); +#endif + winch_flag = 1; +} + void change_screen_size (void) { @@ -758,7 +755,6 @@ change_screen_size (void) tty_keypad (TRUE); tty_nodelay (FALSE); #endif - setup_panels (); /* Inform all running dialogs */ d = current_dlg; @@ -767,10 +763,6 @@ change_screen_size (void) d = d->parent; } -#ifdef RESIZABLE_MENUBAR - menubar_arrange (the_menubar); -#endif - /* Now, force the redraw */ repaint_screen (); #endif /* TIOCGWINSZ */ @@ -800,7 +792,6 @@ void print_vfs_message (const char *msg, ...) char str [128]; va_start (ap, msg); - g_vsnprintf (str, sizeof (str), msg, ap); va_end (ap); diff --git a/src/main.c b/src/main.c index 6c77e4854..f88fd3001 100644 --- a/src/main.c +++ b/src/main.c @@ -1552,6 +1552,11 @@ midnight_callback (Dlg_head *h, Widget *sender, 1, LINES - keybar_visible - 1); return MSG_HANDLED; + case DLG_RESIZE: + setup_panels (); + menubar_arrange (the_menubar); + return MSG_HANDLED; + case DLG_IDLE: /* We only need the first idle event to show user menu after start */ set_idle_proc (h, 0); diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 7000c38eb..0927721b5 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -505,6 +505,27 @@ mcview_handle_key (mcview_t * view, int key) return MSG_NOT_HANDLED; } + +/* --------------------------------------------------------------------------------------------- */ + +static inline void +mcview_adjust_size (Dlg_head *h) +{ + mcview_t *view; + WButtonBar *b; + + /* Look up the viewer and the buttonbar, we assume only two widgets here */ + 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); + + mcview_compute_areas (view); + mcview_update_bytes_per_line (view); +} + + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ diff --git a/src/viewer/display.c b/src/viewer/display.c index 8bf14efaa..808b63d17 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -386,25 +386,6 @@ mcview_display_ruler (mcview_t * view) /* --------------------------------------------------------------------------------------------- */ -void -mcview_adjust_size (Dlg_head *h) -{ - mcview_t *view; - WButtonBar *b; - - /* Look up the viewer and the buttonbar, we assume only two widgets here */ - 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); - - mcview_compute_areas (view); - mcview_update_bytes_per_line (view); -} - -/* --------------------------------------------------------------------------------------------- */ - void mcview_percent (mcview_t * view, off_t p) { diff --git a/src/viewer/internal.h b/src/viewer/internal.h index de40dc415..b53cc3aa2 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -243,7 +243,6 @@ void mcview_update_bytes_per_line (mcview_t *view); void mcview_display_toggle_ruler (mcview_t *view); void mcview_display_clean (mcview_t *view); void mcview_display_ruler (mcview_t *view); -void mcview_adjust_size (Dlg_head *h); void mcview_percent (mcview_t *view, off_t p); /* growbuf.c: */