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