X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=f818927530ee9bafe77cd8595e99ba2b3ceb9d9a;hb=eb0b8eabe5bf8d5139bc82bf79b88aded98d96c8;hp=e6227ec931294e05e84f4877025ea618b33aca41;hpb=ba19c79e683860fba8cafa5ca24b0f8191b4c1d5;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index e6227ec..f818927 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -105,7 +105,6 @@ 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)); -void AnimateAtomicCapture(int fromX, int fromY, int toX, int toY, int nFrames); void DisplayMove P((int moveNumber)); Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen)); void ChatPopUp P((char *s)); @@ -134,6 +133,8 @@ typedef struct { static HighlightInfo highlightInfo = { {{-1, -1}, {-1, -1}} }; static HighlightInfo premoveHighlightInfo = { {{-1, -1}, {-1, -1}} }; +static HighlightInfo partnerHighlightInfo = { {{-1, -1}, {-1, -1}} }; +static HighlightInfo oldPartnerHighlight = { {{-1, -1}, {-1, -1}} }; typedef struct { // [HGM] atomic int fromX, fromY, toX, toY, radius; @@ -223,6 +224,253 @@ static struct { int x; int y; int mode; } backTextureSquareInfo[BOARD_RANKS][BOA #endif #endif +#define INTERNATIONAL + +#ifdef INTERNATIONAL +# define _(s) T_(s) +# define N_(s) s +#else +# define _(s) s +# define N_(s) s +# define T_(s) s +# define Translate(x, y) +# define LoadLanguageFile(s) +#endif + +#ifdef INTERNATIONAL + +Boolean barbaric; // flag indicating if translation is needed + +// list of item numbers used in each dialog (used to alter language at run time) + +#define ABOUTBOX -1 /* not sure why these are needed */ +#define ABOUTBOX2 -1 + +int dialogItems[][40] = { +{ ABOUTBOX, IDOK, 400 }, +{ DLG_TimeControl, IDC_Babble, OPT_TCUseMoves, OPT_TCUseInc, OPT_TCUseFixed, + OPT_TCtext1, OPT_TCtext2, OPT_TCitext1, OPT_TCitext2, OPT_TCftext, GPB_Factors, IDC_Factor1, IDC_Factor2, IDOK, IDCANCEL }, +{ DLG_LoadOptions, OPT_Autostep, OPT_AStext1, IDOK, IDCANCEL }, +{ DLG_SaveOptions, OPT_Autosave, OPT_AVPrompt, OPT_AVToFile, OPT_AVBrowse, + 801, OPT_PGN, OPT_Old, OPT_OutOfBookInfo, IDOK, IDCANCEL }, +{ 1536, 1090, IDC_Directories, 1089, 1091, IDOK, IDCANCEL, 1038, IDC_IndexNr, 1037 }, +{ DLG_CommPort, IDOK, IDCANCEL, IDC_Port, IDC_Rate, IDC_Bits, IDC_Parity, + IDC_Stop, IDC_Flow, OPT_SerialHelp }, +{ DLG_EditComment, IDOK, OPT_CancelComment, OPT_ClearComment, OPT_EditComment }, +{ DLG_PromotionKing, PB_Chancellor, PB_Archbishop, PB_Queen, PB_Rook, + PB_Bishop, PB_Knight, PB_King, IDCANCEL, IDC_Yes, IDC_No, IDC_Centaur }, +{ ABOUTBOX2, IDC_ChessBoard }, +{ DLG_GameList, OPT_GameListLoad, OPT_GameListPrev, OPT_GameListNext, + OPT_GameListClose, IDC_GameListDoFilter }, +{ DLG_EditTags, IDOK, OPT_TagsCancel, OPT_EditTags }, +{ DLG_Error, IDOK }, +{ DLG_Colorize, IDOK, IDCANCEL, OPT_ChooseColor, OPT_Bold, OPT_Italic, + OPT_Underline, OPT_Strikeout, OPT_Sample }, +{ DLG_Question, IDOK, IDCANCEL, OPT_QuestionText }, +{ DLG_Startup, IDC_Welcome, OPT_ChessEngine, OPT_ChessServer, OPT_View, + IDC_SPECIFY_ENG_STATIC, IDC_SPECIFY_SERVER_STATIC, OPT_AnyAdditional, + IDOK, IDCANCEL, IDM_HELPCONTENTS }, +{ DLG_IndexNumber, IDC_Index }, +{ DLG_TypeInMove, IDOK, IDCANCEL }, +{ DLG_TypeInName, IDOK, IDCANCEL }, +{ DLG_Sound, IDC_Event, OPT_NoSound, OPT_DefaultBeep, OPT_BuiltInSound, + OPT_WavFile, OPT_BrowseSound, OPT_DefaultSounds, IDOK, IDCANCEL, OPT_PlaySound }, +{ DLG_GeneralOptions, IDOK, IDCANCEL, OPT_AlwaysOnTop, OPT_HighlightLastMove, + OPT_AlwaysQueen, OPT_PeriodicUpdates, OPT_AnimateDragging, OPT_PonderNextMove, + OPT_AnimateMoving, OPT_PopupExitMessage, OPT_AutoFlag, OPT_PopupMoveErrors, + OPT_AutoFlipView, OPT_ShowButtonBar, OPT_AutoRaiseBoard, OPT_ShowCoordinates, + OPT_Blindfold, OPT_ShowThinking, OPT_HighlightDragging, OPT_TestLegality, + OPT_SaveExtPGN, OPT_HideThinkFromHuman, OPT_ExtraInfoInMoveHistory, + OPT_HighlightMoveArrow, OPT_AutoLogo }, +{ DLG_IcsOptions, IDOK, IDCANCEL, OPT_AutoComment, OPT_AutoKibitz, OPT_AutoObserve, + OPT_GetMoveList, OPT_LocalLineEditing, OPT_QuietPlay, OPT_SeekGraph, OPT_AutoRefresh, + OPT_BgObserve, OPT_DualBoard, OPT_Premove, OPT_PremoveWhite, OPT_PremoveBlack, + OPT_SmartMove, OPT_IcsAlarm, IDC_Sec, OPT_ChooseShoutColor, OPT_ChooseSShoutColor, + OPT_ChooseChannel1Color, OPT_ChooseChannelColor, OPT_ChooseKibitzColor, + OPT_ChooseTellColor, OPT_ChooseChallengeColor, OPT_ChooseRequestColor, + OPT_ChooseSeekColor, OPT_ChooseNormalColor, OPT_ChooseBackgroundColor, + OPT_DefaultColors, OPT_DontColorize, IDC_Boxes, GPB_Colors, GPB_Premove, + GPB_General, GPB_Alarm }, +{ DLG_BoardOptions, IDOK, IDCANCEL, OPT_SizeTiny, OPT_SizeTeeny, OPT_SizeDinky, + OPT_SizePetite, OPT_SizeSlim, OPT_SizeSmall, OPT_SizeMediocre, OPT_SizeMiddling, + OPT_SizeAverage, OPT_SizeModerate, OPT_SizeMedium, OPT_SizeBulky, OPT_SizeLarge, + OPT_SizeBig, OPT_SizeHuge, OPT_SizeGiant, OPT_SizeColossal, OPT_SizeTitanic, + OPT_ChooseLightSquareColor, OPT_ChooseDarkSquareColor, OPT_ChooseWhitePieceColor, + OPT_ChooseBlackPieceColor, OPT_ChooseHighlightSquareColor, OPT_ChoosePremoveHighlightColor, + OPT_Monochrome, OPT_AllWhite, OPT_UpsideDown, OPT_DefaultBoardColors, GPB_Colors, + IDC_Light, IDC_Dark, IDC_White, IDC_Black, IDC_High, IDC_PreHigh, GPB_Size }, +{ DLG_NewVariant, IDOK, IDCANCEL, OPT_VariantNormal, OPT_VariantFRC, OPT_VariantWildcastle, + OPT_VariantNocastle, OPT_VariantLosers, OPT_VariantGiveaway, OPT_VariantSuicide, + OPT_Variant3Check, OPT_VariantTwoKings, OPT_VariantAtomic, OPT_VariantCrazyhouse, + OPT_VariantBughouse, OPT_VariantTwilight, OPT_VariantShogi, OPT_VariantSuper, + OPT_VariantKnightmate, OPT_VariantBerolina, OPT_VariantCylinder, OPT_VariantFairy, + OPT_VariantMakruk, OPT_VariantGothic, OPT_VariantCapablanca, OPT_VariantJanus, + OPT_VariantCRC, OPT_VariantFalcon, OPT_VariantCourier, OPT_VariantGreat, + OPT_VariantShatranj, OPT_VariantXiangqi, GPB_Variant, GPB_Board, IDC_Height, + IDC_Width, IDC_Hand, IDC_Pieces, IDC_Def }, +{ DLG_Fonts, IDOK, IDCANCEL, OPT_ChooseClockFont, OPT_ChooseMessageFont, + OPT_ChooseCoordFont, OPT_ChooseTagFont, OPT_ChooseCommentsFont, OPT_ChooseConsoleFont, OPT_ChooseMoveHistoryFont, OPT_DefaultFonts, + OPT_ClockFont, OPT_MessageFont, OPT_CoordFont, OPT_EditTagsFont, + OPT_CommentsFont, OPT_MessageFont5, GPB_Current, GPB_All, OPT_MessageFont6 }, +{ DLG_NewGameFRC, IDC_NFG_Label, IDC_NFG_Random, IDOK, IDCANCEL }, +{ DLG_GameListOptions, IDC_GLT, IDC_GLT_Up, IDC_GLT_Down, IDC_GLT_Restore, + IDC_GLT_Default, IDOK, IDCANCEL, IDC_GLT_RestoreTo }, +{ DLG_MoveHistory }, +{ DLG_EvalGraph }, +{ DLG_EngineOutput, IDC_EngineLabel1, IDC_Engine1_NPS, IDC_EngineLabel2, IDC_Engine2_NPS }, +{ DLG_Chat, IDC_Partner, IDC_Clear, IDC_Send, }, +{ DLG_EnginePlayOptions, IDC_EpPonder, IDC_EpShowThinking, IDC_EpHideThinkingHuman, + IDC_EpPeriodicUpdates, GPB_Adjudications, IDC_Draw, IDC_Moves, IDC_Threshold, + IDC_Centi, IDC_TestClaims, IDC_DetectMates, IDC_MaterialDraws, IDC_TrivialDraws, + GPB_Apply, IDC_Rule, IDC_Repeats, IDC_ScoreAbs1, IDC_ScoreAbs2, IDOK, IDCANCEL }, +{ DLG_OptionsUCI, IDC_PolyDir, IDC_BrowseForPolyglotDir, IDC_Hash, IDC_Path, + IDC_BrowseForEGTB, IDC_Cache, IDC_UseBook, IDC_BrowseForBook, IDC_CPU, IDC_OwnBook1, + IDC_OwnBook2, IDC_Depth, IDC_Variation, IDC_DefGames, IDOK, IDCANCEL }, +{ 0 } +}; + +static char languageBuf[50000], *foreign[1000], *english[1000], *languageFile[MSG_SIZ]; +static int lastChecked; +static char oldLanguage[MSG_SIZ], *menuText[10][30]; +extern int tinyLayout; +extern char * menuBarText[][8]; + +void +LoadLanguageFile(char *name) +{ //load the file with translations, and make a list of the strings to be translated, and their translations + FILE *f; + int i=0, j=0, n=0, k; + char buf[MSG_SIZ]; + + if(!name || name[0] == NULLCHAR) return; + snprintf(buf, MSG_SIZ, "%s%s", name, strchr(name, '.') ? "" : ".lng"); // auto-append lng extension + 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) { + if(i >= sizeof(languageBuf)) { DisplayError("Language file too big", 0); return; } + languageBuf[i] = k; + if(k == '\n') { + if(languageBuf[n] == '"' && languageBuf[i-1] == '"') { + char *p; + if(p = strstr(languageBuf + n + 1, "\" === \"")) { + if(p > languageBuf+n+2 && p+8 < languageBuf+i) { + if(j >= sizeof(english)) { DisplayError("Too many translated strings", 0); return; } + english[j] = languageBuf + n + 1; *p = 0; + foreign[j++] = p + 7; languageBuf[i-1] = 0; +//if(appData.debugMode) fprintf(debugFP, "translation: replace '%s' by '%s'\n", english[j-1], foreign[j-1]); + } + } + } + n = i + 1; + } else if(i > 0 && languageBuf[i-1] == '\\') { + switch(k) { + case 'n': k = '\n'; break; + case 'r': k = '\r'; break; + case 't': k = '\t'; break; + } + languageBuf[--i] = k; + } + i++; + } + fclose(f); + barbaric = (j != 0); + safeStrCpy(oldLanguage, buf, sizeof(oldLanguage)/sizeof(oldLanguage[0]) ); +} + +char * +T_(char *s) +{ // return the translation of the given string + // efficiency can be improved a lot... + int i=0; +//if(appData.debugMode) fprintf(debugFP, "T_(%s)\n", s); + if(!barbaric) return s; + if(!s) return ""; // sanity + while(english[i]) { + if(!strcmp(s, english[i])) return foreign[i]; + i++; + } + return s; +} + +void +Translate(HWND hDlg, int dialogID) +{ // translate all text items in the given dialog + int i=0, j, k; + char buf[MSG_SIZ], *s; +//if(appData.debugMode) fprintf(debugFP, "Translate(%d)\n", dialogID); + if(!barbaric) return; + while(dialogItems[i][0] && dialogItems[i][0] != dialogID) i++; // find the dialog description + if(dialogItems[i][0] != dialogID) return; // unknown dialog, should not happen + GetWindowText( hDlg, buf, MSG_SIZ ); + s = T_(buf); +//if(appData.debugMode) fprintf(debugFP, "WindowText '%s' -> '%s'\n", buf, s); + if(strcmp(buf, s)) SetWindowText(hDlg, s); // replace by translated string (if different) + for(j=1; k=dialogItems[i][j]; j++) { // translate all listed dialog items + GetDlgItemText(hDlg, k, buf, MSG_SIZ); + if(strlen(buf) == 0) continue; + s = T_(buf); + if(strcmp(buf, s)) SetDlgItemText(hDlg, k, s); // replace by translated string (if different) + } +} + +void +TranslateMenus(int addLanguage) +{ + int i, j; + WIN32_FIND_DATA fileData; + HANDLE hFind; +#define IDM_English 1895 + if(1) { + HMENU mainMenu = GetMenu(hwndMain); + for (i=GetMenuItemCount(mainMenu)-1; i>=0; i--) { + HMENU subMenu = GetSubMenu(mainMenu, i); + ModifyMenu(mainMenu, i, MF_STRING|MF_BYPOSITION|MF_POPUP|EnableMenuItem(mainMenu, i, MF_BYPOSITION), + (UINT) subMenu, T_(menuBarText[tinyLayout][i])); + for(j=GetMenuItemCount(subMenu)-1; j>=0; j--){ + char buf[MSG_SIZ]; + UINT k = GetMenuItemID(subMenu, j); + if(menuText[i][j]) + safeStrCpy(buf, menuText[i][j], sizeof(buf)/sizeof(buf[0]) ); else { + GetMenuString(subMenu, j, buf, MSG_SIZ, MF_BYPOSITION); + menuText[i][j] = strdup(buf); // remember original on first change + } + if(buf[0] == NULLCHAR) continue; +//fprintf(debugFP, "menu(%d,%d) = %s (%08x, %08x) %d\n", i, j, buf, mainMenu, subMenu, k); + ModifyMenu(subMenu, j, MF_STRING|MF_BYPOSITION + |CheckMenuItem(subMenu, j, MF_BYPOSITION) + |EnableMenuItem(subMenu, j, MF_BYPOSITION), k, T_(buf)); + } + } + DrawMenuBar(hwndMain); + } + + if(!addLanguage) return; + if((hFind = FindFirstFile("*.LNG", &fileData)) != INVALID_HANDLE_VALUE) { + HMENU mainMenu = GetMenu(hwndMain); + HMENU subMenu = GetSubMenu(mainMenu, GetMenuItemCount(mainMenu)-1); + AppendMenu(subMenu, MF_SEPARATOR, (UINT_PTR) 0, NULL); + AppendMenu(subMenu, MF_ENABLED|MF_STRING|(barbaric?MF_UNCHECKED:MF_CHECKED), (UINT_PTR) IDM_English, (LPCTSTR) "English"); + i = 0; lastChecked = IDM_English; + do { + char *p, *q = fileData.cFileName; + int checkFlag = MF_UNCHECKED; + languageFile[i] = strdup(q); + if(barbaric && !strcmp(oldLanguage, q)) { + checkFlag = MF_CHECKED; + lastChecked = IDM_English + i + 1; + CheckMenuItem(mainMenu, IDM_English, MF_BYCOMMAND|MF_UNCHECKED); + } + *q = ToUpper(*q); while(*++q) *q = ToLower(*q); + p = strstr(fileData.cFileName, ".lng"); + if(p) *p = 0; + AppendMenu(subMenu, MF_ENABLED|MF_STRING|checkFlag, (UINT_PTR) IDM_English + ++i, (LPCTSTR) fileData.cFileName); + } while(FindNextFile(hFind, &fileData)); + FindClose(hFind); + } +} + +#endif + typedef struct { char *name; int squareSize; @@ -302,8 +550,8 @@ MyButtonDesc buttonDesc[N_BUTTONS] = int tinyLayout = 0, smallLayout = 0; #define MENU_BAR_ITEMS 7 char *menuBarText[2][MENU_BAR_ITEMS+1] = { - { "&File", "&Mode", "&Action", "&Step", "&Options", "&Help", NULL }, - { "&F", "&M", "&A", "&S", "&O", "&H", NULL }, + { N_("&File"), N_("&Mode"), N_("&Action"), N_("&Step"), N_("&Options"), N_("&Help"), NULL }, + { N_("&F"), N_("&M"), N_("&A"), N_("&S"), N_("&O"), N_("&H"), NULL }, }; @@ -311,17 +559,17 @@ MySound sounds[(int)NSoundClasses]; MyTextAttribs textAttribs[(int)NColorClasses]; MyColorizeAttribs colorizeAttribs[] = { - { (COLORREF)0, 0, "Shout Text" }, - { (COLORREF)0, 0, "SShout/CShout" }, - { (COLORREF)0, 0, "Channel 1 Text" }, - { (COLORREF)0, 0, "Channel Text" }, - { (COLORREF)0, 0, "Kibitz Text" }, - { (COLORREF)0, 0, "Tell Text" }, - { (COLORREF)0, 0, "Challenge Text" }, - { (COLORREF)0, 0, "Request Text" }, - { (COLORREF)0, 0, "Seek Text" }, - { (COLORREF)0, 0, "Normal Text" }, - { (COLORREF)0, 0, "None" } + { (COLORREF)0, 0, N_("Shout Text") }, + { (COLORREF)0, 0, N_("SShout/CShout") }, + { (COLORREF)0, 0, N_("Channel 1 Text") }, + { (COLORREF)0, 0, N_("Channel Text") }, + { (COLORREF)0, 0, N_("Kibitz Text") }, + { (COLORREF)0, 0, N_("Tell Text") }, + { (COLORREF)0, 0, N_("Challenge Text") }, + { (COLORREF)0, 0, N_("Request Text") }, + { (COLORREF)0, 0, N_("Seek Text") }, + { (COLORREF)0, 0, N_("Normal Text") }, + { (COLORREF)0, 0, N_("None") } }; @@ -632,9 +880,9 @@ SetUserLogo() if(appData.autoLogo) { curName = UserName(); if(strcmp(curName, oldUserName)) { - sprintf(oldUserName, "logos\\%s.bmp", curName); + snprintf(oldUserName, MSG_SIZ, "logos\\%s.bmp", curName); userLogo = LoadImage( 0, oldUserName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - strcpy(oldUserName, curName); + safeStrCpy(oldUserName, curName, sizeof(oldUserName)/sizeof(oldUserName[0]) ); } } } @@ -726,6 +974,8 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) setbuf(debugFP, NULL); } + LoadLanguageFile(appData.language); + InitBackEnd1(); // InitEngineUCI( installDir, &first ); // [HGM] incorporated in InitBackEnd1() @@ -753,7 +1003,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } else if(appData.autoLogo) { if(appData.firstDirectory && appData.firstDirectory[0]) { char buf[MSG_SIZ]; - sprintf(buf, "%s/logo.bmp", appData.firstDirectory); + snprintf(buf, MSG_SIZ, "%s/logo.bmp", appData.firstDirectory); first.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); } } @@ -767,11 +1017,11 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } else if(appData.autoLogo) { char buf[MSG_SIZ]; if(appData.icsActive) { // [HGM] logo: in ICS mode second can be used for ICS - sprintf(buf, "logos\\%s.bmp", appData.icsHost); + snprintf(buf, MSG_SIZ, "logos\\%s.bmp", appData.icsHost); second.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); } else if(appData.secondDirectory && appData.secondDirectory[0]) { - sprintf(buf, "%s\\logo.bmp", appData.secondDirectory); + snprintf(buf, MSG_SIZ, "%s\\logo.bmp", appData.secondDirectory); second.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); } } @@ -797,6 +1047,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } InitDrawingSizes(boardSize, 0); + TranslateMenus(1); InitMenuChecks(); buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS); @@ -836,8 +1087,6 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) EngineOutputPopUp(); } - InitBackEnd2(); - /* Make the window visible; update its client area; and return "success" */ EnsureOnScreen(&wpMain.x, &wpMain.y, minX, minY); wp.length = sizeof(WINDOWPLACEMENT); @@ -850,6 +1099,8 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) wp.rcNormalPosition.bottom = wpMain.y + wpMain.height; SetWindowPlacement(hwndMain, &wp); + InitBackEnd2(); // [HGM] moved until after all windows placed, to save correct position if fatal error on engine start + if(!appData.noGUI) SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); @@ -859,6 +1110,16 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); #endif ShowWindow(hwndConsole, nCmdShow); + if(appData.chatBoxes) { // [HGM] chat: open chat boxes + char buf[MSG_SIZ], *p = buf, *q; + safeStrCpy(buf, appData.chatBoxes, sizeof(buf)/sizeof(buf[0]) ); + do { + q = strchr(p, ';'); + if(q) *q++ = 0; + if(*p) ChatPopUp(p); + } while(p=q); + } + SetActiveWindow(hwndConsole); } if(!appData.noGUI) UpdateWindow(hwnd); else ShowWindow(hwnd, SW_MINIMIZE); if(gameListDialog) SetFocus(gameListDialog); // [HGM] jaws: for if we clicked multi-game game file @@ -911,7 +1172,7 @@ LFfromMFP(LOGFONT* lf, MyFontParams *mfp) lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; lf->lfQuality = DEFAULT_QUALITY; lf->lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE; - strcpy(lf->lfFaceName, mfp->faceName); + safeStrCpy(lf->lfFaceName, mfp->faceName, sizeof(lf->lfFaceName)/sizeof(lf->lfFaceName[0]) ); } void @@ -956,7 +1217,7 @@ ParseFontName(char *name, MyFontParams *mfp) q = strchr(p, ':'); if (q) { if (q - p >= sizeof(mfp->faceName)) - ExitArgError("Font name too long:", name); + ExitArgError(_("Font name too long:"), name); memcpy(mfp->faceName, p, q - p); mfp->faceName[q - p] = NULLCHAR; p = q + 1; @@ -965,12 +1226,12 @@ ParseFontName(char *name, MyFontParams *mfp) while (*p && !isdigit(*p)) { *q++ = *p++; if (q - mfp->faceName >= sizeof(mfp->faceName)) - ExitArgError("Font name too long:", name); + ExitArgError(_("Font name too long:"), name); } while (q > mfp->faceName && q[-1] == ' ') q--; *q = NULLCHAR; } - if (!*p) ExitArgError("Font point size missing:", name); + if (!*p) ExitArgError(_("Font point size missing:"), name); mfp->pointSize = (float) atof(p); mfp->bold = (strchr(p, 'b') != NULL); mfp->italic = (strchr(p, 'i') != NULL); @@ -1027,7 +1288,7 @@ ParseColorName(char *name) &red, &green, &blue); } if (count != 3) { - sprintf(buf, "Can't parse color name %s", name); + snprintf(buf, MSG_SIZ, _("Can't parse color name %s"), name); DisplayError(buf, 0); return RGB(0, 0, 0); } @@ -1076,7 +1337,7 @@ ParseBoardSize(void *addr, char *name) } bs++; } - ExitArgError("Unrecognized board size value", name); + ExitArgError(_("Unrecognized board size value"), name); } void @@ -1210,7 +1471,19 @@ PrintCommPortSettings(FILE *f, char *name) int MySearchPath(char *installDir, char *name, char *fullname) { - char *dummy; + char *dummy, buf[MSG_SIZ], *p = name, *q; + if(name[0]== '%') { + fullname[0] = 0; // [HGM] first expand any environment variables in the given name + while(*p == '%' && (q = strchr(p+1, '%'))) { // [HGM] recognize %*% as environment variable + safeStrCpy(buf, p+1, sizeof(buf)/sizeof(buf[0]) ); + *strchr(buf, '%') = 0; + strcat(fullname, getenv(buf)); + p = q+1; while(*p == '\\') { strcat(fullname, "\\"); p++; } + } + strcat(fullname, p); // after environment variables (if any), take the remainder of the given name + if(appData.debugMode) fprintf(debugFP, "name = '%s', expanded name = '%s'\n", name, fullname); + return (int) strlen(fullname); + } return (int) SearchPath(installDir, name, NULL, MSG_SIZ, fullname, &dummy); } @@ -1232,6 +1505,7 @@ PopUpStartupDialog() { FARPROC lpProc; + LoadLanguageFile(appData.language); lpProc = MakeProcInstance((FARPROC)StartupDialog, hInst); DialogBox(hInst, MAKEINTRESOURCE(DLG_Startup), NULL, (DLGPROC)lpProc); FreeProcInstance(lpProc); @@ -1786,11 +2060,11 @@ DoLoadBitmap(HINSTANCE hinst, char *piece, int squareSize, char *suffix) { char name[128]; - sprintf(name, "%s%d%s", piece, squareSize, suffix); + snprintf(name, sizeof(name)/sizeof(name[0]), "%s%d%s", piece, squareSize, suffix); if (gameInfo.event && strcmp(gameInfo.event, "Easter Egg Hunt") == 0 && strcmp(name, "k80s") == 0) { - strcpy(name, "tim"); + safeStrCpy(name, "tim", sizeof(name)/sizeof(name[0]) ); } return LoadBitmap(hinst, name); } @@ -1807,7 +2081,7 @@ InsertInPalette(COLORREF color) LPPALETTEENTRY pe = &(pLogPal->palPalEntry[pLogPal->palNumEntries]); if (pLogPal->palNumEntries++ >= PALETTESIZE) { - DisplayFatalError("Too many colors", 0, 1); + DisplayFatalError(_("Too many colors"), 0, 1); pLogPal->palNumEntries--; return; } @@ -1896,6 +2170,7 @@ ResizeBoard(int newSizeX, int newSizeY, int flags) } +extern Boolean twoBoards, partnerUp; // [HGM] dual VOID InitDrawingSizes(BoardSize boardSize, int flags) @@ -1948,7 +2223,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) for (i=0; menuBarText[tinyLayout][i]; i++) { ModifyMenu(hmenu, i, MF_STRING|MF_BYPOSITION|MF_POPUP, - (UINT)GetSubMenu(hmenu, i), menuBarText[tinyLayout][i]); + (UINT)GetSubMenu(hmenu, i), T_(menuBarText[tinyLayout][i])); } DrawMenuBar(hwndMain); } @@ -1959,14 +2234,14 @@ InitDrawingSizes(BoardSize boardSize, int flags) /* Get text area sizes */ hdc = GetDC(hwndMain); if (appData.clockMode) { - sprintf(buf, "White: %s", TimeString(23*60*60*1000L)); + snprintf(buf, MSG_SIZ, _("White: %s"), TimeString(23*60*60*1000L)); } else { - sprintf(buf, "White"); + snprintf(buf, MSG_SIZ, _("White")); } oldFont = SelectObject(hdc, font[boardSize][CLOCK_FONT]->hf); GetTextExtentPoint(hdc, buf, strlen(buf), &clockSize); SelectObject(hdc, font[boardSize][MESSAGE_FONT]->hf); - str = "We only care about the height here"; + str = _("We only care about the height here"); GetTextExtentPoint(hdc, str, strlen(str), &messageSize); SelectObject(hdc, oldFont); ReleaseDC(hwndMain, hdc); @@ -2031,6 +2306,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) winW = 2 * GetSystemMetrics(SM_CXFRAME) + boardRect.right + OUTER_MARGIN; winH = 2 * GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION) + boardRect.bottom + OUTER_MARGIN; + winW *= 1 + twoBoards; if(suppressVisibleEffects) return; // [HGM] when called for filling sizeInfo only wpMain.width = winW; // [HGM] placement: set through temporary which can used by initial sizing choice wpMain.height = winH; // without disturbing window attachments @@ -2182,7 +2458,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) pieceBitmap[2][WhiteBishop] = DoLoadBitmap(hInst, "b", squareSize, "w"); pieceBitmap[2][WhiteRook] = DoLoadBitmap(hInst, "r", squareSize, "w"); pieceBitmap[2][WhiteKing] = DoLoadBitmap(hInst, "k", squareSize, "w"); - if( !strcmp(appData.variant, "shogi") && (squareSize==72 || squareSize==49)) { + if( gameInfo.variant == VariantShogi && squareSize <= 72 && squareSize >= 33) { // in Shogi, Hijack the unused Queen for Lance pieceBitmap[0][WhiteQueen] = DoLoadBitmap(hInst, "l", squareSize, "s"); pieceBitmap[1][WhiteQueen] = DoLoadBitmap(hInst, "l", squareSize, "o"); @@ -2477,23 +2753,14 @@ DrawHighlightOnDC(HDC hdc, BOOLEAN on, int x, int y, int pen) } VOID -DrawHighlightsOnDC(HDC hdc) +DrawHighlightsOnDC(HDC hdc, HighlightInfo *h, int pen) { int i; for (i=0; i<2; i++) { - if (highlightInfo.sq[i].x >= 0 && highlightInfo.sq[i].y >= 0) + if (h->sq[i].x >= 0 && h->sq[i].y >= 0) DrawHighlightOnDC(hdc, TRUE, - highlightInfo.sq[i].x, highlightInfo.sq[i].y, - HIGHLIGHT_PEN); - } - for (i=0; i<2; i++) { - if (premoveHighlightInfo.sq[i].x >= 0 && - premoveHighlightInfo.sq[i].y >= 0) { - DrawHighlightOnDC(hdc, TRUE, - premoveHighlightInfo.sq[i].x, - premoveHighlightInfo.sq[i].y, - PREMOVE_PEN); - } + h->sq[i].x, h->sq[i].y, + pen); } } @@ -2510,7 +2777,7 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, if (appData.blindfold) return; /* [AS] Use font-based pieces if needed */ - if( fontBitmapSquareSize >= 0 && squareSize > 32 ) { + if( fontBitmapSquareSize >= 0 && (squareSize > 32 || gameInfo.variant >= VariantShogi)) { /* Create piece bitmaps, or do nothing if piece set is up to date */ CreatePiecesFromFont(); @@ -2519,6 +2786,9 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, SelectObject( tmphdc, hPieceMask[ index ] ); + if(appData.upsideDown ? color==flipView : (flipView && gameInfo.variant == VariantShogi)) + StretchBlt(hdc, x+squareSize, y+squareSize, -squareSize, -squareSize, tmphdc, 0, 0, squareSize, squareSize, SRCAND); + else BitBlt( hdc, x, y, squareSize, squareSize, @@ -2528,6 +2798,9 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, SelectObject( tmphdc, hPieceFace[ index ] ); + if(appData.upsideDown ? color==flipView : (flipView && gameInfo.variant == VariantShogi)) + StretchBlt(hdc, x+squareSize, y+squareSize, -squareSize, -squareSize, tmphdc, 0, 0, squareSize, squareSize, SRCPAINT); + else BitBlt( hdc, x, y, squareSize, squareSize, @@ -2637,7 +2910,13 @@ VOID RebuildTextureSquareInfo() if( (col + row) & 1 ) { /* Lite square */ if( lite_w >= squareSize && lite_h >= squareSize ) { + if( lite_w >= squareSize*BOARD_WIDTH ) + backTextureSquareInfo[row][col].x = (2*col+1)*lite_w/(2*BOARD_WIDTH) - squareSize/2; /* [HGM] cut out of center of virtual square */ + else backTextureSquareInfo[row][col].x = col * (lite_w - squareSize) / (BOARD_WIDTH-1); /* [HGM] divide by size-1 in stead of size! */ + if( lite_h >= squareSize*BOARD_HEIGHT ) + backTextureSquareInfo[row][col].y = (2*(BOARD_HEIGHT-row)-1)*lite_h/(2*BOARD_HEIGHT) - squareSize/2; + else backTextureSquareInfo[row][col].y = (BOARD_HEIGHT-1-row) * (lite_h - squareSize) / (BOARD_HEIGHT-1); backTextureSquareInfo[row][col].mode = GetBackTextureMode(liteBackTextureMode); } @@ -2645,7 +2924,13 @@ VOID RebuildTextureSquareInfo() else { /* Dark square */ if( dark_w >= squareSize && dark_h >= squareSize ) { + if( dark_w >= squareSize*BOARD_WIDTH ) + backTextureSquareInfo[row][col].x = (2*col+1) * dark_w / (2*BOARD_WIDTH) - squareSize/2; + else backTextureSquareInfo[row][col].x = col * (dark_w - squareSize) / (BOARD_WIDTH-1); + if( dark_h >= squareSize*BOARD_HEIGHT ) + backTextureSquareInfo[row][col].y = (2*(BOARD_HEIGHT-row)-1) * dark_h / (2*BOARD_HEIGHT) - squareSize/2; + else backTextureSquareInfo[row][col].y = (BOARD_HEIGHT-1-row) * (dark_h - squareSize) / (BOARD_HEIGHT-1); backTextureSquareInfo[row][col].mode = GetBackTextureMode(darkBackTextureMode); } @@ -3128,9 +3413,9 @@ void DrawSeekText(char *buf, int x, int y) void DrawSeekDot(int x, int y, int color) { int square = color & 0x80; - color &= 0x7F; - HBRUSH oldBrush = SelectObject(hdcSeek, + HBRUSH oldBrush = SelectObject(hdcSeek, color == 0 ? markerBrush : color == 1 ? darkSquareBrush : explodeBrush); + color &= 0x7F; if(square) Rectangle(hdcSeek, boardRect.left+x - squareSize/9, boardRect.top+y - squareSize/9, boardRect.left+x + squareSize/9, boardRect.top+y + squareSize/9); @@ -3143,10 +3428,10 @@ void DrawSeekDot(int x, int y, int color) VOID HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) { - static Board lastReq, lastDrawn; + static Board lastReq[2], lastDrawn[2]; static HighlightInfo lastDrawnHighlight, lastDrawnPremove; static int lastDrawnFlipView = 0; - static int lastReqValid = 0, lastDrawnValid = 0; + static int lastReqValid[2] = {0, 0}, lastDrawnValid[2] = {0, 0}; int releaseDC, x, y, x2, y2, row, column, num_clips = 0, i; HDC tmphdc; HDC hdcmem; @@ -3155,6 +3440,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) RECT Rect; HRGN clips[MAX_CLIPS]; ChessSquare dragged_piece = EmptySquare; + int nr = twoBoards*partnerUp; /* I'm undecided on this - this function figures out whether a full * repaint is necessary on its own, so there's no real reason to have the @@ -3173,13 +3459,13 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) } if (board == NULL) { - if (!lastReqValid) { + if (!lastReqValid[nr]) { return; } - board = lastReq; + board = lastReq[nr]; } else { - CopyBoard(lastReq, board); - lastReqValid = 1; + CopyBoard(lastReq[nr], board); + lastReqValid[nr] = 1; } if (doingSizing) { @@ -3225,16 +3511,17 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) * newest board with the last drawn board and checking if * flipping has changed. */ - if (!fullrepaint && lastDrawnValid && lastDrawnFlipView == flipView) { + if (!fullrepaint && lastDrawnValid[nr] && (nr == 1 || lastDrawnFlipView == flipView)) { for (row = 0; row < BOARD_HEIGHT; row++) { /* [HGM] true size, not 8 */ for (column = 0; column < BOARD_WIDTH; column++) { - if (lastDrawn[row][column] != board[row][column]) { + if (lastDrawn[nr][row][column] != board[row][column]) { SquareToPos(row, column, &x, &y); clips[num_clips++] = CreateRectRgn(x, y, x + squareSize, y + squareSize); } } } + if(nr == 0) { // [HGM] dual: no highlights on second board for (i=0; i<2; i++) { if (lastDrawnHighlight.sq[i].x != highlightInfo.sq[i].x || lastDrawnHighlight.sq[i].y != highlightInfo.sq[i].y) { @@ -3275,6 +3562,30 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) } } } + } else { // nr == 1 + partnerHighlightInfo.sq[0].y = board[EP_STATUS-4]; + partnerHighlightInfo.sq[0].x = board[EP_STATUS-3]; + partnerHighlightInfo.sq[1].y = board[EP_STATUS-2]; + partnerHighlightInfo.sq[1].x = board[EP_STATUS-1]; + for (i=0; i<2; i++) { + if (partnerHighlightInfo.sq[i].x >= 0 && + partnerHighlightInfo.sq[i].y >= 0) { + SquareToPos(partnerHighlightInfo.sq[i].y, + partnerHighlightInfo.sq[i].x, &x, &y); + clips[num_clips++] = + CreateRectRgn(x - lineGap, y - lineGap, + x + squareSize + lineGap, y + squareSize + lineGap); + } + if (oldPartnerHighlight.sq[i].x >= 0 && + oldPartnerHighlight.sq[i].y >= 0) { + SquareToPos(oldPartnerHighlight.sq[i].y, + oldPartnerHighlight.sq[i].x, &x, &y); + clips[num_clips++] = + CreateRectRgn(x - lineGap, y - lineGap, + x + squareSize + lineGap, y + squareSize + lineGap); + } + } + } } else { fullrepaint = TRUE; } @@ -3334,7 +3645,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) explodes. The old and new positions both had an empty square at the destination, but animation has drawn a piece there and we have to remember to erase it. [HGM] moved until after setting lastDrawn */ - lastDrawn[animInfo.to.y][animInfo.to.x] = animInfo.piece; + lastDrawn[0][animInfo.to.y][animInfo.to.x] = animInfo.piece; } } @@ -3355,6 +3666,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) if(explodeInfo.radius) { // [HGM] atomic HBRUSH oldBrush; int x, y, r=(explodeInfo.radius * squareSize)/100; + ChessSquare piece = board[explodeInfo.fromY][explodeInfo.fromX]; board[explodeInfo.fromY][explodeInfo.fromX] = EmptySquare; // suppress display of capturer SquareToPos(explodeInfo.toY, explodeInfo.toX, &x, &y); x += squareSize/2; @@ -3364,16 +3676,25 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) ExtSelectClipRgn(hdcmem, clips[num_clips++], RGN_OR); } DrawGridOnDC(hdcmem); - DrawHighlightsOnDC(hdcmem); + DrawHighlightsOnDC(hdcmem, &highlightInfo, HIGHLIGHT_PEN); + DrawHighlightsOnDC(hdcmem, &premoveHighlightInfo, PREMOVE_PEN); DrawBoardOnDC(hdcmem, board, tmphdc); + board[explodeInfo.fromY][explodeInfo.fromX] = piece; oldBrush = SelectObject(hdcmem, explodeBrush); Ellipse(hdcmem, x-r, y-r, x+r, y+r); SelectObject(hdcmem, oldBrush); } else { DrawGridOnDC(hdcmem); - DrawHighlightsOnDC(hdcmem); + if(nr == 0) { // [HGM] dual: decide which highlights to draw + DrawHighlightsOnDC(hdcmem, &highlightInfo, HIGHLIGHT_PEN); + DrawHighlightsOnDC(hdcmem, &premoveHighlightInfo, PREMOVE_PEN); + } else { + DrawHighlightsOnDC(hdcmem, &partnerHighlightInfo, HIGHLIGHT_PEN); + oldPartnerHighlight = partnerHighlightInfo; + } DrawBoardOnDC(hdcmem, board, tmphdc); } + if(nr == 0) // [HGM] dual: markers only on left board for (row = 0; row < BOARD_HEIGHT; row++) { for (column = 0; column < BOARD_WIDTH; column++) { if (marker[row][column]) { // marker changes only occur with full repaint! @@ -3428,7 +3749,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) DrawCoordsOnDC(hdcmem); - CopyBoard(lastDrawn, board); /* [HGM] Moved to here from end of routine, */ + CopyBoard(lastDrawn[nr], board); /* [HGM] Moved to here from end of routine, */ /* to make sure lastDrawn contains what is actually drawn */ /* Put the dragged piece back into place and draw it (out of place!) */ @@ -3465,6 +3786,13 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) /* Set clipping on the target DC */ if (!fullrepaint) { + if(nr == 1) for (x = 0; x < num_clips; x++) { // [HGM] dual: translate clips + RECT rect; + GetRgnBox(clips[x], &rect); + DeleteObject(clips[x]); + clips[x] = CreateRectRgn(rect.left + wpMain.width/2, rect.top, + rect.right + wpMain.width/2, rect.bottom); + } SelectClipRgn(hdc, clips[0]); for (x = 1; x < num_clips; x++) { if (ExtSelectClipRgn(hdc, clips[x], RGN_OR) == ERROR) @@ -3476,7 +3804,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) * This way we avoid any flickering */ oldBitmap = SelectObject(tmphdc, bufferBitmap); - BitBlt(hdc, boardRect.left, boardRect.top, + BitBlt(hdc, boardRect.left + twoBoards*partnerUp*wpMain.width/2, boardRect.top, // [HGM] dual boardRect.right - boardRect.left, boardRect.bottom - boardRect.top, tmphdc, boardRect.left, boardRect.top, SRCCOPY); @@ -3564,7 +3892,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) if (releaseDC) ReleaseDC(hwndMain, hdc); - if (lastDrawnFlipView != flipView) { + if (lastDrawnFlipView != flipView && nr == 0) { if (flipView) CheckMenuItem(GetMenu(hwndMain),IDM_FlipView, MF_BYCOMMAND|MF_CHECKED); else @@ -3575,7 +3903,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) lastDrawnHighlight = highlightInfo; lastDrawnPremove = premoveHighlightInfo; lastDrawnFlipView = flipView; - lastDrawnValid = 1; + lastDrawnValid[nr] = 1; } /* [HGM] diag: Save the current board display to the given open file and close the file */ @@ -3616,6 +3944,11 @@ PaintProc(HWND hwnd) RealizePalette(hdc); } HDCDrawPosition(hdc, 1, NULL); + if(twoBoards) { // [HGM] dual: also redraw other board in other orientation + flipView = !flipView; partnerUp = !partnerUp; + HDCDrawPosition(hdc, 1, NULL); + flipView = !flipView; partnerUp = !partnerUp; + } oldFont = SelectObject(hdc, font[boardSize][MESSAGE_FONT]->hf); ExtTextOut(hdc, messageRect.left, messageRect.top, @@ -3660,11 +3993,11 @@ typedef struct { } DropEnable; DropEnable dropEnables[] = { - { 'P', DP_Pawn, "Pawn" }, - { 'N', DP_Knight, "Knight" }, - { 'B', DP_Bishop, "Bishop" }, - { 'R', DP_Rook, "Rook" }, - { 'Q', DP_Queen, "Queen" }, + { 'P', DP_Pawn, N_("Pawn") }, + { 'N', DP_Knight, N_("Knight") }, + { 'B', DP_Bishop, N_("Bishop") }, + { 'R', DP_Rook, N_("Rook") }, + { 'Q', DP_Queen, N_("Queen") }, }; VOID @@ -3680,7 +4013,7 @@ SetupDropMenu(HMENU hmenu) dropEnables[i].piece); count = 0; while (p && *p++ == dropEnables[i].piece) count++; - sprintf(item, "%s %d", dropEnables[i].name, count); + snprintf(item, MSG_SIZ, "%s %d", T_(dropEnables[i].name), count); enable = count > 0 || !appData.testLegality /*!!temp:*/ || (gameInfo.variant == VariantCrazyhouse && !appData.icsActive); @@ -3741,25 +4074,27 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) x = BOARD_WIDTH - 1 - x; } + shiftKey = GetKeyState(VK_SHIFT) < 0; // [HGM] remember last shift status + switch (message) { case WM_LBUTTONDOWN: if (PtInRect((LPRECT) &whiteRect, pt)) { if (gameMode == EditPosition) { SetWhiteToPlayEvent(); + } else if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) { + AdjustClock(flipClock, -1); } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) { CallFlagEvent(); - } else if (gameMode == EditGame) { - AdjustClock(flipClock, -1); } } else if (PtInRect((LPRECT) &blackRect, pt)) { if (gameMode == EditPosition) { SetBlackToPlayEvent(); + } else if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) { + AdjustClock(!flipClock, -1); } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) { CallFlagEvent(); - } else if (gameMode == EditGame) { - AdjustClock(!flipClock, -1); } } dragInfo.start.x = dragInfo.start.y = -1; @@ -3808,12 +4143,12 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* Mouse Wheel is being rolled forward * Play moves forward */ - if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) + 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) + if((short)HIWORD(wParam) > 0 && currentMove > backwardMostMove) { if(lastDir == -1) BackwardEvent(); else lastDir = -1; } } break; @@ -3839,10 +4174,11 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(y == -2) { /* [HGM] right mouse button in clock area edit-game mode ups clock */ if (PtInRect((LPRECT) &whiteRect, pt)) { - if (gameMode == EditGame) AdjustClock(flipClock, 1); + if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) AdjustClock(flipClock, 1); } else if (PtInRect((LPRECT) &blackRect, pt)) { - if (gameMode == EditGame) AdjustClock(!flipClock, 1); + if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) AdjustClock(!flipClock, 1); } + break; } DrawPosition(TRUE, NULL); @@ -3935,6 +4271,7 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: /* message: initialize dialog box */ /* Center the dialog over the application window */ CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); + Translate(hDlg, DLG_PromotionKing); ShowWindow(GetDlgItem(hDlg, PB_King), (!appData.testLegality || gameInfo.variant == VariantSuicide || gameInfo.variant == VariantGiveaway || gameInfo.variant == VariantSuper ) ? @@ -4059,7 +4396,7 @@ LoadGameDialog(HWND hwnd, char* title) if (number == 0) { int error = GameListBuild(f); if (error) { - DisplayError("Cannot build game list", error); + DisplayError(_("Cannot build game list"), error); } else if (!ListEmpty(&gameList) && ((ListGame *) gameList.tailPred)->number > 1) { GameListPopUp(f, fileTitle); @@ -4135,7 +4472,8 @@ ChangedConsoleFont() cfmt.cbSize = sizeof(CHARFORMAT); cfmt.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET; - strcpy(cfmt.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName); + safeStrCpy(cfmt.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName, + sizeof(cfmt.szFaceName)/sizeof(cfmt.szFaceName[0]) ); /* yHeight is expressed in twips. A twip is 1/20 of a font's point * size. This was undocumented in the version of MSVC++ that I had * when I wrote the code, but is apparently documented now. @@ -4281,7 +4619,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_LoadGame: - LoadGameDialog(hwnd, "Load Game from File"); + LoadGameDialog(hwnd, _("Load Game from File")); break; case IDM_LoadNextGame: @@ -4304,7 +4642,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) f = OpenFileDialog(hwnd, "rb", "", appData.oldSaveStyle ? "pos" : "fen", POSITION_FILT, - "Load Position from File", &number, fileTitle, NULL); + _("Load Position from File"), &number, fileTitle, NULL); if (f != NULL) { LoadPosition(f, number, fileTitle); } @@ -4327,7 +4665,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) f = OpenFileDialog(hwnd, "a", defName, appData.oldSaveStyle ? "gam" : "pgn", GAME_FILT, - "Save Game to File", NULL, fileTitle, NULL); + _("Save Game to File"), NULL, fileTitle, NULL); if (f != NULL) { SaveGame(f, 0, ""); } @@ -4338,7 +4676,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) f = OpenFileDialog(hwnd, "a", defName, appData.oldSaveStyle ? "pos" : "fen", POSITION_FILT, - "Save Position to File", NULL, fileTitle, NULL); + _("Save Position to File"), NULL, fileTitle, NULL); if (f != NULL) { SavePosition(f, 0, ""); } @@ -4478,6 +4816,12 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) SAY("computer starts playing black"); break; + case IDM_Match: // [HGM] match: flows into next case, after setting Match Mode and nr of Games + if(gameMode != BeginningOfGame) break; // allow menu item to remain enabled for better mode highligting + matchMode = 2;// distinguish from command-line-triggered case (matchMode=1) + appData.matchGames = appData.defaultMatchGames; + matchGame = 1; + case IDM_TwoMachines: TwoMachinesEvent(); /* @@ -4489,19 +4833,19 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) TagsPopUp(tags, CmailMsg()); free(tags); } - SAY("programs start playing each other"); + SAY("computer starts playing both sides"); break; case IDM_AnalysisMode: if (!first.analysisSupport) { - sprintf(buf, "%s does not support analysis", first.tidy); + snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); DisplayError(buf, 0); } else { SAY("analyzing current position"); /* [DM] icsEngineAnlyze [HGM] Why is this front-end??? */ if (appData.icsActive) { if (gameMode != IcsObserving) { - sprintf(buf, "You are not observing a game"); + snprintf(buf, MSG_SIZ, "You are not observing a game"); DisplayError(buf, 0); /* secure check */ if (appData.icsEngineAnalyze) { @@ -4531,12 +4875,12 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_AnalyzeFile: if (!first.analysisSupport) { char buf[MSG_SIZ]; - sprintf(buf, "%s does not support analysis", first.tidy); + snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); DisplayError(buf, 0); } else { if (!appData.showThinking) ToggleShowThinking(); AnalyzeFileEvent(); - LoadGameDialog(hwnd, "Analyze Game from File"); + LoadGameDialog(hwnd, _("Analyze Game from File")); AnalysisPeriodicEvent(1); } break; @@ -4552,7 +4896,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_EditPosition: EditPositionEvent(); - SAY("to set up a position type a FEN"); + SAY("enter a FEN string or setup a position on the board using the control R pop up menu"); break; case IDM_Training: @@ -4654,7 +4998,11 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_Revert: - RevertEvent(); + RevertEvent(FALSE); + break; + + case IDM_Annotate: // [HGM] vari: revert with annotation + RevertEvent(TRUE); break; case IDM_TruncateGame: @@ -4781,7 +5129,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (!MyHelp (hwnd, "winboard.hlp", HELP_KEY,(DWORD)(LPSTR)"CONTENTS") && !HtmlHelp(hwnd, "winboard.chm", 0, 0) ) { MessageBox (GetFocus(), - "Unable to activate help", + _("Unable to activate help"), szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND); } break; @@ -4790,7 +5138,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (!MyHelp (hwnd, "winboard.hlp", HELP_PARTIALKEY, (DWORD)(LPSTR)"") && !HtmlHelp(hwnd, "winboard.chm", 0, 0) ) { MessageBox (GetFocus(), - "Unable to activate help", + _("Unable to activate help"), szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND); } break; @@ -4798,7 +5146,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_HELPHELP: if(!WinHelp(hwnd, (LPSTR)NULL, HELP_HELPONHELP, 0)) { MessageBox (GetFocus(), - "Unable to activate help", + _("Unable to activate help"), szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND); } break; @@ -4812,12 +5160,12 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_DirectCommand1: - AskQuestionEvent("Direct Command", - "Send to chess program:", "", "1"); + AskQuestionEvent(_("Direct Command"), + _("Send to chess program:"), "", "1"); break; case IDM_DirectCommand2: - AskQuestionEvent("Direct Command", - "Send to second chess program:", "", "2"); + AskQuestionEvent(_("Direct Command"), + _("Send to second chess program:"), "", "2"); break; case EP_WhitePawn: @@ -4995,7 +5343,23 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) fromX = fromY = -1; break; + case IDM_English: + barbaric = 0; + TranslateMenus(0); + CheckMenuItem(GetMenu(hwndMain), lastChecked, MF_BYCOMMAND|MF_UNCHECKED); + CheckMenuItem(GetMenu(hwndMain), IDM_English, MF_BYCOMMAND|MF_CHECKED); + lastChecked = wmId; + break; + default: + if(wmId > IDM_English && wmId < IDM_English+5) { + LoadLanguageFile(languageFile[wmId - IDM_English - 1]); + TranslateMenus(0); + CheckMenuItem(GetMenu(hwndMain), lastChecked, MF_BYCOMMAND|MF_UNCHECKED); + CheckMenuItem(GetMenu(hwndMain), wmId, MF_BYCOMMAND|MF_CHECKED); + lastChecked = wmId; + break; + } return (DefWindowProc(hwnd, message, wParam, lParam)); } break; @@ -5234,7 +5598,7 @@ MyLoadSound(MySound *ms) } if (!ok) { char buf[MSG_SIZ]; - sprintf(buf, "Error loading sound %s", ms->name); + snprintf(buf, MSG_SIZ, _("Error loading sound %s"), ms->name); DisplayError(buf, GetLastError()); } return ok; @@ -5300,6 +5664,7 @@ OldOpenFileHook(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) number = NULL; } CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + Translate(hDlg, 1536); return FALSE; /* Allow for further processing */ case WM_COMMAND: @@ -5319,6 +5684,7 @@ OpenFileHook(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) OFNOTIFY *ofnot; switch (uiMsg) { case WM_INITDIALOG: + Translate(hdlg, DLG_IndexNumber); ofname = (OPENFILENAME *)lParam; number = (UINT *)(ofname->lCustData); break; @@ -5344,12 +5710,12 @@ OpenFileDialog(HWND hwnd, char *write, char *defName, char *defExt, // [HGM] dia if (fileName == NULL) fileName = buf1; if (defName == NULL) { - strcpy(fileName, "*."); + safeStrCpy(fileName, "*.", sizeof(fileName)/sizeof(fileName[0]) ); strcat(fileName, defExt); } else { - strcpy(fileName, defName); + safeStrCpy(fileName, defName, sizeof(fileName)/sizeof(fileName[0]) ); } - if (fileTitle) strcpy(fileTitle, ""); + if (fileTitle) safeStrCpy(fileTitle, "", sizeof(fileTitle)/sizeof(fileTitle[0]) ); if (number) *number = 0; openFileName.lStructSize = sizeof(OPENFILENAME); @@ -5382,13 +5748,13 @@ OpenFileDialog(HWND hwnd, char *write, char *defName, char *defExt, // [HGM] dia /* open the file */ f = fopen(openFileName.lpstrFile, write); if (f == NULL) { - MessageBox(hwnd, "File open failed", NULL, + MessageBox(hwnd, _("File open failed"), NULL, MB_OK|MB_ICONEXCLAMATION); return NULL; } } else { int err = CommDlgExtendedError(); - if (err != 0) DisplayError("Internal error in file dialog box", err); + if (err != 0) DisplayError(_("Internal error in file dialog box"), err); return FALSE; } return f; @@ -5548,7 +5914,7 @@ InitComboStrings(HANDLE hwndCombo, char **cd) SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0); while (*cd != NULL) { - SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) *cd); + SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) T_(*cd)); cd++; } } @@ -5627,10 +5993,10 @@ InitEngineBox(HWND hDlg, HWND hwndCombo, char* nthcp, char* nthd, char* nthdir, InitComboStringsFromOption(hwndCombo, nthnames); q = QuoteForFilename(nthcp); - sprintf(buf, "%s%s%s", q, nthcp, q); + snprintf(buf, MSG_SIZ, "%s%s%s", q, nthcp, q); if (*nthdir != NULLCHAR) { q = QuoteForFilename(nthdir); - sprintf(buf + strlen(buf), " /%s=%s%s%s", nthd, q, nthdir, q); + snprintf(buf + strlen(buf), MSG_SIZ, " /%s=%s%s%s", nthd, q, nthdir, q); } if (*nthcp == NULLCHAR) { SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0); @@ -5651,6 +6017,7 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: /* Center the dialog */ CenterWindow (hDlg, GetDesktopWindow()); + Translate(hDlg, DLG_Startup); /* Initialize the dialog items */ InitEngineBox(hDlg, GetDlgItem(hDlg, OPT_ChessEngineName), appData.firstChessProgram, "fd", appData.firstDirectory, @@ -5660,7 +6027,7 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) secondChessProgramNames); hwndCombo = GetDlgItem(hDlg, OPT_ChessServerName); InitComboStringsFromOption(hwndCombo, icsNames); - sprintf(buf, "%s /icsport=%s", appData.icsHost, appData.icsPort); + snprintf(buf, MSG_SIZ, "%s /icsport=%s", appData.icsHost, appData.icsPort); if (*appData.icsHelper != NULLCHAR) { char *q = QuoteForFilename(appData.icsHelper); sprintf(buf + strlen(buf), " /icshelper=%s%s%s", q, appData.icsHelper, q); @@ -5690,23 +6057,23 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (LOWORD(wParam)) { case IDOK: if (IsDlgButtonChecked(hDlg, OPT_ChessEngine)) { - strcpy(buf, "/fcp="); + safeStrCpy(buf, "/fcp=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_ChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf)); p = buf; ParseArgs(StringGet, &p); - strcpy(buf, "/scp="); + safeStrCpy(buf, "/scp=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_SecondChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf)); p = buf; ParseArgs(StringGet, &p); appData.noChessProgram = FALSE; appData.icsActive = FALSE; } else if (IsDlgButtonChecked(hDlg, OPT_ChessServer)) { - strcpy(buf, "/ics /icshost="); + safeStrCpy(buf, "/ics /icshost=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_ChessServerName, buf + strlen(buf), sizeof(buf) - strlen(buf)); p = buf; ParseArgs(StringGet, &p); if (appData.zippyPlay) { - strcpy(buf, "/fcp="); + safeStrCpy(buf, "/fcp=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_ChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf)); p = buf; ParseArgs(StringGet, &p); @@ -5715,8 +6082,8 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) appData.noChessProgram = TRUE; appData.icsActive = FALSE; } else { - MessageBox(hDlg, "Choose an option, or cancel to exit", - "Option Error", MB_OK|MB_ICONEXCLAMATION); + MessageBox(hDlg, _("Choose an option, or cancel to exit"), + _("Option Error"), MB_OK|MB_ICONEXCLAMATION); return TRUE; } if (IsDlgButtonChecked(hDlg, OPT_AnyAdditional)) { @@ -5734,7 +6101,7 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case IDM_HELPCONTENTS: if (!WinHelp (hDlg, "winboard.hlp", HELP_KEY,(DWORD)(LPSTR)"CONTENTS")) { MessageBox (GetFocus(), - "Unable to activate help", + _("Unable to activate help"), szAppName, MB_SYSTEMMODAL|MB_OK|MB_ICONHAND); } break; @@ -5763,6 +6130,7 @@ About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* Center the dialog over the application window */ CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); SetDlgItemText(hDlg, ABOUTBOX_Version, programVersion); + Translate(hDlg, ABOUTBOX); JAWS_COPYRIGHT return (TRUE); @@ -5796,6 +6164,7 @@ CommentDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ + Translate(hDlg, DLG_EditComment); hwndText = GetDlgItem(hDlg, OPT_CommentText); SetDlgItemText(hDlg, OPT_CommentText, commentText); EnableWindow(GetDlgItem(hDlg, OPT_CancelComment), editComment); @@ -5841,6 +6210,7 @@ CommentDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) sizeY = newSizeY; } } + SendDlgItemMessage( hDlg, OPT_CommentText, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); return FALSE; case WM_COMMAND: /* message: received a command */ @@ -5885,6 +6255,36 @@ CommentDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } break; + case WM_NOTIFY: // [HGM] vari: cloned from whistory.c + if( wParam == OPT_CommentText ) { + MSGFILTER * lpMF = (MSGFILTER *) lParam; + + if( lpMF->msg == WM_RBUTTONDOWN && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) { + POINTL pt; + LRESULT index; + + pt.x = LOWORD( lpMF->lParam ); + pt.y = HIWORD( lpMF->lParam ); + + index = SendDlgItemMessage( hDlg, OPT_CommentText, EM_CHARFROMPOS, 0, (LPARAM) &pt ); + + hwndText = GetDlgItem(hDlg, OPT_CommentText); // cloned from above + len = GetWindowTextLength(hwndText); + str = (char *) malloc(len + 1); + GetWindowText(hwndText, str, len + 1); + ReplaceComment(commentIndex, str); + if(commentIndex != currentMove) ToNrEvent(commentIndex); + LoadVariation( index, str ); // [HGM] also does the actual moving to it, now + free(str); + + /* Zap the message for good: apparently, returning non-zero is not enough */ + lpMF->msg = WM_USER; + + return TRUE; + } + } + break; + case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); @@ -5959,6 +6359,7 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) move[0] = (char) lParam; move[1] = NULLCHAR; CenterWindowEx(hDlg, GetWindow(hDlg, GW_OWNER), 1 ); + Translate(hDlg, DLG_TypeInMove); hInput = GetDlgItem(hDlg, OPT_Move); SetWindowText(hInput, move); SetFocus(hInput); @@ -5967,7 +6368,8 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { - case IDOK: + 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 @@ -5985,7 +6387,7 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } if (gameMode != EditGame && currentMove != forwardMostMove && gameMode != Training) { - DisplayMoveError("Displayed move is not current"); + DisplayMoveError(_("Displayed move is not current")); } else { // GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); // moved upstream int ok = ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, @@ -5997,7 +6399,7 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) forwardMostMove = currentMove; UserMoveEvent(fromX, fromY, toX, toY, promoChar); } else { - DisplayMoveError("Could not parse move"); + DisplayMoveError(_("Could not parse move")); } } EndDialog(hDlg, TRUE); @@ -6051,6 +6453,7 @@ TypeInNameDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) move[0] = (char) lParam; move[1] = NULLCHAR; CenterWindowEx(hDlg, GetWindow(hDlg, GW_OWNER), 1 ); + Translate(hDlg, DLG_TypeInName); hInput = GetDlgItem(hDlg, OPT_Name); SetWindowText(hInput, move); SetFocus(hInput); @@ -6063,6 +6466,12 @@ TypeInNameDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) GetDlgItemText(hDlg, OPT_Name, move, sizeof(move)); appData.userName = strdup(move); SetUserLogo(); + SetGameInfo(); + if(gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack) { + snprintf(move, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black); + DisplayTitle(move); + } + EndDialog(hDlg, TRUE); return TRUE; @@ -6167,6 +6576,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) For now, just give it a default position. */ SetWindowPos(hDlg, NULL, boardRect.left+8, boardRect.top+8, 0, 0, SWP_NOZORDER|SWP_NOSIZE); + Translate(hDlg, DLG_Error); errorDialog = hDlg; SetWindowText(hDlg, errorTitle); @@ -6389,12 +6799,12 @@ CommandX(HWND hwnd, char *command, BOOLEAN getname, BOOLEAN immediate) SendMessage(hwnd, EM_GETSELTEXT, 0, (LPARAM) name); } if (immediate) { - sprintf(buf, "%s %s", command, name); + snprintf(buf, MSG_SIZ, "%s %s", command, name); SetWindowText(hInput, buf); SendMessage(hInput, WM_CHAR, '\r', 0); } else { if(!strcmp(command, "chat")) { ChatPopUp(name); return; } - sprintf(buf, "%s %s ", command, name); /* trailing space */ + snprintf(buf, MSG_SIZ, "%s %s ", command, name); /* trailing space */ SetWindowText(hInput, buf); sel.cpMin = 999999; sel.cpMax = 999999; @@ -6960,7 +7370,8 @@ DisplayHoldingsCount(HDC hdc, int x, int y, int rightAlign, int copyNumber) HFONT oldFont; RECT rect; - if(copyNumber > 1) sprintf(buf, "%d", copyNumber); else buf[0] = 0; + if(copyNumber > 1) + snprintf(buf, sizeof(buf)/sizeof(buf[0]),"%d", copyNumber); else buf[0] = 0; oldFg = SetTextColor(hdc, RGB(255, 255, 255)); /* white */ oldBg = SetBkColor(hdc, RGB(0, 0, 0)); /* black */ @@ -6993,9 +7404,9 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight, if (appData.clockMode) { if (tinyLayout) - sprintf(buf, "%c %s %s", color[0], TimeString(timeRemaining), flagFell); + snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%c %s %s", color[0], TimeString(timeRemaining), flagFell); else - sprintf(buf, "%s:%c%s %s", color, (logoHeight>0 ? 0 : ' '), TimeString(timeRemaining), flagFell); + snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%s:%c%s %s", color, (logoHeight>0 ? 0 : ' '), TimeString(timeRemaining), flagFell); str = buf; } else { str = color; @@ -7017,7 +7428,7 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight, rect, str, strlen(str), NULL); if(logoHeight > 0 && appData.clockMode) { RECT r; - sprintf(buf, "%s %s", buf+7, flagFell); + snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%s %s", buf+7, flagFell); r.top = rect->top + logoHeight/2; r.left = rect->left; r.right = rect->right; @@ -7296,6 +7707,7 @@ GreyRevert(Boolean grey) { // [HGM] vari: for retracting variations in local mode HMENU hmenu = GetMenu(hwndMain); EnableMenuItem(hmenu, IDM_Revert, MF_BYCOMMAND|(grey ? MF_GRAYED : MF_ENABLED)); + EnableMenuItem(hmenu, IDM_Annotate, MF_BYCOMMAND|(grey ? MF_GRAYED : MF_ENABLED)); } VOID @@ -7319,6 +7731,7 @@ Enables gnuEnables[] = { { IDM_StopObserving, MF_BYCOMMAND|MF_GRAYED }, { IDM_Upload, MF_BYCOMMAND|MF_GRAYED }, { IDM_Revert, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Annotate, MF_BYCOMMAND|MF_GRAYED }, { IDM_NewChat, MF_BYCOMMAND|MF_GRAYED }, { -1, -1 } }; @@ -7329,6 +7742,7 @@ Enables icsEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_GRAYED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_GRAYED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Match, MF_BYCOMMAND|MF_GRAYED }, { IDM_MachineBoth, MF_BYCOMMAND|MF_GRAYED }, { IDM_AnalysisMode, MF_BYCOMMAND|MF_ENABLED }, { IDM_AnalyzeFile, MF_BYCOMMAND|MF_GRAYED }, @@ -7339,10 +7753,11 @@ Enables icsEnables[] = { { IDM_IcsOptions, MF_BYCOMMAND|MF_ENABLED }, { IDM_Engine1Options, MF_BYCOMMAND|MF_GRAYED }, { IDM_Engine2Options, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Annotate, MF_BYCOMMAND|MF_GRAYED }, { -1, -1 } }; -#ifdef ZIPPY +#if ZIPPY Enables zippyEnables[] = { { IDM_MoveNow, MF_BYCOMMAND|MF_ENABLED }, { IDM_Hint, MF_BYCOMMAND|MF_ENABLED }, @@ -7358,11 +7773,13 @@ Enables ncpEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_GRAYED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_GRAYED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Match, MF_BYCOMMAND|MF_GRAYED }, { IDM_AnalysisMode, MF_BYCOMMAND|MF_GRAYED }, { IDM_AnalyzeFile, MF_BYCOMMAND|MF_GRAYED }, { IDM_IcsClient, MF_BYCOMMAND|MF_GRAYED }, { ACTION_POS, MF_BYPOSITION|MF_GRAYED }, { IDM_Revert, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Annotate, MF_BYCOMMAND|MF_GRAYED }, { IDM_MoveNow, MF_BYCOMMAND|MF_GRAYED }, { IDM_RetractMove, MF_BYCOMMAND|MF_GRAYED }, { IDM_TimeControl, MF_BYCOMMAND|MF_GRAYED }, @@ -7425,6 +7842,7 @@ Enables machineThinkingEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_GRAYED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_GRAYED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_GRAYED }, + { IDM_Match, MF_BYCOMMAND|MF_GRAYED }, { IDM_TypeInMove, MF_BYCOMMAND|MF_GRAYED }, { IDM_RetractMove, MF_BYCOMMAND|MF_GRAYED }, { -1, -1 } @@ -7444,6 +7862,7 @@ Enables userThinkingEnables[] = { { IDM_MachineWhite, MF_BYCOMMAND|MF_ENABLED }, { IDM_MachineBlack, MF_BYCOMMAND|MF_ENABLED }, { IDM_TwoMachines, MF_BYCOMMAND|MF_ENABLED }, + { IDM_Match, MF_BYCOMMAND|MF_ENABLED }, { IDM_TypeInMove, MF_BYCOMMAND|MF_ENABLED }, { IDM_RetractMove, MF_BYCOMMAND|MF_ENABLED }, { -1, -1 } @@ -7485,7 +7904,7 @@ ModeHighlight() nowChecked = IDM_MachineWhite; break; case TwoMachinesPlay: - nowChecked = IDM_TwoMachines; + nowChecked = matchMode ? IDM_Match : IDM_TwoMachines; // [HGM] match break; case AnalyzeMode: nowChecked = IDM_AnalysisMode; @@ -7552,7 +7971,7 @@ SetICSMode() SetMenuEnables(hmenu, icsEnables); EnableMenuItem(GetSubMenu(hmenu, OPTIONS_POS), ICS_POS, MF_BYPOSITION|MF_ENABLED); -#ifdef ZIPPY +#if ZIPPY if (appData.zippyPlay) { SetMenuEnables(hmenu, zippyEnables); if (!appData.noChessProgram) /* [DM] icsEngineAnalyze */ @@ -7626,7 +8045,7 @@ SetMachineThinkingEnables() } else if (gameMode == MachinePlaysWhite) { (void)EnableMenuItem(hMenu, IDM_MachineWhite, flags); } else if (gameMode == TwoMachinesPlay) { - (void)EnableMenuItem(hMenu, IDM_TwoMachines, flags); + (void)EnableMenuItem(hMenu, matchMode ? IDM_Match : IDM_TwoMachines, flags); // [HGM] match } } @@ -7636,17 +8055,17 @@ DisplayTitle(char *str) { char title[MSG_SIZ], *host; if (str[0] != NULLCHAR) { - strcpy(title, str); + safeStrCpy(title, str, sizeof(title)/sizeof(title[0]) ); } else if (appData.icsActive) { if (appData.icsCommPort[0] != NULLCHAR) host = "ICS"; else host = appData.icsHost; - sprintf(title, "%s: %s", szTitle, host); + snprintf(title, MSG_SIZ, "%s: %s", szTitle, host); } else if (appData.noChessProgram) { - strcpy(title, szTitle); + safeStrCpy(title, szTitle, sizeof(title)/sizeof(title[0]) ); } else { - strcpy(title, szTitle); + safeStrCpy(title, szTitle, sizeof(title)/sizeof(title[0]) ); strcat(title, ": "); strcat(title, first.tidy); } @@ -7701,25 +8120,25 @@ DisplayError(char *str, int error) int len; if (error == 0) { - strcpy(buf, str); + safeStrCpy(buf, str, sizeof(buf)/sizeof(buf[0]) ); } else { len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, LANG_NEUTRAL, (LPSTR) buf2, MSG_SIZ, NULL); if (len > 0) { - sprintf(buf, "%s:\n%s", str, buf2); + snprintf(buf, 2*MSG_SIZ, "%s:\n%s", str, buf2); } else { ErrorMap *em = errmap; while (em->err != 0 && em->err != error) em++; if (em->err != 0) { - sprintf(buf, "%s:\n%s", str, em->msg); + snprintf(buf, 2*MSG_SIZ, "%s:\n%s", str, em->msg); } else { - sprintf(buf, "%s:\nError code %d", str, error); + snprintf(buf, 2*MSG_SIZ, "%s:\nError code %d", str, error); } } } - ErrorPopUp("Error", buf); + ErrorPopUp(_("Error"), buf); } @@ -7730,7 +8149,7 @@ DisplayMoveError(char *str) ClearHighlights(); DrawPosition(FALSE, NULL); if (appData.popupMoveErrors) { - ErrorPopUp("Error", str); + ErrorPopUp(_("Error"), str); } else { DisplayMessage(str, ""); moveErrorMessageUp = TRUE; @@ -7742,21 +8161,21 @@ DisplayFatalError(char *str, int error, int exitStatus) { char buf[2*MSG_SIZ], buf2[MSG_SIZ]; int len; - char *label = exitStatus ? "Fatal Error" : "Exiting"; + char *label = exitStatus ? _("Fatal Error") : _("Exiting"); if (error != 0) { len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, LANG_NEUTRAL, (LPSTR) buf2, MSG_SIZ, NULL); if (len > 0) { - sprintf(buf, "%s:\n%s", str, buf2); + snprintf(buf, 2*MSG_SIZ, "%s:\n%s", str, buf2); } else { ErrorMap *em = errmap; while (em->err != 0 && em->err != error) em++; if (em->err != 0) { - sprintf(buf, "%s:\n%s", str, em->msg); + snprintf(buf, 2*MSG_SIZ, "%s:\n%s", str, em->msg); } else { - sprintf(buf, "%s:\nError code %d", str, error); + snprintf(buf, 2*MSG_SIZ, "%s:\nError code %d", str, error); } } str = buf; @@ -7775,14 +8194,14 @@ DisplayFatalError(char *str, int error, int exitStatus) VOID DisplayInformation(char *str) { - (void) MessageBox(hwndMain, str, "Information", MB_OK|MB_ICONINFORMATION); + (void) MessageBox(hwndMain, str, _("Information"), MB_OK|MB_ICONINFORMATION); } VOID DisplayNote(char *str) { - ErrorPopUp("Note", str); + ErrorPopUp(_("Note"), str); } @@ -7802,6 +8221,7 @@ QuestionDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_INITDIALOG: qp = (QuestionParams *) lParam; CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); + Translate(hDlg, DLG_Question); SetWindowText(hDlg, qp->title); SetDlgItemText(hDlg, OPT_QuestionText, qp->question); SetFocus(GetDlgItem(hDlg, OPT_QuestionInput)); @@ -7810,14 +8230,14 @@ QuestionDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: - strcpy(reply, qp->replyPrefix); + safeStrCpy(reply, qp->replyPrefix, sizeof(reply)/sizeof(reply[0]) ); if (*reply) strcat(reply, " "); len = strlen(reply); GetDlgItemText(hDlg, OPT_QuestionInput, reply + len, sizeof(reply) - len); strcat(reply, "\n"); OutputToProcess(qp->pr, reply, strlen(reply), &err); EndDialog(hDlg, TRUE); - if (err) DisplayFatalError("Error writing to chess program", err, 1); + if (err) DisplayFatalError(_("Error writing to chess program"), err, 1); return TRUE; case IDCANCEL: EndDialog(hDlg, FALSE); @@ -7859,6 +8279,7 @@ LRESULT CALLBACK NewGameFRC_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lpIndexFRC = (int *) lParam; CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); + Translate(hDlg, DLG_NewGameFRC); SendDlgItemMessage( hDlg, IDC_NFG_Edit, EM_SETLIMITTEXT, sizeof(buf)-1, 0 ); SetDlgItemInt( hDlg, IDC_NFG_Edit, *lpIndexFRC, TRUE ); @@ -7885,7 +8306,7 @@ LRESULT CALLBACK NewGameFRC_Proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM } return TRUE; case IDC_NFG_Random: - sprintf( buf, "%d", myrandom() ); /* [HGM] shuffle: no longer limit to 960 */ + snprintf( buf, sizeof(buf)/sizeof(buf[0]), "%d", myrandom() ); /* [HGM] shuffle: no longer limit to 960 */ SetDlgItemText(hDlg, IDC_NFG_Edit, buf ); return TRUE; } @@ -7973,6 +8394,7 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP gameListOptionsDialog = hDlg; // [HGM] pass through global to keep out off back-end CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); + Translate(hDlg, DLG_GameListOptions); /* Initialize list */ GLT_TagsToList( lpUserGLT ); @@ -8019,7 +8441,7 @@ int GameListOptions() int result; FARPROC lpProc = MakeProcInstance( (FARPROC) GameListOptions_Proc, hInst ); - strcpy( lpUserGLT, appData.gameListTags ); + safeStrCpy( lpUserGLT, appData.gameListTags ,LPUSERGLT_SIZE ); result = DialogBoxParam( hInst, MAKEINTRESOURCE(DLG_GameListOptions), hwndMain, (DLGPROC)lpProc, (LPARAM)lpUserGLT ); @@ -8036,7 +8458,7 @@ DisplayIcsInteractionTitle(char *str) { char consoleTitle[MSG_SIZ]; - sprintf(consoleTitle, "%s: %s", szConsoleTitle, str); + snprintf(consoleTitle, MSG_SIZ, "%s: %s", szConsoleTitle, str); SetWindowText(hwndConsole, consoleTitle); } @@ -8065,6 +8487,7 @@ ResetFrontEnd() ReleaseCapture(); DrawPosition(TRUE, NULL); } + TagsPopDown(); } @@ -8072,7 +8495,7 @@ VOID CommentPopUp(char *title, char *str) { HWND hwnd = GetActiveWindow(); - EitherCommentPopUp(0, title, str, FALSE); + EitherCommentPopUp(currentMove, title, str, FALSE); // [HGM] vari: fake move index, rather than 0 SAY(str); SetActiveWindow(hwnd); } @@ -8174,7 +8597,7 @@ UserName() } if (!GetUserName(buf, &bufsiz)) { /*DisplayError("Error getting user name", GetLastError());*/ - strcpy(buf, "User"); + safeStrCpy(buf, _("User"), sizeof(buf)/sizeof(buf[0]) ); } return buf; } @@ -8187,7 +8610,7 @@ HostName() if (!GetComputerName(buf, &bufsiz)) { /*DisplayError("Error getting host name", GetLastError());*/ - strcpy(buf, "Unknown"); + safeStrCpy(buf, _("Unknown"), sizeof(buf)/sizeof(buf[0]) ); } return buf; } @@ -8225,7 +8648,7 @@ DisplayWhiteClock(long timeRemaining, int highlight) hdc = GetDC(hwndMain); if (!IsIconic(hwndMain)) { DisplayAClock(hdc, timeRemaining, highlight, - flipClock ? &blackRect : &whiteRect, "White", flag); + flipClock ? &blackRect : &whiteRect, _("White"), flag); } if (highlight && iconCurrent == iconBlack) { iconCurrent = iconWhite; @@ -8249,7 +8672,7 @@ DisplayBlackClock(long timeRemaining, int highlight) hdc = GetDC(hwndMain); if (!IsIconic(hwndMain)) { DisplayAClock(hdc, timeRemaining, highlight, - flipClock ? &whiteRect : &blackRect, "Black", flag); + flipClock ? &whiteRect : &blackRect, _("Black"), flag); } if (highlight && iconCurrent == iconWhite) { iconCurrent = iconBlack; @@ -8297,7 +8720,7 @@ AutoSaveGame() f = OpenFileDialog(hwndMain, "a", defName, appData.oldSaveStyle ? "gam" : "pgn", GAME_FILT, - "Save Game to File", NULL, fileTitle, NULL); + _("Save Game to File"), NULL, fileTitle, NULL); if (f != NULL) { SaveGame(f, 0, ""); fclose(f); @@ -8601,9 +9024,9 @@ OpenTelnet(char *host, char *port, ProcRef *pr) char cmdLine[MSG_SIZ]; if (port[0] == NULLCHAR) { - sprintf(cmdLine, "%s %s", appData.telnetProgram, host); + snprintf(cmdLine, MSG_SIZ, "%s %s", appData.telnetProgram, host); } else { - sprintf(cmdLine, "%s %s %s", appData.telnetProgram, host, port); + snprintf(cmdLine, MSG_SIZ, "%s %s %s", appData.telnetProgram, host, port); } return StartChildProcess(cmdLine, "", pr); } @@ -8702,9 +9125,9 @@ OpenCommPort(char *name, ProcRef *pr) char fullname[MSG_SIZ]; if (*name != '\\') - sprintf(fullname, "\\\\.\\%s", name); + snprintf(fullname, MSG_SIZ, "\\\\.\\%s", name); else - strcpy(fullname, name); + safeStrCpy(fullname, name, sizeof(fullname)/sizeof(fullname[0]) ); h = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); @@ -8736,7 +9159,7 @@ OpenCommPort(char *name, ProcRef *pr) int OpenLoopback(ProcRef *pr) { - DisplayFatalError("Not implemented", 0, 1); + DisplayFatalError(_("Not implemented"), 0, 1); return NO_ERROR; } @@ -8874,7 +9297,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr) break; } prevStderrPort = fromPort; // remember port used - sprintf(stderrPortStr, "%d", fromPort); + snprintf(stderrPortStr, MSG_SIZ, "%d", fromPort); if (send(s, stderrPortStr, strlen(stderrPortStr) + 1, 0) == SOCKET_ERROR) { err = WSAGetLastError(); @@ -9106,7 +9529,7 @@ void CmailSigHandlerCallBack(InputSourceRef isr, VOIDSTAR closure, char *buf, int count, int error) { - DisplayFatalError("Not implemented", 0, 1); + DisplayFatalError(_("Not implemented"), 0, 1); } /* see wgamelist.c for Game List functions */ @@ -9194,26 +9617,26 @@ static void Tween( POINT * start, POINT * mid, POINT * finish, int factor, POINT frames[], int * nFrames); +#define kFactor 4 + void -AnimateAtomicCapture(int fromX, int fromY, int toX, int toY, int nFrames) +AnimateAtomicCapture(Board board, int fromX, int fromY, int toX, int toY) { // [HGM] atomic: animate blast wave int i; -if(appData.debugMode) fprintf(debugFP, "exploding (%d,%d)\n", toX, toY); + explodeInfo.fromX = fromX; explodeInfo.fromY = fromY; explodeInfo.toX = toX; explodeInfo.toY = toY; - for(i=1; i