dtcm: Resolve CID 87801
[oweals/cde.git] / cde / programs / dtstyle / Main.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*****************************************************************************
24  **
25  **   File:        Main.c
26  **
27  **   Project:     DT 3.0
28  **
29  **   Description: main Dtstyle program
30  **
31  **
32  ****************************************************************************
33  ************************************<+>*************************************/
34 /*$TOG: Main.c /main/16 1998/07/30 12:32:34 mgreess $*/
35 /* 
36  * (c) Copyright 1997, The Open Group 
37  */
38 /*
39  * (c) Copyright 1996 Digital Equipment Corporation.
40  * (c) Copyright 1990, 1993, 1996 Hewlett-Packard Company.
41  * (c) Copyright 1996 International Business Machines Corp.
42  * (c) Copyright 1996 Sun Microsystems, Inc.
43  * (c) Copyright 1996 Novell, Inc. 
44  * (c) Copyright 1996 FUJITSU LIMITED.
45  * (c) Copyright 1996 Hitachi.
46  */
47
48 /*+++++++++++++++++++++++++++++++++++++++*/
49 /* include files                         */
50 /*+++++++++++++++++++++++++++++++++++++++*/
51
52 #include "signal.h"
53 #ifdef TIME
54 # include <time.h>
55 #endif
56 #ifndef NO_MESSAGE_CATALOG
57 # include <nl_types.h>
58 # define TRUE 1
59 # define FALSE 0
60 #endif
61 #include <locale.h>
62
63 /* #include <sys/dir.h> */
64 #include <X11/Xlib.h>
65 #include <Xm/MwmUtil.h>
66
67 #include <Xm/Xm.h>
68 #include <Xm/XmP.h>
69 #include <Xm/MessageB.h>
70
71 #include <Dt/GetDispRes.h>
72 #include <Dt/EnvControlP.h>
73 #include <Dt/Message.h>
74 #include <Dt/SessionM.h>
75 #include <Dt/UserMsg.h>
76 #include <Dt/Wsm.h>
77 #include <Dt/DtNlUtils.h>
78 #include <Dt/DtosP.h>
79
80 #include "MainWin.h"
81 #include "ColorMain.h"
82 #include "ColorFile.h"
83 #include "Resource.h"
84 #include "Protocol.h"
85
86 /*+++++++++++++++++++++++++++++++++++++++*/
87 /* include extern functions              */
88 /*+++++++++++++++++++++++++++++++++++++++*/
89 #include "Main.h"
90
91 /*+++++++++++++++++++++++++++++++++++++++*/
92 /* Local #defines                        */
93 /*+++++++++++++++++++++++++++++++++++++++*/
94 #define STYLE_LOCK "STYLE_LOCK"
95 #define SYS_FILE_SEARCH_PATH "DTPMSYSFILESEARCHPATH"
96 #define MAX_STR_LEN 128
97
98 /*+++++++++++++++++++++++++++++++++++++++*/
99 /* Internal Functions                    */
100 /*+++++++++++++++++++++++++++++++++++++++*/
101
102
103 static int ErrorHandler(
104                         Display *disp,
105                         XErrorEvent *event ) ;
106 static int IOErrorHandler(
107                         Display *disp ) ;
108
109 static void ToolkitErrorHandler(
110                         char *message) ;
111 static void errParentMap( 
112                         Widget w,
113                         XtPointer client_data,
114                         XEvent *event) ;
115 static void UnmanageCB( 
116                         Widget w,
117                         XtPointer client_data,
118                         XtPointer call_data) ;
119 static void DestroyCB( 
120                         Widget w,
121                         XtPointer client_data,
122                         XtPointer call_data) ;
123 static Boolean NewCreateD( XtPointer shell) ;
124 static Boolean NewAddTo( XtPointer shell) ;
125 static Boolean NewCreateTop1( XtPointer shell) ;
126 static Boolean NewCreateTop2( XtPointer shell) ;
127 static Boolean NewAddSysPath( XtPointer shell) ;
128 static Boolean NewAddDirectories( XtPointer shell) ;
129 static Boolean NewAddHomePath( XtPointer shell) ;
130 static Boolean NewReadPal( XtPointer shell) ;
131 static Boolean NewInitPal( XtPointer shell) ;
132 static Boolean NewAllocColor( XtPointer shell) ;
133 static Boolean NewBottomColor( XtPointer shell) ;
134 static Boolean NewCreateButtons( XtPointer shell) ;
135
136 extern void WaitChildDeath(void);
137
138 /*++++++++++++++++++++++++++++++++++++++*/
139 /* Internal Variables                   */
140 /*++++++++++++++++++++++++++++++++++++++*/
141 static XrmOptionDescRec option_list[] =
142 {
143    {  "-session",  "session",    XrmoptionSepArg,  NULL  },
144 };
145
146 /*++++++++++++++++++++++++++++++++++++++*/
147 /* Global Variables                     */
148 /*++++++++++++++++++++++++++++++++++++++*/
149 Style style;
150 char  *progName;
151
152 /*+++++++++++++++++++++++++++++++++++++++++++*/
153 /*Misc functions all the dialogs use         */
154 /*+++++++++++++++++++++++++++++++++++++++++++*/
155
156 /*+++++++++++++++++++++++++++++++++++++++++++*/
157 /* raise a dialog window above peer dialogs  */
158 /* Needs the SHELL of the dialog, not the    */
159 /* dialog box.                               */
160 /*+++++++++++++++++++++++++++++++++++++++++++*/
161 void 
162 raiseWindow(
163         Window dialogWin )
164 {
165   static int changeMask = CWStackMode;
166   static XWindowChanges windowChanges = {0,0,0,0,0,0,Above};
167
168     XReconfigureWMWindow(style.display, dialogWin,
169       style.screenNum, changeMask, &windowChanges);
170 }
171
172
173 /************************************************************************
174  * CenterMsgCB 
175  *    - to be used with message dialogs (assumptions are being made that 
176  *      parent is dialog shell, and child is bb, due to Xm hacks for them)
177  *      (eg. it sets bb x,y to 0,0 and parents x,y to x,y set for bb)
178  *    - parent for positioning only (may not be real parent)
179  *    - use client_data for parent... if NULL, use style.errParent if ok,
180  *    - or main style.shell (makes this routine more generally usefull)
181  *
182  ************************************************************************/
183 void 
184 CenterMsgCB(
185         Widget w,
186         XtPointer client_data,
187         XtPointer call_data )
188 {
189     int n;
190     Position newX, newY;
191     Arg args[4];
192     Widget   shell;
193
194     /* figure out what to use as "visual" parent */
195     shell = (Widget)client_data;
196     if (shell == NULL)
197     {
198         if (!style.errParent || !XtParent(style.errParent) || 
199             !XtIsManaged(style.errParent))
200             shell = style.shell;
201         else
202             shell = XtParent(style.errParent);
203     }
204     else
205         shell = XtParent(shell);
206
207     /* calculate new x,y to be centered in visualParent */
208     newX = XtX(shell) + XtWidth(shell)/2 - XtWidth(w)/2;
209     newY = XtY(shell) + XtHeight(shell)/2 - XtHeight(w)/2;
210
211     if (newX < 0) newX = 0;
212     if (newY < 0) newY = 0;
213
214     n = 0;
215     XtSetArg(args[n], XmNx, newX); n++;
216     XtSetArg(args[n], XmNy, newY); n++;
217     XtSetValues(w, args, n);
218 }
219
220
221 /*************************************************************/
222 /* ErrDialog                                                 */
223 /* Put up an error dialog and block until the user clicks OK */
224 /* by default, there is no cancel or help button, but the    */
225 /* dialog is created with autoUnmanage false, and ok/cancel  */
226 /* callbacks to do the unmanage, so that a help button can   */
227 /* be used                                                   */
228 /*************************************************************/
229 void 
230 ErrDialog(
231         char *errString,
232         Widget visualParent )
233 {
234     int           n;
235     Arg           args[10];
236     XmString      ok;
237
238     /* create the compound string */
239     style.tmpXmStr = CMPSTR(errString);
240
241     style.errParent = visualParent;
242
243     if (style.errDialog == NULL)     /* create it */
244     {
245         ok = XmStringCreateLocalized((String) _DtOkString);
246
247         n = 0;
248         XtSetArg(args[n], XmNokLabelString, ok); n++;
249         XtSetArg(args[n], XmNmessageString, style.tmpXmStr);                n++;
250         XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC);                n++;
251         XtSetArg (args[n], XmNautoUnmanage, False);                         n++;
252         XtSetArg (args[n], XmNdefaultPosition, False);                      n++;
253         style.errDialog = XmCreateErrorDialog(style.shell,"ErrorNotice",args,n);
254
255         XtAddCallback (style.errDialog, XmNokCallback, UnmanageCB, NULL);
256         XtAddCallback (style.errDialog, XmNcancelCallback, UnmanageCB, NULL);
257         XtAddCallback (style.errDialog, XmNmapCallback, CenterMsgCB, NULL);
258         XtUnmanageChild ( XmMessageBoxGetChild (style.errDialog,
259                                                 XmDIALOG_CANCEL_BUTTON));
260         XtUnmanageChild ( XmMessageBoxGetChild (style.errDialog,
261                                                 XmDIALOG_HELP_BUTTON));
262
263         /* set the dialog shell parent title */
264         n=0;
265         XtSetArg (args[n], XmNmwmInputMode,
266                         MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
267         XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
268         XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(2, 3, "Error")));   n++;
269         XtSetValues (XtParent(style.errDialog), args, n);
270     }
271     else                 /* change the string */
272     {
273         n = 0;
274         XtSetArg(args[n], XmNmessageString, style.tmpXmStr); n++;
275         XtSetValues (style.errDialog, args, n);
276     }
277
278     /* free the compound string */
279     XmStringFree (style.tmpXmStr);
280
281     if (XtIsManaged(style.errParent) || XtParent(style.errParent) == NULL)
282     {
283         XtManageChild(style.errDialog);
284         /* ring the bell (PM behavior) */
285         XBell(style.display, 0);
286     }
287     else
288     {
289         XtAddEventHandler(XtParent(style.errParent), StructureNotifyMask, 0,
290                           (XtEventHandler)errParentMap, NULL);
291     }
292
293 }
294
295
296
297 static void 
298 errParentMap(
299         Widget w,
300         XtPointer client_data,
301         XEvent *event )
302 {
303     if (event->type == MapNotify)
304     {
305         XtManageChild(style.errDialog);
306         /* ring the bell (PM behavior) */
307         XBell(style.display, 0);
308         XtRemoveEventHandler(XtParent(style.errParent), StructureNotifyMask,
309                              0, (XtEventHandler)errParentMap, NULL);
310     }
311 }
312
313 /*********************************************************/
314 /* InfoDialog                                            */
315 /* Put up a modeless info dialog.                        */
316 /* There is no cancel or help button.                    */
317 /* Dialog is created with autoUnmanage true.             */
318 /* An ok callback is added which will destroy the dialog */
319 /* and optionally unmap the parent.                      */
320 /*********************************************************/
321 void
322 InfoDialog(
323         char *infoString,
324         Widget parent,
325         Boolean unmapParent )
326 {
327     int             n;
328     Arg             args[10];
329     static XmString ok = NULL;
330     Widget          w;
331
332     /* create the compound string */
333     style.tmpXmStr = CMPSTR(infoString);
334
335     if (ok == NULL)
336         ok = CMPSTR((String) _DtOkString);
337
338     /* create it */
339     n = 0;
340     XtSetArg(args[n], XmNokLabelString, ok);                            n++;
341     XtSetArg(args[n], XmNmessageString, style.tmpXmStr);                n++;
342     XtSetArg(args[n], XmNdialogStyle, XmDIALOG_MODELESS);               n++;
343     XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC);                n++;
344     w = XmCreateInformationDialog(parent, "Notice", args, n);
345
346     if (unmapParent)
347         XtAddCallback (w, XmNokCallback, DestroyCB, parent);
348     else
349         XtAddCallback (w, XmNokCallback, DestroyCB, NULL);
350     XtUnmanageChild ( XmMessageBoxGetChild(w, XmDIALOG_CANCEL_BUTTON) );
351     XtUnmanageChild ( XmMessageBoxGetChild(w, XmDIALOG_HELP_BUTTON) );
352
353     /* set the dialog shell parent title */
354     n=0;
355     XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
356     XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(2, 2, "Notice")));   n++;
357     XtSetValues (XtParent(w), args, n);
358
359     /* free the compound string */
360     XmStringFree (style.tmpXmStr);
361
362     /* manage the info dialog */
363     XtManageChild(w);
364
365 }
366
367
368 /*++++++++++++++++++++++++++++++++++++++*/
369 /* UnmanageCB                           */
370 /*++++++++++++++++++++++++++++++++++++++*/
371 static void 
372 UnmanageCB(
373         Widget w,
374         XtPointer client_data,
375         XtPointer call_data )
376 {
377   XtUnmanageChild(w);
378 }
379
380
381 /*++++++++++++++++++++++++++++++++++++++*/
382 /* DestroyCB                            */
383 /*++++++++++++++++++++++++++++++++++++++*/
384 static void 
385 DestroyCB(
386         Widget w,
387         XtPointer client_data,
388         XtPointer call_data )
389 {
390   XtDestroyWidget(XtParent(w));
391   if (client_data != NULL)
392       XtUnmanageChild((Widget)client_data); 
393 }
394
395
396 /**********************************************************/
397 /* putDialog                                              */
398 /* move a dialog up so it isn't covering the main window  */
399 /* Or down if there is no room up.                        */
400 /* note: "parent" needs to have valid x,y information...  */
401 /*       ex: a child of dialog shell doesn't, its parent  */
402 /*       does, so the parent shell would be passed in     */
403 /**********************************************************/
404 void 
405 putDialog(
406         Widget parent,
407         Widget dialog )
408 {
409   int n;
410   Position newX, newY, pY, pX;
411   Dimension pHeight, myHeight, pWidth, myWidth;
412   Arg args[4];
413
414     pX = XtX(parent);
415     pY = XtY(parent);
416     pHeight = XtHeight(parent);
417     pWidth = XtWidth(parent);
418     myHeight = XtHeight(dialog);
419     myWidth = XtWidth(dialog);
420
421     if ((newY = pY - myHeight +5) < 0) 
422         newY = pY + pHeight;
423     newX = pX + pWidth/2 - myWidth/2;
424
425     n = 0;
426     XtSetArg(args[n], XmNx, newX); n++;
427     XtSetArg(args[n], XmNy, newY); n++;
428     XtSetValues(dialog,args,n);
429
430 #ifdef PutDDEBUG
431   printf("newX, newY, pY, pX;\n");
432   printf("%d    %d    %d  %d\n",newX, newY, pY, pX);
433   printf("pHeight, myHeight, pWidth, myWidth;\n");
434   printf("%d       %d        %d      %d\n", pHeight, myHeight, pWidth, myWidth);
435 #endif
436 }
437
438
439 /*++++++++++++++++++++++++++++++++++++++*/
440 /* main                                 */
441 /*++++++++++++++++++++++++++++++++++++++*/
442 int 
443 main(
444         int argc,
445         char **argv )
446 {
447     int             n;
448     Arg             args[MAX_ARGS];
449     XEvent          event;
450     XPropertyEvent *pEvent=(XPropertyEvent *)&event;
451     long            mwmFunc;
452     Boolean         useMaskRtn, useIconFileCacheRtn;    
453     char           *dirs = NULL;
454     char           *string;
455         Visual         *visual;
456
457 #ifdef USERHELP
458 malloc_check(1);
459 malloc_trace(0);
460 #endif
461
462     XtSetLanguageProc(NULL, NULL, NULL);
463     _DtEnvControl(DT_ENV_SET); 
464     
465
466     /* Initialize the toolkit and open the display */
467     style.shell = 
468         XtInitialize(argv[0], XMCLASS, option_list, 1, (int *)&argc, argv);
469
470 #ifdef __osf__
471     _XmColorObjCreate(style.shell, NULL, NULL);
472 #endif
473
474     /* Allow all WS manipulation functions except resize and maximize */
475     mwmFunc = MWM_FUNC_ALL ^ (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); 
476
477     n = 0;
478     XtSetArg(args[n], XmNmwmFunctions, mwmFunc); n++;
479     XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
480     XtSetValues(style.shell, args, n);
481
482     /* initialize global style data */
483
484     style.display    = XtDisplay(style.shell);
485     style.screen     = DefaultScreenOfDisplay(style.display);
486     style.screenNum  = DefaultScreen(style.display);
487     style.colormap   = DefaultColormap(style.display, style.screenNum);
488     style.root       = DefaultRootWindow(style.display);
489     style.execName   = argv[0];
490     style.errDialog  = NULL;
491     style.tmpXmStr   = NULL;
492     style.home = (char *) XtMalloc(strlen((char *) getenv("HOME")) + 1);
493     strcpy(style.home, (char *) getenv("HOME"));
494     style.colorDialog = NULL;
495     style.backdropDialog = NULL;
496     style.fontDialog = NULL;
497     style.kbdDialog = NULL;
498     style.mouseDialog = NULL;
499     style.audioDialog = NULL;
500     style.screenDialog = NULL;
501     style.startupDialog = NULL;
502     style.dtwmDialog = NULL;
503     style.i18nDialog = NULL;
504         visual = XDefaultVisual(style.display,style.screenNum);
505         style.visualClass = visual->class;
506     
507     if (progName = DtStrrchr(argv[0], '/')) progName++;
508     else progName = argv[0];
509
510     /* Get the lock established to ensure only one dtstyle process
511      * is running per screen .. first malloc enough space*/
512
513     if (_DtGetLock (style.display, STYLE_LOCK) == 0)
514     {
515         _DtSimpleError (progName, DtError, NULL, "%s",
516              ((char *)GETMESSAGE(2, 5, "Style Manager is already running, second attempt aborted.")));
517         exit(1);
518     }
519
520     InitDtstyleProtocol();
521     SetWindowProperties();
522
523     /* Register error handlers */
524     XSetErrorHandler(ErrorHandler);
525     XSetIOErrorHandler(IOErrorHandler);
526     XtAppSetErrorHandler(XtWidgetToApplicationContext(style.shell),
527                          ToolkitErrorHandler);
528     XtAddEventHandler(style.shell, StructureNotifyMask, 0,
529                          (XtEventHandler)MwmReparentNotify, NULL);
530
531     /* set up resolution dependent layout variables */
532     switch (_DtGetDisplayResolution(style.display, style.screenNum))
533     {
534         case LOW_RES_DISPLAY:
535             style.horizontalSpacing = 
536             style.verticalSpacing = 3;
537             break;
538             
539         case MED_RES_DISPLAY:
540             style.horizontalSpacing = 
541             style.verticalSpacing = 5;
542             break;
543             
544         case HIGH_RES_DISPLAY:
545             style.horizontalSpacing = 
546             style.verticalSpacing = 8;
547             break;
548     }
549     
550     GetApplicationResources();
551     
552     XmeGetIconControlInfo(style.screen, &useMaskRtn,
553                           &style.useMultiColorIcons, &useIconFileCacheRtn);
554     
555     
556     /* add the directory $HOME/.dt/backdrops */
557     
558     string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops:") + 1);
559     sprintf(string, "%s/.dt/backdrops:", style.home);
560
561     dirs = (char *)XtCalloc(1, strlen("/etc/dt/backdrops:/usr/dt/backdrops") + 
562                             (style.xrdb.backdropDir == NULL ? 2 :
563                             strlen(style.xrdb.backdropDir)) + 
564                             strlen(string) + 2);
565   
566
567     strcpy(dirs, string);
568     if (style.xrdb.backdropDir) 
569       {
570         strcat(dirs, style.xrdb.backdropDir);
571         strcat(dirs, ":"); 
572       }
573     strcat(dirs, "/etc/dt/backdrops:/usr/dt/backdrops");
574
575     _DtWsmSetBackdropSearchPath(style.screen, dirs, style.useMultiColorIcons);
576
577     if (string != NULL)
578       XtFree((char *)string);
579     
580     if (dirs != NULL)
581       XtFree((char *)dirs); 
582     
583     
584
585     style.count = 0;
586     /* if this is started from save session we need to set up the BMS
587        first, otherwise do it after making the window. (for user perception
588        for how long it takes for the dtstyle to come up) */
589     if(style.xrdb.session != NULL) {
590       DtInitialize (style.display, style.shell, progName, progName);
591       /*Restore a session or build and display the main Window.*/
592       if(!restoreSession(style.shell,style.xrdb.session))
593         init_mainWindow(style.shell);
594     }
595     else {
596       init_mainWindow(style.shell);
597       DtInitialize (style.display, style.shell, progName, progName);
598       InitializeAtoms();
599       CheckMonitor(style.shell);
600       GetDefaultPal(style.shell);
601     }
602     
603     signal(SIGINT,(void (*)())activateCB_exitBtn); 
604     signal(SIGTERM,(void (*)())activateCB_exitBtn); 
605
606     /* to avoid defunct screen saver processes */    
607     signal(SIGCHLD, (void (*)())WaitChildDeath);
608
609     /* backdrop dialog  needs to know when the workspace changes to recolor 
610        the bitmap displayed in the dialog */
611     ListenForWorkspaceChange();
612
613     /* if using COLOR builtin, style.workProcs is True */
614
615     if ((XmeUseColorObj() != FALSE) && style.workProcs)
616
617         XtAppAddWorkProc(XtWidgetToApplicationContext(style.shell), 
618                         NewCreateD, style.shell);
619
620     XtAppMainLoop(XtWidgetToApplicationContext(style.shell));
621
622     return 0;
623 }
624
625 /************************************************************************
626  *
627  *  ErrorHandler
628  *
629  ************************************************************************/
630 static int
631 ErrorHandler(
632         Display *disp,
633         XErrorEvent *event )
634
635 {
636   #define _DTSTYLE_BUFSIZE 1024
637   char errmsg[_DTSTYLE_BUFSIZE];
638
639   _DtPrintDefaultErrorSafe(disp, event, errmsg, _DTSTYLE_BUFSIZE);
640   _DtSimpleError(progName, DtWarning, NULL, errmsg, NULL);
641
642    /* We do not want to exit here lets try to continue... */
643   return 1;
644 }
645
646
647 /************************************************************************
648  *
649  *  IOErrorHandler
650  *
651  ************************************************************************/
652 static int
653 IOErrorHandler (display)
654  Display *display;
655
656 {
657 #ifdef DEBUG
658     Warning ("X IO error occurred during generic operation");
659 #endif /* DEBUG */
660
661     exit (1);
662     return 1;
663
664
665
666
667 /************************************************************************
668  *
669  *  ToolkitErrorHandler
670  * 
671  *  All Xt memory allocation errors should fall through to this routine.
672  *  There is no need to check for Xtmalloc errors where they are used.
673  *
674  ************************************************************************/
675 static void
676 ToolkitErrorHandler(
677         char *message )
678
679 {
680     _DtSimpleError (progName, DtError, NULL, 
681         GETMESSAGE(2, 6, "An X Toolkit error occurred... Exiting.\n"));
682     exit (1);
683 }
684
685
686 static Boolean 
687 NewCreateD(
688         XtPointer shell )
689 {
690 #ifdef TIME
691     struct timeval first, second, lapsed;
692     struct timezone tzp;
693
694     gettimeofday(&first, &tzp);
695 #endif
696
697     /*  Create the Dialog Box Dialog */
698     CreateDialogBoxD((Widget)shell);
699
700 #ifdef TIME
701     gettimeofday(&second, &tzp);
702     if(first.tv_usec > second.tv_usec){
703        second.tv_usec += 1000000;
704        second.tv_sec--;
705     }
706     printf("CreateDialogBoxD elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
707 #endif
708
709     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddTo, shell);
710
711     return(True);
712 }
713
714 static Boolean 
715 NewAddTo(
716         XtPointer shell )
717 {
718 #ifdef TIME
719     struct timeval first, second, lapsed;
720     struct timezone tzp;
721
722     gettimeofday(&first, &tzp);
723 #endif
724
725     /*  Create the Dialog Box Dialog */
726     AddToDialogBox();
727
728 #ifdef TIME
729     gettimeofday(&second, &tzp);
730     if(first.tv_usec > second.tv_usec){
731        second.tv_usec += 1000000;
732        second.tv_sec--;
733     }
734     printf("AddToDialogBox elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
735 #endif
736
737     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateTop1, shell);
738
739     return(True);
740 }
741
742 static Boolean 
743 NewCreateTop1(
744         XtPointer shell )
745 {
746 #ifdef TIME
747     struct timeval first, second, lapsed;
748     struct timezone tzp;
749
750     gettimeofday(&first, &tzp);
751 #endif
752
753     /* Create the top portion of the color dialog */
754     CreateTopColor1();
755
756 #ifdef TIME
757     gettimeofday(&second, &tzp);
758     if(first.tv_usec > second.tv_usec){
759        second.tv_usec += 1000000;
760        second.tv_sec--;
761     }
762     printf("CreateTopColor1 elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
763 #endif
764
765     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateTop2, shell);
766     return(True);
767 }
768
769 static Boolean 
770 NewCreateTop2(
771         XtPointer shell )
772 {
773 #ifdef TIME
774     struct timeval first, second, lapsed;
775     struct timezone tzp;
776
777     gettimeofday(&first, &tzp);
778 #endif
779
780     /* Create the top portion of the color dialog */
781     CreateTopColor2();
782
783 #ifdef TIME
784     gettimeofday(&second, &tzp);
785     if(first.tv_usec > second.tv_usec){
786        second.tv_usec += 1000000;
787        second.tv_sec--;
788     }
789     printf("CreateTopColor2 elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
790 #endif
791
792     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddSysPath, shell);
793
794     return(True);
795 }
796
797 static Boolean 
798 NewAddSysPath(
799         XtPointer shell )
800 {
801 #ifdef TIME
802     struct timeval first, second, lapsed;
803     struct timezone tzp;
804
805     gettimeofday(&first, &tzp);
806 #endif
807
808     /* initialize the system directory */
809     AddSystemPath();
810
811 #ifdef TIME
812     gettimeofday(&second, &tzp);
813     if(first.tv_usec > second.tv_usec){
814        second.tv_usec += 1000000;
815        second.tv_sec--;
816     }
817     printf("AddSystemPath elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
818 #endif
819
820     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddDirectories, shell);
821
822     return(True);
823 }
824
825 static Boolean 
826 NewAddDirectories(
827         XtPointer shell )
828 {
829 #ifdef TIME
830     struct timeval first, second, lapsed;
831     struct timezone tzp;
832
833     gettimeofday(&first, &tzp);
834 #endif
835
836     /* initialize the directorys list in the resource */
837     if(style.xrdb.paletteDir != NULL)
838       AddDirectories(style.xrdb.paletteDir);
839     else
840       style.count++;
841
842 #ifdef TIME
843     gettimeofday(&second, &tzp);
844     if(first.tv_usec > second.tv_usec){
845        second.tv_usec += 1000000;
846        second.tv_sec--;
847     }
848     printf("AddDirectories elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
849 #endif
850
851     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAddHomePath, shell);
852
853     return(True);
854 }
855
856 static Boolean 
857 NewAddHomePath(
858         XtPointer shell )
859 {
860 #ifdef TIME
861     struct timeval first, second, lapsed;
862     struct timezone tzp;
863
864     gettimeofday(&first, &tzp);
865 #endif
866
867     /* initialize the home directory */
868     AddHomePath();
869
870 #ifdef TIME
871     gettimeofday(&second, &tzp);
872     if(first.tv_usec > second.tv_usec){
873        second.tv_usec += 1000000;
874        second.tv_sec--;
875     }
876     printf("AddHomePath elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
877 #endif
878
879     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewReadPal, shell);
880
881     return(True);
882 }
883
884 static Boolean 
885 NewReadPal(
886         XtPointer shell )
887 {
888 #ifdef TIME
889     struct timeval first, second, lapsed;
890     struct timezone tzp;
891
892     gettimeofday(&first, &tzp);
893 #endif
894
895     /* Read in the palettes one at a time */
896     if (ReadPaletteLoop(True)) {
897
898 #ifdef TIME
899        gettimeofday(&second, &tzp);
900        if(first.tv_usec > second.tv_usec){
901           second.tv_usec += 1000000;
902           second.tv_sec--;
903        }
904        printf("ReadPaletteLoop DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
905 #endif
906
907     /* Stop work procs if no palettes found - fatal color error.
908      * When the color button is pressed, the regular processing
909      * will pick up on NumOfPalettes == 0 and post an error
910      * dialog */
911      
912        if (NumOfPalettes == 0)
913             return(True);
914        loadDatabase();
915        XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewInitPal, shell);
916        return(True);
917     }
918
919 #ifdef TIME
920     gettimeofday(&second, &tzp);
921     if(first.tv_usec > second.tv_usec){
922        second.tv_usec += 1000000;
923        second.tv_sec--;
924     }
925     printf("ReadPaletteLoop NOT DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
926 #endif
927       
928     return(False);
929
930 }
931
932 static Boolean 
933 NewInitPal(
934         XtPointer shell )
935 {
936 #ifdef TIME
937     struct timeval first, second, lapsed;
938     struct timezone tzp;
939
940     gettimeofday(&first, &tzp);
941 #endif
942
943     /* initialize the palette list */
944     if(InitializePaletteList((Widget)shell, paletteList, True)) {
945
946 #ifdef TIME
947        gettimeofday(&second, &tzp);
948        if(first.tv_usec > second.tv_usec){
949           second.tv_usec += 1000000;
950           second.tv_sec--;
951        }
952        printf("InitializePaletteList DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
953 #endif
954
955        XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewAllocColor, shell);
956        return(True);
957      }
958
959 #ifdef TIME
960     gettimeofday(&second, &tzp);
961     if(first.tv_usec > second.tv_usec){
962        second.tv_usec += 1000000;
963        second.tv_sec--;
964     }
965     printf("InitializePaletteList NOT DONE elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
966 #endif
967
968     return(False);
969 }
970
971 static Boolean 
972 NewAllocColor(
973         XtPointer shell )
974 {
975 #ifdef TIME
976     struct timeval first, second, lapsed;
977     struct timezone tzp;
978
979     gettimeofday(&first, &tzp);
980 #endif
981
982     /* initialize pixels to the right color */
983     AllocatePaletteCells((Widget)shell);
984
985 #ifdef TIME
986     gettimeofday(&second, &tzp);
987     if(first.tv_usec > second.tv_usec){
988        second.tv_usec += 1000000;
989        second.tv_sec--;
990     }
991     printf("AllocatePaletteCells elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
992 #endif
993
994     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewBottomColor, shell);
995
996     return(True);
997 }
998
999 static Boolean 
1000 NewBottomColor(
1001         XtPointer shell )
1002 {
1003 #ifdef TIME
1004     struct timeval first, second, lapsed;
1005     struct timezone tzp;
1006
1007     gettimeofday(&first, &tzp);
1008 #endif
1009
1010     /* Create the bottom portion of the color dialog */
1011     CreateBottomColor();
1012
1013 #ifdef TIME
1014     gettimeofday(&second, &tzp);
1015     if(first.tv_usec > second.tv_usec){
1016        second.tv_usec += 1000000;
1017        second.tv_sec--;
1018     }
1019     printf("CreateBottomColor elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
1020 #endif
1021
1022     XtAppAddWorkProc(XtWidgetToApplicationContext((Widget) shell), NewCreateButtons, shell);
1023
1024     return(True);
1025 }
1026
1027 static Boolean 
1028 NewCreateButtons(
1029         XtPointer shell )
1030 {
1031 #ifdef TIME
1032     struct timeval first, second, lapsed;
1033     struct timezone tzp;
1034
1035     gettimeofday(&first, &tzp);
1036 #endif
1037
1038     /* initialize pixels to the right color */
1039     CreatePaletteButtons(style.buttonsForm);
1040
1041 #ifdef TIME
1042     gettimeofday(&second, &tzp);
1043     if(first.tv_usec > second.tv_usec){
1044        second.tv_usec += 1000000;
1045        second.tv_sec--;
1046     }
1047     printf("CreatePaletteButtons elapsed time is %ld seconds, %ld microseconds\n", second.tv_sec - first.tv_sec, second.tv_usec - first.tv_usec);
1048 #endif
1049
1050     return(True);
1051 }
1052
1053 /*************************************<->*************************************
1054  *
1055  *  WaitChildDeath()
1056  *
1057  *
1058  *  Description:
1059  *  -----------
1060  *  When a SIGCHLD signal comes in, wait for all child processes to die.
1061  *
1062  *
1063  *  Inputs:
1064  *  ------
1065  * 
1066  *  Outputs:
1067  *  -------
1068  *
1069  *
1070  *  Comments:
1071  *  --------
1072  * 
1073  *************************************<->***********************************/
1074 void
1075 WaitChildDeath( void )
1076 {
1077   int   stat_loc;
1078   pid_t pid;
1079   
1080   pid = wait(&stat_loc);
1081   signal(SIGCHLD,(void (*)())WaitChildDeath);
1082
1083 }