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

« back to all changes in this revision

Viewing changes to src/dialog.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
/* dialog.c - dialog windows for internal use
 
2
 *
 
3
 *  Window Maker window manager
 
4
 *
 
5
 *  Copyright (c) 1997-2003 Alfredo K. Kojima
 
6
 *  Copyright (c) 1998-2003 Dan Pascu
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
21
 *  USA.
 
22
 */
 
23
 
 
24
#include "wconfig.h"
 
25
 
 
26
#include <X11/Xlib.h>
 
27
#include <X11/Xutil.h>
 
28
#include <X11/keysym.h>
 
29
 
 
30
#include <stdlib.h>
 
31
#include <stdio.h>
 
32
#include <unistd.h>
 
33
#include <string.h>
 
34
#include <sys/types.h>
 
35
#include <sys/stat.h>
 
36
#include <dirent.h>
 
37
#include <limits.h>
 
38
 
 
39
#ifdef HAVE_MALLOC_H
 
40
#include <malloc.h>
 
41
#endif
 
42
 
 
43
#include <signal.h>
 
44
#ifdef __FreeBSD__
 
45
#include <sys/signal.h>
 
46
#endif
 
47
 
 
48
 
 
49
#ifndef PATH_MAX
 
50
#define PATH_MAX DEFAULT_PATH_MAX
 
51
#endif
 
52
 
 
53
#include "WindowMaker.h"
 
54
#include "GNUstep.h"
 
55
#include "screen.h"
 
56
#include "dialog.h"
 
57
#include "funcs.h"
 
58
#include "stacking.h"
 
59
#include "framewin.h"
 
60
#include "window.h"
 
61
#include "actions.h"
 
62
#include "defaults.h"
 
63
#include "xinerama.h"
 
64
 
 
65
 
 
66
 
 
67
extern WPreferences wPreferences;
 
68
 
 
69
 
 
70
static WMPoint
 
71
getCenter(WScreen *scr, int width, int height)
 
72
{
 
73
    return wGetPointToCenterRectInHead(scr, wGetHeadForPointerLocation(scr),
 
74
                                       width, height);
 
75
}
 
76
 
 
77
 
 
78
int
 
79
wMessageDialog(WScreen *scr, char *title, char *message,
 
80
               char *defBtn, char *altBtn, char *othBtn)
 
81
{
 
82
    WMAlertPanel *panel;
 
83
    Window parent;
 
84
    WWindow *wwin;
 
85
    int result;
 
86
    WMPoint center;
 
87
 
 
88
    panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
 
89
                               defBtn, altBtn, othBtn);
 
90
 
 
91
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
 
92
 
 
93
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
94
 
 
95
 
 
96
    center = getCenter(scr, 400, 180);
 
97
    wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
 
98
                                 400, 180);
 
99
    wwin->client_leader = WMWidgetXID(panel->win);
 
100
 
 
101
    WMMapWidget(panel->win);
 
102
 
 
103
    wWindowMap(wwin);
 
104
 
 
105
    WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
 
106
 
 
107
    result = panel->result;
 
108
 
 
109
    WMUnmapWidget(panel->win);
 
110
 
 
111
    wUnmanageWindow(wwin, False, False);
 
112
 
 
113
    WMDestroyAlertPanel(panel);
 
114
 
 
115
    XDestroyWindow(dpy, parent);
 
116
 
 
117
    return result;
 
118
}
 
119
 
 
120
 
 
121
void
 
122
toggleSaveSession(WMWidget *w, void *data)
 
123
{
 
124
    wPreferences.save_session_on_exit = WMGetButtonSelected((WMButton *) w);
 
125
}
 
126
 
 
127
 
 
128
int
 
129
wExitDialog(WScreen *scr, char *title, char *message,
 
130
            char *defBtn, char *altBtn, char *othBtn)
 
131
{
 
132
    WMAlertPanel *panel;
 
133
    WMButton *saveSessionBtn;
 
134
    Window parent;
 
135
    WWindow *wwin;
 
136
    WMPoint center;
 
137
    int result;
 
138
 
 
139
    panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
 
140
                               defBtn, altBtn, othBtn);
 
141
 
 
142
    /* add save session button */
 
143
    saveSessionBtn = WMCreateSwitchButton(panel->hbox);
 
144
    WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
 
145
    WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn),
 
146
                    False, True, 200, 0, 0);
 
147
    WMSetButtonText(saveSessionBtn, _("Save workspace state"));
 
148
    WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
 
149
    WMRealizeWidget(saveSessionBtn);
 
150
    WMMapWidget(saveSessionBtn);
 
151
 
 
152
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
 
153
 
 
154
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
155
 
 
156
    center = getCenter(scr, 400, 180);
 
157
    wwin = wManageInternalWindow(scr, parent, None, NULL,
 
158
                                 center.x, center.y, 400, 180);
 
159
 
 
160
    wwin->client_leader = WMWidgetXID(panel->win);
 
161
 
 
162
    WMMapWidget(panel->win);
 
163
 
 
164
    wWindowMap(wwin);
 
165
 
 
166
    WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
 
167
 
 
168
    result = panel->result;
 
169
 
 
170
    WMUnmapWidget(panel->win);
 
171
 
 
172
    wUnmanageWindow(wwin, False, False);
 
173
 
 
174
    WMDestroyAlertPanel(panel);
 
175
 
 
176
    XDestroyWindow(dpy, parent);
 
177
 
 
178
    return result;
 
179
}
 
180
 
 
181
 
 
182
int
 
183
wInputDialog(WScreen *scr, char *title, char *message, char **text)
 
184
{
 
185
    WWindow *wwin;
 
186
    Window parent;
 
187
    WMInputPanel *panel;
 
188
    char *result;
 
189
    WMPoint center;
 
190
 
 
191
    panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
 
192
                               _("OK"), _("Cancel"));
 
193
 
 
194
 
 
195
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
 
196
    XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
 
197
 
 
198
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
199
 
 
200
    center = getCenter(scr, 320, 160);
 
201
    wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
 
202
                                 320, 160);
 
203
 
 
204
    wwin->client_leader = WMWidgetXID(panel->win);
 
205
 
 
206
    WMMapWidget(panel->win);
 
207
 
 
208
    wWindowMap(wwin);
 
209
 
 
210
    WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
 
211
 
 
212
    if (panel->result == WAPRDefault)
 
213
        result = WMGetTextFieldText(panel->text);
 
214
    else
 
215
        result = NULL;
 
216
 
 
217
    wUnmanageWindow(wwin, False, False);
 
218
 
 
219
    WMDestroyInputPanel(panel);
 
220
 
 
221
    XDestroyWindow(dpy, parent);
 
222
 
 
223
    if (result==NULL)
 
224
        return False;
 
225
    else {
 
226
        if (*text)
 
227
            wfree(*text);
 
228
        *text = result;
 
229
 
 
230
        return True;
 
231
    }
 
232
}
 
233
 
 
234
 
 
235
/*
 
236
 *****************************************************************
 
237
 * Icon Selection Panel
 
238
 *****************************************************************
 
239
 */
 
240
 
 
241
typedef struct IconPanel {
 
242
 
 
243
    WScreen *scr;
 
244
 
 
245
    WMWindow *win;
 
246
 
 
247
    WMLabel *dirLabel;
 
248
    WMLabel *iconLabel;
 
249
 
 
250
    WMList *dirList;
 
251
    WMList *iconList;
 
252
    WMFont *normalfont;
 
253
 
 
254
    WMButton *previewButton;
 
255
 
 
256
    WMLabel *iconView;
 
257
 
 
258
    WMLabel *fileLabel;
 
259
    WMTextField *fileField;
 
260
 
 
261
    WMButton *okButton;
 
262
    WMButton *cancelButton;
 
263
#if 0
 
264
    WMButton *chooseButton;
 
265
#endif
 
266
    short done;
 
267
    short result;
 
268
    short preview;
 
269
} IconPanel;
 
270
 
 
271
 
 
272
 
 
273
static void
 
274
listPixmaps(WScreen *scr, WMList *lPtr, char *path)
 
275
{
 
276
    struct dirent *dentry;
 
277
    DIR *dir;
 
278
    char pbuf[PATH_MAX+16];
 
279
    char *apath;
 
280
    IconPanel *panel = WMGetHangedData(lPtr);
 
281
 
 
282
    panel->preview = False;
 
283
 
 
284
    apath = wexpandpath(path);
 
285
    dir = opendir(apath);
 
286
 
 
287
    if (!dir) {
 
288
        char *msg;
 
289
        char *tmp;
 
290
        tmp = _("Could not open directory ");
 
291
        msg = wmalloc(strlen(tmp)+strlen(path)+6);
 
292
        strcpy(msg, tmp);
 
293
        strcat(msg, path);
 
294
 
 
295
        wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
 
296
        wfree(msg);
 
297
        wfree(apath);
 
298
        return;
 
299
    }
 
300
 
 
301
    /* list contents in the column */
 
302
    while ((dentry = readdir(dir))) {
 
303
        struct stat statb;
 
304
 
 
305
        if (strcmp(dentry->d_name, ".")==0 ||
 
306
            strcmp(dentry->d_name, "..")==0)
 
307
            continue;
 
308
 
 
309
        strcpy(pbuf, apath);
 
310
        strcat(pbuf, "/");
 
311
        strcat(pbuf, dentry->d_name);
 
312
 
 
313
        if (stat(pbuf, &statb)<0)
 
314
            continue;
 
315
 
 
316
        if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
 
317
            && statb.st_mode & (S_IFREG|S_IFLNK)) {
 
318
            WMAddListItem(lPtr, dentry->d_name);
 
319
        }
 
320
    }
 
321
    WMSortListItems(lPtr);
 
322
 
 
323
    closedir(dir);
 
324
    wfree(apath);
 
325
    panel->preview = True;
 
326
}
 
327
 
 
328
 
 
329
 
 
330
static void
 
331
setViewedImage(IconPanel *panel, char *file)
 
332
{
 
333
    WMPixmap *pixmap;
 
334
    RColor color;
 
335
 
 
336
    color.red = 0xae;
 
337
    color.green = 0xaa;
 
338
    color.blue = 0xae;
 
339
    color.alpha = 0;
 
340
    pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
 
341
                                           file, &color);
 
342
    if (!pixmap) {
 
343
        WMSetButtonEnabled(panel->okButton, False);
 
344
 
 
345
        WMSetLabelText(panel->iconView, _("Could not load image file "));
 
346
 
 
347
        WMSetLabelImage(panel->iconView, NULL);
 
348
    } else {
 
349
        WMSetButtonEnabled(panel->okButton, True);
 
350
 
 
351
        WMSetLabelText(panel->iconView, NULL);
 
352
        WMSetLabelImage(panel->iconView, pixmap);
 
353
        WMReleasePixmap(pixmap);
 
354
    }
 
355
}
 
356
 
 
357
 
 
358
static void
 
359
listCallback(void *self, void *data)
 
360
{
 
361
    WMList *lPtr = (WMList*)self;
 
362
    IconPanel *panel = (IconPanel*)data;
 
363
    char *path;
 
364
 
 
365
    if (lPtr==panel->dirList) {
 
366
        WMListItem *item = WMGetListSelectedItem(lPtr);
 
367
 
 
368
        if (item == NULL)
 
369
            return;
 
370
        path = item->text;
 
371
 
 
372
        WMSetTextFieldText(panel->fileField, path);
 
373
 
 
374
        WMSetLabelImage(panel->iconView, NULL);
 
375
 
 
376
        WMSetButtonEnabled(panel->okButton, False);
 
377
 
 
378
        WMClearList(panel->iconList);
 
379
        listPixmaps(panel->scr, panel->iconList, path);
 
380
    } else {
 
381
        char *tmp, *iconFile;
 
382
        WMListItem *item = WMGetListSelectedItem(panel->dirList);
 
383
 
 
384
        if (item == NULL)
 
385
            return;
 
386
        path = item->text;
 
387
        tmp = wexpandpath(path);
 
388
 
 
389
        item = WMGetListSelectedItem(panel->iconList);
 
390
        if (item == NULL)
 
391
            return;
 
392
        iconFile = item->text;
 
393
 
 
394
        path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
 
395
        strcpy(path, tmp);
 
396
        strcat(path, "/");
 
397
        strcat(path, iconFile);
 
398
        wfree(tmp);
 
399
        WMSetTextFieldText(panel->fileField, path);
 
400
        setViewedImage(panel, path);
 
401
        wfree(path);
 
402
    }
 
403
}
 
404
 
 
405
 
 
406
static void
 
407
listIconPaths(WMList *lPtr)
 
408
{
 
409
    char *paths;
 
410
    char *path;
 
411
 
 
412
    paths = wstrdup(wPreferences.icon_path);
 
413
 
 
414
    path = strtok(paths, ":");
 
415
 
 
416
    do {
 
417
        char *tmp;
 
418
 
 
419
        tmp = wexpandpath(path);
 
420
        /* do not sort, because the order implies the order of
 
421
         * directories searched */
 
422
        if (access(tmp, X_OK)==0)
 
423
            WMAddListItem(lPtr, path);
 
424
        wfree(tmp);
 
425
    } while ((path=strtok(NULL, ":"))!=NULL);
 
426
 
 
427
    wfree(paths);
 
428
}
 
429
 
 
430
 
 
431
void
 
432
drawIconProc(WMList *lPtr, int index, Drawable d, char *text, int state,
 
433
             WMRect *rect)
 
434
{
 
435
    IconPanel *panel = WMGetHangedData(lPtr);
 
436
    WScreen *scr = panel->scr;
 
437
    GC gc = scr->draw_gc;
 
438
    GC copygc = scr->copy_gc;
 
439
    char *file, *dirfile;
 
440
    WMPixmap *pixmap;
 
441
    WMColor *back;
 
442
    WMSize size;
 
443
    WMScreen *wmscr = WMWidgetScreen(panel->win);
 
444
    RColor color;
 
445
    int x, y, width, height, len;
 
446
 
 
447
    if(!panel->preview) return;
 
448
 
 
449
    x = rect->pos.x;
 
450
    y = rect->pos.y;
 
451
    width = rect->size.width;
 
452
    height = rect->size.height;
 
453
 
 
454
    back = (state & WLDSSelected) ? scr->white : scr->gray;
 
455
 
 
456
    dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
 
457
    len = strlen(dirfile)+strlen(text)+4;
 
458
    file = wmalloc(len);
 
459
    snprintf(file, len, "%s/%s", dirfile, text);
 
460
    wfree(dirfile);
 
461
 
 
462
    color.red = WMRedComponentOfColor(back) >> 8;
 
463
    color.green = WMGreenComponentOfColor(back) >> 8;
 
464
    color.blue = WMBlueComponentOfColor(back) >> 8;
 
465
    color.alpha = WMGetColorAlpha(back) >> 8;
 
466
 
 
467
    pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
 
468
    wfree(file);
 
469
 
 
470
    if (!pixmap) {
 
471
        /*WMRemoveListItem(lPtr, index);*/
 
472
        return;
 
473
    }
 
474
 
 
475
    XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
 
476
 
 
477
    XSetClipMask(dpy, gc, None);
 
478
    /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54);*/
 
479
    XDrawLine(dpy, d, WMColorGC(scr->white), x, y+height-1, x+width, y+height-1);
 
480
 
 
481
    size = WMGetPixmapSize(pixmap);
 
482
 
 
483
    XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
 
484
    XSetClipOrigin(dpy, copygc, x + (width-size.width)/2, y+2);
 
485
    XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
 
486
              size.width>100?100:size.width, size.height>64?64:size.height,
 
487
              x + (width-size.width)/2, y+2);
 
488
 
 
489
    {
 
490
        int i,j;
 
491
        int fheight = WMFontHeight(panel->normalfont);
 
492
        int tlen = strlen(text);
 
493
        int twidth = WMWidthOfString(panel->normalfont, text, tlen);
 
494
        int ofx, ofy;
 
495
 
 
496
        ofx = x + (width - twidth)/2;
 
497
        ofy = y + 64 - fheight;
 
498
 
 
499
        for(i=-1;i<2;i++)
 
500
            for(j=-1;j<2;j++)
 
501
                WMDrawString(wmscr, d, scr->white, panel->normalfont,
 
502
                             ofx+i, ofy+j, text, tlen);
 
503
 
 
504
        WMDrawString(wmscr, d, scr->black, panel->normalfont, ofx, ofy,
 
505
                     text, tlen);
 
506
    }
 
507
 
 
508
    WMReleasePixmap(pixmap);
 
509
    /* I hope it is better to do not use cache / on my box it is fast nuff */
 
510
    XFlush(dpy);
 
511
}
 
512
 
 
513
 
 
514
static void
 
515
buttonCallback(void *self, void *clientData)
 
516
{
 
517
    WMButton *bPtr = (WMButton*)self;
 
518
    IconPanel *panel = (IconPanel*)clientData;
 
519
 
 
520
 
 
521
    if (bPtr==panel->okButton) {
 
522
        panel->done = True;
 
523
        panel->result = True;
 
524
    } else if (bPtr==panel->cancelButton) {
 
525
        panel->done = True;
 
526
        panel->result = False;
 
527
    } else if (bPtr==panel->previewButton) {
 
528
        /**** Previewer ****/
 
529
        WMSetButtonEnabled(bPtr, False);
 
530
        WMSetListUserDrawItemHeight(panel->iconList, 68);
 
531
        WMSetListUserDrawProc(panel->iconList, drawIconProc);
 
532
        WMRedisplayWidget(panel->iconList);
 
533
        /* for draw proc to access screen/gc */
 
534
        /*** end preview ***/
 
535
    }
 
536
#if 0
 
537
    else if (bPtr==panel->chooseButton) {
 
538
        WMOpenPanel *op;
 
539
 
 
540
        op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
 
541
 
 
542
        if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
 
543
            char *path;
 
544
            path = WMGetFilePanelFile(op);
 
545
            WMSetTextFieldText(panel->fileField, path);
 
546
            setViewedImage(panel, path);
 
547
            wfree(path);
 
548
        }
 
549
        WMDestroyFilePanel(op);
 
550
    }
 
551
#endif
 
552
}
 
553
 
 
554
 
 
555
static void
 
556
keyPressHandler(XEvent *event, void *data)
 
557
{
 
558
    IconPanel *panel = (IconPanel*)data;
 
559
    char buffer[32];
 
560
    int count;
 
561
    KeySym ksym;
 
562
    int iidx;
 
563
    int didx;
 
564
    int item = 0;
 
565
    WMList *list = NULL;
 
566
 
 
567
    if (event->type == KeyRelease)
 
568
        return;
 
569
 
 
570
    buffer[0] = 0;
 
571
    count = XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
 
572
 
 
573
 
 
574
    iidx = WMGetListSelectedItemRow(panel->iconList);
 
575
    didx = WMGetListSelectedItemRow(panel->dirList);
 
576
 
 
577
    switch (ksym) {
 
578
    case XK_Up:
 
579
        if (iidx > 0)
 
580
            item = iidx-1;
 
581
        else
 
582
            item = iidx;
 
583
        list = panel->iconList;
 
584
        break;
 
585
    case XK_Down:
 
586
        if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
 
587
            item = iidx+1;
 
588
        else
 
589
            item = iidx;
 
590
        list = panel->iconList;
 
591
        break;
 
592
    case XK_Home:
 
593
        item = 0;
 
594
        list = panel->iconList;
 
595
        break;
 
596
    case XK_End:
 
597
        item = WMGetListNumberOfRows(panel->iconList) - 1;
 
598
        list = panel->iconList;
 
599
        break;
 
600
    case XK_Next:
 
601
        if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
 
602
            item = didx + 1;
 
603
        else
 
604
            item = didx;
 
605
        list = panel->dirList;
 
606
        break;
 
607
    case XK_Prior:
 
608
        if (didx > 0)
 
609
            item = didx - 1;
 
610
        else
 
611
            item = 0;
 
612
        list = panel->dirList;
 
613
        break;
 
614
    case XK_Return:
 
615
        WMPerformButtonClick(panel->okButton);
 
616
        break;
 
617
    case XK_Escape:
 
618
        WMPerformButtonClick(panel->cancelButton);
 
619
        break;
 
620
    }
 
621
 
 
622
    if (list) {
 
623
        WMSelectListItem(list, item);
 
624
        WMSetListPosition(list, item - 5);
 
625
        listCallback(list, panel);
 
626
    }
 
627
}
 
628
 
 
629
 
 
630
 
 
631
Bool
 
632
wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
 
633
{
 
634
    WWindow *wwin;
 
635
    Window parent;
 
636
    IconPanel *panel;
 
637
    WMColor *color;
 
638
    WMFont *boldFont;
 
639
    Bool result;
 
640
 
 
641
    panel = wmalloc(sizeof(IconPanel));
 
642
    memset(panel, 0, sizeof(IconPanel));
 
643
 
 
644
    panel->scr = scr;
 
645
 
 
646
    panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
 
647
    WMResizeWidget(panel->win, 450, 280);
 
648
 
 
649
    WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask|KeyReleaseMask,
 
650
                         keyPressHandler, panel);
 
651
 
 
652
 
 
653
    boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
 
654
    panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
 
655
 
 
656
    panel->dirLabel = WMCreateLabel(panel->win);
 
657
    WMResizeWidget(panel->dirLabel, 200, 20);
 
658
    WMMoveWidget(panel->dirLabel, 10, 7);
 
659
    WMSetLabelText(panel->dirLabel, _("Directories"));
 
660
    WMSetLabelFont(panel->dirLabel, boldFont);
 
661
    WMSetLabelTextAlignment(panel->dirLabel, WACenter);
 
662
 
 
663
    WMSetLabelRelief(panel->dirLabel, WRSunken);
 
664
 
 
665
    panel->iconLabel = WMCreateLabel(panel->win);
 
666
    WMResizeWidget(panel->iconLabel, 140, 20);
 
667
    WMMoveWidget(panel->iconLabel, 215, 7);
 
668
    WMSetLabelText(panel->iconLabel, _("Icons"));
 
669
    WMSetLabelFont(panel->iconLabel, boldFont);
 
670
    WMSetLabelTextAlignment(panel->iconLabel, WACenter);
 
671
 
 
672
    WMReleaseFont(boldFont);
 
673
 
 
674
    color = WMWhiteColor(scr->wmscreen);
 
675
    WMSetLabelTextColor(panel->dirLabel, color);
 
676
    WMSetLabelTextColor(panel->iconLabel, color);
 
677
    WMReleaseColor(color);
 
678
 
 
679
    color = WMDarkGrayColor(scr->wmscreen);
 
680
    WMSetWidgetBackgroundColor(panel->iconLabel, color);
 
681
    WMSetWidgetBackgroundColor(panel->dirLabel, color);
 
682
    WMReleaseColor(color);
 
683
 
 
684
    WMSetLabelRelief(panel->iconLabel, WRSunken);
 
685
 
 
686
    panel->dirList = WMCreateList(panel->win);
 
687
    WMResizeWidget(panel->dirList, 200, 170);
 
688
    WMMoveWidget(panel->dirList, 10, 30);
 
689
    WMSetListAction(panel->dirList, listCallback, panel);
 
690
 
 
691
    panel->iconList = WMCreateList(panel->win);
 
692
    WMResizeWidget(panel->iconList, 140, 170);
 
693
    WMMoveWidget(panel->iconList, 215, 30);
 
694
    WMSetListAction(panel->iconList, listCallback, panel);
 
695
 
 
696
    WMHangData(panel->iconList,panel);
 
697
 
 
698
    panel->previewButton = WMCreateCommandButton(panel->win);
 
699
    WMResizeWidget(panel->previewButton, 75, 26);
 
700
    WMMoveWidget(panel->previewButton, 365, 130);
 
701
    WMSetButtonText(panel->previewButton, _("Preview"));
 
702
    WMSetButtonAction(panel->previewButton, buttonCallback, panel);
 
703
 
 
704
    panel->iconView = WMCreateLabel(panel->win);
 
705
    WMResizeWidget(panel->iconView, 75, 75);
 
706
    WMMoveWidget(panel->iconView, 365, 40);
 
707
    WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
 
708
    WMSetLabelRelief(panel->iconView, WRSunken);
 
709
    WMSetLabelTextAlignment(panel->iconView, WACenter);
 
710
 
 
711
    panel->fileLabel = WMCreateLabel(panel->win);
 
712
    WMResizeWidget(panel->fileLabel, 80, 20);
 
713
    WMMoveWidget(panel->fileLabel, 10, 210);
 
714
    WMSetLabelText(panel->fileLabel, _("File Name:"));
 
715
 
 
716
    panel->fileField = WMCreateTextField(panel->win);
 
717
    WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
 
718
    WMResizeWidget(panel->fileField, 345, 20);
 
719
    WMMoveWidget(panel->fileField, 95, 210);
 
720
    WMSetTextFieldEditable(panel->fileField, False);
 
721
 
 
722
    panel->okButton = WMCreateCommandButton(panel->win);
 
723
    WMResizeWidget(panel->okButton, 80, 26);
 
724
    WMMoveWidget(panel->okButton, 360, 240);
 
725
    WMSetButtonText(panel->okButton, _("OK"));
 
726
    WMSetButtonEnabled(panel->okButton, False);
 
727
    WMSetButtonAction(panel->okButton, buttonCallback, panel);
 
728
 
 
729
    panel->cancelButton = WMCreateCommandButton(panel->win);
 
730
    WMResizeWidget(panel->cancelButton, 80, 26);
 
731
    WMMoveWidget(panel->cancelButton, 270, 240);
 
732
    WMSetButtonText(panel->cancelButton, _("Cancel"));
 
733
    WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
 
734
#if 0
 
735
    panel->chooseButton = WMCreateCommandButton(panel->win);
 
736
    WMResizeWidget(panel->chooseButton, 110, 26);
 
737
    WMMoveWidget(panel->chooseButton, 150, 240);
 
738
    WMSetButtonText(panel->chooseButton, _("Choose File"));
 
739
    WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
 
740
#endif
 
741
    WMRealizeWidget(panel->win);
 
742
    WMMapSubwidgets(panel->win);
 
743
 
 
744
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
 
745
 
 
746
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
747
 
 
748
    {
 
749
        char *tmp;
 
750
        int len = (instance ? strlen(instance) : 0)
 
751
            + (class ? strlen(class) : 0) + 32;
 
752
        WMPoint center;
 
753
 
 
754
        tmp = wmalloc(len);
 
755
 
 
756
        if (tmp && (instance || class))
 
757
            snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
 
758
        else
 
759
            strcpy(tmp, _("Icon Chooser"));
 
760
 
 
761
        center = getCenter(scr, 450, 280);
 
762
 
 
763
        wwin = wManageInternalWindow(scr, parent, None, tmp, center.x,center.y,
 
764
                                     450, 280);
 
765
        wfree(tmp);
 
766
    }
 
767
 
 
768
    /* put icon paths in the list */
 
769
    listIconPaths(panel->dirList);
 
770
 
 
771
    WMMapWidget(panel->win);
 
772
 
 
773
    wWindowMap(wwin);
 
774
 
 
775
    while (!panel->done) {
 
776
        XEvent event;
 
777
 
 
778
        WMNextEvent(dpy, &event);
 
779
        WMHandleEvent(&event);
 
780
    }
 
781
 
 
782
    if (panel->result) {
 
783
        char *defaultPath, *wantedPath;
 
784
 
 
785
        /* check if the file the user selected is not the one that
 
786
         * would be loaded by default with the current search path */
 
787
        *file = WMGetListSelectedItem(panel->iconList)->text;
 
788
        if (**file==0) {
 
789
            wfree(*file);
 
790
            *file = NULL;
 
791
        } else {
 
792
            defaultPath = FindImage(wPreferences.icon_path, *file);
 
793
            wantedPath = WMGetTextFieldText(panel->fileField);
 
794
            /* if the file is not the default, use full path */
 
795
            if (strcmp(wantedPath, defaultPath)!=0) {
 
796
                *file = wantedPath;
 
797
            } else {
 
798
                *file = wstrdup(*file);
 
799
                wfree(wantedPath);
 
800
            }
 
801
            wfree(defaultPath);
 
802
        }
 
803
    } else {
 
804
        *file = NULL;
 
805
    }
 
806
 
 
807
    result = panel->result;
 
808
 
 
809
    WMReleaseFont(panel->normalfont);
 
810
 
 
811
    WMUnmapWidget(panel->win);
 
812
 
 
813
    WMDestroyWidget(panel->win);
 
814
 
 
815
    wUnmanageWindow(wwin, False, False);
 
816
 
 
817
    wfree(panel);
 
818
 
 
819
    XDestroyWindow(dpy, parent);
 
820
 
 
821
    return result;
 
822
}
 
823
 
 
824
 
 
825
/*
 
826
 ***********************************************************************
 
827
 * Info Panel
 
828
 ***********************************************************************
 
829
 */
 
830
 
 
831
 
 
832
typedef struct {
 
833
    WScreen *scr;
 
834
 
 
835
    WWindow *wwin;
 
836
 
 
837
    WMWindow *win;
 
838
 
 
839
    WMLabel *logoL;
 
840
    WMLabel *name1L;
 
841
    WMFrame *lineF;
 
842
    WMLabel *name2L;
 
843
 
 
844
    WMLabel *versionL;
 
845
 
 
846
    WMLabel *infoL;
 
847
 
 
848
    WMLabel *copyrL;
 
849
 
 
850
#ifdef SILLYNESS
 
851
    WMHandlerID timer;
 
852
    int cycle;
 
853
    RImage *icon;
 
854
    RImage *pic;
 
855
    WMPixmap *oldPix;
 
856
    WMFont *oldFont;
 
857
    char *str;
 
858
    int x;
 
859
#endif
 
860
} InfoPanel;
 
861
 
 
862
 
 
863
 
 
864
#define COPYRIGHT_TEXT  \
 
865
    "Copyright \xc2\xa9 1997-2004 Alfredo K. Kojima\n"\
 
866
    "Copyright \xc2\xa9 1998-2004 Dan Pascu"
 
867
 
 
868
 
 
869
 
 
870
static InfoPanel *thePanel = NULL;
 
871
 
 
872
static void
 
873
destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
 
874
{
 
875
#ifdef SILLYNESS
 
876
    if (thePanel->timer) {
 
877
        WMDeleteTimerHandler(thePanel->timer);
 
878
    }
 
879
    if (thePanel->oldPix) {
 
880
        WMReleasePixmap(thePanel->oldPix);
 
881
    }
 
882
    if (thePanel->oldFont) {
 
883
        WMReleaseFont(thePanel->oldFont);
 
884
    }
 
885
    if (thePanel->icon) {
 
886
        RReleaseImage(thePanel->icon);
 
887
    }
 
888
    if (thePanel->pic) {
 
889
        RReleaseImage(thePanel->pic);
 
890
    }
 
891
#endif /* SILLYNESS */
 
892
    WMUnmapWidget(thePanel);
 
893
 
 
894
    wUnmanageWindow(thePanel->wwin, False, False);
 
895
 
 
896
    WMDestroyWidget(thePanel->win);
 
897
 
 
898
    wfree(thePanel);
 
899
 
 
900
    thePanel = NULL;
 
901
}
 
902
 
 
903
 
 
904
#ifdef SILLYNESS
 
905
 
 
906
extern WMPixmap *DoXThing();
 
907
extern Bool InitXThing();
 
908
 
 
909
static void
 
910
logoPushCallback(void *data)
 
911
{
 
912
    InfoPanel *panel = (InfoPanel*)data;
 
913
    char buffer[512];
 
914
    int i;
 
915
    static int oldi = 0;
 
916
    int len;
 
917
    static int jingobeu[] = {
 
918
        329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
 
919
        329, 150, -1, 100, 329, 150, -1, 100,  329, 300, -1, 250,
 
920
        329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
 
921
    };
 
922
    static int c = 0;
 
923
 
 
924
    if (panel->x) {
 
925
        XKeyboardControl kc;
 
926
        XKeyboardState ksave;
 
927
        unsigned long mask = KBBellPitch|KBBellDuration|KBBellPercent;
 
928
 
 
929
        XGetKeyboardControl(dpy, &ksave);
 
930
 
 
931
        if (panel->x > 0) {
 
932
            if(jingobeu[panel->x-1]==0) {
 
933
                panel->x=-1;
 
934
            } else if (jingobeu[panel->x-1]<0) {
 
935
                panel->x++;
 
936
                c=jingobeu[panel->x-1]/50;
 
937
                panel->x++;
 
938
            } else if (c==0) {
 
939
                kc.bell_percent=50;
 
940
                kc.bell_pitch=jingobeu[panel->x-1];
 
941
                panel->x++;
 
942
                kc.bell_duration=jingobeu[panel->x-1];
 
943
                c=jingobeu[panel->x-1]/50;
 
944
                panel->x++;
 
945
                XChangeKeyboardControl(dpy, mask, &kc);
 
946
                XBell(dpy, 50);
 
947
                XFlush(dpy);
 
948
            } else {
 
949
                c--;
 
950
            }
 
951
        }
 
952
        if (!(panel->cycle % 4)) {
 
953
            WMPixmap *p;
 
954
 
 
955
            p = DoXThing(panel->wwin);
 
956
            WMSetLabelImage(panel->logoL, p);
 
957
        }
 
958
        kc.bell_pitch = ksave.bell_pitch;
 
959
        kc.bell_percent = ksave.bell_percent;
 
960
        kc.bell_duration = ksave.bell_duration;
 
961
        XChangeKeyboardControl(dpy, mask, &kc);
 
962
    } else if (panel->cycle < 30) {
 
963
        RImage *image;
 
964
        WMPixmap *pix;
 
965
        RColor gray;
 
966
 
 
967
        gray.red = 0xae;  gray.green = 0xaa;
 
968
        gray.blue = 0xae; gray.alpha = 0;
 
969
 
 
970
        image = RScaleImage(panel->icon, panel->pic->width, panel->pic->height);
 
971
        RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
 
972
        pix = WMCreateBlendedPixmapFromRImage(panel->scr->wmscreen, image, &gray);
 
973
        RReleaseImage(image);
 
974
        WMSetLabelImage(panel->logoL, pix);
 
975
        WMReleasePixmap(pix);
 
976
    }
 
977
 
 
978
    /* slow down text a little */
 
979
    i = (int)(panel->cycle * 50.0/85.0)%200;
 
980
 
 
981
    if (i != oldi) {
 
982
        len = strlen(panel->str);
 
983
 
 
984
        strncpy(buffer, panel->str, i<len ? i : len);
 
985
        if (i >= len)
 
986
            memset(&buffer[len], ' ', i-len);
 
987
 
 
988
        strncpy(buffer, panel->str, i<len ? i : len);
 
989
        if (i >= len)
 
990
            memset(&buffer[len], ' ', i-len);
 
991
        buffer[i]=0;
 
992
 
 
993
        WMSetLabelText(panel->versionL, buffer);
 
994
 
 
995
        XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
 
996
 
 
997
        oldi = i;
 
998
    }
 
999
 
 
1000
    panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
 
1001
    panel->cycle++;
 
1002
}
 
1003
 
 
1004
 
 
1005
static void
 
1006
handleLogoPush(XEvent *event, void *data)
 
1007
{
 
1008
    InfoPanel *panel = (InfoPanel*)data;
 
1009
    static int broken = 0;
 
1010
    static int clicks = 0;
 
1011
    static char *pic_data[] = {
 
1012
        "45 45 57 1",
 
1013
        "       c None",
 
1014
        ".      c #000000",
 
1015
        "X      c #383C00",
 
1016
        "o      c #515500",
 
1017
        "O      c #616100",
 
1018
        "+      c #616900",
 
1019
        "@      c #696D00",
 
1020
        "#      c #697100",
 
1021
        "$      c #495100",
 
1022
        "%      c #202800",
 
1023
        "&      c #969600",
 
1024
        "*      c #CFCF00",
 
1025
        "=      c #D7DB00",
 
1026
        "-      c #D7D700",
 
1027
        ";      c #C7CB00",
 
1028
        ":      c #A6AA00",
 
1029
        ">      c #494900",
 
1030
        ",      c #8E8E00",
 
1031
        "<      c #DFE700",
 
1032
        "1      c #F7FF00",
 
1033
        "2      c #FFFF00",
 
1034
        "3      c #E7EB00",
 
1035
        "4      c #B6B600",
 
1036
        "5      c #595900",
 
1037
        "6      c #717500",
 
1038
        "7      c #AEB200",
 
1039
        "8      c #CFD300",
 
1040
        "9      c #E7EF00",
 
1041
        "0      c #EFF300",
 
1042
        "q      c #9EA200",
 
1043
        "w      c #F7FB00",
 
1044
        "e      c #F7F700",
 
1045
        "r      c #BEBE00",
 
1046
        "t      c #8E9200",
 
1047
        "y      c #EFF700",
 
1048
        "u      c #969A00",
 
1049
        "i      c #414500",
 
1050
        "p      c #595D00",
 
1051
        "a      c #E7E700",
 
1052
        "s      c #C7C700",
 
1053
        "d      c #797D00",
 
1054
        "f      c #BEC300",
 
1055
        "g      c #DFE300",
 
1056
        "h      c #868600",
 
1057
        "j      c #EFEF00",
 
1058
        "k      c #9E9E00",
 
1059
        "l      c #616500",
 
1060
        "z      c #DFDF00",
 
1061
        "x      c #868A00",
 
1062
        "c      c #969200",
 
1063
        "v      c #B6BA00",
 
1064
        "b      c #A6A600",
 
1065
        "n      c #8E8A00",
 
1066
        "m      c #717100",
 
1067
        "M      c #AEAE00",
 
1068
        "N      c #AEAA00",
 
1069
        "B      c #868200",
 
1070
        "               ...............               ",
 
1071
        "             ....XoO+@##+O$%....             ",
 
1072
        "           ...%X&*========-;;:o...           ",
 
1073
        "         ...>.>,<122222222222134@...         ",
 
1074
        "        ..>5678912222222222222220q%..        ",
 
1075
        "       ..$.&-w2222222222222222222er>..       ",
 
1076
        "      ..O.t31222222222222222222222y4>..      ",
 
1077
        "    ...O5u3222222222222222222222222yri...    ",
 
1078
        "    ..>p&a22222222222222222222222222wso..    ",
 
1079
        "   ..ids91222222222222222222222222222wfi..   ",
 
1080
        "  ..X.7w222222wgs-w2222222213=g0222222<hi..  ",
 
1081
        "  ..Xuj2222222<@X5=222222229k@l:022222y4i..  ",
 
1082
        "  .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
 
1083
        " ..o7y22222222v...r222222223hX.i82222221si.. ",
 
1084
        "..io*222222222&...u22222222yt..%*22222220:%. ",
 
1085
        "..>k02222222227...f222222222v..X=222222229t. ",
 
1086
        "..dz12222222220ui:y2222222223d%qw222222221g. ",
 
1087
        ".%vw222222222221y2222222222219*y2222222222wd.",
 
1088
        ".X;2222222222222222222222222222222222222222b.",
 
1089
        ".i*2222222222222222222222222222222222222222v.",
 
1090
        ".i*2222222222222222222222222222222222222222;.",
 
1091
        ".i*22222222222222222222222222222222222222228.",
 
1092
        ".>*2222222222222222222222222222222222222222=.",
 
1093
        ".i*22222222222222222222222222222222222222228.",
 
1094
        ".i*2222222222222222222222222222222222222222;.",
 
1095
        ".X*222222222222222222222222222222we12222222r.",
 
1096
        ".Xs12222222w3aw22222222222222222y8s0222222wk.",
 
1097
        ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
 
1098
        "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
 
1099
        "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
 
1100
        " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
 
1101
        " ..58222wagsh6ry222222222222221;>Of0w222y:...",
 
1102
        " ...:e2222218mdz22222222222222a&$vw222220@...",
 
1103
        " ...O-122222y:.u02222222222229q$uj222221r... ",
 
1104
        "  ..%&a1222223&573w2222222219NOxz122221z>... ",
 
1105
        "   ...t3222221-l$nr8ay1222yzbo,=12222w-5...  ",
 
1106
        "    ..X:022222w-k+>o,7s**s7xOn=12221<f5...   ",
 
1107
        "     ..o:9222221j8:&Bl>>>>ihv<12221=dX...    ",
 
1108
        "      ..Xb9122222109g-****;<y22221zn%...     ",
 
1109
        "       ..X&801222222222222222222w-h....      ",
 
1110
        "        ...o:=022222222222222221=lX...       ",
 
1111
        "          ..X@:;3w2222222222210fO...         ",
 
1112
        "           ...XX&v8<30000003-N@...           ",
 
1113
        "             .....XmnbN:q&Bo....             ",
 
1114
        "                 ............                "
 
1115
    };
 
1116
    static char *msgs[] = {
 
1117
        "Have a nice day!",
 
1118
        "Focus follow mouse users will burn in hell!!!",
 
1119
        "Mooo Canada!!!!",
 
1120
        "Hi! My name is bobby...",
 
1121
        "AHH! The neurotic monkeys are after me!",
 
1122
        "WE GET SIGNAL",
 
1123
        "HOW ARE YOU GENTLEMEN?",
 
1124
        "WHAT YOU SAY??",
 
1125
        "SOMEBODY SET UP US THE BOMB",
 
1126
        "ALL YOUR BASE ARE BELONG TO US!",
 
1127
        "Oh My God!!! Larry is back!"
 
1128
    };
 
1129
 
 
1130
 
 
1131
    clicks++;
 
1132
 
 
1133
    if (!panel->timer && !broken && clicks > 0) {
 
1134
        WMFont *font;
 
1135
 
 
1136
        panel->x = 0;
 
1137
        clicks = 0;
 
1138
        if (!panel->icon) {
 
1139
            panel->icon = WMGetApplicationIconImage(panel->scr->wmscreen);
 
1140
            if (!panel->icon) {
 
1141
                broken = 1;
 
1142
                return;
 
1143
            } else {
 
1144
                RColor color;
 
1145
 
 
1146
                color.red = 0xae;  color.green = 0xaa;
 
1147
                color.blue = 0xae; color.alpha = 0;
 
1148
 
 
1149
                panel->icon = RCloneImage(panel->icon);
 
1150
                RCombineImageWithColor(panel->icon, &color);
 
1151
            }
 
1152
        }
 
1153
        if (!panel->pic) {
 
1154
            panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
 
1155
            if (!panel->pic) {
 
1156
                broken = 1;
 
1157
                RReleaseImage(panel->icon);
 
1158
                panel->icon = NULL;
 
1159
                return;
 
1160
            }
 
1161
        }
 
1162
 
 
1163
        panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
 
1164
 
 
1165
        panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
 
1166
        panel->cycle = 0;
 
1167
        panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
 
1168
        /* If we don't use a fixed font, scrolling will be jumpy */
 
1169
        /* Alternatively we can draw text in a pixmap and scroll it smoothly */
 
1170
        if ((panel->oldFont = WMGetLabelFont(panel->versionL))!=NULL)
 
1171
            WMRetainFont(panel->oldFont);
 
1172
        font = WMCreateFont(WMWidgetScreen(panel->versionL),
 
1173
                            "Lucida Console,Courier New,monospace:pixelsize=12");
 
1174
        if (font) {
 
1175
            WMSetLabelFont(panel->versionL, font);
 
1176
            WMReleaseFont(font);
 
1177
        }
 
1178
        WMSetLabelText(panel->versionL, "");
 
1179
    } else if (panel->timer) {
 
1180
        char version[20];
 
1181
 
 
1182
        panel->x = 0;
 
1183
        clicks = 0;
 
1184
        WMSetLabelImage(panel->logoL, panel->oldPix);
 
1185
        WMReleasePixmap(panel->oldPix);
 
1186
        panel->oldPix = NULL;
 
1187
 
 
1188
        WMDeleteTimerHandler(panel->timer);
 
1189
        panel->timer = NULL;
 
1190
 
 
1191
        WMSetLabelFont(panel->versionL, panel->oldFont);
 
1192
        if (panel->oldFont) {
 
1193
            WMReleaseFont(panel->oldFont);
 
1194
            panel->oldFont = NULL;
 
1195
        }
 
1196
        snprintf(version, sizeof(version), _("Version %s"), VERSION);
 
1197
        WMSetLabelText(panel->versionL, version);
 
1198
        XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
 
1199
    }
 
1200
 
 
1201
    {
 
1202
        XEvent ev;
 
1203
        while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
 
1204
                                      ButtonPress, &ev));
 
1205
    }
 
1206
}
 
1207
#endif /* SILLYNESS */
 
1208
 
 
1209
 
 
1210
void
 
1211
wShowInfoPanel(WScreen *scr)
 
1212
{
 
1213
    InfoPanel *panel;
 
1214
    WMPixmap *logo;
 
1215
    WMSize size;
 
1216
    WMFont *font;
 
1217
    char *strbuf = NULL;
 
1218
    char buffer[256];
 
1219
    char *name;
 
1220
    Window parent;
 
1221
    WWindow *wwin;
 
1222
    char **strl;
 
1223
    int i, width=50, sepWidth;
 
1224
    char *visuals[] = {
 
1225
        "StaticGray",
 
1226
        "GrayScale",
 
1227
        "StaticColor",
 
1228
        "PseudoColor",
 
1229
        "TrueColor",
 
1230
        "DirectColor"
 
1231
    };
 
1232
 
 
1233
 
 
1234
    if (thePanel) {
 
1235
        if (thePanel->scr == scr) {
 
1236
            wRaiseFrame(thePanel->wwin->frame->core);
 
1237
            wSetFocusTo(scr, thePanel->wwin);
 
1238
        }
 
1239
        return;
 
1240
    }
 
1241
 
 
1242
    panel = wmalloc(sizeof(InfoPanel));
 
1243
    memset(panel, 0, sizeof(InfoPanel));
 
1244
 
 
1245
    panel->scr = scr;
 
1246
 
 
1247
    panel->win = WMCreateWindow(scr->wmscreen, "info");
 
1248
    WMResizeWidget(panel->win, 390, 230);
 
1249
 
 
1250
    logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor*)NULL);
 
1251
    if (!logo) {
 
1252
        logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
 
1253
    }
 
1254
    if (logo) {
 
1255
        size = WMGetPixmapSize(logo);
 
1256
        panel->logoL = WMCreateLabel(panel->win);
 
1257
        WMResizeWidget(panel->logoL, 64, 64);
 
1258
        WMMoveWidget(panel->logoL, 30, 20);
 
1259
        WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
 
1260
        WMSetLabelImage(panel->logoL, logo);
 
1261
#ifdef SILLYNESS
 
1262
        WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
 
1263
                             handleLogoPush, panel);
 
1264
#endif
 
1265
        WMReleasePixmap(logo);
 
1266
    }
 
1267
 
 
1268
    sepWidth = 3;
 
1269
    panel->name1L = WMCreateLabel(panel->win);
 
1270
    WMResizeWidget(panel->name1L, 240, 30 - sepWidth);
 
1271
    WMMoveWidget(panel->name1L, 100, 30);
 
1272
 
 
1273
    name = "Lucida Sans,Comic Sans MS,URW Gothic L,Trebuchet MS"
 
1274
        ":bold:pixelsize=26:antialias=true";
 
1275
    font = WMCreateFont(scr->wmscreen, name);
 
1276
    strbuf = "Window Maker";
 
1277
    if (font) {
 
1278
        width = WMWidthOfString(font, strbuf, strlen(strbuf));
 
1279
        WMSetLabelFont(panel->name1L, font);
 
1280
        WMReleaseFont(font);
 
1281
    }
 
1282
    WMSetLabelTextAlignment(panel->name1L, WACenter);
 
1283
    WMSetLabelText(panel->name1L, strbuf);
 
1284
 
 
1285
    panel->lineF = WMCreateFrame(panel->win);
 
1286
    WMResizeWidget(panel->lineF, width, sepWidth);
 
1287
    WMMoveWidget(panel->lineF, 100+(240-width)/2, 60 - sepWidth);
 
1288
    WMSetFrameRelief(panel->lineF, WRSimple);
 
1289
    WMSetWidgetBackgroundColor(panel->lineF, scr->black);
 
1290
 
 
1291
    panel->name2L = WMCreateLabel(panel->win);
 
1292
    WMResizeWidget(panel->name2L, 240, 24);
 
1293
    WMMoveWidget(panel->name2L, 100, 60);
 
1294
    name = "URW Gothic L,Nimbus Sans L:pixelsize=16:antialias=true";
 
1295
    font = WMCreateFont(scr->wmscreen, name);
 
1296
    if (font) {
 
1297
        WMSetLabelFont(panel->name2L, font);
 
1298
        WMReleaseFont(font);
 
1299
        font = NULL;
 
1300
    }
 
1301
    WMSetLabelTextAlignment(panel->name2L, WACenter);
 
1302
    WMSetLabelText(panel->name2L, _("Window Manager for X"));
 
1303
 
 
1304
    snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
 
1305
    panel->versionL = WMCreateLabel(panel->win);
 
1306
    WMResizeWidget(panel->versionL, 310, 16);
 
1307
    WMMoveWidget(panel->versionL, 30, 95);
 
1308
    WMSetLabelTextAlignment(panel->versionL, WARight);
 
1309
    WMSetLabelText(panel->versionL, buffer);
 
1310
    WMSetLabelWraps(panel->versionL, False);
 
1311
 
 
1312
    panel->copyrL = WMCreateLabel(panel->win);
 
1313
    WMResizeWidget(panel->copyrL, 360, 40);
 
1314
    WMMoveWidget(panel->copyrL, 15, 185);
 
1315
    WMSetLabelTextAlignment(panel->copyrL, WALeft);
 
1316
    WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
 
1317
    font = WMSystemFontOfSize(scr->wmscreen, 11);
 
1318
    if (font) {
 
1319
        WMSetLabelFont(panel->copyrL, font);
 
1320
        WMReleaseFont(font);
 
1321
        font = NULL;
 
1322
    }
 
1323
 
 
1324
    strbuf = NULL;
 
1325
    snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
 
1326
             (unsigned)scr->w_visual->visualid,
 
1327
             visuals[scr->w_visual->class], scr->w_depth);
 
1328
 
 
1329
    strbuf = wstrappend(strbuf, buffer);
 
1330
 
 
1331
    switch (scr->w_depth) {
 
1332
    case 15:
 
1333
        strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
 
1334
        break;
 
1335
    case 16:
 
1336
        strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
 
1337
        break;
 
1338
    case 24:
 
1339
    case 32:
 
1340
        strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
 
1341
        break;
 
1342
    default:
 
1343
        snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1<<scr->w_depth);
 
1344
        strbuf = wstrappend(strbuf, buffer);
 
1345
        break;
 
1346
    }
 
1347
 
 
1348
 
 
1349
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 
1350
    {
 
1351
        struct mallinfo ma = mallinfo();
 
1352
        snprintf(buffer, sizeof(buffer),
 
1353
                 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
 
1354
                 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
 
1355
 
 
1356
        strbuf = wstrappend(strbuf, buffer);
 
1357
    }
 
1358
#endif
 
1359
 
 
1360
    strbuf = wstrappend(strbuf, _("Supported image formats: "));
 
1361
    strl = RSupportedFileFormats();
 
1362
    for (i=0; strl[i]!=NULL; i++) {
 
1363
        strbuf = wstrappend(strbuf, strl[i]);
 
1364
        strbuf = wstrappend(strbuf, " ");
 
1365
    }
 
1366
 
 
1367
    strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
 
1368
    {
 
1369
        char *list[9];
 
1370
        char buf[80];
 
1371
        int j = 0;
 
1372
 
 
1373
#ifdef NETWM_HINTS
 
1374
        list[j++] = "WMSPEC";
 
1375
#endif
 
1376
#ifdef MWM_HINTS
 
1377
        list[j++] = "MWM";
 
1378
#endif
 
1379
 
 
1380
        buf[0] = 0;
 
1381
        for (i = 0; i < j; i++) {
 
1382
            if (i > 0) {
 
1383
                if (i == j - 1)
 
1384
                    strcat(buf, _(" and "));
 
1385
                else
 
1386
                    strcat(buf, ", ");
 
1387
            }
 
1388
            strcat(buf, list[i]);
 
1389
        }
 
1390
        strbuf = wstrappend(strbuf, buf);
 
1391
    }
 
1392
 
 
1393
    if (wPreferences.no_sound) {
 
1394
        strbuf = wstrappend(strbuf, _("\nSound disabled"));
 
1395
    } else {
 
1396
        strbuf = wstrappend(strbuf, _("\nSound enabled"));
 
1397
    }
 
1398
 
 
1399
#ifdef VIRTUAL_DESKTOP
 
1400
    if (wPreferences.vdesk_enable)
 
1401
        strbuf = wstrappend(strbuf, _(", VirtualDesktop enabled"));
 
1402
    else
 
1403
        strbuf = wstrappend(strbuf, _(", VirtualDesktop disabled"));
 
1404
#endif
 
1405
 
 
1406
#ifdef XINERAMA
 
1407
    strbuf = wstrappend(strbuf, _("\n"));
 
1408
#ifdef SOLARIS_XINERAMA
 
1409
    strbuf = wstrappend(strbuf, _("Solaris "));
 
1410
#endif
 
1411
    strbuf = wstrappend(strbuf, _("Xinerama: "));
 
1412
    {
 
1413
        char tmp[128];
 
1414
        snprintf(tmp, sizeof(tmp)-1, "%d heads found.", scr->xine_info.count);
 
1415
        strbuf = wstrappend(strbuf, tmp);
 
1416
    }
 
1417
#endif
 
1418
 
 
1419
 
 
1420
    panel->infoL = WMCreateLabel(panel->win);
 
1421
    WMResizeWidget(panel->infoL, 350, 75);
 
1422
    WMMoveWidget(panel->infoL, 15, 115);
 
1423
    WMSetLabelText(panel->infoL, strbuf);
 
1424
    font = WMSystemFontOfSize(scr->wmscreen, 11);
 
1425
    if (font) {
 
1426
        WMSetLabelFont(panel->infoL, font);
 
1427
        WMReleaseFont(font);
 
1428
        font = NULL;
 
1429
    }
 
1430
    wfree(strbuf);
 
1431
 
 
1432
 
 
1433
    WMRealizeWidget(panel->win);
 
1434
    WMMapSubwidgets(panel->win);
 
1435
 
 
1436
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
 
1437
 
 
1438
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
1439
 
 
1440
    WMMapWidget(panel->win);
 
1441
 
 
1442
    {
 
1443
        WMPoint center = getCenter(scr, 382, 230);
 
1444
 
 
1445
        wwin = wManageInternalWindow(scr, parent, None, _("Info"),
 
1446
                                     center.x, center.y,
 
1447
                                     382, 230);
 
1448
    }
 
1449
 
 
1450
    WSETUFLAG(wwin, no_closable, 0);
 
1451
    WSETUFLAG(wwin, no_close_button, 0);
 
1452
#ifdef XKB_BUTTON_HINT
 
1453
    wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
 
1454
#endif
 
1455
    wWindowUpdateButtonImages(wwin);
 
1456
    wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
 
1457
    wwin->frame->on_click_right = destroyInfoPanel;
 
1458
 
 
1459
    wWindowMap(wwin);
 
1460
 
 
1461
    panel->wwin = wwin;
 
1462
 
 
1463
    thePanel = panel;
 
1464
#ifdef SILLYNESS
 
1465
    if (InitXThing(panel->scr)) {
 
1466
        panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
 
1467
        panel->cycle = 0;
 
1468
        panel->x = 1;
 
1469
        panel->str = _("Merry Christmas!");
 
1470
        panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
 
1471
    }
 
1472
#endif
 
1473
}
 
1474
 
 
1475
 
 
1476
/*
 
1477
 ***********************************************************************
 
1478
 * Legal Panel
 
1479
 ***********************************************************************
 
1480
 */
 
1481
 
 
1482
typedef struct {
 
1483
    WScreen *scr;
 
1484
 
 
1485
    WWindow *wwin;
 
1486
 
 
1487
    WMWindow *win;
 
1488
 
 
1489
    WMLabel *licenseL;
 
1490
} LegalPanel;
 
1491
 
 
1492
 
 
1493
static LegalPanel *legalPanel = NULL;
 
1494
 
 
1495
static void
 
1496
destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
 
1497
{
 
1498
    WMUnmapWidget(legalPanel->win);
 
1499
 
 
1500
    WMDestroyWidget(legalPanel->win);
 
1501
 
 
1502
    wUnmanageWindow(legalPanel->wwin, False, False);
 
1503
 
 
1504
    wfree(legalPanel);
 
1505
 
 
1506
    legalPanel = NULL;
 
1507
}
 
1508
 
 
1509
 
 
1510
void
 
1511
wShowLegalPanel(WScreen *scr)
 
1512
{
 
1513
    LegalPanel *panel;
 
1514
    Window parent;
 
1515
    WWindow *wwin;
 
1516
 
 
1517
    if (legalPanel) {
 
1518
        if (legalPanel->scr == scr) {
 
1519
            wRaiseFrame(legalPanel->wwin->frame->core);
 
1520
            wSetFocusTo(scr, legalPanel->wwin);
 
1521
        }
 
1522
        return;
 
1523
    }
 
1524
 
 
1525
    panel = wmalloc(sizeof(LegalPanel));
 
1526
 
 
1527
    panel->scr = scr;
 
1528
 
 
1529
    panel->win = WMCreateWindow(scr->wmscreen, "legal");
 
1530
    WMResizeWidget(panel->win, 420, 250);
 
1531
 
 
1532
 
 
1533
    panel->licenseL = WMCreateLabel(panel->win);
 
1534
    WMSetLabelWraps(panel->licenseL, True);
 
1535
    WMResizeWidget(panel->licenseL, 400, 230);
 
1536
    WMMoveWidget(panel->licenseL, 10, 10);
 
1537
    WMSetLabelTextAlignment(panel->licenseL, WALeft);
 
1538
    WMSetLabelText(panel->licenseL,
 
1539
                   _("    Window Maker is free software; you can redistribute it and/or\n"
 
1540
                     "modify it under the terms of the GNU General Public License as\n"
 
1541
                     "published by the Free Software Foundation; either version 2 of the\n"
 
1542
                     "License, or (at your option) any later version.\n\n"
 
1543
                     "    Window Maker is distributed in the hope that it will be useful,\n"
 
1544
                     "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
 
1545
                     "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
 
1546
                     "See the GNU General Public License for more details.\n\n"
 
1547
                     "    You should have received a copy of the GNU General Public\n"
 
1548
                     "License along with this program; if not, write to the Free Software\n"
 
1549
                     "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
 
1550
                     "02111-1307, USA."));
 
1551
    WMSetLabelRelief(panel->licenseL, WRGroove);
 
1552
 
 
1553
    WMRealizeWidget(panel->win);
 
1554
    WMMapSubwidgets(panel->win);
 
1555
 
 
1556
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
 
1557
 
 
1558
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
1559
 
 
1560
    {
 
1561
        WMPoint center = getCenter(scr, 420, 250);
 
1562
 
 
1563
        wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
 
1564
                                     center.x, center.y,
 
1565
                                     420, 250);
 
1566
    }
 
1567
 
 
1568
    WSETUFLAG(wwin, no_closable, 0);
 
1569
    WSETUFLAG(wwin, no_close_button, 0);
 
1570
    wWindowUpdateButtonImages(wwin);
 
1571
    wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
 
1572
#ifdef XKB_BUTTON_HINT
 
1573
    wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
 
1574
#endif
 
1575
    wwin->frame->on_click_right = destroyLegalPanel;
 
1576
 
 
1577
    panel->wwin = wwin;
 
1578
 
 
1579
    WMMapWidget(panel->win);
 
1580
 
 
1581
    wWindowMap(wwin);
 
1582
 
 
1583
    legalPanel = panel;
 
1584
}
 
1585
 
 
1586
 
 
1587
/*
 
1588
 ***********************************************************************
 
1589
 * Crashing Dialog Panel
 
1590
 ***********************************************************************
 
1591
 */
 
1592
 
 
1593
extern WDDomain *WDWindowAttributes;
 
1594
 
 
1595
 
 
1596
typedef struct _CrashPanel {
 
1597
    WMWindow *win;            /* main window */
 
1598
 
 
1599
    WMLabel *iconL;           /* application icon */
 
1600
    WMLabel *nameL;           /* title of panel */
 
1601
 
 
1602
    WMFrame *sepF;            /* separator frame */
 
1603
 
 
1604
    WMLabel *noteL;           /* Title of note */
 
1605
    WMLabel *note2L;          /* body of note with what happened */
 
1606
 
 
1607
    WMFrame *whatF;           /* "what to do next" frame */
 
1608
    WMPopUpButton *whatP;     /* action selection popup button */
 
1609
 
 
1610
    WMButton *okB;            /* ok button */
 
1611
 
 
1612
    Bool done;                /* if finished with this dialog */
 
1613
    int action;               /* what to do after */
 
1614
 
 
1615
    KeyCode retKey;
 
1616
 
 
1617
} CrashPanel;
 
1618
 
 
1619
 
 
1620
static void
 
1621
handleKeyPress(XEvent *event, void *clientData)
 
1622
{
 
1623
    CrashPanel *panel = (CrashPanel*)clientData;
 
1624
 
 
1625
    if (event->xkey.keycode == panel->retKey) {
 
1626
        WMPerformButtonClick(panel->okB);
 
1627
    }
 
1628
}
 
1629
 
 
1630
 
 
1631
static void
 
1632
okButtonCallback(void *self, void *clientData)
 
1633
{
 
1634
    CrashPanel *panel = (CrashPanel*)clientData;
 
1635
 
 
1636
    panel->done = True;
 
1637
}
 
1638
 
 
1639
 
 
1640
static void
 
1641
setCrashAction(void *self, void *clientData)
 
1642
{
 
1643
    WMPopUpButton *pop = (WMPopUpButton*)self;
 
1644
    CrashPanel *panel = (CrashPanel*)clientData;
 
1645
 
 
1646
    panel->action = WMGetPopUpButtonSelectedItem(pop);
 
1647
}
 
1648
 
 
1649
 
 
1650
/* Make this read the logo from a compiled in pixmap -Dan */
 
1651
static WMPixmap*
 
1652
getWindowMakerIconImage(WMScreen *scr)
 
1653
{
 
1654
    WMPropList *dict, *key, *option, *value=NULL;
 
1655
    WMPixmap *pix=NULL;
 
1656
    char *path;
 
1657
 
 
1658
    if (!WDWindowAttributes || !WDWindowAttributes->dictionary)
 
1659
        return NULL;
 
1660
 
 
1661
    WMPLSetCaseSensitive(True);
 
1662
 
 
1663
    key = WMCreatePLString("Logo.WMPanel");
 
1664
    option = WMCreatePLString("Icon");
 
1665
 
 
1666
    dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
 
1667
 
 
1668
    if (dict) {
 
1669
        value = WMGetFromPLDictionary(dict, option);
 
1670
    }
 
1671
 
 
1672
    WMReleasePropList(key);
 
1673
    WMReleasePropList(option);
 
1674
 
 
1675
    WMPLSetCaseSensitive(False);
 
1676
 
 
1677
    if (value && WMIsPLString(value)) {
 
1678
        path = FindImage(wPreferences.icon_path, WMGetFromPLString(value));
 
1679
 
 
1680
        if (path) {
 
1681
            RColor gray;
 
1682
 
 
1683
            gray.red = 0xae;  gray.green = 0xaa;
 
1684
            gray.blue = 0xae; gray.alpha = 0;
 
1685
 
 
1686
            pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
 
1687
            wfree(path);
 
1688
        }
 
1689
    }
 
1690
 
 
1691
    return pix;
 
1692
}
 
1693
 
 
1694
 
 
1695
#define PWIDTH  295
 
1696
#define PHEIGHT 345
 
1697
 
 
1698
 
 
1699
int
 
1700
wShowCrashingDialogPanel(int whatSig)
 
1701
{
 
1702
    CrashPanel *panel;
 
1703
    WMScreen *scr;
 
1704
    WMFont *font;
 
1705
    WMPixmap *logo;
 
1706
    int screen_no, scr_width, scr_height;
 
1707
    int action;
 
1708
    char buf[256];
 
1709
 
 
1710
    panel = wmalloc(sizeof(CrashPanel));
 
1711
    memset(panel, 0, sizeof(CrashPanel));
 
1712
 
 
1713
    screen_no = DefaultScreen(dpy);
 
1714
    scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
 
1715
    scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
 
1716
 
 
1717
    scr = WMCreateScreen(dpy, screen_no);
 
1718
    if (!scr) {
 
1719
        wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
 
1720
        return WMAbort;
 
1721
    }
 
1722
 
 
1723
    panel->retKey = XKeysymToKeycode(dpy, XK_Return);
 
1724
 
 
1725
    panel->win = WMCreateWindow(scr, "crashingDialog");
 
1726
    WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
 
1727
    WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
 
1728
 
 
1729
    logo = getWindowMakerIconImage(scr);
 
1730
    if (logo) {
 
1731
        panel->iconL = WMCreateLabel(panel->win);
 
1732
        WMResizeWidget(panel->iconL, 64, 64);
 
1733
        WMMoveWidget(panel->iconL, 10, 10);
 
1734
        WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
 
1735
        WMSetLabelImage(panel->iconL, logo);
 
1736
    }
 
1737
 
 
1738
    panel->nameL = WMCreateLabel(panel->win);
 
1739
    WMResizeWidget(panel->nameL, 200, 30);
 
1740
    WMMoveWidget(panel->nameL, 80, 25);
 
1741
    WMSetLabelTextAlignment(panel->nameL, WALeft);
 
1742
    font = WMBoldSystemFontOfSize(scr, 24);
 
1743
    WMSetLabelFont(panel->nameL, font);
 
1744
    WMReleaseFont(font);
 
1745
    WMSetLabelText(panel->nameL, _("Fatal error"));
 
1746
 
 
1747
    panel->sepF = WMCreateFrame(panel->win);
 
1748
    WMResizeWidget(panel->sepF, PWIDTH+4, 2);
 
1749
    WMMoveWidget(panel->sepF, -2, 80);
 
1750
 
 
1751
    panel->noteL = WMCreateLabel(panel->win);
 
1752
    WMResizeWidget(panel->noteL, PWIDTH-20, 40);
 
1753
    WMMoveWidget(panel->noteL, 10, 90);
 
1754
    WMSetLabelTextAlignment(panel->noteL, WAJustified);
 
1755
#ifdef SYS_SIGLIST_DECLARED
 
1756
    snprintf(buf, sizeof(buf), _("Window Maker received signal %i\n(%s)."),
 
1757
             whatSig, sys_siglist[whatSig]);
 
1758
#else
 
1759
    snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
 
1760
#endif
 
1761
    WMSetLabelText(panel->noteL, buf);
 
1762
 
 
1763
    panel->note2L = WMCreateLabel(panel->win);
 
1764
    WMResizeWidget(panel->note2L, PWIDTH-20, 100);
 
1765
    WMMoveWidget(panel->note2L, 10, 130);
 
1766
    WMSetLabelTextAlignment(panel->note2L, WALeft);
 
1767
    WMSetLabelText(panel->note2L,
 
1768
                   _(" This fatal error occured probably due to a bug."
 
1769
                     " Please fill the included BUGFORM and "
 
1770
                     "report it to bugs@windowmaker.org."));
 
1771
    WMSetLabelWraps(panel->note2L, True);
 
1772
 
 
1773
 
 
1774
    panel->whatF = WMCreateFrame(panel->win);
 
1775
    WMResizeWidget(panel->whatF, PWIDTH-20, 50);
 
1776
    WMMoveWidget(panel->whatF, 10, 240);
 
1777
    WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
 
1778
 
 
1779
    panel->whatP = WMCreatePopUpButton(panel->whatF);
 
1780
    WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
 
1781
    WMMoveWidget(panel->whatP, 35, 20);
 
1782
    WMSetPopUpButtonPullsDown(panel->whatP, False);
 
1783
    WMSetPopUpButtonText(panel->whatP, _("Select action"));
 
1784
    WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
 
1785
    WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
 
1786
    WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
 
1787
    WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
 
1788
    WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
 
1789
    panel->action = WMRestart;
 
1790
 
 
1791
    WMMapSubwidgets(panel->whatF);
 
1792
 
 
1793
    panel->okB = WMCreateCommandButton(panel->win);
 
1794
    WMResizeWidget(panel->okB, 80, 26);
 
1795
    WMMoveWidget(panel->okB, 205, 309);
 
1796
    WMSetButtonText(panel->okB, _("OK"));
 
1797
    WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
 
1798
    WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
 
1799
    WMSetButtonImagePosition(panel->okB, WIPRight);
 
1800
    WMSetButtonAction(panel->okB, okButtonCallback, panel);
 
1801
 
 
1802
    panel->done = 0;
 
1803
 
 
1804
    WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
 
1805
                         handleKeyPress, panel);
 
1806
 
 
1807
    WMRealizeWidget(panel->win);
 
1808
    WMMapSubwidgets(panel->win);
 
1809
 
 
1810
    WMMapWidget(panel->win);
 
1811
 
 
1812
    XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
 
1813
 
 
1814
    while (!panel->done) {
 
1815
        XEvent event;
 
1816
 
 
1817
        WMNextEvent(dpy, &event);
 
1818
        WMHandleEvent(&event);
 
1819
    }
 
1820
 
 
1821
    action = panel->action;
 
1822
 
 
1823
    WMUnmapWidget(panel->win);
 
1824
    WMDestroyWidget(panel->win);
 
1825
    wfree(panel);
 
1826
 
 
1827
    return action;
 
1828
}
 
1829
 
 
1830
 
 
1831
 
 
1832
 
 
1833
/*****************************************************************************
 
1834
 *                      About GNUstep Panel
 
1835
 *****************************************************************************/
 
1836
 
 
1837
 
 
1838
static void
 
1839
drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
 
1840
                unsigned long blackPixel, unsigned long whitePixel)
 
1841
{
 
1842
    GC gc;
 
1843
    XGCValues gcv;
 
1844
    XRectangle rects[3];
 
1845
 
 
1846
    gcv.foreground = blackPixel;
 
1847
    gc = XCreateGC(dpy, d, GCForeground, &gcv);
 
1848
 
 
1849
    XFillArc(dpy, d, gc, width/45, height/45,
 
1850
             width - 2*width/45, height - 2*height/45, 0, 360*64);
 
1851
 
 
1852
    rects[0].x = 0;
 
1853
    rects[0].y = 37*height/45;
 
1854
    rects[0].width = width/3;
 
1855
    rects[0].height = height - rects[0].y;
 
1856
 
 
1857
    rects[1].x = rects[0].width;
 
1858
    rects[1].y = height/2;
 
1859
    rects[1].width = width - 2*width/3;
 
1860
    rects[1].height = height - rects[1].y;
 
1861
 
 
1862
    rects[2].x = 2*width/3;
 
1863
    rects[2].y = height - 37*height/45;
 
1864
    rects[2].width = width/3;
 
1865
    rects[2].height = height - rects[2].y;
 
1866
 
 
1867
    XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
 
1868
    XFillRectangle(dpy, d, gc, 0, 0, width, height);
 
1869
 
 
1870
    XSetForeground(dpy, gc, whitePixel);
 
1871
    XFillArc(dpy, d, gc, width/45, height/45,
 
1872
             width - 2*width/45, height - 2*height/45, 0, 360*64);
 
1873
 
 
1874
    XFreeGC(dpy, gc);
 
1875
}
 
1876
 
 
1877
 
 
1878
typedef struct {
 
1879
    WScreen *scr;
 
1880
 
 
1881
    WWindow *wwin;
 
1882
 
 
1883
    WMWindow *win;
 
1884
 
 
1885
    WMLabel *gstepL;
 
1886
    WMLabel *textL;
 
1887
} GNUstepPanel;
 
1888
 
 
1889
 
 
1890
static GNUstepPanel *gnustepPanel = NULL;
 
1891
 
 
1892
static void
 
1893
destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
 
1894
{
 
1895
    WMUnmapWidget(gnustepPanel->win);
 
1896
 
 
1897
    WMDestroyWidget(gnustepPanel->win);
 
1898
 
 
1899
    wUnmanageWindow(gnustepPanel->wwin, False, False);
 
1900
 
 
1901
    wfree(gnustepPanel);
 
1902
 
 
1903
    gnustepPanel = NULL;
 
1904
}
 
1905
 
 
1906
 
 
1907
void
 
1908
wShowGNUstepPanel(WScreen *scr)
 
1909
{
 
1910
    GNUstepPanel *panel;
 
1911
    Window parent;
 
1912
    WWindow *wwin;
 
1913
    WMPixmap *pixmap;
 
1914
    WMColor *color;
 
1915
 
 
1916
    if (gnustepPanel) {
 
1917
        if (gnustepPanel->scr == scr) {
 
1918
            wRaiseFrame(gnustepPanel->wwin->frame->core);
 
1919
            wSetFocusTo(scr, gnustepPanel->wwin);
 
1920
        }
 
1921
        return;
 
1922
    }
 
1923
 
 
1924
    panel = wmalloc(sizeof(GNUstepPanel));
 
1925
 
 
1926
    panel->scr = scr;
 
1927
 
 
1928
    panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
 
1929
    WMResizeWidget(panel->win, 325, 205);
 
1930
 
 
1931
    pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
 
1932
                            WMScreenDepth(scr->wmscreen), True);
 
1933
 
 
1934
    color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
 
1935
 
 
1936
    drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
 
1937
                    WMColorPixel(color), scr->white_pixel);
 
1938
 
 
1939
    WMReleaseColor(color);
 
1940
 
 
1941
    XSetForeground(dpy, scr->mono_gc, 0);
 
1942
    XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
 
1943
                   130, 130);
 
1944
    drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
 
1945
 
 
1946
    panel->gstepL = WMCreateLabel(panel->win);
 
1947
    WMResizeWidget(panel->gstepL, 285, 64);
 
1948
    WMMoveWidget(panel->gstepL, 20, 0);
 
1949
    WMSetLabelTextAlignment(panel->gstepL, WARight);
 
1950
    WMSetLabelText(panel->gstepL, "GNUstep");
 
1951
    {
 
1952
        WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
 
1953
 
 
1954
        WMSetLabelFont(panel->gstepL, font);
 
1955
        WMReleaseFont(font);
 
1956
    }
 
1957
 
 
1958
    panel->textL = WMCreateLabel(panel->win);
 
1959
    WMResizeWidget(panel->textL, 305, 140);
 
1960
    WMMoveWidget(panel->textL, 10, 50);
 
1961
    WMSetLabelTextAlignment(panel->textL, WARight);
 
1962
    WMSetLabelImagePosition(panel->textL, WIPOverlaps);
 
1963
    WMSetLabelText(panel->textL,
 
1964
                   _("Window Maker is part of the GNUstep project.\n"\
 
1965
                     "The GNUstep project aims to create a free\n"\
 
1966
                     "implementation of the OpenStep(tm) specification\n"\
 
1967
                     "which is a object-oriented framework for\n"\
 
1968
                     "creating advanced graphical, multi-platform\n"\
 
1969
                     "applications. Additionally, a development and\n"\
 
1970
                     "user desktop enviroment will be created on top\n"\
 
1971
                     "of the framework. For more information about\n"\
 
1972
                     "GNUstep, please visit: www.gnustep.org"));
 
1973
    WMSetLabelImage(panel->textL, pixmap);
 
1974
 
 
1975
    WMReleasePixmap(pixmap);
 
1976
 
 
1977
    WMRealizeWidget(panel->win);
 
1978
    WMMapSubwidgets(panel->win);
 
1979
 
 
1980
    parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
 
1981
 
 
1982
    XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
 
1983
 
 
1984
    {
 
1985
        WMPoint center = getCenter(scr, 325, 200);
 
1986
 
 
1987
        wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
 
1988
                                     center.x, center.y,
 
1989
                                     325, 200);
 
1990
    }
 
1991
 
 
1992
    WSETUFLAG(wwin, no_closable, 0);
 
1993
    WSETUFLAG(wwin, no_close_button, 0);
 
1994
    wWindowUpdateButtonImages(wwin);
 
1995
    wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
 
1996
#ifdef XKB_BUTTON_HINT
 
1997
    wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
 
1998
#endif
 
1999
    wwin->frame->on_click_right = destroyGNUstepPanel;
 
2000
 
 
2001
    panel->wwin = wwin;
 
2002
 
 
2003
    WMMapWidget(panel->win);
 
2004
 
 
2005
    wWindowMap(wwin);
 
2006
 
 
2007
    gnustepPanel = panel;
 
2008
}
 
2009