~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WPrefs.app/FontSimple.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FontSimple.c- simplified font configuration panel
 
2
 * 
 
3
 *  WPrefs - Window Maker Preferences Program
 
4
 * 
 
5
 *  Copyright (c) 1998-2004 Alfredo K. Kojima
 
6
 * 
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
 
20
 *  USA.
 
21
 */
 
22
 
 
23
 
 
24
#include "WPrefs.h"
 
25
#include <unistd.h>
 
26
#include <fontconfig/fontconfig.h>
 
27
 
 
28
 
 
29
/* workaround for older fontconfig, that doesn't define these constants */
 
30
#ifndef FC_WEIGHT_NORMAL
 
31
/* Weights */
 
32
# define FC_WEIGHT_THIN              10
 
33
# define FC_WEIGHT_EXTRALIGHT        40
 
34
# define FC_WEIGHT_ULTRALIGHT        FC_WEIGHT_EXTRALIGHT
 
35
# define FC_WEIGHT_REGULAR           80
 
36
# define FC_WEIGHT_NORMAL            FC_WEIGHT_REGULAR
 
37
# define FC_WEIGHT_SEMIBOLD          FC_WEIGHT_DEMIBOLD
 
38
# define FC_WEIGHT_EXTRABOLD         205
 
39
# define FC_WEIGHT_ULTRABOLD         FC_WEIGHT_EXTRABOLD
 
40
# define FC_WEIGHT_HEAVY             FC_WEIGHT_BLACK
 
41
/* Widths */
 
42
# define FC_WIDTH_ULTRACONDENSED     50
 
43
# define FC_WIDTH_EXTRACONDENSED     63
 
44
# define FC_WIDTH_CONDENSED          75
 
45
# define FC_WIDTH_SEMICONDENSED      87
 
46
# define FC_WIDTH_NORMAL             100
 
47
# define FC_WIDTH_SEMIEXPANDED       113
 
48
# define FC_WIDTH_EXPANDED           125
 
49
# define FC_WIDTH_EXTRAEXPANDED      150
 
50
# define FC_WIDTH_ULTRAEXPANDED      200
 
51
#endif
 
52
 
 
53
 
 
54
#define SAMPLE_TEXT "The Lazy Fox Jumped Ipsum Foobar 1234 - 56789"
 
55
 
 
56
 
 
57
typedef struct {
 
58
    int weight;
 
59
    int width;
 
60
    int slant;
 
61
} FontStyle;
 
62
 
 
63
typedef struct {
 
64
    char *name;
 
65
    int stylen;
 
66
    FontStyle *styles;
 
67
} FontFamily;
 
68
 
 
69
 
 
70
typedef struct {
 
71
    int familyn;
 
72
    FontFamily *families;
 
73
} FontList;
 
74
 
 
75
 
 
76
typedef struct _Panel {
 
77
    WMBox *box;
 
78
    char *sectionName;
 
79
 
 
80
    char *description;
 
81
    
 
82
    CallbackRec callbacks;
 
83
 
 
84
    WMWidget *parent;
 
85
 
 
86
    WMPopUpButton *optionP;
 
87
    
 
88
    WMList *familyL;
 
89
    WMList *styleL;
 
90
    
 
91
    WMList *sizeL;
 
92
    
 
93
    WMTextField *sampleT;
 
94
    
 
95
    FontList   *fonts;
 
96
} _Panel;
 
97
 
 
98
 
 
99
#define ICON_FILE       "fonts"
 
100
 
 
101
 
 
102
static struct {
 
103
    char *option;
 
104
    char *label;
 
105
} fontOptions[]= {
 
106
    {"WindowTitleFont", N_("Window Title")},
 
107
    {"MenuTitleFont", N_("Menu Title")},
 
108
    {"MenuTextFont", N_("Menu Text")},
 
109
    {"IconTitleFont", N_("Icon Title")},
 
110
    {"ClipTitleFont", N_("Clip Title")},
 
111
    {"LargeDisplayFont", N_("Desktop Caption")},
 
112
    {NULL, NULL},
 
113
};
 
114
 
 
115
 
 
116
static char *standardSizes[]= {
 
117
    "6",
 
118
    "8",
 
119
    "9",
 
120
    "10",
 
121
    "11",
 
122
    "12",
 
123
    "13",
 
124
    "14",
 
125
    "15",
 
126
    "16",
 
127
    "18",
 
128
    "20",
 
129
    "22",
 
130
    "24",
 
131
    "28",
 
132
    "32",
 
133
    "36",
 
134
    "48",
 
135
    "64",
 
136
    "72",
 
137
    NULL
 
138
};
 
139
 
 
140
 
 
141
static struct {
 
142
    int weight;
 
143
    char *name;
 
144
} fontWeights[]= {
 
145
    {FC_WEIGHT_THIN, "Thin"},
 
146
    {FC_WEIGHT_EXTRALIGHT, "ExtraLight"},
 
147
    {FC_WEIGHT_LIGHT, "Light"},
 
148
    {FC_WEIGHT_NORMAL, "Normal"},
 
149
    {FC_WEIGHT_MEDIUM, ""}, /*"medium"},*/
 
150
    {FC_WEIGHT_DEMIBOLD, "DemiBold"},
 
151
    {FC_WEIGHT_BOLD, "Bold"},
 
152
    {FC_WEIGHT_EXTRABOLD, "ExtraBold"},
 
153
    {FC_WEIGHT_BLACK, "Black"},
 
154
    {0, NULL}
 
155
};
 
156
 
 
157
static struct {
 
158
    int slant;
 
159
    char *name;
 
160
} fontSlants[]= {
 
161
    {FC_SLANT_ROMAN, ""}, /*"Roman"},*/
 
162
    {FC_SLANT_ITALIC, "Italic"},
 
163
    {FC_SLANT_OBLIQUE, "Oblique"},
 
164
    {0, NULL}
 
165
};
 
166
 
 
167
static struct {
 
168
    int width;
 
169
    char *name;
 
170
} fontWidths[]= {
 
171
    {FC_WIDTH_ULTRACONDENSED, "UltraCondensed"},
 
172
    {FC_WIDTH_EXTRACONDENSED, "ExtraCondensed"},
 
173
    {FC_WIDTH_CONDENSED, "Condensed"},
 
174
    {FC_WIDTH_SEMICONDENSED, "SemiCondensed"},
 
175
    {FC_WIDTH_NORMAL, ""}, /*"normal"},*/
 
176
    {FC_WIDTH_SEMIEXPANDED, "SemiExpanded"},
 
177
    {FC_WIDTH_EXPANDED, "Expanded"},
 
178
    {FC_WIDTH_EXTRAEXPANDED, "ExtraExpanded"},
 
179
    {FC_WIDTH_ULTRAEXPANDED, "UltraExpanded"},
 
180
    {0, NULL}
 
181
};
 
182
 
 
183
 
 
184
 
 
185
 
 
186
 
 
187
static int compare_family(const void *a, const void *b)
 
188
{
 
189
    FontFamily *fa= (FontFamily*)a;
 
190
    FontFamily *fb= (FontFamily*)b;
 
191
    return strcmp(fa->name, fb->name);
 
192
}
 
193
 
 
194
 
 
195
static int compare_styles(const void *a, const void *b)
 
196
{
 
197
    FontStyle *sa= (FontStyle*)a;
 
198
    FontStyle *sb= (FontStyle*)b;
 
199
    int compare;
 
200
 
 
201
    compare = sa->weight - sb->weight;
 
202
    if (compare != 0)
 
203
        return compare;
 
204
    compare = sa->slant - sb->slant;
 
205
    if (compare != 0)
 
206
        return compare;
 
207
    return (sa->width - sb->width);
 
208
}
 
209
 
 
210
 
 
211
static void 
 
212
lookup_available_fonts(_Panel *panel)
 
213
{
 
214
    FcPattern *pat = FcPatternCreate();
 
215
    FcObjectSet *os;
 
216
    FcFontSet *fonts;
 
217
    FontFamily *family;
 
218
 
 
219
    os = FcObjectSetBuild(FC_FAMILY, FC_WEIGHT, FC_WIDTH, FC_SLANT, NULL);
 
220
    
 
221
    fonts = FcFontList(0, pat, os);
 
222
    
 
223
    if (fonts)
 
224
    {
 
225
        int i;
 
226
 
 
227
        panel->fonts= wmalloc(sizeof(FontList));
 
228
        panel->fonts->familyn= 0;
 
229
        panel->fonts->families= wmalloc(sizeof(FontFamily)*fonts->nfont);
 
230
 
 
231
        for (i= 0; i < fonts->nfont; i++)
 
232
        {
 
233
            FcChar8 *name;
 
234
            int weight, slant, width;
 
235
            int j, found;
 
236
 
 
237
            if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &name) != FcResultMatch)
 
238
              continue;
 
239
 
 
240
            if (FcPatternGetInteger(fonts->fonts[i], FC_WEIGHT, 0, &weight) != FcResultMatch)
 
241
              weight= FC_WEIGHT_MEDIUM;
 
242
 
 
243
            if (FcPatternGetInteger(fonts->fonts[i], FC_WIDTH, 0, &width) != FcResultMatch)
 
244
              width= FC_WIDTH_NORMAL;
 
245
 
 
246
            if (FcPatternGetInteger(fonts->fonts[i], FC_SLANT, 0, &slant) != FcResultMatch)
 
247
              slant= FC_SLANT_ROMAN;
 
248
 
 
249
            found = -1;
 
250
            for (j = 0; j < panel->fonts->familyn && found<0; j++)
 
251
              if (strcasecmp(panel->fonts->families[j].name, name)==0)
 
252
                found= j;
 
253
            
 
254
            if (found < 0)
 
255
            {
 
256
                panel->fonts->families[panel->fonts->familyn++].name= wstrdup(name);
 
257
                family= panel->fonts->families + panel->fonts->familyn-1;
 
258
                family->stylen= 0;
 
259
                family->styles= NULL;
 
260
            }
 
261
            else
 
262
                family= panel->fonts->families+found;
 
263
 
 
264
            family->stylen++;
 
265
            family->styles= wrealloc(family->styles, sizeof(FontStyle)*family->stylen);
 
266
            family->styles[family->stylen-1].weight= weight;
 
267
            family->styles[family->stylen-1].slant= slant;
 
268
            family->styles[family->stylen-1].width= width;
 
269
        }
 
270
        qsort(panel->fonts->families, panel->fonts->familyn, sizeof(FontFamily),
 
271
              compare_family);
 
272
 
 
273
        for (i=0; i < panel->fonts->familyn; i++)
 
274
        {
 
275
            qsort(panel->fonts->families[i].styles, panel->fonts->families[i].stylen,
 
276
                  sizeof(FontStyle), compare_styles);
 
277
        }
 
278
 
 
279
        FcFontSetDestroy(fonts);
 
280
    }
 
281
    if (os)
 
282
      FcObjectSetDestroy(os);
 
283
    if (pat)
 
284
      FcPatternDestroy(pat);
 
285
 
 
286
    panel->fonts->families[panel->fonts->familyn++].name= wstrdup("sans serif");
 
287
    family= panel->fonts->families + panel->fonts->familyn-1;
 
288
    family->styles= wmalloc(sizeof(FontStyle)*2);
 
289
    family->stylen= 2;
 
290
    family->styles[0].weight= FC_WEIGHT_MEDIUM;
 
291
    family->styles[0].slant= FC_SLANT_ROMAN;
 
292
    family->styles[0].width= FC_WIDTH_NORMAL;
 
293
    family->styles[1].weight= FC_WEIGHT_BOLD;
 
294
    family->styles[1].slant= FC_SLANT_ROMAN;
 
295
    family->styles[1].width= FC_WIDTH_NORMAL;
 
296
 
 
297
    panel->fonts->families[panel->fonts->familyn++].name= wstrdup("serif");
 
298
    family= panel->fonts->families + panel->fonts->familyn-1;
 
299
    family->styles= wmalloc(sizeof(FontStyle)*2);
 
300
    family->stylen= 2;
 
301
    family->styles[0].weight= FC_WEIGHT_MEDIUM;
 
302
    family->styles[0].slant= FC_SLANT_ROMAN;
 
303
    family->styles[0].width= FC_WIDTH_NORMAL;
 
304
    family->styles[1].weight= FC_WEIGHT_BOLD;
 
305
    family->styles[1].slant= FC_SLANT_ROMAN;
 
306
    family->styles[1].width= FC_WIDTH_NORMAL;
 
307
}
 
308
 
 
309
 
 
310
static char*
 
311
getSelectedFont(_Panel *panel, char *curfont)
 
312
{
 
313
    WMListItem *item;
 
314
    FcPattern *pat= FcNameParse(curfont);
 
315
    char *name;
 
316
    
 
317
    item= WMGetListSelectedItem(panel->familyL);
 
318
    if (item)
 
319
    {
 
320
        FcPatternDel(pat, FC_FAMILY);
 
321
        FcPatternAddString(pat, FC_FAMILY, item->text);
 
322
    }
 
323
 
 
324
    item= WMGetListSelectedItem(panel->styleL);
 
325
    if (item)
 
326
    {
 
327
        FontStyle *style= (FontStyle*)item->clientData;
 
328
 
 
329
        FcPatternDel(pat, FC_WEIGHT);
 
330
        FcPatternAddInteger(pat, FC_WEIGHT, style->weight);
 
331
        
 
332
        FcPatternDel(pat, FC_WIDTH);
 
333
        FcPatternAddInteger(pat, FC_WIDTH, style->width);
 
334
 
 
335
        FcPatternDel(pat, FC_SLANT);
 
336
        FcPatternAddInteger(pat, FC_SLANT, style->slant);
 
337
    }
 
338
    
 
339
    item= WMGetListSelectedItem(panel->sizeL);
 
340
    if (item)
 
341
    {
 
342
        FcPatternDel(pat, FC_PIXEL_SIZE);
 
343
        FcPatternAddDouble(pat, FC_PIXEL_SIZE, atoi(item->text));
 
344
    }
 
345
 
 
346
    name= FcNameUnparse(pat);
 
347
    FcPatternDestroy(pat);
 
348
    
 
349
    return name;
 
350
}
 
351
 
 
352
 
 
353
 
 
354
static void
 
355
updateSampleFont(_Panel *panel)
 
356
{
 
357
    WMMenuItem *item= WMGetPopUpButtonMenuItem(panel->optionP,
 
358
                                           WMGetPopUpButtonSelectedItem(panel->optionP));
 
359
    char *fn= WMGetMenuItemRepresentedObject(item);
 
360
    WMFont *font= WMCreateFont(WMWidgetScreen(panel->box), fn);
 
361
 
 
362
    if (font)
 
363
    {
 
364
        WMSetTextFieldFont(panel->sampleT, font);
 
365
        WMReleaseFont(font);
 
366
    }
 
367
}
 
368
 
 
369
 
 
370
 
 
371
 
 
372
static void
 
373
selectedFamily(WMWidget *w, void *data)
 
374
{
 
375
    _Panel *panel= (_Panel*)data;
 
376
    WMListItem *item;
 
377
    FontStyle *oldStyle= NULL;
 
378
    char buffer[1024];
 
379
    
 
380
    item= WMGetListSelectedItem(panel->styleL);
 
381
    if (item)
 
382
      oldStyle= (FontStyle*)item->clientData;
 
383
 
 
384
    item= WMGetListSelectedItem(panel->familyL);
 
385
 
 
386
    if (item)
 
387
    {
 
388
        FontFamily *family= (FontFamily*)item->clientData;
 
389
        int i, oldi= 0, oldscore= 0;
 
390
 
 
391
        WMClearList(panel->styleL);
 
392
        for (i = 0; i < family->stylen; i++)
 
393
        {
 
394
            int j;
 
395
            char *weight= "", *slant= "", *width= "";
 
396
            WMListItem *item;
 
397
 
 
398
            for (j= 0; fontWeights[j].name; j++)
 
399
              if (fontWeights[j].weight == family->styles[i].weight)
 
400
              {
 
401
                  weight= fontWeights[j].name;
 
402
                  break;
 
403
              }
 
404
            for (j= 0; fontWidths[j].name; j++)
 
405
              if (fontWidths[j].width == family->styles[i].width)
 
406
              {
 
407
                  width= fontWidths[j].name;
 
408
                  break;
 
409
              }
 
410
            for (j= 0; fontSlants[j].name; j++)
 
411
              if (fontSlants[j].slant == family->styles[i].slant)
 
412
              {
 
413
                  slant= fontSlants[j].name;
 
414
                  break;
 
415
              }
 
416
            sprintf(buffer, "%s%s%s%s%s",
 
417
                    weight, *weight?" ":"",
 
418
                    slant, (*slant || *weight)?" ":"",
 
419
                    width);
 
420
            if (!buffer[0])
 
421
              strcpy(buffer, "Roman");
 
422
            
 
423
            item= WMAddListItem(panel->styleL, buffer);
 
424
            item->clientData= family->styles+i;
 
425
            
 
426
            if (oldStyle) {
 
427
                int score= 0;
 
428
                
 
429
                if (oldStyle->width == family->styles[i].width)
 
430
                  score |= 1;
 
431
                if (oldStyle->weight == family->styles[i].weight)
 
432
                  score |= 2;
 
433
                if (oldStyle->slant == family->styles[i].slant)
 
434
                  score |= 4;
 
435
 
 
436
                if (score > oldscore)
 
437
                {
 
438
                    oldi= i;
 
439
                    oldscore= score;
 
440
                }
 
441
            }
 
442
        }
 
443
        WMSelectListItem(panel->styleL, oldi);
 
444
 
 
445
        {
 
446
            int index= WMGetPopUpButtonSelectedItem(panel->optionP);
 
447
            WMMenuItem *item= WMGetPopUpButtonMenuItem(panel->optionP, index);
 
448
            char *ofont, *nfont;
 
449
 
 
450
            ofont= (char*)WMGetMenuItemRepresentedObject(item);
 
451
            
 
452
            nfont= getSelectedFont(panel, ofont);
 
453
            free(ofont);
 
454
            WMSetMenuItemRepresentedObject(item, nfont);
 
455
        }
 
456
        updateSampleFont(panel);
 
457
    }
 
458
}
 
459
 
 
460
 
 
461
static void
 
462
selected(WMWidget *w, void *data)
 
463
{
 
464
    _Panel *panel= (_Panel*)data;
 
465
    int index= WMGetPopUpButtonSelectedItem(panel->optionP);
 
466
    WMMenuItem *item= WMGetPopUpButtonMenuItem(panel->optionP, index);
 
467
    char *ofont, *nfont;
 
468
 
 
469
    ofont= (char*)WMGetMenuItemRepresentedObject(item);
 
470
    
 
471
    nfont= getSelectedFont(panel, ofont);
 
472
    free(ofont);
 
473
    WMSetMenuItemRepresentedObject(item, nfont);
 
474
 
 
475
    updateSampleFont(panel);
 
476
}
 
477
 
 
478
 
 
479
static void
 
480
selectedOption(WMWidget *w, void *data)
 
481
{
 
482
    _Panel *panel= (_Panel*)data;
 
483
    int index = WMGetPopUpButtonSelectedItem(panel->optionP);
 
484
    WMMenuItem *item= WMGetPopUpButtonMenuItem(panel->optionP, index);
 
485
    char *font;
 
486
 
 
487
    font= (char*)WMGetMenuItemRepresentedObject(item);
 
488
    if (font)
 
489
    {
 
490
        FcPattern *pat;
 
491
 
 
492
        pat= FcNameParse(font);
 
493
        if (pat)
 
494
        {
 
495
            FcChar8 *name;
 
496
            int weight, slant, width;
 
497
            double size;
 
498
            int distance, closest, found;
 
499
            int i;
 
500
 
 
501
            FcDefaultSubstitute(pat);
 
502
 
 
503
            if (FcPatternGetString(pat, FC_FAMILY, 0, &name) != FcResultMatch)
 
504
                name= "sans serif";
 
505
 
 
506
            found= 0;
 
507
            /* select family */
 
508
            for (i= 0; i < WMGetListNumberOfRows(panel->familyL); i++)
 
509
            {
 
510
                WMListItem *item= WMGetListItem(panel->familyL, i);
 
511
                FontFamily *family= (FontFamily*)item->clientData;
 
512
                
 
513
                if (strcasecmp(family->name, name)==0)
 
514
                {
 
515
                    found= 1;
 
516
                    WMSelectListItem(panel->familyL, i);
 
517
                    WMSetListPosition(panel->familyL, i);
 
518
                    break;
 
519
                }
 
520
            }
 
521
            if (!found)
 
522
                WMSelectListItem(panel->familyL, -1);
 
523
            selectedFamily(panel->familyL, panel);
 
524
            
 
525
            /* select style */
 
526
            if (FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight) != FcResultMatch)
 
527
                weight= FC_WEIGHT_NORMAL;
 
528
            if (FcPatternGetInteger(pat, FC_WIDTH, 0, &width) != FcResultMatch)
 
529
                width= FC_WIDTH_NORMAL;
 
530
            if (FcPatternGetInteger(pat, FC_SLANT, 0, &slant) != FcResultMatch)
 
531
                slant= FC_SLANT_ROMAN;
 
532
 
 
533
            if (FcPatternGetDouble(pat, FC_PIXEL_SIZE, 0, &size) != FcResultMatch)
 
534
                size= 10.0;
 
535
 
 
536
            for (i=0, found=0, closest=0; i < WMGetListNumberOfRows(panel->styleL); i++)
 
537
            {
 
538
                WMListItem *item= WMGetListItem(panel->styleL, i);
 
539
                FontStyle *style= (FontStyle*)item->clientData;
 
540
 
 
541
                distance = ((abs(style->weight - weight) << 16) +
 
542
                            (abs(style->slant - slant)   <<  8) +
 
543
                            (abs(style->width - width)));
 
544
 
 
545
                if (i==0 || distance < closest) {
 
546
                    closest = distance;
 
547
                    found = i;
 
548
                    if (distance == 0) {
 
549
                        break; /* perfect match */
 
550
                    }
 
551
                }
 
552
            }
 
553
            WMSelectListItem(panel->styleL, found);
 
554
            WMSetListPosition(panel->styleL, found);
 
555
 
 
556
            for (i=0, found=0, closest=0; i < WMGetListNumberOfRows(panel->sizeL); i++)
 
557
            {
 
558
                WMListItem *item= WMGetListItem(panel->sizeL, i);
 
559
                int distance;
 
560
 
 
561
                distance = abs(size - atoi(item->text));
 
562
 
 
563
                if (i==0 || distance < closest) {
 
564
                    closest= distance;
 
565
                    found= i;
 
566
                    if (distance == 0) {
 
567
                        break; /* perfect match */
 
568
                    }
 
569
                }
 
570
            }
 
571
            WMSelectListItem(panel->sizeL, found);
 
572
            WMSetListPosition(panel->sizeL, found);
 
573
            
 
574
            selected(NULL, panel);
 
575
        }
 
576
        else
 
577
            wwarning("Can't parse font '%s'", font);
 
578
    }
 
579
 
 
580
    updateSampleFont(panel);
 
581
}
 
582
 
 
583
 
 
584
static WMLabel *
 
585
createListLabel(WMScreen *scr, WMWidget *parent, char *text)
 
586
{
 
587
    WMLabel *label;
 
588
    WMColor *color;
 
589
    WMFont *boldFont= WMBoldSystemFontOfSize(scr, 12);
 
590
 
 
591
    label = WMCreateLabel(parent);
 
592
    WMSetLabelFont(label, boldFont);
 
593
    WMSetLabelText(label, text);
 
594
    WMSetLabelRelief(label, WRSunken);
 
595
    WMSetLabelTextAlignment(label, WACenter);
 
596
    color = WMDarkGrayColor(scr);
 
597
    WMSetWidgetBackgroundColor(label, color); 
 
598
    WMReleaseColor(color);
 
599
    color = WMWhiteColor(scr);
 
600
    WMSetLabelTextColor(label, color);
 
601
    WMReleaseColor(color);
 
602
 
 
603
    WMReleaseFont(boldFont);
 
604
    
 
605
    return label;
 
606
}
 
607
 
 
608
 
 
609
static void
 
610
showData(_Panel *panel)
 
611
{
 
612
    int i;
 
613
    WMMenuItem *item;
 
614
    
 
615
    for (i= 0; i < WMGetPopUpButtonNumberOfItems(panel->optionP); i++)
 
616
    {
 
617
        char *ofont, *font;
 
618
        
 
619
        item= WMGetPopUpButtonMenuItem(panel->optionP, i);
 
620
        
 
621
        ofont= WMGetMenuItemRepresentedObject(item);
 
622
        if (ofont)
 
623
          wfree(ofont);
 
624
 
 
625
        font= GetStringForKey(fontOptions[i].option);
 
626
        if (font)
 
627
          font= wstrdup(font);
 
628
        WMSetMenuItemRepresentedObject(item, font);
 
629
    }
 
630
 
 
631
    WMSetPopUpButtonSelectedItem(panel->optionP, 0);
 
632
    selectedOption(panel->optionP, panel);
 
633
}
 
634
 
 
635
 
 
636
static void
 
637
storeData(_Panel *panel)
 
638
{
 
639
    int i;
 
640
    WMMenuItem *item;
 
641
    for (i= 0; i < WMGetPopUpButtonNumberOfItems(panel->optionP); i++)
 
642
    {
 
643
        char *font;
 
644
 
 
645
        item= WMGetPopUpButtonMenuItem(panel->optionP, i);
 
646
 
 
647
        font= WMGetMenuItemRepresentedObject(item);
 
648
        if (font && *font)
 
649
        {
 
650
            SetStringForKey(font, fontOptions[i].option);
 
651
        }
 
652
    }
 
653
}
 
654
 
 
655
 
 
656
static void
 
657
createPanel(Panel *p)
 
658
{
 
659
    _Panel *panel = (_Panel*)p;
 
660
    WMScreen *scr = WMWidgetScreen(panel->parent);
 
661
    WMLabel *label;
 
662
    WMBox *hbox, *vbox;
 
663
    int i;
 
664
 
 
665
    lookup_available_fonts(panel);
 
666
 
 
667
    panel->box = WMCreateBox(panel->parent);
 
668
    WMSetViewExpandsToParent(WMWidgetView(panel->box), 5, 2, 5, 5);
 
669
    WMSetBoxHorizontal(panel->box, False);
 
670
    WMSetBoxBorderWidth(panel->box, 8);
 
671
    WMMapWidget(panel->box);
 
672
 
 
673
    hbox = WMCreateBox(panel->box);
 
674
    WMSetBoxHorizontal(hbox, True);
 
675
    WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 40, 22, 8);
 
676
 
 
677
    vbox= WMCreateBox(hbox);
 
678
    WMAddBoxSubview(hbox, WMWidgetView(vbox), False, True, 130, 0, 10);
 
679
    WMSetBoxHorizontal(vbox, False);
 
680
    panel->optionP = WMCreatePopUpButton(vbox);
 
681
    WMAddBoxSubviewAtEnd(vbox, WMWidgetView(panel->optionP), False, True, 20, 0, 8);
 
682
    for (i= 0; fontOptions[i].option; i++)
 
683
    {
 
684
      WMAddPopUpButtonItem(panel->optionP, _(fontOptions[i].label));
 
685
    }
 
686
    WMSetPopUpButtonAction(panel->optionP, selectedOption, panel);
 
687
 
 
688
    label = WMCreateLabel(hbox);
 
689
    WMSetLabelText(label, _("Sample Text"));
 
690
    WMSetLabelTextAlignment(label, WARight);
 
691
    WMAddBoxSubview(hbox, WMWidgetView(label), False, True, 80, 0, 2);
 
692
 
 
693
    panel->sampleT= WMCreateTextField(hbox);
 
694
    WMSetViewExpandsToParent(WMWidgetView(panel->sampleT), 10, 18, 10, 10);
 
695
    WMSetTextFieldText(panel->sampleT, SAMPLE_TEXT);
 
696
    WMAddBoxSubview(hbox, WMWidgetView(panel->sampleT), True, True, 60, 0, 0);
 
697
 
 
698
    
 
699
    hbox = WMCreateBox(panel->box);
 
700
    WMSetBoxHorizontal(hbox, True);
 
701
    WMAddBoxSubview(panel->box, WMWidgetView(hbox), True, True, 100, 0, 2);
 
702
    
 
703
    vbox = WMCreateBox(hbox);
 
704
    WMSetBoxHorizontal(vbox, False);
 
705
    WMAddBoxSubview(hbox, WMWidgetView(vbox), False, True, 240, 20, 4);
 
706
 
 
707
    label = createListLabel(scr, vbox, _("Family"));
 
708
    WMAddBoxSubview(vbox, WMWidgetView(label), False, True, 20, 0, 2);
 
709
 
 
710
    /* family */
 
711
    panel->familyL = WMCreateList(vbox);
 
712
    WMAddBoxSubview(vbox, WMWidgetView(panel->familyL), True, True, 0, 0, 0);
 
713
    if (panel->fonts)
 
714
    {
 
715
        WMListItem *item;
 
716
        for (i= 0; i < panel->fonts->familyn; i++)
 
717
        {
 
718
            item = WMAddListItem(panel->familyL, panel->fonts->families[i].name);
 
719
            item->clientData= panel->fonts->families+i;
 
720
        }
 
721
    }
 
722
    else
 
723
      WMAddListItem(panel->familyL, "sans serif");
 
724
 
 
725
    WMSetListAction(panel->familyL, selectedFamily, panel);
 
726
 
 
727
    vbox = WMCreateBox(hbox);
 
728
    WMSetBoxHorizontal(vbox, False);
 
729
    WMAddBoxSubview(hbox, WMWidgetView(vbox), True, True, 10, 0, 0);
 
730
 
 
731
    {
 
732
        WMBox *box = WMCreateBox(vbox);
 
733
        WMSetBoxHorizontal(box, True);
 
734
        WMAddBoxSubview(vbox, WMWidgetView(box), False, True, 20, 0, 2);
 
735
 
 
736
        label = createListLabel(scr, box, _("Style"));
 
737
        WMAddBoxSubview(box, WMWidgetView(label), True, True, 20, 0, 4);
 
738
 
 
739
        label = createListLabel(scr, box, _("Size"));
 
740
        WMAddBoxSubview(box, WMWidgetView(label), False, True, 60, 0, 0);
 
741
 
 
742
        box = WMCreateBox(vbox);
 
743
        WMSetBoxHorizontal(box, True);
 
744
        WMAddBoxSubview(vbox, WMWidgetView(box), True, True, 20, 0, 0);
 
745
 
 
746
        panel->styleL = WMCreateList(box);
 
747
        WMAddBoxSubview(box, WMWidgetView(panel->styleL), True, True, 0, 0, 4);
 
748
        WMSetListAction(panel->styleL, selected, panel);
 
749
 
 
750
        panel->sizeL = WMCreateList(box);
 
751
        WMAddBoxSubview(box, WMWidgetView(panel->sizeL), False, True, 60, 0, 0);
 
752
        for (i= 0; standardSizes[i]; i++)
 
753
        {
 
754
            WMAddListItem(panel->sizeL, standardSizes[i]);
 
755
        }
 
756
        WMSetListAction(panel->sizeL, selected, panel);
 
757
    }
 
758
    
 
759
 
 
760
    WMMapSubwidgets(panel->box);
 
761
    WMMapWidget(panel->box);
 
762
    WMRealizeWidget(panel->box);
 
763
 
 
764
    showData(panel);
 
765
}
 
766
 
 
767
 
 
768
 
 
769
Panel*
 
770
InitFontSimple(WMScreen *scr, WMWidget *parent)
 
771
{
 
772
    _Panel *panel;
 
773
 
 
774
    panel = wmalloc(sizeof(_Panel));
 
775
    memset(panel, 0, sizeof(_Panel));
 
776
 
 
777
    panel->sectionName = _("Font Configuration");
 
778
 
 
779
    panel->description = _("Configure fonts for Window Maker titlebars, menus etc.");
 
780
 
 
781
    panel->parent = parent;
 
782
 
 
783
    panel->callbacks.createWidgets = createPanel;
 
784
    panel->callbacks.updateDomain = storeData;
 
785
    
 
786
    AddSection(panel, ICON_FILE);
 
787
 
 
788
    return panel;
 
789
}
 
790