X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=bdfc1f32ca5bf9e4e58ae201fe6ab29adb24610f;hb=73b4112daf718e68b1b60db8a304c4f9a930c703;hp=115b2c3141e64d7c3082e483172d18569f3ff894;hpb=90f6f34297e5405cef465d82f14bbda2674f032f;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 115b2c3..bdfc1f3 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -2,8 +2,10 @@ * WinBoard.c -- Windows NT front end to XBoard * $Id: winboard.c,v 2.3 2003/11/25 05:25:20 mann Exp $ * - * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts. - * Enhancements Copyright 1992-2001 Free Software Foundation, Inc. + * Copyright 1991 by Digital Equipment Corporation, Maynard, + * Massachusetts. Enhancements Copyright + * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software + * Foundation, Inc. * * XBoard borrows its colors and the bitmaps.xchess bitmap set from XChess, * which was written and is copyrighted by Wayne Christopher. @@ -30,30 +32,32 @@ * SOFTWARE. * ------------------------------------------------------------------------ * - * The following terms apply to the enhanced version of XBoard distributed - * by the Free Software Foundation: + * The following terms apply to the enhanced version of XBoard + * distributed by the Free Software Foundation: * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify + * + * GNU XBoard is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU XBoard is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * ------------------------------------------------------------------------ - */ + * along with this program. If not, see http://www.gnu.org/licenses/. * + * + *------------------------------------------------------------------------ + ** See the file ChangeLog for a revision history. */ #include "config.h" #include #include #include +#include #include #include @@ -66,6 +70,7 @@ #include #include #include +#include #if __GNUC__ #include @@ -95,6 +100,9 @@ extern int whiteFlag, blackFlag; Boolean flipClock = FALSE; void DisplayHoldingsCount(HDC hdc, int x, int y, int align, int copyNumber); +VOID NewVariantPopup(HWND hwnd); +int FinishMove P((ChessMove moveType, int fromX, int fromY, int toX, int toY, + /*char*/int promoChar)); typedef struct { ChessSquare piece; @@ -173,7 +181,7 @@ static HWND hwndPause; /* pause button */ static HBITMAP pieceBitmap[3][(int) BlackPawn]; /* [HGM] nr of bitmaps referred to bP in stead of wK */ static HBRUSH lightSquareBrush, darkSquareBrush, blackSquareBrush, /* [HGM] for band between board and holdings */ - whitePieceBrush, blackPieceBrush, iconBkgndBrush, outlineBrush; + whitePieceBrush, blackPieceBrush, iconBkgndBrush /*, outlineBrush*/; static POINT gridEndpoints[(BOARD_SIZE + 1) * 4]; static DWORD gridVertexCounts[(BOARD_SIZE + 1) * 2]; static HPEN gridPen = NULL; @@ -243,7 +251,7 @@ SizeInfo sizeInfo[] = { NULL, 0, 0, 0, 0, 0, 0 } }; -#define MF(x) {x, {0, }, {0, }, 0} +#define MF(x) {x, {{0,}, 0. }, {0, }, 0} MyFont fontRec[NUM_SIZES][NUM_FONTS] = { { MF(CLOCK_FONT_TINY), MF(MESSAGE_FONT_TINY), MF(COORD_FONT_TINY), MF(CONSOLE_FONT_TINY), MF(COMMENT_FONT_TINY), MF(EDITTAGS_FONT_TINY), MF(MOVEHISTORY_FONT_ALL) }, @@ -474,6 +482,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, { MSG msg; HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS; +// INITCOMMONCONTROLSEX ex; debugFP = stderr; @@ -486,6 +495,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (!InitInstance(hInstance, nCmdShow, lpCmdLine)) { return (FALSE); } +// InitCommonControlsEx(&ex); + InitCommonControls(); hAccelMain = LoadAccelerators (hInstance, szAppName); hAccelNoAlt = LoadAccelerators (hInstance, "NO_ALT"); @@ -567,12 +578,14 @@ int screenHeight, screenWidth; void EnsureOnScreen(int *x, int *y) { - int gap = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); +// int gap = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION); /* Be sure window at (x,y) is not off screen (or even mostly off screen) */ if (*x > screenWidth - 32) *x = 0; if (*y > screenHeight - 32) *y = 0; - if (*x < 10) *x = 10; - if (*y < gap) *y = gap; + if (*x < 0) *x = 0; + if (*y < 0) *y = 0; +// if (*x < 10) *x = 10; +// if (*y < gap) *y = gap; } BOOL @@ -1401,6 +1414,7 @@ FileGet(void *getClosure) FILE* f = (FILE*) getClosure; c = getc(f); + if (c == '\r') c = getc(f); // work around DOS format files by bypassing the '\r' completely if (c == EOF) return NULLCHAR; else @@ -1666,6 +1680,8 @@ ParseArgs(GetFunc get, void *cl) case ArgNone: ExitArgError("Unrecognized argument", argValue); break; + case ArgTrue: + case ArgFalse: ; } } } @@ -1839,6 +1855,7 @@ InitAppData(LPSTR lpCmdLine) appData.reuseSecond = TRUE; appData.blindfold = FALSE; appData.icsEngineAnalyze = FALSE; + memset(&dcb, 0, sizeof(DCB)); // required by VS 2002 + dcb.DCBlength = sizeof(DCB); dcb.BaudRate = 9600; dcb.fBinary = TRUE; @@ -1853,12 +1870,6 @@ InitAppData(LPSTR lpCmdLine) dcb.fNull = FALSE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fAbortOnError = FALSE; - /* Microsoft SDK >= Feb. 2003 (MS VS >= 2002) */ - #if (defined(_MSC_VER) && _MSC_VER <= 1200) - //dcb.wReserved = 0; - #else - dcb.wReserved = 0; - #endif dcb.ByteSize = 7; dcb.Parity = SPACEPARITY; dcb.StopBits = ONESTOPBIT; @@ -2277,14 +2288,14 @@ SaveSettings(char* name) case ArgColor: { COLORREF color = *(COLORREF *)ad->argLoc; - fprintf(f, "/%s=#%02x%02x%02x\n", ad->argName, + fprintf(f, "/%s=#%02lx%02lx%02lx\n", ad->argName, color&0xff, (color>>8)&0xff, (color>>16)&0xff); } break; case ArgAttribs: { MyTextAttribs* ta = &textAttribs[(ColorClass)ad->argLoc]; - fprintf(f, "/%s=\"%s%s%s%s%s#%02x%02x%02x\"\n", ad->argName, + fprintf(f, "/%s=\"%s%s%s%s%s#%02lx%02lx%02lx\"\n", ad->argName, (ta->effects & CFE_BOLD) ? "b" : "", (ta->effects & CFE_ITALIC) ? "i" : "", (ta->effects & CFE_UNDERLINE) ? "u" : "", @@ -2322,6 +2333,8 @@ SaveSettings(char* name) break; case ArgCommSettings: PrintCommSettings(f, ad->argName, (DCB *)ad->argLoc); + case ArgNone: + case ArgSettingsFilename: ; } } fclose(f); @@ -3023,8 +3036,8 @@ ResizeBoard(int newSizeX, int newSizeY, int flags) if (recurse > 0) return; recurse++; while (newSize > 0) { - InitDrawingSizes(newSize, 0); - if(newSizeX >= sizeInfo[newSize].cliWidth || + InitDrawingSizes(newSize+1000, 0); // [HGM] kludge to update sizeInfo without visible effects + if(newSizeX >= sizeInfo[newSize].cliWidth && newSizeY >= sizeInfo[newSize].cliHeight) break; newSize--; } @@ -3051,7 +3064,10 @@ InitDrawingSizes(BoardSize boardSize, int flags) int offby; LOGBRUSH logbrush; - /* [HGM] call with -1 uses old size (for if nr of files, ranks changes) */ + int suppressVisibleEffects = 0; // [HGM] kludge to request updating sizeInfo only + if((int)boardSize >= 1000 ) { boardSize -= 1000; suppressVisibleEffects = 1; } + + /* [HGM] call with -2 uses old size (for if nr of files, ranks changes) */ if(boardSize == (BoardSize)(-2) ) boardSize = oldBoardSize; tinyLayout = sizeInfo[boardSize].tinyLayout; @@ -3154,6 +3170,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) sizeInfo[boardSize].cliWidth = boardRect.right + OUTER_MARGIN; sizeInfo[boardSize].cliHeight = boardRect.bottom + OUTER_MARGIN; + if(suppressVisibleEffects) return; // [HGM] when called for filling sizeInfo only winWidth = 2 * GetSystemMetrics(SM_CXFRAME) + boardRect.right + OUTER_MARGIN; winHeight = 2 * GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION) + boardRect.bottom + OUTER_MARGIN; @@ -3245,7 +3262,6 @@ InitDrawingSizes(BoardSize boardSize, int flags) boardRect.top + lineGap / 2 + (i * (squareSize + lineGap)); gridEndpoints[i*2 + 1].x = boardRect.left + lineGap / 2 + BOARD_WIDTH * (squareSize + lineGap); - lineGap / 2 + (i * (squareSize + lineGap)); gridVertexCounts[i*2] = gridVertexCounts[i*2 + 1] = 2; } for (i = 0; i < BOARD_WIDTH + 1; i++) { @@ -3665,8 +3681,8 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, } else { tmpSize = squareSize; if(minorSize && - (piece >= (int)WhiteNightrider && piece <= WhiteGrasshopper || - piece >= (int)BlackNightrider && piece <= BlackGrasshopper) ) { + ((piece >= (int)WhiteNightrider && piece <= WhiteGrasshopper) || + (piece >= (int)BlackNightrider && piece <= BlackGrasshopper)) ) { /* [HGM] no bitmap available for promoted pieces in Crazyhouse */ /* Bitmaps of smaller size are substituted, but we have to align them */ x += (squareSize - minorSize)>>1; @@ -4202,9 +4218,9 @@ void fputDW(FILE *f, int x) VOID DrawLogoOnDC(HDC hdc, RECT logoRect, ChessProgramState *cps) { - HBITMAP bufferBitmap; +// HBITMAP bufferBitmap; BITMAP bi; - RECT Rect; +// RECT Rect; HDC tmphdc; HBITMAP hbm; int w = 100, h = 50; @@ -4543,7 +4559,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) boardRect.bottom - boardRect.top, tmphdc, boardRect.left, boardRect.top, SRCCOPY); if(saveDiagFlag) { - BITMAP b; int i, j, m, w, wb, fac=0; char pData[1000000]; + BITMAP b; int i, j=0, m, w, wb, fac=0; char pData[1000000]; BITMAPINFOHEADER bih; int color[16], nrColors=0; GetObject(bufferBitmap, sizeof(b), &b); @@ -4587,7 +4603,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) while(p&3) pData[p++] = 0; } fac = 3; - wb = (wb+31>>5)<<2; + wb = ((wb+31)>>5)<<2; } // write BITMAPFILEHEADER fprintf(diagFile, "BM"); @@ -4647,9 +4663,6 @@ int SaveDiagram(f) FILE *f; { - time_t tm; - char *fen; - saveDiagFlag = 1; diagFile = f; HDCDrawPosition(NULL, TRUE, NULL); @@ -4674,7 +4687,7 @@ PaintProc(HWND hwnd) PAINTSTRUCT ps; HFONT oldFont; - if(hdc = BeginPaint(hwnd, &ps)) { + if((hdc = BeginPaint(hwnd, &ps))) { if (IsIconic(hwnd)) { DrawIcon(hdc, 2, 2, iconCurrent); } else { @@ -4767,7 +4780,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) POINT pt; static int recursive = 0; HMENU hmenu; - BOOLEAN needsRedraw = FALSE; +// BOOLEAN needsRedraw = FALSE; BOOLEAN saveAnimate; BOOLEAN forceFullRepaint = IsFullRepaintPreferrable(); /* [AS] */ static BOOLEAN sameAgain = FALSE, promotionChoice = FALSE; @@ -4842,7 +4855,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } if (!appData.highlightLastMove) { ClearHighlights(); - DrawPosition(forceFullRepaint || FALSE, NULL); + DrawPosition((int) (forceFullRepaint || FALSE), NULL); } fromX = fromY = -1; dragInfo.start.x = dragInfo.start.y = -1; @@ -4851,8 +4864,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } else if (x < 0 || y < 0 /* [HGM] block clicks between board and holdings */ || x == BOARD_LEFT-1 || x == BOARD_RGHT - || x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize - || x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize + || (x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize) + || (x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize) /* EditPosition, empty square, or different color piece; click-click move is possible */ ) { @@ -4882,8 +4895,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(moveType != ImpossibleMove) { /* [HGM] We use PromotionToKnight in Shogi to indicate frorced promotion */ if (moveType == WhitePromotionKnight || moveType == BlackPromotionKnight || - (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) && - appData.alwaysPromoteToQueen) { + ((moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) && + appData.alwaysPromoteToQueen)) { FinishMove(moveType, fromX, fromY, toX, toY, 'q'); if (!appData.highlightLastMove) { ClearHighlights(); @@ -4988,8 +5001,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* [HGM] use move type to determine if move is promotion. Knight is Shogi kludge for mandatory promotion, Queen means choice */ if (moveType == WhitePromotionKnight || moveType == BlackPromotionKnight || - (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) && - appData.alwaysPromoteToQueen) + ((moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) && + appData.alwaysPromoteToQueen)) FinishMove(moveType, fromX, fromY, toX, toY, 'q'); else if (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen ) { @@ -5048,15 +5061,19 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEWHEEL: // [DM] + { static int lastDir = 0; // [HGM] build in some hysteresis to avoid spurious events /* Mouse Wheel is being rolled forward * Play moves forward */ - if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) ForwardEvent(); + if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) + { if(lastDir == 1) ForwardEvent(); else lastDir = 1; } // [HGM] suppress first event in direction /* Mouse Wheel is being rolled backward * Play moves backward */ - if((short)HIWORD(wParam) < 0 && currentMove > backwardMostMove) BackwardEvent(); - break; + if((short)HIWORD(wParam) < 0 && currentMove > backwardMostMove) + { if(lastDir == -1) BackwardEvent(); else lastDir = -1; } + } + break; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: @@ -5212,16 +5229,16 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SW_SHOW : SW_HIDE); /* [HGM] Only allow C & A promotions if these pieces are defined */ ShowWindow(GetDlgItem(hDlg, PB_Archbishop), - (PieceToChar(WhiteAngel) >= 'A' && - PieceToChar(WhiteAngel) != '~' || - PieceToChar(BlackAngel) >= 'A' && - PieceToChar(BlackAngel) != '~' ) ? + ((PieceToChar(WhiteAngel) >= 'A' && + PieceToChar(WhiteAngel) != '~') || + (PieceToChar(BlackAngel) >= 'A' && + PieceToChar(BlackAngel) != '~') ) ? SW_SHOW : SW_HIDE); ShowWindow(GetDlgItem(hDlg, PB_Chancellor), - (PieceToChar(WhiteMarshall) >= 'A' && - PieceToChar(WhiteMarshall) != '~' || - PieceToChar(BlackMarshall) >= 'A' && - PieceToChar(BlackMarshall) != '~' ) ? + ((PieceToChar(WhiteMarshall) >= 'A' && + PieceToChar(WhiteMarshall) != '~') || + (PieceToChar(BlackMarshall) >= 'A' && + PieceToChar(BlackMarshall) != '~') ) ? SW_SHOW : SW_HIDE); /* [HGM] Hide B & R button in Shogi, use Q as promote, N as defer */ ShowWindow(GetDlgItem(hDlg, PB_Rook), @@ -6771,7 +6788,7 @@ SetStartupDialogEnables(HWND hDlg) { EnableWindow(GetDlgItem(hDlg, OPT_ChessEngineName), IsDlgButtonChecked(hDlg, OPT_ChessEngine) || - appData.zippyPlay && IsDlgButtonChecked(hDlg, OPT_ChessServer)); + (appData.zippyPlay && IsDlgButtonChecked(hDlg, OPT_ChessServer))); EnableWindow(GetDlgItem(hDlg, OPT_SecondChessEngineName), IsDlgButtonChecked(hDlg, OPT_ChessEngine)); EnableWindow(GetDlgItem(hDlg, OPT_ChessServerName), @@ -7397,8 +7414,6 @@ VOID GothicPopUp(char *title, VariantClass variant) { FARPROC lpProc; - char *p, *q; - BOOLEAN modal = hwndMain == NULL; static char *lastTitle; strncpy(errorTitle, title, sizeof(errorTitle)); @@ -7479,7 +7494,7 @@ IcsTextMenuEntry icsTextMenuEntry[ICS_TEXT_MENU_SIZE]; void ParseIcsTextMenu(char *icsTextMenuString) { - int flags = 0; +// int flags = 0; IcsTextMenuEntry *e = icsTextMenuEntry; char *p = icsTextMenuString; while (e->item != NULL && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) { @@ -7922,8 +7937,8 @@ LRESULT CALLBACK ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static SnapData sd; - static HWND hText, hInput, hFocus; - InputSource *is = consoleInputSource; + static HWND hText, hInput /*, hFocus*/; +// InputSource *is = consoleInputSource; RECT rect; static int sizeX, sizeY; int newSizeX, newSizeY; @@ -8288,7 +8303,7 @@ void CheckForInputBufferFull( InputSource * is ) if( p >= is->next ) { if (appData.debugMode) { - fprintf( debugFP, "Input line exceeded buffer size (source id=%u)\n", is->id ); + fprintf( debugFP, "Input line exceeded buffer size (source id=%lu)\n", is->id ); } is->error = ERROR_BROKEN_PIPE; /* [AS] Just any non-successful code! */ @@ -8337,7 +8352,7 @@ InputThread(LPVOID arg) CloseHandle(is->hFile); if (appData.debugMode) { - fprintf( debugFP, "Input thread terminated (id=%u, error=%d, count=%d)\n", is->id, is->error, is->count ); + fprintf( debugFP, "Input thread terminated (id=%lu, error=%d, count=%ld)\n", is->id, is->error, is->count ); } return 0; @@ -8851,7 +8866,7 @@ DisplayMessage(char *str1, char *str2) } messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR; - if (IsIconic(hwndMain)) return; + if (hwndMain == NULL || IsIconic(hwndMain)) return; hdc = GetDC(hwndMain); oldFont = SelectObject(hdc, font[boardSize][MESSAGE_FONT]->hf); ExtTextOut(hdc, messageRect.left, messageRect.top, ETO_CLIPPED|ETO_OPAQUE, @@ -9219,7 +9234,7 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP { char * pc = lpUserGLT; int idx = 0; - int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 ); +// int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 ); char id; do { @@ -9770,7 +9785,7 @@ DestroyChildProcess(ProcRef pr, int/*boolean*/ signal) result = TerminateProcess( cp->hProcess, 0 ); if ( appData.debugMode) { - fprintf( debugFP, "Terminating process %u, result=%d\n", cp->pid, result ); + fprintf( debugFP, "Terminating process %lu, result=%d\n", cp->pid, result ); } } else if( signal == 10 ) { @@ -9780,7 +9795,7 @@ DestroyChildProcess(ProcRef pr, int/*boolean*/ signal) result = TerminateProcess( cp->hProcess, 0 ); if ( appData.debugMode) { - fprintf( debugFP, "Process %u still alive after timeout, killing... result=%d\n", cp->pid, result ); + fprintf( debugFP, "Process %lu still alive after timeout, killing... result=%d\n", cp->pid, result ); } }