More detail for Motif version, and change button labels on help browser to be more...
[nedit.git] / util / fontsel.c
blob91d695863991247d6d2e99ec27db55294a035a71
1 static const char CVSID[] = "$Id: fontsel.c,v 1.18 2002/06/26 23:39:21 slobasso Exp $";
2 /*******************************************************************************
3 * *
4 * fontsel.c -- Nirvana Font Selector *
5 * *
6 * Copyright (C) 1999 Mark Edel *
7 * *
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 *
11 * version. *
12 * *
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 *
16 * for more details. *
17 * *
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 *
21 * *
22 * Nirvana Text Editor *
23 * June 2, 1993 *
24 * *
25 * Written by Suresh Ravoor (assisted by Mark Edel) *
26 * *
27 *******************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 #include "../config.h"
31 #endif
33 #include "fontsel.h"
34 #include "misc.h"
35 #include "DialogF.h"
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <math.h>
42 #include <X11/Intrinsic.h>
43 #include <Xm/Xm.h>
44 #include <Xm/Form.h>
45 #include <Xm/PushB.h>
46 #include <Xm/List.h>
47 #include <Xm/Label.h>
48 #include <Xm/Text.h>
49 #include <Xm/ToggleB.h>
50 #include <Xm/MessageB.h>
51 #include <Xm/DialogS.h>
53 #ifdef HAVE_DEBUG_H
54 #include "../debug.h"
55 #endif
57 #define MAX_ARGS 20
58 #define MAX_NUM_FONTS 32767
59 #define MAX_FONT_NAME_LEN 256
60 #define MAX_ENTRIES_IN_LIST 5000
61 #define MAX_DISPLAY_SIZE 150
62 #define DELIM '-'
63 #define NUM_COMPONENTS_FONT_NAME 14
64 #define TEMP_BUF_SIZE 256
65 #define DISPLAY_HEIGHT 90
67 enum listSpecifier { NONE, FONT, STYLE, SIZE };
70 /* local data structures and types */
72 typedef struct
74 Widget form; /* widget id */
75 Widget okButton; /* widget id */
76 Widget cancelButton; /* widget id */
77 Widget fontList; /* widget id */
78 Widget styleList; /* widget id */
79 Widget sizeList; /* widget id */
80 Widget fontNameField; /* widget id */
81 Widget sizeToggle; /* widget id */
82 Widget propFontToggle; /* widget id */
83 Widget dispLabel; /* widget id */
84 char **fontData; /* font name info */
85 int numFonts; /* number of fonts */
86 char *sel1; /* selection from list 1 */
87 char *sel2; /* selection from list 2 */
88 char *sel3; /* selection from list 3 */
89 int showPropFonts; /* toggle state - show prop fonts */
90 int showSizeInPixels;/* toggle state - size in pixels */
91 char *fontName; /* current font name */
92 XFontStruct *oldFont; /* font data structure for dispSample */
93 XmFontList oldFontList; /* font data structure for dispSample */
94 int exitFlag; /* used for program exit control */
95 int destroyedFlag; /* used to prevent double destruction */
96 } xfselControlBlkType;
99 /* local function prototypes */
101 static void getStringComponent(const char *inStr, int pos, char *outStr);
102 static void setupScrollLists(int dontChange, xfselControlBlkType ctrlBlk);
103 static int notPropFont(const char *font);
104 static int styleMatch(xfselControlBlkType *ctrlBlk, const char *font);
105 static int sizeMatch(xfselControlBlkType *ctrlBlk, const char *font);
106 static int fontMatch(xfselControlBlkType *ctrlBlk, const char *font);
107 static void addItemToList(char **buf, const char *item, int *count);
108 static void getFontPart(const char *font, char *buff1);
109 static void getStylePart(const char *font, char *buff1);
110 static void getSizePart(const char *font, char *buff1, int inPixels);
111 static void propFontToggleAction(Widget widget,
112 xfselControlBlkType *ctrlBlk,
113 XmToggleButtonCallbackStruct *call_data);
114 static void sizeToggleAction(Widget widget,
115 xfselControlBlkType *ctrlBlk,
116 XmToggleButtonCallbackStruct *call_data);
117 static void fontAction(Widget widget, xfselControlBlkType *ctrlBlk,
118 XmListCallbackStruct *call_data);
119 static void styleAction(Widget widget, xfselControlBlkType *ctrlBlk,
120 XmListCallbackStruct *call_data);
121 static void sizeAction(Widget widget, xfselControlBlkType *ctrlBlk,
122 XmListCallbackStruct *call_data);
123 static void choiceMade(xfselControlBlkType *ctrlBlk);
124 static void dispSample(xfselControlBlkType *ctrlBlk);
125 static void destroyCB(Widget widget, xfselControlBlkType *ctrlBlk,
126 XmListCallbackStruct *call_data);
127 static void cancelAction(Widget widget, xfselControlBlkType *ctrlBlk,
128 XmListCallbackStruct *call_data);
129 static void okAction(Widget widget, xfselControlBlkType *ctrlBlk,
130 XmPushButtonCallbackStruct *call_data);
131 static void startupFont(xfselControlBlkType *ctrlBlk, const char *font);
132 static void setFocus(Widget w, xfselControlBlkType *ctrlBlk, XEvent *event,
133 Boolean *continueToDispatch);
134 static void FindBigFont(xfselControlBlkType *ctrlBlk, char *bigFont);
136 /*******************************************************************************
138 * FontSel () *
141 * Function to put up a modal font selection dialog box. The purpose *
142 * of this routine is to allow the user to interactively view sample *
143 * fonts and to choose a font for current use. *
145 * Arguments: *
147 * Widget parent - parent widget ID *
149 * int showPropFont - ONLY_FIXED : shows only fixed fonts *
150 * doesn't show prop font *
151 * toggle button also. *
152 * PREF_FIXED : can select either fixed *
153 * or proportional fonts; *
154 * but starting option is *
155 * Fixed fonts. *
156 * PREF_PROP : can select either fixed *
157 * or proportional fonts; *
158 * but starting option is *
159 * proportional fonts. *
161 * char * currFont - ASCII string that contains the name *
162 * of the currently selected font. *
164 * Returns: *
166 * pointer to an ASCII character string that contains the name of *
167 * the selected font (in X format for naming fonts); it is the users *
168 * responsibility to free the space allocated to this string. *
170 * Comments: *
172 * The calling function has to call the appropriate routines to set *
173 * the current font to the one represented by the returned string. *
175 *******************************************************************************/
177 char *FontSel(Widget parent, int showPropFonts, const char *currFont)
179 Widget dialog, form, okButton, cancelButton;
180 Widget styleList, sizeList, fontName, fontList;
181 Widget sizeToggle, propFontToggle = NULL, dispLabel;
182 Widget nameLabel;
183 Arg args[MAX_ARGS];
184 int n;
185 XmString tempStr;
186 char bigFont[MAX_FONT_NAME_LEN];
187 xfselControlBlkType ctrlBlk;
188 Display *theDisplay;
190 ctrlBlk.fontData = XListFonts(XtDisplay(parent),
191 "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
192 MAX_NUM_FONTS, &ctrlBlk.numFonts);
193 FindBigFont(&ctrlBlk, bigFont);
194 ctrlBlk.oldFont = XLoadQueryFont(XtDisplay(parent), bigFont);
195 ctrlBlk.oldFontList = XmFontListCreate(ctrlBlk.oldFont,
196 XmSTRING_DEFAULT_CHARSET);
198 dialog = CreateDialogShell(parent, "Font Selector", args, 0);
200 /* Set up window sizes for form widget */
202 n = 0;
203 XtSetArg(args[n], XmNautoUnmanage, FALSE); n++;
204 XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
206 /* Create form popup dialog widget */
208 form = XtCreateWidget ("Font Selector", xmFormWidgetClass, dialog,
209 args, n);
211 /* Create pushbutton widgets */
213 n = 0;
214 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
215 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
216 XtSetArg(args[n], XmNbottomOffset, 4); n++;
217 XtSetArg(args[n], XmNtopOffset, 1); n++;
218 XtSetArg(args[n], XmNrightPosition, 45); n++;
219 XtSetArg(args[n], XmNwidth, 110); n++;
220 XtSetArg(args[n], XmNheight, 28); n++;
221 XtSetArg(args[n], XmNshowAsDefault, TRUE); n++;
222 okButton = XtCreateManagedWidget("OK", xmPushButtonWidgetClass, form,
223 args, n);
225 n = 0;
226 XtSetArg(args[n], XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
227 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
228 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
229 XtSetArg(args[n], XmNtopWidget, okButton); n++;
230 XtSetArg(args[n], XmNbottomWidget, okButton); n++;
231 XtSetArg(args[n], XmNleftPosition, 55); n++;
232 XtSetArg(args[n], XmNwidth, 110); n++;
233 XtSetArg(args[n], XmNheight, 28); n++;
234 cancelButton = XtCreateManagedWidget("Cancel", xmPushButtonWidgetClass,
235 form, args, n);
237 /* create font name text widget and the corresponding label */
239 n = 0;
240 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
241 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
242 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
243 XtSetArg(args[n], XmNbottomWidget, okButton); n++;
244 XtSetArg(args[n], XmNleftPosition, 1); n++;
245 XtSetArg(args[n], XmNrightPosition, 99); n++;
246 XtSetArg(args[n], XmNeditable, True); n++;
247 XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
248 XtSetArg(args[n], XmNmaxLength, MAX_FONT_NAME_LEN); n++;
249 fontName = XtCreateManagedWidget("fontname", xmTextWidgetClass, form,
250 args, n);
251 RemapDeleteKey(fontName); /* kludge to handle delete and BS */
253 n = 0;
254 tempStr = XmStringCreate("Font Name:", XmSTRING_DEFAULT_CHARSET);
255 XtSetArg(args[n], XmNlabelString, tempStr); n++;
256 XtSetArg(args[n], XmNmnemonic, 'N'); n++;
257 XtSetArg(args[n], XmNuserData, fontName); n++;
258 XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
259 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
260 XtSetArg(args[n], XmNleftWidget, fontName); n++;
261 XtSetArg(args[n], XmNbottomWidget, fontName); n++;
262 XtSetArg(args[n], XmNtopOffset, 1); n++;
263 nameLabel = XtCreateManagedWidget("Font Name:", xmLabelWidgetClass,
264 form, args, n);
265 XmStringFree(tempStr);
267 /* create sample display label widget */
269 n = 0;
270 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
271 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
272 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
273 XtSetArg(args[n], XmNrightPosition, 99); n++;
274 XtSetArg(args[n], XmNbottomWidget, nameLabel); n++;
275 XtSetArg(args[n], XmNleftPosition, 1); n++;
276 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
277 XtSetArg(args[n], XmNrecomputeSize, FALSE); n++;
278 XtSetArg(args[n], XmNfontList, ctrlBlk.oldFontList); n++;
279 dispLabel = XtCreateManagedWidget(" ", xmLabelWidgetClass, form,
280 args, n);
282 /* create toggle buttons */
284 n = 0;
285 tempStr = XmStringCreate("Show Size in Points",
286 XmSTRING_DEFAULT_CHARSET);
287 XtSetArg(args[n], XmNlabelString, tempStr); n++;
288 XtSetArg(args[n], XmNmnemonic, 'P'); n++;
289 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
290 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
291 XtSetArg(args[n], XmNleftPosition, 2); n++;
292 XtSetArg(args[n], XmNtopOffset, 1); n++;
293 XtSetArg(args[n], XmNbottomWidget, dispLabel); n++;
294 sizeToggle = XtCreateManagedWidget("sizetoggle",
295 xmToggleButtonWidgetClass, form, args, n);
296 XmStringFree(tempStr);
298 if (showPropFonts != ONLY_FIXED)
300 n = 0;
301 tempStr = XmStringCreate("Show Proportional Width Fonts",
302 XmSTRING_DEFAULT_CHARSET);
303 XtSetArg(args[n], XmNlabelString, tempStr); n++;
304 XtSetArg(args[n], XmNmnemonic, 'W'); n++;
305 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
306 XtSetArg(args[n], XmNtopAttachment,
307 XmATTACH_OPPOSITE_WIDGET); n++;
308 XtSetArg(args[n], XmNbottomAttachment,
309 XmATTACH_OPPOSITE_WIDGET); n++;
310 XtSetArg(args[n], XmNrightPosition, 98); n++;
311 XtSetArg(args[n], XmNtopWidget, sizeToggle); n++;
312 XtSetArg(args[n], XmNbottomWidget, sizeToggle); n++;
313 XtSetArg(args[n], XmNtopOffset, 1); n++;
314 propFontToggle = XtCreateManagedWidget("propfonttoggle",
315 xmToggleButtonWidgetClass, form, args, n);
316 XmStringFree(tempStr);
319 /* create scroll list widgets */
320 /* "Font" list */
322 n = 0;
323 tempStr = XmStringCreate("Font:", XmSTRING_DEFAULT_CHARSET);
324 XtSetArg(args[n], XmNlabelString, tempStr); n++;
325 XtSetArg(args[n], XmNmnemonic, 'F'); n++;
326 XtSetArg(args[n], XmNtopOffset, 2); n++;
327 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
328 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
329 XtSetArg(args[n], XmNleftPosition, 1); n++;
330 nameLabel = XtCreateManagedWidget("Font:", xmLabelWidgetClass, form,
331 args, n);
332 XmStringFree(tempStr);
334 n = 0;
335 XtSetArg(args[n], XmNvisibleItemCount, 15); n++;
336 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
337 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
338 XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
339 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
340 XtSetArg(args[n], XmNbottomWidget, sizeToggle); n++;
341 XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
342 XtSetArg(args[n], XmNleftWidget, nameLabel); n++;
343 XtSetArg(args[n], XmNrightPosition, 52); n++;
344 fontList = XmCreateScrolledList(form, "fontlist", args, n);
345 XtManageChild(fontList);
346 XtVaSetValues(nameLabel, XmNuserData, fontList, NULL);
348 /* "Style" list */
350 n = 0;
351 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
352 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
353 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
354 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
355 XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
356 XtSetArg(args[n], XmNleftOffset, 5); n++;
357 XtSetArg(args[n], XmNleftWidget, XtParent(fontList)); n++;
358 XtSetArg(args[n], XmNbottomWidget, XtParent(fontList)); n++;
359 XtSetArg(args[n], XmNrightPosition, 85); n++;
360 styleList = XmCreateScrolledList(form, "stylelist", args, n);
361 XtManageChild(styleList);
363 n = 0;
364 tempStr = XmStringCreate("Style:", XmSTRING_DEFAULT_CHARSET);
365 XtSetArg(args[n], XmNmnemonic, 'y'); n++;
366 XtSetArg(args[n], XmNuserData, styleList); n++;
367 XtSetArg(args[n], XmNlabelString, tempStr); n++;
368 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
369 XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
370 XtSetArg(args[n], XmNbottomWidget, XtParent(styleList)); n++;
371 XtSetArg(args[n], XmNleftWidget, XtParent(styleList)); n++;
372 XtCreateManagedWidget("Style:", xmLabelWidgetClass, form, args, n);
373 XmStringFree(tempStr);
375 /* "Size" list */
377 n = 0;
378 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
379 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
380 XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
381 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
382 XtSetArg(args[n], XmNtopWidget, nameLabel); n++;
383 XtSetArg(args[n], XmNleftWidget, XtParent(styleList)); n++;
384 XtSetArg(args[n], XmNbottomWidget, XtParent(fontList)); n++;
385 XtSetArg(args[n], XmNleftOffset, 5); n++;
386 XtSetArg(args[n], XmNrightPosition, 99); n++;
387 sizeList = XmCreateScrolledList(form, "sizelist", args, n);
388 XtManageChild(sizeList);
390 n = 0;
391 tempStr = XmStringCreate("Size:", XmSTRING_DEFAULT_CHARSET);
392 XtSetArg(args[n], XmNlabelString, tempStr); n++;
393 XtSetArg(args[n], XmNmnemonic, 'z'); n++;
394 XtSetArg(args[n], XmNuserData, sizeList); n++;
395 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
396 XtSetArg(args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
397 XtSetArg(args[n], XmNbottomWidget, XtParent(sizeList)); n++;
398 XtSetArg(args[n], XmNleftWidget, XtParent(sizeList)); n++;
399 XtCreateManagedWidget("Size:", xmLabelWidgetClass, form, args, n);
400 XmStringFree(tempStr);
402 /* update form widgets cancel button */
404 n = 0;
405 XtSetArg(args[n], XmNcancelButton, cancelButton); n++;
406 XtSetValues(form, args, n);
409 /* update application's control block structure */
411 ctrlBlk.form = form;
412 ctrlBlk.okButton = okButton;
413 ctrlBlk.cancelButton = cancelButton;
414 ctrlBlk.fontList = fontList;
415 ctrlBlk.styleList = styleList;
416 ctrlBlk.sizeList = sizeList;
417 ctrlBlk.fontNameField = fontName;
418 ctrlBlk.sizeToggle = sizeToggle;
419 if (showPropFonts != ONLY_FIXED)
420 ctrlBlk.propFontToggle = propFontToggle;
421 ctrlBlk.dispLabel = dispLabel;
422 ctrlBlk.exitFlag = FALSE;
423 ctrlBlk.destroyedFlag = FALSE;
424 ctrlBlk.showPropFonts = showPropFonts;
425 ctrlBlk.showSizeInPixels= TRUE;
426 ctrlBlk.sel1 = NULL;
427 ctrlBlk.sel2 = NULL;
428 ctrlBlk.sel3 = NULL;
429 ctrlBlk.fontName = NULL;
431 setupScrollLists(NONE, ctrlBlk); /* update scroll lists */
433 if (showPropFonts == PREF_PROP)
434 XmToggleButtonSetState(propFontToggle, TRUE, FALSE);
436 /* Register callback functions */
438 if (showPropFonts != ONLY_FIXED)
439 XtAddCallback(propFontToggle, XmNvalueChangedCallback,
440 (XtCallbackProc)propFontToggleAction, (char *)&ctrlBlk);
441 XtAddCallback(sizeToggle, XmNvalueChangedCallback,
442 (XtCallbackProc)sizeToggleAction, (char *)&ctrlBlk);
443 XtAddCallback(fontList, XmNbrowseSelectionCallback,
444 (XtCallbackProc)fontAction, (char *)&ctrlBlk);
445 XtAddCallback(styleList, XmNbrowseSelectionCallback,
446 (XtCallbackProc)styleAction, (char *)&ctrlBlk);
447 XtAddCallback(sizeList, XmNbrowseSelectionCallback,
448 (XtCallbackProc)sizeAction, (char *)&ctrlBlk);
449 XtAddCallback(okButton, XmNactivateCallback,
450 (XtCallbackProc)okAction, (char *)&ctrlBlk);
451 XtAddCallback(cancelButton, XmNactivateCallback,
452 (XtCallbackProc)cancelAction, (char *)&ctrlBlk);
454 /* add event handler to setup input focus at start to scroll list */
456 XtAddEventHandler(fontList, FocusChangeMask, FALSE,
457 (XtEventHandler)setFocus, (char *)&ctrlBlk);
458 XmProcessTraversal(fontList, XmTRAVERSE_CURRENT);
460 /* setup tabgroups */
462 XmAddTabGroup(fontList);
463 XmAddTabGroup(styleList);
464 XmAddTabGroup(sizeList);
465 XmAddTabGroup(sizeToggle);
466 if (showPropFonts != ONLY_FIXED)
467 XmAddTabGroup(propFontToggle);
468 XmAddTabGroup(fontName);
469 XmAddTabGroup(okButton);
470 XmAddTabGroup(cancelButton);
472 /* Make sure that we don't try to access the dialog if the user
473 destroyed it (possibly indirectly, by destroying the parent). */
474 XtAddCallback(dialog, XmNdestroyCallback,
475 (XtCallbackProc)destroyCB, (char *)&ctrlBlk);
477 /* Link Motif Close option to cancel action */
479 AddMotifCloseCallback(dialog, (XtCallbackProc)cancelAction, &ctrlBlk);
481 /* Handle dialog mnemonics */
483 AddDialogMnemonicHandler(form, FALSE);
485 /* Realize Widgets */
487 ManageDialogCenteredOnPointer(form);
489 /* set up current font parameters */
491 if (currFont[0] != '\0')
492 startupFont(&ctrlBlk, currFont);
494 /* Make sure that we can still access the display in case the form
495 gets destroyed */
496 theDisplay = XtDisplay(form);
498 /* enter event loop */
500 while (! ctrlBlk.exitFlag && ! ctrlBlk.destroyedFlag)
501 XtAppProcessEvent(XtWidgetToApplicationContext(form), XtIMAll);
503 if (! ctrlBlk.destroyedFlag) {
504 /* Don't let the callback destroy the font name */
505 XtRemoveCallback(dialog, XmNdestroyCallback,
506 (XtCallbackProc)destroyCB, (char *)&ctrlBlk);
507 XtDestroyWidget(dialog);
510 if (ctrlBlk.oldFont != NULL)
512 XFreeFont(theDisplay, ctrlBlk.oldFont);
513 XmFontListFree(ctrlBlk.oldFontList);
516 return(ctrlBlk.fontName);
520 /* gets a specific substring from a string */
522 static void getStringComponent(const char *inStr, int pos, char *outStr)
524 int i, j;
526 *outStr = '\0';
528 if (pos > NUM_COMPONENTS_FONT_NAME)
530 fprintf(stderr, "Warning: getStringComponent being used for ");
531 fprintf(stderr, "pos > %d\nIf such ", NUM_COMPONENTS_FONT_NAME);
532 fprintf(stderr, "use is intended remove these warning lines\n");
535 for (i = 0; (pos > 0) && (inStr[i] != '\0'); i++)
536 if (inStr[i] == DELIM)
537 pos--;
539 if (inStr[i] == '\0')
540 return;
542 for (j = 0; (inStr[i] != DELIM) && (inStr[i] != '\0'); i++, j++)
543 outStr[j] = inStr[i];
544 outStr[j] = '\0';
548 /* parse through the fontlist data and set up the three scroll lists */
550 static void setupScrollLists(int dontChange, xfselControlBlkType ctrlBlk)
552 char *itemBuf1[MAX_ENTRIES_IN_LIST];
553 char *itemBuf2[MAX_ENTRIES_IN_LIST];
554 char *itemBuf3[MAX_ENTRIES_IN_LIST];
555 int itemCount1, itemCount2, itemCount3;
556 char buff1[TEMP_BUF_SIZE];
557 XmString items[MAX_ENTRIES_IN_LIST];
558 int i;
560 itemCount1 = 0;
561 itemCount2 = 0;
562 itemCount3 = 0;
564 for (i = 0; i < ctrlBlk.numFonts && i < MAX_ENTRIES_IN_LIST; i++)
566 if ((dontChange != FONT) &&
567 (styleMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
568 (sizeMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
569 ((ctrlBlk.showPropFonts == PREF_PROP) ||
570 (notPropFont(ctrlBlk.fontData[i]))))
572 getFontPart(ctrlBlk.fontData[i], buff1);
573 addItemToList(itemBuf1, buff1, &itemCount1);
576 if ((dontChange != STYLE) &&
577 (fontMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
578 (sizeMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
579 ((ctrlBlk.showPropFonts == PREF_PROP) ||
580 (notPropFont(ctrlBlk.fontData[i]))))
582 getStylePart(ctrlBlk.fontData[i], buff1);
583 addItemToList(itemBuf2, buff1, &itemCount2);
586 if ((dontChange != SIZE) &&
587 (fontMatch(&ctrlBlk, ctrlBlk.fontData[i])) &&
588 (styleMatch (&ctrlBlk, ctrlBlk.fontData[i])) &&
589 ((ctrlBlk.showPropFonts == PREF_PROP) ||
590 (notPropFont(ctrlBlk.fontData[i]))))
592 getSizePart(ctrlBlk.fontData[i], buff1,
593 ctrlBlk.showSizeInPixels);
594 addItemToList(itemBuf3, buff1, &itemCount3);
596 } /* end - for (i = 0; i < ctrlBlk.numFonts; i++) */
598 /* recreate all three scroll lists where necessary */
599 if (dontChange != FONT)
601 for (i = 0; i < itemCount1; i++)
603 items[i] = XmStringCreate(itemBuf1[i],
604 XmSTRING_DEFAULT_CHARSET);
605 XtFree(itemBuf1[i]);
607 XmListDeleteAllItems(ctrlBlk.fontList);
608 XmListAddItems(ctrlBlk.fontList, items, itemCount1, 1);
609 if (ctrlBlk.sel1 != NULL)
611 XmStringFree(items[0]);
612 items[0] = XmStringCreate(ctrlBlk.sel1,
613 XmSTRING_DEFAULT_CHARSET);
614 XmListSelectItem(ctrlBlk.fontList, items[0], FALSE);
615 XmListSetBottomItem(ctrlBlk.fontList, items[0]);
617 for (i = 0; i < itemCount1; i++)
618 XmStringFree(items[i]);
621 if (dontChange != STYLE)
623 for (i = 0; i < itemCount2; i++)
625 items[i] = XmStringCreate(itemBuf2[i],
626 XmSTRING_DEFAULT_CHARSET);
627 XtFree(itemBuf2[i]);
629 XmListDeleteAllItems(ctrlBlk.styleList);
630 XmListAddItems(ctrlBlk.styleList, items, itemCount2, 1);
631 if (ctrlBlk.sel2 != NULL)
633 XmStringFree(items[0]);
634 items[0] = XmStringCreate(ctrlBlk.sel2,
635 XmSTRING_DEFAULT_CHARSET);
636 XmListSelectItem(ctrlBlk.styleList, items[0], FALSE);
637 XmListSetBottomItem(ctrlBlk.styleList, items[0]);
639 for (i = 0; i < itemCount2; i++)
640 XmStringFree(items[i]);
643 if (dontChange != SIZE)
645 for (i = 0; i < itemCount3; i++)
647 items[i] = XmStringCreate(itemBuf3[i],
648 XmSTRING_DEFAULT_CHARSET);
649 XtFree(itemBuf3[i]);
651 XmListDeleteAllItems(ctrlBlk.sizeList);
652 XmListAddItems(ctrlBlk.sizeList, items, itemCount3, 1);
653 if (ctrlBlk.sel3 != NULL)
655 XmStringFree(items[0]);
656 items[0] = XmStringCreate(ctrlBlk.sel3,
657 XmSTRING_DEFAULT_CHARSET);
658 XmListSelectItem(ctrlBlk.sizeList, items[0], FALSE);
659 XmListSetBottomItem(ctrlBlk.sizeList, items[0]);
661 for (i = 0; i < itemCount3; i++)
662 XmStringFree(items[i]);
667 /* returns TRUE if argument is not name of a proportional font */
669 static int notPropFont(const char *font)
671 char buff1[TEMP_BUF_SIZE];
673 getStringComponent(font, 11, buff1);
674 if ((strcmp(buff1, "p") == 0) || (strcmp(buff1, "P") == 0))
675 return(FALSE);
676 else
677 return(TRUE);
681 /* returns TRUE if the style portion of the font matches the currently
682 selected style */
684 static int styleMatch(xfselControlBlkType *ctrlBlk, const char *font)
686 char buff[TEMP_BUF_SIZE];
688 if (ctrlBlk->sel2 == NULL)
689 return(TRUE);
691 getStylePart(font, buff);
693 if (strcmp(buff, ctrlBlk->sel2) == 0)
694 return(TRUE);
695 else
696 return(FALSE);
700 /* returns TRUE if the size portion of the font matches the currently
701 selected size */
703 static int sizeMatch(xfselControlBlkType *ctrlBlk, const char *font)
705 char buff[TEMP_BUF_SIZE];
707 if (ctrlBlk->sel3 == NULL)
708 return(TRUE);
710 getSizePart(font, buff, ctrlBlk->showSizeInPixels);
711 if (strcmp(buff, ctrlBlk->sel3) == 0)
712 return(TRUE);
713 else
714 return(FALSE);
718 /* returns TRUE if the font portion of the font matches the currently
719 selected font */
721 static int fontMatch(xfselControlBlkType *ctrlBlk, const char *font)
723 char buff[TEMP_BUF_SIZE];
725 if (ctrlBlk->sel1 == NULL)
726 return(TRUE);
728 getFontPart(font, buff);
729 if (strcmp(buff, ctrlBlk->sel1) == 0)
730 return(TRUE);
731 else
732 return(FALSE);
736 /* inserts a string into correct sorted position in a list */
738 static void addItemToList(char **buf, const char *item, int *count)
740 int i, j;
742 if (*count == MAX_ENTRIES_IN_LIST)
744 fprintf(stderr, "Trying to add more than MAX_ENTRIES_IN_LIST ");
745 fprintf(stderr, "(%d) entries to array\n", MAX_ENTRIES_IN_LIST);
746 return;
749 for (i = 0; i < *count; i++)
751 if (strcmp(buf[i], item) == 0)
752 return;
753 if (strcmp(buf[i], item) > 0)
754 break;
757 for (j = *count; j > i; j--)
758 buf[j] = buf[j-1];
759 buf[i] = XtMalloc(strlen(item) + 1);
760 strcpy(buf[i], item);
761 (*count)++;
765 /* given a font name this function returns the part used in the first
766 scroll list */
768 static void getFontPart(const char *font, char *buff1)
770 char buff2[TEMP_BUF_SIZE], buff3[TEMP_BUF_SIZE];
771 char buff4[TEMP_BUF_SIZE];
773 getStringComponent(font, 2, buff1);
774 getStringComponent(font, 1, buff2);
776 sprintf(buff3, "%s (%s", buff1, buff2);
778 getStringComponent(font, 13, buff1);
779 getStringComponent(font, 14, buff4);
781 if (((strncmp(buff1, "iso8859", 7) == 0) ||
782 (strncmp(buff1, "ISO8859", 7) == 0)) && (strcmp(buff4, "1") == 0))
783 sprintf(buff1, "%s)", buff3);
784 else
786 sprintf(buff2, "%s, %s,", buff3, buff1);
787 sprintf(buff1, "%s %s)", buff2, buff4);
792 /* given a font name this function returns the part used in the second
793 scroll list */
795 static void getStylePart(const char *font, char *buff1)
797 char buff2[TEMP_BUF_SIZE], buff3[TEMP_BUF_SIZE];
799 getStringComponent(font, 3, buff3);
800 getStringComponent(font, 5, buff2);
802 if ((strcmp(buff2, "normal") != 0) && (strcmp(buff2, "Normal") != 0) &&
803 (strcmp(buff2, "NORMAL") != 0))
804 sprintf(buff1, "%s %s", buff3, buff2);
805 else
806 strcpy(buff1, buff3);
808 getStringComponent(font, 6, buff2);
810 if (buff2[0] != '\0')
811 sprintf(buff3, "%s %s", buff1, buff2);
812 else
813 strcpy(buff3, buff1);
815 getStringComponent(font, 4, buff2);
817 if ((strcmp(buff2, "o") == 0) || (strcmp(buff2, "O") == 0))
818 sprintf(buff1, "%s oblique", buff3);
819 else if ((strcmp(buff2, "i") == 0) || (strcmp(buff2, "I") == 0))
820 sprintf(buff1, "%s italic", buff3);
822 if (strcmp(buff1, " ") == 0)
823 strcpy(buff1, "-");
827 /* given a font name this function returns the part used in the third
828 scroll list */
830 static void getSizePart(const char *font, char *buff1, int inPixels)
832 int size;
834 if (inPixels)
836 getStringComponent(font, 7, buff1);
837 size = atoi(buff1);
838 sprintf(buff1, "%2d", size);
840 else
842 double temp;
844 getStringComponent(font, 8, buff1);
845 size = atoi(buff1);
846 temp = (double)size / 10.0;
847 if (buff1[strlen(buff1) - 1] == '0')
849 size = (int)floor(temp+0.5);
850 sprintf(buff1, "%2d", size);
852 else
853 sprintf(buff1, "%4.1f", temp);
858 /* Call back functions start from here - suffix Action in the function name
859 is for the callback function for the corresponding widget */
861 static void propFontToggleAction(Widget widget,
862 xfselControlBlkType *ctrlBlk,
863 XmToggleButtonCallbackStruct *call_data)
865 int n;
866 Arg args[2];
867 XmString str;
869 if (call_data->reason == XmCR_VALUE_CHANGED)
871 if (ctrlBlk->showPropFonts == PREF_FIXED)
872 ctrlBlk->showPropFonts = PREF_PROP;
873 else
874 ctrlBlk->showPropFonts = PREF_FIXED;
876 if (ctrlBlk->sel1 != NULL)
877 XtFree(ctrlBlk->sel1);
878 ctrlBlk->sel1 = NULL;
880 if (ctrlBlk->sel2 != NULL)
881 XtFree(ctrlBlk->sel2);
882 ctrlBlk->sel2 = NULL;
884 if (ctrlBlk->sel3 != NULL)
885 XtFree(ctrlBlk->sel3);
886 ctrlBlk->sel3 = NULL;
888 setupScrollLists(NONE, *ctrlBlk);
890 n = 0;
891 str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
892 XtSetArg(args[n], XmNlabelString, str); n++;
893 XtSetValues(ctrlBlk->dispLabel, args, n);
894 XmTextSetString(ctrlBlk->fontNameField, "");
895 XmStringFree(str);
900 static void sizeToggleAction(Widget widget,
901 xfselControlBlkType *ctrlBlk,
902 XmToggleButtonCallbackStruct *call_data)
904 int i, makeSelection;
905 char newSize[10];
906 XmString str;
908 if (call_data->reason == XmCR_VALUE_CHANGED)
910 makeSelection = (ctrlBlk->sel3 != NULL);
912 for (i = 0; (makeSelection) && (i < ctrlBlk->numFonts); i++)
913 if ((fontMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
914 (styleMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
915 (sizeMatch(ctrlBlk, ctrlBlk->fontData[i])))
917 getSizePart(ctrlBlk->fontData[i], newSize,
918 !ctrlBlk->showSizeInPixels);
919 break;
922 if (ctrlBlk->showSizeInPixels)
923 ctrlBlk->showSizeInPixels = FALSE;
924 else
925 ctrlBlk->showSizeInPixels = TRUE;
927 if (ctrlBlk->sel3 != NULL)
928 XtFree(ctrlBlk->sel3);
930 ctrlBlk->sel3 = NULL;
931 setupScrollLists(NONE, *ctrlBlk);
933 if (makeSelection)
935 str = XmStringCreate(newSize, XmSTRING_DEFAULT_CHARSET);
936 XmListSelectItem(ctrlBlk->sizeList, str, TRUE);
937 XmListSetBottomItem(ctrlBlk->sizeList, str);
938 XmStringFree(str);
944 static void fontAction(Widget widget, xfselControlBlkType *ctrlBlk,
945 XmListCallbackStruct *call_data)
947 char *sel;
949 XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
951 if (ctrlBlk->sel1 == NULL)
953 ctrlBlk->sel1 = XtMalloc(strlen(sel) + 1);
954 strcpy(ctrlBlk->sel1, sel);
956 else
958 if (strcmp(ctrlBlk->sel1, sel) == 0)
959 { /* Unselecting current selection */
960 XtFree(ctrlBlk->sel1);
961 ctrlBlk->sel1 = NULL;
962 XmListDeselectItem(widget, call_data->item);
964 else
966 XtFree(ctrlBlk->sel1);
967 ctrlBlk->sel1 = XtMalloc(strlen(sel) + 1);
968 strcpy(ctrlBlk->sel1, sel);
972 XtFree(sel);
973 setupScrollLists(FONT, *ctrlBlk);
974 if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
975 (ctrlBlk->sel3 != NULL))
976 choiceMade(ctrlBlk);
977 else
979 int n;
980 XmString str;
981 Arg args[2];
983 n = 0;
984 str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
985 XtSetArg(args[n], XmNlabelString, str); n++;
986 XtSetValues(ctrlBlk->dispLabel, args, n);
987 XmTextSetString(ctrlBlk->fontNameField, "");
988 XmStringFree(str);
993 static void styleAction(Widget widget, xfselControlBlkType *ctrlBlk,
994 XmListCallbackStruct *call_data)
996 char *sel;
998 XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
1000 if (ctrlBlk->sel2 == NULL)
1002 ctrlBlk->sel2 = XtMalloc(strlen(sel) + 1);
1003 strcpy(ctrlBlk->sel2, sel);
1005 else
1007 if (strcmp(ctrlBlk->sel2, sel) == 0)
1008 { /* unselecting current selection */
1009 XtFree(ctrlBlk->sel2);
1010 ctrlBlk->sel2 = NULL;
1011 XmListDeselectItem(widget, call_data->item);
1013 else
1015 XtFree(ctrlBlk->sel2);
1016 ctrlBlk->sel2 = XtMalloc(strlen(sel) + 1);
1017 strcpy(ctrlBlk->sel2, sel);
1021 XtFree(sel);
1022 setupScrollLists(STYLE, *ctrlBlk);
1023 if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
1024 (ctrlBlk->sel3 != NULL))
1025 choiceMade(ctrlBlk);
1026 else
1028 int n;
1029 XmString str;
1030 Arg args[2];
1032 n = 0;
1033 str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
1034 XtSetArg(args[n], XmNlabelString, str); n++;
1035 XtSetValues(ctrlBlk->dispLabel, args, n);
1036 XmTextSetString(ctrlBlk->fontNameField, "");
1037 XmStringFree(str);
1042 static void sizeAction(Widget widget, xfselControlBlkType *ctrlBlk,
1043 XmListCallbackStruct *call_data)
1045 char *sel;
1047 XmStringGetLtoR(call_data->item, XmSTRING_DEFAULT_CHARSET, &sel);
1049 if (ctrlBlk->sel3 == NULL)
1051 ctrlBlk->sel3 = XtMalloc(strlen(sel) + 1);
1052 strcpy(ctrlBlk->sel3, sel);
1054 else
1056 if (strcmp(ctrlBlk->sel3, sel) == 0)
1057 { /* unselecting current selection */
1058 XtFree(ctrlBlk->sel3);
1059 ctrlBlk->sel3 = NULL;
1060 XmListDeselectItem(widget, call_data->item);
1062 else
1064 XtFree(ctrlBlk->sel3);
1065 ctrlBlk->sel3 = XtMalloc(strlen(sel) + 1);
1066 strcpy(ctrlBlk->sel3, sel);
1070 XtFree(sel);
1071 setupScrollLists(SIZE, *ctrlBlk);
1072 if ((ctrlBlk->sel1 != NULL) && (ctrlBlk->sel2 != NULL) &&
1073 (ctrlBlk->sel3 != NULL))
1074 choiceMade(ctrlBlk);
1075 else
1077 int n;
1078 XmString str;
1079 Arg args[2];
1081 n = 0;
1082 str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
1083 XtSetArg(args[n], XmNlabelString, str); n++;
1084 XtSetValues(ctrlBlk->dispLabel, args, n);
1085 XmTextSetString(ctrlBlk->fontNameField, "");
1086 XmStringFree(str);
1090 /* function called when all three choices have been made; sets up font
1091 name and displays sample font */
1093 static void choiceMade(xfselControlBlkType *ctrlBlk)
1095 int i;
1097 if (ctrlBlk->fontName != NULL)
1098 XtFree(ctrlBlk->fontName);
1099 ctrlBlk->fontName = NULL;
1101 for (i = 0; i < ctrlBlk->numFonts; i++)
1103 if ((fontMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
1104 (styleMatch(ctrlBlk, ctrlBlk->fontData[i])) &&
1105 (sizeMatch (ctrlBlk, ctrlBlk->fontData[i])))
1107 ctrlBlk->fontName = XtMalloc(
1108 strlen(ctrlBlk->fontData[i]) + 1);
1109 strcpy(ctrlBlk->fontName, ctrlBlk->fontData[i]);
1110 break;
1114 if (ctrlBlk->fontName != NULL)
1116 XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName);
1117 dispSample(ctrlBlk);
1119 else
1120 DialogF (DF_ERR, ctrlBlk->form, 1, "Invalid Font Specification",
1121 "Dismiss");
1125 /* loads selected font and displays sample text in that font */
1127 static void dispSample(xfselControlBlkType *ctrlBlk)
1129 Arg args[2];
1130 int n;
1131 XFontStruct *font;
1132 XmFontList fontList;
1133 Display *display;
1134 XmString dispStr;
1136 display = XtDisplay(ctrlBlk->form);
1137 font = XLoadQueryFont(display, ctrlBlk->fontName);
1138 fontList = XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);
1140 n = 0;
1141 dispStr = XmStringCreate(
1142 "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",
1143 XmSTRING_DEFAULT_CHARSET);
1144 XtSetArg(args[n], XmNlabelString, dispStr); n++;
1145 XtSetArg(args[n], XmNfontList, fontList); n++;
1147 XtSetValues(ctrlBlk->dispLabel, args, n);
1148 XmStringFree(dispStr);
1150 if (ctrlBlk->oldFont != NULL)
1152 XFreeFont(display, ctrlBlk->oldFont);
1153 XmFontListFree(ctrlBlk->oldFontList);
1155 ctrlBlk->oldFont = font;
1156 ctrlBlk->oldFontList = fontList;
1160 static void destroyCB(Widget widget, xfselControlBlkType *ctrlBlk,
1161 XmListCallbackStruct *call_data)
1163 /* Prevent double destruction of the font selection dialog */
1164 ctrlBlk->destroyedFlag = TRUE;
1165 cancelAction(widget, ctrlBlk, call_data);
1168 static void cancelAction(Widget widget, xfselControlBlkType *ctrlBlk,
1169 XmListCallbackStruct *call_data)
1171 if (ctrlBlk->sel1 != NULL)
1172 XtFree(ctrlBlk->sel1);
1173 if (ctrlBlk->sel2 != NULL)
1174 XtFree(ctrlBlk->sel2);
1175 if (ctrlBlk->sel3 != NULL)
1176 XtFree(ctrlBlk->sel3);
1177 if (ctrlBlk->fontName != NULL)
1178 XtFree(ctrlBlk->fontName);
1180 ctrlBlk->fontName = NULL;
1181 XFreeFontNames(ctrlBlk->fontData);
1183 ctrlBlk->exitFlag = TRUE;
1187 static void okAction(Widget widget, xfselControlBlkType *ctrlBlk,
1188 XmPushButtonCallbackStruct *call_data)
1190 char *fontPattern;
1191 char **fontName;
1192 int i;
1194 fontPattern = XmTextGetString(ctrlBlk->fontNameField);
1195 fontName = XListFonts(XtDisplay(ctrlBlk->form), fontPattern, 1, &i);
1196 XtFree(fontPattern);
1198 if (i != 1)
1200 DialogF (DF_ERR, ctrlBlk->okButton, 1,
1201 "Invalid Font Specification", "Dismiss");
1202 XFreeFontNames(fontName);
1204 else
1206 if (ctrlBlk->fontName != NULL)
1207 XtFree(ctrlBlk->fontName);
1208 ctrlBlk->fontName = XtMalloc(strlen(fontName[0]) + 1);
1209 strcpy(ctrlBlk->fontName, fontName[0]);
1211 if (ctrlBlk->sel1 != NULL)
1212 XtFree(ctrlBlk->sel1);
1213 if (ctrlBlk->sel2 != NULL)
1214 XtFree(ctrlBlk->sel2);
1215 if (ctrlBlk->sel3 != NULL)
1216 XtFree(ctrlBlk->sel3);
1218 XFreeFontNames(fontName);
1219 XFreeFontNames(ctrlBlk->fontData);
1221 ctrlBlk->exitFlag = TRUE;
1226 /* if current font is passed as an argument then this function is
1227 invoked and sets up initial entries */
1229 static void startupFont(xfselControlBlkType *ctrlBlk, const char *font)
1231 int i;
1232 char **fontName;
1233 char part[TEMP_BUF_SIZE];
1234 XmString str;
1236 fontName = XListFonts(XtDisplay(ctrlBlk->form), font, 1, &i);
1238 if (i == 0)
1239 { /* invalid font passed in at startup */
1240 XFreeFontNames(fontName);
1241 return;
1244 ctrlBlk->fontName = XtMalloc(strlen(fontName[0]) + 1);
1245 strcpy(ctrlBlk->fontName, fontName[0]);
1247 getFontPart(fontName[0], part);
1248 XFreeFontNames(fontName);
1249 str = XmStringCreate(part, XmSTRING_DEFAULT_CHARSET);
1250 XmListSetBottomItem(ctrlBlk->fontList, str);
1251 XmListSelectItem(ctrlBlk->fontList, str, TRUE);
1252 XmListSelectItem(ctrlBlk->fontList, str, TRUE);
1253 XmStringFree(str);
1255 dispSample(ctrlBlk);
1256 XmTextSetString(ctrlBlk->fontNameField, ctrlBlk->fontName);
1260 /* hacked code to move initial input focus to first scroll list and at the
1261 same time have the OK button as the default button */
1263 static void setFocus(Widget w, xfselControlBlkType *ctrlBlk, XEvent *event,
1264 Boolean *continueToDispatch)
1266 int n;
1267 Arg args[2];
1269 *continueToDispatch = TRUE;
1271 n = 0;
1272 XtSetArg(args[n], XmNdefaultButton, ctrlBlk->okButton); n++;
1273 XtSetValues(ctrlBlk->form, args, n);
1277 /* finds the name of the biggest font less than the given limit
1278 MAX_DISPLAY_SIZE used to set up the initial height of the display widget
1281 static void FindBigFont(xfselControlBlkType *ctrlBlk, char *bigFont)
1283 int i, maxSize, ind = -1, size;
1284 char sizeStr[10];
1286 for (i = 0, maxSize = 0; i < ctrlBlk->numFonts; i++)
1288 getStringComponent(ctrlBlk->fontData[i], 7, sizeStr);
1289 size = atoi(sizeStr);
1290 if ((size > maxSize) && (size < MAX_DISPLAY_SIZE))
1292 ind = i;
1293 maxSize = size;
1296 if (ind >= 0) {
1297 strcpy(bigFont, ctrlBlk->fontData[ind]);
1299 else {
1300 bigFont[0] = 0;