From 959078d28a10387d4583f8bd2f46d52a799065d3 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 21 Sep 2014 16:10:19 +0200 Subject: [PATCH] Add extra font field to Option struct Storing the font in the textValue field was too kludgy, as this field is already heavily used in the various Option types, for storing handles, or defining colors and callbacks. A 'font' field is now added at the end, so that it can be optionally initialized in the rare case it is needed. --- backend.h | 1 + dialogs.c | 16 ++++++++-------- dialogs.h | 3 ++- gtk/xoptions.c | 19 ++++++++----------- nengineoutput.c | 4 ++-- ngamelist.c | 2 +- nhistory.c | 2 +- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/backend.h b/backend.h index d895155..f52f1f5 100644 --- a/backend.h +++ b/backend.h @@ -303,6 +303,7 @@ typedef struct XB_OPT { // [HGM] options: descriptor of UCI-style option char **choice; // points to array of combo choices in cps->combo Control type; char *name; // holds both option name and text value (in allocated memory) + char **font; } Option; typedef struct XB_CPS { diff --git a/dialogs.c b/dialogs.c index f695bb4..83574f7 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1096,7 +1096,7 @@ NewComCallback (int n) } Option commentOptions[] = { -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, (char*) &appData.commentFont, (char **) &CommentClick, TextBox, "" }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, NULL, (char **) &CommentClick, TextBox, "", &appData.commentFont }, { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, N_("clear") }, { 0, SAME_ROW, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, N_("save changes") }, { 0, SAME_ROW, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" } @@ -1195,7 +1195,7 @@ NewMove () static Option tagsOptions[] = { { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL }, -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, (char*) &appData.tagsFont, (char **) &TagsClick, TextBox, "" }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, NULL, (char **) &TagsClick, TextBox, "", &appData.tagsFont }, { 0, 0, 100, NULL, (void*) &NewMove, NULL, NULL, Button, N_("add next move") }, { 0,SAME_ROW,100,NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") }, { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" } @@ -2460,13 +2460,13 @@ Option mainOptions[] = { // description of main window in terms of generic dialo { 13, R2R|T2T|SAME_ROW, 200, NULL, (void*) &CCB, NULL, NULL, Label, "Black" }, // black clock { 50, RR|TT|SAME_ROW, 100, NULL, (void*) &LogoB, NULL, NULL, Skip, "" }, // black logo { 0, LR|T2T|BORDER, 401, NULL, NULL, "", NULL, Skip, "2" }, // backup for title in window (if no room for other) -{ 0, LR|T2T|BORDER, 270, NULL, NULL, (char*)&appData.font, NULL, Label, "message" }, // message field +{ 0, LR|T2T|BORDER, 270, NULL, NULL, NULL, NULL, Label, "message", &appData.font }, // message field { 0, RR|TT|SAME_ROW, 125, NULL, NULL, "", NULL, BoxBegin, "" }, // (optional) button bar - { 0, 0, 0, NULL, (void*) &ToStartEvent, (char*)&appData.font, NULL, Button, N_("<<") }, - { 0, SAME_ROW, 0, NULL, (void*) &BackwardEvent, (char*)&appData.font, NULL, Button, N_("<") }, - { 0, SAME_ROW, 0, NULL, (void*) &PauseEvent, (char*)&appData.font, NULL, Button, N_(PAUSE_BUTTON) }, - { 0, SAME_ROW, 0, NULL, (void*) &ForwardEvent, (char*)&appData.font, NULL, Button, N_(">") }, - { 0, SAME_ROW, 0, NULL, (void*) &ToEndEvent, (char*)&appData.font, NULL, Button, N_(">>") }, + { 0, 0, 0, NULL, (void*) &ToStartEvent, NULL, NULL, Button, N_("<<"), &appData.font }, + { 0, SAME_ROW, 0, NULL, (void*) &BackwardEvent, NULL, NULL, Button, N_("<"), &appData.font }, + { 0, SAME_ROW, 0, NULL, (void*) &PauseEvent, NULL, NULL, Button, N_(PAUSE_BUTTON), &appData.font }, + { 0, SAME_ROW, 0, NULL, (void*) &ForwardEvent, NULL, NULL, Button, N_(">"), &appData.font }, + { 0, SAME_ROW, 0, NULL, (void*) &ToEndEvent, NULL, NULL, Button, N_(">>"), &appData.font }, { 0, 0, 0, NULL, NULL, "", NULL, BoxEnd, "" }, { 401, LR|TB, 401, NULL, (char*) &Exp, NULL, NULL, Graph, "shadow board" }, // board { 2, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, pieceMenuStrings[0], PopUp, "menuW" }, diff --git a/dialogs.h b/dialogs.h index 1e4861c..9c00356 100644 --- a/dialogs.h +++ b/dialogs.h @@ -35,7 +35,8 @@ // char* textValue X/E X/E * // char ** choice C X/E * X // enum type X/E X/E X/E X/E X X X X X X X X -// char[] name X/E X/E X/E X/E X X X X X +// char * name X/E X/E X/E X/E X X X X X +// char ** font X X X X (GTK only) // File and Path options are like String (but get a browse button added in the dialog), and Slider // is like Spin. Menu can be PopUp or PopDown; both need the COMBO_CALLBACK bit (3) set! // (h) or (w) means the field optionally (when non-null) specifies the height or width of the main diff --git a/gtk/xoptions.c b/gtk/xoptions.c index 5df840b..cd78c9f 100644 --- a/gtk/xoptions.c +++ b/gtk/xoptions.c @@ -249,15 +249,13 @@ SetDialogTitle (DialogClass dlg, char *title) gtk_window_set_title(GTK_WINDOW(shells[dlg]), title); } -int -SetWidgetFont (GtkWidget *w, char *s) +void +SetWidgetFont (GtkWidget *w, char **s) { PangoFontDescription *pfd; - if (!s || *s == '#') return 0; // no spec, or spec of color: fail - if(!*(char**)s) return 1; // empty spec: do nothing, but succeed - pfd = pango_font_description_from_string(*(char**)s); + if (!s || !*s || !**s) return; // uses no font, no font spec or empty font spec + pfd = pango_font_description_from_string(*s); gtk_widget_modify_font(w, pfd); - return 1; } void @@ -704,8 +702,6 @@ AddHandler (Option *opt, DialogClass dlg, int nr) g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (TypeInProc), (gpointer) (dlg<<16 | (opt - dialogOptions[dlg]))); break; case 5: // game list -printf("use %s\n", appData.gameListFont); - SetWidgetFont(opt->handle, (char*) &appData.gameListFont); g_signal_connect(opt->handle, "button-press-event", G_CALLBACK (GameListEvent), (gpointer) 0 ); case 4: // game-list filter g_signal_connect(opt->handle, "key-press-event", G_CALLBACK (GameListEvent), (gpointer) (intptr_t) nr ); @@ -1352,7 +1348,7 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width); /* no label so let textview occupy all columns */ Pack(hbox, table, sw, left, left+r, top, GTK_EXPAND); } - SetWidgetFont(textview, option[i].textValue); + SetWidgetFont(textview, option[i].font); if ( *(char**)option[i].target != NULL ) gtk_text_buffer_set_text (textbuffer, *(char**)option[i].target, -1); else @@ -1419,7 +1415,7 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width); option[i].handle = (void *) (label = gtk_label_new(option[i].name)); /* Left Justify */ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - SetWidgetFont(label, option[i].textValue); + SetWidgetFont(label, option[i].font); if(option[i].min & BORDER) { GtkWidget *frame = gtk_frame_new(NULL); gtk_container_add(GTK_CONTAINER(frame), label); @@ -1439,6 +1435,7 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width); case SaveButton: case Button: button = gtk_button_new_with_label (option[i].name); + SetWidgetFont(gtk_bin_get_child(GTK_BIN(button)), option[i].font); /* set button color on view board dialog */ if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) { @@ -1447,7 +1444,6 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width); } /* set button color on new variant dialog */ - if(!SetWidgetFont(gtk_bin_get_child(GTK_BIN(button)), option[i].textValue)) if(option[i].textValue) { gdk_color_parse( option[i].textValue, &color ); gtk_widget_modify_bg ( GTK_WIDGET(button), GTK_STATE_NORMAL, &color ); @@ -1501,6 +1497,7 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width); GtkListStore *store; option[i].handle = (void *) (list = gtk_tree_view_new()); + SetWidgetFont(option[i].handle, option[i].font); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("List Items", renderer, "text", 0, NULL); diff --git a/nengineoutput.c b/nengineoutput.c index 1818e61..81b2b5a 100644 --- a/nengineoutput.c +++ b/nengineoutput.c @@ -80,7 +80,7 @@ Option engoutOptions[] = { /* TRANSLATORS: noun, as in "the move Nf3"*/ { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") }, { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") }, -{200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem1, (char*) &appData.historyFont, (char**) MemoProc, TextBox, "" }, +{200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem1, NULL, (char**) MemoProc, TextBox, "", &appData.historyFont }, { 0, 0, 0, NULL, NULL, "", NULL, Break , "" }, { 0, LL|T2T, 18, NULL, NULL, NULL, NULL, Icon, " " }, { 0, L2L|T2T|SAME_ROW, 162, NULL, NULL, NULL, NULL, Label, N_("engine name") }, @@ -88,7 +88,7 @@ Option engoutOptions[] = { /* TRANSLATORS: noun, as in "the move Nf3"*/ { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") }, { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") }, -{200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem2, (char*) &appData.historyFont, (char**) MemoProc, TextBox, "" }, +{200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem2, NULL, (char**) MemoProc, TextBox, "", &appData.historyFont }, { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" } }; diff --git a/ngamelist.c b/ngamelist.c index b415d19..5417804 100644 --- a/ngamelist.c +++ b/ngamelist.c @@ -82,7 +82,7 @@ static void GameListReplace P((int page)); static void GL_Button P((int n)); static Option gamesOptions[] = { -{ 200, LR|TB, 400, NULL, (void*) list, NULL, NULL, ListBox, "" }, +{ 200, LR|TB, 400, NULL, (void*) list, NULL, NULL, ListBox, "", &appData.gameListFont }, { 0, 0, 100, NULL, (void*) &filterPtr, "", NULL, TextBox, "" }, { 4, SAME_ROW, 0, NULL, (void*) &GL_Button, NULL, NULL, Button, N_("find position") }, { 2, SAME_ROW, 0, NULL, (void*) &GL_Button, NULL, NULL, Button, N_("narrow") }, // buttons referred to by ID in value (=first) field! diff --git a/nhistory.c b/nhistory.c index 2366dfd..eaa7d99 100644 --- a/nhistory.c +++ b/nhistory.c @@ -79,7 +79,7 @@ SelectMove (Option *opt, int n, int x, int y, char *text, int index) } Option historyOptions[] = { -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 400, NULL, (void*) &historyText, (char*) &appData.historyFont, (char**) &SelectMove, TextBox, "" }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 400, NULL, (void*) &historyText, NULL , (char**) &SelectMove, TextBox, "", &appData.historyFont }, { 0, NO_OK, 0, NULL, (void*) NULL, "", NULL, EndMark , "" } }; -- 1.7.0.4