another test for cvs notifications
[wmaker-crm.git] / src / dialog.c
blobef531a248090fe6d50e38a462067dbf989b4adbb
1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/keysym.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <dirent.h>
37 #include <limits.h>
39 #ifdef HAVE_MALLOC_H
40 #include <malloc.h>
41 #endif
43 #include <signal.h>
44 #ifdef __FreeBSD__
45 #include <sys/signal.h>
46 #endif
49 #ifndef PATH_MAX
50 #define PATH_MAX DEFAULT_PATH_MAX
51 #endif
53 #include "WindowMaker.h"
54 #include "GNUstep.h"
55 #include "screen.h"
56 #include "dialog.h"
57 #include "funcs.h"
58 #include "stacking.h"
59 #include "framewin.h"
60 #include "window.h"
61 #include "actions.h"
62 #include "defaults.h"
63 #include "xinerama.h"
67 extern WPreferences wPreferences;
70 static WMPoint getCenter(WScreen *scr, int width, int height)
72 return wGetPointToCenterRectInHead(scr,
73 wGetHeadForPointerLocation(scr),
74 width, height);
78 int
79 wMessageDialog(WScreen *scr, char *title, char *message,
80 char *defBtn, char *altBtn, char *othBtn)
82 WMAlertPanel *panel;
83 Window parent;
84 WWindow *wwin;
85 int result;
86 WMPoint center;
88 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
89 defBtn, altBtn, othBtn);
91 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
93 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
96 center = getCenter(scr, 400, 180);
97 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
98 400, 180);
99 wwin->client_leader = WMWidgetXID(panel->win);
101 WMMapWidget(panel->win);
103 wWindowMap(wwin);
105 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
107 result = panel->result;
109 WMUnmapWidget(panel->win);
111 wUnmanageWindow(wwin, False, False);
113 WMDestroyAlertPanel(panel);
115 XDestroyWindow(dpy, parent);
117 return result;
121 void
122 toggleSaveSession(WMWidget *w, void *data)
124 wPreferences.save_session_on_exit = WMGetButtonSelected((WMButton *) w);
129 wExitDialog(WScreen *scr, char *title, char *message,
130 char *defBtn, char *altBtn, char *othBtn)
132 WMAlertPanel *panel;
133 WMButton *saveSessionBtn;
134 Window parent;
135 WWindow *wwin;
136 WMPoint center;
137 int result;
139 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
140 defBtn, altBtn, othBtn);
142 /* add save session button */
143 saveSessionBtn = WMCreateSwitchButton(panel->hbox);
144 WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
145 WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn),
146 False, True, 200, 0, 0);
147 WMSetButtonText(saveSessionBtn, _("Save workspace state"));
148 WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
149 WMRealizeWidget(saveSessionBtn);
150 WMMapWidget(saveSessionBtn);
152 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
154 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
156 center = getCenter(scr, 400, 180);
157 wwin = wManageInternalWindow(scr, parent, None, NULL,
158 center.x, center.y, 400, 180);
160 wwin->client_leader = WMWidgetXID(panel->win);
162 WMMapWidget(panel->win);
164 wWindowMap(wwin);
166 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
168 result = panel->result;
170 WMUnmapWidget(panel->win);
172 wUnmanageWindow(wwin, False, False);
174 WMDestroyAlertPanel(panel);
176 XDestroyWindow(dpy, parent);
178 return result;
183 wInputDialog(WScreen *scr, char *title, char *message, char **text)
185 WWindow *wwin;
186 Window parent;
187 WMInputPanel *panel;
188 char *result;
189 WMPoint center;
191 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
192 _("OK"), _("Cancel"));
195 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
196 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
198 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
200 center = getCenter(scr, 320, 160);
201 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
202 320, 160);
204 wwin->client_leader = WMWidgetXID(panel->win);
206 WMMapWidget(panel->win);
208 wWindowMap(wwin);
210 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
212 if (panel->result == WAPRDefault)
213 result = WMGetTextFieldText(panel->text);
214 else
215 result = NULL;
217 wUnmanageWindow(wwin, False, False);
219 WMDestroyInputPanel(panel);
221 XDestroyWindow(dpy, parent);
223 if (result==NULL)
224 return False;
225 else {
226 if (*text)
227 wfree(*text);
228 *text = result;
230 return True;
236 *****************************************************************
237 * Icon Selection Panel
238 *****************************************************************
241 typedef struct IconPanel {
243 WScreen *scr;
245 WMWindow *win;
247 WMLabel *dirLabel;
248 WMLabel *iconLabel;
250 WMList *dirList;
251 WMList *iconList;
252 WMFont *normalfont;
254 WMButton *previewButton;
256 WMLabel *iconView;
258 WMLabel *fileLabel;
259 WMTextField *fileField;
261 WMButton *okButton;
262 WMButton *cancelButton;
263 #if 0
264 WMButton *chooseButton;
265 #endif
266 short done;
267 short result;
268 short preview;
269 } IconPanel;
273 static void
274 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
276 struct dirent *dentry;
277 DIR *dir;
278 char pbuf[PATH_MAX+16];
279 char *apath;
280 IconPanel *panel = WMGetHangedData(lPtr);
282 panel->preview = False;
284 apath = wexpandpath(path);
285 dir = opendir(apath);
287 if (!dir) {
288 char *msg;
289 char *tmp;
290 tmp = _("Could not open directory ");
291 msg = wmalloc(strlen(tmp)+strlen(path)+6);
292 strcpy(msg, tmp);
293 strcat(msg, path);
295 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
296 wfree(msg);
297 wfree(apath);
298 return;
301 /* list contents in the column */
302 while ((dentry = readdir(dir))) {
303 struct stat statb;
305 if (strcmp(dentry->d_name, ".")==0 ||
306 strcmp(dentry->d_name, "..")==0)
307 continue;
309 strcpy(pbuf, apath);
310 strcat(pbuf, "/");
311 strcat(pbuf, dentry->d_name);
313 if (stat(pbuf, &statb)<0)
314 continue;
316 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
317 && statb.st_mode & (S_IFREG|S_IFLNK)) {
318 WMAddListItem(lPtr, dentry->d_name);
321 WMSortListItems(lPtr);
323 closedir(dir);
324 wfree(apath);
325 panel->preview = True;
330 static void
331 setViewedImage(IconPanel *panel, char *file)
333 WMPixmap *pixmap;
334 RColor color;
336 color.red = 0xae;
337 color.green = 0xaa;
338 color.blue = 0xae;
339 color.alpha = 0;
340 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
341 file, &color);
342 if (!pixmap) {
343 WMSetButtonEnabled(panel->okButton, False);
345 WMSetLabelText(panel->iconView, _("Could not load image file "));
347 WMSetLabelImage(panel->iconView, NULL);
348 } else {
349 WMSetButtonEnabled(panel->okButton, True);
351 WMSetLabelText(panel->iconView, NULL);
352 WMSetLabelImage(panel->iconView, pixmap);
353 WMReleasePixmap(pixmap);
358 static void
359 listCallback(void *self, void *data)
361 WMList *lPtr = (WMList*)self;
362 IconPanel *panel = (IconPanel*)data;
363 char *path;
365 if (lPtr==panel->dirList) {
366 WMListItem *item = WMGetListSelectedItem(lPtr);
368 if (item == NULL)
369 return;
370 path = item->text;
372 WMSetTextFieldText(panel->fileField, path);
374 WMSetLabelImage(panel->iconView, NULL);
376 WMSetButtonEnabled(panel->okButton, False);
378 WMClearList(panel->iconList);
379 listPixmaps(panel->scr, panel->iconList, path);
380 } else {
381 char *tmp, *iconFile;
382 WMListItem *item = WMGetListSelectedItem(panel->dirList);
384 if (item == NULL)
385 return;
386 path = item->text;
387 tmp = wexpandpath(path);
389 item = WMGetListSelectedItem(panel->iconList);
390 if (item == NULL)
391 return;
392 iconFile = item->text;
394 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
395 strcpy(path, tmp);
396 strcat(path, "/");
397 strcat(path, iconFile);
398 wfree(tmp);
399 WMSetTextFieldText(panel->fileField, path);
400 setViewedImage(panel, path);
401 wfree(path);
406 static void
407 listIconPaths(WMList *lPtr)
409 char *paths;
410 char *path;
412 paths = wstrdup(wPreferences.icon_path);
414 path = strtok(paths, ":");
416 do {
417 char *tmp;
419 tmp = wexpandpath(path);
420 /* do not sort, because the order implies the order of
421 * directories searched */
422 if (access(tmp, X_OK)==0)
423 WMAddListItem(lPtr, path);
424 wfree(tmp);
425 } while ((path=strtok(NULL, ":"))!=NULL);
427 wfree(paths);
431 void
432 drawIconProc(WMList *lPtr, int index, Drawable d, char *text, int state,
433 WMRect *rect)
435 IconPanel *panel = WMGetHangedData(lPtr);
436 WScreen *scr = panel->scr;
437 GC gc = scr->draw_gc;
438 GC copygc = scr->copy_gc;
439 char *file, *dirfile;
440 WMPixmap *pixmap;
441 WMColor *back;
442 WMSize size;
443 WMScreen *wmscr = WMWidgetScreen(panel->win);
444 RColor color;
445 int x, y, width, height, len;
447 if(!panel->preview) return;
449 x = rect->pos.x;
450 y = rect->pos.y;
451 width = rect->size.width;
452 height = rect->size.height;
454 back = (state & WLDSSelected) ? scr->white : scr->gray;
456 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
457 len = strlen(dirfile)+strlen(text)+4;
458 file = wmalloc(len);
459 snprintf(file, len, "%s/%s", dirfile, text);
460 wfree(dirfile);
462 color.red = WMRedComponentOfColor(back) >> 8;
463 color.green = WMGreenComponentOfColor(back) >> 8;
464 color.blue = WMBlueComponentOfColor(back) >> 8;
465 color.alpha = WMGetColorAlpha(back) >> 8;
467 pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
468 wfree(file);
470 if (!pixmap) {
471 /*WMRemoveListItem(lPtr, index);*/
472 return;
475 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
477 XSetClipMask(dpy, gc, None);
478 /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54);*/
479 XDrawLine(dpy, d, WMColorGC(scr->white), x, y+height-1, x+width, y+height-1);
481 size = WMGetPixmapSize(pixmap);
483 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
484 XSetClipOrigin(dpy, copygc, x + (width-size.width)/2, y+2);
485 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
486 size.width>100?100:size.width, size.height>64?64:size.height,
487 x + (width-size.width)/2, y+2);
490 int i,j;
491 int fheight = WMFontHeight(panel->normalfont);
492 int tlen = strlen(text);
493 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
494 int ofx, ofy;
496 ofx = x + (width - twidth)/2;
497 ofy = y + 64 - fheight;
499 for(i=-1;i<2;i++)
500 for(j=-1;j<2;j++)
501 WMDrawString(wmscr, d, scr->white, panel->normalfont,
502 ofx+i, ofy+j, text, tlen);
504 WMDrawString(wmscr, d, scr->black, panel->normalfont, ofx, ofy,
505 text, tlen);
508 WMReleasePixmap(pixmap);
509 /* I hope it is better to do not use cache / on my box it is fast nuff */
510 XFlush(dpy);
514 static void
515 buttonCallback(void *self, void *clientData)
517 WMButton *bPtr = (WMButton*)self;
518 IconPanel *panel = (IconPanel*)clientData;
521 if (bPtr==panel->okButton) {
522 panel->done = True;
523 panel->result = True;
524 } else if (bPtr==panel->cancelButton) {
525 panel->done = True;
526 panel->result = False;
527 } else if (bPtr==panel->previewButton) {
528 /**** Previewer ****/
529 WMSetButtonEnabled(bPtr, False);
530 WMSetListUserDrawItemHeight(panel->iconList, 68);
531 WMSetListUserDrawProc(panel->iconList, drawIconProc);
532 WMRedisplayWidget(panel->iconList);
533 /* for draw proc to access screen/gc */
534 /*** end preview ***/
536 #if 0
537 else if (bPtr==panel->chooseButton) {
538 WMOpenPanel *op;
540 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
542 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
543 char *path;
544 path = WMGetFilePanelFile(op);
545 WMSetTextFieldText(panel->fileField, path);
546 setViewedImage(panel, path);
547 wfree(path);
549 WMDestroyFilePanel(op);
551 #endif
555 static void
556 keyPressHandler(XEvent *event, void *data)
558 IconPanel *panel = (IconPanel*)data;
559 char buffer[32];
560 int count;
561 KeySym ksym;
562 int iidx;
563 int didx;
564 int item;
565 WMList *list = NULL;
567 if (event->type == KeyRelease)
568 return;
570 buffer[0] = 0;
571 count = XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
574 iidx = WMGetListSelectedItemRow(panel->iconList);
575 didx = WMGetListSelectedItemRow(panel->dirList);
577 switch (ksym) {
578 case XK_Up:
579 if (iidx > 0)
580 item = iidx-1;
581 else
582 item = iidx;
583 list = panel->iconList;
584 break;
585 case XK_Down:
586 if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
587 item = iidx+1;
588 else
589 item = iidx;
590 list = panel->iconList;
591 break;
592 case XK_Home:
593 item = 0;
594 list = panel->iconList;
595 break;
596 case XK_End:
597 item = WMGetListNumberOfRows(panel->iconList) - 1;
598 list = panel->iconList;
599 break;
600 case XK_Next:
601 if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
602 item = didx + 1;
603 else
604 item = didx;
605 list = panel->dirList;
606 break;
607 case XK_Prior:
608 if (didx > 0)
609 item = didx - 1;
610 else
611 item = 0;
612 list = panel->dirList;
613 break;
614 case XK_Return:
615 WMPerformButtonClick(panel->okButton);
616 break;
617 case XK_Escape:
618 WMPerformButtonClick(panel->cancelButton);
619 break;
622 if (list) {
623 WMSelectListItem(list, item);
624 WMSetListPosition(list, item - 5);
625 listCallback(list, panel);
631 Bool
632 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
634 WWindow *wwin;
635 Window parent;
636 IconPanel *panel;
637 WMColor *color;
638 WMFont *boldFont;
639 Bool result;
641 panel = wmalloc(sizeof(IconPanel));
642 memset(panel, 0, sizeof(IconPanel));
644 panel->scr = scr;
646 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
647 WMResizeWidget(panel->win, 450, 280);
649 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask|KeyReleaseMask,
650 keyPressHandler, panel);
653 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
654 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
656 panel->dirLabel = WMCreateLabel(panel->win);
657 WMResizeWidget(panel->dirLabel, 200, 20);
658 WMMoveWidget(panel->dirLabel, 10, 7);
659 WMSetLabelText(panel->dirLabel, _("Directories"));
660 WMSetLabelFont(panel->dirLabel, boldFont);
661 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
663 WMSetLabelRelief(panel->dirLabel, WRSunken);
665 panel->iconLabel = WMCreateLabel(panel->win);
666 WMResizeWidget(panel->iconLabel, 140, 20);
667 WMMoveWidget(panel->iconLabel, 215, 7);
668 WMSetLabelText(panel->iconLabel, _("Icons"));
669 WMSetLabelFont(panel->iconLabel, boldFont);
670 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
672 WMReleaseFont(boldFont);
674 color = WMWhiteColor(scr->wmscreen);
675 WMSetLabelTextColor(panel->dirLabel, color);
676 WMSetLabelTextColor(panel->iconLabel, color);
677 WMReleaseColor(color);
679 color = WMDarkGrayColor(scr->wmscreen);
680 WMSetWidgetBackgroundColor(panel->iconLabel, color);
681 WMSetWidgetBackgroundColor(panel->dirLabel, color);
682 WMReleaseColor(color);
684 WMSetLabelRelief(panel->iconLabel, WRSunken);
686 panel->dirList = WMCreateList(panel->win);
687 WMResizeWidget(panel->dirList, 200, 170);
688 WMMoveWidget(panel->dirList, 10, 30);
689 WMSetListAction(panel->dirList, listCallback, panel);
691 panel->iconList = WMCreateList(panel->win);
692 WMResizeWidget(panel->iconList, 140, 170);
693 WMMoveWidget(panel->iconList, 215, 30);
694 WMSetListAction(panel->iconList, listCallback, panel);
696 WMHangData(panel->iconList,panel);
698 panel->previewButton = WMCreateCommandButton(panel->win);
699 WMResizeWidget(panel->previewButton, 75, 26);
700 WMMoveWidget(panel->previewButton, 365, 130);
701 WMSetButtonText(panel->previewButton, _("Preview"));
702 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
704 panel->iconView = WMCreateLabel(panel->win);
705 WMResizeWidget(panel->iconView, 75, 75);
706 WMMoveWidget(panel->iconView, 365, 40);
707 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
708 WMSetLabelRelief(panel->iconView, WRSunken);
709 WMSetLabelTextAlignment(panel->iconView, WACenter);
711 panel->fileLabel = WMCreateLabel(panel->win);
712 WMResizeWidget(panel->fileLabel, 80, 20);
713 WMMoveWidget(panel->fileLabel, 10, 210);
714 WMSetLabelText(panel->fileLabel, _("File Name:"));
716 panel->fileField = WMCreateTextField(panel->win);
717 WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
718 WMResizeWidget(panel->fileField, 345, 20);
719 WMMoveWidget(panel->fileField, 95, 210);
720 WMSetTextFieldEditable(panel->fileField, False);
722 panel->okButton = WMCreateCommandButton(panel->win);
723 WMResizeWidget(panel->okButton, 80, 26);
724 WMMoveWidget(panel->okButton, 360, 240);
725 WMSetButtonText(panel->okButton, _("OK"));
726 WMSetButtonEnabled(panel->okButton, False);
727 WMSetButtonAction(panel->okButton, buttonCallback, panel);
729 panel->cancelButton = WMCreateCommandButton(panel->win);
730 WMResizeWidget(panel->cancelButton, 80, 26);
731 WMMoveWidget(panel->cancelButton, 270, 240);
732 WMSetButtonText(panel->cancelButton, _("Cancel"));
733 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
734 #if 0
735 panel->chooseButton = WMCreateCommandButton(panel->win);
736 WMResizeWidget(panel->chooseButton, 110, 26);
737 WMMoveWidget(panel->chooseButton, 150, 240);
738 WMSetButtonText(panel->chooseButton, _("Choose File"));
739 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
740 #endif
741 WMRealizeWidget(panel->win);
742 WMMapSubwidgets(panel->win);
744 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
746 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
749 char *tmp;
750 int len = (instance ? strlen(instance) : 0)
751 + (class ? strlen(class) : 0) + 32;
752 WMPoint center;
754 tmp = wmalloc(len);
756 if (tmp && (instance || class))
757 snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
758 else
759 strcpy(tmp, _("Icon Chooser"));
761 center = getCenter(scr, 450, 280);
763 wwin = wManageInternalWindow(scr, parent, None, tmp, center.x,center.y,
764 450, 280);
765 wfree(tmp);
768 /* put icon paths in the list */
769 listIconPaths(panel->dirList);
771 WMMapWidget(panel->win);
773 wWindowMap(wwin);
775 while (!panel->done) {
776 XEvent event;
778 WMNextEvent(dpy, &event);
779 WMHandleEvent(&event);
782 if (panel->result) {
783 char *defaultPath, *wantedPath;
785 /* check if the file the user selected is not the one that
786 * would be loaded by default with the current search path */
787 *file = WMGetListSelectedItem(panel->iconList)->text;
788 if (**file==0) {
789 wfree(*file);
790 *file = NULL;
791 } else {
792 defaultPath = FindImage(wPreferences.icon_path, *file);
793 wantedPath = WMGetTextFieldText(panel->fileField);
794 /* if the file is not the default, use full path */
795 if (strcmp(wantedPath, defaultPath)!=0) {
796 *file = wantedPath;
797 } else {
798 *file = wstrdup(*file);
799 wfree(wantedPath);
801 wfree(defaultPath);
803 } else {
804 *file = NULL;
807 result = panel->result;
809 WMReleaseFont(panel->normalfont);
811 WMUnmapWidget(panel->win);
813 WMDestroyWidget(panel->win);
815 wUnmanageWindow(wwin, False, False);
817 wfree(panel);
819 XDestroyWindow(dpy, parent);
821 return result;
826 ***********************************************************************
827 * Info Panel
828 ***********************************************************************
832 typedef struct {
833 WScreen *scr;
835 WWindow *wwin;
837 WMWindow *win;
839 WMLabel *logoL;
840 WMLabel *name1L;
841 WMFrame *lineF;
842 WMLabel *name2L;
844 WMLabel *versionL;
846 WMLabel *infoL;
848 WMLabel *copyrL;
850 #ifdef SILLYNESS
851 WMHandlerID timer;
852 int cycle;
853 RImage *icon;
854 RImage *pic;
855 WMPixmap *oldPix;
856 WMFont *oldFont;
857 char *str;
858 int x;
859 #endif
860 } InfoPanel;
864 #define COPYRIGHT_TEXT \
865 "Copyright \xa9 1997-2003 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
866 "Copyright \xa9 1998-2003 Dan Pascu <dan@windowmaker.org>"
868 #define COPYRIGHT_TEXT_UTF8 \
869 "Copyright \xc2\xa9 1997-2003 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
870 "Copyright \xc2\xa9 1998-2003 Dan Pascu <dan@windowmaker.org>"
874 static InfoPanel *thePanel = NULL;
876 static void
877 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
879 #ifdef SILLYNESS
880 if (thePanel->timer) {
881 WMDeleteTimerHandler(thePanel->timer);
883 if (thePanel->oldPix) {
884 WMReleasePixmap(thePanel->oldPix);
886 if (thePanel->oldFont) {
887 WMReleaseFont(thePanel->oldFont);
889 if (thePanel->icon) {
890 RReleaseImage(thePanel->icon);
892 if (thePanel->pic) {
893 RReleaseImage(thePanel->pic);
895 #endif /* SILLYNESS */
896 WMUnmapWidget(thePanel);
898 wUnmanageWindow(thePanel->wwin, False, False);
900 WMDestroyWidget(thePanel->win);
902 wfree(thePanel);
904 thePanel = NULL;
908 #ifdef SILLYNESS
910 extern WMPixmap *DoXThing();
911 extern Bool InitXThing();
913 static void
914 logoPushCallback(void *data)
916 InfoPanel *panel = (InfoPanel*)data;
917 char buffer[512];
918 int i;
919 static int oldi = 0;
920 int len;
921 static int jingobeu[] = {
922 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
923 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
924 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
926 static int c = 0;
928 if (panel->x) {
929 XKeyboardControl kc;
930 XKeyboardState ksave;
931 unsigned long mask = KBBellPitch|KBBellDuration|KBBellPercent;
933 XGetKeyboardControl(dpy, &ksave);
935 if (panel->x > 0) {
936 if(jingobeu[panel->x-1]==0) {
937 panel->x=-1;
938 } else if (jingobeu[panel->x-1]<0) {
939 panel->x++;
940 c=jingobeu[panel->x-1]/50;
941 panel->x++;
942 } else if (c==0) {
943 kc.bell_percent=50;
944 kc.bell_pitch=jingobeu[panel->x-1];
945 panel->x++;
946 kc.bell_duration=jingobeu[panel->x-1];
947 c=jingobeu[panel->x-1]/50;
948 panel->x++;
949 XChangeKeyboardControl(dpy, mask, &kc);
950 XBell(dpy, 50);
951 XFlush(dpy);
952 } else {
953 c--;
956 if (!(panel->cycle % 4)) {
957 WMPixmap *p;
959 p = DoXThing(panel->wwin);
960 WMSetLabelImage(panel->logoL, p);
962 kc.bell_pitch = ksave.bell_pitch;
963 kc.bell_percent = ksave.bell_percent;
964 kc.bell_duration = ksave.bell_duration;
965 XChangeKeyboardControl(dpy, mask, &kc);
966 } else if (panel->cycle < 30) {
967 RImage *image;
968 WMPixmap *pix;
969 RColor gray;
971 gray.red = 0xae; gray.green = 0xaa;
972 gray.blue = 0xae; gray.alpha = 0;
974 image = RScaleImage(panel->icon, panel->pic->width, panel->pic->height);
975 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
976 pix = WMCreateBlendedPixmapFromRImage(panel->scr->wmscreen, image, &gray);
977 RReleaseImage(image);
978 WMSetLabelImage(panel->logoL, pix);
979 WMReleasePixmap(pix);
982 /* slow down text a little */
983 i = (int)(panel->cycle * 50.0/85.0)%200;
985 if (i != oldi) {
986 len = strlen(panel->str);
988 strncpy(buffer, panel->str, i<len ? i : len);
989 if (i >= len)
990 memset(&buffer[len], ' ', i-len);
992 strncpy(buffer, panel->str, i<len ? i : len);
993 if (i >= len)
994 memset(&buffer[len], ' ', i-len);
995 buffer[i]=0;
997 WMSetLabelText(panel->versionL, buffer);
999 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1001 oldi = i;
1004 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1005 panel->cycle++;
1009 static void
1010 handleLogoPush(XEvent *event, void *data)
1012 InfoPanel *panel = (InfoPanel*)data;
1013 static int broken = 0;
1014 static int clicks = 0;
1015 static char *pic_data[] = {
1016 "45 45 57 1",
1017 " c None",
1018 ". c #000000",
1019 "X c #383C00",
1020 "o c #515500",
1021 "O c #616100",
1022 "+ c #616900",
1023 "@ c #696D00",
1024 "# c #697100",
1025 "$ c #495100",
1026 "% c #202800",
1027 "& c #969600",
1028 "* c #CFCF00",
1029 "= c #D7DB00",
1030 "- c #D7D700",
1031 "; c #C7CB00",
1032 ": c #A6AA00",
1033 "> c #494900",
1034 ", c #8E8E00",
1035 "< c #DFE700",
1036 "1 c #F7FF00",
1037 "2 c #FFFF00",
1038 "3 c #E7EB00",
1039 "4 c #B6B600",
1040 "5 c #595900",
1041 "6 c #717500",
1042 "7 c #AEB200",
1043 "8 c #CFD300",
1044 "9 c #E7EF00",
1045 "0 c #EFF300",
1046 "q c #9EA200",
1047 "w c #F7FB00",
1048 "e c #F7F700",
1049 "r c #BEBE00",
1050 "t c #8E9200",
1051 "y c #EFF700",
1052 "u c #969A00",
1053 "i c #414500",
1054 "p c #595D00",
1055 "a c #E7E700",
1056 "s c #C7C700",
1057 "d c #797D00",
1058 "f c #BEC300",
1059 "g c #DFE300",
1060 "h c #868600",
1061 "j c #EFEF00",
1062 "k c #9E9E00",
1063 "l c #616500",
1064 "z c #DFDF00",
1065 "x c #868A00",
1066 "c c #969200",
1067 "v c #B6BA00",
1068 "b c #A6A600",
1069 "n c #8E8A00",
1070 "m c #717100",
1071 "M c #AEAE00",
1072 "N c #AEAA00",
1073 "B c #868200",
1074 " ............... ",
1075 " ....XoO+@##+O$%.... ",
1076 " ...%X&*========-;;:o... ",
1077 " ...>.>,<122222222222134@... ",
1078 " ..>5678912222222222222220q%.. ",
1079 " ..$.&-w2222222222222222222er>.. ",
1080 " ..O.t31222222222222222222222y4>.. ",
1081 " ...O5u3222222222222222222222222yri... ",
1082 " ..>p&a22222222222222222222222222wso.. ",
1083 " ..ids91222222222222222222222222222wfi.. ",
1084 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
1085 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
1086 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
1087 " ..o7y22222222v...r222222223hX.i82222221si.. ",
1088 "..io*222222222&...u22222222yt..%*22222220:%. ",
1089 "..>k02222222227...f222222222v..X=222222229t. ",
1090 "..dz12222222220ui:y2222222223d%qw222222221g. ",
1091 ".%vw222222222221y2222222222219*y2222222222wd.",
1092 ".X;2222222222222222222222222222222222222222b.",
1093 ".i*2222222222222222222222222222222222222222v.",
1094 ".i*2222222222222222222222222222222222222222;.",
1095 ".i*22222222222222222222222222222222222222228.",
1096 ".>*2222222222222222222222222222222222222222=.",
1097 ".i*22222222222222222222222222222222222222228.",
1098 ".i*2222222222222222222222222222222222222222;.",
1099 ".X*222222222222222222222222222222we12222222r.",
1100 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
1101 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
1102 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
1103 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
1104 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
1105 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
1106 " ...:e2222218mdz22222222222222a&$vw222220@...",
1107 " ...O-122222y:.u02222222222229q$uj222221r... ",
1108 " ..%&a1222223&573w2222222219NOxz122221z>... ",
1109 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
1110 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
1111 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
1112 " ..Xb9122222109g-****;<y22221zn%... ",
1113 " ..X&801222222222222222222w-h.... ",
1114 " ...o:=022222222222222221=lX... ",
1115 " ..X@:;3w2222222222210fO... ",
1116 " ...XX&v8<30000003-N@... ",
1117 " .....XmnbN:q&Bo.... ",
1118 " ............ "
1120 static char *msgs[] = {
1121 "Have a nice day!",
1122 "Focus follow mouse users will burn in hell!!!",
1123 "Mooo Canada!!!!",
1124 "Hi! My name is bobby...",
1125 "AHH! The neurotic monkeys are after me!",
1126 "WE GET SIGNAL",
1127 "HOW ARE YOU GENTLEMEN?",
1128 "WHAT YOU SAY??",
1129 "SOMEBODY SET UP US THE BOMB",
1130 "ALL YOUR BASE ARE BELONG TO US!",
1131 "Oh My God!!! Larry is back!"
1135 clicks++;
1137 if (!panel->timer && !broken && clicks > 0) {
1138 WMFont *font;
1140 panel->x = 0;
1141 clicks = 0;
1142 if (!panel->icon) {
1143 panel->icon = WMGetApplicationIconImage(panel->scr->wmscreen);
1144 if (!panel->icon) {
1145 broken = 1;
1146 return;
1147 } else {
1148 RColor color;
1150 color.red = 0xae; color.green = 0xaa;
1151 color.blue = 0xae; color.alpha = 0;
1153 panel->icon = RCloneImage(panel->icon);
1154 RCombineImageWithColor(panel->icon, &color);
1157 if (!panel->pic) {
1158 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1159 if (!panel->pic) {
1160 broken = 1;
1161 RReleaseImage(panel->icon);
1162 panel->icon = NULL;
1163 return;
1167 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1169 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1170 panel->cycle = 0;
1171 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1172 /* If we don't use a fixed font, scrolling will be jumpy */
1173 /* Alternatively we can draw text in a pixmap and scroll it smoothly */
1174 if ((panel->oldFont = WMGetLabelFont(panel->versionL))!=NULL)
1175 WMRetainFont(panel->oldFont);
1176 font = WMCreateFont(WMWidgetScreen(panel->versionL), "-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*");
1177 if (font) {
1178 WMSetLabelFont(panel->versionL, font);
1179 WMReleaseFont(font);
1181 WMSetLabelText(panel->versionL, "");
1182 } else if (panel->timer) {
1183 char version[20];
1185 panel->x = 0;
1186 clicks = 0;
1187 WMSetLabelImage(panel->logoL, panel->oldPix);
1188 WMReleasePixmap(panel->oldPix);
1189 panel->oldPix = NULL;
1191 WMDeleteTimerHandler(panel->timer);
1192 panel->timer = NULL;
1194 WMSetLabelFont(panel->versionL, panel->oldFont);
1195 if (panel->oldFont) {
1196 WMReleaseFont(panel->oldFont);
1197 panel->oldFont = NULL;
1199 snprintf(version, sizeof(version), _("Version %s"), VERSION);
1200 WMSetLabelText(panel->versionL, version);
1201 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1205 XEvent ev;
1206 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1207 ButtonPress, &ev));
1210 #endif /* SILLYNESS */
1213 void
1214 wShowInfoPanel(WScreen *scr)
1216 InfoPanel *panel;
1217 WMPixmap *logo;
1218 WMSize size;
1219 WMFont *font;
1220 char *strbuf = NULL;
1221 char buffer[256];
1222 Window parent;
1223 WWindow *wwin;
1224 char **strl;
1225 int i, width, sepWidth;
1226 char *visuals[] = {
1227 "StaticGray",
1228 "GrayScale",
1229 "StaticColor",
1230 "PseudoColor",
1231 "TrueColor",
1232 "DirectColor"
1236 if (thePanel) {
1237 if (thePanel->scr == scr) {
1238 wRaiseFrame(thePanel->wwin->frame->core);
1239 wSetFocusTo(scr, thePanel->wwin);
1241 return;
1244 panel = wmalloc(sizeof(InfoPanel));
1245 memset(panel, 0, sizeof(InfoPanel));
1247 panel->scr = scr;
1249 panel->win = WMCreateWindow(scr->wmscreen, "info");
1250 WMResizeWidget(panel->win, 390, 230);
1252 logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor*)NULL);
1253 if (!logo) {
1254 logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
1256 if (logo) {
1257 size = WMGetPixmapSize(logo);
1258 panel->logoL = WMCreateLabel(panel->win);
1259 WMResizeWidget(panel->logoL, 64, 64);
1260 WMMoveWidget(panel->logoL, 30, 20);
1261 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1262 WMSetLabelImage(panel->logoL, logo);
1263 #ifdef SILLYNESS
1264 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1265 handleLogoPush, panel);
1266 #endif
1267 WMReleasePixmap(logo);
1270 sepWidth = 3;
1271 panel->name1L = WMCreateLabel(panel->win);
1272 WMResizeWidget(panel->name1L, 240, 30 - sepWidth);
1273 WMMoveWidget(panel->name1L, 100, 30);
1275 if (WMIsAntialiasingEnabled(scr->wmscreen)) {
1276 font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1277 } else {
1278 font = WMCreateFont(scr->wmscreen, "-*-utopia-*-r-*-*-25-*");
1279 font = font ? font : WMBoldSystemFontOfSize(scr->wmscreen, 24);
1281 strbuf = "Window Maker";
1282 if (font) {
1283 width = WMWidthOfString(font, strbuf, strlen(strbuf));
1284 WMSetLabelFont(panel->name1L, font);
1285 WMReleaseFont(font);
1287 WMSetLabelTextAlignment(panel->name1L, WACenter);
1288 WMSetLabelText(panel->name1L, strbuf);
1290 panel->lineF = WMCreateFrame(panel->win);
1291 WMResizeWidget(panel->lineF, width, sepWidth);
1292 WMMoveWidget(panel->lineF, 100+(240-width)/2, 60 - sepWidth);
1293 WMSetFrameRelief(panel->lineF, WRSimple);
1294 WMSetWidgetBackgroundColor(panel->lineF, scr->black);
1296 panel->name2L = WMCreateLabel(panel->win);
1297 WMResizeWidget(panel->name2L, 240, 24);
1298 WMMoveWidget(panel->name2L, 100, 60);
1299 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1300 if (font) {
1301 WMSetLabelFont(panel->name2L, font);
1302 WMReleaseFont(font);
1303 font = NULL;
1305 WMSetLabelTextAlignment(panel->name2L, WACenter);
1306 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1308 snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
1309 panel->versionL = WMCreateLabel(panel->win);
1310 WMResizeWidget(panel->versionL, 310, 16);
1311 WMMoveWidget(panel->versionL, 30, 95);
1312 WMSetLabelTextAlignment(panel->versionL, WARight);
1313 WMSetLabelText(panel->versionL, buffer);
1314 WMSetLabelWraps(panel->versionL, False);
1316 panel->copyrL = WMCreateLabel(panel->win);
1317 WMResizeWidget(panel->copyrL, 360, 40);
1318 WMMoveWidget(panel->copyrL, 15, 185);
1319 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1320 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT_UTF8);
1321 /* we want the (c) character in the font, so don't use a FontSet here */
1322 // fix this -Dan font = WMCreateFontWithFlags(scr->wmscreen, "SystemFont-11", WFNormalFont);
1323 font = WMSystemFontOfSize(scr->wmscreen, 11);
1324 if (font) {
1325 WMSetLabelFont(panel->copyrL, font);
1326 WMReleaseFont(font);
1327 font = NULL;
1330 strbuf = NULL;
1331 snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
1332 (unsigned)scr->w_visual->visualid,
1333 visuals[scr->w_visual->class], scr->w_depth);
1335 strbuf = wstrappend(strbuf, buffer);
1337 switch (scr->w_depth) {
1338 case 15:
1339 strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
1340 break;
1341 case 16:
1342 strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
1343 break;
1344 case 24:
1345 case 32:
1346 strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
1347 break;
1348 default:
1349 snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1<<scr->w_depth);
1350 strbuf = wstrappend(strbuf, buffer);
1351 break;
1355 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1357 struct mallinfo ma = mallinfo();
1358 snprintf(buffer, sizeof(buffer),
1359 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1360 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
1362 strbuf = wstrappend(strbuf, buffer);
1364 #endif
1366 strbuf = wstrappend(strbuf, _("Supported image formats: "));
1367 strl = RSupportedFileFormats();
1368 for (i=0; strl[i]!=NULL; i++) {
1369 strbuf = wstrappend(strbuf, strl[i]);
1370 strbuf = wstrappend(strbuf, " ");
1373 strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
1375 char *list[8];
1376 char buf[80];
1377 int j = 0;
1379 #ifdef MWM_HINTS
1380 list[j++] = "MWM";
1381 #endif
1382 #ifdef KWM_HINTS
1383 list[j++] = "KDE";
1384 #endif
1385 #ifdef GNOME_STUFF
1386 list[j++] = "GNOME";
1387 #endif
1388 #ifdef OLWM_HINTS
1389 list[j++] = "OLWM";
1390 #endif
1392 buf[0] = 0;
1393 for (i = 0; i < j; i++) {
1394 if (i > 0) {
1395 if (i == j - 1)
1396 strcat(buf, _(" and "));
1397 else
1398 strcat(buf, ", ");
1400 strcat(buf, list[i]);
1402 strbuf = wstrappend(strbuf, buf);
1405 if (wPreferences.no_sound) {
1406 strbuf = wstrappend(strbuf, _("\nSound disabled"));
1407 } else {
1408 strbuf = wstrappend(strbuf, _("\nSound enabled"));
1411 #ifdef XFT
1412 strbuf = wstrappend(strbuf, _("; Antialiased text"));
1413 #endif
1416 panel->infoL = WMCreateLabel(panel->win);
1417 WMResizeWidget(panel->infoL, 350, 75);
1418 WMMoveWidget(panel->infoL, 15, 115);
1419 WMSetLabelText(panel->infoL, strbuf);
1420 font = WMSystemFontOfSize(scr->wmscreen, 11);
1421 if (font) {
1422 WMSetLabelFont(panel->infoL, font);
1423 WMReleaseFont(font);
1424 font = NULL;
1426 wfree(strbuf);
1429 WMRealizeWidget(panel->win);
1430 WMMapSubwidgets(panel->win);
1432 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1434 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1436 WMMapWidget(panel->win);
1439 WMPoint center = getCenter(scr, 382, 230);
1441 wwin = wManageInternalWindow(scr, parent, None, _("Info"),
1442 center.x, center.y,
1443 382, 230);
1446 WSETUFLAG(wwin, no_closable, 0);
1447 WSETUFLAG(wwin, no_close_button, 0);
1448 #ifdef XKB_BUTTON_HINT
1449 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1450 #endif
1451 wWindowUpdateButtonImages(wwin);
1452 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1453 wwin->frame->on_click_right = destroyInfoPanel;
1455 wWindowMap(wwin);
1457 panel->wwin = wwin;
1459 thePanel = panel;
1460 #ifdef SILLYNESS
1461 if (InitXThing(panel->scr)) {
1462 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1463 panel->cycle = 0;
1464 panel->x = 1;
1465 panel->str = _("Merry Christmas!");
1466 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1468 #endif
1473 ***********************************************************************
1474 * Legal Panel
1475 ***********************************************************************
1478 typedef struct {
1479 WScreen *scr;
1481 WWindow *wwin;
1483 WMWindow *win;
1485 WMLabel *licenseL;
1486 } LegalPanel;
1489 static LegalPanel *legalPanel = NULL;
1491 static void
1492 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1494 WMUnmapWidget(legalPanel->win);
1496 WMDestroyWidget(legalPanel->win);
1498 wUnmanageWindow(legalPanel->wwin, False, False);
1500 wfree(legalPanel);
1502 legalPanel = NULL;
1506 void
1507 wShowLegalPanel(WScreen *scr)
1509 LegalPanel *panel;
1510 Window parent;
1511 WWindow *wwin;
1513 if (legalPanel) {
1514 if (legalPanel->scr == scr) {
1515 wRaiseFrame(legalPanel->wwin->frame->core);
1516 wSetFocusTo(scr, legalPanel->wwin);
1518 return;
1521 panel = wmalloc(sizeof(LegalPanel));
1523 panel->scr = scr;
1525 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1526 WMResizeWidget(panel->win, 420, 250);
1529 panel->licenseL = WMCreateLabel(panel->win);
1530 WMSetLabelWraps(panel->licenseL, True);
1531 WMResizeWidget(panel->licenseL, 400, 230);
1532 WMMoveWidget(panel->licenseL, 10, 10);
1533 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1534 WMSetLabelText(panel->licenseL,
1535 _(" Window Maker is free software; you can redistribute it and/or\n"
1536 "modify it under the terms of the GNU General Public License as\n"
1537 "published by the Free Software Foundation; either version 2 of the\n"
1538 "License, or (at your option) any later version.\n\n"
1539 " Window Maker is distributed in the hope that it will be useful,\n"
1540 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1541 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1542 "See the GNU General Public License for more details.\n\n"
1543 " You should have received a copy of the GNU General Public\n"
1544 "License along with this program; if not, write to the Free Software\n"
1545 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
1546 "02111-1307, USA."));
1547 WMSetLabelRelief(panel->licenseL, WRGroove);
1549 WMRealizeWidget(panel->win);
1550 WMMapSubwidgets(panel->win);
1552 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1554 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1557 WMPoint center = getCenter(scr, 420, 250);
1559 wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
1560 center.x, center.y,
1561 420, 250);
1564 WSETUFLAG(wwin, no_closable, 0);
1565 WSETUFLAG(wwin, no_close_button, 0);
1566 wWindowUpdateButtonImages(wwin);
1567 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1568 #ifdef XKB_BUTTON_HINT
1569 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1570 #endif
1571 wwin->frame->on_click_right = destroyLegalPanel;
1573 panel->wwin = wwin;
1575 WMMapWidget(panel->win);
1577 wWindowMap(wwin);
1579 legalPanel = panel;
1584 ***********************************************************************
1585 * Crashing Dialog Panel
1586 ***********************************************************************
1589 extern WDDomain *WDWindowAttributes;
1592 typedef struct _CrashPanel {
1593 WMWindow *win; /* main window */
1595 WMLabel *iconL; /* application icon */
1596 WMLabel *nameL; /* title of panel */
1598 WMFrame *sepF; /* separator frame */
1600 WMLabel *noteL; /* Title of note */
1601 WMLabel *note2L; /* body of note with what happened */
1603 WMFrame *whatF; /* "what to do next" frame */
1604 WMPopUpButton *whatP; /* action selection popup button */
1606 WMButton *okB; /* ok button */
1608 Bool done; /* if finished with this dialog */
1609 int action; /* what to do after */
1611 KeyCode retKey;
1613 } CrashPanel;
1616 static void
1617 handleKeyPress(XEvent *event, void *clientData)
1619 CrashPanel *panel = (CrashPanel*)clientData;
1621 if (event->xkey.keycode == panel->retKey) {
1622 WMPerformButtonClick(panel->okB);
1627 static void
1628 okButtonCallback(void *self, void *clientData)
1630 CrashPanel *panel = (CrashPanel*)clientData;
1632 panel->done = True;
1636 static void
1637 setCrashAction(void *self, void *clientData)
1639 WMPopUpButton *pop = (WMPopUpButton*)self;
1640 CrashPanel *panel = (CrashPanel*)clientData;
1642 panel->action = WMGetPopUpButtonSelectedItem(pop);
1646 static WMPixmap*
1647 getWindowMakerIconImage(WMScreen *scr)
1649 WMPropList *dict, *key, *option, *value=NULL;
1650 WMPixmap *pix=NULL;
1651 char *path;
1653 WMPLSetCaseSensitive(True);
1655 key = WMCreatePLString("Logo.WMPanel");
1656 option = WMCreatePLString("Icon");
1658 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
1660 if (dict) {
1661 value = WMGetFromPLDictionary(dict, option);
1664 WMReleasePropList(key);
1665 WMReleasePropList(option);
1667 WMPLSetCaseSensitive(False);
1669 if (value && WMIsPLString(value)) {
1670 path = FindImage(wPreferences.icon_path, WMGetFromPLString(value));
1672 if (path) {
1673 RColor gray;
1675 gray.red = 0xae; gray.green = 0xaa;
1676 gray.blue = 0xae; gray.alpha = 0;
1678 pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
1679 wfree(path);
1683 return pix;
1687 #define PWIDTH 295
1688 #define PHEIGHT 345
1692 wShowCrashingDialogPanel(int whatSig)
1694 CrashPanel *panel;
1695 WMScreen *scr;
1696 WMFont *font;
1697 WMPixmap *logo;
1698 int screen_no, scr_width, scr_height;
1699 int action;
1700 char buf[256];
1702 panel = wmalloc(sizeof(CrashPanel));
1703 memset(panel, 0, sizeof(CrashPanel));
1705 screen_no = DefaultScreen(dpy);
1706 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1707 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1709 scr = WMCreateScreen(dpy, screen_no);
1710 if (!scr) {
1711 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1712 return WMAbort;
1715 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1717 panel->win = WMCreateWindow(scr, "crashingDialog");
1718 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1719 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1721 logo = getWindowMakerIconImage(scr);
1722 if (logo) {
1723 panel->iconL = WMCreateLabel(panel->win);
1724 WMResizeWidget(panel->iconL, 64, 64);
1725 WMMoveWidget(panel->iconL, 10, 10);
1726 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1727 WMSetLabelImage(panel->iconL, logo);
1730 panel->nameL = WMCreateLabel(panel->win);
1731 WMResizeWidget(panel->nameL, 190, 18);
1732 WMMoveWidget(panel->nameL, 80, 35);
1733 WMSetLabelTextAlignment(panel->nameL, WALeft);
1734 font = WMBoldSystemFontOfSize(scr, 18);
1735 WMSetLabelFont(panel->nameL, font);
1736 WMReleaseFont(font);
1737 WMSetLabelText(panel->nameL, _("Fatal error"));
1739 panel->sepF = WMCreateFrame(panel->win);
1740 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1741 WMMoveWidget(panel->sepF, -2, 80);
1743 panel->noteL = WMCreateLabel(panel->win);
1744 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1745 WMMoveWidget(panel->noteL, 10, 90);
1746 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1747 #ifdef SYS_SIGLIST_DECLARED
1748 snprintf(buf, sizeof(buf), _("Window Maker received signal %i\n(%s)."),
1749 whatSig, sys_siglist[whatSig]);
1750 #else
1751 snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
1752 #endif
1753 WMSetLabelText(panel->noteL, buf);
1755 panel->note2L = WMCreateLabel(panel->win);
1756 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1757 WMMoveWidget(panel->note2L, 10, 130);
1758 WMSetLabelTextAlignment(panel->note2L, WALeft);
1759 WMSetLabelText(panel->note2L,
1760 _(" This fatal error occured probably due to a bug."
1761 " Please fill the included BUGFORM and "
1762 "report it to bugs@windowmaker.org."));
1763 WMSetLabelWraps(panel->note2L, True);
1766 panel->whatF = WMCreateFrame(panel->win);
1767 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1768 WMMoveWidget(panel->whatF, 10, 240);
1769 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1771 panel->whatP = WMCreatePopUpButton(panel->whatF);
1772 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1773 WMMoveWidget(panel->whatP, 35, 20);
1774 WMSetPopUpButtonPullsDown(panel->whatP, False);
1775 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1776 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1777 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1778 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1779 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1780 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1781 panel->action = WMRestart;
1783 WMMapSubwidgets(panel->whatF);
1785 panel->okB = WMCreateCommandButton(panel->win);
1786 WMResizeWidget(panel->okB, 80, 26);
1787 WMMoveWidget(panel->okB, 205, 309);
1788 WMSetButtonText(panel->okB, _("OK"));
1789 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1790 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1791 WMSetButtonImagePosition(panel->okB, WIPRight);
1792 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1794 panel->done = 0;
1796 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1797 handleKeyPress, panel);
1799 WMRealizeWidget(panel->win);
1800 WMMapSubwidgets(panel->win);
1802 WMMapWidget(panel->win);
1804 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1806 while (!panel->done) {
1807 XEvent event;
1809 WMNextEvent(dpy, &event);
1810 WMHandleEvent(&event);
1813 action = panel->action;
1815 WMUnmapWidget(panel->win);
1816 WMDestroyWidget(panel->win);
1817 wfree(panel);
1819 return action;
1825 /*****************************************************************************
1826 * About GNUstep Panel
1827 *****************************************************************************/
1830 static void
1831 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1832 unsigned long blackPixel, unsigned long whitePixel)
1834 GC gc;
1835 XGCValues gcv;
1836 XRectangle rects[3];
1838 gcv.foreground = blackPixel;
1839 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1841 XFillArc(dpy, d, gc, width/45, height/45,
1842 width - 2*width/45, height - 2*height/45, 0, 360*64);
1844 rects[0].x = 0;
1845 rects[0].y = 37*height/45;
1846 rects[0].width = width/3;
1847 rects[0].height = height - rects[0].y;
1849 rects[1].x = rects[0].width;
1850 rects[1].y = height/2;
1851 rects[1].width = width - 2*width/3;
1852 rects[1].height = height - rects[1].y;
1854 rects[2].x = 2*width/3;
1855 rects[2].y = height - 37*height/45;
1856 rects[2].width = width/3;
1857 rects[2].height = height - rects[2].y;
1859 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1860 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1862 XSetForeground(dpy, gc, whitePixel);
1863 XFillArc(dpy, d, gc, width/45, height/45,
1864 width - 2*width/45, height - 2*height/45, 0, 360*64);
1866 XFreeGC(dpy, gc);
1870 typedef struct {
1871 WScreen *scr;
1873 WWindow *wwin;
1875 WMWindow *win;
1877 WMLabel *gstepL;
1878 WMLabel *textL;
1879 } GNUstepPanel;
1882 static GNUstepPanel *gnustepPanel = NULL;
1884 static void
1885 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1887 WMUnmapWidget(gnustepPanel->win);
1889 WMDestroyWidget(gnustepPanel->win);
1891 wUnmanageWindow(gnustepPanel->wwin, False, False);
1893 wfree(gnustepPanel);
1895 gnustepPanel = NULL;
1899 void
1900 wShowGNUstepPanel(WScreen *scr)
1902 GNUstepPanel *panel;
1903 Window parent;
1904 WWindow *wwin;
1905 WMPixmap *pixmap;
1906 WMColor *color;
1908 if (gnustepPanel) {
1909 if (gnustepPanel->scr == scr) {
1910 wRaiseFrame(gnustepPanel->wwin->frame->core);
1911 wSetFocusTo(scr, gnustepPanel->wwin);
1913 return;
1916 panel = wmalloc(sizeof(GNUstepPanel));
1918 panel->scr = scr;
1920 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1921 WMResizeWidget(panel->win, 325, 205);
1923 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1924 WMScreenDepth(scr->wmscreen), True);
1926 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1928 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1929 WMColorPixel(color), scr->white_pixel);
1931 WMReleaseColor(color);
1933 XSetForeground(dpy, scr->mono_gc, 0);
1934 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1935 130, 130);
1936 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1938 panel->gstepL = WMCreateLabel(panel->win);
1939 WMResizeWidget(panel->gstepL, 285, 64);
1940 WMMoveWidget(panel->gstepL, 20, 0);
1941 WMSetLabelTextAlignment(panel->gstepL, WARight);
1942 WMSetLabelText(panel->gstepL, "GNUstep");
1944 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1946 WMSetLabelFont(panel->gstepL, font);
1947 WMReleaseFont(font);
1950 panel->textL = WMCreateLabel(panel->win);
1951 WMResizeWidget(panel->textL, 305, 140);
1952 WMMoveWidget(panel->textL, 10, 50);
1953 WMSetLabelTextAlignment(panel->textL, WARight);
1954 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1955 WMSetLabelText(panel->textL,
1956 _("Window Maker is part of the GNUstep project.\n"\
1957 "The GNUstep project aims to create a free\n"\
1958 "implementation of the OpenStep(tm) specification\n"\
1959 "which is a object-oriented framework for\n"\
1960 "creating advanced graphical, multi-platform\n"\
1961 "applications. Additionally, a development and\n"\
1962 "user desktop enviroment will be created on top\n"\
1963 "of the framework. For more information about\n"\
1964 "GNUstep, please visit: www.gnustep.org"));
1965 WMSetLabelImage(panel->textL, pixmap);
1967 WMReleasePixmap(pixmap);
1969 WMRealizeWidget(panel->win);
1970 WMMapSubwidgets(panel->win);
1972 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1974 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1977 WMPoint center = getCenter(scr, 325, 200);
1979 wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
1980 center.x, center.y,
1981 325, 200);
1984 WSETUFLAG(wwin, no_closable, 0);
1985 WSETUFLAG(wwin, no_close_button, 0);
1986 wWindowUpdateButtonImages(wwin);
1987 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1988 #ifdef XKB_BUTTON_HINT
1989 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1990 #endif
1991 wwin->frame->on_click_right = destroyGNUstepPanel;
1993 panel->wwin = wwin;
1995 WMMapWidget(panel->win);
1997 wWindowMap(wwin);
1999 gnustepPanel = panel;