Jacob's patch to improve Close On Exit behaviour
[u/mdw/putty] / windlg.c
index 12bff5d..b7e878d 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,
@@ -198,6 +204,9 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
     IDC_SESSSAVE,
     IDC_SESSDEL,
     IDC_CLOSEEXIT,
+    IDC_COEALWAYS,
+    IDC_COENORMAL,
+    IDC_COENEVER,
     sessionpanelend,
 
     loggingpanelstart,
@@ -531,7 +540,9 @@ static void init_dlg_ctrls(HWND hwnd) {
     CheckDlgButton (hwnd, IDC_BLINKCUR, cfg.blink_cur);
     CheckDlgButton (hwnd, IDC_SCROLLBAR, cfg.scrollbar);
     CheckDlgButton (hwnd, IDC_LOCKSIZE, cfg.locksize);
-    CheckDlgButton (hwnd, IDC_CLOSEEXIT, cfg.close_on_exit);
+    CheckRadioButton (hwnd, IDC_COEALWAYS, IDC_COENEVER,
+                      cfg.close_on_exit==COE_NEVER ? IDC_COENEVER :
+                      cfg.close_on_exit==COE_NORMAL ? IDC_COENORMAL : IDC_COEALWAYS);
     CheckDlgButton (hwnd, IDC_CLOSEWARN, cfg.warn_on_close);
 
     SetDlgItemText (hwnd, IDC_TTEDIT, cfg.termtype);
@@ -653,7 +664,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 w */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Basic options for your PuTTY session",
@@ -669,12 +680,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
@@ -693,12 +704,15 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
             endbox(&cp);
         }
         beginbox(&cp, NULL, IDC_BOX_SESSION3);
-        checkbox(&cp, "Close Window on E&xit", IDC_CLOSEEXIT);
+        radioline(&cp, "At session end, close &window:", IDC_CLOSEEXIT, 3,
+                  "Always", IDC_COEALWAYS,
+                  "On clean exit", IDC_COENORMAL,
+                  "Never", IDC_COENEVER, NULL);
         endbox(&cp);
     }
 
     if (panel == loggingpanelstart) {
-        /* The Logging panel. Accelerators used: [acgo] lpt */
+        /* The Logging panel. Accelerators used: [acgo] tplfw */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling session logging",
@@ -716,7 +730,7 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
     }
 
     if (panel == terminalpanelstart) {
-        /* The Terminal panel. Accelerators used: [acgo] &dflbentuw */
+        /* The Terminal panel. Accelerators used: [acgo] wdlben ht */
         struct ctlpos cp;
         ctlposinit(&cp, hwnd, 80, 3, 13);
         bartitle(&cp, "Options controlling the terminal emulation",
@@ -733,19 +747,19 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
 
         beginbox(&cp, "Line discipline options",
                  IDC_BOX_TERMINAL2);
-        radioline(&cp, "Local echo:", IDC_ECHOSTATIC, 3,
-                  "A&uto", IDC_ECHOBACKEND,
+        radioline(&cp, "Local ec&ho:", IDC_ECHOSTATIC, 3,
+                  "Auto", IDC_ECHOBACKEND,
                   "Force on", IDC_ECHOYES,
                   "Force off", IDC_ECHONO, NULL);
-        radioline(&cp, "Local line editing:", IDC_EDITSTATIC, 3,
-                  "Au&to", IDC_EDITBACKEND,
+        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",
@@ -788,7 +802,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",
@@ -799,7 +813,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);
@@ -820,7 +834,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",
@@ -853,7 +867,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",
@@ -871,11 +885,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);
@@ -885,7 +899,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",
@@ -899,7 +913,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);
@@ -942,12 +956,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) {
@@ -985,7 +999,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) {
@@ -1000,7 +1014,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);
@@ -1015,7 +1029,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);
         }
@@ -1590,11 +1604,16 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
                GetDlgItemText (hwnd, IDC_WINEDIT, cfg.wintitle,
                                sizeof(cfg.wintitle)-1);
            break;
-         case IDC_CLOSEEXIT:
-           if (HIWORD(wParam) == BN_CLICKED ||
-               HIWORD(wParam) == BN_DOUBLECLICKED)
-               cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC_CLOSEEXIT);
-           break;
+          case IDC_COEALWAYS:
+          case IDC_COENORMAL:
+          case IDC_COENEVER:
+            if (HIWORD(wParam) == BN_CLICKED ||
+                HIWORD(wParam) == BN_DOUBLECLICKED) {
+                cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC_COEALWAYS) ? COE_ALWAYS :
+                                    IsDlgButtonChecked (hwnd, IDC_COENORMAL) ? COE_NORMAL :
+                                    COE_NEVER;
+            }
+            break;
          case IDC_CLOSEWARN:
            if (HIWORD(wParam) == BN_CLICKED ||
                HIWORD(wParam) == BN_DOUBLECLICKED)
@@ -1963,8 +1982,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) {
@@ -1979,7 +1996,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);
 }