updated installer
[xboard.git] / winboard / jaws.c
index a8555a0..4502178 100644 (file)
@@ -1,11 +1,11 @@
 /*\r
  * JAWS.c -- Code for Windows front end to XBoard to use it with JAWS\r
- * $Id: winboard.c,v 2.3 2003/11/25 05:25:20 mann Exp $\r
  *\r
  * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
- * Massachusetts.  Enhancements Copyright\r
- * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
- * Foundation, Inc.\r
+ * Massachusetts.\r
+ *\r
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,\r
+ * 2007, 2008, 2009 Free Software Foundation, Inc.\r
  *\r
  * XBoard borrows its colors and the bitmaps.xchess bitmap set from XChess,\r
  * which was written and is copyrighted by Wayne Christopher.\r
 // BOARD_LEFT as 0, BOARD_RGHT and BOARD_HEIGHT as 8, and set holdingssizes to 0.\r
 // You will need to build with jaws.rc in stead of winboard.rc.\r
 \r
+// from resource.h\r
+\r
+#define IDM_PossibleAttackMove          1800\r
+#define IDM_PossibleAttacked            1801\r
+#define IDM_SayMachineMove              1802\r
+#define IDM_ReadRow                     1803\r
+#define IDM_ReadColumn                  1804\r
+#define IDM_SayCurrentPos               1805\r
+#define IDM_SayAllBoard                 1806\r
+#define IDM_SayUpperDiagnols            1807\r
+#define IDM_SayLowerDiagnols            1808\r
+#define IDM_SayClockTime                1810\r
+#define IDM_SayWhosTurn                 1811\r
+#define IDM_SayKnightMoves              1812\r
+#define ID_SHITTY_HI                    1813\r
+#define IDM_SayWhitePieces              1816\r
+#define IDM_SayBlackPieces              1817\r
+\r
+\r
 // from common.h, but 'extern' added to it, so the actual declaraton can remain in backend.c\r
 \r
 extern long whiteTimeRemaining, blackTimeRemaining, timeControl, timeIncrement;\r
@@ -128,9 +147,8 @@ char* SquareToNum(y)
 \r
 \r
 // from winboard.c: all new routines\r
-\r
-#include "jfwapi.h"\r
-#include "jaws.h"\r
+#define JFWAPI __declspec(dllimport)\r
+JFWAPI BOOL WINAPI JFWSayString (LPCTSTR lpszStrinToSpeak, BOOL bInterrupt);\r
 \r
 typedef JFWAPI BOOL (WINAPI *PSAYSTRING)(LPCTSTR lpszStrinToSpeak, BOOL bInterrupt);\r
 \r
@@ -153,6 +171,72 @@ VOID SayString(char *mess, BOOL flag)
 static int oldFromX, oldFromY;\r
 static int timeflag;\r
 static int suppressClocks = 0;\r
+static int suppressOneKey = 0;\r
+static HANDLE hAccelJAWS;\r
+\r
+typedef struct { char *name; int code; } MenuItemDesc;\r
+\r
+MenuItemDesc menuItemJAWS[] = {\r
+{"Say Clock &Time\tAlt+T",      IDM_SayClockTime },\r
+{"-", 0 },\r
+{"Say Last &Move\tAlt+M",       IDM_SayMachineMove },\r
+{"Say W&ho's Turn\tAlt+X",      IDM_SayWhosTurn },\r
+{"-", 0 },\r
+{"Say Complete &Position\tAlt+P",IDM_SayAllBoard },\r
+{"Say &White Pieces\tAlt+W",    IDM_SayWhitePieces },\r
+{"Say &Black Pieces\tAlt+B",    IDM_SayBlackPieces },\r
+{"Say Board &Rank\tAlt+R",      IDM_ReadRow },\r
+{"Say Board &File\tAlt+F",      IDM_ReadColumn },\r
+{"-", 0 },\r
+{"Say &Upper Diagnols\tAlt+U",  IDM_SayUpperDiagnols },\r
+{"Say &Lower Diagnols\tAlt+L",  IDM_SayLowerDiagnols },\r
+{"Say K&night Moves\tAlt+N",    IDM_SayKnightMoves },\r
+{"Say Current &Square\tAlt+S",  IDM_SayCurrentPos },\r
+{"Say &Attacks\tAlt+A",         IDM_PossibleAttackMove },\r
+{"Say Attacke&d\tAlt+D",        IDM_PossibleAttacked },\r
+{NULL, 0}\r
+};\r
+\r
+ACCEL acceleratorsJAWS[] = {\r
+{FVIRTKEY|FALT, 'T', IDM_SayClockTime },\r
+{FVIRTKEY|FALT, 'M', IDM_SayMachineMove },\r
+{FVIRTKEY|FALT, 'X', IDM_SayWhosTurn },\r
+{FVIRTKEY|FALT, 'P', IDM_SayAllBoard },\r
+{FVIRTKEY|FALT, 'W', IDM_SayWhitePieces },\r
+{FVIRTKEY|FALT, 'B', IDM_SayBlackPieces },\r
+{FVIRTKEY|FALT, 'R', IDM_ReadRow },\r
+{FVIRTKEY|FALT, 'F', IDM_ReadColumn },\r
+{FVIRTKEY|FALT, 'U', IDM_SayUpperDiagnols },\r
+{FVIRTKEY|FALT, 'L', IDM_SayLowerDiagnols },\r
+{FVIRTKEY|FALT, 'N', IDM_SayKnightMoves },\r
+{FVIRTKEY|FALT, 'S', IDM_SayCurrentPos },\r
+{FVIRTKEY|FALT, 'A', IDM_PossibleAttackMove },\r
+{FVIRTKEY|FALT, 'D', IDM_PossibleAttacked }\r
+};\r
+\r
+void\r
+AdaptMenu()\r
+{\r
+       HMENU menuMain, menuJAWS;\r
+       MENUBARINFO helpMenuInfo;\r
+       int e, i;\r
+\r
+       helpMenuInfo.cbSize = sizeof(helpMenuInfo);\r
+       menuMain = GetMenu(hwndMain);\r
+       if(appData.debugMode) fprintf(debugFP, "hwndMain: %8x %8x\n", hwndMain, menuMain);\r
+       menuJAWS = CreatePopupMenu();\r
+       \r
+       for(i=0; menuItemJAWS[i].name; i++) {\r
+           if(menuItemJAWS[i].name[0] == '-') \r
+                AppendMenu(menuJAWS, MF_SEPARATOR, (UINT_PTR) 0, NULL);\r
+           else AppendMenu(menuJAWS, MF_ENABLED|MF_STRING, \r
+                       (UINT_PTR) menuItemJAWS[i].code, (LPCTSTR) menuItemJAWS[i].name);\r
+       }\r
+       InsertMenu(menuMain, 5, MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, \r
+               (UINT_PTR) menuJAWS, "&JAWS");\r
+       oldMenuItemState[6] = oldMenuItemState[5];\r
+       DrawMenuBar(hwndMain);\r
+}\r
 \r
 BOOL\r
 InitJAWS()\r
@@ -170,20 +254,17 @@ InitJAWS()
        }\r
 \r
        {\r
-               // [HGM] kludge to reduce need for modification of winboard.c: mak tinyLayout menu identical\r
+               // [HGM] kludge to reduce need for modification of winboard.c: make tinyLayout menu identical\r
                // to standard layout, so that code for switching between them does not have to be deleted\r
-               HMENU hmenu = GetMenu(hwndMain);\r
                int i;\r
 \r
+               AdaptMenu();\r
                menuBarText[0][5] = "&JAWS";\r
                for(i=0; i<7; i++) menuBarText[1][i] = menuBarText[0][i];\r
-               for (i=0; menuBarText[tinyLayout][i]; i++) {\r
-                       ModifyMenu(hmenu, i, MF_STRING|MF_BYPOSITION|MF_POPUP, \r
-                                       (UINT)GetSubMenu(hmenu, i), menuBarText[tinyLayout][i]);\r
-               }\r
-               DrawMenuBar(hwndMain);\r
        }\r
 \r
+       hAccelJAWS = CreateAcceleratorTable(acceleratorsJAWS, 14);\r
+\r
        /* initialize cursor position */\r
        fromX = fromY = 0;\r
        SetHighlights(fromX, fromY, -1, -1);\r
@@ -719,10 +800,10 @@ SayCurrentPos()
        SayString(xchar, FALSE);\r
        SayString(ynum, FALSE);\r
        SayString(piece, FALSE);\r
-       if((fromX-BOARD_LEFT) ^ fromY)\r
-               SayString("on a dark square",FALSE);\r
-       else \r
+       if(((fromX-BOARD_LEFT) ^ fromY)&1)\r
                SayString("on a light square",FALSE);\r
+       else \r
+               SayString("on a dark square",FALSE);\r
 \r
        PossibleAttacked();\r
        return;\r
@@ -1086,23 +1167,17 @@ NiceTime(int x)
        return (x%3000 == 0);\r
 }\r
 \r
+#if 0\r
+           if(isalpha((char)wParam)) {\r
+               /* capitals of any ind are intercepted and distinguished by left and right shift */\r
+               int mine = GetKeyState(VK_RSHIFT) < 0;\r
+               if(mine || GetKeyState(VK_LSHIFT) < 0) {\r
+#endif\r
+\r
 #define JAWS_ALT_INTERCEPT \\r
-           if(isalpha((char)wParam)) {\\r
-               /* capitals of any ind are intercepted and distinguished by left and right shift */\\r
-               int mine = GetKeyState(VK_RSHIFT) < 0;\\r
-               if(mine || GetKeyState(VK_LSHIFT) < 0) {\\r
-\\r
-                   if(gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) mine = !mine;\\r
-\\r
-                   if(ToLower((char)wParam) == 'x') {\\r
-                       SayPieces(mine ? WhitePlay : BlackPlay);\\r
-                       break;\\r
-                   } else\\r
-                   if(CharToPiece((char)wParam) != EmptySquare) {\\r
-                       SayPieces(CharToPiece(mine ? ToUpper((char)wParam) : ToLower((char)wParam)));\\r
-                       break;\\r
-                   }\\r
-               }\\r
+           if(suppressOneKey) {\\r
+               suppressOneKey = 0;\\r
+               if(GetKeyState(VK_MENU) < 0 && GetKeyState(VK_CONTROL) < 0) break;\\r
            }\\r
            if ((char)wParam == 022 && gameMode == EditPosition) { /* <Ctl R>. Pop up piece menu */\\r
                POINT pt; int x, y;\\r
@@ -1126,6 +1201,30 @@ NiceTime(int x)
 #define JAWS_KB_NAVIGATION \\r
 \\r
        case WM_KEYDOWN:\\r
+\\r
+               if(GetKeyState(VK_MENU) < 0 && GetKeyState(VK_CONTROL) < 0) {\\r
+                   /* Control + Alt + letter used for speaking piece positions */\\r
+                   static int lastTime; static char lastChar;\\r
+                   int mine = 0, time = GetTickCount(); char c;\\r
+\\r
+                   if((char)wParam == lastChar && time-lastTime < 250) mine = 1;\\r
+                   lastChar = wParam; lastTime = time;\\r
+                   c = wParam;\\r
+\\r
+                   if(gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) mine = !mine;\\r
+\\r
+                   if(ToLower(c) == 'x') {\\r
+                       SayPieces(mine ? WhitePlay : BlackPlay);\\r
+                       suppressOneKey = 1;\\r
+                       break;\\r
+                   } else\\r
+                   if(CharToPiece(c) != EmptySquare) {\\r
+                       SayPieces(CharToPiece(mine ? ToUpper(c) : ToLower(c)));\\r
+                       suppressOneKey = 1;\\r
+                       break;\\r
+                   }\\r
+               }\\r
+\\r
                switch (wParam) {\\r
                case VK_LEFT:\\r
                case VK_RIGHT:\\r
@@ -1239,23 +1338,21 @@ NiceTime(int x)
 \\r
 \r
 \r
+#define JAWS_ACCEL \\r
+       !(!frozen && TranslateAccelerator(hwndMain, hAccelJAWS, &msg)) &&\r
+\r
 #define JAWS_INIT if (!InitJAWS()) return (FALSE);\r
 \r
 #define JAWS_DELETE(X)\r
 \r
 #define JAWS_SILENCE if(suppressClocks) return;\r
 \r
+#define JAWS_COPYRIGHT \\r
+       SetDlgItemText(hDlg, OPT_MESS, "Auditory/Keyboard Enhancements  By:  Ed Rodriguez (sort of)");\r
+\r
 #define SAY(S) SayString((S), FALSE)\r
 \r
 #define SAYMACHINEMOVE() SayMachineMove(0)\r
 \r
 // After inclusion of this file somewhere early in winboard.c, the remaining part of the patch\r
 // is scattered over winboard.c for actually calling the routines.\r
-//\r
-// * move fromX, fromY declaration to front, before incusion of this file. (Can be permanent change in winboard.c.)\r
-// * call InitJAWS(), after calling InitIntance(). (Using JAWS_INIT macro)\r
-// * add keyboard cases in main switch of WndProc, though JAWS_KB_NAVIGATION above, e.g. before WM_CHAR case.\r
-// * change the WM_CHAR case of same switch from "if(appData.icsActive)" to "if(appData.icsActive JAWS_IF_TAB)"\r
-// * add new menu cases in WM_COMMAND case of WndProc, e.g. before IDM_Forward. (throug macro defined above)\r
-// * add SAYMACHINEMOVE(); at the end of DisplayMessage();\r
-// * add SAY("board"); in WM_CHAR case of ConsoleTextSubclass, just before "SetFocus(buttondesc..."\r