2 * xedittags.c -- Tags edit window, part of X front end for XBoard
5 * Copyright 1995 Free Software Foundation, Inc.
7 * The following terms apply to the enhanced version of XBoard distributed
8 * by the Free Software Foundation:
9 * ------------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * ------------------------------------------------------------------------
25 * See the file ChangeLog for a revision history.
33 #include <sys/types.h>
38 #else /* not STDC_HEADERS */
39 extern char *getenv();
42 # else /* not HAVE_STRING_H */
44 # endif /* not HAVE_STRING_H */
45 #endif /* not STDC_HEADERS */
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/cursorfont.h>
56 #include <X11/Xaw3d/Dialog.h>
57 #include <X11/Xaw3d/Form.h>
58 #include <X11/Xaw3d/List.h>
59 #include <X11/Xaw3d/Label.h>
60 #include <X11/Xaw3d/SimpleMenu.h>
61 #include <X11/Xaw3d/SmeBSB.h>
62 #include <X11/Xaw3d/SmeLine.h>
63 #include <X11/Xaw3d/Box.h>
64 #include <X11/Xaw3d/MenuButton.h>
65 #include <X11/Xaw3d/Text.h>
66 #include <X11/Xaw3d/AsciiText.h>
67 #include <X11/Xaw3d/Viewport.h>
69 #include <X11/Xaw/Dialog.h>
70 #include <X11/Xaw/Form.h>
71 #include <X11/Xaw/List.h>
72 #include <X11/Xaw/Label.h>
73 #include <X11/Xaw/SimpleMenu.h>
74 #include <X11/Xaw/SmeBSB.h>
75 #include <X11/Xaw/SmeLine.h>
76 #include <X11/Xaw/Box.h>
77 #include <X11/Xaw/MenuButton.h>
78 #include <X11/Xaw/Text.h>
79 #include <X11/Xaw/AsciiText.h>
80 #include <X11/Xaw/Viewport.h>
87 #include "xedittags.h"
91 # define _(s) gettext (s)
92 # define N_(s) gettext_noop (s)
98 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
99 extern Display *xDisplay;
100 extern int squareSize;
101 extern Pixmap xMarkPixmap;
102 extern char *layoutName;
104 Position tagsX = -1, tagsY = -1;
105 int tagsUp = False, editTagsUp = False;
106 Widget tagsShell, editTagsShell;
108 static Arg layoutArgs[] = {
109 { XtNborderWidth, 0 },
110 { XtNdefaultDistance, 0 }
113 void TagsCallback(w, client_data, call_data)
115 XtPointer client_data, call_data;
122 XtSetArg(args[j], XtNlabel, &name); j++;
123 XtGetValues(w, args, j);
125 if (strcmp(name, _("close")) == 0) {
127 } else if (strcmp(name, _("edit")) == 0) {
134 void EditTagsCallback(w, client_data, call_data)
136 XtPointer client_data, call_data;
144 XtSetArg(args[j], XtNlabel, &name); j++;
145 XtGetValues(w, args, j);
147 if (strcmp(name, _("ok")) == 0) {
148 textw = XtNameToWidget(editTagsShell, "*form.text");
150 XtSetArg(args[j], XtNstring, &val); j++;
151 XtGetValues(textw, args, j);
152 ReplaceTags(val, &gameInfo);
154 } else if (strcmp(name, _("cancel")) == 0) {
156 } else if (strcmp(name, _("clear")) == 0) {
157 textw = XtNameToWidget(editTagsShell, "*form.text");
158 XtCallActionProc(textw, "select-all", NULL, NULL, 0);
159 XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
163 Widget TagsCreate(name, text, msg, mutable, callback)
164 char *name, *text, *msg;
165 int /*Boolean*/ mutable;
166 XtCallbackProc callback;
169 Widget shell, form, textw, msgw, layout;
170 Widget b_ok, b_cancel, b_close, b_edit, b;
171 Dimension bw_width, pw_width;
177 XtSetArg(args[j], XtNwidth, &bw_width); j++;
178 XtGetValues(boardWidget, args, j);
181 XtSetArg(args[j], XtNresizable, True); j++;
184 XtCreatePopupShell(name, topLevelShellWidgetClass,
185 shellWidget, args, j);
188 XtCreatePopupShell(name, transientShellWidgetClass,
189 shellWidget, args, j);
192 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
193 layoutArgs, XtNumber(layoutArgs));
195 XtSetArg(args[j], XtNborderWidth, 0); j++;
197 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
201 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
202 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
204 XtSetArg(args[j], XtNstring, text); j++;
205 XtSetArg(args[j], XtNtop, XtChainTop); j++;
206 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
207 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
208 XtSetArg(args[j], XtNright, XtRubber); j++;
209 XtSetArg(args[j], XtNresizable, True); j++;
210 XtSetArg(args[j], XtNwidth, bw_width/2); j++;
211 XtSetArg(args[j], XtNheight, bw_width/3); j++;
213 XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
215 /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
216 XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
218 XtSetArg(args[j], XtNautoFill, False); j++;
220 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
222 if (cmailMsgLoaded && !mutable) {
224 XtSetArg(args[j], XtNfromVert, textw); j++;
225 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
226 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
227 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
228 XtSetArg(args[j], XtNright, XtChainRight); j++;
229 XtSetArg(args[j], XtNborderWidth, 0); j++;
230 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
231 XtSetArg(args[j], XtNlabel, msg); j++;
233 XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
239 XtSetArg(args[j], XtNfromVert, msgw); j++;
240 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
241 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
242 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
243 XtSetArg(args[j], XtNright, XtChainLeft); j++;
245 XtCreateManagedWidget(_("ok"), commandWidgetClass, form, args, j);
246 XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
249 XtSetArg(args[j], XtNfromVert, msgw); j++;
250 XtSetArg(args[j], XtNfromHoriz, b); j++;
251 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
252 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
253 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
254 XtSetArg(args[j], XtNright, XtChainLeft); j++;
256 XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
257 XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
261 XtSetArg(args[j], XtNfromVert, msgw); j++;
262 XtSetArg(args[j], XtNfromHoriz, b); j++;
263 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
264 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
265 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
266 XtSetArg(args[j], XtNright, XtChainLeft); j++;
268 XtCreateManagedWidget("clear", commandWidgetClass, form, args, j);
269 XtAddCallback(b_clear, XtNcallback, callback, (XtPointer) 0);
273 XtSetArg(args[j], XtNfromVert, msgw); j++;
274 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
275 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
276 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
277 XtSetArg(args[j], XtNright, XtChainLeft); j++;
279 XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
280 XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
283 XtSetArg(args[j], XtNfromVert, msgw); j++;
284 XtSetArg(args[j], XtNfromHoriz, b); j++;
285 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
286 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
287 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
288 XtSetArg(args[j], XtNright, XtChainLeft); j++;
290 XtCreateManagedWidget(_("edit"), commandWidgetClass, form, args, j);
291 XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
294 XtRealizeWidget(shell);
295 CatchDeleteWindow(shell, "TagsPopDown");
299 XtSetArg(args[j], XtNwidth, &bw_width); j++;
300 XtGetValues(boardWidget, args, j);
302 XtSetArg(args[j], XtNwidth, &pw_width); j++;
303 XtSetArg(args[j], XtNheight, &pw_height); j++;
304 XtGetValues(shell, args, j);
307 /* This code seems to tickle an X bug if it is executed too soon
308 after xboard starts up. The coordinates get transformed as if
309 the main window was positioned at (0, 0).
311 XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
312 0 - pw_height + squareSize / 3, &x, &y);
314 XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
315 RootWindowOfScreen(XtScreen(boardWidget)),
316 (bw_width - pw_width) / 2,
317 0 - pw_height + squareSize / 3, &xx, &yy, &junk);
321 if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
324 XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset); j++;
325 XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset); j++;
326 XtSetValues(shell, args, j);
327 XtSetKeyboardFocus(shell, textw);
333 void TagsPopUp(tags, msg)
340 if (editTagsUp) TagsPopDown();
341 if (tagsShell == NULL) {
343 TagsCreate(_("Tags"), tags, msg, False, TagsCallback);
345 textw = XtNameToWidget(tagsShell, "*form.text");
347 XtSetArg(args[j], XtNstring, tags); j++;
348 XtSetValues(textw, args, j);
350 XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags"); j++;
351 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Tags")); j++;
352 XtSetValues(tagsShell, args, j);
353 msgw = XtNameToWidget(tagsShell, "*form.msg");
356 XtSetArg(args[j], XtNlabel, msg); j++;
357 XtSetValues(msgw, args, j);
361 XtPopup(tagsShell, XtGrabNone);
362 XSync(xDisplay, False);
366 XtSetArg(args[j], XtNleftBitmap, None); j++;
367 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
372 void EditTagsPopUp(tags)
379 if (tagsUp) TagsPopDown();
380 if (editTagsShell == NULL) {
382 TagsCreate(_("Edit tags"), tags, NULL, True, EditTagsCallback);
384 textw = XtNameToWidget(editTagsShell, "*form.text");
386 XtSetArg(args[j], XtNstring, tags); j++;
387 XtSetValues(textw, args, j);
389 XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags"); j++;
390 XtSetArg(args[j], XtNtitle, (XtArgVal) _("Edit Tags")); j++;
391 XtSetValues(editTagsShell, args, j);
394 XtPopup(editTagsShell, XtGrabNone);
398 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
399 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
411 } else if (editTagsUp) {
417 XtSetArg(args[j], XtNx, &tagsX); j++;
418 XtSetArg(args[j], XtNy, &tagsY); j++;
419 XtGetValues(w, args, j);
421 XSync(xDisplay, False);
422 tagsUp = editTagsUp = False;
424 XtSetArg(args[j], XtNleftBitmap, None); j++;
425 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
430 EditTagsProc(w, event, prms, nprms)
436 if (tagsUp) TagsPopDown();