1 static const char CVSID
[] = "$Id: fontsel.c,v 1.28 2004/08/01 10:06:12 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 if (ctrlBlk
->sel1
!= NULL
)
900 XtFree(ctrlBlk
->sel1
);
901 ctrlBlk
->sel1
= NULL
;
903 if (ctrlBlk
->sel2
!= NULL
)
904 XtFree(ctrlBlk
->sel2
);
905 ctrlBlk
->sel2
= NULL
;
907 if (ctrlBlk
->sel3
!= NULL
)
908 XtFree(ctrlBlk
->sel3
);
909 ctrlBlk
->sel3
= NULL
;
911 setupScrollLists(NONE
, *ctrlBlk
);
913 XmTextSetString(ctrlBlk
->fontNameField
, "");
914 enableSample(ctrlBlk
, False
, NULL
);
919 static void sizeToggleAction(Widget widget
,
920 xfselControlBlkType
*ctrlBlk
,
921 XmToggleButtonCallbackStruct
*call_data
)
923 int i
, makeSelection
;
927 if (call_data
->reason
== XmCR_VALUE_CHANGED
)
929 makeSelection
= (ctrlBlk
->sel3
!= NULL
);
931 for (i
= 0; (makeSelection
) && (i
< ctrlBlk
->numFonts
); i
++)
932 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
933 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
934 (sizeMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])))
936 getSizePart(ctrlBlk
->fontData
[i
], newSize
,
937 !ctrlBlk
->showSizeInPixels
);
941 if (ctrlBlk
->showSizeInPixels
)
942 ctrlBlk
->showSizeInPixels
= FALSE
;
944 ctrlBlk
->showSizeInPixels
= TRUE
;
946 if (ctrlBlk
->sel3
!= NULL
)
947 XtFree(ctrlBlk
->sel3
);
949 ctrlBlk
->sel3
= NULL
;
950 setupScrollLists(NONE
, *ctrlBlk
);
954 str
= XmStringCreate(newSize
, XmSTRING_DEFAULT_CHARSET
);
955 XmListSelectItem(ctrlBlk
->sizeList
, str
, TRUE
);
956 XmListSetBottomItem(ctrlBlk
->sizeList
, str
);
963 static void enableSample(xfselControlBlkType
*ctrlBlk
, Bool turn_on
,
964 XmFontList
*fontList
)
969 XtSetArg(args
[n
], XmNeditable
, turn_on
); n
++;
970 XtSetArg(args
[n
], XmNcursorPositionVisible
, turn_on
); n
++;
973 fprintf(stderr
, "nedit: Internal error in fontsel.c, line %i\n", \
976 XtSetArg(args
[n
], XmNfontList
, *fontList
); n
++;
978 XtSetArg(args
[n
], XmNforeground
, ctrlBlk
->sampleFG
); n
++;
980 XtSetArg(args
[n
], XmNforeground
, ctrlBlk
->sampleBG
); n
++;
982 XtSetValues(ctrlBlk
->dispField
, args
, n
);
983 /* Make sure the sample area gets resized if the font size changes */
984 XtUnmanageChild(ctrlBlk
->dispField
);
985 XtManageChild(ctrlBlk
->dispField
);
989 static void fontAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
990 XmListCallbackStruct
*call_data
)
994 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
996 if (ctrlBlk
->sel1
== NULL
)
998 ctrlBlk
->sel1
= XtMalloc(strlen(sel
) + 1);
999 strcpy(ctrlBlk
->sel1
, sel
);
1003 if (strcmp(ctrlBlk
->sel1
, sel
) == 0)
1004 { /* Unselecting current selection */
1005 XtFree(ctrlBlk
->sel1
);
1006 ctrlBlk
->sel1
= NULL
;
1007 XmListDeselectItem(widget
, call_data
->item
);
1011 XtFree(ctrlBlk
->sel1
);
1012 ctrlBlk
->sel1
= XtMalloc(strlen(sel
) + 1);
1013 strcpy(ctrlBlk
->sel1
, sel
);
1018 setupScrollLists(FONT
, *ctrlBlk
);
1019 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1020 (ctrlBlk
->sel3
!= NULL
))
1021 choiceMade(ctrlBlk
);
1024 enableSample(ctrlBlk
, False
, NULL
);
1025 XmTextSetString(ctrlBlk
->fontNameField
, "");
1030 static void styleAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1031 XmListCallbackStruct
*call_data
)
1035 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
1037 if (ctrlBlk
->sel2
== NULL
)
1039 ctrlBlk
->sel2
= XtMalloc(strlen(sel
) + 1);
1040 strcpy(ctrlBlk
->sel2
, sel
);
1044 if (strcmp(ctrlBlk
->sel2
, sel
) == 0)
1045 { /* unselecting current selection */
1046 XtFree(ctrlBlk
->sel2
);
1047 ctrlBlk
->sel2
= NULL
;
1048 XmListDeselectItem(widget
, call_data
->item
);
1052 XtFree(ctrlBlk
->sel2
);
1053 ctrlBlk
->sel2
= XtMalloc(strlen(sel
) + 1);
1054 strcpy(ctrlBlk
->sel2
, sel
);
1059 setupScrollLists(STYLE
, *ctrlBlk
);
1060 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1061 (ctrlBlk
->sel3
!= NULL
))
1062 choiceMade(ctrlBlk
);
1065 enableSample(ctrlBlk
, False
, NULL
);
1066 XmTextSetString(ctrlBlk
->fontNameField
, "");
1070 static void sizeAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1071 XmListCallbackStruct
*call_data
)
1075 XmStringGetLtoR(call_data
->item
, XmSTRING_DEFAULT_CHARSET
, &sel
);
1077 if (ctrlBlk
->sel3
== NULL
)
1079 ctrlBlk
->sel3
= XtMalloc(strlen(sel
) + 1);
1080 strcpy(ctrlBlk
->sel3
, sel
);
1084 if (strcmp(ctrlBlk
->sel3
, sel
) == 0)
1085 { /* unselecting current selection */
1086 XtFree(ctrlBlk
->sel3
);
1087 ctrlBlk
->sel3
= NULL
;
1088 XmListDeselectItem(widget
, call_data
->item
);
1092 XtFree(ctrlBlk
->sel3
);
1093 ctrlBlk
->sel3
= XtMalloc(strlen(sel
) + 1);
1094 strcpy(ctrlBlk
->sel3
, sel
);
1099 setupScrollLists(SIZE
, *ctrlBlk
);
1100 if ((ctrlBlk
->sel1
!= NULL
) && (ctrlBlk
->sel2
!= NULL
) &&
1101 (ctrlBlk
->sel3
!= NULL
))
1102 choiceMade(ctrlBlk
);
1105 enableSample(ctrlBlk
, False
, NULL
);
1106 XmTextSetString(ctrlBlk
->fontNameField
, "");
1110 /* function called when all three choices have been made; sets up font
1111 name and displays sample font */
1113 static void choiceMade(xfselControlBlkType
*ctrlBlk
)
1117 if (ctrlBlk
->fontName
!= NULL
)
1118 XtFree(ctrlBlk
->fontName
);
1119 ctrlBlk
->fontName
= NULL
;
1121 for (i
= 0; i
< ctrlBlk
->numFonts
; i
++)
1123 if ((fontMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1124 (styleMatch(ctrlBlk
, ctrlBlk
->fontData
[i
])) &&
1125 (sizeMatch (ctrlBlk
, ctrlBlk
->fontData
[i
])))
1127 ctrlBlk
->fontName
= XtMalloc(
1128 strlen(ctrlBlk
->fontData
[i
]) + 1);
1129 strcpy(ctrlBlk
->fontName
, ctrlBlk
->fontData
[i
]);
1134 if (ctrlBlk
->fontName
!= NULL
)
1136 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1137 dispSample(ctrlBlk
);
1141 DialogF (DF_ERR
, ctrlBlk
->form
, 1, "Font Specification",
1142 "Invalid Font Specification", "OK");
1147 /* loads selected font and displays sample text in that font */
1149 static void dispSample(xfselControlBlkType
*ctrlBlk
)
1152 XmFontList fontList
;
1155 display
= XtDisplay(ctrlBlk
->form
);
1156 font
= XLoadQueryFont(display
, ctrlBlk
->fontName
);
1157 fontList
= XmFontListCreate(font
, XmSTRING_DEFAULT_CHARSET
);
1159 enableSample(ctrlBlk
, True
, &fontList
);
1161 if (ctrlBlk
->oldFont
!= NULL
)
1163 XFreeFont(display
, ctrlBlk
->oldFont
);
1164 XmFontListFree(ctrlBlk
->oldFontList
);
1166 ctrlBlk
->oldFont
= font
;
1167 ctrlBlk
->oldFontList
= fontList
;
1171 static void destroyCB(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1172 XmListCallbackStruct
*call_data
)
1174 /* Prevent double destruction of the font selection dialog */
1175 ctrlBlk
->destroyedFlag
= TRUE
;
1176 cancelAction(widget
, ctrlBlk
, call_data
);
1179 static void cancelAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1180 XmListCallbackStruct
*call_data
)
1182 if (ctrlBlk
->sel1
!= NULL
)
1183 XtFree(ctrlBlk
->sel1
);
1184 if (ctrlBlk
->sel2
!= NULL
)
1185 XtFree(ctrlBlk
->sel2
);
1186 if (ctrlBlk
->sel3
!= NULL
)
1187 XtFree(ctrlBlk
->sel3
);
1188 if (ctrlBlk
->fontName
!= NULL
)
1189 XtFree(ctrlBlk
->fontName
);
1191 ctrlBlk
->fontName
= NULL
;
1192 XFreeFontNames(ctrlBlk
->fontData
);
1194 ctrlBlk
->exitFlag
= TRUE
;
1198 static void okAction(Widget widget
, xfselControlBlkType
*ctrlBlk
,
1199 XmPushButtonCallbackStruct
*call_data
)
1205 fontPattern
= XmTextGetString(ctrlBlk
->fontNameField
);
1206 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), fontPattern
, 1, &i
);
1207 XtFree(fontPattern
);
1211 DialogF (DF_ERR
, ctrlBlk
->okButton
, 1, "Font Specification",
1212 "Invalid Font Specification", "OK");
1213 XFreeFontNames(fontName
);
1217 if (ctrlBlk
->fontName
!= NULL
)
1218 XtFree(ctrlBlk
->fontName
);
1219 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1220 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1222 if (ctrlBlk
->sel1
!= NULL
)
1223 XtFree(ctrlBlk
->sel1
);
1224 if (ctrlBlk
->sel2
!= NULL
)
1225 XtFree(ctrlBlk
->sel2
);
1226 if (ctrlBlk
->sel3
!= NULL
)
1227 XtFree(ctrlBlk
->sel3
);
1229 XFreeFontNames(fontName
);
1230 XFreeFontNames(ctrlBlk
->fontData
);
1232 ctrlBlk
->exitFlag
= TRUE
;
1237 /* if current font is passed as an argument then this function is
1238 invoked and sets up initial entries */
1240 static void startupFont(xfselControlBlkType
*ctrlBlk
, const char *font
)
1244 char part
[TEMP_BUF_SIZE
];
1247 fontName
= XListFonts(XtDisplay(ctrlBlk
->form
), font
, 1, &i
);
1250 { /* invalid font passed in at startup */
1251 XFreeFontNames(fontName
);
1255 ctrlBlk
->fontName
= XtMalloc(strlen(fontName
[0]) + 1);
1256 strcpy(ctrlBlk
->fontName
, fontName
[0]);
1258 getFontPart(fontName
[0], part
);
1259 XFreeFontNames(fontName
);
1260 str
= XmStringCreate(part
, XmSTRING_DEFAULT_CHARSET
);
1261 XmListSetBottomItem(ctrlBlk
->fontList
, str
);
1262 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1263 XmListSelectItem(ctrlBlk
->fontList
, str
, TRUE
);
1266 dispSample(ctrlBlk
);
1267 XmTextSetString(ctrlBlk
->fontNameField
, ctrlBlk
->fontName
);
1271 /* hacked code to move initial input focus to first scroll list and at the
1272 same time have the OK button as the default button */
1274 static void setFocus(Widget w
, xfselControlBlkType
*ctrlBlk
, XEvent
*event
,
1275 Boolean
*continueToDispatch
)
1280 *continueToDispatch
= TRUE
;
1283 XtSetArg(args
[n
], XmNdefaultButton
, ctrlBlk
->okButton
); n
++;
1284 XtSetValues(ctrlBlk
->form
, args
, n
);
1288 /* finds the name of the biggest font less than the given limit
1289 MAX_DISPLAY_SIZE used to set up the initial height of the display widget
1292 static void FindBigFont(xfselControlBlkType
*ctrlBlk
, char *bigFont
)
1294 int i
, maxSize
, ind
= -1, size
;
1297 for (i
= 0, maxSize
= 0; i
< ctrlBlk
->numFonts
; i
++)
1299 getStringComponent(ctrlBlk
->fontData
[i
], 7, sizeStr
);
1300 size
= atoi(sizeStr
);
1301 if ((size
> maxSize
) && (size
< MAX_DISPLAY_SIZE
))
1308 strcpy(bigFont
, ctrlBlk
->fontData
[ind
]);