From 6f01cd3e57fc068f24d8075c1dbb87ebef635e6a Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 15 Oct 2012 11:41:33 +0200 Subject: [PATCH] Give LoadListBox two extra parameters It often occurs that we just want to swap two elements, and reloading the entire listbox would be a very inefficient way to do this in widget sets that allow access to a single element. --- dialogs.c | 18 ++++++++++-------- dialogs.h | 2 +- ngamelist.c | 2 +- xaw/xoptions.c | 2 +- xoptions.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dialogs.c b/dialogs.c index db7e249..ca2bd12 100644 --- a/dialogs.c +++ b/dialogs.c @@ -328,7 +328,7 @@ AddToTourney (int n, int sel) } nr = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents ASSIGN(engineMnemonic[0], buf); - LoadListBox(&matchOptions[8], _("# no engines are installed")); + LoadListBox(&matchOptions[8], _("# no engines are installed"), -1, -1); HighlightWithScroll(&matchOptions[8], 0, nr); } @@ -1268,7 +1268,7 @@ EngSel (int n, int sel) } nr = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents ASSIGN(engineMnemonic[0], buf); - LoadListBox(&installOptions[1], _("# no engines are installed")); + LoadListBox(&installOptions[1], _("# no engines are installed"), -1, -1); HighlightWithScroll(&installOptions[1], 0, nr); } @@ -1717,17 +1717,19 @@ GLT_Button (int n) if(index >= strlen(GLT_ALL_TAGS)) return; strings[index] = strings[index+1]; strings[++index] = p; + LoadListBox(&listOptions[0], "?", index, index-1); // only change the two specified entries } else if (n == 2) { if(index == 0) return; strings[index] = strings[index-1]; strings[--index] = p; + LoadListBox(&listOptions[0], "?", index, index+1); } else if (n == 1) { safeStrCpy(lpUserGLT, GLT_DEFAULT_TAGS, LPUSERGLT_SIZE); GLT_TagsToList(lpUserGLT); index = 0; - LoadListBox(&listOptions[0], "?"); // Note: the others don't need this, as the highlight switching redraws the change items + LoadListBox(&listOptions[0], "?", -1, -1); } HighlightListBoxItem(&listOptions[0], index); } @@ -2011,7 +2013,7 @@ CCB (int n) } Option mainOptions[] = { // description of main window in terms of generic dialog creator -{ 0, 0xCA, 0, NULL, NULL, "", NULL, BoxBegin, "" }, // menu bar +{ 0, 0xCA, 0, NULL, NULL, "", NULL, BarBegin, "" }, // menu bar { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("File") }, { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Edit") }, { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("View") }, @@ -2020,7 +2022,7 @@ Option mainOptions[] = { // description of main window in terms of generic dialo { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Engine") }, { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Options") }, { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Help") }, -{ 0, 0, 0, NULL, (void*)&SizeKludge, "", NULL, BoxEnd, "" }, +{ 0, 0, 0, NULL, (void*)&SizeKludge, "", NULL, BarEnd, "" }, { 0, LR|T2T|BORDER|SAME_ROW, 0, NULL, NULL, "", NULL, Label, "1" }, // optional title in window { 50, LL|TT, 100, NULL, (void*) &LogoW, NULL, NULL, -1, "LogoW" }, // white logo { 0, L2L|T2T, 200, NULL, (void*) &CCB, NULL, NULL, Label, "White" }, // white clock @@ -2422,8 +2424,8 @@ void Refresh (int pathFlag) { ListDir(pathFlag); // and make new one - LoadListBox(&browseOptions[5], ""); - LoadListBox(&browseOptions[6], ""); + LoadListBox(&browseOptions[5], "", -1, -1); + LoadListBox(&browseOptions[6], "", -1, -1); SetWidgetLabel(&browseOptions[0], title); } @@ -2447,7 +2449,7 @@ Switch (int n) if(byExtension == (n == 4)) return; extFlag = byExtension = (n == 4); qsort((void*)fileList, filePtr, sizeof(char*), &Comp); - LoadListBox(&browseOptions[6], ""); + LoadListBox(&browseOptions[6], "", -1, -1); } void diff --git a/dialogs.h b/dialogs.h index 2c3e993..09d66a5 100644 --- a/dialogs.h +++ b/dialogs.h @@ -148,7 +148,7 @@ void GetWidgetState P((Option *opt, int *state)); void SetWidgetState P((Option *opt, int state)); void SetWidgetLabel P((Option *opt, char *buf)); void SetDialogTitle P((DialogClass dlg, char *title)); -void LoadListBox P((Option *opt, char *emptyText)); +void LoadListBox P((Option *opt, char *emptyText, int n1, int n2)); void HighlightListBoxItem P((Option *opt, int nr)); void HighlightWithScroll P((Option *opt, int sel, int max)); int SelectedListBoxItem P((Option *opt)); diff --git a/ngamelist.c b/ngamelist.c index f3ef1d9..32fdf33 100644 --- a/ngamelist.c +++ b/ngamelist.c @@ -214,7 +214,7 @@ GameListReplace (int page) if(page + 1000 <= listLength) *st++ = _("next page"); *st = NULL; - LoadListBox(&gamesOptions[0], _("no games matched your request")); + LoadListBox(&gamesOptions[0], _("no games matched your request"), -1, -1); HighlightWithScroll(&gamesOptions[0], listEnd > 1000, listEnd); snprintf(buf, MSG_SIZ, _("%s - %d/%d games (%d-%d-%d)"), glc->filename, listLength, ((ListGame *) gameList.tailPred)->number, wins, losses, draws); SetDialogTitle(GameListDlg, buf); diff --git a/xaw/xoptions.c b/xaw/xoptions.c index 7bbff9b..7e622a7 100644 --- a/xaw/xoptions.c +++ b/xaw/xoptions.c @@ -197,7 +197,7 @@ SetDialogTitle (DialogClass dlg, char *title) } void -LoadListBox (Option *opt, char *emptyText) +LoadListBox (Option *opt, char *emptyText, int n1, int n2) { static char *dummyList[2]; dummyList[0] = emptyText; // empty listboxes tend to crash X, so display user-supplied warning string instead diff --git a/xoptions.c b/xoptions.c index fb12fa3..9d4f122 100644 --- a/xoptions.c +++ b/xoptions.c @@ -206,7 +206,7 @@ SetDialogTitle (DialogClass dlg, char *title) } void -LoadListBox (Option *opt, char *emptyText) +LoadListBox (Option *opt, char *emptyText, int n1, int n2) { #ifdef TODO_GTK static char *dummyList[2]; -- 1.7.0.4