2 * xedittags.c -- Tags edit window, part of X front end for XBoard
4 * Copyright 1995,2009 Free Software Foundation, Inc.
6 * ------------------------------------------------------------------------
8 * GNU XBoard is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at
11 * your option) any later version.
13 * GNU XBoard is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see http://www.gnu.org/licenses/. *
21 *------------------------------------------------------------------------
22 ** See the file ChangeLog for a revision history. */
29 #include <sys/types.h>
34 #else /* not STDC_HEADERS */
35 extern char *getenv();
38 # else /* not HAVE_STRING_H */
40 # endif /* not HAVE_STRING_H */
41 #endif /* not STDC_HEADERS */
47 #include <X11/Intrinsic.h>
48 #include <X11/StringDefs.h>
49 #include <X11/Shell.h>
50 #include <X11/cursorfont.h>
52 #include <X11/Xaw3d/Dialog.h>
53 #include <X11/Xaw3d/Form.h>
54 #include <X11/Xaw3d/List.h>
55 #include <X11/Xaw3d/Label.h>
56 #include <X11/Xaw3d/SimpleMenu.h>
57 #include <X11/Xaw3d/SmeBSB.h>
58 #include <X11/Xaw3d/SmeLine.h>
59 #include <X11/Xaw3d/Box.h>
60 #include <X11/Xaw3d/MenuButton.h>
61 #include <X11/Xaw3d/Text.h>
62 #include <X11/Xaw3d/AsciiText.h>
63 #include <X11/Xaw3d/Viewport.h>
65 #include <X11/Xaw/Dialog.h>
66 #include <X11/Xaw/Form.h>
67 #include <X11/Xaw/List.h>
68 #include <X11/Xaw/Label.h>
69 #include <X11/Xaw/SimpleMenu.h>
70 #include <X11/Xaw/SmeBSB.h>
71 #include <X11/Xaw/SmeLine.h>
72 #include <X11/Xaw/Box.h>
73 #include <X11/Xaw/MenuButton.h>
74 #include <X11/Xaw/Text.h>
75 #include <X11/Xaw/AsciiText.h>
76 #include <X11/Xaw/Viewport.h>
83 #include "xedittags.h"
87 # define _(s) gettext (s)
88 # 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;
100 Position tagsX = -1, tagsY = -1;
101 int tagsUp = False, editTagsUp = False;
102 Widget tagsShell, editTagsShell;
104 static Arg layoutArgs[] = {
105 { XtNborderWidth, 0 },
106 { XtNdefaultDistance, 0 }
109 void TagsCallback(w, client_data, call_data)
111 XtPointer client_data, call_data;
118 XtSetArg(args[j], XtNlabel, &name); j++;
119 XtGetValues(w, args, j);
121 if (strcmp(name, _("close")) == 0) {
123 } else if (strcmp(name, _("edit")) == 0) {
130 void EditTagsCallback(w, client_data, call_data)
132 XtPointer client_data, call_data;
140 XtSetArg(args[j], XtNlabel, &name); j++;
141 XtGetValues(w, args, j);
143 if (strcmp(name, _("ok")) == 0) {
144 textw = XtNameToWidget(editTagsShell, "*form.text");
146 XtSetArg(args[j], XtNstring, &val); j++;
147 XtGetValues(textw, args, j);
148 ReplaceTags(val, &gameInfo);
150 } else if (strcmp(name, _("cancel")) == 0) {
152 } else if (strcmp(name, _("clear")) == 0) {
153 textw = XtNameToWidget(editTagsShell, "*form.text");
154 XtCallActionProc(textw, "select-all", NULL, NULL, 0);
155 XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
159 Widget TagsCreate(name, text, msg, mutable, callback)
160 char *name, *text, *msg;
161 int /*Boolean*/ mutable;
162 XtCallbackProc callback;
165 Widget shell, form, textw, msgw, layout;
166 Widget b_ok, b_cancel, b_close, b_edit, b;
167 Dimension bw_width, pw_width;
173 XtSetArg(args[j], XtNwidth, &bw_width); j++;
174 XtGetValues(boardWidget, args, j);
177 XtSetArg(args[j], XtNresizable, True); j++;
180 XtCreatePopupShell(name, topLevelShellWidgetClass,
181 shellWidget, args, j);
184 XtCreatePopupShell(name, transientShellWidgetClass,
185 shellWidget, args, j);
188 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
189 layoutArgs, XtNumber(layoutArgs));
191 XtSetArg(args[j], XtNborderWidth, 0); j++;
193 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
197 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
198 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
200 XtSetArg(args[j], XtNstring, text); j++;
201 XtSetArg(args[j], XtNtop, XtChainTop); j++;
202 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
203 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
204 XtSetArg(args[j], XtNright, XtRubber); j++;
205 XtSetArg(args[j], XtNresizable, True); j++;
206 XtSetArg(args[j], XtNwidth, bw_width/2); j++;
207 XtSetArg(args[j], XtNheight, bw_width/3); j++;
208 /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
209 XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
210 XtSetArg(args[j], XtNautoFill, False); j++;
212 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
214 if (cmailMsgLoaded && !mutable) {
216 XtSetArg(args[j], XtNfromVert, textw); j++;
217 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
218 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
219 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
220 XtSetArg(args[j], XtNright, XtChainRight); j++;
221 XtSetArg(args[j], XtNborderWidth, 0); j++;
222 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
223 XtSetArg(args[j], XtNlabel, msg); j++;
225 XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
231 XtSetArg(args[j], XtNfromVert, msgw); j++;
232 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
233 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
234 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
235 XtSetArg(args[j], XtNright, XtChainLeft); j++;
237 XtCreateManagedWidget(_("ok"), commandWidgetClass, form, args, j);
238 XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
241 XtSetArg(args[j], XtNfromVert, msgw); j++;
242 XtSetArg(args[j], XtNfromHoriz, b); j++;
243 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
244 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
245 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
246 XtSetArg(args[j], XtNright, XtChainLeft); j++;
248 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
249 XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
253 XtSetArg(args[j], XtNfromVert, msgw); j++;
254 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
255 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
256 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
257 XtSetArg(args[j], XtNright, XtChainLeft); j++;
259 XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
260 XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
263 XtSetArg(args[j], XtNfromVert, msgw); j++;
264 XtSetArg(args[j], XtNfromHoriz, b); j++;
265 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
266 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
267 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
268 XtSetArg(args[j], XtNright, XtChainLeft); j++;
270 XtCreateManagedWidget(_("edit"), commandWidgetClass, form, args, j);
271 XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
274 XtRealizeWidget(shell);
275 CatchDeleteWindow(shell, "TagsPopDown");
279 XtSetArg(args[j], XtNwidth, &bw_width); j++;
280 XtGetValues(boardWidget, args, j);
282 XtSetArg(args[j], XtNwidth, &pw_width); j++;
283 XtSetArg(args[j], XtNheight, &pw_height); j++;
284 XtGetValues(shell, args, j);
287 /* This code seems to tickle an X bug if it is executed too soon
288 after xboard starts up. The coordinates get transformed as if
289 the main window was positioned at (0, 0).
291 XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
292 0 - pw_height + squareSize / 3, &x, &y);
294 XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
295 RootWindowOfScreen(XtScreen(boardWidget)),
296 (bw_width - pw_width) / 2,
297 0 - pw_height + squareSize / 3, &xx, &yy, &junk);
301 if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
304 XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset); j++;
305 XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset); j++;
306 XtSetValues(shell, args, j);
307 XtSetKeyboardFocus(shell, textw);
313 void TagsPopUp(tags, msg)
320 if (editTagsUp) TagsPopDown();
321 if (tagsShell == NULL) {
323 TagsCreate(_("Tags"), tags, msg, False, TagsCallback);
325 textw = XtNameToWidget(tagsShell, "*form.text");
327 XtSetArg(args[j], XtNstring, tags); j++;
328 XtSetValues(textw, args, j);
330 XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags"); j++;
331 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Tags")); j++;
332 XtSetValues(tagsShell, args, j);
333 msgw = XtNameToWidget(tagsShell, "*form.msg");
336 XtSetArg(args[j], XtNlabel, msg); j++;
337 XtSetValues(msgw, args, j);
341 XtPopup(tagsShell, XtGrabNone);
342 XSync(xDisplay, False);
346 XtSetArg(args[j], XtNleftBitmap, None); j++;
347 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
352 void EditTagsPopUp(tags)
359 if (tagsUp) TagsPopDown();
360 if (editTagsShell == NULL) {
362 TagsCreate(_("Edit tags"), tags, NULL, True, EditTagsCallback);
364 textw = XtNameToWidget(editTagsShell, "*form.text");
366 XtSetArg(args[j], XtNstring, tags); j++;
367 XtSetValues(textw, args, j);
369 XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags"); j++;
370 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Edit Tags")); j++;
371 XtSetValues(editTagsShell, args, j);
374 XtPopup(editTagsShell, XtGrabNone);
378 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
379 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
391 } else if (editTagsUp) {
397 XtSetArg(args[j], XtNx, &tagsX); j++;
398 XtSetArg(args[j], XtNy, &tagsY); j++;
399 XtGetValues(w, args, j);
401 XSync(xDisplay, False);
402 tagsUp = editTagsUp = False;
404 XtSetArg(args[j], XtNleftBitmap, None); j++;
405 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
410 EditTagsProc(w, event, prms, nprms)
416 if (tagsUp) TagsPopDown();