Link with C++ linker
[oweals/cde.git] / cde / programs / dtstyle / MainWin.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 /*  $XConsortium: MainWin.c /main/8 1996/03/25 00:52:54 pascale $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        MainWin.c
28  **
29  **   Project:     DT 3.0
30  **
31  **   Description: Controls the main Dtstyle dialog
32  **
33  **
34  ****************************************************************************
35  ************************************<+>*************************************/
36 /*
37  * (c) Copyright 1996 Digital Equipment Corporation.
38  * (c) Copyright 1990, 1996 Hewlett-Packard Company.
39  * (c) Copyright 1996 International Business Machines Corp.
40  * (c) Copyright 1996 Sun Microsystems, Inc.
41  * (c) Copyright 1996 Novell, Inc. 
42  * (c) Copyright 1996 FUJITSU LIMITED.
43  * (c) Copyright 1996 Hitachi.
44  */
45
46 /*+++++++++++++++++++++++++++++++++++++++*/
47 /* include files                         */
48 /*+++++++++++++++++++++++++++++++++++++++*/
49
50 #include <X11/Xlib.h>
51 #include <Xm/MwmUtil.h>
52 #include <signal.h>
53
54 #include <Xm/Xm.h>
55 #include <Xm/XmP.h>
56 #include <Xm/CascadeB.h>
57 #include <Xm/ColorObjP.h>
58 #include <Xm/MainW.h>
59 #include <Xm/Frame.h>
60 #include <Xm/PushB.h>
61 #include <Xm/RowColumn.h>
62 #include <Xm/SeparatoG.h>
63
64 /*
65 #include <Dt/Box.h>
66 */
67 #include <Dt/Control.h>
68 #include <Dt/DialogBox.h>
69 #include <Dt/Icon.h>
70 #include <Dt/IconFile.h>
71
72 #include <Dt/HourGlass.h>
73 #include <Dt/UserMsg.h>
74     
75 #include "Main.h"
76 #include "Help.h"
77 #include "SaveRestore.h"
78
79 /*+++++++++++++++++++++++++++++++++++++++*/
80 /* include extern functions              */
81 /*+++++++++++++++++++++++++++++++++++++++*/
82 #include "MainWin.h"
83
84 /*+++++++++++++++++++++++++++++++++++++++*/
85 /* Local #defines                        */
86 /*+++++++++++++++++++++++++++++++++++++++*/
87
88 /*+++++++++++++++++++++++++++++++++++++++*/
89 /* Internal Functions                    */
90 /*+++++++++++++++++++++++++++++++++++++++*/
91
92 static void _DtMapCB( 
93                         Widget w,
94                         XtPointer client_data,
95                         XtPointer call_data) ;
96 static void build_mainWindow( Widget shell) ;
97 static void activateCB( 
98                         Widget w,
99                         XtPointer client_data,
100                         XtPointer call_data) ;
101 static void ProcessComponentList(
102                         Widget parent,
103                         Widget mainRC) ;
104
105
106 /*+++++++++++++++++++++++++++++++++++++++*/
107 /*  Internal variables                   */
108 /*+++++++++++++++++++++++++++++++++++++++*/
109
110 static int         colorUse = XmCO_BLACK_WHITE;   
111 static saveRestore save = {FALSE, 0, };
112
113
114 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
115 /* init_mainWindow                                          */
116 /*                                                          */
117 /* build if needed, otherwise just manage the mainWindow.   */
118 /* Assumes shell has been created                           */
119 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
120 void 
121 init_mainWindow( Widget shell )
122 {
123     if (style.mainWindow == NULL) {
124         build_mainWindow(shell);
125         if (save.restoreFlag)
126             XtAddCallback (shell, XtNpopupCallback, _DtMapCB, NULL);
127         XtManageChild(style.mainWindow);
128         XtPopup(shell, XtGrabNone);
129     }
130     else   /* fix Shouldn't ever happen */
131         XtManageChild(style.mainWindow);
132 }
133
134 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
135 /* _DtMapCB                                                      */
136 /*        first time only, set correct sizing in case font    */
137 /*        size has changed (if so, saved size is wrong)       */
138 /*            remove callback after first time                */
139 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
140 static void 
141 _DtMapCB(
142         Widget w,
143         XtPointer client_data,
144         XtPointer call_data )
145 {
146     XSizeHints hints;
147
148     if (save.restoreFlag)
149     {
150         hints.min_width  = XtWidth(w);
151         hints.min_height = XtHeight(w);
152         hints.max_width  = XtWidth(w);
153         hints.max_height = XtHeight(w);
154         hints.flags      = PMinSize | PMaxSize;
155         XSetWMNormalHints (style.display, XtWindow(w), &hints);
156     }
157
158     XtRemoveCallback(style.shell, XtNpopupCallback, _DtMapCB, NULL);
159 }
160
161 /*+++++++++++++++++++++++++++++++++++++++++++++*/
162 /* build_mainWindow                            */
163 /*                                             */
164 /* build the main window, but don't manage it. */
165 /*+++++++++++++++++++++++++++++++++++++++++++++*/
166 static void 
167 build_mainWindow(
168         Widget shell )
169 {
170   int        count, n, n2;
171   Arg        args[MAX_ARGS];
172   Widget     WidgList[10];
173   Widget     frame;
174   Widget     mainMenu;
175   Widget     mainRC;
176   Widget     filePulldown;
177   Widget     helpPulldown;
178   Widget     exitBtn;
179   char       *mnemonic;
180   char       *tmpStr;
181   Pixmap     pixmap;
182   XmString   labelString;
183   Pixmap     ditherPix;
184   XmPixelSet pixelSet[XmCO_NUM_COLORS];
185   Pixel      bg;
186   short      a,i,p,s;
187
188
189   /* saveRestore
190    * Note that save.poscnt has been initialized elsewhere.  
191    * save.posArgs may contain information from restoreAudio().*/
192
193     XtSetArg(save.posArgs[save.poscnt], XmNnoResize, True); save.poscnt++;
194     XtSetArg(save.posArgs[save.poscnt], XmNresizePolicy, XmRESIZE_NONE); save.poscnt++;
195     style.mainWindow= XmCreateMainWindow(shell,"mainWindow",  save.posArgs, save.poscnt);
196     XtAddCallback(style.mainWindow, XmNhelpCallback,
197         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MAIN_WINDOW);
198
199     n = 0;
200     tmpStr = (char *)XtMalloc(strlen(GETMESSAGE(4, 1, "Style Manager"))+1);
201     sprintf(tmpStr, GETMESSAGE(4, 1, "Style Manager"));
202     XtSetArg(args[n], XmNtitle, tmpStr); n++;
203     XtSetArg(args[n], XmNiconName, 
204         (char *)GETMESSAGE(4, 37, "Style")); n++;
205     XtSetValues(XtParent(style.mainWindow), args, n);
206     XtFree(tmpStr);
207
208     n = 0;
209     mainMenu= XmCreateMenuBar(style.mainWindow,"mainMenu", args, n);
210     XtAddCallback(mainMenu, XmNhelpCallback,
211         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MENUBAR);
212     XtManageChild(mainMenu);
213
214     /* create the pulldown widgets */
215     n = 0;
216     filePulldown= XmCreatePulldownMenu(mainMenu,"fileMenu", args, n );
217     XtAddCallback(filePulldown, XmNhelpCallback,
218         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FILE_MENU);
219
220     n = 0;
221     helpPulldown= XmCreatePulldownMenu(mainMenu, "helpMenu" , args, n );
222     XtAddCallback(helpPulldown, XmNhelpCallback,
223         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_HELP_MENU);
224
225     /* create the cascade butons */
226     count = 0;
227
228     n = 0;
229     mnemonic = ((char *)GETMESSAGE(4, 2, "F"));
230     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
231     labelString =  CMPSTR((char *)GETMESSAGE(4, 3, "File"));
232     XtSetArg(args[n], XmNlabelString, labelString);  n++;
233     XtSetArg(args[n], XmNsubMenuId, filePulldown); n++;
234     XtSetArg (args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
235     WidgList[count++]= 
236         XmCreateCascadeButton(mainMenu, "fileCascadeButton", args, n );
237     XtAddCallback(WidgList[count-1], XmNhelpCallback,
238         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FILE_MENU);
239     XmStringFree(labelString);
240
241     n = 0;
242     mnemonic = ((char *)GETMESSAGE(4, 4, "H"));
243     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
244     labelString =  CMPSTR((char *)GETMESSAGE(4, 5, "Help"));
245     XtSetArg(args[n], XmNlabelString, labelString); n++;
246     XtSetArg(args[n], XmNsubMenuId, helpPulldown); n++;
247     XtSetArg (args[n], XmNmarginWidth, 6); n++;
248     WidgList[count++]= 
249         XmCreateCascadeButton(mainMenu, "helpCascadeButton", args, n );
250     XtAddCallback(WidgList[count-1], XmNhelpCallback,
251         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_HELP_MENU);
252     XmStringFree(labelString);
253
254     n = 0;
255     XtSetArg(args[n], XmNmenuHelpWidget, WidgList[count-1]);    n++;
256     XtSetValues (mainMenu, args, n);
257
258     XtManageChildren (WidgList, count);
259
260     /* create the File menu pane's buttons */
261     n = 0;
262     mnemonic = ((char *)GETMESSAGE(4, 53, "x"));
263     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
264     labelString =  CMPSTR((char *)GETMESSAGE(4, 7, "Exit"));
265     XtSetArg(args[n], XmNlabelString, labelString); n++;
266     exitBtn= XmCreatePushButton(filePulldown, "exit", args, n );
267     XtAddCallback(exitBtn, XmNactivateCallback, activateCB_exitBtn, NULL);
268     XtAddCallback(exitBtn, XmNhelpCallback,
269         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_EXIT);
270     XtManageChild(exitBtn);
271     XmStringFree(labelString);
272
273     /* create the Help menu pane's buttons */
274     count =0;
275
276     n = 0;
277     mnemonic = ((char *)GETMESSAGE(4, 54, "v"));
278     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
279     labelString = CMPSTR((char *)GETMESSAGE(4, 55, "Overview"));
280     XtSetArg(args[n], XmNlabelString, labelString); n++;
281     WidgList[count++]= 
282         XmCreatePushButton(helpPulldown, "overview", args, n );
283     XtAddCallback(WidgList[count-1], XmNactivateCallback,
284         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_INTRODUCTION);
285     XmStringFree(labelString);
286
287     n = 0;
288     WidgList[count++]= 
289         XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
290             
291     n = 0;
292     mnemonic = ((char *)GETMESSAGE(4, 43, "T"));
293     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
294     labelString = CMPSTR((char *)GETMESSAGE(4, 56, "Tasks"));
295     XtSetArg(args[n], XmNlabelString, labelString);  n++;
296     WidgList[count++]= XmCreatePushButton(helpPulldown, "tasks", args, n );
297     XtAddCallback(WidgList[count-1], XmNactivateCallback,
298         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_TASKS);
299     XmStringFree(labelString);
300
301     n = 0;
302     mnemonic = ((char *)GETMESSAGE(4, 45, "R"));
303     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
304     labelString = CMPSTR((char *)GETMESSAGE(4, 57, "Reference"));
305     XtSetArg(args[n], XmNlabelString, labelString);  n++;
306     WidgList[count++]= XmCreatePushButton(helpPulldown, "reference", args, n );
307     XtAddCallback(WidgList[count-1], XmNactivateCallback,
308         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_REFERENCE);
309     XmStringFree(labelString);
310
311     n = 0;
312     mnemonic = ((char *)GETMESSAGE(4, 47, "O"));
313     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
314     labelString = CMPSTR((char *)GETMESSAGE(4, 48, "On Item"));
315     XtSetArg(args[n], XmNlabelString, labelString);  n++;
316     WidgList[count++]= XmCreatePushButton(helpPulldown, "onItem", args, n );
317     XtAddCallback(WidgList[count-1], XmNactivateCallback,
318         (XtCallbackProc)HelpModeCB, (XtPointer)NULL);
319     XmStringFree(labelString);
320
321     n = 0;
322     WidgList[count++] = 
323         XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
324
325     n = 0;
326     mnemonic = ((char *)GETMESSAGE(4, 49, "U"));
327     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
328     labelString = CMPSTR((char *)GETMESSAGE(4, 58, "Using Help"));
329     XtSetArg(args[n], XmNlabelString, labelString); n++;
330     WidgList[count++]= 
331         XmCreatePushButton(helpPulldown, "usingHelp", args, n );
332     XtAddCallback(WidgList[count-1], XmNactivateCallback,
333         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_USING);
334     XmStringFree(labelString);
335
336     n = 0;
337     WidgList[count++] = 
338         XmCreateSeparatorGadget(helpPulldown,"separator",args,n);
339
340     n = 0;
341     mnemonic = ((char *)GETMESSAGE(4, 59, "A"));
342     XtSetArg(args[n], XmNmnemonic, mnemonic[0]); n++;
343     labelString = CMPSTR((char *)GETMESSAGE(4, 60, "About Style Manager"));
344     XtSetArg(args[n], XmNlabelString, labelString); n++;
345     WidgList[count++]= XmCreatePushButton(helpPulldown, "stylemanager", args, n );
346     XtAddCallback(WidgList[count-1], XmNactivateCallback,
347         (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_VERSION);
348     XmStringFree(labelString);
349
350     XtManageChildren(WidgList, count);
351
352     /*  create frame and row column for icon gadgets */
353     n = 0;
354     XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
355     XtSetArg(args[n], XmNshadowType, XmSHADOW_OUT); n++;
356     XtSetArg(args[n], XmNshadowThickness, 1); n++;
357     frame = XmCreateFrame(style.mainWindow, "frame", args, n);
358     XtManageChild(frame);
359                            
360     /* Save pixels for later use                                           */
361     /* primary top/bottom shadow -> fg/bg for pixmaps in primary areas     */
362     /* secondary top/bottom shadow -> fg/bg for pixmaps in secondary areas */
363     /* secondary select color -> backgrounds of editable text areas        */
364     /* secondary foreground ->  fill color on toggle indicators            */
365
366     /*  Get the primary colors to be used later */
367     n = 0;
368     XtSetArg(args[n], XmNbackground, &bg); n++;
369     XtGetValues(style.mainWindow, args, n);
370
371     XmGetColors (style.screen, style.colormap, bg,
372                  NULL,
373                  &style.primTSCol,
374                  &style.primBSCol,
375                  NULL);
376
377     /*  Get the secondary colors to be used later */
378     n = 0;
379     XtSetArg(args[n], XmNbackground, &style.secBgCol); n++;
380     XtGetValues(exitBtn, args, n);
381
382     XmGetColors (style.screen, style.colormap, style.secBgCol,
383                  &style.tgSelectColor,
384                  &style.secTSCol,
385                  &style.secBSCol,
386                  &style.secSelectColor);
387
388     if ((style.secTSCol == style.secBSCol) || /* B_W or shadowPixmaps==True */
389         (!style.useMultiColorIcons))          /* multiColorIcons turned off */
390     {
391         /* force TS = White, BS = Black */
392         style.secTSCol = style.primTSCol = WhitePixelOfScreen(style.screen);
393         style.secBSCol = style.primBSCol = BlackPixelOfScreen(style.screen);
394     }
395     
396     XmeGetPixelData(style.screenNum, &colorUse, pixelSet, &a, &i, &p, &s);
397
398     n = 0;
399     if (colorUse == XmCO_BLACK_WHITE)
400     {
401     ditherPix = XmGetPixmap (style.screen, "50_foreground",
402                              style.primBSCol,style.primTSCol);
403     XtSetArg(args[n], XmNbackgroundPixmap, ditherPix); n++;
404     }
405     XtSetArg(args[n], XmNallowOverlap, False); n++;
406     XtSetArg(args[n], XmNadjustLast, False); n++;
407     XtSetArg(args[n], XmNpacking, XmPACK_TIGHT); n++;
408     XtSetArg(args[n], XmNspacing, style.horizontalSpacing); n++;
409     mainRC = XmCreateRowColumn(frame, "mainRC", args, n);
410     XtManageChild(mainRC);
411
412     n = 0;
413     XtSetArg(args[n], XmNmenuBar, mainMenu);    n++;
414     XtSetArg(args[n], XmNcommandWindow, NULL);    n++;
415     XtSetArg(args[n], XmNworkWindow, frame);    n++;
416     XtSetValues (style.mainWindow, args, n);
417
418     ProcessComponentList (shell, mainRC);
419
420 }
421
422 /*+++++++++++++++++++++++++++++++++++++++
423  * ProcessComponentList();
424  * 
425  *+++++++++++++++++++++++++++++++++++++++*/
426
427 static void 
428 ProcessComponentList(
429         Widget parent,
430         Widget mainRC )
431 {
432    int       count=0;
433    int       j=0;
434    int       n, n2;
435    Arg       args[MAX_ARGS];
436    Widget    componentWidget;
437    int       s;
438    char      *string;
439    char      *resString, *resString2;
440    XmString  cmp_string;
441    int       helpTag;
442    char      *dtIcon;
443    int       len;
444
445    style.workProcs = False;
446    if (style.xrdb.componentList == NULL) return;
447
448    n = 0;
449    XtSetArg(args[n], XmNalignment, XmALIGNMENT_CENTER); n++;
450    XtSetArg(args[n], XmNpixmapPosition, XmPIXMAP_TOP); n++;
451    XtSetArg(args[n], XmNshadowType, XmSHADOW_OUT); n++;
452    n2 = 3;    /* number of preset args for creating Icons */
453
454    resString = strdup (style.xrdb.componentList);
455    resString2 = resString;
456    len = strlen(resString);
457    string = strtok(resString, " ");
458    s = 0;
459    while (string != NULL)
460    {
461       /* check for valid name, duplicate name *** */
462
463       /* create Icon in Dtstyle main window */
464
465       n = n2;
466       XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
467       if (colorUse == XmCO_BLACK_WHITE)
468       {
469           XtSetArg(args[n], XmNuseEmbossedText, False); n++;
470       }
471       XtSetArg(args[n], XmNpixmapForeground, style.primBSCol); n++;
472       XtSetArg(args[n], XmNpixmapBackground, style.primTSCol); n++;
473       if (strcmp(string, COLOR) == 0)
474       {
475           cmp_string = CMPSTR(GETMESSAGE(4, 27, "Color"));
476           helpTag = HELP_COLOR_BUTTON;
477           dtIcon = _DtGetIconFileName(style.screen, COLOR_ICON, NULL, NULL, NULL);
478           style.workProcs = True;          
479       }
480       else if (strcmp(string, FONT) == 0)
481       {
482           cmp_string = CMPSTR(GETMESSAGE(4, 28, "Font"));
483           dtIcon = _DtGetIconFileName(style.screen, FONT_ICON, NULL, NULL, NULL);
484           helpTag = HELP_FONT_BUTTON;
485       }
486
487       else if (strcmp(string, BACKDROP) == 0)
488       {
489           cmp_string = CMPSTR(GETMESSAGE(4, 29, "Backdrop"));
490           dtIcon = _DtGetIconFileName(style.screen, BACKDROP_ICON, NULL, NULL, NULL);
491           helpTag = HELP_BACKDROP_BUTTON;
492       }
493
494       else if (strcmp(string, KEYBOARD) == 0)
495       {
496           cmp_string = CMPSTR(GETMESSAGE(4, 30, "Keyboard"));
497           dtIcon = _DtGetIconFileName(style.screen, KEYBOARD_ICON, NULL, NULL, NULL);     
498           helpTag = HELP_KEYBOARD_BUTTON;        
499       }
500
501       else if (strcmp(string, MOUSE) == 0)
502       {
503           cmp_string = CMPSTR(GETMESSAGE(4, 31, "Mouse"));
504           dtIcon = _DtGetIconFileName(style.screen, MOUSE_ICON, NULL, NULL, NULL);        
505           helpTag = HELP_MOUSE_BUTTON;
506       }
507
508       else if (strcmp(string, BEEP) == 0)
509       {
510           cmp_string = CMPSTR(GETMESSAGE(4, 32, "Beep"));
511           dtIcon = _DtGetIconFileName(style.screen, BEEP_ICON, NULL, NULL, NULL);         
512           helpTag = HELP_AUDIO_BUTTON;
513       }
514
515       else if (strcmp(string, SCREEN) == 0)
516       {
517           cmp_string = CMPSTR(GETMESSAGE(4, 33, "Screen"));
518           dtIcon = _DtGetIconFileName(style.screen, SCREEN_ICON, NULL, NULL, NULL);       
519           helpTag = HELP_SCREEN_BUTTON;
520       }
521
522       else if (strcmp(string, DTWM) == 0)
523       {
524           cmp_string = CMPSTR(GETMESSAGE(4, 38, "Window"));
525           dtIcon = _DtGetIconFileName(style.screen, DTWM_ICON, NULL, NULL, NULL);         
526           helpTag = HELP_DTWM_BUTTON;
527       }
528
529       else if (strcmp(string, STARTUP) == 0)
530       {
531           cmp_string = CMPSTR(GETMESSAGE(4, 35, "Startup"));
532           dtIcon = _DtGetIconFileName(style.screen, STARTUP_ICON, NULL, NULL, NULL);      
533           helpTag = HELP_STARTUP_BUTTON;
534       }
535       else if (strcmp(string, I18N) == 0)
536       {
537           cmp_string = CMPSTR(GETMESSAGE(4, 34, "Intl'"));
538           dtIcon = _DtGetIconFileName(style.screen, I18N_ICON, NULL, NULL, NULL);         
539           helpTag = HELP_I18N_BUTTON;        
540       }
541       else
542       {
543           s += strlen(string) +1;
544           if (resString+s >= resString2 + len)
545               string = NULL;
546           else
547               string = strtok(resString+s, " ");
548           continue;
549       }
550       XtSetArg(args[n], XmNimageName, dtIcon); n++;  
551       XtSetArg(args[n], XmNstring, cmp_string); n++;
552       componentWidget = _DtCreateControl(mainRC, string, args, n); 
553       XtManageChild (componentWidget);
554       XtAddCallback(componentWidget, XmNcallback, activateCB, string);
555       XtAddCallback(componentWidget, XmNhelpCallback,
556              (XtCallbackProc)HelpRequestCB, (XtPointer)helpTag);
557       XmStringFree(cmp_string);
558       XtFree(dtIcon);
559       
560       s += strlen(string) +1;
561       if (resString+s >= resString2 + len)
562           string = NULL;
563       else
564           string = strtok(resString+s, " ");
565
566    } /* while */
567
568 }
569
570 /*+++++++++++++++++++++++++++++++++++++++*/
571 /* cancel all the dialogs (for exit)     */
572 /*+++++++++++++++++++++++++++++++++++++++*/
573 void 
574 callCancels( void )
575 {
576  DtDialogBoxCallbackStruct CancelBut;
577  char dialogStates[60];
578  static Boolean calledAlready = False;
579
580   if (!calledAlready) {
581      dialogStates[0] = '\0';
582
583    if(style.colorDialog != NULL && XtIsManaged(style.colorDialog)) {
584        CancelBut.button_position = CANCEL_BUTTON;
585        XtCallCallbacks(style.colorDialog, XmNcallback, &CancelBut);
586    }
587
588      if(style.fontDialog != NULL && XtIsManaged(style.fontDialog)) {
589          CancelBut.button_position = CANCEL_BUTTON;
590          XtCallCallbacks(style.fontDialog, XmNcallback, &CancelBut);
591      }
592
593      if(style.audioDialog != NULL && XtIsManaged(style.audioDialog)) {
594          CancelBut.button_position = CANCEL_BUTTON;
595          XtCallCallbacks(style.audioDialog, XmNcallback, &CancelBut);
596      }
597
598      if(style.kbdDialog != NULL && XtIsManaged(style.kbdDialog)) {
599          CancelBut.button_position = CANCEL_BUTTON;
600          XtCallCallbacks(style.kbdDialog, XmNcallback, &CancelBut);
601      }
602
603      if(style.mouseDialog != NULL && XtIsManaged(style.mouseDialog)) {
604          CancelBut.button_position = CANCEL_BUTTON;
605          XtCallCallbacks(style.mouseDialog, XmNcallback, &CancelBut);
606      }
607
608      if(style.screenDialog != NULL &&  XtIsManaged(style.screenDialog)) {
609          CancelBut.button_position = CANCEL_BUTTON;
610          XtCallCallbacks(style.screenDialog, XmNcallback, &CancelBut);
611      }
612
613      if(style.startupDialog != NULL && XtIsManaged(style.startupDialog)) {
614          CancelBut.button_position = CANCEL_BUTTON;
615          XtCallCallbacks(style.startupDialog, XmNcallback, &CancelBut);
616      }
617
618      if (dialogStates) 
619        _DtAddToResource(style.display, dialogStates);
620
621      calledAlready = True;
622   }
623 }
624
625 /*+++++++++++++++++++++++++++++++++++++++*/
626 /* Menu CallBacks                        */
627 /*+++++++++++++++++++++++++++++++++++++++*/
628
629 void 
630 activateCB_exitBtn(
631         Widget w,
632         XtPointer client_data,
633         XtPointer call_data )
634 {
635 /*callCancels() remembers whether its been called so it won't get called*/
636 /*twice on logout.*/
637    callCancels();
638
639    XSync(style.display, 0);
640    exit(0);
641 }
642
643 /*+++++++++++++++++++++++++++++++++++++++*/
644 /* PushButton CallBacks                  */
645 /*+++++++++++++++++++++++++++++++++++++++*/
646
647 /*+++++++++++++++++++++++++++++++++++++++*/
648 /* activateCB                            */
649 /*+++++++++++++++++++++++++++++++++++++++*/
650
651 static void 
652 activateCB(
653         Widget w,
654         XtPointer client_data,
655         XtPointer call_data )
656 {
657   
658   DtControlCallbackStruct *cbs = 
659         (DtControlCallbackStruct *) call_data;
660   char *cd;
661   cd = (char *) client_data;
662    
663   /* if any other event besides an activate
664      event invokes this callback, don't invoke 
665      any dialogs.  Just ignore the event.
666   */
667   if (cbs->reason != XmCR_ACTIVATE) return;
668
669   if (strcmp(cd, COLOR) == 0)
670     Customize(style.shell);
671   
672   else if (strcmp(cd, FONT) == 0)
673     popup_fontBB(style.shell);
674   
675   else if (strcmp(cd, BACKDROP) == 0)
676     BackdropDialog (style.shell);
677   
678   else if (strcmp(cd, KEYBOARD) == 0)
679     popup_keyboardBB(style.shell);
680   
681   else if (strcmp(cd, MOUSE) == 0)
682     popup_mouseBB(style.shell);
683   
684   else if (strcmp(cd, BEEP) == 0)
685     popup_audioBB(style.shell);
686             
687   else if (strcmp(cd, SCREEN) == 0)
688     popup_screenBB(style.shell);
689   
690   else if (strcmp(cd, DTWM) == 0)
691     popup_dtwmBB(style.shell);
692   
693   else if (strcmp(cd, STARTUP) == 0)
694     popup_startupBB(style.shell);
695
696   else if (strcmp(cd, I18N) == 0)
697     popup_i18nBB(style.shell);
698
699 }
700
701
702 /************************************************************************
703  * restoreMain()
704  *
705  * restore any state information saved with saveMain.
706  * This is called from restoreSession with the application
707  * shell and the special xrm database retrieved for restore.
708  ************************************************************************/
709 void 
710 restoreMain(
711         Widget shell,
712         XrmDatabase db )
713 {
714     XrmName xrm_name[5];
715     XrmRepresentation rep_type;
716     XrmValue value;
717
718     xrm_name [0] = XrmStringToQuark ("mainWindow");
719     xrm_name [1] = XrmStringToQuark ("ismapped");
720     xrm_name [2] = NULL;
721
722     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
723       /* Are we supposed to be mapped? */
724       if (strcmp(value.addr, "True") == 0) {
725         save.poscnt = 0;
726
727         /* get x position */
728         xrm_name [1] = XrmStringToQuark ("x");
729         if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
730           XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
731           save.poscnt++;
732         }
733
734         /* get y position */
735         xrm_name [1] = XrmStringToQuark ("y");
736         if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
737           XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
738           save.poscnt++;
739         }
740
741         save.restoreFlag = True;
742         init_mainWindow(shell);
743       }
744     }
745     else
746       _DtSimpleError (progName, DtWarning, NULL, ((char *)GETMESSAGE(4,36,
747         "No Dtstyle restore information available for current session")), NULL);
748 }
749
750 /************************************************************************
751  * saveMain()
752  *
753  * This routine will write out to the passed file descriptor any state
754  * information this dialog needs.  It is called from saveSessionCB with the
755  * file already opened.
756  * All information is saved in xrm format.  There is no restriction
757  * on what can be saved.  It doesn't have to be defined or be part of any
758  * widget or Xt definition.  Just name and save it here and recover it in
759  * restoreMain.  The suggested minimum is whether you are mapped, and your
760  * location.
761  ************************************************************************/
762 void 
763 saveMain(
764         int fd )
765 {
766     Position x,y;
767     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
768
769     if (style.mainWindow != NULL) {
770         if (XtIsRealized(style.mainWindow))
771             sprintf(bufr, "*mainWindow.ismapped: True\n");
772   
773         /* Get and write out the geometry info for our Window */
774         x = XtX(XtParent(style.mainWindow));
775         y = XtY(XtParent(style.mainWindow));
776         sprintf(bufr, "%s*mainWindow.x: %d\n", bufr, x);
777         sprintf(bufr, "%s*mainWindow.y: %d\n", bufr, y);
778
779         write (fd, bufr, strlen(bufr));
780     }
781 }
782