Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wfontpanel.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001
9d2e6ef9 scottc1998-09-29 22:36:29 +00002#include "WINGsP.h"
0e263f73 kojima1999-09-17 22:10:28 +00003#include "WUtil.h"
882b9a8e kojima2001-07-23 20:31:32 +00004#include "wconfig.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +00005
e7df5ed4 kojima1999-09-18 22:57:19 +00006#include <ctype.h>
527bbcf2 dan2000-11-22 07:34:03 +00007#include <string.h>
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +01008#include <stdint.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +00009
9aca0d5f dan2004-10-12 01:34:32 +000010#include <X11/Xft/Xft.h>
11#include <fontconfig/fontconfig.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000012
55d37178 kojima2002-12-04 15:40:32 +000013/* XXX TODO */
14char *WMFontPanelFontChangedNotification = "WMFontPanelFontChangedNotification";
15
9d2e6ef9 scottc1998-09-29 22:36:29 +000016typedef struct W_FontPanel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020017 WMWindow *win;
9d2e6ef9 scottc1998-09-29 22:36:29 +000018
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020019 WMFrame *upperF;
20 WMTextField *sampleT;
9aca0d5f dan2004-10-12 01:34:32 +000021
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020022 WMSplitView *split;
9d2e6ef9 scottc1998-09-29 22:36:29 +000023
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020024 WMFrame *lowerF;
25 WMLabel *famL;
26 WMList *famLs;
27 WMLabel *typL;
28 WMList *typLs;
29 WMLabel *sizL;
30 WMTextField *sizT;
31 WMList *sizLs;
9d2e6ef9 scottc1998-09-29 22:36:29 +000032
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020033 WMAction2 *action;
34 void *data;
55d37178 kojima2002-12-04 15:40:32 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 WMButton *revertB;
37 WMButton *setB;
9aca0d5f dan2004-10-12 01:34:32 +000038
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020039 WMPropList *fdb;
9d2e6ef9 scottc1998-09-29 22:36:29 +000040} FontPanel;
41
9d2e6ef9 scottc1998-09-29 22:36:29 +000042#define MIN_UPPER_HEIGHT 20
43#define MIN_LOWER_HEIGHT 140
44
9d2e6ef9 scottc1998-09-29 22:36:29 +000045#define MAX_FONTS_TO_RETRIEVE 2000
46
e7df5ed4 kojima1999-09-18 22:57:19 +000047#define BUTTON_SPACE_HEIGHT 40
9d2e6ef9 scottc1998-09-29 22:36:29 +000048
49#define MIN_WIDTH 250
e7df5ed4 kojima1999-09-18 22:57:19 +000050#define MIN_HEIGHT (MIN_UPPER_HEIGHT+MIN_LOWER_HEIGHT+BUTTON_SPACE_HEIGHT)
9d2e6ef9 scottc1998-09-29 22:36:29 +000051
e7df5ed4 kojima1999-09-18 22:57:19 +000052#define DEF_UPPER_HEIGHT 60
53#define DEF_LOWER_HEIGHT 310
54
55#define DEF_WIDTH 320
56#define DEF_HEIGHT (DEF_UPPER_HEIGHT+DEF_LOWER_HEIGHT)
57
e7df5ed4 kojima1999-09-18 22:57:19 +000058static int scalableFontSizes[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020059 8,
60 10,
61 11,
62 12,
63 14,
64 16,
65 18,
66 20,
67 24,
68 36,
69 48,
70 64
9d2e6ef9 scottc1998-09-29 22:36:29 +000071};
e7df5ed4 kojima1999-09-18 22:57:19 +000072
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020073static void setFontPanelFontName(FontPanel * panel, char *family, char *style, double size);
9aca0d5f dan2004-10-12 01:34:32 +000074
75static int isXLFD(char *font, int *length_ret);
9d2e6ef9 scottc1998-09-29 22:36:29 +000076
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020077static void arrangeLowerFrame(FontPanel * panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +000078
0e263f73 kojima1999-09-17 22:10:28 +000079static void familyClick(WMWidget *, void *);
80static void typefaceClick(WMWidget *, void *);
81static void sizeClick(WMWidget *, void *);
82
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020083static void listFamilies(WMScreen * scr, WMFontPanel * panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +000084
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020085static void splitViewConstrainCallback(WMSplitView * sPtr, int indView, int *min, int *max)
94f4483d kojima1999-10-27 22:32:12 +000086{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020087 if (indView == 0)
88 *min = MIN_UPPER_HEIGHT;
89 else
90 *min = MIN_LOWER_HEIGHT;
9d2e6ef9 scottc1998-09-29 22:36:29 +000091}
92
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020093static void notificationObserver(void *self, WMNotification * notif)
9d2e6ef9 scottc1998-09-29 22:36:29 +000094{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020095 WMFontPanel *panel = (WMFontPanel *) self;
96 void *object = WMGetNotificationObject(notif);
9d2e6ef9 scottc1998-09-29 22:36:29 +000097
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020098 if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
99 if (object == WMWidgetView(panel->win)) {
100 int h = WMWidgetHeight(panel->win);
101 int w = WMWidgetWidth(panel->win);
9aca0d5f dan2004-10-12 01:34:32 +0000102
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200103 WMResizeWidget(panel->split, w, h - BUTTON_SPACE_HEIGHT);
9aca0d5f dan2004-10-12 01:34:32 +0000104
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200105 WMMoveWidget(panel->setB, w - 80, h - (BUTTON_SPACE_HEIGHT - 5));
9aca0d5f dan2004-10-12 01:34:32 +0000106
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200107 WMMoveWidget(panel->revertB, w - 240, h - (BUTTON_SPACE_HEIGHT - 5));
9aca0d5f dan2004-10-12 01:34:32 +0000108
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200109 } else if (object == WMWidgetView(panel->upperF)) {
9aca0d5f dan2004-10-12 01:34:32 +0000110
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200111 if (WMWidgetHeight(panel->upperF) < MIN_UPPER_HEIGHT) {
112 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF), MIN_UPPER_HEIGHT);
113 } else {
114 WMResizeWidget(panel->sampleT, WMWidgetWidth(panel->upperF) - 20,
115 WMWidgetHeight(panel->upperF) - 10);
116 }
9aca0d5f dan2004-10-12 01:34:32 +0000117
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200118 } else if (object == WMWidgetView(panel->lowerF)) {
9aca0d5f dan2004-10-12 01:34:32 +0000119
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200120 if (WMWidgetHeight(panel->lowerF) < MIN_LOWER_HEIGHT) {
121 WMResizeWidget(panel->upperF, WMWidgetWidth(panel->upperF), MIN_UPPER_HEIGHT);
9aca0d5f dan2004-10-12 01:34:32 +0000122
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200123 WMMoveWidget(panel->lowerF, 0, WMWidgetHeight(panel->upperF)
124 + WMGetSplitViewDividerThickness(panel->split));
9aca0d5f dan2004-10-12 01:34:32 +0000125
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200126 WMResizeWidget(panel->lowerF, WMWidgetWidth(panel->lowerF),
127 WMWidgetWidth(panel->split) - MIN_UPPER_HEIGHT
128 - WMGetSplitViewDividerThickness(panel->split));
129 } else {
130 arrangeLowerFrame(panel);
131 }
132 }
133 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000134}
135
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200136static void closeWindow(WMWidget * w, void *data)
80fb09a7 kojima1999-10-09 20:07:23 +0000137{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200138 FontPanel *panel = (FontPanel *) data;
9aca0d5f dan2004-10-12 01:34:32 +0000139
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200140 WMHideFontPanel(panel);
80fb09a7 kojima1999-10-09 20:07:23 +0000141}
142
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200143static void setClickedAction(WMWidget * w, void *data)
55d37178 kojima2002-12-04 15:40:32 +0000144{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200145 FontPanel *panel = (FontPanel *) data;
9aca0d5f dan2004-10-12 01:34:32 +0000146
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200147 if (panel->action)
148 (*panel->action) (panel, panel->data);
55d37178 kojima2002-12-04 15:40:32 +0000149}
150
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200151static void revertClickedAction(WMWidget * w, void *data)
55d37178 kojima2002-12-04 15:40:32 +0000152{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200153 /*FontPanel *panel = (FontPanel*)data; */
154 /* XXX TODO */
55d37178 kojima2002-12-04 15:40:32 +0000155}
156
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200157WMFontPanel *WMGetFontPanel(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000158{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200159 FontPanel *panel;
160 WMColor *dark, *white;
161 WMFont *font;
162 int divThickness;
163
164 if (scr->sharedFontPanel)
165 return scr->sharedFontPanel;
166
167 panel = wmalloc(sizeof(FontPanel));
168 memset(panel, 0, sizeof(FontPanel));
169
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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000176
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200177 WMSetWindowCloseAction(panel->win, closeWindow, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000178
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200179 panel->split = WMCreateSplitView(panel->win);
180 WMResizeWidget(panel->split, DEF_WIDTH, DEF_HEIGHT - BUTTON_SPACE_HEIGHT);
181 WMSetSplitViewConstrainProc(panel->split, splitViewConstrainCallback);
182
183 divThickness = WMGetSplitViewDividerThickness(panel->split);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000184
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200185 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000192
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200193 WMAddSplitViewSubview(panel->split, W_VIEW(panel->upperF));
194 WMAddSplitViewSubview(panel->split, W_VIEW(panel->lowerF));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000195
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200196 WMResizeWidget(panel->upperF, DEF_WIDTH, DEF_UPPER_HEIGHT);
9aca0d5f dan2004-10-12 01:34:32 +0000197
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200198 WMResizeWidget(panel->lowerF, DEF_WIDTH, DEF_LOWER_HEIGHT);
e7df5ed4 kojima1999-09-18 22:57:19 +0000199
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200200 WMMoveWidget(panel->lowerF, 0, 60 + divThickness);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000201
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200202 white = WMWhiteColor(scr);
203 dark = WMDarkGrayColor(scr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000204
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200205 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"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000209
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200210 font = WMBoldSystemFontOfSize(scr, 12);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000211
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200212 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);
9aca0d5f dan2004-10-12 01:34:32 +0000219
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200220 panel->famLs = WMCreateList(panel->lowerF);
221 WMSetListAction(panel->famLs, familyClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000222
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200223 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000230
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200231 panel->typLs = WMCreateList(panel->lowerF);
232 WMSetListAction(panel->typLs, typefaceClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000233
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200234 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000241
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200242 panel->sizT = WMCreateTextField(panel->lowerF);
243 /* WMSetTextFieldAlignment(panel->sizT, WARight); */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000244
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200245 panel->sizLs = WMCreateList(panel->lowerF);
246 WMSetListAction(panel->sizLs, sizeClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000247
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200248 WMReleaseFont(font);
249 WMReleaseColor(white);
250 WMReleaseColor(dark);
9aca0d5f dan2004-10-12 01:34:32 +0000251
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200252 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000257
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200258 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);
55d37178 kojima2002-12-04 15:40:32 +0000263
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200264 WMRealizeWidget(panel->win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000265
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200266 WMMapSubwidgets(panel->upperF);
267 WMMapSubwidgets(panel->lowerF);
268 WMMapSubwidgets(panel->split);
269 WMMapSubwidgets(panel->win);
e7df5ed4 kojima1999-09-18 22:57:19 +0000270
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200271 WMUnmapWidget(panel->revertB);
e7df5ed4 kojima1999-09-18 22:57:19 +0000272
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200273 arrangeLowerFrame(panel);
e7df5ed4 kojima1999-09-18 22:57:19 +0000274
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200275 scr->sharedFontPanel = panel;
e7df5ed4 kojima1999-09-18 22:57:19 +0000276
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200277 /* 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));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000284
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200285 listFamilies(scr, panel);
e7df5ed4 kojima1999-09-18 22:57:19 +0000286
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200287 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000288}
289
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200290void WMFreeFontPanel(WMFontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000291{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200292 if (panel == WMWidgetScreen(panel->win)->sharedFontPanel) {
293 WMWidgetScreen(panel->win)->sharedFontPanel = NULL;
294 }
295 WMRemoveNotificationObserver(panel);
296 WMUnmapWidget(panel->win);
297 WMDestroyWidget(panel->win);
298 wfree(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000299}
300
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200301void WMShowFontPanel(WMFontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000302{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200303 WMMapWidget(panel->win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000304}
305
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200306void WMHideFontPanel(WMFontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000307{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200308 WMUnmapWidget(panel->win);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000309}
310
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200311WMFont *WMGetFontPanelFont(WMFontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000312{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200313 return WMGetTextFieldFont(panel->sampleT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000314}
315
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200316void WMSetFontPanelFont(WMFontPanel * panel, char *fontName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000317{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200318 int fname_len;
319 FcPattern *pattern;
320 FcChar8 *family, *style;
321 double size;
322
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); */
330 }
331
332 if (!pattern)
333 return;
334
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);
339
340 FcPatternDestroy(pattern);
9aca0d5f dan2004-10-12 01:34:32 +0000341}
9d2e6ef9 scottc1998-09-29 22:36:29 +0000342
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200343void WMSetFontPanelAction(WMFontPanel * panel, WMAction2 * action, void *data)
55d37178 kojima2002-12-04 15:40:32 +0000344{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200345 panel->action = action;
346 panel->data = data;
55d37178 kojima2002-12-04 15:40:32 +0000347}
348
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200349static void arrangeLowerFrame(FontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000350{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200351 int width = WMWidgetWidth(panel->lowerF) - 55 - 30;
352 int height = WMWidgetHeight(panel->split) - WMWidgetHeight(panel->upperF);
353 int fw, tw, sw;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000354
e7df5ed4 kojima1999-09-18 22:57:19 +0000355#define LABEL_HEIGHT 20
356
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200357 height -= WMGetSplitViewDividerThickness(panel->split);
9aca0d5f dan2004-10-12 01:34:32 +0000358
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200359 height -= LABEL_HEIGHT + 8;
e7df5ed4 kojima1999-09-18 22:57:19 +0000360
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200361 fw = (125 * width) / 235;
362 tw = (110 * width) / 235;
363 sw = 55;
e7df5ed4 kojima1999-09-18 22:57:19 +0000364
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200365 WMMoveWidget(panel->famL, 10, 0);
366 WMResizeWidget(panel->famL, fw, LABEL_HEIGHT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000367
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200368 WMMoveWidget(panel->famLs, 10, 23);
369 WMResizeWidget(panel->famLs, fw, height);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000370
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200371 WMMoveWidget(panel->typL, 10 + fw + 3, 0);
372 WMResizeWidget(panel->typL, tw, LABEL_HEIGHT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000373
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200374 WMMoveWidget(panel->typLs, 10 + fw + 3, 23);
375 WMResizeWidget(panel->typLs, tw, height);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000376
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200377 WMMoveWidget(panel->sizL, 10 + fw + 3 + tw + 3, 0);
378 WMResizeWidget(panel->sizL, sw + 4, LABEL_HEIGHT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000379
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200380 WMMoveWidget(panel->sizT, 10 + fw + 3 + tw + 3, 23);
381 WMResizeWidget(panel->sizT, sw + 4, 20);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000382
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200383 WMMoveWidget(panel->sizLs, 10 + fw + 3 + tw + 3, 46);
384 WMResizeWidget(panel->sizLs, sw + 4, height - 23);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000385}
386
9d2e6ef9 scottc1998-09-29 22:36:29 +0000387#define NUM_FIELDS 14
388
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200389static int isXLFD(char *font, int *length_ret)
9aca0d5f dan2004-10-12 01:34:32 +0000390{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200391 int c = 0;
9aca0d5f dan2004-10-12 01:34:32 +0000392
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200393 *length_ret = 0;
394 while (*font) {
395 (*length_ret)++;
396 if (*font++ == '-')
397 c++;
398 }
9aca0d5f dan2004-10-12 01:34:32 +0000399
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200400 return c == NUM_FIELDS;
9aca0d5f dan2004-10-12 01:34:32 +0000401}
402
9aca0d5f dan2004-10-12 01:34:32 +0000403typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200404 char *typeface;
405 WMArray *sizes;
6cfad0b1 dan2004-10-17 06:27:51 +0000406} Typeface;
9aca0d5f dan2004-10-12 01:34:32 +0000407
408typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200409 char *name; /* gotta love simplicity */
410 WMArray *typefaces;
6cfad0b1 dan2004-10-17 06:27:51 +0000411} Family;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000412
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200413static int compare_int(const void *a, const void *b)
e7df5ed4 kojima1999-09-18 22:57:19 +0000414{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200415 int i1 = *(int *)a;
416 int i2 = *(int *)b;
417
418 if (i1 < i2)
419 return -1;
420 else if (i1 > i2)
421 return 1;
422 else
423 return 0;
e7df5ed4 kojima1999-09-18 22:57:19 +0000424}
425
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200426static void addSizeToTypeface(Typeface * face, int size)
e7df5ed4 kojima1999-09-18 22:57:19 +0000427{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200428 if (size == 0) {
429 int j;
430
431 for (j = 0; j < sizeof(scalableFontSizes) / sizeof(int); j++) {
432 size = scalableFontSizes[j];
433
434 if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
435 WMAddToArray(face->sizes, (void *)(uintptr_t) size);
436 }
437 }
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);
443 }
444 }
e7df5ed4 kojima1999-09-18 22:57:19 +0000445}
446
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200447static void addTypefaceToXftFamily(Family * fam, char *style)
9aca0d5f dan2004-10-12 01:34:32 +0000448{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200449 Typeface *face;
450 WMArrayIterator i;
451
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;
458 }
459 } else {
460 fam->typefaces = WMCreateArray(4);
461 }
462
463 face = wmalloc(sizeof(Typeface));
464 memset(face, 0, sizeof(Typeface));
465
466 face->typeface = wstrdup(style);
467 face->sizes = WMCreateArray(4);
468 addSizeToTypeface(face, 0);
469
470 WMAddToArray(fam->typefaces, face);
9aca0d5f dan2004-10-12 01:34:32 +0000471}
472
052ab01c kojima1999-09-16 02:55:56 +0000473/*
046403db dan2001-04-15 01:22:56 +0000474 * families (same family name) (Hashtable of family -> array)
052ab01c kojima1999-09-16 02:55:56 +0000475 * registries (same family but different registries)
9aca0d5f dan2004-10-12 01:34:32 +0000476 *
052ab01c kojima1999-09-16 02:55:56 +0000477 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200478static void addFontToXftFamily(WMHashTable * families, char *name, char *style)
9aca0d5f dan2004-10-12 01:34:32 +0000479{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200480 WMArrayIterator i;
481 WMArray *array;
482 Family *fam;
9aca0d5f dan2004-10-12 01:34:32 +0000483
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200484 array = WMHashGet(families, name);
485 if (array) {
486 WM_ITERATE_ARRAY(array, fam, i) {
487 if (strcmp(fam->name, name) == 0)
488 addTypefaceToXftFamily(fam, style);
489 return;
490 }
491 }
9aca0d5f dan2004-10-12 01:34:32 +0000492
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200493 array = WMCreateArray(8);
9aca0d5f dan2004-10-12 01:34:32 +0000494
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200495 fam = wmalloc(sizeof(Family));
496 memset(fam, 0, sizeof(Family));
9aca0d5f dan2004-10-12 01:34:32 +0000497
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200498 fam->name = wstrdup(name);
9aca0d5f dan2004-10-12 01:34:32 +0000499
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200500 addTypefaceToXftFamily(fam, style);
9aca0d5f dan2004-10-12 01:34:32 +0000501
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200502 WMAddToArray(array, fam);
9aca0d5f dan2004-10-12 01:34:32 +0000503
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200504 WMHashInsert(families, fam->name, array);
9aca0d5f dan2004-10-12 01:34:32 +0000505}
506
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200507static void listFamilies(WMScreen * scr, WMFontPanel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000508{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200509 FcObjectSet *os = 0;
510 FcFontSet *fs;
511 FcPattern *pat;
512 WMHashTable *families;
513 WMHashEnumerator enumer;
514 WMArray *array;
515 int i;
516
517 pat = FcPatternCreate();
518 os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
519 fs = FcFontList(0, pat, os);
520 if (!fs) {
521 WMRunAlertPanel(scr, panel->win, _("Error"),
522 _("Could not init font config library\n"), _("OK"), NULL, NULL);
523 return;
524 }
525 if (pat)
526 FcPatternDestroy(pat);
527
528 families = WMCreateHashTable(WMStringPointerHashCallbacks);
529
530 if (fs) {
531 for (i = 0; i < fs->nfont; i++) {
532 FcChar8 *family;
533 FcChar8 *style;
534
535 if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch)
536 if (FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch)
537 addFontToXftFamily(families, (char *)family, (char *)style);
538 }
539 FcFontSetDestroy(fs);
540 }
541
542 enumer = WMEnumerateHashTable(families);
543
544 while ((array = WMNextHashEnumeratorItem(&enumer))) {
545 WMArrayIterator i;
546 Family *fam;
547 char buffer[256];
548 WMListItem *item;
549
550 WM_ITERATE_ARRAY(array, fam, i) {
551 strcpy(buffer, fam->name);
552 item = WMAddListItem(panel->famLs, buffer);
553
554 item->clientData = fam;
555 }
556
557 WMFreeArray(array);
558 }
559
560 WMSortListItems(panel->famLs);
561
562 WMFreeHashTable(families);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000563}
564
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200565static void getSelectedFont(FontPanel * panel, char buffer[], int bufsize)
d5fbe62d kojima1999-09-22 02:09:42 +0000566{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200567 WMListItem *item;
568 Family *family;
569 Typeface *face;
570 char *size;
d5fbe62d kojima1999-09-22 02:09:42 +0000571
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200572 item = WMGetListSelectedItem(panel->famLs);
573 if (!item)
574 return;
575 family = (Family *) item->clientData;
9aca0d5f dan2004-10-12 01:34:32 +0000576
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200577 item = WMGetListSelectedItem(panel->typLs);
578 if (!item)
579 return;
580 face = (Typeface *) item->clientData;
d5fbe62d kojima1999-09-22 02:09:42 +0000581
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200582 size = WMGetTextFieldText(panel->sizT);
d5fbe62d kojima1999-09-22 02:09:42 +0000583
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200584 snprintf(buffer, bufsize, "%s:style=%s:pixelsize=%s", family->name, face->typeface, size);
d5fbe62d kojima1999-09-22 02:09:42 +0000585
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200586 wfree(size);
d5fbe62d kojima1999-09-22 02:09:42 +0000587}
588
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200589static void preview(FontPanel * panel)
d5fbe62d kojima1999-09-22 02:09:42 +0000590{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200591 char buffer[512];
592 WMFont *font;
593
594 getSelectedFont(panel, buffer, sizeof(buffer));
595 font = WMCreateFont(WMWidgetScreen(panel->win), buffer);
596 if (font) {
597 WMSetTextFieldFont(panel->sampleT, font);
598 WMReleaseFont(font);
599 }
d5fbe62d kojima1999-09-22 02:09:42 +0000600}
601
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200602static void familyClick(WMWidget * w, void *data)
0e263f73 kojima1999-09-17 22:10:28 +0000603{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200604 WMList *lPtr = (WMList *) w;
605 WMListItem *item;
606 Family *family;
607 Typeface *face;
608 FontPanel *panel = (FontPanel *) data;
609 WMArrayIterator i;
610 /* current typeface and size */
611 char *oface = NULL;
612 char *osize = NULL;
613 int facei = -1;
614 int sizei = -1;
615
616 /* must try to keep the same typeface and size for the new family */
617 item = WMGetListSelectedItem(panel->typLs);
618 if (item)
619 oface = wstrdup(item->text);
620
621 osize = WMGetTextFieldText(panel->sizT);
622
623 item = WMGetListSelectedItem(lPtr);
624 family = (Family *) item->clientData;
625
626 WMClearList(panel->typLs);
627
628 WM_ITERATE_ARRAY(family->typefaces, face, i) {
629 char buffer[256];
630 int top = 0;
631 WMListItem *fitem;
632
633 strcpy(buffer, face->typeface);
634 if (strcasecmp(face->typeface, "Roman") == 0)
635 top = 1;
636 if (strcasecmp(face->typeface, "Regular") == 0)
637 top = 1;
638 if (top)
639 fitem = WMInsertListItem(panel->typLs, 0, buffer);
640 else
641 fitem = WMAddListItem(panel->typLs, buffer);
642 fitem->clientData = face;
643 }
644
645 if (oface) {
646 facei = WMFindRowOfListItemWithTitle(panel->typLs, oface);
647 wfree(oface);
648 }
649 if (facei < 0) {
650 facei = 0;
651 }
652 WMSelectListItem(panel->typLs, facei);
653 typefaceClick(panel->typLs, panel);
654
655 if (osize) {
656 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
657 }
658 if (sizei >= 0) {
659 WMSelectListItem(panel->sizLs, sizei);
660 sizeClick(panel->sizLs, panel);
661 }
662
663 if (osize)
664 wfree(osize);
665
666 preview(panel);
0e263f73 kojima1999-09-17 22:10:28 +0000667}
668
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200669static void typefaceClick(WMWidget * w, void *data)
0e263f73 kojima1999-09-17 22:10:28 +0000670{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200671 FontPanel *panel = (FontPanel *) data;
672 WMListItem *item;
673 Typeface *face;
674 WMArrayIterator i;
675 char buffer[32];
676
677 char *osize = NULL;
678 int sizei = -1;
679 void *size;
680
681 osize = WMGetTextFieldText(panel->sizT);
682
683 item = WMGetListSelectedItem(panel->typLs);
684 face = (Typeface *) item->clientData;
685
686 WMClearList(panel->sizLs);
687
688 WM_ITERATE_ARRAY(face->sizes, size, i) {
689 if ((int)(uintptr_t) size != 0) {
690 sprintf(buffer, "%i", (int)(uintptr_t) size);
691
692 WMAddListItem(panel->sizLs, buffer);
693 }
694 }
695
696 if (osize) {
697 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, osize);
698 }
699 if (sizei < 0) {
700 sizei = WMFindRowOfListItemWithTitle(panel->sizLs, "12");
701 }
702 if (sizei < 0) {
703 sizei = 0;
704 }
705 WMSelectListItem(panel->sizLs, sizei);
706 WMSetListPosition(panel->sizLs, sizei);
707 sizeClick(panel->sizLs, panel);
708
709 if (osize)
710 wfree(osize);
711
712 preview(panel);
0e263f73 kojima1999-09-17 22:10:28 +0000713}
714
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200715static void sizeClick(WMWidget * w, void *data)
0e263f73 kojima1999-09-17 22:10:28 +0000716{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200717 FontPanel *panel = (FontPanel *) data;
718 WMListItem *item;
109bb540 dan2004-07-16 18:18:36 +0000719
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200720 item = WMGetListSelectedItem(panel->sizLs);
721 WMSetTextFieldText(panel->sizT, item->text);
9aca0d5f dan2004-10-12 01:34:32 +0000722
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200723 WMSelectTextFieldRange(panel->sizT, wmkrange(0, strlen(item->text)));
e7df5ed4 kojima1999-09-18 22:57:19 +0000724
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200725 preview(panel);
e7df5ed4 kojima1999-09-18 22:57:19 +0000726}
727
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200728static void setFontPanelFontName(FontPanel * panel, char *family, char *style, double size)
9aca0d5f dan2004-10-12 01:34:32 +0000729{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200730 int famrow;
731 int stlrow;
732 int sz;
733 char asize[64];
734 void *vsize;
735 WMListItem *item;
736 Family *fam;
737 Typeface *face;
738 WMArrayIterator i;
9aca0d5f dan2004-10-12 01:34:32 +0000739
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200740 famrow = WMFindRowOfListItemWithTitle(panel->famLs, family);
741 if (famrow < 0) {
742 famrow = 0;
743 return;
744 }
745 WMSelectListItem(panel->famLs, famrow);
746 WMSetListPosition(panel->famLs, famrow);
9aca0d5f dan2004-10-12 01:34:32 +0000747
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200748 WMClearList(panel->typLs);
9aca0d5f dan2004-10-12 01:34:32 +0000749
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200750 item = WMGetListSelectedItem(panel->famLs);
9aca0d5f dan2004-10-12 01:34:32 +0000751
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200752 fam = (Family *) item->clientData;
753 WM_ITERATE_ARRAY(fam->typefaces, face, i) {
754 char buffer[256];
755 int top = 0;
756 WMListItem *fitem;
9aca0d5f dan2004-10-12 01:34:32 +0000757
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200758 strcpy(buffer, face->typeface);
759 if (strcasecmp(face->typeface, "Roman") == 0)
760 top = 1;
761 if (top)
762 fitem = WMInsertListItem(panel->typLs, 0, buffer);
763 else
764 fitem = WMAddListItem(panel->typLs, buffer);
765 fitem->clientData = face;
766 }
9aca0d5f dan2004-10-12 01:34:32 +0000767
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200768 stlrow = WMFindRowOfListItemWithTitle(panel->typLs, style);
9aca0d5f dan2004-10-12 01:34:32 +0000769
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200770 if (stlrow < 0) {
771 stlrow = 0;
772 return;
773 }
9aca0d5f dan2004-10-12 01:34:32 +0000774
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200775 WMSelectListItem(panel->typLs, stlrow);
9aca0d5f dan2004-10-12 01:34:32 +0000776
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200777 item = WMGetListSelectedItem(panel->typLs);
9aca0d5f dan2004-10-12 01:34:32 +0000778
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200779 face = (Typeface *) item->clientData;
9aca0d5f dan2004-10-12 01:34:32 +0000780
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200781 WMClearList(panel->sizLs);
9aca0d5f dan2004-10-12 01:34:32 +0000782
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200783 WM_ITERATE_ARRAY(face->sizes, vsize, i) {
784 char buffer[32];
785 if ((int)(uintptr_t) vsize != 0) {
786 sprintf(buffer, "%i", (int)(uintptr_t) vsize);
9aca0d5f dan2004-10-12 01:34:32 +0000787
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200788 WMAddListItem(panel->sizLs, buffer);
789 }
790 }
9aca0d5f dan2004-10-12 01:34:32 +0000791
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200792 snprintf(asize, sizeof(asize) - 1, "%d", (int)(size + 0.5));
9aca0d5f dan2004-10-12 01:34:32 +0000793
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200794 sz = WMFindRowOfListItemWithTitle(panel->sizLs, asize);
9aca0d5f dan2004-10-12 01:34:32 +0000795
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200796 if (sz < 0) {
797 sz = 4;
798 return;
799 }
9aca0d5f dan2004-10-12 01:34:32 +0000800
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200801 WMSelectListItem(panel->sizLs, sz);
802 sizeClick(panel->sizLs, panel);
9aca0d5f dan2004-10-12 01:34:32 +0000803
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200804 return;
9aca0d5f dan2004-10-12 01:34:32 +0000805}