2 * callback.c -- gtk-interface
4 * Copyright 2009, 2010 Free Software Foundation, Inc.
6 * GNU XBoard is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or (at
9 * your option) any later version.
11 * GNU XBoard is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see http://www.gnu.org/licenses/. *
19 *------------------------------------------------------------------------
20 ** See the file ChangeLog for a revision history. */
29 # define _(s) gettext (s)
30 # define N_(s) gettext_noop (s)
36 extern GtkWidget *about;
37 extern GtkWidget *GUI_Window;
38 extern GtkWidget *GUI_Aspect;
39 extern GtkWidget *GUI_Menubar;
40 extern GtkWidget *GUI_Timer;
41 extern GtkWidget *GUI_Buttonbar;
42 extern GtkWidget *GUI_Board;
44 extern char *programVersion;
45 extern int errorExitStatus;
46 extern int promotionUp;
51 extern int squareSize,lineGap;
53 extern int LoadGamePopUp P((FILE *f, int gameNumber, char *title));
54 extern int LoadPosition P((FILE *f, int gameNumber, char *title));
55 extern int SaveGame P((FILE *f, int gameNumber, char *title));
56 extern int SavePosition P((FILE *f, int gameNumber, char *title));
59 ExposeProc(object, user_data)
63 /* do resizing to a fixed aspect ratio */
67 int boardWidth,boardHeight,old,new;
69 nw=GTK_WIDGET(object)->allocation.width;
70 nh=GTK_WIDGET(object)->allocation.height;
73 squareSize = nw/(BOARD_WIDTH*1.05+0.05);
77 lineGap = squareSize*0.05;
79 boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
80 boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
82 /* get the height of the menus, etc. and calculate the aspect ratio */
83 gtk_widget_size_request(GTK_WIDGET(GUI_Menubar), &w);
85 gtk_widget_size_request(GTK_WIDGET(GUI_Timer), &w);
87 gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar), &w);
90 ratio = ((float)totalh+boardHeight)/((float)boardWidth) ;
92 gtk_widget_set_size_request(GTK_WIDGET(GUI_Board),
93 boardWidth,boardHeight);
95 gtk_aspect_frame_set (GTK_ASPECT_FRAME(GUI_Aspect),0,0,ratio,TRUE);
97 /* recreate pieces with new size... TODO: keep svg in memory and just recreate pixmap instead of reloading files */
100 return FALSE; /* return false, so that other expose events are called too */
104 QuitProc (object, user_data)
113 void InfoProc(object, user_data)
118 snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
124 void ManProc(object, user_data)
129 snprintf(buf, sizeof(buf), "xterm -e man xboard &");
134 void HintProc(object, user_data)
142 void BookProc(object, user_data)
150 void AboutProc (object, user_data)
156 const gchar *authors[] = {"Tim Mann <tim@tim-mann.org>",
158 "Evan Welsh <Evan.Welsh@msdw.com>",
159 "Elmar Bartel <bartel@informatik.tu-muenchen.de>",
162 "Hugh Fisher <Hugh.Fisher@cs.anu.edu.au>",
163 "Allessandro Scotti",
164 "H.G. Muller <h.g.muller AT hccnet DOT nl>",
165 "Eric Mullins <emwine AT earthlink DOT net>",
166 "Arun Persaud <arun@nubati.net>"};
168 /* set up about window */
169 about = GTK_WIDGET(gtk_about_dialog_new());
171 /* fill in some information */
174 char *zippy = " (with Zippy code)";
178 sprintf(buf, "%s%s", programVersion, zippy);
180 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about),buf);
182 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about),
183 "Copyright 1991 Digital Equipment Corporation\n"
184 "Enhancements Copyright 1992-2009 Free Software Foundation\n"
185 "Enhancements Copyright 2005 Alessandro Scotti");
186 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about),"http://www.gnu.org/software/xboard/");
187 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about),authors);
188 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about),
189 " A. Alper (turkish)\n"
190 " A. Persaud (german)\n");
192 /* end set up about window */
193 gtk_dialog_run(GTK_DIALOG (about));
194 gtk_widget_destroy(about);
201 void MachineWhiteProc(object, user_data)
209 void MachineBlackProc(object, user_data)
217 void TwoMachinesProc(object, user_data)
225 void IcsClientProc(object, user_data)
234 AnalyzeFileProc(object, user_data)
238 if (!first.analysisSupport)
241 snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
242 DisplayError(buf, 0);
247 if (!appData.showThinking)
248 ShowThinkingProc(NULL,NULL);
251 FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb");
252 AnalysisPeriodicEvent(1);
257 AnalyzeModeProc(object, user_data)
263 if (!first.analysisSupport)
265 snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
266 DisplayError(buf, 0);
269 /* [DM] icsEngineAnalyze [HGM] This is horrible code; reverse the gameMode and isEngineAnalyze tests! */
270 if (appData.icsActive)
272 if (gameMode != IcsObserving)
274 sprintf(buf,_("You are not observing a game"));
275 DisplayError(buf, 0);
277 if (appData.icsEngineAnalyze)
279 if (appData.debugMode)
280 fprintf(debugFP, _("Found unexpected active ICS engine analyze \n"));
286 /* if enable, use want disable icsEngineAnalyze */
287 if (appData.icsEngineAnalyze)
293 appData.icsEngineAnalyze = TRUE;
294 if (appData.debugMode)
295 fprintf(debugFP, _("ICS engine analyze starting... \n"));
297 if (!appData.showThinking)
298 ShowThinkingProc(NULL,NULL);
305 EditGameProc(object, user_data)
314 EditPositionProc(object, user_data)
323 TrainingProc(object, user_data)
340 LoadNextGameProc(object, user_data)
349 LoadPrevGameProc(object, user_data)
358 ReloadGameProc(object, user_data)
367 LoadNextPositionProc(object, user_data)
376 LoadPrevPositionProc(object, user_data)
385 ReloadPositionProc(object, user_data)
394 LoadPositionProc(object, user_data)
398 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile)
403 FileNamePopUp(_("Load position file name?"), "", LoadPosition, "rb");
408 SaveGameProc(object, user_data)
412 FileNamePopUp(_("Save game file name?"),
413 DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
419 SavePositionProc(object, user_data)
423 FileNamePopUp(_("Save position file name?"),
424 DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
432 void AcceptProc(object, user_data)
440 void DeclineProc(object, user_data)
448 void RematchProc(object, user_data)
456 void CallFlagProc(object, user_data)
464 void DrawProc(object, user_data)
472 void AbortProc(object, user_data)
480 void AdjournProc(object, user_data)
488 void ResignProc(object, user_data)
496 void StopObservingProc(object, user_data)
500 StopObservingEvent();
504 void StopExaminingProc(object, user_data)
508 StopExaminingEvent();
512 void AdjuWhiteProc(object, user_data)
516 UserAdjudicationEvent(+1);
520 void AdjuBlackProc(object, user_data)
524 UserAdjudicationEvent(-1);
528 void AdjuDrawProc(object, user_data)
532 UserAdjudicationEvent(0);
536 void BackwardProc(object, user_data)
544 void ForwardProc(object, user_data)
552 void ToStartProc(object, user_data)
560 void ToEndProc(object, user_data)
568 void RevertProc(object, user_data)
576 void TruncateGameProc(object, user_data)
584 void MoveNowProc(object, user_data)
592 void RetractMoveProc(object, user_data)
602 AutocommProc(object, user_data)
606 appData.autoComment = !appData.autoComment;
611 AutoflagProc(object, user_data)
615 appData.autoCallFlag = !appData.autoCallFlag;
620 AutoflipProc(object, user_data)
624 appData.autoFlipView = !appData.autoFlipView;
629 ShowThinkingProc(object, user_data)
633 appData.showThinking = !appData.showThinking;
640 HideThinkingProc(object, user_data)
644 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman;
651 FlipViewProc(object, user_data)
655 flipView = !flipView;
656 DrawPosition(True, NULL);
661 AlwaysQueenProc(object, user_data)
665 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
670 AnimateDraggingProc(object, user_data)
674 appData.animateDragging = !appData.animateDragging;
676 if (appData.animateDragging)
678 // TODO convert to gtk
686 AnimateMovingProc(object, user_data)
690 appData.animate = !appData.animate;
694 // TODO convert to gtk
702 AutobsProc(object, user_data)
706 appData.autoObserve = !appData.autoObserve;
711 AutoraiseProc(object, user_data)
715 appData.autoRaiseBoard = !appData.autoRaiseBoard;
720 AutosaveProc(object, user_data)
724 appData.autoSaveGames = !appData.autoSaveGames;
729 BlindfoldProc(object, user_data)
733 appData.blindfold = !appData.blindfold;
734 DrawPosition(True, NULL);
739 TestLegalityProc(object, user_data)
743 appData.testLegality = !appData.testLegality;
748 FlashMovesProc(object, user_data)
752 if (appData.flashCount == 0)
754 appData.flashCount = 3;
758 appData.flashCount = -appData.flashCount;
761 // TODO: check if this is working correct*/
767 HighlightDraggingProc(object, user_data)
771 /* TODO: connect to option menu */
772 appData.highlightDragging = !appData.highlightDragging;
778 HighlightLastMoveProc(object, user_data)
782 appData.highlightLastMove = !appData.highlightLastMove;
787 IcsAlarmProc(object, user_data)
791 appData.icsAlarm = !appData.icsAlarm;
796 MoveSoundProc(object, user_data)
800 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
805 OldSaveStyleProc(object, user_data)
809 appData.oldSaveStyle = !appData.oldSaveStyle;
814 PeriodicUpdatesProc(object, user_data)
818 PeriodicUpdatesEvent(!appData.periodicUpdates);
823 PremoveProc(object, user_data)
827 appData.premove = !appData.premove;
832 QuietPlayProc(object, user_data)
836 appData.quietPlay = !appData.quietPlay;
842 PonderNextMoveProc(object, user_data)
846 PonderNextMoveEvent(!appData.ponderNextMove);
851 PopupExitMessageProc(object, user_data)
855 appData.popupExitMessage = !appData.popupExitMessage;
860 PopupMoveErrorsProc(object, user_data)
864 appData.popupMoveErrors = !appData.popupMoveErrors;
870 /* end option menu */
872 gboolean CloseWindowProc(GtkWidget *button)
874 gtk_widget_destroy(gtk_widget_get_toplevel(button));
879 ResetProc (object, user_data)
887 void WhiteClockProc(object, user_data)
891 if (gameMode == EditPosition || gameMode == IcsExamining) {
892 SetWhiteToPlayEvent();
893 } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) {
898 void BlackClockProc(object, user_data)
902 if (gameMode == EditPosition || gameMode == IcsExamining) {
903 SetBlackToPlayEvent();
904 } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) {
910 void ShowCoordsProc(object, user_data)
914 appData.showCoords = !appData.showCoords;
916 DrawPosition(True, NULL);
919 void ErrorPopDownProc(object, user_data)
923 gtk_widget_destroy(GTK_WIDGET(object));
927 void PauseProc(object, user_data)
931 // todo this toggling of the pause button doesn't seem to work?
932 // e.g. select pause from buttonbar doesn't activate menumode.pause
937 void LoadGameProc(object, user_data)
941 FileNamePopUp(_("Load game file name?"),"",LoadGamePopUp,"rb");
950 void EventProc(window, event, data)
955 /* todo do we still need this?
956 if (!XtIsRealized(widget))
960 switch (event->type) {
962 if (event->expose.count > 0) return; /* no clipping is done */
963 DrawPosition(True, NULL);
972 * event handler for parsing user moves
974 void UserMoveProc(window, event, data)
979 if (errorExitStatus != -1) return;
983 if (event->type == GDK_BUTTON_PRESS)
995 // [HGM] mouse: the rest of the mouse handler is moved to the backend, and called here
996 if(event->type == GDK_BUTTON_PRESS) LeftClick(Press, (int)event->button.x, (int)event->button.y);
997 if(event->type == GDK_BUTTON_RELEASE) LeftClick(Release, (int)event->button.x, (int)event->button.y);
1002 void GetMoveListProc(object, user_data)
1006 appData.getMoveList = !appData.getMoveList;
1008 if (appData.getMoveList)
1013 // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
1014 // gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );