From: H.G. Muller Date: Tue, 16 Oct 2012 07:34:02 +0000 (+0200) Subject: Append recent engines to engine menu X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=4b31713470178d16b972c3ed6beed0b467461291;p=xboard.git Append recent engines to engine menu This is now entirely moved to the back-end, by doing it in the table from which the menus are later generated. The special callback for engine items is abandoned, and the euProc for such items is left NULL to flag that RecentEngineEvent should be invoked with the applicable engine number. To calculate the latter a global variable firstEngineItem is dynamically set to the length of the regular engine menu. --- diff --git a/dialogs.c b/dialogs.c index ca2bd12..42d3f98 100644 --- a/dialogs.c +++ b/dialogs.c @@ -2073,7 +2073,7 @@ MenuCallback (int n) { MenuProc *proc = (MenuProc *) (((MenuItem*)(mainOptions[n].choice))[values[n]].proc); - (proc)(); + if(!proc) RecentEngineEvent(values[n] - firstEngineItem); else (proc)(); } static Option * @@ -2143,6 +2143,7 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy) } if(!appData.showButtonBar) for(i=W_BUTTON; iproc) (); } -static void -MenuEngineSelect (Widget w, caddr_t addr, caddr_t index) -{ - RecentEngineEvent((int) (intptr_t) addr); -} - -void -AppendMenuItem (char *msg, int n) -{ - CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n); -} - void SetupDropMenu () { diff --git a/xboard.c b/xboard.c index f1c5425..845c168 100644 --- a/xboard.c +++ b/xboard.c @@ -1325,7 +1325,6 @@ main (int argc, char **argv) XtGetValues(optList[W_PAUSE].handle, args, 2); } #endif - AppendEnginesToMenu(appData.recentEngineList); #ifdef TODO_GTK xBoardWindow = XtWindow(boardWidget); @@ -1684,22 +1683,6 @@ KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) } #endif -#ifdef TODO_GTK -static void -MenuEngineSelect (Widget w, caddr_t addr, caddr_t index) -{ - RecentEngineEvent((int) (intptr_t) addr); -} -#endif - -void -AppendMenuItem (char *msg, int n) -{ -#ifdef TODO_GTK - CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n); -#endif -} - void SetupDropMenu () { diff --git a/xoptions.c b/xoptions.c index d71d182..26e7d02 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1013,6 +1013,19 @@ SetPositionAndSize (Arg *args, Widget leftNeigbor, Widget topNeigbor, int b, int } #endif +static int +SameRow (Option *opt) +{ + return (opt->min & SAME_ROW && (opt->type == Button || opt->type == SaveButton || opt->type == Label || opt->type == ListBox)); +} + +static void +Pack (GtkWidget *hbox, GtkWidget *table, GtkWidget *entry, int left, int right, int top) +{ + if(hbox) gtk_box_pack_start(GTK_BOX (hbox), entry, TRUE, TRUE, 0); + else gtk_table_attach_defaults(GTK_TABLE(table), entry, left, right, top, top+1); +} + int GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent, int modal, int topLevel) { @@ -1022,7 +1035,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent GtkWidget *box; GtkWidget *checkbutton; GtkWidget *entry; - GtkWidget *hbox; + GtkWidget *hbox = NULL; GtkWidget *button; GtkWidget *table; GtkWidget *spinner; @@ -1102,6 +1115,17 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent left = left + 3; gtk_table_resize(GTK_TABLE(table), height, left + 3); } + if(!SameRow(&option[i])) { + if(SameRow(&option[i+1])) { + // make sure hbox is always available when we have more options on same row + hbox = gtk_hbox_new (option[i].type == Button && option[i].textValue, 0); + if (strcmp(option[i].name, "") == 0 || option[i].type == Label || option[i].type == Button) + // for Label and Button name is contained inside option + gtk_table_attach_defaults(GTK_TABLE(table), hbox, left, left+3, top, top+1); + else + gtk_table_attach_defaults(GTK_TABLE(table), hbox, left+1, left+3, top, top+1); + } else hbox = NULL; //and also make sure no hbox exists if only singl option on row + } switch(option[i].type) { case Fractional: snprintf(def, MSG_SIZ, "%.2f", *(float*)option[i].target); @@ -1142,11 +1166,11 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent /* check if label is empty */ if (strcmp(option[i].name,"") != 0) { gtk_table_attach_defaults(GTK_TABLE(table), label, left, left+1, top, top+1); - gtk_table_attach_defaults(GTK_TABLE(table), sw, left+1, left+3, top, top+1); + Pack(hbox, table, sw, left+1, left+3, top); } else { /* no label so let textview occupy all columns */ - gtk_table_attach_defaults(GTK_TABLE(table), sw, left, left+3, top, top+1); + Pack(hbox, table, sw, left, left+3, top); } if ( *(char**)option[i].target != NULL ) gtk_text_buffer_set_text (textbuffer, *(char**)option[i].target, -1); @@ -1186,13 +1210,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent option[i].handle = (void*)entry; } else { - hbox = gtk_hbox_new (FALSE, 0); - if (strcmp(option[i].name, "") == 0) - gtk_table_attach_defaults(GTK_TABLE(table), hbox, left, left+3, top, top+1); - else - gtk_table_attach_defaults(GTK_TABLE(table), hbox, left+1, left+3, top, top+1); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - //gtk_table_attach_defaults(GTK_TABLE(table), entry, left+1, left+3, top, top+1); + Pack(hbox, table, entry, left + (strcmp(option[i].name, "") != 0), left+3, top); option[i].handle = (void*)entry; } break; @@ -1212,7 +1230,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent gtk_container_add(GTK_CONTAINER(frame), label); label = frame; } - gtk_table_attach_defaults(GTK_TABLE(table), label, left, left+3, top, top+1); + Pack(hbox, table, label, left, left+3, top); break; case SaveButton: case Button: @@ -1232,18 +1250,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent || strstr(first.variants, VariantName(option[i].value))); } - if (!(option[i].min & 1)) { - if(option[i].textValue) // for new variant dialog give buttons equal space so they line up nicely - hbox = gtk_hbox_new (TRUE, 0); - else - hbox = gtk_hbox_new (FALSE, 0); - // if only 1 button then put it in 1st column of table only - if ( (arraysize >= (i+1)) && option[i+1].type != Button ) - gtk_table_attach_defaults(GTK_TABLE(table), hbox, left, left+1, top, top+1); - else - gtk_table_attach_defaults(GTK_TABLE(table), hbox, left, left+3, top, top+1); - } - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + Pack(hbox, table, button, left, left+1, top); g_signal_connect (button, "clicked", G_CALLBACK (GenericCallback), (gpointer)(intptr_t) i + (dlgNr<<16)); option[i].handle = (void*)button; break; @@ -1276,12 +1283,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent //option[i].value = j + (option[i].choice[j] == NULL); gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), option[i].value); - - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach_defaults(GTK_TABLE(table), hbox, left+1, left+3, top, top+1); - gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0); - //gtk_table_attach_defaults(GTK_TABLE(table), combobox, 1, 2, i, i+1); - + Pack(hbox, table, combobox, left+1, left+3, top); g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(ComboSelect), (gpointer) (intptr_t) (i + 256*dlgNr)); option[i].handle = (void*)combobox; @@ -1311,7 +1313,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent gtk_widget_set_size_request(GTK_WIDGET(sw), w, 300); /* never has label, so let listbox occupy all columns */ - gtk_table_attach_defaults(GTK_TABLE(table), sw, left, left+3, top, top+1); + Pack(hbox, table, sw, left, left+3, top); } break; case Graph: @@ -1410,9 +1412,6 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent g_signal_connect (dialog, "delete-event", G_CALLBACK (GenericPopDown), (gpointer)(intptr_t) dlgNr); - g_signal_connect (dialog, "destroy-event", - G_CALLBACK (GenericPopDown), - (gpointer)(intptr_t) dlgNr); shellUp[dlgNr]++; #ifdef TODO_GTK