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