2 * xedittags.c -- Tags edit window, part of X front end for XBoard
5 * Copyright 1995,2009 Free Software Foundation, Inc.
7 * ------------------------------------------------------------------------
9 * GNU XBoard is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
14 * GNU XBoard is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/. *
22 *------------------------------------------------------------------------
23 ** See the file ChangeLog for a revision history. */
30 #include <sys/types.h>
35 #else /* not STDC_HEADERS */
36 extern char *getenv();
39 # else /* not HAVE_STRING_H */
41 # endif /* not HAVE_STRING_H */
42 #endif /* not STDC_HEADERS */
48 #include <X11/Intrinsic.h>
49 #include <X11/StringDefs.h>
50 #include <X11/Shell.h>
51 #include <X11/cursorfont.h>
53 #include <X11/Xaw3d/Dialog.h>
54 #include <X11/Xaw3d/Form.h>
55 #include <X11/Xaw3d/List.h>
56 #include <X11/Xaw3d/Label.h>
57 #include <X11/Xaw3d/SimpleMenu.h>
58 #include <X11/Xaw3d/SmeBSB.h>
59 #include <X11/Xaw3d/SmeLine.h>
60 #include <X11/Xaw3d/Box.h>
61 #include <X11/Xaw3d/MenuButton.h>
62 #include <X11/Xaw3d/Text.h>
63 #include <X11/Xaw3d/AsciiText.h>
64 #include <X11/Xaw3d/Viewport.h>
66 #include <X11/Xaw/Dialog.h>
67 #include <X11/Xaw/Form.h>
68 #include <X11/Xaw/List.h>
69 #include <X11/Xaw/Label.h>
70 #include <X11/Xaw/SimpleMenu.h>
71 #include <X11/Xaw/SmeBSB.h>
72 #include <X11/Xaw/SmeLine.h>
73 #include <X11/Xaw/Box.h>
74 #include <X11/Xaw/MenuButton.h>
75 #include <X11/Xaw/Text.h>
76 #include <X11/Xaw/AsciiText.h>
77 #include <X11/Xaw/Viewport.h>
84 #include "xedittags.h"
88 # define _(s) gettext (s)
89 # define N_(s) gettext_noop (s)
95 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
96 extern Display *xDisplay;
97 extern int squareSize;
98 extern Pixmap xMarkPixmap;
99 extern char *layoutName;
101 Position tagsX = -1, tagsY = -1;
102 int tagsUp = False, editTagsUp = False;
103 Widget tagsShell, editTagsShell;
105 static Arg layoutArgs[] = {
106 { XtNborderWidth, 0 },
107 { XtNdefaultDistance, 0 }
110 void TagsCallback(w, client_data, call_data)
112 XtPointer client_data, call_data;
119 XtSetArg(args[j], XtNlabel, &name); j++;
120 XtGetValues(w, args, j);
122 if (strcmp(name, _("close")) == 0) {
124 } else if (strcmp(name, _("edit")) == 0) {
131 void EditTagsCallback(w, client_data, call_data)
133 XtPointer client_data, call_data;
141 XtSetArg(args[j], XtNlabel, &name); j++;
142 XtGetValues(w, args, j);
144 if (strcmp(name, _("ok")) == 0) {
145 textw = XtNameToWidget(editTagsShell, "*form.text");
147 XtSetArg(args[j], XtNstring, &val); j++;
148 XtGetValues(textw, args, j);
149 ReplaceTags(val, &gameInfo);
151 } else if (strcmp(name, _("cancel")) == 0) {
153 } else if (strcmp(name, _("clear")) == 0) {
154 textw = XtNameToWidget(editTagsShell, "*form.text");
155 XtCallActionProc(textw, "select-all", NULL, NULL, 0);
156 XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
160 Widget TagsCreate(name, text, msg, mutable, callback)
161 char *name, *text, *msg;
162 int /*Boolean*/ mutable;
163 XtCallbackProc callback;
166 Widget shell, form, textw, msgw, layout;
167 Widget b_ok, b_cancel, b_close, b_edit, b;
168 Dimension bw_width, pw_width;
174 XtSetArg(args[j], XtNwidth, &bw_width); j++;
175 XtGetValues(boardWidget, args, j);
178 XtSetArg(args[j], XtNresizable, True); j++;
181 XtCreatePopupShell(name, topLevelShellWidgetClass,
182 shellWidget, args, j);
185 XtCreatePopupShell(name, transientShellWidgetClass,
186 shellWidget, args, j);
189 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
190 layoutArgs, XtNumber(layoutArgs));
192 XtSetArg(args[j], XtNborderWidth, 0); j++;
194 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
198 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
199 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
201 XtSetArg(args[j], XtNstring, text); j++;
202 XtSetArg(args[j], XtNtop, XtChainTop); j++;
203 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
204 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
205 XtSetArg(args[j], XtNright, XtRubber); j++;
206 XtSetArg(args[j], XtNresizable, True); j++;
207 XtSetArg(args[j], XtNwidth, bw_width/2); j++;
208 XtSetArg(args[j], XtNheight, bw_width/3); j++;
210 XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
212 /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
213 XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
215 XtSetArg(args[j], XtNautoFill, False); j++;
217 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
219 if (cmailMsgLoaded && !mutable) {
221 XtSetArg(args[j], XtNfromVert, textw); j++;
222 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
223 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
224 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
225 XtSetArg(args[j], XtNright, XtChainRight); j++;
226 XtSetArg(args[j], XtNborderWidth, 0); j++;
227 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
228 XtSetArg(args[j], XtNlabel, msg); j++;
230 XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
236 XtSetArg(args[j], XtNfromVert, msgw); j++;
237 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
238 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
239 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
240 XtSetArg(args[j], XtNright, XtChainLeft); j++;
242 XtCreateManagedWidget(_("ok"), commandWidgetClass, form, args, j);
243 XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
246 XtSetArg(args[j], XtNfromVert, msgw); j++;
247 XtSetArg(args[j], XtNfromHoriz, b); j++;
248 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
249 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
250 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
251 XtSetArg(args[j], XtNright, XtChainLeft); j++;
253 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
254 XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
258 XtSetArg(args[j], XtNfromVert, msgw); j++;
259 XtSetArg(args[j], XtNfromHoriz, b); j++;
260 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
261 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
262 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
263 XtSetArg(args[j], XtNright, XtChainLeft); j++;
265 XtCreateManagedWidget("clear", commandWidgetClass, form, args, j);
266 XtAddCallback(b_clear, XtNcallback, callback, (XtPointer) 0);
270 XtSetArg(args[j], XtNfromVert, msgw); j++;
271 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
272 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
273 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
274 XtSetArg(args[j], XtNright, XtChainLeft); j++;
276 XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
277 XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
280 XtSetArg(args[j], XtNfromVert, msgw); j++;
281 XtSetArg(args[j], XtNfromHoriz, b); j++;
282 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
283 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
284 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
285 XtSetArg(args[j], XtNright, XtChainLeft); j++;
287 XtCreateManagedWidget(_("edit"), commandWidgetClass, form, args, j);
288 XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
291 XtRealizeWidget(shell);
292 CatchDeleteWindow(shell, "TagsPopDown");
296 XtSetArg(args[j], XtNwidth, &bw_width); j++;
297 XtGetValues(boardWidget, args, j);
299 XtSetArg(args[j], XtNwidth, &pw_width); j++;
300 XtSetArg(args[j], XtNheight, &pw_height); j++;
301 XtGetValues(shell, args, j);
304 /* This code seems to tickle an X bug if it is executed too soon
305 after xboard starts up. The coordinates get transformed as if
306 the main window was positioned at (0, 0).
308 XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
309 0 - pw_height + squareSize / 3, &x, &y);
311 XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
312 RootWindowOfScreen(XtScreen(boardWidget)),
313 (bw_width - pw_width) / 2,
314 0 - pw_height + squareSize / 3, &xx, &yy, &junk);
318 if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
321 XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset); j++;
322 XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset); j++;
323 XtSetValues(shell, args, j);
324 XtSetKeyboardFocus(shell, textw);
330 void TagsPopUp(tags, msg)
337 if (editTagsUp) TagsPopDown();
338 if (tagsShell == NULL) {
340 TagsCreate(_("Tags"), tags, msg, False, TagsCallback);
342 textw = XtNameToWidget(tagsShell, "*form.text");
344 XtSetArg(args[j], XtNstring, tags); j++;
345 XtSetValues(textw, args, j);
347 XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags"); j++;
348 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Tags")); j++;
349 XtSetValues(tagsShell, args, j);
350 msgw = XtNameToWidget(tagsShell, "*form.msg");
353 XtSetArg(args[j], XtNlabel, msg); j++;
354 XtSetValues(msgw, args, j);
358 XtPopup(tagsShell, XtGrabNone);
359 XSync(xDisplay, False);
363 XtSetArg(args[j], XtNleftBitmap, None); j++;
364 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
369 void EditTagsPopUp(tags)
376 if (tagsUp) TagsPopDown();
377 if (editTagsShell == NULL) {
379 TagsCreate(_("Edit tags"), tags, NULL, True, EditTagsCallback);
381 textw = XtNameToWidget(editTagsShell, "*form.text");
383 XtSetArg(args[j], XtNstring, tags); j++;
384 XtSetValues(textw, args, j);
386 XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags"); j++;
387 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Edit Tags")); j++;
388 XtSetValues(editTagsShell, args, j);
391 XtPopup(editTagsShell, XtGrabNone);
395 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
396 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
408 } else if (editTagsUp) {
414 XtSetArg(args[j], XtNx, &tagsX); j++;
415 XtSetArg(args[j], XtNy, &tagsY); j++;
416 XtGetValues(w, args, j);
418 XSync(xDisplay, False);
419 tagsUp = editTagsUp = False;
421 XtSetArg(args[j], XtNleftBitmap, None); j++;
422 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
427 EditTagsProc(w, event, prms, nprms)
433 if (tagsUp) TagsPopDown();