Propogate colors to new windows on opening (744294)
[nedit.git] / source / windowTitle.c
blob85654ebd88cb832cc826b9b4526108c5038e1fe2
1 static const char CVSID[] = "$Id: windowTitle.c,v 1.11 2003/05/09 17:43:48 edg 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,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
118 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
119 NULL,NULL,"","","","",0,0,0,0,0};
123 static char* removeSequence(char* sourcePtr, char c)
125 while (*sourcePtr == c) {
126 sourcePtr++;
128 return(sourcePtr);
133 ** Two functions for performing safe insertions into a finite
134 ** size buffer so that we don't get any memory overruns.
136 static char* safeStrCpy(char* dest, char* destEnd, const char* source)
138 int len = (int)strlen(source);
139 if (len <= (destEnd - dest)) {
140 strcpy(dest, source);
141 return(dest + len);
143 else {
144 strncpy(dest, source, destEnd - dest);
145 *destEnd = '\0';
146 return(destEnd);
150 static char* safeCharAdd(char* dest, char* destEnd, char c)
152 if (destEnd - dest > 0)
154 *dest++ = c;
155 *dest = '\0';
157 return(dest);
161 ** Remove empty paranthesis pairs and multiple spaces in a row
162 ** with one space.
163 ** Also remove leading and trailing spaces and dashes.
165 static void compressWindowTitle(char *title)
167 /* Compress the title */
168 int modified;
169 do {
170 char *sourcePtr = title;
171 char *destPtr = sourcePtr;
172 char c = *sourcePtr++;
174 modified = False;
176 /* Remove leading spaces and dashes */
177 while (c == ' ' || c == '-') {
178 c= *sourcePtr++;
181 /* Remove empty constructs */
182 while (c != '\0') {
183 switch (c) {
184 /* remove sequences */
185 case ' ':
186 case '-':
187 sourcePtr = removeSequence(sourcePtr, c);
188 *destPtr++ = c; /* leave one */
189 break;
191 /* remove empty paranthesis pairs */
192 case '(':
193 if (*sourcePtr == ')') {
194 modified = True;
195 sourcePtr++;
197 else *destPtr++ = c;
198 sourcePtr = removeSequence(sourcePtr, ' ');
199 break;
201 case '[':
202 if (*sourcePtr == ']') {
203 modified = True;
204 sourcePtr++;
206 else *destPtr++ = c;
207 sourcePtr = removeSequence(sourcePtr, ' ');
208 break;
210 case '{':
211 if (*sourcePtr == '}') {
212 modified = True;
213 sourcePtr++;
215 else *destPtr++ = c;
216 sourcePtr = removeSequence(sourcePtr, ' ');
217 break;
219 default:
220 *destPtr++ = c;
221 break;
223 c = *sourcePtr++;
224 *destPtr = '\0';
227 /* Remove trailing spaces and dashes */
228 while (destPtr-- > title) {
229 if (*destPtr != ' ' && *destPtr != '-')
230 break;
231 *destPtr = '\0';
233 } while (modified == True);
238 ** Format the windows title using a printf like formatting string.
239 ** The following flags are recognised:
240 ** %c : ClearCase view tag
241 ** %s : server name
242 ** %[n]d : directory, with one optional digit specifying the max number
243 ** of trailing directory components to display. Skipped components are
244 ** replaced by an ellipsis (...).
245 ** %f : file name
246 ** %h : host name
247 ** %S : file status
248 ** %u : user name
250 ** if the ClearCase view tag and server name are identical, only the first one
251 ** specified in the formatting string will be displayed.
253 char *FormatWindowTitle(const char* filename,
254 const char* path,
255 const char* clearCaseViewTag,
256 const char* serverName,
257 int isServer,
258 int filenameSet,
259 int lockReasons,
260 int fileChanged,
261 const char* titleFormat)
263 static char title[WINDOWTITLE_MAX_LEN];
264 char *titlePtr = title;
265 char* titleEnd = title + WINDOWTITLE_MAX_LEN - 1;
268 /* Flags to supress one of these if both are specified and they are identical */
269 int serverNameSeen = False;
270 int clearCaseViewTagSeen = False;
272 int fileNamePresent = False;
273 int hostNamePresent = False;
274 int userNamePresent = False;
275 int serverNamePresent = False;
276 int clearCasePresent = False;
277 int fileStatusPresent = False;
278 int dirNamePresent = False;
279 int noOfComponents = -1;
280 int shortStatus = False;
282 *titlePtr = '\0'; /* always start with an empty string */
284 while (*titleFormat != '\0' && titlePtr < titleEnd) {
285 char c = *titleFormat++;
286 if (c == '%') {
287 c = *titleFormat++;
288 if (c == '\0')
290 titlePtr = safeCharAdd(titlePtr, titleEnd, '%');
291 break;
293 switch (c) {
294 case 'c': /* ClearCase view tag */
295 clearCasePresent = True;
296 if (clearCaseViewTag != NULL) {
297 if (serverNameSeen == False ||
298 strcmp(serverName, clearCaseViewTag) != 0) {
299 titlePtr = safeStrCpy(titlePtr, titleEnd, clearCaseViewTag);
300 clearCaseViewTagSeen = True;
303 break;
305 case 's': /* server name */
306 serverNamePresent = True;
307 if (isServer && serverName[0] != '\0') { /* only applicable for servers */
308 if (clearCaseViewTagSeen == False ||
309 strcmp(serverName, clearCaseViewTag) != 0) {
310 titlePtr = safeStrCpy(titlePtr, titleEnd, serverName);
311 serverNameSeen = True;
314 break;
316 case 'd': /* directory without any limit to no. of components */
317 dirNamePresent = True;
318 if (filenameSet) {
319 titlePtr = safeStrCpy(titlePtr, titleEnd, path);
321 break;
323 case '0': /* directory with limited no. of components */
324 case '1':
325 case '2':
326 case '3':
327 case '4':
328 case '5':
329 case '6':
330 case '7':
331 case '8':
332 case '9':
333 if (*titleFormat == 'd') {
334 dirNamePresent = True;
335 noOfComponents = c - '0';
336 titleFormat++; /* delete the argument */
338 if (filenameSet) {
339 const char* trailingPath = GetTrailingPathComponents(path,
340 noOfComponents);
342 /* prefix with ellipsis if components were skipped */
343 if (trailingPath > path) {
344 titlePtr = safeStrCpy(titlePtr, titleEnd, "...");
346 titlePtr = safeStrCpy(titlePtr, titleEnd, trailingPath);
349 break;
351 case 'f': /* file name */
352 fileNamePresent = True;
353 titlePtr = safeStrCpy(titlePtr, titleEnd, filename);
354 break;
356 case 'h': /* host name */
357 hostNamePresent = True;
358 titlePtr = safeStrCpy(titlePtr, titleEnd, GetNameOfHost());
359 break;
361 case 'S': /* file status */
362 fileStatusPresent = True;
363 if (IS_ANY_LOCKED_IGNORING_USER(lockReasons) && fileChanged)
364 titlePtr = safeStrCpy(titlePtr, titleEnd, "read only, modified");
365 else if (IS_ANY_LOCKED_IGNORING_USER(lockReasons))
366 titlePtr = safeStrCpy(titlePtr, titleEnd, "read only");
367 else if (IS_USER_LOCKED(lockReasons) && fileChanged)
368 titlePtr = safeStrCpy(titlePtr, titleEnd, "locked, modified");
369 else if (IS_USER_LOCKED(lockReasons))
370 titlePtr = safeStrCpy(titlePtr, titleEnd, "locked");
371 else if (fileChanged)
372 titlePtr = safeStrCpy(titlePtr, titleEnd, "modified");
373 break;
375 case 'u': /* user name */
376 userNamePresent = True;
377 titlePtr = safeStrCpy(titlePtr, titleEnd, GetUserName());
378 break;
380 case '%': /* escaped % */
381 titlePtr = safeCharAdd(titlePtr, titleEnd, '%');
382 break;
384 case '*': /* short file status ? */
385 fileStatusPresent = True;
386 if (*titleFormat && *titleFormat == 'S')
388 ++titleFormat;
389 shortStatus = True;
390 if (IS_ANY_LOCKED_IGNORING_USER(lockReasons) && fileChanged)
391 titlePtr = safeStrCpy(titlePtr, titleEnd, "RO*");
392 else if (IS_ANY_LOCKED_IGNORING_USER(lockReasons))
393 titlePtr = safeStrCpy(titlePtr, titleEnd, "RO");
394 else if (IS_USER_LOCKED(lockReasons) && fileChanged)
395 titlePtr = safeStrCpy(titlePtr, titleEnd, "LO*");
396 else if (IS_USER_LOCKED(lockReasons))
397 titlePtr = safeStrCpy(titlePtr, titleEnd, "LO");
398 else if (fileChanged)
399 titlePtr = safeStrCpy(titlePtr, titleEnd, "*");
400 break;
402 /* fall-through */
403 default:
404 titlePtr = safeCharAdd(titlePtr, titleEnd, c);
405 break;
408 else {
409 titlePtr = safeCharAdd(titlePtr, titleEnd, c);
413 compressWindowTitle(title);
415 if (title[0] == 0)
417 sprintf(&title[0], "<empty>"); /* For preview purposes only */
420 if (etDialog.form)
422 /* Prevent recursive callback loop */
423 etDialog.suppressFormatUpdate = True;
425 /* Sync radio buttons with format string (in case the user entered
426 the format manually) */
427 XmToggleButtonSetState(etDialog.fileW, fileNamePresent, False);
428 XmToggleButtonSetState(etDialog.statusW, fileStatusPresent, False);
429 XmToggleButtonSetState(etDialog.serverW, serverNamePresent, False);
430 #ifndef VMS
431 XmToggleButtonSetState(etDialog.ccW, clearCasePresent, False);
432 #endif /* VMS */
433 XmToggleButtonSetState(etDialog.dirW, dirNamePresent, False);
434 XmToggleButtonSetState(etDialog.hostW, hostNamePresent, False);
435 XmToggleButtonSetState(etDialog.nameW, userNamePresent, False);
437 XtSetSensitive(etDialog.shortStatusW, fileStatusPresent);
438 if (fileStatusPresent)
440 XmToggleButtonSetState(etDialog.shortStatusW, shortStatus, False);
443 /* Directory components are also sensitive to presence of dir */
444 XtSetSensitive(etDialog.ndirW, dirNamePresent);
445 XtSetSensitive(etDialog.mdirW, dirNamePresent);
447 if (dirNamePresent) /* Avoid erasing number when not active */
449 if (noOfComponents >= 0)
451 char* value = XmTextGetString(etDialog.ndirW);
452 char buf[2];
453 sprintf(&buf[0], "%d", noOfComponents);
454 if (strcmp(&buf[0], value)) /* Don't overwrite unless diff. */
455 SetIntText(etDialog.ndirW, noOfComponents);
456 XtFree(value);
458 else
460 XmTextSetString(etDialog.ndirW, "");
464 /* Enable/disable test buttons, depending on presence of codes */
465 XtSetSensitive(etDialog.oFileChangedW, fileStatusPresent);
466 XtSetSensitive(etDialog.oFileReadOnlyW, fileStatusPresent);
467 XtSetSensitive(etDialog.oFileLockedW, fileStatusPresent &&
468 !IS_PERM_LOCKED(etDialog.lockReasons));
470 XtSetSensitive(etDialog.oServerNameW, serverNamePresent);
472 #ifndef VMS
473 XtSetSensitive(etDialog.oCcViewTagW, clearCasePresent);
474 XtSetSensitive(etDialog.oServerEqualViewW, clearCasePresent &&
475 serverNamePresent);
476 #endif /* VMS */
478 XtSetSensitive(etDialog.oDirW, dirNamePresent);
480 etDialog.suppressFormatUpdate = False;
483 return(title);
488 /* a utility that sets the values of all toggle buttons */
489 static void setToggleButtons(void)
491 XmToggleButtonSetState(etDialog.oDirW,
492 etDialog.filenameSet == True, False);
493 XmToggleButtonSetState(etDialog.oFileChangedW,
494 etDialog.fileChanged == True, False);
495 XmToggleButtonSetState(etDialog.oFileReadOnlyW,
496 IS_PERM_LOCKED(etDialog.lockReasons), False);
497 XmToggleButtonSetState(etDialog.oFileLockedW,
498 IS_USER_LOCKED(etDialog.lockReasons), False);
499 /* Read-only takes precedence on locked */
500 XtSetSensitive(etDialog.oFileLockedW, !IS_PERM_LOCKED(etDialog.lockReasons));
502 #ifdef VMS
503 XmToggleButtonSetState(etDialog.oServerNameW, etDialog.isServer, False);
504 #else
505 XmToggleButtonSetState(etDialog.oCcViewTagW,
506 GetClearCaseViewTag() != NULL, False);
507 XmToggleButtonSetState(etDialog.oServerNameW,
508 etDialog.isServer, False);
510 if (GetClearCaseViewTag() != NULL &&
511 etDialog.isServer &&
512 GetPrefServerName()[0] != '\0' &&
513 strcmp(GetClearCaseViewTag(), GetPrefServerName()) == 0) {
514 XmToggleButtonSetState(etDialog.oServerEqualViewW,
515 True, False);
516 } else {
517 XmToggleButtonSetState(etDialog.oServerEqualViewW,
518 False, False);
520 #endif /* VMS */
523 static void formatChangedCB(Widget w, XtPointer clientData, XtPointer callData)
525 char *format;
526 int filenameSet = XmToggleButtonGetState(etDialog.oDirW);
527 char *title;
528 const char* serverName;
530 if (etDialog.suppressFormatUpdate)
532 return; /* Prevent recursive feedback */
535 format = XmTextGetString(etDialog.formatW);
537 #ifndef VMS
538 if (XmToggleButtonGetState(etDialog.oServerEqualViewW) &&
539 XmToggleButtonGetState(etDialog.ccW)) {
540 serverName = etDialog.viewTag;
541 } else
542 #endif /* VMS */
544 serverName = XmToggleButtonGetState(etDialog.oServerNameW) ?
545 etDialog.serverName : "";
548 title = FormatWindowTitle(
549 etDialog.filename,
550 etDialog.filenameSet == True ?
551 etDialog.path :
552 "/a/very/long/path/used/as/example/",
553 #ifdef VMS
554 NULL,
555 #else
556 XmToggleButtonGetState(etDialog.oCcViewTagW) ?
557 etDialog.viewTag : NULL,
558 #endif /* VMS */
559 serverName,
560 etDialog.isServer,
561 filenameSet,
562 etDialog.lockReasons,
563 XmToggleButtonGetState(etDialog.oFileChangedW),
564 format);
565 XtFree(format);
566 XmTextFieldSetString(etDialog.previewW, title);
569 #ifndef VMS
570 static void ccViewTagCB(Widget w, XtPointer clientData, XtPointer callData)
572 if (XmToggleButtonGetState(w) == False) {
573 XmToggleButtonSetState(etDialog.oServerEqualViewW, False, False);
575 formatChangedCB(w, clientData, callData);
577 #endif /* VMS */
579 static void serverNameCB(Widget w, XtPointer clientData, XtPointer callData)
581 if (XmToggleButtonGetState(w) == False) {
582 XmToggleButtonSetState(etDialog.oServerEqualViewW, False, False);
584 etDialog.isServer = XmToggleButtonGetState(w);
585 formatChangedCB(w, clientData, callData);
588 static void fileChangedCB(Widget w, XtPointer clientData, XtPointer callData)
590 etDialog.fileChanged = XmToggleButtonGetState(w);
591 formatChangedCB(w, clientData, callData);
594 static void fileLockedCB(Widget w, XtPointer clientData, XtPointer callData)
596 SET_USER_LOCKED(etDialog.lockReasons, XmToggleButtonGetState(w));
597 formatChangedCB(w, clientData, callData);
600 static void fileReadOnlyCB(Widget w, XtPointer clientData, XtPointer callData)
602 SET_PERM_LOCKED(etDialog.lockReasons, XmToggleButtonGetState(w));
603 formatChangedCB(w, clientData, callData);
606 #ifndef VMS
607 static void serverEqualViewCB(Widget w, XtPointer clientData, XtPointer callData)
609 if (XmToggleButtonGetState(w) == True) {
610 XmToggleButtonSetState(etDialog.oCcViewTagW, True, False);
611 XmToggleButtonSetState(etDialog.oServerNameW, True, False);
612 etDialog.isServer = True;
614 formatChangedCB(w, clientData, callData);
616 #endif /* VMS */
618 static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
620 char *format = XmTextGetString(etDialog.formatW);
622 /* pop down the dialog */
623 /* XtUnmanageChild(etDialog.form); */
625 if (strcmp(format, GetPrefTitleFormat()) != 0) {
626 SetPrefTitleFormat(format);
628 XtFree(format);
631 static void dismissCB(Widget w, XtPointer clientData, XtPointer callData)
633 /* pop down the dialog */
634 XtUnmanageChild(etDialog.form);
637 static void restoreCB(Widget w, XtPointer clientData, XtPointer callData)
639 XmTextSetString(etDialog.formatW, "{%c} [%s] %f (%S) - %d");
642 static void helpCB(Widget w, XtPointer clientData, XtPointer callData)
644 Help(HELP_CUSTOM_TITLE_DIALOG);
647 static void wtDestroyCB(Widget w, XtPointer clientData, XtPointer callData)
649 if (w == etDialog.form) /* Prevent disconnecting the replacing dialog */
650 etDialog.form = NULL;
653 static void wtUnmapCB(Widget w, XtPointer clientData, XtPointer callData)
655 if (etDialog.form == w) /* Prevent destroying the replacing dialog */
656 XtDestroyWidget(etDialog.form);
659 static void appendToFormat(const char* string)
661 char *format = XmTextGetString(etDialog.formatW);
662 char *buf = XtMalloc(strlen(string) + strlen(format) + 1);
663 strcpy(buf, format);
664 strcat(buf, string);
665 XmTextSetString(etDialog.formatW, buf);
666 XtFree(format);
667 XtFree(buf);
670 static void removeFromFormat(const char* string)
672 char *format = XmTextGetString(etDialog.formatW);
673 char* pos;
675 /* There can be multiple occurences */
676 while ((pos = strstr(format, string)))
678 /* If the string is preceded or followed by a brace, include
679 the brace(s) for removal */
680 char* start = pos;
681 char* end = pos + strlen(string);
682 char post = *end;
684 if (post == '}' || post == ')' || post == ']' || post == '>')
686 end += 1;
687 post = *end;
690 if (start > format)
692 char pre = *(start-1);
693 if (pre == '{' || pre == '(' || pre == '[' || pre == '<')
694 start -= 1;
696 if (start > format)
698 char pre = *(start-1);
699 /* If there is a space in front and behind, remove one space
700 (there can be more spaces, but in that case it is likely
701 that the user entered them manually); also remove trailing
702 space */
703 if (pre == ' ' && post == ' ')
705 end += 1;
707 else if (pre == ' ' && post == (char)0)
709 /* Remove (1) trailing space */
710 start -= 1;
714 /* Contract the string: move end to start */
715 strcpy(start, end);
718 /* Remove leading and trailing space */
719 pos = format;
720 while (*pos == ' ') ++pos;
721 strcpy(format, pos);
723 pos = format + strlen(format) - 1;
724 while (pos >= format && *pos == ' ')
726 --pos;
728 *(pos+1) = (char)0;
730 XmTextSetString(etDialog.formatW, format);
731 XtFree(format);
735 static void toggleFileCB(Widget w, XtPointer clientData, XtPointer callData)
737 if (XmToggleButtonGetState(etDialog.fileW))
738 appendToFormat(" %f");
739 else
740 removeFromFormat("%f");
743 static void toggleServerCB(Widget w, XtPointer clientData, XtPointer callData)
745 if (XmToggleButtonGetState(etDialog.serverW))
746 appendToFormat(" [%s]");
747 else
748 removeFromFormat("%s");
751 static void toggleHostCB(Widget w, XtPointer clientData, XtPointer callData)
753 if (XmToggleButtonGetState(etDialog.hostW))
754 appendToFormat(" [%h]");
755 else
756 removeFromFormat("%h");
759 #ifndef VMS
760 static void toggleClearCaseCB(Widget w, XtPointer clientData, XtPointer callData)
762 if (XmToggleButtonGetState(etDialog.ccW))
763 appendToFormat(" {%c}");
764 else
765 removeFromFormat("%c");
767 #endif /* VMS */
769 static void toggleStatusCB(Widget w, XtPointer clientData, XtPointer callData)
771 if (XmToggleButtonGetState(etDialog.statusW))
773 if (XmToggleButtonGetState(etDialog.shortStatusW))
774 appendToFormat(" (%*S)");
775 else
776 appendToFormat(" (%S)");
778 else
780 removeFromFormat("%S");
781 removeFromFormat("%*S");
785 static void toggleShortStatusCB(Widget w, XtPointer clientData, XtPointer callData)
787 char *format, *pos;
789 if (etDialog.suppressFormatUpdate)
791 return;
794 format = XmTextGetString(etDialog.formatW);
796 if (XmToggleButtonGetState(etDialog.shortStatusW))
798 /* Find all %S occurrences and replace them by %*S */
801 pos = strstr(format, "%S");
802 if (pos)
804 char* tmp = (char*)XtMalloc((strlen(format)+2)*sizeof(char));
805 strncpy(tmp, format, (size_t)(pos-format+1));
806 tmp[pos-format+1] = 0;
807 strcat(tmp, "*");
808 strcat(tmp, pos+1);
809 XtFree(format);
810 format = tmp;
813 while (pos);
815 else
817 /* Replace all %*S occurences by %S */
820 pos = strstr(format, "%*S");
821 if (pos)
823 strcpy(pos+1, pos+2);
826 while(pos);
829 XmTextSetString(etDialog.formatW, format);
830 XtFree(format);
833 static void toggleUserCB(Widget w, XtPointer clientData, XtPointer callData)
835 if (XmToggleButtonGetState(etDialog.nameW))
836 appendToFormat(" %u");
837 else
838 removeFromFormat("%u");
841 static void toggleDirectoryCB(Widget w, XtPointer clientData, XtPointer callData)
843 if (XmToggleButtonGetState(etDialog.dirW))
845 char buf[20];
846 int maxComp;
847 char *value = XmTextGetString(etDialog.ndirW);
848 if (*value)
850 if (sscanf(value, "%d", &maxComp) > 0)
852 sprintf(&buf[0], " %%%dd ", maxComp);
854 else
856 sprintf(&buf[0], " %%d "); /* Should not be necessary */
859 else
861 sprintf(&buf[0], " %%d ");
863 XtFree(value);
864 appendToFormat(buf);
866 else
868 int i;
869 removeFromFormat("%d");
870 for (i=0; i<=9; ++i)
872 char buf[20];
873 sprintf(&buf[0], "%%%dd", i);
874 removeFromFormat(buf);
879 static void enterMaxDirCB(Widget w, XtPointer clientData, XtPointer callData)
881 int maxComp = -1;
882 char *format;
883 char *value;
885 if (etDialog.suppressFormatUpdate)
887 return;
890 format = XmTextGetString(etDialog.formatW);
891 value = XmTextGetString(etDialog.ndirW);
893 if (*value)
895 if (sscanf(value, "%d", &maxComp) <= 0)
897 /* Don't allow non-digits to be entered */
898 XBell(XtDisplay(w), 0);
899 XmTextSetString(etDialog.ndirW, "");
903 if (maxComp >= 0)
905 char *pos;
906 int found = False;
907 char insert[2];
908 insert[0] = (char)('0' + maxComp);
909 insert[1] = (char)0; /* '0' digit and 0 char ! */
911 /* Find all %d and %nd occurrences and replace them by the new value */
914 int i;
915 found = False;
916 pos = strstr(format, "%d");
917 if (pos)
919 char* tmp = (char*)XtMalloc((strlen(format)+2)*sizeof(char));
920 strncpy(tmp, format, (size_t)(pos-format+1));
921 tmp[pos-format+1] = 0;
922 strcat(tmp, &insert[0]);
923 strcat(tmp, pos+1);
924 XtFree(format);
925 format = tmp;
926 found = True;
929 for (i=0; i<=9; ++i)
931 char buf[20];
932 sprintf(&buf[0], "%%%dd", i);
933 if (i != maxComp)
935 pos = strstr(format, &buf[0]);
936 if (pos)
938 *(pos+1) = insert[0];
939 found = True;
944 while (found);
946 else
948 int found = True;
950 /* Replace all %nd occurences by %d */
953 int i;
954 found = False;
955 for (i=0; i<=9; ++i)
957 char buf[20];
958 char *pos;
959 sprintf(&buf[0], "%%%dd", i);
960 pos = strstr(format, &buf[0]);
961 if (pos)
963 strcpy(pos+1, pos+2);
964 found = True;
968 while(found);
971 XmTextSetString(etDialog.formatW, format);
972 XtFree(format);
973 XtFree(value);
976 static void createEditTitleDialog(Widget parent)
978 #define LEFT_MARGIN_POS 2
979 #define RIGHT_MARGIN_POS 98
980 #define V_MARGIN 5
981 #define RADIO_INDENT 3
983 Widget buttonForm, formatLbl, previewFrame;
984 Widget previewForm, previewBox, selectFrame, selectBox, selectForm;
985 Widget testLbl, selectLbl;
986 Widget applyBtn, dismissBtn, restoreBtn, helpBtn;
987 XmString s1;
988 XmFontList fontList;
989 Arg args[20];
990 int defaultBtnOffset;
991 Dimension shadowThickness;
992 Dimension radioHeight, textHeight;
993 Pixel background;
995 int ac = 0;
996 XtSetArg(args[ac], XmNautoUnmanage, False); ac++;
997 XtSetArg(args[ac], XmNtitle, "Customize Window Title"); ac++;
998 etDialog.form = CreateFormDialog(parent, "customizeTitle", args, ac);
1001 * Destroy the dialog every time it is unmapped (otherwise it 'sticks'
1002 * to the window for which it was created originally).
1004 XtAddCallback(etDialog.form, XmNunmapCallback, wtUnmapCB, NULL);
1005 XtAddCallback(etDialog.form, XmNdestroyCallback, wtDestroyCB, NULL);
1007 etDialog.shell = XtParent(etDialog.form);
1009 /* Definition form */
1010 selectFrame = XtVaCreateManagedWidget("selectionFrame", xmFrameWidgetClass,
1011 etDialog.form,
1012 XmNleftAttachment, XmATTACH_POSITION,
1013 XmNleftPosition, LEFT_MARGIN_POS,
1014 XmNtopAttachment, XmATTACH_FORM,
1015 XmNtopOffset, V_MARGIN,
1016 XmNrightAttachment, XmATTACH_POSITION,
1017 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1019 XtVaCreateManagedWidget("titleLabel", xmLabelGadgetClass,
1020 selectFrame,
1021 XmNlabelString,
1022 s1=XmStringCreateSimple("Title definition"),
1023 XmNchildType, XmFRAME_TITLE_CHILD,
1024 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, NULL);
1025 XmStringFree(s1);
1027 selectForm = XtVaCreateManagedWidget("selectForm", xmFormWidgetClass,
1028 selectFrame ,
1029 XmNleftAttachment, XmATTACH_POSITION,
1030 XmNleftPosition, LEFT_MARGIN_POS,
1031 XmNtopAttachment, XmATTACH_FORM,
1032 XmNtopOffset, V_MARGIN,
1033 XmNrightAttachment, XmATTACH_POSITION,
1034 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1036 selectLbl = XtVaCreateManagedWidget("selectLabel", xmLabelGadgetClass,
1037 selectForm,
1038 XmNlabelString, s1=XmStringCreateSimple("Select title components to include: "),
1039 XmNleftAttachment, XmATTACH_POSITION,
1040 XmNleftPosition, LEFT_MARGIN_POS,
1041 XmNtopOffset, 5,
1042 XmNbottomOffset, 5,
1043 XmNtopAttachment, XmATTACH_FORM, NULL);
1044 XmStringFree(s1);
1046 selectBox = XtVaCreateManagedWidget("selectBox", xmFormWidgetClass,
1047 selectForm,
1048 XmNorientation, XmHORIZONTAL,
1049 XmNpacking, XmPACK_TIGHT,
1050 XmNradioBehavior, False,
1051 XmNleftAttachment, XmATTACH_FORM,
1052 XmNrightAttachment, XmATTACH_FORM,
1053 XmNtopOffset, 5,
1054 XmNtopAttachment, XmATTACH_WIDGET,
1055 XmNtopWidget, selectLbl,
1056 NULL);
1058 etDialog.fileW = XtVaCreateManagedWidget("file",
1059 xmToggleButtonWidgetClass, selectBox,
1060 XmNleftAttachment, XmATTACH_POSITION,
1061 XmNleftPosition, RADIO_INDENT,
1062 XmNtopAttachment, XmATTACH_FORM,
1063 XmNlabelString, s1=XmStringCreateSimple("File name (%f)"),
1064 XmNmnemonic, 'F', NULL);
1065 XtAddCallback(etDialog.fileW, XmNvalueChangedCallback, toggleFileCB, NULL);
1066 XmStringFree(s1);
1068 etDialog.statusW = XtVaCreateManagedWidget("status",
1069 xmToggleButtonWidgetClass, selectBox,
1070 XmNleftAttachment, XmATTACH_POSITION,
1071 XmNleftPosition, RADIO_INDENT,
1072 XmNtopAttachment, XmATTACH_WIDGET,
1073 XmNtopWidget, etDialog.fileW,
1074 XmNlabelString, s1=XmStringCreateSimple("File status (%S) "),
1075 XmNmnemonic, 't', NULL);
1076 XtAddCallback(etDialog.statusW, XmNvalueChangedCallback, toggleStatusCB, NULL);
1077 XmStringFree(s1);
1079 etDialog.shortStatusW = XtVaCreateManagedWidget("shortStatus",
1080 xmToggleButtonWidgetClass, selectBox,
1081 XmNleftAttachment, XmATTACH_WIDGET,
1082 XmNleftWidget, etDialog.statusW,
1083 XmNtopAttachment, XmATTACH_WIDGET,
1084 XmNtopWidget, etDialog.fileW,
1085 XmNlabelString, s1=XmStringCreateSimple("brief"),
1086 XmNmnemonic, 'b', NULL);
1087 XtAddCallback(etDialog.shortStatusW, XmNvalueChangedCallback, toggleShortStatusCB, NULL);
1088 XmStringFree(s1);
1090 etDialog.ccW = XtVaCreateManagedWidget("ccView",
1091 xmToggleButtonWidgetClass, selectBox,
1092 XmNleftAttachment, XmATTACH_POSITION,
1093 XmNleftPosition, RADIO_INDENT,
1094 XmNtopAttachment, XmATTACH_WIDGET,
1095 XmNtopWidget, etDialog.statusW,
1096 XmNlabelString, s1=XmStringCreateSimple("ClearCase view tag (%c) "),
1097 XmNmnemonic, 'C', NULL);
1098 #ifdef VMS
1099 XtSetSensitive(etDialog.ccW, False);
1100 #else
1101 XtAddCallback(etDialog.ccW, XmNvalueChangedCallback, toggleClearCaseCB, NULL);
1102 #endif /* VMS */
1103 XmStringFree(s1);
1105 etDialog.dirW = XtVaCreateManagedWidget("directory",
1106 xmToggleButtonWidgetClass, selectBox,
1107 XmNleftAttachment, XmATTACH_POSITION,
1108 XmNleftPosition, RADIO_INDENT,
1109 XmNtopAttachment, XmATTACH_WIDGET,
1110 XmNtopWidget, etDialog.ccW,
1111 XmNlabelString, s1=XmStringCreateSimple("Directory (%d),"),
1112 XmNmnemonic, 'D', NULL);
1113 XtAddCallback(etDialog.dirW, XmNvalueChangedCallback, toggleDirectoryCB, NULL);
1114 XmStringFree(s1);
1116 XtVaGetValues(etDialog.fileW, XmNheight, &radioHeight, NULL);
1117 etDialog.mdirW = XtVaCreateManagedWidget("componentLab",
1118 xmLabelGadgetClass, selectBox,
1119 XmNheight, radioHeight,
1120 XmNleftAttachment, XmATTACH_WIDGET,
1121 XmNleftWidget, etDialog.dirW,
1122 XmNtopAttachment, XmATTACH_WIDGET,
1123 XmNtopWidget, etDialog.ccW,
1124 XmNlabelString, s1=XmStringCreateSimple("max. components: "),
1125 XmNmnemonic, 'x', NULL);
1126 XmStringFree(s1);
1128 etDialog.ndirW = XtVaCreateManagedWidget("dircomp",
1129 xmTextWidgetClass, selectBox,
1130 XmNcolumns, 1,
1131 XmNmaxLength, 1,
1132 XmNleftAttachment, XmATTACH_WIDGET,
1133 XmNleftWidget, etDialog.mdirW,
1134 XmNtopAttachment, XmATTACH_WIDGET,
1135 XmNtopWidget, etDialog.ccW,
1136 NULL);
1137 XtAddCallback(etDialog.ndirW, XmNvalueChangedCallback, enterMaxDirCB, NULL);
1138 RemapDeleteKey(etDialog.ndirW);
1139 XtVaSetValues(etDialog.mdirW, XmNuserData, etDialog.ndirW, NULL); /* mnemonic processing */
1141 XtVaGetValues(etDialog.ndirW, XmNheight, &textHeight, NULL);
1142 XtVaSetValues(etDialog.dirW, XmNheight, textHeight, NULL);
1143 XtVaSetValues(etDialog.mdirW, XmNheight, textHeight, NULL);
1145 etDialog.hostW = XtVaCreateManagedWidget("host",
1146 xmToggleButtonWidgetClass, selectBox,
1147 XmNleftAttachment, XmATTACH_POSITION,
1148 XmNleftPosition, 50 + RADIO_INDENT,
1149 XmNtopAttachment, XmATTACH_FORM,
1150 XmNlabelString, s1=XmStringCreateSimple("Host name (%h)"),
1151 XmNmnemonic, 'H', NULL);
1152 XtAddCallback(etDialog.hostW, XmNvalueChangedCallback, toggleHostCB, NULL);
1153 XmStringFree(s1);
1155 etDialog.nameW = XtVaCreateManagedWidget("name",
1156 xmToggleButtonWidgetClass, selectBox,
1157 XmNleftAttachment, XmATTACH_POSITION,
1158 XmNleftPosition, 50 + RADIO_INDENT,
1159 XmNtopAttachment, XmATTACH_WIDGET,
1160 XmNtopWidget, etDialog.hostW,
1161 XmNlabelString, s1=XmStringCreateSimple("User name (%u)"),
1162 XmNmnemonic, 'U', NULL);
1163 XtAddCallback(etDialog.nameW, XmNvalueChangedCallback, toggleUserCB, NULL);
1164 XmStringFree(s1);
1166 etDialog.serverW = XtVaCreateManagedWidget("server",
1167 xmToggleButtonWidgetClass, selectBox,
1168 XmNleftAttachment, XmATTACH_POSITION,
1169 XmNleftPosition, 50 + RADIO_INDENT,
1170 XmNtopAttachment, XmATTACH_WIDGET,
1171 XmNtopWidget, etDialog.nameW,
1172 XmNlabelString, s1=XmStringCreateSimple("NEdit server name (%s)"),
1173 XmNmnemonic, 's', NULL);
1174 XtAddCallback(etDialog.serverW, XmNvalueChangedCallback, toggleServerCB, NULL);
1175 XmStringFree(s1);
1177 formatLbl = XtVaCreateManagedWidget("formatLbl", xmLabelGadgetClass,
1178 selectForm,
1179 XmNlabelString, s1=XmStringCreateSimple("Format: "),
1180 XmNmnemonic, 'r',
1181 XmNleftAttachment, XmATTACH_POSITION,
1182 XmNleftPosition, LEFT_MARGIN_POS,
1183 XmNtopAttachment, XmATTACH_WIDGET,
1184 XmNtopWidget, selectBox,
1185 XmNbottomAttachment, XmATTACH_FORM, NULL);
1186 XmStringFree(s1);
1187 etDialog.formatW = XtVaCreateManagedWidget("format", xmTextWidgetClass,
1188 selectForm,
1189 XmNmaxLength, WINDOWTITLE_MAX_LEN,
1190 XmNtopAttachment, XmATTACH_WIDGET,
1191 XmNtopWidget, selectBox,
1192 XmNtopOffset, 5,
1193 XmNleftAttachment, XmATTACH_WIDGET,
1194 XmNleftWidget, formatLbl,
1195 XmNrightAttachment, XmATTACH_POSITION,
1196 XmNrightPosition, RIGHT_MARGIN_POS,
1197 XmNbottomAttachment, XmATTACH_FORM,
1198 XmNbottomOffset, 5, NULL);
1199 RemapDeleteKey(etDialog.formatW);
1200 XtVaSetValues(formatLbl, XmNuserData, etDialog.formatW, NULL);
1201 XtAddCallback(etDialog.formatW, XmNvalueChangedCallback, formatChangedCB, NULL);
1203 XtVaGetValues(etDialog.formatW, XmNheight, &textHeight, NULL);
1204 XtVaSetValues(formatLbl, XmNheight, textHeight, NULL);
1206 previewFrame = XtVaCreateManagedWidget("previewFrame", xmFrameWidgetClass,
1207 etDialog.form,
1208 XmNtopAttachment, XmATTACH_WIDGET,
1209 XmNtopWidget, selectFrame,
1210 XmNleftAttachment, XmATTACH_POSITION,
1211 XmNleftPosition, LEFT_MARGIN_POS,
1212 XmNrightAttachment, XmATTACH_POSITION,
1213 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1215 XtVaCreateManagedWidget("previewLabel", xmLabelGadgetClass,
1216 previewFrame,
1217 XmNlabelString, s1=XmStringCreateSimple("Preview"),
1218 XmNchildType, XmFRAME_TITLE_CHILD,
1219 XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING, NULL);
1220 XmStringFree(s1);
1222 previewForm = XtVaCreateManagedWidget("previewForm", xmFormWidgetClass,
1223 previewFrame,
1224 XmNleftAttachment, XmATTACH_FORM,
1225 XmNleftPosition, LEFT_MARGIN_POS,
1226 XmNtopAttachment, XmATTACH_FORM,
1227 XmNtopOffset, V_MARGIN,
1228 XmNrightAttachment, XmATTACH_FORM,
1229 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1231 /* Copy a variable width font from one of the labels to use for the
1232 preview (no editing is allowed, and with a fixed size font the
1233 preview easily gets partially obscured). Also copy the form background
1234 color to make it clear that this field is not editable */
1235 XtVaGetValues(formatLbl, XmNfontList, &fontList, NULL);
1236 XtVaGetValues(previewForm, XmNbackground, &background, NULL);
1238 etDialog.previewW = XtVaCreateManagedWidget("sample",
1239 xmTextFieldWidgetClass, previewForm,
1240 XmNeditable, False,
1241 XmNcursorPositionVisible, False,
1242 XmNtopAttachment, XmATTACH_FORM,
1243 XmNleftAttachment, XmATTACH_FORM,
1244 XmNleftOffset, V_MARGIN,
1245 XmNrightAttachment, XmATTACH_FORM,
1246 XmNrightOffset, V_MARGIN,
1247 XmNfontList, fontList,
1248 XmNbackground, background,
1249 NULL);
1251 previewBox = XtVaCreateManagedWidget("previewBox", xmFormWidgetClass,
1252 previewForm,
1253 XmNorientation, XmHORIZONTAL,
1254 XmNpacking, XmPACK_TIGHT,
1255 XmNradioBehavior, False,
1256 XmNleftAttachment, XmATTACH_FORM,
1257 XmNrightAttachment, XmATTACH_FORM,
1258 XmNtopAttachment, XmATTACH_WIDGET,
1259 XmNtopWidget, etDialog.previewW, NULL);
1261 testLbl = XtVaCreateManagedWidget("testLabel", xmLabelGadgetClass,
1262 previewBox,
1263 XmNlabelString, s1=XmStringCreateSimple("Test settings: "),
1264 XmNleftAttachment, XmATTACH_POSITION,
1265 XmNleftPosition, LEFT_MARGIN_POS,
1266 XmNtopOffset, 5,
1267 XmNbottomOffset, 5,
1268 XmNtopAttachment, XmATTACH_FORM, NULL);
1269 XmStringFree(s1);
1271 etDialog.oFileChangedW = XtVaCreateManagedWidget("fileChanged",
1272 xmToggleButtonWidgetClass, previewBox,
1273 XmNleftAttachment, XmATTACH_POSITION,
1274 XmNleftPosition, RADIO_INDENT,
1275 XmNtopAttachment, XmATTACH_WIDGET,
1276 XmNtopWidget, testLbl,
1277 XmNlabelString, s1=XmStringCreateSimple("File modified"),
1278 XmNmnemonic, 'o', NULL);
1279 XtAddCallback(etDialog.oFileChangedW, XmNvalueChangedCallback, fileChangedCB, NULL);
1280 XmStringFree(s1);
1282 etDialog.oFileReadOnlyW = XtVaCreateManagedWidget("fileReadOnly",
1283 xmToggleButtonWidgetClass, previewBox,
1284 XmNleftAttachment, XmATTACH_WIDGET,
1285 XmNleftWidget, etDialog.oFileChangedW,
1286 XmNtopAttachment, XmATTACH_WIDGET,
1287 XmNtopWidget, testLbl,
1288 XmNlabelString, s1=XmStringCreateSimple("File read only"),
1289 XmNmnemonic, 'n', NULL);
1290 XtAddCallback(etDialog.oFileReadOnlyW, XmNvalueChangedCallback, fileReadOnlyCB, NULL);
1291 XmStringFree(s1);
1293 etDialog.oFileLockedW = XtVaCreateManagedWidget("fileLocked",
1294 xmToggleButtonWidgetClass, previewBox,
1295 XmNleftAttachment, XmATTACH_WIDGET,
1296 XmNleftWidget, etDialog.oFileReadOnlyW,
1297 XmNtopAttachment, XmATTACH_WIDGET,
1298 XmNtopWidget, testLbl,
1299 XmNlabelString, s1=XmStringCreateSimple("File locked"),
1300 XmNmnemonic, 'l', NULL);
1301 XtAddCallback(etDialog.oFileLockedW, XmNvalueChangedCallback, fileLockedCB, NULL);
1302 XmStringFree(s1);
1304 etDialog.oServerNameW = XtVaCreateManagedWidget("servernameSet",
1305 xmToggleButtonWidgetClass, previewBox,
1306 XmNleftAttachment, XmATTACH_POSITION,
1307 XmNleftPosition, RADIO_INDENT,
1308 XmNtopAttachment, XmATTACH_WIDGET,
1309 XmNtopWidget, etDialog.oFileChangedW,
1310 XmNlabelString, s1=XmStringCreateSimple("Server name present"),
1311 XmNmnemonic, 'v', NULL);
1312 XtAddCallback(etDialog.oServerNameW, XmNvalueChangedCallback, serverNameCB, NULL);
1313 XmStringFree(s1);
1315 etDialog.oCcViewTagW = XtVaCreateManagedWidget("ccViewTagSet",
1316 xmToggleButtonWidgetClass, previewBox,
1317 XmNleftAttachment, XmATTACH_POSITION,
1318 XmNleftPosition, RADIO_INDENT,
1319 XmNtopAttachment, XmATTACH_WIDGET,
1320 XmNtopWidget, etDialog.oServerNameW,
1321 XmNlabelString, s1=XmStringCreateSimple("CC view tag present"),
1322 #ifdef VMS
1323 XmNset, False,
1324 #else
1325 XmNset, GetClearCaseViewTag() != NULL,
1326 #endif /* VMS */
1327 XmNmnemonic, 'w', NULL);
1328 #ifdef VMS
1329 XtSetSensitive(etDialog.oCcViewTagW, False);
1330 #else
1331 XtAddCallback(etDialog.oCcViewTagW, XmNvalueChangedCallback, ccViewTagCB, NULL);
1332 #endif /* VMS */
1333 XmStringFree(s1);
1335 etDialog.oServerEqualViewW = XtVaCreateManagedWidget("serverEqualView",
1336 xmToggleButtonWidgetClass, previewBox,
1337 XmNleftAttachment, XmATTACH_WIDGET,
1338 XmNleftWidget, etDialog.oCcViewTagW,
1339 XmNtopAttachment, XmATTACH_WIDGET,
1340 XmNtopWidget, etDialog.oServerNameW,
1341 XmNlabelString, s1=XmStringCreateSimple("Server name equals CC view tag "),
1342 XmNmnemonic, 'q', NULL);
1343 #ifdef VMS
1344 XtSetSensitive(etDialog.oServerEqualViewW, False);
1345 #else
1346 XtAddCallback(etDialog.oServerEqualViewW, XmNvalueChangedCallback, serverEqualViewCB, NULL);
1347 #endif /* VMS */
1348 XmStringFree(s1);
1350 etDialog.oDirW = XtVaCreateManagedWidget("pathSet",
1351 xmToggleButtonWidgetClass, previewBox,
1352 XmNleftAttachment, XmATTACH_POSITION,
1353 XmNleftPosition, RADIO_INDENT,
1354 XmNtopAttachment, XmATTACH_WIDGET,
1355 XmNtopWidget, etDialog.oCcViewTagW,
1356 XmNlabelString, s1=XmStringCreateSimple("Directory present"),
1357 XmNmnemonic, 'i', NULL);
1358 XtAddCallback(etDialog.oDirW, XmNvalueChangedCallback, formatChangedCB, NULL);
1359 XmStringFree(s1);
1361 /* Button box */
1362 buttonForm = XtVaCreateManagedWidget("buttonForm", xmFormWidgetClass,
1363 etDialog.form,
1364 XmNleftAttachment, XmATTACH_POSITION,
1365 XmNleftPosition, LEFT_MARGIN_POS,
1366 XmNtopAttachment, XmATTACH_WIDGET,
1367 XmNtopWidget, previewFrame,
1368 XmNtopOffset, V_MARGIN,
1369 XmNbottomOffset, V_MARGIN,
1370 XmNbottomAttachment, XmATTACH_FORM,
1371 XmNrightAttachment, XmATTACH_POSITION,
1372 XmNrightPosition, RIGHT_MARGIN_POS, NULL);
1374 applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass,
1375 buttonForm,
1376 XmNhighlightThickness, 2,
1377 XmNlabelString, s1=XmStringCreateSimple("Apply"),
1378 XmNshowAsDefault, (short)1,
1379 XmNleftAttachment, XmATTACH_POSITION,
1380 XmNleftPosition, 6,
1381 XmNrightAttachment, XmATTACH_POSITION,
1382 XmNrightPosition, 25,
1383 XmNbottomAttachment, XmATTACH_FORM,
1384 NULL);
1385 XtAddCallback(applyBtn, XmNactivateCallback, applyCB, NULL);
1386 XmStringFree(s1);
1387 XtVaGetValues(applyBtn, XmNshadowThickness, &shadowThickness, NULL);
1388 defaultBtnOffset = shadowThickness + 4;
1390 dismissBtn = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass,
1391 buttonForm,
1392 XmNhighlightThickness, 2,
1393 XmNlabelString, s1=XmStringCreateSimple("Dismiss"),
1394 XmNleftAttachment, XmATTACH_POSITION,
1395 XmNleftPosition, 52,
1396 XmNrightAttachment, XmATTACH_POSITION,
1397 XmNrightPosition, 71,
1398 XmNbottomAttachment, XmATTACH_FORM,
1399 XmNbottomOffset, defaultBtnOffset,
1400 NULL);
1401 XtAddCallback(dismissBtn, XmNactivateCallback, dismissCB, NULL);
1402 XmStringFree(s1);
1404 restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass,
1405 buttonForm,
1406 XmNhighlightThickness, 2,
1407 XmNlabelString, s1=XmStringCreateSimple("Default"),
1408 XmNleftAttachment, XmATTACH_POSITION,
1409 XmNleftPosition, 29,
1410 XmNrightAttachment, XmATTACH_POSITION,
1411 XmNrightPosition, 48,
1412 XmNbottomAttachment, XmATTACH_FORM,
1413 XmNbottomOffset, defaultBtnOffset,
1414 XmNmnemonic, 'e', NULL);
1415 XtAddCallback(restoreBtn, XmNactivateCallback, restoreCB, NULL);
1416 XmStringFree(s1);
1418 helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
1419 buttonForm,
1420 XmNhighlightThickness, 2,
1421 XmNlabelString, s1=XmStringCreateSimple("Help"),
1422 XmNleftAttachment, XmATTACH_POSITION,
1423 XmNleftPosition, 75,
1424 XmNrightAttachment, XmATTACH_POSITION,
1425 XmNrightPosition, 94,
1426 XmNbottomAttachment, XmATTACH_FORM,
1427 XmNbottomOffset, defaultBtnOffset,
1428 XmNmnemonic, 'p', NULL);
1429 XtAddCallback(helpBtn, XmNactivateCallback, helpCB, NULL);
1430 XmStringFree(s1);
1432 /* Set initial default button */
1433 XtVaSetValues(etDialog.form, XmNdefaultButton, applyBtn, NULL);
1434 XtVaSetValues(etDialog.form, XmNcancelButton, dismissBtn, NULL);
1436 /* Handle mnemonic selection of buttons and focus to dialog */
1437 AddDialogMnemonicHandler(etDialog.form, FALSE);
1439 etDialog.suppressFormatUpdate = FALSE;
1442 void EditCustomTitleFormat(WindowInfo *window)
1444 /* copy attributes from current window so that we can use as many
1445 * 'real world' defaults as possible when testing the effect
1446 * of different formatting strings.
1448 strcpy(etDialog.path, window->path);
1449 strcpy(etDialog.filename, window->filename);
1450 #ifndef VMS
1451 strcpy(etDialog.viewTag, GetClearCaseViewTag() != NULL ?
1452 GetClearCaseViewTag() :
1453 "viewtag");
1454 #endif /* VMS */
1455 strcpy(etDialog.serverName, IsServer ?
1456 GetPrefServerName() :
1457 "servername");
1458 etDialog.isServer = IsServer;
1459 etDialog.filenameSet = window->filenameSet;
1460 etDialog.lockReasons = window->lockReasons;
1461 etDialog.fileChanged = window->fileChanged;
1463 if (etDialog.window != window && etDialog.form)
1465 /* Destroy the dialog owned by the other window.
1466 Note: don't rely on the destroy event handler to reset the
1467 form. Events are handled asynchronously, so the old dialog
1468 may continue to live for a while. */
1469 XtDestroyWidget(etDialog.form);
1470 etDialog.form = NULL;
1473 etDialog.window = window;
1475 /* Create the dialog if it doesn't already exist */
1476 if (etDialog.form == NULL)
1478 createEditTitleDialog(window->shell);
1480 else
1482 /* If the window is already up, just pop it to the top */
1483 if (XtIsManaged(etDialog.form)) {
1485 RaiseShellWindow(XtParent(etDialog.form));
1487 /* force update of the dialog */
1488 setToggleButtons();
1489 formatChangedCB(0, 0, 0);
1490 return;
1494 /* set initial value of format field */
1495 XmTextSetString(etDialog.formatW, (char *)GetPrefTitleFormat());
1497 /* force update of the dialog */
1498 setToggleButtons();
1499 formatChangedCB(0, 0, 0);
1501 /* put up dialog and wait for user to press ok or cancel */
1502 ManageDialogCenteredOnPointer(etDialog.form);