/winboard/winboard.c
C | 1811 lines | 1509 code | 172 blank | 130 comment | 237 complexity | fcca44cd368835cd3a7213560b114829 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception
Large files files are truncated, but you can click here to view the full file
- /*
- * WinBoard.c -- Windows NT front end to XBoard
- *
- * Copyright 1991 by Digital Equipment Corporation, Maynard,
- * Massachusetts.
- *
- * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
- *
- * Enhancements Copyright 2005 Alessandro Scotti
- *
- * XBoard borrows its colors and the bitmaps.xchess bitmap set from XChess,
- * which was written and is copyrighted by Wayne Christopher.
- *
- * The following terms apply to Digital Equipment Corporation's copyright
- * interest in XBoard:
- * ------------------------------------------------------------------------
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of Digital not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- * ------------------------------------------------------------------------
- *
- * The following terms apply to the enhanced version of XBoard
- * distributed by the Free Software Foundation:
- * ------------------------------------------------------------------------
- *
- * 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 3 of the License, or (at
- * your option) any later version.
- *
- * 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, see http://www.gnu.org/licenses/. *
- *
- *------------------------------------------------------------------------
- ** See the file ChangeLog for a revision history. */
-
- #include "config.h"
-
- #include <windows.h>
- #include <winuser.h>
- #include <winsock.h>
- #include <commctrl.h>
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <malloc.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <math.h>
- #include <commdlg.h>
- #include <dlgs.h>
- #include <richedit.h>
- #include <mmsystem.h>
- #include <ctype.h>
- #include <io.h>
-
- #if __GNUC__
- #include <errno.h>
- #include <string.h>
- #endif
-
- #include "common.h"
- #include "frontend.h"
- #include "backend.h"
- #include "winboard.h"
- #include "moves.h"
- #include "wclipbrd.h"
- #include "woptions.h"
- #include "wsockerr.h"
- #include "defaults.h"
- #include "help.h"
- #include "wsnap.h"
-
- //void InitEngineUCI( const char * iniDir, ChessProgramState * cps );
-
- int myrandom(void);
- void mysrandom(unsigned int seed);
-
- extern int whiteFlag, blackFlag;
- Boolean flipClock = FALSE;
- extern HANDLE chatHandle[];
- extern int ics_type;
-
- int MySearchPath P((char *installDir, char *name, char *fullname));
- int MyGetFullPathName P((char *name, char *fullname));
- 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 DisplayMove P((int moveNumber));
- Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen));
- void ChatPopUp P((char *s));
- typedef struct {
- ChessSquare piece;
- 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 */
- POINT to; /* board coordinates of the piece's new pos */
- } AnimInfo;
-
- static AnimInfo animInfo = { EmptySquare, {-1,-1}, {-1,-1}, {-1,-1} };
-
- typedef struct {
- POINT start; /* window coordinates of start pos */
- 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}, EmptySquare };
-
- typedef struct {
- POINT sq[2]; /* board coordinates of from, to squares */
- } HighlightInfo;
-
- 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;
- } ExplodeInfo;
-
- static ExplodeInfo explodeInfo;
-
- /* Window class names */
- char szAppName[] = "WinBoard";
- char szConsoleName[] = "WBConsole";
-
- /* Title bar text */
- char szTitle[] = "WinBoard";
- char szConsoleTitle[] = "I C S Interaction";
-
- char *programName;
- char *settingsFileName;
- Boolean saveSettingsOnExit;
- char installDir[MSG_SIZ];
- int errorExitStatus;
-
- BoardSize boardSize;
- Boolean chessProgram;
- //static int boardX, boardY;
- int minX, minY; // [HGM] placement: volatile limits on upper-left corner
- int squareSize, lineGap, minorSize;
- static int winW, winH;
- static RECT messageRect, whiteRect, blackRect, leftLogoRect, rightLogoRect; // [HGM] logo
- static int logoHeight = 0;
- static char messageText[MESSAGE_TEXT_MAX];
- static int clockTimerEvent = 0;
- static int loadGameTimerEvent = 0;
- static int analysisTimerEvent = 0;
- static DelayedEventCallback delayedTimerCallback;
- static int delayedTimerEvent = 0;
- static int buttonCount = 2;
- char *icsTextMenuString;
- char *icsNames;
- char *firstChessProgramNames;
- char *secondChessProgramNames;
-
- #define PALETTESIZE 256
-
- HINSTANCE hInst; /* current instance */
- Boolean alwaysOnTop = FALSE;
- RECT boardRect;
- COLORREF lightSquareColor, darkSquareColor, whitePieceColor,
- blackPieceColor, highlightSquareColor, premoveHighlightColor;
- HPALETTE hPal;
- ColorClass currentColorClass;
-
- static HWND savedHwnd;
- HWND hCommPort = NULL; /* currently open comm port */
- 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 */
- explodeBrush, /* [HGM] atomic */
- markerBrush, /* [HGM] markers */
- whitePieceBrush, blackPieceBrush, iconBkgndBrush /*, outlineBrush*/;
- static POINT gridEndpoints[(BOARD_RANKS + BOARD_FILES + 2) * 2];
- static DWORD gridVertexCounts[BOARD_RANKS + BOARD_FILES + 2];
- static HPEN gridPen = NULL;
- static HPEN highlightPen = NULL;
- static HPEN premovePen = NULL;
- static NPLOGPALETTE pLogPal;
- static BOOL paletteChanged = FALSE;
- static HICON iconWhite, iconBlack, iconCurrent;
- static int doingSizing = FALSE;
- static int lastSizing = 0;
- static int prevStderrPort;
- static HBITMAP userLogo;
-
- static HBITMAP liteBackTexture = NULL;
- static HBITMAP darkBackTexture = NULL;
- static int liteBackTextureMode = BACK_TEXTURE_MODE_PLAIN;
- static int darkBackTextureMode = BACK_TEXTURE_MODE_PLAIN;
- static int backTextureSquareSize = 0;
- static struct { int x; int y; int mode; } backTextureSquareInfo[BOARD_RANKS][BOARD_FILES];
-
- #if __GNUC__ && !defined(_winmajor)
- #define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */
- #else
- #if defined(_winmajor)
- #define oldDialog (_winmajor < 4)
- #else
- #define oldDialog 0
- #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[][42] = {
- { ABOUTBOX, IDOK, OPT_MESS, 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, OPT_Exact, OPT_Subset, OPT_Struct, OPT_Material, OPT_Range, OPT_Difference,
- OPT_elo1t, OPT_elo2t, OPT_datet, OPT_Stretch, OPT_Stretcht, OPT_Reversed, OPT_SearchMode, OPT_Mirror, OPT_thresholds, 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 ,OPT_SmartMove },
- { 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, OPT_Bitmaps, OPT_PieceFont, OPT_Grid },
- { 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_VariantSChess,
- 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_ChoosePieceFont, OPT_MessageFont8,
- OPT_SampleGameListFont, OPT_ChooseGameListFont, OPT_MessageFont7,
- 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[70000], *foreign[1000], *english[1000], *languageFile[MSG_SIZ];
- static int lastChecked;
- static char oldLanguage[MSG_SIZ], *menuText[10][30];
- extern int tinyLayout;
- extern char * menuBarText[][10];
-
- 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
- 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) {
- 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;
- static char buf[MSG_SIZ];
- //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];
- if(english[i][0] == '%' && strstr(s, english[i]+1) == s) { // allow translation of strings with variable ending
- snprintf(buf, MSG_SIZ, "%s%s", foreign[i], s + strlen(english[i]+1)); // keep unmatched portion
- return buf;
- }
- 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(!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(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)
- }
- }
-
- HMENU
- TranslateOneMenu(int i, HMENU subMenu)
- {
- int j;
- static MENUITEMINFO info;
-
- info.cbSize = sizeof(MENUITEMINFO);
- info.fMask = MIIM_STATE | MIIM_TYPE;
- for(j=GetMenuItemCount(subMenu)-1; j>=0; j--){
- char buf[MSG_SIZ];
- info.dwTypeData = buf;
- info.cch = sizeof(buf);
- GetMenuItemInfo(subMenu, j, TRUE, &info);
- if(i < 10) {
- if(menuText[i][j]) safeStrCpy(buf, menuText[i][j], sizeof(buf)/sizeof(buf[0]) );
- else menuText[i][j] = strdup(buf); // remember original on first change
- }
- if(buf[0] == NULLCHAR) continue;
- info.dwTypeData = T_(buf);
- info.cch = strlen(buf)+1;
- SetMenuItemInfo(subMenu, j, TRUE, &info);
- }
- return subMenu;
- }
-
- void
- TranslateMenus(int addLanguage)
- {
- int i;
- WIN32_FIND_DATA fileData;
- HANDLE hFind;
- #define IDM_English 1970
- 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]));
- TranslateOneMenu(i, subMenu);
- }
- 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
-
- #define IDM_RecentEngines 3000
-
- void
- RecentEngineMenu (char *s)
- {
- if(appData.icsActive) return;
- if(appData.recentEngines > 0 && *s) { // feature is on, and list non-empty
- HMENU mainMenu = GetMenu(hwndMain);
- HMENU subMenu = GetSubMenu(mainMenu, 5); // Engine menu
- int i=IDM_RecentEngines;
- recentEngines = strdup(appData.recentEngineList); // remember them as they are in menu
- AppendMenu(subMenu, MF_SEPARATOR, (UINT_PTR) 0, NULL);
- while(*s) {
- char *p = strchr(s, '\n');
- if(p == NULL) return; // malformed!
- *p = NULLCHAR;
- AppendMenu(subMenu, MF_ENABLED|MF_STRING|MF_UNCHECKED, (UINT_PTR) i++, (LPCTSTR) s);
- *p = '\n';
- s = p+1;
- }
- }
- }
-
-
- typedef struct {
- char *name;
- int squareSize;
- int lineGap;
- int smallLayout;
- int tinyLayout;
- int cliWidth, cliHeight;
- } SizeInfo;
-
- SizeInfo sizeInfo[] =
- {
- { "tiny", 21, 0, 1, 1, 0, 0 },
- { "teeny", 25, 1, 1, 1, 0, 0 },
- { "dinky", 29, 1, 1, 1, 0, 0 },
- { "petite", 33, 1, 1, 1, 0, 0 },
- { "slim", 37, 2, 1, 0, 0, 0 },
- { "small", 40, 2, 1, 0, 0, 0 },
- { "mediocre", 45, 2, 1, 0, 0, 0 },
- { "middling", 49, 2, 0, 0, 0, 0 },
- { "average", 54, 2, 0, 0, 0, 0 },
- { "moderate", 58, 3, 0, 0, 0, 0 },
- { "medium", 64, 3, 0, 0, 0, 0 },
- { "bulky", 72, 3, 0, 0, 0, 0 },
- { "large", 80, 3, 0, 0, 0, 0 },
- { "big", 87, 3, 0, 0, 0, 0 },
- { "huge", 95, 3, 0, 0, 0, 0 },
- { "giant", 108, 3, 0, 0, 0, 0 },
- { "colossal", 116, 4, 0, 0, 0, 0 },
- { "titanic", 129, 4, 0, 0, 0, 0 },
- { NULL, 0, 0, 0, 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), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_TEENY), MF(MESSAGE_FONT_TEENY), MF(COORD_FONT_TEENY), MF(CONSOLE_FONT_TEENY), MF(COMMENT_FONT_TEENY), MF(EDITTAGS_FONT_TEENY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_DINKY), MF(MESSAGE_FONT_DINKY), MF(COORD_FONT_DINKY), MF(CONSOLE_FONT_DINKY), MF(COMMENT_FONT_DINKY), MF(EDITTAGS_FONT_DINKY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_PETITE), MF(MESSAGE_FONT_PETITE), MF(COORD_FONT_PETITE), MF(CONSOLE_FONT_PETITE), MF(COMMENT_FONT_PETITE), MF(EDITTAGS_FONT_PETITE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_SLIM), MF(MESSAGE_FONT_SLIM), MF(COORD_FONT_SLIM), MF(CONSOLE_FONT_SLIM), MF(COMMENT_FONT_SLIM), MF(EDITTAGS_FONT_SLIM), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_SMALL), MF(MESSAGE_FONT_SMALL), MF(COORD_FONT_SMALL), MF(CONSOLE_FONT_SMALL), MF(COMMENT_FONT_SMALL), MF(EDITTAGS_FONT_SMALL), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_MEDIOCRE), MF(MESSAGE_FONT_MEDIOCRE), MF(COORD_FONT_MEDIOCRE), MF(CONSOLE_FONT_MEDIOCRE), MF(COMMENT_FONT_MEDIOCRE), MF(EDITTAGS_FONT_MEDIOCRE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_MIDDLING), MF(MESSAGE_FONT_MIDDLING), MF(COORD_FONT_MIDDLING), MF(CONSOLE_FONT_MIDDLING), MF(COMMENT_FONT_MIDDLING), MF(EDITTAGS_FONT_MIDDLING), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_AVERAGE), MF(MESSAGE_FONT_AVERAGE), MF(COORD_FONT_AVERAGE), MF(CONSOLE_FONT_AVERAGE), MF(COMMENT_FONT_AVERAGE), MF(EDITTAGS_FONT_AVERAGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_MODERATE), MF(MESSAGE_FONT_MODERATE), MF(COORD_FONT_MODERATE), MF(CONSOLE_FONT_MODERATE), MF(COMMENT_FONT_MODERATE), MF(EDITTAGS_FONT_MODERATE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_MEDIUM), MF(MESSAGE_FONT_MEDIUM), MF(COORD_FONT_MEDIUM), MF(CONSOLE_FONT_MEDIUM), MF(COMMENT_FONT_MEDIUM), MF(EDITTAGS_FONT_MEDIUM), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_BULKY), MF(MESSAGE_FONT_BULKY), MF(COORD_FONT_BULKY), MF(CONSOLE_FONT_BULKY), MF(COMMENT_FONT_BULKY), MF(EDITTAGS_FONT_BULKY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_LARGE), MF(MESSAGE_FONT_LARGE), MF(COORD_FONT_LARGE), MF(CONSOLE_FONT_LARGE), MF(COMMENT_FONT_LARGE), MF(EDITTAGS_FONT_LARGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_BIG), MF(MESSAGE_FONT_BIG), MF(COORD_FONT_BIG), MF(CONSOLE_FONT_BIG), MF(COMMENT_FONT_BIG), MF(EDITTAGS_FONT_BIG), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_HUGE), MF(MESSAGE_FONT_HUGE), MF(COORD_FONT_HUGE), MF(CONSOLE_FONT_HUGE), MF(COMMENT_FONT_HUGE), MF(EDITTAGS_FONT_HUGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_GIANT), MF(MESSAGE_FONT_GIANT), MF(COORD_FONT_GIANT), MF(CONSOLE_FONT_GIANT), MF(COMMENT_FONT_GIANT), MF(EDITTAGS_FONT_GIANT), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_COLOSSAL), MF(MESSAGE_FONT_COLOSSAL), MF(COORD_FONT_COLOSSAL), MF(CONSOLE_FONT_COLOSSAL), MF(COMMENT_FONT_COLOSSAL), MF(EDITTAGS_FONT_COLOSSAL), MF(MOVEHISTORY_FONT_ALL), MF (GAMELIST_FONT_ALL) },
- { MF(CLOCK_FONT_TITANIC), MF(MESSAGE_FONT_TITANIC), MF(COORD_FONT_TITANIC), MF(CONSOLE_FONT_TITANIC), MF(COMMENT_FONT_TITANIC), MF(EDITTAGS_FONT_TITANIC), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) },
- };
-
- MyFont *font[NUM_SIZES][NUM_FONTS];
-
- typedef struct {
- char *label;
- int id;
- HWND hwnd;
- WNDPROC wndproc;
- } MyButtonDesc;
-
- #define BUTTON_WIDTH (tinyLayout ? 16 : 32)
- #define N_BUTTONS 5
-
- MyButtonDesc buttonDesc[N_BUTTONS] =
- {
- {"<<", IDM_ToStart, NULL, NULL},
- {"<", IDM_Backward, NULL, NULL},
- {"P", IDM_Pause, NULL, NULL},
- {">", IDM_Forward, NULL, NULL},
- {">>", IDM_ToEnd, NULL, NULL},
- };
-
- int tinyLayout = 0, smallLayout = 0;
- #define MENU_BAR_ITEMS 9
- char *menuBarText[2][MENU_BAR_ITEMS+1] = {
- { N_("&File"), N_("&Edit"), N_("&View"), N_("&Mode"), N_("&Action"), N_("E&ngine"), N_("&Options"), N_("&Help"), NULL },
- { N_("&F"), N_("&E"), N_("&V"), N_("&M"), N_("&A"), N_("&N"), N_("&O"), N_("&H"), NULL },
- };
-
-
- MySound sounds[(int)NSoundClasses];
- MyTextAttribs textAttribs[(int)NColorClasses];
-
- MyColorizeAttribs colorizeAttribs[] = {
- { (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") }
- };
-
-
-
- static char *commentTitle;
- static char *commentText;
- static int commentIndex;
- static Boolean editComment = FALSE;
-
-
- char errorTitle[MSG_SIZ];
- char errorMessage[2*MSG_SIZ];
- HWND errorDialog = NULL;
- BOOLEAN moveErrorMessageUp = FALSE;
- BOOLEAN consoleEcho = TRUE;
- CHARFORMAT consoleCF;
- COLORREF consoleBackgroundColor;
-
- char *programVersion;
-
- #define CPReal 1
- #define CPComm 2
- #define CPSock 3
- #define CPRcmd 4
- typedef int CPKind;
-
- typedef struct {
- CPKind kind;
- HANDLE hProcess;
- DWORD pid;
- HANDLE hTo;
- HANDLE hFrom;
- SOCKET sock;
- SOCKET sock2; /* stderr socket for OpenRcmd */
- } ChildProc;
-
- #define INPUT_SOURCE_BUF_SIZE 4096
-
- typedef struct _InputSource {
- CPKind kind;
- HANDLE hFile;
- SOCKET sock;
- int lineByLine;
- HANDLE hThread;
- DWORD id;
- char buf[INPUT_SOURCE_BUF_SIZE];
- char *next;
- DWORD count;
- int error;
- InputCallback func;
- struct _InputSource *second; /* for stderr thread on CPRcmd */
- VOIDSTAR closure;
- } InputSource;
-
- InputSource *consoleInputSource;
-
- DCB dcb;
-
- /* forward */
- VOID ConsoleOutput(char* data, int length, int forceVisible);
- VOID ConsoleCreate();
- LRESULT CALLBACK
- ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
- VOID ColorizeTextPopup(HWND hwnd, ColorClass cc);
- VOID PrintCommSettings(FILE *f, char *name, DCB *dcb);
- VOID ParseCommSettings(char *arg, DCB *dcb);
- 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 PopUpNameDialog(char firstchar);
- VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca);
-
- /* [AS] */
- int NewGameFRC();
- int GameListOptions();
-
- int dummy; // [HGM] for obsolete args
-
- HWND hwndMain = NULL; /* root window*/
- HWND hwndConsole = NULL;
- HWND commentDialog = NULL;
- HWND moveHistoryDialog = NULL;
- HWND evalGraphDialog = NULL;
- HWND engineOutputDialog = NULL;
- HWND gameListDialog = NULL;
- HWND editTagsDialog = NULL;
-
- int commentUp = FALSE;
-
- WindowPlacement wpMain;
- WindowPlacement wpConsole;
- WindowPlacement wpComment;
- WindowPlacement wpMoveHistory;
- WindowPlacement wpEvalGraph;
- WindowPlacement wpEngineOutput;
- WindowPlacement wpGameList;
- WindowPlacement wpTags;
-
- VOID EngineOptionsPopup(); // [HGM] settings
-
- VOID GothicPopUp(char *title, VariantClass variant);
- /*
- * Setting "frozen" should disable all user input other than deleting
- * the window. We do this while engines are initializing themselves.
- */
- static int frozen = 0;
- static int oldMenuItemState[MENU_BAR_ITEMS];
- void FreezeUI()
- {
- HMENU hmenu;
- int i;
-
- if (frozen) return;
- frozen = 1;
- hmenu = GetMenu(hwndMain);
- for (i=0; i<MENU_BAR_ITEMS; i++) {
- oldMenuItemState[i] = EnableMenuItem(hmenu, i, MF_BYPOSITION|MF_GRAYED);
- }
- DrawMenuBar(hwndMain);
- }
-
- /* Undo a FreezeUI */
- void ThawUI()
- {
- HMENU hmenu;
- int i;
-
- if (!frozen) return;
- frozen = 0;
- hmenu = GetMenu(hwndMain);
- for (i=0; i<MENU_BAR_ITEMS; i++) {
- EnableMenuItem(hmenu, i, MF_BYPOSITION|oldMenuItemState[i]);
- }
- DrawMenuBar(hwndMain);
- }
-
- /*static*/ int fromX = -1, fromY = -1, toX, toY; // [HGM] moved upstream, so JAWS can use them
-
- /* JAWS preparation patch (WinBoard for the sight impaired). Define required insertions as empty */
- #ifdef JAWS
- #include "jaws.c"
- #else
- #define JAWS_INIT
- #define JAWS_ARGS
- #define JAWS_ALT_INTERCEPT
- #define JAWS_KBUP_NAVIGATION
- #define JAWS_KBDOWN_NAVIGATION
- #define JAWS_MENU_ITEMS
- #define JAWS_SILENCE
- #define JAWS_REPLAY
- #define JAWS_ACCEL
- #define JAWS_COPYRIGHT
- #define JAWS_DELETE(X) X
- #define SAYMACHINEMOVE()
- #define SAY(X)
- #endif
-
- /*---------------------------------------------------------------------------*\
- *
- * WinMain
- *
- \*---------------------------------------------------------------------------*/
-
- int APIENTRY
- WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS;
- // INITCOMMONCONTROLSEX ex;
-
- debugFP = stderr;
-
- LoadLibrary("RICHED32.DLL");
- consoleCF.cbSize = sizeof(CHARFORMAT);
-
- if (!InitApplication(hInstance)) {
- return (FALSE);
- }
- if (!InitInstance(hInstance, nCmdShow, lpCmdLine)) {
- return (FALSE);
- }
-
- JAWS_INIT
- TranslateMenus(1);
-
- // InitCommonControlsEx(&ex);
- InitCommonControls();
-
- hAccelMain = LoadAccelerators (hInstance, szAppName);
- hAccelNoAlt = LoadAccelerators (hInstance, "NO_ALT");
- hAccelNoICS = LoadAccelerators( hInstance, "NO_ICS"); /* [AS] No Ctrl-V on ICS!!! */
-
- /* Acquire and dispatch messages until a WM_QUIT message is received. */
-
- while (GetMessage(&msg, /* message structure */
- NULL, /* handle of window receiving the message */
- 0, /* lowest message to examine */
- 0)) /* highest message to examine */
- {
-
- if(msg.message == WM_CHAR && msg.wParam == '\t') {
- // [HGM] navigate: switch between all windows with tab
- HWND e1 = NULL, e2 = NULL, mh = NULL, hInput = NULL, hText = NULL;
- int i, currentElement = 0;
-
- // first determine what element of the chain we come from (if any)
- if(appData.icsActive) {
- hInput = GetDlgItem(hwndConsole, OPT_ConsoleInput);
- hText = GetDlgItem(hwndConsole, OPT_ConsoleText);
- }
- if(engineOutputDialog && EngineOutputIsUp()) {
- e1 = GetDlgItem(engineOutputDialog, IDC_EngineMemo1);
- e2 = GetDlgItem(engineOutputDialog, IDC_EngineMemo2);
- }
- if(moveHistoryDialog && MoveHistoryIsUp()) {
- mh = GetDlgItem(moveHistoryDialog, IDC_MoveHistory);
- }
- if(msg.hwnd == hwndMain) currentElement = 7 ; else
- if(msg.hwnd == engineOutputDialog) currentElement = 2; else
- if(msg.hwnd == e1) currentElement = 2; else
- if(msg.hwnd == e2) currentElement = 3; else
- if(msg.hwnd == moveHistoryDialog) currentElement = 4; else
- if(msg.hwnd == mh) currentElement = 4; else
- if(msg.hwnd == evalGraphDialog) currentElement = 6; else
- if(msg.hwnd == hText) currentElement = 5; else
- if(msg.hwnd == hInput) currentElement = 6; else
- for (i = 0; i < N_BUTTONS; i++) {
- if (buttonDesc[i].hwnd == msg.hwnd) { currentElement = 1; break; }
- }
-
- // determine where to go to
- if(currentElement) { HWND h = NULL; int direction = GetKeyState(VK_SHIFT) < 0 ? -1 : 1;
- do {
- currentElement = (currentElement + direction) % 7;
- switch(currentElement) {
- case 0:
- h = hwndMain; break; // passing this case always makes the loop exit
- case 1:
- h = buttonDesc[0].hwnd; break; // could be NULL
- case 2:
- if(!EngineOutputIsUp()) continue; // skip closed auxiliary windows
- h = e1; break;
- case 3:
- if(!EngineOutputIsUp()) continue;
- h = e2; break;
- case 4:
- if(!MoveHistoryIsUp()) continue;
- h = mh; break;
- // case 6: // input to eval graph does not seem to get here!
- // if(!EvalGraphIsUp()) continue;
- // h = evalGraphDialog; break;
- case 5:
- if(!appData.icsActive) continue;
- SAY("display");
- h = hText; break;
- case 6:
- if(!appData.icsActive) continue;
- SAY("input");
- h = hInput; break;
- }
- } while(h == 0);
-
- if(currentElement > 4 && IsIconic(hwndConsole)) ShowWindow(hwndConsole, SW_RESTORE);
- if(currentElement < 5 && IsIconic(hwndMain)) ShowWindow(hwndMain, SW_RESTORE); // all open together
- SetFocus(h);
-
- continue; // this message now has been processed
- }
- }
-
- if (!(commentDialog && IsDialogMessage(commentDialog, &msg)) &&
- !(moveHistoryDialog && IsDialogMessage(moveHistoryDialog, &msg)) &&
- !(evalGraphDialog && IsDialogMessage(evalGraphDialog, &msg)) &&
- !(engineOutputDialog && IsDialogMessage(engineOutputDialog, &msg)) &&
- !(editTagsDialog && IsDialogMessage(editTagsDialog, &msg)) &&
- !(gameListDialog && IsDialogMessage(gameListDialog, &msg)) &&
- !(errorDialog && IsDialogMessage(errorDialog, &msg)) &&
- !(!frozen && TranslateAccelerator(hwndMain, hAccelMain, &msg)) && JAWS_ACCEL
- !(!hwndConsole && TranslateAccelerator(hwndMain, hAccelNoICS, &msg)) &&
- !(!hwndConsole && TranslateAccelerator(hwndMain, hAccelNoAlt, &msg))) {
- int done = 0, i; // [HGM] chat: dispatch cat-box messages
- for(i=0; i<MAX_CHAT; i++)
- if(chatHandle[i] && IsDialogMessage(chatHandle[i], &msg)) {
- done = 1; break;
- }
- if(done) continue; // [HGM] chat: end patch
- TranslateMessage(&msg); /* Translates virtual key codes */
- DispatchMessage(&msg); /* Dispatches message to window */
- }
- }
-
-
- return (msg.wParam); /* Returns the value from PostQuitMessage */
- }
-
- /*---------------------------------------------------------------------------*\
- *
- * Initialization functions
- *
- \*---------------------------------------------------------------------------*/
-
- void
- SetUserLogo()
- { // update user logo if necessary
- static char oldUserName[MSG_SIZ], dir[MSG_SIZ], *curName;
-
- if(appData.autoLogo) {
- curName = UserName();
- if(strcmp(curName, oldUserName)) {
- GetCurrentDirectory(MSG_SIZ, dir);
- SetCurrentDirectory(installDir);
- snprintf(oldUserName, MSG_SIZ, "logos\\%s.bmp", curName);
- userLogo = LoadImage( 0, oldUserName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- safeStrCpy(oldUserName, curName, sizeof(oldUserName)/sizeof(oldUserName[0]) );
- if(userLogo == NULL)
- userLogo = LoadImage( 0, "logos\\dummy.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- SetCurrentDirectory(dir); /* return to prev directory */
- }
- }
- }
-
- BOOL
- InitApplication(HINSTANCE hInstance)
- {
- WNDCLASS wc;
-
- /* Fill in window class structure with parameters that describe the */
- /* main window. */
-
- wc.style = CS_HREDRAW | CS_VREDRAW; /* Class style(s). */
- wc.lpfnWndProc = (WNDPROC)WndProc; /* Window Procedure */
- wc.cbClsExtra = 0; /* No per-class extra data. */
- wc.cbWndExtra = 0; /* No per-window extra data. */
- wc.hInstance = hInstance; /* Owner of this class */
- wc.hIcon = LoadIcon(hInstance, "icon_white");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* Cursor */
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); /* Default color */
- wc.lpszMenuName = szAppName; /* Menu name from .RC */
- wc.lpszClassName = szAppName; /* Name to register as */
-
- /* Register the window class and return success/failure code. */
- if (!RegisterClass(&wc)) return FALSE;
-
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = (WNDPROC)ConsoleWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = DLGWINDOWEXTRA;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(hInstance, "icon_white");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = szConsoleName;
-
- if (!RegisterClass(&wc)) return FALSE;
- return TRUE;
- }
-
-
- /* Set by InitInstance, used by EnsureOnScreen */
- int screenHeight, screenWidth;
-
- void
- EnsureOnScreen(int *x, int *y, int minX, int minY)
- {
- // 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 < minX) *x = minX;
- if (*y < minY) *y = minY;
- }
-
- VOID
- LoadLogo(ChessProgramState *cps, int n, Boolean ics)
- {
- char buf[MSG_SIZ], dir[MSG_SIZ];
- GetCurrentDirectory(MSG_SIZ, dir);
- SetCurrentDirectory(installDir);
- if( appData.logo[n] && appData.logo[n][0] != NULLCHAR) {
- cps->programLogo = LoadImage( 0, appData.logo[n], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
-
- if (cps->programLogo == NULL && appData.debugMode) {
- fprintf( debugFP, "Unable to load logo bitmap '%s'\n", appData.logo[n] );
- }
- } else if(appData.autoLogo) {
- if(ics) { // [HGM] logo: in ICS mode second can be used for ICS
- sprintf(buf, "logos\\%s.bmp", appData.icsHost);
- cps->programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- } else
- if(appData.directory[n] && appData.directory[n][0]) {
- SetCurrentDirectory(appData.directory[n]);
- cps->programLogo = LoadImage( 0, "logo.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- }
- }
- SetCurrentDirectory(dir); /* return to prev directory */
- }
-
- VOID
- InitTextures()
- {
- ZeroMemory( &backTextureSquareInfo, sizeof(backTextureSquareInfo) );
- backTextureSquareSize = 0; // kludge to force recalculation of texturemode
-
- if( appData.liteBackTextureFile && appData.liteBackTextureFile[0] != NULLCHAR && appData.liteBackTextureFile[0] != '*' ) {
- liteBackTexture = LoadImage( 0, appData.liteBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- liteBackTextureMode = appData.liteBackTextureMode;
-
- if (liteBackTexture == NULL && appData.debugMode) {
- fprintf( debugFP, "Unable to load lite texture bitmap '%s'\n", appData.liteBackTextureFile );
- }
- }
-
- if( appData.darkBackTextureFile && appData.darkBackTextureFile[0] != NULLCHAR && appData.darkBackTextureFile[0] != '*' ) {
- darkBackTexture = LoadImage( 0, appData.darkBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
- darkBackTextureMode = appData.darkBackTextureMode;
-
- if (darkBackTexture == NULL && appData.debugMode) {
- fprintf( debugFP, "Unable to load dark texture bitmap '%s'\n", appData.darkBackTextureFile );
- }
- }
- }
-
- BOOL
- InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
- {
- HWND hwnd; /* Main window handle. */
- int ibs;
- WINDOWPLACEMENT wp;
- char *filepart;
-
- hInst = hInstance; /* Store instance handle in our global variable */
- programName = szAppName;
-
- if (SearchPath(NULL, "WinBoard.exe", NULL, MSG_SIZ, installDir, &filepart)) {
- *filepart = NULLCHAR;
- } else {
- GetCurrentDirectory(MSG_SIZ, installDir);
- }
- gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] won't have open window otherwise
- screenWidth = screenHeight = 1000; // [HGM] placement: kludge to allow calling EnsureOnScreen from InitAppData
- InitAppData(lpCmdLine); /* Get run-time parameters */
- /* xboard, and older WinBoards, controlled the move sound with the
- appData.ringBellAfterMoves option. In the current WinBoard, we
- always turn the option on (so that the backend will call us),
- then let the user turn the sound off by setting it to silence if
- desired. To accommodate old winboard.ini files saved by old
- versions of WinBoard, we also turn off the sound if the option
- was initially set to false. [HGM] taken out of InitAppData */
- if (!appData.ringBellAfterMoves) {
- sounds[(int)SoundMove].name = strdup("");
- appData.ringBellAfterMoves = TRUE;
- }
- if (appData.debugMode) {
- debugFP = fopen(appData.nameOfDebugFile, "w");
- setbuf(debugFP, NULL);
- }
-
- LoadLanguageFile(appData.language);
-
- InitBackEnd1();
-
- // InitEngineUCI( installDir, &first ); // [HGM] incorporated in InitBackEnd1()
- // InitEngineUCI( installDir, &second );
-
- /* Create a main window for this application instance. */
- hwnd = CreateWindow(szAppName, szTitle,
- (WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX),
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
- NULL, NULL, hInstance, NULL);
- hwndMain = hwnd;
-
- /* If window could not be created, return "failure" */
- if (!hwnd) {
- return (FALSE);
- }
-
- /* [HGM] logo: Load logos if specified (must be done before InitDrawingSizes) */
- LoadLogo(&first, 0, FALSE);
- LoadLogo(&second, 1, appData.icsActive);
-
- SetUserLogo();
-
- iconWhite = LoadIcon(hInstance, "icon_white");
- iconBlack = LoadIcon(hInstance, "icon_black");
- iconCurrent = iconWhite;
- InitDrawingColors();
- screenHeight = GetSystemMetrics(SM_CYSCREEN);
- screenWidth = GetSystemMetrics(SM_CXSCREEN);
- for (ibs = (int) NUM_SIZES - 1; ibs >= 0; ibs--) {
- /* Compute window size for each board size, and use the largest
- size that fits on this screen as the default. */
- InitDrawingSizes((BoardSize)(ibs+1000), 0);
- if (boardSize == (BoardSize)-1 &&
- winH <= screenHeight
- - GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYCAPTION) - 10
- && winW <= screenWidth) {
- boardSize = (BoardSize)ibs;
- }
- }
-
- InitDrawingSizes(boardSize, 0);
- RecentEngineMenu(appData.recentEngineList);
- InitMenuChecks();
- buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS);
-
- /* [AS] Load textures if specified */
- InitTextures();
-
- mysrandom( (unsigned) time(NULL) );
-
- /* [AS] Restore layout */
- if( wpMoveHistory.visible ) {
- MoveHistoryPopUp();
- }
-
- if( wpEvalGraph.visible ) {
- EvalGraphPopUp();
- }
-
- if( wpEngineOutput.visible ) {
- EngineOutputPopUp();
- }
-
- /* Make the window visible; update its client area; and return "success" */
- EnsureOnScreen(&wpMain.x, &wpMain.y, minX, minY);
- wp.length = sizeof(WINDOWPLACEMENT);
- wp.flags = 0;
- wp.showCmd = nCmdShow;
- wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
- wp.rcNormalPosition.left = wpMain.x;
- wp.rcNormalPosition.right = wpMain.x + wpMain.width;
- wp.rcNormalPosition.top = wpMain.y;
- 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);
-
- if (hwndConsole) {
- #if AOT_CONSOLE
- SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
- 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
- #endif
- ShowWindow(hwndConsole, nCmdShow);
- 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
-
- return TRUE;
-
- }
-
- VOID
- InitMenuChecks()
- {
- HMENU hmenu = GetMenu(hwndMain);
-
- (void) EnableMenuItem(hmenu, IDM_CommPort,
- MF_BYCOMMAND|((appData.icsActive &&
- *appData.icsCommPort != NULLCHAR) ?
- MF_ENABLED : MF_GRAYED));
- (void) CheckMenuItem(hmenu, IDM_SaveSettingsOnExit,
- MF_BYCOMMAND|(saveSettingsOnExit ?
- MF_CHECKED : MF_UNCHECKED));
- }
-
- //---------------------------------------------------------------------------------------------------------
-
- #define ICS_TEXT_MENU_SIZE (IDM_CommandXLast - IDM_CommandX + 1)
- #define XBOARD FALSE
-
- #define OPTCHAR "/"
- #define SEPCHAR "="
- #define TOPLEVEL 0
-
- #include "args.h"
-
- // front-end part of option handling
-
- VOID
- LFfromMFP(LOGFONT* lf, MyFontParams *mfp)
- {
- HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
- lf->lfHeight = -(int)(mfp->pointSize * GetDeviceCaps(hdc, LOGPIXELSY) / 72.0 + 0.5);
- DeleteDC(hdc);
- lf->lfWidth = 0;
- lf->lfEscapement = 0;
- lf->lfOrientation = 0;
- lf->lfWeight = mfp->bold ? FW_BOLD : FW_NORMAL;
- lf->lfItalic = mfp->italic;
- lf->lfUnderline = mfp->underline;
- lf->lfStrikeOut = mfp->strikeout;
- lf->lfCharSet = mfp->charset;
- lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
- lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
- lf->lfQuality = DEFAULT_QUALITY;
- lf->lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
- safeStrCpy(lf->lfFaceName, mfp->faceName, sizeof(lf->lfFaceName)/sizeof(lf->lfFaceName[0]) );
- }
-
- void
- CreateFontInMF(MyFont *mf)
- {
- LFfromMFP(&mf->lf, &mf->mfp);
- if (mf->hf) DeleteObject(mf->hf);
- mf->hf = CreateFontIndirect(&mf->lf);
- }
-
- // [HGM] This platform-dependent table provides the location for storing the color info
- void *
- colorVariable[] = {
- &whitePieceColor,
- &blackPieceColor,
- &lightSquareColor,
- &darkSquareColor,
- &highlightSquareColor,
- &premoveHighlightColor,
- NULL,
- &consoleBackgroundColor,
- &appData.fontForeColorWhite,
- &appData.fontBackColorWhite,
- &appData.fontForeColorBlack,
- &appData.fontBackColorBlack,
- &appData.evalHistColorWhite,
- &appData.evalHistColorBlack,
- &appData.highlightArrowColor,
- };
-
- /* Command line font name parser. NULL name means do nothing.
- Syntax like "Courier New:10.0 bi" or "Arial:10" or "Arial:10b"
- For backward compatibility, syntax without the colon is also
- accepted, but font names with digits in them won't work in that case.
- */
- VOID
- ParseFontName(char *name, MyFontParams *mfp)
- {
- char *p, *q;
- if (name == NULL) return;
- p = name;
- q = strchr(p, ':');
- if (q) {
- if (q - p >= sizeof(mfp->faceName))
- ExitArgError(_("Font name too long:"), name, TRUE);
- memcpy(mfp->faceName, p, q - p);
- mfp->faceName[q - p] = NULLCHAR;
- p = q + 1;
- } else {
- q = mfp->faceName;
- while (*p && !isdigit(*p)) {
- *q++ = *p++;
- if (q - mfp->faceName >= sizeof(mfp->faceName))
- ExitArgError(_("Font name too long:"), name, TRUE);
- }
- while (q > mfp->faceName && q[-1] == ' ') q--;
- *q = NULLCHAR;
- }
- if (!*p) ExitArgError(_("Font point size missing:"), name, TRUE);
- mfp->pointSize = (float) atof(p);
- mfp->bold = (strchr(p, 'b') != NULL);
- mfp->italic = (strchr(p, 'i') != NULL);
- mfp->underline = (strchr(p, 'u') != NULL);
- mfp->strikeout = (strchr(p, 's') != NULL);
- mfp->charset = DEFAULT_CHARSET;
- q = strchr(p, 'c');
- if (q)
- mfp->charset = (BYTE) atoi(q+1);
- }
-
- void
- ParseFont(char *name, int number)
- { // wrapper to shield back-end from 'font'
- ParseFontName(name, &font[boardSize][number]->mfp);
- }
-
- void
- SetFontDefaults()
- { // in WB we have a 2D array of fonts; this initializes their description
- int i, j;
- /* Point font array elements to structures and
- parse default font names */
- for (i=0; i<NUM_FONTS; i++) {
- for (j=0; j<NUM_SIZES; j++) {
- font[j][i] = &fontRec[j][i];
- ParseFontName(font[j][i]->def, &font[j][i]->mfp);
- }
- }
- }
-
- void
- CreateFonts()
- { // here we create the actual fonts from the selected descriptions
- int i, j;
- for (i=0; i<NUM_FONTS; i++) {
- …
Large files files are truncated, but you can click here to view the full file