- Fixed userdefaults in WINGs not to synchronize on exit a domain that is
[wmaker-crm.git] / src / dialog.c
blob4ece8359bda1540ce795884c39ff6b2b03cb633c
1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 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 WMPoint pt;
74 #ifdef XINERAMA
75 WMRect rect;
77 rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
79 pt.x = rect.pos.x + (rect.size.width - width)/2;
80 pt.y = rect.pos.y + (rect.size.height - height)/2;
81 #else
82 pt.x = (scr->scr_width - width) / 2;
83 pt.y = (scr->scr_height - height) / 2;
84 #endif
86 return pt;
91 int
92 wMessageDialog(WScreen *scr, char *title, char *message,
93 char *defBtn, char *altBtn, char *othBtn)
95 WMAlertPanel *panel;
96 Window parent;
97 WWindow *wwin;
98 int result;
99 WMPoint center;
101 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
102 defBtn, altBtn, othBtn);
104 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
106 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
109 center = getCenter(scr, 400, 180);
110 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
111 400, 180);
112 wwin->client_leader = WMWidgetXID(panel->win);
114 WMMapWidget(panel->win);
116 wWindowMap(wwin);
118 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
120 result = panel->result;
122 WMUnmapWidget(panel->win);
124 wUnmanageWindow(wwin, False, False);
126 WMDestroyAlertPanel(panel);
128 XDestroyWindow(dpy, parent);
130 return result;
134 void
135 toggleSaveSession(WMWidget *w, void *data)
137 wPreferences.save_session_on_exit = WMGetButtonSelected((WMButton *) w);
142 wExitDialog(WScreen *scr, char *title, char *message,
143 char *defBtn, char *altBtn, char *othBtn)
145 WMAlertPanel *panel;
146 WMButton *saveSessionBtn;
147 Window parent;
148 WWindow *wwin;
149 int result;
151 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
152 defBtn, altBtn, othBtn);
154 /* add save session button */
155 saveSessionBtn = WMCreateSwitchButton(panel->hbox);
156 WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
157 WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn),
158 False, True, 200, 0, 0);
159 WMSetButtonText(saveSessionBtn, _("Save workspace state"));
160 WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
161 WMRealizeWidget(saveSessionBtn);
162 WMMapWidget(saveSessionBtn);
164 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
166 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
168 wwin = wManageInternalWindow(scr, parent, None, NULL,
169 (scr->scr_width - 400)/2,
170 (scr->scr_height - 180)/2, 400, 180);
171 wwin->client_leader = WMWidgetXID(panel->win);
173 WMMapWidget(panel->win);
175 wWindowMap(wwin);
177 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
179 result = panel->result;
181 WMUnmapWidget(panel->win);
183 wUnmanageWindow(wwin, False, False);
185 WMDestroyAlertPanel(panel);
187 XDestroyWindow(dpy, parent);
189 return result;
194 wInputDialog(WScreen *scr, char *title, char *message, char **text)
196 WWindow *wwin;
197 Window parent;
198 WMInputPanel *panel;
199 char *result;
200 WMPoint center;
202 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
203 _("OK"), _("Cancel"));
206 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
207 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
209 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
211 center = getCenter(scr, 320, 160);
212 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y,
213 320, 160);
215 wwin->client_leader = WMWidgetXID(panel->win);
217 WMMapWidget(panel->win);
219 wWindowMap(wwin);
221 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
223 if (panel->result == WAPRDefault)
224 result = WMGetTextFieldText(panel->text);
225 else
226 result = NULL;
228 wUnmanageWindow(wwin, False, False);
230 WMDestroyInputPanel(panel);
232 XDestroyWindow(dpy, parent);
234 if (result==NULL)
235 return False;
236 else {
237 if (*text)
238 wfree(*text);
239 *text = result;
241 return True;
247 *****************************************************************
248 * Icon Selection Panel
249 *****************************************************************
252 typedef struct IconPanel {
254 WScreen *scr;
256 WMWindow *win;
258 WMLabel *dirLabel;
259 WMLabel *iconLabel;
261 WMList *dirList;
262 WMList *iconList;
263 WMFont *normalfont;
265 WMButton *previewButton;
267 WMLabel *iconView;
269 WMLabel *fileLabel;
270 WMTextField *fileField;
272 WMButton *okButton;
273 WMButton *cancelButton;
274 #if 0
275 WMButton *chooseButton;
276 #endif
277 short done;
278 short result;
279 short preview;
280 } IconPanel;
284 static void
285 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
287 struct dirent *dentry;
288 DIR *dir;
289 char pbuf[PATH_MAX+16];
290 char *apath;
291 IconPanel *panel = WMGetHangedData(lPtr);
293 panel->preview = False;
295 apath = wexpandpath(path);
296 dir = opendir(apath);
298 if (!dir) {
299 char *msg;
300 char *tmp;
301 tmp = _("Could not open directory ");
302 msg = wmalloc(strlen(tmp)+strlen(path)+6);
303 strcpy(msg, tmp);
304 strcat(msg, path);
306 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
307 wfree(msg);
308 wfree(apath);
309 return;
312 /* list contents in the column */
313 while ((dentry = readdir(dir))) {
314 struct stat statb;
316 if (strcmp(dentry->d_name, ".")==0 ||
317 strcmp(dentry->d_name, "..")==0)
318 continue;
320 strcpy(pbuf, apath);
321 strcat(pbuf, "/");
322 strcat(pbuf, dentry->d_name);
324 if (stat(pbuf, &statb)<0)
325 continue;
327 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
328 && statb.st_mode & (S_IFREG|S_IFLNK)) {
329 WMAddListItem(lPtr, dentry->d_name);
332 WMSortListItems(lPtr);
334 closedir(dir);
335 wfree(apath);
336 panel->preview = True;
341 static void
342 setViewedImage(IconPanel *panel, char *file)
344 WMPixmap *pixmap;
345 RColor color;
347 color.red = 0xae;
348 color.green = 0xaa;
349 color.blue = 0xae;
350 color.alpha = 0;
351 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
352 file, &color);
353 if (!pixmap) {
354 WMSetButtonEnabled(panel->okButton, False);
356 WMSetLabelText(panel->iconView, _("Could not load image file "));
358 WMSetLabelImage(panel->iconView, NULL);
359 } else {
360 WMSetButtonEnabled(panel->okButton, True);
362 WMSetLabelText(panel->iconView, NULL);
363 WMSetLabelImage(panel->iconView, pixmap);
364 WMReleasePixmap(pixmap);
369 static void
370 listCallback(void *self, void *data)
372 WMList *lPtr = (WMList*)self;
373 IconPanel *panel = (IconPanel*)data;
374 char *path;
376 if (lPtr==panel->dirList) {
377 WMListItem *item = WMGetListSelectedItem(lPtr);
379 if (item == NULL)
380 return;
381 path = item->text;
383 WMSetTextFieldText(panel->fileField, path);
385 WMSetLabelImage(panel->iconView, NULL);
387 WMSetButtonEnabled(panel->okButton, False);
389 WMClearList(panel->iconList);
390 listPixmaps(panel->scr, panel->iconList, path);
391 } else {
392 char *tmp, *iconFile;
393 WMListItem *item = WMGetListSelectedItem(panel->dirList);
395 if (item == NULL)
396 return;
397 path = item->text;
398 tmp = wexpandpath(path);
400 item = WMGetListSelectedItem(panel->iconList);
401 if (item == NULL)
402 return;
403 iconFile = item->text;
405 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
406 strcpy(path, tmp);
407 strcat(path, "/");
408 strcat(path, iconFile);
409 wfree(tmp);
410 WMSetTextFieldText(panel->fileField, path);
411 setViewedImage(panel, path);
412 wfree(path);
417 static void
418 listIconPaths(WMList *lPtr)
420 char *paths;
421 char *path;
423 paths = wstrdup(wPreferences.icon_path);
425 path = strtok(paths, ":");
427 do {
428 char *tmp;
430 tmp = wexpandpath(path);
431 /* do not sort, because the order implies the order of
432 * directories searched */
433 if (access(tmp, X_OK)==0)
434 WMAddListItem(lPtr, path);
435 wfree(tmp);
436 } while ((path=strtok(NULL, ":"))!=NULL);
438 wfree(paths);
442 void
443 drawIconProc(WMList *lPtr, int index, Drawable d, char *text, int state,
444 WMRect *rect)
446 IconPanel *panel = WMGetHangedData(lPtr);
447 WScreen *scr = panel->scr;
448 GC gc = scr->draw_gc;
449 GC copygc = scr->copy_gc;
450 char *file, *dirfile;
451 WMPixmap *pixmap;
452 WMColor *back;
453 WMSize size;
454 WMScreen *wmscr = WMWidgetScreen(panel->win);
455 RColor color;
456 int x, y, width, height, len;
458 if(!panel->preview) return;
460 x = rect->pos.x;
461 y = rect->pos.y;
462 width = rect->size.width;
463 height = rect->size.height;
465 back = (state & WLDSSelected) ? scr->white : scr->gray;
467 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
468 len = strlen(dirfile)+strlen(text)+4;
469 file = wmalloc(len);
470 snprintf(file, len, "%s/%s", dirfile, text);
471 wfree(dirfile);
473 color.red = WMRedComponentOfColor(back) >> 8;
474 color.green = WMGreenComponentOfColor(back) >> 8;
475 color.blue = WMBlueComponentOfColor(back) >> 8;
476 color.alpha = WMGetColorAlpha(back) >> 8;
478 pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
479 wfree(file);
481 if (!pixmap) {
482 /*WMRemoveListItem(lPtr, index);*/
483 return;
486 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
488 XSetClipMask(dpy, gc, None);
489 /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54);*/
490 XDrawLine(dpy, d, WMColorGC(scr->white), x, y+height-1, x+width, y+height-1);
492 size = WMGetPixmapSize(pixmap);
494 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
495 XSetClipOrigin(dpy, copygc, x + (width-size.width)/2, y+2);
496 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
497 size.width>100?100:size.width, size.height>64?64:size.height,
498 x + (width-size.width)/2, y+2);
501 int i,j;
502 int fheight = WMFontHeight(panel->normalfont);
503 int tlen = strlen(text);
504 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
505 int ofx, ofy;
507 ofx = x + (width - twidth)/2;
508 ofy = y + 64 - fheight;
510 for(i=-1;i<2;i++)
511 for(j=-1;j<2;j++)
512 WMDrawString(wmscr, d, scr->white, panel->normalfont,
513 ofx+i, ofy+j, text, tlen);
515 WMDrawString(wmscr, d, scr->black, panel->normalfont, ofx, ofy,
516 text, tlen);
519 WMReleasePixmap(pixmap);
520 /* I hope it is better to do not use cache / on my box it is fast nuff */
521 XFlush(dpy);
525 static void
526 buttonCallback(void *self, void *clientData)
528 WMButton *bPtr = (WMButton*)self;
529 IconPanel *panel = (IconPanel*)clientData;
532 if (bPtr==panel->okButton) {
533 panel->done = True;
534 panel->result = True;
535 } else if (bPtr==panel->cancelButton) {
536 panel->done = True;
537 panel->result = False;
538 } else if (bPtr==panel->previewButton) {
539 /**** Previewer ****/
540 WMSetButtonEnabled(bPtr, False);
541 WMSetListUserDrawItemHeight(panel->iconList, 68);
542 WMSetListUserDrawProc(panel->iconList, drawIconProc);
543 WMRedisplayWidget(panel->iconList);
544 /* for draw proc to access screen/gc */
545 /*** end preview ***/
547 #if 0
548 else if (bPtr==panel->chooseButton) {
549 WMOpenPanel *op;
551 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
553 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
554 char *path;
555 path = WMGetFilePanelFile(op);
556 WMSetTextFieldText(panel->fileField, path);
557 setViewedImage(panel, path);
558 wfree(path);
560 WMDestroyFilePanel(op);
562 #endif
566 static void
567 keyPressHandler(XEvent *event, void *data)
569 IconPanel *panel = (IconPanel*)data;
570 char buffer[32];
571 int count;
572 KeySym ksym;
573 int iidx;
574 int didx;
575 int item;
576 WMList *list = NULL;
578 if (event->type == KeyRelease)
579 return;
581 buffer[0] = 0;
582 count = XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
585 iidx = WMGetListSelectedItemRow(panel->iconList);
586 didx = WMGetListSelectedItemRow(panel->dirList);
588 switch (ksym) {
589 case XK_Up:
590 if (iidx > 0)
591 item = iidx-1;
592 else
593 item = iidx;
594 list = panel->iconList;
595 break;
596 case XK_Down:
597 if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
598 item = iidx+1;
599 else
600 item = iidx;
601 list = panel->iconList;
602 break;
603 case XK_Home:
604 item = 0;
605 list = panel->iconList;
606 break;
607 case XK_End:
608 item = WMGetListNumberOfRows(panel->iconList) - 1;
609 list = panel->iconList;
610 break;
611 case XK_Next:
612 if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
613 item = didx + 1;
614 else
615 item = didx;
616 list = panel->dirList;
617 break;
618 case XK_Prior:
619 if (didx > 0)
620 item = didx - 1;
621 else
622 item = 0;
623 list = panel->dirList;
624 break;
625 case XK_Return:
626 WMPerformButtonClick(panel->okButton);
627 break;
628 case XK_Escape:
629 WMPerformButtonClick(panel->cancelButton);
630 break;
633 if (list) {
634 WMSelectListItem(list, item);
635 WMSetListPosition(list, item - 5);
636 listCallback(list, panel);
642 Bool
643 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
645 WWindow *wwin;
646 Window parent;
647 IconPanel *panel;
648 WMColor *color;
649 WMFont *boldFont;
651 panel = wmalloc(sizeof(IconPanel));
652 memset(panel, 0, sizeof(IconPanel));
654 panel->scr = scr;
656 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
657 WMResizeWidget(panel->win, 450, 280);
659 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask|KeyReleaseMask,
660 keyPressHandler, panel);
663 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
664 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
666 panel->dirLabel = WMCreateLabel(panel->win);
667 WMResizeWidget(panel->dirLabel, 200, 20);
668 WMMoveWidget(panel->dirLabel, 10, 7);
669 WMSetLabelText(panel->dirLabel, _("Directories"));
670 WMSetLabelFont(panel->dirLabel, boldFont);
671 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
673 WMSetLabelRelief(panel->dirLabel, WRSunken);
675 panel->iconLabel = WMCreateLabel(panel->win);
676 WMResizeWidget(panel->iconLabel, 140, 20);
677 WMMoveWidget(panel->iconLabel, 215, 7);
678 WMSetLabelText(panel->iconLabel, _("Icons"));
679 WMSetLabelFont(panel->iconLabel, boldFont);
680 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
682 WMReleaseFont(boldFont);
684 color = WMWhiteColor(scr->wmscreen);
685 WMSetLabelTextColor(panel->dirLabel, color);
686 WMSetLabelTextColor(panel->iconLabel, color);
687 WMReleaseColor(color);
689 color = WMDarkGrayColor(scr->wmscreen);
690 WMSetWidgetBackgroundColor(panel->iconLabel, color);
691 WMSetWidgetBackgroundColor(panel->dirLabel, color);
692 WMReleaseColor(color);
694 WMSetLabelRelief(panel->iconLabel, WRSunken);
696 panel->dirList = WMCreateList(panel->win);
697 WMResizeWidget(panel->dirList, 200, 170);
698 WMMoveWidget(panel->dirList, 10, 30);
699 WMSetListAction(panel->dirList, listCallback, panel);
701 panel->iconList = WMCreateList(panel->win);
702 WMResizeWidget(panel->iconList, 140, 170);
703 WMMoveWidget(panel->iconList, 215, 30);
704 WMSetListAction(panel->iconList, listCallback, panel);
706 WMHangData(panel->iconList,panel);
708 panel->previewButton = WMCreateCommandButton(panel->win);
709 WMResizeWidget(panel->previewButton, 75, 26);
710 WMMoveWidget(panel->previewButton, 365, 130);
711 WMSetButtonText(panel->previewButton, _("Preview"));
712 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
714 panel->iconView = WMCreateLabel(panel->win);
715 WMResizeWidget(panel->iconView, 75, 75);
716 WMMoveWidget(panel->iconView, 365, 40);
717 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
718 WMSetLabelRelief(panel->iconView, WRSunken);
719 WMSetLabelTextAlignment(panel->iconView, WACenter);
721 panel->fileLabel = WMCreateLabel(panel->win);
722 WMResizeWidget(panel->fileLabel, 80, 20);
723 WMMoveWidget(panel->fileLabel, 10, 210);
724 WMSetLabelText(panel->fileLabel, _("File Name:"));
726 panel->fileField = WMCreateTextField(panel->win);
727 WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
728 WMResizeWidget(panel->fileField, 345, 20);
729 WMMoveWidget(panel->fileField, 95, 210);
730 WMSetTextFieldEditable(panel->fileField, False);
732 panel->okButton = WMCreateCommandButton(panel->win);
733 WMResizeWidget(panel->okButton, 80, 26);
734 WMMoveWidget(panel->okButton, 360, 240);
735 WMSetButtonText(panel->okButton, _("OK"));
736 WMSetButtonEnabled(panel->okButton, False);
737 WMSetButtonAction(panel->okButton, buttonCallback, panel);
739 panel->cancelButton = WMCreateCommandButton(panel->win);
740 WMResizeWidget(panel->cancelButton, 80, 26);
741 WMMoveWidget(panel->cancelButton, 270, 240);
742 WMSetButtonText(panel->cancelButton, _("Cancel"));
743 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
744 #if 0
745 panel->chooseButton = WMCreateCommandButton(panel->win);
746 WMResizeWidget(panel->chooseButton, 110, 26);
747 WMMoveWidget(panel->chooseButton, 150, 240);
748 WMSetButtonText(panel->chooseButton, _("Choose File"));
749 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
750 #endif
751 WMRealizeWidget(panel->win);
752 WMMapSubwidgets(panel->win);
754 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
756 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
759 char *tmp;
760 int len = (instance ? strlen(instance) : 0)
761 + (class ? strlen(class) : 0) + 32;
762 WMPoint center;
764 tmp = wmalloc(len);
766 if (tmp && (instance || class))
767 snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
768 else
769 strcpy(tmp, _("Icon Chooser"));
771 center = getCenter(scr, 450, 280);
773 wwin = wManageInternalWindow(scr, parent, None, tmp, center.x,center.y,
774 450, 280);
775 wfree(tmp);
778 /* put icon paths in the list */
779 listIconPaths(panel->dirList);
781 WMMapWidget(panel->win);
783 wWindowMap(wwin);
785 while (!panel->done) {
786 XEvent event;
788 WMNextEvent(dpy, &event);
789 WMHandleEvent(&event);
792 if (panel->result) {
793 char *defaultPath, *wantedPath;
795 /* check if the file the user selected is not the one that
796 * would be loaded by default with the current search path */
797 *file = WMGetListSelectedItem(panel->iconList)->text;
798 if ((*file)[0]==0) {
799 wfree(*file);
800 *file = NULL;
801 } else {
802 defaultPath = FindImage(wPreferences.icon_path, *file);
803 wantedPath = WMGetTextFieldText(panel->fileField);
804 /* if the file is not the default, use full path */
805 if (strcmp(wantedPath, defaultPath)!=0) {
806 *file = wantedPath;
807 } else {
808 *file = wstrdup(*file);
809 wfree(wantedPath);
811 wfree(defaultPath);
813 } else {
814 *file = NULL;
817 WMReleaseFont(panel->normalfont);
819 WMUnmapWidget(panel->win);
821 WMDestroyWidget(panel->win);
823 wUnmanageWindow(wwin, False, False);
825 wfree(panel);
827 XDestroyWindow(dpy, parent);
829 return panel->result;
834 ***********************************************************************
835 * Info Panel
836 ***********************************************************************
840 typedef struct {
841 WScreen *scr;
843 WWindow *wwin;
845 WMWindow *win;
847 WMLabel *logoL;
848 WMLabel *name1L;
849 WMFrame *lineF;
850 WMLabel *name2L;
852 WMLabel *versionL;
854 WMLabel *infoL;
856 WMLabel *copyrL;
858 #ifdef SILLYNESS
859 WMHandlerID timer;
860 int cycle;
861 RImage *icon;
862 RImage *pic;
863 WMPixmap *oldPix;
864 WMFont *oldFont;
865 char *str;
866 int x;
867 #endif
868 } InfoPanel;
872 #define COPYRIGHT_TEXT \
873 "Copyright \xa9 1997-2002 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
874 "Copyright \xa9 1998-2002 Dan Pascu <dan@windowmaker.org>"
878 static InfoPanel *thePanel = NULL;
880 static void
881 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
883 #ifdef SILLYNESS
884 if (thePanel->timer) {
885 WMDeleteTimerHandler(thePanel->timer);
887 if (thePanel->oldPix) {
888 WMReleasePixmap(thePanel->oldPix);
890 if (thePanel->oldFont) {
891 WMReleaseFont(thePanel->oldFont);
893 if (thePanel->icon) {
894 RReleaseImage(thePanel->icon);
896 if (thePanel->pic) {
897 RReleaseImage(thePanel->pic);
899 #endif /* SILLYNESS */
900 WMUnmapWidget(thePanel);
902 wUnmanageWindow(thePanel->wwin, False, False);
904 WMDestroyWidget(thePanel->win);
906 wfree(thePanel);
908 thePanel = NULL;
912 #ifdef SILLYNESS
914 extern WMPixmap *DoXThing();
915 extern Bool InitXThing();
917 static void
918 logoPushCallback(void *data)
920 InfoPanel *panel = (InfoPanel*)data;
921 char buffer[512];
922 int i;
923 static int oldi = 0;
924 int len;
925 static int jingobeu[] = {
926 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
927 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
928 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
930 static int c = 0;
932 if (panel->x) {
933 XKeyboardControl kc;
934 XKeyboardState ksave;
935 unsigned long mask = KBBellPitch|KBBellDuration|KBBellPercent;
937 XGetKeyboardControl(dpy, &ksave);
939 if (panel->x > 0) {
940 if(jingobeu[panel->x-1]==0) {
941 panel->x=-1;
942 } else if (jingobeu[panel->x-1]<0) {
943 panel->x++;
944 c=jingobeu[panel->x-1]/50;
945 panel->x++;
946 } else if (c==0) {
947 kc.bell_percent=50;
948 kc.bell_pitch=jingobeu[panel->x-1];
949 panel->x++;
950 kc.bell_duration=jingobeu[panel->x-1];
951 c=jingobeu[panel->x-1]/50;
952 panel->x++;
953 XChangeKeyboardControl(dpy, mask, &kc);
954 XBell(dpy, 50);
955 XFlush(dpy);
956 } else {
957 c--;
960 if (!(panel->cycle % 4)) {
961 WMPixmap *p;
963 p = DoXThing(panel->wwin);
964 WMSetLabelImage(panel->logoL, p);
966 kc.bell_pitch = ksave.bell_pitch;
967 kc.bell_percent = ksave.bell_percent;
968 kc.bell_duration = ksave.bell_duration;
969 XChangeKeyboardControl(dpy, mask, &kc);
970 } else if (panel->cycle < 30) {
971 RImage *image;
972 WMPixmap *pix;
973 RColor gray;
975 gray.red = 0xae; gray.green = 0xaa;
976 gray.blue = 0xae; gray.alpha = 0;
978 image = RScaleImage(panel->icon, panel->pic->width, panel->pic->height);
979 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
980 pix = WMCreateBlendedPixmapFromRImage(panel->scr->wmscreen, image, &gray);
981 RReleaseImage(image);
982 WMSetLabelImage(panel->logoL, pix);
983 WMReleasePixmap(pix);
986 /* slow down text a little */
987 i = (int)(panel->cycle * 50.0/85.0)%200;
989 if (i != oldi) {
990 len = strlen(panel->str);
992 strncpy(buffer, panel->str, i<len ? i : len);
993 if (i >= len)
994 memset(&buffer[len], ' ', i-len);
996 strncpy(buffer, panel->str, i<len ? i : len);
997 if (i >= len)
998 memset(&buffer[len], ' ', i-len);
999 buffer[i]=0;
1001 WMSetLabelText(panel->versionL, buffer);
1003 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1005 oldi = i;
1008 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1009 panel->cycle++;
1013 static void
1014 handleLogoPush(XEvent *event, void *data)
1016 InfoPanel *panel = (InfoPanel*)data;
1017 static int broken = 0;
1018 static int clicks = 0;
1019 static char *pic_data[] = {
1020 "45 45 57 1",
1021 " c None",
1022 ". c #000000",
1023 "X c #383C00",
1024 "o c #515500",
1025 "O c #616100",
1026 "+ c #616900",
1027 "@ c #696D00",
1028 "# c #697100",
1029 "$ c #495100",
1030 "% c #202800",
1031 "& c #969600",
1032 "* c #CFCF00",
1033 "= c #D7DB00",
1034 "- c #D7D700",
1035 "; c #C7CB00",
1036 ": c #A6AA00",
1037 "> c #494900",
1038 ", c #8E8E00",
1039 "< c #DFE700",
1040 "1 c #F7FF00",
1041 "2 c #FFFF00",
1042 "3 c #E7EB00",
1043 "4 c #B6B600",
1044 "5 c #595900",
1045 "6 c #717500",
1046 "7 c #AEB200",
1047 "8 c #CFD300",
1048 "9 c #E7EF00",
1049 "0 c #EFF300",
1050 "q c #9EA200",
1051 "w c #F7FB00",
1052 "e c #F7F700",
1053 "r c #BEBE00",
1054 "t c #8E9200",
1055 "y c #EFF700",
1056 "u c #969A00",
1057 "i c #414500",
1058 "p c #595D00",
1059 "a c #E7E700",
1060 "s c #C7C700",
1061 "d c #797D00",
1062 "f c #BEC300",
1063 "g c #DFE300",
1064 "h c #868600",
1065 "j c #EFEF00",
1066 "k c #9E9E00",
1067 "l c #616500",
1068 "z c #DFDF00",
1069 "x c #868A00",
1070 "c c #969200",
1071 "v c #B6BA00",
1072 "b c #A6A600",
1073 "n c #8E8A00",
1074 "m c #717100",
1075 "M c #AEAE00",
1076 "N c #AEAA00",
1077 "B c #868200",
1078 " ............... ",
1079 " ....XoO+@##+O$%.... ",
1080 " ...%X&*========-;;:o... ",
1081 " ...>.>,<122222222222134@... ",
1082 " ..>5678912222222222222220q%.. ",
1083 " ..$.&-w2222222222222222222er>.. ",
1084 " ..O.t31222222222222222222222y4>.. ",
1085 " ...O5u3222222222222222222222222yri... ",
1086 " ..>p&a22222222222222222222222222wso.. ",
1087 " ..ids91222222222222222222222222222wfi.. ",
1088 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
1089 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
1090 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
1091 " ..o7y22222222v...r222222223hX.i82222221si.. ",
1092 "..io*222222222&...u22222222yt..%*22222220:%. ",
1093 "..>k02222222227...f222222222v..X=222222229t. ",
1094 "..dz12222222220ui:y2222222223d%qw222222221g. ",
1095 ".%vw222222222221y2222222222219*y2222222222wd.",
1096 ".X;2222222222222222222222222222222222222222b.",
1097 ".i*2222222222222222222222222222222222222222v.",
1098 ".i*2222222222222222222222222222222222222222;.",
1099 ".i*22222222222222222222222222222222222222228.",
1100 ".>*2222222222222222222222222222222222222222=.",
1101 ".i*22222222222222222222222222222222222222228.",
1102 ".i*2222222222222222222222222222222222222222;.",
1103 ".X*222222222222222222222222222222we12222222r.",
1104 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
1105 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
1106 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
1107 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
1108 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
1109 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
1110 " ...:e2222218mdz22222222222222a&$vw222220@...",
1111 " ...O-122222y:.u02222222222229q$uj222221r... ",
1112 " ..%&a1222223&573w2222222219NOxz122221z>... ",
1113 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
1114 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
1115 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
1116 " ..Xb9122222109g-****;<y22221zn%... ",
1117 " ..X&801222222222222222222w-h.... ",
1118 " ...o:=022222222222222221=lX... ",
1119 " ..X@:;3w2222222222210fO... ",
1120 " ...XX&v8<30000003-N@... ",
1121 " .....XmnbN:q&Bo.... ",
1122 " ............ "
1124 static char *msgs[] = {
1125 "Have a nice day!",
1126 "Focus follow mouse users will burn in hell!!!",
1127 "Mooo Canada!!!!",
1128 "Hi! My name is bobby...",
1129 "AHH! The neurotic monkeys are after me!",
1130 "WE GET SIGNAL",
1131 "HOW ARE YOU GENTLEMEN?",
1132 "WHAT YOU SAY??",
1133 "SOMEBODY SET UP US THE BOMB",
1134 "ALL YOUR BASE ARE BELONG TO US!",
1135 "Oh My God!!! Larry is back!"
1139 clicks++;
1141 if (!panel->timer && !broken && clicks > 0) {
1142 WMFont *font;
1144 panel->x = 0;
1145 clicks = 0;
1146 if (!panel->icon) {
1147 panel->icon = WMGetApplicationIconImage(panel->scr->wmscreen);
1148 if (!panel->icon) {
1149 broken = 1;
1150 return;
1151 } else {
1152 RColor color;
1154 color.red = 0xae; color.green = 0xaa;
1155 color.blue = 0xae; color.alpha = 0;
1157 panel->icon = RCloneImage(panel->icon);
1158 RCombineImageWithColor(panel->icon, &color);
1161 if (!panel->pic) {
1162 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1163 if (!panel->pic) {
1164 broken = 1;
1165 RReleaseImage(panel->icon);
1166 panel->icon = NULL;
1167 return;
1171 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1173 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1174 panel->cycle = 0;
1175 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1176 /* If we don't use a fixed font, scrolling will be jumpy */
1177 /* Alternatively we can draw text in a pixmap and scroll it smoothly */
1178 if ((panel->oldFont = WMGetLabelFont(panel->versionL))!=NULL)
1179 WMRetainFont(panel->oldFont);
1180 font = WMCreateFont(WMWidgetScreen(panel->versionL), "-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*");
1181 if (font) {
1182 WMSetLabelFont(panel->versionL, font);
1183 WMReleaseFont(font);
1185 WMSetLabelText(panel->versionL, "");
1186 } else if (panel->timer) {
1187 char version[20];
1189 panel->x = 0;
1190 clicks = 0;
1191 WMSetLabelImage(panel->logoL, panel->oldPix);
1192 WMReleasePixmap(panel->oldPix);
1193 panel->oldPix = NULL;
1195 WMDeleteTimerHandler(panel->timer);
1196 panel->timer = NULL;
1198 WMSetLabelFont(panel->versionL, panel->oldFont);
1199 if (panel->oldFont) {
1200 WMReleaseFont(panel->oldFont);
1201 panel->oldFont = NULL;
1203 snprintf(version, sizeof(version), _("Version %s"), VERSION);
1204 WMSetLabelText(panel->versionL, version);
1205 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1209 XEvent ev;
1210 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1211 ButtonPress, &ev));
1214 #endif /* SILLYNESS */
1217 void
1218 wShowInfoPanel(WScreen *scr)
1220 InfoPanel *panel;
1221 WMPixmap *logo;
1222 WMSize size;
1223 WMFont *font;
1224 char *strbuf = NULL;
1225 char buffer[256];
1226 Window parent;
1227 WWindow *wwin;
1228 char **strl;
1229 int i, width, sepWidth;
1230 char *visuals[] = {
1231 "StaticGray",
1232 "GrayScale",
1233 "StaticColor",
1234 "PseudoColor",
1235 "TrueColor",
1236 "DirectColor"
1240 if (thePanel) {
1241 if (thePanel->scr == scr) {
1242 wRaiseFrame(thePanel->wwin->frame->core);
1243 wSetFocusTo(scr, thePanel->wwin);
1245 return;
1248 panel = wmalloc(sizeof(InfoPanel));
1249 memset(panel, 0, sizeof(InfoPanel));
1251 panel->scr = scr;
1253 panel->win = WMCreateWindow(scr->wmscreen, "info");
1254 WMResizeWidget(panel->win, 390, 230);
1256 logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor*)NULL);
1257 if (!logo) {
1258 logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
1260 if (logo) {
1261 size = WMGetPixmapSize(logo);
1262 panel->logoL = WMCreateLabel(panel->win);
1263 WMResizeWidget(panel->logoL, 64, 64);
1264 WMMoveWidget(panel->logoL, 30, 20);
1265 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1266 WMSetLabelImage(panel->logoL, logo);
1267 #ifdef SILLYNESS
1268 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1269 handleLogoPush, panel);
1270 #endif
1271 WMReleasePixmap(logo);
1274 sepWidth = 3;
1275 panel->name1L = WMCreateLabel(panel->win);
1276 WMResizeWidget(panel->name1L, 240, 30 - sepWidth);
1277 WMMoveWidget(panel->name1L, 100, 30);
1279 if (WMIsAntialiasingEnabled(scr->wmscreen)) {
1280 font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1281 } else {
1282 font = WMCreateFont(scr->wmscreen, "-*-utopia-*-r-*-*-25-*");
1283 font = font ? font : WMBoldSystemFontOfSize(scr->wmscreen, 24);
1285 strbuf = "Window Maker";
1286 if (font) {
1287 width = WMWidthOfString(font, strbuf, strlen(strbuf));
1288 WMSetLabelFont(panel->name1L, font);
1289 WMReleaseFont(font);
1291 WMSetLabelTextAlignment(panel->name1L, WACenter);
1292 WMSetLabelText(panel->name1L, strbuf);
1294 panel->lineF = WMCreateFrame(panel->win);
1295 WMResizeWidget(panel->lineF, width, sepWidth);
1296 WMMoveWidget(panel->lineF, 100+(240-width)/2, 60 - sepWidth);
1297 WMSetFrameRelief(panel->lineF, WRSimple);
1298 WMSetWidgetBackgroundColor(panel->lineF, scr->black);
1300 panel->name2L = WMCreateLabel(panel->win);
1301 WMResizeWidget(panel->name2L, 240, 24);
1302 WMMoveWidget(panel->name2L, 100, 60);
1303 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1304 if (font) {
1305 WMSetLabelFont(panel->name2L, font);
1306 WMReleaseFont(font);
1307 font = NULL;
1309 WMSetLabelTextAlignment(panel->name2L, WACenter);
1310 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1312 snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
1313 panel->versionL = WMCreateLabel(panel->win);
1314 WMResizeWidget(panel->versionL, 310, 16);
1315 WMMoveWidget(panel->versionL, 30, 95);
1316 WMSetLabelTextAlignment(panel->versionL, WARight);
1317 WMSetLabelText(panel->versionL, buffer);
1318 WMSetLabelWraps(panel->versionL, False);
1320 panel->copyrL = WMCreateLabel(panel->win);
1321 WMResizeWidget(panel->copyrL, 360, 40);
1322 WMMoveWidget(panel->copyrL, 15, 185);
1323 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1324 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1325 /* we want the (c) character in the font, so don't use a FontSet here */
1326 font = WMCreateFontWithFlags(scr->wmscreen, "SystemFont-11", WFNormalFont);
1327 if (font) {
1328 WMSetLabelFont(panel->copyrL, font);
1329 WMReleaseFont(font);
1330 font = NULL;
1333 strbuf = NULL;
1334 snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
1335 (unsigned)scr->w_visual->visualid,
1336 visuals[scr->w_visual->class], scr->w_depth);
1338 strbuf = wstrappend(strbuf, buffer);
1340 switch (scr->w_depth) {
1341 case 15:
1342 strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
1343 break;
1344 case 16:
1345 strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
1346 break;
1347 case 24:
1348 case 32:
1349 strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
1350 break;
1351 default:
1352 snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1<<scr->w_depth);
1353 strbuf = wstrappend(strbuf, buffer);
1354 break;
1358 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1360 struct mallinfo ma = mallinfo();
1361 snprintf(buffer, sizeof(buffer),
1362 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1363 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
1365 strbuf = wstrappend(strbuf, buffer);
1367 #endif
1369 strbuf = wstrappend(strbuf, _("Supported image formats: "));
1370 strl = RSupportedFileFormats();
1371 for (i=0; strl[i]!=NULL; i++) {
1372 strbuf = wstrappend(strbuf, strl[i]);
1373 strbuf = wstrappend(strbuf, " ");
1376 strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
1378 char *list[8];
1379 char buf[80];
1380 int j = 0;
1382 #ifdef MWM_HINTS
1383 list[j++] = "MWM";
1384 #endif
1385 #ifdef KWM_HINTS
1386 list[j++] = "KDE";
1387 #endif
1388 #ifdef GNOME_STUFF
1389 list[j++] = "GNOME";
1390 #endif
1391 #ifdef OLWM_HINTS
1392 list[j++] = "OLWM";
1393 #endif
1395 buf[0] = 0;
1396 for (i = 0; i < j; i++) {
1397 if (i > 0) {
1398 if (i == j - 1)
1399 strcat(buf, _(" and "));
1400 else
1401 strcat(buf, ", ");
1403 strcat(buf, list[i]);
1405 strbuf = wstrappend(strbuf, buf);
1408 if (wPreferences.no_sound) {
1409 strbuf = wstrappend(strbuf, _("\nSound disabled"));
1410 } else {
1411 strbuf = wstrappend(strbuf, _("\nSound enabled"));
1415 panel->infoL = WMCreateLabel(panel->win);
1416 WMResizeWidget(panel->infoL, 350, 75);
1417 WMMoveWidget(panel->infoL, 15, 115);
1418 WMSetLabelText(panel->infoL, strbuf);
1419 font = WMSystemFontOfSize(scr->wmscreen, 11);
1420 if (font) {
1421 WMSetLabelFont(panel->infoL, font);
1422 WMReleaseFont(font);
1423 font = NULL;
1425 wfree(strbuf);
1428 WMRealizeWidget(panel->win);
1429 WMMapSubwidgets(panel->win);
1431 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1433 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1435 WMMapWidget(panel->win);
1438 WMPoint center = getCenter(scr, 382, 230);
1440 wwin = wManageInternalWindow(scr, parent, None, _("Info"),
1441 center.x, center.y,
1442 382, 230);
1445 WSETUFLAG(wwin, no_closable, 0);
1446 WSETUFLAG(wwin, no_close_button, 0);
1447 #ifdef XKB_BUTTON_HINT
1448 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1449 #endif
1450 wWindowUpdateButtonImages(wwin);
1451 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1452 wwin->frame->on_click_right = destroyInfoPanel;
1454 wWindowMap(wwin);
1456 panel->wwin = wwin;
1458 thePanel = panel;
1459 #ifdef SILLYNESS
1460 if (InitXThing(panel->scr)) {
1461 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1462 panel->cycle = 0;
1463 panel->x = 1;
1464 panel->str = _("Merry Christmas!");
1465 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1467 #endif
1472 ***********************************************************************
1473 * Legal Panel
1474 ***********************************************************************
1477 typedef struct {
1478 WScreen *scr;
1480 WWindow *wwin;
1482 WMWindow *win;
1484 WMLabel *licenseL;
1485 } LegalPanel;
1488 static LegalPanel *legalPanel = NULL;
1490 static void
1491 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1493 WMUnmapWidget(legalPanel->win);
1495 WMDestroyWidget(legalPanel->win);
1497 wUnmanageWindow(legalPanel->wwin, False, False);
1499 wfree(legalPanel);
1501 legalPanel = NULL;
1505 void
1506 wShowLegalPanel(WScreen *scr)
1508 LegalPanel *panel;
1509 Window parent;
1510 WWindow *wwin;
1512 if (legalPanel) {
1513 if (legalPanel->scr == scr) {
1514 wRaiseFrame(legalPanel->wwin->frame->core);
1515 wSetFocusTo(scr, legalPanel->wwin);
1517 return;
1520 panel = wmalloc(sizeof(LegalPanel));
1522 panel->scr = scr;
1524 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1525 WMResizeWidget(panel->win, 420, 250);
1528 panel->licenseL = WMCreateLabel(panel->win);
1529 WMSetLabelWraps(panel->licenseL, True);
1530 WMResizeWidget(panel->licenseL, 400, 230);
1531 WMMoveWidget(panel->licenseL, 10, 10);
1532 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1533 WMSetLabelText(panel->licenseL,
1534 _(" Window Maker is free software; you can redistribute it and/or\n"
1535 "modify it under the terms of the GNU General Public License as\n"
1536 "published by the Free Software Foundation; either version 2 of the\n"
1537 "License, or (at your option) any later version.\n\n"
1538 " Window Maker is distributed in the hope that it will be useful,\n"
1539 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1540 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1541 "See the GNU General Public License for more details.\n\n"
1542 " You should have received a copy of the GNU General Public\n"
1543 "License along with this program; if not, write to the Free Software\n"
1544 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
1545 "02111-1307, USA."));
1546 WMSetLabelRelief(panel->licenseL, WRGroove);
1548 WMRealizeWidget(panel->win);
1549 WMMapSubwidgets(panel->win);
1551 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1553 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1556 WMPoint center = getCenter(scr, 420, 250);
1558 wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
1559 center.x, center.y,
1560 420, 250);
1563 WSETUFLAG(wwin, no_closable, 0);
1564 WSETUFLAG(wwin, no_close_button, 0);
1565 wWindowUpdateButtonImages(wwin);
1566 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1567 #ifdef XKB_BUTTON_HINT
1568 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1569 #endif
1570 wwin->frame->on_click_right = destroyLegalPanel;
1572 panel->wwin = wwin;
1574 WMMapWidget(panel->win);
1576 wWindowMap(wwin);
1578 legalPanel = panel;
1583 ***********************************************************************
1584 * Crashing Dialog Panel
1585 ***********************************************************************
1588 extern WDDomain *WDWindowAttributes;
1591 typedef struct _CrashPanel {
1592 WMWindow *win; /* main window */
1594 WMLabel *iconL; /* application icon */
1595 WMLabel *nameL; /* title of panel */
1597 WMFrame *sepF; /* separator frame */
1599 WMLabel *noteL; /* Title of note */
1600 WMLabel *note2L; /* body of note with what happened */
1602 WMFrame *whatF; /* "what to do next" frame */
1603 WMPopUpButton *whatP; /* action selection popup button */
1605 WMButton *okB; /* ok button */
1607 Bool done; /* if finished with this dialog */
1608 int action; /* what to do after */
1610 KeyCode retKey;
1612 } CrashPanel;
1615 static void
1616 handleKeyPress(XEvent *event, void *clientData)
1618 CrashPanel *panel = (CrashPanel*)clientData;
1620 if (event->xkey.keycode == panel->retKey) {
1621 WMPerformButtonClick(panel->okB);
1626 static void
1627 okButtonCallback(void *self, void *clientData)
1629 CrashPanel *panel = (CrashPanel*)clientData;
1631 panel->done = True;
1635 static void
1636 setCrashAction(void *self, void *clientData)
1638 WMPopUpButton *pop = (WMPopUpButton*)self;
1639 CrashPanel *panel = (CrashPanel*)clientData;
1641 panel->action = WMGetPopUpButtonSelectedItem(pop);
1645 static WMPixmap*
1646 getWindowMakerIconImage(WMScreen *scr)
1648 WMPropList *dict, *key, *option, *value=NULL;
1649 WMPixmap *pix=NULL;
1650 char *path;
1652 WMPLSetCaseSensitive(True);
1654 key = WMCreatePLString("Logo.WMPanel");
1655 option = WMCreatePLString("Icon");
1657 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
1659 if (dict) {
1660 value = WMGetFromPLDictionary(dict, option);
1663 WMReleasePropList(key);
1664 WMReleasePropList(option);
1666 WMPLSetCaseSensitive(False);
1668 if (value && WMIsPLString(value)) {
1669 path = FindImage(wPreferences.icon_path, WMGetFromPLString(value));
1671 if (path) {
1672 RColor gray;
1674 gray.red = 0xae; gray.green = 0xaa;
1675 gray.blue = 0xae; gray.alpha = 0;
1677 pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
1678 wfree(path);
1682 return pix;
1686 #define PWIDTH 295
1687 #define PHEIGHT 345
1691 wShowCrashingDialogPanel(int whatSig)
1693 CrashPanel *panel;
1694 WMScreen *scr;
1695 WMFont *font;
1696 WMPixmap *logo;
1697 int screen_no, scr_width, scr_height;
1698 int action;
1699 char buf[256];
1701 panel = wmalloc(sizeof(CrashPanel));
1702 memset(panel, 0, sizeof(CrashPanel));
1704 screen_no = DefaultScreen(dpy);
1705 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1706 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1708 scr = WMCreateScreen(dpy, screen_no);
1709 if (!scr) {
1710 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1711 return WMAbort;
1714 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1716 panel->win = WMCreateWindow(scr, "crashingDialog");
1717 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1718 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1720 logo = getWindowMakerIconImage(scr);
1721 if (logo) {
1722 panel->iconL = WMCreateLabel(panel->win);
1723 WMResizeWidget(panel->iconL, 64, 64);
1724 WMMoveWidget(panel->iconL, 10, 10);
1725 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1726 WMSetLabelImage(panel->iconL, logo);
1729 panel->nameL = WMCreateLabel(panel->win);
1730 WMResizeWidget(panel->nameL, 190, 18);
1731 WMMoveWidget(panel->nameL, 80, 35);
1732 WMSetLabelTextAlignment(panel->nameL, WALeft);
1733 font = WMBoldSystemFontOfSize(scr, 18);
1734 WMSetLabelFont(panel->nameL, font);
1735 WMReleaseFont(font);
1736 WMSetLabelText(panel->nameL, _("Fatal error"));
1738 panel->sepF = WMCreateFrame(panel->win);
1739 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1740 WMMoveWidget(panel->sepF, -2, 80);
1742 panel->noteL = WMCreateLabel(panel->win);
1743 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1744 WMMoveWidget(panel->noteL, 10, 90);
1745 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1746 #ifdef SYS_SIGLIST_DECLARED
1747 snprintf(buf, sizeof(buf), _("Window Maker received signal %i\n(%s)."),
1748 whatSig, sys_siglist[whatSig]);
1749 #else
1750 snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
1751 #endif
1752 WMSetLabelText(panel->noteL, buf);
1754 panel->note2L = WMCreateLabel(panel->win);
1755 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1756 WMMoveWidget(panel->note2L, 10, 130);
1757 WMSetLabelTextAlignment(panel->note2L, WALeft);
1758 WMSetLabelText(panel->note2L,
1759 _(" This fatal error occured probably due to a bug."
1760 " Please fill the included BUGFORM and "
1761 "report it to bugs@windowmaker.org."));
1762 WMSetLabelWraps(panel->note2L, True);
1765 panel->whatF = WMCreateFrame(panel->win);
1766 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1767 WMMoveWidget(panel->whatF, 10, 240);
1768 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1770 panel->whatP = WMCreatePopUpButton(panel->whatF);
1771 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1772 WMMoveWidget(panel->whatP, 35, 20);
1773 WMSetPopUpButtonPullsDown(panel->whatP, False);
1774 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1775 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1776 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1777 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1778 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1779 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1780 panel->action = WMRestart;
1782 WMMapSubwidgets(panel->whatF);
1784 panel->okB = WMCreateCommandButton(panel->win);
1785 WMResizeWidget(panel->okB, 80, 26);
1786 WMMoveWidget(panel->okB, 205, 309);
1787 WMSetButtonText(panel->okB, _("OK"));
1788 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1789 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1790 WMSetButtonImagePosition(panel->okB, WIPRight);
1791 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1793 panel->done = 0;
1795 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1796 handleKeyPress, panel);
1798 WMRealizeWidget(panel->win);
1799 WMMapSubwidgets(panel->win);
1801 WMMapWidget(panel->win);
1803 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1805 while (!panel->done) {
1806 XEvent event;
1808 WMNextEvent(dpy, &event);
1809 WMHandleEvent(&event);
1812 action = panel->action;
1814 WMUnmapWidget(panel->win);
1815 WMDestroyWidget(panel->win);
1816 wfree(panel);
1818 return action;
1824 /*****************************************************************************
1825 * About GNUstep Panel
1826 *****************************************************************************/
1829 static void
1830 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1831 unsigned long blackPixel, unsigned long whitePixel)
1833 GC gc;
1834 XGCValues gcv;
1835 XRectangle rects[3];
1837 gcv.foreground = blackPixel;
1838 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1840 XFillArc(dpy, d, gc, width/45, height/45,
1841 width - 2*width/45, height - 2*height/45, 0, 360*64);
1843 rects[0].x = 0;
1844 rects[0].y = 37*height/45;
1845 rects[0].width = width/3;
1846 rects[0].height = height - rects[0].y;
1848 rects[1].x = rects[0].width;
1849 rects[1].y = height/2;
1850 rects[1].width = width - 2*width/3;
1851 rects[1].height = height - rects[1].y;
1853 rects[2].x = 2*width/3;
1854 rects[2].y = height - 37*height/45;
1855 rects[2].width = width/3;
1856 rects[2].height = height - rects[2].y;
1858 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1859 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1861 XSetForeground(dpy, gc, whitePixel);
1862 XFillArc(dpy, d, gc, width/45, height/45,
1863 width - 2*width/45, height - 2*height/45, 0, 360*64);
1865 XFreeGC(dpy, gc);
1869 typedef struct {
1870 WScreen *scr;
1872 WWindow *wwin;
1874 WMWindow *win;
1876 WMLabel *gstepL;
1877 WMLabel *textL;
1878 } GNUstepPanel;
1881 static GNUstepPanel *gnustepPanel = NULL;
1883 static void
1884 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1886 WMUnmapWidget(gnustepPanel->win);
1888 WMDestroyWidget(gnustepPanel->win);
1890 wUnmanageWindow(gnustepPanel->wwin, False, False);
1892 wfree(gnustepPanel);
1894 gnustepPanel = NULL;
1898 void
1899 wShowGNUstepPanel(WScreen *scr)
1901 GNUstepPanel *panel;
1902 Window parent;
1903 WWindow *wwin;
1904 WMPixmap *pixmap;
1905 WMColor *color;
1907 if (gnustepPanel) {
1908 if (gnustepPanel->scr == scr) {
1909 wRaiseFrame(gnustepPanel->wwin->frame->core);
1910 wSetFocusTo(scr, gnustepPanel->wwin);
1912 return;
1915 panel = wmalloc(sizeof(GNUstepPanel));
1917 panel->scr = scr;
1919 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1920 WMResizeWidget(panel->win, 325, 200);
1922 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1923 WMScreenDepth(scr->wmscreen), True);
1925 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1927 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1928 WMColorPixel(color), scr->white_pixel);
1930 WMReleaseColor(color);
1932 XSetForeground(dpy, scr->mono_gc, 0);
1933 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1934 130, 130);
1935 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1937 panel->gstepL = WMCreateLabel(panel->win);
1938 WMResizeWidget(panel->gstepL, 285, 64);
1939 WMMoveWidget(panel->gstepL, 20, 0);
1940 WMSetLabelTextAlignment(panel->gstepL, WARight);
1941 WMSetLabelText(panel->gstepL, "GNUstep");
1943 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1945 WMSetLabelFont(panel->gstepL, font);
1946 WMReleaseFont(font);
1949 panel->textL = WMCreateLabel(panel->win);
1950 WMResizeWidget(panel->textL, 275, 130);
1951 WMMoveWidget(panel->textL, 30, 50);
1952 WMSetLabelTextAlignment(panel->textL, WARight);
1953 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1954 WMSetLabelText(panel->textL,
1955 _("Window Maker is part of the GNUstep project.\n"\
1956 "The GNUstep project aims to create a free\n"\
1957 "implementation of the OpenStep(tm) specification\n"\
1958 "which is a object-oriented framework for\n"\
1959 "creating advanced graphical, multi-platform\n"\
1960 "applications. Additionally, a development and\n"\
1961 "user desktop enviroment will be created on top\n"\
1962 "of the framework. For more information about\n"\
1963 "GNUstep, please visit: www.gnustep.org"));
1964 WMSetLabelImage(panel->textL, pixmap);
1966 WMReleasePixmap(pixmap);
1968 WMRealizeWidget(panel->win);
1969 WMMapSubwidgets(panel->win);
1971 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1973 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1976 WMPoint center = getCenter(scr, 325, 200);
1978 wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
1979 center.x, center.y,
1980 325, 200);
1983 WSETUFLAG(wwin, no_closable, 0);
1984 WSETUFLAG(wwin, no_close_button, 0);
1985 wWindowUpdateButtonImages(wwin);
1986 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1987 #ifdef XKB_BUTTON_HINT
1988 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1989 #endif
1990 wwin->frame->on_click_right = destroyGNUstepPanel;
1992 panel->wwin = wwin;
1994 WMMapWidget(panel->win);
1996 wWindowMap(wwin);
1998 gnustepPanel = panel;