Various bug/warning fixes from Jacob
[u/mdw/putty] / windlg.c
index 629e689..d6fce02 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -3,6 +3,7 @@
 #include <commdlg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <ctype.h>
 
 #include "ssh.h"
 #include "putty.h"
@@ -66,6 +67,11 @@ static int CALLBACK LogProc (HWND hwnd, UINT msg,
                 int *selitems;
                 selcount = SendDlgItemMessage(hwnd, IDN_LIST,
                                               LB_GETSELCOUNT, 0, 0);
+                if (selcount == 0) {   /* don't even try to copy zero items */
+                    MessageBeep(0);
+                    break;
+                }
+                    
                 selitems = smalloc(selcount * sizeof(int));
                 if (selitems) {
                     int count = SendDlgItemMessage(hwnd, IDN_LIST,
@@ -200,6 +206,17 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
     IDC_CLOSEEXIT,
     sessionpanelend,
 
+    loggingpanelstart,
+    IDC_BOX_LOGGING1,
+    IDC_LSTATSTATIC,
+    IDC_LSTATOFF,
+    IDC_LSTATASCII,
+    IDC_LSTATRAW,
+    IDC_LGFSTATIC,
+    IDC_LGFEDIT,
+    IDC_LGFBUTTON,
+    loggingpanelend,
+
     keyboardpanelstart,
     IDC_TITLE_KEYBOARD,
     IDC_BOX_KEYBOARD1,
@@ -238,14 +255,14 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
     IDC_BEEP,
     IDC_BCE,
     IDC_BLINKTEXT,
-    IDC_LDISCTERM,
-    IDC_LSTATSTATIC,
-    IDC_LSTATOFF,
-    IDC_LSTATASCII,
-    IDC_LSTATRAW,
-    IDC_LGFSTATIC,
-    IDC_LGFEDIT,
-    IDC_LGFBUTTON,
+    IDC_ECHOSTATIC,
+    IDC_ECHOBACKEND,
+    IDC_ECHOYES,
+    IDC_ECHONO,
+    IDC_EDITSTATIC,
+    IDC_EDITBACKEND,
+    IDC_EDITYES,
+    IDC_EDITNO,
     terminalpanelend,
 
     windowpanelstart,
@@ -489,7 +506,12 @@ static void init_dlg_ctrls(HWND hwnd) {
     CheckDlgButton (hwnd, IDC_ALTSPACE, cfg.alt_space);
     CheckDlgButton (hwnd, IDC_ALTONLY, cfg.alt_only);
     CheckDlgButton (hwnd, IDC_COMPOSEKEY, cfg.compose_key);
-    CheckDlgButton (hwnd, IDC_LDISCTERM, cfg.ldisc_term);
+    CheckRadioButton (hwnd, IDC_ECHOBACKEND, IDC_ECHONO,
+                     cfg.localecho == LD_BACKEND ? IDC_ECHOBACKEND:
+                      cfg.localecho == LD_YES ? IDC_ECHOYES : IDC_ECHONO);
+    CheckRadioButton (hwnd, IDC_EDITBACKEND, IDC_EDITNO,
+                     cfg.localedit == LD_BACKEND ? IDC_EDITBACKEND:
+                      cfg.localedit == LD_YES ? IDC_EDITYES : IDC_EDITNO);
     CheckDlgButton (hwnd, IDC_ALWAYSONTOP, cfg.alwaysontop);
     CheckDlgButton (hwnd, IDC_SCROLLKEY, cfg.scroll_on_key);
     CheckDlgButton (hwnd, IDC_SCROLLDISP, cfg.scroll_on_disp);
@@ -637,7 +659,7 @@ static HTREEITEM treeview_insert(struct treeview_faff *faff,
  */
 static void create_controls(HWND hwnd, int dlgtype, int panel) {
     if (panel == sessionpanelstart) {
-       /* The Session panel. Accelerators used: [acgo] nprthelsdx */
+       /* The Session panel. Accelerators used: [acgo] nprtih elsd x */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Basic options for your PuTTY session",
@@ -653,12 +675,12 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
                 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 4,
                           "&Raw", IDC_PROTRAW,
                           "&Telnet", IDC_PROTTELNET,
-                          "R&login", IDC_PROTRLOGIN, NULL);
+                          "Rlog&in", IDC_PROTRLOGIN, NULL);
             } else {
                 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 4,
                           "&Raw", IDC_PROTRAW,
                           "&Telnet", IDC_PROTTELNET,
-                          "R&login", IDC_PROTRLOGIN,
+                          "Rlog&in", IDC_PROTRLOGIN,
 #ifdef FWHACK
                           "SS&H/hack",
 #else
@@ -681,8 +703,26 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
         endbox(&cp);
     }
 
+    if (panel == loggingpanelstart) {
+        /* The Logging panel. Accelerators used: [acgo] tplfw */
+        struct ctlpos cp;
+        ctlposinit(&cp, hwnd, 80, 3, 13);
+        bartitle(&cp, "Options controlling session logging",
+                 IDC_TITLE_TERMINAL);
+        beginbox(&cp, NULL, IDC_BOX_LOGGING1);
+        radiobig(&cp,
+                 "Session logging:", IDC_LSTATSTATIC,
+                 "Logging &turned off completely", IDC_LSTATOFF,
+                 "Log &printable output only", IDC_LSTATASCII,
+                 "&Log all session output", IDC_LSTATRAW, NULL);
+        editbutton(&cp, "Log &file name:",
+                   IDC_LGFSTATIC, IDC_LGFEDIT, "Bro&wse...",
+                   IDC_LGFBUTTON);
+        endbox(&cp);
+    }
+
     if (panel == terminalpanelstart) {
-        /* The Terminal panel. Accelerators used: [acgo] &dflbenuw */
+        /* The Terminal panel. Accelerators used: [acgo] wdlben ht */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling the terminal emulation",
@@ -695,24 +735,23 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
         checkbox(&cp, "&Beep enabled", IDC_BEEP);
         checkbox(&cp, "Use background colour to &erase screen", IDC_BCE);
         checkbox(&cp, "Enable bli&nking text", IDC_BLINKTEXT);
-        checkbox(&cp, "&Use local terminal line discipline", IDC_LDISCTERM);
         endbox(&cp);
 
-        beginbox(&cp, "Control session logging",
+        beginbox(&cp, "Line discipline options",
                  IDC_BOX_TERMINAL2);
-        radiobig(&cp,
-                 "Session logging:", IDC_LSTATSTATIC,
-                 "Logging turned &off completely", IDC_LSTATOFF,
-                 "Log printable output only", IDC_LSTATASCII,
-                 "Log all session output", IDC_LSTATRAW, NULL);
-        editbutton(&cp, "Log &file name:",
-                   IDC_LGFSTATIC, IDC_LGFEDIT, "Bro&wse...",
-                   IDC_LGFBUTTON);
+        radioline(&cp, "Local ec&ho:", IDC_ECHOSTATIC, 3,
+                  "Auto", IDC_ECHOBACKEND,
+                  "Force on", IDC_ECHOYES,
+                  "Force off", IDC_ECHONO, NULL);
+        radioline(&cp, "Local line edi&ting:", IDC_EDITSTATIC, 3,
+                  "Auto", IDC_EDITBACKEND,
+                  "Force on", IDC_EDITYES,
+                  "Force off", IDC_EDITNO, NULL);
         endbox(&cp);
     }
 
     if (panel == keyboardpanelstart) {
-        /* The Keyboard panel. Accelerators used: [acgo] h?srvlxvnpmietu */
+        /* The Keyboard panel. Accelerators used: [acgo] h?sr~lxv unpymie t */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling the effects of keys",
@@ -755,7 +794,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == windowpanelstart) {
-        /* The Window panel. Accelerators used: [acgo] bsdkw4ylpt */
+        /* The Window panel. Accelerators used: [acgo] rmz sdkp w4ylt */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling PuTTY's window",
@@ -766,7 +805,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
                   "&Rows", IDC_ROWSSTATIC, IDC_ROWSEDIT, 50,
                   "Colu&mns", IDC_COLSSTATIC, IDC_COLSEDIT, 50,
                   NULL);
-        checkbox(&cp, "Loc&k window size against resizing", IDC_LOCKSIZE);
+        checkbox(&cp, "Lock window size against resi&zing", IDC_LOCKSIZE);
         endbox(&cp);
         beginbox(&cp, "Control the scrollback in the window",
                  IDC_BOX_WINDOW2);
@@ -787,7 +826,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == appearancepanelstart) {
-        /* The Appearance panel. Accelerators used: [acgo] rmkhtibluv */
+        /* The Appearance panel. Accelerators used: [acgo] luvb h ti p */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling PuTTY's appearance",
@@ -820,7 +859,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == translationpanelstart) {
-        /* The Translation panel. Accelerators used: [acgo] xbepnkis */
+        /* The Translation panel. Accelerators used: [acgo] xbep t s */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling character set translation",
@@ -838,11 +877,11 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
         beginbox(&cp, "Enable character set translation on received data",
                  IDC_BOX_TRANSLATION2);
         radiobig(&cp,
-                 "Character set translation:", IDC_XLATSTATIC,
-                 "&None", IDC_NOXLAT,
-                 "&KOI8 / Win-1251", IDC_KOI8WIN1251,
-                 "&ISO-8859-2 / Win-1250", IDC_88592WIN1250,
-                 "&ISO-8859-2 / CP852", IDC_88592CP852, NULL);
+                 "Character set &translation:", IDC_XLATSTATIC,
+                 "None", IDC_NOXLAT,
+                 "KOI8 / Win-1251", IDC_KOI8WIN1251,
+                 "ISO-8859-2 / Win-1250", IDC_88592WIN1250,
+                 "ISO-8859-2 / CP852", IDC_88592CP852, NULL);
         endbox(&cp);
         beginbox(&cp, "Enable character set translation on input data",
                  IDC_BOX_TRANSLATION3);
@@ -852,7 +891,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == selectionpanelstart) {
-        /* The Selection panel. Accelerators used: [acgo] wxst */
+        /* The Selection panel. Accelerators used: [acgo] wx hst */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling copy and paste",
@@ -866,7 +905,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
         endbox(&cp);
         beginbox(&cp, "Control the select-one-word-at-a-time mode",
                  IDC_BOX_SELECTION2);
-        charclass(&cp, "Character classes:", IDC_CCSTATIC, IDC_CCLIST,
+        charclass(&cp, "C&haracter classes:", IDC_CCSTATIC, IDC_CCLIST,
                   "&Set", IDC_CCSET, IDC_CCEDIT,
                   "&to class", IDC_CCSTATIC2);
         endbox(&cp);
@@ -909,12 +948,12 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
         beginbox(&cp, "Sending of null packets to keep session active",
                  IDC_BOX_CONNECTION2);
         staticedit(&cp, "Seconds between &keepalives (0 to turn off)",
-                   IDC_PINGSTATIC, IDC_PINGEDIT, 25);
+                   IDC_PINGSTATIC, IDC_PINGEDIT, 20);
         endbox(&cp);
     }
 
     if (panel == telnetpanelstart) {
-        /* The Telnet panel. Accelerators used: [acgo] svldrbf */
+        /* The Telnet panel. Accelerators used: [acgo] svldr bf */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         if (dlgtype == 0) {
@@ -952,7 +991,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == sshpanelstart) {
-        /* The SSH panel. Accelerators used: [acgo] rmakwp123bd */
+        /* The SSH panel. Accelerators used: [acgo] rmfkw pe123bd i */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         if (dlgtype == 0) {
@@ -967,7 +1006,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
                      IDC_BOX_SSH2);
             checkbox(&cp, "Atte&mpt TIS or CryptoCard authentication",
                      IDC_AUTHTIS);
-            checkbox(&cp, "Allow &agent forwarding", IDC_AGENTFWD);
+            checkbox(&cp, "Allow agent &forwarding", IDC_AGENTFWD);
             editbutton(&cp, "Private &key file for authentication:",
                        IDC_PKSTATIC, IDC_PKEDIT, "Bro&wse...", IDC_PKBUTTON);
             endbox(&cp);
@@ -982,7 +1021,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
                       "&3DES", IDC_CIPHER3DES,
                       "&Blowfish", IDC_CIPHERBLOWF,
                       "&DES", IDC_CIPHERDES, NULL);
-            checkbox(&cp, "Imitate SSH 2 MAC bug in commercial <= v2.3.x",
+            checkbox(&cp, "&Imitate SSH 2 MAC bug in commercial <= v2.3.x",
                      IDC_BUGGYMAC);
             endbox(&cp);
         }
@@ -1081,6 +1120,7 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
         * Set up the tree view contents.
         */
         hsession = treeview_insert(&tvfaff, 0, "Session");
+        treeview_insert(&tvfaff, 1, "Logging");
         treeview_insert(&tvfaff, 0, "Terminal");
         treeview_insert(&tvfaff, 1, "Keyboard");
         treeview_insert(&tvfaff, 0, "Window");
@@ -1144,6 +1184,8 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
             }
            if (!strcmp(buffer, "Session"))
                create_controls(hwnd, dlgtype, sessionpanelstart);
+           if (!strcmp(buffer, "Logging"))
+               create_controls(hwnd, dlgtype, loggingpanelstart);
            if (!strcmp(buffer, "Keyboard"))
                create_controls(hwnd, dlgtype, keyboardpanelstart);
            if (!strcmp(buffer, "Terminal"))
@@ -1398,10 +1440,25 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
                HIWORD(wParam) == BN_DOUBLECLICKED)
                cfg.alt_only = IsDlgButtonChecked (hwnd, IDC_ALTONLY);
            break;
-         case IDC_LDISCTERM:
+         case IDC_ECHOBACKEND:
+         case IDC_ECHOYES:
+         case IDC_ECHONO:
            if (HIWORD(wParam) == BN_CLICKED ||
-               HIWORD(wParam) == BN_DOUBLECLICKED)
-               cfg.ldisc_term = IsDlgButtonChecked (hwnd, IDC_LDISCTERM);
+               HIWORD(wParam) == BN_DOUBLECLICKED) {
+               if (LOWORD(wParam)==IDC_ECHOBACKEND) cfg.localecho=LD_BACKEND;
+               if (LOWORD(wParam)==IDC_ECHOYES) cfg.localecho=LD_YES;
+               if (LOWORD(wParam)==IDC_ECHONO) cfg.localecho=LD_NO;
+            }
+           break;
+         case IDC_EDITBACKEND:
+         case IDC_EDITYES:
+         case IDC_EDITNO:
+           if (HIWORD(wParam) == BN_CLICKED ||
+               HIWORD(wParam) == BN_DOUBLECLICKED) {
+               if (LOWORD(wParam)==IDC_EDITBACKEND) cfg.localedit=LD_BACKEND;
+               if (LOWORD(wParam)==IDC_EDITYES) cfg.localedit=LD_YES;
+               if (LOWORD(wParam)==IDC_EDITNO) cfg.localedit=LD_NO;
+            }
            break;
           case IDC_ALWAYSONTOP:
            if (HIWORD(wParam) == BN_CLICKED ||
@@ -1912,8 +1969,6 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
 
 static int CALLBACK MainDlgProc (HWND hwnd, UINT msg,
                                 WPARAM wParam, LPARAM lParam) {
-    static HWND page = NULL;
-
     if (msg == WM_COMMAND && LOWORD(wParam) == IDOK) {
     }
     if (msg == WM_COMMAND && LOWORD(wParam) == IDCX_ABOUT) {
@@ -1928,7 +1983,6 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg,
 
 static int CALLBACK ReconfDlgProc (HWND hwnd, UINT msg,
                                   WPARAM wParam, LPARAM lParam) {
-    static HWND page;
     return GenericMainDlgProc (hwnd, msg, wParam, lParam, 1);
 }