Fix periodic focus bug
[wmaker-crm.git] / WINGs / wfontpanel.c
blobc9909055e71a2bacfde2d57927c37d0c9a932744
5 #include "WINGsP.h"
6 #include "WUtil.h"
7 #include "wconfig.h"
9 #include <ctype.h>
10 #include <string.h>
12 #include <X11/Xft/Xft.h>
13 #include <fontconfig/fontconfig.h>
16 /* XXX TODO */
17 char *WMFontPanelFontChangedNotification = "WMFontPanelFontChangedNotification";
22 typedef struct W_FontPanel {
23 WMWindow *win;
25 WMFrame *upperF;
26 WMTextField *sampleT;
28 WMSplitView *split;
30 WMFrame *lowerF;
31 WMLabel *famL;
32 WMList *famLs;
33 WMLabel *typL;
34 WMList *typLs;
35 WMLabel *sizL;
36 WMTextField *sizT;
37 WMList *sizLs;
39 WMAction2 *action;
40 void *data;
42 WMButton *revertB;
43 WMButton *setB;
45 WMPropList *fdb;
46 } FontPanel;
49 #define MIN_UPPER_HEIGHT 20
50 #define MIN_LOWER_HEIGHT 140
53 #define MAX_FONTS_TO_RETRIEVE 2000
55 #define BUTTON_SPACE_HEIGHT 40
57 #define MIN_WIDTH 250
58 #define MIN_HEIGHT (MIN_UPPER_HEIGHT+MIN_LOWER_HEIGHT+BUTTON_SPACE_HEIGHT)
60 #define DEF_UPPER_HEIGHT 60
61 #define DEF_LOWER_HEIGHT 310
63 #define DEF_WIDTH 320
64 #define DEF_HEIGHT (DEF_UPPER_HEIGHT+DEF_LOWER_HEIGHT)
69 static int scalableFontSizes[] = {
71 10,
72 11,
73 12,
74 14,
75 16,
76 18,
77 20,
78 24,
79 36,
80 48,
86 static void setFontPanelFontName(FontPanel *panel, char *family, char *style, double size);
88 static int isXLFD(char *font, int *length_ret);
90 static void arrangeLowerFrame(FontPanel *panel);
92 static void familyClick(WMWidget *, void *);
93 static void typefaceClick(WMWidget *, void *);
94 static void sizeClick(WMWidget *, void *);
97 static void listFamilies(WMScreen *scr, WMFontPanel *panel);
100 static void
101 splitViewConstrainCallback(WMSplitView *sPtr, int indView, int *min, int *max)
103 if (indView == 0)
104 *min = MIN_UPPER_HEIGHT;
105 else
106 *min = MIN_LOWER_HEIGHT;
109 static void
110 notificationObserver(void *self, WMNotification *notif)
112 WMFontPanel *panel = (WMFontPanel*)self;
113 void *object = WMGetNotificationObject(notif);
115 if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
116 if (object == WMWidgetView(panel->win)) {
117 int h = WMWidgetHeight(panel->win);
118 int w = WMWidgetWidth(panel->win);
120 WMResizeWidget(panel->split, w, h-BUTTON_SPACE_HEIGHT);
122 WMMoveWidget(panel->setB, w-80, h-(BUTTON_SPACE_HEIGHT-5));
124 WMMoveWidget(panel->revertB, w-240, h-(BUTTON_SPACE_HEIGHT-5));
126 } else if (object == WMWidgetView(panel->upperF)) {
128 if (WMWidgetHeight(panel->upperF) < MIN_UPPER_HEIGHT) {
129 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF),
130 MIN_UPPER_HEIGHT);
131 } else {
132 WMResizeWidget(panel->sampleT, WMWidgetWidth(panel->upperF)-20,
133 WMWidgetHeight(panel->upperF)-10);
136 } else if (object == WMWidgetView(panel->lowerF)) {
138 if (WMWidgetHeight(panel->lowerF) < MIN_LOWER_HEIGHT) {
139 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF),
140 MIN_UPPER_HEIGHT);
142 WMMoveWidget(panel->lowerF, 0, WMWidgetHeight(panel->upperF)
143 + WMGetSplitViewDividerThickness(panel->split));
145 WMResizeWidget(panel->lowerF, WMWidgetWidth(panel->lowerF),
146 WMWidgetWidth(panel->split) - MIN_UPPER_HEIGHT
147 - WMGetSplitViewDividerThickness(panel->split));
148 } else {
149 arrangeLowerFrame(panel);
156 static void
157 closeWindow(WMWidget *w, void *data)
159 FontPanel *panel = (FontPanel*)data;
161 WMHideFontPanel(panel);
167 static void
168 setClickedAction(WMWidget *w, void *data)
170 FontPanel *panel = (FontPanel*)data;
172 if (panel->action)
173 (*panel->action)(panel, panel->data);
177 static void
178 revertClickedAction(WMWidget *w, void *data)
180 /*FontPanel *panel = (FontPanel*)data;*/
181 /* XXX TODO */
186 WMFontPanel*
187 WMGetFontPanel(WMScreen *scr)
189 FontPanel *panel;
190 WMColor *dark, *white;
191 WMFont *font;
192 int divThickness;
194 if (scr->sharedFontPanel)
195 return scr->sharedFontPanel;
198 panel = wmalloc(sizeof(FontPanel));
199 memset(panel, 0, sizeof(FontPanel));
201 panel->win = WMCreateWindow(scr, "fontPanel");
202 /* WMSetWidgetBackgroundColor(panel->win, WMWhiteColor(scr));*/
203 WMSetWindowTitle(panel->win, _("Font Panel"));
204 WMResizeWidget(panel->win, DEF_WIDTH, DEF_HEIGHT);
205 WMSetWindowMinSize(panel->win, MIN_WIDTH, MIN_HEIGHT);
206 WMSetViewNotifySizeChanges(WMWidgetView(panel->win), True);
208 WMSetWindowCloseAction(panel->win, closeWindow, panel);
210 panel->split = WMCreateSplitView(panel->win);
211 WMResizeWidget(panel->split, DEF_WIDTH, DEF_HEIGHT - BUTTON_SPACE_HEIGHT);
212 WMSetSplitViewConstrainProc(panel->split, splitViewConstrainCallback);
214 divThickness = WMGetSplitViewDividerThickness(panel->split);
216 panel->upperF = WMCreateFrame(panel->win);
217 WMSetFrameRelief(panel->upperF, WRFlat);
218 WMSetViewNotifySizeChanges(WMWidgetView(panel->upperF), True);
219 panel->lowerF = WMCreateFrame(panel->win);
220 /* WMSetWidgetBackgroundColor(panel->lowerF, WMBlackColor(scr));*/
221 WMSetFrameRelief(panel->lowerF, WRFlat);
222 WMSetViewNotifySizeChanges(WMWidgetView(panel->lowerF), True);
224 WMAddSplitViewSubview(panel->split, W_VIEW(panel->upperF));
225 WMAddSplitViewSubview(panel->split, W_VIEW(panel->lowerF));
227 WMResizeWidget(panel->upperF, DEF_WIDTH, DEF_UPPER_HEIGHT);
229 WMResizeWidget(panel->lowerF, DEF_WIDTH, DEF_LOWER_HEIGHT);
231 WMMoveWidget(panel->lowerF, 0, 60+divThickness);
233 white = WMWhiteColor(scr);
234 dark = WMDarkGrayColor(scr);
236 panel->sampleT = WMCreateTextField(panel->upperF);
237 WMResizeWidget(panel->sampleT, DEF_WIDTH - 20, 50);
238 WMMoveWidget(panel->sampleT, 10, 10);
239 WMSetTextFieldText(panel->sampleT, _("The quick brown fox jumps over the lazy dog"));
241 font = WMBoldSystemFontOfSize(scr, 12);
243 panel->famL = WMCreateLabel(panel->lowerF);
244 WMSetWidgetBackgroundColor(panel->famL, dark);
245 WMSetLabelText(panel->famL, _("Family"));
246 WMSetLabelFont(panel->famL, font);
247 WMSetLabelTextColor(panel->famL, white);
248 WMSetLabelRelief(panel->famL, WRSunken);
249 WMSetLabelTextAlignment(panel->famL, WACenter);
251 panel->famLs = WMCreateList(panel->lowerF);
252 WMSetListAction(panel->famLs, familyClick, panel);
254 panel->typL = WMCreateLabel(panel->lowerF);
255 WMSetWidgetBackgroundColor(panel->typL, dark);
256 WMSetLabelText(panel->typL, _("Typeface"));
257 WMSetLabelFont(panel->typL, font);
258 WMSetLabelTextColor(panel->typL, white);
259 WMSetLabelRelief(panel->typL, WRSunken);
260 WMSetLabelTextAlignment(panel->typL, WACenter);
262 panel->typLs = WMCreateList(panel->lowerF);
263 WMSetListAction(panel->typLs, typefaceClick, panel);
265 panel->sizL = WMCreateLabel(panel->lowerF);
266 WMSetWidgetBackgroundColor(panel->sizL, dark);
267 WMSetLabelText(panel->sizL, _("Size"));
268 WMSetLabelFont(panel->sizL, font);
269 WMSetLabelTextColor(panel->sizL, white);
270 WMSetLabelRelief(panel->sizL, WRSunken);
271 WMSetLabelTextAlignment(panel->sizL, WACenter);
273 panel->sizT = WMCreateTextField(panel->lowerF);
274 /* WMSetTextFieldAlignment(panel->sizT, WARight);*/
276 panel->sizLs = WMCreateList(panel->lowerF);
277 WMSetListAction(panel->sizLs, sizeClick, panel);
279 WMReleaseFont(font);
280 WMReleaseColor(white);
281 WMReleaseColor(dark);
283 panel->setB = WMCreateCommandButton(panel->win);
284 WMResizeWidget(panel->setB, 70, 24);
285 WMMoveWidget(panel->setB, 240, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT-5));
286 WMSetButtonText(panel->setB, _("Set"));
287 WMSetButtonAction(panel->setB, setClickedAction, panel);
289 panel->revertB = WMCreateCommandButton(panel->win);
290 WMResizeWidget(panel->revertB, 70, 24);
291 WMMoveWidget(panel->revertB, 80, DEF_HEIGHT - (BUTTON_SPACE_HEIGHT-5));
292 WMSetButtonText(panel->revertB, _("Revert"));
293 WMSetButtonAction(panel->revertB, revertClickedAction, panel);
296 WMRealizeWidget(panel->win);
298 WMMapSubwidgets(panel->upperF);
299 WMMapSubwidgets(panel->lowerF);
300 WMMapSubwidgets(panel->split);
301 WMMapSubwidgets(panel->win);
303 WMUnmapWidget(panel->revertB);
305 arrangeLowerFrame(panel);
307 scr->sharedFontPanel = panel;
310 /* register notification observers */
311 WMAddNotificationObserver(notificationObserver, panel,
312 WMViewSizeDidChangeNotification,
313 WMWidgetView(panel->win));
314 WMAddNotificationObserver(notificationObserver, panel,
315 WMViewSizeDidChangeNotification,
316 WMWidgetView(panel->upperF));
317 WMAddNotificationObserver(notificationObserver, panel,
318 WMViewSizeDidChangeNotification,
319 WMWidgetView(panel->lowerF));
322 listFamilies(scr, panel);
325 return panel;
329 void
330 WMFreeFontPanel(WMFontPanel *panel)
332 if (panel == WMWidgetScreen(panel->win)->sharedFontPanel) {
333 WMWidgetScreen(panel->win)->sharedFontPanel = NULL;
335 WMRemoveNotificationObserver(panel);
336 WMUnmapWidget(panel->win);
337 WMDestroyWidget(panel->win);
338 wfree(panel);
342 void
343 WMShowFontPanel(WMFontPanel *panel)
345 WMMapWidget(panel->win);
349 void
350 WMHideFontPanel(WMFontPanel *panel)
352 WMUnmapWidget(panel->win);
356 WMFont*
357 WMGetFontPanelFont(WMFontPanel *panel)
359 return WMGetTextFieldFont(panel->sampleT);
363 void
364 WMSetFontPanelFont(WMFontPanel *panel, char *fontName)
366 int fname_len;
367 FcPattern *pattern;
368 FcChar8 *family, *style;
369 double size;
371 if (!isXLFD(fontName, &fname_len)) {
372 /* maybe its proper fontconfig and we can parse it */
373 pattern = FcNameParse((FcChar8*)fontName);
374 } else {
375 /* maybe its proper xlfd and we can convert it to an FcPattern */
376 pattern = XftXlfdParse(fontName, False, False);
377 /*//FcPatternPrint(pattern);*/
380 if (!pattern)
381 return;
383 if (FcPatternGetString(pattern, FC_FAMILY, 0, &family)==FcResultMatch)
384 if (FcPatternGetString(pattern, FC_STYLE, 0, &style)==FcResultMatch)
385 if (FcPatternGetDouble(pattern, "pixelsize", 0, &size)==FcResultMatch)
386 setFontPanelFontName(panel, (char*)family, (char*)style, size);
388 FcPatternDestroy(pattern);
392 void
393 WMSetFontPanelAction(WMFontPanel *panel, WMAction2 *action, void *data)
395 panel->action = action;
396 panel->data = data;
403 static void
404 arrangeLowerFrame(FontPanel *panel)
406 int width = WMWidgetWidth(panel->lowerF) - 55 - 30;
407 int height = WMWidgetHeight(panel->split) - WMWidgetHeight(panel->upperF);
408 int fw, tw, sw;
410 #define LABEL_HEIGHT 20
412 height -= WMGetSplitViewDividerThickness(panel->split);
415 height -= LABEL_HEIGHT + 8;
417 fw = (125*width) / 235;
418 tw = (110*width) / 235;
419 sw = 55;
421 WMMoveWidget(panel->famL, 10, 0);
422 WMResizeWidget(panel->famL, fw, LABEL_HEIGHT);
424 WMMoveWidget(panel->famLs, 10, 23);
425 WMResizeWidget(panel->famLs, fw, height);
427 WMMoveWidget(panel->typL, 10+fw+3, 0);
428 WMResizeWidget(panel->typL, tw, LABEL_HEIGHT);
430 WMMoveWidget(panel->typLs, 10+fw+3, 23);
431 WMResizeWidget(panel->typLs, tw, height);
433 WMMoveWidget(panel->sizL, 10+fw+3+tw+3, 0);
434 WMResizeWidget(panel->sizL, sw+4, LABEL_HEIGHT);
436 WMMoveWidget(panel->sizT, 10+fw+3+tw+3, 23);
437 WMResizeWidget(panel->sizT, sw+4, 20);
439 WMMoveWidget(panel->sizLs, 10+fw+3+tw+3, 46);
440 WMResizeWidget(panel->sizLs, sw+4, height-23);
445 #define NUM_FIELDS 14
448 static int
449 isXLFD(char *font, int *length_ret)
451 int c = 0;
453 *length_ret = 0;
454 while (*font) {
455 (*length_ret)++;
456 if (*font++ == '-')
457 c++;
460 return c==NUM_FIELDS;
464 typedef struct {
465 char *typeface;
466 WMArray *sizes;
467 } Typeface;
469 typedef struct {
470 char *name; /* gotta love simplicity */
471 WMArray *typefaces;
472 } Family;
475 static int
476 compare_int(const void *a, const void *b)
478 int i1 = *(int*)a;
479 int i2 = *(int*)b;
481 if (i1 < i2)
482 return -1;
483 else if (i1 > i2)
484 return 1;
485 else
486 return 0;
490 static void
491 addSizeToTypeface(Typeface *face, int size)
493 if (size == 0) {
494 int j;
496 for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) {
497 size = scalableFontSizes[j];
499 if (!WMCountInArray(face->sizes, (void*)size)) {
500 WMAddToArray(face->sizes, (void*)size);
503 WMSortArray(face->sizes, compare_int);
504 } else {
505 if (!WMCountInArray(face->sizes, (void*)size)) {
506 WMAddToArray(face->sizes, (void*)size);
507 WMSortArray(face->sizes, compare_int);
512 static void
513 addTypefaceToXftFamily(Family *fam, char *style)
515 Typeface *face;
516 WMArrayIterator i;
518 if(fam->typefaces) {
519 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
520 if(strcmp(face->typeface, style) != 0)
521 continue; /* go to next interation */
522 addSizeToTypeface(face, 0);
523 return;
525 } else {
526 fam->typefaces = WMCreateArray(4);
529 face = wmalloc(sizeof(Typeface));
530 memset(face, 0 , sizeof(Typeface));
532 face->typeface = wstrdup(style);
533 face->sizes = WMCreateArray(4);
534 addSizeToTypeface(face, 0);
536 WMAddToArray(fam->typefaces, face);
540 * families (same family name) (Hashtable of family -> array)
541 * registries (same family but different registries)
544 static void
545 addFontToXftFamily(WMHashTable *families, char *name, char *style)
547 WMArrayIterator i;
548 WMArray *array;
549 Family *fam;
551 array = WMHashGet(families, name);
552 if(array) {
553 WM_ITERATE_ARRAY(array, fam, i) {
554 if(strcmp(fam->name, name) == 0 )
555 addTypefaceToXftFamily(fam, style);
556 return;
560 array = WMCreateArray(8);
562 fam = wmalloc(sizeof(Family));
563 memset(fam, 0, sizeof(Family));
565 fam->name = wstrdup(name);
567 addTypefaceToXftFamily(fam, style);
569 WMAddToArray(array, fam);
571 WMHashInsert(families, fam->name, array);
575 static void
576 listFamilies(WMScreen *scr, WMFontPanel *panel)
578 FcObjectSet *os = 0;
579 FcFontSet *fs;
580 FcPattern *pat;
581 WMHashTable *families;
582 WMHashEnumerator enumer;
583 WMArray *array;
584 int i;
586 pat = FcPatternCreate();
587 os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, 0);
588 fs = FcFontList(0, pat, os);
589 if (!fs) {
590 WMRunAlertPanel(scr, panel->win, _("Error"),
591 _("Could not init font config library\n"), _("OK"), NULL, NULL);
592 return;
594 if (pat)
595 FcPatternDestroy (pat);
597 families = WMCreateHashTable(WMStringPointerHashCallbacks);
599 if(fs) {
600 for (i = 0; i < fs->nfont; i++) {
601 FcChar8 *family;
602 FcChar8 *style;
604 if (FcPatternGetString(fs->fonts[i],FC_FAMILY,0,&family)==FcResultMatch)
605 if (FcPatternGetString(fs->fonts[i],FC_STYLE,0,&style)==FcResultMatch)
606 addFontToXftFamily(families, (char*)family, (char*)style);
608 FcFontSetDestroy(fs);
611 enumer = WMEnumerateHashTable(families);
613 while ((array = WMNextHashEnumeratorItem(&enumer))) {
614 WMArrayIterator i;
615 Family *fam;
616 char buffer[256];
617 WMListItem *item;
619 WM_ITERATE_ARRAY(array, fam, i) {
620 strcpy(buffer, fam->name);
621 item = WMAddListItem(panel->famLs, buffer);
623 item->clientData = fam;
626 WMFreeArray(array);
629 WMSortListItems(panel->famLs);
631 WMFreeHashTable(families);
635 static void
636 getSelectedFont(FontPanel *panel, char buffer[], int bufsize)
638 WMListItem *item;
639 Family *family;
640 Typeface *face;
641 char *size;
644 item = WMGetListSelectedItem(panel->famLs);
645 if (!item)
646 return;
647 family = (Family*)item->clientData;
649 item = WMGetListSelectedItem(panel->typLs);
650 if (!item)
651 return;
652 face = (Typeface*)item->clientData;
654 size = WMGetTextFieldText(panel->sizT);
656 snprintf(buffer, bufsize, "%s:style=%s:pixelsize=%s",
657 family->name,
658 face->typeface,
659 size);
661 wfree(size);
666 static void
667 preview(FontPanel *panel)
669 char buffer[512];
670 WMFont *font;
672 getSelectedFont(panel, buffer, sizeof(buffer));
673 font = WMCreateFont(WMWidgetScreen(panel->win), buffer);
674 if (font) {
675 WMSetTextFieldFont(panel->sampleT, font);
676 WMReleaseFont(font);
682 static void
683 familyClick(WMWidget *w, void *data)
685 WMList *lPtr = (WMList*)w;
686 WMListItem *item;
687 Family *family;
688 Typeface *face;
689 FontPanel *panel = (FontPanel*)data;
690 WMArrayIterator i;
691 /* current typeface and size */
692 char *oface = NULL;
693 char *osize = NULL;
694 int facei = -1;
695 int sizei = -1;
697 /* must try to keep the same typeface and size for the new family */
698 item = WMGetListSelectedItem(panel->typLs);
699 if (item)
700 oface = wstrdup(item->text);
702 osize = WMGetTextFieldText(panel->sizT);
705 item = WMGetListSelectedItem(lPtr);
706 family = (Family*)item->clientData;
708 WMClearList(panel->typLs);
711 WM_ITERATE_ARRAY(family->typefaces, face, i) {
712 char buffer[256];
713 int top=0;
714 WMListItem *fitem;
716 strcpy(buffer, face->typeface);
717 if(strcasecmp(face->typeface, "Roman") == 0)
718 top = 1;
719 if(strcasecmp(face->typeface, "Regular") == 0)
720 top = 1;
721 if (top)
722 fitem = WMInsertListItem(panel->typLs, 0, buffer);
723 else
724 fitem = WMAddListItem(panel->typLs, buffer);
725 fitem->clientData = face;
728 if (oface) {
729 facei = WMFindRowOfListItemWithTitle(panel->typLs, oface);
730 wfree(oface);
732 if (facei < 0) {
733 facei = 0;
735 WMSelectListItem(panel->typLs, facei);
736 typefaceClick(panel->typLs, panel);
738 if (osize) {
739 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
741 if (sizei >= 0) {
742 WMSelectListItem(panel->sizLs, sizei);
743 sizeClick(panel->sizLs, panel);
746 if (osize)
747 wfree(osize);
750 preview(panel);
754 static void
755 typefaceClick(WMWidget *w, void *data)
757 FontPanel *panel = (FontPanel*)data;
758 WMListItem *item;
759 Typeface *face;
760 WMArrayIterator i;
761 char buffer[32];
763 char *osize = NULL;
764 int sizei = -1;
765 void *size;
767 osize = WMGetTextFieldText(panel->sizT);
770 item = WMGetListSelectedItem(panel->typLs);
771 face = (Typeface*)item->clientData;
773 WMClearList(panel->sizLs);
775 WM_ITERATE_ARRAY(face->sizes, size, i) {
776 if ((int)size != 0) {
777 sprintf(buffer, "%i", (int)size);
779 WMAddListItem(panel->sizLs, buffer);
783 if (osize) {
784 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
786 if (sizei < 0) {
787 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, "12");
789 if (sizei < 0) {
790 sizei = 0;
792 WMSelectListItem(panel->sizLs, sizei);
793 WMSetListPosition(panel->sizLs, sizei);
794 sizeClick(panel->sizLs, panel);
796 if (osize)
797 wfree(osize);
799 preview(panel);
802 static void
803 sizeClick(WMWidget *w, void *data)
805 FontPanel *panel = (FontPanel*)data;
806 WMListItem *item;
808 item = WMGetListSelectedItem(panel->sizLs);
809 WMSetTextFieldText(panel->sizT, item->text);
811 WMSelectTextFieldRange(panel->sizT, wmkrange(0, strlen(item->text)));
813 preview(panel);
817 static void
818 setFontPanelFontName(FontPanel *panel, char *family, char *style, double size)
820 int famrow;
821 int stlrow;
822 int sz;
823 char asize[64];
824 void *vsize;
825 WMListItem *item;
826 Family *fam;
827 Typeface *face;
828 WMArrayIterator i;
830 famrow = WMFindRowOfListItemWithTitle(panel->famLs, family);
831 if (famrow < 0 ){
832 famrow = 0;
833 return;
835 WMSelectListItem(panel->famLs, famrow);
836 WMSetListPosition(panel->famLs, famrow);
838 WMClearList(panel->typLs);
840 item = WMGetListSelectedItem(panel->famLs);
842 fam = (Family*)item->clientData;
843 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
844 char buffer[256];
845 int top=0;
846 WMListItem *fitem;
848 strcpy(buffer, face->typeface);
849 if(strcasecmp(face->typeface, "Roman") == 0)
850 top = 1;
851 if (top)
852 fitem = WMInsertListItem(panel->typLs, 0, buffer);
853 else
854 fitem = WMAddListItem(panel->typLs, buffer);
855 fitem->clientData = face;
859 stlrow = WMFindRowOfListItemWithTitle(panel->typLs, style);
861 if (stlrow < 0) {
862 stlrow = 0;
863 return;
866 WMSelectListItem(panel->typLs, stlrow);
868 item = WMGetListSelectedItem(panel->typLs);
870 face = (Typeface*)item->clientData;
872 WMClearList(panel->sizLs);
875 WM_ITERATE_ARRAY(face->sizes, vsize, i) {
876 char buffer[32];
877 if ((int)vsize != 0) {
878 sprintf(buffer, "%i", (int)vsize);
880 WMAddListItem(panel->sizLs, buffer);
884 snprintf(asize, sizeof(asize)-1, "%d",(int)(size+0.5));
886 sz = WMFindRowOfListItemWithTitle(panel->sizLs, asize);
888 if (sz < 0) {
889 sz = 4;
890 return;
893 WMSelectListItem(panel->sizLs, sz);
894 sizeClick(panel->sizLs, panel);
896 return;