X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=c8bf0b209ed1f2b4212b10717487f4d67e30d24f;hb=5bd571321c23608ce3f07bf523a8bbf2ddda2210;hp=b76a358dd6040cfc56d89e94882ac482b640cf0a;hpb=1bcb6712e5c6c25eebac7e8bf55d33095b51cffa;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index b76a358..c8bf0b2 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -73,6 +73,7 @@ #include #include #include +#include #if __GNUC__ #include @@ -123,9 +124,10 @@ typedef struct { POINT pos; /* window coordinates of current pos */ POINT lastpos; /* window coordinates of last pos - used for clipping */ POINT from; /* board coordinates of the piece's orig pos */ + ChessSquare piece; } DragInfo; -static DragInfo dragInfo = { {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1} }; +static DragInfo dragInfo = { {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, EmptySquare }; typedef struct { POINT sq[2]; /* board coordinates of from, to squares */ @@ -345,6 +347,7 @@ LoadLanguageFile(char *name) if(!name || name[0] == NULLCHAR) return; snprintf(buf, MSG_SIZ, "%s%s", name, strchr(name, '.') ? "" : ".lng"); // auto-append lng extension + appData.language = oldLanguage; if(!strcmp(buf, oldLanguage)) { barbaric = 1; return; } // this language already loaded; just switch on if((f = fopen(buf, "r")) == NULL) return; while((k = fgetc(f)) != EOF) { @@ -443,7 +446,7 @@ TranslateMenus(int addLanguage) int i; WIN32_FIND_DATA fileData; HANDLE hFind; -#define IDM_English 1895 +#define IDM_English 1970 if(1) { HMENU mainMenu = GetMenu(hwndMain); for (i=GetMenuItemCount(mainMenu)-1; i>=0; i--) { @@ -651,7 +654,6 @@ LRESULT CALLBACK StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); VOID APIENTRY MenuPopup(HWND hwnd, POINT pt, HMENU hmenu, UINT def); void ParseIcsTextMenu(char *icsTextMenuString); -VOID PopUpMoveDialog(char firstchar); VOID PopUpNameDialog(char firstchar); VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca); @@ -3795,8 +3797,8 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) board[dragInfo.from.y][dragInfo.from.x] = dragged_piece; x = dragInfo.pos.x - squareSize / 2; y = dragInfo.pos.y - squareSize / 2; - DrawPieceOnDC(hdcmem, dragged_piece, - ((int) dragged_piece < (int) BlackPawn), + DrawPieceOnDC(hdcmem, dragInfo.piece, + ((int) dragInfo.piece < (int) BlackPawn), (dragInfo.from.y + dragInfo.from.x) % 2, x, y, tmphdc); } @@ -3841,11 +3843,11 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) boardRect.bottom - boardRect.top, tmphdc, boardRect.left, boardRect.top, SRCCOPY); if(saveDiagFlag) { - BITMAP b; int i, j=0, m, w, wb, fac=0; char pData[1000000]; + BITMAP b; int i, j=0, m, w, wb, fac=0; char *pData; BITMAPINFOHEADER bih; int color[16], nrColors=0; GetObject(bufferBitmap, sizeof(b), &b); - if(b.bmWidthBytes*b.bmHeight <= 990000) { + if(pData = malloc(b.bmWidthBytes*b.bmHeight + 10000)) { bih.biSize = sizeof(BITMAPINFOHEADER); bih.biWidth = b.bmWidth; bih.biHeight = b.bmHeight; @@ -3909,6 +3911,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) // write bitmap data for(i=0; i IDM_English && wmId < IDM_English+5) { + if(wmId > IDM_English && wmId < IDM_English+20) { LoadLanguageFile(languageFile[wmId - IDM_English - 1]); TranslateMenus(0); CheckMenuItem(GetMenu(hwndMain), lastChecked, MF_BYCOMMAND|MF_UNCHECKED); @@ -6396,9 +6402,6 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char move[MSG_SIZ]; HWND hInput; - ChessMove moveType; - int fromX, fromY, toX, toY; - char promoChar; switch (message) { case WM_INITDIALOG: @@ -6417,36 +6420,8 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case IDOK: shiftKey = GetKeyState(VK_SHIFT) < 0; // [HGM] remember last shift status - GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); - { int n; Board board; - // [HGM] FENedit - if(gameMode == EditPosition && ParseFEN(board, &n, move) ) { - EditPositionPasteFEN(move); - EndDialog(hDlg, TRUE); - return TRUE; - } - // [HGM] movenum: allow move number to be typed in any mode - if(sscanf(move, "%d", &n) == 1 && n != 0 ) { - ToNrEvent(2*n-1); - EndDialog(hDlg, TRUE); - return TRUE; - } - } - if (gameMode != EditGame && currentMove != forwardMostMove && - gameMode != Training) { - DisplayMoveError(_("Displayed move is not current")); - } else { -// GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); // moved upstream - int ok = ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, - &moveType, &fromX, &fromY, &toX, &toY, &promoChar); - if(!ok && move[0] >= 'a') { move[0] += 'A' - 'a'; ok = 2; } // [HGM] try also capitalized - if (ok==1 || ok && ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, - &moveType, &fromX, &fromY, &toX, &toY, &promoChar)) { - UserMoveEvent(fromX, fromY, toX, toY, promoChar); - } else { - DisplayMoveError(_("Could not parse move")); - } - } + GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); + TypeInDoneEvent(move); EndDialog(hDlg, TRUE); return TRUE; case IDCANCEL: @@ -6464,21 +6439,11 @@ VOID PopUpMoveDialog(char firstchar) { FARPROC lpProc; - - if ((gameMode == BeginningOfGame && !appData.icsActive) || - gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack || - gameMode == AnalyzeMode || gameMode == EditGame || - gameMode == EditPosition || gameMode == IcsExamining || - gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || - isdigit(firstchar) && // [HGM] movenum: allow typing in of move nr in 'passive' modes - ( gameMode == AnalyzeFile || gameMode == PlayFromGameFile || - gameMode == IcsObserving || gameMode == TwoMachinesPlay ) || - gameMode == Training) { + lpProc = MakeProcInstance((FARPROC)TypeInMoveDialog, hInst); DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_TypeInMove), hwndMain, (DLGPROC)lpProc, (LPARAM)firstchar); FreeProcInstance(lpProc); - } } /*---------------------------------------------------------------------------*\ @@ -8149,7 +8114,8 @@ DisplayMessage(char *str1, char *str2) if (len > remain) len = remain; strncat(messageText, str2, len); } - messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR; + messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR; + safeStrCpy(lastMsg, messageText, MSG_SIZ); if (hwndMain == NULL || IsIconic(hwndMain)) return; @@ -9819,3 +9785,19 @@ SettingsPopUp(ChessProgramState *cps) { // [HGM] wrapper needed because handles must not be passed through back-end EngineOptionsPopup(savedHwnd, cps); } + +int flock(int fid, int code) +{ + HANDLE hFile = (HANDLE) _get_osfhandle(fid); + OVERLAPPED ov; + ov.hEvent = NULL; + ov.Offset = 0; + ov.OffsetHigh = 0; + switch(code) { + case 1: LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_SH + case 2: LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_EX + case 3: UnlockFileEx(hFile, 0, 1024, 0, &ov); break; // LOCK_UN + default: return -1; + } + return 0; +}