2 * xgamelistopt.c -- Game list options dialog, part of X front end for XBoard
4 * Copyright 1995,2009 Free Software Foundation, Inc.
5 * ------------------------------------------------------------------------
7 * GNU XBoard is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU XBoard is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/. *
20 *------------------------------------------------------------------------
21 ** See the file ChangeLog for a revision history. */
28 #include <sys/types.h>
33 #else /* not STDC_HEADERS */
34 extern char *getenv();
37 # else /* not HAVE_STRING_H */
39 # endif /* not HAVE_STRING_H */
40 #endif /* not STDC_HEADERS */
46 #include <X11/Intrinsic.h>
47 #include <X11/StringDefs.h>
48 #include <X11/Shell.h>
49 #include <X11/cursorfont.h>
51 #include <X11/Xaw3d/Dialog.h>
52 #include <X11/Xaw3d/Form.h>
53 #include <X11/Xaw3d/List.h>
54 #include <X11/Xaw3d/Label.h>
55 #include <X11/Xaw3d/SimpleMenu.h>
56 #include <X11/Xaw3d/SmeBSB.h>
57 #include <X11/Xaw3d/SmeLine.h>
58 #include <X11/Xaw3d/Box.h>
59 #include <X11/Xaw3d/MenuButton.h>
60 #include <X11/Xaw3d/Text.h>
61 #include <X11/Xaw3d/AsciiText.h>
62 #include <X11/Xaw3d/Viewport.h>
64 #include <X11/Xaw/Dialog.h>
65 #include <X11/Xaw/Form.h>
66 #include <X11/Xaw/List.h>
67 #include <X11/Xaw/Label.h>
68 #include <X11/Xaw/SimpleMenu.h>
69 #include <X11/Xaw/SmeBSB.h>
70 #include <X11/Xaw/SmeLine.h>
71 #include <X11/Xaw/Box.h>
72 #include <X11/Xaw/MenuButton.h>
73 #include <X11/Xaw/Text.h>
74 #include <X11/Xaw/AsciiText.h>
75 #include <X11/Xaw/Viewport.h>
82 #include "xgamelist.h"
86 # define _(s) gettext (s)
87 # define N_(s) gettext_noop (s)
94 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
95 extern Display *xDisplay;
96 extern int squareSize;
97 extern Pixmap xMarkPixmap;
98 extern char *layoutName;
99 extern char lpUserGLT[];
101 char gameListOptTranslations[] =
102 "<Btn1Up>(2): LoadSelectedProc() \n \
103 <Key>Return: LoadSelectedProc() \n";
105 static Arg layoutArgs[] = {
106 { XtNborderWidth, 0 },
107 { XtNdefaultDistance, 0 }
110 Widget gameListOptShell, listwidg;
121 void GLT_AddToList(char *name)
123 strings[stringPtr++] = name;
124 strings[stringPtr] = NULL;
127 void GLT_GetFromList(int index, char *name)
129 strcpy(name, strings[index]);
132 void GLT_DeSelectList()
134 XawListChange(listwidg, strings, 0, 0, True);
135 XawListHighlight(listwidg, 0);
139 GameListOptionsPopDown()
144 if (gameListOptShell == NULL) return;
145 XtPopdown(gameListOptShell);
146 XtDestroyWidget(gameListOptShell);
147 gameListOptShell = 0;
148 XtSetKeyboardFocus(shellWidget, formWidget);
152 GameListOptionsCallback(w, client_data, call_data)
154 XtPointer client_data, call_data;
160 XawListReturnStruct *rs;
165 XtSetArg(args[j], XtNlabel, &name); j++;
166 XtGetValues(w, args, j);
168 if (strcmp(name, _("OK")) == 0) {
170 appData.gameListTags = strdup(lpUserGLT);
171 GameListOptionsPopDown();
174 if (strcmp(name, _("cancel")) == 0) {
175 GameListOptionsPopDown();
178 listwidg = XtNameToWidget(gameListOptShell, "*form.list");
179 rs = XawListShowCurrent(listwidg);
180 index = rs->list_index;
182 DisplayError(_("No tag selected"), 0);
186 if (strcmp(name, _("down")) == 0) {
187 if(index >= strlen(GLT_ALL_TAGS)) return;
188 strings[index] = strings[index+1];
189 strings[++index] = p;
191 if (strcmp(name, _("up")) == 0) {
192 if(index == 0) return;
193 strings[index] = strings[index-1];
194 strings[--index] = p;
196 if (strcmp(name, _("factory")) == 0) {
197 strcpy(lpUserGLT, GLT_DEFAULT_TAGS);
198 GLT_TagsToList(lpUserGLT);
201 XawListHighlight(listwidg, index);
205 GameListOptionsCreate()
208 Widget shell, form, viewport, layout;
209 Widget b_load, b_loadprev, b_loadnext, b_close, b_cancel;
211 XtPointer client_data = NULL;
215 XtSetArg(args[j], XtNwidth, &fw_width); j++;
216 XtGetValues(formWidget, args, j);
219 XtSetArg(args[j], XtNresizable, True); j++;
220 XtSetArg(args[j], XtNallowShellResize, True); j++;
221 shell = gameListOptShell =
222 XtCreatePopupShell("Game-list options", transientShellWidgetClass,
223 shellWidget, args, j);
225 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
226 layoutArgs, XtNumber(layoutArgs));
228 XtSetArg(args[j], XtNborderWidth, 0); j++;
230 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
233 // XtSetArg(args[j], XtNlist, glc->strings); j++;
234 XtSetArg(args[j], XtNdefaultColumns, 1); j++;
235 XtSetArg(args[j], XtNforceColumns, True); j++;
236 XtSetArg(args[j], XtNverticalList, True); j++;
237 listwidg = viewport =
238 XtCreateManagedWidget("list", listWidgetClass, form, args, j);
239 XawListHighlight(listwidg, 0);
240 XtAugmentTranslations(listwidg,
241 XtParseTranslationTable(gameListOptTranslations));
244 XtSetArg(args[j], XtNfromVert, viewport); j++;
245 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
246 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
247 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
248 XtSetArg(args[j], XtNright, XtChainLeft); j++;
250 XtCreateManagedWidget(_("factory"), commandWidgetClass, form, args, j);
251 XtAddCallback(b_load, XtNcallback, GameListOptionsCallback, client_data);
254 XtSetArg(args[j], XtNfromVert, viewport); j++;
255 XtSetArg(args[j], XtNfromHoriz, b_load); j++;
256 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
257 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
258 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
259 XtSetArg(args[j], XtNright, XtChainLeft); j++;
261 XtCreateManagedWidget(_("up"), commandWidgetClass, form, args, j);
262 XtAddCallback(b_loadprev, XtNcallback, GameListOptionsCallback, client_data);
265 XtSetArg(args[j], XtNfromVert, viewport); j++;
266 XtSetArg(args[j], XtNfromHoriz, b_loadprev); j++;
267 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
268 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
269 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
270 XtSetArg(args[j], XtNright, XtChainLeft); j++;
272 XtCreateManagedWidget(_("down"), commandWidgetClass, form, args, j);
273 XtAddCallback(b_loadnext, XtNcallback, GameListOptionsCallback, client_data);
276 XtSetArg(args[j], XtNfromVert, viewport); j++;
277 XtSetArg(args[j], XtNfromHoriz, b_loadnext); j++;
278 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
279 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
280 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
281 XtSetArg(args[j], XtNright, XtChainLeft); j++;
283 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
284 XtAddCallback(b_cancel, XtNcallback, GameListOptionsCallback, client_data);
287 XtSetArg(args[j], XtNfromVert, viewport); j++;
288 XtSetArg(args[j], XtNfromHoriz, b_cancel); j++;
289 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
290 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
291 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
292 XtSetArg(args[j], XtNright, XtChainLeft); j++;
294 XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j);
295 XtAddCallback(b_close, XtNcallback, GameListOptionsCallback, client_data);
297 strcpy(lpUserGLT, appData.gameListTags);
298 GLT_TagsToList(lpUserGLT);
300 XtRealizeWidget(shell);
301 CatchDeleteWindow(shell, "GameListOptionsPopDown");
307 GameListOptionsPopUp(Widget w, XEvent *event, String *prms, Cardinal *nprms)
313 if (gameListOptShell == NULL) {
314 gameListOptShell = GameListOptionsCreate();
317 XtPopup(gameListOptShell, XtGrabNone);