X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/ffc31afe16643bc63fcc04553ecfd0b7feeb2e83..2784cd098cc201db40725bb11c888791cba0ee0f:/window.c diff --git a/window.c b/window.c index 6dba5b1e..fe9d2e91 100644 --- a/window.c +++ b/window.c @@ -13,6 +13,7 @@ #define PUTTY_DO_GLOBALS /* actually _define_ globals */ #include "putty.h" +#include "storage.h" #include "win_res.h" #define IDM_SHOWLOG 0x0010 @@ -42,7 +43,6 @@ #define WM_IGNORE_SIZE (WM_XUSER + 1) #define WM_IGNORE_CLIP (WM_XUSER + 2) -#define WM_IGNORE_KEYMENU (WM_XUSER + 3) static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, unsigned char *output); @@ -83,6 +83,8 @@ static RGBTRIPLE defpal[NCOLOURS]; static HWND hwnd; +static HBITMAP caretbm; + static int dbltime, lasttime, lastact; static Mouse_Button lastbtn; @@ -154,6 +156,32 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { tolower(p[1]) == 'o' && tolower(p[2]) == 'g') { logfile = "putty.log"; + } else if (q == p + 7 && + tolower(p[0]) == 'c' && + tolower(p[1]) == 'l' && + tolower(p[2]) == 'e' && + tolower(p[3]) == 'a' && + tolower(p[4]) == 'n' && + tolower(p[5]) == 'u' && + tolower(p[6]) == 'p') { + /* + * `putty -cleanup'. Remove all registry entries + * associated with PuTTY, and also find and delete + * the random seed file. + */ + if (MessageBox(NULL, + "This procedure will remove ALL Registry\n" + "entries associated with PuTTY, and will\n" + "also remove the PuTTY random seed file.\n" + "\n" + "THIS PROCESS WILL DESTROY YOUR SAVED\n" + "SESSIONS. Are you really sure you want\n" + "to continue?", + "PuTTY Warning", + MB_YESNO | MB_ICONWARNING) == IDYES) { + cleanup_all(); + } + exit(0); } p = q + strspn(q, " \t"); } @@ -229,6 +257,19 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { return 0; } } + + /* See if host is of the form user@host */ + if (cfg.host[0] != '\0') { + char *atsign = strchr(cfg.host, '@'); + /* Make sure we're not overflowing the user field */ + if (atsign) { + if (atsign-cfg.host < sizeof cfg.username) { + strncpy (cfg.username, cfg.host, atsign-cfg.host); + cfg.username[atsign-cfg.host] = '\0'; + } + memmove(cfg.host, atsign+1, 1+strlen(atsign+1)); + } + } } /* @@ -344,6 +385,17 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER); /* + * Set up a caret bitmap, with no content. + */ + { + char *bits; + int size = (font_width+15)/16 * 2 * font_height; + bits = calloc(size, 1); + caretbm = CreateBitmap(font_width, font_height, 1, 1, bits); + free(bits); + } + + /* * Initialise the scroll bar. */ { @@ -363,7 +415,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { */ { char *error; - char msg[1024]; + char msg[1024], *title; char *realhost; error = back->init (hwnd, cfg.host, cfg.port, &realhost); @@ -373,9 +425,14 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { return 0; } window_name = icon_name = NULL; - sprintf(msg, "%s - PuTTY", realhost); - set_title (msg); - set_icon (msg); + if (*cfg.wintitle) { + title = cfg.wintitle; + } else { + sprintf(msg, "%s - PuTTY", realhost); + title = msg; + } + set_title (title); + set_icon (title); } session_closed = FALSE; @@ -497,9 +554,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { KillTimer(hwnd, timer_id); timer_id = 0; } + HideCaret(hwnd); if (inbuf_head) term_out(); term_update(); + ShowCaret(hwnd); if (!has_focus) timer_id = SetTimer(hwnd, 1, 2000, NULL); else if (cfg.blinktext) @@ -942,7 +1001,6 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, HDC hdc; static int ignore_size = FALSE; static int ignore_clip = FALSE; - static int ignore_keymenu = TRUE; static int just_reconfigged = FALSE; static int resizing = FALSE; @@ -952,7 +1010,9 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, enact_pending_netevent(); if (inbuf_head) term_out(); + HideCaret(hwnd); term_update(); + ShowCaret(hwnd); return 0; case WM_CREATE: break; @@ -968,10 +1028,6 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, return 0; case WM_SYSCOMMAND: switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */ - case SC_KEYMENU: - if (ignore_keymenu) - return 0; /* don't put up system menu on Alt */ - break; case IDM_SHOWLOG: showeventlog(hwnd); break; @@ -1201,9 +1257,6 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, case WM_IGNORE_CLIP: ignore_clip = wParam; /* don't panic on DESTROYCLIPBOARD */ break; - case WM_IGNORE_KEYMENU: - ignore_keymenu = wParam; /* do or don't ignore SC_KEYMENU */ - break; case WM_DESTROYCLIPBOARD: if (!ignore_clip) term_deselect(); @@ -1212,6 +1265,7 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, case WM_PAINT: { PAINTSTRUCT p; + HideCaret(hwnd); hdc = BeginPaint (hwnd, &p); if (pal) { SelectPalette (hdc, pal, TRUE); @@ -1222,6 +1276,7 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, SelectObject (hdc, GetStockObject(SYSTEM_FONT)); SelectObject (hdc, GetStockObject(WHITE_PEN)); EndPaint (hwnd, &p); + ShowCaret(hwnd); } return 0; case WM_NETEVENT: @@ -1238,11 +1293,14 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, return 0; case WM_SETFOCUS: has_focus = TRUE; + CreateCaret(hwnd, caretbm, 0, 0); + ShowCaret(hwnd); term_out(); term_update(); break; case WM_KILLFOCUS: has_focus = FALSE; + DestroyCaret(); term_out(); term_update(); break; @@ -1417,6 +1475,16 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, } /* + * Move the system caret. (We maintain one, even though it's + * invisible, for the benefit of blind people: apparently some + * helper software tracks the system caret, so we should arrange to + * have one.) + */ +void sys_cursor(int x, int y) { + SetCaretPos(x * font_width, y * font_height); +} + +/* * Draw a line of text in the window, at given character * coordinates, in given attributes. * @@ -1819,9 +1887,7 @@ static WPARAM compose_key = 0; } if (left_alt && wParam == VK_SPACE && cfg.alt_space) { - SendMessage (hwnd, WM_IGNORE_KEYMENU, FALSE, 0); SendMessage (hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0); - SendMessage (hwnd, WM_IGNORE_KEYMENU, TRUE, 0); return -1; } @@ -2064,13 +2130,11 @@ static WPARAM compose_key = 0; } /* This stops ALT press-release doing a 'COMMAND MENU' function */ -#if 0 if (message == WM_SYSKEYUP && wParam == VK_MENU) { keystate[VK_MENU] = 0; return 0; } -#endif return -1; }