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

« back to all changes in this revision

Viewing changes to WINGs/Tests/wtest.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
/*
 
2
 * WINGs test application
 
3
 */
 
4
 
 
5
#include <WINGs/WINGs.h>
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
 
 
11
/*
 
12
 * You need to define this function to link any program to WINGs.
 
13
 * (this is no longer required as there is a default abort handler in WINGs)
 
14
 * This will be called when the application will be terminated because
 
15
 * of a fatal error (only for memory allocation failures ATM).
 
16
 */
 
17
void
 
18
wAbort()
 
19
{
 
20
    exit(1);
 
21
}
 
22
 
 
23
 
 
24
 
 
25
 
 
26
Display *dpy;
 
27
 
 
28
int windowCount = 0;
 
29
 
 
30
void
 
31
closeAction(WMWidget *self, void *data)
 
32
{
 
33
    WMDestroyWidget(self);
 
34
    windowCount--;
 
35
    printf("window closed, window count = %d\n", windowCount);
 
36
    if (windowCount < 1)
 
37
        exit(0);
 
38
}
 
39
 
 
40
 
 
41
void
 
42
testOpenFilePanel(WMScreen *scr)
 
43
{
 
44
    WMOpenPanel *panel;
 
45
 
 
46
    /* windowCount++; */
 
47
 
 
48
    /* get the shared Open File panel */
 
49
    panel = WMGetOpenPanel(scr);
 
50
 
 
51
    WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
 
52
 
 
53
    /* free the panel to save some memory. Not needed otherwise. */
 
54
    WMFreeFilePanel(WMGetOpenPanel(scr));
 
55
}
 
56
 
 
57
 
 
58
void
 
59
testFontPanel(WMScreen *scr)
 
60
{
 
61
    WMFontPanel *panel;
 
62
 
 
63
    /*windowCount++;*/
 
64
 
 
65
    panel = WMGetFontPanel(scr);
 
66
 
 
67
    WMShowFontPanel(panel);
 
68
 
 
69
    /*WMFreeFontPanel(panel);*/
 
70
}
 
71
 
 
72
 
 
73
 
 
74
void
 
75
testFrame(WMScreen *scr)
 
76
{
 
77
    WMWindow *win;
 
78
    WMFrame *frame;
 
79
    int i;
 
80
    static char* titles[] = {
 
81
        "AboveTop",
 
82
        "AtTop",
 
83
        "BelowTop",
 
84
        "AboveBottom",
 
85
        "AtBottom",
 
86
        "BelowBottom"
 
87
    };
 
88
    static WMTitlePosition pos[] = {
 
89
        WTPAboveTop,
 
90
        WTPAtTop,
 
91
        WTPBelowTop,
 
92
        WTPAboveBottom,
 
93
        WTPAtBottom,
 
94
        WTPBelowBottom
 
95
    };
 
96
 
 
97
    windowCount++;
 
98
 
 
99
    win = WMCreateWindow(scr, "testFrame");
 
100
    WMSetWindowTitle(win, "Frame");
 
101
    WMSetWindowCloseAction(win, closeAction, NULL);
 
102
    WMResizeWidget(win, 400, 300);
 
103
 
 
104
    for (i = 0; i < 6; i++) {
 
105
        frame = WMCreateFrame(win);
 
106
        WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
 
107
        WMResizeWidget(frame, 120, 120);
 
108
        WMSetFrameTitle(frame, titles[i]);
 
109
        WMSetFrameTitlePosition(frame, pos[i]);
 
110
    }
 
111
 
 
112
    WMRealizeWidget(win);
 
113
    WMMapSubwidgets(win);
 
114
    WMMapWidget(win);
 
115
 
 
116
}
 
117
 
 
118
 
 
119
/*static void
 
120
 resizedWindow(void *self, WMNotification *notif)
 
121
 {
 
122
 WMView *view = (WMView*)WMGetNotificationObject(notif);
 
123
 WMSize size = WMGetViewSize(view);
 
124
 
 
125
 WMResizeWidget((WMWidget*)self, size.width, size.height);
 
126
 }*/
 
127
 
 
128
void
 
129
testBox(WMScreen *scr)
 
130
{
 
131
    WMWindow *win;
 
132
    WMBox *box, *hbox;
 
133
    WMButton *btn;
 
134
    WMPopUpButton *pop;
 
135
    int i;
 
136
 
 
137
    windowCount++;
 
138
 
 
139
    win = WMCreateWindow(scr, "testBox");
 
140
    WMSetWindowTitle(win, "Box");
 
141
    WMSetWindowCloseAction(win, closeAction, NULL);
 
142
    WMResizeWidget(win, 400, 300);
 
143
 
 
144
    box = WMCreateBox(win);
 
145
    WMSetBoxBorderWidth(box, 5);
 
146
    WMSetViewExpandsToParent(WMWidgetView(box), 0, 0, 0, 0);
 
147
 
 
148
    /*WMSetBoxHorizontal(box, True);*/
 
149
    for (i = 0; i < 4; i++) {
 
150
        btn = WMCreateCommandButton(box);
 
151
        WMSetButtonText(btn, "bla");
 
152
        WMMapWidget(btn);
 
153
        WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
 
154
    }
 
155
 
 
156
    pop = WMCreatePopUpButton(box);
 
157
    WMAddPopUpButtonItem(pop, "ewqeq");
 
158
    WMAddPopUpButtonItem(pop, "ewqeqrewrw");
 
159
    WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5);
 
160
    WMMapWidget(pop);
 
161
 
 
162
    hbox = WMCreateBox(box);
 
163
    WMSetBoxHorizontal(hbox, True);
 
164
    WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
 
165
    WMMapWidget(hbox);
 
166
 
 
167
    for (i = 0; i < 4; i++) {
 
168
        btn = WMCreateCommandButton(hbox);
 
169
        WMSetButtonText(btn, "bla");
 
170
        WMMapWidget(btn);
 
171
        WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
 
172
    }
 
173
 
 
174
 
 
175
    WMRealizeWidget(win);
 
176
    WMMapSubwidgets(win);
 
177
    WMMapWidget(win);
 
178
 
 
179
}
 
180
 
 
181
 
 
182
 
 
183
static void
 
184
singleClick(WMWidget *self, void *data)
 
185
{
 
186
}
 
187
 
 
188
 
 
189
static void
 
190
doubleClick(WMWidget *self, void *data)
 
191
{
 
192
    WMSelectAllListItems((WMList*)self);
 
193
}
 
194
 
 
195
 
 
196
static void
 
197
listSelectionObserver(void *observer, WMNotification *notification)
 
198
{
 
199
    WMLabel *label = (WMLabel*)observer;
 
200
    WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
 
201
    char buf[255];
 
202
 
 
203
    sprintf(buf, "Selected items: %d",
 
204
            WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
 
205
    WMSetLabelText(label, buf);
 
206
}
 
207
 
 
208
 
 
209
void
 
210
testList(WMScreen *scr)
 
211
{
 
212
    WMWindow *win;
 
213
    WMList *list;
 
214
    WMList *mlist;
 
215
    WMLabel *label;
 
216
    WMLabel *mlabel;
 
217
    WMLabel *title;
 
218
    WMLabel *mtitle;
 
219
    char text[100];
 
220
    int i;
 
221
 
 
222
    windowCount++;
 
223
 
 
224
    win = WMCreateWindow(scr, "testList");
 
225
    WMResizeWidget(win, 370, 250);
 
226
    WMSetWindowTitle(win, "List");
 
227
    WMSetWindowCloseAction(win, closeAction, NULL);
 
228
 
 
229
    title = WMCreateLabel(win);
 
230
    WMResizeWidget(title, 150, 20);
 
231
    WMMoveWidget(title, 10, 10);
 
232
    WMSetLabelRelief(title, WRRidge);
 
233
    WMSetLabelText(title, "Single selection list");
 
234
 
 
235
    mtitle = WMCreateLabel(win);
 
236
    WMResizeWidget(mtitle, 150, 20);
 
237
    WMMoveWidget(mtitle, 210, 10);
 
238
    WMSetLabelRelief(mtitle, WRRidge);
 
239
    WMSetLabelText(mtitle, "Multiple selection list");
 
240
 
 
241
    list = WMCreateList(win);
 
242
    /*WMSetListAllowEmptySelection(list, True);*/
 
243
    WMMoveWidget(list, 10, 40);
 
244
    for (i=0; i<105; i++) {
 
245
        sprintf(text, "Item %i", i);
 
246
        WMAddListItem(list, text);
 
247
    }
 
248
    mlist = WMCreateList(win);
 
249
    WMSetListAllowMultipleSelection(mlist, True);
 
250
    /*WMSetListAllowEmptySelection(mlist, True);*/
 
251
    WMMoveWidget(mlist, 210, 40);
 
252
    for (i=0; i<135; i++) {
 
253
        sprintf(text, "Item %i", i);
 
254
        WMAddListItem(mlist, text);
 
255
    }
 
256
 
 
257
    label = WMCreateLabel(win);
 
258
    WMResizeWidget(label, 150, 40);
 
259
    WMMoveWidget(label, 10, 200);
 
260
    WMSetLabelRelief(label, WRRidge);
 
261
    WMSetLabelText(label, "Selected items: 0");
 
262
 
 
263
    mlabel = WMCreateLabel(win);
 
264
    WMResizeWidget(mlabel, 150, 40);
 
265
    WMMoveWidget(mlabel, 210, 200);
 
266
    WMSetLabelRelief(mlabel, WRRidge);
 
267
    WMSetLabelText(mlabel, "Selected items: 0");
 
268
 
 
269
    WMSetListAction(list, singleClick, label);
 
270
    WMSetListDoubleAction(list, doubleClick, label);
 
271
    WMSetListAction(mlist, singleClick, mlabel);
 
272
    WMSetListDoubleAction(mlist, doubleClick, mlabel);
 
273
 
 
274
    WMAddNotificationObserver(listSelectionObserver, label,
 
275
                              WMListSelectionDidChangeNotification, list);
 
276
    WMAddNotificationObserver(listSelectionObserver, mlabel,
 
277
                              WMListSelectionDidChangeNotification, mlist);
 
278
 
 
279
 
 
280
    WMRealizeWidget(win);
 
281
    WMMapSubwidgets(win);
 
282
    WMMapWidget(win);
 
283
}
 
284
 
 
285
 
 
286
void
 
287
testButton(WMScreen *scr)
 
288
{
 
289
    WMWindow *win;
 
290
    int i;
 
291
    char *types[] = {
 
292
        "MomentaryPush",
 
293
        "PushOnPushOff",
 
294
        "Toggle",
 
295
        "Switch",
 
296
        "Radio",
 
297
        "MomentaryChange",
 
298
        "OnOff",
 
299
        "MomentaryLigh"
 
300
    };
 
301
 
 
302
    windowCount++;
 
303
 
 
304
    win = WMCreateWindow(scr, "testButton");
 
305
    WMResizeWidget(win, 300, 300);
 
306
    WMSetWindowTitle(win, "Buttons");
 
307
 
 
308
    WMSetWindowCloseAction(win, closeAction, NULL);
 
309
 
 
310
    for (i = 1; i < 9; i++) {
 
311
        WMButton *b;
 
312
        b = WMCreateButton(win, i);
 
313
        WMResizeWidget(b, 150, 24);
 
314
        WMMoveWidget(b, 20, i*30);
 
315
        WMSetButtonText(b, types[i-1]);
 
316
    }
 
317
 
 
318
    WMRealizeWidget(win);
 
319
    WMMapSubwidgets(win);
 
320
    WMMapWidget(win);
 
321
}
 
322
 
 
323
 
 
324
void
 
325
testGradientButtons(WMScreen *scr)
 
326
{
 
327
    WMWindow *win;
 
328
    WMButton *btn;
 
329
    WMPixmap *pix1, *pix2;
 
330
    RImage *back;
 
331
    RColor light, dark;
 
332
    WMColor *color, *altColor;
 
333
 
 
334
    windowCount++;
 
335
 
 
336
    /* creates the top-level window */
 
337
    win = WMCreateWindow(scr, "testGradientButtons");
 
338
    WMSetWindowTitle(win, "Gradiented Button Demo");
 
339
    WMResizeWidget(win, 300, 200);
 
340
 
 
341
    WMSetWindowCloseAction(win, closeAction, NULL);
 
342
 
 
343
 
 
344
    light.red = 0x90;
 
345
    light.green = 0x85;
 
346
    light.blue = 0x90;
 
347
    dark.red = 0x35;
 
348
    dark.green = 0x30;
 
349
    dark.blue = 0x35;
 
350
 
 
351
    color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
 
352
    WMSetWidgetBackgroundColor(win, color);
 
353
    WMReleaseColor(color);
 
354
 
 
355
    back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
 
356
    RBevelImage(back, RBEV_RAISED2);
 
357
    pix1 = WMCreatePixmapFromRImage(scr, back, 0);
 
358
    RReleaseImage(back);
 
359
 
 
360
    back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
 
361
    RBevelImage(back, RBEV_SUNKEN);
 
362
    pix2 = WMCreatePixmapFromRImage(scr, back, 0);
 
363
    RReleaseImage(back);
 
364
 
 
365
    color = WMWhiteColor(scr);
 
366
    altColor = WMCreateNamedColor(scr, "red", True);
 
367
 
 
368
    btn = WMCreateButton(win, WBTMomentaryChange);
 
369
    WMResizeWidget(btn, 60, 24);
 
370
    WMMoveWidget(btn, 20, 100);
 
371
    WMSetButtonBordered(btn, False);
 
372
    WMSetButtonImagePosition(btn, WIPOverlaps);
 
373
    WMSetButtonImage(btn, pix1);
 
374
    WMSetButtonAltImage(btn, pix2);
 
375
    WMSetButtonText(btn, "Cool");
 
376
    WMSetButtonTextColor(btn, color);
 
377
    WMSetButtonAltTextColor(btn, altColor);
 
378
 
 
379
    WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
 
380
 
 
381
    btn = WMCreateButton(win, WBTMomentaryChange);
 
382
    WMResizeWidget(btn, 60, 24);
 
383
    WMMoveWidget(btn, 90, 100);
 
384
    WMSetButtonBordered(btn, False);
 
385
    WMSetButtonImagePosition(btn, WIPOverlaps);
 
386
    WMSetButtonImage(btn, pix1);
 
387
    WMSetButtonAltImage(btn, pix2);
 
388
    WMSetButtonText(btn, "Button");
 
389
    WMSetButtonTextColor(btn, color);
 
390
 
 
391
    WMSetBalloonTextForView("Este ļæ½ outro balļæ½o.", WMWidgetView(btn));
 
392
 
 
393
    WMReleaseColor(color);
 
394
    color = WMCreateNamedColor(scr, "orange", True);
 
395
 
 
396
    btn = WMCreateButton(win, WBTMomentaryChange);
 
397
    WMResizeWidget(btn, 60, 24);
 
398
    WMMoveWidget(btn, 160, 100);
 
399
    WMSetButtonBordered(btn, False);
 
400
    WMSetButtonImagePosition(btn, WIPOverlaps);
 
401
    WMSetButtonImage(btn, pix1);
 
402
    WMSetButtonAltImage(btn, pix2);
 
403
    WMSetButtonText(btn, "Test");
 
404
    WMSetButtonTextColor(btn, color);
 
405
 
 
406
    WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
 
407
                            WMWidgetView(btn));
 
408
 
 
409
    WMReleaseColor(color);
 
410
    WMReleaseColor(altColor);
 
411
 
 
412
    WMRealizeWidget(win);
 
413
    WMMapSubwidgets(win);
 
414
    WMMapWidget(win);
 
415
}
 
416
 
 
417
 
 
418
void
 
419
testScrollView(WMScreen *scr)
 
420
{
 
421
    WMWindow *win;
 
422
    WMScrollView *sview;
 
423
    WMFrame *f;
 
424
    WMLabel *l;
 
425
    char buffer[128];
 
426
    int i;
 
427
 
 
428
    windowCount++;
 
429
 
 
430
    /* creates the top-level window */
 
431
    win = WMCreateWindow(scr, "testScroll");
 
432
    WMSetWindowTitle(win, "Scrollable View");
 
433
 
 
434
    WMSetWindowCloseAction(win, closeAction, NULL);
 
435
 
 
436
    /* set the window size */
 
437
    WMResizeWidget(win, 300, 300);
 
438
 
 
439
    /* creates a scrollable view inside the top-level window */
 
440
    sview = WMCreateScrollView(win);
 
441
    WMResizeWidget(sview, 200, 200);
 
442
    WMMoveWidget(sview, 30, 30);
 
443
    WMSetScrollViewRelief(sview, WRSunken);
 
444
    WMSetScrollViewHasVerticalScroller(sview, True);
 
445
    WMSetScrollViewHasHorizontalScroller(sview, True);
 
446
 
 
447
    /* create a frame with a bunch of labels */
 
448
    f = WMCreateFrame(win);
 
449
    WMResizeWidget(f, 400, 400);
 
450
    WMSetFrameRelief(f, WRFlat);
 
451
 
 
452
    for (i=0; i<20; i++) {
 
453
        l = WMCreateLabel(f);
 
454
        WMResizeWidget(l, 50, 18);
 
455
        WMMoveWidget(l, 10, 20*i);
 
456
        sprintf(buffer, "Label %i", i);
 
457
        WMSetLabelText(l, buffer);
 
458
        WMSetLabelRelief(l, WRSimple);
 
459
    }
 
460
    WMMapSubwidgets(f);
 
461
    WMMapWidget(f);
 
462
 
 
463
    WMSetScrollViewContentView(sview, WMWidgetView(f));
 
464
 
 
465
    /* make the windows of the widgets be actually created */
 
466
    WMRealizeWidget(win);
 
467
 
 
468
    /* Map all child widgets of the top-level be mapped.
 
469
     * You must call this for each container widget (like frames),
 
470
     * even if they are childs of the top-level window.
 
471
     */
 
472
    WMMapSubwidgets(win);
 
473
 
 
474
    /* map the top-level window */
 
475
    WMMapWidget(win);
 
476
}
 
477
 
 
478
 
 
479
void
 
480
testColorWell(WMScreen *scr)
 
481
{
 
482
    WMWindow *win;
 
483
    WMColorWell *well1, *well2;
 
484
 
 
485
    windowCount++;
 
486
 
 
487
    win = WMCreateWindow(scr, "testColor");
 
488
    WMResizeWidget(win, 300, 300);
 
489
    WMSetWindowCloseAction(win, closeAction, NULL);
 
490
 
 
491
    well1 = WMCreateColorWell(win);
 
492
    WMResizeWidget(well1, 60, 40);
 
493
    WMMoveWidget(well1, 100, 100);
 
494
    WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
 
495
    well2 = WMCreateColorWell(win);
 
496
    WMResizeWidget(well2, 60, 40);
 
497
    WMMoveWidget(well2, 200, 100);
 
498
    WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
 
499
 
 
500
    WMRealizeWidget(win);
 
501
    WMMapSubwidgets(win);
 
502
    WMMapWidget(win);
 
503
}
 
504
 
 
505
 
 
506
void
 
507
testColorPanel(WMScreen *scr)
 
508
{
 
509
    WMColorPanel *panel = WMGetColorPanel(scr);
 
510
 
 
511
    /*if (colorname) {
 
512
     startcolor = WMCreateNamedColor(scr, colorname, False);
 
513
     WMSetColorPanelColor(panel, startcolor);
 
514
     WMReleaseColor(startcolor);
 
515
     }*/
 
516
 
 
517
    WMShowColorPanel(panel);
 
518
}
 
519
 
 
520
void
 
521
sliderCallback(WMWidget *w, void *data)
 
522
{
 
523
    printf("SLIDER == %i\n", WMGetSliderValue(w));
 
524
}
 
525
 
 
526
 
 
527
void
 
528
testSlider(WMScreen *scr)
 
529
{
 
530
    WMWindow *win;
 
531
    WMSlider *s;
 
532
 
 
533
    windowCount++;
 
534
 
 
535
    win = WMCreateWindow(scr, "testSlider");
 
536
    WMResizeWidget(win, 300, 300);
 
537
    WMSetWindowTitle(win, "Sliders");
 
538
 
 
539
    WMSetWindowCloseAction(win, closeAction, NULL);
 
540
 
 
541
    s = WMCreateSlider(win);
 
542
    WMResizeWidget(s, 16, 100);
 
543
    WMMoveWidget(s, 100, 100);
 
544
    WMSetSliderKnobThickness(s, 8);
 
545
    WMSetSliderContinuous(s, False);
 
546
    WMSetSliderAction(s, sliderCallback, s);
 
547
 
 
548
    s = WMCreateSlider(win);
 
549
    WMResizeWidget(s, 100, 16);
 
550
    WMMoveWidget(s, 100, 10);
 
551
    WMSetSliderKnobThickness(s, 8);
 
552
 
 
553
    WMRealizeWidget(win);
 
554
    WMMapSubwidgets(win);
 
555
    WMMapWidget(win);
 
556
}
 
557
 
 
558
 
 
559
void
 
560
testTextField(WMScreen *scr)
 
561
{
 
562
    WMWindow *win;
 
563
    WMTextField *field, *field2;
 
564
 
 
565
    windowCount++;
 
566
 
 
567
    win = WMCreateWindow(scr, "testTextField");
 
568
    WMResizeWidget(win, 400, 300);
 
569
 
 
570
    WMSetWindowCloseAction(win, closeAction, NULL);
 
571
 
 
572
    field = WMCreateTextField(win);
 
573
    WMResizeWidget(field, 200, 20);
 
574
    WMMoveWidget(field, 20, 20);
 
575
 
 
576
    field2 = WMCreateTextField(win);
 
577
    WMResizeWidget(field2, 200, 20);
 
578
    WMMoveWidget(field2, 20, 50);
 
579
    WMSetTextFieldAlignment(field2, WARight);
 
580
 
 
581
    WMRealizeWidget(win);
 
582
    WMMapSubwidgets(win);
 
583
    WMMapWidget(win);
 
584
 
 
585
}
 
586
 
 
587
 
 
588
void
 
589
testText(WMScreen *scr)
 
590
{
 
591
    WMWindow *win;
 
592
    WMText *text;
 
593
    WMFont *font;
 
594
    void *tb;
 
595
    FILE *file = fopen("wm.html", "rb");
 
596
 
 
597
    windowCount++;
 
598
 
 
599
    win = WMCreateWindow(scr, "testText");
 
600
    WMResizeWidget(win, 500, 300);
 
601
 
 
602
    WMSetWindowCloseAction(win, closeAction, NULL);
 
603
 
 
604
    text = WMCreateText(win);
 
605
    WMResizeWidget(text, 480, 280);
 
606
    WMMoveWidget(text, 10, 10);
 
607
    WMSetTextHasVerticalScroller(text, True);
 
608
    WMSetTextEditable(text, False);
 
609
    WMSetTextIgnoresNewline(text, False);
 
610
 
 
611
#define FNAME "Verdana,Luxi Sans:pixelsize=12"
 
612
#define MSG \
 
613
    "Window Maker is the GNU window manager for the " \
 
614
    "X Window System. It was designed to emulate the " \
 
615
    "look and feel of part of the NEXTSTEP(tm) GUI. It's " \
 
616
    "supposed to be relatively fast and small, feature " \
 
617
    "rich, easy to configure and easy to use, with a simple " \
 
618
    "and elegant appearance borrowed from NEXTSTEP(tm)."
 
619
 
 
620
    font = WMCreateFont(scr, FNAME":autohint=false");
 
621
    WMSetTextDefaultFont(text, font);
 
622
    WMReleaseFont(font);
 
623
 
 
624
    if (0 && file) {
 
625
        char buf[1024];
 
626
 
 
627
        WMFreezeText(text);
 
628
        while(fgets(buf, 1023, file))
 
629
            WMAppendTextStream(text, buf);
 
630
 
 
631
        fclose(file);
 
632
        WMThawText(text);
 
633
    } else {
 
634
        WMAppendTextStream(text, "First paragraph has autohinting turned off, "
 
635
                           "while the second has it turned on:");
 
636
        WMAppendTextStream(text, "\n\n\n");
 
637
        WMAppendTextStream(text, MSG);
 
638
        WMAppendTextStream(text, "\n\n\n");
 
639
        font = WMCreateFont(scr, FNAME":autohint=true");
 
640
        tb = WMCreateTextBlockWithText(text, MSG, font, WMBlackColor(scr),
 
641
                                       0, strlen(MSG));
 
642
        WMAppendTextBlock(text, tb);
 
643
        WMReleaseFont(font);
 
644
    }
 
645
 
 
646
    WMRealizeWidget(win);
 
647
    WMMapSubwidgets(win);
 
648
    WMMapWidget(win);
 
649
}
 
650
 
 
651
 
 
652
void
 
653
testProgressIndicator(WMScreen *scr)
 
654
{
 
655
    WMWindow *win;
 
656
    WMProgressIndicator *pPtr;
 
657
 
 
658
    windowCount++;
 
659
 
 
660
    win = WMCreateWindow(scr, "testProgressIndicator");
 
661
    WMResizeWidget(win, 292, 32);
 
662
 
 
663
    WMSetWindowCloseAction(win, closeAction, NULL);
 
664
 
 
665
    pPtr = WMCreateProgressIndicator(win);
 
666
    WMMoveWidget(pPtr, 8, 8);
 
667
    WMSetProgressIndicatorValue(pPtr, 75);
 
668
 
 
669
    WMRealizeWidget(win);
 
670
    WMMapSubwidgets(win);
 
671
    WMMapWidget(win);
 
672
 
 
673
}
 
674
 
 
675
 
 
676
void
 
677
testPullDown(WMScreen *scr)
 
678
{
 
679
    WMWindow *win;
 
680
    WMPopUpButton *pop, *pop2;
 
681
 
 
682
    windowCount++;
 
683
 
 
684
    win = WMCreateWindow(scr, "pullDown");
 
685
    WMResizeWidget(win, 400, 300);
 
686
 
 
687
    WMSetWindowCloseAction(win, closeAction, NULL);
 
688
 
 
689
    pop = WMCreatePopUpButton(win);
 
690
    WMResizeWidget(pop, 100, 20);
 
691
    WMMoveWidget(pop, 50, 60);
 
692
    WMSetPopUpButtonPullsDown(pop, True);
 
693
    WMSetPopUpButtonText(pop, "Commands");
 
694
    WMAddPopUpButtonItem(pop, "Add");
 
695
    WMAddPopUpButtonItem(pop, "Remove");
 
696
    WMAddPopUpButtonItem(pop, "Check");
 
697
    WMAddPopUpButtonItem(pop, "Eat");
 
698
 
 
699
    pop2 = WMCreatePopUpButton(win);
 
700
    WMResizeWidget(pop2, 100, 20);
 
701
    WMMoveWidget(pop2, 200, 60);
 
702
    WMSetPopUpButtonText(pop2, "Select");
 
703
    WMAddPopUpButtonItem(pop2, "Apples");
 
704
    WMAddPopUpButtonItem(pop2, "Bananas");
 
705
    WMAddPopUpButtonItem(pop2, "Strawberries");
 
706
    WMAddPopUpButtonItem(pop2, "Blueberries");
 
707
 
 
708
    WMRealizeWidget(win);
 
709
    WMMapSubwidgets(win);
 
710
    WMMapWidget(win);
 
711
 
 
712
}
 
713
 
 
714
 
 
715
void
 
716
testTabView(WMScreen *scr)
 
717
{
 
718
    WMWindow *win;
 
719
    WMTabView *tabv;
 
720
    WMTabViewItem *tab;
 
721
    WMFrame *frame;
 
722
    WMLabel *label;
 
723
 
 
724
    windowCount++;
 
725
 
 
726
    win = WMCreateWindow(scr, "testTabs");
 
727
    WMResizeWidget(win, 400, 300);
 
728
 
 
729
    WMSetWindowCloseAction(win, closeAction, NULL);
 
730
 
 
731
    tabv = WMCreateTabView(win);
 
732
    WMMoveWidget(tabv, 50, 50);
 
733
    WMResizeWidget(tabv, 300, 200);
 
734
 
 
735
    frame = WMCreateFrame(win);
 
736
    WMSetFrameRelief(frame, WRFlat);
 
737
    label = WMCreateLabel(frame);
 
738
    WMResizeWidget(label, 100, 100);
 
739
    WMSetLabelText(label, "Label 1");
 
740
    WMMapWidget(label);
 
741
 
 
742
 
 
743
    tab = WMCreateTabViewItemWithIdentifier(0);
 
744
    WMSetTabViewItemView(tab, WMWidgetView(frame));
 
745
    WMAddItemInTabView(tabv, tab);
 
746
    WMSetTabViewItemLabel(tab, "Instances");
 
747
 
 
748
    frame = WMCreateFrame(win);
 
749
    WMSetFrameRelief(frame, WRFlat);
 
750
    label = WMCreateLabel(frame);
 
751
    WMResizeWidget(label, 40, 50);
 
752
    WMSetLabelText(label, "Label 2");
 
753
    WMMapWidget(label);
 
754
 
 
755
 
 
756
    tab = WMCreateTabViewItemWithIdentifier(0);
 
757
    WMSetTabViewItemView(tab, WMWidgetView(frame));
 
758
    WMAddItemInTabView(tabv, tab);
 
759
    WMSetTabViewItemLabel(tab, "Classes");
 
760
 
 
761
 
 
762
    frame = WMCreateFrame(win);
 
763
    WMSetFrameRelief(frame, WRFlat);
 
764
    label = WMCreateLabel(frame);
 
765
    WMResizeWidget(label, 100, 100);
 
766
    WMMoveWidget(label, 60, 40);
 
767
    WMSetLabelText(label, "Label 3");
 
768
    WMMapWidget(label);
 
769
 
 
770
    tab = WMCreateTabViewItemWithIdentifier(0);
 
771
    WMSetTabViewItemView(tab, WMWidgetView(frame));
 
772
    WMAddItemInTabView(tabv, tab);
 
773
    WMSetTabViewItemLabel(tab, "Something");
 
774
 
 
775
 
 
776
    frame = WMCreateFrame(win);
 
777
    WMSetFrameRelief(frame, WRFlat);
 
778
    label = WMCreateLabel(frame);
 
779
    WMResizeWidget(label, 100, 100);
 
780
    WMMoveWidget(label, 160, 40);
 
781
    WMSetLabelText(label, "Label 4");
 
782
    WMMapWidget(label);
 
783
 
 
784
    tab = WMCreateTabViewItemWithIdentifier(0);
 
785
    WMSetTabViewItemView(tab, WMWidgetView(frame));
 
786
    WMAddItemInTabView(tabv, tab);
 
787
    WMSetTabViewItemLabel(tab, "Bla!");
 
788
 
 
789
 
 
790
 
 
791
    frame = WMCreateFrame(win);
 
792
    WMSetFrameRelief(frame, WRFlat);
 
793
    label = WMCreateLabel(frame);
 
794
    WMResizeWidget(label, 100, 100);
 
795
    WMMoveWidget(label, 160, 40);
 
796
    WMSetLabelText(label, "Label fjweqklrj qwl");
 
797
    WMMapWidget(label);
 
798
    tab = WMCreateTabViewItemWithIdentifier(0);
 
799
    WMSetTabViewItemView(tab, WMWidgetView(frame));
 
800
    WMAddItemInTabView(tabv, tab);
 
801
    WMSetTabViewItemLabel(tab, "Weee!");
 
802
 
 
803
 
 
804
    WMRealizeWidget(win);
 
805
    WMMapSubwidgets(win);
 
806
    WMMapWidget(win);
 
807
}
 
808
 
 
809
 
 
810
void
 
811
splitViewConstrainProc(WMSplitView *sPtr, int indView,
 
812
                       int *minSize, int *maxSize)
 
813
{
 
814
    switch (indView) {
 
815
    case 0:
 
816
        *minSize = 20;
 
817
        break;
 
818
    case 1:
 
819
        *minSize = 40;
 
820
        *maxSize = 80;
 
821
        break;
 
822
    case 2:
 
823
        *maxSize = 60;
 
824
        break;
 
825
    default:
 
826
        break;
 
827
    }
 
828
}
 
829
 
 
830
 
 
831
static void
 
832
resizeSplitView(XEvent *event, void *data)
 
833
{
 
834
    WMSplitView *sPtr = (WMSplitView*)data;
 
835
 
 
836
    if (event->type == ConfigureNotify) {
 
837
        int width = event->xconfigure.width - 10;
 
838
 
 
839
        if (width < WMGetSplitViewDividerThickness(sPtr))
 
840
            width = WMGetSplitViewDividerThickness(sPtr);
 
841
 
 
842
        if (width != WMWidgetWidth(sPtr) ||
 
843
            event->xconfigure.height != WMWidgetHeight(sPtr))
 
844
            WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
 
845
    }
 
846
}
 
847
 
 
848
void
 
849
appendSubviewButtonAction(WMWidget *self, void *data)
 
850
{
 
851
    WMSplitView *sPtr = (WMSplitView*)data;
 
852
    char buf[64];
 
853
    WMLabel *label = WMCreateLabel(sPtr);
 
854
 
 
855
    sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
 
856
    WMSetLabelText(label, buf);
 
857
    WMSetLabelRelief(label, WRSunken);
 
858
    WMAddSplitViewSubview(sPtr, WMWidgetView(label));
 
859
    WMRealizeWidget(label);
 
860
    WMMapWidget(label);
 
861
}
 
862
 
 
863
void
 
864
removeSubviewButtonAction(WMWidget *self, void *data)
 
865
{
 
866
    WMSplitView *sPtr = (WMSplitView*)data;
 
867
    int count = WMGetSplitViewSubviewsCount(sPtr);
 
868
 
 
869
    if (count > 2) {
 
870
        WMView *view = WMGetSplitViewSubviewAt(sPtr, count-1);
 
871
        WMDestroyWidget(WMWidgetOfView(view));
 
872
        WMRemoveSplitViewSubviewAt(sPtr, count-1);
 
873
    }
 
874
}
 
875
 
 
876
void
 
877
orientationButtonAction(WMWidget *self, void *data)
 
878
{
 
879
    WMSplitView *sPtr = (WMSplitView*)data;
 
880
    WMSetSplitViewVertical(sPtr, !WMGetSplitViewVertical(sPtr));
 
881
}
 
882
 
 
883
void
 
884
adjustSubviewsButtonAction(WMWidget *self, void *data)
 
885
{
 
886
    WMAdjustSplitViewSubviews((WMSplitView*)data);
 
887
}
 
888
 
 
889
void
 
890
testSplitView(WMScreen *scr)
 
891
{
 
892
    WMWindow *win;
 
893
    WMSplitView *splitv1, *splitv2;
 
894
    WMFrame *frame;
 
895
    WMLabel *label;
 
896
    WMButton *button;
 
897
 
 
898
    windowCount++;
 
899
 
 
900
    win = WMCreateWindow(scr, "testTabs");
 
901
    WMResizeWidget(win, 300, 400);
 
902
    WMSetWindowCloseAction(win, closeAction, NULL);
 
903
 
 
904
    frame = WMCreateFrame(win);
 
905
    WMSetFrameRelief(frame, WRSunken);
 
906
    WMMoveWidget(frame, 5, 5);
 
907
    WMResizeWidget(frame, 290, 40);
 
908
 
 
909
    splitv1 = WMCreateSplitView(win);
 
910
    WMMoveWidget(splitv1, 5, 50);
 
911
    WMResizeWidget(splitv1, 290, 345);
 
912
    WMSetSplitViewConstrainProc(splitv1, splitViewConstrainProc);
 
913
    WMCreateEventHandler(WMWidgetView(win), StructureNotifyMask,
 
914
                         resizeSplitView, splitv1);
 
915
 
 
916
    button = WMCreateCommandButton(frame);
 
917
    WMSetButtonText(button, "+");
 
918
    WMSetButtonAction(button, appendSubviewButtonAction, splitv1);
 
919
    WMMoveWidget(button, 10, 8);
 
920
    WMMapWidget(button);
 
921
 
 
922
    button = WMCreateCommandButton(frame);
 
923
    WMSetButtonText(button, "-");
 
924
    WMSetButtonAction(button, removeSubviewButtonAction, splitv1);
 
925
    WMMoveWidget(button, 80, 8);
 
926
    WMMapWidget(button);
 
927
 
 
928
    button = WMCreateCommandButton(frame);
 
929
    WMSetButtonText(button, "=");
 
930
    WMMoveWidget(button, 150, 8);
 
931
    WMSetButtonAction(button, adjustSubviewsButtonAction, splitv1);
 
932
    WMMapWidget(button);
 
933
 
 
934
    button = WMCreateCommandButton(frame);
 
935
    WMSetButtonText(button, "#");
 
936
    WMMoveWidget(button, 220, 8);
 
937
    WMSetButtonAction(button, orientationButtonAction, splitv1);
 
938
    WMMapWidget(button);
 
939
 
 
940
    label = WMCreateLabel(splitv1);
 
941
    WMSetLabelText(label, "Subview 1");
 
942
    WMSetLabelRelief(label, WRSunken);
 
943
    WMMapWidget(label);
 
944
    WMAddSplitViewSubview(splitv1, WMWidgetView(label));
 
945
 
 
946
    splitv2 = WMCreateSplitView(splitv1);
 
947
    WMResizeWidget(splitv2, 150, 150);
 
948
    WMSetSplitViewVertical(splitv2, True);
 
949
 
 
950
    label = WMCreateLabel(splitv2);
 
951
    WMSetLabelText(label, "Subview 2.1");
 
952
    WMSetLabelRelief(label, WRSunken);
 
953
    WMMapWidget(label);
 
954
    WMAddSplitViewSubview(splitv2, WMWidgetView(label));
 
955
 
 
956
    label = WMCreateLabel(splitv2);
 
957
    WMSetLabelText(label, "Subview 2.2");
 
958
    WMSetLabelRelief(label, WRSunken);
 
959
    WMMapWidget(label);
 
960
    WMAddSplitViewSubview(splitv2, WMWidgetView(label));
 
961
 
 
962
    label = WMCreateLabel(splitv2);
 
963
    WMSetLabelText(label, "Subview 2.3");
 
964
    WMSetLabelRelief(label, WRSunken);
 
965
    WMMapWidget(label);
 
966
    WMAddSplitViewSubview(splitv2, WMWidgetView(label));
 
967
 
 
968
    WMMapWidget(splitv2);
 
969
    WMAddSplitViewSubview(splitv1, WMWidgetView(splitv2));
 
970
 
 
971
    WMRealizeWidget(win);
 
972
    WMMapSubwidgets(win);
 
973
    WMMapWidget(win);
 
974
}
 
975
 
 
976
 
 
977
void
 
978
testUD()
 
979
{
 
980
    WMUserDefaults *defs;
 
981
    char str[32];
 
982
 
 
983
    defs = WMGetStandardUserDefaults();
 
984
 
 
985
    sprintf(str, "TEST DATA");
 
986
    puts(str);
 
987
    WMSetUDStringForKey(defs, str, "testKey");
 
988
    puts(str);
 
989
}
 
990
 
 
991
 
 
992
int
 
993
main(int argc, char **argv)
 
994
{
 
995
    WMScreen *scr;
 
996
    WMPixmap *pixmap;
 
997
 
 
998
 
 
999
    /* Initialize the application */
 
1000
    WMInitializeApplication("Test@eqweq_ewq$eqw", &argc, argv);
 
1001
 
 
1002
    testUD();
 
1003
 
 
1004
    /*
 
1005
     * Open connection to the X display.
 
1006
     */
 
1007
    dpy = XOpenDisplay("");
 
1008
 
 
1009
    if (!dpy) {
 
1010
        puts("could not open display");
 
1011
        exit(1);
 
1012
    }
 
1013
 
 
1014
    /* This is used to disable buffering of X protocol requests.
 
1015
     * Do NOT use it unless when debugging. It will cause a major
 
1016
     * slowdown in your application
 
1017
     */
 
1018
#if 0
 
1019
    XSynchronize(dpy, True);
 
1020
#endif
 
1021
    /*
 
1022
     * Create screen descriptor.
 
1023
     */
 
1024
    scr = WMCreateScreen(dpy, DefaultScreen(dpy));
 
1025
 
 
1026
    /*
 
1027
     * Loads the logo of the application.
 
1028
     */
 
1029
    pixmap = WMCreatePixmapFromFile(scr, "logo.xpm");
 
1030
 
 
1031
    /*
 
1032
     * Makes the logo be used in standard dialog panels.
 
1033
     */
 
1034
    if (pixmap) {
 
1035
        WMSetApplicationIconPixmap(scr, pixmap);
 
1036
        WMReleasePixmap(pixmap);
 
1037
    }
 
1038
 
 
1039
    /*
 
1040
     * Do some test stuff.
 
1041
     *
 
1042
     * Put the testSomething() function you want to test here.
 
1043
     */
 
1044
 
 
1045
    testText(scr);
 
1046
    testFontPanel(scr);
 
1047
 
 
1048
    testColorPanel(scr);
 
1049
 
 
1050
#if 0
 
1051
 
 
1052
    testBox(scr);
 
1053
    testButton(scr);
 
1054
    testColorPanel(scr);
 
1055
    testColorWell(scr);
 
1056
    testDragAndDrop(scr);
 
1057
    testFrame(scr);
 
1058
    testGradientButtons(scr);
 
1059
    testList(scr);
 
1060
    testOpenFilePanel(scr);
 
1061
    testProgressIndicator(scr);
 
1062
    testPullDown(scr);
 
1063
    testScrollView(scr);
 
1064
    testSlider(scr);
 
1065
    testSplitView(scr);
 
1066
    testTabView(scr);
 
1067
    testTextField(scr);
 
1068
#endif
 
1069
    /*
 
1070
     * The main event loop.
 
1071
     *
 
1072
     */
 
1073
    WMScreenMainLoop(scr);
 
1074
 
 
1075
    return 0;
 
1076
}
 
1077