Thou shalt not suffer a misplaced apostrophe to live.
[u/mdw/putty] / windows / window.c
index d73c04b..386f109 100644 (file)
@@ -317,6 +317,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 {
     WNDCLASS wndclass;
     MSG msg;
+    HRESULT hr;
     int guess_width, guess_height;
 
     hinst = inst;
@@ -355,6 +356,18 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     init_flashwindow();
 
     /*
+     * Initialize COM.
+     */
+    hr = CoInitialize(NULL);
+    if (hr != S_OK && hr != S_FALSE) {
+        char *str = dupprintf("%s Fatal Error", appname);
+       MessageBox(NULL, "Failed to initialize COM subsystem",
+                  str, MB_OK | MB_ICONEXCLAMATION);
+       sfree(str);
+       return 1;
+    }
+
+    /*
      * Process the command line.
      */
     {
@@ -381,14 +394,21 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
        /*
         * Process a couple of command-line options which are more
-        * easily dealt with before the line is broken up into
-        * words. These are the soon-to-be-defunct @sessionname and
-        * the internal-use-only &sharedmemoryhandle, neither of
-        * which are combined with anything else.
+        * easily dealt with before the line is broken up into words.
+        * These are the old-fashioned but convenient @sessionname and
+        * the internal-use-only &sharedmemoryhandle, neither of which
+        * are combined with anything else.
         */
        while (*p && isspace(*p))
            p++;
        if (*p == '@') {
+            /*
+             * An initial @ means that the whole of the rest of the
+             * command line should be treated as the name of a saved
+             * session, with _no quoting or escaping_. This makes it a
+             * very convenient means of automated saved-session
+             * launching, via IDM_SAVEDSESS or Windows 7 jump lists.
+             */
            int i = strlen(p);
            while (i > 1 && isspace(p[i - 1]))
                i--;
@@ -867,6 +887,9 @@ void cleanup_exit(int code)
     }
     shutdown_help();
 
+    /* Clean up COM. */
+    CoUninitialize();
+
     exit(code);
 }
 
@@ -1950,6 +1973,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
     static int ignore_clip = FALSE;
     static int need_backend_resize = FALSE;
     static int fullscr_on_max = FALSE;
+    static int processed_resize = FALSE;
     static UINT last_mousemove = 0;
 
     switch (message) {
@@ -2044,7 +2068,6 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                                           / MENU_SAVED_STEP) + 1;
                    if (sessno < (unsigned)sesslist.nsessions) {
                        char *session = sesslist.sessions[sessno];
-                       /* XXX spaces? quotes? "-load"? */
                        cl = dupprintf("putty @%s", session);
                        inherit_handles = FALSE;
                        freecl = TRUE;
@@ -2627,7 +2650,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
         * 1) Keep the sizetip uptodate
         * 2) Make sure the window size is _stepped_ in units of the font size.
         */
-       if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
+        if (cfg.resize_action == RESIZE_TERM ||
+            (cfg.resize_action == RESIZE_EITHER && !is_alt_pressed())) {
            int width, height, w, h, ew, eh;
            LPRECT r = (LPRECT) lParam;
 
@@ -2733,13 +2757,36 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                          cfg.win_name_always ? window_name : icon_name);
        if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
            SetWindowText(hwnd, window_name);
-        if (wParam == SIZE_RESTORED)
+        if (wParam == SIZE_RESTORED) {
+            processed_resize = FALSE;
             clear_full_screen();
+            if (processed_resize) {
+                /*
+                 * Inhibit normal processing of this WM_SIZE; a
+                 * secondary one was triggered just now by
+                 * clear_full_screen which contained the correct
+                 * client area size.
+                 */
+                return 0;
+            }
+        }
         if (wParam == SIZE_MAXIMIZED && fullscr_on_max) {
             fullscr_on_max = FALSE;
+            processed_resize = FALSE;
             make_full_screen();
+            if (processed_resize) {
+                /*
+                 * Inhibit normal processing of this WM_SIZE; a
+                 * secondary one was triggered just now by
+                 * make_full_screen which contained the correct client
+                 * area size.
+                 */
+                return 0;
+            }
         }
 
+        processed_resize = TRUE;
+
        if (cfg.resize_action == RESIZE_DISABLED) {
            /* A resize, well it better be a minimize. */
            reset_window(-1);
@@ -2771,13 +2818,16 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                     h = (height-cfg.window_border*2) / font_height;
                     if (h < 1) h = 1;
                     term_size(term, h, w, cfg.savelines);
+                    reset_window(2);
                 } else if (cfg.resize_action != RESIZE_FONT)
                     reset_window(2);
                 else
                     reset_window(0);
             } else if (wParam == SIZE_MINIMIZED) {
                 /* do nothing */
-           } else if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
+           } else if (cfg.resize_action == RESIZE_TERM ||
+                       (cfg.resize_action == RESIZE_EITHER &&
+                        !is_alt_pressed())) {
                 w = (width-cfg.window_border*2) / font_width;
                 if (w < 1) w = 1;
                 h = (height-cfg.window_border*2) / font_height;
@@ -3354,7 +3404,7 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
        if (bold_mode == BOLD_SHADOW && (attr & ATTR_BOLD)) {
            SetBkMode(hdc, TRANSPARENT);
 
-           /* GRR: This draws the character outside it's box and can leave
+           /* GRR: This draws the character outside its box and can leave
             * 'droppings' even with the clip box! I suppose I could loop it
             * one character at a time ... yuk. 
             *