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