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++;
209 XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
211 /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
212 XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
214 XtSetArg(args[j], XtNautoFill, False); j++;
216 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
218 if (cmailMsgLoaded && !mutable) {
220 XtSetArg(args[j], XtNfromVert, textw); j++;
221 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
222 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
223 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
224 XtSetArg(args[j], XtNright, XtChainRight); j++;
225 XtSetArg(args[j], XtNborderWidth, 0); j++;
226 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
227 XtSetArg(args[j], XtNlabel, msg); j++;
229 XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
235 XtSetArg(args[j], XtNfromVert, msgw); j++;
236 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
237 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
238 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
239 XtSetArg(args[j], XtNright, XtChainLeft); j++;
241 XtCreateManagedWidget(_("ok"), commandWidgetClass, form, args, j);
242 XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
245 XtSetArg(args[j], XtNfromVert, msgw); j++;
246 XtSetArg(args[j], XtNfromHoriz, b); j++;
247 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
248 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
249 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
250 XtSetArg(args[j], XtNright, XtChainLeft); j++;
252 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
253 XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
257 XtSetArg(args[j], XtNfromVert, msgw); j++;
258 XtSetArg(args[j], XtNfromHoriz, b); j++;
259 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
260 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
261 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
262 XtSetArg(args[j], XtNright, XtChainLeft); j++;
264 XtCreateManagedWidget("clear", commandWidgetClass, form, args, j);
265 XtAddCallback(b_clear, XtNcallback, callback, (XtPointer) 0);
269 XtSetArg(args[j], XtNfromVert, msgw); j++;
270 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
271 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
272 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
273 XtSetArg(args[j], XtNright, XtChainLeft); j++;
275 XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
276 XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
279 XtSetArg(args[j], XtNfromVert, msgw); j++;
280 XtSetArg(args[j], XtNfromHoriz, b); j++;
281 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
282 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
283 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
284 XtSetArg(args[j], XtNright, XtChainLeft); j++;
286 XtCreateManagedWidget(_("edit"), commandWidgetClass, form, args, j);
287 XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
290 XtRealizeWidget(shell);
291 CatchDeleteWindow(shell, "TagsPopDown");
295 XtSetArg(args[j], XtNwidth, &bw_width); j++;
296 XtGetValues(boardWidget, args, j);
298 XtSetArg(args[j], XtNwidth, &pw_width); j++;
299 XtSetArg(args[j], XtNheight, &pw_height); j++;
300 XtGetValues(shell, args, j);
303 /* This code seems to tickle an X bug if it is executed too soon
304 after xboard starts up. The coordinates get transformed as if
305 the main window was positioned at (0, 0).
307 XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
308 0 - pw_height + squareSize / 3, &x, &y);
310 XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
311 RootWindowOfScreen(XtScreen(boardWidget)),
312 (bw_width - pw_width) / 2,
313 0 - pw_height + squareSize / 3, &xx, &yy, &junk);
317 if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
320 XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset); j++;
321 XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset); j++;
322 XtSetValues(shell, args, j);
323 XtSetKeyboardFocus(shell, textw);
329 void TagsPopUp(tags, msg)
336 if (editTagsUp) TagsPopDown();
337 if (tagsShell == NULL) {
339 TagsCreate(_("Tags"), tags, msg, False, TagsCallback);
341 textw = XtNameToWidget(tagsShell, "*form.text");
343 XtSetArg(args[j], XtNstring, tags); j++;
344 XtSetValues(textw, args, j);
346 XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags"); j++;
347 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Tags")); j++;
348 XtSetValues(tagsShell, args, j);
349 msgw = XtNameToWidget(tagsShell, "*form.msg");
352 XtSetArg(args[j], XtNlabel, msg); j++;
353 XtSetValues(msgw, args, j);
357 XtPopup(tagsShell, XtGrabNone);
358 XSync(xDisplay, False);
362 XtSetArg(args[j], XtNleftBitmap, None); j++;
363 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
368 void EditTagsPopUp(tags)
375 if (tagsUp) TagsPopDown();
376 if (editTagsShell == NULL) {
378 TagsCreate(_("Edit tags"), tags, NULL, True, EditTagsCallback);
380 textw = XtNameToWidget(editTagsShell, "*form.text");
382 XtSetArg(args[j], XtNstring, tags); j++;
383 XtSetValues(textw, args, j);
385 XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags"); j++;
386 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Edit Tags")); j++;
387 XtSetValues(editTagsShell, args, j);
390 XtPopup(editTagsShell, XtGrabNone);
394 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
395 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
407 } else if (editTagsUp) {
413 XtSetArg(args[j], XtNx, &tagsX); j++;
414 XtSetArg(args[j], XtNy, &tagsY); j++;
415 XtGetValues(w, args, j);
417 XSync(xDisplay, False);
418 tagsUp = editTagsUp = False;
420 XtSetArg(args[j], XtNleftBitmap, None); j++;
421 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
426 EditTagsProc(w, event, prms, nprms)
432 if (tagsUp) TagsPopDown();