From bdb4175a5cbca3f506502f644ab1f027f8e636f2 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 15 Oct 2012 19:52:17 +0200 Subject: [PATCH] Implement menu checkmarking and enabling odes in the (later over-written) handle field specify which items are to be checkmarked, and by what style button. --- dialogs.h | 3 --- menus.c | 46 +++++++++++++++++++++++----------------------- menus.h | 3 +++ xboard.c | 4 +--- xoptions.c | 45 +++++++-------------------------------------- 5 files changed, 34 insertions(+), 67 deletions(-) diff --git a/dialogs.h b/dialogs.h index 739dc18..5b21b9f 100644 --- a/dialogs.h +++ b/dialogs.h @@ -95,9 +95,6 @@ #define W_MENUB 26 #define W_DROP 27 // drop (popup) menu -#define CHECK (void *) 1 -#define RADIO (void *) 2 - typedef enum { // identifier of dialogs done by GenericPopup TransientDlg=0, // transient: grabs mouse events and is destroyed at pop-down (so other dialog can use this ID next time) CommentDlg, TagsDlg, TextMenuDlg, InputBoxDlg, ChatDlg, DummyDlg, HistoryDlg, // persistent: no grab and reused diff --git a/menus.c b/menus.c index c0c0687..1d0e23d 100644 --- a/menus.c +++ b/menus.c @@ -577,7 +577,7 @@ MenuItem fileMenu[] = { {N_("New Shuffle Game ..."), "NewShuffleGame", ShuffleMenuProc}, {N_("New Variant ... Alt+Shift+V"), "NewVariant", NewVariantProc}, // [HGM] variant: not functional yet {"----", NULL, NothingProc}, - {N_("Load Game Ctrl+O"), "LoadGame", LoadGameProc}, + {N_("Load Game Ctrl+O"), "LoadGame", LoadGameProc, CHECK}, {N_("Load Position Ctrl+Shift+O"), "LoadPosition", LoadPositionProc}, // {N_("Load Next Game"), "LoadNextGame", LoadNextGameProc}, // {N_("Load Previous Game"), "LoadPreviousGame", LoadPrevGameProc}, @@ -622,18 +622,18 @@ MenuItem editMenu[] = { }; MenuItem viewMenu[] = { - {N_("Flip View F2"), "FlipView", FlipViewProc}, + {N_("Flip View F2"), "FlipView", FlipViewProc, CHECK}, {"----", NULL, NothingProc}, - {N_("Engine Output Alt+Shift+O"), "EngineOutput", EngineOutputProc}, - {N_("Move History Alt+Shift+H"), "MoveHistory", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code - {N_("Evaluation Graph Alt+Shift+E"), "EvaluationGraph", EvalGraphProc}, - {N_("Game List Alt+Shift+G"), "GameList", ShowGameListProc}, - {N_("ICS text menu"), "ICStextmenu", IcsTextProc}, + {N_("Engine Output Alt+Shift+O"), "EngineOutput", EngineOutputProc, CHECK}, + {N_("Move History Alt+Shift+H"), "MoveHistory", HistoryShowProc, CHECK}, // [HGM] hist: activate 4.2.7 code + {N_("Evaluation Graph Alt+Shift+E"), "EvaluationGraph", EvalGraphProc, CHECK}, + {N_("Game List Alt+Shift+G"), "GameList", ShowGameListProc, CHECK}, + {N_("ICS text menu"), "ICStextmenu", IcsTextProc, CHECK}, {"----", NULL, NothingProc}, - {N_("Tags"), "Tags", EditTagsProc}, - {N_("Comments"), "Comments", EditCommentProc}, - {N_("ICS Input Box"), "ICSInputBox", IcsInputBoxProc}, - {N_("Open Chat Window"), "OpenChatWindow", ChatProc}, + {N_("Tags"), "Tags", EditTagsProc, CHECK}, + {N_("Comments"), "Comments", EditCommentProc, CHECK}, + {N_("ICS Input Box"), "ICSInputBox", IcsInputBoxProc, CHECK}, + {N_("Open Chat Window"), "OpenChatWindow", ChatProc, CHECK}, {"----", NULL, NothingProc}, {N_("Board..."), "Board", BoardOptionsProc}, {N_("Game List Tags..."), "GameListTags", GameListOptionsProc}, @@ -641,18 +641,18 @@ MenuItem viewMenu[] = { }; MenuItem modeMenu[] = { - {N_("Machine White Ctrl+W"), "MachineWhite", MachineWhiteEvent}, - {N_("Machine Black Ctrl+B"), "MachineBlack", MachineBlackEvent}, - {N_("Two Machines Ctrl+T"), "TwoMachines", TwoMachinesEvent}, - {N_("Analysis Mode Ctrl+A"), "AnalysisMode", (MenuProc*) AnalyzeModeEvent}, - {N_("Analyze Game Ctrl+G"), "AnalyzeFile", AnalyzeFileEvent }, - {N_("Edit Game Ctrl+E"), "EditGame", EditGameEvent}, - {N_("Edit Position Ctrl+Shift+E"), "EditPosition", EditPositionEvent}, - {N_("Training"), "Training", TrainingEvent}, - {N_("ICS Client"), "ICSClient", IcsClientEvent}, + {N_("Machine White Ctrl+W"), "MachineWhite", MachineWhiteEvent, RADIO }, + {N_("Machine Black Ctrl+B"), "MachineBlack", MachineBlackEvent, RADIO }, + {N_("Two Machines Ctrl+T"), "TwoMachines", TwoMachinesEvent, RADIO }, + {N_("Analysis Mode Ctrl+A"), "AnalysisMode", (MenuProc*) AnalyzeModeEvent, RADIO}, + {N_("Analyze Game Ctrl+G"), "AnalyzeFile", AnalyzeFileEvent, RADIO }, + {N_("Edit Game Ctrl+E"), "EditGame", EditGameEvent, RADIO }, + {N_("Edit Position Ctrl+Shift+E"), "EditPosition", EditPositionEvent, RADIO }, + {N_("Training"), "Training", TrainingEvent, RADIO }, + {N_("ICS Client"), "ICSClient", IcsClientEvent, RADIO }, {"----", NULL, NothingProc}, - {N_("Machine Match"), "MachineMatch", MatchProc}, - {N_("Pause Pause"), "Pause", PauseEvent}, + {N_("Machine Match"), "MachineMatch", MatchProc, CHECK }, + {N_("Pause Pause"), "Pause", PauseEvent, CHECK }, {NULL, NULL, NULL} }; @@ -734,7 +734,7 @@ MenuItem optionsMenu[] = { {"----", NULL, NothingProc}, #endif {N_("Save Settings Now"), "SaveSettingsNow", SaveSettingsProc}, - {N_("Save Settings on Exit"), "SaveSettingsonExit", SaveOnExitProc}, + {N_("Save Settings on Exit"), "SaveSettingsonExit", SaveOnExitProc, CHECK }, {NULL, NULL, NULL} }; diff --git a/menus.h b/menus.h index 29ade2b..c59c6df 100644 --- a/menus.h +++ b/menus.h @@ -189,6 +189,9 @@ extern char *settingsFileName; +#define CHECK (void *) 1 +#define RADIO (void *) 2 + #define OPTIONSDIALOG #define INFOFILE "xboard.info" diff --git a/xboard.c b/xboard.c index 2857317..6ed7bfc 100644 --- a/xboard.c +++ b/xboard.c @@ -1694,9 +1694,7 @@ EnableNamedMenuItem (char *menuRef, int state) { MenuItem *item = MenuNameToItem(menuRef); -#ifdef TODO_GTK - if(item) XtSetSensitive(item->handle, state); -#endif + if(item) gtk_widget_set_sensitive(item->handle, state); } void diff --git a/xoptions.c b/xoptions.c index d33dd7f..4c004d2 100644 --- a/xoptions.c +++ b/xoptions.c @@ -139,13 +139,9 @@ MarkMenuItem (char *menuRef, int state) { MenuItem *item = MenuNameToItem(menuRef); -#ifdef TODO_GTK if(item) { - Arg args[2]; - XtSetArg(args[0], XtNleftBitmap, state ? xMarkPixmap : None); - XtSetValues(item->handle, args, 1); + ((GtkCheckMenuItem *) (item->handle))->active = state; } -#endif } void GetWidgetTextGTK(GtkWidget *w, char **buf) @@ -597,30 +593,6 @@ RaiseWindow (DialogClass dlg) #endif } -/* Sets a check box on (True) or off (False) in the menu */ -void SetCheckMenuItemActive(gchar *name, int menuDlgNr, gboolean active) -{ -#ifdef TODO_GTK -// This doesn't work anymore, as we don't use builder - gchar menuItemName[50]; - - if (name != NULL) - strcpy(menuItemName, name); - else - GetMenuItemName(menuDlgNr, menuItemName); - - if (strcmp(menuItemName, "") == 0) return; - - GtkCheckMenuItem *chk; - chk = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(GTK_BUILDER(builder), menuItemName)); - if (chk == NULL) { - printf("Error: failed to get check menu item %s from builder\n", menuItemName); - return; - } - chk->active = active; // set the check box without emitting any signals -#endif -} - int PopDown (DialogClass n) { @@ -649,15 +621,12 @@ PopDown (DialogClass n) gtk_widget_destroy(shells[n]); shells[n] = NULL; } -#ifdef TODO_GTK + if(marked[n]) { MarkMenuItem(marked[n], False); marked[n] = NULL; } -#else - // when popping down uncheck the check box of the menu item - SetCheckMenuItemActive(NULL, n, False); -#endif + if(!n) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now currentOption = dialogOptions[TransientDlg]; // just in case a transient dialog was up (to allow its check and combo callbacks to work) #ifdef TODO_GTK @@ -737,7 +706,7 @@ ColorChanged (Widget w, XtPointer data, XEvent *event, Boolean *b) #endif static void -GraphEventProc(GtkWidget *widget, GdkEventExpose *event, gpointer gdata) +GraphEventProc(GtkWidget *widget, GdkEvent *event, gpointer gdata) { // handle expose and mouse events on Graph widget int w, h; int j, button=10, f=1, sizing=0; @@ -745,7 +714,7 @@ GraphEventProc(GtkWidget *widget, GdkEventExpose *event, gpointer gdata) PointerCallback *userHandler = graph->target; GdkEventExpose *eevent = (GdkEventExpose *) event; GdkEventButton *bevent = (GdkEventButton *) event; - GdkEventMotion *mevent = (GdkEventButton *) event; + GdkEventMotion *mevent = (GdkEventMotion *) event; cairo_t *cr; // if (!XtIsRealized(widget)) return; @@ -819,7 +788,8 @@ GraphExpose (Option *opt, int x, int y, int w, int h) GdkEventExpose e; if(!opt->handle) return; e.area.x = x; e.area.y = y; e.area.width = w; e.area.height = h; e.count = -1; e.type = GDK_EXPOSE; // count = -1: kludge to suppress sizing - GraphEventProc(opt->handle, (GdkEvent *) &e, (gpointer) opt); // fake expose event + GraphEventProc(opt->handle, (GdkEvent// gtk_check_menu_item_set_active((GtkCheckMenuItem *) item->handle, state); + *) &e, (gpointer) opt); // fake expose event } /* GTK callback used when OK/cancel clicked in genericpopup for non-modal dialog */ @@ -1301,7 +1271,6 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent g_signal_connect (graph, "button-press-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]); g_signal_connect (graph, "button-release-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]); g_signal_connect (graph, "motion-notify-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]); -// g_signal_connect (graph, "motion-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]); #ifdef TODO_GTK XtAddEventHandler(last, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, False, -- 1.7.0.4