new icon chooser dialog.
[wmaker-crm.git] / src / dialog.c
blob4efbea7e6f91017b936d06a6e29398cc1c60a280
1 /* dialog.c - dialog windows for internal use
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1999 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.
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 #include <signal.h>
40 #ifdef __FreeBSD__
41 #include <sys/signal.h>
42 #endif
45 #ifndef PATH_MAX
46 #define PATH_MAX DEFAULT_PATH_MAX
47 #endif
49 #include "WindowMaker.h"
50 #include "GNUstep.h"
51 #include "screen.h"
52 #include "dialog.h"
53 #include "funcs.h"
54 #include "stacking.h"
55 #include "framewin.h"
56 #include "window.h"
57 #include "actions.h"
58 #include "defaults.h"
61 extern WPreferences wPreferences;
65 int
66 wMessageDialog(WScreen *scr, char *title, char *message,
67 char *defBtn, char *altBtn, char *othBtn)
69 WMAlertPanel *panel;
70 Window parent;
71 WWindow *wwin;
72 int result;
74 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
75 defBtn, altBtn, othBtn);
77 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
79 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
81 wwin = wManageInternalWindow(scr, parent, None, NULL,
82 (scr->scr_width - 400)/2,
83 (scr->scr_height - 180)/2, 400, 180);
84 wwin->client_leader = WMWidgetXID(panel->win);
86 WMMapWidget(panel->win);
88 wWindowMap(wwin);
90 while (!panel->done) {
91 XEvent event;
93 WMNextEvent(dpy, &event);
94 WMHandleEvent(&event);
97 result = panel->result;
99 WMUnmapWidget(panel->win);
101 wUnmanageWindow(wwin, False, False);
103 WMDestroyAlertPanel(panel);
105 XDestroyWindow(dpy, parent);
107 return result;
113 wInputDialog(WScreen *scr, char *title, char *message, char **text)
115 WWindow *wwin;
116 Window parent;
117 WMInputPanel *panel;
118 char *result;
121 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
122 _("OK"), _("Cancel"));
125 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
126 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
128 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
130 wwin = wManageInternalWindow(scr, parent, None, NULL,
131 (scr->scr_width - 320)/2,
132 (scr->scr_height - 160)/2, 320, 160);
134 wwin->client_leader = WMWidgetXID(panel->win);
136 WMMapWidget(panel->win);
138 wWindowMap(wwin);
140 while (!panel->done) {
141 XEvent event;
143 WMNextEvent(dpy, &event);
144 WMHandleEvent(&event);
147 if (panel->result == WAPRDefault)
148 result = WMGetTextFieldText(panel->text);
149 else
150 result = NULL;
152 wUnmanageWindow(wwin, False, False);
154 WMDestroyInputPanel(panel);
156 XDestroyWindow(dpy, parent);
158 if (result==NULL)
159 return False;
160 else {
161 if (*text)
162 free(*text);
163 *text = result;
165 return True;
171 *****************************************************************
172 * Icon Selection Panel
173 *****************************************************************
176 typedef struct IconPanel {
178 WScreen *scr;
180 WMWindow *win;
182 WMLabel *dirLabel;
183 WMLabel *iconLabel;
185 WMList *dirList;
186 WMList *iconList;
187 WMFont *normalfont;
189 WMButton *previewButton;
191 WMLabel *iconView;
193 WMLabel *fileLabel;
194 WMTextField *fileField;
196 WMButton *okButton;
197 WMButton *cancelButton;
198 #if 0
199 WMButton *chooseButton;
200 #endif
201 short done;
202 short result;
203 short preview;
204 } IconPanel;
208 static void
209 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
211 struct dirent *dentry;
212 DIR *dir;
213 char pbuf[PATH_MAX+16];
214 char *apath;
215 IconPanel *panel = WMGetHangedData(lPtr);
217 panel->preview = False;
219 apath = wexpandpath(path);
220 dir = opendir(apath);
222 if (!dir) {
223 char *msg;
224 char *tmp;
225 tmp = _("Could not open directory ");
226 msg = wmalloc(strlen(tmp)+strlen(path)+6);
227 strcpy(msg, tmp);
228 strcat(msg, path);
230 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
231 free(msg);
232 free(apath);
233 return;
236 /* list contents in the column */
237 while ((dentry = readdir(dir))) {
238 struct stat statb;
240 if (strcmp(dentry->d_name, ".")==0 ||
241 strcmp(dentry->d_name, "..")==0)
242 continue;
244 strcpy(pbuf, apath);
245 strcat(pbuf, "/");
246 strcat(pbuf, dentry->d_name);
248 if (stat(pbuf, &statb)<0)
249 continue;
251 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
252 && statb.st_mode & (S_IFREG|S_IFLNK)) {
253 WMAddSortedListItem(lPtr, dentry->d_name);
257 closedir(dir);
258 free(apath);
259 panel->preview = True;
264 static void
265 setViewedImage(IconPanel *panel, char *file)
267 WMPixmap *pixmap;
268 RColor color;
270 color.red = 0xae;
271 color.green = 0xaa;
272 color.blue = 0xae;
273 color.alpha = 0;
274 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
275 file, &color);
276 if (!pixmap) {
277 WMSetButtonEnabled(panel->okButton, False);
279 WMSetLabelText(panel->iconView, _("Could not load image file "));
281 WMSetLabelImage(panel->iconView, NULL);
282 } else {
283 WMSetButtonEnabled(panel->okButton, True);
285 WMSetLabelText(panel->iconView, NULL);
286 WMSetLabelImage(panel->iconView, pixmap);
287 WMReleasePixmap(pixmap);
292 static void
293 listCallback(void *self, void *data)
295 WMList *lPtr = (WMList*)self;
296 IconPanel *panel = (IconPanel*)data;
297 char *path;
299 if (lPtr==panel->dirList) {
300 path = WMGetListSelectedItem(lPtr)->text;
302 WMSetTextFieldText(panel->fileField, path);
304 WMSetLabelImage(panel->iconView, NULL);
306 WMSetButtonEnabled(panel->okButton, False);
308 WMClearList(panel->iconList);
309 listPixmaps(panel->scr, panel->iconList, path);
310 } else {
311 char *tmp, *iconFile;
313 path = WMGetListSelectedItem(panel->dirList)->text;
314 tmp = wexpandpath(path);
316 iconFile = WMGetListSelectedItem(panel->iconList)->text;
318 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
319 strcpy(path, tmp);
320 strcat(path, "/");
321 strcat(path, iconFile);
322 free(tmp);
323 WMSetTextFieldText(panel->fileField, path);
324 setViewedImage(panel, path);
325 free(path);
330 static void
331 listIconPaths(WMList *lPtr)
333 char *paths;
334 char *path;
336 paths = wstrdup(wPreferences.icon_path);
338 path = strtok(paths, ":");
340 do {
341 char *tmp;
343 tmp = wexpandpath(path);
344 /* do not sort, because the order implies the order of
345 * directories searched */
346 if (access(tmp, X_OK)==0)
347 WMAddListItem(lPtr, path);
348 free(tmp);
349 } while ((path=strtok(NULL, ":"))!=NULL);
351 free(paths);
355 void drawIconProc(WMList *lPtr, int index, Drawable d, char *text,
356 int state, WMRect *rect) {
357 IconPanel *panel = WMGetHangedData(lPtr);
358 GC gc = panel->scr->draw_gc;
359 GC copygc = panel->scr->copy_gc;
360 char *buffer, *dirfile, *iconfile;
361 WMPixmap *pixmap;
362 WMColor *blackcolor;
363 WMColor *whitecolor;
364 WMSize size;
365 WMScreen *wmscr=WMWidgetScreen(panel->win);
366 int width;
368 if(!panel->preview) return;
370 width = rect->size.width;
372 blackcolor = WMBlackColor(wmscr);
373 whitecolor = WMWhiteColor(wmscr);
375 dirfile = WMGetListSelectedItem(panel->dirList)->text;
376 buffer = wmalloc(strlen(dirfile)+strlen(text)+4);
377 sprintf(buffer,"%s/%s" ,dirfile,text);
379 pixmap = WMCreatePixmapFromFile(WMWidgetScreen(panel->win), buffer);
380 free(buffer);
381 if (!pixmap) {
382 WMRemoveListItem(lPtr, index);
383 return;
386 XClearArea(dpy, d, rect->pos.x,rect->pos.y, width, 64, False);
387 XSetClipMask(dpy, gc, None);
388 XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,rect->pos.y +5, width - 10, 54);
389 if (state&WLDSSelected) {
390 XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,rect->pos.y +5, width - 10, 54);
394 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
395 XSetClipOrigin(dpy, copygc, rect->pos.x, rect->pos.y);
396 size = WMGetPixmapSize(pixmap);
397 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
398 size.width>100?100:size.width, size.height>64?64:size.height, rect->pos.x,rect->pos.y);
401 int i,j;
402 for(i=-1;i<2;i++)
403 for(j=-1;j<2;j++)
404 WMDrawString(wmscr, d, WMColorGC(whitecolor), panel->normalfont , rect->pos.x+i+7, rect->pos.y+62+j-WMFontHeight(panel->normalfont), text, strlen(text));
406 WMDrawString(wmscr, d, WMColorGC(blackcolor), panel->normalfont , rect->pos.x+7, rect->pos.y+62-WMFontHeight(panel->normalfont), text, strlen(text));
408 WMReleasePixmap(pixmap);
409 /* I hope it is better to do not use cache / on my box it is fast nuff */
410 XFlush(dpy);
412 WMReleaseColor(blackcolor);
413 WMReleaseColor(whitecolor);
416 static void
417 buttonCallback(void *self, void *clientData)
419 WMButton *bPtr = (WMButton*)self;
420 IconPanel *panel = (IconPanel*)clientData;
423 if (bPtr==panel->okButton) {
424 panel->done = True;
425 panel->result = True;
426 } else if (bPtr==panel->cancelButton) {
427 panel->done = True;
428 panel->result = False;
429 } else if (bPtr==panel->previewButton) {
430 /**** Previewer ****/
431 WMSetButtonEnabled(bPtr, False);
432 WMSetListUserDrawItemHeight(panel->iconList, 64);
433 WMSetListUserDrawProc(panel->iconList, drawIconProc);
434 WMRedisplayWidget(panel->iconList);
435 /* for draw proc to access screen/gc */
436 /*** end preview ***/
438 #if 0
439 else if (bPtr==panel->chooseButton) {
440 WMOpenPanel *op;
442 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
444 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
445 char *path;
446 path = WMGetFilePanelFile(op);
447 WMSetTextFieldText(panel->fileField, path);
448 setViewedImage(panel, path);
449 free(path);
451 WMDestroyFilePanel(op);
453 #endif
457 Bool
458 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
460 WWindow *wwin;
461 Window parent;
462 IconPanel *panel;
463 WMColor *color;
464 WMFont *boldFont;
466 panel = wmalloc(sizeof(IconPanel));
467 memset(panel, 0, sizeof(IconPanel));
469 panel->scr = scr;
471 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
472 WMResizeWidget(panel->win, 450, 280);
474 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
475 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
477 panel->dirLabel = WMCreateLabel(panel->win);
478 WMResizeWidget(panel->dirLabel, 200, 20);
479 WMMoveWidget(panel->dirLabel, 10, 7);
480 WMSetLabelText(panel->dirLabel, _("Directories"));
481 WMSetLabelFont(panel->dirLabel, boldFont);
482 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
484 WMSetLabelRelief(panel->dirLabel, WRSunken);
486 panel->iconLabel = WMCreateLabel(panel->win);
487 WMResizeWidget(panel->iconLabel, 140, 20);
488 WMMoveWidget(panel->iconLabel, 215, 7);
489 WMSetLabelText(panel->iconLabel, _("Icons"));
490 WMSetLabelFont(panel->iconLabel, boldFont);
491 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
493 WMReleaseFont(boldFont);
495 color = WMWhiteColor(scr->wmscreen);
496 WMSetLabelTextColor(panel->dirLabel, color);
497 WMSetLabelTextColor(panel->iconLabel, color);
498 WMReleaseColor(color);
500 color = WMDarkGrayColor(scr->wmscreen);
501 WMSetWidgetBackgroundColor(panel->iconLabel, color);
502 WMSetWidgetBackgroundColor(panel->dirLabel, color);
503 WMReleaseColor(color);
505 WMSetLabelRelief(panel->iconLabel, WRSunken);
507 panel->dirList = WMCreateList(panel->win);
508 WMResizeWidget(panel->dirList, 200, 170);
509 WMMoveWidget(panel->dirList, 10, 30);
510 WMSetListAction(panel->dirList, listCallback, panel);
512 panel->iconList = WMCreateList(panel->win);
513 WMResizeWidget(panel->iconList, 140, 170);
514 WMMoveWidget(panel->iconList, 215, 30);
515 WMSetListAction(panel->iconList, listCallback, panel);
517 WMHangData(panel->iconList,panel);
519 panel->previewButton = WMCreateCommandButton(panel->win);
520 WMResizeWidget(panel->previewButton, 75, 26);
521 WMMoveWidget(panel->previewButton, 365, 130);
522 WMSetButtonText(panel->previewButton, _("Preview"));
523 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
525 panel->iconView = WMCreateLabel(panel->win);
526 WMResizeWidget(panel->iconView, 75, 75);
527 WMMoveWidget(panel->iconView, 365, 40);
528 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
529 WMSetLabelRelief(panel->iconView, WRSunken);
530 WMSetLabelTextAlignment(panel->iconView, WACenter);
532 panel->fileLabel = WMCreateLabel(panel->win);
533 WMResizeWidget(panel->fileLabel, 80, 20);
534 WMMoveWidget(panel->fileLabel, 10, 210);
535 WMSetLabelText(panel->fileLabel, _("File Name:"));
537 panel->fileField = WMCreateTextField(panel->win);
538 WMResizeWidget(panel->fileField, 345, 20);
539 WMMoveWidget(panel->fileField, 95, 210);
540 WMSetTextFieldEditable(panel->fileField, False);
542 panel->okButton = WMCreateCommandButton(panel->win);
543 WMResizeWidget(panel->okButton, 80, 26);
544 WMMoveWidget(panel->okButton, 360, 240);
545 WMSetButtonText(panel->okButton, _("OK"));
546 WMSetButtonEnabled(panel->okButton, False);
547 WMSetButtonAction(panel->okButton, buttonCallback, panel);
549 panel->cancelButton = WMCreateCommandButton(panel->win);
550 WMResizeWidget(panel->cancelButton, 80, 26);
551 WMMoveWidget(panel->cancelButton, 270, 240);
552 WMSetButtonText(panel->cancelButton, _("Cancel"));
553 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
554 #if 0
555 panel->chooseButton = WMCreateCommandButton(panel->win);
556 WMResizeWidget(panel->chooseButton, 110, 26);
557 WMMoveWidget(panel->chooseButton, 150, 240);
558 WMSetButtonText(panel->chooseButton, _("Choose File"));
559 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
560 #endif
561 WMRealizeWidget(panel->win);
562 WMMapSubwidgets(panel->win);
564 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
566 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
569 char *tmp;
571 tmp = wmalloc((instance ? strlen(instance) : 0)
572 + (class ? strlen(class) : 0) + 32);
574 if (tmp && (instance || class))
575 sprintf(tmp, "%s [%s.%s]", _("Icon Chooser"), instance, class);
576 else
577 strcpy(tmp, _("Icon Chooser"));
579 wwin = wManageInternalWindow(scr, parent, None, tmp,
580 (scr->scr_width - 450)/2,
581 (scr->scr_height - 280)/2, 450, 280);
582 free(tmp);
585 /* put icon paths in the list */
586 listIconPaths(panel->dirList);
588 WMMapWidget(panel->win);
590 wWindowMap(wwin);
592 while (!panel->done) {
593 XEvent event;
595 WMNextEvent(dpy, &event);
596 WMHandleEvent(&event);
599 if (panel->result) {
600 char *defaultPath, *wantedPath;
602 /* check if the file the user selected is not the one that
603 * would be loaded by default with the current search path */
604 *file = WMGetListSelectedItem(panel->iconList)->text;
605 if ((*file)[0]==0) {
606 free(*file);
607 *file = NULL;
608 } else {
609 defaultPath = FindImage(wPreferences.icon_path, *file);
610 wantedPath = WMGetTextFieldText(panel->fileField);
611 /* if the file is not the default, use full path */
612 if (strcmp(wantedPath, defaultPath)!=0) {
613 *file = wantedPath;
614 } else {
615 *file = wstrdup(*file);
616 free(wantedPath);
618 free(defaultPath);
620 } else {
621 *file = NULL;
624 WMReleaseFont(panel->normalfont);
626 WMUnmapWidget(panel->win);
628 WMDestroyWidget(panel->win);
630 wUnmanageWindow(wwin, False, False);
632 free(panel);
634 XDestroyWindow(dpy, parent);
636 return panel->result;
641 ***********************************************************************
642 * Info Panel
643 ***********************************************************************
647 typedef struct {
648 WScreen *scr;
650 WWindow *wwin;
652 WMWindow *win;
654 WMLabel *logoL;
655 WMLabel *name1L;
656 WMLabel *name2L;
658 WMLabel *versionL;
660 WMLabel *infoL;
662 WMLabel *copyrL;
664 #ifdef SILLYNESS
665 WMHandlerID timer;
666 int cycle;
667 RImage *icon;
668 RImage *pic;
669 WMPixmap *oldPix;
670 char *str;
671 int x;
672 #endif
673 } InfoPanel;
677 #define COPYRIGHT_TEXT \
678 "Copyright \xa9 1997~1999 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
679 "Copyright \xa9 1998,1999 Dan Pascu <dan@windowmaker.org>"
683 static InfoPanel *thePanel = NULL;
685 static void
686 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
688 #ifdef SILLYNESS
689 if (thePanel->timer) {
690 WMDeleteTimerHandler(thePanel->timer);
692 if (thePanel->oldPix) {
693 WMReleasePixmap(thePanel->oldPix);
695 if (thePanel->icon) {
696 RDestroyImage(thePanel->icon);
698 if (thePanel->pic) {
699 RDestroyImage(thePanel->pic);
701 #endif /* SILLYNESS */
702 WMUnmapWidget(thePanel);
704 wUnmanageWindow(thePanel->wwin, False, False);
706 WMDestroyWidget(thePanel->win);
708 free(thePanel);
710 thePanel = NULL;
714 WMPixmap*
715 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
717 WMPixmap *wpix = NULL;
718 Pixmap grad = None;
719 Pixmap mask = None;
720 RContext *rc = WMScreenRContext(scr);
721 XFontStruct *f = NULL;
722 int w, h;
723 GC gc = None;
725 f = XLoadQueryFont(dpy, font);
726 if (!f)
727 return NULL;
729 w = XTextWidth(f, text, strlen(text));
730 h = f->ascent+f->descent;
732 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
733 gc = XCreateGC(dpy, mask, 0, NULL);
734 XSetForeground(dpy, gc, 0);
735 XSetFont(dpy, gc, f->fid);
736 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
738 XSetForeground(dpy, gc, 1);
739 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
740 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
741 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
743 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
745 WMColor *color;
747 color = WMBlackColor(scr);
748 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
749 WMReleaseColor(color);
752 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
754 if (gc)
755 XFreeGC(dpy, gc);
756 XFreeFont(dpy, f);
758 return wpix;
761 #ifdef SILLYNESS
763 extern WMPixmap *DoXThing();
764 extern Bool InitXThing();
766 static void
767 logoPushCallback(void *data)
769 InfoPanel *panel = (InfoPanel*)data;
770 char buffer[512];
771 int i;
772 int len;
773 static int jingobeu[] = {
774 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
775 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
776 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
778 static int c = 0;
780 if (panel->x) {
781 XKeyboardControl kc;
783 if (panel->x > 0) {
784 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
785 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
786 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
787 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
788 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
789 XBell(dpy,50);XFlush(dpy);}else{c--;}}
790 if (!(panel->cycle % 4)) {
791 WMPixmap *p;
793 p = DoXThing(panel->wwin);
794 WMSetLabelImage(panel->logoL, p);
796 } else if (panel->cycle < 30) {
797 RImage *image;
798 WMPixmap *pix;
800 image = RCloneImage(panel->icon);
801 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
802 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
803 RDestroyImage(image);
804 WMSetLabelImage(panel->logoL, pix);
805 WMReleasePixmap(pix);
808 i = panel->cycle%200;
810 len = strlen(panel->str);
812 strncpy(buffer, panel->str, i<len ? i : len);
813 if (i >= len)
814 memset(&buffer[len], ' ', i-len);
816 strncpy(buffer, panel->str, i<len ? i : len);
817 if (i >= len)
818 memset(&buffer[len], ' ', i-len);
819 buffer[i]=0;
820 WMSetLabelText(panel->versionL, buffer);
822 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
823 panel->cycle++;
827 static void
828 handleLogoPush(XEvent *event, void *data)
830 InfoPanel *panel = (InfoPanel*)data;
831 static int broken = 0;
832 static int clicks = 0;
833 static char *pic_data[] = {
834 "45 45 57 1",
835 " c None",
836 ". c #000000",
837 "X c #383C00",
838 "o c #515500",
839 "O c #616100",
840 "+ c #616900",
841 "@ c #696D00",
842 "# c #697100",
843 "$ c #495100",
844 "% c #202800",
845 "& c #969600",
846 "* c #CFCF00",
847 "= c #D7DB00",
848 "- c #D7D700",
849 "; c #C7CB00",
850 ": c #A6AA00",
851 "> c #494900",
852 ", c #8E8E00",
853 "< c #DFE700",
854 "1 c #F7FF00",
855 "2 c #FFFF00",
856 "3 c #E7EB00",
857 "4 c #B6B600",
858 "5 c #595900",
859 "6 c #717500",
860 "7 c #AEB200",
861 "8 c #CFD300",
862 "9 c #E7EF00",
863 "0 c #EFF300",
864 "q c #9EA200",
865 "w c #F7FB00",
866 "e c #F7F700",
867 "r c #BEBE00",
868 "t c #8E9200",
869 "y c #EFF700",
870 "u c #969A00",
871 "i c #414500",
872 "p c #595D00",
873 "a c #E7E700",
874 "s c #C7C700",
875 "d c #797D00",
876 "f c #BEC300",
877 "g c #DFE300",
878 "h c #868600",
879 "j c #EFEF00",
880 "k c #9E9E00",
881 "l c #616500",
882 "z c #DFDF00",
883 "x c #868A00",
884 "c c #969200",
885 "v c #B6BA00",
886 "b c #A6A600",
887 "n c #8E8A00",
888 "m c #717100",
889 "M c #AEAE00",
890 "N c #AEAA00",
891 "B c #868200",
892 " ............... ",
893 " ....XoO+@##+O$%.... ",
894 " ...%X&*========-;;:o... ",
895 " ...>.>,<122222222222134@... ",
896 " ..>5678912222222222222220q%.. ",
897 " ..$.&-w2222222222222222222er>.. ",
898 " ..O.t31222222222222222222222y4>.. ",
899 " ...O5u3222222222222222222222222yri... ",
900 " ..>p&a22222222222222222222222222wso.. ",
901 " ..ids91222222222222222222222222222wfi.. ",
902 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
903 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
904 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
905 " ..o7y22222222v...r222222223hX.i82222221si.. ",
906 "..io*222222222&...u22222222yt..%*22222220:%. ",
907 "..>k02222222227...f222222222v..X=222222229t. ",
908 "..dz12222222220ui:y2222222223d%qw222222221g. ",
909 ".%vw222222222221y2222222222219*y2222222222wd.",
910 ".X;2222222222222222222222222222222222222222b.",
911 ".i*2222222222222222222222222222222222222222v.",
912 ".i*2222222222222222222222222222222222222222;.",
913 ".i*22222222222222222222222222222222222222228.",
914 ".>*2222222222222222222222222222222222222222=.",
915 ".i*22222222222222222222222222222222222222228.",
916 ".i*2222222222222222222222222222222222222222;.",
917 ".X*222222222222222222222222222222we12222222r.",
918 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
919 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
920 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
921 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
922 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
923 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
924 " ...:e2222218mdz22222222222222a&$vw222220@...",
925 " ...O-122222y:.u02222222222229q$uj222221r... ",
926 " ..%&a1222223&573w2222222219NOxz122221z>... ",
927 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
928 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
929 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
930 " ..Xb9122222109g-****;<y22221zn%... ",
931 " ..X&801222222222222222222w-h.... ",
932 " ...o:=022222222222222221=lX... ",
933 " ..X@:;3w2222222222210fO... ",
934 " ...XX&v8<30000003-N@... ",
935 " .....XmnbN:q&Bo.... ",
936 " ............ "};
937 static char *msgs[] = {
938 "Sloppy focus is a *?#@",
939 "Repent! Sloppy focus users will burn in hell!!!",
940 "Have a nice day!"
944 clicks++;
945 if (!panel->timer && !broken && clicks > 0) {
946 char *file;
947 char *path;
949 panel->x = 0;
950 clicks = 0;
951 if (!panel->icon) {
952 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
953 if (!file) {
954 broken = 1;
955 return;
958 path = FindImage(wPreferences.icon_path, file);
959 if (!path) {
960 broken = 1;
961 return;
964 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
965 free(path);
966 if (!panel->icon) {
967 broken = 1;
968 return;
971 if (!panel->pic) {
972 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
973 if (!panel->pic || panel->icon->width!=panel->pic->width
974 || panel->icon->height!=panel->pic->height) {
975 broken = 1;
976 RDestroyImage(panel->icon);
977 panel->icon = NULL;
978 if (panel->pic) {
979 RDestroyImage(panel->pic);
980 panel->pic = NULL;
982 return;
986 RColor color;
987 color.red = 0xae;
988 color.green = 0xaa;
989 color.blue = 0xae;
990 color.alpha = 255;
991 RCombineImageWithColor(panel->icon, &color);
992 RCombineImageWithColor(panel->pic, &color);
996 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
998 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
999 panel->cycle = 0;
1000 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1001 } else if (panel->timer) {
1002 char version[20];
1004 panel->x = 0;
1005 clicks = 0;
1006 WMSetLabelImage(panel->logoL, panel->oldPix);
1007 WMReleasePixmap(panel->oldPix);
1008 panel->oldPix = NULL;
1010 WMDeleteTimerHandler(panel->timer);
1011 panel->timer = NULL;
1013 sprintf(version, "Version %s", VERSION);
1014 WMSetLabelText(panel->versionL, version);
1018 XEvent ev;
1019 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1020 ButtonPress, &ev));
1023 #endif /* SILLYNESS */
1026 void
1027 wShowInfoPanel(WScreen *scr)
1029 InfoPanel *panel;
1030 WMPixmap *logo;
1031 WMSize size;
1032 WMFont *font;
1033 char version[32];
1034 char buffer[512];
1035 Window parent;
1036 WWindow *wwin;
1037 RColor color1, color2;
1038 char **strl;
1039 int i;
1040 char *visuals[] = {
1041 "StaticGray",
1042 "GrayScale",
1043 "StaticColor",
1044 "PseudoColor",
1045 "TrueColor",
1046 "DirectColor"
1050 if (thePanel) {
1051 if (thePanel->scr == scr) {
1052 wRaiseFrame(thePanel->wwin->frame->core);
1053 wSetFocusTo(scr, thePanel->wwin);
1055 return;
1058 panel = wmalloc(sizeof(InfoPanel));
1059 memset(panel, 0, sizeof(InfoPanel));
1061 panel->scr = scr;
1063 panel->win = WMCreateWindow(scr->wmscreen, "info");
1064 WMResizeWidget(panel->win, 382, 230);
1066 logo = WMGetApplicationIconImage(scr->wmscreen);
1067 if (logo) {
1068 size = WMGetPixmapSize(logo);
1069 panel->logoL = WMCreateLabel(panel->win);
1070 WMResizeWidget(panel->logoL, 64, 64);
1071 WMMoveWidget(panel->logoL, 30, 20);
1072 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1073 WMSetLabelImage(panel->logoL, logo);
1074 #ifdef SILLYNESS
1075 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1076 handleLogoPush, panel);
1077 #endif
1080 panel->name1L = WMCreateLabel(panel->win);
1081 WMResizeWidget(panel->name1L, 240, 30);
1082 WMMoveWidget(panel->name1L, 100, 30);
1083 color1.red = 0;
1084 color1.green = 0;
1085 color1.blue = 0;
1086 color2.red = 0x50;
1087 color2.green = 0x50;
1088 color2.blue = 0x70;
1089 logo = renderText(scr->wmscreen, "GNU Window Maker",
1090 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1091 if (logo) {
1092 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1093 WMSetLabelImage(panel->name1L, logo);
1094 WMReleasePixmap(logo);
1095 } else {
1096 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1097 if (font) {
1098 WMSetLabelFont(panel->name1L, font);
1099 WMReleaseFont(font);
1101 WMSetLabelTextAlignment(panel->name1L, WACenter);
1102 WMSetLabelText(panel->name1L, "GNU Window Maker");
1105 panel->name2L = WMCreateLabel(panel->win);
1106 WMResizeWidget(panel->name2L, 240, 24);
1107 WMMoveWidget(panel->name2L, 100, 60);
1108 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1109 if (font) {
1110 WMSetLabelFont(panel->name2L, font);
1111 WMReleaseFont(font);
1112 font = NULL;
1114 WMSetLabelTextAlignment(panel->name2L, WACenter);
1115 WMSetLabelText(panel->name2L, "Window Manager for X");
1118 sprintf(version, "Version %s", VERSION);
1119 panel->versionL = WMCreateLabel(panel->win);
1120 WMResizeWidget(panel->versionL, 310, 16);
1121 WMMoveWidget(panel->versionL, 30, 95);
1122 WMSetLabelTextAlignment(panel->versionL, WARight);
1123 WMSetLabelText(panel->versionL, version);
1124 WMSetLabelWraps(panel->versionL, False);
1126 panel->copyrL = WMCreateLabel(panel->win);
1127 WMResizeWidget(panel->copyrL, 340, 40);
1128 WMMoveWidget(panel->copyrL, 15, 185);
1129 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1130 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1131 /* we want the (c) character in the helvetica font */
1132 font = WMCreateNormalFont(scr->wmscreen, HELVETICA10_FONT);
1133 if (font) {
1134 WMSetLabelFont(panel->copyrL, font);
1137 switch (scr->w_depth) {
1138 case 15:
1139 strcpy(version, "32 thousand");
1140 break;
1141 case 16:
1142 strcpy(version, "64 thousand");
1143 break;
1144 case 24:
1145 case 32:
1146 strcpy(version, "16 million");
1147 break;
1148 default:
1149 sprintf(version, "%d", 1<<scr->w_depth);
1150 break;
1153 sprintf(buffer, "Using visual 0x%x: %s %ibpp (%s colors)\n",
1154 (unsigned)scr->w_visual->visualid,
1155 visuals[scr->w_visual->class], scr->w_depth, version);
1157 strcat(buffer, "Supported image formats: ");
1158 strl = RSupportedFileFormats();
1159 for (i=0; strl[i]!=NULL; i++) {
1160 strcat(buffer, strl[i]);
1161 strcat(buffer, " ");
1164 strcat(buffer, "\nAdditional Support For: ");
1166 char *list[8];
1167 char buf[80];
1168 int j = 0;
1170 #ifdef MWM_HINTS
1171 list[j++] = "MWM";
1172 #endif
1173 #ifdef KWM_HINTS
1174 list[j++] = "KDE";
1175 #endif
1176 #ifdef GNOME_STUFF
1177 list[j++] = "GNOME";
1178 #endif
1179 #ifdef OLWM_HINTS
1180 list[j++] = "OLWM";
1181 #endif
1182 #ifdef WMSOUND
1183 list[j++] = "Sound";
1184 #endif
1186 buf[0] = 0;
1187 for (i = 0; i < j; i++) {
1188 if (i > 0) {
1189 if (i == j - 1)
1190 strcat(buf, " and ");
1191 else
1192 strcat(buf, ", ");
1194 strcat(buf, list[i]);
1196 strcat(buffer, buf);
1200 panel->infoL = WMCreateLabel(panel->win);
1201 WMResizeWidget(panel->infoL, 350, 75);
1202 WMMoveWidget(panel->infoL, 15, 115);
1203 WMSetLabelText(panel->infoL, buffer);
1204 if (font) {
1205 WMSetLabelFont(panel->infoL, font);
1206 WMReleaseFont(font);
1210 WMRealizeWidget(panel->win);
1211 WMMapSubwidgets(panel->win);
1213 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1215 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1217 WMMapWidget(panel->win);
1219 wwin = wManageInternalWindow(scr, parent, None, "Info",
1220 (scr->scr_width - 382)/2,
1221 (scr->scr_height - 230)/2, 382, 230);
1223 WSETUFLAG(wwin, no_closable, 0);
1224 WSETUFLAG(wwin, no_close_button, 0);
1225 #ifdef XKB_BUTTON_HINT
1226 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1227 #endif
1228 wWindowUpdateButtonImages(wwin);
1229 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1230 wwin->frame->on_click_right = destroyInfoPanel;
1232 wWindowMap(wwin);
1234 panel->wwin = wwin;
1236 thePanel = panel;
1237 #ifdef SILLYNESS
1238 if (InitXThing(panel->scr)) {
1239 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1240 panel->cycle = 0;
1241 panel->x = 1;
1242 panel->str = "Merry Christmas!";
1243 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1245 #endif
1250 ***********************************************************************
1251 * Legal Panel
1252 ***********************************************************************
1255 typedef struct {
1256 WScreen *scr;
1258 WWindow *wwin;
1260 WMWindow *win;
1262 WMLabel *licenseL;
1263 } LegalPanel;
1267 #define LICENSE_TEXT \
1268 " Window Maker is free software; you can redistribute it and/or modify "\
1269 "it under the terms of the GNU General Public License as published "\
1270 "by the Free Software Foundation; either version 2 of the License, "\
1271 "or (at your option) any later version.\n\n\n"\
1272 " Window Maker is distributed in the hope that it will be useful, but "\
1273 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
1274 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
1275 "General Public License for more details.\n\n\n"\
1276 " You should have received a copy of the GNU General Public License "\
1277 "along with this program; if not, write to the Free Software "\
1278 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
1279 "02111-1307, USA."
1282 static LegalPanel *legalPanel = NULL;
1284 static void
1285 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1287 WMUnmapWidget(legalPanel->win);
1289 WMDestroyWidget(legalPanel->win);
1291 wUnmanageWindow(legalPanel->wwin, False, False);
1293 free(legalPanel);
1295 legalPanel = NULL;
1299 void
1300 wShowLegalPanel(WScreen *scr)
1302 LegalPanel *panel;
1303 Window parent;
1304 WWindow *wwin;
1306 if (legalPanel) {
1307 if (legalPanel->scr == scr) {
1308 wRaiseFrame(legalPanel->wwin->frame->core);
1309 wSetFocusTo(scr, legalPanel->wwin);
1311 return;
1314 panel = wmalloc(sizeof(LegalPanel));
1316 panel->scr = scr;
1318 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1319 WMResizeWidget(panel->win, 420, 250);
1322 panel->licenseL = WMCreateLabel(panel->win);
1323 WMResizeWidget(panel->licenseL, 400, 230);
1324 WMMoveWidget(panel->licenseL, 10, 10);
1325 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1326 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
1327 WMSetLabelRelief(panel->licenseL, WRGroove);
1329 WMRealizeWidget(panel->win);
1330 WMMapSubwidgets(panel->win);
1332 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1334 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1336 wwin = wManageInternalWindow(scr, parent, None, "Legal",
1337 (scr->scr_width - 420)/2,
1338 (scr->scr_height - 250)/2, 420, 250);
1340 WSETUFLAG(wwin, no_closable, 0);
1341 WSETUFLAG(wwin, no_close_button, 0);
1342 wWindowUpdateButtonImages(wwin);
1343 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1344 #ifdef XKB_BUTTON_HINT
1345 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1346 #endif
1347 wwin->frame->on_click_right = destroyLegalPanel;
1349 panel->wwin = wwin;
1351 WMMapWidget(panel->win);
1353 wWindowMap(wwin);
1355 legalPanel = panel;
1360 ***********************************************************************
1361 * Crashing Dialog Panel
1362 ***********************************************************************
1365 extern WDDomain *WDWindowAttributes;
1368 typedef struct _CrashPanel {
1369 WMWindow *win; /* main window */
1371 WMLabel *iconL; /* application icon */
1372 WMLabel *nameL; /* title of panel */
1374 WMFrame *sepF; /* separator frame */
1376 WMLabel *noteL; /* Title of note */
1377 WMLabel *note2L; /* body of note with what happened */
1379 WMFrame *whatF; /* "what to do next" frame */
1380 WMPopUpButton *whatP; /* action selection popup button */
1382 WMButton *okB; /* ok button */
1384 Bool done; /* if finished with this dialog */
1385 int action; /* what to do after */
1387 KeyCode retKey;
1389 } CrashPanel;
1392 static void
1393 handleKeyPress(XEvent *event, void *clientData)
1395 CrashPanel *panel = (CrashPanel*)clientData;
1397 if (event->xkey.keycode == panel->retKey) {
1398 WMPerformButtonClick(panel->okB);
1403 static void
1404 okButtonCallback(void *self, void *clientData)
1406 CrashPanel *panel = (CrashPanel*)clientData;
1408 panel->done = True;
1412 static void
1413 setCrashAction(void *self, void *clientData)
1415 WMPopUpButton *pop = (WMPopUpButton*)self;
1416 CrashPanel *panel = (CrashPanel*)clientData;
1418 panel->action = WMGetPopUpButtonSelectedItem(pop);
1422 static WMPixmap*
1423 getWindowMakerIconImage(WMScreen *scr)
1425 proplist_t dict, key, option, value=NULL;
1426 WMPixmap *pix=NULL;
1427 char *path;
1429 PLSetStringCmpHook(NULL);
1431 key = PLMakeString("Logo.WMPanel");
1432 option = PLMakeString("Icon");
1434 dict = PLGetDictionaryEntry(WDWindowAttributes->dictionary, key);
1436 if (dict) {
1437 value = PLGetDictionaryEntry(dict, option);
1440 PLRelease(key);
1441 PLRelease(option);
1443 PLSetStringCmpHook(StringCompareHook);
1445 if (value && PLIsString(value)) {
1446 path = FindImage(wPreferences.icon_path, PLGetString(value));
1448 if (path) {
1449 RImage *image;
1451 image = RLoadImage(WMScreenRContext(scr), path, 0);
1452 if (image) {
1453 pix = WMCreatePixmapFromRImage(scr, image, 0);
1454 RDestroyImage(image);
1456 free(path);
1460 return pix;
1464 #define PWIDTH 295
1465 #define PHEIGHT 345
1469 wShowCrashingDialogPanel(int whatSig)
1471 CrashPanel *panel;
1472 WMScreen *scr;
1473 WMFont *font;
1474 WMPixmap *logo;
1475 int screen_no, scr_width, scr_height;
1476 int action;
1477 char buf[256];
1479 panel = wmalloc(sizeof(CrashPanel));
1480 memset(panel, 0, sizeof(CrashPanel));
1482 screen_no = DefaultScreen(dpy);
1483 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1484 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1486 scr = WMCreateScreen(dpy, screen_no);
1487 if (!scr) {
1488 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1489 return WMAbort;
1492 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1494 panel->win = WMCreateWindow(scr, "crashingDialog");
1495 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1496 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1498 logo = getWindowMakerIconImage(scr);
1499 if (logo) {
1500 panel->iconL = WMCreateLabel(panel->win);
1501 WMResizeWidget(panel->iconL, 64, 64);
1502 WMMoveWidget(panel->iconL, 10, 10);
1503 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1504 WMSetLabelImage(panel->iconL, logo);
1507 panel->nameL = WMCreateLabel(panel->win);
1508 WMResizeWidget(panel->nameL, 190, 18);
1509 WMMoveWidget(panel->nameL, 80, 35);
1510 WMSetLabelTextAlignment(panel->nameL, WALeft);
1511 font = WMBoldSystemFontOfSize(scr, 18);
1512 WMSetLabelFont(panel->nameL, font);
1513 WMReleaseFont(font);
1514 WMSetLabelText(panel->nameL, _("Fatal error"));
1516 panel->sepF = WMCreateFrame(panel->win);
1517 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1518 WMMoveWidget(panel->sepF, -2, 80);
1520 panel->noteL = WMCreateLabel(panel->win);
1521 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1522 WMMoveWidget(panel->noteL, 10, 90);
1523 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1524 #ifdef SYS_SIGLIST_DECLARED
1525 sprintf(buf, _("Window Maker received signal %i\n(%s)."),
1526 whatSig, sys_siglist[whatSig]);
1527 #else
1528 sprintf(buf, _("Window Maker received signal %i."), whatSig);
1529 #endif
1530 WMSetLabelText(panel->noteL, buf);
1532 panel->note2L = WMCreateLabel(panel->win);
1533 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1534 WMMoveWidget(panel->note2L, 10, 130);
1535 WMSetLabelTextAlignment(panel->note2L, WALeft);
1536 WMSetLabelText(panel->note2L,
1537 _(" This fatal error occured probably due to a bug."
1538 " Please fill the included BUGFORM and "
1539 "report it to bugs@windowmaker.org."));
1542 panel->whatF = WMCreateFrame(panel->win);
1543 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1544 WMMoveWidget(panel->whatF, 10, 240);
1545 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1547 panel->whatP = WMCreatePopUpButton(panel->whatF);
1548 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1549 WMMoveWidget(panel->whatP, 35, 20);
1550 WMSetPopUpButtonPullsDown(panel->whatP, False);
1551 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1552 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1553 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1554 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1555 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1556 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1557 panel->action = WMRestart;
1559 WMMapSubwidgets(panel->whatF);
1561 panel->okB = WMCreateCommandButton(panel->win);
1562 WMResizeWidget(panel->okB, 80, 26);
1563 WMMoveWidget(panel->okB, 205, 309);
1564 WMSetButtonText(panel->okB, _("OK"));
1565 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1566 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1567 WMSetButtonImagePosition(panel->okB, WIPRight);
1568 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1570 panel->done = 0;
1572 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1573 handleKeyPress, panel);
1575 WMRealizeWidget(panel->win);
1576 WMMapSubwidgets(panel->win);
1578 WMMapWidget(panel->win);
1580 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1582 while (!panel->done) {
1583 XEvent event;
1585 WMNextEvent(dpy, &event);
1586 WMHandleEvent(&event);
1589 action = panel->action;
1591 WMUnmapWidget(panel->win);
1592 WMDestroyWidget(panel->win);
1593 free(panel);
1595 return action;
1601 /*****************************************************************************
1602 * About GNUstep Panel
1603 *****************************************************************************/
1606 static void
1607 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1608 unsigned long blackPixel, unsigned long whitePixel)
1610 GC gc;
1611 XGCValues gcv;
1612 XRectangle rects[3];
1614 gcv.foreground = blackPixel;
1615 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1617 XFillArc(dpy, d, gc, width/45, height/45,
1618 width - 2*width/45, height - 2*height/45, 0, 360*64);
1620 rects[0].x = 0;
1621 rects[0].y = 37*height/45;
1622 rects[0].width = width/3;
1623 rects[0].height = height - rects[0].y;
1625 rects[1].x = rects[0].width;
1626 rects[1].y = height/2;
1627 rects[1].width = width - 2*width/3;
1628 rects[1].height = height - rects[1].y;
1630 rects[2].x = 2*width/3;
1631 rects[2].y = height - 37*height/45;
1632 rects[2].width = width/3;
1633 rects[2].height = height - rects[2].y;
1635 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1636 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1638 XSetForeground(dpy, gc, whitePixel);
1639 XFillArc(dpy, d, gc, width/45, height/45,
1640 width - 2*width/45, height - 2*height/45, 0, 360*64);
1642 XFreeGC(dpy, gc);
1647 #define GNUSTEP_TEXT \
1648 "Window Maker is part of the GNUstep project.\n"\
1649 "The GNUstep project aims to create a free\n"\
1650 "implementation of the OpenStep(tm) specification\n"\
1651 "which is a object-oriented framework for\n"\
1652 "creating advanced graphical, multi-platform\n"\
1653 "applications. Aditionally, a development and\n"\
1654 "user desktop enviroment will be created on top\n"\
1655 "of the framework. For more information about\n"\
1656 "GNUstep, please visit: www.gnustep.org"
1659 typedef struct {
1660 WScreen *scr;
1662 WWindow *wwin;
1664 WMWindow *win;
1666 WMLabel *gstepL;
1667 WMLabel *textL;
1668 } GNUstepPanel;
1671 static GNUstepPanel *gnustepPanel = NULL;
1673 static void
1674 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1676 WMUnmapWidget(gnustepPanel->win);
1678 WMDestroyWidget(gnustepPanel->win);
1680 wUnmanageWindow(gnustepPanel->wwin, False, False);
1682 free(gnustepPanel);
1684 gnustepPanel = NULL;
1688 void
1689 wShowGNUstepPanel(WScreen *scr)
1691 GNUstepPanel *panel;
1692 Window parent;
1693 WWindow *wwin;
1694 WMPixmap *pixmap;
1695 WMColor *color;
1697 if (gnustepPanel) {
1698 if (gnustepPanel->scr == scr) {
1699 wRaiseFrame(gnustepPanel->wwin->frame->core);
1700 wSetFocusTo(scr, gnustepPanel->wwin);
1702 return;
1705 panel = wmalloc(sizeof(GNUstepPanel));
1707 panel->scr = scr;
1709 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1710 WMResizeWidget(panel->win, 325, 200);
1712 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1713 WMScreenDepth(scr->wmscreen), True);
1715 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1717 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1718 WMColorPixel(color), scr->white_pixel);
1720 WMReleaseColor(color);
1722 XSetForeground(dpy, scr->mono_gc, 0);
1723 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1724 130, 130);
1725 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1727 panel->gstepL = WMCreateLabel(panel->win);
1728 WMResizeWidget(panel->gstepL, 285, 64);
1729 WMMoveWidget(panel->gstepL, 20, 0);
1730 WMSetLabelTextAlignment(panel->gstepL, WARight);
1731 WMSetLabelText(panel->gstepL, "GNUstep");
1733 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1735 WMSetLabelFont(panel->gstepL, font);
1736 WMReleaseFont(font);
1739 panel->textL = WMCreateLabel(panel->win);
1740 WMResizeWidget(panel->textL, 275, 130);
1741 WMMoveWidget(panel->textL, 30, 50);
1742 WMSetLabelTextAlignment(panel->textL, WARight);
1743 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1744 WMSetLabelText(panel->textL, GNUSTEP_TEXT);
1745 WMSetLabelImage(panel->textL, pixmap);
1747 WMReleasePixmap(pixmap);
1749 WMRealizeWidget(panel->win);
1750 WMMapSubwidgets(panel->win);
1752 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1754 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1756 wwin = wManageInternalWindow(scr, parent, None, "About GNUstep",
1757 (scr->scr_width - 325)/2,
1758 (scr->scr_height - 200)/2, 325, 200);
1760 WSETUFLAG(wwin, no_closable, 0);
1761 WSETUFLAG(wwin, no_close_button, 0);
1762 wWindowUpdateButtonImages(wwin);
1763 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1764 #ifdef XKB_BUTTON_HINT
1765 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1766 #endif
1767 wwin->frame->on_click_right = destroyGNUstepPanel;
1769 panel->wwin = wwin;
1771 WMMapWidget(panel->win);
1773 wWindowMap(wwin);
1775 gnustepPanel = panel;