1 static const char CVSID
[] = "$Id: fontsel.c,v 1.29 2006/12/02 10:27:06 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 *
11 * version. In addition, you may distribute version of this program linked to *
12 * Motif or Open Motif. See README for details. *
14 * This software is distributed in the hope that it will be useful, but WITHOUT *
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
19 * You should have received a copy of the GNU General Public License along with *
20 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
21 * Place, Suite 330, Boston, MA 02111-1307 USA *
23 * Nirvana Text Editor *
26 * Written by Suresh Ravoor (assisted by Mark Edel) *
28 *******************************************************************************/
31 #include "../config.h"
43 #include <X11/Intrinsic.h>
51 #include <Xm/ToggleB.h>
52 #include <Xm/MessageB.h>
53 #include <Xm/DialogS.h>
60 #define MAX_NUM_FONTS 32767
61 #define MAX_FONT_NAME_LEN 256
62 #define MAX_ENTRIES_IN_LIST 5000
63 #define MAX_DISPLAY_SIZE 150
65 #define NUM_COMPONENTS_FONT_NAME 14
66 #define TEMP_BUF_SIZE 256
67 #define DISPLAY_HEIGHT 90
69 enum listSpecifier
{ NONE
, FONT
, STYLE
, SIZE
};
72 /* local data structures and types */
76 Widget form
; /* widget id */
77 Widget okButton
; /* widget id */
78 Widget cancelButton
; /* widget id */
79 Widget fontList
; /* widget id */
80 Widget styleList
; /* widget id */
81 Widget sizeList
; /* widget id */
82 Widget fontNameField
; /* widget id */
83 Widget sizeToggle
; /* widget id */
84 Widget propFontToggle
; /* widget id */
85 Widget dispField
; /* widget id */
86 char **fontData
; /* font name info */
87 int numFonts
; /* number of fonts */
88 char *sel1
; /* selection from list 1 */
89 char *sel2
; /* selection from list 2 */
90 char *sel3
; /* selection from list 3 */
91 int showPropFonts
; /* toggle state - show prop fonts */
92 int showSizeInPixels
;/* toggle state - size in pixels */
93 char *fontName
; /* current font name */
94 XFontStruct
*oldFont
; /* font data structure for dispSample */
95 XmFontList oldFontList
; /* font data structure for dispSample */
96 int exitFlag
; /* used for program exit control */
97 int destroyedFlag
; /* used to prevent double destruction */
98 Pixel sampleFG
; /* Colors for the sample field */
100 } xfselControlBlkType
;
103 /* local function prototypes */
105 static void getStringComponent(const char *inStr
, int pos
, char *outStr
);
106 static void setupScrollLists(int dontChange
, xfselControlBlkType ctrlBlk
);
107 static int notPropFont(const char *font
);
108 static int styleMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
109 static int sizeMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
110 static int fontMatch(xfselControlBlkType
*ctrlBlk
, const char *font
);
111 static void addItemToList(char **buf
, const char *item
, int *count
);
112 static void getFontPart(const char *font
, char *buff1
);
113 static void getStylePart(const char *font
, char *buff1
);
114 static void getSizePart(const char *font
, char *buff1
, int inPixels
);
115 static void propFontToggleAction(Widget widget
,
116 xfselControlBlkType
*ctrlBlk
,
117 XmToggleButtonCallbackStruct
*call_data
);
118 static void sizeToggleAction(Widget widget
,
119 xfselControlBlkType
*ctrlBlk
,
120 XmToggleButtonCallbackStruct
*call_data
);
121 static void fontAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
122 XmListCallbackStruct
*call_data
);
123 static void styleAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
124 XmListCallbackStruct
*call_data
);
125 static void sizeAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
126 XmListCallbackStruct
*call_data
);
127 static void choiceMade(xfselControlBlkType
*ctrlBlk
);
128 static void dispSample(xfselControlBlkType
*ctrlBlk
);
129 static void destroyCB(Widget widget
, xfselControlBlkType
*ctrlBlk
,
130 XmListCallbackStruct
*call_data
);
131 static void cancelAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
132 XmListCallbackStruct
*call_data
);
133 static void okAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
134 XmPushButtonCallbackStruct
*call_data
);
135 static void startupFont(xfselControlBlkType
*ctrlBlk
, const char *font
);
136 static void setFocus(Widget w
, xfselControlBlkType
*ctrlBlk
, XEvent
*event
,
137 Boolean
*continueToDispatch
);
138 static void FindBigFont(xfselControlBlkType
*ctrlBlk
, char *bigFont
);
139 static void enableSample(xfselControlBlkType
*ctrlBlk
, Bool turn_on
,
140 XmFontList
*fontList
);
142 /*******************************************************************************
147 * Function to put up a modal font selection dialog box. The purpose *
148 * of this routine is to allow the user to interactively view sample *
149 * fonts and to choose a font for current use. *
153 * Widget parent - parent widget ID *
155 * int showPropFont - ONLY_FIXED : shows only fixed fonts *
156 * doesn't show prop font *
157 * toggle button also. *
158 * PREF_FIXED : can select either fixed *
159 * or proportional fonts; *
160 * but starting option is *
162 * PREF_PROP : can select either fixed *
163 * or proportional fonts; *
164 * but starting option is *
165 * proportional fonts. *
167 * char * currFont - ASCII string that contains the name *
168 * of the currently selected font. *
170 * Pixel sampleFG, sampleBG - Foreground/Background colors in *
171 * which to display the sample *
177 * pointer to an ASCII character string that contains the name of *
178 * the selected font (in X format for naming fonts); it is the users *
179 * responsibility to free the space allocated to this string. *
183 * The calling function has to call the appropriate routines to set *
184 * the current font to the one represented by the returned string. *
186 *******************************************************************************/
188 char *FontSel(Widget parent
, int showPropFonts
, const char *currFont
,
189 Pixel sampleFG
, Pixel sampleBG
)
191 Widget dialog
, form
, okButton
, cancelButton
;
192 Widget styleList
, sizeList
, fontName
, fontList
;
193 Widget sizeToggle
, propFontToggle
= NULL
, dispField
;
194 Widget nameLabel
, sampleLabel
;
198 char bigFont
[MAX_FONT_NAME_LEN
];
199 xfselControlBlkType ctrlBlk
;
202 ctrlBlk
.fontData
= XListFonts(XtDisplay(parent
),
203 "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
204 MAX_NUM_FONTS
, &ctrlBlk
.numFonts
);
205 FindBigFont(&ctrlBlk
, bigFont
);
206 ctrlBlk
.oldFont
= XLoadQueryFont(XtDisplay(parent
), bigFont
);
207 ctrlBlk
.oldFontList
= XmFontListCreate(ctrlBlk
.oldFont
,
208 XmSTRING_DEFAULT_CHARSET
);
209 ctrlBlk
.sampleFG
= sampleFG
;
210 ctrlBlk
.sampleBG
= sampleBG
;
212 dialog
= CreateDialogShell(parent
, "Font Selector", args
, 0);
214 /* Set up window sizes for form widget */
217 XtSetArg(args
[n
], XmNautoUnmanage
, FALSE
); n
++;
218 XtSetArg(args
[n
], XmNdialogStyle
, XmDIALOG_FULL_APPLICATION_MODAL
); n
++;
220 /* Create form popup dialog widget */
222 form
= XtCreateWidget ("Font Selector", xmFormWidgetClass
, dialog
,
225 /* Create pushbutton widgets */
228 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_FORM
); n
++;
229 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
230 XtSetArg(args
[n
], XmNbottomOffset
, 4); n
++;
231 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
232 XtSetArg(args
[n
], XmNrightPosition
, 45); n
++;
233 XtSetArg(args
[n
], XmNwidth
, 110); n
++;
234 XtSetArg(args
[n
], XmNheight
, 28); n
++;
235 XtSetArg(args
[n
], XmNshowAsDefault
, TRUE
); n
++;
236 okButton
= XtCreateManagedWidget("OK", xmPushButtonWidgetClass
, form
,
240 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
241 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
242 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
243 XtSetArg(args
[n
], XmNtopWidget
, okButton
); n
++;
244 XtSetArg(args
[n
], XmNbottomWidget
, okButton
); n
++;
245 XtSetArg(args
[n
], XmNleftPosition
, 55); n
++;
246 XtSetArg(args
[n
], XmNwidth
, 110); n
++;
247 XtSetArg(args
[n
], XmNheight
, 28); n
++;
248 cancelButton
= XtCreateManagedWidget("Cancel", xmPushButtonWidgetClass
,
251 /* create font name text widget and the corresponding label */
254 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
255 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
256 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
257 XtSetArg(args
[n
], XmNbottomWidget
, okButton
); n
++;
258 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
259 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
260 XtSetArg(args
[n
], XmNeditable
, True
); n
++;
261 XtSetArg(args
[n
], XmNeditMode
, XmSINGLE_LINE_EDIT
); n
++;
262 XtSetArg(args
[n
], XmNmaxLength
, MAX_FONT_NAME_LEN
); n
++;
263 fontName
= XtCreateManagedWidget("fontname", xmTextWidgetClass
, form
,
265 RemapDeleteKey(fontName
); /* kludge to handle delete and BS */
268 tempStr
= XmStringCreate("Font Name:", XmSTRING_DEFAULT_CHARSET
);
269 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
270 XtSetArg(args
[n
], XmNmnemonic
, 'N'); n
++;
271 XtSetArg(args
[n
], XmNuserData
, fontName
); n
++;
272 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
273 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
274 XtSetArg(args
[n
], XmNleftWidget
, fontName
); n
++;
275 XtSetArg(args
[n
], XmNbottomWidget
, fontName
); n
++;
276 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
277 nameLabel
= XtCreateManagedWidget("Font Name:", xmLabelWidgetClass
,
279 XmStringFree(tempStr
);
281 /* create sample display text field widget */
284 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
285 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
286 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
287 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
288 XtSetArg(args
[n
], XmNbottomWidget
, nameLabel
); n
++;
289 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
290 XtSetArg(args
[n
], XmNalignment
, XmALIGNMENT_BEGINNING
); n
++;
291 XtSetArg(args
[n
], XmNvalue
,
292 "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789");
294 XtSetArg(args
[n
], XmNforeground
, sampleFG
); n
++;
295 XtSetArg(args
[n
], XmNbackground
, sampleBG
); n
++;
296 dispField
= XtCreateManagedWidget(" ", xmTextFieldWidgetClass
, form
,
300 tempStr
= XmStringCreate("Sample:", XmSTRING_DEFAULT_CHARSET
);
301 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
302 XtSetArg(args
[n
], XmNmnemonic
, 'S'); n
++;
303 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
304 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
305 XtSetArg(args
[n
], XmNleftWidget
, dispField
); n
++;
306 XtSetArg(args
[n
], XmNbottomWidget
, dispField
); n
++;
307 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
308 sampleLabel
= XtCreateManagedWidget("Font Name:", xmLabelWidgetClass
,
310 XmStringFree(tempStr
);
312 /* create toggle buttons */
315 tempStr
= XmStringCreate("Show Size in Points",
316 XmSTRING_DEFAULT_CHARSET
);
317 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
318 XtSetArg(args
[n
], XmNmnemonic
, 'P'); n
++;
319 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
320 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
321 XtSetArg(args
[n
], XmNleftPosition
, 2); n
++;
322 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
323 XtSetArg(args
[n
], XmNbottomWidget
, sampleLabel
); n
++;
324 sizeToggle
= XtCreateManagedWidget("sizetoggle",
325 xmToggleButtonWidgetClass
, form
, args
, n
);
326 XmStringFree(tempStr
);
328 if (showPropFonts
!= ONLY_FIXED
)
331 tempStr
= XmStringCreate("Show Proportional Width Fonts",
332 XmSTRING_DEFAULT_CHARSET
);
333 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
334 XtSetArg(args
[n
], XmNmnemonic
, 'W'); n
++;
335 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
336 XtSetArg(args
[n
], XmNtopAttachment
,
337 XmATTACH_OPPOSITE_WIDGET
); n
++;
338 XtSetArg(args
[n
], XmNbottomAttachment
,
339 XmATTACH_OPPOSITE_WIDGET
); n
++;
340 XtSetArg(args
[n
], XmNrightPosition
, 98); n
++;
341 XtSetArg(args
[n
], XmNtopWidget
, sizeToggle
); n
++;
342 XtSetArg(args
[n
], XmNbottomWidget
, sizeToggle
); n
++;
343 XtSetArg(args
[n
], XmNtopOffset
, 1); n
++;
344 propFontToggle
= XtCreateManagedWidget("propfonttoggle",
345 xmToggleButtonWidgetClass
, form
, args
, n
);
346 XmStringFree(tempStr
);
349 /* create scroll list widgets */
353 tempStr
= XmStringCreate("Font:", XmSTRING_DEFAULT_CHARSET
);
354 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
355 XtSetArg(args
[n
], XmNmnemonic
, 'F'); n
++;
356 XtSetArg(args
[n
], XmNtopOffset
, 2); n
++;
357 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_FORM
); n
++;
358 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_POSITION
); n
++;
359 XtSetArg(args
[n
], XmNleftPosition
, 1); n
++;
360 nameLabel
= XtCreateManagedWidget("Font:", xmLabelWidgetClass
, form
,
362 XmStringFree(tempStr
);
365 XtSetArg(args
[n
], XmNvisibleItemCount
, 15); n
++;
366 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
367 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
368 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
369 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
370 XtSetArg(args
[n
], XmNbottomWidget
, sizeToggle
); n
++;
371 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
372 XtSetArg(args
[n
], XmNleftWidget
, nameLabel
); n
++;
373 XtSetArg(args
[n
], XmNrightPosition
, 52); n
++;
374 fontList
= XmCreateScrolledList(form
, "fontlist", args
, n
);
375 AddMouseWheelSupport(fontList
);
376 XtManageChild(fontList
);
377 XtVaSetValues(nameLabel
, XmNuserData
, fontList
, NULL
);
382 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
383 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
384 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_WIDGET
); n
++;
385 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
386 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
387 XtSetArg(args
[n
], XmNleftOffset
, 5); n
++;
388 XtSetArg(args
[n
], XmNleftWidget
, XtParent(fontList
)); n
++;
389 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(fontList
)); n
++;
390 XtSetArg(args
[n
], XmNrightPosition
, 85); n
++;
391 styleList
= XmCreateScrolledList(form
, "stylelist", args
, n
);
392 AddMouseWheelSupport(styleList
);
393 XtManageChild(styleList
);
396 tempStr
= XmStringCreate("Style:", XmSTRING_DEFAULT_CHARSET
);
397 XtSetArg(args
[n
], XmNmnemonic
, 'y'); n
++;
398 XtSetArg(args
[n
], XmNuserData
, styleList
); n
++;
399 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
400 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
401 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
402 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(styleList
)); n
++;
403 XtSetArg(args
[n
], XmNleftWidget
, XtParent(styleList
)); n
++;
404 XtCreateManagedWidget("Style:", xmLabelWidgetClass
, form
, args
, n
);
405 XmStringFree(tempStr
);
410 XtSetArg(args
[n
], XmNtopAttachment
, XmATTACH_WIDGET
); n
++;
411 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_WIDGET
); n
++;
412 XtSetArg(args
[n
], XmNrightAttachment
, XmATTACH_POSITION
); n
++;
413 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
414 XtSetArg(args
[n
], XmNtopWidget
, nameLabel
); n
++;
415 XtSetArg(args
[n
], XmNleftWidget
, XtParent(styleList
)); n
++;
416 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(fontList
)); n
++;
417 XtSetArg(args
[n
], XmNleftOffset
, 5); n
++;
418 XtSetArg(args
[n
], XmNrightPosition
, 99); n
++;
419 sizeList
= XmCreateScrolledList(form
, "sizelist", args
, n
);
420 AddMouseWheelSupport(sizeList
);
421 XtManageChild(sizeList
);
424 tempStr
= XmStringCreate("Size:", XmSTRING_DEFAULT_CHARSET
);
425 XtSetArg(args
[n
], XmNlabelString
, tempStr
); n
++;
426 XtSetArg(args
[n
], XmNmnemonic
, 'z'); n
++;
427 XtSetArg(args
[n
], XmNuserData
, sizeList
); n
++;
428 XtSetArg(args
[n
], XmNbottomAttachment
, XmATTACH_WIDGET
); n
++;
429 XtSetArg(args
[n
], XmNleftAttachment
, XmATTACH_OPPOSITE_WIDGET
); n
++;
430 XtSetArg(args
[n
], XmNbottomWidget
, XtParent(sizeList
)); n
++;
431 XtSetArg(args
[n
], XmNleftWidget
, XtParent(sizeList
)); n
++;
432 XtCreateManagedWidget("Size:", xmLabelWidgetClass
, form
, args
, n
);
433 XmStringFree(tempStr
);
435 /* update form widgets cancel button */
438 XtSetArg(args
[n
], XmNcancelButton
, cancelButton
); n
++;
439 XtSetValues(form
, args
, n
);
442 /* update application's control block structure */
445 ctrlBlk
.okButton
= okButton
;
446 ctrlBlk
.cancelButton
= cancelButton
;
447 ctrlBlk
.fontList
= fontList
;
448 ctrlBlk
.styleList
= styleList
;
449 ctrlBlk
.sizeList
= sizeList
;
450 ctrlBlk
.fontNameField
= fontName
;
451 ctrlBlk
.sizeToggle
= sizeToggle
;
452 if (showPropFonts
!= ONLY_FIXED
)
453 ctrlBlk
.propFontToggle
= propFontToggle
;
454 ctrlBlk
.dispField
= dispField
;
455 ctrlBlk
.exitFlag
= FALSE
;
456 ctrlBlk
.destroyedFlag
= FALSE
;
457 ctrlBlk
.showPropFonts
= showPropFonts
;
458 ctrlBlk
.showSizeInPixels
= TRUE
;
462 ctrlBlk
.fontName
= NULL
;
464 setupScrollLists(NONE
, ctrlBlk
); /* update scroll lists */
466 if (showPropFonts
== PREF_PROP
)
467 XmToggleButtonSetState(propFontToggle
, TRUE
, FALSE
);
469 /* Register callback functions */
471 if (showPropFonts
!= ONLY_FIXED
)
472 XtAddCallback(propFontToggle
, XmNvalueChangedCallback
,
473 (XtCallbackProc
)propFontToggleAction
, (char *)&ctrlBlk
);
474 XtAddCallback(sizeToggle
, XmNvalueChangedCallback
,
475 (XtCallbackProc
)sizeToggleAction
, (char *)&ctrlBlk
);
476 XtAddCallback(fontList
, XmNbrowseSelectionCallback
,
477 (XtCallbackProc
)fontAction
, (char *)&ctrlBlk
);
478 XtAddCallback(styleList
, XmNbrowseSelectionCallback
,
479 (XtCallbackProc
)styleAction
, (char *)&ctrlBlk
);
480 XtAddCallback(sizeList
, XmNbrowseSelectionCallback
,
481 (XtCallbackProc
)sizeAction
, (char *)&ctrlBlk
);
482 XtAddCallback(okButton
, XmNactivateCallback
,
483 (XtCallbackProc
)okAction
, (char *)&ctrlBlk
);
484 XtAddCallback(cancelButton
, XmNactivateCallback
,
485 (XtCallbackProc
)cancelAction
, (char *)&ctrlBlk
);
487 /* add event handler to setup input focus at start to scroll list */
489 XtAddEventHandler(fontList
, FocusChangeMask
, FALSE
,
490 (XtEventHandler
)setFocus
, (char *)&ctrlBlk
);
491 XmProcessTraversal(fontList
, XmTRAVERSE_CURRENT
);
493 /* setup tabgroups */
495 XmAddTabGroup(fontList
);
496 XmAddTabGroup(styleList
);
497 XmAddTabGroup(sizeList
);
498 XmAddTabGroup(sizeToggle
);
499 if (showPropFonts
!= ONLY_FIXED
)
500 XmAddTabGroup(propFontToggle
);
501 XmAddTabGroup(fontName
);
502 XmAddTabGroup(okButton
);
503 XmAddTabGroup(cancelButton
);
505 /* Make sure that we don't try to access the dialog if the user
506 destroyed it (possibly indirectly, by destroying the parent). */
507 XtAddCallback(dialog
, XmNdestroyCallback
,
508 (XtCallbackProc
)destroyCB
, (char *)&ctrlBlk
);
510 /* Link Motif Close option to cancel action */
512 AddMotifCloseCallback(dialog
, (XtCallbackProc
)cancelAction
, &ctrlBlk
);
514 /* Handle dialog mnemonics */
516 AddDialogMnemonicHandler(form
, FALSE
);
518 /* Realize Widgets */
520 ManageDialogCenteredOnPointer(form
);
522 /* set up current font parameters */
524 if (currFont
[0] != '\0')
525 startupFont(&ctrlBlk
, currFont
);
527 /* Make sure that we can still access the display in case the form
529 theDisplay
= XtDisplay(form
);
531 /* enter event loop */
533 while (! ctrlBlk
.exitFlag
&& ! ctrlBlk
.destroyedFlag
)
534 XtAppProcessEvent(XtWidgetToApplicationContext(form
), XtIMAll
);
536 if (! ctrlBlk
.destroyedFlag
) {
537 /* Don't let the callback destroy the font name */
538 XtRemoveCallback(dialog
, XmNdestroyCallback
,
539 (XtCallbackProc
)destroyCB
, (char *)&ctrlBlk
);
540 XtDestroyWidget(dialog
);
543 if (ctrlBlk
.oldFont
!= NULL
)
545 XFreeFont(theDisplay
, ctrlBlk
.oldFont
);
546 XmFontListFree(ctrlBlk
.oldFontList
);
549 return(ctrlBlk
.fontName
);
553 /* gets a specific substring from a string */
555 static void getStringComponent(const char *inStr
, int pos
, char *outStr
)
561 if (pos
> NUM_COMPONENTS_FONT_NAME
)
563 fprintf(stderr
, "Warning: getStringComponent being used for ");
564 fprintf(stderr
, "pos > %d\nIf such ", NUM_COMPONENTS_FONT_NAME
);
565 fprintf(stderr
, "use is intended remove these warning lines\n");
568 for (i
= 0; (pos
> 0) && (inStr
[i
] != '\0'); i
++)
569 if (inStr
[i
] == DELIM
)
572 if (inStr
[i
] == '\0')
575 for (j
= 0; (inStr
[i
] != DELIM
) && (inStr
[i
] != '\0'); i
++, j
++)
576 outStr
[j
] = inStr
[i
];
581 /* parse through the fontlist data and set up the three scroll lists */
583 static void setupScrollLists(int dontChange
, xfselControlBlkType ctrlBlk
)
585 char *itemBuf1
[MAX_ENTRIES_IN_LIST
];
586 char *itemBuf2
[MAX_ENTRIES_IN_LIST
];
587 char *itemBuf3
[MAX_ENTRIES_IN_LIST
];
588 int itemCount1
, itemCount2
, itemCount3
;
589 char buff1
[TEMP_BUF_SIZE
];
590 XmString items
[MAX_ENTRIES_IN_LIST
];
597 for (i
= 0; i
< ctrlBlk
.numFonts
&& i
< MAX_ENTRIES_IN_LIST
; i
++)
599 if ((dontChange
!= FONT
) &&
600 (styleMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
601 (sizeMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
602 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
603 (notPropFont(ctrlBlk
.fontData
[i
]))))
605 getFontPart(ctrlBlk
.fontData
[i
], buff1
);
606 addItemToList(itemBuf1
, buff1
, &itemCount1
);
609 if ((dontChange
!= STYLE
) &&
610 (fontMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
611 (sizeMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
612 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
613 (notPropFont(ctrlBlk
.fontData
[i
]))))
615 getStylePart(ctrlBlk
.fontData
[i
], buff1
);
616 addItemToList(itemBuf2
, buff1
, &itemCount2
);
619 if ((dontChange
!= SIZE
) &&
620 (fontMatch(&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
621 (styleMatch (&ctrlBlk
, ctrlBlk
.fontData
[i
])) &&
622 ((ctrlBlk
.showPropFonts
== PREF_PROP
) ||
623 (notPropFont(ctrlBlk
.fontData
[i
]))))
625 getSizePart(ctrlBlk
.fontData
[i
], buff1
, ctrlBlk
.showSizeInPixels
);
626 addItemToList(itemBuf3
, buff1
, &itemCount3
);
628 } /* end - for (i = 0; i < ctrlBlk.numFonts; i++) */
630 /* recreate all three scroll lists where necessary */
631 if (dontChange
!= FONT
)
633 for (i
= 0; i
< itemCount1
; i
++)
635 items
[i
] = XmStringCreate(itemBuf1
[i
], XmSTRING_DEFAULT_CHARSET
);
638 XmListDeleteAllItems(ctrlBlk
.fontList
);
639 XmListAddItems(ctrlBlk
.fontList
, items
, itemCount1
, 1);
640 if (ctrlBlk
.sel1
!= NULL
)
642 XmStringFree(items
[0]);
643 items
[0] = XmStringCreate(ctrlBlk
.sel1
, XmSTRING_DEFAULT_CHARSET
);
644 XmListSelectItem(ctrlBlk
.fontList
, items
[0], FALSE
);
645 XmListSetBottomItem(ctrlBlk
.fontList
, items
[0]);
647 for (i
= 0; i
< itemCount1
; i
++)
648 XmStringFree(items
[i
]);
651 if (dontChange
!= STYLE
)
653 for (i
= 0; i
< itemCount2
; i
++)
655 items
[i
] = XmStringCreate(itemBuf2
[i
], XmSTRING_DEFAULT_CHARSET
);
658 XmListDeleteAllItems(ctrlBlk
.styleList
);
659 XmListAddItems(ctrlBlk
.styleList
, items
, itemCount2
, 1);
660 if (ctrlBlk
.sel2
!= NULL
)
662 XmStringFree(items
[0]);
663 items
[0] = XmStringCreate(ctrlBlk
.sel2
, XmSTRING_DEFAULT_CHARSET
);
664 XmListSelectItem(ctrlBlk
.styleList
, items
[0], FALSE
);
665 XmListSetBottomItem(ctrlBlk
.styleList
, items
[0]);
667 for (i
= 0; i
< itemCount2
; i
++)
668 XmStringFree(items
[i
]);
671 if (dontChange
!= SIZE
)
673 for (i
= 0; i
< itemCount3
; i
++)
675 items
[i
] = XmStringCreate(itemBuf3
[i
],
676 XmSTRING_DEFAULT_CHARSET
);
679 XmListDeleteAllItems(ctrlBlk
.sizeList
);
680 XmListAddItems(ctrlBlk
.sizeList
, items
, itemCount3
, 1);
681 if (ctrlBlk
.sel3
!= NULL
)
683 XmStringFree(items
[0]);
684 items
[0] = XmStringCreate(ctrlBlk
.sel3
, XmSTRING_DEFAULT_CHARSET
);
685 XmListSelectItem(ctrlBlk
.sizeList
, items
[0], FALSE
);
686 XmListSetBottomItem(ctrlBlk
.sizeList
, items
[0]);
688 for (i
= 0; i
< itemCount3
; i
++)
689 XmStringFree(items
[i
]);
694 /* returns TRUE if argument is not name of a proportional font */
696 static int notPropFont(const char *font
)
698 char buff1
[TEMP_BUF_SIZE
];
700 getStringComponent(font
, 11, buff1
);
701 if ((strcmp(buff1
, "p") == 0) || (strcmp(buff1
, "P") == 0))
708 /* returns TRUE if the style portion of the font matches the currently
711 static int styleMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
713 char buff
[TEMP_BUF_SIZE
];
715 if (ctrlBlk
->sel2
== NULL
)
718 getStylePart(font
, buff
);
720 if (strcmp(buff
, ctrlBlk
->sel2
) == 0)
727 /* returns TRUE if the size portion of the font matches the currently
730 static int sizeMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
732 char buff
[TEMP_BUF_SIZE
];
734 if (ctrlBlk
->sel3
== NULL
)
737 getSizePart(font
, buff
, ctrlBlk
->showSizeInPixels
);
738 if (strcmp(buff
, ctrlBlk
->sel3
) == 0)
745 /* returns TRUE if the font portion of the font matches the currently
748 static int fontMatch(xfselControlBlkType
*ctrlBlk
, const char *font
)
750 char buff
[TEMP_BUF_SIZE
];
752 if (ctrlBlk
->sel1
== NULL
)
755 getFontPart(font
, buff
);
756 if (strcmp(buff
, ctrlBlk
->sel1
) == 0)
763 /* inserts a string into correct sorted position in a list */
765 static void addItemToList(char **buf
, const char *item
, int *count
)
769 if (*count
== MAX_ENTRIES_IN_LIST
)
771 fprintf(stderr
, "Trying to add more than MAX_ENTRIES_IN_LIST ");
772 fprintf(stderr
, "(%d) entries to array\n", MAX_ENTRIES_IN_LIST
);
776 for (i
= 0; i
< *count
; i
++)
778 if (strcmp(buf
[i
], item
) == 0)
780 if (strcmp(buf
[i
], item
) > 0)
784 for (j
= *count
; j
> i
; j
--)
786 buf
[i
] = XtMalloc(strlen(item
) + 1);
787 strcpy(buf
[i
], item
);
792 /* given a font name this function returns the part used in the first
795 static void getFontPart(const char *font
, char *buff1
)
797 char buff2
[TEMP_BUF_SIZE
], buff3
[TEMP_BUF_SIZE
];
798 char buff4
[TEMP_BUF_SIZE
];
800 getStringComponent(font
, 2, buff1
);
801 getStringComponent(font
, 1, buff2
);
803 sprintf(buff3
, "%s (%s", buff1
, buff2
);
805 getStringComponent(font
, 13, buff1
);
806 getStringComponent(font
, 14, buff4
);
808 if (((strncmp(buff1
, "iso8859", 7) == 0) ||
809 (strncmp(buff1
, "ISO8859", 7) == 0)) && (strcmp(buff4
, "1") == 0))
810 sprintf(buff1
, "%s)", buff3
);
813 sprintf(buff2
, "%s, %s,", buff3
, buff1
);
814 sprintf(buff1
, "%s %s)", buff2
, buff4
);
819 /* given a font name this function returns the part used in the second
822 static void getStylePart(const char *font
, char *buff1
)
824 char buff2
[TEMP_BUF_SIZE
], buff3
[TEMP_BUF_SIZE
];
826 getStringComponent(font
, 3, buff3
);
827 getStringComponent(font
, 5, buff2
);
829 if ((strcmp(buff2
, "normal") != 0) && (strcmp(buff2
, "Normal") != 0) &&
830 (strcmp(buff2
, "NORMAL") != 0))
831 sprintf(buff1
, "%s %s", buff3
, buff2
);
833 strcpy(buff1
, buff3
);
835 getStringComponent(font
, 6, buff2
);
837 if (buff2
[0] != '\0')
838 sprintf(buff3
, "%s %s", buff1
, buff2
);
840 strcpy(buff3
, buff1
);
842 getStringComponent(font
, 4, buff2
);
844 if ((strcmp(buff2
, "o") == 0) || (strcmp(buff2
, "O") == 0))
845 sprintf(buff1
, "%s oblique", buff3
);
846 else if ((strcmp(buff2
, "i") == 0) || (strcmp(buff2
, "I") == 0))
847 sprintf(buff1
, "%s italic", buff3
);
849 if (strcmp(buff1
, " ") == 0)
854 /* given a font name this function returns the part used in the third
857 static void getSizePart(const char *font
, char *buff1
, int inPixels
)
863 getStringComponent(font
, 7, buff1
);
865 sprintf(buff1
, "%2d", size
);
871 getStringComponent(font
, 8, buff1
);
873 temp
= (double)size
/ 10.0;
874 if (buff1
[strlen(buff1
) - 1] == '0')
876 size
= (int)floor(temp
+0.5);
877 sprintf(buff1
, "%2d", size
);
880 sprintf(buff1
, "%4.1f", temp
);
885 /* Call back functions start from here - suffix Action in the function name
886 is for the callback function for the corresponding widget */
888 static void propFontToggleAction(Widget widget
,
889 xfselControlBlkType
*ctrlBlk
,
890 XmToggleButtonCallbackStruct
*call_data
)
892 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
894 if (ctrlBlk
->showPropFonts
== PREF_FIXED
)
895 ctrlBlk
->showPropFonts
= PREF_PROP
;
897 ctrlBlk
->showPropFonts
= PREF_FIXED
;
899 XtFree(ctrlBlk
->sel1
);
900 ctrlBlk
->sel1
= NULL
;
902 XtFree(ctrlBlk
->sel2
);
903 ctrlBlk
->sel2
= NULL
;
905 XtFree(ctrlBlk
->sel3
);
906 ctrlBlk
->sel3
= NULL
;
908 setupScrollLists(NONE
, *ctrlBlk
);
910 XmTextSetString(ctrlBlk
->fontNameField
, "");
911 enableSample(ctrlBlk
, False
, NULL
);
916 static void sizeToggleAction(Widget widget
,
917 xfselControlBlkType
*ctrlBlk
,
918 XmToggleButtonCallbackStruct
*call_data
)
920 int i
, makeSelection
;
924 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
926 makeSelection
= (ctrlBlk
->sel3
!= NULL
);
928 for (i
= 0; (makeSelection
) && (i
< ctrlBlk
->numFonts
); i
++)
929 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
930 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
931 (sizeMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])))
933 getSizePart(ctrlBlk
->fontData
[i
], newSize
,
934 !ctrlBlk
->showSizeInPixels
);
938 if (ctrlBlk
->showSizeInPixels
)
939 ctrlBlk
->showSizeInPixels
= FALSE
;
941 ctrlBlk
->showSizeInPixels
= TRUE
;
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 XtFree(ctrlBlk
->fontName
);
1114 ctrlBlk
->fontName
= NULL
;
1116 for (i
= 0; i
< ctrlBlk
->numFonts
; i
++)
1118 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1119 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1120 (sizeMatch (ctrlBlk
, ctrlBlk
->fontData
[i
])))
1122 ctrlBlk
->fontName
= XtMalloc(
1123 strlen(ctrlBlk
->fontData
[i
]) + 1);
1124 strcpy(ctrlBlk
->fontName
, ctrlBlk
->fontData
[i
]);
1129 if (ctrlBlk
->fontName
!= NULL
)
1131 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1132 dispSample(ctrlBlk
);
1136 DialogF (DF_ERR
, ctrlBlk
->form
, 1, "Font Specification",
1137 "Invalid Font Specification", "OK");
1142 /* loads selected font and displays sample text in that font */
1144 static void dispSample(xfselControlBlkType
*ctrlBlk
)
1147 XmFontList fontList
;
1150 display
= XtDisplay(ctrlBlk
->form
);
1151 font
= XLoadQueryFont(display
, ctrlBlk
->fontName
);
1152 fontList
= XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
1154 enableSample(ctrlBlk
, True
, &fontList
);
1156 if (ctrlBlk
->oldFont
!= NULL
)
1158 XFreeFont(display
, ctrlBlk
->oldFont
);
1159 XmFontListFree(ctrlBlk
->oldFontList
);
1161 ctrlBlk
->oldFont
= font
;
1162 ctrlBlk
->oldFontList
= fontList
;
1166 static void destroyCB(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1167 XmListCallbackStruct
*call_data
)
1169 /* Prevent double destruction of the font selection dialog */
1170 ctrlBlk
->destroyedFlag
= TRUE
;
1171 cancelAction(widget
, ctrlBlk
, call_data
);
1174 static void cancelAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1175 XmListCallbackStruct
*call_data
)
1177 XtFree(ctrlBlk
->sel1
);
1178 XtFree(ctrlBlk
->sel2
);
1179 XtFree(ctrlBlk
->sel3
);
1180 XtFree(ctrlBlk
->fontName
);
1182 ctrlBlk
->fontName
= NULL
;
1183 XFreeFontNames(ctrlBlk
->fontData
);
1185 ctrlBlk
->exitFlag
= TRUE
;
1189 static void okAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1190 XmPushButtonCallbackStruct
*call_data
)
1196 fontPattern
= XmTextGetString(ctrlBlk
->fontNameField
);
1197 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), fontPattern
, 1, &i
);
1198 XtFree(fontPattern
);
1202 DialogF (DF_ERR
, ctrlBlk
->okButton
, 1, "Font Specification",
1203 "Invalid Font Specification", "OK");
1204 XFreeFontNames(fontName
);
1208 XtFree(ctrlBlk
->fontName
);
1209 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1210 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1212 XtFree(ctrlBlk
->sel1
);
1213 XtFree(ctrlBlk
->sel2
);
1214 XtFree(ctrlBlk
->sel3
);
1216 XFreeFontNames(fontName
);
1217 XFreeFontNames(ctrlBlk
->fontData
);
1219 ctrlBlk
->exitFlag
= TRUE
;
1224 /* if current font is passed as an argument then this function is
1225 invoked and sets up initial entries */
1227 static void startupFont(xfselControlBlkType
*ctrlBlk
, const char *font
)
1231 char part
[TEMP_BUF_SIZE
];
1234 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), font
, 1, &i
);
1237 { /* invalid font passed in at startup */
1238 XFreeFontNames(fontName
);
1242 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1243 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1245 getFontPart(fontName
[0], part
);
1246 XFreeFontNames(fontName
);
1247 str
= XmStringCreate(part
, XmSTRING_DEFAULT_CHARSET
);
1248 XmListSetBottomItem(ctrlBlk
->fontList
, str
);
1249 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1250 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1253 dispSample(ctrlBlk
);
1254 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1258 /* hacked code to move initial input focus to first scroll list and at the
1259 same time have the OK button as the default button */
1261 static void setFocus(Widget w
, xfselControlBlkType
*ctrlBlk
, XEvent
*event
,
1262 Boolean
*continueToDispatch
)
1267 *continueToDispatch
= TRUE
;
1270 XtSetArg(args
[n
], XmNdefaultButton
, ctrlBlk
->okButton
); n
++;
1271 XtSetValues(ctrlBlk
->form
, args
, n
);
1275 /* finds the name of the biggest font less than the given limit
1276 MAX_DISPLAY_SIZE used to set up the initial height of the display widget
1279 static void FindBigFont(xfselControlBlkType
*ctrlBlk
, char *bigFont
)
1281 int i
, maxSize
, ind
= -1, size
;
1284 for (i
= 0, maxSize
= 0; i
< ctrlBlk
->numFonts
; i
++)
1286 getStringComponent(ctrlBlk
->fontData
[i
], 7, sizeStr
);
1287 size
= atoi(sizeStr
);
1288 if ((size
> maxSize
) && (size
< MAX_DISPLAY_SIZE
))
1295 strcpy(bigFont
, ctrlBlk
->fontData
[ind
]);