fixed some stuffs
[wmaker-crm.git] / src / dialog.c
blob80ca55dc38265126c19e8c3634638c2c54ddb09e
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 #ifdef HAVE_MALLOC_H
40 #include <malloc.h>
41 #endif
43 #include <signal.h>
44 #ifdef __FreeBSD__
45 #include <sys/signal.h>
46 #endif
49 #ifndef PATH_MAX
50 #define PATH_MAX DEFAULT_PATH_MAX
51 #endif
53 #include "WindowMaker.h"
54 #include "GNUstep.h"
55 #include "screen.h"
56 #include "dialog.h"
57 #include "funcs.h"
58 #include "stacking.h"
59 #include "framewin.h"
60 #include "window.h"
61 #include "actions.h"
62 #include "defaults.h"
65 extern WPreferences wPreferences;
69 int
70 wMessageDialog(WScreen *scr, char *title, char *message,
71 char *defBtn, char *altBtn, char *othBtn)
73 WMAlertPanel *panel;
74 Window parent;
75 WWindow *wwin;
76 int result;
78 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
79 defBtn, altBtn, othBtn);
81 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
83 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
85 wwin = wManageInternalWindow(scr, parent, None, NULL,
86 (scr->scr_width - 400)/2,
87 (scr->scr_height - 180)/2, 400, 180);
88 wwin->client_leader = WMWidgetXID(panel->win);
90 WMMapWidget(panel->win);
92 wWindowMap(wwin);
94 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
96 result = panel->result;
98 WMUnmapWidget(panel->win);
100 wUnmanageWindow(wwin, False, False);
102 WMDestroyAlertPanel(panel);
104 XDestroyWindow(dpy, parent);
106 return result;
112 wInputDialog(WScreen *scr, char *title, char *message, char **text)
114 WWindow *wwin;
115 Window parent;
116 WMInputPanel *panel;
117 char *result;
120 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
121 _("OK"), _("Cancel"));
124 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
125 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
127 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
129 wwin = wManageInternalWindow(scr, parent, None, NULL,
130 (scr->scr_width - 320)/2,
131 (scr->scr_height - 160)/2, 320, 160);
133 wwin->client_leader = WMWidgetXID(panel->win);
135 WMMapWidget(panel->win);
137 wWindowMap(wwin);
139 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
141 if (panel->result == WAPRDefault)
142 result = WMGetTextFieldText(panel->text);
143 else
144 result = NULL;
146 wUnmanageWindow(wwin, False, False);
148 WMDestroyInputPanel(panel);
150 XDestroyWindow(dpy, parent);
152 if (result==NULL)
153 return False;
154 else {
155 if (*text)
156 wfree(*text);
157 *text = result;
159 return True;
165 *****************************************************************
166 * Icon Selection Panel
167 *****************************************************************
170 typedef struct IconPanel {
172 WScreen *scr;
174 WMWindow *win;
176 WMLabel *dirLabel;
177 WMLabel *iconLabel;
179 WMList *dirList;
180 WMList *iconList;
181 WMFont *normalfont;
183 WMButton *previewButton;
185 WMLabel *iconView;
187 WMLabel *fileLabel;
188 WMTextField *fileField;
190 WMButton *okButton;
191 WMButton *cancelButton;
192 #if 0
193 WMButton *chooseButton;
194 #endif
195 short done;
196 short result;
197 short preview;
198 } IconPanel;
202 static void
203 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
205 struct dirent *dentry;
206 DIR *dir;
207 char pbuf[PATH_MAX+16];
208 char *apath;
209 IconPanel *panel = WMGetHangedData(lPtr);
211 panel->preview = False;
213 apath = wexpandpath(path);
214 dir = opendir(apath);
216 if (!dir) {
217 char *msg;
218 char *tmp;
219 tmp = _("Could not open directory ");
220 msg = wmalloc(strlen(tmp)+strlen(path)+6);
221 strcpy(msg, tmp);
222 strcat(msg, path);
224 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
225 wfree(msg);
226 wfree(apath);
227 return;
230 /* list contents in the column */
231 while ((dentry = readdir(dir))) {
232 struct stat statb;
234 if (strcmp(dentry->d_name, ".")==0 ||
235 strcmp(dentry->d_name, "..")==0)
236 continue;
238 strcpy(pbuf, apath);
239 strcat(pbuf, "/");
240 strcat(pbuf, dentry->d_name);
242 if (stat(pbuf, &statb)<0)
243 continue;
245 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
246 && statb.st_mode & (S_IFREG|S_IFLNK)) {
247 WMAddListItem(lPtr, dentry->d_name);
250 WMSortListItems(lPtr);
252 closedir(dir);
253 wfree(apath);
254 panel->preview = True;
259 static void
260 setViewedImage(IconPanel *panel, char *file)
262 WMPixmap *pixmap;
263 RColor color;
265 color.red = 0xae;
266 color.green = 0xaa;
267 color.blue = 0xae;
268 color.alpha = 0;
269 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
270 file, &color);
271 if (!pixmap) {
272 WMSetButtonEnabled(panel->okButton, False);
274 WMSetLabelText(panel->iconView, _("Could not load image file "));
276 WMSetLabelImage(panel->iconView, NULL);
277 } else {
278 WMSetButtonEnabled(panel->okButton, True);
280 WMSetLabelText(panel->iconView, NULL);
281 WMSetLabelImage(panel->iconView, pixmap);
282 WMReleasePixmap(pixmap);
287 static void
288 listCallback(void *self, void *data)
290 WMList *lPtr = (WMList*)self;
291 IconPanel *panel = (IconPanel*)data;
292 char *path;
294 if (lPtr==panel->dirList) {
295 path = WMGetListSelectedItem(lPtr)->text;
297 WMSetTextFieldText(panel->fileField, path);
299 WMSetLabelImage(panel->iconView, NULL);
301 WMSetButtonEnabled(panel->okButton, False);
303 WMClearList(panel->iconList);
304 listPixmaps(panel->scr, panel->iconList, path);
305 } else {
306 char *tmp, *iconFile;
308 path = WMGetListSelectedItem(panel->dirList)->text;
309 tmp = wexpandpath(path);
311 iconFile = WMGetListSelectedItem(panel->iconList)->text;
313 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
314 strcpy(path, tmp);
315 strcat(path, "/");
316 strcat(path, iconFile);
317 wfree(tmp);
318 WMSetTextFieldText(panel->fileField, path);
319 setViewedImage(panel, path);
320 wfree(path);
325 static void
326 listIconPaths(WMList *lPtr)
328 char *paths;
329 char *path;
331 paths = wstrdup(wPreferences.icon_path);
333 path = strtok(paths, ":");
335 do {
336 char *tmp;
338 tmp = wexpandpath(path);
339 /* do not sort, because the order implies the order of
340 * directories searched */
341 if (access(tmp, X_OK)==0)
342 WMAddListItem(lPtr, path);
343 wfree(tmp);
344 } while ((path=strtok(NULL, ":"))!=NULL);
346 wfree(paths);
350 void
351 drawIconProc(WMList *lPtr, int index, Drawable d, char *text,
352 int state, WMRect *rect)
354 IconPanel *panel = WMGetHangedData(lPtr);
355 GC gc = panel->scr->draw_gc;
356 GC copygc = panel->scr->copy_gc;
357 char *buffer, *dirfile;
358 WMPixmap *pixmap;
359 WMColor *blackcolor;
360 WMColor *whitecolor;
361 WMSize size;
362 WMScreen *wmscr=WMWidgetScreen(panel->win);
363 int width;
365 if(!panel->preview) return;
367 width = rect->size.width;
369 blackcolor = WMBlackColor(wmscr);
370 whitecolor = WMWhiteColor(wmscr);
372 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
373 buffer = wmalloc(strlen(dirfile)+strlen(text)+4);
374 sprintf(buffer, "%s/%s", dirfile, text);
375 wfree(dirfile);
377 pixmap = WMCreatePixmapFromFile(WMWidgetScreen(panel->win), buffer);
378 wfree(buffer);
379 if (!pixmap) {
380 WMRemoveListItem(lPtr, index);
381 return;
384 XClearArea(dpy, d, rect->pos.x, rect->pos.y, width, rect->size.height,
385 False);
386 XSetClipMask(dpy, gc, None);
388 XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,
389 rect->pos.y +5, width - 10, 54);
391 XDrawLine(dpy, d, WMColorGC(whitecolor), rect->pos.x,
392 rect->pos.y+rect->size.height-1, rect->pos.x+width,
393 rect->pos.y+rect->size.height-1);
396 if (state&WLDSSelected) {
397 XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x,
398 rect->pos.y, width, rect->size.height);
401 size = WMGetPixmapSize(pixmap);
403 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
404 XSetClipOrigin(dpy, copygc, rect->pos.x + (width-size.width)/2,
405 rect->pos.y+2);
406 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
407 size.width>100?100:size.width, size.height>64?64:size.height,
408 rect->pos.x + (width-size.width)/2, rect->pos.y+2);
411 int i,j;
412 int fheight = WMFontHeight(panel->normalfont);
413 int tlen = strlen(text);
414 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
415 int ofx, ofy;
417 ofx = rect->pos.x + (width - twidth)/2;
418 ofy = rect->pos.y + 64 - fheight;
420 for(i=-1;i<2;i++)
421 for(j=-1;j<2;j++)
422 WMDrawString(wmscr, d, WMColorGC(whitecolor),
423 panel->normalfont, ofx+i, ofy+j,
424 text, tlen);
426 WMDrawString(wmscr, d, WMColorGC(blackcolor), panel->normalfont,
427 ofx, ofy, text, tlen);
430 WMReleasePixmap(pixmap);
431 /* I hope it is better to do not use cache / on my box it is fast nuff */
432 XFlush(dpy);
434 WMReleaseColor(blackcolor);
435 WMReleaseColor(whitecolor);
439 static void
440 buttonCallback(void *self, void *clientData)
442 WMButton *bPtr = (WMButton*)self;
443 IconPanel *panel = (IconPanel*)clientData;
446 if (bPtr==panel->okButton) {
447 panel->done = True;
448 panel->result = True;
449 } else if (bPtr==panel->cancelButton) {
450 panel->done = True;
451 panel->result = False;
452 } else if (bPtr==panel->previewButton) {
453 /**** Previewer ****/
454 WMSetButtonEnabled(bPtr, False);
455 WMSetListUserDrawItemHeight(panel->iconList, 68);
456 WMSetListUserDrawProc(panel->iconList, drawIconProc);
457 WMRedisplayWidget(panel->iconList);
458 /* for draw proc to access screen/gc */
459 /*** end preview ***/
461 #if 0
462 else if (bPtr==panel->chooseButton) {
463 WMOpenPanel *op;
465 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
467 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
468 char *path;
469 path = WMGetFilePanelFile(op);
470 WMSetTextFieldText(panel->fileField, path);
471 setViewedImage(panel, path);
472 wfree(path);
474 WMDestroyFilePanel(op);
476 #endif
480 Bool
481 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
483 WWindow *wwin;
484 Window parent;
485 IconPanel *panel;
486 WMColor *color;
487 WMFont *boldFont;
489 panel = wmalloc(sizeof(IconPanel));
490 memset(panel, 0, sizeof(IconPanel));
492 panel->scr = scr;
494 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
495 WMResizeWidget(panel->win, 450, 280);
497 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
498 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
500 panel->dirLabel = WMCreateLabel(panel->win);
501 WMResizeWidget(panel->dirLabel, 200, 20);
502 WMMoveWidget(panel->dirLabel, 10, 7);
503 WMSetLabelText(panel->dirLabel, _("Directories"));
504 WMSetLabelFont(panel->dirLabel, boldFont);
505 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
507 WMSetLabelRelief(panel->dirLabel, WRSunken);
509 panel->iconLabel = WMCreateLabel(panel->win);
510 WMResizeWidget(panel->iconLabel, 140, 20);
511 WMMoveWidget(panel->iconLabel, 215, 7);
512 WMSetLabelText(panel->iconLabel, _("Icons"));
513 WMSetLabelFont(panel->iconLabel, boldFont);
514 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
516 WMReleaseFont(boldFont);
518 color = WMWhiteColor(scr->wmscreen);
519 WMSetLabelTextColor(panel->dirLabel, color);
520 WMSetLabelTextColor(panel->iconLabel, color);
521 WMReleaseColor(color);
523 color = WMDarkGrayColor(scr->wmscreen);
524 WMSetWidgetBackgroundColor(panel->iconLabel, color);
525 WMSetWidgetBackgroundColor(panel->dirLabel, color);
526 WMReleaseColor(color);
528 WMSetLabelRelief(panel->iconLabel, WRSunken);
530 panel->dirList = WMCreateList(panel->win);
531 WMResizeWidget(panel->dirList, 200, 170);
532 WMMoveWidget(panel->dirList, 10, 30);
533 WMSetListAction(panel->dirList, listCallback, panel);
535 panel->iconList = WMCreateList(panel->win);
536 WMResizeWidget(panel->iconList, 140, 170);
537 WMMoveWidget(panel->iconList, 215, 30);
538 WMSetListAction(panel->iconList, listCallback, panel);
540 WMHangData(panel->iconList,panel);
542 panel->previewButton = WMCreateCommandButton(panel->win);
543 WMResizeWidget(panel->previewButton, 75, 26);
544 WMMoveWidget(panel->previewButton, 365, 130);
545 WMSetButtonText(panel->previewButton, _("Preview"));
546 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
548 panel->iconView = WMCreateLabel(panel->win);
549 WMResizeWidget(panel->iconView, 75, 75);
550 WMMoveWidget(panel->iconView, 365, 40);
551 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
552 WMSetLabelRelief(panel->iconView, WRSunken);
553 WMSetLabelTextAlignment(panel->iconView, WACenter);
555 panel->fileLabel = WMCreateLabel(panel->win);
556 WMResizeWidget(panel->fileLabel, 80, 20);
557 WMMoveWidget(panel->fileLabel, 10, 210);
558 WMSetLabelText(panel->fileLabel, _("File Name:"));
560 panel->fileField = WMCreateTextField(panel->win);
561 WMResizeWidget(panel->fileField, 345, 20);
562 WMMoveWidget(panel->fileField, 95, 210);
563 WMSetTextFieldEditable(panel->fileField, False);
565 panel->okButton = WMCreateCommandButton(panel->win);
566 WMResizeWidget(panel->okButton, 80, 26);
567 WMMoveWidget(panel->okButton, 360, 240);
568 WMSetButtonText(panel->okButton, _("OK"));
569 WMSetButtonEnabled(panel->okButton, False);
570 WMSetButtonAction(panel->okButton, buttonCallback, panel);
572 panel->cancelButton = WMCreateCommandButton(panel->win);
573 WMResizeWidget(panel->cancelButton, 80, 26);
574 WMMoveWidget(panel->cancelButton, 270, 240);
575 WMSetButtonText(panel->cancelButton, _("Cancel"));
576 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
577 #if 0
578 panel->chooseButton = WMCreateCommandButton(panel->win);
579 WMResizeWidget(panel->chooseButton, 110, 26);
580 WMMoveWidget(panel->chooseButton, 150, 240);
581 WMSetButtonText(panel->chooseButton, _("Choose File"));
582 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
583 #endif
584 WMRealizeWidget(panel->win);
585 WMMapSubwidgets(panel->win);
587 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
589 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
592 char *tmp;
594 tmp = wmalloc((instance ? strlen(instance) : 0)
595 + (class ? strlen(class) : 0) + 32);
597 if (tmp && (instance || class))
598 sprintf(tmp, "%s [%s.%s]", _("Icon Chooser"), instance, class);
599 else
600 strcpy(tmp, _("Icon Chooser"));
602 wwin = wManageInternalWindow(scr, parent, None, tmp,
603 (scr->scr_width - 450)/2,
604 (scr->scr_height - 280)/2, 450, 280);
605 wfree(tmp);
608 /* put icon paths in the list */
609 listIconPaths(panel->dirList);
611 WMMapWidget(panel->win);
613 wWindowMap(wwin);
615 while (!panel->done) {
616 XEvent event;
618 WMNextEvent(dpy, &event);
619 WMHandleEvent(&event);
622 if (panel->result) {
623 char *defaultPath, *wantedPath;
625 /* check if the file the user selected is not the one that
626 * would be loaded by default with the current search path */
627 *file = WMGetListSelectedItem(panel->iconList)->text;
628 if ((*file)[0]==0) {
629 wfree(*file);
630 *file = NULL;
631 } else {
632 defaultPath = FindImage(wPreferences.icon_path, *file);
633 wantedPath = WMGetTextFieldText(panel->fileField);
634 /* if the file is not the default, use full path */
635 if (strcmp(wantedPath, defaultPath)!=0) {
636 *file = wantedPath;
637 } else {
638 *file = wstrdup(*file);
639 wfree(wantedPath);
641 wfree(defaultPath);
643 } else {
644 *file = NULL;
647 WMReleaseFont(panel->normalfont);
649 WMUnmapWidget(panel->win);
651 WMDestroyWidget(panel->win);
653 wUnmanageWindow(wwin, False, False);
655 wfree(panel);
657 XDestroyWindow(dpy, parent);
659 return panel->result;
664 ***********************************************************************
665 * Info Panel
666 ***********************************************************************
670 typedef struct {
671 WScreen *scr;
673 WWindow *wwin;
675 WMWindow *win;
677 WMLabel *logoL;
678 WMLabel *name1L;
679 WMLabel *name2L;
681 WMLabel *versionL;
683 WMLabel *infoL;
685 WMLabel *copyrL;
687 #ifdef SILLYNESS
688 WMHandlerID timer;
689 int cycle;
690 RImage *icon;
691 RImage *pic;
692 WMPixmap *oldPix;
693 char *str;
694 int x;
695 #endif
696 } InfoPanel;
700 #define COPYRIGHT_TEXT \
701 "Copyright \xa9 1997~2001 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
702 "Copyright \xa9 1998~2001 Dan Pascu <dan@windowmaker.org>"
706 static InfoPanel *thePanel = NULL;
708 static void
709 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
711 #ifdef SILLYNESS
712 if (thePanel->timer) {
713 WMDeleteTimerHandler(thePanel->timer);
715 if (thePanel->oldPix) {
716 WMReleasePixmap(thePanel->oldPix);
718 if (thePanel->icon) {
719 RDestroyImage(thePanel->icon);
721 if (thePanel->pic) {
722 RDestroyImage(thePanel->pic);
724 #endif /* SILLYNESS */
725 WMUnmapWidget(thePanel);
727 wUnmanageWindow(thePanel->wwin, False, False);
729 WMDestroyWidget(thePanel->win);
731 wfree(thePanel);
733 thePanel = NULL;
737 WMPixmap*
738 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
740 WMPixmap *wpix = NULL;
741 Pixmap grad = None;
742 Pixmap mask = None;
743 RContext *rc = WMScreenRContext(scr);
744 XFontStruct *f = NULL;
745 int w, h;
746 GC gc = None;
748 f = XLoadQueryFont(dpy, font);
749 if (!f)
750 return NULL;
752 w = XTextWidth(f, text, strlen(text));
753 h = f->ascent+f->descent;
755 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
756 gc = XCreateGC(dpy, mask, 0, NULL);
757 XSetForeground(dpy, gc, 0);
758 XSetFont(dpy, gc, f->fid);
759 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
761 XSetForeground(dpy, gc, 1);
762 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
763 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
764 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
766 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
768 WMColor *color;
770 color = WMBlackColor(scr);
771 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
772 WMReleaseColor(color);
775 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
777 if (gc)
778 XFreeGC(dpy, gc);
779 XFreeFont(dpy, f);
781 return wpix;
784 #ifdef SILLYNESS
786 extern WMPixmap *DoXThing();
787 extern Bool InitXThing();
789 static void
790 logoPushCallback(void *data)
792 InfoPanel *panel = (InfoPanel*)data;
793 char buffer[512];
794 int i;
795 int len;
796 static int jingobeu[] = {
797 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
798 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
799 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
801 static int c = 0;
803 if (panel->x) {
804 XKeyboardControl kc;
806 if (panel->x > 0) {
807 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
808 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
809 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
810 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
811 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
812 XBell(dpy,50);XFlush(dpy);}else{c--;}}
813 if (!(panel->cycle % 4)) {
814 WMPixmap *p;
816 p = DoXThing(panel->wwin);
817 WMSetLabelImage(panel->logoL, p);
819 } else if (panel->cycle < 30) {
820 RImage *image;
821 WMPixmap *pix;
823 image = RCloneImage(panel->icon);
824 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
825 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
826 RDestroyImage(image);
827 WMSetLabelImage(panel->logoL, pix);
828 WMReleasePixmap(pix);
831 i = panel->cycle%200;
833 len = strlen(panel->str);
835 strncpy(buffer, panel->str, i<len ? i : len);
836 if (i >= len)
837 memset(&buffer[len], ' ', i-len);
839 strncpy(buffer, panel->str, i<len ? i : len);
840 if (i >= len)
841 memset(&buffer[len], ' ', i-len);
842 buffer[i]=0;
843 WMSetLabelText(panel->versionL, buffer);
845 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
846 panel->cycle++;
850 static void
851 handleLogoPush(XEvent *event, void *data)
853 InfoPanel *panel = (InfoPanel*)data;
854 static int broken = 0;
855 static int clicks = 0;
856 static char *pic_data[] = {
857 "45 45 57 1",
858 " c None",
859 ". c #000000",
860 "X c #383C00",
861 "o c #515500",
862 "O c #616100",
863 "+ c #616900",
864 "@ c #696D00",
865 "# c #697100",
866 "$ c #495100",
867 "% c #202800",
868 "& c #969600",
869 "* c #CFCF00",
870 "= c #D7DB00",
871 "- c #D7D700",
872 "; c #C7CB00",
873 ": c #A6AA00",
874 "> c #494900",
875 ", c #8E8E00",
876 "< c #DFE700",
877 "1 c #F7FF00",
878 "2 c #FFFF00",
879 "3 c #E7EB00",
880 "4 c #B6B600",
881 "5 c #595900",
882 "6 c #717500",
883 "7 c #AEB200",
884 "8 c #CFD300",
885 "9 c #E7EF00",
886 "0 c #EFF300",
887 "q c #9EA200",
888 "w c #F7FB00",
889 "e c #F7F700",
890 "r c #BEBE00",
891 "t c #8E9200",
892 "y c #EFF700",
893 "u c #969A00",
894 "i c #414500",
895 "p c #595D00",
896 "a c #E7E700",
897 "s c #C7C700",
898 "d c #797D00",
899 "f c #BEC300",
900 "g c #DFE300",
901 "h c #868600",
902 "j c #EFEF00",
903 "k c #9E9E00",
904 "l c #616500",
905 "z c #DFDF00",
906 "x c #868A00",
907 "c c #969200",
908 "v c #B6BA00",
909 "b c #A6A600",
910 "n c #8E8A00",
911 "m c #717100",
912 "M c #AEAE00",
913 "N c #AEAA00",
914 "B c #868200",
915 " ............... ",
916 " ....XoO+@##+O$%.... ",
917 " ...%X&*========-;;:o... ",
918 " ...>.>,<122222222222134@... ",
919 " ..>5678912222222222222220q%.. ",
920 " ..$.&-w2222222222222222222er>.. ",
921 " ..O.t31222222222222222222222y4>.. ",
922 " ...O5u3222222222222222222222222yri... ",
923 " ..>p&a22222222222222222222222222wso.. ",
924 " ..ids91222222222222222222222222222wfi.. ",
925 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
926 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
927 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
928 " ..o7y22222222v...r222222223hX.i82222221si.. ",
929 "..io*222222222&...u22222222yt..%*22222220:%. ",
930 "..>k02222222227...f222222222v..X=222222229t. ",
931 "..dz12222222220ui:y2222222223d%qw222222221g. ",
932 ".%vw222222222221y2222222222219*y2222222222wd.",
933 ".X;2222222222222222222222222222222222222222b.",
934 ".i*2222222222222222222222222222222222222222v.",
935 ".i*2222222222222222222222222222222222222222;.",
936 ".i*22222222222222222222222222222222222222228.",
937 ".>*2222222222222222222222222222222222222222=.",
938 ".i*22222222222222222222222222222222222222228.",
939 ".i*2222222222222222222222222222222222222222;.",
940 ".X*222222222222222222222222222222we12222222r.",
941 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
942 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
943 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
944 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
945 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
946 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
947 " ...:e2222218mdz22222222222222a&$vw222220@...",
948 " ...O-122222y:.u02222222222229q$uj222221r... ",
949 " ..%&a1222223&573w2222222219NOxz122221z>... ",
950 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
951 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
952 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
953 " ..Xb9122222109g-****;<y22221zn%... ",
954 " ..X&801222222222222222222w-h.... ",
955 " ...o:=022222222222222221=lX... ",
956 " ..X@:;3w2222222222210fO... ",
957 " ...XX&v8<30000003-N@... ",
958 " .....XmnbN:q&Bo.... ",
959 " ............ "};
960 static char *msgs[] = {
961 "Have a nice day!",
962 "Focus follow mouse users will burn in hell!!!",
963 "F'ck Canada!!!!",
964 "F'ck Bastard Imperialists!!!",
965 "Hi! My name is bobby...",
966 "AHH! The neurotic monkeys are after me!"
970 clicks++;
972 if (!panel->timer && !broken && clicks > 0) {
973 char *file;
974 char *path;
976 panel->x = 0;
977 clicks = 0;
978 if (!panel->icon) {
979 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
980 if (!file) {
981 broken = 1;
982 return;
985 path = FindImage(wPreferences.icon_path, file);
986 if (!path) {
987 broken = 1;
988 return;
991 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
992 wfree(path);
993 if (!panel->icon) {
994 broken = 1;
995 return;
998 if (!panel->pic) {
999 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1000 if (!panel->pic || panel->icon->width!=panel->pic->width
1001 || panel->icon->height!=panel->pic->height) {
1002 broken = 1;
1003 RDestroyImage(panel->icon);
1004 panel->icon = NULL;
1005 if (panel->pic) {
1006 RDestroyImage(panel->pic);
1007 panel->pic = NULL;
1009 return;
1013 RColor color;
1014 color.red = 0xae;
1015 color.green = 0xaa;
1016 color.blue = 0xae;
1017 color.alpha = 255;
1018 RCombineImageWithColor(panel->icon, &color);
1019 RCombineImageWithColor(panel->pic, &color);
1023 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1025 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1026 panel->cycle = 0;
1027 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1028 } else if (panel->timer) {
1029 char version[20];
1031 panel->x = 0;
1032 clicks = 0;
1033 WMSetLabelImage(panel->logoL, panel->oldPix);
1034 WMReleasePixmap(panel->oldPix);
1035 panel->oldPix = NULL;
1037 WMDeleteTimerHandler(panel->timer);
1038 panel->timer = NULL;
1040 sprintf(version, _("Version %s"), VERSION);
1041 WMSetLabelText(panel->versionL, version);
1045 XEvent ev;
1046 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1047 ButtonPress, &ev));
1050 #endif /* SILLYNESS */
1053 void
1054 wShowInfoPanel(WScreen *scr)
1056 InfoPanel *panel;
1057 WMPixmap *logo;
1058 WMSize size;
1059 WMFont *font;
1060 char version[32];
1061 char buffer[512];
1062 Window parent;
1063 WWindow *wwin;
1064 RColor color1, color2;
1065 char **strl;
1066 int i;
1067 char *visuals[] = {
1068 "StaticGray",
1069 "GrayScale",
1070 "StaticColor",
1071 "PseudoColor",
1072 "TrueColor",
1073 "DirectColor"
1077 if (thePanel) {
1078 if (thePanel->scr == scr) {
1079 wRaiseFrame(thePanel->wwin->frame->core);
1080 wSetFocusTo(scr, thePanel->wwin);
1082 return;
1085 panel = wmalloc(sizeof(InfoPanel));
1086 memset(panel, 0, sizeof(InfoPanel));
1088 panel->scr = scr;
1090 panel->win = WMCreateWindow(scr->wmscreen, "info");
1091 WMResizeWidget(panel->win, 382, 230);
1093 logo = WMGetApplicationIconImage(scr->wmscreen);
1094 if (logo) {
1095 size = WMGetPixmapSize(logo);
1096 panel->logoL = WMCreateLabel(panel->win);
1097 WMResizeWidget(panel->logoL, 64, 64);
1098 WMMoveWidget(panel->logoL, 30, 20);
1099 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1100 WMSetLabelImage(panel->logoL, logo);
1101 #ifdef SILLYNESS
1102 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1103 handleLogoPush, panel);
1104 #endif
1107 panel->name1L = WMCreateLabel(panel->win);
1108 WMResizeWidget(panel->name1L, 240, 30);
1109 WMMoveWidget(panel->name1L, 100, 30);
1110 color1.red = 0;
1111 color1.green = 0;
1112 color1.blue = 0;
1113 color2.red = 0x50;
1114 color2.green = 0x50;
1115 color2.blue = 0x70;
1116 logo = renderText(scr->wmscreen, "GNU Window Maker",
1117 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1118 if (logo) {
1119 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1120 WMSetLabelImage(panel->name1L, logo);
1121 WMReleasePixmap(logo);
1122 } else {
1123 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1124 if (font) {
1125 WMSetLabelFont(panel->name1L, font);
1126 WMReleaseFont(font);
1128 WMSetLabelTextAlignment(panel->name1L, WACenter);
1129 WMSetLabelText(panel->name1L, "GNU Window Maker");
1132 panel->name2L = WMCreateLabel(panel->win);
1133 WMResizeWidget(panel->name2L, 240, 24);
1134 WMMoveWidget(panel->name2L, 100, 60);
1135 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1136 if (font) {
1137 WMSetLabelFont(panel->name2L, font);
1138 WMReleaseFont(font);
1139 font = NULL;
1141 WMSetLabelTextAlignment(panel->name2L, WACenter);
1142 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1145 sprintf(version, _("Version %s"), VERSION);
1146 panel->versionL = WMCreateLabel(panel->win);
1147 WMResizeWidget(panel->versionL, 310, 16);
1148 WMMoveWidget(panel->versionL, 30, 95);
1149 WMSetLabelTextAlignment(panel->versionL, WARight);
1150 WMSetLabelText(panel->versionL, version);
1151 WMSetLabelWraps(panel->versionL, False);
1153 panel->copyrL = WMCreateLabel(panel->win);
1154 WMResizeWidget(panel->copyrL, 340, 40);
1155 WMMoveWidget(panel->copyrL, 15, 185);
1156 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1157 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1158 /* we want the (c) character in the helvetica font */
1159 font = WMCreateNormalFont(scr->wmscreen, HELVETICA10_FONT);
1160 if (font) {
1161 WMSetLabelFont(panel->copyrL, font);
1164 switch (scr->w_depth) {
1165 case 15:
1166 strcpy(version, _("32 thousand"));
1167 break;
1168 case 16:
1169 strcpy(version, _("64 thousand"));
1170 break;
1171 case 24:
1172 case 32:
1173 strcpy(version, _("16 million"));
1174 break;
1175 default:
1176 sprintf(version, "%d", 1<<scr->w_depth);
1177 break;
1180 sprintf(buffer, _("Using visual 0x%x: %s %ibpp (%s colors)\n"),
1181 (unsigned)scr->w_visual->visualid,
1182 visuals[scr->w_visual->class], scr->w_depth, version);
1184 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1186 struct mallinfo ma = mallinfo();
1187 sprintf(buffer+strlen(buffer),
1188 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1189 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
1192 #endif
1194 strcat(buffer, _("Supported image formats: "));
1195 strl = RSupportedFileFormats();
1196 for (i=0; strl[i]!=NULL; i++) {
1197 strcat(buffer, strl[i]);
1198 strcat(buffer, " ");
1201 strcat(buffer, _("\nAdditional Support For: "));
1203 char *list[8];
1204 char buf[80];
1205 int j = 0;
1207 #ifdef MWM_HINTS
1208 list[j++] = "MWM";
1209 #endif
1210 #ifdef KWM_HINTS
1211 list[j++] = "KDE";
1212 #endif
1213 #ifdef GNOME_STUFF
1214 list[j++] = "GNOME";
1215 #endif
1216 #ifdef OLWM_HINTS
1217 list[j++] = "OLWM";
1218 #endif
1219 #ifdef WSOUND
1220 list[j++] = _("Sound");
1221 #endif
1223 buf[0] = 0;
1224 for (i = 0; i < j; i++) {
1225 if (i > 0) {
1226 if (i == j - 1)
1227 strcat(buf, _(" and "));
1228 else
1229 strcat(buf, ", ");
1231 strcat(buf, list[i]);
1233 strcat(buffer, buf);
1237 panel->infoL = WMCreateLabel(panel->win);
1238 WMResizeWidget(panel->infoL, 350, 75);
1239 WMMoveWidget(panel->infoL, 15, 115);
1240 WMSetLabelText(panel->infoL, buffer);
1241 if (font) {
1242 WMSetLabelFont(panel->infoL, font);
1243 WMReleaseFont(font);
1247 WMRealizeWidget(panel->win);
1248 WMMapSubwidgets(panel->win);
1250 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1252 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1254 WMMapWidget(panel->win);
1256 wwin = wManageInternalWindow(scr, parent, None, _("Info"),
1257 (scr->scr_width - 382)/2,
1258 (scr->scr_height - 230)/2, 382, 230);
1260 WSETUFLAG(wwin, no_closable, 0);
1261 WSETUFLAG(wwin, no_close_button, 0);
1262 #ifdef XKB_BUTTON_HINT
1263 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1264 #endif
1265 wWindowUpdateButtonImages(wwin);
1266 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1267 wwin->frame->on_click_right = destroyInfoPanel;
1269 wWindowMap(wwin);
1271 panel->wwin = wwin;
1273 thePanel = panel;
1274 #ifdef SILLYNESS
1275 if (InitXThing(panel->scr)) {
1276 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1277 panel->cycle = 0;
1278 panel->x = 1;
1279 panel->str = _("Merry X'mas!");
1280 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1282 #endif
1287 ***********************************************************************
1288 * Legal Panel
1289 ***********************************************************************
1292 typedef struct {
1293 WScreen *scr;
1295 WWindow *wwin;
1297 WMWindow *win;
1299 WMLabel *licenseL;
1300 } LegalPanel;
1303 static LegalPanel *legalPanel = NULL;
1305 static void
1306 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1308 WMUnmapWidget(legalPanel->win);
1310 WMDestroyWidget(legalPanel->win);
1312 wUnmanageWindow(legalPanel->wwin, False, False);
1314 wfree(legalPanel);
1316 legalPanel = NULL;
1320 void
1321 wShowLegalPanel(WScreen *scr)
1323 LegalPanel *panel;
1324 Window parent;
1325 WWindow *wwin;
1327 if (legalPanel) {
1328 if (legalPanel->scr == scr) {
1329 wRaiseFrame(legalPanel->wwin->frame->core);
1330 wSetFocusTo(scr, legalPanel->wwin);
1332 return;
1335 panel = wmalloc(sizeof(LegalPanel));
1337 panel->scr = scr;
1339 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1340 WMResizeWidget(panel->win, 420, 250);
1343 panel->licenseL = WMCreateLabel(panel->win);
1344 WMSetLabelWraps(panel->licenseL, True);
1345 WMResizeWidget(panel->licenseL, 400, 230);
1346 WMMoveWidget(panel->licenseL, 10, 10);
1347 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1348 WMSetLabelText(panel->licenseL,
1349 _(" Window Maker is free software; you can redistribute it and/or\n"
1350 "modify it under the terms of the GNU General Public License as\n"
1351 "published by the Free Software Foundation; either version 2 of the\n"
1352 "License, or (at your option) any later version.\n\n\n"
1353 " Window Maker is distributed in the hope that it will be useful,\n"
1354 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1355 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1356 "See the GNU General Public License for more details.\n\n\n"
1357 " You should have received a copy of the GNU General Public\n"
1358 "License along with this program; if not, write to the Free Software\n"
1359 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
1360 "02111-1307, USA."));
1361 WMSetLabelRelief(panel->licenseL, WRGroove);
1363 WMRealizeWidget(panel->win);
1364 WMMapSubwidgets(panel->win);
1366 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1368 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1370 wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
1371 (scr->scr_width - 420)/2,
1372 (scr->scr_height - 250)/2, 420, 250);
1374 WSETUFLAG(wwin, no_closable, 0);
1375 WSETUFLAG(wwin, no_close_button, 0);
1376 wWindowUpdateButtonImages(wwin);
1377 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1378 #ifdef XKB_BUTTON_HINT
1379 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1380 #endif
1381 wwin->frame->on_click_right = destroyLegalPanel;
1383 panel->wwin = wwin;
1385 WMMapWidget(panel->win);
1387 wWindowMap(wwin);
1389 legalPanel = panel;
1394 ***********************************************************************
1395 * Crashing Dialog Panel
1396 ***********************************************************************
1399 extern WDDomain *WDWindowAttributes;
1402 typedef struct _CrashPanel {
1403 WMWindow *win; /* main window */
1405 WMLabel *iconL; /* application icon */
1406 WMLabel *nameL; /* title of panel */
1408 WMFrame *sepF; /* separator frame */
1410 WMLabel *noteL; /* Title of note */
1411 WMLabel *note2L; /* body of note with what happened */
1413 WMFrame *whatF; /* "what to do next" frame */
1414 WMPopUpButton *whatP; /* action selection popup button */
1416 WMButton *okB; /* ok button */
1418 Bool done; /* if finished with this dialog */
1419 int action; /* what to do after */
1421 KeyCode retKey;
1423 } CrashPanel;
1426 static void
1427 handleKeyPress(XEvent *event, void *clientData)
1429 CrashPanel *panel = (CrashPanel*)clientData;
1431 if (event->xkey.keycode == panel->retKey) {
1432 WMPerformButtonClick(panel->okB);
1437 static void
1438 okButtonCallback(void *self, void *clientData)
1440 CrashPanel *panel = (CrashPanel*)clientData;
1442 panel->done = True;
1446 static void
1447 setCrashAction(void *self, void *clientData)
1449 WMPopUpButton *pop = (WMPopUpButton*)self;
1450 CrashPanel *panel = (CrashPanel*)clientData;
1452 panel->action = WMGetPopUpButtonSelectedItem(pop);
1456 static WMPixmap*
1457 getWindowMakerIconImage(WMScreen *scr)
1459 proplist_t dict, key, option, value=NULL;
1460 WMPixmap *pix=NULL;
1461 char *path;
1463 PLSetStringCmpHook(NULL);
1465 key = PLMakeString("Logo.WMPanel");
1466 option = PLMakeString("Icon");
1468 dict = PLGetDictionaryEntry(WDWindowAttributes->dictionary, key);
1470 if (dict) {
1471 value = PLGetDictionaryEntry(dict, option);
1474 PLRelease(key);
1475 PLRelease(option);
1477 PLSetStringCmpHook(StringCompareHook);
1479 if (value && PLIsString(value)) {
1480 path = FindImage(wPreferences.icon_path, PLGetString(value));
1482 if (path) {
1483 RImage *image;
1485 image = RLoadImage(WMScreenRContext(scr), path, 0);
1486 if (image) {
1487 pix = WMCreatePixmapFromRImage(scr, image, 0);
1488 RDestroyImage(image);
1490 wfree(path);
1494 return pix;
1498 #define PWIDTH 295
1499 #define PHEIGHT 345
1503 wShowCrashingDialogPanel(int whatSig)
1505 CrashPanel *panel;
1506 WMScreen *scr;
1507 WMFont *font;
1508 WMPixmap *logo;
1509 int screen_no, scr_width, scr_height;
1510 int action;
1511 char buf[256];
1513 panel = wmalloc(sizeof(CrashPanel));
1514 memset(panel, 0, sizeof(CrashPanel));
1516 screen_no = DefaultScreen(dpy);
1517 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1518 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1520 scr = WMCreateScreen(dpy, screen_no);
1521 if (!scr) {
1522 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1523 return WMAbort;
1526 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1528 panel->win = WMCreateWindow(scr, "crashingDialog");
1529 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1530 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1532 logo = getWindowMakerIconImage(scr);
1533 if (logo) {
1534 panel->iconL = WMCreateLabel(panel->win);
1535 WMResizeWidget(panel->iconL, 64, 64);
1536 WMMoveWidget(panel->iconL, 10, 10);
1537 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1538 WMSetLabelImage(panel->iconL, logo);
1541 panel->nameL = WMCreateLabel(panel->win);
1542 WMResizeWidget(panel->nameL, 190, 18);
1543 WMMoveWidget(panel->nameL, 80, 35);
1544 WMSetLabelTextAlignment(panel->nameL, WALeft);
1545 font = WMBoldSystemFontOfSize(scr, 18);
1546 WMSetLabelFont(panel->nameL, font);
1547 WMReleaseFont(font);
1548 WMSetLabelText(panel->nameL, _("Fatal error"));
1550 panel->sepF = WMCreateFrame(panel->win);
1551 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1552 WMMoveWidget(panel->sepF, -2, 80);
1554 panel->noteL = WMCreateLabel(panel->win);
1555 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1556 WMMoveWidget(panel->noteL, 10, 90);
1557 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1558 #ifdef SYS_SIGLIST_DECLARED
1559 sprintf(buf, _("Window Maker received signal %i\n(%s)."),
1560 whatSig, sys_siglist[whatSig]);
1561 #else
1562 sprintf(buf, _("Window Maker received signal %i."), whatSig);
1563 #endif
1564 WMSetLabelText(panel->noteL, buf);
1566 panel->note2L = WMCreateLabel(panel->win);
1567 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1568 WMMoveWidget(panel->note2L, 10, 130);
1569 WMSetLabelTextAlignment(panel->note2L, WALeft);
1570 WMSetLabelText(panel->note2L,
1571 _(" This fatal error occured probably due to a bug."
1572 " Please fill the included BUGFORM and "
1573 "report it to bugs@windowmaker.org."));
1576 panel->whatF = WMCreateFrame(panel->win);
1577 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1578 WMMoveWidget(panel->whatF, 10, 240);
1579 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1581 panel->whatP = WMCreatePopUpButton(panel->whatF);
1582 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1583 WMMoveWidget(panel->whatP, 35, 20);
1584 WMSetPopUpButtonPullsDown(panel->whatP, False);
1585 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1586 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1587 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1588 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1589 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1590 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1591 panel->action = WMRestart;
1593 WMMapSubwidgets(panel->whatF);
1595 panel->okB = WMCreateCommandButton(panel->win);
1596 WMResizeWidget(panel->okB, 80, 26);
1597 WMMoveWidget(panel->okB, 205, 309);
1598 WMSetButtonText(panel->okB, _("OK"));
1599 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1600 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1601 WMSetButtonImagePosition(panel->okB, WIPRight);
1602 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1604 panel->done = 0;
1606 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1607 handleKeyPress, panel);
1609 WMRealizeWidget(panel->win);
1610 WMMapSubwidgets(panel->win);
1612 WMMapWidget(panel->win);
1614 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1616 while (!panel->done) {
1617 XEvent event;
1619 WMNextEvent(dpy, &event);
1620 WMHandleEvent(&event);
1623 action = panel->action;
1625 WMUnmapWidget(panel->win);
1626 WMDestroyWidget(panel->win);
1627 wfree(panel);
1629 return action;
1635 /*****************************************************************************
1636 * About GNUstep Panel
1637 *****************************************************************************/
1640 static void
1641 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1642 unsigned long blackPixel, unsigned long whitePixel)
1644 GC gc;
1645 XGCValues gcv;
1646 XRectangle rects[3];
1648 gcv.foreground = blackPixel;
1649 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1651 XFillArc(dpy, d, gc, width/45, height/45,
1652 width - 2*width/45, height - 2*height/45, 0, 360*64);
1654 rects[0].x = 0;
1655 rects[0].y = 37*height/45;
1656 rects[0].width = width/3;
1657 rects[0].height = height - rects[0].y;
1659 rects[1].x = rects[0].width;
1660 rects[1].y = height/2;
1661 rects[1].width = width - 2*width/3;
1662 rects[1].height = height - rects[1].y;
1664 rects[2].x = 2*width/3;
1665 rects[2].y = height - 37*height/45;
1666 rects[2].width = width/3;
1667 rects[2].height = height - rects[2].y;
1669 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1670 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1672 XSetForeground(dpy, gc, whitePixel);
1673 XFillArc(dpy, d, gc, width/45, height/45,
1674 width - 2*width/45, height - 2*height/45, 0, 360*64);
1676 XFreeGC(dpy, gc);
1680 typedef struct {
1681 WScreen *scr;
1683 WWindow *wwin;
1685 WMWindow *win;
1687 WMLabel *gstepL;
1688 WMLabel *textL;
1689 } GNUstepPanel;
1692 static GNUstepPanel *gnustepPanel = NULL;
1694 static void
1695 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1697 WMUnmapWidget(gnustepPanel->win);
1699 WMDestroyWidget(gnustepPanel->win);
1701 wUnmanageWindow(gnustepPanel->wwin, False, False);
1703 wfree(gnustepPanel);
1705 gnustepPanel = NULL;
1709 void
1710 wShowGNUstepPanel(WScreen *scr)
1712 GNUstepPanel *panel;
1713 Window parent;
1714 WWindow *wwin;
1715 WMPixmap *pixmap;
1716 WMColor *color;
1718 if (gnustepPanel) {
1719 if (gnustepPanel->scr == scr) {
1720 wRaiseFrame(gnustepPanel->wwin->frame->core);
1721 wSetFocusTo(scr, gnustepPanel->wwin);
1723 return;
1726 panel = wmalloc(sizeof(GNUstepPanel));
1728 panel->scr = scr;
1730 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1731 WMResizeWidget(panel->win, 325, 200);
1733 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1734 WMScreenDepth(scr->wmscreen), True);
1736 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1738 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1739 WMColorPixel(color), scr->white_pixel);
1741 WMReleaseColor(color);
1743 XSetForeground(dpy, scr->mono_gc, 0);
1744 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1745 130, 130);
1746 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1748 panel->gstepL = WMCreateLabel(panel->win);
1749 WMResizeWidget(panel->gstepL, 285, 64);
1750 WMMoveWidget(panel->gstepL, 20, 0);
1751 WMSetLabelTextAlignment(panel->gstepL, WARight);
1752 WMSetLabelText(panel->gstepL, "GNUstep");
1754 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1756 WMSetLabelFont(panel->gstepL, font);
1757 WMReleaseFont(font);
1760 panel->textL = WMCreateLabel(panel->win);
1761 WMResizeWidget(panel->textL, 275, 130);
1762 WMMoveWidget(panel->textL, 30, 50);
1763 WMSetLabelTextAlignment(panel->textL, WARight);
1764 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1765 WMSetLabelText(panel->textL,
1766 _("Window Maker is part of the GNUstep project.\n"\
1767 "The GNUstep project aims to create a free\n"\
1768 "implementation of the OpenStep(tm) specification\n"\
1769 "which is a object-oriented framework for\n"\
1770 "creating advanced graphical, multi-platform\n"\
1771 "applications. Additionally, a development and\n"\
1772 "user desktop enviroment will be created on top\n"\
1773 "of the framework. For more information about\n"\
1774 "GNUstep, please visit: www.gnustep.org"));
1775 WMSetLabelImage(panel->textL, pixmap);
1777 WMReleasePixmap(pixmap);
1779 WMRealizeWidget(panel->win);
1780 WMMapSubwidgets(panel->win);
1782 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1784 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1786 wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
1787 (scr->scr_width - 325)/2,
1788 (scr->scr_height - 200)/2, 325, 200);
1790 WSETUFLAG(wwin, no_closable, 0);
1791 WSETUFLAG(wwin, no_close_button, 0);
1792 wWindowUpdateButtonImages(wwin);
1793 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1794 #ifdef XKB_BUTTON_HINT
1795 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1796 #endif
1797 wwin->frame->on_click_right = destroyGNUstepPanel;
1799 panel->wwin = wwin;
1801 WMMapWidget(panel->win);
1803 wWindowMap(wwin);
1805 gnustepPanel = panel;