From: H.G. Muller Date: Sat, 2 May 2009 17:55:39 +0000 (-0700) Subject: changes from H.G. Muller; version 4.3.16 X-Git-Tag: v4.3.16 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=74025874f2010f84fd4f7f2e120e84b56ee9781b;p=xboard.git changes from H.G. Muller; version 4.3.16 --- diff --git a/backend.c b/backend.c index 5496797..25ee4c0 100644 --- a/backend.c +++ b/backend.c @@ -55,7 +55,7 @@ #else -#define DoSleep( n ) +#define DoSleep( n ) if( (n) >= 0) sleep(n) #endif @@ -127,23 +127,6 @@ typedef struct { int ms; /* Assuming this is >= 16 bits */ } TimeMark; -/* Search stats from chessprogram */ -typedef struct { - char movelist[2*MSG_SIZ]; /* Last PV we were sent */ - int depth; /* Current search depth */ - int nr_moves; /* Total nr of root moves */ - int moves_left; /* Moves remaining to be searched */ - char move_name[MOVE_LEN]; /* Current move being searched, if provided */ - unsigned long nodes; /* # of nodes searched */ - int time; /* Search time (centiseconds) */ - int score; /* Score (centipawns) */ - int got_only_move; /* If last msg was "(only move)" */ - int got_fail; /* 0 - nothing, 1 - got "--", 2 - got "++" */ - int ok_to_send; /* handshaking between send & recv */ - int line_is_book; /* 1 if movelist is book moves */ - int seen_stat; /* 1 if we've seen the stat01: line */ -} ChessProgramStats; - int establish P((void)); void read_from_player P((InputSourceRef isr, VOIDSTAR closure, char *buf, int count, int error)); @@ -216,6 +199,8 @@ void InitBackEnd3 P((void)); void FeatureDone P((ChessProgramState* cps, int val)); void InitChessProgram P((ChessProgramState *cps, int setup)); ChessProgramState *WhitePlayer(); +void InsertIntoMemo P((int which, char *text)); // [HGM] kibitz: in engineo.c +int VerifyDisplayMode P(()); char *GetInfoFromComment( int, char * ); // [HGM] PV time: returns stripped comment void InitEngineUCI( const char * iniDir, ChessProgramState * cps ); // [HGM] moved here from winboard.c @@ -224,7 +209,7 @@ char *SendMoveToBookUser P((int nr, ChessProgramState *cps, int initial)); // [H extern char installDir[MSG_SIZ]; extern int tinyLayout, smallLayout; -static ChessProgramStats programStats; +ChessProgramStats programStats; static int exiting = 0; /* [HGM] moved to top */ static int setboardSpoiledMachineBlack = 0, errorExitFlag = 0; extern int startedFromPositionFile; @@ -233,6 +218,7 @@ char endingGame = 0; /* [HGM] crash: flag to prevent recursion of GameEnds() int whiteNPS, blackNPS; /* [HGM] nps: for easily making clocks aware of NPS */ VariantClass currentlyInitializedVariant; /* [HGM] variantswitch */ int lastIndex = 0; /* [HGM] autoinc: last game/position used in match mode */ +int opponentKibitzes; /* States for ics_getting_history */ #define H_FALSE 0 @@ -318,9 +304,9 @@ PosFlags(index) if ((index % 2) == 0) flags |= F_WHITE_ON_MOVE; switch (gameInfo.variant) { case VariantSuicide: - case VariantGiveaway: - flags |= F_IGNORE_CHECK; flags &= ~F_ALL_CASTLE_OK; + case VariantGiveaway: // [HGM] moved this case label one down: seems Giveaway does have castling on ICC! + flags |= F_IGNORE_CHECK; break; case VariantAtomic: flags |= F_IGNORE_CHECK | F_ATOMIC_CAPTURE; @@ -495,6 +481,13 @@ ChessSquare CapablancaArray[2][BOARD_SIZE] = { BlackKing, BlackBishop, BlackMarshall, BlackKnight, BlackRook } }; +ChessSquare GreatArray[2][BOARD_SIZE] = { + { WhiteDragon, WhiteKnight, WhiteAlfil, WhiteGrasshopper, WhiteKing, + WhiteSilver, WhiteCardinal, WhiteAlfil, WhiteKnight, WhiteDragon }, + { BlackDragon, BlackKnight, BlackAlfil, BlackGrasshopper, BlackKing, + BlackSilver, BlackCardinal, BlackAlfil, BlackKnight, BlackDragon }, +}; + ChessSquare JanusArray[2][BOARD_SIZE] = { { WhiteRook, WhiteAngel, WhiteKnight, WhiteBishop, WhiteKing, WhiteQueen, WhiteBishop, WhiteKnight, WhiteAngel, WhiteRook }, @@ -528,6 +521,7 @@ ChessSquare FalconArray[2][BOARD_SIZE] = { #define XiangqiPosition FIDEArray #define CapablancaArray FIDEArray #define GothicArray FIDEArray +#define GreatArray FIDEArray #endif // !(BOARD_SIZE>=10) #if (BOARD_SIZE>=12) @@ -860,6 +854,7 @@ InitBackEnd1() case VariantCapaRandom: /* should work */ case VariantJanus: /* should work */ case VariantSuper: /* experimental */ + case VariantGreat: /* experimental, requires legality testing to be off */ break; } } @@ -1531,7 +1526,8 @@ StringToVariant(e) if (!found) { if ((StrCaseStr(e, "fischer") && StrCaseStr(e, "random")) - || StrCaseStr(e, "wild/fr")) { + || StrCaseStr(e, "wild/fr") + || StrCaseStr(e, "frc") || StrCaseStr(e, "960")) { v = VariantFischeRandom; } else if ((i = 4, p = StrCaseStr(e, "wild")) || (i = 1, p = StrCaseStr(e, "w"))) { @@ -1673,6 +1669,9 @@ StringToVariant(e) case 49: v = VariantSuper; break; + case 50: + v = VariantGreat; + break; case -1: /* Found "wild" or "w" in the string but no number; must assume it's normal chess. */ @@ -1889,7 +1888,7 @@ CopyHoldings(Board board, char *holdings, ChessSquare lowestPiece) j = PieceToNumber(piece); if(j >= gameInfo.holdingsSize) continue; /* ignore pieces that do not fit */ if(j < 0) continue; /* should not happen */ - piece = (ChessSquare) ( j + (int)lowestPiece ); + piece = (ChessSquare) ( (int)piece + (int)lowestPiece ); board[holdingsStartRow+j*direction][holdingsColumn] = piece; board[holdingsStartRow+j*direction][countsColumn]++; } @@ -1996,6 +1995,7 @@ static int player2Rating = -1; /*----------------------------*/ ColorClass curColor = ColorNormal; +int suppressKibitz = 0; void read_from_ics(isr, closure, data, count, error) @@ -2208,7 +2208,28 @@ read_from_ics(isr, closure, data, count, error) parse[parse_pos++] = buf[i]; if (buf[i] == '\n') { parse[parse_pos] = NULLCHAR; - AppendComment(forwardMostMove, StripHighlight(parse)); + if(!suppressKibitz) // [HGM] kibitz + AppendComment(forwardMostMove, StripHighlight(parse)); + else { // [HGM kibitz: divert memorized engine kibitz to engine-output window + int nrDigit = 0, nrAlph = 0, i; + if(parse_pos > MSG_SIZ - 30) // defuse unreasonably long input + { parse_pos = MSG_SIZ-30; parse[parse_pos - 1] = '\n'; } + parse[parse_pos] = NULLCHAR; + // try to be smart: if it does not look like search info, it should go to + // ICS interaction window after all, not to engine-output window. + for(i=0; i= '0' && parse[i] <= '9'); + nrAlph += (parse[i] >= 'a' && parse[i] <= 'z'); + nrAlph += (parse[i] >= 'A' && parse[i] <= 'Z'); + } + if(nrAlph < 9*nrDigit) { // if more than 10% digit we assume search info + OutputKibitz(suppressKibitz, parse); + } else { + char tmp[MSG_SIZ]; + sprintf(tmp, "your opponent kibitzes: %s", parse); + SendToPlayer(tmp, strlen(tmp)); + } + } started = STARTED_NONE; } else { /* Don't match patterns against characters in chatter */ @@ -2289,6 +2310,33 @@ read_from_ics(isr, closure, data, count, error) } oldi = i; + // [HGM] kibitz: try to recognize opponent engine-score kibitzes, to divert them to engine-output window + if (appData.autoKibitz && started == STARTED_NONE && + (gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || gameMode == IcsObserving)) { + if(looking_at(buf, &i, "* kibitzes: ") && + (StrStr(star_match[0], gameInfo.white) == star_match[0] || + StrStr(star_match[0], gameInfo.black) == star_match[0] )) { // kibitz of self or opponent + suppressKibitz = TRUE; + if((StrStr(star_match[0], gameInfo.white) == star_match[0]) + && (gameMode == IcsPlayingWhite) || + (StrStr(star_match[0], gameInfo.black) == star_match[0]) + && (gameMode == IcsPlayingBlack) ) // opponent kibitz + started = STARTED_CHATTER; // own kibitz we simply discard + else { + started = STARTED_COMMENT; // make sure it will be collected in parse[] + parse_pos = 0; parse[0] = NULLCHAR; + savingComment = TRUE; + suppressKibitz = gameMode != IcsObserving ? 2 : + (StrStr(star_match[0], gameInfo.white) == NULL) + 1; + } + continue; + } else + if(looking_at(buf, &i, "kibitzed to")) { // suppress the acknowledgements of our own autoKibitz + started = STARTED_CHATTER; + suppressKibitz = TRUE; + } + } // [HGM] kibitz: end of patch + if (appData.zippyTalk || appData.zippyPlay) { #if ZIPPY if (ZippyControl(buf, &i) || @@ -2637,7 +2685,7 @@ read_from_ics(isr, closure, data, count, error) if (looking_at(buf, &i, "% ") || ((started == STARTED_MOVES || started == STARTED_MOVES_NOHIDE) - && looking_at(buf, &i, "}*"))) { + && looking_at(buf, &i, "}*"))) { char *bookHit = NULL; // [HGM] book savingComment = FALSE; switch (started) { case STARTED_MOVES: @@ -2656,11 +2704,18 @@ read_from_ics(isr, closure, data, count, error) } SendTimeRemaining(&first, TRUE); } +#if 0 if (first.useColors) { SendToProgram("white\ngo\n", &first); } else { SendToProgram("go\n", &first); } +#else + if (first.useColors) { + SendToProgram("white\n", &first); // [HGM] book: made sending of "go\n" book dependent + } + bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: probe book for initial pos +#endif first.maybeThinking = TRUE; } else { if (first.usePlayother) { @@ -2681,11 +2736,18 @@ read_from_ics(isr, closure, data, count, error) } SendTimeRemaining(&first, FALSE); } +#if 0 if (first.useColors) { SendToProgram("black\ngo\n", &first); } else { SendToProgram("go\n", &first); } +#else + if (first.useColors) { + SendToProgram("black\n", &first); + } + bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); +#endif first.maybeThinking = TRUE; } else { if (first.usePlayother) { @@ -2738,6 +2800,17 @@ read_from_ics(isr, closure, data, count, error) default: break; } + if(bookHit) { // [HGM] book: simulate book reply + static char bookMove[MSG_SIZ]; // a bit generous? + + programStats.depth = programStats.nodes = programStats.time = + programStats.score = programStats.got_only_move = 0; + sprintf(programStats.movelist, "%s (xbook)", bookHit); + + strcpy(bookMove, "move "); + strcat(bookMove, bookHit); + HandleMachineMove(bookMove, &first); + } continue; } @@ -3120,11 +3193,12 @@ read_from_ics(isr, closure, data, count, error) i++; /* skip unparsed character and loop back */ } - if (started != STARTED_MOVES && started != STARTED_BOARD && + if (started != STARTED_MOVES && started != STARTED_BOARD && !suppressKibitz && // [HGM] kibitz suppress printing in ICS interaction window started != STARTED_HOLDINGS && i > next_out) { SendToPlayer(&buf[next_out], i - next_out); next_out = i; } + suppressKibitz = FALSE; // [HGM] kibitz: has done its duty in if-statement above leftover_len = buf_len - leftover_start; /* if buffer ends with something we couldn't parse, @@ -3548,8 +3622,37 @@ ParseBoard12(string) strcat(parseList[moveNum - 1], " "); strcat(parseList[moveNum - 1], elapsed_time); moveList[moveNum - 1][0] = NULLCHAR; - } else if (ParseOneMove(move_str, moveNum - 1, &moveType, - &fromX, &fromY, &toX, &toY, &promoChar)) { + } else if (strcmp(move_str, "none") == 0) { + // [HGM] long SAN: swapped order; test for 'none' before parsing move + /* Again, we don't know what the board looked like; + this is really the start of the game. */ + parseList[moveNum - 1][0] = NULLCHAR; + moveList[moveNum - 1][0] = NULLCHAR; + backwardMostMove = moveNum; + startedFromSetupPosition = TRUE; + fromX = fromY = toX = toY = -1; + } else { + // [HGM] long SAN: if legality-testing is off, disambiguation might not work or give wrong move. + // So we parse the long-algebraic move string in stead of the SAN move + int valid; char buf[MSG_SIZ], *prom; + + // str looks something like "Q/a1-a2"; kill the slash + if(str[1] == '/') + sprintf(buf, "%c%s", str[0], str+2); + else strcpy(buf, str); // might be castling + if((prom = strstr(move_str, "=")) && !strstr(buf, "=")) + strcat(buf, prom); // long move lacks promo specification! + if(!appData.testLegality) { + if(appData.debugMode) + fprintf(debugFP, "replaced ICS move '%s' by '%s'\n", move_str, buf); + strcpy(move_str, buf); + } + valid = ParseOneMove(move_str, moveNum - 1, &moveType, + &fromX, &fromY, &toX, &toY, &promoChar) + || ParseOneMove(buf, moveNum - 1, &moveType, + &fromX, &fromY, &toX, &toY, &promoChar); + // end of long SAN patch + if (valid) { (void) CoordsToAlgebraic(boards[moveNum - 1], PosFlags(moveNum - 1), EP_UNKNOWN, fromY, fromX, toY, toX, promoChar, @@ -3573,15 +3676,7 @@ ParseBoard12(string) /* currentMoveString is set as a side-effect of ParseOneMove */ strcpy(moveList[moveNum - 1], currentMoveString); strcat(moveList[moveNum - 1], "\n"); - } else if (strcmp(move_str, "none") == 0) { - /* Again, we don't know what the board looked like; - this is really the start of the game. */ - parseList[moveNum - 1][0] = NULLCHAR; - moveList[moveNum - 1][0] = NULLCHAR; - backwardMostMove = moveNum; - startedFromSetupPosition = TRUE; - fromX = fromY = toX = toY = -1; - } else { + } else { /* Move from ICS was illegal!? Punt. */ if (appData.debugMode) { fprintf(debugFP, "Illegal move from ICS '%s'\n", move_str); @@ -3598,6 +3693,7 @@ ParseBoard12(string) strcat(parseList[moveNum - 1], elapsed_time); moveList[moveNum - 1][0] = NULLCHAR; fromX = fromY = toX = toY = -1; + } } if (appData.debugMode) { fprintf(debugFP, "Move parsed to '%s'\n", parseList[moveNum - 1]); @@ -3724,7 +3820,7 @@ ParseBoard12(string) programStats.depth = programStats.nodes = programStats.time = programStats.score = programStats.got_only_move = 0; - sprintf(programStats.movelist, "%s (xbook)", bookMove); + sprintf(programStats.movelist, "%s (xbook)", bookHit); strcpy(bookMove, "move "); strcat(bookMove, bookHit); @@ -3874,10 +3970,14 @@ SendMoveToICS(moveType, fromX, fromY, toX, toY) case BlackPromotionChancellor: case WhitePromotionArchbishop: case BlackPromotionArchbishop: - if(gameInfo.variant == VariantShatranj) + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) sprintf(user_move, "%c%c%c%c=%c\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY, PieceToChar(WhiteFerz)); + else if(gameInfo.variant == VariantGreat) + sprintf(user_move, "%c%c%c%c=%c\n", + AAA + fromX, ONE + fromY, AAA + toX, ONE + toY, + PieceToChar(WhiteMan)); else sprintf(user_move, "%c%c%c%c=%c\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY, @@ -4521,6 +4621,12 @@ InitPosition(redraw) pieces = fairyArray; SetCharTable(pieceToChar, "PNBRQFEACWMOHIJGDVSLUKpnbrqfeacwmohijgdvsluk"); break; + case VariantGreat: + pieces = GreatArray; + gameInfo.boardWidth = 10; + SetCharTable(pieceToChar, "PN....E...S..HWGMKpn....e...s..hwgmk"); + gameInfo.holdingsSize = 8; + break; case VariantSuper: pieces = FIDEArray; SetCharTable(pieceToChar, "PNBRQ..SE.......V.AKpnbrq..se.......v.ak"); @@ -4619,6 +4725,12 @@ InitPosition(redraw) } if(gameInfo.variant == VariantSuper) Prelude(initialPosition); + if(gameInfo.variant == VariantGreat) { // promotion commoners + initialPosition[PieceToNumber(WhiteMan)][BOARD_RGHT-1] = WhiteMan; + initialPosition[PieceToNumber(WhiteMan)][BOARD_RGHT-2] = 9; + initialPosition[BOARD_HEIGHT-1-PieceToNumber(WhiteMan)][0] = BlackMan; + initialPosition[BOARD_HEIGHT-1-PieceToNumber(WhiteMan)][1] = 9; + } #if 0 if(gameInfo.variant == VariantFischeRandom) { if( appData.defaultFrcPosition < 0 ) { @@ -5077,7 +5189,7 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar) return ImpossibleMove; } } - +if(appData.debugMode) fprintf(debugFP, "moveType 3 = %d, promochar = %x\n", moveType, promoChar); return moveType; /* [HGM] in stead of calling FinishMove directly, this function is made into one that returns an OK move type if FinishMove @@ -5096,8 +5208,8 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) /*char*/int promoChar; { char *bookHit = 0; - - if(gameInfo.variant == VariantSuper && promoChar != NULLCHAR) { +if(appData.debugMode) fprintf(debugFP, "moveType 5 = %d, promochar = %x\n", moveType, promoChar); + if((gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) && promoChar != NULLCHAR) { // [HGM] superchess: suppress promotions to non-available piece int k = PieceToNumber(CharToPiece(ToUpper(promoChar))); if(WhiteOnMove(currentMove)) { @@ -5111,7 +5223,7 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) move type in caller when we know the move is a legal promotion */ if(moveType == NormalMove && promoChar) moveType = PromoCharToMoveType(WhiteOnMove(currentMove), promoChar); - +if(appData.debugMode) fprintf(debugFP, "moveType 1 = %d, promochar = %x\n", moveType, promoChar); /* [HGM] convert drag-and-drop piece drops to standard form */ if( fromX == BOARD_LEFT-2 || fromX == BOARD_RGHT+1) { moveType = WhiteOnMove(currentMove) ? WhiteDrop : BlackDrop; @@ -5175,7 +5287,8 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) MakeMove(fromX, fromY, toX, toY, promoChar); /*updates forwardMostMove*/ - if(gameInfo.variant == VariantSuper && promoChar != NULLCHAR && gameInfo.holdingsSize) { + if((gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) + && promoChar != NULLCHAR && gameInfo.holdingsSize) { // [HGM] superchess: take promotion piece out of holdings int k = PieceToNumber(CharToPiece(ToUpper(promoChar))); if(WhiteOnMove(forwardMostMove-1)) { @@ -5206,7 +5319,7 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) } ModeHighlight(); } - +if(appData.debugMode) fprintf(debugFP, "moveType 2 = %d, promochar = %x\n", moveType, promoChar); /* Relay move to ICS or chess engine */ if (appData.icsActive) { if (gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || @@ -5267,7 +5380,7 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) programStats.depth = programStats.nodes = programStats.time = programStats.score = programStats.got_only_move = 0; - sprintf(programStats.movelist, "%s (xbook)", bookMove); + sprintf(programStats.movelist, "%s (xbook)", bookHit); strcpy(bookMove, "move "); strcat(bookMove, bookHit); @@ -5291,7 +5404,7 @@ UserMoveEvent(fromX, fromY, toX, toY, promoChar) to do anything in between, can call this routine the old way. */ ChessMove moveType = UserMoveTest(fromX, fromY, toX, toY, promoChar); - +if(appData.debugMode) fprintf(debugFP, "moveType 4 = %d, promochar = %x\n", moveType, promoChar); if(moveType != ImpossibleMove) FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } @@ -5327,7 +5440,7 @@ char *SendMoveToBookUser(int moveNr, ChessProgramState *cps, int initial) //first determine if the incoming move brings opponent into his book if(appData.usePolyglotBook && (cps == &first ? !appData.firstHasOwnBookUCI : !appData.secondHasOwnBookUCI)) bookHit = ProbeBook(moveNr+1, appData.polyglotBook); // returns move - if(appData.debugMode && bookHit) fprintf(debugFP, "book hit = %s\n", bookHit); + if(appData.debugMode) fprintf(debugFP, "book hit = %s\n", bookHit ? bookHit : "(NULL)"); if(bookHit != NULL && !cps->bookSuspend) { // make sure opponent is not going to reply after receiving move to book position SendToProgram("force\n", cps); @@ -5614,7 +5727,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if( gameMode == TwoMachinesPlay ) { // [HGM] some adjudications useful with buggy engines int k, count = 0, epFile = epStatus[forwardMostMove]; static int bare = 1; - if(gameInfo.holdingsSize == 0 || gameInfo.variant == VariantSuper) { + if(gameInfo.holdingsSize == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { if(appData.testLegality) // don't wait for engine to announce game end if we can judge ourselves @@ -5628,6 +5741,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h case MT_STALEMATE: epStatus[forwardMostMove] = EP_STALEMATE; if(appData.checkMates) { + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( GameIsDrawn, "Xboard adjudication: Stalemate", GE_XBOARD ); @@ -5636,6 +5750,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h case MT_CHECKMATE: epStatus[forwardMostMove] = EP_CHECKMATE; if(appData.checkMates) { + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( WhiteOnMove(forwardMostMove) ? BlackWins : WhiteWins, "Xboard adjudication: Checkmate", @@ -5661,11 +5776,13 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h case WhiteKnight: NrWN++; break; case WhiteBishop: + case WhiteFerz: // [HGM] shatranj: kludge to mke it work in shatranj bishopsColor |= 1 << ((i^j)&1); NrWB++; break; case BlackKnight: NrBN++; break; case BlackBishop: + case BlackFerz: // [HGM] shatranj: kludge to mke it work in shatranj bishopsColor |= 1 << ((i^j)&1); NrBB++; break; case WhiteRook: @@ -5685,10 +5802,16 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } NrPieces += (p != EmptySquare); NrW += ((int)p < (int)BlackPawn); + if(gameInfo.variant == VariantXiangqi && + (p == WhiteFerz || p == WhiteAlfil || p == BlackFerz || p == BlackAlfil)) { + NrPieces--; // [HGM] XQ: do not count purely defensive pieces + NrW -= ((int)p < (int)BlackPawn); + } } - if( NrPieces == 3 && NrWN+NrBN+NrWB+NrBB == 1 || NrPieces == 2 - || NrPieces == 4 && NrBB+NrWB == NrPieces-2 && bishopsColor != 3) + if( NrPieces == 2 || gameInfo.variant != VariantXiangqi && + (NrPieces == 3 && NrWN+NrBN+NrWB+NrBB == 1 || + NrPieces == NrBB+NrWB+2 && bishopsColor != 3)) // [HGM] all Bishops (Ferz!) same color { /* KBK, KNK, KK of KBKB with like Bishops */ /* always flag draws, for judging claims */ @@ -5696,6 +5819,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if(appData.materialDraws) { /* but only adjudicate them if adjudication enabled */ + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see last move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( GameIsDrawn, "Xboard adjudication: Insufficient mating material", GE_XBOARD ); return; @@ -5708,6 +5833,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if(--bare < 0 && appData.checkMates) { /* but only adjudicate them if adjudication enabled */ + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( NrW > 1 ? WhiteWins : NrPieces - NrW > 1 ? BlackWins : GameIsDrawn, "Xboard adjudication: Bare king", GE_XBOARD ); @@ -5724,6 +5850,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h ) ) { if(--moveCount < 0 && appData.trivialDraws) { /* if the first 3 moves do not show a tactical win, declare draw */ + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( GameIsDrawn, "Xboard adjudication: Trivial draw", GE_XBOARD ); return; @@ -5790,7 +5918,30 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if( rights == 0 && ++count > appData.drawRepeats-2 && appData.drawRepeats > 1) { /* adjudicate after user-specified nr of repeats */ + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ + if(gameInfo.variant == VariantXiangqi && appData.testLegality) { + // [HGM] xiangqi: check for forbidden perpetuals + int m, ourPerpetual = 1, hisPerpetual = 1; + for(m=forwardMostMove; m>k; m-=2) { + if(MateTest(boards[m], PosFlags(m), + EP_NONE, castlingRights[m]) != MT_CHECK) + ourPerpetual = 0; // the current mover did not always check + if(MateTest(boards[m-1], PosFlags(m-1), + EP_NONE, castlingRights[m-1]) != MT_CHECK) + hisPerpetual = 0; // the opponent did not always check + } + if(ourPerpetual && !hisPerpetual) { // we are actively checking him: forfeit + GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, + "Xboard adjudication: perpetual checking", GE_XBOARD ); + return; + } + if(hisPerpetual && !ourPerpetual) // he is checking us, but did not repeat yet + break; // (or we would have caught him before). Abort repetition-checking loop. + // if neither of us is checking all the time, or both are, it is draw + // (illegal-chase forfeits not implemented yet!) + } GameEnds( GameIsDrawn, "Xboard adjudication: repetition draw", GE_XBOARD ); return; } @@ -5812,6 +5963,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h epStatus[forwardMostMove] = EP_RULE_DRAW; /* this is used to judge if draw claims are legal */ if(appData.ruleMoves > 0 && count >= 2*appData.ruleMoves) { + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ GameEnds( GameIsDrawn, "Xboard adjudication: 50-move rule", GE_XBOARD ); return; @@ -5831,6 +5984,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if(epStatus[forwardMostMove] == EP_INSUF_DRAW) p = "Draw claim: insufficient mating material"; if( p != NULL ) { + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ GameEnds( GameIsDrawn, p, GE_XBOARD ); ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ return; @@ -5838,14 +5993,15 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } - } - - if( appData.adjudicateDrawMoves > 0 && forwardMostMove > (2*appData.adjudicateDrawMoves) ) { - ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ + if( appData.adjudicateDrawMoves > 0 && forwardMostMove > (2*appData.adjudicateDrawMoves) ) { + SendToProgram("force\n", cps->other); // suppress reply + SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */ + ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ - GameEnds( GameIsDrawn, "Xboard adjudication: long game", GE_XBOARD ); + GameEnds( GameIsDrawn, "Xboard adjudication: long game", GE_XBOARD ); - return; + return; + } } bookHit = NULL; @@ -5895,7 +6051,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h cps = cps->other; programStats.depth = programStats.nodes = programStats.time = programStats.score = programStats.got_only_move = 0; - sprintf(programStats.movelist, "%s (xbook)", bookMove); + sprintf(programStats.movelist, "%s (xbook)", bookHit); if(cps->lastPing != cps->lastPong) { savedMessage = message; // args for deferred call @@ -6836,24 +6992,28 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) epStatus[p] = EP_CAPTURE; if( board[fromY][fromX] == WhitePawn ) { - epStatus[p] = EP_PAWN_MOVE; - if( toY-fromY==2) + if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers + epStatus[p] = EP_PAWN_MOVE; + if( toY-fromY==2) { if(toX>BOARD_LEFT && board[toY][toX-1] == BlackPawn && gameInfo.variant != VariantBerolina || toX < fromX) epStatus[p] = toX | berolina; if(toX fromX) epStatus[p] = toX; + } } else if( board[fromY][fromX] == BlackPawn ) { - epStatus[p] = EP_PAWN_MOVE; - if( toY-fromY== -2) + if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers + epStatus[p] = EP_PAWN_MOVE; + if( toY-fromY== -2) { if(toX>BOARD_LEFT && board[toY][toX-1] == WhitePawn && gameInfo.variant != VariantBerolina || toX < fromX) epStatus[p] = toX | berolina; if(toX fromX) epStatus[p] = toX; + } } for(i=0; i 0 && gameInfo.variant != VariantBughouse ) { /* [HGM] holdings: Add to holdings, if holdings exist */ - if(gameInfo.variant == VariantSuper) { + if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { // [HGM] superchess: suppress flipping color of captured pieces by reverse pre-flip captured = (int) captured >= (int) BlackPawn ? BLACK_TO_WHITE captured : WHITE_TO_BLACK captured; } @@ -7308,6 +7468,8 @@ InitChessProgram(cps, setup) overruled = gameInfo.boardWidth != 12 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0; if( gameInfo.variant == VariantSuper ) overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 8; + if( gameInfo.variant == VariantGreat ) + overruled = gameInfo.boardWidth != 10 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 8; if(overruled) { sprintf(b, "%dx%d+%d_%s", gameInfo.boardWidth, gameInfo.boardHeight, @@ -7408,6 +7570,8 @@ StartChessProgram(cps) cps->isr = AddInputSource(cps->pr, TRUE, ReceiveFromProgram, cps); if (cps->protocolVersion > 1) { sprintf(buf, "xboard\nprotover %d\n", cps->protocolVersion); + cps->nrOptions = 0; // [HGM] options: clear all engine-specific options + cps->comboCnt = 0; // and values of combo boxes SendToProgram(buf, cps); } else { SendToProgram("xboard\n", cps); @@ -7545,7 +7709,7 @@ GameEnds(result, resultDetails, whosays) claimer = whosays == GE_ENGINE1 ? /* color of claimer */ first.twoMachinesColor[0] : second.twoMachinesColor[0] ; - if( (gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper) && + if( (gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) && (result == WhiteWins && claimer == 'w' || result == BlackWins && claimer == 'b' ) ) { if (appData.debugMode) { @@ -7573,7 +7737,8 @@ GameEnds(result, resultDetails, whosays) /* (Claiming a loss is accepted no questions asked!) */ } /* [HGM] bare: don't allow bare King to win */ - if((gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper) && result != GameIsDrawn) + if((gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) + && result != GameIsDrawn) { int i, j, k=0, color = (result==WhiteWins ? (int)WhitePawn : (int)BlackPawn); for(j=BOARD_LEFT; jname, " -spin ")) { + if((n = sscanf(p, " -spin %d %d %d", &def, &min, &max)) < 3 ) return FALSE; + if(max < min) max = min; // enforce consistency + if(def < min) def = min; + if(def > max) def = max; + opt->value = def; + opt->min = min; + opt->max = max; + opt->type = Spin; + } else if(p = strstr(opt->name, " -string ")) { + opt->textValue = p+9; + opt->type = TextBox; + } else if(p = strstr(opt->name, " -check ")) { + if(sscanf(p, " -check %d", &def) < 1) return FALSE; + opt->value = (def != 0); + opt->type = CheckBox; + } else if(p = strstr(opt->name, " -combo ")) { + opt->textValue = (char*) (&cps->comboList[cps->comboCnt]); // cheat with pointer type + cps->comboList[cps->comboCnt++] = q = p+8; // holds possible choices + opt->value = n = 0; + while(q = StrStr(q, " /// ")) { + n++; *q = 0; // count choices, and null-terminate each of them + q += 5; + if(*q == '*') { // remember default, which is marked with * prefix + q++; + opt->value = n; + } + cps->comboList[cps->comboCnt++] = q; + } + cps->comboList[cps->comboCnt++] = NULL; + opt->max = n + 1; + opt->type = ComboBox; + } else if(p = strstr(opt->name, " -button")) { + opt->type = Button; + } else if(p = strstr(opt->name, " -save")) { + opt->type = SaveButton; + } else return FALSE; + *p = 0; // terminate option name + return TRUE; +} + void FeatureDone(cps, val) ChessProgramState* cps; @@ -12155,6 +12372,16 @@ ParseFeatures(args, cps) if (BoolFeature(&p, "memory", &cps->memSize, cps)) continue; if (BoolFeature(&p, "smp", &cps->maxCores, cps)) continue; if (StringFeature(&p, "egt", &cps->egtFormats, cps)) continue; + if (StringFeature(&p, "option", &(cps->option[cps->nrOptions].name), cps)) { + ParseOption(&(cps->option[cps->nrOptions++]), cps); // [HGM] options: add option feature + if(cps->nrOptions >= MAX_OPTIONS) { + cps->nrOptions--; + sprintf(buf, "%s engine has too many options\n", cps->which); + DisplayError(buf, 0); + } + continue; + } + if (BoolFeature(&p, "smp", &cps->maxCores, cps)) continue; /* End of additions by HGM */ /* unknown feature: complain and skip */ diff --git a/backend.h b/backend.h index 995890d..eba5366 100644 --- a/backend.h +++ b/backend.h @@ -206,6 +206,19 @@ char * GameListLineFull P(( int, GameInfo *)); extern char* StripHighlight P((char *)); /* returns static data */ extern char* StripHighlightAndTitle P((char *)); /* returns static data */ +typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, SaveButton } Control; + +typedef struct _OPT { // [HGM] options: descriptor of UCI-style option + int value; // current setting, starts as default + int min; + int max; + void *handle; // for use by front end + char *textValue; // points to beginning of text value in name field + char **choice; // points to array of combo choices in cps->combo + Control type; + char name[MSG_SIZ]; // holds both option name and text value +} Option; + typedef struct _CPS { char *which; int maybeThinking; @@ -263,8 +276,14 @@ typedef struct _CPS { int alphaRank; /* [HGM] shogi: engine uses shogi-type coordinates */ int maxCores; /* [HGM] SMP: engine understands cores command */ int memSize; /* [HGM] memsize: engine understands memory command */ - char egtFormats[MSG_SIZ]; /* [HGM] EGT: supported tablebase formats */ - int bookSuspend; /* HGM book: go was deferred bcause of book hit */ + char egtFormats[MSG_SIZ]; /* [HGM] EGT: supported tablebase formats */ + int bookSuspend; /* [HGM] book: go was deferred because of book hit */ + int nrOptions; /* [HGM] options: remembered option="..." features */ +#define MAX_OPTIONS 50 + Option option[MAX_OPTIONS]; + int comboCnt; + char *comboList[10*MAX_OPTIONS]; + void *programLogo; /* [HGM] logo: bitmap of the logo */ } ChessProgramState; extern ChessProgramState first, second; @@ -276,7 +295,25 @@ typedef struct { int time; /* Milliseconds */ } ChessProgramStats_Move; +/* Search stats from chessprogram */ +typedef struct { + char movelist[2*MSG_SIZ]; /* Last PV we were sent */ + int depth; /* Current search depth */ + int nr_moves; /* Total nr of root moves */ + int moves_left; /* Moves remaining to be searched */ + char move_name[MOVE_LEN]; /* Current move being searched, if provided */ + unsigned long nodes; /* # of nodes searched */ + int time; /* Search time (centiseconds) */ + int score; /* Score (centipawns) */ + int got_only_move; /* If last msg was "(only move)" */ + int got_fail; /* 0 - nothing, 1 - got "--", 2 - got "++" */ + int ok_to_send; /* handshaking between send & recv */ + int line_is_book; /* 1 if movelist is book moves */ + int seen_stat; /* 1 if we've seen the stat01: line */ +} ChessProgramStats; + extern ChessProgramStats_Move pvInfoList[MAX_MOVES]; extern shuffleOpenings; +extern ChessProgramStats programStats; #endif /* _BACKEND */ diff --git a/common.h b/common.h index 6d8a6ec..8263d63 100644 --- a/common.h +++ b/common.h @@ -286,6 +286,7 @@ typedef enum { VariantBerolina, VariantJanus, VariantSuper, + VariantGreat, VariantUnknown /* Catchall for other unknown variants */ } VariantClass; @@ -326,6 +327,7 @@ typedef enum { "berolina",\ "janus",\ "super",\ + "great",\ "unknown" \ } @@ -575,8 +577,12 @@ typedef struct { char *userName; int rewindIndex; /* [HGM] autoinc */ int sameColorGames; /* [HGM] alternate */ - int smpCores; + int smpCores; /* [HGM] SMP */ char *egtFormats; + int niceEngines; /* [HGM] nice */ + char *firstLogo; /* [HGM] logo */ + char *secondLogo; + Boolean autoLogo; } AppData, *AppDataPtr; /* [AS] PGN tags (for showing in the game list) */ diff --git a/configure b/configure old mode 100644 new mode 100755 index 631b067..335b730 --- a/configure +++ b/configure @@ -4673,7 +4673,7 @@ fi PRODUCT=xboard #VERSION=4.3 # version is already defined -PATCHLEVEL=15 +PATCHLEVEL=16 if test -z "$CFLAGS" ; then diff --git a/engine-intf.html b/engine-intf.html index b2cd121..13e1719 100644 --- a/engine-intf.html +++ b/engine-intf.html @@ -1019,8 +1019,8 @@ the engine has to decide for itself how to divide up the available memory between the various tables it wants to use (e.g. main hash, pawn hash, tablebase cache, bitbases). This command will only be sent to engines that have requested it through the memory feature, -and only at the beginning of a game -(before any moves have been done). +and only at the start of a game, +as the first of the commands to relay engine option settings just before each "new" command.

@@ -1032,7 +1032,9 @@ This could be interpreted as the number of search threads for SMP engines. This command will only be sent to engines that have requested it through the smp feature. The engine should be able to respond to the "cores" command any time during a game, but it is allowed to finish a search in progress before procesing the command. -(Reaction during ponder time should be immediate, though.) +(Obeying the command should take priority over finishing a ponder search, though.) +In any case it will be sent at the start of every game +as the last command to relay engine option settings before the "new" command.

@@ -1052,6 +1054,7 @@ but could also be the name of a file, or in fact anything the particular EGT typ It is upto the developer of the EGT format to specify the syntax of this parameter. This command will only be sent to engines that have told the GUI they support EGTs of the given TYPE through the egt feature. +It will be sent at the start of each game, before the "new" command. @@ -1391,6 +1394,8 @@ will be set by the GUI through the "memory" command.

If smp=1, the GUI will send the "cores" command to the engine to inform it how many CPU cores it can use. +Note that sending smp=1 does not imply the engine can use more than one CPU; +just that it wants to receive the "cores" command.
diff --git a/moves.c b/moves.c index 0def075..58cbfc0 100644 --- a/moves.c +++ b/moves.c @@ -169,7 +169,8 @@ ChessMove PromoCharToMoveType(whiteOnMove, promoChar) int whiteOnMove; int promoChar; { /* [HGM] made dependent on CharToPiece to alow alternate piece letters */ - ChessSquare piece = CharToPiece(whiteOnMove ? ToUpper(promoChar) : ToLower(promoChar) ); + ChessSquare piece = CharToPiece(whiteOnMove ? ToUpper(promoChar) : ToLower(promoChar) ); + if(promoChar == NULLCHAR) return NormalMove; switch(piece) { case WhiteQueen: @@ -577,7 +578,7 @@ void GenPseudoLegal(board, flags, epfile, callback, closure) if (board[rt][ft] != EmptySquare) break; } if(m==1) goto mounted; - if(m==2) goto walking; + if(m==2) goto finishGold; break; case WhiteQueen: @@ -1265,7 +1266,7 @@ void Disambiguate(board, flags, epfile, closure) #endif /* [HGM] returns 'q' for optional promotion, 'n' for mandatory */ if(closure->promoCharIn != '=') - closure->promoChar = ToLower(PieceToChar(PromoPiece(closure->kind))); + closure->promoChar = ToLower(closure->promoCharIn); else closure->promoChar = '='; if (closure->promoChar == 'x') closure->promoChar = NULLCHAR; if (closure->count > 1) { @@ -1280,7 +1281,7 @@ void Disambiguate(board, flags, epfile, closure) } if(closure->kind == IllegalMove) /* [HGM] might be a variant we don't understand, pass on promotion info */ - closure->promoChar = closure->promoCharIn; + closure->promoChar = ToLower(closure->promoCharIn); if (appData.debugMode) { fprintf(debugFP, "Disambiguate out: %d(%d,%d)-(%d,%d) = %d (%c)\n", closure->piece,closure->ff,closure->rf,closure->ft,closure->rt,closure->promoChar, diff --git a/parser.c b/parser.c index 58282bd..27d1a13 100644 --- a/parser.c +++ b/parser.c @@ -2278,6 +2278,8 @@ YY_RULE_SETUP result == WhitePromotionQueen || result == BlackPromotionQueen)) { if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) currentMoveString[4] = PieceToChar(BlackFerz); + else if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); else currentMoveString[4] = PieceToChar(BlackQueen); currentMoveString[5] = NULLCHAR; @@ -2427,7 +2429,6 @@ YY_RULE_SETUP if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */ currentMoveString[0] != currentMoveString[2] ) { - if (yytext[2+skip] == ONE) return (int) ImpossibleMove; currentMoveString[1] = yytext[2+skip]; } else if (WhiteOnMove(yyboardindex)) { @@ -2462,6 +2463,11 @@ YY_RULE_SETUP (result == WhitePromotionQueen || result == BlackPromotionQueen || result == WhitePromotionKnight || result == BlackPromotionKnight)) { currentMoveString[4] = PieceToChar(BlackQueen); + // [HGM] shatranj: take care of variants without Queen + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + currentMoveString[4] = PieceToChar(BlackFerz); + if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); currentMoveString[5] = NULLCHAR; } diff --git a/parser.l b/parser.l old mode 100644 new mode 100755 index 41feced..48e78f3 --- a/parser.l +++ b/parser.l @@ -304,6 +304,8 @@ extern void CopyBoard P((Board to, Board from)); result == WhitePromotionQueen || result == BlackPromotionQueen)) { if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) currentMoveString[4] = PieceToChar(BlackFerz); + else if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); else currentMoveString[4] = PieceToChar(BlackQueen); currentMoveString[5] = NULLCHAR; @@ -448,7 +450,6 @@ extern void CopyBoard P((Board to, Board from)); if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */ currentMoveString[0] != currentMoveString[2] ) { - if (yytext[2+skip] == ONE) return (int) ImpossibleMove; currentMoveString[1] = yytext[2+skip]; } else if (WhiteOnMove(yyboardindex)) { @@ -483,6 +484,11 @@ extern void CopyBoard P((Board to, Board from)); (result == WhitePromotionQueen || result == BlackPromotionQueen || result == WhitePromotionKnight || result == BlackPromotionKnight)) { currentMoveString[4] = PieceToChar(BlackQueen); + // [HGM] shatranj: take care of variants without Queen + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + currentMoveString[4] = PieceToChar(BlackFerz); + if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); currentMoveString[5] = NULLCHAR; } diff --git a/texi2man b/texi2man old mode 100644 new mode 100755 diff --git a/winboard/config.h b/winboard/config.h index bc657f5..32aceb1 100644 --- a/winboard/config.h +++ b/winboard/config.h @@ -36,7 +36,7 @@ #define LAST_PTY_LETTER 'q' -#define PATCHLEVEL "15m" +#define PATCHLEVEL "15k" #define PRODUCT "WinBoard" diff --git a/winboard/cygwin.mak b/winboard/cygwin.mak index cb4781e..833d169 100644 --- a/winboard/cygwin.mak +++ b/winboard/cygwin.mak @@ -1,97 +1,96 @@ -# -# Makefile for WinBoard, using the GNU Cygwin toolset -# - -# Uncomment both lines to turn on debugging symbols ####### -cdebug= -g -linkdebug= -g -####################################################### - -proj=winboard -allobj= winboard.o backend.o parser.o moves.o lists.o \ - gamelist.o pgntags.o wedittags.o wgamelist.o zippy.o \ - wsockerr.o wbres.o wclipbrd.o woptions.o uci.o \ - wengineo.o wevalgraph.o whistory.o wlayout.o \ - wplugin.o wsnap.o book.o - -dotc= winboard.c backend.c parser.c moves.c lists.c \ - gamelist.c pgntags.c wedittags.c wgamelist.c zippy.c \ - wsockerr.c winboard.rc wclipbrd.c woptions.c uci.c \ - wengineo.c wevalgraph.c whistory.c wlayout.c \ - wplugin.c wsnap.c book.c - -# Currently WinBoard will build either with or without -mno-cygwin -# however, a Cygwin bug in forming the command line to WinMain() is -# exposed if -mno-cygwin is not used. -cygwin= -mno-cygwin - -VPATH= .:.. -CFLAGS= $(cdebug) -INCLUDES= -I. -I.. -CVARS= $(INCLUDES) $(cygwin) -CC = gcc $(CVARS) -WCC = $(CC) -mwindows $(linkdebug) -HC="/c/program files/help workshop/hcrtf.exe" -xn - -all: $(proj).exe - -depend: $(dotc) - makedepend -Y -f cygwin.mak $(INCLUDES) $^ - -clean: - rm -f *.obj *~ $(proj).exe $(proj).err $(proj).rbj \ - $(proj).RES $(proj).res $(proj).ini *.sbr *.bsc *.o \ - *.plg *.opt *.ncb *.debug *.bak *.gid *.GID - -maintainer-clean: clean - rm -f parser.c *.hlp *.HLP - -# Update the help file if necessary -#$(proj).hlp : $(proj).rtf -# $(HC) $(proj).hpj -# cat $(proj).err - -# Update the resource if necessary -wbres.o: $(proj).rc $(proj).h resource.h - windres --use-temp-file --include-dir .. $< -O coff -o $@ - -# Update the object files if necessary - -parser.c: parser.l - flex -oparser.c -L $< - -#$(proj).exe: $(allobj) $(proj).hlp $(proj).rc -$(proj).exe: $(allobj) $(proj).rc - $(WCC) $(guiflags) $(allobj) \ - -lwsock32 -lwinmm \ - -o $(proj).exe - -# DO NOT DELETE - -winboard.o: config.h ../common.h winboard.h resource.h ../frontend.h -winboard.o: ../backend.h ../lists.h ../moves.h wclipbrd.h wgamelist.h -winboard.o: wedittags.h woptions.h wsockerr.h defaults.h -backend.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h -backend.o: ../parser.h ../moves.h ../zippy.h ../backendz.h -parser.o: config.h ../common.h ../backend.h ../lists.h ../frontend.h -parser.o: ../parser.h ../moves.h -moves.o: config.h ../common.h ../backend.h ../lists.h ../frontend.h -moves.o: ../moves.h ../parser.h -lists.o: config.h ../common.h ../lists.h -gamelist.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h -gamelist.o: ../parser.h -pgntags.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h -pgntags.o: ../parser.h -wedittags.o: config.h ../common.h winboard.h resource.h ../frontend.h -wedittags.o: ../backend.h ../lists.h -wgamelist.o: config.h ../common.h winboard.h resource.h ../frontend.h -wgamelist.o: ../backend.h ../lists.h -zippy.o: config.h ../common.h ../zippy.h ../frontend.h ../backend.h -zippy.o: ../lists.h ../backendz.h -wsockerr.o: wsockerr.h -winboard.o: resource.h -wclipbrd.o: config.h ../common.h winboard.h resource.h ../frontend.h -wclipbrd.o: ../backend.h ../lists.h wclipbrd.h -woptions.o: config.h ../common.h winboard.h resource.h ../backend.h -woptions.o: ../lists.h ../frontend.h woptions.h defaults.h wedittags.h +# +# Makefile for WinBoard, using the GNU Cygwin toolset +# + +# Uncomment both lines to turn on debugging symbols ####### +cdebug= -g +linkdebug= -g +####################################################### + +proj=winboard +allobj= winboard.o backend.o parser.o moves.o lists.o \ + gamelist.o pgntags.o wedittags.o wgamelist.o zippy.o \ + wsockerr.o wbres.o wclipbrd.o woptions.o uci.o \ + wengineo.o wevalgraph.o whistory.o wlayout.o \ + wplugin.o wsnap.o book.o + +dotc= winboard.c backend.c parser.c moves.c lists.c \ + gamelist.c pgntags.c wedittags.c wgamelist.c zippy.c \ + wsockerr.c winboard.rc wclipbrd.c woptions.c uci.c \ + wengineo.c wevalgraph.c whistory.c wlayout.c \ + wplugin.c wsnap.c book.c + +# Currently WinBoard will build either with or without -mno-cygwin +# however, a Cygwin bug in forming the command line to WinMain() is +# exposed if -mno-cygwin is not used. +cygwin= -mno-cygwin + +VPATH= .:.. +CFLAGS= $(cdebug) +INCLUDES= -I. -I.. +CVARS= $(INCLUDES) $(cygwin) +CC = gcc $(CVARS) +WCC = $(CC) -mwindows $(linkdebug) +HC="/c/program files/help workshop/hcrtf.exe" -xn + +all: $(proj).exe + +depend: $(dotc) + makedepend -Y -f cygwin.mak $(INCLUDES) $^ + +clean: + rm -f *.obj *~ $(proj).exe $(proj).err $(proj).rbj \ + $(proj).RES $(proj).res $(proj).ini *.sbr *.bsc *.o \ + *.plg *.opt *.ncb *.debug *.bak *.gid *.GID + +maintainer-clean: clean + rm -f parser.c *.hlp *.HLP + +# Update the help file if necessary +#$(proj).hlp : $(proj).rtf +# $(HC) $(proj).hpj +# cat $(proj).err + +# Update the resource if necessary +wbres.o: $(proj).rc $(proj).h resource.h + windres --use-temp-file --include-dir .. $< -O coff -o $@ + +# Update the object files if necessary + +parser.c: parser.l + flex -oparser.c -L $< + +$(proj).exe: $(allobj) $(proj).hlp $(proj).rc + $(WCC) $(guiflags) $(allobj) \ + -lwsock32 -lwinmm \ + -o $(proj).exe + +# DO NOT DELETE + +winboard.o: config.h ../common.h winboard.h resource.h ../frontend.h +winboard.o: ../backend.h ../lists.h ../moves.h wclipbrd.h wgamelist.h +winboard.o: wedittags.h woptions.h wsockerr.h defaults.h +backend.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h +backend.o: ../parser.h ../moves.h ../zippy.h ../backendz.h +parser.o: config.h ../common.h ../backend.h ../lists.h ../frontend.h +parser.o: ../parser.h ../moves.h +moves.o: config.h ../common.h ../backend.h ../lists.h ../frontend.h +moves.o: ../moves.h ../parser.h +lists.o: config.h ../common.h ../lists.h +gamelist.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h +gamelist.o: ../parser.h +pgntags.o: config.h ../common.h ../frontend.h ../backend.h ../lists.h +pgntags.o: ../parser.h +wedittags.o: config.h ../common.h winboard.h resource.h ../frontend.h +wedittags.o: ../backend.h ../lists.h +wgamelist.o: config.h ../common.h winboard.h resource.h ../frontend.h +wgamelist.o: ../backend.h ../lists.h +zippy.o: config.h ../common.h ../zippy.h ../frontend.h ../backend.h +zippy.o: ../lists.h ../backendz.h +wsockerr.o: wsockerr.h +winboard.o: resource.h +wclipbrd.o: config.h ../common.h winboard.h resource.h ../frontend.h +wclipbrd.o: ../backend.h ../lists.h wclipbrd.h +woptions.o: config.h ../common.h winboard.h resource.h ../backend.h +woptions.o: ../lists.h ../frontend.h woptions.h defaults.h wedittags.h book.o: ../common.h ../backend.h \ No newline at end of file diff --git a/winboard/readme.txt b/winboard/readme.txt index 8ebc2ca..b22e6b4 100644 --- a/winboard/readme.txt +++ b/winboard/readme.txt @@ -1,34 +1,3 @@ - WinBoard 4.3.15m RELEASE NOTES - -Compared to version 4.3.14k described below, this version features - -New command-line options -/rewindIndex=N (for the new auto-increment mode of the loadGameIndex or loadPositionIndex in match mode -/sameColorGames=N (for playing a match where the same player has white all the time) -/egtFormats="..." (for specifying where various end-game tables are installed on the computer) - -New menu items -+ Time-odds factors can be set in the time-control dialog -+ Nr of CPUs for SMP engines can be set in the Options -> UCI dialog -+ Own-Book options can be switched from the Options -> UCI dialog -+ The ScoreIsAbs options can be set from the Options -> Engine dialog -+ New-Variant menu adds Superchess - -General Enhancements: -* WinBoard engines can now also use the Polyglot opening book (implemented as general GUI book) -* New WB-protocol commands memory, cores and egtpath make interactive setting of these parameters - possible on WB engines -* New Polyglot is available that relays the interactive setting of these parameters to UCI engines -* Match mode suports an auto-increment mode, so that all games or positions from a file can be played -* Draw claims with Kings and an arbitrary number of like Bishops (e.g. KBBKB) are accepted - -The source tree in original XBoard 4.2.7 format can now be compiled under Cygwin with the aid -of the cygwin.mak file in the ~/winboard/ subdirectory of the source release. Makefiles for -other compilers are not updated since 4.2.7, as I do not have those compilers. - -Note that this release is a bug-fix for the 4.3.15k release, which had a bug in human-ICS play mode. - - WinBoard 4.3.14k RELEASE NOTES Compared to version 4.3.13 described below, this version features @@ -52,7 +21,7 @@ Bugfixes: * In ICS observing mode game history is now fully accessible * Moves are not fed to engine in zippy mode, when observing a game from a variant unknown to the engine * a problem with loading PGN of FRC games with move disambiguation and initial castling rights was fixed. -* A bug in the clock display that made previous versions of WinBoard crash for tiny displays is fixed +* A bug in the clock display that mad previous versions of WinBoard crash for tiny displays is fixed General enhancements: * variant name displayed in title bar in ICS mode, when not 'normal' diff --git a/winboard/wengineo.c b/winboard/wengineo.c index 0623e3d..994af41 100644 --- a/winboard/wengineo.c +++ b/winboard/wengineo.c @@ -1,751 +1,839 @@ -/* - * Engine output (PV) - * - * Author: Alessandro Scotti (Dec 2005) - * - * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * ------------------------------------------------------------------------ - */ -#include "config.h" - -#include /* required for all Windows applications */ -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "winboard.h" -#include "frontend.h" -#include "backend.h" - -#include "wsnap.h" - -VOID EngineOutputPopUp(); -VOID EngineOutputPopDown(); -BOOL EngineOutputIsUp(); - -#define SHOW_PONDERING - -/* Imports from backend.c */ -char * SavePart(char *str); - -/* Imports from winboard.c */ -extern HWND engineOutputDialog; -extern BOOLEAN engineOutputDialogUp; - -extern HINSTANCE hInst; -extern HWND hwndMain; - -extern WindowPlacement wpEngineOutput; - -/* Module variables */ -#define H_MARGIN 2 -#define V_MARGIN 2 -#define LABEL_V_DISTANCE 1 /* Distance between label and memo */ -#define SPLITTER_SIZE 4 /* Distance between first memo and second label */ - -#define ICON_SIZE 14 - -#define STATE_UNKNOWN -1 -#define STATE_THINKING 0 -#define STATE_IDLE 1 -#define STATE_PONDERING 2 -#define STATE_ANALYZING 3 - -static int windowMode = 1; - -static BOOL needInit = TRUE; - -static HICON hiColorBlack = NULL; -static HICON hiColorWhite = NULL; -static HICON hiColorUnknown = NULL; -static HICON hiClear = NULL; -static HICON hiPondering = NULL; -static HICON hiThinking = NULL; -static HICON hiAnalyzing = NULL; - -static int lastDepth[2] = { -1, -1 }; -static int lastForwardMostMove[2] = { -1, -1 }; -static int engineState[2] = { -1, -1 }; - -typedef struct { - HWND hColorIcon; - HWND hLabel; - HWND hStateIcon; - HWND hStateData; - HWND hLabelNPS; - HWND hMemo; - char * name; - int which; - int depth; - unsigned long nodes; - int score; - int time; - char * pv; - char * hint; - int an_move_index; - int an_move_count; -} EngineOutputData; - -static HICON LoadIconEx( int id ) -{ - return LoadImage( hInst, MAKEINTRESOURCE(id), IMAGE_ICON, ICON_SIZE, ICON_SIZE, 0 ); -} - -static VOID InitializeEngineOutput() -{ - if( needInit ) { - hiColorBlack = LoadIconEx( IDI_BLACK_14 ); - hiColorWhite = LoadIconEx( IDI_WHITE_14 ); - hiColorUnknown = LoadIconEx( IDI_UNKNOWN_14 ); - hiClear = LoadIconEx( IDI_TRANS_14 ); - hiPondering = LoadIconEx( IDI_PONDER_14 ); - hiThinking = LoadIconEx( IDI_CLOCK_14 ); - hiAnalyzing = LoadIconEx( IDI_ANALYZE2_14 ); - needInit = FALSE; - } -} - -static VOID SetControlPos( HWND hDlg, int id, int x, int y, int width, int height ) -{ - HWND hControl = GetDlgItem( hDlg, id ); - - SetWindowPos( hControl, HWND_TOP, x, y, width, height, SWP_NOZORDER ); -} - -#define HIDDEN_X 20000 -#define HIDDEN_Y 20000 - -static VOID HideControl( HWND hDlg, int id ) -{ - HWND hControl = GetDlgItem( hDlg, id ); - RECT rc; - - GetWindowRect( hControl, &rc ); - - /* - Avoid hiding an already hidden control, because that causes many - unnecessary WM_ERASEBKGND messages! - */ - if( rc.left != HIDDEN_X || rc.top != HIDDEN_Y ) { - SetControlPos( hDlg, id, 20000, 20000, 100, 100 ); - } -} - -static int GetControlWidth( HWND hDlg, int id ) -{ - RECT rc; - - GetWindowRect( GetDlgItem( hDlg, id ), &rc ); - - return rc.right - rc.left; -} - -static int GetControlHeight( HWND hDlg, int id ) -{ - RECT rc; - - GetWindowRect( GetDlgItem( hDlg, id ), &rc ); - - return rc.bottom - rc.top; -} - -static int GetHeaderHeight() -{ - int result = GetControlHeight( engineOutputDialog, IDC_EngineLabel1 ); - - if( result < ICON_SIZE ) result = ICON_SIZE; - - return result; -} - -#define ENGINE_COLOR_WHITE 'w' -#define ENGINE_COLOR_BLACK 'b' -#define ENGINE_COLOR_UNKNOWN ' ' - -char GetEngineColor( int which ) -{ - char result = ENGINE_COLOR_UNKNOWN; - - if( which == 0 || which == 1 ) { - ChessProgramState * cps; - - switch (gameMode) { - case MachinePlaysBlack: - case IcsPlayingBlack: - result = ENGINE_COLOR_BLACK; - break; - case MachinePlaysWhite: - case IcsPlayingWhite: - result = ENGINE_COLOR_WHITE; - break; - case AnalyzeMode: - case AnalyzeFile: - result = WhiteOnMove(forwardMostMove) ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; - break; - case TwoMachinesPlay: - cps = (which == 0) ? &first : &second; - result = cps->twoMachinesColor[0]; - result = result == 'w' ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; - break; - } - } - - return result; -} - -char GetActiveEngineColor() -{ - char result = ENGINE_COLOR_UNKNOWN; - - if( gameMode == TwoMachinesPlay ) { - result = WhiteOnMove(forwardMostMove) ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; - } - - return result; -} - -static int IsEnginePondering( int which ) -{ - int result = FALSE; - - switch (gameMode) { - case MachinePlaysBlack: - case IcsPlayingBlack: - if( WhiteOnMove(forwardMostMove) ) result = TRUE; - break; - case MachinePlaysWhite: - case IcsPlayingWhite: - if( ! WhiteOnMove(forwardMostMove) ) result = TRUE; - break; - case TwoMachinesPlay: - if( GetActiveEngineColor() != ENGINE_COLOR_UNKNOWN ) { - if( GetEngineColor( which ) != GetActiveEngineColor() ) result = TRUE; - } - break; - } - - return result; -} - -static VOID PositionControlSet( HWND hDlg, int x, int y, int clientWidth, int memoHeight, int idColor, int idEngineLabel, int idNPS, int idMemo, int idStateIcon, int idStateData ) -{ - int label_x = x + ICON_SIZE + H_MARGIN; - int label_h = GetControlHeight( hDlg, IDC_EngineLabel1 ); - int label_y = y + ICON_SIZE - label_h; - int nps_w = GetControlWidth( hDlg, IDC_Engine1_NPS ); - int nps_x = clientWidth - H_MARGIN - nps_w; - int state_data_w = GetControlWidth( hDlg, IDC_StateData1 ); - int state_data_x = nps_x - H_MARGIN - state_data_w; - int state_icon_x = state_data_x - ICON_SIZE - 2; - int max_w = clientWidth - 2*H_MARGIN; - int memo_y = y + ICON_SIZE + LABEL_V_DISTANCE; - - SetControlPos( hDlg, idColor, x, y, ICON_SIZE, ICON_SIZE ); - SetControlPos( hDlg, idEngineLabel, label_x, label_y, state_icon_x - label_x, label_h ); - SetControlPos( hDlg, idStateIcon, state_icon_x, y, ICON_SIZE, ICON_SIZE ); - SetControlPos( hDlg, idStateData, state_data_x, label_y, state_data_w, label_h ); - SetControlPos( hDlg, idNPS, nps_x, label_y, nps_w, label_h ); - SetControlPos( hDlg, idMemo, x, memo_y, max_w, memoHeight ); -} - -static VOID ResizeWindowControls( HWND hDlg, int mode ) -{ - RECT rc; - int headerHeight = GetHeaderHeight(); - int labelHeight = GetControlHeight( hDlg, IDC_EngineLabel1 ); - int labelOffset = H_MARGIN + ICON_SIZE + H_MARGIN; - int labelDeltaY = ICON_SIZE - labelHeight; - int clientWidth; - int clientHeight; - int maxControlWidth; - int npsWidth; - - /* Initialize variables */ - GetClientRect( hDlg, &rc ); - - clientWidth = rc.right - rc.left; - clientHeight = rc.bottom - rc.top; - - maxControlWidth = clientWidth - 2*H_MARGIN; - - npsWidth = GetControlWidth( hDlg, IDC_Engine1_NPS ); - - /* Resize controls */ - if( mode == 0 ) { - /* One engine */ - PositionControlSet( hDlg, H_MARGIN, V_MARGIN, - clientWidth, - clientHeight - V_MARGIN - LABEL_V_DISTANCE - headerHeight- V_MARGIN, - IDC_Color1, IDC_EngineLabel1, IDC_Engine1_NPS, IDC_EngineMemo1, IDC_StateIcon1, IDC_StateData1 ); - - /* Hide controls for the second engine */ - HideControl( hDlg, IDC_Color2 ); - HideControl( hDlg, IDC_EngineLabel2 ); - HideControl( hDlg, IDC_StateIcon2 ); - HideControl( hDlg, IDC_StateData2 ); - HideControl( hDlg, IDC_Engine2_NPS ); - HideControl( hDlg, IDC_EngineMemo2 ); - SendDlgItemMessage( hDlg, IDC_EngineMemo2, WM_SETTEXT, 0, (LPARAM) "" ); - /* TODO: we should also hide/disable them!!! what about tab stops?!?! */ - } - else { - /* Two engines */ - int memo_h = (clientHeight - headerHeight*2 - V_MARGIN*2 - LABEL_V_DISTANCE*2 - SPLITTER_SIZE) / 2; - int header1_y = V_MARGIN; - int header2_y = V_MARGIN + headerHeight + LABEL_V_DISTANCE + memo_h + SPLITTER_SIZE; - - PositionControlSet( hDlg, H_MARGIN, header1_y, clientWidth, memo_h, - IDC_Color1, IDC_EngineLabel1, IDC_Engine1_NPS, IDC_EngineMemo1, IDC_StateIcon1, IDC_StateData1 ); - - PositionControlSet( hDlg, H_MARGIN, header2_y, clientWidth, memo_h, - IDC_Color2, IDC_EngineLabel2, IDC_Engine2_NPS, IDC_EngineMemo2, IDC_StateIcon2, IDC_StateData2 ); - } - - InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo1), NULL, FALSE ); - InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo2), NULL, FALSE ); -} - -static VOID SetDisplayMode( int mode ) -{ - if( windowMode != mode ) { - windowMode = mode; - - ResizeWindowControls( engineOutputDialog, mode ); - } -} - -static VOID VerifyDisplayMode() -{ - int mode; - - /* Get proper mode for current game */ - switch( gameMode ) { - case AnalyzeMode: - case AnalyzeFile: - case MachinePlaysWhite: - case MachinePlaysBlack: - case IcsPlayingWhite: - case IcsPlayingBlack: - mode = 0; - break; - case TwoMachinesPlay: - mode = 1; - break; - default: - /* Do not change */ - return; - } - - SetDisplayMode( mode ); -} - -static VOID InsertIntoMemo( HWND hMemo, char * text ) -{ - SendMessage( hMemo, EM_SETSEL, 0, 0 ); - - SendMessage( hMemo, EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); -} - -static VOID SetIcon( HWND hControl, HICON hIcon ) -{ - if( hIcon != NULL ) { - SendMessage( hControl, STM_SETICON, (WPARAM) hIcon, 0 ); - } -} - -static VOID SetEngineColorIcon( HWND hControl, int which ) -{ - char color = GetEngineColor(which); - HICON hicon = NULL; - - if( color == ENGINE_COLOR_BLACK ) - hicon = hiColorBlack; - else if( color == ENGINE_COLOR_WHITE ) - hicon = hiColorWhite; - else - hicon = hiColorUnknown; - - SetIcon( hControl, hicon ); -} - -static SetEngineState( int which, int state, char * state_data ) -{ - int x_which = 1 - which; - HWND hStateIcon = GetDlgItem( engineOutputDialog, which == 0 ? IDC_StateIcon1 : IDC_StateIcon2 ); - HWND hStateData = GetDlgItem( engineOutputDialog, which == 0 ? IDC_StateData1 : IDC_StateData2 ); - - if( engineState[ which ] != state ) { - engineState[ which ] = state; - - switch( state ) { - case STATE_THINKING: - SetIcon( hStateIcon, hiThinking ); - if( engineState[ x_which ] == STATE_THINKING ) { - SetEngineState( x_which, STATE_IDLE, "" ); - } - break; - case STATE_PONDERING: - SetIcon( hStateIcon, hiPondering ); - break; - case STATE_ANALYZING: - SetIcon( hStateIcon, hiAnalyzing ); - break; - default: - SetIcon( hStateIcon, hiClear ); - break; - } - } - - if( state_data != 0 ) { - SetWindowText( hStateData, state_data ); - } -} - -#define MAX_NAME_LENGTH 32 - -static VOID UpdateControls( EngineOutputData * ed ) -{ - BOOL isPondering = FALSE; - - char s_label[MAX_NAME_LENGTH + 32]; - - char * name = ed->name; - - /* Label */ - if( name == 0 || *name == '\0' ) { - name = "?"; - } - - strncpy( s_label, name, MAX_NAME_LENGTH ); - s_label[ MAX_NAME_LENGTH-1 ] = '\0'; - -#ifdef SHOW_PONDERING - if( IsEnginePondering( ed->which ) ) { - char buf[8]; - - buf[0] = '\0'; - - if( ed->hint != 0 && *ed->hint != '\0' ) { - strncpy( buf, ed->hint, sizeof(buf) ); - buf[sizeof(buf)-1] = '\0'; - } - else if( ed->pv != 0 && *ed->pv != '\0' ) { - char * sep = strchr( ed->pv, ' ' ); - int buflen = sizeof(buf); - - if( sep != NULL ) { - buflen = sep - ed->pv + 1; - if( buflen > sizeof(buf) ) buflen = sizeof(buf); - } - - strncpy( buf, ed->pv, buflen ); - buf[ buflen-1 ] = '\0'; - } - - SetEngineState( ed->which, STATE_PONDERING, buf ); - } - else if( gameMode == TwoMachinesPlay ) { - SetEngineState( ed->which, STATE_THINKING, "" ); - } - else if( gameMode == AnalyzeMode || gameMode == AnalyzeFile ) { - char buf[64]; - int time_secs = ed->time / 100; - int time_mins = time_secs / 60; - - buf[0] = '\0'; - - if( ed->an_move_index != 0 && ed->an_move_count != 0 && *ed->hint != '\0' ) { - char mov[16]; - - strncpy( mov, ed->hint, sizeof(mov) ); - mov[ sizeof(mov)-1 ] = '\0'; - - sprintf( buf, "%d/%d: %s [%02d:%02d:%02d]", ed->an_move_index, ed->an_move_count, mov, time_mins / 60, time_mins % 60, time_secs % 60 ); - } - - SetEngineState( ed->which, STATE_ANALYZING, buf ); - } - else { - SetEngineState( ed->which, STATE_IDLE, "" ); - } -#endif - - SetWindowText( ed->hLabel, s_label ); - - s_label[0] = '\0'; - - if( ed->time > 0 && ed->nodes > 0 ) { - unsigned long nps_100 = ed->nodes / ed->time; - - if( nps_100 < 100000 ) { - sprintf( s_label, "NPS: %lu", nps_100 * 100 ); - } - else { - sprintf( s_label, "NPS: %.1fk", nps_100 / 10.0 ); - } - } - - SetWindowText( ed->hLabelNPS, s_label ); - - /* Memo */ - if( ed->pv != 0 && *ed->pv != '\0' ) { - char s_nodes[24]; - char s_score[16]; - char s_time[24]; - char buf[256]; - int buflen; - int time_secs = ed->time / 100; - int time_cent = ed->time % 100; - - /* Nodes */ - if( ed->nodes < 1000000 ) { - sprintf( s_nodes, "%lu", ed->nodes ); - } - else { - sprintf( s_nodes, "%.1fM", ed->nodes / 1000000.0 ); - } - - /* Score */ - if( ed->score > 0 ) { - sprintf( s_score, "+%.2f", ed->score / 100.0 ); - } - else { - sprintf( s_score, "%.2f", ed->score / 100.0 ); - } - - /* Time */ - sprintf( s_time, "%d:%02d.%02d", time_secs / 60, time_secs % 60, time_cent ); - - /* Put all together... */ - sprintf( buf, "%3d\t%s\t%s\t%s\t", ed->depth, s_score, s_nodes, s_time ); - - /* Add PV */ - buflen = strlen(buf); - - strncpy( buf + buflen, ed->pv, sizeof(buf) - buflen ); - - buf[ sizeof(buf) - 3 ] = '\0'; - - strcat( buf + buflen, "\r\n" ); - - /* Update memo */ - InsertIntoMemo( ed->hMemo, buf ); - } - - /* Colors */ - SetEngineColorIcon( ed->hColorIcon, ed->which ); -} - -LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) -{ - static SnapData sd; - - switch (message) { - case WM_INITDIALOG: - if( engineOutputDialog == NULL ) { - engineOutputDialog = hDlg; - - RestoreWindowPlacement( hDlg, &wpEngineOutput ); /* Restore window placement */ - - ResizeWindowControls( hDlg, windowMode ); - - SetEngineState( 0, STATE_IDLE, "" ); - SetEngineState( 1, STATE_IDLE, "" ); - } - - return FALSE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDOK: - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - default: - break; - } - - break; - - case WM_GETMINMAXINFO: - { - MINMAXINFO * mmi = (MINMAXINFO *) lParam; - - mmi->ptMinTrackSize.x = 100; - mmi->ptMinTrackSize.y = 160; - } - break; - - case WM_CLOSE: - EngineOutputPopDown(); - break; - - case WM_SIZE: - ResizeWindowControls( hDlg, windowMode ); - break; - - case WM_ENTERSIZEMOVE: - return OnEnterSizeMove( &sd, hDlg, wParam, lParam ); - - case WM_SIZING: - return OnSizing( &sd, hDlg, wParam, lParam ); - - case WM_MOVING: - return OnMoving( &sd, hDlg, wParam, lParam ); - - case WM_EXITSIZEMOVE: - return OnExitSizeMove( &sd, hDlg, wParam, lParam ); - } - - return FALSE; -} - -VOID EngineOutputPopUp() -{ - FARPROC lpProc; - - if( needInit ) { - InitializeEngineOutput(); - } - - CheckMenuItem(GetMenu(hwndMain), IDM_ShowEngineOutput, MF_CHECKED); - - if( engineOutputDialog ) { - SendMessage( engineOutputDialog, WM_INITDIALOG, 0, 0 ); - - if( ! engineOutputDialogUp ) { - ShowWindow(engineOutputDialog, SW_SHOW); - } - } - else { - lpProc = MakeProcInstance( (FARPROC) EngineOutputProc, hInst ); - - /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */ - CreateDialog( hInst, MAKEINTRESOURCE(DLG_EngineOutput), hwndMain, (DLGPROC)lpProc ); - - FreeProcInstance(lpProc); - } - - engineOutputDialogUp = TRUE; - ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output -} - -VOID EngineOutputPopDown() -{ - CheckMenuItem(GetMenu(hwndMain), IDM_ShowEngineOutput, MF_UNCHECKED); - - if( engineOutputDialog ) { - ShowWindow(engineOutputDialog, SW_HIDE); - } - - engineOutputDialogUp = FALSE; - ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output -} - -BOOL EngineOutputIsUp() -{ - return engineOutputDialogUp; -} - -VOID EngineOutputUpdate( FrontEndProgramStats * stats ) -{ - EngineOutputData ed; - BOOL clearMemo = FALSE; - int which; - int depth; - - if( stats == 0 ) { - SetEngineState( 0, STATE_IDLE, "" ); - SetEngineState( 1, STATE_IDLE, "" ); - return; - } - - which = stats->which; - depth = stats->depth; - - if( which < 0 || which > 1 || depth < 0 || stats->time < 0 || stats->pv == 0 ) { - return; - } - - if( engineOutputDialog == NULL ) { - return; - } - - VerifyDisplayMode(); - - ed.which = which; - ed.depth = depth; - ed.nodes = stats->nodes; - ed.score = stats->score; - ed.time = stats->time; - ed.pv = stats->pv; - ed.hint = stats->hint; - ed.an_move_index = stats->an_move_index; - ed.an_move_count = stats->an_move_count; - - /* Get target control */ - if( which == 0 ) { - ed.hColorIcon = GetDlgItem( engineOutputDialog, IDC_Color1 ); - ed.hLabel = GetDlgItem( engineOutputDialog, IDC_EngineLabel1 ); - ed.hStateIcon = GetDlgItem( engineOutputDialog, IDC_StateIcon1 ); - ed.hStateData = GetDlgItem( engineOutputDialog, IDC_StateData1 ); - ed.hLabelNPS = GetDlgItem( engineOutputDialog, IDC_Engine1_NPS ); - ed.hMemo = GetDlgItem( engineOutputDialog, IDC_EngineMemo1 ); - ed.name = first.tidy; - } - else { - ed.hColorIcon = GetDlgItem( engineOutputDialog, IDC_Color2 ); - ed.hLabel = GetDlgItem( engineOutputDialog, IDC_EngineLabel2 ); - ed.hStateIcon = GetDlgItem( engineOutputDialog, IDC_StateIcon2 ); - ed.hStateData = GetDlgItem( engineOutputDialog, IDC_StateData2 ); - ed.hLabelNPS = GetDlgItem( engineOutputDialog, IDC_Engine2_NPS ); - ed.hMemo = GetDlgItem( engineOutputDialog, IDC_EngineMemo2 ); - ed.name = second.tidy; - } - - /* Clear memo if needed */ - if( lastDepth[which] > depth || (lastDepth[which] == depth && depth <= 1) ) { - clearMemo = TRUE; - } - - if( lastForwardMostMove[which] != forwardMostMove ) { - clearMemo = TRUE; - } - - if( clearMemo ) { - SendMessage( ed.hMemo, WM_SETTEXT, 0, (LPARAM) "" ); - } - - /* Update */ - lastDepth[which] = depth; - lastForwardMostMove[which] = forwardMostMove; - - if( ed.pv != 0 && ed.pv[0] == ' ' ) { - if( strncmp( ed.pv, " no PV", 6 ) == 0 ) { /* Hack on hack! :-O */ - ed.pv = ""; - } - } - - UpdateControls( &ed ); -} +/* + * Engine output (PV) + * + * Author: Alessandro Scotti (Dec 2005) + * + * ------------------------------------------------------------------------ + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * ------------------------------------------------------------------------ + */ +#include "config.h" + +#include /* required for all Windows applications */ +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "winboard.h" +#include "frontend.h" +#include "backend.h" + +#include "wsnap.h" + +// [HGM] define numbers to indicate icons, for referring to them in platform-independent way +#define nColorBlack 1 +#define nColorWhite 2 +#define nColorUnknown 3 +#define nClear 4 +#define nPondering 5 +#define nThinking 6 +#define nAnalyzing 7 + +HICON icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle + +// [HGM] same for output fields (note that there are two of each type, one per color) +#define nColorIcon 1 +#define nStateIcon 2 +#define nLabel 3 +#define nStateData 4 +#define nLabelNPS 5 +#define nMemo 6 + +HWND outputField[2][7]; // [HGM] front-end array to translate output field to window handle + +void EngineOutputPopUp(); +void EngineOutputPopDown(); +int EngineOutputIsUp(); + +#define SHOW_PONDERING + +/* Imports from backend.c */ +char * SavePart(char *str); +extern int opponentKibitzes; + +/* Imports from winboard.c */ +extern HWND engineOutputDialog; +extern int engineOutputDialogUp; + +extern HINSTANCE hInst; +extern HWND hwndMain; + +extern WindowPlacement wpEngineOutput; + +/* Module variables */ +#define H_MARGIN 2 +#define V_MARGIN 2 +#define LABEL_V_DISTANCE 1 /* Distance between label and memo */ +#define SPLITTER_SIZE 4 /* Distance between first memo and second label */ + +#define ICON_SIZE 14 + +#define STATE_UNKNOWN -1 +#define STATE_THINKING 0 +#define STATE_IDLE 1 +#define STATE_PONDERING 2 +#define STATE_ANALYZING 3 + +static int windowMode = 1; + +static int needInit = TRUE; + +static int lastDepth[2] = { -1, -1 }; +static int lastForwardMostMove[2] = { -1, -1 }; +static int engineState[2] = { -1, -1 }; + +typedef struct { +// HWND hColorIcon; // [HGM] the output-control handles are no loger passed, +// HWND hLabel; // to give better front-end / back-end separation +// HWND hStateIcon; // the front-end routines now get them from a (front-end) +// HWND hStateData; // table, indexed by output-field indicators. +// HWND hLabelNPS; +// HWND hMemo; + char * name; + int which; + int depth; + unsigned long nodes; + int score; + int time; + char * pv; + char * hint; + int an_move_index; + int an_move_count; +} EngineOutputData; + +static VerifyDisplayMode(); +static void UpdateControls( EngineOutputData * ed ); +static SetEngineState( int which, int state, char * state_data ); + +// front end +static HICON LoadIconEx( int id ) +{ + return LoadImage( hInst, MAKEINTRESOURCE(id), IMAGE_ICON, ICON_SIZE, ICON_SIZE, 0 ); +} + +// [HGM] the platform-dependent way of indicating where output should go is now all +// concentrated here, where a table of platform-dependent handles are initialized. +// This cleanses most other routines of front-end stuff, so they can go into the back end. +static void InitializeEngineOutput() +{ + // if( needInit ) { // needInit was already tested before call + // [HGM] made this into a table, rather than separate global variables + icons[nColorBlack] = LoadIconEx( IDI_BLACK_14 ); + icons[nColorWhite] = LoadIconEx( IDI_WHITE_14 ); + icons[nColorUnknown] = LoadIconEx( IDI_UNKNOWN_14 ); + icons[nClear] = LoadIconEx( IDI_TRANS_14 ); + icons[nPondering] = LoadIconEx( IDI_PONDER_14 ); + icons[nThinking] = LoadIconEx( IDI_CLOCK_14 ); + icons[nAnalyzing] = LoadIconEx( IDI_ANALYZE2_14 ); + + // [HGM] also make a table of handles to output controls + // Note that engineOutputDialog must be defined first! + outputField[0][nColorIcon] = GetDlgItem( engineOutputDialog, IDC_Color1 ); + outputField[0][nLabel] = GetDlgItem( engineOutputDialog, IDC_EngineLabel1 ); + outputField[0][nStateIcon] = GetDlgItem( engineOutputDialog, IDC_StateIcon1 ); + outputField[0][nStateData] = GetDlgItem( engineOutputDialog, IDC_StateData1 ); + outputField[0][nLabelNPS] = GetDlgItem( engineOutputDialog, IDC_Engine1_NPS ); + outputField[0][nMemo] = GetDlgItem( engineOutputDialog, IDC_EngineMemo1 ); + + outputField[1][nColorIcon] = GetDlgItem( engineOutputDialog, IDC_Color2 ); + outputField[1][nLabel] = GetDlgItem( engineOutputDialog, IDC_EngineLabel2 ); + outputField[1][nStateIcon] = GetDlgItem( engineOutputDialog, IDC_StateIcon2 ); + outputField[1][nStateData] = GetDlgItem( engineOutputDialog, IDC_StateData2 ); + outputField[1][nLabelNPS] = GetDlgItem( engineOutputDialog, IDC_Engine2_NPS ); + outputField[1][nMemo] = GetDlgItem( engineOutputDialog, IDC_EngineMemo2 ); +// needInit = FALSE; +// } +} + +// front end +static void SetControlPos( HWND hDlg, int id, int x, int y, int width, int height ) +{ + HWND hControl = GetDlgItem( hDlg, id ); + + SetWindowPos( hControl, HWND_TOP, x, y, width, height, SWP_NOZORDER ); +} + +#define HIDDEN_X 20000 +#define HIDDEN_Y 20000 + +// front end +static void HideControl( HWND hDlg, int id ) +{ + HWND hControl = GetDlgItem( hDlg, id ); + RECT rc; + + GetWindowRect( hControl, &rc ); + + /* + Avoid hiding an already hidden control, because that causes many + unnecessary WM_ERASEBKGND messages! + */ + if( rc.left != HIDDEN_X || rc.top != HIDDEN_Y ) { + SetControlPos( hDlg, id, 20000, 20000, 100, 100 ); + } +} + +// front end, although we might make GetWindowRect front end instead +static int GetControlWidth( HWND hDlg, int id ) +{ + RECT rc; + + GetWindowRect( GetDlgItem( hDlg, id ), &rc ); + + return rc.right - rc.left; +} + +// front end? +static int GetControlHeight( HWND hDlg, int id ) +{ + RECT rc; + + GetWindowRect( GetDlgItem( hDlg, id ), &rc ); + + return rc.bottom - rc.top; +} + +static int GetHeaderHeight() +{ + int result = GetControlHeight( engineOutputDialog, IDC_EngineLabel1 ); + + if( result < ICON_SIZE ) result = ICON_SIZE; + + return result; +} + +// The size calculations should be backend? If setControlPos is a platform-dependent way of doing things, +// a platform-independent wrapper for it should be supplied. +static void PositionControlSet( HWND hDlg, int x, int y, int clientWidth, int memoHeight, int idColor, int idEngineLabel, int idNPS, int idMemo, int idStateIcon, int idStateData ) +{ + int label_x = x + ICON_SIZE + H_MARGIN; + int label_h = GetControlHeight( hDlg, IDC_EngineLabel1 ); + int label_y = y + ICON_SIZE - label_h; + int nps_w = GetControlWidth( hDlg, IDC_Engine1_NPS ); + int nps_x = clientWidth - H_MARGIN - nps_w; + int state_data_w = GetControlWidth( hDlg, IDC_StateData1 ); + int state_data_x = nps_x - H_MARGIN - state_data_w; + int state_icon_x = state_data_x - ICON_SIZE - 2; + int max_w = clientWidth - 2*H_MARGIN; + int memo_y = y + ICON_SIZE + LABEL_V_DISTANCE; + + SetControlPos( hDlg, idColor, x, y, ICON_SIZE, ICON_SIZE ); + SetControlPos( hDlg, idEngineLabel, label_x, label_y, state_icon_x - label_x, label_h ); + SetControlPos( hDlg, idStateIcon, state_icon_x, y, ICON_SIZE, ICON_SIZE ); + SetControlPos( hDlg, idStateData, state_data_x, label_y, state_data_w, label_h ); + SetControlPos( hDlg, idNPS, nps_x, label_y, nps_w, label_h ); + SetControlPos( hDlg, idMemo, x, memo_y, max_w, memoHeight ); +} + +// Also here some of the size calculations should go to the back end, and their actual application to a front-end routine +static void ResizeWindowControls( HWND hDlg, int mode ) +{ + RECT rc; + int headerHeight = GetHeaderHeight(); + int labelHeight = GetControlHeight( hDlg, IDC_EngineLabel1 ); + int labelOffset = H_MARGIN + ICON_SIZE + H_MARGIN; + int labelDeltaY = ICON_SIZE - labelHeight; + int clientWidth; + int clientHeight; + int maxControlWidth; + int npsWidth; + + /* Initialize variables */ + GetClientRect( hDlg, &rc ); + + clientWidth = rc.right - rc.left; + clientHeight = rc.bottom - rc.top; + + maxControlWidth = clientWidth - 2*H_MARGIN; + + npsWidth = GetControlWidth( hDlg, IDC_Engine1_NPS ); + + /* Resize controls */ + if( mode == 0 ) { + /* One engine */ + PositionControlSet( hDlg, H_MARGIN, V_MARGIN, + clientWidth, + clientHeight - V_MARGIN - LABEL_V_DISTANCE - headerHeight- V_MARGIN, + IDC_Color1, IDC_EngineLabel1, IDC_Engine1_NPS, IDC_EngineMemo1, IDC_StateIcon1, IDC_StateData1 ); + + /* Hide controls for the second engine */ + HideControl( hDlg, IDC_Color2 ); + HideControl( hDlg, IDC_EngineLabel2 ); + HideControl( hDlg, IDC_StateIcon2 ); + HideControl( hDlg, IDC_StateData2 ); + HideControl( hDlg, IDC_Engine2_NPS ); + HideControl( hDlg, IDC_EngineMemo2 ); + SendDlgItemMessage( hDlg, IDC_EngineMemo2, WM_SETTEXT, 0, (LPARAM) "" ); + /* TODO: we should also hide/disable them!!! what about tab stops?!?! */ + } + else { + /* Two engines */ + int memo_h = (clientHeight - headerHeight*2 - V_MARGIN*2 - LABEL_V_DISTANCE*2 - SPLITTER_SIZE) / 2; + int header1_y = V_MARGIN; + int header2_y = V_MARGIN + headerHeight + LABEL_V_DISTANCE + memo_h + SPLITTER_SIZE; + + PositionControlSet( hDlg, H_MARGIN, header1_y, clientWidth, memo_h, + IDC_Color1, IDC_EngineLabel1, IDC_Engine1_NPS, IDC_EngineMemo1, IDC_StateIcon1, IDC_StateData1 ); + + PositionControlSet( hDlg, H_MARGIN, header2_y, clientWidth, memo_h, + IDC_Color2, IDC_EngineLabel2, IDC_Engine2_NPS, IDC_EngineMemo2, IDC_StateIcon2, IDC_StateData2 ); + } + + InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo1), NULL, FALSE ); + InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo2), NULL, FALSE ); +} + +// front end. Actual printing of PV lines into the output field +static void InsertIntoMemo( int which, char * text ) +{ + SendMessage( outputField[which][nMemo], EM_SETSEL, 0, 0 ); + + SendMessage( outputField[which][nMemo], EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); +} + +// front end. Associates an icon with an output field ("control" in Windows jargon). +// [HGM] let it find out the output field from the 'which' number by itself +static void SetIcon( int which, int field, int nIcon ) +{ + + if( nIcon != 0 ) { + SendMessage( outputField[which][field], STM_SETICON, (WPARAM) icons[nIcon], 0 ); + } +} + +// front end wrapper for SetWindowText, taking control number in stead of handle +void DoSetWindowText(int which, int field, char *s_label) +{ + SetWindowText( outputField[which][field], s_label ); +} + +// This seems pure front end +LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) +{ + static SnapData sd; + + switch (message) { + case WM_INITDIALOG: + if( engineOutputDialog == NULL ) { + engineOutputDialog = hDlg; + + RestoreWindowPlacement( hDlg, &wpEngineOutput ); /* Restore window placement */ + + ResizeWindowControls( hDlg, windowMode ); + + SetEngineState( 0, STATE_IDLE, "" ); + SetEngineState( 1, STATE_IDLE, "" ); + } + + return FALSE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + default: + break; + } + + break; + + case WM_GETMINMAXINFO: + { + MINMAXINFO * mmi = (MINMAXINFO *) lParam; + + mmi->ptMinTrackSize.x = 100; + mmi->ptMinTrackSize.y = 160; + } + break; + + case WM_CLOSE: + EngineOutputPopDown(); + break; + + case WM_SIZE: + ResizeWindowControls( hDlg, windowMode ); + break; + + case WM_ENTERSIZEMOVE: + return OnEnterSizeMove( &sd, hDlg, wParam, lParam ); + + case WM_SIZING: + return OnSizing( &sd, hDlg, wParam, lParam ); + + case WM_MOVING: + return OnMoving( &sd, hDlg, wParam, lParam ); + + case WM_EXITSIZEMOVE: + return OnExitSizeMove( &sd, hDlg, wParam, lParam ); + } + + return FALSE; +} + +// front end +void EngineOutputPopUp() +{ + FARPROC lpProc; + + CheckMenuItem(GetMenu(hwndMain), IDM_ShowEngineOutput, MF_CHECKED); + + if( engineOutputDialog ) { + SendMessage( engineOutputDialog, WM_INITDIALOG, 0, 0 ); + + if( ! engineOutputDialogUp ) { + ShowWindow(engineOutputDialog, SW_SHOW); + } + } + else { + lpProc = MakeProcInstance( (FARPROC) EngineOutputProc, hInst ); + + /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */ + CreateDialog( hInst, MAKEINTRESOURCE(DLG_EngineOutput), hwndMain, (DLGPROC)lpProc ); + + FreeProcInstance(lpProc); + } + + // [HGM] displaced to after creation of dialog, to allow initialization of output fields + if( needInit ) { + InitializeEngineOutput(); + needInit = FALSE; + } + + engineOutputDialogUp = TRUE; +} + +// front end +void EngineOutputPopDown() +{ + CheckMenuItem(GetMenu(hwndMain), IDM_ShowEngineOutput, MF_UNCHECKED); + + if( engineOutputDialog ) { + ShowWindow(engineOutputDialog, SW_HIDE); + } + + engineOutputDialogUp = FALSE; +} + +// front end. [HGM] Takes handle of output control from table, so only number is passed +void DoClearMemo(int which) +{ + SendMessage( outputField[which][nMemo], WM_SETTEXT, 0, (LPARAM) "" ); +} + +//------------------------ pure back-end routines ------------------------------- + + +// back end, due to front-end wrapper for SetWindowText, and new SetIcon arguments +static SetEngineState( int which, int state, char * state_data ) +{ + int x_which = 1 - which; + + if( engineState[ which ] != state ) { + engineState[ which ] = state; + + switch( state ) { + case STATE_THINKING: + SetIcon( which, nStateIcon, nThinking ); + if( engineState[ x_which ] == STATE_THINKING ) { + SetEngineState( x_which, STATE_IDLE, "" ); + } + break; + case STATE_PONDERING: + SetIcon( which, nStateIcon, nPondering ); + break; + case STATE_ANALYZING: + SetIcon( which, nStateIcon, nAnalyzing ); + break; + default: + SetIcon( which, nStateIcon, nClear ); + break; + } + } + + if( state_data != 0 ) { + DoSetWindowText( which, nStateData, state_data ); + } +} + +// back end, now the front-end wrapper ClearMemo is used, and ed no longer contains handles. +void EngineOutputUpdate( FrontEndProgramStats * stats ) +{ + EngineOutputData ed; + int clearMemo = FALSE; + int which; + int depth; + + if( stats == 0 ) { + SetEngineState( 0, STATE_IDLE, "" ); + SetEngineState( 1, STATE_IDLE, "" ); + return; + } + + if(gameMode == IcsObserving) return; // [HGM] kibitz: shut up engine if we are observing an ICS game + + which = stats->which; + depth = stats->depth; + + if( which < 0 || which > 1 || depth < 0 || stats->time < 0 || stats->pv == 0 ) { + return; + } + + if( engineOutputDialog == NULL ) { + return; + } + + VerifyDisplayMode(); + + ed.which = which; + ed.depth = depth; + ed.nodes = stats->nodes; + ed.score = stats->score; + ed.time = stats->time; + ed.pv = stats->pv; + ed.hint = stats->hint; + ed.an_move_index = stats->an_move_index; + ed.an_move_count = stats->an_move_count; + + /* Get target control. [HGM] this is moved to front end, which get them from a table */ + if( which == 0 ) { + ed.name = first.tidy; + } + else { + ed.name = second.tidy; + } + + /* Clear memo if needed */ + if( lastDepth[which] > depth || (lastDepth[which] == depth && depth <= 1) ) { + clearMemo = TRUE; + } + + if( lastForwardMostMove[which] != forwardMostMove ) { + clearMemo = TRUE; + } + + if( clearMemo ) DoClearMemo(which); + + /* Update */ + lastDepth[which] = depth; + lastForwardMostMove[which] = forwardMostMove; + + if( ed.pv != 0 && ed.pv[0] == ' ' ) { + if( strncmp( ed.pv, " no PV", 6 ) == 0 ) { /* Hack on hack! :-O */ + ed.pv = ""; + } + } + + UpdateControls( &ed ); +} + +#define ENGINE_COLOR_WHITE 'w' +#define ENGINE_COLOR_BLACK 'b' +#define ENGINE_COLOR_UNKNOWN ' ' + +// pure back end +char GetEngineColor( int which ) +{ + char result = ENGINE_COLOR_UNKNOWN; + + if( which == 0 || which == 1 ) { + ChessProgramState * cps; + + switch (gameMode) { + case MachinePlaysBlack: + case IcsPlayingBlack: + result = ENGINE_COLOR_BLACK; + break; + case MachinePlaysWhite: + case IcsPlayingWhite: + result = ENGINE_COLOR_WHITE; + break; + case AnalyzeMode: + case AnalyzeFile: + result = WhiteOnMove(forwardMostMove) ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; + break; + case TwoMachinesPlay: + cps = (which == 0) ? &first : &second; + result = cps->twoMachinesColor[0]; + result = result == 'w' ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; + break; + } + } + + return result; +} + +// pure back end +char GetActiveEngineColor() +{ + char result = ENGINE_COLOR_UNKNOWN; + + if( gameMode == TwoMachinesPlay ) { + result = WhiteOnMove(forwardMostMove) ? ENGINE_COLOR_WHITE : ENGINE_COLOR_BLACK; + } + + return result; +} + +// pure back end +static int IsEnginePondering( int which ) +{ + int result = FALSE; + + switch (gameMode) { + case MachinePlaysBlack: + case IcsPlayingBlack: + if( WhiteOnMove(forwardMostMove) ) result = TRUE; + break; + case MachinePlaysWhite: + case IcsPlayingWhite: + if( ! WhiteOnMove(forwardMostMove) ) result = TRUE; + break; + case TwoMachinesPlay: + if( GetActiveEngineColor() != ENGINE_COLOR_UNKNOWN ) { + if( GetEngineColor( which ) != GetActiveEngineColor() ) result = TRUE; + } + break; + } + + return result; +} + +// back end +static void SetDisplayMode( int mode ) +{ + if( windowMode != mode ) { + windowMode = mode; + + ResizeWindowControls( engineOutputDialog, mode ); + } +} + +// pure back end +static VerifyDisplayMode() +{ + int mode; + + /* Get proper mode for current game */ + switch( gameMode ) { + case AnalyzeMode: + case AnalyzeFile: + case MachinePlaysWhite: + case MachinePlaysBlack: + mode = 0; + break; + case IcsPlayingWhite: + case IcsPlayingBlack: + mode = appData.zippyPlay && opponentKibitzes; // [HGM] kibitz + break; + case TwoMachinesPlay: + mode = 1; + break; + default: + /* Do not change */ + return; + } + + SetDisplayMode( mode ); +} + +// back end. Determine what icon to se in the color-icon field, and print it +static void SetEngineColorIcon( int which ) +{ + char color = GetEngineColor(which); + int nicon = 0; + + if( color == ENGINE_COLOR_BLACK ) + nicon = nColorBlack; + else if( color == ENGINE_COLOR_WHITE ) + nicon = nColorWhite; + else + nicon = nColorUnknown; + + SetIcon( which, nColorIcon, nicon ); +} + +#define MAX_NAME_LENGTH 32 + +// pure back end, now SetWindowText is called via wrapper DoSetWindowText +static void UpdateControls( EngineOutputData * ed ) +{ + int isPondering = FALSE; + + char s_label[MAX_NAME_LENGTH + 32]; + + char * name = ed->name; + + /* Label */ + if( name == 0 || *name == '\0' ) { + name = "?"; + } + + strncpy( s_label, name, MAX_NAME_LENGTH ); + s_label[ MAX_NAME_LENGTH-1 ] = '\0'; + +#ifdef SHOW_PONDERING + if( IsEnginePondering( ed->which ) ) { + char buf[8]; + + buf[0] = '\0'; + + if( ed->hint != 0 && *ed->hint != '\0' ) { + strncpy( buf, ed->hint, sizeof(buf) ); + buf[sizeof(buf)-1] = '\0'; + } + else if( ed->pv != 0 && *ed->pv != '\0' ) { + char * sep = strchr( ed->pv, ' ' ); + int buflen = sizeof(buf); + + if( sep != NULL ) { + buflen = sep - ed->pv + 1; + if( buflen > sizeof(buf) ) buflen = sizeof(buf); + } + + strncpy( buf, ed->pv, buflen ); + buf[ buflen-1 ] = '\0'; + } + + SetEngineState( ed->which, STATE_PONDERING, buf ); + } + else if( gameMode == TwoMachinesPlay ) { + SetEngineState( ed->which, STATE_THINKING, "" ); + } + else if( gameMode == AnalyzeMode || gameMode == AnalyzeFile ) { + char buf[64]; + int time_secs = ed->time / 100; + int time_mins = time_secs / 60; + + buf[0] = '\0'; + + if( ed->an_move_index != 0 && ed->an_move_count != 0 && *ed->hint != '\0' ) { + char mov[16]; + + strncpy( mov, ed->hint, sizeof(mov) ); + mov[ sizeof(mov)-1 ] = '\0'; + + sprintf( buf, "%d/%d: %s [%02d:%02d:%02d]", ed->an_move_index, ed->an_move_count, mov, time_mins / 60, time_mins % 60, time_secs % 60 ); + } + + SetEngineState( ed->which, STATE_ANALYZING, buf ); + } + else { + SetEngineState( ed->which, STATE_IDLE, "" ); + } +#endif + + DoSetWindowText( ed->which, nLabel, s_label ); + + s_label[0] = '\0'; + + if( ed->time > 0 && ed->nodes > 0 ) { + unsigned long nps_100 = ed->nodes / ed->time; + + if( nps_100 < 100000 ) { + sprintf( s_label, "NPS: %lu", nps_100 * 100 ); + } + else { + sprintf( s_label, "NPS: %.1fk", nps_100 / 10.0 ); + } + } + + DoSetWindowText( ed->which, nLabelNPS, s_label ); + + /* Memo */ + if( ed->pv != 0 && *ed->pv != '\0' ) { + char s_nodes[24]; + char s_score[16]; + char s_time[24]; + char buf[256]; + int buflen; + int time_secs = ed->time / 100; + int time_cent = ed->time % 100; + + /* Nodes */ + if( ed->nodes < 1000000 ) { + sprintf( s_nodes, "%lu", ed->nodes ); + } + else { + sprintf( s_nodes, "%.1fM", ed->nodes / 1000000.0 ); + } + + /* Score */ + if( ed->score > 0 ) { + sprintf( s_score, "+%.2f", ed->score / 100.0 ); + } + else { + sprintf( s_score, "%.2f", ed->score / 100.0 ); + } + + /* Time */ + sprintf( s_time, "%d:%02d.%02d", time_secs / 60, time_secs % 60, time_cent ); + + /* Put all together... */ + sprintf( buf, "%3d\t%s\t%s\t%s\t", ed->depth, s_score, s_nodes, s_time ); + + /* Add PV */ + buflen = strlen(buf); + + strncpy( buf + buflen, ed->pv, sizeof(buf) - buflen ); + + buf[ sizeof(buf) - 3 ] = '\0'; + + strcat( buf + buflen, "\r\n" ); + + /* Update memo */ + InsertIntoMemo( ed->which, buf ); + } + + /* Colors */ + SetEngineColorIcon( ed->which ); +} + +// back end +int EngineOutputIsUp() +{ + return engineOutputDialogUp; +} + +// [HGM] kibitz: write kibitz line; split window for it if necessary +void OutputKibitz(int window, char *text) +{ + if(!EngineOutputIsUp()) return; + if(!opponentKibitzes) { // on first kibitz of game, clear memos + DoClearMemo(1); + if(gameMode == IcsObserving) DoClearMemo(0); + } + opponentKibitzes = TRUE; // this causes split window DisplayMode in ICS modes. + VerifyDisplayMode(); + if(gameMode == IcsObserving) { + DoSetWindowText(0, nLabel, gameInfo.white); + SetIcon( 0, nColorIcon, nColorWhite); + SetIcon( 0, nStateIcon, nClear); + } + DoSetWindowText(1, nLabel, gameMode == IcsPlayingBlack ? gameInfo.white : gameInfo.black); // opponent name + SetIcon( 1, nColorIcon, gameMode == IcsPlayingBlack ? nColorWhite : nColorBlack); + SetIcon( 1, nStateIcon, nClear); + InsertIntoMemo(window-1, text); +} + diff --git a/winboard/wengineoutput.c b/winboard/wengineoutput.c index 86715e3..0623e3d 100644 --- a/winboard/wengineoutput.c +++ b/winboard/wengineoutput.c @@ -648,6 +648,7 @@ VOID EngineOutputPopUp() } engineOutputDialogUp = TRUE; + ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output } VOID EngineOutputPopDown() @@ -659,6 +660,7 @@ VOID EngineOutputPopDown() } engineOutputDialogUp = FALSE; + ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output } BOOL EngineOutputIsUp() diff --git a/winboard/winboard.c b/winboard/winboard.c index a70f16b..6ad5def 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -140,7 +140,8 @@ BOOLEAN chessProgram; static int boardX, boardY, consoleX, consoleY, consoleW, consoleH; static int squareSize, lineGap, minorSize; static int winWidth, winHeight; -static RECT messageRect, whiteRect, blackRect; +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; @@ -613,6 +614,35 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) return (FALSE); } + /* [HGM] logo: Load logos if specified (must be done before InitDrawingSizes) */ + if( appData.firstLogo && appData.firstLogo[0] != NULLCHAR) { + first.programLogo = LoadImage( 0, appData.firstLogo, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + + if (first.programLogo == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load logo bitmap '%s'\n", appData.firstLogo ); + } + } else if(appData.autoLogo) { + if(appData.firstDirectory && appData.firstDirectory[0]) { + char buf[MSG_SIZ]; + sprintf(buf, "%s/logo.bmp", appData.firstDirectory); + first.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + } + } + + if( appData.secondLogo && appData.secondLogo[0] != NULLCHAR) { + second.programLogo = LoadImage( 0, appData.secondLogo, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + + if (second.programLogo == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load logo bitmap '%s'\n", appData.secondLogo ); + } + } else if(appData.autoLogo) { + if(appData.secondDirectory && appData.secondDirectory[0]) { + char buf[MSG_SIZ]; + sprintf(buf, "%s\\logo.bmp", appData.secondDirectory); + second.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + } + } + iconWhite = LoadIcon(hInstance, "icon_white"); iconBlack = LoadIcon(hInstance, "icon_black"); iconCurrent = iconWhite; @@ -630,6 +660,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) boardSize = (BoardSize)ibs; } } + InitDrawingSizes(boardSize, 0); InitMenuChecks(); buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS); @@ -1188,6 +1219,10 @@ ArgDescriptor argDescriptors[] = { { "sameColorGames", ArgInt, (LPVOID) &appData.sameColorGames, FALSE }, { "smpCores", ArgInt, (LPVOID) &appData.smpCores, TRUE }, { "egtFormats", ArgString, (LPVOID) &appData.egtFormats, TRUE }, + { "niceEngines", ArgInt, (LPVOID) &appData.niceEngines, TRUE }, + { "firstLogo", ArgFilename, (LPVOID) &appData.firstLogo, FALSE }, + { "secondLogo", ArgFilename, (LPVOID) &appData.secondLogo, FALSE }, + { "autoLogo", ArgBoolean, (LPVOID) &appData.autoLogo, TRUE }, #ifdef ZIPPY { "zippyTalk", ArgBoolean, (LPVOID) &appData.zippyTalk, FALSE }, @@ -2530,7 +2565,7 @@ static void CreatePieceMaskFromFont( HDC hdc_window, HDC hdc, int index ) SetBkMode( hdc, TRANSPARENT ); SetTextColor( hdc, chroma ); /* Step 2: the piece has been drawn in purple, there are now black and purple in this bitmap */ - TextOut( hdc, pt.x, pt.y, &pieceToFontChar[index], 1 ); + TextOut( hdc, pt.x, pt.y, &pieceToFontChar[appData.allWhite && index >= (int)BlackPawn ? index - (int)BlackPawn : index], 1 ); SelectObject( hdc, GetStockObject(WHITE_BRUSH) ); /* Step 3: the area outside the piece is filled with white */ @@ -2569,7 +2604,7 @@ static void CreatePieceMaskFromFont( HDC hdc_window, HDC hdc, int index ) Step 5: some fonts have "disconnected" areas that are skipped by the fill: draw the piece again in black for safety. */ - TextOut( hdc, pt.x, pt.y, &pieceToFontChar[index], 1 ); + TextOut( hdc, pt.x, pt.y, &pieceToFontChar[appData.allWhite && index >= (int)BlackPawn ? index - (int)BlackPawn : index], 1 ); SelectObject( hdc, hbm_old ); @@ -2610,7 +2645,7 @@ static void CreatePieceMaskFromFont( HDC hdc_window, HDC hdc, int index ) } SetTextColor( hdc, foreColor ); - TextOut( hdc, pt.x, pt.y, &pieceToFontChar[index], 1 ); + TextOut( hdc, pt.x, pt.y, &pieceToFontChar[appData.allWhite && index >= (int)BlackPawn ? index - (int)BlackPawn : index], 1 ); SelectObject( hdc, hbm_old ); @@ -3059,27 +3094,52 @@ InitDrawingSizes(BoardSize boardSize, int flags) ReleaseDC(hwndMain, hdc); /* Compute where everything goes */ - whiteRect.left = OUTER_MARGIN; - whiteRect.right = whiteRect.left + boardWidth/2 - INNER_MARGIN/2; - whiteRect.top = OUTER_MARGIN; - whiteRect.bottom = whiteRect.top + clockSize.cy; + if(first.programLogo || second.programLogo) { + /* [HGM] logo: if either logo is on, reserve space for it */ + logoHeight = 2*clockSize.cy; + leftLogoRect.left = OUTER_MARGIN; + leftLogoRect.right = leftLogoRect.left + 4*clockSize.cy; + leftLogoRect.top = OUTER_MARGIN; + leftLogoRect.bottom = OUTER_MARGIN + logoHeight; + + rightLogoRect.right = OUTER_MARGIN + boardWidth; + rightLogoRect.left = rightLogoRect.right - 4*clockSize.cy; + rightLogoRect.top = OUTER_MARGIN; + rightLogoRect.bottom = OUTER_MARGIN + logoHeight; + + + blackRect.left = leftLogoRect.right; + blackRect.right = rightLogoRect.left; + blackRect.top = OUTER_MARGIN; + blackRect.bottom = blackRect.top + clockSize.cy; + + whiteRect.left = blackRect.left ; + whiteRect.right = blackRect.right; + whiteRect.top = blackRect.bottom; + whiteRect.bottom = leftLogoRect.bottom; + } else { + whiteRect.left = OUTER_MARGIN; + whiteRect.right = whiteRect.left + boardWidth/2 - INNER_MARGIN/2; + whiteRect.top = OUTER_MARGIN + logoHeight; + whiteRect.bottom = whiteRect.top + clockSize.cy; - blackRect.left = whiteRect.right + INNER_MARGIN; - blackRect.right = blackRect.left + boardWidth/2 - 1; - blackRect.top = whiteRect.top; - blackRect.bottom = whiteRect.bottom; + blackRect.left = whiteRect.right + INNER_MARGIN; + blackRect.right = blackRect.left + boardWidth/2 - 1; + blackRect.top = whiteRect.top; + blackRect.bottom = whiteRect.bottom; + } - messageRect.left = whiteRect.left + MESSAGE_LINE_LEFTMARGIN; + messageRect.left = OUTER_MARGIN + MESSAGE_LINE_LEFTMARGIN; if (appData.showButtonBar) { - messageRect.right = blackRect.right + messageRect.right = OUTER_MARGIN + boardWidth // [HGM] logo: expressed independent of clock placement - N_BUTTONS*BUTTON_WIDTH - MESSAGE_LINE_LEFTMARGIN; } else { - messageRect.right = blackRect.right; + messageRect.right = OUTER_MARGIN + boardWidth; } messageRect.top = whiteRect.bottom + INNER_MARGIN; messageRect.bottom = messageRect.top + messageSize.cy; - boardRect.left = whiteRect.left; + boardRect.left = OUTER_MARGIN; boardRect.right = boardRect.left + boardWidth; boardRect.top = messageRect.bottom + INNER_MARGIN; boardRect.bottom = boardRect.top + boardHeight; @@ -3565,7 +3625,7 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, CreatePiecesFromFont(); if( fontBitmapSquareSize == squareSize ) { - int index = TranslatePieceToFontPiece( piece ); + int index = TranslatePieceToFontPiece(piece); SelectObject( tmphdc, hPieceMask[ index ] ); @@ -3710,16 +3770,16 @@ VOID RebuildTextureSquareInfo() if( (col + row) & 1 ) { /* Lite square */ if( lite_w >= squareSize && lite_h >= squareSize ) { - backTextureSquareInfo[row][col].x = col * (lite_w - squareSize) / BOARD_WIDTH; - backTextureSquareInfo[row][col].y = row * (lite_h - squareSize) / BOARD_HEIGHT; + backTextureSquareInfo[row][col].x = col * (lite_w - squareSize) / (BOARD_WIDTH-1); /* [HGM] divide by size-1 in stead of size! */ + backTextureSquareInfo[row][col].y = (BOARD_HEIGHT-1-row) * (lite_h - squareSize) / (BOARD_HEIGHT-1); backTextureSquareInfo[row][col].mode = GetBackTextureMode(liteBackTextureMode); } } else { /* Dark square */ if( dark_w >= squareSize && dark_h >= squareSize ) { - backTextureSquareInfo[row][col].x = col * (dark_w - squareSize) / BOARD_WIDTH; - backTextureSquareInfo[row][col].y = row * (dark_h - squareSize) / BOARD_HEIGHT; + backTextureSquareInfo[row][col].x = col * (dark_w - squareSize) / (BOARD_WIDTH-1); + backTextureSquareInfo[row][col].y = (BOARD_HEIGHT-1-row) * (dark_h - squareSize) / (BOARD_HEIGHT-1); backTextureSquareInfo[row][col].mode = GetBackTextureMode(darkBackTextureMode); } } @@ -4045,7 +4105,7 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) piece = board[row][column]; square_color = ((column + row) % 2) == 1; - if(!strcmp(appData.variant, "xiangqi") ) { + if( gameInfo.variant == VariantXiangqi ) { square_color = !InPalace(row, column); if(BOARD_HEIGHT&1) { if(row==BOARD_HEIGHT/2) square_color ^= 1; } else if(row < BOARD_HEIGHT/2) square_color ^= 1; @@ -4086,14 +4146,16 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) else if( backTextureSquareInfo[row][column].mode > 0 ) { /* [AS] Draw the square using a texture bitmap */ HBITMAP hbm = SelectObject( texture_hdc, square_color ? liteBackTexture : darkBackTexture ); + int r = row, c = column; // [HGM] do not flip board in flipView + if(flipView) { r = BOARD_HEIGHT-1 - r; c = BOARD_WIDTH-1 - c; } DrawTile( x, y, squareSize, squareSize, hdc, texture_hdc, - backTextureSquareInfo[row][column].mode, - backTextureSquareInfo[row][column].x, - backTextureSquareInfo[row][column].y ); + backTextureSquareInfo[r][c].mode, + backTextureSquareInfo[r][c].x, + backTextureSquareInfo[r][c].y ); SelectObject( texture_hdc, hbm ); @@ -4130,6 +4192,32 @@ void fputDW(FILE *f, int x) #define MAX_CLIPS 200 /* more than enough */ VOID +DrawLogoOnDC(HDC hdc, RECT logoRect, ChessProgramState *cps) +{ + HBITMAP bufferBitmap; + BITMAP bi; + RECT Rect; + HDC tmphdc; + HBITMAP hbm; + int w = 100, h = 50; + + if(cps->programLogo == NULL) return; +// GetClientRect(hwndMain, &Rect); +// bufferBitmap = CreateCompatibleBitmap(hdc, Rect.right-Rect.left+1, +// Rect.bottom-Rect.top+1); + tmphdc = CreateCompatibleDC(hdc); + hbm = SelectObject(tmphdc, (HBITMAP) cps->programLogo); + if( GetObject( cps->programLogo, sizeof(bi), &bi ) > 0 ) { + w = bi.bmWidth; + h = bi.bmHeight; + } + StretchBlt(hdc, logoRect.left, logoRect.top, logoRect.right - logoRect.left, + logoRect.bottom - logoRect.top, tmphdc, 0, 0, w, h, SRCCOPY); + SelectObject(tmphdc, hbm); + DeleteDC(tmphdc); +} + +VOID HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) { static Board lastReq, lastDrawn; @@ -4383,6 +4471,11 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) DrawHighlightsOnDC(hdcmem); DrawBoardOnDC(hdcmem, board, tmphdc); + if(logoHeight) { + DrawLogoOnDC(hdc, leftLogoRect, flipClock ? &second : &first); + DrawLogoOnDC(hdc, rightLogoRect, flipClock ? &first : &second); + } + if( appData.highlightMoveWithArrow ) { DrawArrowHighlight(hdcmem); } @@ -4727,7 +4820,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) gameMode == MachinePlaysWhite) { CallFlagEvent(); } else if (gameMode == EditGame) { - AdjustClock(flipClock, -1); + AdjustClock((logoHeight > 0 ? flipView: flipClock), -1); } } else if (PtInRect((LPRECT) &blackRect, pt)) { if (gameMode == EditPosition) { @@ -4736,7 +4829,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) gameMode == MachinePlaysBlack) { CallFlagEvent(); } else if (gameMode == EditGame) { - AdjustClock(!flipClock, -1); + AdjustClock(!(logoHeight > 0 ? flipView: flipClock), -1); } } if (!appData.highlightLastMove) { @@ -4794,7 +4887,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) DrawPosition(forceFullRepaint || FALSE, NULL); /* [HGM] Popup calls FinishMove now. If promotion to Q is legal, all are legal! */ - if(gameInfo.variant == VariantSuper) + if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { ChessSquare p = boards[currentMove][fromY][fromX], q = boards[currentMove][toY][toX]; // kludge to temporarily execute move on display, wthout promotng yet promotionChoice = TRUE; @@ -4893,7 +4986,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) else if (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen ) { DrawPosition(forceFullRepaint || FALSE, NULL); - if(gameInfo.variant == VariantSuper) + if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { ChessSquare p = boards[currentMove][fromY][fromX], q = boards[currentMove][toY][toX]; // kludge to temporarily execute move on display, wthout promotng yet promotionChoice = TRUE; @@ -4961,9 +5054,9 @@ 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) AdjustClock((logoHeight > 0 ? flipView: flipClock), 1); } else if (PtInRect((LPRECT) &blackRect, pt)) { - if (gameMode == EditGame) AdjustClock(!flipClock, 1); + if (gameMode == EditGame) AdjustClock(!(logoHeight > 0 ? flipView: flipClock), 1); } } DrawPosition(TRUE, NULL); @@ -5192,7 +5285,7 @@ VOID ToggleShowThinking() { appData.showThinking = !appData.showThinking; - ShowThinkingEvent(); + ShowThinkingEvent(); } VOID @@ -5506,7 +5599,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } else { EngineOutputPopUp(); - } + } break; /* [AS] User adjudication */ @@ -9293,7 +9386,8 @@ DisplayWhiteClock(long timeRemaining, int highlight) char *flag = whiteFlag && gameMode == TwoMachinesPlay ? "(!)" : ""; if (!IsIconic(hwndMain)) { - DisplayAClock(hdc, timeRemaining, highlight, flipClock ? &blackRect : &whiteRect, "White", flag); + DisplayAClock(hdc, timeRemaining, highlight, + (logoHeight > 0 ? flipView: flipClock) ? &blackRect : &whiteRect, "White", flag); } if (highlight && iconCurrent == iconBlack) { iconCurrent = iconWhite; @@ -9315,7 +9409,8 @@ DisplayBlackClock(long timeRemaining, int highlight) hdc = GetDC(hwndMain); if (!IsIconic(hwndMain)) { - DisplayAClock(hdc, timeRemaining, highlight, flipClock ? &whiteRect : &blackRect, "Black", flag); + DisplayAClock(hdc, timeRemaining, highlight, + (logoHeight > 0 ? flipView: flipClock) ? &whiteRect : &blackRect, "Black", flag); } if (highlight && iconCurrent == iconWhite) { iconCurrent = iconBlack; @@ -9406,6 +9501,23 @@ CancelDelayedEvent() } } +DWORD GetWin32Priority(int nice) +{ // [HGM] nice: translate Unix nice() value to indows priority class. (Code stolen from Polyglot 1.4w11) +/* +REALTIME_PRIORITY_CLASS 0x00000100 +HIGH_PRIORITY_CLASS 0x00000080 +ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 +NORMAL_PRIORITY_CLASS 0x00000020 +BELOW_NORMAL_PRIORITY_CLASS 0x00004000 +IDLE_PRIORITY_CLASS 0x00000040 +*/ + if (nice < -15) return 0x00000080; + if (nice < 0) return 0x00008000; + if (nice == 0) return 0x00000020; + if (nice < 15) return 0x00004000; + return 0x00000040; +} + /* Start a child process running the given program. The process's standard output can be read from "from", and its standard input can be written to "to". @@ -9521,6 +9633,11 @@ StartChildProcess(char *cmdLine, char *dir, ProcRef *pr) return err; } + if (appData.niceEngines){ // [HGM] nice: adjust engine proc priority + if(appData.debugMode) fprintf(debugFP, "nice engine proc to %d\n", appData.niceEngines); + SetPriorityClass(piProcInfo.hProcess, GetWin32Priority(appData.niceEngines)); + } + /* Close the handles we don't need in the parent */ CloseHandle(piProcInfo.hThread); CloseHandle(hChildStdinRd); diff --git a/winboard/woptions.c b/winboard/woptions.c index 0941cce..aa272e9 100644 --- a/winboard/woptions.c +++ b/winboard/woptions.c @@ -1,2986 +1,2986 @@ -/* - * woptions.c -- Options dialog box routines for WinBoard - * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $ - * - * Copyright 2000 Free Software Foundation, Inc. - * - * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * ------------------------------------------------------------------------ - */ - -#include "config.h" - -#include /* required for all Windows applications */ -#include -#include -#include /* [AS] Requires NT 4.0 or Win95 */ - -#include "common.h" -#include "winboard.h" -#include "backend.h" -#include "woptions.h" -#include "defaults.h" -#include "wedittags.h" -#include - -#if __GNUC__ -#include -#include -#endif - -/* Imports from winboard.c */ - -extern MyFont *font[NUM_SIZES][NUM_FONTS]; -extern HINSTANCE hInst; /* current instance */ -extern HWND hwndMain; /* root window*/ -extern BOOLEAN alwaysOnTop; -extern RECT boardRect; -extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor, - blackPieceColor, highlightSquareColor, premoveHighlightColor; -extern HPALETTE hPal; -extern BoardSize boardSize; -extern COLORREF consoleBackgroundColor; -extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */ -extern MyTextAttribs textAttribs[]; -extern MySound sounds[]; -extern ColorClass currentColorClass; -extern HWND hwndConsole; -extern char *defaultTextAttribs[]; -extern HWND commentDialog; -extern HWND moveHistoryDialog; -extern char installDir[]; -extern HWND hCommPort; /* currently open comm port */ -extern DCB dcb; -extern BOOLEAN chessProgram; -extern startedFromPositionFile; /* [HGM] loadPos */ - -/* types */ - -typedef struct { - char *label; - unsigned value; -} ComboData; - -typedef struct { - char *label; - char *name; -} SoundComboData; - -/* module prototypes */ - -LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM); -VOID ChangeBoardSize(BoardSize newSize); -VOID PaintSampleSquare( - HWND hwnd, - int ctrlid, - COLORREF squareColor, - COLORREF pieceColor, - COLORREF squareOutlineColor, - COLORREF pieceDetailColor, - BOOL isWhitePiece, - BOOL isMono, - HBITMAP pieces[3] - ); -VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color); -VOID SetBoardOptionEnables(HWND hDlg); -BoardSize BoardOptionsWhichRadio(HWND hDlg); -BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font); -VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca); -LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM); -VOID ColorizeTextPopup(HWND hwnd, ColorClass cc); -VOID SetIcsOptionEnables(HWND hDlg); -VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf); -VOID CopyFont(MyFont *dest, const MyFont *src); -void InitSoundComboData(SoundComboData *scd); -void ResetSoundComboData(SoundComboData *scd); -void InitSoundCombo(HWND hwndCombo, SoundComboData *scd); -int SoundDialogWhichRadio(HWND hDlg); -VOID SoundDialogSetEnables(HWND hDlg, int radio); -char * SoundDialogGetName(HWND hDlg, int radio); -void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name); -VOID ParseCommSettings(char *arg, DCB *dcb); -VOID PrintCommSettings(FILE *f, char *name, DCB *dcb); -void InitCombo(HANDLE hwndCombo, ComboData *cd); -void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value); -VOID SetLoadOptionEnables(HWND hDlg); -VOID SetSaveOptionEnables(HWND hDlg); -VOID SetTimeControlEnables(HWND hDlg); - -/*---------------------------------------------------------------------------*\ - * - * General Options Dialog functions - * -\*---------------------------------------------------------------------------*/ - - -LRESULT CALLBACK -GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static Boolean oldShowCoords; - static Boolean oldBlindfold; - static Boolean oldShowButtonBar; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - oldShowCoords = appData.showCoords; - oldBlindfold = appData.blindfold; - oldShowButtonBar = appData.showButtonBar; - - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - - /* Initialize the dialog items */ -#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) - - CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop); - CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen); - CHECK_BOX(OPT_AnimateDragging, appData.animateDragging); - CHECK_BOX(OPT_AnimateMoving, appData.animate); - CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag); - CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView); - CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard); - CHECK_BOX(OPT_Blindfold, appData.blindfold); - CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging); - CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove); - CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates); - CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove); - CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage); - CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors); - CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar); - CHECK_BOX(OPT_ShowCoordinates, appData.showCoords); - CHECK_BOX(OPT_ShowThinking, appData.showThinking); - CHECK_BOX(OPT_TestLegality, appData.testLegality); - CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman); - CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN); - CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory); - CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow); - -#undef CHECK_BOX - - EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag), - appData.icsActive || !appData.noChessProgram); - EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView), - appData.icsActive || !appData.noChessProgram); - EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove), - !appData.noChessProgram); - EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates), - !appData.noChessProgram && !appData.icsActive); - EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking), - !appData.noChessProgram); - return TRUE; - - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - -#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) - - alwaysOnTop = IS_CHECKED(OPT_AlwaysOnTop); - appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen); - appData.animateDragging = IS_CHECKED(OPT_AnimateDragging); - appData.animate = IS_CHECKED(OPT_AnimateMoving); - appData.autoCallFlag = IS_CHECKED(OPT_AutoFlag); - appData.autoFlipView = IS_CHECKED(OPT_AutoFlipView); - appData.autoRaiseBoard = IS_CHECKED(OPT_AutoRaiseBoard); - appData.blindfold = IS_CHECKED(OPT_Blindfold); - appData.highlightDragging = IS_CHECKED(OPT_HighlightDragging); - appData.highlightLastMove = IS_CHECKED(OPT_HighlightLastMove); - PeriodicUpdatesEvent( IS_CHECKED(OPT_PeriodicUpdates)); - PonderNextMoveEvent( IS_CHECKED(OPT_PonderNextMove)); - appData.popupExitMessage = IS_CHECKED(OPT_PopupExitMessage); - appData.popupMoveErrors = IS_CHECKED(OPT_PopupMoveErrors); - appData.showButtonBar = IS_CHECKED(OPT_ShowButtonBar); - appData.showCoords = IS_CHECKED(OPT_ShowCoordinates); - // [HGM] thinking: next three moved up - appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN); - appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman); - appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory); -#if 0 - ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking)); -#else - appData.showThinking = IS_CHECKED(OPT_ShowThinking); - ShowThinkingEvent(); // [HGM] thinking: tests four options -#endif - appData.testLegality = IS_CHECKED(OPT_TestLegality); - appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow); - -#undef IS_CHECKED - - SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, - 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); -#if AOT_CONSOLE - if (hwndConsole) { - SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, - 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); - } -#endif - if (!appData.highlightLastMove) { - ClearHighlights(); - DrawPosition(FALSE, NULL); - } - /* - * for some reason the redraw seems smoother when we invalidate - * the board rect after the call to EndDialog() - */ - EndDialog(hDlg, TRUE); - - if (oldShowButtonBar != appData.showButtonBar) { - InitDrawingSizes(boardSize, 0); - } else if ((oldShowCoords != appData.showCoords) || - (oldBlindfold != appData.blindfold)) { - InvalidateRect(hwndMain, &boardRect, FALSE); - } - - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - } - break; - } - return FALSE; -} - -VOID -GeneralOptionsPopup(HWND hwnd) -{ - FARPROC lpProc; - - lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd, - (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} -/*---------------------------------------------------------------------------*\ - * - * Board Options Dialog functions - * -\*---------------------------------------------------------------------------*/ - -const int SAMPLE_SQ_SIZE = 54; - -VOID -ChangeBoardSize(BoardSize newSize) -{ - if (newSize != boardSize) { - boardSize = newSize; - InitDrawingSizes(boardSize, 0); - } -} - -VOID -PaintSampleSquare( - HWND hwnd, - int ctrlid, - COLORREF squareColor, - COLORREF pieceColor, - COLORREF squareOutlineColor, - COLORREF pieceDetailColor, - BOOL isWhitePiece, - BOOL isMono, - HBITMAP pieces[3] - ) -{ - HBRUSH brushSquare; - HBRUSH brushSquareOutline; - HBRUSH brushPiece; - HBRUSH brushPieceDetail; - HBRUSH oldBrushPiece; - HBRUSH oldBrushSquare; - HBITMAP oldBitmapMem; - HBITMAP oldBitmapTemp; - HBITMAP bufferBitmap; - RECT rect; - HDC hdcScreen, hdcMem, hdcTemp; - HPEN pen, oldPen; - HWND hCtrl = GetDlgItem(hwnd, ctrlid); - int x, y; - - const int SOLID = 0; - const int WHITE = 1; - const int OUTLINE = 2; - const int BORDER = 4; - - InvalidateRect(hCtrl, NULL, TRUE); - UpdateWindow(hCtrl); - GetClientRect(hCtrl, &rect); - x = rect.left + (BORDER / 2); - y = rect.top + (BORDER / 2); - hdcScreen = GetDC(hCtrl); - hdcMem = CreateCompatibleDC(hdcScreen); - hdcTemp = CreateCompatibleDC(hdcScreen); - - bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1, - rect.bottom-rect.top+1); - oldBitmapMem = SelectObject(hdcMem, bufferBitmap); - if (!isMono) { - SelectPalette(hdcMem, hPal, FALSE); - } - brushSquare = CreateSolidBrush(squareColor); - brushSquareOutline = CreateSolidBrush(squareOutlineColor); - brushPiece = CreateSolidBrush(pieceColor); - brushPieceDetail = CreateSolidBrush(pieceDetailColor); - - /* - * first draw the rectangle - */ - pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor); - oldPen = (HPEN) SelectObject(hdcMem, pen); - oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare); - Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom); - - /* - * now draw the piece - */ - if (isMono) { - oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0, - isWhitePiece ? SRCCOPY : NOTSRCCOPY); - SelectObject(hdcTemp, oldBitmapTemp); - } else { - if (isWhitePiece) { - oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]); - oldBrushPiece = SelectObject(hdcMem, brushPiece); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, 0x00B8074A); -#if 0 - /* Use pieceDetailColor for outline of white pieces */ - SelectObject(hdcTemp, pieces[OUTLINE]); - SelectObject(hdcMem, brushPieceDetail); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, 0x00B8074A); -#else - /* Use black for outline of white pieces */ - SelectObject(hdcTemp, pieces[OUTLINE]); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, SRCAND); -#endif - } else { -#if 0 - /* Use pieceDetailColor for details of black pieces */ - /* Requires filled-in solid bitmaps (BLACK_PIECE class); the - WHITE_PIECE ones aren't always the right shape. */ - oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]); - oldBrushPiece = SelectObject(hdcMem, brushPieceDetail); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, 0x00B8074A); - SelectObject(hdcTemp, pieces[SOLID]); - SelectObject(hdcMem, brushPiece); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, 0x00B8074A); -#else - /* Use square color for details of black pieces */ - oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]); - oldBrushPiece = SelectObject(hdcMem, brushPiece); - BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, - hdcTemp, 0, 0, 0x00B8074A); -#endif - } - SelectObject(hdcMem, oldBrushPiece); - SelectObject(hdcTemp, oldBitmapTemp); - } - /* - * copy the memory dc to the screen - */ - SelectObject(hdcMem, bufferBitmap); - BitBlt(hdcScreen, rect.left, rect.top, - rect.right - rect.left, - rect.bottom - rect.top, - hdcMem, rect.left, rect.top, SRCCOPY); - SelectObject(hdcMem, oldBitmapMem); - /* - * clean up - */ - SelectObject(hdcMem, oldBrushPiece); - SelectObject(hdcMem, oldPen); - DeleteObject(brushPiece); - DeleteObject(brushPieceDetail); - DeleteObject(brushSquare); - DeleteObject(brushSquareOutline); - DeleteObject(pen); - DeleteDC(hdcTemp); - DeleteDC(hdcMem); - ReleaseDC(hCtrl, hdcScreen); -} - - -VOID -PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color) -{ - HDC hdc; - HBRUSH brush, oldBrush; - RECT rect; - HWND hCtrl = GetDlgItem(hwnd, ctrlid); - - hdc = GetDC(hCtrl); - InvalidateRect(hCtrl, NULL, TRUE); - UpdateWindow(hCtrl); - GetClientRect(hCtrl, &rect); - brush = CreateSolidBrush(color); - oldBrush = (HBRUSH)SelectObject(hdc, brush); - Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom); - SelectObject(hdc, oldBrush); - DeleteObject(brush); - ReleaseDC(hCtrl, hdc); -} - - -VOID -SetBoardOptionEnables(HWND hDlg) -{ - if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) { - ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE); - ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE); - ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE); - ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE); - - EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE); - } else { - ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW); - ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW); - ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW); - ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW); - - EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE); - EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE); - } -} - -BoardSize -BoardOptionsWhichRadio(HWND hDlg) -{ - return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny : - (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny : - (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky : - (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite : - (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim : - (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall : - (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre : - (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling : - (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage : - (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate : - (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium : - (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky : - (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge : - (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig : - (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge : - (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant : - (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal : - SizeTitanic ))))))))))))))))); -} - -LRESULT CALLBACK -BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static Boolean mono, white, flip; - static BoardSize size; - static COLORREF lsc, dsc, wpc, bpc, hsc, phc; - static HBITMAP pieces[3]; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - switch (boardSize) { - case SizeTiny: - CheckDlgButton(hDlg, OPT_SizeTiny, TRUE); - break; - case SizeTeeny: - CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE); - break; - case SizeDinky: - CheckDlgButton(hDlg, OPT_SizeDinky, TRUE); - break; - case SizePetite: - CheckDlgButton(hDlg, OPT_SizePetite, TRUE); - break; - case SizeSlim: - CheckDlgButton(hDlg, OPT_SizeSlim, TRUE); - break; - case SizeSmall: - CheckDlgButton(hDlg, OPT_SizeSmall, TRUE); - break; - case SizeMediocre: - CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE); - break; - case SizeMiddling: - CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE); - break; - case SizeAverage: - CheckDlgButton(hDlg, OPT_SizeAverage, TRUE); - break; - case SizeModerate: - CheckDlgButton(hDlg, OPT_SizeModerate, TRUE); - break; - case SizeMedium: - CheckDlgButton(hDlg, OPT_SizeMedium, TRUE); - break; - case SizeBulky: - CheckDlgButton(hDlg, OPT_SizeBulky, TRUE); - break; - case SizeLarge: - CheckDlgButton(hDlg, OPT_SizeLarge, TRUE); - break; - case SizeBig: - CheckDlgButton(hDlg, OPT_SizeBig, TRUE); - break; - case SizeHuge: - CheckDlgButton(hDlg, OPT_SizeHuge, TRUE); - break; - case SizeGiant: - CheckDlgButton(hDlg, OPT_SizeGiant, TRUE); - break; - case SizeColossal: - CheckDlgButton(hDlg, OPT_SizeColossal, TRUE); - break; - case SizeTitanic: - CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE); - } - - if (appData.monoMode) - CheckDlgButton(hDlg, OPT_Monochrome, TRUE); - - if (appData.allWhite) - CheckDlgButton(hDlg, OPT_AllWhite, TRUE); - - if (appData.upsideDown) - CheckDlgButton(hDlg, OPT_UpsideDown, TRUE); - - pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s"); - pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w"); - pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o"); - - lsc = lightSquareColor; - dsc = darkSquareColor; - wpc = whitePieceColor; - bpc = blackPieceColor; - hsc = highlightSquareColor; - phc = premoveHighlightColor; - mono = appData.monoMode; - white= appData.allWhite; - flip = appData.upsideDown; - size = boardSize; - - SetBoardOptionEnables(hDlg); - return TRUE; - - case WM_PAINT: - PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); - PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); - PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); - PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); - PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); - PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); - PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, - TRUE, mono, pieces); - PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, - FALSE, mono, pieces); - - return FALSE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* - * if we call EndDialog() after the call to ChangeBoardSize(), - * then ChangeBoardSize() does not take effect, although the new - * boardSize is saved. Go figure... - */ - EndDialog(hDlg, TRUE); - - size = BoardOptionsWhichRadio(hDlg); - - /* - * did any settings change? - */ - if (size != boardSize) { - ChangeBoardSize(size); - } - - if ((mono != appData.monoMode) || - (lsc != lightSquareColor) || - (dsc != darkSquareColor) || - (wpc != whitePieceColor) || - (bpc != blackPieceColor) || - (hsc != highlightSquareColor) || - (flip != appData.upsideDown) || - (white != appData.allWhite) || - (phc != premoveHighlightColor)) { - - lightSquareColor = lsc; - darkSquareColor = dsc; - whitePieceColor = wpc; - blackPieceColor = bpc; - highlightSquareColor = hsc; - premoveHighlightColor = phc; - appData.monoMode = mono; - appData.allWhite = white; - appData.upsideDown = flip; - - InitDrawingColors(); - InitDrawingSizes(boardSize, 0); - InvalidateRect(hwndMain, &boardRect, FALSE); - } - DeleteObject(pieces[0]); - DeleteObject(pieces[1]); - DeleteObject(pieces[2]); - return TRUE; - - case IDCANCEL: - DeleteObject(pieces[0]); - DeleteObject(pieces[1]); - DeleteObject(pieces[2]); - EndDialog(hDlg, FALSE); - return TRUE; - - case OPT_ChooseLightSquareColor: - if (ChangeColor(hDlg, &lsc)) - PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); - PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, - TRUE, mono, pieces); - break; - - case OPT_ChooseDarkSquareColor: - if (ChangeColor(hDlg, &dsc)) - PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); - PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, - FALSE, mono, pieces); - break; - - case OPT_ChooseWhitePieceColor: - if (ChangeColor(hDlg, &wpc)) - PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); - PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, - TRUE, mono, pieces); - break; - - case OPT_ChooseBlackPieceColor: - if (ChangeColor(hDlg, &bpc)) - PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); - PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, - FALSE, mono, pieces); - break; - - case OPT_ChooseHighlightSquareColor: - if (ChangeColor(hDlg, &hsc)) - PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); - PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, - TRUE, mono, pieces); - break; - - case OPT_ChoosePremoveHighlightColor: - if (ChangeColor(hDlg, &phc)) - PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); - PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, - FALSE, mono, pieces); - break; - - case OPT_DefaultBoardColors: - lsc = ParseColorName(LIGHT_SQUARE_COLOR); - dsc = ParseColorName(DARK_SQUARE_COLOR); - wpc = ParseColorName(WHITE_PIECE_COLOR); - bpc = ParseColorName(BLACK_PIECE_COLOR); - hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR); - phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR); - mono = FALSE; - white= FALSE; - flip = FALSE; - CheckDlgButton(hDlg, OPT_Monochrome, FALSE); - CheckDlgButton(hDlg, OPT_AllWhite, FALSE); - CheckDlgButton(hDlg, OPT_UpsideDown, FALSE); - PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); - PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); - PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); - PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); - PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); - PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); - SetBoardOptionEnables(hDlg); - PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, - TRUE, mono, pieces); - PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, - FALSE, mono, pieces); - break; - - case OPT_Monochrome: - mono = !mono; - SetBoardOptionEnables(hDlg); - break; - - case OPT_AllWhite: - white = !white; - SetBoardOptionEnables(hDlg); - break; - - case OPT_UpsideDown: - flip = !flip; - SetBoardOptionEnables(hDlg); - break; - } - break; - } - return FALSE; -} - - -VOID -BoardOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd, - (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -VariantClass -VariantWhichRadio(HWND hDlg) -{ - return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy : - (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic : - (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse : - (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse : - (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier : - (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : - (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi : - (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi : - (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca : - (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings : - (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate : - (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers : - (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide : - (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic : - (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : - (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom : - (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder : - (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon : - (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom : - (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper : - (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina : - (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus : - (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle : - (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle : - VariantNormal )))))))))))))))))))))))); -} - -LRESULT CALLBACK -NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static Boolean mono; - static VariantClass v; - static COLORREF lsc, dsc, wpc, bpc, hsc, phc; - static HBITMAP pieces[3]; - static int n1_ok, n2_ok, n3_ok; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - switch (gameInfo.variant) { - case VariantNormal: - CheckDlgButton(hDlg, OPT_VariantNormal, TRUE); - break; - case VariantCrazyhouse: - CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE); - break; - case VariantBughouse: - CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE); - break; - case VariantShogi: - CheckDlgButton(hDlg, OPT_VariantShogi, TRUE); - break; - case VariantXiangqi: - CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE); - break; - case VariantCapablanca: - CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE); - break; - case VariantGothic: - CheckDlgButton(hDlg, OPT_VariantGothic, TRUE); - break; - case VariantCourier: - CheckDlgButton(hDlg, OPT_VariantCourier, TRUE); - break; - case VariantKnightmate: - CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE); - break; - case VariantTwoKings: - CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE); - break; - case VariantFairy: - CheckDlgButton(hDlg, OPT_VariantFairy, TRUE); - break; - case VariantAtomic: - CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE); - break; - case VariantSuicide: - CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE); - break; - case VariantLosers: - CheckDlgButton(hDlg, OPT_VariantLosers, TRUE); - break; - case VariantShatranj: - CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE); - break; - case VariantFischeRandom: - CheckDlgButton(hDlg, OPT_VariantFRC, TRUE); - break; - case VariantCapaRandom: - CheckDlgButton(hDlg, OPT_VariantCRC, TRUE); - break; - case VariantFalcon: - CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE); - break; - case VariantCylinder: - CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE); - break; - case Variant3Check: - case VariantSuper: - CheckDlgButton(hDlg, OPT_VariantSuper, TRUE); - break; - case VariantBerolina: - CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE); - break; - case VariantJanus: - CheckDlgButton(hDlg, OPT_VariantJanus, TRUE); - break; - case VariantWildCastle: - CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE); - break; - case VariantNoCastle: - CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE); - break; - } - - SetDlgItemInt( hDlg, IDC_Files, -1, TRUE ); - SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 ); - - SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE ); - SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); - - SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE ); - SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); - - n1_ok = n2_ok = n3_ok = FALSE; - - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* - * if we call EndDialog() after the call to ChangeBoardSize(), - * then ChangeBoardSize() does not take effect, although the new - * boardSize is saved. Go figure... - */ - EndDialog(hDlg, TRUE); - - v = VariantWhichRadio(hDlg); - if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ]; - if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) { - /* [HGM] in protocol 2 we check if variant is suported by engine */ - sprintf(buf, "Variant %s not supported by %s", name, first.tidy); - DisplayError(buf, 0); - return TRUE; /* treat as "Cancel" if first engine does not support it */ - } else - if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) { - sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy); - DisplayError(buf, 0); /* use of second engine is optional; only warn user */ - } - } - - gameInfo.variant = v; - appData.variant = VariantName(v); - - appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE ); - appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE ); - appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE ); - - if(!n1_ok) appData.NrFiles = -1; - if(!n2_ok) appData.NrRanks = -1; - if(!n3_ok) appData.holdingsSize = -1; - - shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ - startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ - appData.pieceToCharTable = NULL; - Reset(TRUE, TRUE); - - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case IDC_Ranks: - case IDC_Files: - case IDC_Holdings: - if( HIWORD(wParam) == EN_CHANGE ) { - - GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE ); - - /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/ - } - return TRUE; - } - break; - } - return FALSE; -} - - -VOID -NewVariantPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd, - (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * ICS Options Dialog functions - * -\*---------------------------------------------------------------------------*/ - -BOOL APIENTRY -MyCreateFont(HWND hwnd, MyFont *font) -{ - CHOOSEFONT cf; - HFONT hf; - - /* Initialize members of the CHOOSEFONT structure. */ - cf.lStructSize = sizeof(CHOOSEFONT); - cf.hwndOwner = hwnd; - cf.hDC = (HDC)NULL; - cf.lpLogFont = &font->lf; - cf.iPointSize = 0; - cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT; - cf.rgbColors = RGB(0,0,0); - cf.lCustData = 0L; - cf.lpfnHook = (LPCFHOOKPROC)NULL; - cf.lpTemplateName = (LPSTR)NULL; - cf.hInstance = (HINSTANCE) NULL; - cf.lpszStyle = (LPSTR)NULL; - cf.nFontType = SCREEN_FONTTYPE; - cf.nSizeMin = 0; - cf.nSizeMax = 0; - - /* Display the CHOOSEFONT common-dialog box. */ - if (!ChooseFont(&cf)) { - return FALSE; - } - - /* Create a logical font based on the user's */ - /* selection and return a handle identifying */ - /* that font. */ - hf = CreateFontIndirect(cf.lpLogFont); - if (hf == NULL) { - return FALSE; - } - - font->hf = hf; - font->mfp.pointSize = (float) (cf.iPointSize / 10.0); - font->mfp.bold = (font->lf.lfWeight >= FW_BOLD); - font->mfp.italic = font->lf.lfItalic; - font->mfp.underline = font->lf.lfUnderline; - font->mfp.strikeout = font->lf.lfStrikeOut; - strcpy(font->mfp.faceName, font->lf.lfFaceName); - return TRUE; -} - - -VOID -UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca) -{ - CHARFORMAT cf; - cf.cbSize = sizeof(CHARFORMAT); - cf.dwMask = - CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE; - cf.crTextColor = mca->color; - cf.dwEffects = mca->effects; - strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName); - /* - * The 20.0 below is in fact documented. yHeight is expressed in twips. - * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT. - * --msw - */ - cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5); - cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */ - cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE; - SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); -} - -LRESULT CALLBACK -ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static MyColorizeAttribs mca; - static ColorClass cc; - COLORREF background = (COLORREF)0; - - switch (message) { - case WM_INITDIALOG: - cc = (ColorClass)lParam; - mca = colorizeAttribs[cc]; - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0); - CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0); - CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0); - CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0); - - /* get the current background color from the parent window */ - SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND, - (WPARAM)WM_USER_GetConsoleBackground, - (LPARAM)&background); - - /* set the background color */ - SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background); - - SetDlgItemText(hDlg, OPT_Sample, mca.name); - UpdateSampleText(hDlg, OPT_Sample, &mca); - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - colorizeAttribs[cc] = mca; - textAttribs[cc].color = mca.color; - textAttribs[cc].effects = mca.effects; - Colorize(currentColorClass, TRUE); - if (cc == ColorNormal) { - CHARFORMAT cf; - cf.cbSize = sizeof(CHARFORMAT); - cf.dwMask = CFM_COLOR; - cf.crTextColor = mca.color; - SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, - EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); - } - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case OPT_ChooseColor: - ChangeColor(hDlg, &mca.color); - UpdateSampleText(hDlg, OPT_Sample, &mca); - return TRUE; - - default: - mca.effects = - (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) | - (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) | - (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) | - (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0); - UpdateSampleText(hDlg, OPT_Sample, &mca); - break; - } - break; - } - return FALSE; -} - -VOID -ColorizeTextPopup(HWND hwnd, ColorClass cc) -{ - FARPROC lpProc; - - lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst); - DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize), - hwnd, (DLGPROC)lpProc, (LPARAM) cc); - FreeProcInstance(lpProc); -} - -VOID -SetIcsOptionEnables(HWND hDlg) -{ -#define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y)) - - UINT state = IsDlgButtonChecked(hDlg, OPT_Premove); - ENABLE_DLG_ITEM(OPT_PremoveWhite, state); - ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state); - ENABLE_DLG_ITEM(OPT_PremoveBlack, state); - ENABLE_DLG_ITEM(OPT_PremoveBlackText, state); - - ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm)); - -#undef ENABLE_DLG_ITEM -} - - -LRESULT CALLBACK -IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MSG_SIZ]; - int number; - int i; - static COLORREF cbc; - static MyColorizeAttribs *mca; - COLORREF *colorref; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - - mca = colorizeAttribs; - - for (i=0; i < NColorClasses - 1; i++) { - mca[i].color = textAttribs[i].color; - mca[i].effects = textAttribs[i].effects; - } - cbc = consoleBackgroundColor; - - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - - /* Initialize the dialog items */ -#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) - - CHECK_BOX(OPT_AutoComment, appData.autoComment); - CHECK_BOX(OPT_AutoObserve, appData.autoObserve); - CHECK_BOX(OPT_GetMoveList, appData.getMoveList); - CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing); - CHECK_BOX(OPT_QuietPlay, appData.quietPlay); - CHECK_BOX(OPT_Premove, appData.premove); - CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite); - CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack); - CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm); - CHECK_BOX(OPT_DontColorize, !appData.colorize); - -#undef CHECK_BOX - - sprintf(buf, "%d", appData.icsAlarmTime / 1000); - SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf); - SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText); - SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText); - - SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); - - SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name); - SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name); - SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name); - SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name); - SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name); - SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name); - SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name); - SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name); - SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name); - SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name); - - UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); - UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); - UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]); - UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); - UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); - UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); - UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); - UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); - UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); - UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); - - SetIcsOptionEnables(hDlg); - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - - case WM_USER_GetConsoleBackground: - /* the ColorizeTextDialog needs the current background color */ - colorref = (COLORREF *)lParam; - *colorref = cbc; - return FALSE; - - case IDOK: - /* Read changed options from the dialog box */ - GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ); - if (sscanf(buf, "%d", &number) != 1 || (number < 0)){ - MessageBox(hDlg, "Invalid ICS Alarm Time", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - -#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) - - appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm); - appData.premove = IS_CHECKED(OPT_Premove); - appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite); - appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack); - appData.autoComment = IS_CHECKED(OPT_AutoComment); - appData.autoObserve = IS_CHECKED(OPT_AutoObserve); - appData.getMoveList = IS_CHECKED(OPT_GetMoveList); - appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing); - appData.quietPlay = IS_CHECKED(OPT_QuietPlay); - -#undef IS_CHECKED - - appData.icsAlarmTime = number * 1000; - GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5); - GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5); - - if (appData.localLineEditing) { - DontEcho(); - EchoOn(); - } else { - DoEcho(); - EchoOff(); - } - - appData.colorize = - (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize); - - if (!appData.colorize) { - CHARFORMAT cf; - COLORREF background = ParseColorName(COLOR_BKGD); - /* - SetDefaultTextAttribs(); - Colorize(currentColorClass); - */ - cf.cbSize = sizeof(CHARFORMAT); - cf.dwMask = CFM_COLOR; - cf.crTextColor = ParseColorName(COLOR_NORMAL); - - SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, - EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); - SendDlgItemMessage(hwndConsole, OPT_ConsoleText, - EM_SETBKGNDCOLOR, FALSE, background); - SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, - EM_SETBKGNDCOLOR, FALSE, background); - } - - if (cbc != consoleBackgroundColor) { - consoleBackgroundColor = cbc; - if (appData.colorize) { - SendDlgItemMessage(hwndConsole, OPT_ConsoleText, - EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor); - SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, - EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor); - } - } - - for (i=0; i < NColorClasses - 1; i++) { - textAttribs[i].color = mca[i].color; - textAttribs[i].effects = mca[i].effects; - } - - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case OPT_ChooseShoutColor: - ColorizeTextPopup(hDlg, ColorShout); - UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); - break; - - case OPT_ChooseSShoutColor: - ColorizeTextPopup(hDlg, ColorSShout); - UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); - break; - - case OPT_ChooseChannel1Color: - ColorizeTextPopup(hDlg, ColorChannel1); - UpdateSampleText(hDlg, OPT_SampleChannel1, - &colorizeAttribs[ColorChannel1]); - break; - - case OPT_ChooseChannelColor: - ColorizeTextPopup(hDlg, ColorChannel); - UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); - break; - - case OPT_ChooseKibitzColor: - ColorizeTextPopup(hDlg, ColorKibitz); - UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); - break; - - case OPT_ChooseTellColor: - ColorizeTextPopup(hDlg, ColorTell); - UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); - break; - - case OPT_ChooseChallengeColor: - ColorizeTextPopup(hDlg, ColorChallenge); - UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); - break; - - case OPT_ChooseRequestColor: - ColorizeTextPopup(hDlg, ColorRequest); - UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); - break; - - case OPT_ChooseSeekColor: - ColorizeTextPopup(hDlg, ColorSeek); - UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); - break; - - case OPT_ChooseNormalColor: - ColorizeTextPopup(hDlg, ColorNormal); - UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); - break; - - case OPT_ChooseBackgroundColor: - if (ChangeColor(hDlg, &cbc)) { - SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); - } - break; - - case OPT_DefaultColors: - for (i=0; i < NColorClasses - 1; i++) - ParseAttribs(&mca[i].color, - &mca[i].effects, - defaultTextAttribs[i]); - - cbc = ParseColorName(COLOR_BKGD); - SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); - SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); - - UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); - UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); - UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]); - UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); - UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); - UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); - UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); - UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); - UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); - UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); - break; - - default: - SetIcsOptionEnables(hDlg); - break; - } - break; - } - return FALSE; -} - -VOID -IcsOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd, - (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * Fonts Dialog functions - * -\*---------------------------------------------------------------------------*/ - -VOID -SetSampleFontText(HWND hwnd, int id, const MyFont *mf) -{ - char buf[MSG_SIZ]; - HWND hControl; - HDC hdc; - CHARFORMAT cf; - SIZE size; - RECT rectClient, rectFormat; - HFONT oldFont; - POINT center; - int len; - - len = sprintf(buf, "%.0f pt. %s%s%s\n", - mf->mfp.pointSize, mf->mfp.faceName, - mf->mfp.bold ? " bold" : "", - mf->mfp.italic ? " italic" : ""); - SetDlgItemText(hwnd, id, buf); - - hControl = GetDlgItem(hwnd, id); - hdc = GetDC(hControl); - SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */ - oldFont = SelectObject(hdc, mf->hf); - - /* get number of logical units necessary to display font name */ - GetTextExtentPoint32(hdc, buf, len, &size); - - /* calculate formatting rectangle in the rich edit control. - * May be larger or smaller than the actual control. - */ - GetClientRect(hControl, &rectClient); - center.x = (rectClient.left + rectClient.right) / 2; - center.y = (rectClient.top + rectClient.bottom) / 2; - rectFormat.top = center.y - (size.cy / 2) - 1; - rectFormat.bottom = center.y + (size.cy / 2) + 1; - rectFormat.left = center.x - (size.cx / 2) - 1; - rectFormat.right = center.x + (size.cx / 2) + 1; - -#if 0 - fprintf(debugFP, "\nfont: %s\n" - "center.x %d, centerY %d\n" - "size.cx %d, size.cy %d\n" - "client.top %d, bottom %d, left %d, right %d\n" - "format.top %d, bottom %d, left %d, right %d\n", - buf, - center.x, center.y, - size.cx, size.cy, - rectClient.top, rectClient.bottom, rectClient.left, - rectClient.right, - rectFormat.top, rectFormat.bottom, rectFormat.left, - rectFormat.right); -#endif - - cf.cbSize = sizeof(CHARFORMAT); - cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC; - cf.dwEffects = 0; - if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD; - if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC; - strcpy(cf.szFaceName, mf->mfp.faceName); - /* - * yHeight is expressed in twips. A twip is 1/20 of a font's point - * size. See documentation of CHARFORMAT. --msw - */ - cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5); - cf.bCharSet = mf->lf.lfCharSet; - cf.bPitchAndFamily = mf->lf.lfPitchAndFamily; - - /* format the text in the rich edit control */ - SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf); - SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat); - - /* clean up */ - SelectObject(hdc, oldFont); - ReleaseDC(hControl, hdc); -} - -VOID -CopyFont(MyFont *dest, const MyFont *src) -{ - dest->mfp.pointSize = src->mfp.pointSize; - dest->mfp.bold = src->mfp.bold; - dest->mfp.italic = src->mfp.italic; - dest->mfp.underline = src->mfp.underline; - dest->mfp.strikeout = src->mfp.strikeout; - lstrcpy(dest->mfp.faceName, src->mfp.faceName); - CreateFontInMF(dest); -} - - -LRESULT CALLBACK -FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static MyFont workFont[NUM_FONTS]; - static BOOL firstPaint; - int i; - RECT rect; - - switch (message) { - case WM_INITDIALOG: - - /* copy the current font settings into a working copy */ - for (i=0; i < NUM_FONTS; i++) - CopyFont(&workFont[i], font[boardSize][i]); - - if (!appData.icsActive) - EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE); - - firstPaint = TRUE; /* see rant below */ - - /* If I don't call SetFocus(), the dialog won't respond to the keyboard - * when first drawn. Why is this the only dialog that behaves this way? Is - * is the WM_PAINT stuff below?? Sigh... - */ - SetFocus(GetDlgItem(hDlg, IDOK)); - break; - - case WM_PAINT: - /* This should not be necessary. However, if SetSampleFontText() is called - * in response to WM_INITDIALOG, the strings are not properly centered in - * the controls when the dialog first appears. I can't figure out why, so - * this is the workaround. --msw - */ - if (firstPaint) { - SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]); - SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]); - SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]); - SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]); - SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]); - SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); - SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); - firstPaint = FALSE; - } - break; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - - case IDOK: - /* again, it seems to avoid redraw problems if we call EndDialog first */ - EndDialog(hDlg, FALSE); - - /* copy modified settings back to the fonts array */ - for (i=0; i < NUM_FONTS; i++) - CopyFont(font[boardSize][i], &workFont[i]); - - /* a sad necessity due to the original design of having a separate - * console font, tags font, and comment font for each board size. IMHO - * these fonts should not be dependent on the current board size. I'm - * running out of time, so I am doing this hack rather than redesign the - * data structure. Besides, I think if I redesigned the data structure, I - * might break backwards compatibility with old winboard.ini files. - * --msw - */ - for (i=0; i < NUM_SIZES; i++) { - CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]); - CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]); - CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]); - CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]); - } - /* end sad necessity */ - - InitDrawingSizes(boardSize, 0); - InvalidateRect(hwndMain, NULL, TRUE); - - if (commentDialog) { - SendDlgItemMessage(commentDialog, OPT_CommentText, - WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf, - MAKELPARAM(TRUE, 0)); - GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect); - InvalidateRect(commentDialog, &rect, TRUE); - } - - if (editTagsDialog) { - SendDlgItemMessage(editTagsDialog, OPT_TagsText, - WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, - MAKELPARAM(TRUE, 0)); - GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect); - InvalidateRect(editTagsDialog, &rect, TRUE); - } - - if( moveHistoryDialog != NULL ) { - SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory, - WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, - MAKELPARAM(TRUE, 0)); - InvalidateRect(editTagsDialog, NULL, TRUE); - } - - if (hwndConsole) { - ChangedConsoleFont(); - } - - for (i=0; idef, &workFont[i].mfp); - CreateFontInMF(&workFont[i]); - } - SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]); - SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]); - SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]); - SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]); - SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]); - SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); - SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); - break; - } - } - return FALSE; -} - -VOID -FontsOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd, - (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * Sounds Dialog functions - * -\*---------------------------------------------------------------------------*/ - - -SoundComboData soundComboData[] = { - {"Move", NULL}, - {"Bell", NULL}, - {"ICS Alarm", NULL}, - {"ICS Win", NULL}, - {"ICS Loss", NULL}, - {"ICS Draw", NULL}, - {"ICS Unfinished", NULL}, - {"Shout", NULL}, - {"SShout/CShout", NULL}, - {"Channel 1", NULL}, - {"Channel", NULL}, - {"Kibitz", NULL}, - {"Tell", NULL}, - {"Challenge", NULL}, - {"Request", NULL}, - {"Seek", NULL}, - {NULL, NULL}, -}; - - -void -InitSoundComboData(SoundComboData *scd) -{ - SoundClass sc; - ColorClass cc; - int index; - - /* copy current sound settings to combo array */ - - for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) { - scd[sc].name = strdup(sounds[sc].name); - } - for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) { - index = (int)cc + (int)NSoundClasses; - scd[index].name = strdup(textAttribs[cc].sound.name); - } -} - - -void -ResetSoundComboData(SoundComboData *scd) -{ - while (scd->label) { - if (scd->name != NULL) { - free (scd->name); - scd->name = NULL; - } - scd++; - } -} - -void -InitSoundCombo(HWND hwndCombo, SoundComboData *scd) -{ - char buf[255]; - DWORD err; - DWORD cnt = 0; - SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0); - - /* send the labels to the combo box */ - while (scd->label) { - err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label); - if (err != cnt++) { - sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n", - err, cnt); - MessageBox(NULL, buf, NULL, MB_OK); - } - scd++; - } - SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0); -} - -int -SoundDialogWhichRadio(HWND hDlg) -{ - if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound; - if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep; - if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound; - if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile; - return -1; -} - -VOID -SoundDialogSetEnables(HWND hDlg, int radio) -{ - EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName), - radio == OPT_BuiltInSound); - EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile); - EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile); -} - -char * -SoundDialogGetName(HWND hDlg, int radio) -{ - static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ]; - char *dummy, *ret; - switch (radio) { - case OPT_NoSound: - default: - return ""; - case OPT_DefaultBeep: - return "$"; - case OPT_BuiltInSound: - buf[0] = '!'; - GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1); - return buf; - case OPT_WavFile: - GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf)); - GetCurrentDirectory(MSG_SIZ, buf3); - SetCurrentDirectory(installDir); - if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) { - ret = buf2; - } else { - ret = buf; - } - SetCurrentDirectory(buf3); - return ret; - } -} - -void -DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name) -{ - int radio; - /* - * I think it's best to clear the combo and edit boxes. It looks stupid - * to have a value from another sound event sitting there grayed out. - */ - SetDlgItemText(hDlg, OPT_WavFileName, ""); - SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); - - if (appData.debugMode) - fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name); - switch (name[0]) { - case NULLCHAR: - radio = OPT_NoSound; - break; - case '$': - if (name[1] == NULLCHAR) { - radio = OPT_DefaultBeep; - } else { - radio = OPT_WavFile; - SetDlgItemText(hDlg, OPT_WavFileName, name); - } - break; - case '!': - if (name[1] == NULLCHAR) { - radio = OPT_NoSound; - } else { - radio = OPT_BuiltInSound; - if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1, - (LPARAM) (name + 1)) == CB_ERR) { - SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); - SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1)); - } - } - break; - default: - radio = OPT_WavFile; - SetDlgItemText(hDlg, OPT_WavFileName, name); - break; - } - SoundDialogSetEnables(hDlg, radio); - CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio); -} - - -char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES; - -LRESULT CALLBACK -SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static HWND hSoundCombo; - static DWORD index; - static HWND hBISN; - int radio; - MySound tmp; - FILE *f; - char buf[MSG_SIZ]; - char *newName; - SoundClass sc; - ColorClass cc; - SoundComboData *scd; - - switch (message) { - case WM_INITDIALOG: - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - - /* Initialize the built-in sounds combo */ - hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName); - InitComboStrings(hBISN, builtInSoundNames); - - /* Initialize the sound events combo */ - index = 0; - InitSoundComboData(soundComboData); - hSoundCombo = GetDlgItem(hDlg, CBO_Sounds); - InitSoundCombo(hSoundCombo, soundComboData); - - /* update the dialog */ - DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); - return TRUE; - - case WM_COMMAND: /* message: received a command */ - - if (((HWND)lParam == hSoundCombo) && - (HIWORD(wParam) == CBN_SELCHANGE)) { - /* - * the user has selected a new sound event. We must store the name for - * the previously selected event, then retrieve the name for the - * newly selected event and update the dialog. - */ - radio = SoundDialogWhichRadio(hDlg); - newName = strdup(SoundDialogGetName(hDlg, radio)); - - if (strcmp(newName, soundComboData[index].name) != 0) { - free(soundComboData[index].name); - soundComboData[index].name = newName; - } else { - free(newName); - newName = NULL; - } - /* now get the settings for the newly selected event */ - index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); - DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); - - return TRUE; - } - switch (LOWORD(wParam)) { - case IDOK: - /* - * save the name for the currently selected sound event - */ - radio = SoundDialogWhichRadio(hDlg); - newName = strdup(SoundDialogGetName(hDlg, radio)); - - if (strcmp(soundComboData[index].name, newName) != 0) { - free(soundComboData[index].name); - soundComboData[index].name = newName; - } else { - free(newName); - newName = NULL; - } - - /* save all the sound names that changed and load the sounds */ - - for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) { - if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) { - free(sounds[sc].name); - sounds[sc].name = strdup(soundComboData[sc].name); - MyLoadSound(&sounds[sc]); - } - } - for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) { - index = (int)cc + (int)NSoundClasses; - if (strcmp(soundComboData[index].name, - textAttribs[cc].sound.name) != 0) { - free(textAttribs[cc].sound.name); - textAttribs[cc].sound.name = strdup(soundComboData[index].name); - MyLoadSound(&textAttribs[cc].sound); - } - } - - ResetSoundComboData(soundComboData); - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - ResetSoundComboData(soundComboData); - EndDialog(hDlg, FALSE); - return TRUE; - - case OPT_DefaultSounds: - /* can't use SetDefaultSounds() because we need to be able to "undo" if - * user selects "Cancel" later on. So we do it the hard way here. - */ - scd = &soundComboData[0]; - while (scd->label != NULL) { - if (scd->name != NULL) free(scd->name); - scd->name = strdup(""); - scd++; - } - free(soundComboData[(int)SoundBell].name); - soundComboData[(int)SoundBell].name = strdup(SOUND_BELL); - DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); - break; - - case OPT_PlaySound: - radio = SoundDialogWhichRadio(hDlg); - tmp.name = strdup(SoundDialogGetName(hDlg, radio)); - tmp.data = NULL; - MyLoadSound(&tmp); - MyPlaySound(&tmp); - if (tmp.data != NULL) free(tmp.data); - if (tmp.name != NULL) free(tmp.name); - return TRUE; - - case OPT_BrowseSound: - f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT, - "Browse for Sound File", NULL, NULL, buf); - if (f != NULL) { - fclose(f); - SetDlgItemText(hDlg, OPT_WavFileName, buf); - } - return TRUE; - - default: - radio = SoundDialogWhichRadio(hDlg); - SoundDialogSetEnables(hDlg, radio); - break; - } - break; - } - return FALSE; -} - - -VOID SoundOptionsPopup(HWND hwnd) -{ - FARPROC lpProc; - - lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc); - FreeProcInstance(lpProc); -} - - -/*---------------------------------------------------------------------------*\ - * - * Comm Port dialog functions - * -\*---------------------------------------------------------------------------*/ - - -#define FLOW_NONE 0 -#define FLOW_XOFF 1 -#define FLOW_CTS 2 -#define FLOW_DSR 3 - -#define PORT_NONE - -ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2}, - {"COM3", 3}, {"COM4", 4}, {NULL, 0} }; -ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200}, - {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200}, - {"38400", 38400}, {NULL, 0} }; -ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} }; -ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY}, - {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} }; -ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS}, - {"2", TWOSTOPBITS}, {NULL, 0} }; -ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS}, - {"DSR", FLOW_DSR}, {NULL, 0} }; - - -VOID -ParseCommSettings(char *arg, DCB *dcb) -{ - int dataRate, count; - char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ]; - ComboData *cd; - count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]", - &dataRate, bits, parity, stopBits, flow); - if (count != 5) goto cant_parse; - dcb->BaudRate = dataRate; - cd = cdDataBits; - while (cd->label != NULL) { - if (StrCaseCmp(cd->label, bits) == 0) { - dcb->ByteSize = cd->value; - break; - } - cd++; - } - if (cd->label == NULL) goto cant_parse; - cd = cdParity; - while (cd->label != NULL) { - if (StrCaseCmp(cd->label, parity) == 0) { - dcb->Parity = cd->value; - break; - } - cd++; - } - if (cd->label == NULL) goto cant_parse; - cd = cdStopBits; - while (cd->label != NULL) { - if (StrCaseCmp(cd->label, stopBits) == 0) { - dcb->StopBits = cd->value; - break; - } - cd++; - } - cd = cdFlow; - if (cd->label == NULL) goto cant_parse; - while (cd->label != NULL) { - if (StrCaseCmp(cd->label, flow) == 0) { - switch (cd->value) { - case FLOW_NONE: - dcb->fOutX = FALSE; - dcb->fOutxCtsFlow = FALSE; - dcb->fOutxDsrFlow = FALSE; - break; - case FLOW_CTS: - dcb->fOutX = FALSE; - dcb->fOutxCtsFlow = TRUE; - dcb->fOutxDsrFlow = FALSE; - break; - case FLOW_DSR: - dcb->fOutX = FALSE; - dcb->fOutxCtsFlow = FALSE; - dcb->fOutxDsrFlow = TRUE; - break; - case FLOW_XOFF: - dcb->fOutX = TRUE; - dcb->fOutxCtsFlow = FALSE; - dcb->fOutxDsrFlow = FALSE; - break; - } - break; - } - cd++; - } - if (cd->label == NULL) goto cant_parse; - return; -cant_parse: - ExitArgError("Can't parse com port settings", arg); -} - - -VOID PrintCommSettings(FILE *f, char *name, DCB *dcb) -{ - char *flow = "??", *parity = "??", *stopBits = "??"; - ComboData *cd; - - cd = cdParity; - while (cd->label != NULL) { - if (dcb->Parity == cd->value) { - parity = cd->label; - break; - } - cd++; - } - cd = cdStopBits; - while (cd->label != NULL) { - if (dcb->StopBits == cd->value) { - stopBits = cd->label; - break; - } - cd++; - } - if (dcb->fOutX) { - flow = cdFlow[FLOW_XOFF].label; - } else if (dcb->fOutxCtsFlow) { - flow = cdFlow[FLOW_CTS].label; - } else if (dcb->fOutxDsrFlow) { - flow = cdFlow[FLOW_DSR].label; - } else { - flow = cdFlow[FLOW_NONE].label; - } - fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name, - dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow); -} - - -void -InitCombo(HANDLE hwndCombo, ComboData *cd) -{ - SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0); - - while (cd->label != NULL) { - SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label); - cd++; - } -} - -void -SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value) -{ - int i; - - i = 0; - while (cd->label != NULL) { - if (cd->value == value) { - SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0); - return; - } - cd++; - i++; - } -} - -LRESULT CALLBACK -CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MSG_SIZ]; - HANDLE hwndCombo; - char *p; - LRESULT index; - unsigned value; - int err; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER)); - /* Initialize the dialog items */ - /* !! There should probably be some synchronization - in accessing hCommPort and dcb. Or does modal nature - of this dialog box do it for us? - */ - hwndCombo = GetDlgItem(hDlg, OPT_Port); - InitCombo(hwndCombo, cdPort); - p = strrchr(appData.icsCommPort, '\\'); - if (p++ == NULL) p = appData.icsCommPort; - if ((*p == '\0') || - (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) { - SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None"); - } - EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/ - - hwndCombo = GetDlgItem(hDlg, OPT_DataRate); - InitCombo(hwndCombo, cdDataRate); - sprintf(buf, "%u", dcb.BaudRate); - if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) { - SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); - SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf); - } - - hwndCombo = GetDlgItem(hDlg, OPT_Bits); - InitCombo(hwndCombo, cdDataBits); - SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize); - - hwndCombo = GetDlgItem(hDlg, OPT_Parity); - InitCombo(hwndCombo, cdParity); - SelectComboValue(hwndCombo, cdParity, dcb.Parity); - - hwndCombo = GetDlgItem(hDlg, OPT_StopBits); - InitCombo(hwndCombo, cdStopBits); - SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits); - - hwndCombo = GetDlgItem(hDlg, OPT_Flow); - InitCombo(hwndCombo, cdFlow); - if (dcb.fOutX) { - SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF); - } else if (dcb.fOutxCtsFlow) { - SelectComboValue(hwndCombo, cdFlow, FLOW_CTS); - } else if (dcb.fOutxDsrFlow) { - SelectComboValue(hwndCombo, cdFlow, FLOW_DSR); - } else { - SelectComboValue(hwndCombo, cdFlow, FLOW_NONE); - } - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ -#ifdef NOTDEF - /* !! Currently we can't change comm ports in midstream */ - hwndCombo = GetDlgItem(hDlg, OPT_Port); - index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); - if (index == PORT_NONE) { - appData.icsCommPort = ""; - if (hCommPort != NULL) { - CloseHandle(hCommPort); - hCommPort = NULL; - } - EndDialog(hDlg, TRUE); - return TRUE; - } - SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf); - appData.icsCommPort = strdup(buf); - if (hCommPort != NULL) { - CloseHandle(hCommPort); - hCommPort = NULL; - } - /* now what?? can't really do this; have to fix up the ChildProc - and InputSource records for the comm port that we gave to the - back end. */ -#endif /*NOTDEF*/ - - hwndCombo = GetDlgItem(hDlg, OPT_DataRate); - SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf); - if (sscanf(buf, "%u", &value) != 1) { - MessageBox(hDlg, "Invalid data rate", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return TRUE; - } - dcb.BaudRate = value; - - hwndCombo = GetDlgItem(hDlg, OPT_Bits); - index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); - dcb.ByteSize = cdDataBits[index].value; - - hwndCombo = GetDlgItem(hDlg, OPT_Parity); - index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); - dcb.Parity = cdParity[index].value; - - hwndCombo = GetDlgItem(hDlg, OPT_StopBits); - index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); - dcb.StopBits = cdStopBits[index].value; - - hwndCombo = GetDlgItem(hDlg, OPT_Flow); - index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); - switch (cdFlow[index].value) { - case FLOW_NONE: - dcb.fOutX = FALSE; - dcb.fOutxCtsFlow = FALSE; - dcb.fOutxDsrFlow = FALSE; - break; - case FLOW_CTS: - dcb.fOutX = FALSE; - dcb.fOutxCtsFlow = TRUE; - dcb.fOutxDsrFlow = FALSE; - break; - case FLOW_DSR: - dcb.fOutX = FALSE; - dcb.fOutxCtsFlow = FALSE; - dcb.fOutxDsrFlow = TRUE; - break; - case FLOW_XOFF: - dcb.fOutX = TRUE; - dcb.fOutxCtsFlow = FALSE; - dcb.fOutxDsrFlow = FALSE; - break; - } - if (!SetCommState(hCommPort, (LPDCB) &dcb)) { - err = GetLastError(); - switch(MessageBox(hDlg, - "Failed to set comm port state;\r\ninvalid options?", - "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) { - case IDABORT: - DisplayFatalError("Failed to set comm port state", err, 1); - exit(1); /*is it ok to do this from here?*/ - - case IDRETRY: - return TRUE; - - case IDIGNORE: - EndDialog(hDlg, TRUE); - return TRUE; - } - } - - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - default: - break; - } - break; - } - return FALSE; -} - -VOID -CommPortOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * Load Options dialog functions - * -\*---------------------------------------------------------------------------*/ - -VOID -SetLoadOptionEnables(HWND hDlg) -{ - UINT state; - - state = IsDlgButtonChecked(hDlg, OPT_Autostep); - EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state); - EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state); -} - -LRESULT CALLBACK -LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MSG_SIZ]; - float fnumber; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - if (appData.timeDelay >= 0.0) { - CheckDlgButton(hDlg, OPT_Autostep, TRUE); - sprintf(buf, "%.2g", appData.timeDelay); - SetDlgItemText(hDlg, OPT_ASTimeDelay, buf); - } else { - CheckDlgButton(hDlg, OPT_Autostep, FALSE); - } - SetLoadOptionEnables(hDlg); - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - if (IsDlgButtonChecked(hDlg, OPT_Autostep)) { - GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ); - if (sscanf(buf, "%f", &fnumber) != 1) { - MessageBox(hDlg, "Invalid load game step rate", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - appData.timeDelay = fnumber; - } else { - appData.timeDelay = (float) -1.0; - } - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - default: - SetLoadOptionEnables(hDlg); - break; - } - break; - } - return FALSE; -} - - -VOID -LoadOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * Save Options dialog functions - * -\*---------------------------------------------------------------------------*/ - -VOID -SetSaveOptionEnables(HWND hDlg) -{ - UINT state; - - state = IsDlgButtonChecked(hDlg, OPT_Autosave); - EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state); - EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state); - if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) && - !IsDlgButtonChecked(hDlg, OPT_AVToFile)) { - CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt); - } - - state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile); - EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state); - EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state); -} - -LRESULT CALLBACK -SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MSG_SIZ]; - FILE *f; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - if (*appData.saveGameFile != NULLCHAR) { - CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE); - CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile); - SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile); - } else if (appData.autoSaveGames) { - CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE); - CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt); - } else { - CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE); - } - if (appData.oldSaveStyle) { - CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old); - } else { - CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN); - } - CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo ); - SetSaveOptionEnables(hDlg); - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - if (IsDlgButtonChecked(hDlg, OPT_Autosave)) { - appData.autoSaveGames = TRUE; - if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) { - appData.saveGameFile = ""; - } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ { - GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ); - if (*buf == NULLCHAR) { - MessageBox(hDlg, "Invalid save game file name", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - if ((isalpha(buf[0]) && buf[1] == ':') || - (buf[0] == '\\' && buf[1] == '\\')) { - appData.saveGameFile = strdup(buf); - } else { - char buf2[MSG_SIZ], buf3[MSG_SIZ]; - char *dummy; - GetCurrentDirectory(MSG_SIZ, buf3); - SetCurrentDirectory(installDir); - if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) { - appData.saveGameFile = strdup(buf2); - } else { - appData.saveGameFile = strdup(buf); - } - SetCurrentDirectory(buf3); - } - } - } else { - appData.autoSaveGames = FALSE; - appData.saveGameFile = ""; - } - appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old); - appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo ); - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case OPT_AVBrowse: - f = OpenFileDialog(hDlg, "a", NULL, - appData.oldSaveStyle ? "gam" : "pgn", - GAME_FILT, "Browse for Auto Save File", - NULL, NULL, buf); - if (f != NULL) { - fclose(f); - SetDlgItemText(hDlg, OPT_AVFilename, buf); - } - break; - - default: - SetSaveOptionEnables(hDlg); - break; - } - break; - } - return FALSE; -} - -VOID -SaveOptionsPopup(HWND hwnd) -{ - FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * Time Control Options dialog functions - * -\*---------------------------------------------------------------------------*/ - -VOID -SetTimeControlEnables(HWND hDlg) -{ - UINT state; - - state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves); - EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state); - EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state); - EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state); - EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state); - EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state); - EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state); - EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state); - EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state); - EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state); -} - - -LRESULT CALLBACK -TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MSG_SIZ]; - int mps, increment, odds1, odds2; - BOOL ok, ok2; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - /* Initialize the dialog items */ - if (appData.clockMode && !appData.icsActive) { - if (appData.timeIncrement == -1) { - CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc, - OPT_TCUseMoves); - SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl); - SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession, - FALSE); - SetDlgItemText(hDlg, OPT_TCTime2, ""); - SetDlgItemText(hDlg, OPT_TCInc, ""); - } else { - CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc, - OPT_TCUseInc); - SetDlgItemText(hDlg, OPT_TCTime, ""); - SetDlgItemText(hDlg, OPT_TCMoves, ""); - SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl); - SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE); - } - SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE); - SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE); - SetTimeControlEnables(hDlg); - } - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) { - increment = -1; - mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE); - if (!ok || mps <= 0) { - MessageBox(hDlg, "Invalid moves per time control", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ); - if (!ParseTimeControl(buf, increment, mps)) { - MessageBox(hDlg, "Invalid minutes per time control", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - } else { - increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE); - mps = appData.movesPerSession; - if (!ok || increment < 0) { - MessageBox(hDlg, "Invalid increment", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ); - if (!ParseTimeControl(buf, increment, mps)) { - MessageBox(hDlg, "Invalid initial time", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - } - odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE); - odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE); - if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) { - MessageBox(hDlg, "Invalid time-odds factor", - "Option Error", MB_OK|MB_ICONEXCLAMATION); - return FALSE; - } - appData.timeControl = strdup(buf); - appData.movesPerSession = mps; - appData.timeIncrement = increment; - appData.firstTimeOdds = first.timeOdds = odds1; - appData.secondTimeOdds = second.timeOdds = odds2; - Reset(TRUE, TRUE); - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - default: - SetTimeControlEnables(hDlg); - break; - } - break; - } - return FALSE; -} - -VOID -TimeControlOptionsPopup(HWND hwnd) -{ - if (gameMode != BeginningOfGame) { - DisplayError("Changing time control during a game is not implemented", 0); - } else { - FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); - } -} - -/*---------------------------------------------------------------------------*\ - * - * Engine Options Dialog functions - * -\*---------------------------------------------------------------------------*/ -#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) -#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) - -#define INT_ABS( n ) ((n) >= 0 ? (n) : -(n)) - -LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - - /* Initialize the dialog items */ - CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates); - CHECK_BOX(IDC_EpPonder, appData.ponderNextMove); - CHECK_BOX(IDC_EpShowThinking, appData.showThinking); - CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman); - - CHECK_BOX(IDC_TestClaims, appData.testClaims); - CHECK_BOX(IDC_DetectMates, appData.checkMates); - CHECK_BOX(IDC_MaterialDraws, appData.materialDraws); - CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws); - - CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute); - CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute); - - SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE ); - SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 ); - - SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE ); - SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 ); - - SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE ); - SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 ); - - SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE ); - SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 ); - - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - /* Read changed options from the dialog box */ - PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates)); - PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder)); - appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up -#if 0 - ShowThinkingEvent( IS_CHECKED(IDC_EpShowThinking)); -#else - appData.showThinking = IS_CHECKED(IDC_EpShowThinking); - ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output -#endif - appData.testClaims = IS_CHECKED(IDC_TestClaims); - appData.checkMates = IS_CHECKED(IDC_DetectMates); - appData.materialDraws = IS_CHECKED(IDC_MaterialDraws); - appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws); - - appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE ); - appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE ); - appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE ); - appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE ); - - appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1); - appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2); - - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case IDC_EpDrawMoveCount: - case IDC_EpAdjudicationThreshold: - case IDC_DrawRepeats: - case IDC_RuleMoves: - if( HIWORD(wParam) == EN_CHANGE ) { - int n1_ok; - int n2_ok; - int n3_ok; - int n4_ok; - - GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE ); - - EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE ); - } - return TRUE; - } - break; - } - return FALSE; -} - -VOID EnginePlayOptionsPopup(HWND hwnd) -{ - FARPROC lpProc; - - lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} - -/*---------------------------------------------------------------------------*\ - * - * UCI Options Dialog functions - * -\*---------------------------------------------------------------------------*/ -static BOOL BrowseForFolder( const char * title, char * path ) -{ - BOOL result = FALSE; - BROWSEINFO bi; - LPITEMIDLIST pidl; - - ZeroMemory( &bi, sizeof(bi) ); - - bi.lpszTitle = title == 0 ? "Choose Folder" : title; - bi.ulFlags = BIF_RETURNONLYFSDIRS; - - pidl = SHBrowseForFolder( &bi ); - - if( pidl != 0 ) { - IMalloc * imalloc = 0; - - if( SHGetPathFromIDList( pidl, path ) ) { - result = TRUE; - } - - if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) { - imalloc->lpVtbl->Free(imalloc,pidl); - imalloc->lpVtbl->Release(imalloc); - } - } - - return result; -} - -LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[MAX_PATH]; - int oldCores; - - switch (message) { - case WM_INITDIALOG: /* message: initialize dialog box */ - - /* Center the dialog over the application window */ - CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); - - /* Initialize the dialog items */ - SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir ); - SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE ); - SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB ); - SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE ); - CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook ); - SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook ); - // [HGM] smp: input field for nr of cores: - SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE ); - // [HGM] book: tick boxes for own book use - CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI ); - CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI ); - - SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 ); - - return TRUE; - - case WM_COMMAND: /* message: received a command */ - switch (LOWORD(wParam)) { - case IDOK: - GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) ); - appData.polyglotDir = strdup(buf); - appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE ); - appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE ); - GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) ); - appData.defaultPathEGTB = strdup(buf); - GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) ); - appData.polyglotBook = strdup(buf); - appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook ); - // [HGM] smp: get nr of cores: - oldCores = appData.smpCores; - appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE ); - if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores); - // [HGM] book: read tick boxes for own book use - appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 ); - appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 ); - - if(gameMode == BeginningOfGame) Reset(TRUE, TRUE); - EndDialog(hDlg, TRUE); - return TRUE; - - case IDCANCEL: - EndDialog(hDlg, FALSE); - return TRUE; - - case IDC_BrowseForBook: - { - char filter[] = { - 'A','l','l',' ','F','i','l','e','s', 0, - '*','.','*', 0, - 'B','I','N',' ','F','i','l','e','s', 0, - '*','.','b','i','n', 0, - 0 }; - - OPENFILENAME ofn; - - strcpy( buf, "" ); - - ZeroMemory( &ofn, sizeof(ofn) ); - - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = hDlg; - ofn.hInstance = hInst; - ofn.lpstrFilter = filter; - ofn.lpstrFile = buf; - ofn.nMaxFile = sizeof(buf); - ofn.lpstrTitle = "Choose Book"; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY; - - if( GetOpenFileName( &ofn ) ) { - SetDlgItemText( hDlg, IDC_BookFile, buf ); - } - } - return TRUE; - - case IDC_BrowseForPolyglotDir: - if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) { - SetDlgItemText( hDlg, IDC_PolyglotDir, buf ); - - strcat( buf, "\\polyglot.exe" ); - - if( GetFileAttributes(buf) == 0xFFFFFFFF ) { - MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING ); - } - } - return TRUE; - - case IDC_BrowseForEGTB: - if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) { - SetDlgItemText( hDlg, IDC_PathToEGTB, buf ); - } - return TRUE; - - case IDC_HashSize: - case IDC_SizeOfEGTB: - if( HIWORD(wParam) == EN_CHANGE ) { - int n1_ok; - int n2_ok; - - GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE ); - GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE ); - - EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE ); - } - return TRUE; - } - break; - } - return FALSE; -} - -VOID UciOptionsPopup(HWND hwnd) -{ - FARPROC lpProc; - - lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst); - DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc); - FreeProcInstance(lpProc); -} +/* + * woptions.c -- Options dialog box routines for WinBoard + * $Id: woptions.c,v 2.1 2003/10/27 19:21:02 mann Exp $ + * + * Copyright 2000 Free Software Foundation, Inc. + * + * ------------------------------------------------------------------------ + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * ------------------------------------------------------------------------ + */ + +#include "config.h" + +#include /* required for all Windows applications */ +#include +#include +#include /* [AS] Requires NT 4.0 or Win95 */ + +#include "common.h" +#include "winboard.h" +#include "backend.h" +#include "woptions.h" +#include "defaults.h" +#include "wedittags.h" +#include + +#if __GNUC__ +#include +#include +#endif + +/* Imports from winboard.c */ + +extern MyFont *font[NUM_SIZES][NUM_FONTS]; +extern HINSTANCE hInst; /* current instance */ +extern HWND hwndMain; /* root window*/ +extern BOOLEAN alwaysOnTop; +extern RECT boardRect; +extern COLORREF lightSquareColor, darkSquareColor, whitePieceColor, + blackPieceColor, highlightSquareColor, premoveHighlightColor; +extern HPALETTE hPal; +extern BoardSize boardSize; +extern COLORREF consoleBackgroundColor; +extern MyColorizeAttribs colorizeAttribs[]; /* do I need the size? */ +extern MyTextAttribs textAttribs[]; +extern MySound sounds[]; +extern ColorClass currentColorClass; +extern HWND hwndConsole; +extern char *defaultTextAttribs[]; +extern HWND commentDialog; +extern HWND moveHistoryDialog; +extern char installDir[]; +extern HWND hCommPort; /* currently open comm port */ +extern DCB dcb; +extern BOOLEAN chessProgram; +extern startedFromPositionFile; /* [HGM] loadPos */ + +/* types */ + +typedef struct { + char *label; + unsigned value; +} ComboData; + +typedef struct { + char *label; + char *name; +} SoundComboData; + +/* module prototypes */ + +LRESULT CALLBACK GeneralOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK BoardOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK NewVariant(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK IcsOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK FontOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK CommPortOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK LoadOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK SaveOptions(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK TimeControl(HWND, UINT, WPARAM, LPARAM); +VOID ChangeBoardSize(BoardSize newSize); +VOID PaintSampleSquare( + HWND hwnd, + int ctrlid, + COLORREF squareColor, + COLORREF pieceColor, + COLORREF squareOutlineColor, + COLORREF pieceDetailColor, + BOOL isWhitePiece, + BOOL isMono, + HBITMAP pieces[3] + ); +VOID PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color); +VOID SetBoardOptionEnables(HWND hDlg); +BoardSize BoardOptionsWhichRadio(HWND hDlg); +BOOL APIENTRY MyCreateFont(HWND hwnd, MyFont *font); +VOID UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca); +LRESULT CALLBACK ColorizeTextDialog(HWND , UINT, WPARAM, LPARAM); +VOID ColorizeTextPopup(HWND hwnd, ColorClass cc); +VOID SetIcsOptionEnables(HWND hDlg); +VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf); +VOID CopyFont(MyFont *dest, const MyFont *src); +void InitSoundComboData(SoundComboData *scd); +void ResetSoundComboData(SoundComboData *scd); +void InitSoundCombo(HWND hwndCombo, SoundComboData *scd); +int SoundDialogWhichRadio(HWND hDlg); +VOID SoundDialogSetEnables(HWND hDlg, int radio); +char * SoundDialogGetName(HWND hDlg, int radio); +void DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name); +VOID ParseCommSettings(char *arg, DCB *dcb); +VOID PrintCommSettings(FILE *f, char *name, DCB *dcb); +void InitCombo(HANDLE hwndCombo, ComboData *cd); +void SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value); +VOID SetLoadOptionEnables(HWND hDlg); +VOID SetSaveOptionEnables(HWND hDlg); +VOID SetTimeControlEnables(HWND hDlg); + +/*---------------------------------------------------------------------------*\ + * + * General Options Dialog functions + * +\*---------------------------------------------------------------------------*/ + + +LRESULT CALLBACK +GeneralOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static Boolean oldShowCoords; + static Boolean oldBlindfold; + static Boolean oldShowButtonBar; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + oldShowCoords = appData.showCoords; + oldBlindfold = appData.blindfold; + oldShowButtonBar = appData.showButtonBar; + + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + + /* Initialize the dialog items */ +#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) + + CHECK_BOX(OPT_AlwaysOnTop, alwaysOnTop); + CHECK_BOX(OPT_AlwaysQueen, appData.alwaysPromoteToQueen); + CHECK_BOX(OPT_AnimateDragging, appData.animateDragging); + CHECK_BOX(OPT_AnimateMoving, appData.animate); + CHECK_BOX(OPT_AutoFlag, appData.autoCallFlag); + CHECK_BOX(OPT_AutoFlipView, appData.autoFlipView); + CHECK_BOX(OPT_AutoRaiseBoard, appData.autoRaiseBoard); + CHECK_BOX(OPT_Blindfold, appData.blindfold); + CHECK_BOX(OPT_HighlightDragging, appData.highlightDragging); + CHECK_BOX(OPT_HighlightLastMove, appData.highlightLastMove); + CHECK_BOX(OPT_PeriodicUpdates, appData.periodicUpdates); + CHECK_BOX(OPT_PonderNextMove, appData.ponderNextMove); + CHECK_BOX(OPT_PopupExitMessage, appData.popupExitMessage); + CHECK_BOX(OPT_PopupMoveErrors, appData.popupMoveErrors); + CHECK_BOX(OPT_ShowButtonBar, appData.showButtonBar); + CHECK_BOX(OPT_ShowCoordinates, appData.showCoords); + CHECK_BOX(OPT_ShowThinking, appData.showThinking); + CHECK_BOX(OPT_TestLegality, appData.testLegality); + CHECK_BOX(OPT_HideThinkFromHuman, appData.hideThinkingFromHuman); + CHECK_BOX(OPT_SaveExtPGN, appData.saveExtendedInfoInPGN); + CHECK_BOX(OPT_ExtraInfoInMoveHistory, appData.showEvalInMoveHistory); + CHECK_BOX(OPT_HighlightMoveArrow, appData.highlightMoveWithArrow); + +#undef CHECK_BOX + + EnableWindow(GetDlgItem(hDlg, OPT_AutoFlag), + appData.icsActive || !appData.noChessProgram); + EnableWindow(GetDlgItem(hDlg, OPT_AutoFlipView), + appData.icsActive || !appData.noChessProgram); + EnableWindow(GetDlgItem(hDlg, OPT_PonderNextMove), + !appData.noChessProgram); + EnableWindow(GetDlgItem(hDlg, OPT_PeriodicUpdates), + !appData.noChessProgram && !appData.icsActive); + EnableWindow(GetDlgItem(hDlg, OPT_ShowThinking), + !appData.noChessProgram); + return TRUE; + + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + +#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) + + alwaysOnTop = IS_CHECKED(OPT_AlwaysOnTop); + appData.alwaysPromoteToQueen = IS_CHECKED(OPT_AlwaysQueen); + appData.animateDragging = IS_CHECKED(OPT_AnimateDragging); + appData.animate = IS_CHECKED(OPT_AnimateMoving); + appData.autoCallFlag = IS_CHECKED(OPT_AutoFlag); + appData.autoFlipView = IS_CHECKED(OPT_AutoFlipView); + appData.autoRaiseBoard = IS_CHECKED(OPT_AutoRaiseBoard); + appData.blindfold = IS_CHECKED(OPT_Blindfold); + appData.highlightDragging = IS_CHECKED(OPT_HighlightDragging); + appData.highlightLastMove = IS_CHECKED(OPT_HighlightLastMove); + PeriodicUpdatesEvent( IS_CHECKED(OPT_PeriodicUpdates)); + PonderNextMoveEvent( IS_CHECKED(OPT_PonderNextMove)); + appData.popupExitMessage = IS_CHECKED(OPT_PopupExitMessage); + appData.popupMoveErrors = IS_CHECKED(OPT_PopupMoveErrors); + appData.showButtonBar = IS_CHECKED(OPT_ShowButtonBar); + appData.showCoords = IS_CHECKED(OPT_ShowCoordinates); + // [HGM] thinking: next three moved up + appData.saveExtendedInfoInPGN= IS_CHECKED(OPT_SaveExtPGN); + appData.hideThinkingFromHuman= IS_CHECKED(OPT_HideThinkFromHuman); + appData.showEvalInMoveHistory= IS_CHECKED(OPT_ExtraInfoInMoveHistory); +#if 0 + ShowThinkingEvent( IS_CHECKED(OPT_ShowThinking)); +#else + appData.showThinking = IS_CHECKED(OPT_ShowThinking); + ShowThinkingEvent(); // [HGM] thinking: tests four options +#endif + appData.testLegality = IS_CHECKED(OPT_TestLegality); + appData.highlightMoveWithArrow=IS_CHECKED(OPT_HighlightMoveArrow); + +#undef IS_CHECKED + + SetWindowPos(hwndMain, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); +#if AOT_CONSOLE + if (hwndConsole) { + SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, + 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } +#endif + if (!appData.highlightLastMove) { + ClearHighlights(); + DrawPosition(FALSE, NULL); + } + /* + * for some reason the redraw seems smoother when we invalidate + * the board rect after the call to EndDialog() + */ + EndDialog(hDlg, TRUE); + + if (oldShowButtonBar != appData.showButtonBar) { + InitDrawingSizes(boardSize, 0); + } else if ((oldShowCoords != appData.showCoords) || + (oldBlindfold != appData.blindfold)) { + InvalidateRect(hwndMain, &boardRect, FALSE); + } + + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + } + break; + } + return FALSE; +} + +VOID +GeneralOptionsPopup(HWND hwnd) +{ + FARPROC lpProc; + + lpProc = MakeProcInstance((FARPROC)GeneralOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_GeneralOptions), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} +/*---------------------------------------------------------------------------*\ + * + * Board Options Dialog functions + * +\*---------------------------------------------------------------------------*/ + +const int SAMPLE_SQ_SIZE = 54; + +VOID +ChangeBoardSize(BoardSize newSize) +{ + if (newSize != boardSize) { + boardSize = newSize; + InitDrawingSizes(boardSize, 0); + } +} + +VOID +PaintSampleSquare( + HWND hwnd, + int ctrlid, + COLORREF squareColor, + COLORREF pieceColor, + COLORREF squareOutlineColor, + COLORREF pieceDetailColor, + BOOL isWhitePiece, + BOOL isMono, + HBITMAP pieces[3] + ) +{ + HBRUSH brushSquare; + HBRUSH brushSquareOutline; + HBRUSH brushPiece; + HBRUSH brushPieceDetail; + HBRUSH oldBrushPiece; + HBRUSH oldBrushSquare; + HBITMAP oldBitmapMem; + HBITMAP oldBitmapTemp; + HBITMAP bufferBitmap; + RECT rect; + HDC hdcScreen, hdcMem, hdcTemp; + HPEN pen, oldPen; + HWND hCtrl = GetDlgItem(hwnd, ctrlid); + int x, y; + + const int SOLID = 0; + const int WHITE = 1; + const int OUTLINE = 2; + const int BORDER = 4; + + InvalidateRect(hCtrl, NULL, TRUE); + UpdateWindow(hCtrl); + GetClientRect(hCtrl, &rect); + x = rect.left + (BORDER / 2); + y = rect.top + (BORDER / 2); + hdcScreen = GetDC(hCtrl); + hdcMem = CreateCompatibleDC(hdcScreen); + hdcTemp = CreateCompatibleDC(hdcScreen); + + bufferBitmap = CreateCompatibleBitmap(hdcScreen, rect.right-rect.left+1, + rect.bottom-rect.top+1); + oldBitmapMem = SelectObject(hdcMem, bufferBitmap); + if (!isMono) { + SelectPalette(hdcMem, hPal, FALSE); + } + brushSquare = CreateSolidBrush(squareColor); + brushSquareOutline = CreateSolidBrush(squareOutlineColor); + brushPiece = CreateSolidBrush(pieceColor); + brushPieceDetail = CreateSolidBrush(pieceDetailColor); + + /* + * first draw the rectangle + */ + pen = CreatePen(PS_SOLID, BORDER, squareOutlineColor); + oldPen = (HPEN) SelectObject(hdcMem, pen); + oldBrushSquare = (HBRUSH)SelectObject(hdcMem, brushSquare); + Rectangle(hdcMem, rect.left, rect.top, rect.right, rect.bottom); + + /* + * now draw the piece + */ + if (isMono) { + oldBitmapTemp = SelectObject(hdcTemp, pieces[OUTLINE]); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, hdcTemp, 0, 0, + isWhitePiece ? SRCCOPY : NOTSRCCOPY); + SelectObject(hdcTemp, oldBitmapTemp); + } else { + if (isWhitePiece) { + oldBitmapTemp = SelectObject(hdcTemp, pieces[WHITE]); + oldBrushPiece = SelectObject(hdcMem, brushPiece); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, 0x00B8074A); +#if 0 + /* Use pieceDetailColor for outline of white pieces */ + SelectObject(hdcTemp, pieces[OUTLINE]); + SelectObject(hdcMem, brushPieceDetail); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, 0x00B8074A); +#else + /* Use black for outline of white pieces */ + SelectObject(hdcTemp, pieces[OUTLINE]); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, SRCAND); +#endif + } else { +#if 0 + /* Use pieceDetailColor for details of black pieces */ + /* Requires filled-in solid bitmaps (BLACK_PIECE class); the + WHITE_PIECE ones aren't always the right shape. */ + oldBitmapTemp = SelectObject(hdcTemp, pieces[BLACK]); + oldBrushPiece = SelectObject(hdcMem, brushPieceDetail); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, 0x00B8074A); + SelectObject(hdcTemp, pieces[SOLID]); + SelectObject(hdcMem, brushPiece); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, 0x00B8074A); +#else + /* Use square color for details of black pieces */ + oldBitmapTemp = SelectObject(hdcTemp, pieces[SOLID]); + oldBrushPiece = SelectObject(hdcMem, brushPiece); + BitBlt(hdcMem, x, y, SAMPLE_SQ_SIZE, SAMPLE_SQ_SIZE, + hdcTemp, 0, 0, 0x00B8074A); +#endif + } + SelectObject(hdcMem, oldBrushPiece); + SelectObject(hdcTemp, oldBitmapTemp); + } + /* + * copy the memory dc to the screen + */ + SelectObject(hdcMem, bufferBitmap); + BitBlt(hdcScreen, rect.left, rect.top, + rect.right - rect.left, + rect.bottom - rect.top, + hdcMem, rect.left, rect.top, SRCCOPY); + SelectObject(hdcMem, oldBitmapMem); + /* + * clean up + */ + SelectObject(hdcMem, oldBrushPiece); + SelectObject(hdcMem, oldPen); + DeleteObject(brushPiece); + DeleteObject(brushPieceDetail); + DeleteObject(brushSquare); + DeleteObject(brushSquareOutline); + DeleteObject(pen); + DeleteDC(hdcTemp); + DeleteDC(hdcMem); + ReleaseDC(hCtrl, hdcScreen); +} + + +VOID +PaintColorBlock(HWND hwnd, int ctrlid, COLORREF color) +{ + HDC hdc; + HBRUSH brush, oldBrush; + RECT rect; + HWND hCtrl = GetDlgItem(hwnd, ctrlid); + + hdc = GetDC(hCtrl); + InvalidateRect(hCtrl, NULL, TRUE); + UpdateWindow(hCtrl); + GetClientRect(hCtrl, &rect); + brush = CreateSolidBrush(color); + oldBrush = (HBRUSH)SelectObject(hdc, brush); + Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom); + SelectObject(hdc, oldBrush); + DeleteObject(brush); + ReleaseDC(hCtrl, hdc); +} + + +VOID +SetBoardOptionEnables(HWND hDlg) +{ + if (IsDlgButtonChecked(hDlg, OPT_Monochrome)) { + ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_HIDE); + ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_HIDE); + ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_HIDE); + ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_HIDE); + + EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), FALSE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), FALSE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), FALSE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), FALSE); + } else { + ShowWindow(GetDlgItem(hDlg, OPT_LightSquareColor), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, OPT_DarkSquareColor), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, OPT_WhitePieceColor), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, OPT_BlackPieceColor), SW_SHOW); + + EnableWindow(GetDlgItem(hDlg, OPT_ChooseLightSquareColor), TRUE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseDarkSquareColor), TRUE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseWhitePieceColor), TRUE); + EnableWindow(GetDlgItem(hDlg, OPT_ChooseBlackPieceColor), TRUE); + } +} + +BoardSize +BoardOptionsWhichRadio(HWND hDlg) +{ + return (IsDlgButtonChecked(hDlg, OPT_SizeTiny) ? SizeTiny : + (IsDlgButtonChecked(hDlg, OPT_SizeTeeny) ? SizeTeeny : + (IsDlgButtonChecked(hDlg, OPT_SizeDinky) ? SizeDinky : + (IsDlgButtonChecked(hDlg, OPT_SizePetite) ? SizePetite : + (IsDlgButtonChecked(hDlg, OPT_SizeSlim) ? SizeSlim : + (IsDlgButtonChecked(hDlg, OPT_SizeSmall) ? SizeSmall : + (IsDlgButtonChecked(hDlg, OPT_SizeMediocre) ? SizeMediocre : + (IsDlgButtonChecked(hDlg, OPT_SizeMiddling) ? SizeMiddling : + (IsDlgButtonChecked(hDlg, OPT_SizeAverage) ? SizeAverage : + (IsDlgButtonChecked(hDlg, OPT_SizeModerate) ? SizeModerate : + (IsDlgButtonChecked(hDlg, OPT_SizeMedium) ? SizeMedium : + (IsDlgButtonChecked(hDlg, OPT_SizeBulky) ? SizeBulky : + (IsDlgButtonChecked(hDlg, OPT_SizeLarge) ? SizeLarge : + (IsDlgButtonChecked(hDlg, OPT_SizeBig) ? SizeBig : + (IsDlgButtonChecked(hDlg, OPT_SizeHuge) ? SizeHuge : + (IsDlgButtonChecked(hDlg, OPT_SizeGiant) ? SizeGiant : + (IsDlgButtonChecked(hDlg, OPT_SizeColossal) ? SizeColossal : + SizeTitanic ))))))))))))))))); +} + +LRESULT CALLBACK +BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static Boolean mono, white, flip; + static BoardSize size; + static COLORREF lsc, dsc, wpc, bpc, hsc, phc; + static HBITMAP pieces[3]; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + switch (boardSize) { + case SizeTiny: + CheckDlgButton(hDlg, OPT_SizeTiny, TRUE); + break; + case SizeTeeny: + CheckDlgButton(hDlg, OPT_SizeTeeny, TRUE); + break; + case SizeDinky: + CheckDlgButton(hDlg, OPT_SizeDinky, TRUE); + break; + case SizePetite: + CheckDlgButton(hDlg, OPT_SizePetite, TRUE); + break; + case SizeSlim: + CheckDlgButton(hDlg, OPT_SizeSlim, TRUE); + break; + case SizeSmall: + CheckDlgButton(hDlg, OPT_SizeSmall, TRUE); + break; + case SizeMediocre: + CheckDlgButton(hDlg, OPT_SizeMediocre, TRUE); + break; + case SizeMiddling: + CheckDlgButton(hDlg, OPT_SizeMiddling, TRUE); + break; + case SizeAverage: + CheckDlgButton(hDlg, OPT_SizeAverage, TRUE); + break; + case SizeModerate: + CheckDlgButton(hDlg, OPT_SizeModerate, TRUE); + break; + case SizeMedium: + CheckDlgButton(hDlg, OPT_SizeMedium, TRUE); + break; + case SizeBulky: + CheckDlgButton(hDlg, OPT_SizeBulky, TRUE); + break; + case SizeLarge: + CheckDlgButton(hDlg, OPT_SizeLarge, TRUE); + break; + case SizeBig: + CheckDlgButton(hDlg, OPT_SizeBig, TRUE); + break; + case SizeHuge: + CheckDlgButton(hDlg, OPT_SizeHuge, TRUE); + break; + case SizeGiant: + CheckDlgButton(hDlg, OPT_SizeGiant, TRUE); + break; + case SizeColossal: + CheckDlgButton(hDlg, OPT_SizeColossal, TRUE); + break; + case SizeTitanic: + CheckDlgButton(hDlg, OPT_SizeTitanic, TRUE); + } + + if (appData.monoMode) + CheckDlgButton(hDlg, OPT_Monochrome, TRUE); + + if (appData.allWhite) + CheckDlgButton(hDlg, OPT_AllWhite, TRUE); + + if (appData.upsideDown) + CheckDlgButton(hDlg, OPT_UpsideDown, TRUE); + + pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s"); + pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w"); + pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o"); + + lsc = lightSquareColor; + dsc = darkSquareColor; + wpc = whitePieceColor; + bpc = blackPieceColor; + hsc = highlightSquareColor; + phc = premoveHighlightColor; + mono = appData.monoMode; + white= appData.allWhite; + flip = appData.upsideDown; + size = boardSize; + + SetBoardOptionEnables(hDlg); + return TRUE; + + case WM_PAINT: + PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); + PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); + PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); + PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); + PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); + PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); + PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, + TRUE, mono, pieces); + PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, + FALSE, mono, pieces); + + return FALSE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* + * if we call EndDialog() after the call to ChangeBoardSize(), + * then ChangeBoardSize() does not take effect, although the new + * boardSize is saved. Go figure... + */ + EndDialog(hDlg, TRUE); + + size = BoardOptionsWhichRadio(hDlg); + + /* + * did any settings change? + */ + if (size != boardSize) { + ChangeBoardSize(size); + } + + if ((mono != appData.monoMode) || + (lsc != lightSquareColor) || + (dsc != darkSquareColor) || + (wpc != whitePieceColor) || + (bpc != blackPieceColor) || + (hsc != highlightSquareColor) || + (flip != appData.upsideDown) || + (white != appData.allWhite) || + (phc != premoveHighlightColor)) { + + lightSquareColor = lsc; + darkSquareColor = dsc; + whitePieceColor = wpc; + blackPieceColor = bpc; + highlightSquareColor = hsc; + premoveHighlightColor = phc; + appData.monoMode = mono; + appData.allWhite = white; + appData.upsideDown = flip; + + InitDrawingColors(); + InitDrawingSizes(boardSize, 0); + InvalidateRect(hwndMain, &boardRect, FALSE); + } + DeleteObject(pieces[0]); + DeleteObject(pieces[1]); + DeleteObject(pieces[2]); + return TRUE; + + case IDCANCEL: + DeleteObject(pieces[0]); + DeleteObject(pieces[1]); + DeleteObject(pieces[2]); + EndDialog(hDlg, FALSE); + return TRUE; + + case OPT_ChooseLightSquareColor: + if (ChangeColor(hDlg, &lsc)) + PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); + PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, + TRUE, mono, pieces); + break; + + case OPT_ChooseDarkSquareColor: + if (ChangeColor(hDlg, &dsc)) + PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); + PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, + FALSE, mono, pieces); + break; + + case OPT_ChooseWhitePieceColor: + if (ChangeColor(hDlg, &wpc)) + PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); + PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, + TRUE, mono, pieces); + break; + + case OPT_ChooseBlackPieceColor: + if (ChangeColor(hDlg, &bpc)) + PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); + PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, + FALSE, mono, pieces); + break; + + case OPT_ChooseHighlightSquareColor: + if (ChangeColor(hDlg, &hsc)) + PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); + PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, + TRUE, mono, pieces); + break; + + case OPT_ChoosePremoveHighlightColor: + if (ChangeColor(hDlg, &phc)) + PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); + PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, + FALSE, mono, pieces); + break; + + case OPT_DefaultBoardColors: + lsc = ParseColorName(LIGHT_SQUARE_COLOR); + dsc = ParseColorName(DARK_SQUARE_COLOR); + wpc = ParseColorName(WHITE_PIECE_COLOR); + bpc = ParseColorName(BLACK_PIECE_COLOR); + hsc = ParseColorName(HIGHLIGHT_SQUARE_COLOR); + phc = ParseColorName(PREMOVE_HIGHLIGHT_COLOR); + mono = FALSE; + white= FALSE; + flip = FALSE; + CheckDlgButton(hDlg, OPT_Monochrome, FALSE); + CheckDlgButton(hDlg, OPT_AllWhite, FALSE); + CheckDlgButton(hDlg, OPT_UpsideDown, FALSE); + PaintColorBlock(hDlg, OPT_LightSquareColor, lsc); + PaintColorBlock(hDlg, OPT_DarkSquareColor, dsc); + PaintColorBlock(hDlg, OPT_WhitePieceColor, wpc); + PaintColorBlock(hDlg, OPT_BlackPieceColor, bpc); + PaintColorBlock(hDlg, OPT_HighlightSquareColor, hsc); + PaintColorBlock(hDlg, OPT_PremoveHighlightColor, phc); + SetBoardOptionEnables(hDlg); + PaintSampleSquare(hDlg, OPT_SampleLightSquare, lsc, wpc, hsc, bpc, + TRUE, mono, pieces); + PaintSampleSquare(hDlg, OPT_SampleDarkSquare, dsc, bpc, phc, wpc, + FALSE, mono, pieces); + break; + + case OPT_Monochrome: + mono = !mono; + SetBoardOptionEnables(hDlg); + break; + + case OPT_AllWhite: + white = !white; + SetBoardOptionEnables(hDlg); + break; + + case OPT_UpsideDown: + flip = !flip; + SetBoardOptionEnables(hDlg); + break; + } + break; + } + return FALSE; +} + + +VOID +BoardOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)BoardOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_BoardOptions), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +VariantClass +VariantWhichRadio(HWND hDlg) +{ + return (IsDlgButtonChecked(hDlg, OPT_VariantFairy) ? VariantFairy : + (IsDlgButtonChecked(hDlg, OPT_VariantGothic) ? VariantGothic : + (IsDlgButtonChecked(hDlg, OPT_VariantCrazyhouse) ? VariantCrazyhouse : + (IsDlgButtonChecked(hDlg, OPT_VariantBughouse) ? VariantBughouse : + (IsDlgButtonChecked(hDlg, OPT_VariantCourier) ? VariantCourier : + (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : + (IsDlgButtonChecked(hDlg, OPT_VariantShogi) ? VariantShogi : + (IsDlgButtonChecked(hDlg, OPT_VariantXiangqi) ? VariantXiangqi : + (IsDlgButtonChecked(hDlg, OPT_VariantCapablanca) ? VariantCapablanca : + (IsDlgButtonChecked(hDlg, OPT_VariantTwoKings) ? VariantTwoKings : + (IsDlgButtonChecked(hDlg, OPT_VariantKnightmate) ? VariantKnightmate : + (IsDlgButtonChecked(hDlg, OPT_VariantLosers) ? VariantLosers : + (IsDlgButtonChecked(hDlg, OPT_VariantSuicide) ? VariantSuicide : + (IsDlgButtonChecked(hDlg, OPT_VariantAtomic) ? VariantAtomic : + (IsDlgButtonChecked(hDlg, OPT_VariantShatranj) ? VariantShatranj : + (IsDlgButtonChecked(hDlg, OPT_VariantFRC) ? VariantFischeRandom : + (IsDlgButtonChecked(hDlg, OPT_VariantCylinder) ? VariantCylinder : + (IsDlgButtonChecked(hDlg, OPT_VariantFalcon) ? VariantFalcon : + (IsDlgButtonChecked(hDlg, OPT_VariantCRC) ? VariantCapaRandom : + (IsDlgButtonChecked(hDlg, OPT_VariantSuper) ? VariantSuper : + (IsDlgButtonChecked(hDlg, OPT_VariantBerolina) ? VariantBerolina : + (IsDlgButtonChecked(hDlg, OPT_VariantJanus) ? VariantJanus : + (IsDlgButtonChecked(hDlg, OPT_VariantWildcastle) ? VariantWildCastle : + (IsDlgButtonChecked(hDlg, OPT_VariantNocastle) ? VariantNoCastle : + VariantNormal )))))))))))))))))))))))); +} + +LRESULT CALLBACK +NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static Boolean mono; + static VariantClass v; + static COLORREF lsc, dsc, wpc, bpc, hsc, phc; + static HBITMAP pieces[3]; + static int n1_ok, n2_ok, n3_ok; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + switch (gameInfo.variant) { + case VariantNormal: + CheckDlgButton(hDlg, OPT_VariantNormal, TRUE); + break; + case VariantCrazyhouse: + CheckDlgButton(hDlg, OPT_VariantCrazyhouse, TRUE); + break; + case VariantBughouse: + CheckDlgButton(hDlg, OPT_VariantBughouse, TRUE); + break; + case VariantShogi: + CheckDlgButton(hDlg, OPT_VariantShogi, TRUE); + break; + case VariantXiangqi: + CheckDlgButton(hDlg, OPT_VariantXiangqi, TRUE); + break; + case VariantCapablanca: + CheckDlgButton(hDlg, OPT_VariantCapablanca, TRUE); + break; + case VariantGothic: + CheckDlgButton(hDlg, OPT_VariantGothic, TRUE); + break; + case VariantCourier: + CheckDlgButton(hDlg, OPT_VariantCourier, TRUE); + break; + case VariantKnightmate: + CheckDlgButton(hDlg, OPT_VariantKnightmate, TRUE); + break; + case VariantTwoKings: + CheckDlgButton(hDlg, OPT_VariantTwoKings, TRUE); + break; + case VariantFairy: + CheckDlgButton(hDlg, OPT_VariantFairy, TRUE); + break; + case VariantAtomic: + CheckDlgButton(hDlg, OPT_VariantAtomic, TRUE); + break; + case VariantSuicide: + CheckDlgButton(hDlg, OPT_VariantSuicide, TRUE); + break; + case VariantLosers: + CheckDlgButton(hDlg, OPT_VariantLosers, TRUE); + break; + case VariantShatranj: + CheckDlgButton(hDlg, OPT_VariantShatranj, TRUE); + break; + case VariantFischeRandom: + CheckDlgButton(hDlg, OPT_VariantFRC, TRUE); + break; + case VariantCapaRandom: + CheckDlgButton(hDlg, OPT_VariantCRC, TRUE); + break; + case VariantFalcon: + CheckDlgButton(hDlg, OPT_VariantFalcon, TRUE); + break; + case VariantCylinder: + CheckDlgButton(hDlg, OPT_VariantCylinder, TRUE); + break; + case Variant3Check: + case VariantSuper: + CheckDlgButton(hDlg, OPT_VariantSuper, TRUE); + break; + case VariantBerolina: + CheckDlgButton(hDlg, OPT_VariantBerolina, TRUE); + break; + case VariantJanus: + CheckDlgButton(hDlg, OPT_VariantJanus, TRUE); + break; + case VariantWildCastle: + CheckDlgButton(hDlg, OPT_VariantWildcastle, TRUE); + break; + case VariantNoCastle: + CheckDlgButton(hDlg, OPT_VariantNocastle, TRUE); + break; + } + + SetDlgItemInt( hDlg, IDC_Files, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Files, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_Ranks, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_Holdings, -1, TRUE ); + SendDlgItemMessage( hDlg, IDC_Ranks, EM_SETSEL, 0, -1 ); + + n1_ok = n2_ok = n3_ok = FALSE; + + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* + * if we call EndDialog() after the call to ChangeBoardSize(), + * then ChangeBoardSize() does not take effect, although the new + * boardSize is saved. Go figure... + */ + EndDialog(hDlg, TRUE); + + v = VariantWhichRadio(hDlg); + if(!appData.noChessProgram) { char *name = VariantName(v), buf[MSG_SIZ]; + if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) { + /* [HGM] in protocol 2 we check if variant is suported by engine */ + sprintf(buf, "Variant %s not supported by %s", name, first.tidy); + DisplayError(buf, 0); + return TRUE; /* treat as "Cancel" if first engine does not support it */ + } else + if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) { + sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy); + DisplayError(buf, 0); /* use of second engine is optional; only warn user */ + } + } + + gameInfo.variant = v; + appData.variant = VariantName(v); + + appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE ); + appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE ); + appData.holdingsSize = (int) GetDlgItemInt(hDlg, IDC_Holdings, NULL, FALSE ); + + if(!n1_ok) appData.NrFiles = -1; + if(!n2_ok) appData.NrRanks = -1; + if(!n3_ok) appData.holdingsSize = -1; + + shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ + startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ + appData.pieceToCharTable = NULL; + Reset(TRUE, TRUE); + + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case IDC_Ranks: + case IDC_Files: + case IDC_Holdings: + if( HIWORD(wParam) == EN_CHANGE ) { + + GetDlgItemInt(hDlg, IDC_Files, &n1_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_Ranks, &n2_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_Holdings, &n3_ok, FALSE ); + + /*EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok ? TRUE : FALSE );*/ + } + return TRUE; + } + break; + } + return FALSE; +} + + +VOID +NewVariantPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)NewVariantDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_NewVariant), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * ICS Options Dialog functions + * +\*---------------------------------------------------------------------------*/ + +BOOL APIENTRY +MyCreateFont(HWND hwnd, MyFont *font) +{ + CHOOSEFONT cf; + HFONT hf; + + /* Initialize members of the CHOOSEFONT structure. */ + cf.lStructSize = sizeof(CHOOSEFONT); + cf.hwndOwner = hwnd; + cf.hDC = (HDC)NULL; + cf.lpLogFont = &font->lf; + cf.iPointSize = 0; + cf.Flags = CF_SCREENFONTS|/*CF_ANSIONLY|*/CF_INITTOLOGFONTSTRUCT; + cf.rgbColors = RGB(0,0,0); + cf.lCustData = 0L; + cf.lpfnHook = (LPCFHOOKPROC)NULL; + cf.lpTemplateName = (LPSTR)NULL; + cf.hInstance = (HINSTANCE) NULL; + cf.lpszStyle = (LPSTR)NULL; + cf.nFontType = SCREEN_FONTTYPE; + cf.nSizeMin = 0; + cf.nSizeMax = 0; + + /* Display the CHOOSEFONT common-dialog box. */ + if (!ChooseFont(&cf)) { + return FALSE; + } + + /* Create a logical font based on the user's */ + /* selection and return a handle identifying */ + /* that font. */ + hf = CreateFontIndirect(cf.lpLogFont); + if (hf == NULL) { + return FALSE; + } + + font->hf = hf; + font->mfp.pointSize = (float) (cf.iPointSize / 10.0); + font->mfp.bold = (font->lf.lfWeight >= FW_BOLD); + font->mfp.italic = font->lf.lfItalic; + font->mfp.underline = font->lf.lfUnderline; + font->mfp.strikeout = font->lf.lfStrikeOut; + strcpy(font->mfp.faceName, font->lf.lfFaceName); + return TRUE; +} + + +VOID +UpdateSampleText(HWND hDlg, int id, MyColorizeAttribs *mca) +{ + CHARFORMAT cf; + cf.cbSize = sizeof(CHARFORMAT); + cf.dwMask = + CFM_COLOR|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE; + cf.crTextColor = mca->color; + cf.dwEffects = mca->effects; + strcpy(cf.szFaceName, font[boardSize][CONSOLE_FONT]->mfp.faceName); + /* + * The 20.0 below is in fact documented. yHeight is expressed in twips. + * A twip is 1/20 of a font's point size. See documentation of CHARFORMAT. + * --msw + */ + cf.yHeight = (int)(font[boardSize][CONSOLE_FONT]->mfp.pointSize * 20.0 + 0.5); + cf.bCharSet = DEFAULT_CHARSET; /* should be ignored anyway */ + cf.bPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE; + SendDlgItemMessage(hDlg, id, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); +} + +LRESULT CALLBACK +ColorizeTextDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static MyColorizeAttribs mca; + static ColorClass cc; + COLORREF background = (COLORREF)0; + + switch (message) { + case WM_INITDIALOG: + cc = (ColorClass)lParam; + mca = colorizeAttribs[cc]; + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + CheckDlgButton(hDlg, OPT_Bold, (mca.effects & CFE_BOLD) != 0); + CheckDlgButton(hDlg, OPT_Italic, (mca.effects & CFE_ITALIC) != 0); + CheckDlgButton(hDlg, OPT_Underline, (mca.effects & CFE_UNDERLINE) != 0); + CheckDlgButton(hDlg, OPT_Strikeout, (mca.effects & CFE_STRIKEOUT) != 0); + + /* get the current background color from the parent window */ + SendMessage(GetWindow(hDlg, GW_OWNER),WM_COMMAND, + (WPARAM)WM_USER_GetConsoleBackground, + (LPARAM)&background); + + /* set the background color */ + SendDlgItemMessage(hDlg, OPT_Sample, EM_SETBKGNDCOLOR, FALSE, background); + + SetDlgItemText(hDlg, OPT_Sample, mca.name); + UpdateSampleText(hDlg, OPT_Sample, &mca); + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + colorizeAttribs[cc] = mca; + textAttribs[cc].color = mca.color; + textAttribs[cc].effects = mca.effects; + Colorize(currentColorClass, TRUE); + if (cc == ColorNormal) { + CHARFORMAT cf; + cf.cbSize = sizeof(CHARFORMAT); + cf.dwMask = CFM_COLOR; + cf.crTextColor = mca.color; + SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, + EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + } + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case OPT_ChooseColor: + ChangeColor(hDlg, &mca.color); + UpdateSampleText(hDlg, OPT_Sample, &mca); + return TRUE; + + default: + mca.effects = + (IsDlgButtonChecked(hDlg, OPT_Bold) ? CFE_BOLD : 0) | + (IsDlgButtonChecked(hDlg, OPT_Italic) ? CFE_ITALIC : 0) | + (IsDlgButtonChecked(hDlg, OPT_Underline) ? CFE_UNDERLINE : 0) | + (IsDlgButtonChecked(hDlg, OPT_Strikeout) ? CFE_STRIKEOUT : 0); + UpdateSampleText(hDlg, OPT_Sample, &mca); + break; + } + break; + } + return FALSE; +} + +VOID +ColorizeTextPopup(HWND hwnd, ColorClass cc) +{ + FARPROC lpProc; + + lpProc = MakeProcInstance((FARPROC)ColorizeTextDialog, hInst); + DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_Colorize), + hwnd, (DLGPROC)lpProc, (LPARAM) cc); + FreeProcInstance(lpProc); +} + +VOID +SetIcsOptionEnables(HWND hDlg) +{ +#define ENABLE_DLG_ITEM(x,y) EnableWindow(GetDlgItem(hDlg,(x)), (y)) + + UINT state = IsDlgButtonChecked(hDlg, OPT_Premove); + ENABLE_DLG_ITEM(OPT_PremoveWhite, state); + ENABLE_DLG_ITEM(OPT_PremoveWhiteText, state); + ENABLE_DLG_ITEM(OPT_PremoveBlack, state); + ENABLE_DLG_ITEM(OPT_PremoveBlackText, state); + + ENABLE_DLG_ITEM(OPT_IcsAlarmTime, IsDlgButtonChecked(hDlg, OPT_IcsAlarm)); + +#undef ENABLE_DLG_ITEM +} + + +LRESULT CALLBACK +IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + int number; + int i; + static COLORREF cbc; + static MyColorizeAttribs *mca; + COLORREF *colorref; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + + mca = colorizeAttribs; + + for (i=0; i < NColorClasses - 1; i++) { + mca[i].color = textAttribs[i].color; + mca[i].effects = textAttribs[i].effects; + } + cbc = consoleBackgroundColor; + + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + + /* Initialize the dialog items */ +#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) + + CHECK_BOX(OPT_AutoComment, appData.autoComment); + CHECK_BOX(OPT_AutoObserve, appData.autoObserve); + CHECK_BOX(OPT_GetMoveList, appData.getMoveList); + CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing); + CHECK_BOX(OPT_QuietPlay, appData.quietPlay); + CHECK_BOX(OPT_Premove, appData.premove); + CHECK_BOX(OPT_PremoveWhite, appData.premoveWhite); + CHECK_BOX(OPT_PremoveBlack, appData.premoveBlack); + CHECK_BOX(OPT_IcsAlarm, appData.icsAlarm); + CHECK_BOX(OPT_DontColorize, !appData.colorize); + +#undef CHECK_BOX + + sprintf(buf, "%d", appData.icsAlarmTime / 1000); + SetDlgItemText(hDlg, OPT_IcsAlarmTime, buf); + SetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText); + SetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText); + + SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); + + SetDlgItemText(hDlg, OPT_SampleShout, mca[ColorShout].name); + SetDlgItemText(hDlg, OPT_SampleSShout, mca[ColorSShout].name); + SetDlgItemText(hDlg, OPT_SampleChannel1, mca[ColorChannel1].name); + SetDlgItemText(hDlg, OPT_SampleChannel, mca[ColorChannel].name); + SetDlgItemText(hDlg, OPT_SampleKibitz, mca[ColorKibitz].name); + SetDlgItemText(hDlg, OPT_SampleTell, mca[ColorTell].name); + SetDlgItemText(hDlg, OPT_SampleChallenge, mca[ColorChallenge].name); + SetDlgItemText(hDlg, OPT_SampleRequest, mca[ColorRequest].name); + SetDlgItemText(hDlg, OPT_SampleSeek, mca[ColorSeek].name); + SetDlgItemText(hDlg, OPT_SampleNormal, mca[ColorNormal].name); + + UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); + UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); + UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]); + UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); + UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); + UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); + UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); + UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); + UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); + UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); + + SetIcsOptionEnables(hDlg); + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + + case WM_USER_GetConsoleBackground: + /* the ColorizeTextDialog needs the current background color */ + colorref = (COLORREF *)lParam; + *colorref = cbc; + return FALSE; + + case IDOK: + /* Read changed options from the dialog box */ + GetDlgItemText(hDlg, OPT_IcsAlarmTime, buf, MSG_SIZ); + if (sscanf(buf, "%d", &number) != 1 || (number < 0)){ + MessageBox(hDlg, "Invalid ICS Alarm Time", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + +#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) + + appData.icsAlarm = IS_CHECKED(OPT_IcsAlarm); + appData.premove = IS_CHECKED(OPT_Premove); + appData.premoveWhite = IS_CHECKED(OPT_PremoveWhite); + appData.premoveBlack = IS_CHECKED(OPT_PremoveBlack); + appData.autoComment = IS_CHECKED(OPT_AutoComment); + appData.autoObserve = IS_CHECKED(OPT_AutoObserve); + appData.getMoveList = IS_CHECKED(OPT_GetMoveList); + appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing); + appData.quietPlay = IS_CHECKED(OPT_QuietPlay); + +#undef IS_CHECKED + + appData.icsAlarmTime = number * 1000; + GetDlgItemText(hDlg, OPT_PremoveWhiteText, appData.premoveWhiteText, 5); + GetDlgItemText(hDlg, OPT_PremoveBlackText, appData.premoveBlackText, 5); + + if (appData.localLineEditing) { + DontEcho(); + EchoOn(); + } else { + DoEcho(); + EchoOff(); + } + + appData.colorize = + (Boolean)!IsDlgButtonChecked(hDlg, OPT_DontColorize); + + if (!appData.colorize) { + CHARFORMAT cf; + COLORREF background = ParseColorName(COLOR_BKGD); + /* + SetDefaultTextAttribs(); + Colorize(currentColorClass); + */ + cf.cbSize = sizeof(CHARFORMAT); + cf.dwMask = CFM_COLOR; + cf.crTextColor = ParseColorName(COLOR_NORMAL); + + SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, + EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); + SendDlgItemMessage(hwndConsole, OPT_ConsoleText, + EM_SETBKGNDCOLOR, FALSE, background); + SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, + EM_SETBKGNDCOLOR, FALSE, background); + } + + if (cbc != consoleBackgroundColor) { + consoleBackgroundColor = cbc; + if (appData.colorize) { + SendDlgItemMessage(hwndConsole, OPT_ConsoleText, + EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor); + SendDlgItemMessage(hwndConsole, OPT_ConsoleInput, + EM_SETBKGNDCOLOR, FALSE, consoleBackgroundColor); + } + } + + for (i=0; i < NColorClasses - 1; i++) { + textAttribs[i].color = mca[i].color; + textAttribs[i].effects = mca[i].effects; + } + + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case OPT_ChooseShoutColor: + ColorizeTextPopup(hDlg, ColorShout); + UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); + break; + + case OPT_ChooseSShoutColor: + ColorizeTextPopup(hDlg, ColorSShout); + UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); + break; + + case OPT_ChooseChannel1Color: + ColorizeTextPopup(hDlg, ColorChannel1); + UpdateSampleText(hDlg, OPT_SampleChannel1, + &colorizeAttribs[ColorChannel1]); + break; + + case OPT_ChooseChannelColor: + ColorizeTextPopup(hDlg, ColorChannel); + UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); + break; + + case OPT_ChooseKibitzColor: + ColorizeTextPopup(hDlg, ColorKibitz); + UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); + break; + + case OPT_ChooseTellColor: + ColorizeTextPopup(hDlg, ColorTell); + UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); + break; + + case OPT_ChooseChallengeColor: + ColorizeTextPopup(hDlg, ColorChallenge); + UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); + break; + + case OPT_ChooseRequestColor: + ColorizeTextPopup(hDlg, ColorRequest); + UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); + break; + + case OPT_ChooseSeekColor: + ColorizeTextPopup(hDlg, ColorSeek); + UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); + break; + + case OPT_ChooseNormalColor: + ColorizeTextPopup(hDlg, ColorNormal); + UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); + break; + + case OPT_ChooseBackgroundColor: + if (ChangeColor(hDlg, &cbc)) { + SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); + } + break; + + case OPT_DefaultColors: + for (i=0; i < NColorClasses - 1; i++) + ParseAttribs(&mca[i].color, + &mca[i].effects, + defaultTextAttribs[i]); + + cbc = ParseColorName(COLOR_BKGD); + SendDlgItemMessage(hDlg, OPT_SampleShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSShout, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel1, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChannel, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleKibitz, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleTell, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleChallenge, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleRequest, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleSeek, EM_SETBKGNDCOLOR, 0, cbc); + SendDlgItemMessage(hDlg, OPT_SampleNormal, EM_SETBKGNDCOLOR, 0, cbc); + + UpdateSampleText(hDlg, OPT_SampleShout, &mca[ColorShout]); + UpdateSampleText(hDlg, OPT_SampleSShout, &mca[ColorSShout]); + UpdateSampleText(hDlg, OPT_SampleChannel1, &mca[ColorChannel1]); + UpdateSampleText(hDlg, OPT_SampleChannel, &mca[ColorChannel]); + UpdateSampleText(hDlg, OPT_SampleKibitz, &mca[ColorKibitz]); + UpdateSampleText(hDlg, OPT_SampleTell, &mca[ColorTell]); + UpdateSampleText(hDlg, OPT_SampleChallenge, &mca[ColorChallenge]); + UpdateSampleText(hDlg, OPT_SampleRequest, &mca[ColorRequest]); + UpdateSampleText(hDlg, OPT_SampleSeek, &mca[ColorSeek]); + UpdateSampleText(hDlg, OPT_SampleNormal, &mca[ColorNormal]); + break; + + default: + SetIcsOptionEnables(hDlg); + break; + } + break; + } + return FALSE; +} + +VOID +IcsOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)IcsOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_IcsOptions), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * Fonts Dialog functions + * +\*---------------------------------------------------------------------------*/ + +VOID +SetSampleFontText(HWND hwnd, int id, const MyFont *mf) +{ + char buf[MSG_SIZ]; + HWND hControl; + HDC hdc; + CHARFORMAT cf; + SIZE size; + RECT rectClient, rectFormat; + HFONT oldFont; + POINT center; + int len; + + len = sprintf(buf, "%.0f pt. %s%s%s\n", + mf->mfp.pointSize, mf->mfp.faceName, + mf->mfp.bold ? " bold" : "", + mf->mfp.italic ? " italic" : ""); + SetDlgItemText(hwnd, id, buf); + + hControl = GetDlgItem(hwnd, id); + hdc = GetDC(hControl); + SetMapMode(hdc, MM_TEXT); /* 1 pixel == 1 logical unit */ + oldFont = SelectObject(hdc, mf->hf); + + /* get number of logical units necessary to display font name */ + GetTextExtentPoint32(hdc, buf, len, &size); + + /* calculate formatting rectangle in the rich edit control. + * May be larger or smaller than the actual control. + */ + GetClientRect(hControl, &rectClient); + center.x = (rectClient.left + rectClient.right) / 2; + center.y = (rectClient.top + rectClient.bottom) / 2; + rectFormat.top = center.y - (size.cy / 2) - 1; + rectFormat.bottom = center.y + (size.cy / 2) + 1; + rectFormat.left = center.x - (size.cx / 2) - 1; + rectFormat.right = center.x + (size.cx / 2) + 1; + +#if 0 + fprintf(debugFP, "\nfont: %s\n" + "center.x %d, centerY %d\n" + "size.cx %d, size.cy %d\n" + "client.top %d, bottom %d, left %d, right %d\n" + "format.top %d, bottom %d, left %d, right %d\n", + buf, + center.x, center.y, + size.cx, size.cy, + rectClient.top, rectClient.bottom, rectClient.left, + rectClient.right, + rectFormat.top, rectFormat.bottom, rectFormat.left, + rectFormat.right); +#endif + + cf.cbSize = sizeof(CHARFORMAT); + cf.dwMask = CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_BOLD|CFM_ITALIC; + cf.dwEffects = 0; + if (mf->lf.lfWeight == FW_BOLD) cf.dwEffects |= CFE_BOLD; + if (mf->lf.lfItalic) cf.dwEffects |= CFE_ITALIC; + strcpy(cf.szFaceName, mf->mfp.faceName); + /* + * yHeight is expressed in twips. A twip is 1/20 of a font's point + * size. See documentation of CHARFORMAT. --msw + */ + cf.yHeight = (int)(mf->mfp.pointSize * 20.0 + 0.5); + cf.bCharSet = mf->lf.lfCharSet; + cf.bPitchAndFamily = mf->lf.lfPitchAndFamily; + + /* format the text in the rich edit control */ + SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf); + SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat); + + /* clean up */ + SelectObject(hdc, oldFont); + ReleaseDC(hControl, hdc); +} + +VOID +CopyFont(MyFont *dest, const MyFont *src) +{ + dest->mfp.pointSize = src->mfp.pointSize; + dest->mfp.bold = src->mfp.bold; + dest->mfp.italic = src->mfp.italic; + dest->mfp.underline = src->mfp.underline; + dest->mfp.strikeout = src->mfp.strikeout; + lstrcpy(dest->mfp.faceName, src->mfp.faceName); + CreateFontInMF(dest); +} + + +LRESULT CALLBACK +FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static MyFont workFont[NUM_FONTS]; + static BOOL firstPaint; + int i; + RECT rect; + + switch (message) { + case WM_INITDIALOG: + + /* copy the current font settings into a working copy */ + for (i=0; i < NUM_FONTS; i++) + CopyFont(&workFont[i], font[boardSize][i]); + + if (!appData.icsActive) + EnableWindow(GetDlgItem(hDlg, OPT_ChooseConsoleFont), FALSE); + + firstPaint = TRUE; /* see rant below */ + + /* If I don't call SetFocus(), the dialog won't respond to the keyboard + * when first drawn. Why is this the only dialog that behaves this way? Is + * is the WM_PAINT stuff below?? Sigh... + */ + SetFocus(GetDlgItem(hDlg, IDOK)); + break; + + case WM_PAINT: + /* This should not be necessary. However, if SetSampleFontText() is called + * in response to WM_INITDIALOG, the strings are not properly centered in + * the controls when the dialog first appears. I can't figure out why, so + * this is the workaround. --msw + */ + if (firstPaint) { + SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]); + SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]); + SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]); + SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]); + SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]); + SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); + SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); + firstPaint = FALSE; + } + break; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + + case IDOK: + /* again, it seems to avoid redraw problems if we call EndDialog first */ + EndDialog(hDlg, FALSE); + + /* copy modified settings back to the fonts array */ + for (i=0; i < NUM_FONTS; i++) + CopyFont(font[boardSize][i], &workFont[i]); + + /* a sad necessity due to the original design of having a separate + * console font, tags font, and comment font for each board size. IMHO + * these fonts should not be dependent on the current board size. I'm + * running out of time, so I am doing this hack rather than redesign the + * data structure. Besides, I think if I redesigned the data structure, I + * might break backwards compatibility with old winboard.ini files. + * --msw + */ + for (i=0; i < NUM_SIZES; i++) { + CopyFont(font[i][EDITTAGS_FONT], &workFont[EDITTAGS_FONT]); + CopyFont(font[i][CONSOLE_FONT], &workFont[CONSOLE_FONT]); + CopyFont(font[i][COMMENT_FONT], &workFont[COMMENT_FONT]); + CopyFont(font[i][MOVEHISTORY_FONT], &workFont[MOVEHISTORY_FONT]); + } + /* end sad necessity */ + + InitDrawingSizes(boardSize, 0); + InvalidateRect(hwndMain, NULL, TRUE); + + if (commentDialog) { + SendDlgItemMessage(commentDialog, OPT_CommentText, + WM_SETFONT, (WPARAM)font[boardSize][COMMENT_FONT]->hf, + MAKELPARAM(TRUE, 0)); + GetClientRect(GetDlgItem(commentDialog, OPT_CommentText), &rect); + InvalidateRect(commentDialog, &rect, TRUE); + } + + if (editTagsDialog) { + SendDlgItemMessage(editTagsDialog, OPT_TagsText, + WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, + MAKELPARAM(TRUE, 0)); + GetClientRect(GetDlgItem(editTagsDialog, OPT_TagsText), &rect); + InvalidateRect(editTagsDialog, &rect, TRUE); + } + + if( moveHistoryDialog != NULL ) { + SendDlgItemMessage(moveHistoryDialog, IDC_MoveHistory, + WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, + MAKELPARAM(TRUE, 0)); + InvalidateRect(editTagsDialog, NULL, TRUE); + } + + if (hwndConsole) { + ChangedConsoleFont(); + } + + for (i=0; idef, &workFont[i].mfp); + CreateFontInMF(&workFont[i]); + } + SetSampleFontText(hDlg, OPT_SampleClockFont, &workFont[CLOCK_FONT]); + SetSampleFontText(hDlg, OPT_SampleMessageFont, &workFont[MESSAGE_FONT]); + SetSampleFontText(hDlg, OPT_SampleCoordFont, &workFont[COORD_FONT]); + SetSampleFontText(hDlg, OPT_SampleTagFont, &workFont[EDITTAGS_FONT]); + SetSampleFontText(hDlg, OPT_SampleCommentsFont, &workFont[COMMENT_FONT]); + SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); + SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); + break; + } + } + return FALSE; +} + +VOID +FontsOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)FontOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_Fonts), hwnd, + (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * Sounds Dialog functions + * +\*---------------------------------------------------------------------------*/ + + +SoundComboData soundComboData[] = { + {"Move", NULL}, + {"Bell", NULL}, + {"ICS Alarm", NULL}, + {"ICS Win", NULL}, + {"ICS Loss", NULL}, + {"ICS Draw", NULL}, + {"ICS Unfinished", NULL}, + {"Shout", NULL}, + {"SShout/CShout", NULL}, + {"Channel 1", NULL}, + {"Channel", NULL}, + {"Kibitz", NULL}, + {"Tell", NULL}, + {"Challenge", NULL}, + {"Request", NULL}, + {"Seek", NULL}, + {NULL, NULL}, +}; + + +void +InitSoundComboData(SoundComboData *scd) +{ + SoundClass sc; + ColorClass cc; + int index; + + /* copy current sound settings to combo array */ + + for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) { + scd[sc].name = strdup(sounds[sc].name); + } + for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) { + index = (int)cc + (int)NSoundClasses; + scd[index].name = strdup(textAttribs[cc].sound.name); + } +} + + +void +ResetSoundComboData(SoundComboData *scd) +{ + while (scd->label) { + if (scd->name != NULL) { + free (scd->name); + scd->name = NULL; + } + scd++; + } +} + +void +InitSoundCombo(HWND hwndCombo, SoundComboData *scd) +{ + char buf[255]; + DWORD err; + DWORD cnt = 0; + SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0); + + /* send the labels to the combo box */ + while (scd->label) { + err = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) scd->label); + if (err != cnt++) { + sprintf(buf, "InitSoundCombo(): err '%d', cnt '%d'\n", + err, cnt); + MessageBox(NULL, buf, NULL, MB_OK); + } + scd++; + } + SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0); +} + +int +SoundDialogWhichRadio(HWND hDlg) +{ + if (IsDlgButtonChecked(hDlg, OPT_NoSound)) return OPT_NoSound; + if (IsDlgButtonChecked(hDlg, OPT_DefaultBeep)) return OPT_DefaultBeep; + if (IsDlgButtonChecked(hDlg, OPT_BuiltInSound)) return OPT_BuiltInSound; + if (IsDlgButtonChecked(hDlg, OPT_WavFile)) return OPT_WavFile; + return -1; +} + +VOID +SoundDialogSetEnables(HWND hDlg, int radio) +{ + EnableWindow(GetDlgItem(hDlg, OPT_BuiltInSoundName), + radio == OPT_BuiltInSound); + EnableWindow(GetDlgItem(hDlg, OPT_WavFileName), radio == OPT_WavFile); + EnableWindow(GetDlgItem(hDlg, OPT_BrowseSound), radio == OPT_WavFile); +} + +char * +SoundDialogGetName(HWND hDlg, int radio) +{ + static char buf[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ]; + char *dummy, *ret; + switch (radio) { + case OPT_NoSound: + default: + return ""; + case OPT_DefaultBeep: + return "$"; + case OPT_BuiltInSound: + buf[0] = '!'; + GetDlgItemText(hDlg, OPT_BuiltInSoundName, buf + 1, sizeof(buf) - 1); + return buf; + case OPT_WavFile: + GetDlgItemText(hDlg, OPT_WavFileName, buf, sizeof(buf)); + GetCurrentDirectory(MSG_SIZ, buf3); + SetCurrentDirectory(installDir); + if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) { + ret = buf2; + } else { + ret = buf; + } + SetCurrentDirectory(buf3); + return ret; + } +} + +void +DisplaySelectedSound(HWND hDlg, HWND hCombo, const char *name) +{ + int radio; + /* + * I think it's best to clear the combo and edit boxes. It looks stupid + * to have a value from another sound event sitting there grayed out. + */ + SetDlgItemText(hDlg, OPT_WavFileName, ""); + SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + + if (appData.debugMode) + fprintf(debugFP, "DisplaySelectedSound(,,'%s'):\n", name); + switch (name[0]) { + case NULLCHAR: + radio = OPT_NoSound; + break; + case '$': + if (name[1] == NULLCHAR) { + radio = OPT_DefaultBeep; + } else { + radio = OPT_WavFile; + SetDlgItemText(hDlg, OPT_WavFileName, name); + } + break; + case '!': + if (name[1] == NULLCHAR) { + radio = OPT_NoSound; + } else { + radio = OPT_BuiltInSound; + if (SendMessage(hCombo, CB_SELECTSTRING, (WPARAM) -1, + (LPARAM) (name + 1)) == CB_ERR) { + SendMessage(hCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + SendMessage(hCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) (name + 1)); + } + } + break; + default: + radio = OPT_WavFile; + SetDlgItemText(hDlg, OPT_WavFileName, name); + break; + } + SoundDialogSetEnables(hDlg, radio); + CheckRadioButton(hDlg, OPT_NoSound, OPT_WavFile, radio); +} + + +char *builtInSoundNames[] = BUILT_IN_SOUND_NAMES; + +LRESULT CALLBACK +SoundOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static HWND hSoundCombo; + static DWORD index; + static HWND hBISN; + int radio; + MySound tmp; + FILE *f; + char buf[MSG_SIZ]; + char *newName; + SoundClass sc; + ColorClass cc; + SoundComboData *scd; + + switch (message) { + case WM_INITDIALOG: + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + + /* Initialize the built-in sounds combo */ + hBISN = GetDlgItem(hDlg, OPT_BuiltInSoundName); + InitComboStrings(hBISN, builtInSoundNames); + + /* Initialize the sound events combo */ + index = 0; + InitSoundComboData(soundComboData); + hSoundCombo = GetDlgItem(hDlg, CBO_Sounds); + InitSoundCombo(hSoundCombo, soundComboData); + + /* update the dialog */ + DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); + return TRUE; + + case WM_COMMAND: /* message: received a command */ + + if (((HWND)lParam == hSoundCombo) && + (HIWORD(wParam) == CBN_SELCHANGE)) { + /* + * the user has selected a new sound event. We must store the name for + * the previously selected event, then retrieve the name for the + * newly selected event and update the dialog. + */ + radio = SoundDialogWhichRadio(hDlg); + newName = strdup(SoundDialogGetName(hDlg, radio)); + + if (strcmp(newName, soundComboData[index].name) != 0) { + free(soundComboData[index].name); + soundComboData[index].name = newName; + } else { + free(newName); + newName = NULL; + } + /* now get the settings for the newly selected event */ + index = SendMessage(hSoundCombo, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); + DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); + + return TRUE; + } + switch (LOWORD(wParam)) { + case IDOK: + /* + * save the name for the currently selected sound event + */ + radio = SoundDialogWhichRadio(hDlg); + newName = strdup(SoundDialogGetName(hDlg, radio)); + + if (strcmp(soundComboData[index].name, newName) != 0) { + free(soundComboData[index].name); + soundComboData[index].name = newName; + } else { + free(newName); + newName = NULL; + } + + /* save all the sound names that changed and load the sounds */ + + for ( sc = (SoundClass)0; sc < NSoundClasses; sc++) { + if (strcmp(soundComboData[sc].name, sounds[sc].name) != 0) { + free(sounds[sc].name); + sounds[sc].name = strdup(soundComboData[sc].name); + MyLoadSound(&sounds[sc]); + } + } + for ( cc = (ColorClass)0; cc < NColorClasses - 2; cc++) { + index = (int)cc + (int)NSoundClasses; + if (strcmp(soundComboData[index].name, + textAttribs[cc].sound.name) != 0) { + free(textAttribs[cc].sound.name); + textAttribs[cc].sound.name = strdup(soundComboData[index].name); + MyLoadSound(&textAttribs[cc].sound); + } + } + + ResetSoundComboData(soundComboData); + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + ResetSoundComboData(soundComboData); + EndDialog(hDlg, FALSE); + return TRUE; + + case OPT_DefaultSounds: + /* can't use SetDefaultSounds() because we need to be able to "undo" if + * user selects "Cancel" later on. So we do it the hard way here. + */ + scd = &soundComboData[0]; + while (scd->label != NULL) { + if (scd->name != NULL) free(scd->name); + scd->name = strdup(""); + scd++; + } + free(soundComboData[(int)SoundBell].name); + soundComboData[(int)SoundBell].name = strdup(SOUND_BELL); + DisplaySelectedSound(hDlg, hBISN, soundComboData[index].name); + break; + + case OPT_PlaySound: + radio = SoundDialogWhichRadio(hDlg); + tmp.name = strdup(SoundDialogGetName(hDlg, radio)); + tmp.data = NULL; + MyLoadSound(&tmp); + MyPlaySound(&tmp); + if (tmp.data != NULL) free(tmp.data); + if (tmp.name != NULL) free(tmp.name); + return TRUE; + + case OPT_BrowseSound: + f = OpenFileDialog(hDlg, "rb", NULL, "wav", SOUND_FILT, + "Browse for Sound File", NULL, NULL, buf); + if (f != NULL) { + fclose(f); + SetDlgItemText(hDlg, OPT_WavFileName, buf); + } + return TRUE; + + default: + radio = SoundDialogWhichRadio(hDlg); + SoundDialogSetEnables(hDlg, radio); + break; + } + break; + } + return FALSE; +} + + +VOID SoundOptionsPopup(HWND hwnd) +{ + FARPROC lpProc; + + lpProc = MakeProcInstance((FARPROC)SoundOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_Sound), hwnd, (DLGPROC)lpProc); + FreeProcInstance(lpProc); +} + + +/*---------------------------------------------------------------------------*\ + * + * Comm Port dialog functions + * +\*---------------------------------------------------------------------------*/ + + +#define FLOW_NONE 0 +#define FLOW_XOFF 1 +#define FLOW_CTS 2 +#define FLOW_DSR 3 + +#define PORT_NONE + +ComboData cdPort[] = { {"None", PORT_NONE}, {"COM1", 1}, {"COM2", 2}, + {"COM3", 3}, {"COM4", 4}, {NULL, 0} }; +ComboData cdDataRate[] = { {"110", 110}, {"300", 300}, {"600", 600}, {"1200", 1200}, + {"2400", 2400}, {"4800", 4800}, {"9600", 9600}, {"19200", 19200}, + {"38400", 38400}, {NULL, 0} }; +ComboData cdDataBits[] = { {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {NULL, 0} }; +ComboData cdParity[] = { {"None", NOPARITY}, {"Odd", ODDPARITY}, {"Even", EVENPARITY}, + {"Mark", MARKPARITY}, {"Space", SPACEPARITY}, {NULL, 0} }; +ComboData cdStopBits[] = { {"1", ONESTOPBIT}, {"1.5", ONE5STOPBITS}, + {"2", TWOSTOPBITS}, {NULL, 0} }; +ComboData cdFlow[] = { {"None", FLOW_NONE}, {"Xoff/Xon", FLOW_XOFF}, {"CTS", FLOW_CTS}, + {"DSR", FLOW_DSR}, {NULL, 0} }; + + +VOID +ParseCommSettings(char *arg, DCB *dcb) +{ + int dataRate, count; + char bits[MSG_SIZ], parity[MSG_SIZ], stopBits[MSG_SIZ], flow[MSG_SIZ]; + ComboData *cd; + count = sscanf(arg, "%d%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]%*[, ]%[^, ]", + &dataRate, bits, parity, stopBits, flow); + if (count != 5) goto cant_parse; + dcb->BaudRate = dataRate; + cd = cdDataBits; + while (cd->label != NULL) { + if (StrCaseCmp(cd->label, bits) == 0) { + dcb->ByteSize = cd->value; + break; + } + cd++; + } + if (cd->label == NULL) goto cant_parse; + cd = cdParity; + while (cd->label != NULL) { + if (StrCaseCmp(cd->label, parity) == 0) { + dcb->Parity = cd->value; + break; + } + cd++; + } + if (cd->label == NULL) goto cant_parse; + cd = cdStopBits; + while (cd->label != NULL) { + if (StrCaseCmp(cd->label, stopBits) == 0) { + dcb->StopBits = cd->value; + break; + } + cd++; + } + cd = cdFlow; + if (cd->label == NULL) goto cant_parse; + while (cd->label != NULL) { + if (StrCaseCmp(cd->label, flow) == 0) { + switch (cd->value) { + case FLOW_NONE: + dcb->fOutX = FALSE; + dcb->fOutxCtsFlow = FALSE; + dcb->fOutxDsrFlow = FALSE; + break; + case FLOW_CTS: + dcb->fOutX = FALSE; + dcb->fOutxCtsFlow = TRUE; + dcb->fOutxDsrFlow = FALSE; + break; + case FLOW_DSR: + dcb->fOutX = FALSE; + dcb->fOutxCtsFlow = FALSE; + dcb->fOutxDsrFlow = TRUE; + break; + case FLOW_XOFF: + dcb->fOutX = TRUE; + dcb->fOutxCtsFlow = FALSE; + dcb->fOutxDsrFlow = FALSE; + break; + } + break; + } + cd++; + } + if (cd->label == NULL) goto cant_parse; + return; +cant_parse: + ExitArgError("Can't parse com port settings", arg); +} + + +VOID PrintCommSettings(FILE *f, char *name, DCB *dcb) +{ + char *flow = "??", *parity = "??", *stopBits = "??"; + ComboData *cd; + + cd = cdParity; + while (cd->label != NULL) { + if (dcb->Parity == cd->value) { + parity = cd->label; + break; + } + cd++; + } + cd = cdStopBits; + while (cd->label != NULL) { + if (dcb->StopBits == cd->value) { + stopBits = cd->label; + break; + } + cd++; + } + if (dcb->fOutX) { + flow = cdFlow[FLOW_XOFF].label; + } else if (dcb->fOutxCtsFlow) { + flow = cdFlow[FLOW_CTS].label; + } else if (dcb->fOutxDsrFlow) { + flow = cdFlow[FLOW_DSR].label; + } else { + flow = cdFlow[FLOW_NONE].label; + } + fprintf(f, "/%s=%d,%d,%s,%s,%s\n", name, + dcb->BaudRate, dcb->ByteSize, parity, stopBits, flow); +} + + +void +InitCombo(HANDLE hwndCombo, ComboData *cd) +{ + SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0); + + while (cd->label != NULL) { + SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) cd->label); + cd++; + } +} + +void +SelectComboValue(HANDLE hwndCombo, ComboData *cd, unsigned value) +{ + int i; + + i = 0; + while (cd->label != NULL) { + if (cd->value == value) { + SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) i, (LPARAM) 0); + return; + } + cd++; + i++; + } +} + +LRESULT CALLBACK +CommPortOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + HANDLE hwndCombo; + char *p; + LRESULT index; + unsigned value; + int err; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow(hDlg, GW_OWNER)); + /* Initialize the dialog items */ + /* !! There should probably be some synchronization + in accessing hCommPort and dcb. Or does modal nature + of this dialog box do it for us? + */ + hwndCombo = GetDlgItem(hDlg, OPT_Port); + InitCombo(hwndCombo, cdPort); + p = strrchr(appData.icsCommPort, '\\'); + if (p++ == NULL) p = appData.icsCommPort; + if ((*p == '\0') || + (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) p) == CB_ERR)) { + SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) "None"); + } + EnableWindow(hwndCombo, hCommPort == NULL); /*!! don't allow change for now*/ + + hwndCombo = GetDlgItem(hDlg, OPT_DataRate); + InitCombo(hwndCombo, cdDataRate); + sprintf(buf, "%u", dcb.BaudRate); + if (SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) buf) == CB_ERR) { + SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0); + SendMessage(hwndCombo, WM_SETTEXT, (WPARAM) 0, (LPARAM) buf); + } + + hwndCombo = GetDlgItem(hDlg, OPT_Bits); + InitCombo(hwndCombo, cdDataBits); + SelectComboValue(hwndCombo, cdDataBits, dcb.ByteSize); + + hwndCombo = GetDlgItem(hDlg, OPT_Parity); + InitCombo(hwndCombo, cdParity); + SelectComboValue(hwndCombo, cdParity, dcb.Parity); + + hwndCombo = GetDlgItem(hDlg, OPT_StopBits); + InitCombo(hwndCombo, cdStopBits); + SelectComboValue(hwndCombo, cdStopBits, dcb.StopBits); + + hwndCombo = GetDlgItem(hDlg, OPT_Flow); + InitCombo(hwndCombo, cdFlow); + if (dcb.fOutX) { + SelectComboValue(hwndCombo, cdFlow, FLOW_XOFF); + } else if (dcb.fOutxCtsFlow) { + SelectComboValue(hwndCombo, cdFlow, FLOW_CTS); + } else if (dcb.fOutxDsrFlow) { + SelectComboValue(hwndCombo, cdFlow, FLOW_DSR); + } else { + SelectComboValue(hwndCombo, cdFlow, FLOW_NONE); + } + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ +#ifdef NOTDEF + /* !! Currently we can't change comm ports in midstream */ + hwndCombo = GetDlgItem(hDlg, OPT_Port); + index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + if (index == PORT_NONE) { + appData.icsCommPort = ""; + if (hCommPort != NULL) { + CloseHandle(hCommPort); + hCommPort = NULL; + } + EndDialog(hDlg, TRUE); + return TRUE; + } + SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf); + appData.icsCommPort = strdup(buf); + if (hCommPort != NULL) { + CloseHandle(hCommPort); + hCommPort = NULL; + } + /* now what?? can't really do this; have to fix up the ChildProc + and InputSource records for the comm port that we gave to the + back end. */ +#endif /*NOTDEF*/ + + hwndCombo = GetDlgItem(hDlg, OPT_DataRate); + SendMessage(hwndCombo, WM_GETTEXT, (WPARAM) MSG_SIZ, (LPARAM) buf); + if (sscanf(buf, "%u", &value) != 1) { + MessageBox(hDlg, "Invalid data rate", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return TRUE; + } + dcb.BaudRate = value; + + hwndCombo = GetDlgItem(hDlg, OPT_Bits); + index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + dcb.ByteSize = cdDataBits[index].value; + + hwndCombo = GetDlgItem(hDlg, OPT_Parity); + index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + dcb.Parity = cdParity[index].value; + + hwndCombo = GetDlgItem(hDlg, OPT_StopBits); + index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + dcb.StopBits = cdStopBits[index].value; + + hwndCombo = GetDlgItem(hDlg, OPT_Flow); + index = SendMessage(hwndCombo, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); + switch (cdFlow[index].value) { + case FLOW_NONE: + dcb.fOutX = FALSE; + dcb.fOutxCtsFlow = FALSE; + dcb.fOutxDsrFlow = FALSE; + break; + case FLOW_CTS: + dcb.fOutX = FALSE; + dcb.fOutxCtsFlow = TRUE; + dcb.fOutxDsrFlow = FALSE; + break; + case FLOW_DSR: + dcb.fOutX = FALSE; + dcb.fOutxCtsFlow = FALSE; + dcb.fOutxDsrFlow = TRUE; + break; + case FLOW_XOFF: + dcb.fOutX = TRUE; + dcb.fOutxCtsFlow = FALSE; + dcb.fOutxDsrFlow = FALSE; + break; + } + if (!SetCommState(hCommPort, (LPDCB) &dcb)) { + err = GetLastError(); + switch(MessageBox(hDlg, + "Failed to set comm port state;\r\ninvalid options?", + "Option Error", MB_ABORTRETRYIGNORE|MB_ICONQUESTION)) { + case IDABORT: + DisplayFatalError("Failed to set comm port state", err, 1); + exit(1); /*is it ok to do this from here?*/ + + case IDRETRY: + return TRUE; + + case IDIGNORE: + EndDialog(hDlg, TRUE); + return TRUE; + } + } + + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + default: + break; + } + break; + } + return FALSE; +} + +VOID +CommPortOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)CommPortOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_CommPort), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * Load Options dialog functions + * +\*---------------------------------------------------------------------------*/ + +VOID +SetLoadOptionEnables(HWND hDlg) +{ + UINT state; + + state = IsDlgButtonChecked(hDlg, OPT_Autostep); + EnableWindow(GetDlgItem(hDlg, OPT_ASTimeDelay), state); + EnableWindow(GetDlgItem(hDlg, OPT_AStext1), state); +} + +LRESULT CALLBACK +LoadOptions(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + float fnumber; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + if (appData.timeDelay >= 0.0) { + CheckDlgButton(hDlg, OPT_Autostep, TRUE); + sprintf(buf, "%.2g", appData.timeDelay); + SetDlgItemText(hDlg, OPT_ASTimeDelay, buf); + } else { + CheckDlgButton(hDlg, OPT_Autostep, FALSE); + } + SetLoadOptionEnables(hDlg); + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + if (IsDlgButtonChecked(hDlg, OPT_Autostep)) { + GetDlgItemText(hDlg, OPT_ASTimeDelay, buf, MSG_SIZ); + if (sscanf(buf, "%f", &fnumber) != 1) { + MessageBox(hDlg, "Invalid load game step rate", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + appData.timeDelay = fnumber; + } else { + appData.timeDelay = (float) -1.0; + } + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + default: + SetLoadOptionEnables(hDlg); + break; + } + break; + } + return FALSE; +} + + +VOID +LoadOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)LoadOptions, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_LoadOptions), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * Save Options dialog functions + * +\*---------------------------------------------------------------------------*/ + +VOID +SetSaveOptionEnables(HWND hDlg) +{ + UINT state; + + state = IsDlgButtonChecked(hDlg, OPT_Autosave); + EnableWindow(GetDlgItem(hDlg, OPT_AVPrompt), state); + EnableWindow(GetDlgItem(hDlg, OPT_AVToFile), state); + if (state && !IsDlgButtonChecked(hDlg, OPT_AVPrompt) && + !IsDlgButtonChecked(hDlg, OPT_AVToFile)) { + CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt); + } + + state = state && IsDlgButtonChecked(hDlg, OPT_AVToFile); + EnableWindow(GetDlgItem(hDlg, OPT_AVFilename), state); + EnableWindow(GetDlgItem(hDlg, OPT_AVBrowse), state); +} + +LRESULT CALLBACK +SaveOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + FILE *f; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + if (*appData.saveGameFile != NULLCHAR) { + CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE); + CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVToFile); + SetDlgItemText(hDlg, OPT_AVFilename, appData.saveGameFile); + } else if (appData.autoSaveGames) { + CheckDlgButton(hDlg, OPT_Autosave, (UINT) TRUE); + CheckRadioButton(hDlg, OPT_AVPrompt, OPT_AVToFile, OPT_AVPrompt); + } else { + CheckDlgButton(hDlg, OPT_Autosave, (UINT) FALSE); + } + if (appData.oldSaveStyle) { + CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_Old); + } else { + CheckRadioButton(hDlg, OPT_PGN, OPT_Old, OPT_PGN); + } + CheckDlgButton( hDlg, OPT_OutOfBookInfo, appData.saveOutOfBookInfo ); + SetSaveOptionEnables(hDlg); + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + if (IsDlgButtonChecked(hDlg, OPT_Autosave)) { + appData.autoSaveGames = TRUE; + if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) { + appData.saveGameFile = ""; + } else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ { + GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ); + if (*buf == NULLCHAR) { + MessageBox(hDlg, "Invalid save game file name", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + if ((isalpha(buf[0]) && buf[1] == ':') || + (buf[0] == '\\' && buf[1] == '\\')) { + appData.saveGameFile = strdup(buf); + } else { + char buf2[MSG_SIZ], buf3[MSG_SIZ]; + char *dummy; + GetCurrentDirectory(MSG_SIZ, buf3); + SetCurrentDirectory(installDir); + if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) { + appData.saveGameFile = strdup(buf2); + } else { + appData.saveGameFile = strdup(buf); + } + SetCurrentDirectory(buf3); + } + } + } else { + appData.autoSaveGames = FALSE; + appData.saveGameFile = ""; + } + appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old); + appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo ); + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case OPT_AVBrowse: + f = OpenFileDialog(hDlg, "a", NULL, + appData.oldSaveStyle ? "gam" : "pgn", + GAME_FILT, "Browse for Auto Save File", + NULL, NULL, buf); + if (f != NULL) { + fclose(f); + SetDlgItemText(hDlg, OPT_AVFilename, buf); + } + break; + + default: + SetSaveOptionEnables(hDlg); + break; + } + break; + } + return FALSE; +} + +VOID +SaveOptionsPopup(HWND hwnd) +{ + FARPROC lpProc = MakeProcInstance((FARPROC)SaveOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_SaveOptions), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * Time Control Options dialog functions + * +\*---------------------------------------------------------------------------*/ + +VOID +SetTimeControlEnables(HWND hDlg) +{ + UINT state; + + state = IsDlgButtonChecked(hDlg, OPT_TCUseMoves); + EnableWindow(GetDlgItem(hDlg, OPT_TCTime), state); + EnableWindow(GetDlgItem(hDlg, OPT_TCMoves), state); + EnableWindow(GetDlgItem(hDlg, OPT_TCtext1), state); + EnableWindow(GetDlgItem(hDlg, OPT_TCtext2), state); + EnableWindow(GetDlgItem(hDlg, OPT_TCTime2), !state); + EnableWindow(GetDlgItem(hDlg, OPT_TCInc), !state); + EnableWindow(GetDlgItem(hDlg, OPT_TCitext1), !state); + EnableWindow(GetDlgItem(hDlg, OPT_TCitext2), !state); + EnableWindow(GetDlgItem(hDlg, OPT_TCitext3), !state); +} + + +LRESULT CALLBACK +TimeControl(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + int mps, increment, odds1, odds2; + BOOL ok, ok2; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + /* Initialize the dialog items */ + if (appData.clockMode && !appData.icsActive) { + if (appData.timeIncrement == -1) { + CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc, + OPT_TCUseMoves); + SetDlgItemText(hDlg, OPT_TCTime, appData.timeControl); + SetDlgItemInt(hDlg, OPT_TCMoves, appData.movesPerSession, + FALSE); + SetDlgItemText(hDlg, OPT_TCTime2, ""); + SetDlgItemText(hDlg, OPT_TCInc, ""); + } else { + CheckRadioButton(hDlg, OPT_TCUseMoves, OPT_TCUseInc, + OPT_TCUseInc); + SetDlgItemText(hDlg, OPT_TCTime, ""); + SetDlgItemText(hDlg, OPT_TCMoves, ""); + SetDlgItemText(hDlg, OPT_TCTime2, appData.timeControl); + SetDlgItemInt(hDlg, OPT_TCInc, appData.timeIncrement, FALSE); + } + SetDlgItemInt(hDlg, OPT_TCOdds1, 1, FALSE); + SetDlgItemInt(hDlg, OPT_TCOdds2, 1, FALSE); + SetTimeControlEnables(hDlg); + } + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + if (IsDlgButtonChecked(hDlg, OPT_TCUseMoves)) { + increment = -1; + mps = GetDlgItemInt(hDlg, OPT_TCMoves, &ok, FALSE); + if (!ok || mps <= 0) { + MessageBox(hDlg, "Invalid moves per time control", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + GetDlgItemText(hDlg, OPT_TCTime, buf, MSG_SIZ); + if (!ParseTimeControl(buf, increment, mps)) { + MessageBox(hDlg, "Invalid minutes per time control", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + } else { + increment = GetDlgItemInt(hDlg, OPT_TCInc, &ok, FALSE); + mps = appData.movesPerSession; + if (!ok || increment < 0) { + MessageBox(hDlg, "Invalid increment", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + GetDlgItemText(hDlg, OPT_TCTime2, buf, MSG_SIZ); + if (!ParseTimeControl(buf, increment, mps)) { + MessageBox(hDlg, "Invalid initial time", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + } + odds1 = GetDlgItemInt(hDlg, OPT_TCOdds1, &ok, FALSE); + odds2 = GetDlgItemInt(hDlg, OPT_TCOdds2, &ok2, FALSE); + if (!ok || !ok2 || odds1 <= 0 || odds2 <= 0) { + MessageBox(hDlg, "Invalid time-odds factor", + "Option Error", MB_OK|MB_ICONEXCLAMATION); + return FALSE; + } + appData.timeControl = strdup(buf); + appData.movesPerSession = mps; + appData.timeIncrement = increment; + appData.firstTimeOdds = first.timeOdds = odds1; + appData.secondTimeOdds = second.timeOdds = odds2; + Reset(TRUE, TRUE); + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + default: + SetTimeControlEnables(hDlg); + break; + } + break; + } + return FALSE; +} + +VOID +TimeControlOptionsPopup(HWND hwnd) +{ + if (gameMode != BeginningOfGame) { + DisplayError("Changing time control during a game is not implemented", 0); + } else { + FARPROC lpProc = MakeProcInstance((FARPROC)TimeControl, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_TimeControl), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); + } +} + +/*---------------------------------------------------------------------------*\ + * + * Engine Options Dialog functions + * +\*---------------------------------------------------------------------------*/ +#define CHECK_BOX(x,y) CheckDlgButton(hDlg, (x), (BOOL)(y)) +#define IS_CHECKED(x) (Boolean)IsDlgButtonChecked(hDlg, (x)) + +#define INT_ABS( n ) ((n) >= 0 ? (n) : -(n)) + +LRESULT CALLBACK EnginePlayOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + + /* Initialize the dialog items */ + CHECK_BOX(IDC_EpPeriodicUpdates, appData.periodicUpdates); + CHECK_BOX(IDC_EpPonder, appData.ponderNextMove); + CHECK_BOX(IDC_EpShowThinking, appData.showThinking); + CHECK_BOX(IDC_EpHideThinkingHuman, appData.hideThinkingFromHuman); + + CHECK_BOX(IDC_TestClaims, appData.testClaims); + CHECK_BOX(IDC_DetectMates, appData.checkMates); + CHECK_BOX(IDC_MaterialDraws, appData.materialDraws); + CHECK_BOX(IDC_TrivialDraws, appData.trivialDraws); + + CHECK_BOX(IDC_ScoreAbs1, appData.firstScoreIsAbsolute); + CHECK_BOX(IDC_ScoreAbs2, appData.secondScoreIsAbsolute); + + SetDlgItemInt( hDlg, IDC_EpDrawMoveCount, appData.adjudicateDrawMoves, TRUE ); + SendDlgItemMessage( hDlg, IDC_EpDrawMoveCount, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_EpAdjudicationThreshold, INT_ABS(appData.adjudicateLossThreshold), TRUE ); + SendDlgItemMessage( hDlg, IDC_EpAdjudicationThreshold, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_RuleMoves, appData.ruleMoves, TRUE ); + SendDlgItemMessage( hDlg, IDC_RuleMoves, EM_SETSEL, 0, -1 ); + + SetDlgItemInt( hDlg, IDC_DrawRepeats, INT_ABS(appData.drawRepeats), TRUE ); + SendDlgItemMessage( hDlg, IDC_DrawRepeats, EM_SETSEL, 0, -1 ); + + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + /* Read changed options from the dialog box */ + PeriodicUpdatesEvent( IS_CHECKED(IDC_EpPeriodicUpdates)); + PonderNextMoveEvent( IS_CHECKED(IDC_EpPonder)); + appData.hideThinkingFromHuman= IS_CHECKED(IDC_EpHideThinkingHuman); // [HGM] thinking: moved up +#if 0 + ShowThinkingEvent( IS_CHECKED(IDC_EpShowThinking)); +#else + appData.showThinking = IS_CHECKED(IDC_EpShowThinking); + ShowThinkingEvent(); // [HGM] thinking: tests all options that need thinking output +#endif + appData.testClaims = IS_CHECKED(IDC_TestClaims); + appData.checkMates = IS_CHECKED(IDC_DetectMates); + appData.materialDraws = IS_CHECKED(IDC_MaterialDraws); + appData.trivialDraws = IS_CHECKED(IDC_TrivialDraws); + + appData.adjudicateDrawMoves = GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, NULL, FALSE ); + appData.adjudicateLossThreshold = - (int) GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, NULL, FALSE ); + appData.ruleMoves = GetDlgItemInt(hDlg, IDC_RuleMoves, NULL, FALSE ); + appData.drawRepeats = (int) GetDlgItemInt(hDlg, IDC_DrawRepeats, NULL, FALSE ); + + appData.firstScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs1); + appData.secondScoreIsAbsolute = IS_CHECKED(IDC_ScoreAbs2); + + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case IDC_EpDrawMoveCount: + case IDC_EpAdjudicationThreshold: + case IDC_DrawRepeats: + case IDC_RuleMoves: + if( HIWORD(wParam) == EN_CHANGE ) { + int n1_ok; + int n2_ok; + int n3_ok; + int n4_ok; + + GetDlgItemInt(hDlg, IDC_EpDrawMoveCount, &n1_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_EpAdjudicationThreshold, &n2_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_RuleMoves, &n3_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_DrawRepeats, &n4_ok, FALSE ); + + EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok && n3_ok && n4_ok ? TRUE : FALSE ); + } + return TRUE; + } + break; + } + return FALSE; +} + +VOID EnginePlayOptionsPopup(HWND hwnd) +{ + FARPROC lpProc; + + lpProc = MakeProcInstance((FARPROC)EnginePlayOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_EnginePlayOptions), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} + +/*---------------------------------------------------------------------------*\ + * + * UCI Options Dialog functions + * +\*---------------------------------------------------------------------------*/ +static BOOL BrowseForFolder( const char * title, char * path ) +{ + BOOL result = FALSE; + BROWSEINFO bi; + LPITEMIDLIST pidl; + + ZeroMemory( &bi, sizeof(bi) ); + + bi.lpszTitle = title == 0 ? "Choose Folder" : title; + bi.ulFlags = BIF_RETURNONLYFSDIRS; + + pidl = SHBrowseForFolder( &bi ); + + if( pidl != 0 ) { + IMalloc * imalloc = 0; + + if( SHGetPathFromIDList( pidl, path ) ) { + result = TRUE; + } + + if( SUCCEEDED( SHGetMalloc ( &imalloc ) ) ) { + imalloc->lpVtbl->Free(imalloc,pidl); + imalloc->lpVtbl->Release(imalloc); + } + } + + return result; +} + +LRESULT CALLBACK UciOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MAX_PATH]; + int oldCores; + + switch (message) { + case WM_INITDIALOG: /* message: initialize dialog box */ + + /* Center the dialog over the application window */ + CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER)); + + /* Initialize the dialog items */ + SetDlgItemText( hDlg, IDC_PolyglotDir, appData.polyglotDir ); + SetDlgItemInt( hDlg, IDC_HashSize, appData.defaultHashSize, TRUE ); + SetDlgItemText( hDlg, IDC_PathToEGTB, appData.defaultPathEGTB ); + SetDlgItemInt( hDlg, IDC_SizeOfEGTB, appData.defaultCacheSizeEGTB, TRUE ); + CheckDlgButton( hDlg, IDC_UseBook, (BOOL) appData.usePolyglotBook ); + SetDlgItemText( hDlg, IDC_BookFile, appData.polyglotBook ); + // [HGM] smp: input field for nr of cores: + SetDlgItemInt( hDlg, IDC_Cores, appData.smpCores, TRUE ); + // [HGM] book: tick boxes for own book use + CheckDlgButton( hDlg, IDC_OwnBook1, (BOOL) appData.firstHasOwnBookUCI ); + CheckDlgButton( hDlg, IDC_OwnBook2, (BOOL) appData.secondHasOwnBookUCI ); + + SendDlgItemMessage( hDlg, IDC_PolyglotDir, EM_SETSEL, 0, -1 ); + + return TRUE; + + case WM_COMMAND: /* message: received a command */ + switch (LOWORD(wParam)) { + case IDOK: + GetDlgItemText( hDlg, IDC_PolyglotDir, buf, sizeof(buf) ); + appData.polyglotDir = strdup(buf); + appData.defaultHashSize = GetDlgItemInt(hDlg, IDC_HashSize, NULL, FALSE ); + appData.defaultCacheSizeEGTB = GetDlgItemInt(hDlg, IDC_SizeOfEGTB, NULL, FALSE ); + GetDlgItemText( hDlg, IDC_PathToEGTB, buf, sizeof(buf) ); + appData.defaultPathEGTB = strdup(buf); + GetDlgItemText( hDlg, IDC_BookFile, buf, sizeof(buf) ); + appData.polyglotBook = strdup(buf); + appData.usePolyglotBook = (Boolean) IsDlgButtonChecked( hDlg, IDC_UseBook ); + // [HGM] smp: get nr of cores: + oldCores = appData.smpCores; + appData.smpCores = GetDlgItemInt(hDlg, IDC_Cores, NULL, FALSE ); + if(appData.smpCores != oldCores) NewSettingEvent(FALSE, "cores", appData.smpCores); + // [HGM] book: read tick boxes for own book use + appData.firstHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook1 ); + appData.secondHasOwnBookUCI = (Boolean) IsDlgButtonChecked( hDlg, IDC_OwnBook2 ); + + if(gameMode == BeginningOfGame) Reset(TRUE, TRUE); + EndDialog(hDlg, TRUE); + return TRUE; + + case IDCANCEL: + EndDialog(hDlg, FALSE); + return TRUE; + + case IDC_BrowseForBook: + { + char filter[] = { + 'A','l','l',' ','F','i','l','e','s', 0, + '*','.','*', 0, + 'B','I','N',' ','F','i','l','e','s', 0, + '*','.','b','i','n', 0, + 0 }; + + OPENFILENAME ofn; + + strcpy( buf, "" ); + + ZeroMemory( &ofn, sizeof(ofn) ); + + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hDlg; + ofn.hInstance = hInst; + ofn.lpstrFilter = filter; + ofn.lpstrFile = buf; + ofn.nMaxFile = sizeof(buf); + ofn.lpstrTitle = "Choose Book"; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY; + + if( GetOpenFileName( &ofn ) ) { + SetDlgItemText( hDlg, IDC_BookFile, buf ); + } + } + return TRUE; + + case IDC_BrowseForPolyglotDir: + if( BrowseForFolder( "Choose Polyglot Directory", buf ) ) { + SetDlgItemText( hDlg, IDC_PolyglotDir, buf ); + + strcat( buf, "\\polyglot.exe" ); + + if( GetFileAttributes(buf) == 0xFFFFFFFF ) { + MessageBox( hDlg, "Polyglot was not found in the specified folder!", "Warning", MB_OK | MB_ICONWARNING ); + } + } + return TRUE; + + case IDC_BrowseForEGTB: + if( BrowseForFolder( "Choose EGTB Directory:", buf ) ) { + SetDlgItemText( hDlg, IDC_PathToEGTB, buf ); + } + return TRUE; + + case IDC_HashSize: + case IDC_SizeOfEGTB: + if( HIWORD(wParam) == EN_CHANGE ) { + int n1_ok; + int n2_ok; + + GetDlgItemInt(hDlg, IDC_HashSize, &n1_ok, FALSE ); + GetDlgItemInt(hDlg, IDC_SizeOfEGTB, &n2_ok, FALSE ); + + EnableWindow( GetDlgItem(hDlg, IDOK), n1_ok && n2_ok ? TRUE : FALSE ); + } + return TRUE; + } + break; + } + return FALSE; +} + +VOID UciOptionsPopup(HWND hwnd) +{ + FARPROC lpProc; + + lpProc = MakeProcInstance((FARPROC)UciOptionsDialog, hInst); + DialogBox(hInst, MAKEINTRESOURCE(DLG_OptionsUCI), hwnd, (DLGPROC) lpProc); + FreeProcInstance(lpProc); +} diff --git a/xboard.c b/xboard.c index 54718f3..54c457e 100644 --- a/xboard.c +++ b/xboard.c @@ -423,11 +423,14 @@ void EngineMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void UciMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void TimeControlProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void NewVariantProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void FirstSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void SecondSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ShufflePopDown P(()); void EnginePopDown P(()); void UciPopDown P(()); void TimeControlPopDown P(()); void NewVariantPopDown P(()); +void SettingsPopDown P(()); /* * XBoard depends on Xt R4 or higher */ @@ -606,7 +609,9 @@ MenuItem optionsMenu[] = { {"Flip View", FlipViewProc}, {"----", NothingProc}, {"Adjudications ...", EngineMenuProc}, - {"Engine Settings ...", UciMenuProc}, + {"General Settings ...", UciMenuProc}, + {"Engine #1 Settings ...", FirstSettingsProc}, + {"Engine #2 Settings ...", SecondSettingsProc}, {"Time Control ...", TimeControlProc}, {"----", NothingProc}, {"Always Queen", AlwaysQueenProc}, @@ -1287,6 +1292,9 @@ XtResource clientResources[] = { { "smpCores", "smpCores", XtRInt, sizeof(int), XtOffset(AppDataPtr, smpCores), XtRImmediate, (XtPointer) 1}, + { "niceEngines", "niceEngines", XtRInt, + sizeof(int), XtOffset(AppDataPtr, niceEngines), + XtRImmediate, (XtPointer) 0}, // [HGM] Winboard_x UCI options { "firstIsUCI", "firstIsUCI", XtRBoolean, @@ -1319,6 +1327,12 @@ XtResource clientResources[] = { { "defaultPathEGTB", "defaultPathEGTB", XtRString, sizeof(String), XtOffset(AppDataPtr, defaultPathEGTB), XtRImmediate, (XtPointer) "/usr/local/share/egtb"}, + { "delayBeforeQuit", "delayBeforeQuit", XtRInt, + sizeof(int), XtOffset(AppDataPtr, delayBeforeQuit), + XtRImmediate, (XtPointer) 0}, + { "delayAfterQuit", "delayAfterQuit", XtRInt, + sizeof(int), XtOffset(AppDataPtr, delayAfterQuit), + XtRImmediate, (XtPointer) 0}, }; XrmOptionDescRec shellOptions[] = { @@ -1668,6 +1682,9 @@ XrmOptionDescRec shellOptions[] = { { "-smpCores", "smpCores", XrmoptionSepArg, NULL }, { "-sameColorGames", "sameColorGames", XrmoptionSepArg, NULL }, { "-rewindIndex", "rewindIndex", XrmoptionSepArg, NULL }, + { "-niceEngines", "niceEngines", XrmoptionSepArg, NULL }, + { "-delayBeforeQuit", "delayBeforeQuit", XrmoptionSepArg, NULL }, + { "-delayAfterQuit", "delayAfterQuit", XrmoptionSepArg, NULL }, }; @@ -1791,6 +1808,7 @@ XtActionsRec boardActions[] = { { "UciPopDown", (XtActionProc) UciPopDown }, { "TimeControlPopDown", (XtActionProc) TimeControlPopDown }, { "NewVariantPopDown", (XtActionProc) NewVariantPopDown }, + { "SettingsPopDown", (XtActionProc) SettingsPopDown }, }; char globalTranslations[] = @@ -7997,7 +8015,9 @@ int StartChildProcess(cmdLine, dir, pr) if (dir[0] != NULLCHAR && chdir(dir) != 0) { perror(dir); exit(1); - } + } + + nice(appData.niceEngines); // [HGM] nice: adjust priority of engine proc execvp(argv[0], argv); @@ -8019,22 +8039,37 @@ int StartChildProcess(cmdLine, dir, pr) return 0; } +// [HGM] kill: implement the 'hard killing' of AS's Winboard_x +static RETSIGTYPE AlarmCallBack(int n) +{ + return; +} + void -DestroyChildProcess(pr, signal) +DestroyChildProcess(pr, signalType) ProcRef pr; - int signal; + int signalType; { ChildProc *cp = (ChildProc *) pr; if (cp->kind != CPReal) return; cp->kind = CPNone; - if (signal) { - kill(cp->pid, SIGTERM); + if (signalType == 10) { // [HGM] kill: if it does not terminate in 3 sec, kill + signal(SIGALRM, AlarmCallBack); + alarm(3); + if(wait((int *) 0) == -1) { // process does not terminate on its own accord + kill(cp->pid, SIGKILL); // kill it forcefully + wait((int *) 0); // and wait again + } + } else { + if (signalType) { + kill(cp->pid, signalType == 9 ? SIGKILL : SIGTERM); // [HGM] kill: use hard kill if so requested + } + /* Process is exiting either because of the kill or because of + a quit command sent by the backend; either way, wait for it to die. + */ + wait((int *) 0); } - /* Process is exiting either because of the kill or because of - a quit command sent by the backend; either way, wait for it to die. - */ - wait((int *) 0); close(cp->fdFrom); close(cp->fdTo); } diff --git a/xengineoutput.c b/xengineoutput.c index 72b6e26..a7d595d 100644 --- a/xengineoutput.c +++ b/xengineoutput.c @@ -124,7 +124,8 @@ static void SetEngineColorIcon( int which ); #define SHOW_PONDERING /* Imports from backend.c */ -char * SavePart(char *str); +char * SavePart(char *str); +extern int opponentKibitzes; /* Imports from winboard.c */ //extern HWND engineOutputDialog; @@ -172,7 +173,7 @@ typedef struct { int an_move_count; } EngineOutputData; -static VerifyDisplayMode(); +static int VerifyDisplayMode(); static void UpdateControls( EngineOutputData * ed ); static SetEngineState( int which, int state, char * state_data ); @@ -844,6 +845,7 @@ void EngineOutputPopDown() int j; if (!engineOutputDialogUp) return; + DoClearMemo(1); j = 0; XtSetArg(args[j], XtNx, &engineOutputX); j++; XtSetArg(args[j], XtNy, &engineOutputY); j++; @@ -930,6 +932,8 @@ void EngineOutputUpdate( FrontEndProgramStats * stats ) return; } + if(gameMode == IcsObserving) return; // [HGM] kibitz: shut up engine if we are observing an ICS game + which = stats->which; depth = stats->depth; @@ -1068,7 +1072,7 @@ static void SetDisplayMode( int mode ) } // pure back end -static VerifyDisplayMode() +int VerifyDisplayMode() { int mode; @@ -1078,9 +1082,11 @@ static VerifyDisplayMode() case AnalyzeFile: case MachinePlaysWhite: case MachinePlaysBlack: + mode = 0; + break; case IcsPlayingWhite: case IcsPlayingBlack: - mode = 0; + mode = appData.zippyPlay && opponentKibitzes; // [HGM] kibitz break; case TwoMachinesPlay: mode = 1; @@ -1263,4 +1269,25 @@ EngineOutputProc(w, event, prms, nprms) } // ToNrEvent(currentMove); } - + +// [HGM] kibitz: write kibitz line; split window for it if necessary +void OutputKibitz(int window, char *text) +{ + if(!EngineOutputIsUp()) return; + if(!opponentKibitzes) { // on first kibitz of game, clear memos + DoClearMemo(1); + if(gameMode == IcsObserving) DoClearMemo(0); + } + opponentKibitzes = TRUE; // this causes split window DisplayMode in ICS modes. + VerifyDisplayMode(); + if(gameMode == IcsObserving) { + DoSetWindowText(0, nLabel, gameInfo.white); + SetIcon( 0, nColorIcon, nColorWhite); + SetIcon( 0, nStateIcon, nClear); + } + DoSetWindowText(1, nLabel, gameMode == IcsPlayingBlack ? gameInfo.white : gameInfo.black); // opponent name + SetIcon( 1, nColorIcon, gameMode == IcsPlayingBlack ? nColorWhite : nColorBlack); + SetIcon( 1, nStateIcon, nClear); + InsertIntoMemo(window-1, text); +} + diff --git a/xoptions.c b/xoptions.c index 1165a09..5e4fac8 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1,1401 +1,1723 @@ -/* - * xoptions.c -- Move list window, part of X front end for XBoard - * - * Copyright 2000 Free Software Foundation, Inc. - * - * The following terms apply to the enhanced version of XBoard distributed - * by the Free Software Foundation: - * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ------------------------------------------------------------------------ - * - * See the file ChangeLog for a revision history. - */ - -// [HGM] this file is the counterpart of woptions.c, containing xboard popup menus -// similar to those of WinBoard, to set the most common options interactively. - -#include "config.h" - -#include -#include -#include -#include - -#if STDC_HEADERS -# include -# include -#else /* not STDC_HEADERS */ -extern char *getenv(); -# if HAVE_STRING_H -# include -# else /* not HAVE_STRING_H */ -# include -# endif /* not HAVE_STRING_H */ -#endif /* not STDC_HEADERS */ - -#if HAVE_UNISTD_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "backend.h" -#include "xboard.h" - -extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; -extern Display *xDisplay; -extern int squareSize; -extern Pixmap xMarkPixmap; -extern char *layoutName; -extern Window xBoardWindow; -extern Arg layoutArgs[2], formArgs[2]; -Pixel timerForegroundPixel, timerBackgroundPixel; - -// [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines - -static Widget previous = NULL; - -void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b) -{ - Arg args; - - if(previous) { - XtSetArg(args, XtNdisplayCaret, False); - XtSetValues(previous, &args, 1); - } - XtSetArg(args, XtNdisplayCaret, True); - XtSetValues(w, &args, 1); - XtSetKeyboardFocus((Widget) data, w); - previous = w; -} - -//--------------------------- New Shuffle Game -------------------------------------------- -extern int shuffleOpenings; -extern int startedFromPositionFile; -int shuffleUp; -Widget shuffleShell; - -void ShufflePopDown() -{ - if (!shuffleUp) return; - XtPopdown(shuffleShell); - XtDestroyWidget(shuffleShell); - shuffleUp = False; - ModeHighlight(); -} - -void ShuffleCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget w2; - Arg args[16]; - char buf[80]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, "cancel") == 0) { - ShufflePopDown(); - return; - } - if (strcmp(name, "off") == 0) { - ShufflePopDown(); - shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it! - ResetGameEvent(); - AnalysisPopDown(); - return; - } - if (strcmp(name, "random") == 0) { - sprintf(buf, "%d", rand()); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(XtParent(w), args, 1); - return; - } - if (strcmp(name, "ok") == 0) { - int nr; String name; - name = XawDialogGetValueString(w2 = XtParent(w)); - if(sscanf(name ,"%d",&nr) != 1) { - sprintf(buf, "%d", appData.defaultFrcPosition); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(w2, args, 1); - return; - } - appData.defaultFrcPosition = nr; - shuffleOpenings = True; - ShufflePopDown(); - ResetGameEvent(); - AnalysisPopDown(); - return; - } -} - -void ShufflePopUp() -{ - Arg args[16]; - Widget popup, layout, dialog, edit; - Window root, child; - int x, y, i; - int win_x, win_y; - unsigned int mask; - char def[80]; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - shuffleShell = popup = - XtCreatePopupShell("New Shuffle Game", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - sprintf(def, "%d\n", appData.defaultFrcPosition); - i = 0; - XtSetArg(args[i], XtNlabel, "Start-position number:"); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("Shuffle", dialogWidgetClass, - layout, args, i); - -// XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently -// XtSetArg(args[1], XtNuseStringInPlace, False); -// XtSetValues(dialog, args, 2); - - XawDialogAddButton(dialog, "ok", ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, "cancel", ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, "random", ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, "off", ShuffleCallback, (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "ShufflePopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - shuffleUp = True; - - edit = XtNameToWidget(dialog, "*value"); - - XtSetKeyboardFocus(popup, edit); -} - -void ShuffleMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ -// if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { -// Reset(FALSE, TRUE); -// } - ShufflePopUp(); -} - -//--------------------------- Time-Control Menu Popup ---------------------------------- -int TimeControlUp; -Widget TimeControlShell; -int tcInc; -Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2; -int tcIncrement, tcMoves; - -void TimeControlPopDown() -{ - if (!TimeControlUp) return; - XtPopdown(TimeControlShell); - XtDestroyWidget(TimeControlShell); - TimeControlUp = False; - ModeHighlight(); -} - -void TimeControlCallback(w, client_data, call_data) +/* + * xoptions.c -- Move list window, part of X front end for XBoard + * + * Copyright 2000 Free Software Foundation, Inc. + * + * The following terms apply to the enhanced version of XBoard distributed + * by the Free Software Foundation: + * ------------------------------------------------------------------------ + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ------------------------------------------------------------------------ + * + * See the file ChangeLog for a revision history. + */ + +// [HGM] this file is the counterpart of woptions.c, containing xboard popup menus +// similar to those of WinBoard, to set the most common options interactively. + +#include "config.h" + +#include +#include +#include +#include + +#if STDC_HEADERS +# include +# include +#else /* not STDC_HEADERS */ +extern char *getenv(); +# if HAVE_STRING_H +# include +# else /* not HAVE_STRING_H */ +# include +# endif /* not HAVE_STRING_H */ +#endif /* not STDC_HEADERS */ + +#if HAVE_UNISTD_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "backend.h" +#include "xboard.h" + +extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; +extern Display *xDisplay; +extern int squareSize; +extern Pixmap xMarkPixmap; +extern char *layoutName; +extern Window xBoardWindow; +extern Arg layoutArgs[2], formArgs[2]; +Pixel timerForegroundPixel, timerBackgroundPixel; + +// [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines + +static Widget previous = NULL; + +void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b) +{ + Arg args; + + if(previous) { + XtSetArg(args, XtNdisplayCaret, False); + XtSetValues(previous, &args, 1); + } + XtSetArg(args, XtNdisplayCaret, True); + XtSetValues(w, &args, 1); + XtSetKeyboardFocus((Widget) data, w); + previous = w; +} + +//--------------------------- New Shuffle Game -------------------------------------------- +extern int shuffleOpenings; +extern int startedFromPositionFile; +int shuffleUp; +Widget shuffleShell; + +void ShufflePopDown() +{ + if (!shuffleUp) return; + XtPopdown(shuffleShell); + XtDestroyWidget(shuffleShell); + shuffleUp = False; + ModeHighlight(); +} + +void ShuffleCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name; + Widget w2; + Arg args[16]; + char buf[80]; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "cancel") == 0) { + ShufflePopDown(); + return; + } + if (strcmp(name, "off") == 0) { + ShufflePopDown(); + shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it! + ResetGameEvent(); + AnalysisPopDown(); + return; + } + if (strcmp(name, "random") == 0) { + sprintf(buf, "%d", rand()); + XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value + XtSetValues(XtParent(w), args, 1); + return; + } + if (strcmp(name, "ok") == 0) { + int nr; String name; + name = XawDialogGetValueString(w2 = XtParent(w)); + if(sscanf(name ,"%d",&nr) != 1) { + sprintf(buf, "%d", appData.defaultFrcPosition); + XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value + XtSetValues(w2, args, 1); + return; + } + appData.defaultFrcPosition = nr; + shuffleOpenings = True; + ShufflePopDown(); + ResetGameEvent(); + AnalysisPopDown(); + return; + } +} + +void ShufflePopUp() +{ + Arg args[16]; + Widget popup, layout, dialog, edit; + Window root, child; + int x, y, i; + int win_x, win_y; + unsigned int mask; + char def[80]; + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; + XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; + shuffleShell = popup = + XtCreatePopupShell("New Shuffle Game", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + sprintf(def, "%d\n", appData.defaultFrcPosition); + i = 0; + XtSetArg(args[i], XtNlabel, "Start-position number:"); i++; + XtSetArg(args[i], XtNvalue, def); i++; + XtSetArg(args[i], XtNborderWidth, 0); i++; + dialog = XtCreateManagedWidget("Shuffle", dialogWidgetClass, + layout, args, i); + +// XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently +// XtSetArg(args[1], XtNuseStringInPlace, False); +// XtSetValues(dialog, args, 2); + + XawDialogAddButton(dialog, "ok", ShuffleCallback, (XtPointer) dialog); + XawDialogAddButton(dialog, "cancel", ShuffleCallback, (XtPointer) dialog); + XawDialogAddButton(dialog, "random", ShuffleCallback, (XtPointer) dialog); + XawDialogAddButton(dialog, "off", ShuffleCallback, (XtPointer) dialog); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "ShufflePopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + shuffleUp = True; + + edit = XtNameToWidget(dialog, "*value"); + + XtSetKeyboardFocus(popup, edit); +} + +void ShuffleMenuProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ +// if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { +// Reset(FALSE, TRUE); +// } + ShufflePopUp(); +} + +//--------------------------- Time-Control Menu Popup ---------------------------------- +int TimeControlUp; +Widget TimeControlShell; +int tcInc; +Widget tcMess1, tcMess2, tcData, tcTime, tcOdds1, tcOdds2; +int tcIncrement, tcMoves; + +void TimeControlPopDown() +{ + if (!TimeControlUp) return; + XtPopdown(TimeControlShell); + XtDestroyWidget(TimeControlShell); + TimeControlUp = False; + ModeHighlight(); +} + +void TimeControlCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name, txt; + Widget w2; + Arg args[16]; + char buf[80]; + int j; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "classical") == 0) { + if(!tcInc) return; + j=0; + XtSetArg(args[j], XtNlabel, "minutes for each"); j++; + XtSetValues(tcMess1, args, j); + j=0; + XtSetArg(args[j], XtNlabel, "moves"); j++; + XtSetValues(tcMess2, args, j); + j=0; + XtSetArg(args[j], XtNstring, &name); j++; + XtGetValues(tcData, args, j); + tcIncrement = 0; sscanf(name, "%d", &tcIncrement); + sprintf(buf, "%d", tcMoves); + j=0; + XtSetArg(args[j], XtNstring, buf); j++; + XtSetValues(tcData, args, j); + tcInc = False; + return; + } + if (strcmp(name, "incremental") == 0) { + if(tcInc) return; + j=0; + XtSetArg(args[j], XtNlabel, "minutes, plus"); j++; + XtSetValues(tcMess1, args, j); + j=0; + XtSetArg(args[j], XtNlabel, "sec/move"); j++; + XtSetValues(tcMess2, args, j); + j=0; + XtSetArg(args[j], XtNstring, &name); j++; + XtGetValues(tcData, args, j); + tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves); + sprintf(buf, "%d", tcIncrement); + j=0; + XtSetArg(args[j], XtNstring, buf); j++; + XtSetValues(tcData, args, j); + tcInc = True; + return; + } + if (strcmp(name, " OK ") == 0) { + int inc, mps, tc, ok; + XtSetArg(args[0], XtNstring, &txt); + XtGetValues(tcData, args, 1); + if(tcInc) { + ok = sscanf(txt, "%d", &inc); mps = 0; + if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero + ok &= (inc >= 0); + } else { + ok = sscanf(txt, "%d", &mps); inc = -1; + ok &= (mps > 0); + } + if(ok != 1) { + XtSetArg(args[0], XtNstring, ""); // erase any offending input + XtSetValues(tcData, args, 1); + return; + } + XtSetArg(args[0], XtNstring, &txt); + XtGetValues(tcTime, args, 1); + if(!ParseTimeControl(txt, inc, mps)) { + XtSetArg(args[0], XtNstring, ""); // erase any offending input + XtSetValues(tcTime, args, 1); + DisplayError("Bad Time-Control String", 0); + return; + } + appData.movesPerSession = mps; + appData.timeIncrement = inc; + appData.timeControl = strdup(txt); + XtSetArg(args[0], XtNstring, &txt); + XtGetValues(tcOdds1, args, 1); + appData.firstTimeOdds = first.timeOdds + = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1; + XtGetValues(tcOdds2, args, 1); + appData.secondTimeOdds = second.timeOdds + = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1; + + Reset(True, True); + TimeControlPopDown(); + return; + } +} + +void TimeControlPopUp() +{ + Arg args[16]; + Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess; + Window root, child; + int x, y, i, j; + int win_x, win_y; + unsigned int mask; + char def[80]; + + tcInc = (appData.timeIncrement >= 0); + tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement; + if(!tcInc) tcIncrement = 0; + sprintf(def, "%d", tcInc ? tcIncrement : tcMoves); + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; +// XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; + TimeControlShell = popup = + XtCreatePopupShell("TimeControl Menu", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + form = + XtCreateManagedWidget(layoutName, formWidgetClass, layout, + formArgs, XtNumber(formArgs)); + + j = 0; +// XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++; +// XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++; + XtSetValues(popup, args, j); + + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, appData.timeControl); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 85); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, tcInc ? " minutes, plus " : "minutes for each"); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromHoriz, tcTime); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + // XtSetArg(args[j], XtNwidth, 100); j++; + // XtSetArg(args[j], XtNheight, 20); j++; + tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); + + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromHoriz, tcMess1); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, def); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 40); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, tcInc ? "sec/move" : "moves "); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromHoriz, tcData); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; +// XtSetArg(args[j], XtNwidth, 80); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, + form, args, j); + + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, tcTime); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, "1"); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 40); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, tcTime); j++; + XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, "1"); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 40); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, "Engine #1 and #2 Time-Odds Factors"); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromVert, tcTime); j++; + XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; +// XtSetArg(args[j], XtNwidth, 200); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + mess = XtCreateManagedWidget("Oddstext", labelWidgetClass, + form, args, j); + j=0; + XtSetArg(args[j], XtNfromVert, tcOdds1); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + b_clas= XtCreateManagedWidget("classical", commandWidgetClass, + form, args, j); + XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0); + + j=0; + XtSetArg(args[j], XtNfromVert, tcOdds1); j++; + XtSetArg(args[j], XtNfromHoriz, b_clas); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + b_inc = XtCreateManagedWidget("incremental", commandWidgetClass, + form, args, j); + XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0); + + j=0; + XtSetArg(args[j], XtNfromVert, tcOdds1); j++; + XtSetArg(args[j], XtNfromHoriz, tcData); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_ok= XtCreateManagedWidget(" OK ", commandWidgetClass, + form, args, j); + XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0); + + j=0; + XtSetArg(args[j], XtNfromVert, tcOdds1); j++; + XtSetArg(args[j], XtNfromHoriz, b_ok); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_cancel= XtCreateManagedWidget("cancel", commandWidgetClass, + form, args, j); + XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "TimeControlPopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + TimeControlUp = True; + + previous = NULL; + SetFocus(tcTime, popup, (XEvent*) NULL, False); +// XtSetKeyboardFocus(popup, tcTime); +} + +void TimeControlProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + TimeControlPopUp(); +} + +//--------------------------- Engine-Options Menu Popup ---------------------------------- +int EngineUp; +Widget EngineShell; +extern int adjudicateLossThreshold; + +Widget engDrawMoves, engThreshold, engRule, engRepeat; + +void EnginePopDown() +{ + if (!EngineUp) return; + XtPopdown(EngineShell); + XtDestroyWidget(EngineShell); + EngineUp = False; + ModeHighlight(); +} + +int ReadToggle(Widget w) +{ + Arg args; Boolean res; + + XtSetArg(args, XtNstate, &res); + XtGetValues(w, &args, 1); + + return res; +} + +Widget w1, w2, w3, w4, w5, w6, w7, w8; + +void EngineCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name; + Widget s2; + Arg args[16]; + char buf[80]; + int j; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "OK") == 0) { + // read all switches + appData.periodicUpdates = ReadToggle(w1); +// appData.hideThinkingFromHuman = ReadToggle(w2); + appData.firstScoreIsAbsolute = ReadToggle(w3); + appData.secondScoreIsAbsolute = ReadToggle(w4); + appData.testClaims = ReadToggle(w5); + appData.checkMates = ReadToggle(w6); + appData.materialDraws = ReadToggle(w7); + appData.trivialDraws = ReadToggle(w8); + + // adjust setting in other menu for duplicates + // (perhaps duplicates should be removed from general Option Menu?) +// XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None); +// XtSetValues(XtNameToWidget(menuBarWidget, +// "menuOptions.Show Thinking"), args, 1); + + // read out numeric controls, simply ignore bad formats for now + XtSetArg(args[0], XtNstring, &name); + XtGetValues(engDrawMoves, args, 1); + if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j; + XtGetValues(engThreshold, args, 1); + if(sscanf(name, "%d", &j) == 1) + adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted! + XtGetValues(engRule, args, 1); + if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j; + XtGetValues(engRepeat, args, 1); + if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j; + + EnginePopDown(); + ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output + return; + } +} + +void EnginePopUp() +{ + Arg args[16]; + Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1; + Window root, child; + int x, y, i, j, width; + int win_x, win_y; + unsigned int mask; + char def[80]; + + tcInc = (appData.timeIncrement >= 0); + tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement; + if(!tcInc) tcIncrement = 0; + sprintf(def, "%d", tcInc ? tcIncrement : tcMoves); + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; +// XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; + EngineShell = popup = + XtCreatePopupShell("Adjudications", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + form = + XtCreateManagedWidget(layoutName, formWidgetClass, layout, + formArgs, XtNumber(formArgs)); + + j = 0; +// XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++; +// XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++; +// XtSetValues(popup, args, j); + + j = 0; +// XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++; +// XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++; + XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++; + XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++; + XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++; +// XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; + w1 = XtCreateManagedWidget("Periodic Updates (Analysis Mode)", toggleWidgetClass, form, args, j); + + XtSetArg(args[j], XtNwidth, (XtArgVal) &width); + XtGetValues(w1, &args[j], 1); + +// XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1); +// XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman); +// w2 = XtCreateManagedWidget("Hide Thinking from Human", toggleWidgetClass, form, args, j); + + XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++; + XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute); + XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++; + w3 = XtCreateManagedWidget("Engine #1 Score is Absolute", toggleWidgetClass, form, args, j); + + XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3); + XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute); + w4 = XtCreateManagedWidget("Engine #2 Score is Absolute", toggleWidgetClass, form, args, j); + + s1 = XtCreateManagedWidget("\nEngine-Engine Adjudications:", labelWidgetClass, form, args, 3); + + XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1); + XtSetArg(args[j-3], XtNstate, appData.testClaims); + w5 = XtCreateManagedWidget("Verify Engine Result Claims", toggleWidgetClass, form, args, j); + + XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5); + XtSetArg(args[j-3], XtNstate, appData.checkMates); + w6 = XtCreateManagedWidget("Detect All Mates", toggleWidgetClass, form, args, j); + + XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6); + XtSetArg(args[j-3], XtNstate, appData.materialDraws); + w7 = XtCreateManagedWidget("Draw when Insuff. Mating Material", toggleWidgetClass, form, args, j); + + XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7); + XtSetArg(args[j-3], XtNstate, appData.trivialDraws); + w8 = XtCreateManagedWidget("Adjudicate Trivial Draws", toggleWidgetClass, form, args, j); + + XtSetArg(args[0], XtNfromVert, (XtArgVal) w4); + XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0); + XtSetValues(s1, args, 2); + + sprintf(def, "%d", appData.adjudicateDrawMoves); + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, w8); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, def); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 60); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, " moves maximum, then draw"); j++; + XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromVert, w8); j++; + XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; +// XtSetArg(args[j], XtNwidth, 170); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); + + sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted! + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, engDrawMoves); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, def); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 60); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, "-centiPawn lead is win"); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromVert, engDrawMoves); j++; + XtSetArg(args[j], XtNfromHoriz, engThreshold); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; +// XtSetArg(args[j], XtNwidth, 150); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j); + + sprintf(def, "%d", appData.ruleMoves); + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, engThreshold); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, def); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 30); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, "-move rule applied"); j++; + XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromVert, engThreshold); j++; + XtSetArg(args[j], XtNfromHoriz, engRule); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; +// XtSetArg(args[j], XtNwidth, 130); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); + + sprintf(def, "%d", appData.drawRepeats); + j= 0; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNfromVert, engRule); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNstring, def); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, 30); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup); + + j= 0; + XtSetArg(args[j], XtNlabel, "-fold repeat is draw"); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNfromVert, engRule); j++; + XtSetArg(args[j], XtNfromHoriz, engRepeat); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; +// XtSetArg(args[j], XtNwidth, 130); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j); + + j=0; + XtSetArg(args[j], XtNfromVert, engRepeat); j++; + XtSetArg(args[j], XtNfromHoriz, tcMess2); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_ok= XtCreateManagedWidget("OK", commandWidgetClass, form, args, j); + XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0); + + j=0; + XtSetArg(args[j], XtNfromVert, engRepeat); j++; + XtSetArg(args[j], XtNfromHoriz, b_ok); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_cancel= XtCreateManagedWidget("cancel", commandWidgetClass, + form, args, j); + XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "EnginePopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + EngineUp = True; + + previous = NULL; + SetFocus(engThreshold, popup, (XEvent*) NULL, False); +} + +void EngineMenuProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + EnginePopUp(); +} + +//--------------------------- New-Variant Menu PopUp ----------------------------------- +struct NewVarButton { + char *name; + char *color; + Widget handle; + VariantClass variant; +}; + +struct NewVarButton buttonDesc[] = { + {"normal", "#FFFFFF", 0, VariantNormal}, + {"FRC", "#FFFFFF", 0, VariantFischeRandom}, + {"wild castle", "#FFFFFF", 0, VariantWildCastle}, + {"no castle", "#FFFFFF", 0, VariantNoCastle}, + {"knightmate", "#FFFFFF", 0, VariantKnightmate}, + {"berolina", "#FFFFFF", 0, VariantBerolina}, + {"cylinder", "#FFFFFF", 0, VariantCylinder}, + {"shatranj", "#FFFFFF", 0, VariantShatranj}, + {"atomic", "#FFFFFF", 0, VariantAtomic}, + {"two kings", "#FFFFFF", 0, VariantTwoKings}, + {"3-checks", "#FFFFFF", 0, Variant3Check}, + {"suicide", "#FFFFBF", 0, VariantSuicide}, + {"give-away", "#FFFFBF", 0, VariantGiveaway}, + {"losers", "#FFFFBF", 0, VariantLosers}, + {"fairy", "#BFBFBF", 0, VariantFairy}, + {"Superchess", "#FFBFBF", 0, VariantSuper}, + {"crazyhouse", "#FFBFBF", 0, VariantCrazyhouse}, + {"bughouse", "#FFBFBF", 0, VariantBughouse}, + {"shogi (9x9)", "#BFFFFF", 0, VariantShogi}, + {"xiangqi (9x10)", "#BFFFFF", 0, VariantXiangqi}, + {"courier (12x8)", "#BFFFBF", 0, VariantCourier}, + {"janus (10x8)", "#BFBFFF", 0, VariantJanus}, + {"Capablanca (10x8)", "#BFBFFF", 0, VariantCapablanca}, + {"CRC (10x8)", "#BFBFFF", 0, VariantCapaRandom}, +#ifdef GOTHIC + {"Gothic (10x8)", "#BFBFFF", 0, VariantGothic}, +#endif +#ifdef FALCON + {"Falcon (10x8)", "#BFBFFF", 0, VariantFalcon}, +#endif + {NULL, 0, 0, (VariantClass) 0} +}; + +int NewVariantUp; +Widget NewVariantShell; + +void NewVariantPopDown() +{ + if (!NewVariantUp) return; + XtPopdown(NewVariantShell); + XtDestroyWidget(NewVariantShell); + NewVariantUp = False; + ModeHighlight(); +} + +void NewVariantCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name; + Widget w2; + Arg args[16]; + char buf[80]; + VariantClass v; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, " OK ") == 0) { + int nr = (int) XawToggleGetCurrent(buttonDesc[0].handle) - 1; + if(nr < 0) return; + v = buttonDesc[nr].variant; + if(!appData.noChessProgram) { + char *name = VariantName(v), buf[MSG_SIZ]; + if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) { + /* [HGM] in protocol 2 we check if variant is suported by engine */ + sprintf(buf, "Variant %s not supported by %s", name, first.tidy); + DisplayError(buf, 0); +// NewVariantPopDown(); + return; /* ignore OK if first engine does not support it */ + } else + if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) { + sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy); + DisplayError(buf, 0); /* use of second engine is optional; only warn user */ + } + } + + gameInfo.variant = v; + appData.variant = VariantName(v); + + shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ + startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ + appData.pieceToCharTable = NULL; + Reset(True, True); + NewVariantPopDown(); + return; + } +} + +void NewVariantPopUp() +{ + Arg args[16]; + Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel; + Window root, child; + int x, y, i, j; + int win_x, win_y; + unsigned int mask; + char def[80]; + XrmValue vFrom, vTo; + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; +// XtSetArg(args[i], XtNwidth, 250); i++; +// XtSetArg(args[i], XtNheight, 300); i++; + NewVariantShell = popup = + XtCreatePopupShell("NewVariant Menu", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + form = + XtCreateManagedWidget("form", formWidgetClass, layout, + formArgs, XtNumber(formArgs)); + + for(i = 0; buttonDesc[i].name != NULL; i++) { + Pixel buttonColor; + if (!appData.monoMode) { + vFrom.addr = (caddr_t) buttonDesc[i].color; + vFrom.size = strlen(buttonDesc[i].color); + XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo); + if (vTo.addr == NULL) { + buttonColor = (Pixel) -1; + } else { + buttonColor = *(Pixel *) vTo.addr; + } + } + + j = 0; + XtSetArg(args[j], XtNradioGroup, last); j++; + XtSetArg(args[j], XtNwidth, 125); j++; +// XtSetArg(args[j], XtNheight, 16); j++; + XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++; + XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++; + XtSetArg(args[j], XtNradioData, i+1); j++; + XtSetArg(args[j], XtNbackground, buttonColor); j++; + XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++; + buttonDesc[i].handle = last = + XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j); + } + + j=0; + XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++; + XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++; + XtSetArg(args[j], XtNheight, 35); j++; +// XtSetArg(args[j], XtNwidth, 60); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_cancel= XtCreateManagedWidget("CANCEL", commandWidgetClass, form, args, j); + XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0); + + j=0; + XtSetArg(args[j], XtNfromHoriz, b_cancel); j++; + XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++; + XtSetArg(args[j], XtNheight, 35); j++; +// XtSetArg(args[j], XtNwidth, 60); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + b_ok= XtCreateManagedWidget(" OK ", commandWidgetClass, form, args, j); + XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "NewVariantPopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + NewVariantUp = True; +} + +void NewVariantProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + NewVariantPopUp(); +} + +//--------------------------- UCI Menu Popup ------------------------------------------ +int UciUp; +Widget UciShell; + +struct UciControl { + char *name; + Widget handle; + void *ptr; +}; + +struct UciControl controlDesc[] = { + {"maximum nr of CPUs:", 0, &appData.smpCores}, + {"Polyglot Directory:", 0, &appData.polyglotDir}, + {"Hash Size (MB):", 0, &appData.defaultHashSize}, + {"EGTB Path:", 0, &appData.defaultPathEGTB}, + {"EGTB Cache (MB):", 0, &appData.defaultCacheSizeEGTB}, + {"Polyglot Book:", 0, &appData.polyglotBook}, + {NULL, 0, NULL}, +}; + +void UciPopDown() +{ + if (!UciUp) return; + XtPopdown(UciShell); + XtDestroyWidget(UciShell); + UciUp = False; + ModeHighlight(); +} + +void UciCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name; + Arg args[16]; + char buf[80]; + int oldCores = appData.smpCores, ponder = 0; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "OK") == 0) { + int nr, i, j; String name; + for(i=0; i<6; i++) { + XtSetArg(args[0], XtNstring, &name); + XtGetValues(controlDesc[i].handle, args, 1); + if(i&1) { + if(name) + *(char**) controlDesc[i].ptr = strdup(name); + } else { + if(sscanf(name, "%d", &j) == 1) + *(int*) controlDesc[i].ptr = j; + } + } + XtSetArg(args[0], XtNstate, &appData.usePolyglotBook); + XtGetValues(w1, args, 1); + XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI); + XtGetValues(w2, args, 1); + XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI); + XtGetValues(w3, args, 1); + XtSetArg(args[0], XtNstate, &ponder); + XtGetValues(w4, args, 1); + + // adjust setting in other menu for duplicates + // (perhaps duplicates should be removed from general Option Menu?) + XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None); + XtSetValues(XtNameToWidget(menuBarWidget, + "menuOptions.Ponder Next Move"), args, 1); + + // make sure changes are sent to first engine by re-initializing it + // if it was already started pre-emptively at end of previous game + if(gameMode == BeginningOfGame) Reset(True, True); else { + // Some changed setting need immediate sending always. + PonderNextMoveEvent(ponder); + if(oldCores != appData.smpCores) + NewSettingEvent(False, "cores", appData.smpCores); + } + UciPopDown(); + return; + } +} + +void UciPopUp() +{ + Arg args[16]; + Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft; + Window root, child; + int x, y, i, j; + int win_x, win_y; + unsigned int mask; + char def[80]; + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; +// XtSetArg(args[i], XtNwidth, 300); i++; + UciShell = popup = + XtCreatePopupShell("Engine Settings", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + + form = + XtCreateManagedWidget("form", formWidgetClass, layout, + formArgs, XtNumber(formArgs)); + + j = 0; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; +// XtSetArg(args[j], XtNheight, 20); j++; + for(i = 0; controlDesc[i].name != NULL; i++) { + j = 3; + XtSetArg(args[j], XtNfromVert, last); j++; +// XtSetArg(args[j], XtNwidth, 130); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j); + if(i==0) upperLeft = new; + + j = 4; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++; + if(i&1) { + XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ? + * (char**) controlDesc[i].ptr : ""); j++; + } else { + sprintf(def, "%d", * (int*) controlDesc[i].ptr); + XtSetArg(args[j], XtNstring, def); j++; + } + XtSetArg(args[j], XtNfromHoriz, upperLeft); j++; + controlDesc[i].handle = last = + XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j); + XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup); + } + + j=0; + XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++; + XtSetArg(args[j], XtNbottom, XtChainTop); j++; + XtSetArg(args[j], XtNtop, XtChainTop); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++; + w4 = XtCreateManagedWidget("Ponder", toggleWidgetClass, form, args, j); + + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + b_ok = XtCreateManagedWidget("OK", commandWidgetClass, form, args, j); + XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0); + + XtSetArg(args[j], XtNfromHoriz, b_ok); j++; + b_cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form, args, j); + XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0); + + j = 5; + XtSetArg(args[j], XtNfromHoriz, upperLeft); j++; + XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++; + w1 = XtCreateManagedWidget(" use book ", toggleWidgetClass, form, args, j); +// XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0); + + j = 5; + XtSetArg(args[j], XtNfromHoriz, w1); j++; + XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++; + w2 = XtCreateManagedWidget("own book 1", toggleWidgetClass, form, args, j); +// XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0); + + j = 5; + XtSetArg(args[j], XtNfromHoriz, w2); j++; + XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++; + w3 = XtCreateManagedWidget("own book 2", toggleWidgetClass, form, args, j); +// XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "UciPopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + UciUp = True; + + previous = NULL; + SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False); +// XtSetKeyboardFocus(popup, controlDesc[1].handle); +} + +void UciMenuProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + UciPopUp(); +} + +//--------------------------- Engine-specific options menu ---------------------------------- + +int SettingsUp; +Widget SettingsShell; +int values[MAX_OPTIONS]; +ChessProgramState *currentCps; + +void SettingsPopDown() +{ + if (!SettingsUp) return; + XtPopdown(SettingsShell); + XtDestroyWidget(SettingsShell); + SettingsUp = False; + ModeHighlight(); +} + +void SpinCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name, val; + Widget w2; + Arg args[16]; + char buf[MSG_SIZ]; + int i, j; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + j = 0; + XtSetArg(args[0], XtNstring, &val); + XtGetValues(currentCps->option[(int)client_data].handle, args, 1); + sscanf(val, "%d", &j); + if (strcmp(name, "+") == 0) { + if(++j > currentCps->option[(int)client_data].max) return; + } else + if (strcmp(name, "-") == 0) { + if(--j < currentCps->option[(int)client_data].min) return; + } else return; + sprintf(buf, "%d", j); + XtSetArg(args[0], XtNstring, buf); + XtSetValues(currentCps->option[(int)client_data].handle, args, 1); +} + +void SettingsCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name, val; + Widget w2; + Arg args[16]; + char buf[MSG_SIZ]; + int i, j; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "cancel") == 0) { + SettingsPopDown(); + return; + } + if (strcmp(name, "OK") == 0 || (int)client_data) { // save buttons imply OK + int nr; + + for(i=0; inrOptions; i++) { // send all options that had to be OK-ed to engine + switch(currentCps->option[i].type) { + case TextBox: + XtSetArg(args[0], XtNstring, &val); + XtGetValues(currentCps->option[i].handle, args, 1); + if(strcmp(currentCps->option[i].textValue, val)) { + strcpy(currentCps->option[i].textValue, val); + sprintf(buf, "option %s %s\n", currentCps->option[i].name, val); + SendToProgram(buf, currentCps); + } + break; + case Spin: + XtSetArg(args[0], XtNstring, &val); + XtGetValues(currentCps->option[i].handle, args, 1); + sscanf(val, "%d", &j); + if(j > currentCps->option[i].max) j = currentCps->option[i].max; + if(j < currentCps->option[i].min) j = currentCps->option[i].min; + if(currentCps->option[i].value != j) { + currentCps->option[i].value = j; + sprintf(buf, "option %s %d\n", currentCps->option[i].name, j); + SendToProgram(buf, currentCps); + } + break; + case CheckBox: + j = 0; + XtSetArg(args[0], XtNstate, &j); + XtGetValues(currentCps->option[i].handle, args, 1); + if(currentCps->option[i].value != j) { + currentCps->option[i].value = j; + sprintf(buf, "option %s %d\n", currentCps->option[i].name, j); + SendToProgram(buf, currentCps); + } + break; + case ComboBox: + if(currentCps->option[i].value != values[i]) { + currentCps->option[i].value = values[i]; + sprintf(buf, "option %s %s\n", currentCps->option[i].name, + ((char**)currentCps->option[i].textValue)[values[i]]); + SendToProgram(buf, currentCps); + } + break; + } + } + if((int)client_data) { // send save-button command to engine + sprintf(buf, "option %s\n", name); + SendToProgram(buf, currentCps); + } + SettingsPopDown(); + return; + } + sprintf(buf, "option %s\n", name); + SendToProgram(buf, currentCps); +} + +void ComboSelect(w, addr, index) // callback for all combo items Widget w; - XtPointer client_data, call_data; -{ - String name, txt; - Widget w2; - Arg args[16]; - char buf[80]; - int j; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, "classical") == 0) { - if(!tcInc) return; - j=0; - XtSetArg(args[j], XtNlabel, "minutes for each"); j++; - XtSetValues(tcMess1, args, j); - j=0; - XtSetArg(args[j], XtNlabel, "moves"); j++; - XtSetValues(tcMess2, args, j); - j=0; - XtSetArg(args[j], XtNstring, &name); j++; - XtGetValues(tcData, args, j); - tcIncrement = 0; sscanf(name, "%d", &tcIncrement); - sprintf(buf, "%d", tcMoves); - j=0; - XtSetArg(args[j], XtNstring, buf); j++; - XtSetValues(tcData, args, j); - tcInc = False; - return; - } - if (strcmp(name, "incremental") == 0) { - if(tcInc) return; - j=0; - XtSetArg(args[j], XtNlabel, "minutes, plus"); j++; - XtSetValues(tcMess1, args, j); - j=0; - XtSetArg(args[j], XtNlabel, "sec/move"); j++; - XtSetValues(tcMess2, args, j); - j=0; - XtSetArg(args[j], XtNstring, &name); j++; - XtGetValues(tcData, args, j); - tcMoves = appData.movesPerSession; sscanf(name, "%d", &tcMoves); - sprintf(buf, "%d", tcIncrement); - j=0; - XtSetArg(args[j], XtNstring, buf); j++; - XtSetValues(tcData, args, j); - tcInc = True; - return; - } - if (strcmp(name, " OK ") == 0) { - int inc, mps, tc, ok; - XtSetArg(args[0], XtNstring, &txt); - XtGetValues(tcData, args, 1); - if(tcInc) { - ok = sscanf(txt, "%d", &inc); mps = 0; - if(!ok && txt[0] == 0) { inc = 0; ok = 1; } // accept empty string as zero - ok &= (inc >= 0); - } else { - ok = sscanf(txt, "%d", &mps); inc = -1; - ok &= (mps > 0); - } - if(ok != 1) { - XtSetArg(args[0], XtNstring, ""); // erase any offending input - XtSetValues(tcData, args, 1); - return; - } - XtSetArg(args[0], XtNstring, &txt); - XtGetValues(tcTime, args, 1); - if(!ParseTimeControl(txt, inc, mps)) { - XtSetArg(args[0], XtNstring, ""); // erase any offending input - XtSetValues(tcTime, args, 1); - DisplayError("Bad Time-Control String", 0); - return; - } - appData.movesPerSession = mps; - appData.timeIncrement = inc; - appData.timeControl = strdup(txt); - XtSetArg(args[0], XtNstring, &txt); - XtGetValues(tcOdds1, args, 1); - appData.firstTimeOdds = first.timeOdds - = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1; - XtGetValues(tcOdds2, args, 1); - appData.secondTimeOdds = second.timeOdds - = (sscanf(txt, "%d", &j) == 1 && j > 0) ? j : 1; - - Reset(True, True); - TimeControlPopDown(); - return; - } -} - -void TimeControlPopUp() + caddr_t addr; + caddr_t index; +{ + Arg args[16]; + int i = ((int)addr)>>8; + int j = 255 & (int) addr; + + values[i] = j; // store in temporary, for transfer at OK + XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]); + XtSetValues(currentCps->option[i].handle, args, 1); +} + +void CreateComboPopup(parent, name, n, mb) + Widget parent; + String name; + int n; + char *mb[]; { + int i=0, j; + Widget menu, entry; Arg args[16]; - Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, mess; - Window root, child; - int x, y, i, j; - int win_x, win_y; - unsigned int mask; - char def[80]; - - tcInc = (appData.timeIncrement >= 0); - tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement; - if(!tcInc) tcIncrement = 0; - sprintf(def, "%d", tcInc ? tcIncrement : tcMoves); - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; -// XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - TimeControlShell = popup = - XtCreatePopupShell("TimeControl Menu", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - form = - XtCreateManagedWidget(layoutName, formWidgetClass, layout, - formArgs, XtNumber(formArgs)); - + menu = XtCreatePopupShell(name, simpleMenuWidgetClass, + parent, NULL, 0); j = 0; -// XtSetArg(args[j], XtNwidth, (XtArgVal) 300); j++; -// XtSetArg(args[j], XtNheight, (XtArgVal) 85); j++; - XtSetValues(popup, args, j); - - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, appData.timeControl); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 85); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, tcInc ? " minutes, plus " : "minutes for each"); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromHoriz, tcTime); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - // XtSetArg(args[j], XtNwidth, 100); j++; - // XtSetArg(args[j], XtNheight, 20); j++; - tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); - - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromHoriz, tcMess1); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, def); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 40); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcData = XtCreateManagedWidget("MPS", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(tcData, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, tcInc ? "sec/move" : "moves "); j++; - XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromHoriz, tcData); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; -// XtSetArg(args[j], XtNwidth, 80); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, - form, args, j); - - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, tcTime); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, "1"); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 40); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcOdds1 = XtCreateManagedWidget("Odds1", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(tcOdds1, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, tcTime); j++; - XtSetArg(args[j], XtNfromHoriz, tcOdds1); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, "1"); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 40); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcOdds2 = XtCreateManagedWidget("Odds2", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(tcOdds2, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, "Engine #1 and #2 Time-Odds Factors"); j++; - XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromVert, tcTime); j++; - XtSetArg(args[j], XtNfromHoriz, tcOdds2); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; -// XtSetArg(args[j], XtNwidth, 200); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - mess = XtCreateManagedWidget("Oddstext", labelWidgetClass, - form, args, j); - j=0; - XtSetArg(args[j], XtNfromVert, tcOdds1); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - b_clas= XtCreateManagedWidget("classical", commandWidgetClass, - form, args, j); - XtAddCallback(b_clas, XtNcallback, TimeControlCallback, (XtPointer) 0); - - j=0; - XtSetArg(args[j], XtNfromVert, tcOdds1); j++; - XtSetArg(args[j], XtNfromHoriz, b_clas); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - b_inc = XtCreateManagedWidget("incremental", commandWidgetClass, - form, args, j); - XtAddCallback(b_inc, XtNcallback, TimeControlCallback, (XtPointer) 0); - - j=0; - XtSetArg(args[j], XtNfromVert, tcOdds1); j++; - XtSetArg(args[j], XtNfromHoriz, tcData); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_ok= XtCreateManagedWidget(" OK ", commandWidgetClass, - form, args, j); - XtAddCallback(b_ok, XtNcallback, TimeControlCallback, (XtPointer) 0); - - j=0; - XtSetArg(args[j], XtNfromVert, tcOdds1); j++; - XtSetArg(args[j], XtNfromHoriz, b_ok); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_cancel= XtCreateManagedWidget("cancel", commandWidgetClass, - form, args, j); - XtAddCallback(b_cancel, XtNcallback, TimeControlPopDown, (XtPointer) 0); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "TimeControlPopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - TimeControlUp = True; - - previous = NULL; - SetFocus(tcTime, popup, (XEvent*) NULL, False); -// XtSetKeyboardFocus(popup, tcTime); -} - -void TimeControlProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - TimeControlPopUp(); -} - -//--------------------------- Engine-Options Menu Popup ---------------------------------- -int EngineUp; -Widget EngineShell; -extern int adjudicateLossThreshold; - -Widget engDrawMoves, engThreshold, engRule, engRepeat; - -void EnginePopDown() -{ - if (!EngineUp) return; - XtPopdown(EngineShell); - XtDestroyWidget(EngineShell); - EngineUp = False; - ModeHighlight(); -} - -int ReadToggle(Widget w) -{ - Arg args; Boolean res; - - XtSetArg(args, XtNstate, &res); - XtGetValues(w, &args, 1); - - return res; -} - -Widget w1, w2, w3, w4, w5, w6, w7, w8; - -void EngineCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget s2; - Arg args[16]; - char buf[80]; - int j; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, "OK") == 0) { - // read all switches - appData.periodicUpdates = ReadToggle(w1); -// appData.hideThinkingFromHuman = ReadToggle(w2); - appData.firstScoreIsAbsolute = ReadToggle(w3); - appData.secondScoreIsAbsolute = ReadToggle(w4); - appData.testClaims = ReadToggle(w5); - appData.checkMates = ReadToggle(w6); - appData.materialDraws = ReadToggle(w7); - appData.trivialDraws = ReadToggle(w8); - - // adjust setting in other menu for duplicates - // (perhaps duplicates should be removed from general Option Menu?) -// XtSetArg(args[0], XtNleftBitmap, appData.showThinking ? xMarkPixmap : None); -// XtSetValues(XtNameToWidget(menuBarWidget, -// "menuOptions.Show Thinking"), args, 1); - - // read out numeric controls, simply ignore bad formats for now - XtSetArg(args[0], XtNstring, &name); - XtGetValues(engDrawMoves, args, 1); - if(sscanf(name, "%d", &j) == 1) appData.adjudicateDrawMoves = j; - XtGetValues(engThreshold, args, 1); - if(sscanf(name, "%d", &j) == 1) - adjudicateLossThreshold = appData.adjudicateLossThreshold = -j; // inverted! - XtGetValues(engRule, args, 1); - if(sscanf(name, "%d", &j) == 1) appData.ruleMoves = j; - XtGetValues(engRepeat, args, 1); - if(sscanf(name, "%d", &j) == 1) appData.drawRepeats = j; - - EnginePopDown(); - ShowThinkingEvent(); // [HGM] thinking: score adjudication might need thinking output - return; + XtSetArg(args[j], XtNwidth, 100); j++; +// XtSetArg(args[j], XtNright, XtChainRight); j++; + while (mb[i] != NULL) { + entry = XtCreateManagedWidget(mb[i], smeBSBObjectClass, + menu, args, j); + XtAddCallback(entry, XtNcallback, + (XtCallbackProc) ComboSelect, + (caddr_t) (256*n+i)); + i++; } -} - -void EnginePopUp() -{ - Arg args[16]; - Widget popup, layout, form, edit, b_ok, b_cancel, b_clas, b_inc, s1; - Window root, child; - int x, y, i, j, width; - int win_x, win_y; - unsigned int mask; - char def[80]; - - tcInc = (appData.timeIncrement >= 0); - tcMoves = appData.movesPerSession; tcIncrement = appData.timeIncrement; - if(!tcInc) tcIncrement = 0; - sprintf(def, "%d", tcInc ? tcIncrement : tcMoves); - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; -// XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - EngineShell = popup = - XtCreatePopupShell("Adjudications", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - form = - XtCreateManagedWidget(layoutName, formWidgetClass, layout, - formArgs, XtNumber(formArgs)); - - j = 0; -// XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++; -// XtSetArg(args[j], XtNheight, (XtArgVal) 400); j++; -// XtSetValues(popup, args, j); - - j = 0; -// XtSetArg(args[j], XtNwidth, (XtArgVal) 250); j++; -// XtSetArg(args[j], XtNheight, (XtArgVal) 20); j++; - XtSetArg(args[j], XtNleft, (XtArgVal) XtChainLeft); j++; - XtSetArg(args[j], XtNright, (XtArgVal) XtChainRight); j++; - XtSetArg(args[j], XtNstate, appData.periodicUpdates); j++; -// XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; - w1 = XtCreateManagedWidget("Periodic Updates (Analysis Mode)", toggleWidgetClass, form, args, j); - - XtSetArg(args[j], XtNwidth, (XtArgVal) &width); - XtGetValues(w1, &args[j], 1); - -// XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w1); -// XtSetArg(args[j-3], XtNstate, appData.hideThinkingFromHuman); -// w2 = XtCreateManagedWidget("Hide Thinking from Human", toggleWidgetClass, form, args, j); - - XtSetArg(args[j], XtNwidth, (XtArgVal) width); j++; - XtSetArg(args[j-2], XtNstate, appData.firstScoreIsAbsolute); - XtSetArg(args[j], XtNfromVert, (XtArgVal) w1); j++; - w3 = XtCreateManagedWidget("Engine #1 Score is Absolute", toggleWidgetClass, form, args, j); - - XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w3); - XtSetArg(args[j-3], XtNstate, appData.secondScoreIsAbsolute); - w4 = XtCreateManagedWidget("Engine #2 Score is Absolute", toggleWidgetClass, form, args, j); - - s1 = XtCreateManagedWidget("\nEngine-Engine Adjudications:", labelWidgetClass, form, args, 3); - - XtSetArg(args[j-1], XtNfromVert, (XtArgVal) s1); - XtSetArg(args[j-3], XtNstate, appData.testClaims); - w5 = XtCreateManagedWidget("Verify Engine Result Claims", toggleWidgetClass, form, args, j); - - XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w5); - XtSetArg(args[j-3], XtNstate, appData.checkMates); - w6 = XtCreateManagedWidget("Detect All Mates", toggleWidgetClass, form, args, j); - - XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w6); - XtSetArg(args[j-3], XtNstate, appData.materialDraws); - w7 = XtCreateManagedWidget("Draw when Insuff. Mating Material", toggleWidgetClass, form, args, j); - - XtSetArg(args[j-1], XtNfromVert, (XtArgVal) w7); - XtSetArg(args[j-3], XtNstate, appData.trivialDraws); - w8 = XtCreateManagedWidget("Adjudicate Trivial Draws", toggleWidgetClass, form, args, j); - - XtSetArg(args[0], XtNfromVert, (XtArgVal) w4); - XtSetArg(args[1], XtNborderWidth, (XtArgVal) 0); - XtSetValues(s1, args, 2); - - sprintf(def, "%d", appData.adjudicateDrawMoves); - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, w8); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, def); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 60); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - engDrawMoves = XtCreateManagedWidget("Length", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(engDrawMoves, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, " moves maximum, then draw"); j++; - XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromVert, w8); j++; - XtSetArg(args[j], XtNfromHoriz, engDrawMoves); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; -// XtSetArg(args[j], XtNwidth, 170); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); - - sprintf(def, "%d", -appData.adjudicateLossThreshold); // inverted! - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, engDrawMoves); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, def); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 60); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, "-centiPawn lead is win"); j++; - XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromVert, engDrawMoves); j++; - XtSetArg(args[j], XtNfromHoriz, engThreshold); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; -// XtSetArg(args[j], XtNwidth, 150); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j); - - sprintf(def, "%d", appData.ruleMoves); - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, engThreshold); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, def); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 30); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - engRule = XtCreateManagedWidget("Rule", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(engRule, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, "-move rule applied"); j++; - XtSetArg(args[j], XtNjustify, (XtArgVal) XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromVert, engThreshold); j++; - XtSetArg(args[j], XtNfromHoriz, engRule); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; -// XtSetArg(args[j], XtNwidth, 130); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcMess1 = XtCreateManagedWidget("TCtext", labelWidgetClass, form, args, j); - - sprintf(def, "%d", appData.drawRepeats); - j= 0; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNfromVert, engRule); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNstring, def); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, 30); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - engRepeat = XtCreateManagedWidget("Repeats", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(engRepeat, ButtonPressMask, False, SetFocus, (XtPointer) popup); - - j= 0; - XtSetArg(args[j], XtNlabel, "-fold repeat is draw"); j++; - XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - XtSetArg(args[j], XtNfromVert, engRule); j++; - XtSetArg(args[j], XtNfromHoriz, engRepeat); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; -// XtSetArg(args[j], XtNwidth, 130); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - tcMess2 = XtCreateManagedWidget("MPStext", labelWidgetClass, form, args, j); - - j=0; - XtSetArg(args[j], XtNfromVert, engRepeat); j++; - XtSetArg(args[j], XtNfromHoriz, tcMess2); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_ok= XtCreateManagedWidget("OK", commandWidgetClass, form, args, j); - XtAddCallback(b_ok, XtNcallback, EngineCallback, (XtPointer) 0); - - j=0; - XtSetArg(args[j], XtNfromVert, engRepeat); j++; - XtSetArg(args[j], XtNfromHoriz, b_ok); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_cancel= XtCreateManagedWidget("cancel", commandWidgetClass, - form, args, j); - XtAddCallback(b_cancel, XtNcallback, EnginePopDown, (XtPointer) 0); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "EnginePopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - EngineUp = True; - - previous = NULL; - SetFocus(engThreshold, popup, (XEvent*) NULL, False); -} - -void EngineMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - EnginePopUp(); -} - -//--------------------------- New-Variant Menu PopUp ----------------------------------- -struct NewVarButton { - char *name; - char *color; - Widget handle; - VariantClass variant; -}; - -struct NewVarButton buttonDesc[] = { - {"normal", "#FFFFFF", 0, VariantNormal}, - {"FRC", "#FFFFFF", 0, VariantFischeRandom}, - {"wild castle", "#FFFFFF", 0, VariantWildCastle}, - {"no castle", "#FFFFFF", 0, VariantNoCastle}, - {"knightmate", "#FFFFFF", 0, VariantKnightmate}, - {"berolina", "#FFFFFF", 0, VariantBerolina}, - {"cylinder", "#FFFFFF", 0, VariantCylinder}, - {"shatranj", "#FFFFFF", 0, VariantShatranj}, - {"atomic", "#FFFFFF", 0, VariantAtomic}, - {"two kings", "#FFFFFF", 0, VariantTwoKings}, - {"3-checks", "#FFFFFF", 0, Variant3Check}, - {"suicide", "#FFFFBF", 0, VariantSuicide}, - {"give-away", "#FFFFBF", 0, VariantGiveaway}, - {"losers", "#FFFFBF", 0, VariantLosers}, - {"fairy", "#BFBFBF", 0, VariantFairy}, - {"Superchess", "#FFBFBF", 0, VariantSuper}, - {"crazyhouse", "#FFBFBF", 0, VariantCrazyhouse}, - {"bughouse", "#FFBFBF", 0, VariantBughouse}, - {"shogi (9x9)", "#BFFFFF", 0, VariantShogi}, - {"xiangqi (9x10)", "#BFFFFF", 0, VariantXiangqi}, - {"courier (12x8)", "#BFFFBF", 0, VariantCourier}, - {"janus (10x8)", "#BFBFFF", 0, VariantJanus}, - {"Capablanca (10x8)", "#BFBFFF", 0, VariantCapablanca}, - {"CRC (10x8)", "#BFBFFF", 0, VariantCapaRandom}, -#ifdef GOTHIC - {"Gothic (10x8)", "#BFBFFF", 0, VariantGothic}, -#endif -#ifdef FALCON - {"Falcon (10x8)", "#BFBFFF", 0, VariantFalcon}, -#endif - {NULL, 0, 0, (VariantClass) 0} -}; - -int NewVariantUp; -Widget NewVariantShell; - -void NewVariantPopDown() -{ - if (!NewVariantUp) return; - XtPopdown(NewVariantShell); - XtDestroyWidget(NewVariantShell); - NewVariantUp = False; - ModeHighlight(); -} - -void NewVariantCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget w2; - Arg args[16]; - char buf[80]; - VariantClass v; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, " OK ") == 0) { - int nr = (int) XawToggleGetCurrent(buttonDesc[0].handle) - 1; - if(nr < 0) return; - v = buttonDesc[nr].variant; - if(!appData.noChessProgram) { - char *name = VariantName(v), buf[MSG_SIZ]; - if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) { - /* [HGM] in protocol 2 we check if variant is suported by engine */ - sprintf(buf, "Variant %s not supported by %s", name, first.tidy); - DisplayError(buf, 0); -// NewVariantPopDown(); - return; /* ignore OK if first engine does not support it */ - } else - if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) { - sprintf(buf, "Warning: second engine (%s) does not support this!", second.tidy); - DisplayError(buf, 0); /* use of second engine is optional; only warn user */ - } - } - - gameInfo.variant = v; - appData.variant = VariantName(v); - - shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ - startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ - appData.pieceToCharTable = NULL; - Reset(True, True); - NewVariantPopDown(); - return; - } -} - -void NewVariantPopUp() -{ - Arg args[16]; - Widget popup, layout, dialog, edit, form, last = NULL, b_ok, b_cancel; - Window root, child; - int x, y, i, j; - int win_x, win_y; - unsigned int mask; - char def[80]; - XrmValue vFrom, vTo; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; -// XtSetArg(args[i], XtNwidth, 250); i++; -// XtSetArg(args[i], XtNheight, 300); i++; - NewVariantShell = popup = - XtCreatePopupShell("NewVariant Menu", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - form = - XtCreateManagedWidget("form", formWidgetClass, layout, - formArgs, XtNumber(formArgs)); - - for(i = 0; buttonDesc[i].name != NULL; i++) { - Pixel buttonColor; - if (!appData.monoMode) { - vFrom.addr = (caddr_t) buttonDesc[i].color; - vFrom.size = strlen(buttonDesc[i].color); - XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo); - if (vTo.addr == NULL) { - buttonColor = (Pixel) -1; - } else { - buttonColor = *(Pixel *) vTo.addr; - } - } - - j = 0; - XtSetArg(args[j], XtNradioGroup, last); j++; - XtSetArg(args[j], XtNwidth, 125); j++; -// XtSetArg(args[j], XtNheight, 16); j++; - XtSetArg(args[j], XtNfromVert, i == 15 ? NULL : last); j++; - XtSetArg(args[j], XtNfromHoriz, i < 15 ? NULL : buttonDesc[i-15].handle); j++; - XtSetArg(args[j], XtNradioData, i+1); j++; - XtSetArg(args[j], XtNbackground, buttonColor); j++; - XtSetArg(args[j], XtNstate, gameInfo.variant == buttonDesc[i].variant); j++; - buttonDesc[i].handle = last = - XtCreateManagedWidget(buttonDesc[i].name, toggleWidgetClass, form, args, j); - } - - j=0; - XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++; - XtSetArg(args[j], XtNfromHoriz, buttonDesc[12].handle); j++; - XtSetArg(args[j], XtNheight, 35); j++; -// XtSetArg(args[j], XtNwidth, 60); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_cancel= XtCreateManagedWidget("CANCEL", commandWidgetClass, form, args, j); - XtAddCallback(b_cancel, XtNcallback, NewVariantPopDown, (XtPointer) 0); - - j=0; - XtSetArg(args[j], XtNfromHoriz, b_cancel); j++; - XtSetArg(args[j], XtNfromVert, buttonDesc[12].handle); j++; - XtSetArg(args[j], XtNheight, 35); j++; -// XtSetArg(args[j], XtNwidth, 60); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - b_ok= XtCreateManagedWidget(" OK ", commandWidgetClass, form, args, j); - XtAddCallback(b_ok, XtNcallback, NewVariantCallback, (XtPointer) 0); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "NewVariantPopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - NewVariantUp = True; -} - -void NewVariantProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - NewVariantPopUp(); -} - -//--------------------------- UCI Menu Popup ------------------------------------------ -int UciUp; -Widget UciShell; - -struct UciControl { - char *name; - Widget handle; - void *ptr; -}; - -struct UciControl controlDesc[] = { - {"maximum nr of CPUs:", 0, &appData.smpCores}, - {"Polyglot Directory:", 0, &appData.polyglotDir}, - {"Hash Size (MB):", 0, &appData.defaultHashSize}, - {"EGTB Path:", 0, &appData.defaultPathEGTB}, - {"EGTB Cache (MB):", 0, &appData.defaultCacheSizeEGTB}, - {"Polyglot Book:", 0, &appData.polyglotBook}, - {NULL, 0, NULL}, -}; - -void UciPopDown() -{ - if (!UciUp) return; - XtPopdown(UciShell); - XtDestroyWidget(UciShell); - UciUp = False; - ModeHighlight(); -} - -void UciCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Arg args[16]; - char buf[80]; - int oldCores = appData.smpCores, ponder = 0; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, "OK") == 0) { - int nr, i, j; String name; - for(i=0; i<6; i++) { - XtSetArg(args[0], XtNstring, &name); - XtGetValues(controlDesc[i].handle, args, 1); - if(i&1) { - if(name) - *(char**) controlDesc[i].ptr = strdup(name); - } else { - if(sscanf(name, "%d", &j) == 1) - *(int*) controlDesc[i].ptr = j; - } - } - XtSetArg(args[0], XtNstate, &appData.usePolyglotBook); - XtGetValues(w1, args, 1); - XtSetArg(args[0], XtNstate, &appData.firstHasOwnBookUCI); - XtGetValues(w2, args, 1); - XtSetArg(args[0], XtNstate, &appData.secondHasOwnBookUCI); - XtGetValues(w3, args, 1); - XtSetArg(args[0], XtNstate, &ponder); - XtGetValues(w4, args, 1); - - // adjust setting in other menu for duplicates - // (perhaps duplicates should be removed from general Option Menu?) - XtSetArg(args[0], XtNleftBitmap, ponder ? xMarkPixmap : None); - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Ponder Next Move"), args, 1); - - // make sure changes are sent to first engine by re-initializing it - // if it was already started pre-emptively at end of previous game - if(gameMode == BeginningOfGame) Reset(True, True); else { - // Some changed setting need immediate sending always. - PonderNextMoveEvent(ponder); - if(oldCores != appData.smpCores) - NewSettingEvent(False, "cores", appData.smpCores); - } - UciPopDown(); - return; - } -} - -void UciPopUp() -{ - Arg args[16]; - Widget popup, layout, dialog, edit, form, b_ok, b_cancel, last = NULL, new, upperLeft; - Window root, child; - int x, y, i, j; - int win_x, win_y; - unsigned int mask; - char def[80]; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; -// XtSetArg(args[i], XtNwidth, 300); i++; - UciShell = popup = - XtCreatePopupShell("Engine Settings", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - - form = - XtCreateManagedWidget("form", formWidgetClass, layout, - formArgs, XtNumber(formArgs)); - - j = 0; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; -// XtSetArg(args[j], XtNheight, 20); j++; - for(i = 0; controlDesc[i].name != NULL; i++) { - j = 3; - XtSetArg(args[j], XtNfromVert, last); j++; -// XtSetArg(args[j], XtNwidth, 130); j++; - XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - XtSetArg(args[j], XtNborderWidth, 0); j++; - new = XtCreateManagedWidget(controlDesc[i].name, labelWidgetClass, form, args, j); - if(i==0) upperLeft = new; - - j = 4; - XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNeditType, XawtextEdit); j++; - XtSetArg(args[j], XtNuseStringInPlace, False); j++; - XtSetArg(args[j], XtNdisplayCaret, False); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - XtSetArg(args[j], XtNresizable, True); j++; - XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++; - if(i&1) { - XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ? - * (char**) controlDesc[i].ptr : ""); j++; - } else { - sprintf(def, "%d", * (int*) controlDesc[i].ptr); - XtSetArg(args[j], XtNstring, def); j++; - } - XtSetArg(args[j], XtNfromHoriz, upperLeft); j++; - controlDesc[i].handle = last = - XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j); - XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup); - } - - j=0; - XtSetArg(args[j], XtNfromHoriz, controlDesc[0].handle); j++; - XtSetArg(args[j], XtNbottom, XtChainTop); j++; - XtSetArg(args[j], XtNtop, XtChainTop); j++; - XtSetArg(args[j], XtNleft, XtChainRight); j++; - XtSetArg(args[j], XtNright, XtChainRight); j++; - XtSetArg(args[j], XtNstate, appData.ponderNextMove); j++; - w4 = XtCreateManagedWidget("Ponder", toggleWidgetClass, form, args, j); - - j=0; - XtSetArg(args[j], XtNfromVert, last); j++; - XtSetArg(args[j], XtNbottom, XtChainBottom); j++; - XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; - b_ok = XtCreateManagedWidget("OK", commandWidgetClass, form, args, j); - XtAddCallback(b_ok, XtNcallback, UciCallback, (XtPointer) 0); - - XtSetArg(args[j], XtNfromHoriz, b_ok); j++; - b_cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form, args, j); - XtAddCallback(b_cancel, XtNcallback, UciPopDown, (XtPointer) 0); - - j = 5; - XtSetArg(args[j], XtNfromHoriz, upperLeft); j++; - XtSetArg(args[j], XtNstate, appData.usePolyglotBook); j++; - w1 = XtCreateManagedWidget(" use book ", toggleWidgetClass, form, args, j); -// XtAddCallback(w1, XtNcallback, UciCallback, (XtPointer) 0); - - j = 5; - XtSetArg(args[j], XtNfromHoriz, w1); j++; - XtSetArg(args[j], XtNstate, appData.firstHasOwnBookUCI); j++; - w2 = XtCreateManagedWidget("own book 1", toggleWidgetClass, form, args, j); -// XtAddCallback(w2, XtNcallback, UciCallback, (XtPointer) 0); - - j = 5; - XtSetArg(args[j], XtNfromHoriz, w2); j++; - XtSetArg(args[j], XtNstate, appData.secondHasOwnBookUCI); j++; - w3 = XtCreateManagedWidget("own book 2", toggleWidgetClass, form, args, j); -// XtAddCallback(w3, XtNcallback, UciCallback, (XtPointer) 0); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "UciPopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - UciUp = True; - - previous = NULL; - SetFocus(controlDesc[2].handle, popup, (XEvent*) NULL, False); -// XtSetKeyboardFocus(popup, controlDesc[1].handle); -} - -void UciMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - UciPopUp(); -} - -//--------------------------- General Popup for Cloning ---------------------------------- -#if 0 -int XXXUp; -Widget XXXShell; - -void XXXPopDown() -{ - if (!XXXUp) return; - XtPopdown(XXXShell); - XtDestroyWidget(XXXShell); - XXXUp = False; - ModeHighlight(); -} - -void XXXCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget w2; - Arg args[16]; - char buf[80]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, "cancel") == 0) { - XXXPopDown(); - return; - } - if (strcmp(name, "ok") == 0) { - int nr; String name; - name = XawDialogGetValueString(w2 = XtParent(w)); - if(sscanf(name ,"%d",&nr) != 1) { - sprintf(buf, "%d", appData.defaultFrcPosition); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(w2, args, 1); - return; - } - XXXPopDown(); - return; - } -} - -void XXXPopUp() -{ - Arg args[16]; - Widget popup, layout, dialog, edit; - Window root, child; - int x, y, i; - int win_x, win_y; - unsigned int mask; - char def[80]; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - XXXShell = popup = - XtCreatePopupShell("XXX Menu", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - sprintf(def, "%d\n", appData.defaultFrcPosition); - i = 0; - XtSetArg(args[i], XtNlabel, ""); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("XXX", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, "ok", XXXCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, "cancel", XXXCallback, (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "XXXPopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - XXXUp = True; - - edit = XtNameToWidget(dialog, "*value"); - - previous = NULL; - SetFocus(engThreshold, popup, (XEvent*) NULL, False); -} - -void XXXMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - XXXPopUp(); -} -#endif - +} + +void SettingsPopUp(ChessProgramState *cps) +{ + Arg args[16]; + Widget popup, layout, dialog, edit, form, oldform, last, b_ok, b_cancel; + Window root, child; + int x, y, i, j; + int win_x, win_y; + unsigned int mask; + char def[80], *p, *q; + + // to do: start up second engine if needed + if(!cps->initDone || !cps->nrOptions) return; // nothing to be done + currentCps = cps; + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; + SettingsShell = popup = + XtCreatePopupShell("Settings Menu", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + form = + XtCreateManagedWidget(layoutName, formWidgetClass, layout, + formArgs, XtNumber(formArgs)); + + last = NULL; + for(i=0; inrOptions; i++) { + Widget box; + switch(cps->option[i].type) { + case Spin: + sprintf(def, "%d", cps->option[i].value); + case TextBox: + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j); + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNfromHoriz, dialog); j++; + XtSetArg(args[j], XtNborderWidth, 1); j++; + XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++; + XtSetArg(args[j], XtNeditType, XawtextEdit); j++; + XtSetArg(args[j], XtNuseStringInPlace, False); j++; + XtSetArg(args[j], XtNdisplayCaret, False); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNresizable, True); j++; + XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++; + edit = last; + cps->option[i].handle = (void*) + (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j)); + XtAddEventHandler(box, ButtonPressMask, False, SetFocus, (XtPointer) popup); + if(cps->option[i].type == TextBox) break; + // add increment and decrement controls for spin + j=0; + XtSetArg(args[j], XtNfromVert, edit); j++; + XtSetArg(args[j], XtNfromHoriz, box); j++; + XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNwidth, 20); j++; + edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j); + XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i); + j=0; + XtSetArg(args[j], XtNfromVert, edit); j++; + XtSetArg(args[j], XtNfromHoriz, last); j++; + XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNwidth, 20); j++; + last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j); + XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i); + break; + case CheckBox: + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNwidth, 10); j++; + XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNstate, cps->option[i].value); j++; + cps->option[i].handle = (void*) + (dialog = XtCreateManagedWidget(" ", toggleWidgetClass, form, args, j)); + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNfromHoriz, dialog); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + last = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j); + break; + case SaveButton: + case Button: + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNstate, cps->option[i].value); j++; + cps->option[i].handle = (void*) + (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j)); + XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton)); + break; + case ComboBox: + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNborderWidth, 0); j++; + XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j); + + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNfromHoriz, dialog); j++; + XtSetArg(args[j], XtNwidth, 100); j++; + XtSetArg(args[j], XtNmenuName, XtNewString(cps->option[i].name)); j++; + XtSetArg(args[j], XtNlabel, ((char**)cps->option[i].textValue)[cps->option[i].value]); j++; + cps->option[i].handle = (void*) + (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j)); + CreateComboPopup(last, cps->option[i].name, i, (char **) cps->option[i].textValue); + values[i] = cps->option[i].value; + break; + } + } + + j=0; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNbottom, XtChainBottom); j++; + XtSetArg(args[j], XtNtop, XtChainBottom); j++; + XtSetArg(args[j], XtNleft, XtChainLeft); j++; + XtSetArg(args[j], XtNright, XtChainLeft); j++; + b_ok = XtCreateManagedWidget("OK", commandWidgetClass, form, args, j); + XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0); + + XtSetArg(args[j], XtNfromHoriz, b_ok); j++; + b_cancel = XtCreateManagedWidget("cancel", commandWidgetClass, form, args, j); + XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "SettingsPopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + SettingsUp = True; + + previous = NULL; + SetFocus(edit, popup, (XEvent*) NULL, False); +} + +void FirstSettingsProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + SettingsPopUp(&first); +} + +void SecondSettingsProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + SettingsPopUp(&second); +} + +//--------------------------- General Popup for Cloning ---------------------------------- +#if 0 +int XXXUp; +Widget XXXShell; + +void XXXPopDown() +{ + if (!XXXUp) return; + XtPopdown(XXXShell); + XtDestroyWidget(XXXShell); + XXXUp = False; + ModeHighlight(); +} + +void XXXCallback(w, client_data, call_data) + Widget w; + XtPointer client_data, call_data; +{ + String name; + Widget w2; + Arg args[16]; + char buf[80]; + + XtSetArg(args[0], XtNlabel, &name); + XtGetValues(w, args, 1); + + if (strcmp(name, "cancel") == 0) { + XXXPopDown(); + return; + } + if (strcmp(name, "ok") == 0) { + int nr; String name; + name = XawDialogGetValueString(w2 = XtParent(w)); + if(sscanf(name ,"%d",&nr) != 1) { + sprintf(buf, "%d", appData.defaultFrcPosition); + XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value + XtSetValues(w2, args, 1); + return; + } + XXXPopDown(); + return; + } +} + +void XXXPopUp() +{ + Arg args[16]; + Widget popup, layout, dialog, edit; + Window root, child; + int x, y, i; + int win_x, win_y; + unsigned int mask; + char def[80]; + + i = 0; + XtSetArg(args[i], XtNresizable, True); i++; + XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; + XXXShell = popup = + XtCreatePopupShell("XXX Menu", transientShellWidgetClass, + shellWidget, args, i); + + layout = + XtCreateManagedWidget(layoutName, formWidgetClass, popup, + layoutArgs, XtNumber(layoutArgs)); + + sprintf(def, "%d\n", appData.defaultFrcPosition); + i = 0; + XtSetArg(args[i], XtNlabel, ""); i++; + XtSetArg(args[i], XtNvalue, def); i++; + XtSetArg(args[i], XtNborderWidth, 0); i++; + dialog = XtCreateManagedWidget("XXX", dialogWidgetClass, + layout, args, i); + + XawDialogAddButton(dialog, "ok", XXXCallback, (XtPointer) dialog); + XawDialogAddButton(dialog, "cancel", XXXCallback, (XtPointer) dialog); + + XtRealizeWidget(popup); + CatchDeleteWindow(popup, "XXXPopDown"); + + XQueryPointer(xDisplay, xBoardWindow, &root, &child, + &x, &y, &win_x, &win_y, &mask); + + XtSetArg(args[0], XtNx, x - 10); + XtSetArg(args[1], XtNy, y - 30); + XtSetValues(popup, args, 2); + + XtPopup(popup, XtGrabExclusive); + XXXUp = True; + + edit = XtNameToWidget(dialog, "*value"); + + previous = NULL; + SetFocus(engThreshold, popup, (XEvent*) NULL, False); +} + +void XXXMenuProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + XXXPopUp(); +} +#endif + diff --git a/zippy.c b/zippy.c index f75ecb2..c77276f 100644 --- a/zippy.c +++ b/zippy.c @@ -88,6 +88,8 @@ extern char *getenv(); #include "backend.h" #include "backendz.h" +char *SendMoveToBookUser P((int nr, ChessProgramState *cps, int initial)); // [HGM] book + static char zippyPartner[MSG_SIZ]; static char zippyLastOpp[MSG_SIZ]; static int zippyConsecGames; @@ -964,7 +966,8 @@ void ZippyFirstBoard(moveNum, basetime, increment) char buf[MSG_SIZ]; int w, b; char *opp = (gameMode==IcsPlayingWhite ? gameInfo.black : gameInfo.white); - Boolean sentPos = FALSE; + Boolean sentPos = FALSE; + char *bookHit = NULL; // [HGM] book if (!first.initDone) { /* Game is starting prematurely. We can't deal with this */ @@ -1035,7 +1038,7 @@ void ZippyFirstBoard(moveNum, basetime, increment) SendTimeRemaining(&first, TRUE); } } - SendToProgram("go\n", &first); + bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move } else { /* Engine's opponent is on move now */ if (first.usePlayother) { @@ -1061,7 +1064,8 @@ void ZippyFirstBoard(moveNum, basetime, increment) SendTimeRemaining(&first, TRUE); } } - SendToProgram("go\n", &first); +// SendToProgram("go\n", &first); + bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move } } } else if (gameMode == IcsPlayingBlack) { @@ -1085,7 +1089,8 @@ void ZippyFirstBoard(moveNum, basetime, increment) SendTimeRemaining(&first, FALSE); } } - SendToProgram("go\n", &first); +// SendToProgram("go\n", &first); + bookHit = SendMoveToBookUser(forwardMostMove-1, &first, TRUE); // [HGM] book: send go or retrieve book move } else { /* Engine's opponent is on move now */ if (first.usePlayother) { @@ -1103,6 +1108,18 @@ void ZippyFirstBoard(moveNum, basetime, increment) /* Nothing needs to be done here */ } } + + if(bookHit) { // [HGM] book: simulate book reply + static char bookMove[MSG_SIZ]; // a bit generous? + + programStats.depth = programStats.nodes = programStats.time = + programStats.score = programStats.got_only_move = 0; + sprintf(programStats.movelist, "%s (xbook)", bookHit); + + strcpy(bookMove, "move "); + strcat(bookMove, bookHit); + HandleMachineMove(bookMove, &first); + } }