few more fixes to std colormap code
[wmaker-crm.git] / src / dialog.c
blob94c5ffb230364869a3121d57f21a7ef490824533
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 WMAddListItem(lPtr, dentry->d_name);
256 WMSortListItems(lPtr);
258 closedir(dir);
259 free(apath);
260 panel->preview = True;
265 static void
266 setViewedImage(IconPanel *panel, char *file)
268 WMPixmap *pixmap;
269 RColor color;
271 color.red = 0xae;
272 color.green = 0xaa;
273 color.blue = 0xae;
274 color.alpha = 0;
275 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
276 file, &color);
277 if (!pixmap) {
278 WMSetButtonEnabled(panel->okButton, False);
280 WMSetLabelText(panel->iconView, _("Could not load image file "));
282 WMSetLabelImage(panel->iconView, NULL);
283 } else {
284 WMSetButtonEnabled(panel->okButton, True);
286 WMSetLabelText(panel->iconView, NULL);
287 WMSetLabelImage(panel->iconView, pixmap);
288 WMReleasePixmap(pixmap);
293 static void
294 listCallback(void *self, void *data)
296 WMList *lPtr = (WMList*)self;
297 IconPanel *panel = (IconPanel*)data;
298 char *path;
300 if (lPtr==panel->dirList) {
301 path = WMGetListSelectedItem(lPtr)->text;
303 WMSetTextFieldText(panel->fileField, path);
305 WMSetLabelImage(panel->iconView, NULL);
307 WMSetButtonEnabled(panel->okButton, False);
309 WMClearList(panel->iconList);
310 listPixmaps(panel->scr, panel->iconList, path);
311 } else {
312 char *tmp, *iconFile;
314 path = WMGetListSelectedItem(panel->dirList)->text;
315 tmp = wexpandpath(path);
317 iconFile = WMGetListSelectedItem(panel->iconList)->text;
319 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
320 strcpy(path, tmp);
321 strcat(path, "/");
322 strcat(path, iconFile);
323 free(tmp);
324 WMSetTextFieldText(panel->fileField, path);
325 setViewedImage(panel, path);
326 free(path);
331 static void
332 listIconPaths(WMList *lPtr)
334 char *paths;
335 char *path;
337 paths = wstrdup(wPreferences.icon_path);
339 path = strtok(paths, ":");
341 do {
342 char *tmp;
344 tmp = wexpandpath(path);
345 /* do not sort, because the order implies the order of
346 * directories searched */
347 if (access(tmp, X_OK)==0)
348 WMAddListItem(lPtr, path);
349 free(tmp);
350 } while ((path=strtok(NULL, ":"))!=NULL);
352 free(paths);
356 void
357 drawIconProc(WMList *lPtr, int index, Drawable d, char *text,
358 int state, WMRect *rect)
360 IconPanel *panel = WMGetHangedData(lPtr);
361 GC gc = panel->scr->draw_gc;
362 GC copygc = panel->scr->copy_gc;
363 char *buffer, *dirfile;
364 WMPixmap *pixmap;
365 WMColor *blackcolor;
366 WMColor *whitecolor;
367 WMSize size;
368 WMScreen *wmscr=WMWidgetScreen(panel->win);
369 int width;
371 if(!panel->preview) return;
373 width = rect->size.width;
375 blackcolor = WMBlackColor(wmscr);
376 whitecolor = WMWhiteColor(wmscr);
378 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
379 buffer = wmalloc(strlen(dirfile)+strlen(text)+4);
380 sprintf(buffer, "%s/%s", dirfile, text);
381 free(dirfile);
383 pixmap = WMCreatePixmapFromFile(WMWidgetScreen(panel->win), buffer);
384 free(buffer);
385 if (!pixmap) {
386 WMRemoveListItem(lPtr, index);
387 return;
390 XClearArea(dpy, d, rect->pos.x, rect->pos.y, width, rect->size.height,
391 False);
392 XSetClipMask(dpy, gc, None);
394 XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,
395 rect->pos.y +5, width - 10, 54);
397 XDrawLine(dpy, d, WMColorGC(whitecolor), rect->pos.x,
398 rect->pos.y+rect->size.height-1, rect->pos.x+width,
399 rect->pos.y+rect->size.height-1);
402 if (state&WLDSSelected) {
403 XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x,
404 rect->pos.y, width, rect->size.height);
407 size = WMGetPixmapSize(pixmap);
409 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
410 XSetClipOrigin(dpy, copygc, rect->pos.x + (width-size.width)/2,
411 rect->pos.y+2);
412 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
413 size.width>100?100:size.width, size.height>64?64:size.height,
414 rect->pos.x + (width-size.width)/2, rect->pos.y+2);
417 int i,j;
418 int fheight = WMFontHeight(panel->normalfont);
419 int tlen = strlen(text);
420 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
421 int ofx, ofy;
423 ofx = rect->pos.x + (width - twidth)/2;
424 ofy = rect->pos.y + 64 - fheight;
426 for(i=-1;i<2;i++)
427 for(j=-1;j<2;j++)
428 WMDrawString(wmscr, d, WMColorGC(whitecolor),
429 panel->normalfont, ofx+i, ofy+j,
430 text, tlen);
432 WMDrawString(wmscr, d, WMColorGC(blackcolor), panel->normalfont,
433 ofx, ofy, text, tlen);
436 WMReleasePixmap(pixmap);
437 /* I hope it is better to do not use cache / on my box it is fast nuff */
438 XFlush(dpy);
440 WMReleaseColor(blackcolor);
441 WMReleaseColor(whitecolor);
445 static void
446 buttonCallback(void *self, void *clientData)
448 WMButton *bPtr = (WMButton*)self;
449 IconPanel *panel = (IconPanel*)clientData;
452 if (bPtr==panel->okButton) {
453 panel->done = True;
454 panel->result = True;
455 } else if (bPtr==panel->cancelButton) {
456 panel->done = True;
457 panel->result = False;
458 } else if (bPtr==panel->previewButton) {
459 /**** Previewer ****/
460 WMSetButtonEnabled(bPtr, False);
461 WMSetListUserDrawItemHeight(panel->iconList, 68);
462 WMSetListUserDrawProc(panel->iconList, drawIconProc);
463 WMRedisplayWidget(panel->iconList);
464 /* for draw proc to access screen/gc */
465 /*** end preview ***/
467 #if 0
468 else if (bPtr==panel->chooseButton) {
469 WMOpenPanel *op;
471 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
473 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
474 char *path;
475 path = WMGetFilePanelFile(op);
476 WMSetTextFieldText(panel->fileField, path);
477 setViewedImage(panel, path);
478 free(path);
480 WMDestroyFilePanel(op);
482 #endif
486 Bool
487 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
489 WWindow *wwin;
490 Window parent;
491 IconPanel *panel;
492 WMColor *color;
493 WMFont *boldFont;
495 panel = wmalloc(sizeof(IconPanel));
496 memset(panel, 0, sizeof(IconPanel));
498 panel->scr = scr;
500 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
501 WMResizeWidget(panel->win, 450, 280);
503 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
504 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
506 panel->dirLabel = WMCreateLabel(panel->win);
507 WMResizeWidget(panel->dirLabel, 200, 20);
508 WMMoveWidget(panel->dirLabel, 10, 7);
509 WMSetLabelText(panel->dirLabel, _("Directories"));
510 WMSetLabelFont(panel->dirLabel, boldFont);
511 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
513 WMSetLabelRelief(panel->dirLabel, WRSunken);
515 panel->iconLabel = WMCreateLabel(panel->win);
516 WMResizeWidget(panel->iconLabel, 140, 20);
517 WMMoveWidget(panel->iconLabel, 215, 7);
518 WMSetLabelText(panel->iconLabel, _("Icons"));
519 WMSetLabelFont(panel->iconLabel, boldFont);
520 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
522 WMReleaseFont(boldFont);
524 color = WMWhiteColor(scr->wmscreen);
525 WMSetLabelTextColor(panel->dirLabel, color);
526 WMSetLabelTextColor(panel->iconLabel, color);
527 WMReleaseColor(color);
529 color = WMDarkGrayColor(scr->wmscreen);
530 WMSetWidgetBackgroundColor(panel->iconLabel, color);
531 WMSetWidgetBackgroundColor(panel->dirLabel, color);
532 WMReleaseColor(color);
534 WMSetLabelRelief(panel->iconLabel, WRSunken);
536 panel->dirList = WMCreateList(panel->win);
537 WMResizeWidget(panel->dirList, 200, 170);
538 WMMoveWidget(panel->dirList, 10, 30);
539 WMSetListAction(panel->dirList, listCallback, panel);
541 panel->iconList = WMCreateList(panel->win);
542 WMResizeWidget(panel->iconList, 140, 170);
543 WMMoveWidget(panel->iconList, 215, 30);
544 WMSetListAction(panel->iconList, listCallback, panel);
546 WMHangData(panel->iconList,panel);
548 panel->previewButton = WMCreateCommandButton(panel->win);
549 WMResizeWidget(panel->previewButton, 75, 26);
550 WMMoveWidget(panel->previewButton, 365, 130);
551 WMSetButtonText(panel->previewButton, _("Preview"));
552 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
554 panel->iconView = WMCreateLabel(panel->win);
555 WMResizeWidget(panel->iconView, 75, 75);
556 WMMoveWidget(panel->iconView, 365, 40);
557 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
558 WMSetLabelRelief(panel->iconView, WRSunken);
559 WMSetLabelTextAlignment(panel->iconView, WACenter);
561 panel->fileLabel = WMCreateLabel(panel->win);
562 WMResizeWidget(panel->fileLabel, 80, 20);
563 WMMoveWidget(panel->fileLabel, 10, 210);
564 WMSetLabelText(panel->fileLabel, _("File Name:"));
566 panel->fileField = WMCreateTextField(panel->win);
567 WMResizeWidget(panel->fileField, 345, 20);
568 WMMoveWidget(panel->fileField, 95, 210);
569 WMSetTextFieldEditable(panel->fileField, False);
571 panel->okButton = WMCreateCommandButton(panel->win);
572 WMResizeWidget(panel->okButton, 80, 26);
573 WMMoveWidget(panel->okButton, 360, 240);
574 WMSetButtonText(panel->okButton, _("OK"));
575 WMSetButtonEnabled(panel->okButton, False);
576 WMSetButtonAction(panel->okButton, buttonCallback, panel);
578 panel->cancelButton = WMCreateCommandButton(panel->win);
579 WMResizeWidget(panel->cancelButton, 80, 26);
580 WMMoveWidget(panel->cancelButton, 270, 240);
581 WMSetButtonText(panel->cancelButton, _("Cancel"));
582 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
583 #if 0
584 panel->chooseButton = WMCreateCommandButton(panel->win);
585 WMResizeWidget(panel->chooseButton, 110, 26);
586 WMMoveWidget(panel->chooseButton, 150, 240);
587 WMSetButtonText(panel->chooseButton, _("Choose File"));
588 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
589 #endif
590 WMRealizeWidget(panel->win);
591 WMMapSubwidgets(panel->win);
593 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
595 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
598 char *tmp;
600 tmp = wmalloc((instance ? strlen(instance) : 0)
601 + (class ? strlen(class) : 0) + 32);
603 if (tmp && (instance || class))
604 sprintf(tmp, "%s [%s.%s]", _("Icon Chooser"), instance, class);
605 else
606 strcpy(tmp, _("Icon Chooser"));
608 wwin = wManageInternalWindow(scr, parent, None, tmp,
609 (scr->scr_width - 450)/2,
610 (scr->scr_height - 280)/2, 450, 280);
611 free(tmp);
614 /* put icon paths in the list */
615 listIconPaths(panel->dirList);
617 WMMapWidget(panel->win);
619 wWindowMap(wwin);
621 while (!panel->done) {
622 XEvent event;
624 WMNextEvent(dpy, &event);
625 WMHandleEvent(&event);
628 if (panel->result) {
629 char *defaultPath, *wantedPath;
631 /* check if the file the user selected is not the one that
632 * would be loaded by default with the current search path */
633 *file = WMGetListSelectedItem(panel->iconList)->text;
634 if ((*file)[0]==0) {
635 free(*file);
636 *file = NULL;
637 } else {
638 defaultPath = FindImage(wPreferences.icon_path, *file);
639 wantedPath = WMGetTextFieldText(panel->fileField);
640 /* if the file is not the default, use full path */
641 if (strcmp(wantedPath, defaultPath)!=0) {
642 *file = wantedPath;
643 } else {
644 *file = wstrdup(*file);
645 free(wantedPath);
647 free(defaultPath);
649 } else {
650 *file = NULL;
653 WMReleaseFont(panel->normalfont);
655 WMUnmapWidget(panel->win);
657 WMDestroyWidget(panel->win);
659 wUnmanageWindow(wwin, False, False);
661 free(panel);
663 XDestroyWindow(dpy, parent);
665 return panel->result;
670 ***********************************************************************
671 * Info Panel
672 ***********************************************************************
676 typedef struct {
677 WScreen *scr;
679 WWindow *wwin;
681 WMWindow *win;
683 WMLabel *logoL;
684 WMLabel *name1L;
685 WMLabel *name2L;
687 WMLabel *versionL;
689 WMLabel *infoL;
691 WMLabel *copyrL;
693 #ifdef SILLYNESS
694 WMHandlerID timer;
695 int cycle;
696 RImage *icon;
697 RImage *pic;
698 WMPixmap *oldPix;
699 char *str;
700 int x;
701 #endif
702 } InfoPanel;
706 #define COPYRIGHT_TEXT \
707 "Copyright \xa9 1997~1999 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
708 "Copyright \xa9 1998,1999 Dan Pascu <dan@windowmaker.org>"
712 static InfoPanel *thePanel = NULL;
714 static void
715 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
717 #ifdef SILLYNESS
718 if (thePanel->timer) {
719 WMDeleteTimerHandler(thePanel->timer);
721 if (thePanel->oldPix) {
722 WMReleasePixmap(thePanel->oldPix);
724 if (thePanel->icon) {
725 RDestroyImage(thePanel->icon);
727 if (thePanel->pic) {
728 RDestroyImage(thePanel->pic);
730 #endif /* SILLYNESS */
731 WMUnmapWidget(thePanel);
733 wUnmanageWindow(thePanel->wwin, False, False);
735 WMDestroyWidget(thePanel->win);
737 free(thePanel);
739 thePanel = NULL;
743 WMPixmap*
744 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
746 WMPixmap *wpix = NULL;
747 Pixmap grad = None;
748 Pixmap mask = None;
749 RContext *rc = WMScreenRContext(scr);
750 XFontStruct *f = NULL;
751 int w, h;
752 GC gc = None;
754 f = XLoadQueryFont(dpy, font);
755 if (!f)
756 return NULL;
758 w = XTextWidth(f, text, strlen(text));
759 h = f->ascent+f->descent;
761 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
762 gc = XCreateGC(dpy, mask, 0, NULL);
763 XSetForeground(dpy, gc, 0);
764 XSetFont(dpy, gc, f->fid);
765 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
767 XSetForeground(dpy, gc, 1);
768 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
769 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
770 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
772 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
774 WMColor *color;
776 color = WMBlackColor(scr);
777 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
778 WMReleaseColor(color);
781 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
783 if (gc)
784 XFreeGC(dpy, gc);
785 XFreeFont(dpy, f);
787 return wpix;
790 #ifdef SILLYNESS
792 extern WMPixmap *DoXThing();
793 extern Bool InitXThing();
795 static void
796 logoPushCallback(void *data)
798 InfoPanel *panel = (InfoPanel*)data;
799 char buffer[512];
800 int i;
801 int len;
802 static int jingobeu[] = {
803 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
804 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
805 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
807 static int c = 0;
809 if (panel->x) {
810 XKeyboardControl kc;
812 if (panel->x > 0) {
813 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
814 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
815 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
816 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
817 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
818 XBell(dpy,50);XFlush(dpy);}else{c--;}}
819 if (!(panel->cycle % 4)) {
820 WMPixmap *p;
822 p = DoXThing(panel->wwin);
823 WMSetLabelImage(panel->logoL, p);
825 } else if (panel->cycle < 30) {
826 RImage *image;
827 WMPixmap *pix;
829 image = RCloneImage(panel->icon);
830 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
831 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
832 RDestroyImage(image);
833 WMSetLabelImage(panel->logoL, pix);
834 WMReleasePixmap(pix);
837 i = panel->cycle%200;
839 len = strlen(panel->str);
841 strncpy(buffer, panel->str, i<len ? i : len);
842 if (i >= len)
843 memset(&buffer[len], ' ', i-len);
845 strncpy(buffer, panel->str, i<len ? i : len);
846 if (i >= len)
847 memset(&buffer[len], ' ', i-len);
848 buffer[i]=0;
849 WMSetLabelText(panel->versionL, buffer);
851 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
852 panel->cycle++;
856 static void
857 handleLogoPush(XEvent *event, void *data)
859 InfoPanel *panel = (InfoPanel*)data;
860 static int broken = 0;
861 static int clicks = 0;
862 static char *pic_data[] = {
863 "45 45 57 1",
864 " c None",
865 ". c #000000",
866 "X c #383C00",
867 "o c #515500",
868 "O c #616100",
869 "+ c #616900",
870 "@ c #696D00",
871 "# c #697100",
872 "$ c #495100",
873 "% c #202800",
874 "& c #969600",
875 "* c #CFCF00",
876 "= c #D7DB00",
877 "- c #D7D700",
878 "; c #C7CB00",
879 ": c #A6AA00",
880 "> c #494900",
881 ", c #8E8E00",
882 "< c #DFE700",
883 "1 c #F7FF00",
884 "2 c #FFFF00",
885 "3 c #E7EB00",
886 "4 c #B6B600",
887 "5 c #595900",
888 "6 c #717500",
889 "7 c #AEB200",
890 "8 c #CFD300",
891 "9 c #E7EF00",
892 "0 c #EFF300",
893 "q c #9EA200",
894 "w c #F7FB00",
895 "e c #F7F700",
896 "r c #BEBE00",
897 "t c #8E9200",
898 "y c #EFF700",
899 "u c #969A00",
900 "i c #414500",
901 "p c #595D00",
902 "a c #E7E700",
903 "s c #C7C700",
904 "d c #797D00",
905 "f c #BEC300",
906 "g c #DFE300",
907 "h c #868600",
908 "j c #EFEF00",
909 "k c #9E9E00",
910 "l c #616500",
911 "z c #DFDF00",
912 "x c #868A00",
913 "c c #969200",
914 "v c #B6BA00",
915 "b c #A6A600",
916 "n c #8E8A00",
917 "m c #717100",
918 "M c #AEAE00",
919 "N c #AEAA00",
920 "B c #868200",
921 " ............... ",
922 " ....XoO+@##+O$%.... ",
923 " ...%X&*========-;;:o... ",
924 " ...>.>,<122222222222134@... ",
925 " ..>5678912222222222222220q%.. ",
926 " ..$.&-w2222222222222222222er>.. ",
927 " ..O.t31222222222222222222222y4>.. ",
928 " ...O5u3222222222222222222222222yri... ",
929 " ..>p&a22222222222222222222222222wso.. ",
930 " ..ids91222222222222222222222222222wfi.. ",
931 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
932 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
933 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
934 " ..o7y22222222v...r222222223hX.i82222221si.. ",
935 "..io*222222222&...u22222222yt..%*22222220:%. ",
936 "..>k02222222227...f222222222v..X=222222229t. ",
937 "..dz12222222220ui:y2222222223d%qw222222221g. ",
938 ".%vw222222222221y2222222222219*y2222222222wd.",
939 ".X;2222222222222222222222222222222222222222b.",
940 ".i*2222222222222222222222222222222222222222v.",
941 ".i*2222222222222222222222222222222222222222;.",
942 ".i*22222222222222222222222222222222222222228.",
943 ".>*2222222222222222222222222222222222222222=.",
944 ".i*22222222222222222222222222222222222222228.",
945 ".i*2222222222222222222222222222222222222222;.",
946 ".X*222222222222222222222222222222we12222222r.",
947 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
948 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
949 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
950 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
951 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
952 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
953 " ...:e2222218mdz22222222222222a&$vw222220@...",
954 " ...O-122222y:.u02222222222229q$uj222221r... ",
955 " ..%&a1222223&573w2222222219NOxz122221z>... ",
956 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
957 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
958 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
959 " ..Xb9122222109g-****;<y22221zn%... ",
960 " ..X&801222222222222222222w-h.... ",
961 " ...o:=022222222222222221=lX... ",
962 " ..X@:;3w2222222222210fO... ",
963 " ...XX&v8<30000003-N@... ",
964 " .....XmnbN:q&Bo.... ",
965 " ............ "};
966 static char *msgs[] = {
967 "Sloppy focus is a *?#@",
968 "Repent! Sloppy focus users will burn in hell!!!",
969 "Have a nice day!"
973 clicks++;
974 if (!panel->timer && !broken && clicks > 0) {
975 char *file;
976 char *path;
978 panel->x = 0;
979 clicks = 0;
980 if (!panel->icon) {
981 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
982 if (!file) {
983 broken = 1;
984 return;
987 path = FindImage(wPreferences.icon_path, file);
988 if (!path) {
989 broken = 1;
990 return;
993 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
994 free(path);
995 if (!panel->icon) {
996 broken = 1;
997 return;
1000 if (!panel->pic) {
1001 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1002 if (!panel->pic || panel->icon->width!=panel->pic->width
1003 || panel->icon->height!=panel->pic->height) {
1004 broken = 1;
1005 RDestroyImage(panel->icon);
1006 panel->icon = NULL;
1007 if (panel->pic) {
1008 RDestroyImage(panel->pic);
1009 panel->pic = NULL;
1011 return;
1015 RColor color;
1016 color.red = 0xae;
1017 color.green = 0xaa;
1018 color.blue = 0xae;
1019 color.alpha = 255;
1020 RCombineImageWithColor(panel->icon, &color);
1021 RCombineImageWithColor(panel->pic, &color);
1025 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1027 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1028 panel->cycle = 0;
1029 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1030 } else if (panel->timer) {
1031 char version[20];
1033 panel->x = 0;
1034 clicks = 0;
1035 WMSetLabelImage(panel->logoL, panel->oldPix);
1036 WMReleasePixmap(panel->oldPix);
1037 panel->oldPix = NULL;
1039 WMDeleteTimerHandler(panel->timer);
1040 panel->timer = NULL;
1042 sprintf(version, "Version %s", VERSION);
1043 WMSetLabelText(panel->versionL, version);
1047 XEvent ev;
1048 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1049 ButtonPress, &ev));
1052 #endif /* SILLYNESS */
1055 void
1056 wShowInfoPanel(WScreen *scr)
1058 InfoPanel *panel;
1059 WMPixmap *logo;
1060 WMSize size;
1061 WMFont *font;
1062 char version[32];
1063 char buffer[512];
1064 Window parent;
1065 WWindow *wwin;
1066 RColor color1, color2;
1067 char **strl;
1068 int i;
1069 char *visuals[] = {
1070 "StaticGray",
1071 "GrayScale",
1072 "StaticColor",
1073 "PseudoColor",
1074 "TrueColor",
1075 "DirectColor"
1079 if (thePanel) {
1080 if (thePanel->scr == scr) {
1081 wRaiseFrame(thePanel->wwin->frame->core);
1082 wSetFocusTo(scr, thePanel->wwin);
1084 return;
1087 panel = wmalloc(sizeof(InfoPanel));
1088 memset(panel, 0, sizeof(InfoPanel));
1090 panel->scr = scr;
1092 panel->win = WMCreateWindow(scr->wmscreen, "info");
1093 WMResizeWidget(panel->win, 382, 230);
1095 logo = WMGetApplicationIconImage(scr->wmscreen);
1096 if (logo) {
1097 size = WMGetPixmapSize(logo);
1098 panel->logoL = WMCreateLabel(panel->win);
1099 WMResizeWidget(panel->logoL, 64, 64);
1100 WMMoveWidget(panel->logoL, 30, 20);
1101 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1102 WMSetLabelImage(panel->logoL, logo);
1103 #ifdef SILLYNESS
1104 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1105 handleLogoPush, panel);
1106 #endif
1109 panel->name1L = WMCreateLabel(panel->win);
1110 WMResizeWidget(panel->name1L, 240, 30);
1111 WMMoveWidget(panel->name1L, 100, 30);
1112 color1.red = 0;
1113 color1.green = 0;
1114 color1.blue = 0;
1115 color2.red = 0x50;
1116 color2.green = 0x50;
1117 color2.blue = 0x70;
1118 logo = renderText(scr->wmscreen, "GNU Window Maker",
1119 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1120 if (logo) {
1121 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1122 WMSetLabelImage(panel->name1L, logo);
1123 WMReleasePixmap(logo);
1124 } else {
1125 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1126 if (font) {
1127 WMSetLabelFont(panel->name1L, font);
1128 WMReleaseFont(font);
1130 WMSetLabelTextAlignment(panel->name1L, WACenter);
1131 WMSetLabelText(panel->name1L, "GNU Window Maker");
1134 panel->name2L = WMCreateLabel(panel->win);
1135 WMResizeWidget(panel->name2L, 240, 24);
1136 WMMoveWidget(panel->name2L, 100, 60);
1137 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1138 if (font) {
1139 WMSetLabelFont(panel->name2L, font);
1140 WMReleaseFont(font);
1141 font = NULL;
1143 WMSetLabelTextAlignment(panel->name2L, WACenter);
1144 WMSetLabelText(panel->name2L, "Window Manager for X");
1147 sprintf(version, "Version %s", VERSION);
1148 panel->versionL = WMCreateLabel(panel->win);
1149 WMResizeWidget(panel->versionL, 310, 16);
1150 WMMoveWidget(panel->versionL, 30, 95);
1151 WMSetLabelTextAlignment(panel->versionL, WARight);
1152 WMSetLabelText(panel->versionL, version);
1153 WMSetLabelWraps(panel->versionL, False);
1155 panel->copyrL = WMCreateLabel(panel->win);
1156 WMResizeWidget(panel->copyrL, 340, 40);
1157 WMMoveWidget(panel->copyrL, 15, 185);
1158 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1159 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1160 /* we want the (c) character in the helvetica font */
1161 font = WMCreateNormalFont(scr->wmscreen, HELVETICA10_FONT);
1162 if (font) {
1163 WMSetLabelFont(panel->copyrL, font);
1166 switch (scr->w_depth) {
1167 case 15:
1168 strcpy(version, "32 thousand");
1169 break;
1170 case 16:
1171 strcpy(version, "64 thousand");
1172 break;
1173 case 24:
1174 case 32:
1175 strcpy(version, "16 million");
1176 break;
1177 default:
1178 sprintf(version, "%d", 1<<scr->w_depth);
1179 break;
1182 sprintf(buffer, "Using visual 0x%x: %s %ibpp (%s colors)\n",
1183 (unsigned)scr->w_visual->visualid,
1184 visuals[scr->w_visual->class], scr->w_depth, version);
1186 strcat(buffer, "Supported image formats: ");
1187 strl = RSupportedFileFormats();
1188 for (i=0; strl[i]!=NULL; i++) {
1189 strcat(buffer, strl[i]);
1190 strcat(buffer, " ");
1193 strcat(buffer, "\nAdditional Support For: ");
1195 char *list[8];
1196 char buf[80];
1197 int j = 0;
1199 #ifdef MWM_HINTS
1200 list[j++] = "MWM";
1201 #endif
1202 #ifdef KWM_HINTS
1203 list[j++] = "KDE";
1204 #endif
1205 #ifdef GNOME_STUFF
1206 list[j++] = "GNOME";
1207 #endif
1208 #ifdef OLWM_HINTS
1209 list[j++] = "OLWM";
1210 #endif
1211 #ifdef WMSOUND
1212 list[j++] = "Sound";
1213 #endif
1215 buf[0] = 0;
1216 for (i = 0; i < j; i++) {
1217 if (i > 0) {
1218 if (i == j - 1)
1219 strcat(buf, " and ");
1220 else
1221 strcat(buf, ", ");
1223 strcat(buf, list[i]);
1225 strcat(buffer, buf);
1229 panel->infoL = WMCreateLabel(panel->win);
1230 WMResizeWidget(panel->infoL, 350, 75);
1231 WMMoveWidget(panel->infoL, 15, 115);
1232 WMSetLabelText(panel->infoL, buffer);
1233 if (font) {
1234 WMSetLabelFont(panel->infoL, font);
1235 WMReleaseFont(font);
1239 WMRealizeWidget(panel->win);
1240 WMMapSubwidgets(panel->win);
1242 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1244 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1246 WMMapWidget(panel->win);
1248 wwin = wManageInternalWindow(scr, parent, None, "Info",
1249 (scr->scr_width - 382)/2,
1250 (scr->scr_height - 230)/2, 382, 230);
1252 WSETUFLAG(wwin, no_closable, 0);
1253 WSETUFLAG(wwin, no_close_button, 0);
1254 #ifdef XKB_BUTTON_HINT
1255 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1256 #endif
1257 wWindowUpdateButtonImages(wwin);
1258 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1259 wwin->frame->on_click_right = destroyInfoPanel;
1261 wWindowMap(wwin);
1263 panel->wwin = wwin;
1265 thePanel = panel;
1266 #ifdef SILLYNESS
1267 if (InitXThing(panel->scr)) {
1268 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1269 panel->cycle = 0;
1270 panel->x = 1;
1271 panel->str = "Merry Christmas!";
1272 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1274 #endif
1279 ***********************************************************************
1280 * Legal Panel
1281 ***********************************************************************
1284 typedef struct {
1285 WScreen *scr;
1287 WWindow *wwin;
1289 WMWindow *win;
1291 WMLabel *licenseL;
1292 } LegalPanel;
1296 #define LICENSE_TEXT \
1297 " Window Maker is free software; you can redistribute it and/or modify "\
1298 "it under the terms of the GNU General Public License as published "\
1299 "by the Free Software Foundation; either version 2 of the License, "\
1300 "or (at your option) any later version.\n\n\n"\
1301 " Window Maker is distributed in the hope that it will be useful, but "\
1302 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
1303 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
1304 "General Public License for more details.\n\n\n"\
1305 " You should have received a copy of the GNU General Public License "\
1306 "along with this program; if not, write to the Free Software "\
1307 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
1308 "02111-1307, USA."
1311 static LegalPanel *legalPanel = NULL;
1313 static void
1314 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1316 WMUnmapWidget(legalPanel->win);
1318 WMDestroyWidget(legalPanel->win);
1320 wUnmanageWindow(legalPanel->wwin, False, False);
1322 free(legalPanel);
1324 legalPanel = NULL;
1328 void
1329 wShowLegalPanel(WScreen *scr)
1331 LegalPanel *panel;
1332 Window parent;
1333 WWindow *wwin;
1335 if (legalPanel) {
1336 if (legalPanel->scr == scr) {
1337 wRaiseFrame(legalPanel->wwin->frame->core);
1338 wSetFocusTo(scr, legalPanel->wwin);
1340 return;
1343 panel = wmalloc(sizeof(LegalPanel));
1345 panel->scr = scr;
1347 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1348 WMResizeWidget(panel->win, 420, 250);
1351 panel->licenseL = WMCreateLabel(panel->win);
1352 WMResizeWidget(panel->licenseL, 400, 230);
1353 WMMoveWidget(panel->licenseL, 10, 10);
1354 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1355 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
1356 WMSetLabelRelief(panel->licenseL, WRGroove);
1358 WMRealizeWidget(panel->win);
1359 WMMapSubwidgets(panel->win);
1361 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1363 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1365 wwin = wManageInternalWindow(scr, parent, None, "Legal",
1366 (scr->scr_width - 420)/2,
1367 (scr->scr_height - 250)/2, 420, 250);
1369 WSETUFLAG(wwin, no_closable, 0);
1370 WSETUFLAG(wwin, no_close_button, 0);
1371 wWindowUpdateButtonImages(wwin);
1372 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1373 #ifdef XKB_BUTTON_HINT
1374 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1375 #endif
1376 wwin->frame->on_click_right = destroyLegalPanel;
1378 panel->wwin = wwin;
1380 WMMapWidget(panel->win);
1382 wWindowMap(wwin);
1384 legalPanel = panel;
1389 ***********************************************************************
1390 * Crashing Dialog Panel
1391 ***********************************************************************
1394 extern WDDomain *WDWindowAttributes;
1397 typedef struct _CrashPanel {
1398 WMWindow *win; /* main window */
1400 WMLabel *iconL; /* application icon */
1401 WMLabel *nameL; /* title of panel */
1403 WMFrame *sepF; /* separator frame */
1405 WMLabel *noteL; /* Title of note */
1406 WMLabel *note2L; /* body of note with what happened */
1408 WMFrame *whatF; /* "what to do next" frame */
1409 WMPopUpButton *whatP; /* action selection popup button */
1411 WMButton *okB; /* ok button */
1413 Bool done; /* if finished with this dialog */
1414 int action; /* what to do after */
1416 KeyCode retKey;
1418 } CrashPanel;
1421 static void
1422 handleKeyPress(XEvent *event, void *clientData)
1424 CrashPanel *panel = (CrashPanel*)clientData;
1426 if (event->xkey.keycode == panel->retKey) {
1427 WMPerformButtonClick(panel->okB);
1432 static void
1433 okButtonCallback(void *self, void *clientData)
1435 CrashPanel *panel = (CrashPanel*)clientData;
1437 panel->done = True;
1441 static void
1442 setCrashAction(void *self, void *clientData)
1444 WMPopUpButton *pop = (WMPopUpButton*)self;
1445 CrashPanel *panel = (CrashPanel*)clientData;
1447 panel->action = WMGetPopUpButtonSelectedItem(pop);
1451 static WMPixmap*
1452 getWindowMakerIconImage(WMScreen *scr)
1454 proplist_t dict, key, option, value=NULL;
1455 WMPixmap *pix=NULL;
1456 char *path;
1458 PLSetStringCmpHook(NULL);
1460 key = PLMakeString("Logo.WMPanel");
1461 option = PLMakeString("Icon");
1463 dict = PLGetDictionaryEntry(WDWindowAttributes->dictionary, key);
1465 if (dict) {
1466 value = PLGetDictionaryEntry(dict, option);
1469 PLRelease(key);
1470 PLRelease(option);
1472 PLSetStringCmpHook(StringCompareHook);
1474 if (value && PLIsString(value)) {
1475 path = FindImage(wPreferences.icon_path, PLGetString(value));
1477 if (path) {
1478 RImage *image;
1480 image = RLoadImage(WMScreenRContext(scr), path, 0);
1481 if (image) {
1482 pix = WMCreatePixmapFromRImage(scr, image, 0);
1483 RDestroyImage(image);
1485 free(path);
1489 return pix;
1493 #define PWIDTH 295
1494 #define PHEIGHT 345
1498 wShowCrashingDialogPanel(int whatSig)
1500 CrashPanel *panel;
1501 WMScreen *scr;
1502 WMFont *font;
1503 WMPixmap *logo;
1504 int screen_no, scr_width, scr_height;
1505 int action;
1506 char buf[256];
1508 panel = wmalloc(sizeof(CrashPanel));
1509 memset(panel, 0, sizeof(CrashPanel));
1511 screen_no = DefaultScreen(dpy);
1512 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1513 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1515 scr = WMCreateScreen(dpy, screen_no);
1516 if (!scr) {
1517 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1518 return WMAbort;
1521 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1523 panel->win = WMCreateWindow(scr, "crashingDialog");
1524 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1525 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1527 logo = getWindowMakerIconImage(scr);
1528 if (logo) {
1529 panel->iconL = WMCreateLabel(panel->win);
1530 WMResizeWidget(panel->iconL, 64, 64);
1531 WMMoveWidget(panel->iconL, 10, 10);
1532 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1533 WMSetLabelImage(panel->iconL, logo);
1536 panel->nameL = WMCreateLabel(panel->win);
1537 WMResizeWidget(panel->nameL, 190, 18);
1538 WMMoveWidget(panel->nameL, 80, 35);
1539 WMSetLabelTextAlignment(panel->nameL, WALeft);
1540 font = WMBoldSystemFontOfSize(scr, 18);
1541 WMSetLabelFont(panel->nameL, font);
1542 WMReleaseFont(font);
1543 WMSetLabelText(panel->nameL, _("Fatal error"));
1545 panel->sepF = WMCreateFrame(panel->win);
1546 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1547 WMMoveWidget(panel->sepF, -2, 80);
1549 panel->noteL = WMCreateLabel(panel->win);
1550 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1551 WMMoveWidget(panel->noteL, 10, 90);
1552 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1553 #ifdef SYS_SIGLIST_DECLARED
1554 sprintf(buf, _("Window Maker received signal %i\n(%s)."),
1555 whatSig, sys_siglist[whatSig]);
1556 #else
1557 sprintf(buf, _("Window Maker received signal %i."), whatSig);
1558 #endif
1559 WMSetLabelText(panel->noteL, buf);
1561 panel->note2L = WMCreateLabel(panel->win);
1562 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1563 WMMoveWidget(panel->note2L, 10, 130);
1564 WMSetLabelTextAlignment(panel->note2L, WALeft);
1565 WMSetLabelText(panel->note2L,
1566 _(" This fatal error occured probably due to a bug."
1567 " Please fill the included BUGFORM and "
1568 "report it to bugs@windowmaker.org."));
1571 panel->whatF = WMCreateFrame(panel->win);
1572 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1573 WMMoveWidget(panel->whatF, 10, 240);
1574 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1576 panel->whatP = WMCreatePopUpButton(panel->whatF);
1577 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1578 WMMoveWidget(panel->whatP, 35, 20);
1579 WMSetPopUpButtonPullsDown(panel->whatP, False);
1580 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1581 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1582 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1583 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1584 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1585 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1586 panel->action = WMRestart;
1588 WMMapSubwidgets(panel->whatF);
1590 panel->okB = WMCreateCommandButton(panel->win);
1591 WMResizeWidget(panel->okB, 80, 26);
1592 WMMoveWidget(panel->okB, 205, 309);
1593 WMSetButtonText(panel->okB, _("OK"));
1594 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1595 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1596 WMSetButtonImagePosition(panel->okB, WIPRight);
1597 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1599 panel->done = 0;
1601 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1602 handleKeyPress, panel);
1604 WMRealizeWidget(panel->win);
1605 WMMapSubwidgets(panel->win);
1607 WMMapWidget(panel->win);
1609 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1611 while (!panel->done) {
1612 XEvent event;
1614 WMNextEvent(dpy, &event);
1615 WMHandleEvent(&event);
1618 action = panel->action;
1620 WMUnmapWidget(panel->win);
1621 WMDestroyWidget(panel->win);
1622 free(panel);
1624 return action;
1630 /*****************************************************************************
1631 * About GNUstep Panel
1632 *****************************************************************************/
1635 static void
1636 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1637 unsigned long blackPixel, unsigned long whitePixel)
1639 GC gc;
1640 XGCValues gcv;
1641 XRectangle rects[3];
1643 gcv.foreground = blackPixel;
1644 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1646 XFillArc(dpy, d, gc, width/45, height/45,
1647 width - 2*width/45, height - 2*height/45, 0, 360*64);
1649 rects[0].x = 0;
1650 rects[0].y = 37*height/45;
1651 rects[0].width = width/3;
1652 rects[0].height = height - rects[0].y;
1654 rects[1].x = rects[0].width;
1655 rects[1].y = height/2;
1656 rects[1].width = width - 2*width/3;
1657 rects[1].height = height - rects[1].y;
1659 rects[2].x = 2*width/3;
1660 rects[2].y = height - 37*height/45;
1661 rects[2].width = width/3;
1662 rects[2].height = height - rects[2].y;
1664 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1665 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1667 XSetForeground(dpy, gc, whitePixel);
1668 XFillArc(dpy, d, gc, width/45, height/45,
1669 width - 2*width/45, height - 2*height/45, 0, 360*64);
1671 XFreeGC(dpy, gc);
1676 #define GNUSTEP_TEXT \
1677 "Window Maker is part of the GNUstep project.\n"\
1678 "The GNUstep project aims to create a free\n"\
1679 "implementation of the OpenStep(tm) specification\n"\
1680 "which is a object-oriented framework for\n"\
1681 "creating advanced graphical, multi-platform\n"\
1682 "applications. Aditionally, a development and\n"\
1683 "user desktop enviroment will be created on top\n"\
1684 "of the framework. For more information about\n"\
1685 "GNUstep, please visit: www.gnustep.org"
1688 typedef struct {
1689 WScreen *scr;
1691 WWindow *wwin;
1693 WMWindow *win;
1695 WMLabel *gstepL;
1696 WMLabel *textL;
1697 } GNUstepPanel;
1700 static GNUstepPanel *gnustepPanel = NULL;
1702 static void
1703 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1705 WMUnmapWidget(gnustepPanel->win);
1707 WMDestroyWidget(gnustepPanel->win);
1709 wUnmanageWindow(gnustepPanel->wwin, False, False);
1711 free(gnustepPanel);
1713 gnustepPanel = NULL;
1717 void
1718 wShowGNUstepPanel(WScreen *scr)
1720 GNUstepPanel *panel;
1721 Window parent;
1722 WWindow *wwin;
1723 WMPixmap *pixmap;
1724 WMColor *color;
1726 if (gnustepPanel) {
1727 if (gnustepPanel->scr == scr) {
1728 wRaiseFrame(gnustepPanel->wwin->frame->core);
1729 wSetFocusTo(scr, gnustepPanel->wwin);
1731 return;
1734 panel = wmalloc(sizeof(GNUstepPanel));
1736 panel->scr = scr;
1738 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1739 WMResizeWidget(panel->win, 325, 200);
1741 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1742 WMScreenDepth(scr->wmscreen), True);
1744 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1746 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1747 WMColorPixel(color), scr->white_pixel);
1749 WMReleaseColor(color);
1751 XSetForeground(dpy, scr->mono_gc, 0);
1752 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1753 130, 130);
1754 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1756 panel->gstepL = WMCreateLabel(panel->win);
1757 WMResizeWidget(panel->gstepL, 285, 64);
1758 WMMoveWidget(panel->gstepL, 20, 0);
1759 WMSetLabelTextAlignment(panel->gstepL, WARight);
1760 WMSetLabelText(panel->gstepL, "GNUstep");
1762 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1764 WMSetLabelFont(panel->gstepL, font);
1765 WMReleaseFont(font);
1768 panel->textL = WMCreateLabel(panel->win);
1769 WMResizeWidget(panel->textL, 275, 130);
1770 WMMoveWidget(panel->textL, 30, 50);
1771 WMSetLabelTextAlignment(panel->textL, WARight);
1772 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1773 WMSetLabelText(panel->textL, GNUSTEP_TEXT);
1774 WMSetLabelImage(panel->textL, pixmap);
1776 WMReleasePixmap(pixmap);
1778 WMRealizeWidget(panel->win);
1779 WMMapSubwidgets(panel->win);
1781 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1783 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1785 wwin = wManageInternalWindow(scr, parent, None, "About GNUstep",
1786 (scr->scr_width - 325)/2,
1787 (scr->scr_height - 200)/2, 325, 200);
1789 WSETUFLAG(wwin, no_closable, 0);
1790 WSETUFLAG(wwin, no_close_button, 0);
1791 wWindowUpdateButtonImages(wwin);
1792 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1793 #ifdef XKB_BUTTON_HINT
1794 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1795 #endif
1796 wwin->frame->on_click_right = destroyGNUstepPanel;
1798 panel->wwin = wwin;
1800 WMMapWidget(panel->win);
1802 wWindowMap(wwin);
1804 gnustepPanel = panel;