1 static const char CVSID
[] = "$Id: fontsel.c,v 1.18 2002/06/26 23:39:21 slobasso 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>
49 #include <Xm/ToggleB.h>
50 #include <Xm/MessageB.h>
51 #include <Xm/DialogS.h>
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
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 */
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 /*******************************************************************************
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. *
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 *
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. *
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. *
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
;
186 char bigFont
[MAX_FONT_NAME_LEN
];
187 xfselControlBlkType ctrlBlk
;
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 */
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
,
211 /* Create pushbutton widgets */
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
,
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
,
237 /* create font name text widget and the corresponding label */
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
,
251 RemapDeleteKey(fontName
); /* kludge to handle delete and BS */
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
,
265 XmStringFree(tempStr
);
267 /* create sample display label widget */
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
,
282 /* create toggle buttons */
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
)
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 */
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
,
332 XmStringFree(tempStr
);
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
);
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
);
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
);
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
);
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 */
405 XtSetArg(args
[n
], XmNcancelButton
, cancelButton
); n
++;
406 XtSetValues(form
, args
, n
);
409 /* update application's control block structure */
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
;
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
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
)
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
)
539 if (inStr
[i
] == '\0')
542 for (j
= 0; (inStr
[i
] != DELIM
) && (inStr
[i
] != '\0'); i
++, j
++)
543 outStr
[j
] = inStr
[i
];
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
];
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
);
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
);
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
);
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))
681 /* returns TRUE if the style portion of the font matches the currently
684 static int styleMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
686 char buff
[TEMP_BUF_SIZE
];
688 if (ctrlBlk
->sel2
== NULL
)
691 getStylePart(font
, buff
);
693 if (strcmp(buff
, ctrlBlk
->sel2
) == 0)
700 /* returns TRUE if the size portion of the font matches the currently
703 static int sizeMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
705 char buff
[TEMP_BUF_SIZE
];
707 if (ctrlBlk
->sel3
== NULL
)
710 getSizePart(font
, buff
, ctrlBlk
->showSizeInPixels
);
711 if (strcmp(buff
, ctrlBlk
->sel3
) == 0)
718 /* returns TRUE if the font portion of the font matches the currently
721 static int fontMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
723 char buff
[TEMP_BUF_SIZE
];
725 if (ctrlBlk
->sel1
== NULL
)
728 getFontPart(font
, buff
);
729 if (strcmp(buff
, ctrlBlk
->sel1
) == 0)
736 /* inserts a string into correct sorted position in a list */
738 static void addItemToList(char **buf
, const char *item
, int *count
)
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
);
749 for (i
= 0; i
< *count
; i
++)
751 if (strcmp(buf
[i
], item
) == 0)
753 if (strcmp(buf
[i
], item
) > 0)
757 for (j
= *count
; j
> i
; j
--)
759 buf
[i
] = XtMalloc(strlen(item
) + 1);
760 strcpy(buf
[i
], item
);
765 /* given a font name this function returns the part used in the first
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
);
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
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
);
806 strcpy(buff1
, buff3
);
808 getStringComponent(font
, 6, buff2
);
810 if (buff2
[0] != '\0')
811 sprintf(buff3
, "%s %s", buff1
, buff2
);
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)
827 /* given a font name this function returns the part used in the third
830 static void getSizePart(const char *font
, char *buff1
, int inPixels
)
836 getStringComponent(font
, 7, buff1
);
838 sprintf(buff1
, "%2d", size
);
844 getStringComponent(font
, 8, 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
);
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
)
869 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
871 if (ctrlBlk
->showPropFonts
== PREF_FIXED
)
872 ctrlBlk
->showPropFonts
= PREF_PROP
;
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
);
891 str
= XmStringCreate("", XmSTRING_DEFAULT_CHARSET
);
892 XtSetArg(args
[n
], XmNlabelString
, str
); n
++;
893 XtSetValues(ctrlBlk
->dispLabel
, args
, n
);
894 XmTextSetString(ctrlBlk
->fontNameField
, "");
900 static void sizeToggleAction(Widget widget
,
901 xfselControlBlkType
*ctrlBlk
,
902 XmToggleButtonCallbackStruct
*call_data
)
904 int i
, makeSelection
;
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
);
922 if (ctrlBlk
->showSizeInPixels
)
923 ctrlBlk
->showSizeInPixels
= FALSE
;
925 ctrlBlk
->showSizeInPixels
= TRUE
;
927 if (ctrlBlk
->sel3
!= NULL
)
928 XtFree(ctrlBlk
->sel3
);
930 ctrlBlk
->sel3
= NULL
;
931 setupScrollLists(NONE
, *ctrlBlk
);
935 str
= XmStringCreate(newSize
, XmSTRING_DEFAULT_CHARSET
);
936 XmListSelectItem(ctrlBlk
->sizeList
, str
, TRUE
);
937 XmListSetBottomItem(ctrlBlk
->sizeList
, str
);
944 static void fontAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
945 XmListCallbackStruct
*call_data
)
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
);
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
);
966 XtFree(ctrlBlk
->sel1
);
967 ctrlBlk
->sel1
= XtMalloc(strlen(sel
) + 1);
968 strcpy(ctrlBlk
->sel1
, sel
);
973 setupScrollLists(FONT
, *ctrlBlk
);
974 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
975 (ctrlBlk
->sel3
!= NULL
))
984 str
= XmStringCreate("", XmSTRING_DEFAULT_CHARSET
);
985 XtSetArg(args
[n
], XmNlabelString
, str
); n
++;
986 XtSetValues(ctrlBlk
->dispLabel
, args
, n
);
987 XmTextSetString(ctrlBlk
->fontNameField
, "");
993 static void styleAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
994 XmListCallbackStruct
*call_data
)
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
);
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
);
1015 XtFree(ctrlBlk
->sel2
);
1016 ctrlBlk
->sel2
= XtMalloc(strlen(sel
) + 1);
1017 strcpy(ctrlBlk
->sel2
, sel
);
1022 setupScrollLists(STYLE
, *ctrlBlk
);
1023 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1024 (ctrlBlk
->sel3
!= NULL
))
1025 choiceMade(ctrlBlk
);
1033 str
= XmStringCreate("", XmSTRING_DEFAULT_CHARSET
);
1034 XtSetArg(args
[n
], XmNlabelString
, str
); n
++;
1035 XtSetValues(ctrlBlk
->dispLabel
, args
, n
);
1036 XmTextSetString(ctrlBlk
->fontNameField
, "");
1042 static void sizeAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1043 XmListCallbackStruct
*call_data
)
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
);
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
);
1064 XtFree(ctrlBlk
->sel3
);
1065 ctrlBlk
->sel3
= XtMalloc(strlen(sel
) + 1);
1066 strcpy(ctrlBlk
->sel3
, sel
);
1071 setupScrollLists(SIZE
, *ctrlBlk
);
1072 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1073 (ctrlBlk
->sel3
!= NULL
))
1074 choiceMade(ctrlBlk
);
1082 str
= XmStringCreate("", XmSTRING_DEFAULT_CHARSET
);
1083 XtSetArg(args
[n
], XmNlabelString
, str
); n
++;
1084 XtSetValues(ctrlBlk
->dispLabel
, args
, n
);
1085 XmTextSetString(ctrlBlk
->fontNameField
, "");
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
)
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
]);
1114 if (ctrlBlk
->fontName
!= NULL
)
1116 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1117 dispSample(ctrlBlk
);
1120 DialogF (DF_ERR
, ctrlBlk
->form
, 1, "Invalid Font Specification",
1125 /* loads selected font and displays sample text in that font */
1127 static void dispSample(xfselControlBlkType
*ctrlBlk
)
1132 XmFontList fontList
;
1136 display
= XtDisplay(ctrlBlk
->form
);
1137 font
= XLoadQueryFont(display
, ctrlBlk
->fontName
);
1138 fontList
= XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
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
)
1194 fontPattern
= XmTextGetString(ctrlBlk
->fontNameField
);
1195 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), fontPattern
, 1, &i
);
1196 XtFree(fontPattern
);
1200 DialogF (DF_ERR
, ctrlBlk
->okButton
, 1,
1201 "Invalid Font Specification", "Dismiss");
1202 XFreeFontNames(fontName
);
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
)
1233 char part
[TEMP_BUF_SIZE
];
1236 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), font
, 1, &i
);
1239 { /* invalid font passed in at startup */
1240 XFreeFontNames(fontName
);
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
);
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
)
1269 *continueToDispatch
= TRUE
;
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
;
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
))
1297 strcpy(bigFont
, ctrlBlk
->fontData
[ind
]);