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"
89 extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
90 extern Display *xDisplay;
91 extern int squareSize;
92 extern Pixmap xMarkPixmap;
93 extern char *layoutName;
95 Position tagsX = -1, tagsY = -1;
96 int tagsUp = False, editTagsUp = False;
97 Widget tagsShell, editTagsShell;
99 static Arg layoutArgs[] = {
100 { XtNborderWidth, 0 },
101 { XtNdefaultDistance, 0 }
104 void TagsCallback(w, client_data, call_data)
106 XtPointer client_data, call_data;
113 XtSetArg(args[j], XtNlabel, &name); j++;
114 XtGetValues(w, args, j);
116 if (strcmp(name, "close") == 0) {
118 } else if (strcmp(name, "edit") == 0) {
125 void EditTagsCallback(w, client_data, call_data)
127 XtPointer client_data, call_data;
135 XtSetArg(args[j], XtNlabel, &name); j++;
136 XtGetValues(w, args, j);
138 if (strcmp(name, "ok") == 0) {
139 textw = XtNameToWidget(editTagsShell, "*form.text");
141 XtSetArg(args[j], XtNstring, &val); j++;
142 XtGetValues(textw, args, j);
143 ReplaceTags(val, &gameInfo);
145 } else if (strcmp(name, "cancel") == 0) {
147 } else if (strcmp(name, "clear") == 0) {
148 textw = XtNameToWidget(editTagsShell, "*form.text");
149 XtCallActionProc(textw, "select-all", NULL, NULL, 0);
150 XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
154 Widget TagsCreate(name, text, msg, mutable, callback)
155 char *name, *text, *msg;
156 int /*Boolean*/ mutable;
157 XtCallbackProc callback;
160 Widget shell, form, textw, msgw, layout;
161 Widget b_ok, b_cancel, b_close, b_edit, b;
162 Dimension bw_width, pw_width;
168 XtSetArg(args[j], XtNwidth, &bw_width); j++;
169 XtGetValues(boardWidget, args, j);
172 XtSetArg(args[j], XtNresizable, True); j++;
175 XtCreatePopupShell(name, topLevelShellWidgetClass,
176 shellWidget, args, j);
179 XtCreatePopupShell(name, transientShellWidgetClass,
180 shellWidget, args, j);
183 XtCreateManagedWidget(layoutName, formWidgetClass, shell,
184 layoutArgs, XtNumber(layoutArgs));
186 XtSetArg(args[j], XtNborderWidth, 0); j++;
188 XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
192 XtSetArg(args[j], XtNeditType, XawtextEdit); j++;
193 XtSetArg(args[j], XtNuseStringInPlace, False); j++;
195 XtSetArg(args[j], XtNstring, text); j++;
196 XtSetArg(args[j], XtNtop, XtChainTop); j++;
197 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
198 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
199 XtSetArg(args[j], XtNright, XtRubber); j++;
200 XtSetArg(args[j], XtNresizable, True); j++;
201 XtSetArg(args[j], XtNwidth, bw_width/2); j++;
202 XtSetArg(args[j], XtNheight, bw_width/3); j++;
204 XtSetArg(args[j], XtNscrollVertical, XawtextScrollWhenNeeded); j++;
206 /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
207 XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++;
209 XtSetArg(args[j], XtNautoFill, False); j++;
211 XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
213 if (cmailMsgLoaded && !mutable) {
215 XtSetArg(args[j], XtNfromVert, textw); j++;
216 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
217 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
218 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
219 XtSetArg(args[j], XtNright, XtChainRight); j++;
220 XtSetArg(args[j], XtNborderWidth, 0); j++;
221 XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
222 XtSetArg(args[j], XtNlabel, msg); j++;
224 XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
230 XtSetArg(args[j], XtNfromVert, msgw); j++;
231 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
232 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
233 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
234 XtSetArg(args[j], XtNright, XtChainLeft); j++;
236 XtCreateManagedWidget("ok", commandWidgetClass, form, args, j);
237 XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
240 XtSetArg(args[j], XtNfromVert, msgw); j++;
241 XtSetArg(args[j], XtNfromHoriz, b); j++;
242 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
243 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
244 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
245 XtSetArg(args[j], XtNright, XtChainLeft); j++;
247 XtCreateManagedWidget("cancel", commandWidgetClass, form, args, j);
248 XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
252 XtSetArg(args[j], XtNfromVert, msgw); j++;
253 XtSetArg(args[j], XtNfromHoriz, b); 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("clear", commandWidgetClass, form, args, j);
260 XtAddCallback(b_clear, XtNcallback, callback, (XtPointer) 0);
264 XtSetArg(args[j], XtNfromVert, msgw); 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("close", commandWidgetClass, form, args, j);
271 XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
274 XtSetArg(args[j], XtNfromVert, msgw); j++;
275 XtSetArg(args[j], XtNfromHoriz, b); j++;
276 XtSetArg(args[j], XtNtop, XtChainBottom); j++;
277 XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
278 XtSetArg(args[j], XtNleft, XtChainLeft); j++;
279 XtSetArg(args[j], XtNright, XtChainLeft); j++;
281 XtCreateManagedWidget("edit", commandWidgetClass, form, args, j);
282 XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
285 XtRealizeWidget(shell);
286 CatchDeleteWindow(shell, "TagsPopDown");
290 XtSetArg(args[j], XtNwidth, &bw_width); j++;
291 XtGetValues(boardWidget, args, j);
293 XtSetArg(args[j], XtNwidth, &pw_width); j++;
294 XtSetArg(args[j], XtNheight, &pw_height); j++;
295 XtGetValues(shell, args, j);
298 /* This code seems to tickle an X bug if it is executed too soon
299 after xboard starts up. The coordinates get transformed as if
300 the main window was positioned at (0, 0).
302 XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
303 0 - pw_height + squareSize / 3, &x, &y);
305 XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
306 RootWindowOfScreen(XtScreen(boardWidget)),
307 (bw_width - pw_width) / 2,
308 0 - pw_height + squareSize / 3, &xx, &yy, &junk);
312 if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
315 XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset); j++;
316 XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset); j++;
317 XtSetValues(shell, args, j);
318 XtSetKeyboardFocus(shell, textw);
324 void TagsPopUp(tags, msg)
331 if (editTagsUp) TagsPopDown();
332 if (tagsShell == NULL) {
334 TagsCreate("Tags", tags, msg, False, TagsCallback);
336 textw = XtNameToWidget(tagsShell, "*form.text");
338 XtSetArg(args[j], XtNstring, tags); j++;
339 XtSetValues(textw, args, j);
341 XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags"); j++;
342 XtSetArg(args[j], XtNtitle, (XtArgVal) "Tags"); j++;
343 XtSetValues(tagsShell, args, j);
344 msgw = XtNameToWidget(tagsShell, "*form.msg");
347 XtSetArg(args[j], XtNlabel, msg); j++;
348 XtSetValues(msgw, args, j);
352 XtPopup(tagsShell, XtGrabNone);
353 XSync(xDisplay, False);
357 XtSetArg(args[j], XtNleftBitmap, None); j++;
358 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
363 void EditTagsPopUp(tags)
370 if (tagsUp) TagsPopDown();
371 if (editTagsShell == NULL) {
373 TagsCreate("Edit tags", tags, NULL, True, EditTagsCallback);
375 textw = XtNameToWidget(editTagsShell, "*form.text");
377 XtSetArg(args[j], XtNstring, tags); j++;
378 XtSetValues(textw, args, j);
380 XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags"); j++;
381 XtSetArg(args[j], XtNtitle, (XtArgVal) "Edit Tags"); j++;
382 XtSetValues(editTagsShell, args, j);
385 XtPopup(editTagsShell, XtGrabNone);
389 XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
390 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
402 } else if (editTagsUp) {
408 XtSetArg(args[j], XtNx, &tagsX); j++;
409 XtSetArg(args[j], XtNy, &tagsY); j++;
410 XtGetValues(w, args, j);
412 XSync(xDisplay, False);
413 tagsUp = editTagsUp = False;
415 XtSetArg(args[j], XtNleftBitmap, None); j++;
416 XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
421 EditTagsProc(w, event, prms, nprms)
427 if (tagsUp) TagsPopDown();