From c78a1dbc1d0d2c727cbdf575e891ff0a34be215e Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Tue, 29 Oct 2013 21:09:04 +1100 Subject: winecon maxwin --- programs/wineconsole/curses.c | 18 ++++++++++++++++++ programs/wineconsole/user.c | 21 +++++++++++++++++++++ programs/wineconsole/winecon_private.h | 1 + programs/wineconsole/wineconsole.c | 13 ++++++++++--- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/programs/wineconsole/curses.c b/programs/wineconsole/curses.c index 735ec97..10772fa 100644 --- a/programs/wineconsole/curses.c +++ b/programs/wineconsole/curses.c @@ -241,6 +241,23 @@ sym_not_found: #define acs_map (*p_acs_map) /****************************************************************** + * WCCURSES_SetMaxWindowSize + * + * Calculates the maximum possible console window size. + */ +static COORD WCCURSES_SetMaxWindowSize(int font_width, int font_height) +{ + COORD c; + + getmaxyx(stdscr, c.Y, c.X); + + if (c.X < 80) c.X = 80; + if (c.Y < 25) c.Y = 25; + + return c; +} + +/****************************************************************** * WCCURSES_ResizeScreenBuffer * * @@ -1047,6 +1064,7 @@ enum init_return WCCURSES_InitBackend(struct inner_data* data) if (!data->private) return init_failed; data->fnMainLoop = WCCURSES_MainLoop; + data->fnSetMaxWindowSize = WCCURSES_SetMaxWindowSize; data->fnPosCursor = WCCURSES_PosCursor; data->fnShapeCursor = WCCURSES_ShapeCursor; data->fnComputePositions = WCCURSES_ComputePositions; diff --git a/programs/wineconsole/user.c b/programs/wineconsole/user.c index 5c8c2c0..53ad691 100644 --- a/programs/wineconsole/user.c +++ b/programs/wineconsole/user.c @@ -42,6 +42,26 @@ const COLORREF WCUSER_ColorMap[16] = static BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONTW* font); /****************************************************************** + * WCUSER_SetMaxWindowSize + * + * Calculates the maximum possible console window size. + */ +static COORD WCUSER_SetMaxWindowSize(int font_width, int font_height) +{ + RECT workarea; + COORD c; + + SystemParametersInfoW(SPI_GETWORKAREA, 0, &workarea, 0); + c.X = (workarea.right / font_width) - 4; + c.Y = (workarea.bottom / font_height) - 3; + + if (c.X < 80) c.X = 80; + if (c.Y < 25) c.Y = 25; + + return c; +} + +/****************************************************************** * WCUSER_FillMemDC * * Fills the Mem DC with current cells values @@ -1419,6 +1439,7 @@ enum init_return WCUSER_InitBackend(struct inner_data* data) if (!data->private) return init_failed; data->fnMainLoop = WCUSER_MainLoop; + data->fnSetMaxWindowSize = WCUSER_SetMaxWindowSize; data->fnPosCursor = WCUSER_PosCursor; data->fnShapeCursor = WCUSER_ShapeCursor; data->fnComputePositions = WCUSER_ComputePositions; diff --git a/programs/wineconsole/winecon_private.h b/programs/wineconsole/winecon_private.h index 1daf581..d6db7fa 100644 --- a/programs/wineconsole/winecon_private.h +++ b/programs/wineconsole/winecon_private.h @@ -65,6 +65,7 @@ struct inner_data { BOOL dying; /* to TRUE when we've been notified by server that child has died */ int (*fnMainLoop)(struct inner_data* data); + COORD (*fnSetMaxWindowSize)(int font_width, int font_height); void (*fnPosCursor)(const struct inner_data* data); void (*fnShapeCursor)(struct inner_data* data, int size, int vis, BOOL force); void (*fnComputePositions)(struct inner_data* data); diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c index 7698521..5f01095 100644 --- a/programs/wineconsole/wineconsole.c +++ b/programs/wineconsole/wineconsole.c @@ -370,6 +370,9 @@ void WINECON_GrabChanges(struct inner_data* data) */ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cfg) { + COORD max_window; + int window_width, window_height; + if (data->in_set_config) return; data->in_set_config = TRUE; if (data->curcfg.cursor_size != cfg->cursor_size || @@ -399,7 +402,7 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf } data->curcfg.menu_mask = cfg->menu_mask; data->curcfg.quick_edit = cfg->quick_edit; - if (1 /* FIXME: font info has changed */) + if (data->curcfg.cell_width != cfg->cell_width || data->curcfg.cell_height != cfg->cell_height) { data->fnSetFont(data, cfg->face_name, cfg->cell_height, cfg->font_weight); } @@ -426,7 +429,7 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf } while (0) #define ChgWinHPos() do {pos.Left = cfg->win_pos.X - data->curcfg.win_pos.X; \ pos.Top = 0; \ - pos.Right = pos.Left + cfg->win_width - data->curcfg.win_width; \ + pos.Right = pos.Left + window_width - data->curcfg.win_width; \ pos.Bottom = 0; \ SetConsoleWindowInfo(data->hConOut, FALSE, &pos);\ } while (0) @@ -441,10 +444,14 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf #define ChgWinVPos() do {pos.Left = 0; \ pos.Top = cfg->win_pos.Y - data->curcfg.win_pos.Y; \ pos.Right = 0; \ - pos.Bottom = pos.Top + cfg->win_height - data->curcfg.win_height; \ + pos.Bottom = pos.Top + window_height - data->curcfg.win_height; \ SetConsoleWindowInfo(data->hConOut, FALSE, &pos);\ } while (0) + max_window = data->fnSetMaxWindowSize(cfg->cell_width, cfg->cell_height); + window_width = cfg->sb_width > max_window.X ? max_window.X : cfg->sb_width; + window_height = cfg->sb_height > max_window.Y ? max_window.Y : cfg->sb_height; + do { COORD c; -- 1.7.10.4