Add input-focus support for System 7, where the Control Manager can't do
[u/mdw/putty] / windlg.c
index ca1890c..6656c96 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -102,7 +102,7 @@ static int CALLBACK LogProc(HWND hwnd, UINT msg,
                    break;
                }
 
-               selitems = smalloc(selcount * sizeof(int));
+               selitems = snewn(selcount, int);
                if (selitems) {
                    int count = SendDlgItemMessage(hwnd, IDN_LIST,
                                                   LB_GETSELITEMS,
@@ -123,7 +123,7 @@ static int CALLBACK LogProc(HWND hwnd, UINT msg,
                        size +=
                            strlen(events[selitems[i]]) + sizeof(sel_nl);
 
-                   clipdata = smalloc(size);
+                   clipdata = snewn(size, char);
                    if (clipdata) {
                        char *p = clipdata;
                        for (i = 0; i < count; i++) {
@@ -582,16 +582,13 @@ int do_config(void)
     ctrlbox = ctrl_new_box();
     setup_config_box(ctrlbox, &sesslist, FALSE, 0);
     win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), FALSE);
+    dp_init(&dp);
     winctrl_init(&ctrls_base);
     winctrl_init(&ctrls_panel);
-    dp.controltrees[0] = &ctrls_base;
-    dp.controltrees[1] = &ctrls_panel;
-    dp.nctrltrees = 2;
+    dp_add_tree(&dp, &ctrls_base);
+    dp_add_tree(&dp, &ctrls_panel);
     dp.errtitle = "PuTTY Error";
     dp.data = &cfg;
-    dp.ended = FALSE;
-    dp.lastfocused = NULL;
-    memset(dp.shortcuts, 0, sizeof(dp.shortcuts));
     dp.shortcuts['g'] = TRUE;         /* the treeview: `Cate&gory' */
 
     get_sesslist(&sesslist, TRUE);
@@ -601,8 +598,9 @@ int do_config(void)
     get_sesslist(&sesslist, FALSE);
 
     ctrl_free_box(ctrlbox);
-    winctrl_cleanup(&ctrls_base);
     winctrl_cleanup(&ctrls_panel);
+    winctrl_cleanup(&ctrls_base);
+    dp_cleanup(&dp);
 
     return ret;
 }
@@ -617,16 +615,13 @@ int do_reconfig(HWND hwnd)
     ctrlbox = ctrl_new_box();
     setup_config_box(ctrlbox, NULL, TRUE, cfg.protocol);
     win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), TRUE);
+    dp_init(&dp);
     winctrl_init(&ctrls_base);
     winctrl_init(&ctrls_panel);
-    dp.controltrees[0] = &ctrls_base;
-    dp.controltrees[1] = &ctrls_panel;
-    dp.nctrltrees = 2;
+    dp_add_tree(&dp, &ctrls_base);
+    dp_add_tree(&dp, &ctrls_panel);
     dp.errtitle = "PuTTY Error";
     dp.data = &cfg;
-    dp.ended = FALSE;
-    dp.lastfocused = NULL;
-    memset(dp.shortcuts, 0, sizeof(dp.shortcuts));
     dp.shortcuts['g'] = TRUE;         /* the treeview: `Cate&gory' */
 
     ret =
@@ -636,6 +631,7 @@ int do_reconfig(HWND hwnd)
     ctrl_free_box(ctrlbox);
     winctrl_cleanup(&ctrls_base);
     winctrl_cleanup(&ctrls_panel);
+    dp_cleanup(&dp);
 
     if (!ret)
        cfg = backup_cfg;              /* structure copy */
@@ -652,14 +648,14 @@ void logevent(void *frontend, char *string)
 
     if (nevents >= negsize) {
        negsize += 64;
-       events = srealloc(events, negsize * sizeof(*events));
+       events = sresize(events, negsize, char *);
     }
 
     time(&t);
     strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
             localtime(&t));
 
-    events[nevents] = smalloc(strlen(timebuf) + strlen(string) + 1);
+    events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
     strcpy(events[nevents], timebuf);
     strcat(events[nevents], string);
     if (logbox) {