Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtstyle / Font.c
1 /************************************<+>*************************************
2  ****************************************************************************
3  **
4  **   File:        Font.c
5  **
6  **   Project:     DT 3.0
7  **
8  **   Description: Controls the Dtstyle Font dialog
9  **
10  **
11  **  (c) Copyright Hewlett-Packard Company, 1990.  
12  **
13  **
14  **
15  ****************************************************************************
16  ************************************<+>*************************************/
17 /* $XConsortium: Font.c /main/7 1996/10/30 11:14:15 drk $ */
18
19 /*+++++++++++++++++++++++++++++++++++++++*/
20 /* include files                         */
21 /*+++++++++++++++++++++++++++++++++++++++*/
22
23 #include <X11/Xlib.h>
24 #include <Xm/MwmUtil.h>
25
26 #include <Xm/Xm.h>
27 #include <Xm/XmP.h>
28 #include <Xm/MessageB.h>
29 #include <Xm/Form.h>
30 #include <Xm/Frame.h>
31 #include <Xm/LabelG.h>
32 #include <Xm/List.h>
33 #include <Xm/Scale.h>
34 #include <Xm/Text.h>
35 #include <Xm/TextF.h>
36 #include <Xm/VendorSEP.h>
37
38 #include <Dt/DialogBox.h>
39 #include <Dt/Icon.h>
40 #include <Dt/TitleBox.h>
41
42 #include <Dt/Message.h>
43 #include <Dt/SessionM.h>
44 #include <Dt/HourGlass.h>
45
46 #include <string.h>
47 #include "Help.h"
48 #include "Main.h"
49 #include "SaveRestore.h"
50
51 /*+++++++++++++++++++++++++++++++++++++++*/
52 /* Local #defines                        */
53 /*+++++++++++++++++++++++++++++++++++++++*/
54
55 #define FONT_MSG   ((char *)GETMESSAGE(5, 23, "Style Manager - Font"))
56 #define PREVIEW    ((char *)GETMESSAGE(5, 17, "Preview"))
57 #define IMMEDIATE  ((char *)GETMESSAGE(5, 18, "The changes to fonts will show up in some\napplications the next time they are started.\nOther applications, such as file manager and\napplication manager, will not show the font\nchanges until you Exit the desktop and then log\nback in.")) 
58 #define LATER      ((char *)GETMESSAGE(5, 19, "The selected font will be used when\n you restart this session."))
59 #define INFO_MSG   ((char *)GETMESSAGE(5, 24, "The font that is currently used for your desktop is not\navailable in the Size list. If a new font is selected and\napplied, you will not be able to return to the current font\nusing the Style Manager - Font dialog."))
60 #define SYSTEM_MSG ((char *)GETMESSAGE(5, 20, "AaBbCcDdEeFfGg0123456789"))
61 #define USER_MSG   ((char *)GETMESSAGE(5, 21, "AaBbCcDdEeFfGg0123456789"))
62 #define BLANK_MSG  "                          "
63 #define SIZE       ((char *)GETMESSAGE(5, 22, "Size"))
64
65
66 /*+++++++++++++++++++++++++++++++++++++++*/
67 /* Internal Variables                    */
68 /*+++++++++++++++++++++++++++++++++++++++*/
69
70 typedef struct {
71     Widget fontWkarea;
72     Widget fontpictLabel;
73     Widget previewTB;
74     Widget previewForm;
75     Widget systemLabel;
76     Widget userText;
77     Widget sizeTB;
78     Widget sizeList;
79     int    originalFontIndex;
80     int    selectedFontIndex;
81     String selectedFontStr;
82     Boolean userTextChanged;
83 } FontData;
84 static FontData font;
85
86 static saveRestore save = {FALSE, 0, };
87
88 /*+++++++++++++++++++++++++++++++++++++++*/
89 /* Internal Functions                    */
90 /*+++++++++++++++++++++++++++++++++++++++*/
91
92
93 static void CreateFontDlg( 
94                         Widget parent) ;
95 static void _DtmapCB_fontBB( 
96                         Widget w,
97                         XtPointer client_data,
98                         XtPointer call_data) ;
99 static void ButtonCB( 
100                         Widget w,
101                         XtPointer client_data,
102                         XtPointer call_data) ;
103 static void changeSampleFontCB( 
104                         Widget w,
105                         XtPointer client_data,
106                         XtPointer call_data) ;
107 static void valueChangedCB( 
108                         Widget w,
109                         XtPointer client_data,
110                         XtPointer call_data) ;
111
112
113 /*+++++++++++++++++++++++++++++++++++++++*/
114 /* popup_fontBB                          */
115 /*+++++++++++++++++++++++++++++++++++++++*/
116 void 
117 popup_fontBB(
118         Widget shell )
119 {
120   if (style.fontDialog == NULL) {
121     _DtTurnOnHourGlass(shell);  
122     CreateFontDlg(shell); 
123     XtManageChild(style.fontDialog);
124     _DtTurnOffHourGlass(shell);  
125   } else { 
126     XtManageChild(style.fontDialog);
127     raiseWindow(XtWindow(XtParent(style.fontDialog)));
128   }
129
130   /* If no font is found to match current Desktop
131      font, pop up informative message */
132   if (font.selectedFontIndex < 0)
133      InfoDialog(INFO_MSG, style.shell, False);
134 }
135
136 /*+++++++++++++++++++++++++++++++++++++++*/
137 /* CreateFontDlg                         */
138 /*+++++++++++++++++++++++++++++++++++++++*/
139 static void 
140 CreateFontDlg(
141         Widget parent )
142 {
143
144     register int     n;
145     int              i;
146     Arg              args[MAX_ARGS];
147     Widget           appTBox;
148     Widget           sizeMenuPlDn;
149     XmString         button_string[NUM_LABELS];
150     XmString         string;
151     int              count = 0;
152     Widget           widget_list[6];
153     XmString         *sizeItems;
154     XmStringTable    selectedSize;
155     char             sizeStr[111];
156     Dimension        fontheight;
157
158
159     font.selectedFontStr = style.xrdb.systemFontStr;
160
161     /* Assume nothing is selected */
162     font.selectedFontIndex = -1;
163
164     /* 
165      * The following flag is used to determine if the user has 
166      * entered anything into the sample user font field.  If 
167      * he does, than when the font selection is changed, the 
168      * default message "aAbBcC..." won't be displayed overwriting
169      * the user's text, only the fontlist will be changed. 
170      * This flag will be set in the valueChanged callback for the
171      * font.sizeList widget.
172      */
173     font.userTextChanged = FALSE;
174
175     /* 
176      * Look for the selectedFont in the fontChoice array and set 
177      * selectedFontIndex to that entry
178      */
179     for (i=0; i<style.xrdb.numFonts; i++)
180         if (strcmp (font.selectedFontStr, 
181                     style.xrdb.fontChoice[i].sysStr) == 0)
182         {
183             font.selectedFontIndex = i;        
184             if (!style.xrdb.fontChoice[i].userFont)
185                 GetUserFontResource(i);
186             if (!style.xrdb.fontChoice[i].sysFont)
187                 GetSysFontResource(i);
188             break;    
189         }            
190
191     /* 
192      * Save the index of the originally selected font.  If no
193      * font is selected, this value will remain -1.
194      */
195     font.originalFontIndex = font.selectedFontIndex;
196
197     /* Set up button labels. */
198     button_string[0] = CMPSTR(_DtOkString);
199     button_string[1] = CMPSTR(_DtCancelString);
200     button_string[2] = CMPSTR(_DtHelpString);
201
202     /* Create toplevel DialogBox */
203     /* saveRestore
204      * Note that save.poscnt has been initialized elsewhere.  
205      * save.posArgs may contain information from restoreFont().
206      */
207
208     XtSetArg(save.posArgs[save.poscnt], XmNallowOverlap, False); save.poscnt++;
209     XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False); 
210     save.poscnt++;
211     XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);  
212     save.poscnt++;
213     XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string); 
214     save.poscnt++;
215     style.fontDialog = 
216         __DtCreateDialogBoxDialog(parent, "Fonts", save.posArgs, save.poscnt);
217     XtAddCallback(style.fontDialog, XmNcallback, ButtonCB, NULL);
218     XtAddCallback(style.fontDialog, XmNmapCallback, _DtmapCB_fontBB, 
219                             (XtPointer)parent);
220     XtAddCallback(style.fontDialog, XmNhelpCallback,
221             (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FONT_DIALOG);
222
223     XmStringFree(button_string[0]);
224     XmStringFree(button_string[1]);
225     XmStringFree(button_string[2]);
226
227     widget_list[0] = _DtDialogBoxGetButton(style.fontDialog,2);
228     n=0;
229     XtSetArg(args[n], XmNautoUnmanage, False); n++;
230     XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
231     XtSetValues (style.fontDialog, args, n);
232
233     n=0;
234     XtSetArg(args[n], XmNtitle, FONT_MSG); n++;
235     XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
236     XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
237     XtSetValues (XtParent(style.fontDialog), args, n);
238
239     n = 0;
240     XtSetArg (args[n], XmNchildType, XmWORK_AREA);  n++;
241     XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
242     XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
243     XtSetArg(args[n], XmNallowOverlap, False); n++;
244     font.fontWkarea = XmCreateForm(style.fontDialog, "fontWorkArea", args, n);
245
246     n = 0;
247     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);  n++;
248     XtSetArg(args[n], XmNtopOffset, style.verticalSpacing);  n++;
249     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);  n++;
250
251     XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
252     XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
253     XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
254     XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
255     XtSetArg(args[n], XmNstring, NULL); n++;  
256     XtSetArg(args[n], XmNshadowThickness, 0); n++;  
257     XtSetArg(args[n], XmNimageName, FONT_ICON); n++;  
258     XtSetArg(args[n], XmNtraversalOn, False); n++;  
259     widget_list[count++] = font.fontpictLabel = 
260         _DtCreateIcon(font.fontWkarea, "fontpictLabel", args, n);
261
262     /* Create a TitleBox and Scale/List to choose the font size */
263
264     n = 0;
265     string = CMPSTR(SIZE);
266     XtSetArg(args[n], XmNtitleString, string);  n++;
267     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
268     XtSetArg(args[n], XmNtopWidget,          font.fontpictLabel);  n++;
269     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing+5);  n++;
270     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
271     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
272     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
273     widget_list[count++] = font.sizeTB =
274         _DtCreateTitleBox(font.fontWkarea, "sizeTB", args, n); 
275     XmStringFree(string);
276
277     /* calculate size for each of the fonts based on system font size */
278
279     sizeItems = (XmString *) XtMalloc(sizeof(XmString) * style.xrdb.numFonts);
280     for (n=0; n<style.xrdb.numFonts; n++)
281       {
282         sprintf(sizeStr, "%d", (int)(n+1));
283         sizeItems[n] = CMPSTR(sizeStr);
284         style.xrdb.fontChoice[n].pointSize = CMPSTR(sizeStr); 
285       }
286   
287
288     n=0;
289     XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
290     XtSetArg (args[n], XmNautomaticSelection, True); n++;
291     XtSetArg (args[n], XmNvisibleItemCount, 7); n++;
292     XtSetArg (args[n], XmNitemCount, style.xrdb.numFonts); n++;
293     XtSetArg (args[n], XmNitems, sizeItems); n++;
294
295     /* 
296      * If matching font was found for current selection,
297      * display it as selected.  Otherwise, don't select
298      * anything.
299      */
300     if (font.selectedFontIndex >=0) {
301       selectedSize = &(style.xrdb.fontChoice[font.selectedFontIndex].pointSize);
302       XtSetArg (args[n], XmNselectedItems, selectedSize); n++; 
303       XtSetArg (args[n], XmNselectedItemCount, 1); n++;
304     }
305     font.sizeList = XmCreateScrolledList(font.sizeTB,"sizeList",args,n);
306     XtAddCallback(font.sizeList, XmNbrowseSelectionCallback,
307                                          changeSampleFontCB, NULL);
308
309     /* If a font match was found and selected, then set it's point size. */
310     if (font.selectedFontIndex >=0)
311       XmListSetItem(font.sizeList,
312         style.xrdb.fontChoice[font.selectedFontIndex].pointSize);
313     XtFree((char *)sizeItems);
314
315     /* preview TitleBox */
316     n = 0;
317     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
318     XtSetArg(args[n], XmNtopWidget,          font.fontpictLabel);  n++;
319     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing+5);  n++;
320     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);     n++; 
321     XtSetArg(args[n], XmNleftWidget,         font.sizeTB);         n++;
322     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
323     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
324     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
325     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);    n++;
326     string = CMPSTR(PREVIEW); 
327     XtSetArg(args[n], XmNtitleString, string); n++;
328     widget_list[count++] = font.previewTB =
329         _DtCreateTitleBox(font.fontWkarea, "systemSample", args, n);
330     XmStringFree(string);
331   
332     /*form to contain preview font area*/
333     n = 0;
334     font.previewForm = 
335         XmCreateForm(font.previewTB, "previewForm", args, n);
336
337     /* sample system font */
338     n = 0;
339
340     /* 
341      * If a font match was found and selected, then set the fontlist
342      * and the sample string.  Otherwise, output a blank message.
343      */
344     if (font.selectedFontIndex >=0) {
345       XtSetArg (args[n], XmNfontList, 
346         style.xrdb.fontChoice[font.selectedFontIndex].sysFont); n++; 
347       string = CMPSTR(SYSTEM_MSG); 
348     } else {
349       string = CMPSTR(BLANK_MSG);
350     }
351     XtSetArg (args[n], XmNlabelString, string);  n++;
352     XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING);  n++;
353     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM);  n++;
354     XtSetArg (args[n], XmNtopOffset, 2 * style.verticalSpacing);  n++;    
355     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM);  n++;
356     XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM);  n++;
357     XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE);  n++;
358     font.systemLabel = 
359         XmCreateLabelGadget(font.previewForm, "systemSample", args, n);
360     XmStringFree(string);
361
362     /* sample user font */
363     n = 0;
364     /* 
365      * If a font match was found and selected, then set the fontlist
366      * and the sample string.   Otherwise output a blank message.
367      */
368     if (font.selectedFontIndex >=0) {
369       XtSetArg (args[n], XmNfontList, 
370               style.xrdb.fontChoice[font.selectedFontIndex].userFont); n++;
371       XtSetArg (args[n], XmNvalue, USER_MSG);  n++;
372     } else {
373       XtSetArg (args[n], XmNvalue, NULL);  n++;
374     }
375
376     XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET);  n++;
377     XtSetArg (args[n], XmNtopWidget, font.systemLabel);  n++;
378     XtSetArg (args[n], XmNtopOffset, 2 * style.verticalSpacing);  n++;    
379     XtSetArg (args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET);  n++;
380     XtSetArg (args[n], XmNleftWidget, font.systemLabel);  n++;
381     XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE);  n++;
382     XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET);  n++;
383     XtSetArg (args[n], XmNrightWidget, font.systemLabel);  n++;
384     font.userText = 
385         XmCreateText(font.previewForm, "userText", args, n);
386     /* Add callback to determine if user changes text in sample field */
387     XtAddCallback(font.userText, XmNvalueChangedCallback, valueChangedCB, NULL);
388
389     XtManageChild(font.systemLabel);
390     XtManageChild(font.userText);
391     XtManageChild(font.previewForm);
392     XtManageChild(font.sizeList);
393     XtManageChildren(widget_list,count);
394     XtManageChild(font.fontWkarea);
395
396 }
397
398
399 /*+++++++++++++++++++++++++++++++++++++++*/
400 /* _DtmapCB_fontBB                          */
401 /*+++++++++++++++++++++++++++++++++++++++*/
402 static void 
403 _DtmapCB_fontBB(
404         Widget w,
405         XtPointer client_data,
406         XtPointer call_data )
407 {
408    
409     DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
410
411     if (!save.restoreFlag)
412         putDialog ((Widget)client_data, w);
413       
414     XmTextShowPosition(font.userText, 0);    
415
416     XtRemoveCallback(style.fontDialog, XmNmapCallback, _DtmapCB_fontBB, NULL);
417
418 }
419
420     
421 /*+++++++++++++++++++++++++++++++++++++++++++++++++*/
422 /* ButtonCB                                        */
423 /* Process callback from PushButtons in DialogBox. */
424 /*+++++++++++++++++++++++++++++++++++++++++++++++++*/
425 static void 
426 ButtonCB(
427         Widget w,
428         XtPointer client_data,
429         XtPointer call_data )
430 {
431   DtDialogBoxCallbackStruct *cb     
432            = (DtDialogBoxCallbackStruct *) call_data;
433   int      n, len, items;
434   char     *str, *fntstr, *fntsetstr;
435   Arg      args[MAX_ARGS];
436   char     fontres[8192];
437
438   switch (cb->button_position)
439     {
440         /* Set the xrdb or pass to dtsession and close the window */
441       case OK_BUTTON:
442          /* 
443           * Need to test for the case where the Font dialog maps without 
444           * any fonts selected, and the user presses OK.  Do this by 
445           * checking for number of items selected before changing 
446           * anything.
447           */
448          XtVaGetValues (font.sizeList, XmNselectedItemCount, &items, NULL);
449
450          /*   Post an info dialog explaining when the new fonts will appear */
451          if ((font.selectedFontIndex != font.originalFontIndex) && (items > 0))
452          {
453             XtUnmanageChild(style.fontDialog);  
454
455             if(style.xrdb.writeXrdbImmediate) 
456             { 
457               InfoDialog(IMMEDIATE, style.shell, False); 
458             }
459             else 
460             {
461               InfoDialog(LATER, style.shell, False); 
462             }
463
464             /* 
465                for *FontSet resource: find first font entry delimited by a ":" 
466                or an "=". 
467             */ 
468             len =strcspn(style.xrdb.fontChoice[font.selectedFontIndex].userStr,
469                          ":=");
470             fntsetstr = (char *) XtCalloc(1, len + 1);
471             memcpy(fntsetstr, 
472                    style.xrdb.fontChoice[font.selectedFontIndex].userStr,
473                    len);
474
475             /* 
476                Since the *Font and *FontSet resources may be used by old
477                X applications, a fontlist of multiple fonts must be converted 
478                to Xt font set format (';'s converted to ','s since many old X 
479                apps don't understand ';' syntax.)
480             */
481             str = strstr(fntsetstr,";");
482             while (str) {
483                 *str = ',';
484                 str = strstr(str,";");
485             }
486
487             /* 
488                for *Font resource: find first font entry delimited by a comma, 
489                a colon or an = 
490             */
491             len = strcspn(fntsetstr,",:=");
492             fntstr = (char *) XtCalloc(1, len + 1);
493             memcpy(fntstr, 
494                    style.xrdb.fontChoice[font.selectedFontIndex].userStr,
495                    len);
496
497             /*
498               for *FontSet resource: if we got a font (instead of a font set)
499               from the first entry, then wildcard its charset fields
500              */
501             len = strlen(fntsetstr);
502             if (style.xrdb.fontChoice[font.selectedFontIndex].userStr[len] 
503                 != ':') {
504                 str = strchr(fntsetstr, '-');
505                 for (n = 1; n < 13 && str; n++)
506                     str = strchr(str + 1, '-');
507                 if (str)
508                     strcpy(str + 1, "*-*");
509             }
510
511            /* create the font resource specs with the selected font for xrdb */
512             sprintf(fontres,
513                  "*systemFont: %s\n*userFont: %s\n*FontList: %s\n*buttonFontList: %s\n*labelFontList: %s\n*textFontList: %s\n*XmText*FontList: %s\n*XmTextField*FontList: %s\n*DtEditor*textFontList: %s\n*Font: %s\n*FontSet: %s\n",
514                  style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
515                  style.xrdb.fontChoice[font.selectedFontIndex].userStr,
516                  style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
517                  style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
518                  style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
519                  style.xrdb.fontChoice[font.selectedFontIndex].userStr,
520                  style.xrdb.fontChoice[font.selectedFontIndex].userStr,
521                  style.xrdb.fontChoice[font.selectedFontIndex].userStr,
522                  style.xrdb.fontChoice[font.selectedFontIndex].userStr,
523                  fntstr, fntsetstr);
524
525             XtFree(fntstr);
526             XtFree(fntsetstr);
527
528             /* if writeXrdbImmediate true write to Xrdb else send to session mgr */
529             if(style.xrdb.writeXrdbImmediate)
530                 _DtAddToResource(style.display,fontres);
531
532             SmNewFontSettings(fontres);
533
534             font.originalFontIndex = font.selectedFontIndex;
535             style.xrdb.systemFontStr = font.selectedFontStr;
536          }
537
538          else 
539                  XtUnmanageChild(style.fontDialog);  
540                  
541          break;
542
543     case CANCEL_BUTTON:
544
545       /* reset preview area fonts to original and close the window*/
546
547       XtUnmanageChild(style.fontDialog);
548
549       if (font.originalFontIndex >= 0)
550         XmListSelectPos(font.sizeList, font.originalFontIndex+1, True);
551       else { 
552         /* 
553          * if no font was originally selected, need to undo any results
554          * from selections that were made by user before pressing Cancel.
555          */
556         XtVaSetValues (font.sizeList, XmNselectedItemCount, 0, NULL);
557         XtVaSetValues (font.userText, 
558                        XmNvalue, BLANK_MSG, 
559                        XmNfontList, style.xrdb.userFont,
560                        NULL);
561         XtVaSetValues (font.systemLabel, 
562                        XmNlabelString, CMPSTR(BLANK_MSG), 
563                        XmNfontList, style.xrdb.systemFont,
564                        NULL);
565         font.userTextChanged = FALSE;
566         font.selectedFontIndex = -1;
567       }
568       break;
569
570     case HELP_BUTTON:
571       XtCallCallbacks(style.fontDialog, XmNhelpCallback, (XtPointer)NULL);
572       break;
573
574     default:
575       break;
576     }
577 }
578
579
580 /*+++++++++++++++++++++++++++++++++++++++*/
581 /* changSampleFontCB                     */
582 /*  Change the font in the sample areas  */
583 /*+++++++++++++++++++++++++++++++++++++++*/
584 static void 
585 changeSampleFontCB(
586         Widget w,
587         XtPointer client_data,
588         XtPointer call_data )
589 {
590     int       n;
591     int       pos;
592     int       hourGlassOn;
593     Arg       args[MAX_ARGS];
594     XmListCallbackStruct *cb = (XmListCallbackStruct *) call_data;
595
596     pos = cb->item_position-1;
597
598     font.selectedFontIndex = pos;
599     font.selectedFontStr = style.xrdb.fontChoice[pos].sysStr;
600
601     hourGlassOn = !style.xrdb.fontChoice[pos].userFont ||
602                 !style.xrdb.fontChoice[pos].sysFont;
603
604     if (hourGlassOn)
605       _DtTurnOnHourGlass(style.fontDialog);
606
607     if (!style.xrdb.fontChoice[pos].userFont)
608       GetUserFontResource(pos);
609     if (!style.xrdb.fontChoice[pos].sysFont)
610       GetSysFontResource(pos);
611
612     if (hourGlassOn)
613       _DtTurnOffHourGlass(style.fontDialog);
614
615     /* Set the sample System Font string to different Font */
616     n = 0;
617     XtSetArg(args[n], XmNfontList, style.xrdb.fontChoice[pos].sysFont); n++;
618     /* string_val = CMPSTR(SYSTEM_MSG);*/
619     XtSetArg (args[n], XmNlabelString, CMPSTR(SYSTEM_MSG));  n++;
620     XtSetValues (font.systemLabel, args, n); 
621
622     /* 
623      * If the user didn't change the text field, output standard user 
624      * text message.
625      */
626     n = 0;
627     if (!font.userTextChanged) 
628       XtSetArg (args[n], XmNvalue, USER_MSG);  n++;
629     XtSetArg(args[n], XmNfontList, style.xrdb.fontChoice[pos].userFont); n++;
630     XtSetValues (font.userText, args, n);
631     XmTextShowPosition(font.userText, 0);
632 }
633
634 /*+++++++++++++++++++++++++++++++++++++++*/
635 /* valueChangedCB                        */
636 /*  Set flag indicating that the user    */
637 /*  text field has been modified.        */
638 /*+++++++++++++++++++++++++++++++++++++++*/
639 static void 
640 valueChangedCB(
641         Widget w,
642         XtPointer client_data,
643         XtPointer call_data )
644
645
646   font.userTextChanged = TRUE; 
647 }
648
649 /************************************************************************
650  * restoreFonts()
651  *
652  * restore any state information saved with saveFonts.
653  * This is called from restoreSession with the application
654  * shell and the special xrm database retrieved for restore.
655  ************************************************************************/
656 void 
657 restoreFonts(
658         Widget shell,
659         XrmDatabase db )
660 {
661     XrmName xrm_name[5];
662     XrmRepresentation rep_type;
663     XrmValue value;
664
665     xrm_name [0] = XrmStringToQuark ("Fonts");
666     xrm_name [2] = NULL;
667
668     /* get x position */
669     xrm_name [1] = XrmStringToQuark ("x");
670     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
671       XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); 
672       save.poscnt++;
673       save.restoreFlag = True;
674     }
675
676     /* get y position */
677     xrm_name [1] = XrmStringToQuark ("y");
678     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
679       XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); 
680       save.poscnt++;
681     }
682
683     xrm_name [1] = XrmStringToQuark ("ismapped");
684     XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
685     /* Are we supposed to be mapped? */
686     if (strcmp(value.addr, "True") == 0) 
687       popup_fontBB(shell);
688 }
689
690 /************************************************************************
691  * saveFonts()
692  *
693  * This routine will write out to the passed file descriptor any state
694  * information this dialog needs.  It is called from saveSessionCB with the
695  * file already opened.
696  * All information is saved in xrm format.  There is no restriction
697  * on what can be saved.  It doesn't have to be defined or be part of any
698  * widget or Xt definition.  Just name and save it here and recover it in
699  * restoreFonts.  The suggested minimum is whether you are mapped, and your
700  * location.
701  ************************************************************************/
702 void 
703 saveFonts(
704         int fd )
705 {
706     Position x,y;
707     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
708     XmVendorShellExtObject  vendorExt;
709     XmWidgetExtData         extData;
710
711     if (style.fontDialog != NULL) {
712         if (XtIsManaged(style.fontDialog))
713           sprintf(bufr, "*Fonts.ismapped: True\n");
714         else
715           sprintf(bufr, "*Fonts.ismapped: False\n");
716
717         /* Get and write out the geometry info for our Window */
718
719         x = XtX(XtParent(style.fontDialog));
720         y = XtY(XtParent(style.fontDialog));
721
722         /* Modify x & y to take into account window mgr frames
723          * This is pretty bogus, but I don't know a better way to do it.
724          */
725         extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
726         vendorExt = (XmVendorShellExtObject)extData->widget;
727         x -= vendorExt->vendor.xOffset;
728         y -= vendorExt->vendor.yOffset;
729
730         sprintf(bufr, "%s*Fonts.x: %d\n", bufr, x);
731         sprintf(bufr, "%s*Fonts.y: %d\n", bufr, y);
732
733         write (fd, bufr, strlen(bufr));
734     }
735 }
736
737
738