From 5a73255e97ac417640274e014d50a58e3fa51255 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 15 Sep 2001 15:54:24 +0000 Subject: [PATCH] Three more patches from RDB: one to make Atomica work right, one to fiddle with the widths of characters in DBCS screen fonts, and (the big one) one to enable a mode in which resizing the window locks the terminal size and lets the font change, instead of vice versa. That should shut up a few feature requests! git-svn-id: svn://svn.tartarus.org/sgt/putty@1269 cda61777-01e9-0310-a592-d414129be87e --- putty.h | 9 +- settings.c | 8 +- terminal.c | 73 ++++-- unicode.c | 9 +- windlg.c | 27 ++- window.c | 742 +++++++++++++++++++++++++++++++++++++++++++++---------------- 6 files changed, 643 insertions(+), 225 deletions(-) diff --git a/putty.h b/putty.h index 371945f0..b6b13344 100644 --- a/putty.h +++ b/putty.h @@ -66,6 +66,7 @@ #define UCSERR (ATTR_LINEDRW|'a') /* UCS Format error character. */ #define UCSWIDE 0x303F +#define ATTR_NARROW 0x20000000UL #define ATTR_WIDE 0x10000000UL #define ATTR_BOLD 0x01000000UL #define ATTR_UNDER 0x02000000UL @@ -92,8 +93,6 @@ typedef HDC Context; GLOBAL int rows, cols, savelines; -GLOBAL int font_width, font_height; - #define INBUF_SIZE 2048 GLOBAL unsigned char inbuf[INBUF_SIZE]; GLOBAL int inbuf_head; @@ -113,6 +112,7 @@ GLOBAL int repeat_off, cr_lf_return; GLOBAL int seen_key_event; GLOBAL int seen_disp_event; +GLOBAL int alt_pressed; GLOBAL int session_closed; @@ -313,6 +313,7 @@ typedef struct { char bell_wavefile[FILENAME_MAX]; int scrollbar; int locksize; + int lockfont; int bce; int blinktext; int win_name_always; @@ -326,6 +327,7 @@ typedef struct { int logxfovr; int hide_mouseptr; int sunken_edge; + int window_border; char answerback[256]; /* Colour options */ int try_palette; @@ -386,9 +388,10 @@ struct RSAKey; /* be a little careful of scope */ /* * Exports from window.c. */ -void request_resize(int, int, int); +void request_resize(int, int); void do_text(Context, int, int, char *, int, unsigned long, int); void do_cursor(Context, int, int, char *, int, unsigned long, int); +int CharWidth(Context ctx, int uc); void set_title(char *); void set_icon(char *); void set_sbar(int, int, int); diff --git a/settings.c b/settings.c index 07103c31..31faf3ab 100644 --- a/settings.c +++ b/settings.c @@ -201,6 +201,7 @@ void save_settings(char *section, int do_host, Config * cfg) write_setting_i(sesskey, "FullScreenOnAltEnter", cfg->fullscreenonaltenter); write_setting_i(sesskey, "HideMousePtr", cfg->hide_mouseptr); write_setting_i(sesskey, "SunkenEdge", cfg->sunken_edge); + write_setting_i(sesskey, "WindowBorder", cfg->window_border); write_setting_i(sesskey, "CurType", cfg->cursor_type); write_setting_i(sesskey, "BlinkCur", cfg->blink_cur); write_setting_i(sesskey, "Beep", cfg->beep); @@ -251,6 +252,7 @@ void save_settings(char *section, int do_host, Config * cfg) write_setting_i(sesskey, "ScrollOnKey", cfg->scroll_on_key); write_setting_i(sesskey, "ScrollOnDisp", cfg->scroll_on_disp); write_setting_i(sesskey, "LockSize", cfg->locksize); + write_setting_i(sesskey, "LockFont", cfg->lockfont); write_setting_i(sesskey, "BCE", cfg->bce); write_setting_i(sesskey, "BlinkText", cfg->blinktext); write_setting_i(sesskey, "X11Forward", cfg->x11_forward); @@ -378,6 +380,7 @@ void load_settings(char *section, int do_host, Config * cfg) gppi(sesskey, "FullScreenOnAltEnter", 0, &cfg->fullscreenonaltenter); gppi(sesskey, "HideMousePtr", 0, &cfg->hide_mouseptr); gppi(sesskey, "SunkenEdge", 0, &cfg->sunken_edge); + gppi(sesskey, "WindowBorder", 1, &cfg->window_border); gppi(sesskey, "CurType", 0, &cfg->cursor_type); gppi(sesskey, "BlinkCur", 0, &cfg->blink_cur); /* pedantic compiler tells me I can't use &cfg->beep as an int * :-) */ @@ -397,7 +400,7 @@ void load_settings(char *section, int do_host, Config * cfg) gpps(sesskey, "WinTitle", "", cfg->wintitle, sizeof(cfg->wintitle)); gppi(sesskey, "TermWidth", 80, &cfg->width); gppi(sesskey, "TermHeight", 24, &cfg->height); - gpps(sesskey, "Font", "Courier", cfg->font, sizeof(cfg->font)); + gpps(sesskey, "Font", "Courier New", cfg->font, sizeof(cfg->font)); gppi(sesskey, "FontIsBold", 0, &cfg->fontisbold); gppi(sesskey, "FontCharSet", ANSI_CHARSET, &cfg->fontcharset); gppi(sesskey, "FontHeight", 10, &cfg->fontheight); @@ -413,7 +416,7 @@ void load_settings(char *section, int do_host, Config * cfg) newh--; cfg->fontheight = newh; } - gppi(sesskey, "FontVTMode", VT_OEMANSI, (int *) &cfg->vtmode); + gppi(sesskey, "FontVTMode", VT_UNICODE, (int *) &cfg->vtmode); gppi(sesskey, "TryPalette", 0, &cfg->try_palette); gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour); for (i = 0; i < 22; i++) { @@ -472,6 +475,7 @@ void load_settings(char *section, int do_host, Config * cfg) gppi(sesskey, "ScrollOnKey", 0, &cfg->scroll_on_key); gppi(sesskey, "ScrollOnDisp", 1, &cfg->scroll_on_disp); gppi(sesskey, "LockSize", 0, &cfg->locksize); + gppi(sesskey, "LockFont", cfg->locksize, &cfg->lockfont); gppi(sesskey, "BCE", 0, &cfg->bce); gppi(sesskey, "BlinkText", 0, &cfg->blinktext); gppi(sesskey, "X11Forward", 0, &cfg->x11_forward); diff --git a/terminal.c b/terminal.c index 7300e96b..ab97e3c4 100644 --- a/terminal.c +++ b/terminal.c @@ -497,6 +497,7 @@ void term_size(int newrows, int newcols, int newsavelines) update_sbar(); term_update(); + back->size(); } /* @@ -851,7 +852,7 @@ static void toggle_mode(int mode, int query, int state) break; case 3: /* 80/132 columns */ deselect(); - request_resize(state ? 132 : 80, rows, 1); + request_resize(state ? 132 : 80, rows); reset_132 = state; break; case 5: /* reverse video */ @@ -1339,12 +1340,18 @@ void term_out(void) width = wcwidth((wchar_t) c); switch (width) { case 2: - if (curs.x + 1 != cols) { - *cpos++ = c | ATTR_WIDE | curr_attr; - *cpos++ = UCSWIDE | curr_attr; - curs.x++; - break; + *cpos++ = c | curr_attr; + if (++curs.x == cols) { + *cpos |= LATTR_WRAPPED; + if (curs.y == marg_b) + scroll(marg_t, marg_b, 1, TRUE); + else if (curs.y < rows - 1) + curs.y++; + curs.x = 0; + fix_cpos; } + *cpos++ = UCSWIDE | curr_attr; + break; case 1: *cpos++ = c | curr_attr; break; @@ -1461,7 +1468,7 @@ void term_out(void) compatibility(VT100); power_on(); if (reset_132) { - request_resize(80, rows, 1); + request_resize(80, rows); reset_132 = 0; } fix_cpos; @@ -1906,7 +1913,7 @@ void term_out(void) compatibility(VT340TEXT); if (esc_nargs <= 1 && (esc_args[0] < 1 || esc_args[0] >= 24)) { - request_resize(cols, def(esc_args[0], 24), 0); + request_resize(cols, def(esc_args[0], 24)); deselect(); } break; @@ -1932,9 +1939,7 @@ void term_out(void) */ compatibility(VT420); if (esc_nargs == 1 && esc_args[0] > 0) { - request_resize(cols, - def(esc_args[0], cfg.height), - 0); + request_resize(cols, def(esc_args[0], cfg.height)); deselect(); } break; @@ -1945,8 +1950,7 @@ void term_out(void) */ compatibility(VT340TEXT); if (esc_nargs <= 1) { - request_resize(def(esc_args[0], cfg.width), - rows, 0); + request_resize(def(esc_args[0], cfg.width), rows); deselect(); } break; @@ -2074,9 +2078,9 @@ void term_out(void) */ if (!has_compat(VT420) && has_compat(VT100)) { if (reset_132) - request_resize(132, 24, 1); + request_resize(132, 24); else - request_resize(80, 24, 1); + request_resize(80, 24); } #endif break; @@ -2531,9 +2535,10 @@ static void do_paint(Context ctx, int may_optimise) if (dispcurs && (curstype != cursor || dispcurs != disptext + our_curs_y * (cols + 1) + curs.x)) { - if (dispcurs > disptext && (dispcurs[-1] & ATTR_WIDE)) + if (dispcurs > disptext && + (*dispcurs & (CHAR_MASK | CSET_MASK)) == UCSWIDE) dispcurs[-1] |= ATTR_INVALID; - if ((*dispcurs & ATTR_WIDE)) + if ( (dispcurs[1] & (CHAR_MASK | CSET_MASK)) == UCSWIDE) dispcurs[1] |= ATTR_INVALID; *dispcurs |= ATTR_INVALID; curstype = 0; @@ -2580,6 +2585,8 @@ static void do_paint(Context ctx, int may_optimise) } tattr |= (tchar & CSET_MASK); tchar &= CHAR_MASK; + if ((d[1] & (CHAR_MASK | CSET_MASK)) == UCSWIDE) + tattr |= ATTR_WIDE; /* Video reversing things */ tattr = (tattr ^ rv @@ -2596,6 +2603,17 @@ static void do_paint(Context ctx, int may_optimise) tattr &= ~ATTR_BLINK; } + /* + * Check the font we'll _probably_ be using to see if + * the character is wide when we don't want it to be. + */ + if ((tchar | tattr) != (disptext[idx]& ~ATTR_NARROW)) { + if ((tattr & ATTR_WIDE) == 0 && + CharWidth(ctx, (tchar | tattr) & 0xFFFF) == 2) + tattr |= ATTR_NARROW; + } else if (disptext[idx]&ATTR_NARROW) + tattr |= ATTR_NARROW; + /* Cursor here ? Save the 'background' */ if (i == our_curs_y && j == curs.x) { cursor_background = tattr | tchar; @@ -2716,14 +2734,14 @@ void term_invalidate(void) /* * Paint the window in response to a WM_PAINT message. */ -void term_paint(Context ctx, int l, int t, int r, int b) +void term_paint(Context ctx, int left, int top, int right, int bottom) { - int i, j, left, top, right, bottom; + int i, j; + if (left < 0) left = 0; + if (top < 0) top = 0; + if (right >= cols) right = cols-1; + if (bottom >= rows) bottom = rows-1; - left = l / font_width; - right = (r - 1) / font_width; - top = t / font_height; - bottom = (b - 1) / font_height; for (i = top; i <= bottom && i < rows; i++) { if ((disptext[i * (cols + 1) + cols] & LATTR_MODE) == LATTR_NORM) for (j = left; j <= right && j < cols; j++) @@ -2736,8 +2754,9 @@ void term_paint(Context ctx, int l, int t, int r, int b) /* This should happen soon enough, also for some reason it sometimes * fails to actually do anything when re-sizing ... painting the wrong * window perhaps ? - do_paint (ctx, FALSE); */ + if (alt_pressed) + do_paint (ctx, FALSE); } /* @@ -2987,6 +3006,12 @@ static int wordtype(int uc) break; } + /* For DBCS font's I can't do anything usefull. Even this will sometimes + * fail as there's such a thing as a double width space. :-( + */ + if (dbcs_screenfont && font_codepage == line_codepage) + return (uc != ' '); + if (uc < 0x80) return wordness[uc]; diff --git a/unicode.c b/unicode.c index 8dfe1d15..877aff6e 100644 --- a/unicode.c +++ b/unicode.c @@ -393,6 +393,13 @@ void init_ucs_tables(void) link_font(unitab_xterm, unitab_oemcp, ATTR_OEMCP); } + if (dbcs_screenfont && font_codepage != line_codepage) { + /* F***ing Microsoft fonts, Japanese and Korean codepage fonts + * have a currency symbol at 0x5C but their unicode value is + * still given as U+005C not the correct U+00A5. */ + unitab_line['\\'] = ATTR_OEMCP + '\\'; + } + /* Last chance, if !unicode then try poorman links. */ if (cfg.vtmode != VT_UNICODE) { static char poorman_scoacs[] = @@ -537,7 +544,7 @@ int check_compose(int first, int second) 0x43, 0x2f, 0x00a2}, { 0x43, 0x7c, 0x00a2}, { 0x4c, 0x2d, 0x00a3}, { - 0x4c, 0x3d, 0x00a3}, { + 0x4c, 0x3d, 0x20a4}, { 0x58, 0x4f, 0x00a4}, { 0x58, 0x30, 0x00a4}, { 0x59, 0x2d, 0x00a5}, { diff --git a/windlg.c b/windlg.c index 785f3800..33301a52 100644 --- a/windlg.c +++ b/windlg.c @@ -355,6 +355,7 @@ enum { IDCX_ABOUT = IDC_COLSSTATIC, IDC_COLSEDIT, IDC_LOCKSIZE, + IDC_LOCKFONT, IDC_SCROLLBAR, IDC_CLOSEWARN, IDC_SAVESTATIC, @@ -387,6 +388,8 @@ enum { IDCX_ABOUT = IDC_WINNAME, IDC_HIDEMOUSE, IDC_SUNKENEDGE, + IDC_WINBSTATIC, + IDC_WINBEDIT, appearancepanelend, connectionpanelstart, @@ -662,12 +665,14 @@ static void init_dlg_ctrls(HWND hwnd, int keepsess) CheckDlgButton(hwnd, IDC_WINNAME, cfg.win_name_always); CheckDlgButton(hwnd, IDC_HIDEMOUSE, cfg.hide_mouseptr); CheckDlgButton(hwnd, IDC_SUNKENEDGE, cfg.sunken_edge); + SetDlgItemInt(hwnd, IDC_WINBEDIT, cfg.window_border, FALSE); CheckRadioButton(hwnd, IDC_CURBLOCK, IDC_CURVERT, cfg.cursor_type == 0 ? IDC_CURBLOCK : cfg.cursor_type == 1 ? IDC_CURUNDER : IDC_CURVERT); CheckDlgButton(hwnd, IDC_BLINKCUR, cfg.blink_cur); CheckDlgButton(hwnd, IDC_SCROLLBAR, cfg.scrollbar); CheckDlgButton(hwnd, IDC_LOCKSIZE, cfg.locksize); + CheckDlgButton(hwnd, IDC_LOCKFONT, cfg.lockfont); CheckRadioButton(hwnd, IDC_COEALWAYS, IDC_COENORMAL, cfg.close_on_exit == COE_NORMAL ? IDC_COENORMAL : cfg.close_on_exit == @@ -1037,7 +1042,8 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) multiedit(&cp, "&Rows", IDC_ROWSSTATIC, IDC_ROWSEDIT, 50, "Colu&mns", IDC_COLSSTATIC, IDC_COLSEDIT, 50, NULL); - checkbox(&cp, "Lock window size against resi&zing", IDC_LOCKSIZE); + checkbox(&cp, "Lock terminal size against resi&zing", IDC_LOCKSIZE); + checkbox(&cp, "Lock font size against resi&zing", IDC_LOCKFONT); endbox(&cp); beginbox(&cp, "Control the scrollback in the window", IDC_BOX_WINDOW2); @@ -1062,8 +1068,8 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) /* The Appearance panel. Accelerators used: [acgo] luvb h ti p s */ struct ctlpos cp; ctlposinit(&cp, hwnd, 80, 3, 13); - bartitle(&cp, "Options controlling PuTTY's appearance", - IDC_TITLE_APPEARANCE); + /* bartitle(&cp, "Options controlling PuTTY's appearance", + IDC_TITLE_APPEARANCE); */ beginbox(&cp, "Adjust the use of the cursor", IDC_BOX_APPEARANCE1); radioline(&cp, "Cursor appearance:", IDC_CURSORSTATIC, 3, "B&lock", IDC_CURBLOCK, @@ -1089,6 +1095,8 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) beginbox(&cp, "Adjust the window border", IDC_BOX_APPEARANCE5); checkbox(&cp, "&Sunken-edge border (slightly thicker)", IDC_SUNKENEDGE); + staticedit(&cp, "Gap between text and window edge", + IDC_WINBSTATIC, IDC_WINBEDIT, 20); endbox(&cp); } @@ -2058,6 +2066,13 @@ static int GenericMainDlgProc(HWND hwnd, UINT msg, cfg.sunken_edge = IsDlgButtonChecked(hwnd, IDC_SUNKENEDGE); break; + case IDC_WINBEDIT: + if (HIWORD(wParam) == EN_CHANGE) + MyGetDlgItemInt(hwnd, IDC_WINBEDIT, + &cfg.window_border); + if (cfg.window_border > 32) + cfg.window_border = 32; + break; case IDC_CURBLOCK: if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DOUBLECLICKED) @@ -2091,6 +2106,12 @@ static int GenericMainDlgProc(HWND hwnd, UINT msg, cfg.locksize = IsDlgButtonChecked(hwnd, IDC_LOCKSIZE); break; + case IDC_LOCKFONT: + if (HIWORD(wParam) == BN_CLICKED || + HIWORD(wParam) == BN_DOUBLECLICKED) + cfg.lockfont = + IsDlgButtonChecked(hwnd, IDC_LOCKFONT); + break; case IDC_WINEDIT: if (HIWORD(wParam) == EN_CHANGE) GetDlgItemText(hwnd, IDC_WINEDIT, cfg.wintitle, diff --git a/window.c b/window.c index 869e91f3..3eb9567c 100644 --- a/window.c +++ b/window.c @@ -49,7 +49,6 @@ #define IDM_SAVED_MIN 0x1000 #define IDM_SAVED_MAX 0x2000 -#define WM_IGNORE_SIZE (WM_XUSER + 1) #define WM_IGNORE_CLIP (WM_XUSER + 2) /* Needed for Chinese support and apparently not always defined. */ @@ -67,11 +66,18 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, unsigned char *output); static void cfgtopalette(void); static void init_palette(void); -static void init_fonts(int); +static void init_fonts(int, int); static void another_font(int); static void deinit_fonts(void); +/* Window layout information */ +static void reset_window(int); static int full_screen = 0, extra_width, extra_height; +static int font_width, font_height, font_dualwidth; +static int offset_width, offset_height; +static int was_zoomed = 0; +static int prev_rows, prev_cols; + static LONG old_wind_style; static WINDOWPLACEMENT old_wind_placement; @@ -91,14 +97,13 @@ static time_t last_movement = 0; #define FONT_WIDE 0x04 #define FONT_HIGH 0x08 #define FONT_NARROW 0x10 + #define FONT_OEM 0x20 #define FONT_OEMBOLD 0x21 #define FONT_OEMUND 0x22 #define FONT_OEMBOLDUND 0x23 -#define FONT_MSGOTHIC 0x40 -#define FONT_MINGLIU 0x60 -#define FONT_GULIMCHE 0x80 -#define FONT_MAXNO 0x8F + +#define FONT_MAXNO 0x2F #define FONT_SHIFT 5 static HFONT fonts[FONT_MAXNO]; static int fontflag[FONT_MAXNO]; @@ -381,7 +386,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) wndclass.hInstance = inst; wndclass.hIcon = LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON)); wndclass.hCursor = LoadCursor(NULL, IDC_IBEAM); - wndclass.hbrBackground = GetStockObject(BLACK_BRUSH); + wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = appname; @@ -424,7 +429,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) int exwinmode = 0; if (!cfg.scrollbar) winmode &= ~(WS_VSCROLL); - if (cfg.locksize) + if (cfg.locksize && cfg.lockfont) winmode &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); if (cfg.alwaysontop) exwinmode |= WS_EX_TOPMOST; @@ -440,9 +445,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) * Initialise the fonts, simultaneously correcting the guesses * for font_{width,height}. */ - bold_mode = cfg.bold_colour ? BOLD_COLOURS : BOLD_FONT; - und_mode = UND_FONT; - init_fonts(0); + init_fonts(0,0); /* * Correct the guesses for extra_{width,height}. @@ -451,8 +454,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) RECT cr, wr; GetWindowRect(hwnd, &wr); GetClientRect(hwnd, &cr); - extra_width = wr.right - wr.left - cr.right + cr.left; - extra_height = wr.bottom - wr.top - cr.bottom + cr.top; + offset_width = offset_height = cfg.window_border; + extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; + extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; } /* @@ -461,7 +465,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) */ guess_width = extra_width + font_width * cols; guess_height = extra_height + font_height * rows; - SendMessage(hwnd, WM_IGNORE_SIZE, 0, 0); SetWindowPos(hwnd, NULL, 0, 0, guess_width, guess_height, SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER); @@ -866,7 +869,7 @@ static void init_palette(void) * ordinary one (manual underlining by means of line drawing can * be done in a pinch). */ -static void init_fonts(int pick_width) +static void init_fonts(int pick_width, int pick_height) { TEXTMETRIC tm; CPINFO cpinfo; @@ -878,6 +881,9 @@ static void init_fonts(int pick_width) for (i = 0; i < FONT_MAXNO; i++) fonts[i] = NULL; + bold_mode = cfg.bold_colour ? BOLD_COLOURS : BOLD_FONT; + und_mode = UND_FONT; + if (cfg.fontisbold) { fw_dontcare = FW_BOLD; fw_bold = FW_HEAVY; @@ -888,10 +894,14 @@ static void init_fonts(int pick_width) hdc = GetDC(hwnd); - font_height = cfg.fontheight; - if (font_height > 0) { - font_height = - -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72); + if (pick_height) + font_height = pick_height; + else { + font_height = cfg.fontheight; + if (font_height > 0) { + font_height = + -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72); + } } font_width = pick_width; @@ -905,8 +915,17 @@ static void init_fonts(int pick_width) SelectObject(hdc, fonts[FONT_NORMAL]); GetTextMetrics(hdc, &tm); - font_height = tm.tmHeight; - font_width = tm.tmAveCharWidth; + + if (pick_width == 0 || pick_height == 0) { + font_height = tm.tmHeight; + font_width = tm.tmAveCharWidth; + } + font_dualwidth = (tm.tmAveCharWidth != tm.tmMaxCharWidth); + +#ifdef RDB_DEBUG_PATCH + debug(23, "Primary font H=%d, AW=%d, MW=%d", + tm.tmHeight, tm.tmAveCharWidth, tm.tmMaxCharWidth); +#endif { CHARSETINFO info; @@ -1046,7 +1065,7 @@ static void another_font(int fontno) if (fontno & FONT_WIDE) x *= 2; if (fontno & FONT_NARROW) - x /= 2; + x = (x+1)/2; if (fontno & FONT_OEM) c = OEM_CHARSET; if (fontno & FONT_BOLD) @@ -1074,25 +1093,21 @@ static void deinit_fonts(void) } } -void request_resize(int w, int h, int refont) +void request_resize(int w, int h) { int width, height; /* If the window is maximized supress resizing attempts */ - if (IsZoomed(hwnd)) - return; + if (IsZoomed(hwnd)) { + if (cfg.lockfont) + return; + } - if (refont && w != cols && (cols == 80 || cols == 132)) { - /* If font width too big for screen should we shrink the font more ? */ - if (w == 132) - font_width = ((font_width * cols + w / 2) / w); - else - font_width = 0; - deinit_fonts(); - bold_mode = cfg.bold_colour ? BOLD_COLOURS : BOLD_FONT; - und_mode = UND_FONT; - init_fonts(font_width); - } else { + if (cfg.lockfont && cfg.locksize) return; + if (h == rows && w == cols) return; + + /* Sanity checks ... */ + { static int first_time = 1; static RECT ss; @@ -1107,26 +1122,212 @@ void request_resize(int w, int h, int refont) } case 0: /* Make sure the values are sane */ - width = (ss.right - ss.left - extra_width) / font_width; - height = (ss.bottom - ss.top - extra_height) / font_height; + width = (ss.right - ss.left - extra_width) / 4; + height = (ss.bottom - ss.top - extra_height) / 6; - if (w > width) - w = width; - if (h > height) - h = height; + if (w > width || h > height) + return; if (w < 15) w = 15; if (h < 1) - w = 1; + h = 1; } } - width = extra_width + font_width * w; - height = extra_height + font_height * h; + term_size(h, w, cfg.savelines); + + if (cfg.lockfont) { + width = extra_width + font_width * w; + height = extra_height + font_height * h; - SetWindowPos(hwnd, NULL, 0, 0, width, height, - SWP_NOACTIVATE | SWP_NOCOPYBITS | - SWP_NOMOVE | SWP_NOZORDER); + SetWindowPos(hwnd, NULL, 0, 0, width, height, + SWP_NOACTIVATE | SWP_NOCOPYBITS | + SWP_NOMOVE | SWP_NOZORDER); + } else + reset_window(0); + + InvalidateRect(hwnd, NULL, TRUE); +} + +static void reset_window(int reinit) { + /* + * This function decides how to resize or redraw when the + * user changes something. + * + * This function doesn't like to change the terminal size but if the + * font size is locked that may be it's only soluion. + */ + int win_width, win_height; + RECT cr, wr; + +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window()")); +#endif + + /* Current window sizes ... */ + GetWindowRect(hwnd, &wr); + GetClientRect(hwnd, &cr); + + win_width = cr.right - cr.left; + win_height = cr.bottom - cr.top; + + /* Are we being forced to reload the fonts ? */ + if (reinit>1) { +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -- Forced deinit")); +#endif + deinit_fonts(); + init_fonts(0,0); + } + + /* Oh, looks like we're minimised */ + if (win_width == 0 || win_height == 0) + return; + + /* Is the window out of position ? */ + if ( !reinit && + (offset_width != (win_width-font_width*cols)/2 || + offset_height != (win_height-font_height*rows)/2) ){ + offset_width = (win_width-font_width*cols)/2; + offset_height = (win_height-font_height*rows)/2; + InvalidateRect(hwnd, NULL, TRUE); +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -> Reposition terminal")); +#endif + } + + if (IsZoomed(hwnd)) { + /* We're fullscreen, this means we must not change the size of + * the window so it's the font size or the terminal itself. + */ + + extra_width = wr.right - wr.left - cr.right + cr.left; + extra_height = wr.bottom - wr.top - cr.bottom + cr.top; + + if (!cfg.lockfont) { + if ( font_width != win_width/cols || + font_height != win_height/rows) { + deinit_fonts(); + init_fonts(win_width/cols, win_height/rows); + offset_width = (win_width-font_width*cols)/2; + offset_height = (win_height-font_height*rows)/2; + InvalidateRect(hwnd, NULL, TRUE); +#ifdef RDB_DEBUG_PATCH + debug((25, "reset_window() -> Z font resize to (%d, %d)", + font_width, font_height)); +#endif + } + } else { + if ( font_width != win_width/cols || + font_height != win_height/rows) { + /* Our only choice at this point is to change the + * size of the terminal; Oh well. + */ + term_size( win_height/font_height, win_width/font_width, + cfg.savelines); + offset_width = (win_width-font_width*cols)/2; + offset_height = (win_height-font_height*rows)/2; + InvalidateRect(hwnd, NULL, TRUE); +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -> Zoomed term_size")); +#endif + } + } + return; + } + + /* Hmm, a force re-init means we should ignore the current window + * so we resize to the default font size. + */ + if (reinit>0) { +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -> Forced re-init")); +#endif + + offset_width = offset_height = cfg.window_border; + extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; + extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; + + if (win_width != font_width*cols + offset_width*2 || + win_height != font_height*rows + offset_height*2) { + + /* If this is too large windows will resize it to the maximum + * allowed window size, we will then be back in here and resize + * the font or terminal to fit. + */ + SetWindowPos(hwnd, NULL, 0, 0, + font_width*cols + extra_width, + font_height*rows + extra_height, + SWP_NOMOVE | SWP_NOZORDER); + } + return; + } + + /* Okay the user doesn't want us to change the font so we try the + * window. But that may be too big for the screen which forces us + * to change the terminal. + */ + if ((cfg.lockfont && reinit==0) || reinit>0) { + offset_width = offset_height = cfg.window_border; + extra_width = wr.right - wr.left - cr.right + cr.left + offset_width*2; + extra_height = wr.bottom - wr.top - cr.bottom + cr.top +offset_height*2; + + if (win_width != font_width*cols + offset_width*2 || + win_height != font_height*rows + offset_height*2) { + + static RECT ss; + int width, height; + + GetClientRect(GetDesktopWindow(), &ss); + width = (ss.right - ss.left - extra_width) / font_width; + height = (ss.bottom - ss.top - extra_height) / font_height; + + /* Grrr too big */ + if ( rows > height || cols > width ) { + if ( height > rows ) height = rows; + if ( width > cols ) width = cols; + term_size(height, width, cfg.savelines); +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -> term resize to (%d,%d)", + height, width)); +#endif + } + + SetWindowPos(hwnd, NULL, 0, 0, + font_width*cols + extra_width, + font_height*rows + extra_height, + SWP_NOMOVE | SWP_NOZORDER); + + InvalidateRect(hwnd, NULL, TRUE); +#ifdef RDB_DEBUG_PATCH + debug((27, "reset_window() -> window resize to (%d,%d)", + font_width*cols + extra_width, + font_height*rows + extra_height)); +#endif + } + return; + } + + /* We're allowed to or must change the font but do we want to ? */ + + if (font_width != (win_width-cfg.window_border*2)/cols || + font_height != (win_height-cfg.window_border*2)/rows) { + + deinit_fonts(); + init_fonts((win_width-cfg.window_border*2)/cols, + (win_height-cfg.window_border*2)/rows); + offset_width = (win_width-font_width*cols)/2; + offset_height = (win_height-font_height*rows)/2; + + extra_width = wr.right - wr.left - cr.right + cr.left +offset_width*2; + extra_height = wr.bottom - wr.top - cr.bottom + cr.top+offset_height*2; + + InvalidateRect(hwnd, NULL, TRUE); +#ifdef RDB_DEBUG_PATCH + debug((25, "reset_window() -> font resize to (%d,%d)", + font_width, font_height)); +#endif + } } static void click(Mouse_Button b, int x, int y, int shift, int ctrl) @@ -1183,12 +1384,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; - static int ignore_size = FALSE; static int ignore_clip = FALSE; - static int just_reconfigged = FALSE; static int resizing = FALSE; static int need_backend_resize = FALSE; - static int defered_resize = FALSE; switch (message) { case WM_TIMER: @@ -1298,33 +1496,21 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, break; case IDM_RECONF: { - int prev_alwaysontop = cfg.alwaysontop; - int prev_sunken_edge = cfg.sunken_edge; - char oldlogfile[FILENAME_MAX]; - int oldlogtype; - int need_setwpos = FALSE; - int old_fwidth, old_fheight; - - strcpy(oldlogfile, cfg.logfilename); - oldlogtype = cfg.logtype; - old_fwidth = font_width; - old_fheight = font_height; + Config prev_cfg; + int init_lvl = 1; + GetWindowText(hwnd, cfg.wintitle, sizeof(cfg.wintitle)); + prev_cfg = cfg; if (!do_reconfig(hwnd)) break; - if (strcmp(oldlogfile, cfg.logfilename) || - oldlogtype != cfg.logtype) { + if (strcmp(prev_cfg.logfilename, cfg.logfilename) || + prev_cfg.logtype != cfg.logtype) { logfclose(); /* reset logging */ logfopen(); } - just_reconfigged = TRUE; - deinit_fonts(); - bold_mode = cfg.bold_colour ? BOLD_COLOURS : BOLD_FONT; - und_mode = UND_FONT; - init_fonts(0); sfree(logpal); /* * Flush the line discipline's edit buffer in the @@ -1338,6 +1524,13 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, cfgtopalette(); init_palette(); + /* Screen size changed ? */ + if (cfg.height != prev_cfg.height || + cfg.width != prev_cfg.width || + cfg.savelines != prev_cfg.savelines || + cfg.locksize ) + term_size(cfg.height, cfg.width, cfg.savelines); + /* Enable or disable the scroll bar, etc */ { LONG nflg, flag = GetWindowLong(hwnd, GWL_STYLE); @@ -1345,7 +1538,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, GetWindowLong(hwnd, GWL_EXSTYLE); nexflag = exflag; - if (cfg.alwaysontop != prev_alwaysontop) { + if (cfg.alwaysontop != prev_cfg.alwaysontop) { if (cfg.alwaysontop) { nexflag |= WS_EX_TOPMOST; SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, @@ -1366,84 +1559,51 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, nflg |= WS_VSCROLL; else nflg &= ~WS_VSCROLL; - if (cfg.locksize) + if (cfg.locksize && cfg.lockfont) nflg &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); else nflg |= (WS_THICKFRAME | WS_MAXIMIZEBOX); if (nflg != flag || nexflag != exflag) { - RECT cr, wr; - if (nflg != flag) SetWindowLong(hwnd, GWL_STYLE, nflg); if (nexflag != exflag) SetWindowLong(hwnd, GWL_EXSTYLE, nexflag); - SendMessage(hwnd, WM_IGNORE_SIZE, 0, 0); - SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOCOPYBITS | - SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER - | SWP_FRAMECHANGED); - - GetWindowRect(hwnd, &wr); - GetClientRect(hwnd, &cr); - extra_width = - wr.right - wr.left - cr.right + cr.left; - extra_height = - wr.bottom - wr.top - cr.bottom + cr.top; - need_setwpos = TRUE; - } - } + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | + SWP_FRAMECHANGED); - if (cfg.height != rows || - cfg.width != cols || - old_fwidth != font_width || - old_fheight != font_height || - cfg.savelines != savelines || - cfg.sunken_edge != prev_sunken_edge) - need_setwpos = TRUE; - - if (IsZoomed(hwnd)) { - int w, h; - RECT cr; - if (need_setwpos) - defered_resize = TRUE; - - GetClientRect(hwnd, &cr); - w = cr.right - cr.left; - h = cr.bottom - cr.top; - w = w / font_width; - if (w < 1) - w = 1; - h = h / font_height; - if (h < 1) - h = 1; - - term_size(h, w, cfg.savelines); - InvalidateRect(hwnd, NULL, TRUE); - back->size(); - } else { - term_size(cfg.height, cfg.width, cfg.savelines); - InvalidateRect(hwnd, NULL, TRUE); - if (need_setwpos) { - SetWindowPos(hwnd, NULL, 0, 0, - extra_width + font_width * cfg.width, - extra_height + - font_height * cfg.height, - SWP_NOACTIVATE | SWP_NOCOPYBITS | - SWP_NOMOVE | SWP_NOZORDER); + init_lvl = 2; } } + /* Oops */ - if (cfg.locksize && IsZoomed(hwnd)) + if (cfg.locksize && cfg.lockfont && IsZoomed(hwnd)) { force_normal(hwnd); + init_lvl = 2; + } + set_title(cfg.wintitle); if (IsIconic(hwnd)) { SetWindowText(hwnd, cfg.win_name_always ? window_name : icon_name); } + + if (strcmp(cfg.font, prev_cfg.font) != 0 || + strcmp(cfg.line_codepage, prev_cfg.line_codepage) != 0 || + cfg.fontisbold != prev_cfg.fontisbold || + cfg.fontheight != prev_cfg.fontheight || + cfg.fontcharset != prev_cfg.fontcharset || + cfg.vtmode != prev_cfg.vtmode || + cfg.bold_colour != prev_cfg.bold_colour || + (cfg.lockfont && !prev_cfg.lockfont)) + init_lvl = 2; + + InvalidateRect(hwnd, NULL, TRUE); + reset_window(init_lvl); } break; case IDM_COPYALL: @@ -1518,8 +1678,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, #define X_POS(l) ((int)(short)LOWORD(l)) #define Y_POS(l) ((int)(short)HIWORD(l)) -#define TO_CHR_X(x) (((x)<0 ? (x)-font_width+1 : (x)) / font_width) -#define TO_CHR_Y(y) (((y)<0 ? (y)-font_height+1: (y)) / font_height) +#define TO_CHR_X(x) ((((x)<0 ? (x)-font_width+1 : (x))-offset_width) / font_width) +#define TO_CHR_Y(y) ((((y)<0 ? (y)-font_height+1: (y))-offset_height) / font_height) #define WHEEL_DELTA 120 case WM_MOUSEWHEEL: { @@ -1651,8 +1811,42 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, SelectPalette(hdc, pal, TRUE); RealizePalette(hdc); } - term_paint(hdc, p.rcPaint.left, p.rcPaint.top, - p.rcPaint.right, p.rcPaint.bottom); + term_paint(hdc, + (p.rcPaint.left-offset_width)/font_width, + (p.rcPaint.top-offset_height)/font_height, + (p.rcPaint.right-offset_width-1)/font_width, + (p.rcPaint.bottom-offset_height-1)/font_height); + + if (p.fErase || + p.rcPaint.left < offset_width || + p.rcPaint.top < offset_height || + p.rcPaint.right >= offset_width + font_width*cols || + p.rcPaint.bottom>= offset_height + font_height*rows) + { + HBRUSH fillcolour, oldbrush; + HPEN edge, oldpen; + fillcolour = CreateSolidBrush ( + colours[(ATTR_DEFBG>>ATTR_BGSHIFT)*2]); + oldbrush = SelectObject(hdc, fillcolour); + edge = CreatePen(PS_SOLID, 0, + colours[(ATTR_DEFBG>>ATTR_BGSHIFT)*2]); + oldpen = SelectObject(hdc, edge); + + ExcludeClipRect(hdc, + offset_width, offset_height, + offset_width+font_width*cols, + offset_height+font_height*rows); + + Rectangle(hdc, p.rcPaint.left, p.rcPaint.top, + p.rcPaint.right, p.rcPaint.bottom); + + // SelectClipRgn(hdc, NULL); + + SelectObject(hdc, oldbrush); + DeleteObject(fillcolour); + SelectObject(hdc, oldpen); + DeleteObject(edge); + } SelectObject(hdc, GetStockObject(SYSTEM_FONT)); SelectObject(hdc, GetStockObject(WHITE_PEN)); EndPaint(hwnd, &p); @@ -1691,10 +1885,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, term_out(); term_update(); break; - case WM_IGNORE_SIZE: - ignore_size = TRUE; /* don't panic on next WM_SIZE msg */ - break; case WM_ENTERSIZEMOVE: +#ifdef RDB_DEBUG_PATCH + debug((27, "WM_ENTERSIZEMOVE")); +#endif EnableSizeTip(1); resizing = TRUE; need_backend_resize = FALSE; @@ -1702,14 +1896,40 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case WM_EXITSIZEMOVE: EnableSizeTip(0); resizing = FALSE; - if (need_backend_resize) - back->size(); +#ifdef RDB_DEBUG_PATCH + debug((27, "WM_EXITSIZEMOVE")); +#endif + if (need_backend_resize) { + term_size(cfg.height, cfg.width, cfg.savelines); + InvalidateRect(hwnd, NULL, TRUE); + } break; case WM_SIZING: - { + /* + * This does two jobs: + * 1) Keep the sizetip uptodate + * 2) Make sure the window size is _stepped_ in units of the font size. + */ + if (!cfg.locksize && !alt_pressed) { int width, height, w, h, ew, eh; LPRECT r = (LPRECT) lParam; + if ( !need_backend_resize && + (cfg.height != rows || cfg.width != cols )) { + /* + * Great! It seems the host has been changing the terminal + * size, well the user is now grabbing so this is probably + * the least confusing solution in the long run even though + * it a is suprise. Unfortunatly the only way to prevent + * this seems to be to let the host change the window size + * and as that's a user option we're still right back here. + */ + term_size(cfg.height, cfg.width, cfg.savelines); + reset_window(2); + InvalidateRect(hwnd, NULL, TRUE); + need_backend_resize = TRUE; + } + width = r->right - r->left - extra_width; height = r->bottom - r->top - extra_height; w = (width + font_width / 2) / font_width; @@ -1739,9 +1959,49 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, return 1; else return 0; + } else { + int width, height, w, h, rv = 0; + int ex_width = extra_width + (cfg.window_border - offset_width) * 2; + int ex_height = extra_height + (cfg.window_border - offset_height) * 2; + LPRECT r = (LPRECT) lParam; + + width = r->right - r->left - ex_width; + height = r->bottom - r->top - ex_height; + + w = (width + cols/2)/cols; + h = (height + rows/2)/rows; + if ( r->right != r->left + w*cols + ex_width) + rv = 1; + + if (wParam == WMSZ_LEFT || + wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_TOPLEFT) + r->left = r->right - w*cols - ex_width; + else + r->right = r->left + w*cols + ex_width; + + if (r->bottom != r->top + h*rows + ex_height) + rv = 1; + + if (wParam == WMSZ_TOP || + wParam == WMSZ_TOPRIGHT || wParam == WMSZ_TOPLEFT) + r->top = r->bottom - h*rows - ex_height; + else + r->bottom = r->top + h*rows + ex_height; + + return rv; } + break; /* break; (never reached) */ case WM_SIZE: +#ifdef RDB_DEBUG_PATCH + debug((27, "WM_SIZE %s (%d,%d)", + (wParam == SIZE_MINIMIZED) ? "SIZE_MINIMIZED": + (wParam == SIZE_MAXIMIZED) ? "SIZE_MAXIMIZED": + (wParam == SIZE_RESTORED && resizing) ? "to": + (wParam == SIZE_RESTORED) ? "SIZE_RESTORED": + "...", + LOWORD(lParam), HIWORD(lParam))); +#endif if (wParam == SIZE_MINIMIZED) { SetWindowText(hwnd, cfg.win_name_always ? window_name : icon_name); @@ -1749,59 +2009,65 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) SetWindowText(hwnd, window_name); - if (!ignore_size) { + + if (cfg.lockfont && cfg.locksize) { + /* A resize, well it better be a minimize. */ + reset_window(-1); + } else { + int width, height, w, h; -#if 0 /* we have fixed this using WM_SIZING now */ - int ew, eh; -#endif width = LOWORD(lParam); height = HIWORD(lParam); - w = width / font_width; - if (w < 1) - w = 1; - h = height / font_height; - if (h < 1) - h = 1; -#if 0 /* we have fixed this using WM_SIZING now */ - ew = width - w * font_width; - eh = height - h * font_height; - if (ew != 0 || eh != 0) { - RECT r; - GetWindowRect(hwnd, &r); - SendMessage(hwnd, WM_IGNORE_SIZE, 0, 0); - SetWindowPos(hwnd, NULL, 0, 0, - r.right - r.left - ew, r.bottom - r.top - eh, - SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); - } -#endif - if (w != cols || h != rows || just_reconfigged) { - term_invalidate(); - term_size(h, w, cfg.savelines); - /* - * Don't call back->size in mid-resize. (To prevent - * massive numbers of resize events getting sent - * down the connection during an NT opaque drag.) + + if (!resizing) { + if (wParam == SIZE_MAXIMIZED) { + was_zoomed = 1; + prev_rows = rows; + prev_cols = cols; + if (cfg.lockfont) { + w = width / font_width; + if (w < 1) w = 1; + h = height / font_height; + if (h < 1) h = 1; + + term_size(h, w, cfg.savelines); + } + reset_window(0); + } else if (wParam == SIZE_RESTORED && was_zoomed) { + was_zoomed = 0; + if (cfg.lockfont) + term_size(prev_rows, prev_cols, cfg.savelines); + reset_window(0); + } + /* This is an unexpected resize, these will normally happen + * if the window is too large. Probably either the user + * selected a huge font or the screen size has changed. + * + * This is also called with minimize. */ - if (!resizing) - back->size(); - else { + else reset_window(-1); + } + + /* + * Don't call back->size in mid-resize. (To prevent + * massive numbers of resize events getting sent + * down the connection during an NT opaque drag.) + */ + if (resizing) { + if (!cfg.locksize && !alt_pressed) { need_backend_resize = TRUE; + w = (width-cfg.window_border*2) / font_width; + if (w < 1) w = 1; + h = (height-cfg.window_border*2) / font_height; + if (h < 1) h = 1; + cfg.height = h; cfg.width = w; - } - just_reconfigged = FALSE; + } else + reset_window(0); } } - if (wParam == SIZE_RESTORED && defered_resize) { - defered_resize = FALSE; - SetWindowPos(hwnd, NULL, 0, 0, - extra_width + font_width * cfg.width, - extra_height + font_height * cfg.height, - SWP_NOACTIVATE | SWP_NOCOPYBITS | - SWP_NOMOVE | SWP_NOZORDER); - } - ignore_size = FALSE; return 0; case WM_VSCROLL: switch (LOWORD(wParam)) { @@ -1986,7 +2252,8 @@ void sys_cursor(int x, int y) if (!has_focus) return; - SetCaretPos(x * font_width, y * font_height); + SetCaretPos(x * font_width + offset_width, + y * font_height + offset_height); /* IMM calls on Win98 and beyond only */ if(osVersion.dwPlatformId == VER_PLATFORM_WIN32s) return; /* 3.11 */ @@ -2037,8 +2304,14 @@ void do_text(Context ctx, int x, int y, char *text, int len, IpDx[i] = char_width; } + /* Only want the left half of double width lines */ + if (lattr != LATTR_NORM && x*2 >= cols) + return; + x *= fnt_width; y *= font_height; + x += offset_width; + y += offset_height; if ((attr & TATTR_ACTCURS) && (cfg.cursor_type == 0 || big_cursor)) { attr &= ATTR_CUR_AND | (bold_mode != BOLD_COLOURS ? ATTR_BOLD : 0); @@ -2060,11 +2333,12 @@ void do_text(Context ctx, int x, int y, char *text, int len, nfont |= FONT_WIDE + FONT_HIGH; break; } + if (attr & ATTR_NARROW) + nfont |= FONT_NARROW; /* Special hack for the VT100 linedraw glyphs. */ if ((attr & CSET_MASK) == 0x2300) { - if (!dbcs_screenfont && - text[0] >= (char) 0xBA && text[0] <= (char) 0xBD) { + if (text[0] >= (char) 0xBA && text[0] <= (char) 0xBD) { switch ((unsigned char) (text[0])) { case 0xBA: text_adjust = -2 * font_height / 5; @@ -2095,7 +2369,7 @@ void do_text(Context ctx, int x, int y, char *text, int len, if (DIRECT_CHAR(attr)) { attr &= ~CSET_MASK; attr |= 0xFF00; - memset(text, 0xFF, len); + memset(text, 0xFD, len); } /* OEM CP */ @@ -2139,33 +2413,52 @@ void do_text(Context ctx, int x, int y, char *text, int len, line_box.right = x + char_width * len; line_box.bottom = y + font_height; + /* Only want the left half of double width lines */ + if (line_box.right > font_width*cols+offset_width) + line_box.right = font_width*cols+offset_width; + /* We're using a private area for direct to font. (512 chars.) */ if (dbcs_screenfont && (attr & CSET_MASK) == ATTR_ACP) { /* Ho Hum, dbcs fonts are a PITA! */ /* To display on W9x I have to convert to UCS */ static wchar_t *uni_buf = 0; static int uni_len = 0; - int nlen; + int nlen, mptr; if (len > uni_len) { sfree(uni_buf); uni_buf = smalloc((uni_len = len) * sizeof(wchar_t)); } - nlen = MultiByteToWideChar(font_codepage, MB_USEGLYPHCHARS, - text, len, uni_buf, uni_len); + for(nlen = mptr = 0; mptr= ' ' && (uc&CHAR_MASK)<= '~') + return 1; + + if ( (uc & CSET_MASK) == ATTR_ACP ) { + SelectObject(hdc, fonts[FONT_NORMAL]); + } else if ( (uc & CSET_MASK) == ATTR_OEMCP ) { + another_font(FONT_OEM); + if (!fonts[FONT_OEM]) return 0; + + SelectObject(hdc, fonts[FONT_OEM]); + } else + return 0; + + if ( GetCharWidth32(hdc, uc&CHAR_MASK, uc&CHAR_MASK, &ibuf) != 1 && + GetCharWidth(hdc, uc&CHAR_MASK, uc&CHAR_MASK, &ibuf) != 1) + return 0; + } else { + /* Speedup, I know of no font where ascii is the wrong width */ + if (uc >= ' ' && uc <= '~') return 1; + + SelectObject(hdc, fonts[FONT_NORMAL]); + if ( GetCharWidth32W(hdc, uc, uc, &ibuf) == 1 ) + /* Okay that one worked */ ; + else if ( GetCharWidthW(hdc, uc, uc, &ibuf) == 1 ) + /* This should work on 9x too, but it's "less accurate" */ ; + else + return 0; + } + + ibuf += font_width / 2 -1; + ibuf /= font_width; + + return ibuf; +} + /* * Translate a WM_(SYS)?KEY(UP|DOWN) message into a string of ASCII * codes. Returns number of bytes used or zero to drop the message @@ -2439,6 +2795,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, } } + alt_pressed = (left_alt && key_down); + scan = (HIWORD(lParam) & (KF_UP | KF_EXTENDED | 0xFF)); shift_state = ((keystate[VK_SHIFT] & 0x80) != 0) + ((keystate[VK_CONTROL] & 0x80) != 0) * 2; @@ -3324,10 +3682,10 @@ void optimised_move(int to, int from, int lines) min = (to < from ? to : from); max = to + from - min; - r.left = 0; - r.right = cols * font_width; - r.top = min * font_height; - r.bottom = (max + lines) * font_height; + r.left = offset_width; + r.right = offset_width + cols * font_width; + r.top = offset_height + min * font_height; + r.bottom = offset_height + (max + lines) * font_height; ScrollWindow(hwnd, 0, (to - from) * font_height, &r, &r); } #endif -- 2.11.0