Extra diagnostics in the hope that we can track down the problem with
[u/mdw/putty] / window.c
index 07dc694..1805088 100644 (file)
--- a/window.c
+++ b/window.c
@@ -1,6 +1,7 @@
 #include <windows.h>
 #include <imm.h>
 #include <commctrl.h>
+#include <mmsystem.h>
 #ifndef AUTO_WINSOCK
 #ifdef WINSOCK_TWO
 #include <winsock2.h>
@@ -42,6 +43,9 @@
 #define IDM_SAVEDSESS 0x0150
 #define IDM_COPYALL   0x0160
 
+#define IDM_SESSLGP   0x0250  /* log type printable */
+#define IDM_SESSLGA   0x0260  /* log type all chars */
+#define IDM_SESSLGE   0x0270  /* log end */
 #define IDM_SAVED_MIN 0x1000
 #define IDM_SAVED_MAX 0x2000
 
@@ -367,7 +371,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
         int exwinmode = 0;
        if (!cfg.scrollbar)  winmode &= ~(WS_VSCROLL);
        if (cfg.locksize)    winmode &= ~(WS_THICKFRAME|WS_MAXIMIZEBOX);
-        if (cfg.alwaysontop) exwinmode = WS_EX_TOPMOST;
+        if (cfg.alwaysontop) exwinmode |= WS_EX_TOPMOST;
+       if (cfg.sunken_edge) exwinmode |= WS_EX_CLIENTEDGE;
         hwnd = CreateWindowEx (exwinmode, appname, appname,
                               winmode, CW_USEDEFAULT, CW_USEDEFAULT,
                               guess_width, guess_height,
@@ -441,7 +446,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
 
        error = back->init (cfg.host, cfg.port, &realhost);
        if (error) {
-           sprintf(msg, "Unable to open connection:\n%s", error);
+           sprintf(msg, "Unable to open connection to\n"
+                   "%.800s\n"
+                   "%s", cfg.host, error);
            MessageBox(NULL, msg, "PuTTY Error", MB_ICONERROR | MB_OK);
            return 0;
        }
@@ -599,7 +606,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
               /* Hmm, term_update didn't want to do an update too soon ... */
               timer_id = SetTimer(hwnd, 1, 50, NULL);
            else if (!has_focus)
-              timer_id = SetTimer(hwnd, 1, 59500, NULL);
+              timer_id = SetTimer(hwnd, 1, 2000, NULL);
            else
               timer_id = SetTimer(hwnd, 1, 100, NULL);
            long_timer = 1;
@@ -1187,6 +1194,7 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
           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;
@@ -1240,15 +1248,19 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
                     nexflag = exflag;
                     if (cfg.alwaysontop != prev_alwaysontop) {
                         if (cfg.alwaysontop) {
-                            nexflag = WS_EX_TOPMOST;
+                            nexflag |= WS_EX_TOPMOST;
                             SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
                                          SWP_NOMOVE | SWP_NOSIZE);
                         } else {
-                            nexflag = 0;
+                            nexflag &= ~(WS_EX_TOPMOST);
                             SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
                                          SWP_NOMOVE | SWP_NOSIZE);
                         }
                     }
+                    if (cfg.sunken_edge)
+                        nexflag |= WS_EX_CLIENTEDGE;
+                    else
+                        nexflag &= ~(WS_EX_CLIENTEDGE);
 
                     nflg = flag;
                     if (cfg.scrollbar) nflg |=  WS_VSCROLL;
@@ -1285,7 +1297,8 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
                    cfg.width != cols ||
                    old_fwidth != font_width ||
                    old_fheight != font_height ||
-                   cfg.savelines != savelines)
+                   cfg.savelines != savelines ||
+                    cfg.sunken_edge != prev_sunken_edge)
                    need_setwpos = TRUE;
                 term_size(cfg.height, cfg.width, cfg.savelines);
                 InvalidateRect(hwnd, NULL, TRUE);
@@ -1659,7 +1672,8 @@ static LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
  * have one.)
  */
 void sys_cursor(int x, int y) {
-    SetCaretPos(x * font_width, y * font_height);
+    if (has_focus)
+       SetCaretPos(x * font_width, y * font_height);
 }
 
 /*
@@ -2318,6 +2332,24 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
        /* Reorder edit keys to physical order */
        if (cfg.funky_type == 3 && code <= 6 ) code = "\0\2\1\4\5\3\6"[code];
 
+       if (vt52_mode && code > 0 && code <= 6) {
+           p += sprintf((char *)p, "\x1B%c", " HLMEIG"[code]);
+           return p - output;
+       }
+
+       if (cfg.funky_type == 5 && code >= 11 && code <= 24) {
+           p += sprintf((char *)p, "\x1B[%c", code + 'M' - 11);
+           return p - output;
+       }
+       if ((vt52_mode || cfg.funky_type == 4) && code >= 11 && code <= 24) {
+           int offt = 0;
+           if (code>15) offt++; if (code>21) offt++;
+           if (vt52_mode)
+               p += sprintf((char *)p, "\x1B%c", code + 'P' - 11 - offt);
+           else
+               p += sprintf((char *)p, "\x1BO%c", code + 'P' - 11 - offt);
+           return p - output;
+       }
        if (cfg.funky_type == 1 && code >= 11 && code <= 15) {
            p += sprintf((char *)p, "\x1B[[%c", code + 'A' - 11);
            return p - output;
@@ -2640,7 +2672,21 @@ void fatalbox(char *fmt, ...) {
  */
 void beep(int mode) {
     if (mode == BELL_DEFAULT) {
+       /*
+        * For MessageBeep style bells, we want to be careful of
+        * timing, because they don't have the nice property of
+        * PlaySound bells that each one cancels the previous
+        * active one. So we limit the rate to one per 50ms or so.
+        */
+       static long lastbeep = 0;
+       long now, beepdiff;
+
+       now = GetTickCount();
+       beepdiff = now - lastbeep;
+       if (beepdiff >= 0 && beepdiff < 50)
+           return;
        MessageBeep(MB_OK);
+       lastbeep = now;
     } else if (mode == BELL_WAVEFILE) {
        if (!PlaySound(cfg.bell_wavefile, NULL, SND_ASYNC | SND_FILENAME)) {
            char buf[sizeof(cfg.bell_wavefile)+80];