Small changes; see ChangeLog for details.
[xboard.git] / winboard / winboard.c
index 68dab66..7bd3de0 100644 (file)
@@ -337,6 +337,7 @@ HWND analysisDialog = NULL;
 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
@@ -4071,6 +4072,26 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  *\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
@@ -4942,6 +4963,45 @@ PopUpMoveDialog(char firstchar)
 \*---------------------------------------------------------------------------*/\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
@@ -4964,6 +5024,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
       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
@@ -6316,31 +6377,8 @@ DisplayError(char *str, int error)
       }\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
@@ -6351,7 +6389,7 @@ DisplayMoveError(char *str)
   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
@@ -6400,6 +6438,13 @@ DisplayInformation(char *str)
 }\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