Right-click refactoring: step III
[xboard.git] / winboard / winboard.c
index d790116..81d5d03 100644 (file)
@@ -3652,7 +3652,7 @@ void DragPieceEnd(int x, int y)
 VOID\r
 MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  int x, y;\r
+  int x, y, menuNr;\r
   POINT pt;\r
   static int recursive = 0;\r
   HMENU hmenu;\r
@@ -3760,7 +3760,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_MBUTTONUP:\r
   case WM_RBUTTONUP:\r
     ReleaseCapture();\r
-    UnLoadPV();\r
+    RightClick(Release, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY);\r
     break;\r
  \r
   case WM_MBUTTONDOWN:\r
@@ -3785,14 +3785,9 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
     DrawPosition(TRUE, NULL);\r
 \r
-    switch (gameMode) {\r
-    case IcsExamining:\r
-      if(x < BOARD_LEFT || x >= BOARD_RGHT) break;\r
-    case EditPosition:\r
-      if (x == BOARD_LEFT-1 || x == BOARD_RGHT) break;\r
-      if (x < 0 || y < 0) break;\r
-      fromX = x;\r
-      fromY = y;\r
+    menuNr = RightClick(Press, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY);\r
+    switch (menuNr) {\r
+    case 0:\r
       if (message == WM_MBUTTONDOWN) {\r
        buttonCount = 3;  /* even if system didn't think so */\r
        if (wParam & MK_SHIFT) \r
@@ -3809,35 +3804,13 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             MenuPopup(hwnd, pt, LoadMenu(hInst, "ShogiPieceMenu"), -1);\r
       }\r
       break;\r
-    case IcsObserving:\r
-      if(!appData.icsEngineAnalyze) break;\r
-    case IcsPlayingWhite:\r
-    case IcsPlayingBlack:\r
-      if(!appData.zippyPlay) goto noZip;\r
-    case MachinePlaysWhite:\r
-    case MachinePlaysBlack:\r
-    case TwoMachinesPlay:\r
-    case AnalyzeMode:\r
-    case AnalyzeFile:\r
-      if (!appData.dropMenu) {\r
-        SetCapture(hwndMain);\r
-        LoadPV(pt.x - boardRect.left, pt.y - boardRect.top);\r
-        break;\r
-      }\r
-      if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||\r
-         gameMode == AnalyzeFile || gameMode == IcsObserving) break;\r
-    case EditGame:\r
-    noZip:\r
-      if (x < 0 || y < 0) break;\r
-      if (!appData.dropMenu || appData.testLegality &&\r
-         gameInfo.variant != VariantBughouse &&\r
-         gameInfo.variant != VariantCrazyhouse) break;\r
-      fromX = x;\r
-      fromY = y;\r
+    case 2:\r
+      SetCapture(hwndMain);
+      break;\r
+    case 1:\r
       hmenu = LoadMenu(hInst, "DropPieceMenu");\r
       SetupDropMenu(hmenu);\r
       MenuPopup(hwnd, pt, hmenu, -1);\r
-      break;\r
     default:\r
       break;\r
     }\r