From 47c4744347b7d5b468bae2bbc6cbb2e0d4254195 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 14 Oct 2009 13:27:41 +0400 Subject: [PATCH] Ticket #1451: fixed placement of choose encoding dialog window. The "Choose codepage" dialog (for file panel) is centered over the according panel. Renamed create_listbox_window_delta() function to create_listbox_window_centered(). Now this function takes in coordinates of dialog center. Changed argumets order to unified dialogs API. Signed-off-by: Andrew Borodin --- edit/choosesyntax.c | 2 +- src/boxes.c | 2 +- src/cmd.c | 9 ++------- src/listmode.c | 2 +- src/screen.c | 14 +++++++------- src/selcodepage.c | 10 +++++----- src/selcodepage.h | 2 +- src/user.c | 2 +- src/wtools.c | 38 ++++++++++++++++++++++++++++++-------- src/wtools.h | 6 +++--- 10 files changed, 52 insertions(+), 35 deletions(-) diff --git a/edit/choosesyntax.c b/edit/choosesyntax.c index a12cb5a4f..20df93526 100644 --- a/edit/choosesyntax.c +++ b/edit/choosesyntax.c @@ -45,7 +45,7 @@ static int exec_edit_syntax_dialog (const char **names) { int i; - Listbox *syntaxlist = create_listbox_window (MAX_ENTRY_LEN, LIST_LINES, + Listbox *syntaxlist = create_listbox_window (LIST_LINES, MAX_ENTRY_LEN, _(" Choose syntax highlighting "), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL); LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL); diff --git a/src/boxes.c b/src/boxes.c index 7f0f3321c..80944e6a8 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -541,7 +541,7 @@ sel_charset_button (int action) (void) action; - new_dcp = select_charset (0, 0, new_display_codepage, TRUE); + new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; diff --git a/src/cmd.c b/src/cmd.c index 0728622b1..de413554e 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1436,11 +1436,6 @@ toggle_listing_cmd (void) void encoding_cmd (void) { - WPanel *panel; - - if (!SELECTED_IS_PANEL) - return; - - panel = MENU_PANEL; - set_panel_encoding (panel); + if (SELECTED_IS_PANEL) + set_panel_encoding (MENU_PANEL); } diff --git a/src/listmode.c b/src/listmode.c index c9095906d..bf1620f71 100644 --- a/src/listmode.c +++ b/src/listmode.c @@ -102,7 +102,7 @@ select_new_item (void) possible_items = panel_get_user_possible_fields(NULL); mylistbox = - create_listbox_window (12, 20, " Add listing format item ", + create_listbox_window (20, 12, " Add listing format item ", listmode_section); for (i = 0; possible_items[i]; i++) { listbox_add_item (mylistbox->list, 0, 0, possible_items[i], NULL); diff --git a/src/screen.c b/src/screen.c index c814c9d77..9a1f0135c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -3126,20 +3126,20 @@ set_panel_encoding (WPanel *panel) const char *encoding = NULL; char *cd_path; #ifdef HAVE_CHARSET + int center_x, center_y; const char *errmsg; - int offset; int r; if (horizontal_split) { - offset = (get_current_index () != 0) ? panel->widget.lines : -panel->widget.lines; - r = select_charset (0, offset, source_codepage, FALSE); + center_y = panel->widget.y + panel->widget.lines/2; + center_x = COLS/2; } else { - offset = (panel->widget.cols == COLS) ? 0 - : (get_current_index () != 0) ? panel->widget.cols - : -panel->widget.cols; - r = select_charset (offset, 0, source_codepage, FALSE); + center_y = LINES/2; + center_x = panel->widget.x + panel->widget.cols/2; } + r = select_charset (center_y, center_x, source_codepage, FALSE); + if (r == SELECT_CHARSET_CANCEL) return; /* Cancel */ diff --git a/src/selcodepage.c b/src/selcodepage.c index fb1759d86..a3be1a1d4 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -36,7 +36,7 @@ #include "selcodepage.h" #include "main.h" -#define ENTRY_LEN 35 +#define ENTRY_LEN 30 /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */ int source_codepage = -1; @@ -55,14 +55,14 @@ get_hotkey (int n) * >= 0 : charset number */ int -select_charset (int delta_x, int delta_y, int current_charset, gboolean seldisplay) +select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay) { int i; char buffer[255]; /* Create listbox */ - Listbox *listbox = create_listbox_window_delta (delta_x, delta_y, - ENTRY_LEN + 2, n_codepages + 1, + Listbox *listbox = create_listbox_window_centered (center_y, center_x, + n_codepages + 1, ENTRY_LEN + 2, _("Choose codepage"), "[Codepages Translation]"); @@ -114,7 +114,7 @@ do_select_codepage (void) const char *errmsg = NULL; int r; - r = select_charset (0, 0, source_codepage, FALSE); + r = select_charset (-1, -1, source_codepage, FALSE); if (r == SELECT_CHARSET_CANCEL) return FALSE; diff --git a/src/selcodepage.h b/src/selcodepage.h index e16def969..5f4844cbf 100644 --- a/src/selcodepage.h +++ b/src/selcodepage.h @@ -10,7 +10,7 @@ #include "global.h" -int select_charset (int delta_x, int delta_y, int current_charset, gboolean seldisplay); +int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay); gboolean do_select_codepage (void); /* some results of select_charset() */ diff --git a/src/user.c b/src/user.c index c970df74f..f47036348 100644 --- a/src/user.c +++ b/src/user.c @@ -863,7 +863,7 @@ user_menu_cmd (WEdit *edit_widget) max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ - listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "), + listbox = create_listbox_window (menu_lines, max_cols + 2,_(" User menu "), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { diff --git a/src/wtools.c b/src/wtools.c index ce0d3d0e7..d81b5414c 100644 --- a/src/wtools.c +++ b/src/wtools.c @@ -36,9 +36,10 @@ #include "global.h" #include "../src/tty/tty.h" -#include "../src/skin/skin.h" /* INPUT_COLOR */ #include "../src/tty/key.h" /* tty_getch() */ +#include "../src/skin/skin.h" /* INPUT_COLOR */ + #include "dialog.h" #include "widget.h" #include "wtools.h" @@ -47,7 +48,7 @@ Listbox * -create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, +create_listbox_window_centered (int center_y, int center_x, int lines, int cols, const char *title, const char *help) { const int listbox_colors[DLG_COLOR_NUM] = @@ -58,6 +59,8 @@ create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, MENU_HOTSEL_COLOR, }; + const int space = 4; + int xpos, ypos, len; Listbox *listbox; @@ -72,14 +75,33 @@ create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, cols = min (cols, COLS - 6); /* adjust position */ - xpos = (COLS - cols + delta_x) / 2; - ypos = (LINES - lines + delta_y) / 2 - 2; + if ((center_y < 0) || (center_x < 0)) { + ypos = LINES/2; + xpos = COLS/2; + } else { + ypos = center_y; + xpos = center_x; + } + + ypos -= lines/2; + xpos -= cols/2; + + if (ypos + lines >= LINES) + ypos = LINES - lines - space; + if (ypos < 0) + ypos = 0; + + if (xpos + cols >= COLS) + xpos = COLS - cols - space; + if (xpos < 0) + xpos = 0; listbox = g_new (Listbox, 1); listbox->dlg = - create_dlg (ypos, xpos, lines + 4, cols + 4, listbox_colors, NULL, - help, title, DLG_REVERSE); + create_dlg (ypos, xpos, lines + space, cols + space, + listbox_colors, NULL, + help, title, DLG_REVERSE | DLG_TRYUP); listbox->list = listbox_new (2, 2, lines, cols, NULL); add_widget (listbox->dlg, listbox->list); @@ -88,9 +110,9 @@ create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, } Listbox * -create_listbox_window (int cols, int lines, const char *title, const char *help) +create_listbox_window (int lines, int cols, const char *title, const char *help) { - return create_listbox_window_delta (0, 0, cols, lines, title, help); + return create_listbox_window_centered (-1, -1, lines, cols, title, help); } /* Returns the number of the item selected */ diff --git a/src/wtools.h b/src/wtools.h index 1fc45ad92..5d06391c2 100644 --- a/src/wtools.h +++ b/src/wtools.h @@ -16,9 +16,9 @@ typedef struct { } Listbox; /* Listbox utility functions */ -Listbox *create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, const char *title, const char *help); - -Listbox *create_listbox_window (int cols, int lines, const char *title, const char *help); +Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols, + const char *title, const char *help); +Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help); #define LISTBOX_APPEND_TEXT(l,h,t,d) \ listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)