Describe relaunching in the NEWS file.
[wmaker-crm.git] / WINGs / wfontpanel.c
blob3cf14c845792af031a10af8db2f85259ea9aca89
2 #include "WINGsP.h"
3 #include "WUtil.h"
4 #include "wconfig.h"
6 #include <ctype.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdint.h>
11 #include <X11/Xft/Xft.h>
12 #include <fontconfig/fontconfig.h>
14 /* XXX TODO */
15 char *WMFontPanelFontChangedNotification = "WMFontPanelFontChangedNotification";
17 typedef struct W_FontPanel {
18 WMWindow *win;
20 WMFrame *upperF;
21 WMTextField *sampleT;
23 WMSplitView *split;
25 WMFrame *lowerF;
26 WMLabel *famL;
27 WMList *famLs;
28 WMLabel *typL;
29 WMList *typLs;
30 WMLabel *sizL;
31 WMTextField *sizT;
32 WMList *sizLs;
34 WMAction2 *action;
35 void *data;
37 WMButton *revertB;
38 WMButton *setB;
40 WMPropList *fdb;
41 } FontPanel;
43 #define MIN_UPPER_HEIGHT 20
44 #define MIN_LOWER_HEIGHT 140
46 #define MAX_FONTS_TO_RETRIEVE 2000
48 #define BUTTON_SPACE_HEIGHT 40
50 #define MIN_WIDTH 250
51 #define MIN_HEIGHT (MIN_UPPER_HEIGHT+MIN_LOWER_HEIGHT+BUTTON_SPACE_HEIGHT)
53 #define DEF_UPPER_HEIGHT 60
54 #define DEF_LOWER_HEIGHT 310
56 #define DEF_WIDTH 320
57 #define DEF_HEIGHT (DEF_UPPER_HEIGHT+DEF_LOWER_HEIGHT)
59 static int scalableFontSizes[] = {
61 10,
62 11,
63 12,
64 14,
65 16,
66 18,
67 20,
68 24,
69 36,
70 48,
74 static void setFontPanelFontName(FontPanel * panel, char *family, char *style, double size);
76 static int isXLFD(char *font, int *length_ret);
78 static void arrangeLowerFrame(FontPanel * panel);
80 static void familyClick(WMWidget *, void *);
81 static void typefaceClick(WMWidget *, void *);
82 static void sizeClick(WMWidget *, void *);
84 static void listFamilies(WMScreen * scr, WMFontPanel * panel);
86 static void splitViewConstrainCallback(WMSplitView * sPtr, int indView, int *min, int *max)
88 if (indView == 0)
89 *min = MIN_UPPER_HEIGHT;
90 else
91 *min = MIN_LOWER_HEIGHT;
94 static void notificationObserver(void *self, WMNotification * notif)
96 WMFontPanel *panel = (WMFontPanel *) self;
97 void *object = WMGetNotificationObject(notif);
99 if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
100 if (object == WMWidgetView(panel->win)) {
101 int h = WMWidgetHeight(panel->win);
102 int w = WMWidgetWidth(panel->win);
104 WMResizeWidget(panel->split, w, h - BUTTON_SPACE_HEIGHT);
106 WMMoveWidget(panel->setB, w - 80, h - (BUTTON_SPACE_HEIGHT - 5));
108 WMMoveWidget(panel->revertB, w - 240, h - (BUTTON_SPACE_HEIGHT - 5));
110 } else if (object == WMWidgetView(panel->upperF)) {
112 if (WMWidgetHeight(panel->upperF) < MIN_UPPER_HEIGHT) {
113 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF), MIN_UPPER_HEIGHT);
114 } else {
115 WMResizeWidget(panel->sampleT, WMWidgetWidth(panel->upperF) - 20,
116 WMWidgetHeight(panel->upperF) - 10);
119 } else if (object == WMWidgetView(panel->lowerF)) {
121 if (WMWidgetHeight(panel->lowerF) < MIN_LOWER_HEIGHT) {
122 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF), MIN_UPPER_HEIGHT);
124 WMMoveWidget(panel->lowerF, 0, WMWidgetHeight(panel->upperF)
125 + WMGetSplitViewDividerThickness(panel->split));
127 WMResizeWidget(panel->lowerF, WMWidgetWidth(panel->lowerF),
128 WMWidgetWidth(panel->split) - MIN_UPPER_HEIGHT
129 - WMGetSplitViewDividerThickness(panel->split));
130 } else {
131 arrangeLowerFrame(panel);
137 static void closeWindow(WMWidget * w, void *data)
139 FontPanel *panel = (FontPanel *) data;
141 WMHideFontPanel(panel);
144 static void setClickedAction(WMWidget * w, void *data)
146 FontPanel *panel = (FontPanel *) data;
148 if (panel->action)
149 (*panel->action) (panel, panel->data);
152 static void revertClickedAction(WMWidget * w, void *data)
154 /*FontPanel *panel = (FontPanel*)data; */
155 /* XXX TODO */
158 WMFontPanel *WMGetFontPanel(WMScreen * scr)
160 FontPanel *panel;
161 WMColor *dark, *white;
162 WMFont *font;
163 int divThickness;
165 if (scr->sharedFontPanel)
166 return scr->sharedFontPanel;
168 panel = wmalloc(sizeof(FontPanel));
170 panel->win = WMCreateWindow(scr, "fontPanel");
171 /* WMSetWidgetBackgroundColor(panel->win, WMWhiteColor(scr)); */
172 WMSetWindowTitle(panel->win, _("Font Panel"));
173 WMResizeWidget(panel->win, DEF_WIDTH, DEF_HEIGHT);
174 WMSetWindowMinSize(panel->win, MIN_WIDTH, MIN_HEIGHT);
175 WMSetViewNotifySizeChanges(WMWidgetView(panel->win), True);
177 WMSetWindowCloseAction(panel->win, closeWindow, panel);
179 panel->split = WMCreateSplitView(panel->win);
180 WMResizeWidget(panel->split, DEF_WIDTH, DEF_HEIGHT - BUTTON_SPACE_HEIGHT);
181 WMSetSplitViewConstrainProc(panel->split, splitViewConstrainCallback);
183 divThickness = WMGetSplitViewDividerThickness(panel->split);
185 panel->upperF = WMCreateFrame(panel->win);
186 WMSetFrameRelief(panel->upperF, WRFlat);
187 WMSetViewNotifySizeChanges(WMWidgetView(panel->upperF), True);
188 panel->lowerF = WMCreateFrame(panel->win);
189 /* WMSetWidgetBackgroundColor(panel->lowerF, WMBlackColor(scr)); */
190 WMSetFrameRelief(panel->lowerF, WRFlat);
191 WMSetViewNotifySizeChanges(WMWidgetView(panel->lowerF), True);
193 WMAddSplitViewSubview(panel->split, W_VIEW(panel->upperF));
194 WMAddSplitViewSubview(panel->split, W_VIEW(panel->lowerF));
196 WMResizeWidget(panel->upperF, DEF_WIDTH, DEF_UPPER_HEIGHT);
198 WMResizeWidget(panel->lowerF, DEF_WIDTH, DEF_LOWER_HEIGHT);
200 WMMoveWidget(panel->lowerF, 0, 60 + divThickness);
202 white = WMWhiteColor(scr);
203 dark = WMDarkGrayColor(scr);
205 panel->sampleT = WMCreateTextField(panel->upperF);
206 WMResizeWidget(panel->sampleT, DEF_WIDTH - 20, 50);
207 WMMoveWidget(panel->sampleT, 10, 10);
208 WMSetTextFieldText(panel->sampleT, _("The quick brown fox jumps over the lazy dog"));
210 font = WMBoldSystemFontOfSize(scr, 12);
212 panel->famL = WMCreateLabel(panel->lowerF);
213 WMSetWidgetBackgroundColor(panel->famL, dark);
214 WMSetLabelText(panel->famL, _("Family"));
215 WMSetLabelFont(panel->famL, font);
216 WMSetLabelTextColor(panel->famL, white);
217 WMSetLabelRelief(panel->famL, WRSunken);
218 WMSetLabelTextAlignment(panel->famL, WACenter);
220 panel->famLs = WMCreateList(panel->lowerF);
221 WMSetListAction(panel->famLs, familyClick, panel);
223 panel->typL = WMCreateLabel(panel->lowerF);
224 WMSetWidgetBackgroundColor(panel->typL, dark);
225 WMSetLabelText(panel->typL, _("Typeface"));
226 WMSetLabelFont(panel->typL, font);
227 WMSetLabelTextColor(panel->typL, white);
228 WMSetLabelRelief(panel->typL, WRSunken);
229 WMSetLabelTextAlignment(panel->typL, WACenter);
231 panel->typLs = WMCreateList(panel->lowerF);
232 WMSetListAction(panel->typLs, typefaceClick, panel);
234 panel->sizL = WMCreateLabel(panel->lowerF);
235 WMSetWidgetBackgroundColor(panel->sizL, dark);
236 WMSetLabelText(panel->sizL, _("Size"));
237 WMSetLabelFont(panel->sizL, font);
238 WMSetLabelTextColor(panel->sizL, white);
239 WMSetLabelRelief(panel->sizL, WRSunken);
240 WMSetLabelTextAlignment(panel->sizL, WACenter);
242 panel->sizT = WMCreateTextField(panel->lowerF);
243 /* WMSetTextFieldAlignment(panel->sizT, WARight); */
245 panel->sizLs = WMCreateList(panel->lowerF);
246 WMSetListAction(panel->sizLs, sizeClick, panel);
248 WMReleaseFont(font);
249 WMReleaseColor(white);
250 WMReleaseColor(dark);
252 panel->setB = WMCreateCommandButton(panel->win);
253 WMResizeWidget(panel->setB, 70, 24);
254 WMMoveWidget(panel->setB, 240, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT - 5));
255 WMSetButtonText(panel->setB, _("Set"));
256 WMSetButtonAction(panel->setB, setClickedAction, panel);
258 panel->revertB = WMCreateCommandButton(panel->win);
259 WMResizeWidget(panel->revertB, 70, 24);
260 WMMoveWidget(panel->revertB, 80, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT - 5));
261 WMSetButtonText(panel->revertB, _("Revert"));
262 WMSetButtonAction(panel->revertB, revertClickedAction, panel);
264 WMRealizeWidget(panel->win);
266 WMMapSubwidgets(panel->upperF);
267 WMMapSubwidgets(panel->lowerF);
268 WMMapSubwidgets(panel->split);
269 WMMapSubwidgets(panel->win);
271 WMUnmapWidget(panel->revertB);
273 arrangeLowerFrame(panel);
275 scr->sharedFontPanel = panel;
277 /* register notification observers */
278 WMAddNotificationObserver(notificationObserver, panel,
279 WMViewSizeDidChangeNotification, WMWidgetView(panel->win));
280 WMAddNotificationObserver(notificationObserver, panel,
281 WMViewSizeDidChangeNotification, WMWidgetView(panel->upperF));
282 WMAddNotificationObserver(notificationObserver, panel,
283 WMViewSizeDidChangeNotification, WMWidgetView(panel->lowerF));
285 listFamilies(scr, panel);
287 return panel;
290 void WMFreeFontPanel(WMFontPanel * panel)
292 if (panel == WMWidgetScreen(panel->win)->sharedFontPanel) {
293 WMWidgetScreen(panel->win)->sharedFontPanel = NULL;
295 WMRemoveNotificationObserver(panel);
296 WMUnmapWidget(panel->win);
297 WMDestroyWidget(panel->win);
298 wfree(panel);
301 void WMShowFontPanel(WMFontPanel * panel)
303 WMMapWidget(panel->win);
306 void WMHideFontPanel(WMFontPanel * panel)
308 WMUnmapWidget(panel->win);
311 WMFont *WMGetFontPanelFont(WMFontPanel * panel)
313 return WMGetTextFieldFont(panel->sampleT);
316 void WMSetFontPanelFont(WMFontPanel * panel, char *fontName)
318 int fname_len;
319 FcPattern *pattern;
320 FcChar8 *family, *style;
321 double size;
323 if (!isXLFD(fontName, &fname_len)) {
324 /* maybe its proper fontconfig and we can parse it */
325 pattern = FcNameParse((FcChar8 *) fontName);
326 } else {
327 /* maybe its proper xlfd and we can convert it to an FcPattern */
328 pattern = XftXlfdParse(fontName, False, False);
329 /*//FcPatternPrint(pattern); */
332 if (!pattern)
333 return;
335 if (FcPatternGetString(pattern, FC_FAMILY, 0, &family) == FcResultMatch)
336 if (FcPatternGetString(pattern, FC_STYLE, 0, &style) == FcResultMatch)
337 if (FcPatternGetDouble(pattern, "pixelsize", 0, &size) == FcResultMatch)
338 setFontPanelFontName(panel, (char *)family, (char *)style, size);
340 FcPatternDestroy(pattern);
343 void WMSetFontPanelAction(WMFontPanel * panel, WMAction2 * action, void *data)
345 panel->action = action;
346 panel->data = data;
349 static void arrangeLowerFrame(FontPanel * panel)
351 int width = WMWidgetWidth(panel->lowerF) - 55 - 30;
352 int height = WMWidgetHeight(panel->split) - WMWidgetHeight(panel->upperF);
353 int fw, tw, sw;
355 #define LABEL_HEIGHT 20
357 height -= WMGetSplitViewDividerThickness(panel->split);
359 height -= LABEL_HEIGHT + 8;
361 fw = (125 * width) / 235;
362 tw = (110 * width) / 235;
363 sw = 55;
365 WMMoveWidget(panel->famL, 10, 0);
366 WMResizeWidget(panel->famL, fw, LABEL_HEIGHT);
368 WMMoveWidget(panel->famLs, 10, 23);
369 WMResizeWidget(panel->famLs, fw, height);
371 WMMoveWidget(panel->typL, 10 + fw + 3, 0);
372 WMResizeWidget(panel->typL, tw, LABEL_HEIGHT);
374 WMMoveWidget(panel->typLs, 10 + fw + 3, 23);
375 WMResizeWidget(panel->typLs, tw, height);
377 WMMoveWidget(panel->sizL, 10 + fw + 3 + tw + 3, 0);
378 WMResizeWidget(panel->sizL, sw + 4, LABEL_HEIGHT);
380 WMMoveWidget(panel->sizT, 10 + fw + 3 + tw + 3, 23);
381 WMResizeWidget(panel->sizT, sw + 4, 20);
383 WMMoveWidget(panel->sizLs, 10 + fw + 3 + tw + 3, 46);
384 WMResizeWidget(panel->sizLs, sw + 4, height - 23);
387 #define NUM_FIELDS 14
389 static int isXLFD(char *font, int *length_ret)
391 int c = 0;
393 *length_ret = 0;
394 while (*font) {
395 (*length_ret)++;
396 if (*font++ == '-')
397 c++;
400 return c == NUM_FIELDS;
403 typedef struct {
404 char *typeface;
405 WMArray *sizes;
406 } Typeface;
408 typedef struct {
409 char *name; /* gotta love simplicity */
410 WMArray *typefaces;
411 } Family;
413 static int compare_int(const void *a, const void *b)
415 int i1 = *(int *)a;
416 int i2 = *(int *)b;
418 if (i1 < i2)
419 return -1;
420 else if (i1 > i2)
421 return 1;
422 else
423 return 0;
426 static void addSizeToTypeface(Typeface * face, int size)
428 if (size == 0) {
429 int j;
431 for (j = 0; j < sizeof(scalableFontSizes) / sizeof(int); j++) {
432 size = scalableFontSizes[j];
434 if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
435 WMAddToArray(face->sizes, (void *)(uintptr_t) size);
438 WMSortArray(face->sizes, compare_int);
439 } else {
440 if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
441 WMAddToArray(face->sizes, (void *)(uintptr_t) size);
442 WMSortArray(face->sizes, compare_int);
447 static void addTypefaceToXftFamily(Family * fam, char *style)
449 Typeface *face;
450 WMArrayIterator i;
452 if (fam->typefaces) {
453 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
454 if (strcmp(face->typeface, style) != 0)
455 continue; /* go to next interation */
456 addSizeToTypeface(face, 0);
457 return;
459 } else {
460 fam->typefaces = WMCreateArray(4);
463 face = wmalloc(sizeof(Typeface));
465 face->typeface = wstrdup(style);
466 face->sizes = WMCreateArray(4);
467 addSizeToTypeface(face, 0);
469 WMAddToArray(fam->typefaces, face);
473 * families (same family name) (Hashtable of family -> array)
474 * registries (same family but different registries)
477 static void addFontToXftFamily(WMHashTable * families, char *name, char *style)
479 WMArrayIterator i;
480 WMArray *array;
481 Family *fam;
483 array = WMHashGet(families, name);
484 if (array) {
485 WM_ITERATE_ARRAY(array, fam, i) {
486 if (strcmp(fam->name, name) == 0)
487 addTypefaceToXftFamily(fam, style);
488 return;
492 array = WMCreateArray(8);
494 fam = wmalloc(sizeof(Family));
495 memset(fam, 0, sizeof(Family));
497 fam->name = wstrdup(name);
499 addTypefaceToXftFamily(fam, style);
501 WMAddToArray(array, fam);
503 WMHashInsert(families, fam->name, array);
506 static void listFamilies(WMScreen * scr, WMFontPanel * panel)
508 FcObjectSet *os = 0;
509 FcFontSet *fs;
510 FcPattern *pat;
511 WMHashTable *families;
512 WMHashEnumerator enumer;
513 WMArray *array;
514 int i;
516 pat = FcPatternCreate();
517 os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
518 fs = FcFontList(0, pat, os);
519 if (!fs) {
520 WMRunAlertPanel(scr, panel->win, _("Error"),
521 _("Could not init font config library\n"), _("OK"), NULL, NULL);
522 return;
524 if (pat)
525 FcPatternDestroy(pat);
527 families = WMCreateHashTable(WMStringPointerHashCallbacks);
529 if (fs) {
530 for (i = 0; i < fs->nfont; i++) {
531 FcChar8 *family;
532 FcChar8 *style;
534 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch)
535 if (FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch)
536 addFontToXftFamily(families, (char *)family, (char *)style);
538 FcFontSetDestroy(fs);
541 enumer = WMEnumerateHashTable(families);
543 while ((array = WMNextHashEnumeratorItem(&enumer))) {
544 WMArrayIterator i;
545 Family *fam;
546 char buffer[256];
547 WMListItem *item;
549 WM_ITERATE_ARRAY(array, fam, i) {
550 wstrlcpy(buffer, fam->name, sizeof(buffer));
551 item = WMAddListItem(panel->famLs, buffer);
553 item->clientData = fam;
556 WMFreeArray(array);
559 WMSortListItems(panel->famLs);
561 WMFreeHashTable(families);
564 static void getSelectedFont(FontPanel * panel, char buffer[], int bufsize)
566 WMListItem *item;
567 Family *family;
568 Typeface *face;
569 char *size;
571 item = WMGetListSelectedItem(panel->famLs);
572 if (!item)
573 return;
574 family = (Family *) item->clientData;
576 item = WMGetListSelectedItem(panel->typLs);
577 if (!item)
578 return;
579 face = (Typeface *) item->clientData;
581 size = WMGetTextFieldText(panel->sizT);
583 snprintf(buffer, bufsize, "%s:style=%s:pixelsize=%s", family->name, face->typeface, size);
585 wfree(size);
588 static void preview(FontPanel * panel)
590 char buffer[512];
591 WMFont *font;
593 getSelectedFont(panel, buffer, sizeof(buffer));
594 font = WMCreateFont(WMWidgetScreen(panel->win), buffer);
595 if (font) {
596 WMSetTextFieldFont(panel->sampleT, font);
597 WMReleaseFont(font);
601 static void familyClick(WMWidget * w, void *data)
603 WMList *lPtr = (WMList *) w;
604 WMListItem *item;
605 Family *family;
606 Typeface *face;
607 FontPanel *panel = (FontPanel *) data;
608 WMArrayIterator i;
609 /* current typeface and size */
610 char *oface = NULL;
611 char *osize = NULL;
612 int facei = -1;
613 int sizei = -1;
615 /* must try to keep the same typeface and size for the new family */
616 item = WMGetListSelectedItem(panel->typLs);
617 if (item)
618 oface = wstrdup(item->text);
620 osize = WMGetTextFieldText(panel->sizT);
622 item = WMGetListSelectedItem(lPtr);
623 family = (Family *) item->clientData;
625 WMClearList(panel->typLs);
627 WM_ITERATE_ARRAY(family->typefaces, face, i) {
628 char buffer[256];
629 int top = 0;
630 WMListItem *fitem;
632 wstrlcpy(buffer, face->typeface, sizeof(buffer));
633 if (strcasecmp(face->typeface, "Roman") == 0)
634 top = 1;
635 if (strcasecmp(face->typeface, "Regular") == 0)
636 top = 1;
637 if (top)
638 fitem = WMInsertListItem(panel->typLs, 0, buffer);
639 else
640 fitem = WMAddListItem(panel->typLs, buffer);
641 fitem->clientData = face;
644 if (oface) {
645 facei = WMFindRowOfListItemWithTitle(panel->typLs, oface);
646 wfree(oface);
648 if (facei < 0) {
649 facei = 0;
651 WMSelectListItem(panel->typLs, facei);
652 typefaceClick(panel->typLs, panel);
654 if (osize) {
655 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
657 if (sizei >= 0) {
658 WMSelectListItem(panel->sizLs, sizei);
659 sizeClick(panel->sizLs, panel);
662 if (osize)
663 wfree(osize);
665 preview(panel);
668 static void typefaceClick(WMWidget * w, void *data)
670 FontPanel *panel = (FontPanel *) data;
671 WMListItem *item;
672 Typeface *face;
673 WMArrayIterator i;
674 char buffer[32];
676 char *osize = NULL;
677 int sizei = -1;
678 void *size;
680 osize = WMGetTextFieldText(panel->sizT);
682 item = WMGetListSelectedItem(panel->typLs);
683 face = (Typeface *) item->clientData;
685 WMClearList(panel->sizLs);
687 WM_ITERATE_ARRAY(face->sizes, size, i) {
688 if ((uintptr_t)size != 0) {
689 sprintf(buffer, "%li", (uintptr_t)size);
691 WMAddListItem(panel->sizLs, buffer);
695 if (osize) {
696 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
698 if (sizei < 0) {
699 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, "12");
701 if (sizei < 0) {
702 sizei = 0;
704 WMSelectListItem(panel->sizLs, sizei);
705 WMSetListPosition(panel->sizLs, sizei);
706 sizeClick(panel->sizLs, panel);
708 if (osize)
709 wfree(osize);
711 preview(panel);
714 static void sizeClick(WMWidget * w, void *data)
716 FontPanel *panel = (FontPanel *) data;
717 WMListItem *item;
719 item = WMGetListSelectedItem(panel->sizLs);
720 WMSetTextFieldText(panel->sizT, item->text);
722 WMSelectTextFieldRange(panel->sizT, wmkrange(0, strlen(item->text)));
724 preview(panel);
727 static void setFontPanelFontName(FontPanel * panel, char *family, char *style, double size)
729 int famrow;
730 int stlrow;
731 int sz;
732 char asize[64];
733 void *vsize;
734 WMListItem *item;
735 Family *fam;
736 Typeface *face;
737 WMArrayIterator i;
739 famrow = WMFindRowOfListItemWithTitle(panel->famLs, family);
740 if (famrow < 0) {
741 famrow = 0;
742 return;
744 WMSelectListItem(panel->famLs, famrow);
745 WMSetListPosition(panel->famLs, famrow);
747 WMClearList(panel->typLs);
749 item = WMGetListSelectedItem(panel->famLs);
751 fam = (Family *) item->clientData;
752 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
753 char buffer[256];
754 int top = 0;
755 WMListItem *fitem;
757 wstrlcpy(buffer, face->typeface, sizeof(buffer));
758 if (strcasecmp(face->typeface, "Roman") == 0)
759 top = 1;
760 if (top)
761 fitem = WMInsertListItem(panel->typLs, 0, buffer);
762 else
763 fitem = WMAddListItem(panel->typLs, buffer);
764 fitem->clientData = face;
767 stlrow = WMFindRowOfListItemWithTitle(panel->typLs, style);
769 if (stlrow < 0) {
770 stlrow = 0;
771 return;
774 WMSelectListItem(panel->typLs, stlrow);
776 item = WMGetListSelectedItem(panel->typLs);
778 face = (Typeface *) item->clientData;
780 WMClearList(panel->sizLs);
782 WM_ITERATE_ARRAY(face->sizes, vsize, i) {
783 char buffer[32];
784 if ((uintptr_t)vsize != 0) {
785 sprintf(buffer, "%li", (uintptr_t)vsize);
787 WMAddListItem(panel->sizLs, buffer);
791 snprintf(asize, sizeof(asize) - 1, "%d", (int)(size + 0.5));
793 sz = WMFindRowOfListItemWithTitle(panel->sizLs, asize);
795 if (sz < 0) {
796 sz = 4;
797 return;
800 WMSelectListItem(panel->sizLs, sz);
801 sizeClick(panel->sizLs, panel);
803 return;