From: Arun Persaud Date: Wed, 14 Oct 2009 05:52:22 +0000 (-0700) Subject: moved several game/position opening/saving functions to gtk X-Git-Tag: gtk-20091122~11 X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=ceea9af6f6673bc83700a080d860fa68a4c29b41 moved several game/position opening/saving functions to gtk still need to add several features, seee FileNamePopUp for a todo list --- diff --git a/callback.c b/callback.c index eb9b4da..652db01 100644 --- a/callback.c +++ b/callback.c @@ -29,6 +29,11 @@ extern int toX; extern int toY; extern int squareSize,lineGap; +extern int LoadGamePopUp P((FILE *f, int gameNumber, char *title)); +extern int LoadPosition P((FILE *f, int gameNumber, char *title)); +extern int SaveGame P((FILE *f, int gameNumber, char *title)); +extern int SavePosition P((FILE *f, int gameNumber, char *title)); + gboolean ExposeProc(object, user_data) GtkObject *object; @@ -39,20 +44,20 @@ ExposeProc(object, user_data) int totalh=0,nw,nh; float ratio; int boardWidth,boardHeight,old,new; - + nw=GTK_WIDGET(object)->allocation.width; nh=GTK_WIDGET(object)->allocation.height; - + old=squareSize; squareSize = nw/(BOARD_WIDTH*1.05+0.05); if(old!=squareSize) { lineGap = squareSize*0.05; - + boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); - + /* get the height of the menus, etc. and calculate the aspect ratio */ gtk_widget_size_request(GTK_WIDGET(GUI_Menubar), &w); totalh += w.height; @@ -60,17 +65,17 @@ ExposeProc(object, user_data) totalh += w.height; gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar), &w); totalh += w.height; - + ratio = ((float)totalh+boardHeight)/((float)boardWidth) ; - + gtk_widget_set_size_request(GTK_WIDGET(GUI_Board), boardWidth,boardHeight); - + gtk_aspect_frame_set (GTK_ASPECT_FRAME(GUI_Aspect),0,0,ratio,TRUE); /* recreate pieces with new size... TODO: keep svg in memory and just recreate pixmap instead of reloading files */ CreatePieces(); - } + } return FALSE; /* return false, so that other expose events are called too */ } @@ -182,7 +187,8 @@ void IcsClientProc(object, user_data) * File menu */ -void LoadNextGameProc(object, user_data) +void +LoadNextGameProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -190,7 +196,8 @@ void LoadNextGameProc(object, user_data) return; } -void LoadPrevGameProc(object, user_data) +void +LoadPrevGameProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -198,7 +205,8 @@ void LoadPrevGameProc(object, user_data) return; } -void ReloadGameProc(object, user_data) +void +ReloadGameProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -206,8 +214,8 @@ void ReloadGameProc(object, user_data) return; } - -void LoadNextPositionProc(object, user_data) +void +LoadNextPositionProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -215,7 +223,8 @@ void LoadNextPositionProc(object, user_data) return; } -void LoadPrevPositionProc(object, user_data) +void +LoadPrevPositionProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -223,7 +232,8 @@ void LoadPrevPositionProc(object, user_data) return; } -void ReloadPositionProc(object, user_data) +void +ReloadPositionProc(object, user_data) GtkObject *object; gpointer user_data; { @@ -231,6 +241,65 @@ void ReloadPositionProc(object, user_data) return; } +void +LoadPositionProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) + { + Reset(FALSE, TRUE); + }; + + FileNamePopUp(_("Load position file name?"), "", LoadPosition, "rb"); + return; +} + +void +SaveGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + FileNamePopUp(_("Save game file name?"), + DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"), + SaveGame, "a"); + return; +} + +void +SavePositionProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + FileNamePopUp(_("Save position file name?"), + DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"), + SavePosition, "a"); + return; +} + +void +AnalyzeFileProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + if (!first.analysisSupport) + { + char buf[MSG_SIZ]; + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + }; + Reset(FALSE, TRUE); + + if (!appData.showThinking) + ShowThinkingProc(NULL,NULL); + + AnalyzeFileEvent(); + FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb"); + AnalysisPeriodicEvent(1); + return; +} + /* End File Menu */ @@ -455,7 +524,7 @@ void ShowThinkingProc(object, user_data) GtkObject *object; gpointer user_data; { - appData.showThinking = !appData.showThinking; + appData.showThinking = !appData.showThinking; ShowThinkingEvent(); return; @@ -550,37 +619,7 @@ void LoadGameProc(object, user_data) GtkObject *object; gpointer user_data; { - GtkWidget *dialog; - dialog = gtk_file_chooser_dialog_new (_("Load game file name?"), - GTK_WINDOW(GUI_Window), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) - { - char *filename; - FILE *f; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - //see loadgamepopup - f = fopen(filename, "rb"); - if (f == NULL) - { - DisplayError(_("Failed to open file"), errno); - } - else - { - /* TODO add indec */ - (void) LoadGamePopUp(f, 0, filename); - } - g_free (filename); - }; - - gtk_widget_destroy (dialog); - ModeHighlight(); - + FileNamePopUp(_("Load game file name?"),"",LoadGamePopUp,"rb"); return; } @@ -798,14 +837,14 @@ void GetMoveListProc(object, user_data) gpointer user_data; { appData.getMoveList = !appData.getMoveList; - - if (appData.getMoveList) + + if (appData.getMoveList) { GetMoveListEvent(); - } + } // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1 // gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList ); - + return; } diff --git a/callback.h b/callback.h index 38ef708..4862238 100644 --- a/callback.h +++ b/callback.h @@ -28,6 +28,9 @@ void ReloadGameProc P((GtkObject *object, gpointer user_data)); void LoadNextPositionProc P((GtkObject *object, gpointer user_data)); void LoadPrevPositionProc P((GtkObject *object, gpointer user_data)); void ReloadPositionProc P((GtkObject *object, gpointer user_data)); +void LoadPositionProc P((GtkObject *object, gpointer user_data)); +void SaveGameProc P((GtkObject *object, gpointer user_data)); +void SavePositionProc P((GtkObject *object, gpointer user_data)); /* Step Menu */ void BackwardProc P((GtkObject *object, gpointer user_data)); diff --git a/gtk-interface.xml b/gtk-interface.xml index f060108..3e1a345 100644 --- a/gtk-interface.xml +++ b/gtk-interface.xml @@ -181,10 +181,12 @@ - - True + Save Game - True + True + image2 + False + @@ -244,6 +246,7 @@ True Save Position True + @@ -356,6 +359,7 @@ True True menuMode.Machine White + @@ -1070,4 +1074,9 @@ 0.40000000596046448 gtk-open + + True + gtk-save + 1 + diff --git a/interface.c b/interface.c index ef59a5f..e1a2069 100644 --- a/interface.c +++ b/interface.c @@ -31,6 +31,7 @@ # define N_(s) s #endif +extern GtkWidget *GUI_Window; GdkPixbuf *load_pixbuf(char *filename,int size) @@ -49,3 +50,53 @@ GdkPixbuf *load_pixbuf(char *filename,int size) } return image; } + +void +FileNamePopUp(label, def, proc, openMode) + char *label; + char *def; + FileProc proc; + char *openMode; +{ + /* TODO: + * implement look for certain file types + * use save/load button depending on what function is calling + */ + + GtkWidget *dialog; + + dialog = gtk_file_chooser_dialog_new (label, + GTK_WINDOW(GUI_Window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + FILE *f; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + //see loadgamepopup + f = fopen(filename, openMode); + if (f == NULL) + { + DisplayError(_("Failed to open file"), errno); + } + else + { + printf( "DEBUG: before call\n"); + /* TODO add indec */ + (*proc)(f, 0, filename); + printf( "DEBUG: after call\n"); + } + g_free (filename); + }; + + gtk_widget_destroy (dialog); + ModeHighlight(); + + return; + +} diff --git a/interface.h b/interface.h index 10f975b..faaa1ba 100644 --- a/interface.h +++ b/interface.h @@ -30,4 +30,6 @@ GdkPixbuf *SVGNeutralSquare=NULL; GdkCursor *BoardCursor=NULL; -GdkPixbuf *load_pixbuf(char *filename,int size); +GdkPixbuf *load_pixbuf P((char *filename,int size)); +void FileNamePopUp P((char *label, char *def, + FileProc proc, char *openMode)); diff --git a/xboard.c b/xboard.c index d0345f1..77e58ae 100644 --- a/xboard.c +++ b/xboard.c @@ -269,13 +269,6 @@ void CommentCallback P((Widget w, XtPointer client_data, XtPointer call_data)); void ICSInputBoxPopUp P((void)); void ICSInputBoxPopDown P((void)); -void FileNamePopUp P((char *label, char *def, - FileProc proc, char *openMode)); -void FileNamePopDown P((void)); -void FileNameCallback P((Widget w, XtPointer client_data, - XtPointer call_data)); -void FileNameAction P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void AskQuestionReplyAction P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AskQuestionProc P((Widget w, XEvent *event, @@ -289,24 +282,17 @@ void EditCommentPopDown P((void)); void EditCommentCallback P((Widget w, XtPointer client_data, XtPointer call_data)); void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data)); -void LoadPositionProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void CopyPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void PastePositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void CopyGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void PasteGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void SaveGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void SavePositionProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void MailMoveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ReloadCmailMsgProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AnalyzeModeProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void AnalyzeFileProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); void EditGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void EditPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); @@ -637,24 +623,24 @@ Enables userThinkingEnables[] = { MenuItem fileMenu[] = { {N_("New Shuffle Game ..."), ShuffleMenuProc}, {N_("New Variant ..."), NewVariantProc}, // [HGM] variant: not functional yet - {"----", NothingProc}, - {N_("Save Game"), SaveGameProc}, - {"----", NothingProc}, + // {"----", NothingProc}, + // {N_("Save Game"), SaveGameProc}, + // {"----", NothingProc}, {N_("Copy Game"), CopyGameProc}, {N_("Paste Game"), PasteGameProc}, - {"----", NothingProc}, - {N_("Load Position"), LoadPositionProc}, + // {"----", NothingProc}, + // {N_("Load Position"), LoadPositionProc}, // {N_("Load Next Position"), LoadNextPositionProc}, // {N_("Load Previous Position"), LoadPrevPositionProc}, // {N_("Reload Same Position"), ReloadPositionProc}, - {N_("Save Position"), SavePositionProc}, - {"----", NothingProc}, + // {N_("Save Position"), SavePositionProc}, + // {"----", NothingProc}, {N_("Copy Position"), CopyPositionProc}, {N_("Paste Position"), PastePositionProc}, - {"----", NothingProc}, + // {"----", NothingProc}, {N_("Mail Move"), MailMoveProc}, {N_("Reload CMail Message"), ReloadCmailMsgProc}, - {"----", NothingProc}, + // {"----", NothingProc}, {NULL, NULL} }; @@ -663,7 +649,7 @@ MenuItem modeMenu[] = { // {N_("Machine Black"), MachineBlackProc}, // {N_("Two Machines"), TwoMachinesProc}, {N_("Analysis Mode"), AnalyzeModeProc}, - {N_("Analyze File"), AnalyzeFileProc }, + // {N_("Analyze File"), AnalyzeFileProc }, // {N_("ICS Client"), IcsClientProc}, {N_("Edit Game"), EditGameProc}, {N_("Edit Position"), EditPositionProc}, @@ -1785,7 +1771,7 @@ XrmOptionDescRec shellOptions[] = { XtActionsRec boardActions[] = { { "HandleUserMove", HandleUserMove }, { "AnimateUserMove", AnimateUserMove }, - { "FileNameAction", FileNameAction }, + // { "FileNameAction", FileNameAction }, { "AskQuestionProc", AskQuestionProc }, { "AskQuestionReplyAction", AskQuestionReplyAction }, { "PieceMenuPopup", PieceMenuPopup }, @@ -1793,7 +1779,7 @@ XtActionsRec boardActions[] = { // { "BlackClock", BlackClock }, { "Iconify", Iconify }, { "LoadSelectedProc", LoadSelectedProc }, - { "LoadPositionProc", LoadPositionProc }, + // { "LoadPositionProc", LoadPositionProc }, // { "LoadNextPositionProc", LoadNextPositionProc }, // { "LoadPrevPositionProc", LoadPrevPositionProc }, // { "ReloadPositionProc", ReloadPositionProc }, @@ -1801,14 +1787,14 @@ XtActionsRec boardActions[] = { { "PastePositionProc", PastePositionProc }, { "CopyGameProc", CopyGameProc }, { "PasteGameProc", PasteGameProc }, - { "SaveGameProc", SaveGameProc }, - { "SavePositionProc", SavePositionProc }, + // { "SaveGameProc", SaveGameProc }, + // { "SavePositionProc", SavePositionProc }, { "MailMoveProc", MailMoveProc }, { "ReloadCmailMsgProc", ReloadCmailMsgProc }, // { "MachineWhiteProc", MachineWhiteProc }, // { "MachineBlackProc", MachineBlackProc }, { "AnalysisModeProc", AnalyzeModeProc }, - { "AnalyzeFileProc", AnalyzeFileProc }, + // { "AnalyzeFileProc", AnalyzeFileProc }, // { "TwoMachinesProc", TwoMachinesProc }, // { "IcsClientProc", IcsClientProc }, { "EditGameProc", EditGameProc }, @@ -1884,7 +1870,7 @@ XtActionsRec boardActions[] = { { "ErrorPopDown", (XtActionProc) ErrorPopDown }, { "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, - { "FileNamePopDown", (XtActionProc) FileNamePopDown }, + // { "FileNamePopDown", (XtActionProc) FileNamePopDown }, { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown }, { "GameListPopDown", (XtActionProc) GameListPopDown }, { "PromotionPopDown", (XtActionProc) PromotionPopDown }, @@ -1903,7 +1889,7 @@ char ICSInputTranslations[] = "Return: EnterKeyProc() \n"; String xboardResources[] = { - "*fileName*value.translations: #override\\n Return: FileNameAction()", + // "*fileName*value.translations: #override\\n Return: FileNameAction()", "*question*value.translations: #override\\n Return: AskQuestionReplyAction()", "*errorpopup*translations: #override\\n Return: ErrorPopDown()", NULL @@ -4666,138 +4652,6 @@ void CommentPopDown() commentUp = False; } -void FileNamePopUp(label, def, proc, openMode) - char *label; - char *def; - FileProc proc; - char *openMode; -{ - Arg args[16]; - Widget popup, layout, dialog, edit; - Window root, child; - int x, y, i; - int win_x, win_y; - unsigned int mask; - - fileProc = proc; /* I can't see a way not */ - fileOpenMode = openMode; /* to use globals here */ - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - XtSetArg(args[i], XtNtitle, XtNewString(_("File name prompt"))); i++; - fileNameShell = popup = - XtCreatePopupShell("File name prompt", transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, label); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("fileName", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), FileNameCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("cancel"), FileNameCallback, - (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "FileNamePopDown"); - - 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); - filenameUp = True; - - edit = XtNameToWidget(dialog, "*value"); - XtSetKeyboardFocus(popup, edit); -} - -void FileNamePopDown() -{ - if (!filenameUp) return; - XtPopdown(fileNameShell); - XtDestroyWidget(fileNameShell); - filenameUp = False; - ModeHighlight(); -} - -void FileNameCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Arg args[16]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - FileNamePopDown(); - return; - } - - FileNameAction(w, NULL, NULL, NULL); -} - -void FileNameAction(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - char buf[MSG_SIZ]; - String name; - FILE *f; - char *p, *fullname; - int index; - - name = XawDialogGetValueString(w = XtParent(w)); - - if ((name != NULL) && (*name != NULLCHAR)) { - strcpy(buf, name); - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - - p = strrchr(buf, ' '); - if (p == NULL) { - index = 0; - } else { - *p++ = NULLCHAR; - index = atoi(p); - } - fullname = ExpandPathName(buf); - if (!fullname) { - ErrorPopUp(_("Error"), _("Can't open file"), FALSE); - } - else { - f = fopen(fullname, fileOpenMode); - if (f == NULL) { - DisplayError(_("Failed to open file"), errno); - } else { - (void) (*fileProc)(f, index, buf); - } - } - ModeHighlight(); - return; - } - - XtPopdown(w = XtParent(XtParent(w))); - XtDestroyWidget(w); - filenameUp = False; - ModeHighlight(); -} - void PromotionPopUp() { Arg args[16]; @@ -5095,7 +4949,8 @@ int LoadGamePopUp(f, gameNumber, title) else if (!ListEmpty(&gameList) && ((ListGame *) gameList.tailPred)->number > 1) { - GameListPopUp(f, title); + // TODO convert to GTK + // GameListPopUp(f, title); return TRUE; }; @@ -5106,40 +4961,6 @@ int LoadGamePopUp(f, gameNumber, title) return LoadGame(f, gameNumber, title, FALSE); } -void LoadPositionProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { - Reset(FALSE, TRUE); - } - FileNamePopUp(_("Load position file name?"), "", LoadPosition, "rb"); -} - -void SaveGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - FileNamePopUp(_("Save game file name?"), - DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"), - SaveGame, "a"); -} - -void SavePositionProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - FileNamePopUp(_("Save position file name?"), - DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"), - SavePosition, "a"); -} - void ReloadCmailMsgProc(w, event, prms, nprms) Widget w; XEvent *event; @@ -5339,7 +5160,8 @@ void PasteGameProc(w, event, prms, nprms) void AutoSaveGame() { - SaveGameProc(NULL, NULL, NULL, NULL); + SaveGameProc(NULL, NULL); + return; } void AnalyzeModeProc(w, event, prms, nprms) @@ -5385,29 +5207,6 @@ void AnalyzeModeProc(w, event, prms, nprms) AnalyzeModeEvent(); } -void AnalyzeFileProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - if (!first.analysisSupport) { - char buf[MSG_SIZ]; - snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - return; - } - Reset(FALSE, TRUE); - - if (!appData.showThinking) - ShowThinkingProc(NULL,NULL); - - AnalyzeFileEvent(); - FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb"); - AnalysisPeriodicEvent(1); -} - - void EditGameProc(w, event, prms, nprms) Widget w; XEvent *event;