1 static const char CVSID
[] = "$Id: fontsel.c,v 1.24 2003/04/07 22:51:41 yooden Exp $";
2 /*******************************************************************************
4 * fontsel.c -- Nirvana Font Selector *
6 * Copyright (C) 1999 Mark Edel *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
13 * This software is distributed in the hope that it will be useful, but WITHOUT *
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
18 * You should have received a copy of the GNU General Public License along with *
19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
20 * Place, Suite 330, Boston, MA 02111-1307 USA *
22 * Nirvana Text Editor *
25 * Written by Suresh Ravoor (assisted by Mark Edel) *
27 *******************************************************************************/
30 #include "../config.h"
42 #include <X11/Intrinsic.h>
50 #include <Xm/ToggleB.h>
51 #include <Xm/MessageB.h>
52 #include <Xm/DialogS.h>
59 #define MAX_NUM_FONTS 32767
60 #define MAX_FONT_NAME_LEN 256
61 #define MAX_ENTRIES_IN_LIST 5000
62 #define MAX_DISPLAY_SIZE 150
64 #define NUM_COMPONENTS_FONT_NAME 14
65 #define TEMP_BUF_SIZE 256
66 #define DISPLAY_HEIGHT 90
68 enum listSpecifier
{ NONE
, FONT
, STYLE
, SIZE
};
71 /* local data structures and types */
75 Widget form
; /* widget id */
76 Widget okButton
; /* widget id */
77 Widget cancelButton
; /* widget id */
78 Widget fontList
; /* widget id */
79 Widget styleList
; /* widget id */
80 Widget sizeList
; /* widget id */
81 Widget fontNameField
; /* widget id */
82 Widget sizeToggle
; /* widget id */
83 Widget propFontToggle
; /* widget id */
84 Widget dispField
; /* widget id */
85 char **fontData
; /* font name info */
86 int numFonts
; /* number of fonts */
87 char *sel1
; /* selection from list 1 */
88 char *sel2
; /* selection from list 2 */
89 char *sel3
; /* selection from list 3 */
90 int showPropFonts
; /* toggle state - show prop fonts */
91 int showSizeInPixels
;/* toggle state - size in pixels */
92 char *fontName
; /* current font name */
93 XFontStruct
*oldFont
; /* font data structure for dispSample */
94 XmFontList oldFontList
; /* font data structure for dispSample */
95 int exitFlag
; /* used for program exit control */
96 int destroyedFlag
; /* used to prevent double destruction */
97 Pixel sampleFG
; /* Colors for the sample field */
99 } xfselControlBlkType
;
102 /* local function prototypes */
104 static void getStringComponent(const char *inStr
, int pos
, char *outStr
);
105 static void setupScrollLists(int dontChange
, xfselControlBlkType ctrlBlk
);
106 static int notPropFont(const char *font
);
107 static int styleMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
108 static int sizeMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
109 static int fontMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
110 static void addItemToList(char **buf
, const char *item
, int *count
);
111 static void getFontPart(const char *font
, char *buff1
);
112 static void getStylePart(const char *font
, char *buff1
);
113 static void getSizePart(const char *font
, char *buff1
, int inPixels
);
114 static void propFontToggleAction(Widget widget
,
115 xfselControlBlkType
*ctrlBlk
,
116 XmToggleButtonCallbackStruct
*call_data
);
117 static void sizeToggleAction(Widget widget
,
118 xfselControlBlkType
*ctrlBlk
,
119 XmToggleButtonCallbackStruct
*call_data
);
120 static void fontAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
121 XmListCallbackStruct
*call_data
);
122 static void styleAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
123 XmListCallbackStruct
*call_data
);
124 static void sizeAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
125 XmListCallbackStruct
*call_data
);
126 static void choiceMade(xfselControlBlkType
*ctrlBlk
);
127 static void dispSample(xfselControlBlkType
*ctrlBlk
);
128 static void destroyCB(Widget widget
, xfselControlBlkType
*ctrlBlk
,
129 XmListCallbackStruct
*call_data
);
130 static void cancelAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
131 XmListCallbackStruct
*call_data
);
132 static void okAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
133 XmPushButtonCallbackStruct
*call_data
);
134 static void startupFont(xfselControlBlkType
*ctrlBlk
, const char *font
);
135 static void setFocus(Widget w
, xfselControlBlkType
*ctrlBlk
, XEvent
*event
,
136 Boolean
*continueToDispatch
);
137 static void FindBigFont(xfselControlBlkType
*ctrlBlk
, char *bigFont
);
138 static void enableSample(xfselControlBlkType
*ctrlBlk
, Bool turn_on
,
139 XmFontList
*fontList
);
141 /*******************************************************************************
146 * Function to put up a modal font selection dialog box. The purpose *
147 * of this routine is to allow the user to interactively view sample *
148 * fonts and to choose a font for current use. *
152 * Widget parent - parent widget ID *
154 * int showPropFont - ONLY_FIXED : shows only fixed fonts *
155 * doesn't show prop font *
156 * toggle button also. *
157 * PREF_FIXED : can select either fixed *
158 * or proportional fonts; *
159 * but starting option is *
161 * PREF_PROP : can select either fixed *
162 * or proportional fonts; *
163 * but starting option is *
164 * proportional fonts. *
166 * char * currFont - ASCII string that contains the name *
167 * of the currently selected font. *
169 * Pixel sampleFG, sampleBG - Foreground/Background colors in *
170 * which to display the sample *
176 * pointer to an ASCII character string that contains the name of *
177 * the selected font (in X format for naming fonts); it is the users *
178 * responsibility to free the space allocated to this string. *
182 * The calling function has to call the appropriate routines to set *
183 * the current font to the one represented by the returned string. *
185 *******************************************************************************/
187 char *FontSel(Widget parent
, int showPropFonts
, const char *currFont
,
188 Pixel sampleFG
, Pixel sampleBG
)
190 Widget dialog
, form
, okButton
, cancelButton
;
191 Widget styleList
, sizeList
, fontName
, fontList
;
192 Widget sizeToggle
, propFontToggle
= NULL
, dispField
;
193 Widget nameLabel
, sampleLabel
;
197 char bigFont
[MAX_FONT_NAME_LEN
];
198 xfselControlBlkType ctrlBlk
;
201 ctrlBlk
.fontData
= XListFonts(XtDisplay(parent
),
202 "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
203 MAX_NUM_FONTS
, &ctrlBlk
.numFonts
);
204 FindBigFont(&ctrlBlk
, bigFont
);
205 ctrlBlk
.oldFont
= XLoadQueryFont(XtDisplay(parent
), bigFont
);
206 ctrlBlk
.oldFontList
= XmFontListCreate(ctrlBlk
.oldFont
,
207 XmSTRING_DEFAULT_CHARSET
);
208 ctrlBlk
.sampleFG
= sampleFG
;
209 ctrlBlk
.sampleBG
= sampleBG
;
211 dialog
= CreateDialogShell(parent
, "Font Selector", args
, 0);
213 /* Set up window sizes for form widget */
216 XtSetArg(args
[n
], XmNautoUnmanage
, FALSE
); n
++;
217 XtSetArg(args
[n
], XmNdialogStyle
, XmDIALOG_FULL_APPLICATION_MODAL
); n
++;
219 /* Create form popup dialog widget */
221 form
= XtCreateWidget ("Font Selector", xmFormWidgetClass
, dialog
,
224 /* Create pushbutton widgets */
227 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_FORM
); n
++;
228 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
229 XtSetArg(args
[n
], XmNbottomOffset
, 4); n
++;
230 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
231 XtSetArg(args
[n
], XmNrightPosition
, 45); n
++;
232 XtSetArg(args
[n
], XmNwidth
, 110); n
++;
233 XtSetArg(args
[n
], XmNheight
, 28); n
++;
234 XtSetArg(args
[n
], XmNshowAsDefault
, TRUE
); n
++;
235 okButton
= XtCreateManagedWidget("OK", xmPushButtonWidgetClass
, form
,
239 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
240 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
241 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
242 XtSetArg(args
[n
], XmNtopWidget
, okButton
); n
++;
243 XtSetArg(args
[n
], XmNbottomWidget
, okButton
); n
++;
244 XtSetArg(args
[n
], XmNleftPosition
, 55); n
++;
245 XtSetArg(args
[n
], XmNwidth
, 110); n
++;
246 XtSetArg(args
[n
], XmNheight
, 28); n
++;
247 cancelButton
= XtCreateManagedWidget("Cancel", xmPushButtonWidgetClass
,
250 /* create font name text widget and the corresponding label */
253 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
254 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
255 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
256 XtSetArg(args
[n
], XmNbottomWidget
, okButton
); n
++;
257 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
258 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
259 XtSetArg(args
[n
], XmNeditable
, True
); n
++;
260 XtSetArg(args
[n
], XmNeditMode
, XmSINGLE_LINE_EDIT
); n
++;
261 XtSetArg(args
[n
], XmNmaxLength
, MAX_FONT_NAME_LEN
); n
++;
262 fontName
= XtCreateManagedWidget("fontname", xmTextWidgetClass
, form
,
264 RemapDeleteKey(fontName
); /* kludge to handle delete and BS */
267 tempStr
= XmStringCreate("Font Name:", XmSTRING_DEFAULT_CHARSET
);
268 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
269 XtSetArg(args
[n
], XmNmnemonic
, 'N'); n
++;
270 XtSetArg(args
[n
], XmNuserData
, fontName
); n
++;
271 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
272 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
273 XtSetArg(args
[n
], XmNleftWidget
, fontName
); n
++;
274 XtSetArg(args
[n
], XmNbottomWidget
, fontName
); n
++;
275 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
276 nameLabel
= XtCreateManagedWidget("Font Name:", xmLabelWidgetClass
,
278 XmStringFree(tempStr
);
280 /* create sample display text field widget */
283 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
284 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
285 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
286 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
287 XtSetArg(args
[n
], XmNbottomWidget
, nameLabel
); n
++;
288 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
289 XtSetArg(args
[n
], XmNalignment
, XmALIGNMENT_BEGINNING
); n
++;
290 XtSetArg(args
[n
], XmNvalue
,
291 "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789");
293 XtSetArg(args
[n
], XmNforeground
, sampleFG
); n
++;
294 XtSetArg(args
[n
], XmNbackground
, sampleBG
); n
++;
295 dispField
= XtCreateManagedWidget(" ", xmTextFieldWidgetClass
, form
,
299 tempStr
= XmStringCreate("Sample:", XmSTRING_DEFAULT_CHARSET
);
300 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
301 XtSetArg(args
[n
], XmNmnemonic
, 'S'); n
++;
302 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
303 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
304 XtSetArg(args
[n
], XmNleftWidget
, dispField
); n
++;
305 XtSetArg(args
[n
], XmNbottomWidget
, dispField
); n
++;
306 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
307 sampleLabel
= XtCreateManagedWidget("Font Name:", xmLabelWidgetClass
,
309 XmStringFree(tempStr
);
311 /* create toggle buttons */
314 tempStr
= XmStringCreate("Show Size in Points",
315 XmSTRING_DEFAULT_CHARSET
);
316 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
317 XtSetArg(args
[n
], XmNmnemonic
, 'P'); n
++;
318 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
319 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
320 XtSetArg(args
[n
], XmNleftPosition
, 2); n
++;
321 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
322 XtSetArg(args
[n
], XmNbottomWidget
, sampleLabel
); n
++;
323 sizeToggle
= XtCreateManagedWidget("sizetoggle",
324 xmToggleButtonWidgetClass
, form
, args
, n
);
325 XmStringFree(tempStr
);
327 if (showPropFonts
!= ONLY_FIXED
)
330 tempStr
= XmStringCreate("Show Proportional Width Fonts",
331 XmSTRING_DEFAULT_CHARSET
);
332 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
333 XtSetArg(args
[n
], XmNmnemonic
, 'W'); n
++;
334 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
335 XtSetArg(args
[n
], XmNtopAttachment
,
336 XmATTACH_OPPOSITE_WIDGET
); n
++;
337 XtSetArg(args
[n
], XmNbottomAttachment
,
338 XmATTACH_OPPOSITE_WIDGET
); n
++;
339 XtSetArg(args
[n
], XmNrightPosition
, 98); n
++;
340 XtSetArg(args
[n
], XmNtopWidget
, sizeToggle
); n
++;
341 XtSetArg(args
[n
], XmNbottomWidget
, sizeToggle
); n
++;
342 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
343 propFontToggle
= XtCreateManagedWidget("propfonttoggle",
344 xmToggleButtonWidgetClass
, form
, args
, n
);
345 XmStringFree(tempStr
);
348 /* create scroll list widgets */
352 tempStr
= XmStringCreate("Font:", XmSTRING_DEFAULT_CHARSET
);
353 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
354 XtSetArg(args
[n
], XmNmnemonic
, 'F'); n
++;
355 XtSetArg(args
[n
], XmNtopOffset
, 2); n
++;
356 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_FORM
); n
++;
357 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
358 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
359 nameLabel
= XtCreateManagedWidget("Font:", xmLabelWidgetClass
, form
,
361 XmStringFree(tempStr
);
364 XtSetArg(args
[n
], XmNvisibleItemCount
, 15); n
++;
365 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
366 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
367 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
368 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
369 XtSetArg(args
[n
], XmNbottomWidget
, sizeToggle
); n
++;
370 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
371 XtSetArg(args
[n
], XmNleftWidget
, nameLabel
); n
++;
372 XtSetArg(args
[n
], XmNrightPosition
, 52); n
++;
373 fontList
= XmCreateScrolledList(form
, "fontlist", args
, n
);
374 XtManageChild(fontList
);
375 XtVaSetValues(nameLabel
, XmNuserData
, fontList
, NULL
);
380 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
381 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
382 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_WIDGET
); n
++;
383 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
384 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
385 XtSetArg(args
[n
], XmNleftOffset
, 5); n
++;
386 XtSetArg(args
[n
], XmNleftWidget
, XtParent(fontList
)); n
++;
387 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(fontList
)); n
++;
388 XtSetArg(args
[n
], XmNrightPosition
, 85); n
++;
389 styleList
= XmCreateScrolledList(form
, "stylelist", args
, n
);
390 XtManageChild(styleList
);
393 tempStr
= XmStringCreate("Style:", XmSTRING_DEFAULT_CHARSET
);
394 XtSetArg(args
[n
], XmNmnemonic
, 'y'); n
++;
395 XtSetArg(args
[n
], XmNuserData
, styleList
); n
++;
396 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
397 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
398 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
399 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(styleList
)); n
++;
400 XtSetArg(args
[n
], XmNleftWidget
, XtParent(styleList
)); n
++;
401 XtCreateManagedWidget("Style:", xmLabelWidgetClass
, form
, args
, n
);
402 XmStringFree(tempStr
);
407 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
408 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_WIDGET
); n
++;
409 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
410 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
411 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
412 XtSetArg(args
[n
], XmNleftWidget
, XtParent(styleList
)); n
++;
413 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(fontList
)); n
++;
414 XtSetArg(args
[n
], XmNleftOffset
, 5); n
++;
415 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
416 sizeList
= XmCreateScrolledList(form
, "sizelist", args
, n
);
417 XtManageChild(sizeList
);
420 tempStr
= XmStringCreate("Size:", XmSTRING_DEFAULT_CHARSET
);
421 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
422 XtSetArg(args
[n
], XmNmnemonic
, 'z'); n
++;
423 XtSetArg(args
[n
], XmNuserData
, sizeList
); n
++;
424 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
425 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
426 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(sizeList
)); n
++;
427 XtSetArg(args
[n
], XmNleftWidget
, XtParent(sizeList
)); n
++;
428 XtCreateManagedWidget("Size:", xmLabelWidgetClass
, form
, args
, n
);
429 XmStringFree(tempStr
);
431 /* update form widgets cancel button */
434 XtSetArg(args
[n
], XmNcancelButton
, cancelButton
); n
++;
435 XtSetValues(form
, args
, n
);
438 /* update application's control block structure */
441 ctrlBlk
.okButton
= okButton
;
442 ctrlBlk
.cancelButton
= cancelButton
;
443 ctrlBlk
.fontList
= fontList
;
444 ctrlBlk
.styleList
= styleList
;
445 ctrlBlk
.sizeList
= sizeList
;
446 ctrlBlk
.fontNameField
= fontName
;
447 ctrlBlk
.sizeToggle
= sizeToggle
;
448 if (showPropFonts
!= ONLY_FIXED
)
449 ctrlBlk
.propFontToggle
= propFontToggle
;
450 ctrlBlk
.dispField
= dispField
;
451 ctrlBlk
.exitFlag
= FALSE
;
452 ctrlBlk
.destroyedFlag
= FALSE
;
453 ctrlBlk
.showPropFonts
= showPropFonts
;
454 ctrlBlk
.showSizeInPixels
= TRUE
;
458 ctrlBlk
.fontName
= NULL
;
460 setupScrollLists(NONE
, ctrlBlk
); /* update scroll lists */
462 if (showPropFonts
== PREF_PROP
)
463 XmToggleButtonSetState(propFontToggle
, TRUE
, FALSE
);
465 /* Register callback functions */
467 if (showPropFonts
!= ONLY_FIXED
)
468 XtAddCallback(propFontToggle
, XmNvalueChangedCallback
,
469 (XtCallbackProc
)propFontToggleAction
, (char *)&ctrlBlk
);
470 XtAddCallback(sizeToggle
, XmNvalueChangedCallback
,
471 (XtCallbackProc
)sizeToggleAction
, (char *)&ctrlBlk
);
472 XtAddCallback(fontList
, XmNbrowseSelectionCallback
,
473 (XtCallbackProc
)fontAction
, (char *)&ctrlBlk
);
474 XtAddCallback(styleList
, XmNbrowseSelectionCallback
,
475 (XtCallbackProc
)styleAction
, (char *)&ctrlBlk
);
476 XtAddCallback(sizeList
, XmNbrowseSelectionCallback
,
477 (XtCallbackProc
)sizeAction
, (char *)&ctrlBlk
);
478 XtAddCallback(okButton
, XmNactivateCallback
,
479 (XtCallbackProc
)okAction
, (char *)&ctrlBlk
);
480 XtAddCallback(cancelButton
, XmNactivateCallback
,
481 (XtCallbackProc
)cancelAction
, (char *)&ctrlBlk
);
483 /* add event handler to setup input focus at start to scroll list */
485 XtAddEventHandler(fontList
, FocusChangeMask
, FALSE
,
486 (XtEventHandler
)setFocus
, (char *)&ctrlBlk
);
487 XmProcessTraversal(fontList
, XmTRAVERSE_CURRENT
);
489 /* setup tabgroups */
491 XmAddTabGroup(fontList
);
492 XmAddTabGroup(styleList
);
493 XmAddTabGroup(sizeList
);
494 XmAddTabGroup(sizeToggle
);
495 if (showPropFonts
!= ONLY_FIXED
)
496 XmAddTabGroup(propFontToggle
);
497 XmAddTabGroup(fontName
);
498 XmAddTabGroup(okButton
);
499 XmAddTabGroup(cancelButton
);
501 /* Make sure that we don't try to access the dialog if the user
502 destroyed it (possibly indirectly, by destroying the parent). */
503 XtAddCallback(dialog
, XmNdestroyCallback
,
504 (XtCallbackProc
)destroyCB
, (char *)&ctrlBlk
);
506 /* Link Motif Close option to cancel action */
508 AddMotifCloseCallback(dialog
, (XtCallbackProc
)cancelAction
, &ctrlBlk
);
510 /* Handle dialog mnemonics */
512 AddDialogMnemonicHandler(form
, FALSE
);
514 /* Realize Widgets */
516 ManageDialogCenteredOnPointer(form
);
518 /* set up current font parameters */
520 if (currFont
[0] != '\0')
521 startupFont(&ctrlBlk
, currFont
);
523 /* Make sure that we can still access the display in case the form
525 theDisplay
= XtDisplay(form
);
527 /* enter event loop */
529 while (! ctrlBlk
.exitFlag
&& ! ctrlBlk
.destroyedFlag
)
530 XtAppProcessEvent(XtWidgetToApplicationContext(form
), XtIMAll
);
532 if (! ctrlBlk
.destroyedFlag
) {
533 /* Don't let the callback destroy the font name */
534 XtRemoveCallback(dialog
, XmNdestroyCallback
,
535 (XtCallbackProc
)destroyCB
, (char *)&ctrlBlk
);
536 XtDestroyWidget(dialog
);
539 if (ctrlBlk
.oldFont
!= NULL
)
541 XFreeFont(theDisplay
, ctrlBlk
.oldFont
);
542 XmFontListFree(ctrlBlk
.oldFontList
);
545 return(ctrlBlk
.fontName
);
549 /* gets a specific substring from a string */
551 static void getStringComponent(const char *inStr
, int pos
, char *outStr
)
557 if (pos
> NUM_COMPONENTS_FONT_NAME
)
559 fprintf(stderr
, "Warning: getStringComponent being used for ");
560 fprintf(stderr
, "pos > %d\nIf such ", NUM_COMPONENTS_FONT_NAME
);
561 fprintf(stderr
, "use is intended remove these warning lines\n");
564 for (i
= 0; (pos
> 0) && (inStr
[i
] != '\0'); i
++)
565 if (inStr
[i
] == DELIM
)
568 if (inStr
[i
] == '\0')
571 for (j
= 0; (inStr
[i
] != DELIM
) && (inStr
[i
] != '\0'); i
++, j
++)
572 outStr
[j
] = inStr
[i
];
577 /* parse through the fontlist data and set up the three scroll lists */
579 static void setupScrollLists(int dontChange
, xfselControlBlkType ctrlBlk
)
581 char *itemBuf1
[MAX_ENTRIES_IN_LIST
];
582 char *itemBuf2
[MAX_ENTRIES_IN_LIST
];
583 char *itemBuf3
[MAX_ENTRIES_IN_LIST
];
584 int itemCount1
, itemCount2
, itemCount3
;
585 char buff1
[TEMP_BUF_SIZE
];
586 XmString items
[MAX_ENTRIES_IN_LIST
];
593 for (i
= 0; i
< ctrlBlk
.numFonts
&& i
< MAX_ENTRIES_IN_LIST
; i
++)
595 if ((dontChange
!= FONT
) &&
596 (styleMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
597 (sizeMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
598 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
599 (notPropFont(ctrlBlk
.fontData
[i
]))))
601 getFontPart(ctrlBlk
.fontData
[i
], buff1
);
602 addItemToList(itemBuf1
, buff1
, &itemCount1
);
605 if ((dontChange
!= STYLE
) &&
606 (fontMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
607 (sizeMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
608 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
609 (notPropFont(ctrlBlk
.fontData
[i
]))))
611 getStylePart(ctrlBlk
.fontData
[i
], buff1
);
612 addItemToList(itemBuf2
, buff1
, &itemCount2
);
615 if ((dontChange
!= SIZE
) &&
616 (fontMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
617 (styleMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
618 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
619 (notPropFont(ctrlBlk
.fontData
[i
]))))
621 getSizePart(ctrlBlk
.fontData
[i
], buff1
, ctrlBlk
.showSizeInPixels
);
622 addItemToList(itemBuf3
, buff1
, &itemCount3
);
624 } /* end - for (i = 0; i < ctrlBlk.numFonts; i++) */
626 /* recreate all three scroll lists where necessary */
627 if (dontChange
!= FONT
)
629 for (i
= 0; i
< itemCount1
; i
++)
631 items
[i
] = XmStringCreate(itemBuf1
[i
], XmSTRING_DEFAULT_CHARSET
);
634 XmListDeleteAllItems(ctrlBlk
.fontList
);
635 XmListAddItems(ctrlBlk
.fontList
, items
, itemCount1
, 1);
636 if (ctrlBlk
.sel1
!= NULL
)
638 XmStringFree(items
[0]);
639 items
[0] = XmStringCreate(ctrlBlk
.sel1
, XmSTRING_DEFAULT_CHARSET
);
640 XmListSelectItem(ctrlBlk
.fontList
, items
[0], FALSE
);
641 XmListSetBottomItem(ctrlBlk
.fontList
, items
[0]);
643 for (i
= 0; i
< itemCount1
; i
++)
644 XmStringFree(items
[i
]);
647 if (dontChange
!= STYLE
)
649 for (i
= 0; i
< itemCount2
; i
++)
651 items
[i
] = XmStringCreate(itemBuf2
[i
], XmSTRING_DEFAULT_CHARSET
);
654 XmListDeleteAllItems(ctrlBlk
.styleList
);
655 XmListAddItems(ctrlBlk
.styleList
, items
, itemCount2
, 1);
656 if (ctrlBlk
.sel2
!= NULL
)
658 XmStringFree(items
[0]);
659 items
[0] = XmStringCreate(ctrlBlk
.sel2
, XmSTRING_DEFAULT_CHARSET
);
660 XmListSelectItem(ctrlBlk
.styleList
, items
[0], FALSE
);
661 XmListSetBottomItem(ctrlBlk
.styleList
, items
[0]);
663 for (i
= 0; i
< itemCount2
; i
++)
664 XmStringFree(items
[i
]);
667 if (dontChange
!= SIZE
)
669 for (i
= 0; i
< itemCount3
; i
++)
671 items
[i
] = XmStringCreate(itemBuf3
[i
],
672 XmSTRING_DEFAULT_CHARSET
);
675 XmListDeleteAllItems(ctrlBlk
.sizeList
);
676 XmListAddItems(ctrlBlk
.sizeList
, items
, itemCount3
, 1);
677 if (ctrlBlk
.sel3
!= NULL
)
679 XmStringFree(items
[0]);
680 items
[0] = XmStringCreate(ctrlBlk
.sel3
, XmSTRING_DEFAULT_CHARSET
);
681 XmListSelectItem(ctrlBlk
.sizeList
, items
[0], FALSE
);
682 XmListSetBottomItem(ctrlBlk
.sizeList
, items
[0]);
684 for (i
= 0; i
< itemCount3
; i
++)
685 XmStringFree(items
[i
]);
690 /* returns TRUE if argument is not name of a proportional font */
692 static int notPropFont(const char *font
)
694 char buff1
[TEMP_BUF_SIZE
];
696 getStringComponent(font
, 11, buff1
);
697 if ((strcmp(buff1
, "p") == 0) || (strcmp(buff1
, "P") == 0))
704 /* returns TRUE if the style portion of the font matches the currently
707 static int styleMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
709 char buff
[TEMP_BUF_SIZE
];
711 if (ctrlBlk
->sel2
== NULL
)
714 getStylePart(font
, buff
);
716 if (strcmp(buff
, ctrlBlk
->sel2
) == 0)
723 /* returns TRUE if the size portion of the font matches the currently
726 static int sizeMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
728 char buff
[TEMP_BUF_SIZE
];
730 if (ctrlBlk
->sel3
== NULL
)
733 getSizePart(font
, buff
, ctrlBlk
->showSizeInPixels
);
734 if (strcmp(buff
, ctrlBlk
->sel3
) == 0)
741 /* returns TRUE if the font portion of the font matches the currently
744 static int fontMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
746 char buff
[TEMP_BUF_SIZE
];
748 if (ctrlBlk
->sel1
== NULL
)
751 getFontPart(font
, buff
);
752 if (strcmp(buff
, ctrlBlk
->sel1
) == 0)
759 /* inserts a string into correct sorted position in a list */
761 static void addItemToList(char **buf
, const char *item
, int *count
)
765 if (*count
== MAX_ENTRIES_IN_LIST
)
767 fprintf(stderr
, "Trying to add more than MAX_ENTRIES_IN_LIST ");
768 fprintf(stderr
, "(%d) entries to array\n", MAX_ENTRIES_IN_LIST
);
772 for (i
= 0; i
< *count
; i
++)
774 if (strcmp(buf
[i
], item
) == 0)
776 if (strcmp(buf
[i
], item
) > 0)
780 for (j
= *count
; j
> i
; j
--)
782 buf
[i
] = XtMalloc(strlen(item
) + 1);
783 strcpy(buf
[i
], item
);
788 /* given a font name this function returns the part used in the first
791 static void getFontPart(const char *font
, char *buff1
)
793 char buff2
[TEMP_BUF_SIZE
], buff3
[TEMP_BUF_SIZE
];
794 char buff4
[TEMP_BUF_SIZE
];
796 getStringComponent(font
, 2, buff1
);
797 getStringComponent(font
, 1, buff2
);
799 sprintf(buff3
, "%s (%s", buff1
, buff2
);
801 getStringComponent(font
, 13, buff1
);
802 getStringComponent(font
, 14, buff4
);
804 if (((strncmp(buff1
, "iso8859", 7) == 0) ||
805 (strncmp(buff1
, "ISO8859", 7) == 0)) && (strcmp(buff4
, "1") == 0))
806 sprintf(buff1
, "%s)", buff3
);
809 sprintf(buff2
, "%s, %s,", buff3
, buff1
);
810 sprintf(buff1
, "%s %s)", buff2
, buff4
);
815 /* given a font name this function returns the part used in the second
818 static void getStylePart(const char *font
, char *buff1
)
820 char buff2
[TEMP_BUF_SIZE
], buff3
[TEMP_BUF_SIZE
];
822 getStringComponent(font
, 3, buff3
);
823 getStringComponent(font
, 5, buff2
);
825 if ((strcmp(buff2
, "normal") != 0) && (strcmp(buff2
, "Normal") != 0) &&
826 (strcmp(buff2
, "NORMAL") != 0))
827 sprintf(buff1
, "%s %s", buff3
, buff2
);
829 strcpy(buff1
, buff3
);
831 getStringComponent(font
, 6, buff2
);
833 if (buff2
[0] != '\0')
834 sprintf(buff3
, "%s %s", buff1
, buff2
);
836 strcpy(buff3
, buff1
);
838 getStringComponent(font
, 4, buff2
);
840 if ((strcmp(buff2
, "o") == 0) || (strcmp(buff2
, "O") == 0))
841 sprintf(buff1
, "%s oblique", buff3
);
842 else if ((strcmp(buff2
, "i") == 0) || (strcmp(buff2
, "I") == 0))
843 sprintf(buff1
, "%s italic", buff3
);
845 if (strcmp(buff1
, " ") == 0)
850 /* given a font name this function returns the part used in the third
853 static void getSizePart(const char *font
, char *buff1
, int inPixels
)
859 getStringComponent(font
, 7, buff1
);
861 sprintf(buff1
, "%2d", size
);
867 getStringComponent(font
, 8, buff1
);
869 temp
= (double)size
/ 10.0;
870 if (buff1
[strlen(buff1
) - 1] == '0')
872 size
= (int)floor(temp
+0.5);
873 sprintf(buff1
, "%2d", size
);
876 sprintf(buff1
, "%4.1f", temp
);
881 /* Call back functions start from here - suffix Action in the function name
882 is for the callback function for the corresponding widget */
884 static void propFontToggleAction(Widget widget
,
885 xfselControlBlkType
*ctrlBlk
,
886 XmToggleButtonCallbackStruct
*call_data
)
888 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
890 if (ctrlBlk
->showPropFonts
== PREF_FIXED
)
891 ctrlBlk
->showPropFonts
= PREF_PROP
;
893 ctrlBlk
->showPropFonts
= PREF_FIXED
;
895 if (ctrlBlk
->sel1
!= NULL
)
896 XtFree(ctrlBlk
->sel1
);
897 ctrlBlk
->sel1
= NULL
;
899 if (ctrlBlk
->sel2
!= NULL
)
900 XtFree(ctrlBlk
->sel2
);
901 ctrlBlk
->sel2
= NULL
;
903 if (ctrlBlk
->sel3
!= NULL
)
904 XtFree(ctrlBlk
->sel3
);
905 ctrlBlk
->sel3
= NULL
;
907 setupScrollLists(NONE
, *ctrlBlk
);
909 XmTextSetString(ctrlBlk
->fontNameField
, "");
910 enableSample(ctrlBlk
, False
, NULL
);
915 static void sizeToggleAction(Widget widget
,
916 xfselControlBlkType
*ctrlBlk
,
917 XmToggleButtonCallbackStruct
*call_data
)
919 int i
, makeSelection
;
923 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
925 makeSelection
= (ctrlBlk
->sel3
!= NULL
);
927 for (i
= 0; (makeSelection
) && (i
< ctrlBlk
->numFonts
); i
++)
928 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
929 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
930 (sizeMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])))
932 getSizePart(ctrlBlk
->fontData
[i
], newSize
,
933 !ctrlBlk
->showSizeInPixels
);
937 if (ctrlBlk
->showSizeInPixels
)
938 ctrlBlk
->showSizeInPixels
= FALSE
;
940 ctrlBlk
->showSizeInPixels
= TRUE
;
942 if (ctrlBlk
->sel3
!= NULL
)
943 XtFree(ctrlBlk
->sel3
);
945 ctrlBlk
->sel3
= NULL
;
946 setupScrollLists(NONE
, *ctrlBlk
);
950 str
= XmStringCreate(newSize
, XmSTRING_DEFAULT_CHARSET
);
951 XmListSelectItem(ctrlBlk
->sizeList
, str
, TRUE
);
952 XmListSetBottomItem(ctrlBlk
->sizeList
, str
);
959 static void enableSample(xfselControlBlkType
*ctrlBlk
, Bool turn_on
,
960 XmFontList
*fontList
)
965 XtSetArg(args
[n
], XmNeditable
, turn_on
); n
++;
966 XtSetArg(args
[n
], XmNcursorPositionVisible
, turn_on
); n
++;
969 fprintf(stderr
, "nedit: Internal error in fontsel.c, line %i\n", \
972 XtSetArg(args
[n
], XmNfontList
, *fontList
); n
++;
974 XtSetArg(args
[n
], XmNforeground
, ctrlBlk
->sampleFG
); n
++;
976 XtSetArg(args
[n
], XmNforeground
, ctrlBlk
->sampleBG
); n
++;
978 XtSetValues(ctrlBlk
->dispField
, args
, n
);
979 /* Make sure the sample area gets resized if the font size changes */
980 XtUnmanageChild(ctrlBlk
->dispField
);
981 XtManageChild(ctrlBlk
->dispField
);
985 static void fontAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
986 XmListCallbackStruct
*call_data
)
990 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
992 if (ctrlBlk
->sel1
== NULL
)
994 ctrlBlk
->sel1
= XtMalloc(strlen(sel
) + 1);
995 strcpy(ctrlBlk
->sel1
, sel
);
999 if (strcmp(ctrlBlk
->sel1
, sel
) == 0)
1000 { /* Unselecting current selection */
1001 XtFree(ctrlBlk
->sel1
);
1002 ctrlBlk
->sel1
= NULL
;
1003 XmListDeselectItem(widget
, call_data
->item
);
1007 XtFree(ctrlBlk
->sel1
);
1008 ctrlBlk
->sel1
= XtMalloc(strlen(sel
) + 1);
1009 strcpy(ctrlBlk
->sel1
, sel
);
1014 setupScrollLists(FONT
, *ctrlBlk
);
1015 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1016 (ctrlBlk
->sel3
!= NULL
))
1017 choiceMade(ctrlBlk
);
1020 enableSample(ctrlBlk
, False
, NULL
);
1021 XmTextSetString(ctrlBlk
->fontNameField
, "");
1026 static void styleAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1027 XmListCallbackStruct
*call_data
)
1031 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
1033 if (ctrlBlk
->sel2
== NULL
)
1035 ctrlBlk
->sel2
= XtMalloc(strlen(sel
) + 1);
1036 strcpy(ctrlBlk
->sel2
, sel
);
1040 if (strcmp(ctrlBlk
->sel2
, sel
) == 0)
1041 { /* unselecting current selection */
1042 XtFree(ctrlBlk
->sel2
);
1043 ctrlBlk
->sel2
= NULL
;
1044 XmListDeselectItem(widget
, call_data
->item
);
1048 XtFree(ctrlBlk
->sel2
);
1049 ctrlBlk
->sel2
= XtMalloc(strlen(sel
) + 1);
1050 strcpy(ctrlBlk
->sel2
, sel
);
1055 setupScrollLists(STYLE
, *ctrlBlk
);
1056 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1057 (ctrlBlk
->sel3
!= NULL
))
1058 choiceMade(ctrlBlk
);
1061 enableSample(ctrlBlk
, False
, NULL
);
1062 XmTextSetString(ctrlBlk
->fontNameField
, "");
1066 static void sizeAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1067 XmListCallbackStruct
*call_data
)
1071 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
1073 if (ctrlBlk
->sel3
== NULL
)
1075 ctrlBlk
->sel3
= XtMalloc(strlen(sel
) + 1);
1076 strcpy(ctrlBlk
->sel3
, sel
);
1080 if (strcmp(ctrlBlk
->sel3
, sel
) == 0)
1081 { /* unselecting current selection */
1082 XtFree(ctrlBlk
->sel3
);
1083 ctrlBlk
->sel3
= NULL
;
1084 XmListDeselectItem(widget
, call_data
->item
);
1088 XtFree(ctrlBlk
->sel3
);
1089 ctrlBlk
->sel3
= XtMalloc(strlen(sel
) + 1);
1090 strcpy(ctrlBlk
->sel3
, sel
);
1095 setupScrollLists(SIZE
, *ctrlBlk
);
1096 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1097 (ctrlBlk
->sel3
!= NULL
))
1098 choiceMade(ctrlBlk
);
1101 enableSample(ctrlBlk
, False
, NULL
);
1102 XmTextSetString(ctrlBlk
->fontNameField
, "");
1106 /* function called when all three choices have been made; sets up font
1107 name and displays sample font */
1109 static void choiceMade(xfselControlBlkType
*ctrlBlk
)
1113 if (ctrlBlk
->fontName
!= NULL
)
1114 XtFree(ctrlBlk
->fontName
);
1115 ctrlBlk
->fontName
= NULL
;
1117 for (i
= 0; i
< ctrlBlk
->numFonts
; i
++)
1119 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1120 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1121 (sizeMatch (ctrlBlk
, ctrlBlk
->fontData
[i
])))
1123 ctrlBlk
->fontName
= XtMalloc(
1124 strlen(ctrlBlk
->fontData
[i
]) + 1);
1125 strcpy(ctrlBlk
->fontName
, ctrlBlk
->fontData
[i
]);
1130 if (ctrlBlk
->fontName
!= NULL
)
1132 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1133 dispSample(ctrlBlk
);
1137 DialogF (DF_ERR
, ctrlBlk
->form
, 1, "Font Specification",
1138 "Invalid Font Specification", "Dismiss");
1143 /* loads selected font and displays sample text in that font */
1145 static void dispSample(xfselControlBlkType
*ctrlBlk
)
1148 XmFontList fontList
;
1151 display
= XtDisplay(ctrlBlk
->form
);
1152 font
= XLoadQueryFont(display
, ctrlBlk
->fontName
);
1153 fontList
= XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
1155 enableSample(ctrlBlk
, True
, &fontList
);
1157 if (ctrlBlk
->oldFont
!= NULL
)
1159 XFreeFont(display
, ctrlBlk
->oldFont
);
1160 XmFontListFree(ctrlBlk
->oldFontList
);
1162 ctrlBlk
->oldFont
= font
;
1163 ctrlBlk
->oldFontList
= fontList
;
1167 static void destroyCB(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1168 XmListCallbackStruct
*call_data
)
1170 /* Prevent double destruction of the font selection dialog */
1171 ctrlBlk
->destroyedFlag
= TRUE
;
1172 cancelAction(widget
, ctrlBlk
, call_data
);
1175 static void cancelAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1176 XmListCallbackStruct
*call_data
)
1178 if (ctrlBlk
->sel1
!= NULL
)
1179 XtFree(ctrlBlk
->sel1
);
1180 if (ctrlBlk
->sel2
!= NULL
)
1181 XtFree(ctrlBlk
->sel2
);
1182 if (ctrlBlk
->sel3
!= NULL
)
1183 XtFree(ctrlBlk
->sel3
);
1184 if (ctrlBlk
->fontName
!= NULL
)
1185 XtFree(ctrlBlk
->fontName
);
1187 ctrlBlk
->fontName
= NULL
;
1188 XFreeFontNames(ctrlBlk
->fontData
);
1190 ctrlBlk
->exitFlag
= TRUE
;
1194 static void okAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1195 XmPushButtonCallbackStruct
*call_data
)
1201 fontPattern
= XmTextGetString(ctrlBlk
->fontNameField
);
1202 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), fontPattern
, 1, &i
);
1203 XtFree(fontPattern
);
1207 DialogF (DF_ERR
, ctrlBlk
->okButton
, 1, "Font Specification",
1208 "Invalid Font Specification", "Dismiss");
1209 XFreeFontNames(fontName
);
1213 if (ctrlBlk
->fontName
!= NULL
)
1214 XtFree(ctrlBlk
->fontName
);
1215 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1216 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1218 if (ctrlBlk
->sel1
!= NULL
)
1219 XtFree(ctrlBlk
->sel1
);
1220 if (ctrlBlk
->sel2
!= NULL
)
1221 XtFree(ctrlBlk
->sel2
);
1222 if (ctrlBlk
->sel3
!= NULL
)
1223 XtFree(ctrlBlk
->sel3
);
1225 XFreeFontNames(fontName
);
1226 XFreeFontNames(ctrlBlk
->fontData
);
1228 ctrlBlk
->exitFlag
= TRUE
;
1233 /* if current font is passed as an argument then this function is
1234 invoked and sets up initial entries */
1236 static void startupFont(xfselControlBlkType
*ctrlBlk
, const char *font
)
1240 char part
[TEMP_BUF_SIZE
];
1243 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), font
, 1, &i
);
1246 { /* invalid font passed in at startup */
1247 XFreeFontNames(fontName
);
1251 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1252 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1254 getFontPart(fontName
[0], part
);
1255 XFreeFontNames(fontName
);
1256 str
= XmStringCreate(part
, XmSTRING_DEFAULT_CHARSET
);
1257 XmListSetBottomItem(ctrlBlk
->fontList
, str
);
1258 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1259 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1262 dispSample(ctrlBlk
);
1263 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1267 /* hacked code to move initial input focus to first scroll list and at the
1268 same time have the OK button as the default button */
1270 static void setFocus(Widget w
, xfselControlBlkType
*ctrlBlk
, XEvent
*event
,
1271 Boolean
*continueToDispatch
)
1276 *continueToDispatch
= TRUE
;
1279 XtSetArg(args
[n
], XmNdefaultButton
, ctrlBlk
->okButton
); n
++;
1280 XtSetValues(ctrlBlk
->form
, args
, n
);
1284 /* finds the name of the biggest font less than the given limit
1285 MAX_DISPLAY_SIZE used to set up the initial height of the display widget
1288 static void FindBigFont(xfselControlBlkType
*ctrlBlk
, char *bigFont
)
1290 int i
, maxSize
, ind
= -1, size
;
1293 for (i
= 0, maxSize
= 0; i
< ctrlBlk
->numFonts
; i
++)
1295 getStringComponent(ctrlBlk
->fontData
[i
], 7, sizeStr
);
1296 size
= atoi(sizeStr
);
1297 if ((size
> maxSize
) && (size
< MAX_DISPLAY_SIZE
))
1304 strcpy(bigFont
, ctrlBlk
->fontData
[ind
]);