\r
#include <windows.h>\r
#include <winuser.h>\r
+#include <winsock.h>\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <malloc.h>\r
-#include <io.h>\r
#include <sys/stat.h>\r
#include <fcntl.h>\r
#include <math.h>\r
#include <commdlg.h>\r
#include <dlgs.h>\r
#include <richedit.h>\r
+#include <mmsystem.h>\r
\r
#if __GNUC__\r
#include <errno.h>\r
static HICON iconWhite, iconBlack, iconCurrent;\r
static int doingSizing = FALSE;\r
static int lastSizing = 0;\r
+static int prevStderrPort;\r
\r
#if __GNUC__ && !defined(_winmajor)\r
#define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */\r
BOOLEAN analysisDialogUp = FALSE;\r
static int analysisX, analysisY, analysisH, analysisW;\r
\r
+char errorTitle[MSG_SIZ];\r
char errorMessage[2*MSG_SIZ];\r
HWND errorDialog = NULL;\r
BOOLEAN moveErrorMessageUp = FALSE;\r
\r
char *programVersion;\r
\r
-#include <winsock.h>\r
-\r
#define CPReal 1\r
#define CPComm 2\r
#define CPSock 3\r
dragInfo.lastpos = dragInfo.pos;\r
}\r
break;\r
-\r
+ case WM_MOUSEWHEEL:\r
+ /* Mouse Wheel is being rolled forward \r
+ * Play moves forward\r
+ */\r
+ if((short)HIWORD(wParam) > 0 ) ForwardEvent();\r
+ /* Mouse Wheel is being rolled backward \r
+ * Play moves backward\r
+ */\r
+ if((short)HIWORD(wParam) < 0 ) BackwardEvent();\r
+ break;\r
case WM_MBUTTONDOWN:\r
case WM_RBUTTONDOWN:\r
ErrorPopDown();\r
/* Center the dialog over the application window */\r
CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));\r
ShowWindow(GetDlgItem(hDlg, PB_King), \r
- (!appData.testLegality || gameInfo.variant == VariantSuicide) ?\r
+ (!appData.testLegality || gameInfo.variant == VariantSuicide ||\r
+ gameInfo.variant == VariantGiveaway) ?\r
SW_SHOW : SW_HIDE);\r
return TRUE;\r
\r
case WM_MBUTTONUP:\r
case WM_RBUTTONUP:\r
case WM_MOUSEMOVE:\r
+ case WM_MOUSEWHEEL:\r
MouseEvent(hwnd, message, wParam, lParam);\r
break;\r
\r
*\r
\*---------------------------------------------------------------------------*/\r
\r
+/*\r
+ * Decent random number generator, at least not as bad as Windows\r
+ * standard rand, which returns a value in the range 0 to 0x7fff.\r
+ */\r
+unsigned int randstate;\r
+\r
+int\r
+myrandom(void)\r
+{\r
+ randstate = randstate * 1664525 + 1013904223;\r
+ return (int) randstate & 0x7fffffff;\r
+}\r
+\r
+void\r
+mysrandom(unsigned int seed)\r
+{\r
+ randstate = seed;\r
+}\r
+\r
+\r
/* \r
* returns TRUE if user selects a different color, FALSE otherwise \r
*/\r
if (write ? GetSaveFileName(&openFileName) : \r
GetOpenFileName(&openFileName)) {\r
/* open the file */\r
- f = fopen(openFileName.lpstrFile, write ? "a" : "r");\r
+ f = fopen(openFileName.lpstrFile, write ? "a" : "rb");\r
if (f == NULL) {\r
MessageBox(hwnd, "File open failed", NULL,\r
MB_OK|MB_ICONEXCLAMATION);\r
\*---------------------------------------------------------------------------*/\r
\r
/* Nonmodal error box */\r
+LRESULT CALLBACK ErrorDialog(HWND hDlg, UINT message,\r
+ WPARAM wParam, LPARAM lParam);\r
+\r
+VOID\r
+ErrorPopUp(char *title, char *content)\r
+{\r
+ FARPROC lpProc;\r
+ char *p, *q;\r
+ BOOLEAN modal = hwndMain == NULL;\r
+\r
+ p = content;\r
+ q = errorMessage;\r
+ while (*p) {\r
+ if (*p == '\n') {\r
+ if (modal) {\r
+ *q++ = ' ';\r
+ p++;\r
+ } else {\r
+ *q++ = '\r';\r
+ *q++ = *p++;\r
+ }\r
+ } else {\r
+ *q++ = *p++;\r
+ }\r
+ }\r
+ *q = NULLCHAR;\r
+ strncpy(errorTitle, title, sizeof(errorTitle));\r
+ errorTitle[sizeof(errorTitle) - 1] = '\0';\r
+ \r
+ if (modal) {\r
+ MessageBox(NULL, errorMessage, errorTitle, MB_OK|MB_ICONEXCLAMATION);\r
+ } else {\r
+ lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst);\r
+ CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error),\r
+ hwndMain, (DLGPROC)lpProc);\r
+ FreeProcInstance(lpProc);\r
+ }\r
+}\r
+\r
VOID\r
ErrorPopDown()\r
{\r
rChild.top + boardRect.top - (rChild.bottom - rChild.top), \r
0, 0, SWP_NOZORDER|SWP_NOSIZE);\r
errorDialog = hDlg;\r
+ SetWindowText(hDlg, errorTitle);\r
hwndText = GetDlgItem(hDlg, OPT_ErrorText);\r
SetDlgItemText(hDlg, OPT_ErrorText, errorMessage);\r
return FALSE;\r
switch (LOWORD(wParam)) {\r
case IDOK:\r
case IDCANCEL:\r
- if (errorDialog = hDlg) errorDialog = NULL;\r
+ if (errorDialog == hDlg) errorDialog = NULL;\r
DestroyWindow(hDlg);\r
return TRUE;\r
\r
VOID\r
DisplayError(char *str, int error)\r
{\r
- FARPROC lpProc;\r
char buf[MSG_SIZ*2], buf2[MSG_SIZ];\r
int len;\r
- char *p, *q;\r
-\r
+ \r
if (error == 0) {\r
strcpy(buf, str);\r
} else {\r
}\r
}\r
}\r
- p = buf;\r
- q = errorMessage;\r
- while (*p) {\r
- if (*p == '\n') {\r
- if (hwndMain != NULL /*!!?*/) {\r
- *q++ = '\r';\r
- *q++ = *p++;\r
- } else {\r
- *q++ = ' ';\r
- p++;\r
- }\r
- } else {\r
- *q++ = *p++;\r
- }\r
- }\r
- *q = NULLCHAR;\r
\r
- if (hwndMain == NULL) {\r
- MessageBox(NULL, errorMessage, "Error", MB_OK|MB_ICONEXCLAMATION);\r
- } else {\r
- lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst);\r
- CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error),\r
- hwndMain, (DLGPROC)lpProc);\r
- FreeProcInstance(lpProc);\r
- }\r
+ ErrorPopUp("Error", buf);\r
}\r
\r
\r
ClearHighlights();\r
DrawPosition(FALSE, NULL);\r
if (appData.popupMoveErrors) {\r
- DisplayError(str, 0);\r
+ ErrorPopUp("Error", str);\r
} else {\r
DisplayMessage(str, "");\r
moveErrorMessageUp = TRUE;\r
}\r
\r
\r
+VOID\r
+DisplayNote(char *str)\r
+{\r
+ ErrorPopUp("Note", str);\r
+}\r
+\r
+\r
typedef struct {\r
char *title, *question, *replyPrefix;\r
ProcRef pr;\r
mysa.sin_family = AF_INET;\r
mysa.sin_addr.s_addr = INADDR_ANY;\r
for (fromPort = 1023;; fromPort--) {\r
+ if (fromPort == prevStderrPort) continue; // don't reuse port\r
if (fromPort < 0) {\r
(void) closesocket(s);\r
WSACleanup();\r
}\r
break;\r
}\r
+ prevStderrPort = fromPort; // remember port used\r
sprintf(stderrPortStr, "%d", fromPort);\r
\r
if (send(s, stderrPortStr, strlen(stderrPortStr) + 1, 0) == SOCKET_ERROR) {\r