Colin Watson suggests that Alt-click (or Option-click) could
[sgt/puzzles] / windows.c
index da324b1..be1f17c 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -35,8 +35,8 @@
 #define IDM_SEED      0x00A0
 #define IDM_HELPC     0x00B0
 #define IDM_GAMEHELP  0x00C0
+#define IDM_ABOUT     0x00D0
 #define IDM_PRESETS   0x0100
-#define IDM_ABOUT     0x0110
 
 #define HELP_FILE_NAME  "puzzles.hlp"
 #define HELP_CNT_NAME   "puzzles.cnt"
@@ -77,13 +77,6 @@ void debug_printf(char *fmt, ...)
     dputs(buf);
     va_end(ap);
 }
-
-#define debug(x) (debug_printf x)
-
-#else
-
-#define debug(x)
-
 #endif
 
 struct font {
@@ -118,6 +111,7 @@ struct frontend {
     HFONT cfgfont;
     char *help_path;
     int help_has_contents;
+    char *laststatus;
 };
 
 void fatal(char *fmt, ...)
@@ -144,7 +138,14 @@ void get_random_seed(void **randseed, int *randseedsize)
 
 void status_bar(frontend *fe, char *text)
 {
-    SetWindowText(fe->statusbar, text);
+    char *rewritten = midend_rewrite_statusbar(fe->me, text);
+    if (!fe->laststatus || strcmp(rewritten, fe->laststatus)) {
+       SetWindowText(fe->statusbar, rewritten);
+       sfree(fe->laststatus);
+       fe->laststatus = rewritten;
+    } else {
+       sfree(rewritten);
+    }
 }
 
 void frontend_default_colour(frontend *fe, float *output)
@@ -437,6 +438,8 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     fe->fonts = NULL;
     fe->nfonts = fe->fontsize = 0;
 
+    fe->laststatus = NULL;
+
     {
        int i, ncolours;
         float *colours;
@@ -1104,6 +1107,19 @@ static void new_game_type(frontend *fe)
     midend_redraw(fe->me);
 }
 
+static int is_alt_pressed(void)
+{
+    BYTE keystate[256];
+    int r = GetKeyboardState(keystate);
+    if (!r)
+       return FALSE;
+    if (keystate[VK_MENU] & 0x80)
+       return TRUE;
+    if (keystate[VK_RMENU] & 0x80)
+       return TRUE;
+    return FALSE;
+}
+
 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                                WPARAM wParam, LPARAM lParam)
 {
@@ -1120,8 +1136,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                PostQuitMessage(0);
            break;
          case IDM_RESTART:
-           if (!midend_process_key(fe->me, 0, 0, 'r'))
-               PostQuitMessage(0);
+           midend_restart_game(fe->me);
            break;
          case IDM_UNDO:
            if (!midend_process_key(fe->me, 0, 0, 'u'))
@@ -1222,31 +1237,35 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
       case WM_KEYDOWN:
        {
            int key = -1;
+            BYTE keystate[256];
+            int r = GetKeyboardState(keystate);
+            int shift = (r && (keystate[VK_SHIFT] & 0x80)) ? MOD_SHFT : 0;
+            int ctrl = (r && (keystate[VK_CONTROL] & 0x80)) ? MOD_CTRL : 0;
 
            switch (wParam) {
              case VK_LEFT:
                if (!(lParam & 0x01000000))
                    key = MOD_NUM_KEYPAD | '4';
-               else
-                   key = CURSOR_LEFT;
+                else
+                   key = shift | ctrl | CURSOR_LEFT;
                break;
              case VK_RIGHT:
                if (!(lParam & 0x01000000))
                    key = MOD_NUM_KEYPAD | '6';
-               else
-                   key = CURSOR_RIGHT;
+                else
+                   key = shift | ctrl | CURSOR_RIGHT;
                break;
              case VK_UP:
                if (!(lParam & 0x01000000))
                    key = MOD_NUM_KEYPAD | '8';
-               else
-                   key = CURSOR_UP;
+                else
+                   key = shift | ctrl | CURSOR_UP;
                break;
              case VK_DOWN:
                if (!(lParam & 0x01000000))
                    key = MOD_NUM_KEYPAD | '2';
-               else
-                   key = CURSOR_DOWN;
+                else
+                   key = shift | ctrl | CURSOR_DOWN;
                break;
                /*
                 * Diagonal keys on the numeric keypad.
@@ -1310,10 +1329,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
             */
            if (message == WM_MBUTTONDOWN || (wParam & MK_SHIFT))
                button = MIDDLE_BUTTON;
-           else if (message == WM_LBUTTONDOWN)
-               button = LEFT_BUTTON;
-           else
+           else if (message == WM_RBUTTONDOWN || is_alt_pressed())
                button = RIGHT_BUTTON;
+           else
+               button = LEFT_BUTTON;
 
            if (!midend_process_key(fe->me, (signed short)LOWORD(lParam),
                                    (signed short)HIWORD(lParam), button))
@@ -1335,10 +1354,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
             */
            if (message == WM_MBUTTONUP || (wParam & MK_SHIFT))
                button = MIDDLE_RELEASE;
-           else if (message == WM_LBUTTONUP)
-               button = LEFT_RELEASE;
-           else
+           else if (message == WM_RBUTTONUP || is_alt_pressed())
                button = RIGHT_RELEASE;
+           else
+               button = LEFT_RELEASE;
 
            if (!midend_process_key(fe->me, (signed short)LOWORD(lParam),
                                    (signed short)HIWORD(lParam), button))
@@ -1353,10 +1372,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 
            if (wParam & (MK_MBUTTON | MK_SHIFT))
                button = MIDDLE_DRAG;
-           else if (wParam & MK_LBUTTON)
-               button = LEFT_DRAG;
-           else
+           else if (wParam & MK_RBUTTON || is_alt_pressed())
                button = RIGHT_DRAG;
+           else
+               button = LEFT_DRAG;
            
            if (!midend_process_key(fe->me, (signed short)LOWORD(lParam),
                                    (signed short)HIWORD(lParam), button))