wmaker: Fix compiler warnings about pointer <--> integer conversion
[wmaker-crm.git] / WINGs / wfontpanel.c
blob537e54dd202a40675fc16720e93ea8c76baf8a1f
5 #include "WINGsP.h"
6 #include "WUtil.h"
7 #include "wconfig.h"
9 #include <ctype.h>
10 #include <string.h>
11 #include <stdint.h>
13 #include <X11/Xft/Xft.h>
14 #include <fontconfig/fontconfig.h>
17 /* XXX TODO */
18 char *WMFontPanelFontChangedNotification = "WMFontPanelFontChangedNotification";
23 typedef struct W_FontPanel {
24 WMWindow *win;
26 WMFrame *upperF;
27 WMTextField *sampleT;
29 WMSplitView *split;
31 WMFrame *lowerF;
32 WMLabel *famL;
33 WMList *famLs;
34 WMLabel *typL;
35 WMList *typLs;
36 WMLabel *sizL;
37 WMTextField *sizT;
38 WMList *sizLs;
40 WMAction2 *action;
41 void *data;
43 WMButton *revertB;
44 WMButton *setB;
46 WMPropList *fdb;
47 } FontPanel;
50 #define MIN_UPPER_HEIGHT 20
51 #define MIN_LOWER_HEIGHT 140
54 #define MAX_FONTS_TO_RETRIEVE 2000
56 #define BUTTON_SPACE_HEIGHT 40
58 #define MIN_WIDTH 250
59 #define MIN_HEIGHT (MIN_UPPER_HEIGHT+MIN_LOWER_HEIGHT+BUTTON_SPACE_HEIGHT)
61 #define DEF_UPPER_HEIGHT 60
62 #define DEF_LOWER_HEIGHT 310
64 #define DEF_WIDTH 320
65 #define DEF_HEIGHT (DEF_UPPER_HEIGHT+DEF_LOWER_HEIGHT)
70 static int scalableFontSizes[] = {
72 10,
73 11,
74 12,
75 14,
76 16,
77 18,
78 20,
79 24,
80 36,
81 48,
87 static void setFontPanelFontName(FontPanel *panel, char *family, char *style, double size);
89 static int isXLFD(char *font, int *length_ret);
91 static void arrangeLowerFrame(FontPanel *panel);
93 static void familyClick(WMWidget *, void *);
94 static void typefaceClick(WMWidget *, void *);
95 static void sizeClick(WMWidget *, void *);
98 static void listFamilies(WMScreen *scr, WMFontPanel *panel);
101 static void
102 splitViewConstrainCallback(WMSplitView *sPtr, int indView, int *min, int *max)
104 if (indView == 0)
105 *min = MIN_UPPER_HEIGHT;
106 else
107 *min = MIN_LOWER_HEIGHT;
110 static void
111 notificationObserver(void *self, WMNotification *notif)
113 WMFontPanel *panel = (WMFontPanel*)self;
114 void *object = WMGetNotificationObject(notif);
116 if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
117 if (object == WMWidgetView(panel->win)) {
118 int h = WMWidgetHeight(panel->win);
119 int w = WMWidgetWidth(panel->win);
121 WMResizeWidget(panel->split, w, h-BUTTON_SPACE_HEIGHT);
123 WMMoveWidget(panel->setB, w-80, h-(BUTTON_SPACE_HEIGHT-5));
125 WMMoveWidget(panel->revertB, w-240, h-(BUTTON_SPACE_HEIGHT-5));
127 } else if (object == WMWidgetView(panel->upperF)) {
129 if (WMWidgetHeight(panel->upperF) < MIN_UPPER_HEIGHT) {
130 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF),
131 MIN_UPPER_HEIGHT);
132 } else {
133 WMResizeWidget(panel->sampleT, WMWidgetWidth(panel->upperF)-20,
134 WMWidgetHeight(panel->upperF)-10);
137 } else if (object == WMWidgetView(panel->lowerF)) {
139 if (WMWidgetHeight(panel->lowerF) < MIN_LOWER_HEIGHT) {
140 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF),
141 MIN_UPPER_HEIGHT);
143 WMMoveWidget(panel->lowerF, 0, WMWidgetHeight(panel->upperF)
144 + WMGetSplitViewDividerThickness(panel->split));
146 WMResizeWidget(panel->lowerF, WMWidgetWidth(panel->lowerF),
147 WMWidgetWidth(panel->split) - MIN_UPPER_HEIGHT
148 - WMGetSplitViewDividerThickness(panel->split));
149 } else {
150 arrangeLowerFrame(panel);
157 static void
158 closeWindow(WMWidget *w, void *data)
160 FontPanel *panel = (FontPanel*)data;
162 WMHideFontPanel(panel);
168 static void
169 setClickedAction(WMWidget *w, void *data)
171 FontPanel *panel = (FontPanel*)data;
173 if (panel->action)
174 (*panel->action)(panel, panel->data);
178 static void
179 revertClickedAction(WMWidget *w, void *data)
181 /*FontPanel *panel = (FontPanel*)data;*/
182 /* XXX TODO */
187 WMFontPanel*
188 WMGetFontPanel(WMScreen *scr)
190 FontPanel *panel;
191 WMColor *dark, *white;
192 WMFont *font;
193 int divThickness;
195 if (scr->sharedFontPanel)
196 return scr->sharedFontPanel;
199 panel = wmalloc(sizeof(FontPanel));
200 memset(panel, 0, sizeof(FontPanel));
202 panel->win = WMCreateWindow(scr, "fontPanel");
203 /* WMSetWidgetBackgroundColor(panel->win, WMWhiteColor(scr));*/
204 WMSetWindowTitle(panel->win, _("Font Panel"));
205 WMResizeWidget(panel->win, DEF_WIDTH, DEF_HEIGHT);
206 WMSetWindowMinSize(panel->win, MIN_WIDTH, MIN_HEIGHT);
207 WMSetViewNotifySizeChanges(WMWidgetView(panel->win), True);
209 WMSetWindowCloseAction(panel->win, closeWindow, panel);
211 panel->split = WMCreateSplitView(panel->win);
212 WMResizeWidget(panel->split, DEF_WIDTH, DEF_HEIGHT - BUTTON_SPACE_HEIGHT);
213 WMSetSplitViewConstrainProc(panel->split, splitViewConstrainCallback);
215 divThickness = WMGetSplitViewDividerThickness(panel->split);
217 panel->upperF = WMCreateFrame(panel->win);
218 WMSetFrameRelief(panel->upperF, WRFlat);
219 WMSetViewNotifySizeChanges(WMWidgetView(panel->upperF), True);
220 panel->lowerF = WMCreateFrame(panel->win);
221 /* WMSetWidgetBackgroundColor(panel->lowerF, WMBlackColor(scr));*/
222 WMSetFrameRelief(panel->lowerF, WRFlat);
223 WMSetViewNotifySizeChanges(WMWidgetView(panel->lowerF), True);
225 WMAddSplitViewSubview(panel->split, W_VIEW(panel->upperF));
226 WMAddSplitViewSubview(panel->split, W_VIEW(panel->lowerF));
228 WMResizeWidget(panel->upperF, DEF_WIDTH, DEF_UPPER_HEIGHT);
230 WMResizeWidget(panel->lowerF, DEF_WIDTH, DEF_LOWER_HEIGHT);
232 WMMoveWidget(panel->lowerF, 0, 60+divThickness);
234 white = WMWhiteColor(scr);
235 dark = WMDarkGrayColor(scr);
237 panel->sampleT = WMCreateTextField(panel->upperF);
238 WMResizeWidget(panel->sampleT, DEF_WIDTH - 20, 50);
239 WMMoveWidget(panel->sampleT, 10, 10);
240 WMSetTextFieldText(panel->sampleT, _("The quick brown fox jumps over the lazy dog"));
242 font = WMBoldSystemFontOfSize(scr, 12);
244 panel->famL = WMCreateLabel(panel->lowerF);
245 WMSetWidgetBackgroundColor(panel->famL, dark);
246 WMSetLabelText(panel->famL, _("Family"));
247 WMSetLabelFont(panel->famL, font);
248 WMSetLabelTextColor(panel->famL, white);
249 WMSetLabelRelief(panel->famL, WRSunken);
250 WMSetLabelTextAlignment(panel->famL, WACenter);
252 panel->famLs = WMCreateList(panel->lowerF);
253 WMSetListAction(panel->famLs, familyClick, panel);
255 panel->typL = WMCreateLabel(panel->lowerF);
256 WMSetWidgetBackgroundColor(panel->typL, dark);
257 WMSetLabelText(panel->typL, _("Typeface"));
258 WMSetLabelFont(panel->typL, font);
259 WMSetLabelTextColor(panel->typL, white);
260 WMSetLabelRelief(panel->typL, WRSunken);
261 WMSetLabelTextAlignment(panel->typL, WACenter);
263 panel->typLs = WMCreateList(panel->lowerF);
264 WMSetListAction(panel->typLs, typefaceClick, panel);
266 panel->sizL = WMCreateLabel(panel->lowerF);
267 WMSetWidgetBackgroundColor(panel->sizL, dark);
268 WMSetLabelText(panel->sizL, _("Size"));
269 WMSetLabelFont(panel->sizL, font);
270 WMSetLabelTextColor(panel->sizL, white);
271 WMSetLabelRelief(panel->sizL, WRSunken);
272 WMSetLabelTextAlignment(panel->sizL, WACenter);
274 panel->sizT = WMCreateTextField(panel->lowerF);
275 /* WMSetTextFieldAlignment(panel->sizT, WARight);*/
277 panel->sizLs = WMCreateList(panel->lowerF);
278 WMSetListAction(panel->sizLs, sizeClick, panel);
280 WMReleaseFont(font);
281 WMReleaseColor(white);
282 WMReleaseColor(dark);
284 panel->setB = WMCreateCommandButton(panel->win);
285 WMResizeWidget(panel->setB, 70, 24);
286 WMMoveWidget(panel->setB, 240, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT-5));
287 WMSetButtonText(panel->setB, _("Set"));
288 WMSetButtonAction(panel->setB, setClickedAction, panel);
290 panel->revertB = WMCreateCommandButton(panel->win);
291 WMResizeWidget(panel->revertB, 70, 24);
292 WMMoveWidget(panel->revertB, 80, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT-5));
293 WMSetButtonText(panel->revertB, _("Revert"));
294 WMSetButtonAction(panel->revertB, revertClickedAction, panel);
297 WMRealizeWidget(panel->win);
299 WMMapSubwidgets(panel->upperF);
300 WMMapSubwidgets(panel->lowerF);
301 WMMapSubwidgets(panel->split);
302 WMMapSubwidgets(panel->win);
304 WMUnmapWidget(panel->revertB);
306 arrangeLowerFrame(panel);
308 scr->sharedFontPanel = panel;
311 /* register notification observers */
312 WMAddNotificationObserver(notificationObserver, panel,
313 WMViewSizeDidChangeNotification,
314 WMWidgetView(panel->win));
315 WMAddNotificationObserver(notificationObserver, panel,
316 WMViewSizeDidChangeNotification,
317 WMWidgetView(panel->upperF));
318 WMAddNotificationObserver(notificationObserver, panel,
319 WMViewSizeDidChangeNotification,
320 WMWidgetView(panel->lowerF));
323 listFamilies(scr, panel);
326 return panel;
330 void
331 WMFreeFontPanel(WMFontPanel *panel)
333 if (panel == WMWidgetScreen(panel->win)->sharedFontPanel) {
334 WMWidgetScreen(panel->win)->sharedFontPanel = NULL;
336 WMRemoveNotificationObserver(panel);
337 WMUnmapWidget(panel->win);
338 WMDestroyWidget(panel->win);
339 wfree(panel);
343 void
344 WMShowFontPanel(WMFontPanel *panel)
346 WMMapWidget(panel->win);
350 void
351 WMHideFontPanel(WMFontPanel *panel)
353 WMUnmapWidget(panel->win);
357 WMFont*
358 WMGetFontPanelFont(WMFontPanel *panel)
360 return WMGetTextFieldFont(panel->sampleT);
364 void
365 WMSetFontPanelFont(WMFontPanel *panel, char *fontName)
367 int fname_len;
368 FcPattern *pattern;
369 FcChar8 *family, *style;
370 double size;
372 if (!isXLFD(fontName, &fname_len)) {
373 /* maybe its proper fontconfig and we can parse it */
374 pattern = FcNameParse((FcChar8*)fontName);
375 } else {
376 /* maybe its proper xlfd and we can convert it to an FcPattern */
377 pattern = XftXlfdParse(fontName, False, False);
378 /*//FcPatternPrint(pattern);*/
381 if (!pattern)
382 return;
384 if (FcPatternGetString(pattern, FC_FAMILY, 0, &family)==FcResultMatch)
385 if (FcPatternGetString(pattern, FC_STYLE, 0, &style)==FcResultMatch)
386 if (FcPatternGetDouble(pattern, "pixelsize", 0, &size)==FcResultMatch)
387 setFontPanelFontName(panel, (char*)family, (char*)style, size);
389 FcPatternDestroy(pattern);
393 void
394 WMSetFontPanelAction(WMFontPanel *panel, WMAction2 *action, void *data)
396 panel->action = action;
397 panel->data = data;
404 static void
405 arrangeLowerFrame(FontPanel *panel)
407 int width = WMWidgetWidth(panel->lowerF) - 55 - 30;
408 int height = WMWidgetHeight(panel->split) - WMWidgetHeight(panel->upperF);
409 int fw, tw, sw;
411 #define LABEL_HEIGHT 20
413 height -= WMGetSplitViewDividerThickness(panel->split);
416 height -= LABEL_HEIGHT + 8;
418 fw = (125*width) / 235;
419 tw = (110*width) / 235;
420 sw = 55;
422 WMMoveWidget(panel->famL, 10, 0);
423 WMResizeWidget(panel->famL, fw, LABEL_HEIGHT);
425 WMMoveWidget(panel->famLs, 10, 23);
426 WMResizeWidget(panel->famLs, fw, height);
428 WMMoveWidget(panel->typL, 10+fw+3, 0);
429 WMResizeWidget(panel->typL, tw, LABEL_HEIGHT);
431 WMMoveWidget(panel->typLs, 10+fw+3, 23);
432 WMResizeWidget(panel->typLs, tw, height);
434 WMMoveWidget(panel->sizL, 10+fw+3+tw+3, 0);
435 WMResizeWidget(panel->sizL, sw+4, LABEL_HEIGHT);
437 WMMoveWidget(panel->sizT, 10+fw+3+tw+3, 23);
438 WMResizeWidget(panel->sizT, sw+4, 20);
440 WMMoveWidget(panel->sizLs, 10+fw+3+tw+3, 46);
441 WMResizeWidget(panel->sizLs, sw+4, height-23);
446 #define NUM_FIELDS 14
449 static int
450 isXLFD(char *font, int *length_ret)
452 int c = 0;
454 *length_ret = 0;
455 while (*font) {
456 (*length_ret)++;
457 if (*font++ == '-')
458 c++;
461 return c==NUM_FIELDS;
465 typedef struct {
466 char *typeface;
467 WMArray *sizes;
468 } Typeface;
470 typedef struct {
471 char *name; /* gotta love simplicity */
472 WMArray *typefaces;
473 } Family;
476 static int
477 compare_int(const void *a, const void *b)
479 int i1 = *(int*)a;
480 int i2 = *(int*)b;
482 if (i1 < i2)
483 return -1;
484 else if (i1 > i2)
485 return 1;
486 else
487 return 0;
491 static void
492 addSizeToTypeface(Typeface *face, int size)
494 if (size == 0) {
495 int j;
497 for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) {
498 size = scalableFontSizes[j];
500 if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) {
501 WMAddToArray(face->sizes, (void*)(uintptr_t)size);
504 WMSortArray(face->sizes, compare_int);
505 } else {
506 if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) {
507 WMAddToArray(face->sizes, (void*)(uintptr_t)size);
508 WMSortArray(face->sizes, compare_int);
513 static void
514 addTypefaceToXftFamily(Family *fam, char *style)
516 Typeface *face;
517 WMArrayIterator i;
519 if(fam->typefaces) {
520 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
521 if(strcmp(face->typeface, style) != 0)
522 continue; /* go to next interation */
523 addSizeToTypeface(face, 0);
524 return;
526 } else {
527 fam->typefaces = WMCreateArray(4);
530 face = wmalloc(sizeof(Typeface));
531 memset(face, 0 , sizeof(Typeface));
533 face->typeface = wstrdup(style);
534 face->sizes = WMCreateArray(4);
535 addSizeToTypeface(face, 0);
537 WMAddToArray(fam->typefaces, face);
541 * families (same family name) (Hashtable of family -> array)
542 * registries (same family but different registries)
545 static void
546 addFontToXftFamily(WMHashTable *families, char *name, char *style)
548 WMArrayIterator i;
549 WMArray *array;
550 Family *fam;
552 array = WMHashGet(families, name);
553 if(array) {
554 WM_ITERATE_ARRAY(array, fam, i) {
555 if(strcmp(fam->name, name) == 0 )
556 addTypefaceToXftFamily(fam, style);
557 return;
561 array = WMCreateArray(8);
563 fam = wmalloc(sizeof(Family));
564 memset(fam, 0, sizeof(Family));
566 fam->name = wstrdup(name);
568 addTypefaceToXftFamily(fam, style);
570 WMAddToArray(array, fam);
572 WMHashInsert(families, fam->name, array);
576 static void
577 listFamilies(WMScreen *scr, WMFontPanel *panel)
579 FcObjectSet *os = 0;
580 FcFontSet *fs;
581 FcPattern *pat;
582 WMHashTable *families;
583 WMHashEnumerator enumer;
584 WMArray *array;
585 int i;
587 pat = FcPatternCreate();
588 os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, 0);
589 fs = FcFontList(0, pat, os);
590 if (!fs) {
591 WMRunAlertPanel(scr, panel->win, _("Error"),
592 _("Could not init font config library\n"), _("OK"), NULL, NULL);
593 return;
595 if (pat)
596 FcPatternDestroy (pat);
598 families = WMCreateHashTable(WMStringPointerHashCallbacks);
600 if(fs) {
601 for (i = 0; i < fs->nfont; i++) {
602 FcChar8 *family;
603 FcChar8 *style;
605 if (FcPatternGetString(fs->fonts[i],FC_FAMILY,0,&family)==FcResultMatch)
606 if (FcPatternGetString(fs->fonts[i],FC_STYLE,0,&style)==FcResultMatch)
607 addFontToXftFamily(families, (char*)family, (char*)style);
609 FcFontSetDestroy(fs);
612 enumer = WMEnumerateHashTable(families);
614 while ((array = WMNextHashEnumeratorItem(&enumer))) {
615 WMArrayIterator i;
616 Family *fam;
617 char buffer[256];
618 WMListItem *item;
620 WM_ITERATE_ARRAY(array, fam, i) {
621 strcpy(buffer, fam->name);
622 item = WMAddListItem(panel->famLs, buffer);
624 item->clientData = fam;
627 WMFreeArray(array);
630 WMSortListItems(panel->famLs);
632 WMFreeHashTable(families);
636 static void
637 getSelectedFont(FontPanel *panel, char buffer[], int bufsize)
639 WMListItem *item;
640 Family *family;
641 Typeface *face;
642 char *size;
645 item = WMGetListSelectedItem(panel->famLs);
646 if (!item)
647 return;
648 family = (Family*)item->clientData;
650 item = WMGetListSelectedItem(panel->typLs);
651 if (!item)
652 return;
653 face = (Typeface*)item->clientData;
655 size = WMGetTextFieldText(panel->sizT);
657 snprintf(buffer, bufsize, "%s:style=%s:pixelsize=%s",
658 family->name,
659 face->typeface,
660 size);
662 wfree(size);
667 static void
668 preview(FontPanel *panel)
670 char buffer[512];
671 WMFont *font;
673 getSelectedFont(panel, buffer, sizeof(buffer));
674 font = WMCreateFont(WMWidgetScreen(panel->win), buffer);
675 if (font) {
676 WMSetTextFieldFont(panel->sampleT, font);
677 WMReleaseFont(font);
683 static void
684 familyClick(WMWidget *w, void *data)
686 WMList *lPtr = (WMList*)w;
687 WMListItem *item;
688 Family *family;
689 Typeface *face;
690 FontPanel *panel = (FontPanel*)data;
691 WMArrayIterator i;
692 /* current typeface and size */
693 char *oface = NULL;
694 char *osize = NULL;
695 int facei = -1;
696 int sizei = -1;
698 /* must try to keep the same typeface and size for the new family */
699 item = WMGetListSelectedItem(panel->typLs);
700 if (item)
701 oface = wstrdup(item->text);
703 osize = WMGetTextFieldText(panel->sizT);
706 item = WMGetListSelectedItem(lPtr);
707 family = (Family*)item->clientData;
709 WMClearList(panel->typLs);
712 WM_ITERATE_ARRAY(family->typefaces, face, i) {
713 char buffer[256];
714 int top=0;
715 WMListItem *fitem;
717 strcpy(buffer, face->typeface);
718 if(strcasecmp(face->typeface, "Roman") == 0)
719 top = 1;
720 if(strcasecmp(face->typeface, "Regular") == 0)
721 top = 1;
722 if (top)
723 fitem = WMInsertListItem(panel->typLs, 0, buffer);
724 else
725 fitem = WMAddListItem(panel->typLs, buffer);
726 fitem->clientData = face;
729 if (oface) {
730 facei = WMFindRowOfListItemWithTitle(panel->typLs, oface);
731 wfree(oface);
733 if (facei < 0) {
734 facei = 0;
736 WMSelectListItem(panel->typLs, facei);
737 typefaceClick(panel->typLs, panel);
739 if (osize) {
740 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
742 if (sizei >= 0) {
743 WMSelectListItem(panel->sizLs, sizei);
744 sizeClick(panel->sizLs, panel);
747 if (osize)
748 wfree(osize);
751 preview(panel);
755 static void
756 typefaceClick(WMWidget *w, void *data)
758 FontPanel *panel = (FontPanel*)data;
759 WMListItem *item;
760 Typeface *face;
761 WMArrayIterator i;
762 char buffer[32];
764 char *osize = NULL;
765 int sizei = -1;
766 void *size;
768 osize = WMGetTextFieldText(panel->sizT);
771 item = WMGetListSelectedItem(panel->typLs);
772 face = (Typeface*)item->clientData;
774 WMClearList(panel->sizLs);
776 WM_ITERATE_ARRAY(face->sizes, size, i) {
777 if ((int)(uintptr_t)size != 0) {
778 sprintf(buffer, "%i", (int)(uintptr_t)size);
780 WMAddListItem(panel->sizLs, buffer);
784 if (osize) {
785 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
787 if (sizei < 0) {
788 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, "12");
790 if (sizei < 0) {
791 sizei = 0;
793 WMSelectListItem(panel->sizLs, sizei);
794 WMSetListPosition(panel->sizLs, sizei);
795 sizeClick(panel->sizLs, panel);
797 if (osize)
798 wfree(osize);
800 preview(panel);
803 static void
804 sizeClick(WMWidget *w, void *data)
806 FontPanel *panel = (FontPanel*)data;
807 WMListItem *item;
809 item = WMGetListSelectedItem(panel->sizLs);
810 WMSetTextFieldText(panel->sizT, item->text);
812 WMSelectTextFieldRange(panel->sizT, wmkrange(0, strlen(item->text)));
814 preview(panel);
818 static void
819 setFontPanelFontName(FontPanel *panel, char *family, char *style, double size)
821 int famrow;
822 int stlrow;
823 int sz;
824 char asize[64];
825 void *vsize;
826 WMListItem *item;
827 Family *fam;
828 Typeface *face;
829 WMArrayIterator i;
831 famrow = WMFindRowOfListItemWithTitle(panel->famLs, family);
832 if (famrow < 0 ){
833 famrow = 0;
834 return;
836 WMSelectListItem(panel->famLs, famrow);
837 WMSetListPosition(panel->famLs, famrow);
839 WMClearList(panel->typLs);
841 item = WMGetListSelectedItem(panel->famLs);
843 fam = (Family*)item->clientData;
844 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
845 char buffer[256];
846 int top=0;
847 WMListItem *fitem;
849 strcpy(buffer, face->typeface);
850 if(strcasecmp(face->typeface, "Roman") == 0)
851 top = 1;
852 if (top)
853 fitem = WMInsertListItem(panel->typLs, 0, buffer);
854 else
855 fitem = WMAddListItem(panel->typLs, buffer);
856 fitem->clientData = face;
860 stlrow = WMFindRowOfListItemWithTitle(panel->typLs, style);
862 if (stlrow < 0) {
863 stlrow = 0;
864 return;
867 WMSelectListItem(panel->typLs, stlrow);
869 item = WMGetListSelectedItem(panel->typLs);
871 face = (Typeface*)item->clientData;
873 WMClearList(panel->sizLs);
876 WM_ITERATE_ARRAY(face->sizes, vsize, i) {
877 char buffer[32];
878 if ((int)(uintptr_t)vsize != 0) {
879 sprintf(buffer, "%i", (int)(uintptr_t)vsize);
881 WMAddListItem(panel->sizLs, buffer);
885 snprintf(asize, sizeof(asize)-1, "%d",(int)(size+0.5));
887 sz = WMFindRowOfListItemWithTitle(panel->sizLs, asize);
889 if (sz < 0) {
890 sz = 4;
891 return;
894 WMSelectListItem(panel->sizLs, sz);
895 sizeClick(panel->sizLs, panel);
897 return;