- Finished moving to the new proplist handling code in WINGs.
[wmaker-crm.git] / src / dialog.c
blob6b90bf231f660860a2005e82074c4fe0e18317fe
1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1999 Dan Pascu
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.
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.
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.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
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>
39 #ifdef HAVE_MALLOC_H
40 #include <malloc.h>
41 #endif
43 #include <signal.h>
44 #ifdef __FreeBSD__
45 #include <sys/signal.h>
46 #endif
49 #ifndef PATH_MAX
50 #define PATH_MAX DEFAULT_PATH_MAX
51 #endif
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"
65 extern WPreferences wPreferences;
69 int
70 wMessageDialog(WScreen *scr, char *title, char *message,
71 char *defBtn, char *altBtn, char *othBtn)
73 WMAlertPanel *panel;
74 Window parent;
75 WWindow *wwin;
76 int result;
78 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
79 defBtn, altBtn, othBtn);
81 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
83 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
85 wwin = wManageInternalWindow(scr, parent, None, NULL,
86 (scr->scr_width - 400)/2,
87 (scr->scr_height - 180)/2, 400, 180);
88 wwin->client_leader = WMWidgetXID(panel->win);
90 WMMapWidget(panel->win);
92 wWindowMap(wwin);
94 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
96 result = panel->result;
98 WMUnmapWidget(panel->win);
100 wUnmanageWindow(wwin, False, False);
102 WMDestroyAlertPanel(panel);
104 XDestroyWindow(dpy, parent);
106 return result;
112 wInputDialog(WScreen *scr, char *title, char *message, char **text)
114 WWindow *wwin;
115 Window parent;
116 WMInputPanel *panel;
117 char *result;
120 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
121 _("OK"), _("Cancel"));
124 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
125 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
127 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
129 wwin = wManageInternalWindow(scr, parent, None, NULL,
130 (scr->scr_width - 320)/2,
131 (scr->scr_height - 160)/2, 320, 160);
133 wwin->client_leader = WMWidgetXID(panel->win);
135 WMMapWidget(panel->win);
137 wWindowMap(wwin);
139 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
141 if (panel->result == WAPRDefault)
142 result = WMGetTextFieldText(panel->text);
143 else
144 result = NULL;
146 wUnmanageWindow(wwin, False, False);
148 WMDestroyInputPanel(panel);
150 XDestroyWindow(dpy, parent);
152 if (result==NULL)
153 return False;
154 else {
155 if (*text)
156 wfree(*text);
157 *text = result;
159 return True;
165 *****************************************************************
166 * Icon Selection Panel
167 *****************************************************************
170 typedef struct IconPanel {
172 WScreen *scr;
174 WMWindow *win;
176 WMLabel *dirLabel;
177 WMLabel *iconLabel;
179 WMList *dirList;
180 WMList *iconList;
181 WMFont *normalfont;
183 WMButton *previewButton;
185 WMLabel *iconView;
187 WMLabel *fileLabel;
188 WMTextField *fileField;
190 WMButton *okButton;
191 WMButton *cancelButton;
192 #if 0
193 WMButton *chooseButton;
194 #endif
195 short done;
196 short result;
197 short preview;
198 } IconPanel;
202 static void
203 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
205 struct dirent *dentry;
206 DIR *dir;
207 char pbuf[PATH_MAX+16];
208 char *apath;
209 IconPanel *panel = WMGetHangedData(lPtr);
211 panel->preview = False;
213 apath = wexpandpath(path);
214 dir = opendir(apath);
216 if (!dir) {
217 char *msg;
218 char *tmp;
219 tmp = _("Could not open directory ");
220 msg = wmalloc(strlen(tmp)+strlen(path)+6);
221 strcpy(msg, tmp);
222 strcat(msg, path);
224 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
225 wfree(msg);
226 wfree(apath);
227 return;
230 /* list contents in the column */
231 while ((dentry = readdir(dir))) {
232 struct stat statb;
234 if (strcmp(dentry->d_name, ".")==0 ||
235 strcmp(dentry->d_name, "..")==0)
236 continue;
238 strcpy(pbuf, apath);
239 strcat(pbuf, "/");
240 strcat(pbuf, dentry->d_name);
242 if (stat(pbuf, &statb)<0)
243 continue;
245 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
246 && statb.st_mode & (S_IFREG|S_IFLNK)) {
247 WMAddListItem(lPtr, dentry->d_name);
250 WMSortListItems(lPtr);
252 closedir(dir);
253 wfree(apath);
254 panel->preview = True;
259 static void
260 setViewedImage(IconPanel *panel, char *file)
262 WMPixmap *pixmap;
263 RColor color;
265 color.red = 0xae;
266 color.green = 0xaa;
267 color.blue = 0xae;
268 color.alpha = 0;
269 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
270 file, &color);
271 if (!pixmap) {
272 WMSetButtonEnabled(panel->okButton, False);
274 WMSetLabelText(panel->iconView, _("Could not load image file "));
276 WMSetLabelImage(panel->iconView, NULL);
277 } else {
278 WMSetButtonEnabled(panel->okButton, True);
280 WMSetLabelText(panel->iconView, NULL);
281 WMSetLabelImage(panel->iconView, pixmap);
282 WMReleasePixmap(pixmap);
287 static void
288 listCallback(void *self, void *data)
290 WMList *lPtr = (WMList*)self;
291 IconPanel *panel = (IconPanel*)data;
292 char *path;
294 if (lPtr==panel->dirList) {
295 WMListItem *item = WMGetListSelectedItem(lPtr);
297 if (item == NULL)
298 return;
299 path = item->text;
301 WMSetTextFieldText(panel->fileField, path);
303 WMSetLabelImage(panel->iconView, NULL);
305 WMSetButtonEnabled(panel->okButton, False);
307 WMClearList(panel->iconList);
308 listPixmaps(panel->scr, panel->iconList, path);
309 } else {
310 char *tmp, *iconFile;
311 WMListItem *item = WMGetListSelectedItem(panel->dirList);
313 if (item == NULL)
314 return;
315 path = item->text;
316 tmp = wexpandpath(path);
318 item = WMGetListSelectedItem(panel->iconList);
319 if (item == NULL)
320 return;
321 iconFile = item->text;
323 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
324 strcpy(path, tmp);
325 strcat(path, "/");
326 strcat(path, iconFile);
327 wfree(tmp);
328 WMSetTextFieldText(panel->fileField, path);
329 setViewedImage(panel, path);
330 wfree(path);
335 static void
336 listIconPaths(WMList *lPtr)
338 char *paths;
339 char *path;
341 paths = wstrdup(wPreferences.icon_path);
343 path = strtok(paths, ":");
345 do {
346 char *tmp;
348 tmp = wexpandpath(path);
349 /* do not sort, because the order implies the order of
350 * directories searched */
351 if (access(tmp, X_OK)==0)
352 WMAddListItem(lPtr, path);
353 wfree(tmp);
354 } while ((path=strtok(NULL, ":"))!=NULL);
356 wfree(paths);
360 void
361 drawIconProc(WMList *lPtr, int index, Drawable d, char *text,
362 int state, WMRect *rect)
364 IconPanel *panel = WMGetHangedData(lPtr);
365 GC gc = panel->scr->draw_gc;
366 GC copygc = panel->scr->copy_gc;
367 char *file, *dirfile;
368 WMPixmap *pixmap;
369 WMColor *blackcolor;
370 WMColor *whitecolor;
371 WMSize size;
372 WMScreen *wmscr = WMWidgetScreen(panel->win);
373 RColor color;
374 int width;
376 if(!panel->preview) return;
378 width = rect->size.width;
380 blackcolor = WMBlackColor(wmscr);
381 whitecolor = WMWhiteColor(wmscr);
383 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
385 int len = strlen(dirfile)+strlen(text)+4;
386 file = wmalloc(len);
387 snprintf(file, len, "%s/%s", dirfile, text);
389 wfree(dirfile);
391 if ((state & WLDSSelected) != 0) {
392 color.red = color.green = color.blue = 0xff;
393 color.alpha = 0;
394 } else {
395 color.red = color.blue = 0xae;
396 color.green = 0xaa; color.alpha = 0;
398 pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
399 wfree(file);
401 if (!pixmap) {
402 WMRemoveListItem(lPtr, index);
403 return;
406 XClearArea(dpy, d, rect->pos.x, rect->pos.y, width, rect->size.height,
407 False);
408 XSetClipMask(dpy, gc, None);
410 XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,
411 rect->pos.y +5, width - 10, 54);
413 XDrawLine(dpy, d, WMColorGC(whitecolor), rect->pos.x,
414 rect->pos.y+rect->size.height-1, rect->pos.x+width,
415 rect->pos.y+rect->size.height-1);
418 if (state&WLDSSelected) {
419 XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x,
420 rect->pos.y, width, rect->size.height);
423 size = WMGetPixmapSize(pixmap);
425 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
426 XSetClipOrigin(dpy, copygc, rect->pos.x + (width-size.width)/2,
427 rect->pos.y+2);
428 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
429 size.width>100?100:size.width, size.height>64?64:size.height,
430 rect->pos.x + (width-size.width)/2, rect->pos.y+2);
433 int i,j;
434 int fheight = WMFontHeight(panel->normalfont);
435 int tlen = strlen(text);
436 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
437 int ofx, ofy;
439 ofx = rect->pos.x + (width - twidth)/2;
440 ofy = rect->pos.y + 64 - fheight;
442 for(i=-1;i<2;i++)
443 for(j=-1;j<2;j++)
444 WMDrawString(wmscr, d, WMColorGC(whitecolor),
445 panel->normalfont, ofx+i, ofy+j,
446 text, tlen);
448 WMDrawString(wmscr, d, WMColorGC(blackcolor), panel->normalfont,
449 ofx, ofy, text, tlen);
452 WMReleasePixmap(pixmap);
453 /* I hope it is better to do not use cache / on my box it is fast nuff */
454 XFlush(dpy);
456 WMReleaseColor(blackcolor);
457 WMReleaseColor(whitecolor);
461 static void
462 buttonCallback(void *self, void *clientData)
464 WMButton *bPtr = (WMButton*)self;
465 IconPanel *panel = (IconPanel*)clientData;
468 if (bPtr==panel->okButton) {
469 panel->done = True;
470 panel->result = True;
471 } else if (bPtr==panel->cancelButton) {
472 panel->done = True;
473 panel->result = False;
474 } else if (bPtr==panel->previewButton) {
475 /**** Previewer ****/
476 WMSetButtonEnabled(bPtr, False);
477 WMSetListUserDrawItemHeight(panel->iconList, 68);
478 WMSetListUserDrawProc(panel->iconList, drawIconProc);
479 WMRedisplayWidget(panel->iconList);
480 /* for draw proc to access screen/gc */
481 /*** end preview ***/
483 #if 0
484 else if (bPtr==panel->chooseButton) {
485 WMOpenPanel *op;
487 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
489 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
490 char *path;
491 path = WMGetFilePanelFile(op);
492 WMSetTextFieldText(panel->fileField, path);
493 setViewedImage(panel, path);
494 wfree(path);
496 WMDestroyFilePanel(op);
498 #endif
502 static void
503 keyPressHandler(XEvent *event, void *data)
505 IconPanel *panel = (IconPanel*)data;
506 char buffer[32];
507 int count;
508 KeySym ksym;
509 int iidx;
510 int didx;
511 int item;
512 WMList *list = NULL;
514 if (event->type == KeyRelease)
515 return;
517 buffer[0] = 0;
518 count = XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
521 iidx = WMGetListSelectedItemRow(panel->iconList);
522 didx = WMGetListSelectedItemRow(panel->dirList);
524 switch (ksym) {
525 case XK_Up:
526 if (iidx > 0)
527 item = iidx-1;
528 else
529 item = iidx;
530 list = panel->iconList;
531 break;
532 case XK_Down:
533 if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
534 item = iidx+1;
535 else
536 item = iidx;
537 list = panel->iconList;
538 break;
539 case XK_Home:
540 item = 0;
541 list = panel->iconList;
542 break;
543 case XK_End:
544 item = WMGetListNumberOfRows(panel->iconList) - 1;
545 list = panel->iconList;
546 break;
547 case XK_Next:
548 if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
549 item = didx + 1;
550 else
551 item = didx;
552 list = panel->dirList;
553 break;
554 case XK_Prior:
555 if (didx > 0)
556 item = didx - 1;
557 else
558 item = 0;
559 list = panel->dirList;
560 break;
561 case XK_Return:
562 WMPerformButtonClick(panel->okButton);
563 break;
564 case XK_Escape:
565 WMPerformButtonClick(panel->cancelButton);
566 break;
569 if (list) {
570 WMSelectListItem(list, item);
571 WMSetListPosition(list, item - 5);
572 listCallback(list, panel);
578 Bool
579 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
581 WWindow *wwin;
582 Window parent;
583 IconPanel *panel;
584 WMColor *color;
585 WMFont *boldFont;
587 panel = wmalloc(sizeof(IconPanel));
588 memset(panel, 0, sizeof(IconPanel));
590 panel->scr = scr;
592 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
593 WMResizeWidget(panel->win, 450, 280);
595 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask|KeyReleaseMask,
596 keyPressHandler, panel);
599 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
600 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
602 panel->dirLabel = WMCreateLabel(panel->win);
603 WMResizeWidget(panel->dirLabel, 200, 20);
604 WMMoveWidget(panel->dirLabel, 10, 7);
605 WMSetLabelText(panel->dirLabel, _("Directories"));
606 WMSetLabelFont(panel->dirLabel, boldFont);
607 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
609 WMSetLabelRelief(panel->dirLabel, WRSunken);
611 panel->iconLabel = WMCreateLabel(panel->win);
612 WMResizeWidget(panel->iconLabel, 140, 20);
613 WMMoveWidget(panel->iconLabel, 215, 7);
614 WMSetLabelText(panel->iconLabel, _("Icons"));
615 WMSetLabelFont(panel->iconLabel, boldFont);
616 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
618 WMReleaseFont(boldFont);
620 color = WMWhiteColor(scr->wmscreen);
621 WMSetLabelTextColor(panel->dirLabel, color);
622 WMSetLabelTextColor(panel->iconLabel, color);
623 WMReleaseColor(color);
625 color = WMDarkGrayColor(scr->wmscreen);
626 WMSetWidgetBackgroundColor(panel->iconLabel, color);
627 WMSetWidgetBackgroundColor(panel->dirLabel, color);
628 WMReleaseColor(color);
630 WMSetLabelRelief(panel->iconLabel, WRSunken);
632 panel->dirList = WMCreateList(panel->win);
633 WMResizeWidget(panel->dirList, 200, 170);
634 WMMoveWidget(panel->dirList, 10, 30);
635 WMSetListAction(panel->dirList, listCallback, panel);
637 panel->iconList = WMCreateList(panel->win);
638 WMResizeWidget(panel->iconList, 140, 170);
639 WMMoveWidget(panel->iconList, 215, 30);
640 WMSetListAction(panel->iconList, listCallback, panel);
642 WMHangData(panel->iconList,panel);
644 panel->previewButton = WMCreateCommandButton(panel->win);
645 WMResizeWidget(panel->previewButton, 75, 26);
646 WMMoveWidget(panel->previewButton, 365, 130);
647 WMSetButtonText(panel->previewButton, _("Preview"));
648 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
650 panel->iconView = WMCreateLabel(panel->win);
651 WMResizeWidget(panel->iconView, 75, 75);
652 WMMoveWidget(panel->iconView, 365, 40);
653 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
654 WMSetLabelRelief(panel->iconView, WRSunken);
655 WMSetLabelTextAlignment(panel->iconView, WACenter);
657 panel->fileLabel = WMCreateLabel(panel->win);
658 WMResizeWidget(panel->fileLabel, 80, 20);
659 WMMoveWidget(panel->fileLabel, 10, 210);
660 WMSetLabelText(panel->fileLabel, _("File Name:"));
662 panel->fileField = WMCreateTextField(panel->win);
663 WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
664 WMResizeWidget(panel->fileField, 345, 20);
665 WMMoveWidget(panel->fileField, 95, 210);
666 WMSetTextFieldEditable(panel->fileField, False);
668 panel->okButton = WMCreateCommandButton(panel->win);
669 WMResizeWidget(panel->okButton, 80, 26);
670 WMMoveWidget(panel->okButton, 360, 240);
671 WMSetButtonText(panel->okButton, _("OK"));
672 WMSetButtonEnabled(panel->okButton, False);
673 WMSetButtonAction(panel->okButton, buttonCallback, panel);
675 panel->cancelButton = WMCreateCommandButton(panel->win);
676 WMResizeWidget(panel->cancelButton, 80, 26);
677 WMMoveWidget(panel->cancelButton, 270, 240);
678 WMSetButtonText(panel->cancelButton, _("Cancel"));
679 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
680 #if 0
681 panel->chooseButton = WMCreateCommandButton(panel->win);
682 WMResizeWidget(panel->chooseButton, 110, 26);
683 WMMoveWidget(panel->chooseButton, 150, 240);
684 WMSetButtonText(panel->chooseButton, _("Choose File"));
685 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
686 #endif
687 WMRealizeWidget(panel->win);
688 WMMapSubwidgets(panel->win);
690 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
692 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
695 char *tmp;
696 int len = (instance ? strlen(instance) : 0)
697 + (class ? strlen(class) : 0) + 32;
699 tmp = wmalloc(len);
701 if (tmp && (instance || class))
702 snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
703 else
704 strcpy(tmp, _("Icon Chooser"));
706 wwin = wManageInternalWindow(scr, parent, None, tmp,
707 (scr->scr_width - 450)/2,
708 (scr->scr_height - 280)/2, 450, 280);
709 wfree(tmp);
712 /* put icon paths in the list */
713 listIconPaths(panel->dirList);
715 WMMapWidget(panel->win);
717 wWindowMap(wwin);
719 while (!panel->done) {
720 XEvent event;
722 WMNextEvent(dpy, &event);
723 WMHandleEvent(&event);
726 if (panel->result) {
727 char *defaultPath, *wantedPath;
729 /* check if the file the user selected is not the one that
730 * would be loaded by default with the current search path */
731 *file = WMGetListSelectedItem(panel->iconList)->text;
732 if ((*file)[0]==0) {
733 wfree(*file);
734 *file = NULL;
735 } else {
736 defaultPath = FindImage(wPreferences.icon_path, *file);
737 wantedPath = WMGetTextFieldText(panel->fileField);
738 /* if the file is not the default, use full path */
739 if (strcmp(wantedPath, defaultPath)!=0) {
740 *file = wantedPath;
741 } else {
742 *file = wstrdup(*file);
743 wfree(wantedPath);
745 wfree(defaultPath);
747 } else {
748 *file = NULL;
751 WMReleaseFont(panel->normalfont);
753 WMUnmapWidget(panel->win);
755 WMDestroyWidget(panel->win);
757 wUnmanageWindow(wwin, False, False);
759 wfree(panel);
761 XDestroyWindow(dpy, parent);
763 return panel->result;
768 ***********************************************************************
769 * Info Panel
770 ***********************************************************************
774 typedef struct {
775 WScreen *scr;
777 WWindow *wwin;
779 WMWindow *win;
781 WMLabel *logoL;
782 WMLabel *name1L;
783 WMLabel *name2L;
785 WMLabel *versionL;
787 WMLabel *infoL;
789 WMLabel *copyrL;
791 #ifdef SILLYNESS
792 WMHandlerID timer;
793 int cycle;
794 RImage *icon;
795 RImage *pic;
796 WMPixmap *oldPix;
797 WMFont *oldFont;
798 char *str;
799 int x;
800 #endif
801 } InfoPanel;
805 #define COPYRIGHT_TEXT \
806 "Copyright \xa9 1997~2001 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
807 "Copyright \xa9 1998~2001 Dan Pascu <dan@windowmaker.org>"
811 static InfoPanel *thePanel = NULL;
813 static void
814 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
816 #ifdef SILLYNESS
817 if (thePanel->timer) {
818 WMDeleteTimerHandler(thePanel->timer);
820 if (thePanel->oldPix) {
821 WMReleasePixmap(thePanel->oldPix);
823 if (thePanel->oldFont) {
824 WMReleaseFont(thePanel->oldFont);
826 if (thePanel->icon) {
827 RReleaseImage(thePanel->icon);
829 if (thePanel->pic) {
830 RReleaseImage(thePanel->pic);
832 #endif /* SILLYNESS */
833 WMUnmapWidget(thePanel);
835 wUnmanageWindow(thePanel->wwin, False, False);
837 WMDestroyWidget(thePanel->win);
839 wfree(thePanel);
841 thePanel = NULL;
845 WMPixmap*
846 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
848 WMPixmap *wpix = NULL;
849 Pixmap grad = None;
850 Pixmap mask = None;
851 RContext *rc = WMScreenRContext(scr);
852 XFontStruct *f = NULL;
853 int w, h;
854 GC gc = None;
856 f = XLoadQueryFont(dpy, font);
857 if (!f)
858 return NULL;
860 w = XTextWidth(f, text, strlen(text));
861 h = f->ascent+f->descent;
863 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
864 gc = XCreateGC(dpy, mask, 0, NULL);
865 XSetForeground(dpy, gc, 0);
866 XSetFont(dpy, gc, f->fid);
867 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
869 XSetForeground(dpy, gc, 1);
870 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
871 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
872 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
874 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
876 WMColor *color;
878 color = WMBlackColor(scr);
879 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
880 WMReleaseColor(color);
883 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
885 if (gc)
886 XFreeGC(dpy, gc);
887 XFreeFont(dpy, f);
889 return wpix;
892 #ifdef SILLYNESS
894 extern WMPixmap *DoXThing();
895 extern Bool InitXThing();
897 static void
898 logoPushCallback(void *data)
900 InfoPanel *panel = (InfoPanel*)data;
901 char buffer[512];
902 int i;
903 static int oldi = 0;
904 int len;
905 static int jingobeu[] = {
906 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
907 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
908 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
910 static int c = 0;
912 if (panel->x) {
913 XKeyboardControl kc;
915 if (panel->x > 0) {
916 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
917 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
918 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
919 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
920 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
921 XBell(dpy,50);XFlush(dpy);}else{c--;}}
922 if (!(panel->cycle % 4)) {
923 WMPixmap *p;
925 p = DoXThing(panel->wwin);
926 WMSetLabelImage(panel->logoL, p);
928 } else if (panel->cycle < 30) {
929 RImage *image;
930 WMPixmap *pix;
931 RColor gray;
933 gray.red = 0xae; gray.green = 0xaa;
934 gray.blue = 0xae; gray.alpha = 0;
936 image = RScaleImage(panel->icon, panel->pic->width, panel->pic->height);
937 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
938 pix = WMCreateBlendedPixmapFromRImage(panel->scr->wmscreen, image, &gray);
939 RReleaseImage(image);
940 WMSetLabelImage(panel->logoL, pix);
941 WMReleasePixmap(pix);
944 /* slow down text a little */
945 i = (int)(panel->cycle * 50.0/85.0)%200;
947 if (i != oldi) {
948 len = strlen(panel->str);
950 strncpy(buffer, panel->str, i<len ? i : len);
951 if (i >= len)
952 memset(&buffer[len], ' ', i-len);
954 strncpy(buffer, panel->str, i<len ? i : len);
955 if (i >= len)
956 memset(&buffer[len], ' ', i-len);
957 buffer[i]=0;
959 WMSetLabelText(panel->versionL, buffer);
961 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
963 oldi = i;
966 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
967 panel->cycle++;
971 static void
972 handleLogoPush(XEvent *event, void *data)
974 InfoPanel *panel = (InfoPanel*)data;
975 static int broken = 0;
976 static int clicks = 0;
977 static char *pic_data[] = {
978 "45 45 57 1",
979 " c None",
980 ". c #000000",
981 "X c #383C00",
982 "o c #515500",
983 "O c #616100",
984 "+ c #616900",
985 "@ c #696D00",
986 "# c #697100",
987 "$ c #495100",
988 "% c #202800",
989 "& c #969600",
990 "* c #CFCF00",
991 "= c #D7DB00",
992 "- c #D7D700",
993 "; c #C7CB00",
994 ": c #A6AA00",
995 "> c #494900",
996 ", c #8E8E00",
997 "< c #DFE700",
998 "1 c #F7FF00",
999 "2 c #FFFF00",
1000 "3 c #E7EB00",
1001 "4 c #B6B600",
1002 "5 c #595900",
1003 "6 c #717500",
1004 "7 c #AEB200",
1005 "8 c #CFD300",
1006 "9 c #E7EF00",
1007 "0 c #EFF300",
1008 "q c #9EA200",
1009 "w c #F7FB00",
1010 "e c #F7F700",
1011 "r c #BEBE00",
1012 "t c #8E9200",
1013 "y c #EFF700",
1014 "u c #969A00",
1015 "i c #414500",
1016 "p c #595D00",
1017 "a c #E7E700",
1018 "s c #C7C700",
1019 "d c #797D00",
1020 "f c #BEC300",
1021 "g c #DFE300",
1022 "h c #868600",
1023 "j c #EFEF00",
1024 "k c #9E9E00",
1025 "l c #616500",
1026 "z c #DFDF00",
1027 "x c #868A00",
1028 "c c #969200",
1029 "v c #B6BA00",
1030 "b c #A6A600",
1031 "n c #8E8A00",
1032 "m c #717100",
1033 "M c #AEAE00",
1034 "N c #AEAA00",
1035 "B c #868200",
1036 " ............... ",
1037 " ....XoO+@##+O$%.... ",
1038 " ...%X&*========-;;:o... ",
1039 " ...>.>,<122222222222134@... ",
1040 " ..>5678912222222222222220q%.. ",
1041 " ..$.&-w2222222222222222222er>.. ",
1042 " ..O.t31222222222222222222222y4>.. ",
1043 " ...O5u3222222222222222222222222yri... ",
1044 " ..>p&a22222222222222222222222222wso.. ",
1045 " ..ids91222222222222222222222222222wfi.. ",
1046 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
1047 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
1048 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
1049 " ..o7y22222222v...r222222223hX.i82222221si.. ",
1050 "..io*222222222&...u22222222yt..%*22222220:%. ",
1051 "..>k02222222227...f222222222v..X=222222229t. ",
1052 "..dz12222222220ui:y2222222223d%qw222222221g. ",
1053 ".%vw222222222221y2222222222219*y2222222222wd.",
1054 ".X;2222222222222222222222222222222222222222b.",
1055 ".i*2222222222222222222222222222222222222222v.",
1056 ".i*2222222222222222222222222222222222222222;.",
1057 ".i*22222222222222222222222222222222222222228.",
1058 ".>*2222222222222222222222222222222222222222=.",
1059 ".i*22222222222222222222222222222222222222228.",
1060 ".i*2222222222222222222222222222222222222222;.",
1061 ".X*222222222222222222222222222222we12222222r.",
1062 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
1063 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
1064 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
1065 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
1066 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
1067 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
1068 " ...:e2222218mdz22222222222222a&$vw222220@...",
1069 " ...O-122222y:.u02222222222229q$uj222221r... ",
1070 " ..%&a1222223&573w2222222219NOxz122221z>... ",
1071 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
1072 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
1073 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
1074 " ..Xb9122222109g-****;<y22221zn%... ",
1075 " ..X&801222222222222222222w-h.... ",
1076 " ...o:=022222222222222221=lX... ",
1077 " ..X@:;3w2222222222210fO... ",
1078 " ...XX&v8<30000003-N@... ",
1079 " .....XmnbN:q&Bo.... ",
1080 " ............ "
1082 static char *msgs[] = {
1083 "Have a nice day!",
1084 "Focus follow mouse users will burn in hell!!!",
1085 "Mooo Canada!!!!",
1086 "Hi! My name is bobby...",
1087 "AHH! The neurotic monkeys are after me!",
1088 "WHAT YOU SAY??",
1089 "WE GET SIGNAL",
1090 "SOMEBODY SET UP US THE BOMB",
1091 "ALL YOUR BASE ARE BELONG TO US!",
1092 "Oh My God!!! Larry is back!"
1096 clicks++;
1098 if (!panel->timer && !broken && clicks > 0) {
1099 WMFont *font;
1101 panel->x = 0;
1102 clicks = 0;
1103 if (!panel->icon) {
1104 panel->icon = WMGetApplicationIconImage(panel->scr->wmscreen);
1105 if (!panel->icon) {
1106 broken = 1;
1107 return;
1108 } else {
1109 RColor color;
1111 color.red = 0xae; color.green = 0xaa;
1112 color.blue = 0xae; color.alpha = 0;
1114 panel->icon = RCloneImage(panel->icon);
1115 RCombineImageWithColor(panel->icon, &color);
1118 if (!panel->pic) {
1119 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1120 if (!panel->pic) {
1121 broken = 1;
1122 RReleaseImage(panel->icon);
1123 panel->icon = NULL;
1124 return;
1128 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1130 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1131 panel->cycle = 0;
1132 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1133 /* If we don't use a fixed font, scrolling will be jumpy */
1134 /* Alternatively we can draw text in a pixmap and scroll it smoothly */
1135 if ((panel->oldFont = WMGetLabelFont(panel->versionL))!=NULL)
1136 WMRetainFont(panel->oldFont);
1137 font = WMCreateFont(WMWidgetScreen(panel->versionL), "-*-fixed-*-*-*-*-14-*-*-*-*-*-*-*");
1138 if (font) {
1139 WMSetLabelFont(panel->versionL, font);
1140 WMReleaseFont(font);
1142 WMSetLabelText(panel->versionL, "");
1143 } else if (panel->timer) {
1144 char version[20];
1146 panel->x = 0;
1147 clicks = 0;
1148 WMSetLabelImage(panel->logoL, panel->oldPix);
1149 WMReleasePixmap(panel->oldPix);
1150 panel->oldPix = NULL;
1152 WMDeleteTimerHandler(panel->timer);
1153 panel->timer = NULL;
1155 WMSetLabelFont(panel->versionL, panel->oldFont);
1156 if (panel->oldFont) {
1157 WMReleaseFont(panel->oldFont);
1158 panel->oldFont = NULL;
1160 snprintf(version, sizeof(version), _("Version %s"), VERSION);
1161 WMSetLabelText(panel->versionL, version);
1162 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1166 XEvent ev;
1167 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1168 ButtonPress, &ev));
1171 #endif /* SILLYNESS */
1174 void
1175 wShowInfoPanel(WScreen *scr)
1177 InfoPanel *panel;
1178 WMPixmap *logo;
1179 WMSize size;
1180 WMFont *font;
1181 char *strbuf = NULL;
1182 char buffer[256];
1183 Window parent;
1184 WWindow *wwin;
1185 RColor color1, color2;
1186 char **strl;
1187 int i;
1188 char *visuals[] = {
1189 "StaticGray",
1190 "GrayScale",
1191 "StaticColor",
1192 "PseudoColor",
1193 "TrueColor",
1194 "DirectColor"
1198 if (thePanel) {
1199 if (thePanel->scr == scr) {
1200 wRaiseFrame(thePanel->wwin->frame->core);
1201 wSetFocusTo(scr, thePanel->wwin);
1203 return;
1206 panel = wmalloc(sizeof(InfoPanel));
1207 memset(panel, 0, sizeof(InfoPanel));
1209 panel->scr = scr;
1211 panel->win = WMCreateWindow(scr->wmscreen, "info");
1212 WMResizeWidget(panel->win, 382, 230);
1214 logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor*)NULL);
1215 if (!logo) {
1216 logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
1218 if (logo) {
1219 size = WMGetPixmapSize(logo);
1220 panel->logoL = WMCreateLabel(panel->win);
1221 WMResizeWidget(panel->logoL, 64, 64);
1222 WMMoveWidget(panel->logoL, 30, 20);
1223 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1224 WMSetLabelImage(panel->logoL, logo);
1225 #ifdef SILLYNESS
1226 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1227 handleLogoPush, panel);
1228 #endif
1229 WMReleasePixmap(logo);
1232 panel->name1L = WMCreateLabel(panel->win);
1233 WMResizeWidget(panel->name1L, 240, 30);
1234 WMMoveWidget(panel->name1L, 100, 30);
1235 color1.red = 0;
1236 color1.green = 0;
1237 color1.blue = 0;
1238 color2.red = 0x50;
1239 color2.green = 0x50;
1240 color2.blue = 0x70;
1241 logo = renderText(scr->wmscreen, "GNU Window Maker",
1242 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1243 if (logo) {
1244 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1245 WMSetLabelImage(panel->name1L, logo);
1246 WMReleasePixmap(logo);
1247 } else {
1248 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1249 if (font) {
1250 WMSetLabelFont(panel->name1L, font);
1251 WMReleaseFont(font);
1253 WMSetLabelTextAlignment(panel->name1L, WACenter);
1254 WMSetLabelText(panel->name1L, "GNU Window Maker");
1257 panel->name2L = WMCreateLabel(panel->win);
1258 WMResizeWidget(panel->name2L, 240, 24);
1259 WMMoveWidget(panel->name2L, 100, 60);
1260 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1261 if (font) {
1262 WMSetLabelFont(panel->name2L, font);
1263 WMReleaseFont(font);
1264 font = NULL;
1266 WMSetLabelTextAlignment(panel->name2L, WACenter);
1267 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1270 snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
1271 panel->versionL = WMCreateLabel(panel->win);
1272 WMResizeWidget(panel->versionL, 310, 16);
1273 WMMoveWidget(panel->versionL, 30, 95);
1274 WMSetLabelTextAlignment(panel->versionL, WARight);
1275 WMSetLabelText(panel->versionL, buffer);
1276 WMSetLabelWraps(panel->versionL, False);
1278 panel->copyrL = WMCreateLabel(panel->win);
1279 WMResizeWidget(panel->copyrL, 340, 40);
1280 WMMoveWidget(panel->copyrL, 15, 185);
1281 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1282 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1283 /* we want the (c) character in the helvetica font */
1284 font = WMCreateNormalFont(scr->wmscreen, HELVETICA10_FONT);
1285 if (font) {
1286 WMSetLabelFont(panel->copyrL, font);
1289 strbuf = NULL;
1290 snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
1291 (unsigned)scr->w_visual->visualid,
1292 visuals[scr->w_visual->class], scr->w_depth);
1294 strbuf = wstrappend(strbuf, buffer);
1296 switch (scr->w_depth) {
1297 case 15:
1298 strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
1299 break;
1300 case 16:
1301 strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
1302 break;
1303 case 24:
1304 case 32:
1305 strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
1306 break;
1307 default:
1308 snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1<<scr->w_depth);
1309 strbuf = wstrappend(strbuf, buffer);
1310 break;
1314 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1316 struct mallinfo ma = mallinfo();
1317 snprintf(buffer, sizeof(buffer),
1318 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1319 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
1321 strbuf = wstrappend(strbuf, buffer);
1323 #endif
1325 strbuf = wstrappend(strbuf, _("Supported image formats: "));
1326 strl = RSupportedFileFormats();
1327 for (i=0; strl[i]!=NULL; i++) {
1328 strbuf = wstrappend(strbuf, strl[i]);
1329 strbuf = wstrappend(strbuf, " ");
1332 strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
1334 char *list[8];
1335 char buf[80];
1336 int j = 0;
1338 #ifdef MWM_HINTS
1339 list[j++] = "MWM";
1340 #endif
1341 #ifdef KWM_HINTS
1342 list[j++] = "KDE";
1343 #endif
1344 #ifdef GNOME_STUFF
1345 list[j++] = "GNOME";
1346 #endif
1347 #ifdef OLWM_HINTS
1348 list[j++] = "OLWM";
1349 #endif
1351 buf[0] = 0;
1352 for (i = 0; i < j; i++) {
1353 if (i > 0) {
1354 if (i == j - 1)
1355 strcat(buf, _(" and "));
1356 else
1357 strcat(buf, ", ");
1359 strcat(buf, list[i]);
1361 strbuf = wstrappend(strbuf, buf);
1364 if (wPreferences.no_sound) {
1365 strbuf = wstrappend(strbuf, _("\nSound disabled"));
1366 } else {
1367 strbuf = wstrappend(strbuf, _("\nSound enabled"));
1371 panel->infoL = WMCreateLabel(panel->win);
1372 WMResizeWidget(panel->infoL, 350, 75);
1373 WMMoveWidget(panel->infoL, 15, 115);
1374 WMSetLabelText(panel->infoL, strbuf);
1375 if (font) {
1376 WMSetLabelFont(panel->infoL, font);
1377 WMReleaseFont(font);
1379 wfree(strbuf);
1382 WMRealizeWidget(panel->win);
1383 WMMapSubwidgets(panel->win);
1385 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1387 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1389 WMMapWidget(panel->win);
1391 wwin = wManageInternalWindow(scr, parent, None, _("Info"),
1392 (scr->scr_width - 382)/2,
1393 (scr->scr_height - 230)/2, 382, 230);
1395 WSETUFLAG(wwin, no_closable, 0);
1396 WSETUFLAG(wwin, no_close_button, 0);
1397 #ifdef XKB_BUTTON_HINT
1398 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1399 #endif
1400 wWindowUpdateButtonImages(wwin);
1401 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1402 wwin->frame->on_click_right = destroyInfoPanel;
1404 wWindowMap(wwin);
1406 panel->wwin = wwin;
1408 thePanel = panel;
1409 #ifdef SILLYNESS
1410 if (InitXThing(panel->scr)) {
1411 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1412 panel->cycle = 0;
1413 panel->x = 1;
1414 panel->str = _("Merry X'mas!");
1415 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1417 #endif
1422 ***********************************************************************
1423 * Legal Panel
1424 ***********************************************************************
1427 typedef struct {
1428 WScreen *scr;
1430 WWindow *wwin;
1432 WMWindow *win;
1434 WMLabel *licenseL;
1435 } LegalPanel;
1438 static LegalPanel *legalPanel = NULL;
1440 static void
1441 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1443 WMUnmapWidget(legalPanel->win);
1445 WMDestroyWidget(legalPanel->win);
1447 wUnmanageWindow(legalPanel->wwin, False, False);
1449 wfree(legalPanel);
1451 legalPanel = NULL;
1455 void
1456 wShowLegalPanel(WScreen *scr)
1458 LegalPanel *panel;
1459 Window parent;
1460 WWindow *wwin;
1462 if (legalPanel) {
1463 if (legalPanel->scr == scr) {
1464 wRaiseFrame(legalPanel->wwin->frame->core);
1465 wSetFocusTo(scr, legalPanel->wwin);
1467 return;
1470 panel = wmalloc(sizeof(LegalPanel));
1472 panel->scr = scr;
1474 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1475 WMResizeWidget(panel->win, 420, 250);
1478 panel->licenseL = WMCreateLabel(panel->win);
1479 WMSetLabelWraps(panel->licenseL, True);
1480 WMResizeWidget(panel->licenseL, 400, 230);
1481 WMMoveWidget(panel->licenseL, 10, 10);
1482 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1483 WMSetLabelText(panel->licenseL,
1484 _(" Window Maker is free software; you can redistribute it and/or\n"
1485 "modify it under the terms of the GNU General Public License as\n"
1486 "published by the Free Software Foundation; either version 2 of the\n"
1487 "License, or (at your option) any later version.\n\n\n"
1488 " Window Maker is distributed in the hope that it will be useful,\n"
1489 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1490 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1491 "See the GNU General Public License for more details.\n\n\n"
1492 " You should have received a copy of the GNU General Public\n"
1493 "License along with this program; if not, write to the Free Software\n"
1494 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
1495 "02111-1307, USA."));
1496 WMSetLabelRelief(panel->licenseL, WRGroove);
1498 WMRealizeWidget(panel->win);
1499 WMMapSubwidgets(panel->win);
1501 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1503 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1505 wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
1506 (scr->scr_width - 420)/2,
1507 (scr->scr_height - 250)/2, 420, 250);
1509 WSETUFLAG(wwin, no_closable, 0);
1510 WSETUFLAG(wwin, no_close_button, 0);
1511 wWindowUpdateButtonImages(wwin);
1512 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1513 #ifdef XKB_BUTTON_HINT
1514 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1515 #endif
1516 wwin->frame->on_click_right = destroyLegalPanel;
1518 panel->wwin = wwin;
1520 WMMapWidget(panel->win);
1522 wWindowMap(wwin);
1524 legalPanel = panel;
1529 ***********************************************************************
1530 * Crashing Dialog Panel
1531 ***********************************************************************
1534 extern WDDomain *WDWindowAttributes;
1537 typedef struct _CrashPanel {
1538 WMWindow *win; /* main window */
1540 WMLabel *iconL; /* application icon */
1541 WMLabel *nameL; /* title of panel */
1543 WMFrame *sepF; /* separator frame */
1545 WMLabel *noteL; /* Title of note */
1546 WMLabel *note2L; /* body of note with what happened */
1548 WMFrame *whatF; /* "what to do next" frame */
1549 WMPopUpButton *whatP; /* action selection popup button */
1551 WMButton *okB; /* ok button */
1553 Bool done; /* if finished with this dialog */
1554 int action; /* what to do after */
1556 KeyCode retKey;
1558 } CrashPanel;
1561 static void
1562 handleKeyPress(XEvent *event, void *clientData)
1564 CrashPanel *panel = (CrashPanel*)clientData;
1566 if (event->xkey.keycode == panel->retKey) {
1567 WMPerformButtonClick(panel->okB);
1572 static void
1573 okButtonCallback(void *self, void *clientData)
1575 CrashPanel *panel = (CrashPanel*)clientData;
1577 panel->done = True;
1581 static void
1582 setCrashAction(void *self, void *clientData)
1584 WMPopUpButton *pop = (WMPopUpButton*)self;
1585 CrashPanel *panel = (CrashPanel*)clientData;
1587 panel->action = WMGetPopUpButtonSelectedItem(pop);
1591 static WMPixmap*
1592 getWindowMakerIconImage(WMScreen *scr)
1594 WMPropList *dict, *key, *option, *value=NULL;
1595 WMPixmap *pix=NULL;
1596 char *path;
1598 WMPLSetCaseSensitive(True);
1600 key = WMCreatePLString("Logo.WMPanel");
1601 option = WMCreatePLString("Icon");
1603 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
1605 if (dict) {
1606 value = WMGetFromPLDictionary(dict, option);
1609 WMReleasePropList(key);
1610 WMReleasePropList(option);
1612 WMPLSetCaseSensitive(False);
1614 if (value && WMIsPLString(value)) {
1615 path = FindImage(wPreferences.icon_path, WMGetFromPLString(value));
1617 if (path) {
1618 RColor gray;
1620 gray.red = 0xae; gray.green = 0xaa;
1621 gray.blue = 0xae; gray.alpha = 0;
1623 pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
1624 wfree(path);
1628 return pix;
1632 #define PWIDTH 295
1633 #define PHEIGHT 345
1637 wShowCrashingDialogPanel(int whatSig)
1639 CrashPanel *panel;
1640 WMScreen *scr;
1641 WMFont *font;
1642 WMPixmap *logo;
1643 int screen_no, scr_width, scr_height;
1644 int action;
1645 char buf[256];
1647 panel = wmalloc(sizeof(CrashPanel));
1648 memset(panel, 0, sizeof(CrashPanel));
1650 screen_no = DefaultScreen(dpy);
1651 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1652 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1654 scr = WMCreateScreen(dpy, screen_no);
1655 if (!scr) {
1656 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1657 return WMAbort;
1660 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1662 panel->win = WMCreateWindow(scr, "crashingDialog");
1663 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1664 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1666 logo = getWindowMakerIconImage(scr);
1667 if (logo) {
1668 panel->iconL = WMCreateLabel(panel->win);
1669 WMResizeWidget(panel->iconL, 64, 64);
1670 WMMoveWidget(panel->iconL, 10, 10);
1671 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1672 WMSetLabelImage(panel->iconL, logo);
1675 panel->nameL = WMCreateLabel(panel->win);
1676 WMResizeWidget(panel->nameL, 190, 18);
1677 WMMoveWidget(panel->nameL, 80, 35);
1678 WMSetLabelTextAlignment(panel->nameL, WALeft);
1679 font = WMBoldSystemFontOfSize(scr, 18);
1680 WMSetLabelFont(panel->nameL, font);
1681 WMReleaseFont(font);
1682 WMSetLabelText(panel->nameL, _("Fatal error"));
1684 panel->sepF = WMCreateFrame(panel->win);
1685 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1686 WMMoveWidget(panel->sepF, -2, 80);
1688 panel->noteL = WMCreateLabel(panel->win);
1689 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1690 WMMoveWidget(panel->noteL, 10, 90);
1691 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1692 #ifdef SYS_SIGLIST_DECLARED
1693 snprintf(buf, sizeof(buf), _("Window Maker received signal %i\n(%s)."),
1694 whatSig, sys_siglist[whatSig]);
1695 #else
1696 snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
1697 #endif
1698 WMSetLabelText(panel->noteL, buf);
1700 panel->note2L = WMCreateLabel(panel->win);
1701 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1702 WMMoveWidget(panel->note2L, 10, 130);
1703 WMSetLabelTextAlignment(panel->note2L, WALeft);
1704 WMSetLabelText(panel->note2L,
1705 _(" This fatal error occured probably due to a bug."
1706 " Please fill the included BUGFORM and "
1707 "report it to bugs@windowmaker.org."));
1708 WMSetLabelWraps(panel->note2L, True);
1711 panel->whatF = WMCreateFrame(panel->win);
1712 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1713 WMMoveWidget(panel->whatF, 10, 240);
1714 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1716 panel->whatP = WMCreatePopUpButton(panel->whatF);
1717 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1718 WMMoveWidget(panel->whatP, 35, 20);
1719 WMSetPopUpButtonPullsDown(panel->whatP, False);
1720 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1721 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1722 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1723 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1724 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1725 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1726 panel->action = WMRestart;
1728 WMMapSubwidgets(panel->whatF);
1730 panel->okB = WMCreateCommandButton(panel->win);
1731 WMResizeWidget(panel->okB, 80, 26);
1732 WMMoveWidget(panel->okB, 205, 309);
1733 WMSetButtonText(panel->okB, _("OK"));
1734 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1735 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1736 WMSetButtonImagePosition(panel->okB, WIPRight);
1737 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1739 panel->done = 0;
1741 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1742 handleKeyPress, panel);
1744 WMRealizeWidget(panel->win);
1745 WMMapSubwidgets(panel->win);
1747 WMMapWidget(panel->win);
1749 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1751 while (!panel->done) {
1752 XEvent event;
1754 WMNextEvent(dpy, &event);
1755 WMHandleEvent(&event);
1758 action = panel->action;
1760 WMUnmapWidget(panel->win);
1761 WMDestroyWidget(panel->win);
1762 wfree(panel);
1764 return action;
1770 /*****************************************************************************
1771 * About GNUstep Panel
1772 *****************************************************************************/
1775 static void
1776 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1777 unsigned long blackPixel, unsigned long whitePixel)
1779 GC gc;
1780 XGCValues gcv;
1781 XRectangle rects[3];
1783 gcv.foreground = blackPixel;
1784 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1786 XFillArc(dpy, d, gc, width/45, height/45,
1787 width - 2*width/45, height - 2*height/45, 0, 360*64);
1789 rects[0].x = 0;
1790 rects[0].y = 37*height/45;
1791 rects[0].width = width/3;
1792 rects[0].height = height - rects[0].y;
1794 rects[1].x = rects[0].width;
1795 rects[1].y = height/2;
1796 rects[1].width = width - 2*width/3;
1797 rects[1].height = height - rects[1].y;
1799 rects[2].x = 2*width/3;
1800 rects[2].y = height - 37*height/45;
1801 rects[2].width = width/3;
1802 rects[2].height = height - rects[2].y;
1804 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1805 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1807 XSetForeground(dpy, gc, whitePixel);
1808 XFillArc(dpy, d, gc, width/45, height/45,
1809 width - 2*width/45, height - 2*height/45, 0, 360*64);
1811 XFreeGC(dpy, gc);
1815 typedef struct {
1816 WScreen *scr;
1818 WWindow *wwin;
1820 WMWindow *win;
1822 WMLabel *gstepL;
1823 WMLabel *textL;
1824 } GNUstepPanel;
1827 static GNUstepPanel *gnustepPanel = NULL;
1829 static void
1830 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1832 WMUnmapWidget(gnustepPanel->win);
1834 WMDestroyWidget(gnustepPanel->win);
1836 wUnmanageWindow(gnustepPanel->wwin, False, False);
1838 wfree(gnustepPanel);
1840 gnustepPanel = NULL;
1844 void
1845 wShowGNUstepPanel(WScreen *scr)
1847 GNUstepPanel *panel;
1848 Window parent;
1849 WWindow *wwin;
1850 WMPixmap *pixmap;
1851 WMColor *color;
1853 if (gnustepPanel) {
1854 if (gnustepPanel->scr == scr) {
1855 wRaiseFrame(gnustepPanel->wwin->frame->core);
1856 wSetFocusTo(scr, gnustepPanel->wwin);
1858 return;
1861 panel = wmalloc(sizeof(GNUstepPanel));
1863 panel->scr = scr;
1865 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1866 WMResizeWidget(panel->win, 325, 200);
1868 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1869 WMScreenDepth(scr->wmscreen), True);
1871 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1873 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1874 WMColorPixel(color), scr->white_pixel);
1876 WMReleaseColor(color);
1878 XSetForeground(dpy, scr->mono_gc, 0);
1879 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1880 130, 130);
1881 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1883 panel->gstepL = WMCreateLabel(panel->win);
1884 WMResizeWidget(panel->gstepL, 285, 64);
1885 WMMoveWidget(panel->gstepL, 20, 0);
1886 WMSetLabelTextAlignment(panel->gstepL, WARight);
1887 WMSetLabelText(panel->gstepL, "GNUstep");
1889 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1891 WMSetLabelFont(panel->gstepL, font);
1892 WMReleaseFont(font);
1895 panel->textL = WMCreateLabel(panel->win);
1896 WMResizeWidget(panel->textL, 275, 130);
1897 WMMoveWidget(panel->textL, 30, 50);
1898 WMSetLabelTextAlignment(panel->textL, WARight);
1899 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1900 WMSetLabelText(panel->textL,
1901 _("Window Maker is part of the GNUstep project.\n"\
1902 "The GNUstep project aims to create a free\n"\
1903 "implementation of the OpenStep(tm) specification\n"\
1904 "which is a object-oriented framework for\n"\
1905 "creating advanced graphical, multi-platform\n"\
1906 "applications. Additionally, a development and\n"\
1907 "user desktop enviroment will be created on top\n"\
1908 "of the framework. For more information about\n"\
1909 "GNUstep, please visit: www.gnustep.org"));
1910 WMSetLabelImage(panel->textL, pixmap);
1912 WMReleasePixmap(pixmap);
1914 WMRealizeWidget(panel->win);
1915 WMMapSubwidgets(panel->win);
1917 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1919 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1921 wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
1922 (scr->scr_width - 325)/2,
1923 (scr->scr_height - 200)/2, 325, 200);
1925 WSETUFLAG(wwin, no_closable, 0);
1926 WSETUFLAG(wwin, no_close_button, 0);
1927 wWindowUpdateButtonImages(wwin);
1928 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1929 #ifdef XKB_BUTTON_HINT
1930 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1931 #endif
1932 wwin->frame->on_click_right = destroyGNUstepPanel;
1934 panel->wwin = wwin;
1936 WMMapWidget(panel->win);
1938 wWindowMap(wwin);
1940 gnustepPanel = panel;