Fix hang caused by posting the "reload" dialog box on a hidden window (during
[nedit.git] / source / windowTitle.c
blobe28d97a278b5b4f323402b72378989213ecf93c9
1 static const char CVSID[] = "$Id: windowTitle.c,v 1.8 2002/07/11 21:18:12 slobasso Exp $";
2 /*******************************************************************************
3 * *
4 * windowTitle.c -- Nirvana Editor window title customization *
5 * *
6 * Copyright (C) 2001, Arne Forlie *
7 * *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
11 * version. *
12 * *
13 * This software is distributed in the hope that it will be useful, but WITHOUT *
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
16 * for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License along with *
19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
20 * Place, Suite 330, Boston, MA 02111-1307 USA *
21 * *
22 * Nirvana Text Editor *
23 * July 31, 2001 *
24 * *
25 * Written by Arne Forlie, http://arne.forlie.com *
26 * *
27 *******************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 #include "../config.h"
31 #endif
33 #include "windowTitle.h"
34 #include "textBuf.h"
35 #include "nedit.h"
36 #include "preferences.h"
37 #include "help.h"
38 #include "../util/prefFile.h"
39 #include "../util/misc.h"
40 #include "../util/DialogF.h"
41 #include "../util/utils.h"
42 #include "../util/fileUtils.h"
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <ctype.h>
47 #include <string.h>
48 #ifdef VMS
49 #include "../util/VMSparam.h"
50 #else
51 #ifndef __MVS__
52 #include <sys/param.h>
53 #endif
54 #include "../util/clearcase.h"
55 #endif /*VMS*/
57 #include <Xm/Xm.h>
58 #include <Xm/SelectioB.h>
59 #include <Xm/Form.h>
60 #include <Xm/List.h>
61 #include <Xm/SeparatoG.h>
62 #include <Xm/LabelG.h>
63 #include <Xm/PushBG.h>
64 #include <Xm/PushB.h>
65 #include <Xm/ToggleBG.h>
66 #include <Xm/ToggleB.h>
67 #include <Xm/RowColumn.h>
68 #include <Xm/CascadeBG.h>
69 #include <Xm/Frame.h>
70 #include <Xm/Text.h>
71 #include <Xm/TextF.h>
73 #ifdef HAVE_DEBUG_H
74 #include "../debug.h"
75 #endif
78 #define WINDOWTITLE_MAX_LEN 500
80 /* Customize window title dialog information */
81 static struct {
82 Widget form;
83 Widget shell;
84 WindowInfo* window;
85 Widget previewW;
86 Widget formatW;
88 Widget ccW;
89 Widget fileW;
90 Widget hostW;
91 Widget dirW;
92 Widget statusW;
93 Widget shortStatusW;
94 Widget serverW;
95 Widget nameW;
96 Widget mdirW;
97 Widget ndirW;
99 Widget oDirW;
100 Widget oCcViewTagW;
101 Widget oServerNameW;
102 Widget oFileChangedW;
103 Widget oFileLockedW;
104 Widget oFileReadOnlyW;
105 Widget oServerEqualViewW;
107 char filename[MAXPATHLEN];
108 char path[MAXPATHLEN];
109 char viewTag[MAXPATHLEN];
110 char serverName[MAXPATHLEN];
111 int isServer;
112 int filenameSet;
113 int lockReasons;
114 int fileChanged;
116 int suppressFormatUpdate;
117 } etDialog = {NULL};
121 static char* removeSequence(char* sourcePtr, char c)
123 while (*sourcePtr == c) {
124 sourcePtr++;
126 return(sourcePtr);
131 ** Two functions for performing safe insertions into a finite
132 ** size buffer so that we don't get any memory overruns.
134 static char* safeStrCpy(char* dest, char* destEnd, const char* source)
136 int len = (int)strlen(source);
137 if (len <= (destEnd - dest)) {
138 strcpy(dest, source);
139 return(dest + len);
141 else {
142 strncpy(dest, source, destEnd - dest);
143 *destEnd = '\0';
144 return(destEnd);
148 static char* safeCharAdd(char* dest, char* destEnd, char c)
150 if (destEnd - dest > 0)
152 *dest++ = c;
153 *dest = '\0';
155 return(dest);
159 ** Remove empty paranthesis pairs and multiple spaces in a row
160 ** with one space.
161 ** Also remove leading and trailing spaces and dashes.
163 static void compressWindowTitle(char *title)
165 /* Compress the title */
166 int modified;
167 do {
168 char *sourcePtr = title;
169 char *destPtr = sourcePtr;
170 char c = *sourcePtr++;
172 modified = False;
174 /* Remove leading spaces and dashes */
175 while (c == ' ' || c == '-') {
176 c= *sourcePtr++;
179 /* Remove empty constructs */
180 while (c != '\0') {
181 switch (c) {
182 /* remove sequences */
183 case ' ':
184 case '-':
185 sourcePtr = removeSequence(sourcePtr, c);
186 *destPtr++ = c; /* leave one */
187 break;
189 /* remove empty paranthesis pairs */
190 case '(':
191 if (*sourcePtr == ')') {
192 modified = True;
193 sourcePtr++;
195 else *destPtr++ = c;
196 sourcePtr = removeSequence(sourcePtr, ' ');
197 break;
199 case '[':
200 if (*sourcePtr == ']') {
201 modified = True;
202 sourcePtr++;
204 else *destPtr++ = c;
205 sourcePtr = removeSequence(sourcePtr, ' ');
206 break;
208 case '{':
209 if (*sourcePtr == '}') {
210 modified = True;
211 sourcePtr++;
213 else *destPtr++ = c;
214 sourcePtr = removeSequence(sourcePtr, ' ');
215 break;
217 default:
218 *destPtr++ = c;
219 break;
221 c = *sourcePtr++;
222 *destPtr = '\0';
225 /* Remove trailing spaces and dashes */
226 while (destPtr-- > title) {
227 if (*destPtr != ' ' && *destPtr != '-')
228 break;
229 *destPtr = '\0';
231 } while (modified == True);
236 ** Format the windows title using a printf like formatting string.
237 ** The following flags are recognised:
238 ** %c : ClearCase view tag
239 ** %s : server name
240 ** %[n]d : directory, with one optional digit specifying the max number
241 ** of trailing directory components to display. Skipped components are
242 ** replaced by an ellipsis (...).
243 ** %f : file name
244 ** %h : host name
245 ** %S : file status
246 ** %u : user name
248 ** if the ClearCase view tag and server name are identical, only the first one
249 ** specified in the formatting string will be displayed.
251 char *FormatWindowTitle(const char* filename,
252 const char* path,
253 const char* clearCaseViewTag,
254 const char* serverName,
255 int isServer,
256 int filenameSet,
257 int lockReasons,
258 int fileChanged,
259 const char* titleFormat)
261 static char title[WINDOWTITLE_MAX_LEN];
262 char *titlePtr = title;
263 char* titleEnd = title + WINDOWTITLE_MAX_LEN - 1;
266 /* Flags to supress one of these if both are specified and they are identical */
267 int serverNameSeen = False;
268 int clearCaseViewTagSeen = False;
270 int fileNamePresent = False;
271 int hostNamePresent = False;
272 int userNamePresent = False;
273 int serverNamePresent = False;
274 int clearCasePresent = False;
275 int fileStatusPresent = False;
276 int dirNamePresent = False;
277 int noOfComponents = -1;
278 int shortStatus = False;
280 *titlePtr = '\0'; /* always start with an empty string */
282 while (*titleFormat != '\0' && titlePtr < titleEnd) {
283 char c = *titleFormat++;
284 if (c == '%') {
285 c = *titleFormat++;
286 if (c == '\0')
288 titlePtr = safeCharAdd(titlePtr, titleEnd, '%');
289 break;
291 switch (c) {
292 case 'c': /* ClearCase view tag */
293 clearCasePresent = True;
294 if (clearCaseViewTag != NULL) {
295 if (serverNameSeen == False ||
296 strcmp(serverName, clearCaseViewTag) != 0) {
297 titlePtr = safeStrCpy(titlePtr, titleEnd, clearCaseViewTag);
298 clearCaseViewTagSeen = True;
301 break;
303 case 's': /* server name */
304 serverNamePresent = True;
305 if (isServer && serverName[0] != '\0') { /* only applicable for servers */
306 if (clearCaseViewTagSeen == False ||
307 strcmp(serverName, clearCaseViewTag) != 0) {
308 titlePtr = safeStrCpy(titlePtr, titleEnd, serverName);
309 serverNameSeen = True;
312 break;
314 case 'd': /* directory without any limit to no. of components */
315 dirNamePresent = True;
316 if (filenameSet) {
317 titlePtr = safeStrCpy(titlePtr, titleEnd, path);
319 break;
321 case '0': /* directory with limited no. of components */
322 case '1':
323 case '2':
324 case '3':
325 case '4':
326 case '5':
327 case '6':
328 case '7':
329 case '8':
330 case '9':
331 if (*titleFormat == 'd') {
332 dirNamePresent = True;
333 noOfComponents = c - '0';
334 titleFormat++; /* delete the argument */
336 if (filenameSet) {
337 const char* trailingPath = GetTrailingPathComponents(path,
338 noOfComponents);
340 /* prefix with ellipsis if components were skipped */
341 if (trailingPath > path) {
342 titlePtr = safeStrCpy(titlePtr, titleEnd, "...");
344 titlePtr = safeStrCpy(titlePtr, titleEnd, trailingPath);
347 break;
349 case 'f': /* file name */
350 fileNamePresent = True;
351 titlePtr = safeStrCpy(titlePtr, titleEnd, filename);
352 break;
354 case 'h': /* host name */
355 hostNamePresent = True;
356 titlePtr = safeStrCpy(titlePtr, titleEnd, GetNameOfHost());
357 break;
359 case 'S': /* file status */
360 fileStatusPresent = True;
361 if (IS_ANY_LOCKED_IGNORING_USER(lockReasons) && fileChanged)
362 titlePtr = safeStrCpy(titlePtr, titleEnd, "read only, modified");
363 else if (IS_ANY_LOCKED_IGNORING_USER(lockReasons))
364 titlePtr = safeStrCpy(titlePtr, titleEnd, "read only");
365 else if (IS_USER_LOCKED(lockReasons) && fileChanged)
366 titlePtr = safeStrCpy(titlePtr, titleEnd, "locked, modified");
367 else if (IS_USER_LOCKED(lockReasons))
368 titlePtr = safeStrCpy(titlePtr, titleEnd, "locked");
369 else if (fileChanged)
370 titlePtr = safeStrCpy(titlePtr, titleEnd, "modified");
371 break;
373 case 'u': /* user name */
374 userNamePresent = True;
375 titlePtr = safeStrCpy(titlePtr, titleEnd, GetUserName());
376 break;
378 case '%': /* escaped % */
379 titlePtr = safeCharAdd(titlePtr, titleEnd, '%');
380 break;
382 case '*': /* short file status ? */
383 fileStatusPresent = True;
384 if (*titleFormat && *titleFormat == 'S')
386 ++titleFormat;
387 shortStatus = True;
388 if (IS_ANY_LOCKED_IGNORING_USER(lockReasons) && fileChanged)
389 titlePtr = safeStrCpy(titlePtr, titleEnd, "RO*");
390 else if (IS_ANY_LOCKED_IGNORING_USER(lockReasons))
391 titlePtr = safeStrCpy(titlePtr, titleEnd, "RO");
392 else if (IS_USER_LOCKED(lockReasons) && fileChanged)
393 titlePtr = safeStrCpy(titlePtr, titleEnd, "LO*");
394 else if (IS_USER_LOCKED(lockReasons))
395 titlePtr = safeStrCpy(titlePtr, titleEnd, "LO");
396 else if (fileChanged)
397 titlePtr = safeStrCpy(titlePtr, titleEnd, "*");
398 break;
400 /* fall-through */
401 default:
402 titlePtr = safeCharAdd(titlePtr, titleEnd, c);
403 break;
406 else {
407 titlePtr = safeCharAdd(titlePtr, titleEnd, c);
411 compressWindowTitle(title);
413 if (title[0] == 0)
415 sprintf(&title[0], "<empty>"); /* For preview purposes only */
418 if (etDialog.form)
420 /* Prevent recursive callback loop */
421 etDialog.suppressFormatUpdate = True;
423 /* Sync radio buttons with format string (in case the user entered
424 the format manually) */
425 XmToggleButtonSetState(etDialog.fileW, fileNamePresent, False);
426 XmToggleButtonSetState(etDialog.statusW, fileStatusPresent, False);
427 XmToggleButtonSetState(etDialog.serverW, serverNamePresent, False);
428 #ifndef VMS
429 XmToggleButtonSetState(etDialog.ccW, clearCasePresent, False);
430 #endif /* VMS */
431 XmToggleButtonSetState(etDialog.dirW, dirNamePresent, False);
432 XmToggleButtonSetState(etDialog.hostW, hostNamePresent, False);
433 XmToggleButtonSetState(etDialog.nameW, userNamePresent, False);
435 XtSetSensitive(etDialog.shortStatusW, fileStatusPresent);
436 if (fileStatusPresent)
438 XmToggleButtonSetState(etDialog.shortStatusW, shortStatus, False);
441 /* Directory components are also sensitive to presence of dir */
442 XtSetSensitive(etDialog.ndirW, dirNamePresent);
443 XtSetSensitive(etDialog.mdirW, dirNamePresent);
445 if (dirNamePresent) /* Avoid erasing number when not active */
447 if (noOfComponents >= 0)
449 char* value = XmTextGetString(etDialog.ndirW);
450 char buf[2];
451 sprintf(&buf[0], "%d", noOfComponents);
452 if (strcmp(&buf[0], value)) /* Don't overwrite unless diff. */
453 SetIntText(etDialog.ndirW, noOfComponents);
454 XtFree(value);
456 else
458 XmTextSetString(etDialog.ndirW, "");
462 /* Enable/disable test buttons, depending on presence of codes */
463 XtSetSensitive(etDialog.oFileChangedW, fileStatusPresent);
464 XtSetSensitive(etDialog.oFileReadOnlyW, fileStatusPresent);
465 XtSetSensitive(etDialog.oFileLockedW, fileStatusPresent &&
466 !IS_PERM_LOCKED(etDialog.lockReasons));
468 XtSetSensitive(etDialog.oServerNameW, serverNamePresent);
470 #ifndef VMS
471 XtSetSensitive(etDialog.oCcViewTagW, clearCasePresent);
472 XtSetSensitive(etDialog.oServerEqualViewW, clearCasePresent &&
473 serverNamePresent);
474 #endif /* VMS */
476 XtSetSensitive(etDialog.oDirW, dirNamePresent);
478 etDialog.suppressFormatUpdate = False;
481 return(title);
486 /* a utility that sets the values of all toggle buttons */
487 static void setToggleButtons(void)
489 XmToggleButtonSetState(etDialog.oDirW,
490 etDialog.filenameSet == True, False);
491 XmToggleButtonSetState(etDialog.oFileChangedW,
492 etDialog.fileChanged == True, False);
493 XmToggleButtonSetState(etDialog.oFileReadOnlyW,
494 IS_PERM_LOCKED(etDialog.lockReasons), False);
495 XmToggleButtonSetState(etDialog.oFileLockedW,
496 IS_USER_LOCKED(etDialog.lockReasons), False);
497 /* Read-only takes precedence on locked */
498 XtSetSensitive(etDialog.oFileLockedW, !IS_PERM_LOCKED(etDialog.lockReasons));
500 #ifdef VMS
501 XmToggleButtonSetState(etDialog.oServerNameW, etDialog.isServer, False);
502 #else
503 XmToggleButtonSetState(etDialog.oCcViewTagW,
504 GetClearCaseViewTag() != NULL, False);
505 XmToggleButtonSetState(etDialog.oServerNameW,
506 etDialog.isServer, False);
508 if (GetClearCaseViewTag() != NULL &&
509 etDialog.isServer &&
510 GetPrefServerName()[0] != '\0' &&
511 strcmp(GetClearCaseViewTag(), GetPrefServerName()) == 0) {
512 XmToggleButtonSetState(etDialog.oServerEqualViewW,
513 True, False);
514 } else {
515 XmToggleButtonSetState(etDialog.oServerEqualViewW,
516 False, False);
518 #endif /* VMS */
521 static void formatChangedCB(Widget w, XtPointer clientData, XtPointer callData)
523 char *format;
524 int filenameSet = XmToggleButtonGetState(etDialog.oDirW);
525 char *title;
526 const char* serverName;
528 if (etDialog.suppressFormatUpdate)
530 return; /* Prevent recursive feedback */
533 format = XmTextGetString(etDialog.formatW);
535 #ifndef VMS
536 if (XmToggleButtonGetState(etDialog.oServerEqualViewW) &&
537 XmToggleButtonGetState(etDialog.ccW)) {
538 serverName = etDialog.viewTag;
539 } else
540 #endif /* VMS */
542 serverName = XmToggleButtonGetState(etDialog.oServerNameW) ?
543 etDialog.serverName : "";
546 title = FormatWindowTitle(
547 etDialog.filename,
548 etDialog.filenameSet == True ?
549 etDialog.path :
550 "/a/very/long/path/used/as/example/",
551 #ifdef VMS
552 NULL,
553 #else
554 XmToggleButtonGetState(etDialog.oCcViewTagW) ?
555 etDialog.viewTag : NULL,
556 #endif /* VMS */
557 serverName,
558 etDialog.isServer,
559 filenameSet,
560 etDialog.lockReasons,
561 XmToggleButtonGetState(etDialog.oFileChangedW),
562 format);
563 XtFree(format);
564 XmTextFieldSetString(etDialog.previewW, title);
567 #ifndef VMS
568 static void ccViewTagCB(Widget w, XtPointer clientData, XtPointer callData)
570 if (XmToggleButtonGetState(w) == False) {
571 XmToggleButtonSetState(etDialog.oServerEqualViewW, False, False);
573 formatChangedCB(w, clientData, callData);
575 #endif /* VMS */
577 static void serverNameCB(Widget w, XtPointer clientData, XtPointer callData)
579 if (XmToggleButtonGetState(w) == False) {
580 XmToggleButtonSetState(etDialog.oServerEqualViewW, False, False);
582 etDialog.isServer = XmToggleButtonGetState(w);
583 formatChangedCB(w, clientData, callData);
586 static void fileChangedCB(Widget w, XtPointer clientData, XtPointer callData)
588 etDialog.fileChanged = XmToggleButtonGetState(w);
589 formatChangedCB(w, clientData, callData);
592 static void fileLockedCB(Widget w, XtPointer clientData, XtPointer callData)
594 SET_USER_LOCKED(etDialog.lockReasons, XmToggleButtonGetState(w));
595 formatChangedCB(w, clientData, callData);
598 static void fileReadOnlyCB(Widget w, XtPointer clientData, XtPointer callData)
600 SET_PERM_LOCKED(etDialog.lockReasons, XmToggleButtonGetState(w));
601 formatChangedCB(w, clientData, callData);
604 #ifndef VMS
605 static void serverEqualViewCB(Widget w, XtPointer clientData, XtPointer callData)
607 if (XmToggleButtonGetState(w) == True) {
608 XmToggleButtonSetState(etDialog.oCcViewTagW, True, False);
609 XmToggleButtonSetState(etDialog.oServerNameW, True, False);
610 etDialog.isServer = True;
612 formatChangedCB(w, clientData, callData);
614 #endif /* VMS */
616 static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
618 char *format = XmTextGetString(etDialog.formatW);
620 /* pop down the dialog */
621 /* XtUnmanageChild(etDialog.form); */
623 if (strcmp(format, GetPrefTitleFormat()) != 0) {
624 SetPrefTitleFormat(format);
626 XtFree(format);
629 static void dismissCB(Widget w, XtPointer clientData, XtPointer callData)
631 /* pop down the dialog */
632 XtUnmanageChild(etDialog.form);
635 static void restoreCB(Widget w, XtPointer clientData, XtPointer callData)
637 XmTextSetString(etDialog.formatW, "{%c} [%s] %f (%S) - %d");
640 static void helpCB(Widget w, XtPointer clientData, XtPointer callData)
642 Help(etDialog.form, HELP_CUSTOM_TITLE_DIALOG);
645 static void wtDestroyCB(Widget w, XtPointer clientData, XtPointer callData)
647 if (w == etDialog.form) /* Prevent disconnecting the replacing dialog */
648 etDialog.form = NULL;
651 static void wtUnmapCB(Widget w, XtPointer clientData, XtPointer callData)
653 if (etDialog.form == w) /* Prevent destroying the replacing dialog */
654 XtDestroyWidget(etDialog.form);
657 static void appendToFormat(const char* string)
659 char *format = XmTextGetString(etDialog.formatW);
660 char *buf = XtMalloc(strlen(string) + strlen(format) + 1);
661 strcpy(buf, format);
662 strcat(buf, string);
663 XmTextSetString(etDialog.formatW, buf);
664 XtFree(format);
665 XtFree(buf);
668 static void removeFromFormat(const char* string)
670 char *format = XmTextGetString(etDialog.formatW);
671 char* pos;
673 /* There can be multiple occurences */
674 while ((pos = strstr(format, string)))
676 /* If the string is preceded or followed by a brace, include
677 the brace(s) for removal */
678 char* start = pos;
679 char* end = pos + strlen(string);
680 char post = *end;
682 if (post == '}' || post == ')' || post == ']' || post == '>')
684 end += 1;
685 post = *end;
688 if (start > format)
690 char pre = *(start-1);
691 if (pre == '{' || pre == '(' || pre == '[' || pre == '<')
692 start -= 1;
694 if (start > format)
696 char pre = *(start-1);
697 /* If there is a space in front and behind, remove one space
698 (there can be more spaces, but in that case it is likely
699 that the user entered them manually); also remove trailing
700 space */
701 if (pre == ' ' && post == ' ')
703 end += 1;
705 else if (pre == ' ' && post == (char)0)
707 /* Remove (1) trailing space */
708 start -= 1;
712 /* Contract the string: move end to start */
713 strcpy(start, end);
716 /* Remove leading and trailing space */
717 pos = format;
718 while (*pos == ' ') ++pos;
719 strcpy(format, pos);
721 pos = format + strlen(format) - 1;
722 while (pos >= format && *pos == ' ')
724 --pos;
726 *(pos+1) = (char)0;
728 XmTextSetString(etDialog.formatW, format);
729 XtFree(format);
733 static void toggleFileCB(Widget w, XtPointer clientData, XtPointer callData)
735 if (XmToggleButtonGetState(etDialog.fileW))
736 appendToFormat(" %f");
737 else
738 removeFromFormat("%f");
741 static void toggleServerCB(Widget w, XtPointer clientData, XtPointer callData)
743 if (XmToggleButtonGetState(etDialog.serverW))
744 appendToFormat(" [%s]");
745 else
746 removeFromFormat("%s");
749 static void toggleHostCB(Widget w, XtPointer clientData, XtPointer callData)
751 if (XmToggleButtonGetState(etDialog.hostW))
752 appendToFormat(" [%h]");
753 else
754 removeFromFormat("%h");
757 #ifndef VMS
758 static void toggleClearCaseCB(Widget w, XtPointer clientData, XtPointer callData)
760 if (XmToggleButtonGetState(etDialog.ccW))
761 appendToFormat(" {%c}");
762 else
763 removeFromFormat("%c");
765 #endif /* VMS */
767 static void toggleStatusCB(Widget w, XtPointer clientData, XtPointer callData)
769 if (XmToggleButtonGetState(etDialog.statusW))
771 if (XmToggleButtonGetState(etDialog.shortStatusW))
772 appendToFormat(" (%*S)");
773 else
774 appendToFormat(" (%S)");
776 else
778 removeFromFormat("%S");
779 removeFromFormat("%*S");
783 static void toggleShortStatusCB(Widget w, XtPointer clientData, XtPointer callData)
785 char *format, *pos;
787 if (etDialog.suppressFormatUpdate)
789 return;
792 format = XmTextGetString(etDialog.formatW);
794 if (XmToggleButtonGetState(etDialog.shortStatusW))
796 /* Find all %S occurrences and replace them by %*S */
799 pos = strstr(format, "%S");
800 if (pos)
802 char* tmp = (char*)XtMalloc((strlen(format)+2)*sizeof(char));
803 strncpy(tmp, format, (size_t)(pos-format+1));
804 tmp[pos-format+1] = 0;
805 strcat(tmp, "*");
806 strcat(tmp, pos+1);
807 XtFree(format);
808 format = tmp;
811 while (pos);
813 else
815 /* Replace all %*S occurences by %S */
818 pos = strstr(format, "%*S");
819 if (pos)
821 strcpy(pos+1, pos+2);
824 while(pos);
827 XmTextSetString(etDialog.formatW, format);
828 XtFree(format);
831 static void toggleUserCB(Widget w, XtPointer clientData, XtPointer callData)
833 if (XmToggleButtonGetState(etDialog.nameW))
834 appendToFormat(" %u");
835 else
836 removeFromFormat("%u");
839 static void toggleDirectoryCB(Widget w, XtPointer clientData, XtPointer callData)
841 if (XmToggleButtonGetState(etDialog.dirW))
843 char buf[20];
844 int maxComp;
845 char *value = XmTextGetString(etDialog.ndirW);
846 if (*value)
848 if (sscanf(value, "%d", &maxComp) > 0)
850 sprintf(&buf[0], " %%%dd ", maxComp);
852 else
854 sprintf(&buf[0], " %%d "); /* Should not be necessary */
857 else
859 sprintf(&buf[0], " %%d ");
861 XtFree(value);
862 appendToFormat(buf);
864 else
866 int i;
867 removeFromFormat("%d");
868 for (i=0; i<=9; ++i)
870 char buf[20];
871 sprintf(&buf[0], "%%%dd", i);
872 removeFromFormat(buf);
877 static void enterMaxDirCB(Widget w, XtPointer clientData, XtPointer callData)
879 int maxComp = -1;
880 char *format;
881 char *value;
883 if (etDialog.suppressFormatUpdate)
885 return;
888 format = XmTextGetString(etDialog.formatW);
889 value = XmTextGetString(etDialog.ndirW);
891 if (*value)
893 if (sscanf(value, "%d", &maxComp) <= 0)
895 /* Don't allow non-digits to be entered */
896 XBell(XtDisplay(w), 0);
897 XmTextSetString(etDialog.ndirW, "");
901 if (maxComp >= 0)
903 char *pos;
904 int found = False;
905 char insert[2];
906 insert[0] = (char)('0' + maxComp);
907 insert[1] = (char)0; /* '0' digit and 0 char ! */
909 /* Find all %d and %nd occurrences and replace them by the new value */
912 int i;
913 found = False;
914 pos = strstr(format, "%d");
915 if (pos)
917 char* tmp = (char*)XtMalloc((strlen(format)+2)*sizeof(char));
918 strncpy(tmp, format, (size_t)(pos-format+1));
919 tmp[pos-format+1] = 0;
920 strcat(tmp, &insert[0]);
921 strcat(tmp, pos+1);
922 XtFree(format);
923 format = tmp;
924 found = True;
927 for (i=0; i<=9; ++i)
929 char buf[20];
930 sprintf(&buf[0], "%%%dd", i);
931 if (i != maxComp)
933 pos = strstr(format, &buf[0]);
934 if (pos)
936 *(pos+1) = insert[0];
937 found = True;
942 while (found);
944 else
946 int found = True;
948 /* Replace all %nd occurences by %d */
951 int i;
952 found = False;
953 for (i=0; i<=9; ++i)
955 char buf[20];
956 char *pos;
957 sprintf(&buf[0], "%%%dd", i);
958 pos = strstr(format, &buf[0]);
959 if (pos)
961 strcpy(pos+1, pos+2);
962 found = True;
966 while(found);
969 XmTextSetString(etDialog.formatW, format);
970 XtFree(format);
971 XtFree(value);
974 static void createEditTitleDialog(Widget parent, WindowInfo *window)
976 #define LEFT_MARGIN_POS 2
977 #define RIGHT_MARGIN_POS 98
978 #define V_MARGIN 5
979 #define RADIO_INDENT 3
981 Widget buttonForm, formatLbl, previewFrame;
982 Widget previewForm, previewBox, selectFrame, selectBox, selectForm;
983 Widget testLbl, selectLbl;
984 Widget applyBtn, dismissBtn, restoreBtn, helpBtn;
985 XmString s1;
986 XmFontList fontList;
987 Arg args[20];
988 int defaultBtnOffset;
989 Dimension shadowThickness;
990 Dimension radioHeight, textHeight;
991 Pixel background;
993 int ac = 0;
994 XtSetArg(args[ac], XmNautoUnmanage, False); ac++;
995 XtSetArg(args[ac], XmNtitle, "Customize Window Title"); ac++;
996 etDialog.form = CreateFormDialog(parent, "customizeTitle", args, ac);
999 * Destroy the dialog every time it is unmapped (otherwise it 'sticks'
1000 * to the window for which it was created originally).
1002 XtAddCallback(etDialog.form, XmNunmapCallback, wtUnmapCB, NULL);
1003 XtAddCallback(etDialog.form, XmNdestroyCallback, wtDestroyCB, NULL);
1005 etDialog.shell = XtParent(etDialog.form);
1007 /* Definition form */
1008 selectFrame = XtVaCreateManagedWidget("selectionFrame", xmFrameWidgetClass,
1009 etDialog.form,
1010 XmNleftAttachment, XmATTACH_POSITION,
1011 XmNleftPosition, LEFT_MARGIN_POS,
1012 XmNtopAttachment, XmATTACH_FORM,
1013 XmNtopOffset, V_MARGIN,
1014 XmNrightAttachment, XmATTACH_POSITION,
1015 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1017 XtVaCreateManagedWidget("titleLabel", xmLabelGadgetClass,
1018 selectFrame,
1019 XmNlabelString,
1020 s1=XmStringCreateSimple("Title definition"),
1021 XmNchildType, XmFRAME_TITLE_CHILD,
1022 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, NULL);
1023 XmStringFree(s1);
1025 selectForm = XtVaCreateManagedWidget("selectForm", xmFormWidgetClass,
1026 selectFrame ,
1027 XmNleftAttachment, XmATTACH_POSITION,
1028 XmNleftPosition, LEFT_MARGIN_POS,
1029 XmNtopAttachment, XmATTACH_FORM,
1030 XmNtopOffset, V_MARGIN,
1031 XmNrightAttachment, XmATTACH_POSITION,
1032 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1034 selectLbl = XtVaCreateManagedWidget("selectLabel", xmLabelGadgetClass,
1035 selectForm,
1036 XmNlabelString, s1=XmStringCreateSimple("Select title components to include: "),
1037 XmNleftAttachment, XmATTACH_POSITION,
1038 XmNleftPosition, LEFT_MARGIN_POS,
1039 XmNtopOffset, 5,
1040 XmNbottomOffset, 5,
1041 XmNtopAttachment, XmATTACH_FORM, NULL);
1042 XmStringFree(s1);
1044 selectBox = XtVaCreateManagedWidget("selectBox", xmFormWidgetClass,
1045 selectForm,
1046 XmNorientation, XmHORIZONTAL,
1047 XmNpacking, XmPACK_TIGHT,
1048 XmNradioBehavior, False,
1049 XmNleftAttachment, XmATTACH_FORM,
1050 XmNrightAttachment, XmATTACH_FORM,
1051 XmNtopOffset, 5,
1052 XmNtopAttachment, XmATTACH_WIDGET,
1053 XmNtopWidget, selectLbl,
1054 NULL);
1056 etDialog.fileW = XtVaCreateManagedWidget("file",
1057 xmToggleButtonWidgetClass, selectBox,
1058 XmNleftAttachment, XmATTACH_POSITION,
1059 XmNleftPosition, RADIO_INDENT,
1060 XmNtopAttachment, XmATTACH_FORM,
1061 XmNlabelString, s1=XmStringCreateSimple("File name (%f)"),
1062 XmNmnemonic, 'F', NULL);
1063 XtAddCallback(etDialog.fileW, XmNvalueChangedCallback, toggleFileCB, NULL);
1064 XmStringFree(s1);
1066 etDialog.statusW = XtVaCreateManagedWidget("status",
1067 xmToggleButtonWidgetClass, selectBox,
1068 XmNleftAttachment, XmATTACH_POSITION,
1069 XmNleftPosition, RADIO_INDENT,
1070 XmNtopAttachment, XmATTACH_WIDGET,
1071 XmNtopWidget, etDialog.fileW,
1072 XmNlabelString, s1=XmStringCreateSimple("File status (%S) "),
1073 XmNmnemonic, 't', NULL);
1074 XtAddCallback(etDialog.statusW, XmNvalueChangedCallback, toggleStatusCB, NULL);
1075 XmStringFree(s1);
1077 etDialog.shortStatusW = XtVaCreateManagedWidget("shortStatus",
1078 xmToggleButtonWidgetClass, selectBox,
1079 XmNleftAttachment, XmATTACH_WIDGET,
1080 XmNleftWidget, etDialog.statusW,
1081 XmNtopAttachment, XmATTACH_WIDGET,
1082 XmNtopWidget, etDialog.fileW,
1083 XmNlabelString, s1=XmStringCreateSimple("brief"),
1084 XmNmnemonic, 'b', NULL);
1085 XtAddCallback(etDialog.shortStatusW, XmNvalueChangedCallback, toggleShortStatusCB, NULL);
1086 XmStringFree(s1);
1088 etDialog.ccW = XtVaCreateManagedWidget("ccView",
1089 xmToggleButtonWidgetClass, selectBox,
1090 XmNleftAttachment, XmATTACH_POSITION,
1091 XmNleftPosition, RADIO_INDENT,
1092 XmNtopAttachment, XmATTACH_WIDGET,
1093 XmNtopWidget, etDialog.statusW,
1094 XmNlabelString, s1=XmStringCreateSimple("ClearCase view tag (%c) "),
1095 XmNmnemonic, 'C', NULL);
1096 #ifdef VMS
1097 XtSetSensitive(etDialog.ccW, False);
1098 #else
1099 XtAddCallback(etDialog.ccW, XmNvalueChangedCallback, toggleClearCaseCB, NULL);
1100 #endif /* VMS */
1101 XmStringFree(s1);
1103 etDialog.dirW = XtVaCreateManagedWidget("directory",
1104 xmToggleButtonWidgetClass, selectBox,
1105 XmNleftAttachment, XmATTACH_POSITION,
1106 XmNleftPosition, RADIO_INDENT,
1107 XmNtopAttachment, XmATTACH_WIDGET,
1108 XmNtopWidget, etDialog.ccW,
1109 XmNlabelString, s1=XmStringCreateSimple("Directory (%d),"),
1110 XmNmnemonic, 'D', NULL);
1111 XtAddCallback(etDialog.dirW, XmNvalueChangedCallback, toggleDirectoryCB, NULL);
1112 XmStringFree(s1);
1114 etDialog.mdirW = XtVaCreateManagedWidget("componentLab",
1115 xmLabelGadgetClass, selectBox,
1116 XmNheight, radioHeight,
1117 XmNleftAttachment, XmATTACH_WIDGET,
1118 XmNleftWidget, etDialog.dirW,
1119 XmNtopAttachment, XmATTACH_WIDGET,
1120 XmNtopWidget, etDialog.ccW,
1121 XmNlabelString, s1=XmStringCreateSimple("max. components: "),
1122 XmNmnemonic, 'x', NULL);
1123 XmStringFree(s1);
1125 etDialog.ndirW = XtVaCreateManagedWidget("dircomp",
1126 xmTextWidgetClass, selectBox,
1127 XmNcolumns, 1,
1128 XmNmaxLength, 1,
1129 XmNleftAttachment, XmATTACH_WIDGET,
1130 XmNleftWidget, etDialog.mdirW,
1131 XmNtopAttachment, XmATTACH_WIDGET,
1132 XmNtopWidget, etDialog.ccW,
1133 NULL);
1134 XtAddCallback(etDialog.ndirW, XmNvalueChangedCallback, enterMaxDirCB, NULL);
1135 RemapDeleteKey(etDialog.ndirW);
1136 XtVaSetValues(etDialog.mdirW, XmNuserData, etDialog.ndirW, NULL); /* mnemonic processing */
1138 XtVaGetValues(etDialog.ndirW, XmNheight, &textHeight, NULL);
1139 XtVaSetValues(etDialog.dirW, XmNheight, textHeight, NULL);
1140 XtVaSetValues(etDialog.mdirW, XmNheight, textHeight, NULL);
1142 etDialog.hostW = XtVaCreateManagedWidget("host",
1143 xmToggleButtonWidgetClass, selectBox,
1144 XmNleftAttachment, XmATTACH_POSITION,
1145 XmNleftPosition, 50 + RADIO_INDENT,
1146 XmNtopAttachment, XmATTACH_FORM,
1147 XmNlabelString, s1=XmStringCreateSimple("Host name (%h)"),
1148 XmNmnemonic, 'H', NULL);
1149 XtAddCallback(etDialog.hostW, XmNvalueChangedCallback, toggleHostCB, NULL);
1150 XmStringFree(s1);
1152 etDialog.nameW = XtVaCreateManagedWidget("name",
1153 xmToggleButtonWidgetClass, selectBox,
1154 XmNleftAttachment, XmATTACH_POSITION,
1155 XmNleftPosition, 50 + RADIO_INDENT,
1156 XmNtopAttachment, XmATTACH_WIDGET,
1157 XmNtopWidget, etDialog.hostW,
1158 XmNlabelString, s1=XmStringCreateSimple("User name (%u)"),
1159 XmNmnemonic, 'U', NULL);
1160 XtAddCallback(etDialog.nameW, XmNvalueChangedCallback, toggleUserCB, NULL);
1161 XmStringFree(s1);
1163 etDialog.serverW = XtVaCreateManagedWidget("server",
1164 xmToggleButtonWidgetClass, selectBox,
1165 XmNleftAttachment, XmATTACH_POSITION,
1166 XmNleftPosition, 50 + RADIO_INDENT,
1167 XmNtopAttachment, XmATTACH_WIDGET,
1168 XmNtopWidget, etDialog.nameW,
1169 XmNlabelString, s1=XmStringCreateSimple("NEdit server name (%s)"),
1170 XmNmnemonic, 's', NULL);
1171 XtAddCallback(etDialog.serverW, XmNvalueChangedCallback, toggleServerCB, NULL);
1172 XmStringFree(s1);
1174 formatLbl = XtVaCreateManagedWidget("formatLbl", xmLabelGadgetClass,
1175 selectForm,
1176 XmNlabelString, s1=XmStringCreateSimple("Format: "),
1177 XmNmnemonic, 'r',
1178 XmNleftAttachment, XmATTACH_POSITION,
1179 XmNleftPosition, LEFT_MARGIN_POS,
1180 XmNtopAttachment, XmATTACH_WIDGET,
1181 XmNtopWidget, selectBox,
1182 XmNbottomAttachment, XmATTACH_FORM, NULL);
1183 XmStringFree(s1);
1184 etDialog.formatW = XtVaCreateManagedWidget("format", xmTextWidgetClass,
1185 selectForm,
1186 XmNmaxLength, WINDOWTITLE_MAX_LEN,
1187 XmNtopAttachment, XmATTACH_WIDGET,
1188 XmNtopWidget, selectBox,
1189 XmNtopOffset, 5,
1190 XmNleftAttachment, XmATTACH_WIDGET,
1191 XmNleftWidget, formatLbl,
1192 XmNrightAttachment, XmATTACH_POSITION,
1193 XmNrightPosition, RIGHT_MARGIN_POS,
1194 XmNbottomAttachment, XmATTACH_FORM,
1195 XmNbottomOffset, 5, NULL);
1196 RemapDeleteKey(etDialog.formatW);
1197 XtVaSetValues(formatLbl, XmNuserData, etDialog.formatW, NULL);
1198 XtAddCallback(etDialog.formatW, XmNvalueChangedCallback, formatChangedCB, NULL);
1200 XtVaGetValues(etDialog.formatW, XmNheight, &textHeight, NULL);
1201 XtVaSetValues(formatLbl, XmNheight, textHeight, NULL);
1203 previewFrame = XtVaCreateManagedWidget("previewFrame", xmFrameWidgetClass,
1204 etDialog.form,
1205 XmNtopAttachment, XmATTACH_WIDGET,
1206 XmNtopWidget, selectFrame,
1207 XmNleftAttachment, XmATTACH_POSITION,
1208 XmNleftPosition, LEFT_MARGIN_POS,
1209 XmNrightAttachment, XmATTACH_POSITION,
1210 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1212 XtVaCreateManagedWidget("previewLabel", xmLabelGadgetClass,
1213 previewFrame,
1214 XmNlabelString, s1=XmStringCreateSimple("Preview"),
1215 XmNchildType, XmFRAME_TITLE_CHILD,
1216 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, NULL);
1217 XmStringFree(s1);
1219 previewForm = XtVaCreateManagedWidget("previewForm", xmFormWidgetClass,
1220 previewFrame,
1221 XmNleftAttachment, XmATTACH_FORM,
1222 XmNleftPosition, LEFT_MARGIN_POS,
1223 XmNtopAttachment, XmATTACH_FORM,
1224 XmNtopOffset, V_MARGIN,
1225 XmNrightAttachment, XmATTACH_FORM,
1226 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1228 /* Copy a variable width font from one of the labels to use for the
1229 preview (no editing is allowed, and with a fixed size font the
1230 preview easily gets partially obscured). Also copy the form background
1231 color to make it clear that this field is not editable */
1232 XtVaGetValues(formatLbl, XmNfontList, &fontList, NULL);
1233 XtVaGetValues(previewForm, XmNbackground, &background, NULL);
1235 etDialog.previewW = XtVaCreateManagedWidget("sample",
1236 xmTextFieldWidgetClass, previewForm,
1237 XmNeditable, False,
1238 XmNcursorPositionVisible, False,
1239 XmNtopAttachment, XmATTACH_FORM,
1240 XmNleftAttachment, XmATTACH_FORM,
1241 XmNleftOffset, V_MARGIN,
1242 XmNrightAttachment, XmATTACH_FORM,
1243 XmNrightOffset, V_MARGIN,
1244 XmNfontList, fontList,
1245 XmNbackground, background,
1246 NULL);
1248 previewBox = XtVaCreateManagedWidget("previewBox", xmFormWidgetClass,
1249 previewForm,
1250 XmNorientation, XmHORIZONTAL,
1251 XmNpacking, XmPACK_TIGHT,
1252 XmNradioBehavior, False,
1253 XmNleftAttachment, XmATTACH_FORM,
1254 XmNrightAttachment, XmATTACH_FORM,
1255 XmNtopAttachment, XmATTACH_WIDGET,
1256 XmNtopWidget, etDialog.previewW, NULL);
1258 testLbl = XtVaCreateManagedWidget("testLabel", xmLabelGadgetClass,
1259 previewBox,
1260 XmNlabelString, s1=XmStringCreateSimple("Test settings: "),
1261 XmNleftAttachment, XmATTACH_POSITION,
1262 XmNleftPosition, LEFT_MARGIN_POS,
1263 XmNtopOffset, 5,
1264 XmNbottomOffset, 5,
1265 XmNtopAttachment, XmATTACH_FORM, NULL);
1266 XmStringFree(s1);
1268 etDialog.oFileChangedW = XtVaCreateManagedWidget("fileChanged",
1269 xmToggleButtonWidgetClass, previewBox,
1270 XmNleftAttachment, XmATTACH_POSITION,
1271 XmNleftPosition, RADIO_INDENT,
1272 XmNtopAttachment, XmATTACH_WIDGET,
1273 XmNtopWidget, testLbl,
1274 XmNlabelString, s1=XmStringCreateSimple("File modified"),
1275 XmNmnemonic, 'o', NULL);
1276 XtAddCallback(etDialog.oFileChangedW, XmNvalueChangedCallback, fileChangedCB, NULL);
1277 XmStringFree(s1);
1279 etDialog.oFileReadOnlyW = XtVaCreateManagedWidget("fileReadOnly",
1280 xmToggleButtonWidgetClass, previewBox,
1281 XmNleftAttachment, XmATTACH_WIDGET,
1282 XmNleftWidget, etDialog.oFileChangedW,
1283 XmNtopAttachment, XmATTACH_WIDGET,
1284 XmNtopWidget, testLbl,
1285 XmNlabelString, s1=XmStringCreateSimple("File read only"),
1286 XmNmnemonic, 'n', NULL);
1287 XtAddCallback(etDialog.oFileReadOnlyW, XmNvalueChangedCallback, fileReadOnlyCB, NULL);
1288 XmStringFree(s1);
1290 etDialog.oFileLockedW = XtVaCreateManagedWidget("fileLocked",
1291 xmToggleButtonWidgetClass, previewBox,
1292 XmNleftAttachment, XmATTACH_WIDGET,
1293 XmNleftWidget, etDialog.oFileReadOnlyW,
1294 XmNtopAttachment, XmATTACH_WIDGET,
1295 XmNtopWidget, testLbl,
1296 XmNlabelString, s1=XmStringCreateSimple("File locked"),
1297 XmNmnemonic, 'l', NULL);
1298 XtAddCallback(etDialog.oFileLockedW, XmNvalueChangedCallback, fileLockedCB, NULL);
1299 XmStringFree(s1);
1301 etDialog.oServerNameW = XtVaCreateManagedWidget("servernameSet",
1302 xmToggleButtonWidgetClass, previewBox,
1303 XmNleftAttachment, XmATTACH_POSITION,
1304 XmNleftPosition, RADIO_INDENT,
1305 XmNtopAttachment, XmATTACH_WIDGET,
1306 XmNtopWidget, etDialog.oFileChangedW,
1307 XmNlabelString, s1=XmStringCreateSimple("Server name present"),
1308 XmNmnemonic, 'v', NULL);
1309 XtAddCallback(etDialog.oServerNameW, XmNvalueChangedCallback, serverNameCB, NULL);
1310 XmStringFree(s1);
1312 etDialog.oCcViewTagW = XtVaCreateManagedWidget("ccViewTagSet",
1313 xmToggleButtonWidgetClass, previewBox,
1314 XmNleftAttachment, XmATTACH_POSITION,
1315 XmNleftPosition, RADIO_INDENT,
1316 XmNtopAttachment, XmATTACH_WIDGET,
1317 XmNtopWidget, etDialog.oServerNameW,
1318 XmNlabelString, s1=XmStringCreateSimple("CC view tag present"),
1319 #ifdef VMS
1320 XmNset, False,
1321 #else
1322 XmNset, GetClearCaseViewTag() != NULL,
1323 #endif /* VMS */
1324 XmNmnemonic, 'w', NULL);
1325 #ifdef VMS
1326 XtSetSensitive(etDialog.oCcViewTagW, False);
1327 #else
1328 XtAddCallback(etDialog.oCcViewTagW, XmNvalueChangedCallback, ccViewTagCB, NULL);
1329 #endif /* VMS */
1330 XmStringFree(s1);
1332 etDialog.oServerEqualViewW = XtVaCreateManagedWidget("serverEqualView",
1333 xmToggleButtonWidgetClass, previewBox,
1334 XmNleftAttachment, XmATTACH_WIDGET,
1335 XmNleftWidget, etDialog.oCcViewTagW,
1336 XmNtopAttachment, XmATTACH_WIDGET,
1337 XmNtopWidget, etDialog.oServerNameW,
1338 XmNlabelString, s1=XmStringCreateSimple("Server name equals CC view tag "),
1339 XmNmnemonic, 'q', NULL);
1340 #ifdef VMS
1341 XtSetSensitive(etDialog.oServerEqualViewW, False);
1342 #else
1343 XtAddCallback(etDialog.oServerEqualViewW, XmNvalueChangedCallback, serverEqualViewCB, NULL);
1344 #endif /* VMS */
1345 XmStringFree(s1);
1347 etDialog.oDirW = XtVaCreateManagedWidget("pathSet",
1348 xmToggleButtonWidgetClass, previewBox,
1349 XmNleftAttachment, XmATTACH_POSITION,
1350 XmNleftPosition, RADIO_INDENT,
1351 XmNtopAttachment, XmATTACH_WIDGET,
1352 XmNtopWidget, etDialog.oCcViewTagW,
1353 XmNlabelString, s1=XmStringCreateSimple("Directory present"),
1354 XmNmnemonic, 'i', NULL);
1355 XtAddCallback(etDialog.oDirW, XmNvalueChangedCallback, formatChangedCB, NULL);
1356 XmStringFree(s1);
1357 XtVaGetValues(etDialog.fileW, XmNheight, &radioHeight, NULL);
1359 /* Button box */
1360 buttonForm = XtVaCreateManagedWidget("buttonForm", xmFormWidgetClass,
1361 etDialog.form,
1362 XmNleftAttachment, XmATTACH_POSITION,
1363 XmNleftPosition, LEFT_MARGIN_POS,
1364 XmNtopAttachment, XmATTACH_WIDGET,
1365 XmNtopWidget, previewFrame,
1366 XmNtopOffset, V_MARGIN,
1367 XmNbottomOffset, V_MARGIN,
1368 XmNbottomAttachment, XmATTACH_FORM,
1369 XmNrightAttachment, XmATTACH_POSITION,
1370 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1372 applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass,
1373 buttonForm,
1374 XmNhighlightThickness, 2,
1375 XmNlabelString, s1=XmStringCreateSimple("Apply"),
1376 XmNshowAsDefault, (short)1,
1377 XmNleftAttachment, XmATTACH_POSITION,
1378 XmNleftPosition, 6,
1379 XmNrightAttachment, XmATTACH_POSITION,
1380 XmNrightPosition, 25,
1381 XmNbottomAttachment, XmATTACH_FORM,
1382 NULL);
1383 XtAddCallback(applyBtn, XmNactivateCallback, applyCB, NULL);
1384 XmStringFree(s1);
1385 XtVaGetValues(applyBtn, XmNshadowThickness, &shadowThickness, NULL);
1386 defaultBtnOffset = shadowThickness + 4;
1388 dismissBtn = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass,
1389 buttonForm,
1390 XmNhighlightThickness, 2,
1391 XmNlabelString, s1=XmStringCreateSimple("Dismiss"),
1392 XmNleftAttachment, XmATTACH_POSITION,
1393 XmNleftPosition, 52,
1394 XmNrightAttachment, XmATTACH_POSITION,
1395 XmNrightPosition, 71,
1396 XmNbottomAttachment, XmATTACH_FORM,
1397 XmNbottomOffset, defaultBtnOffset,
1398 NULL);
1399 XtAddCallback(dismissBtn, XmNactivateCallback, dismissCB, NULL);
1400 XmStringFree(s1);
1402 restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass,
1403 buttonForm,
1404 XmNhighlightThickness, 2,
1405 XmNlabelString, s1=XmStringCreateSimple("Default"),
1406 XmNleftAttachment, XmATTACH_POSITION,
1407 XmNleftPosition, 29,
1408 XmNrightAttachment, XmATTACH_POSITION,
1409 XmNrightPosition, 48,
1410 XmNbottomAttachment, XmATTACH_FORM,
1411 XmNbottomOffset, defaultBtnOffset,
1412 XmNmnemonic, 'e', NULL);
1413 XtAddCallback(restoreBtn, XmNactivateCallback, restoreCB, NULL);
1414 XmStringFree(s1);
1416 helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
1417 buttonForm,
1418 XmNhighlightThickness, 2,
1419 XmNlabelString, s1=XmStringCreateSimple("Help"),
1420 XmNleftAttachment, XmATTACH_POSITION,
1421 XmNleftPosition, 75,
1422 XmNrightAttachment, XmATTACH_POSITION,
1423 XmNrightPosition, 94,
1424 XmNbottomAttachment, XmATTACH_FORM,
1425 XmNbottomOffset, defaultBtnOffset,
1426 XmNmnemonic, 'p', NULL);
1427 XtAddCallback(helpBtn, XmNactivateCallback, helpCB, NULL);
1428 XmStringFree(s1);
1430 /* Set initial default button */
1431 XtVaSetValues(etDialog.form, XmNdefaultButton, applyBtn, NULL);
1432 XtVaSetValues(etDialog.form, XmNcancelButton, dismissBtn, NULL);
1434 /* Handle mnemonic selection of buttons and focus to dialog */
1435 AddDialogMnemonicHandler(etDialog.form, FALSE);
1437 etDialog.suppressFormatUpdate = FALSE;
1440 void EditCustomTitleFormat(Widget parent, WindowInfo *window)
1442 /* copy attributes from current window so that we can use as many
1443 * 'real world' defaults as possible when testing the effect
1444 * of different formatting strings.
1446 strcpy(etDialog.path, window->path);
1447 strcpy(etDialog.filename, window->filename);
1448 #ifndef VMS
1449 strcpy(etDialog.viewTag, GetClearCaseViewTag() != NULL ?
1450 GetClearCaseViewTag() :
1451 "viewtag");
1452 #endif /* VMS */
1453 strcpy(etDialog.serverName, IsServer ?
1454 GetPrefServerName() :
1455 "servername");
1456 etDialog.isServer = IsServer;
1457 etDialog.filenameSet = window->filenameSet;
1458 etDialog.lockReasons = window->lockReasons;
1459 etDialog.fileChanged = window->fileChanged;
1461 if (etDialog.window != window && etDialog.form)
1463 /* Destroy the dialog owned by the other window.
1464 Note: don't rely on the destroy event handler to reset the
1465 form. Events are handled asynchronously, so the old dialog
1466 may continue to live for a while. */
1467 XtDestroyWidget(etDialog.form);
1468 etDialog.form = NULL;
1471 etDialog.window = window;
1473 /* Create the dialog if it doesn't already exist */
1474 if (etDialog.form == NULL)
1476 createEditTitleDialog(window->shell, window);
1478 else
1480 /* If the window is already up, just pop it to the top */
1481 if (XtIsManaged(etDialog.form)) {
1483 RaiseShellWindow(XtParent(etDialog.form));
1485 /* force update of the dialog */
1486 setToggleButtons();
1487 formatChangedCB(0, 0, 0);
1488 return;
1492 /* set initial value of format field */
1493 XmTextSetString(etDialog.formatW, (char *)GetPrefTitleFormat());
1495 /* force update of the dialog */
1496 setToggleButtons();
1497 formatChangedCB(0, 0, 0);
1499 /* put up dialog and wait for user to press ok or cancel */
1500 ManageDialogCenteredOnPointer(etDialog.form);