X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=32addcc96738cf86cf0e76a0c1008d1d022e46cd;hb=eac70dd1506787967e790af36b5ab29676ad4fd7;hp=68dab6659b58015563697b5e9b6177d5c94051fb;hpb=b8ccc2d03263c833777a7c055a372501b40bc7ce;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 68dab66..32addcc 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -337,6 +337,7 @@ HWND analysisDialog = NULL; BOOLEAN analysisDialogUp = FALSE; static int analysisX, analysisY, analysisH, analysisW; +char errorTitle[MSG_SIZ]; char errorMessage[2*MSG_SIZ]; HWND errorDialog = NULL; BOOLEAN moveErrorMessageUp = FALSE; @@ -4071,6 +4072,26 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) * \*---------------------------------------------------------------------------*/ +/* + * Decent random number generator, at least not as bad as Windows + * standard rand, which returns a value in the range 0 to 0x7fff. + */ +unsigned int randstate; + +int +myrandom(void) +{ + randstate = randstate * 1664525 + 1013904223; + return (int) randstate & 0x7fffffff; +} + +void +mysrandom(unsigned int seed) +{ + randstate = seed; +} + + /* * returns TRUE if user selects a different color, FALSE otherwise */ @@ -4942,6 +4963,45 @@ PopUpMoveDialog(char firstchar) \*---------------------------------------------------------------------------*/ /* Nonmodal error box */ +LRESULT CALLBACK ErrorDialog(HWND hDlg, UINT message, + WPARAM wParam, LPARAM lParam); + +VOID +ErrorPopUp(char *title, char *content) +{ + FARPROC lpProc; + char *p, *q; + BOOLEAN modal = hwndMain == NULL; + + p = content; + q = errorMessage; + while (*p) { + if (*p == '\n') { + if (modal) { + *q++ = ' '; + p++; + } else { + *q++ = '\r'; + *q++ = *p++; + } + } else { + *q++ = *p++; + } + } + *q = NULLCHAR; + strncpy(errorTitle, title, sizeof(errorTitle)); + errorTitle[sizeof(errorTitle) - 1] = '\0'; + + if (modal) { + MessageBox(NULL, errorMessage, errorTitle, MB_OK|MB_ICONEXCLAMATION); + } else { + lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst); + CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error), + hwndMain, (DLGPROC)lpProc); + FreeProcInstance(lpProc); + } +} + VOID ErrorPopDown() { @@ -4964,6 +5024,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) rChild.top + boardRect.top - (rChild.bottom - rChild.top), 0, 0, SWP_NOZORDER|SWP_NOSIZE); errorDialog = hDlg; + SetWindowText(hDlg, errorTitle); hwndText = GetDlgItem(hDlg, OPT_ErrorText); SetDlgItemText(hDlg, OPT_ErrorText, errorMessage); return FALSE; @@ -6293,11 +6354,9 @@ DisplayMessage(char *str1, char *str2) VOID DisplayError(char *str, int error) { - FARPROC lpProc; char buf[MSG_SIZ*2], buf2[MSG_SIZ]; int len; - char *p, *q; - + if (error == 0) { strcpy(buf, str); } else { @@ -6316,31 +6375,8 @@ DisplayError(char *str, int error) } } } - p = buf; - q = errorMessage; - while (*p) { - if (*p == '\n') { - if (hwndMain != NULL /*!!?*/) { - *q++ = '\r'; - *q++ = *p++; - } else { - *q++ = ' '; - p++; - } - } else { - *q++ = *p++; - } - } - *q = NULLCHAR; - if (hwndMain == NULL) { - MessageBox(NULL, errorMessage, "Error", MB_OK|MB_ICONEXCLAMATION); - } else { - lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst); - CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error), - hwndMain, (DLGPROC)lpProc); - FreeProcInstance(lpProc); - } + ErrorPopUp("Error", buf); } @@ -6351,7 +6387,7 @@ DisplayMoveError(char *str) ClearHighlights(); DrawPosition(FALSE, NULL); if (appData.popupMoveErrors) { - DisplayError(str, 0); + ErrorPopUp("Error", str); } else { DisplayMessage(str, ""); moveErrorMessageUp = TRUE; @@ -6400,6 +6436,13 @@ DisplayInformation(char *str) } +VOID +DisplayNote(char *str) +{ + ErrorPopUp("Note", str); +} + + typedef struct { char *title, *question, *replyPrefix; ProcRef pr;