X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=69146fc98f332c7ca56bc2754d5129565e227ada;hb=9d33882a8307d8e00849941e30032d99fc75de43;hp=455c48366407ccc055486ecb2b93e85b9764e87b;hpb=05bc30b15e31c427ce208495a889e9ff36e6642b;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 455c483..69146fc 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -53,17 +53,18 @@ #include #include +#include #include #include #include -#include #include #include #include #include #include #include +#include #if __GNUC__ #include @@ -168,6 +169,7 @@ static BOOL paletteChanged = FALSE; static HICON iconWhite, iconBlack, iconCurrent; static int doingSizing = FALSE; static int lastSizing = 0; +static int prevStderrPort; #if __GNUC__ && !defined(_winmajor) #define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */ @@ -335,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; @@ -344,8 +347,6 @@ COLORREF consoleBackgroundColor; char *programVersion; -#include - #define CPReal 1 #define CPComm 2 #define CPSock 3 @@ -3107,7 +3108,16 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) dragInfo.lastpos = dragInfo.pos; } break; - + case WM_MOUSEWHEEL: + /* Mouse Wheel is being rolled forward + * Play moves forward + */ + if((short)HIWORD(wParam) > 0 ) ForwardEvent(); + /* Mouse Wheel is being rolled backward + * Play moves backward + */ + if((short)HIWORD(wParam) < 0 ) BackwardEvent(); + break; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: ErrorPopDown(); @@ -3246,7 +3256,8 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* Center the dialog over the application window */ CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); ShowWindow(GetDlgItem(hDlg, PB_King), - (!appData.testLegality || gameInfo.variant == VariantSuicide) ? + (!appData.testLegality || gameInfo.variant == VariantSuicide || + gameInfo.variant == VariantGiveaway) ? SW_SHOW : SW_HIDE); return TRUE; @@ -3413,6 +3424,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_MOUSEMOVE: + case WM_MOUSEWHEEL: MouseEvent(hwnd, message, wParam, lParam); break; @@ -4070,6 +4082,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 */ @@ -4317,7 +4349,7 @@ OpenFileDialog(HWND hwnd, BOOL write, char *defName, char *defExt, if (write ? GetSaveFileName(&openFileName) : GetOpenFileName(&openFileName)) { /* open the file */ - f = fopen(openFileName.lpstrFile, write ? "a" : "r"); + f = fopen(openFileName.lpstrFile, write ? "a" : "rb"); if (f == NULL) { MessageBox(hwnd, "File open failed", NULL, MB_OK|MB_ICONEXCLAMATION); @@ -4941,6 +4973,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() { @@ -4963,6 +5034,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; @@ -4971,7 +5043,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: - if (errorDialog = hDlg) errorDialog = NULL; + if (errorDialog == hDlg) errorDialog = NULL; DestroyWindow(hDlg); return TRUE; @@ -6292,11 +6364,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 { @@ -6315,31 +6385,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); } @@ -6350,7 +6397,7 @@ DisplayMoveError(char *str) ClearHighlights(); DrawPosition(FALSE, NULL); if (appData.popupMoveErrors) { - DisplayError(str, 0); + ErrorPopUp("Error", str); } else { DisplayMessage(str, ""); moveErrorMessageUp = TRUE; @@ -6399,6 +6446,13 @@ DisplayInformation(char *str) } +VOID +DisplayNote(char *str) +{ + ErrorPopUp("Note", str); +} + + typedef struct { char *title, *question, *replyPrefix; ProcRef pr; @@ -7202,6 +7256,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr) mysa.sin_family = AF_INET; mysa.sin_addr.s_addr = INADDR_ANY; for (fromPort = 1023;; fromPort--) { + if (fromPort == prevStderrPort) continue; // don't reuse port if (fromPort < 0) { (void) closesocket(s); WSACleanup(); @@ -7239,6 +7294,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr) } break; } + prevStderrPort = fromPort; // remember port used sprintf(stderrPortStr, "%d", fromPort); if (send(s, stderrPortStr, strlen(stderrPortStr) + 1, 0) == SOCKET_ERROR) {