mirror of https://github.com/MidnightCommander/mc
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 <aborodin@vmail.ru>
This commit is contained in:
parent
5f3447a66c
commit
47c4744347
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
14
src/screen.c
14
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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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() */
|
||||
|
|
|
@ -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++) {
|
||||
|
|
38
src/wtools.c
38
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 */
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue