- Slovak .po file updates from (Jan Tomka <judas@linux.sk>)
[wmaker-crm.git] / src / dialog.c
blob3d62d27a9a33efe2aaa890dd9ff9ea63e326bd3b
1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 * Copyright (c) 1999 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"
65 extern WPreferences wPreferences;
69 int
70 wMessageDialog(WScreen *scr, char *title, char *message,
71 char *defBtn, char *altBtn, char *othBtn)
73 WMAlertPanel *panel;
74 Window parent;
75 WWindow *wwin;
76 int result;
78 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
79 defBtn, altBtn, othBtn);
81 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
83 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
85 wwin = wManageInternalWindow(scr, parent, None, NULL,
86 (scr->scr_width - 400)/2,
87 (scr->scr_height - 180)/2, 400, 180);
88 wwin->client_leader = WMWidgetXID(panel->win);
90 WMMapWidget(panel->win);
92 wWindowMap(wwin);
94 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
96 result = panel->result;
98 WMUnmapWidget(panel->win);
100 wUnmanageWindow(wwin, False, False);
102 WMDestroyAlertPanel(panel);
104 XDestroyWindow(dpy, parent);
106 return result;
110 void
111 toggleSaveSession(WMWidget *w, void *data)
113 wPreferences.save_session_on_exit = WMGetButtonSelected((WMButton *) w);
118 wExitDialog(WScreen *scr, char *title, char *message,
119 char *defBtn, char *altBtn, char *othBtn)
121 WMAlertPanel *panel;
122 WMButton *saveSessionBtn;
123 Window parent;
124 WWindow *wwin;
125 int result;
127 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
128 defBtn, altBtn, othBtn);
130 /* add save session button */
131 saveSessionBtn = WMCreateSwitchButton(panel->hbox);
132 WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
133 WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn),
134 False, True, 200, 0, 0);
135 WMSetButtonText(saveSessionBtn, _("Save workspace state"));
136 WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
137 WMRealizeWidget(saveSessionBtn);
138 WMMapWidget(saveSessionBtn);
140 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
142 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
144 wwin = wManageInternalWindow(scr, parent, None, NULL,
145 (scr->scr_width - 400)/2,
146 (scr->scr_height - 180)/2, 400, 180);
147 wwin->client_leader = WMWidgetXID(panel->win);
149 WMMapWidget(panel->win);
151 wWindowMap(wwin);
153 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
155 result = panel->result;
157 WMUnmapWidget(panel->win);
159 wUnmanageWindow(wwin, False, False);
161 WMDestroyAlertPanel(panel);
163 XDestroyWindow(dpy, parent);
165 return result;
170 wInputDialog(WScreen *scr, char *title, char *message, char **text)
172 WWindow *wwin;
173 Window parent;
174 WMInputPanel *panel;
175 char *result;
178 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
179 _("OK"), _("Cancel"));
182 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
183 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
185 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
187 wwin = wManageInternalWindow(scr, parent, None, NULL,
188 (scr->scr_width - 320)/2,
189 (scr->scr_height - 160)/2, 320, 160);
191 wwin->client_leader = WMWidgetXID(panel->win);
193 WMMapWidget(panel->win);
195 wWindowMap(wwin);
197 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
199 if (panel->result == WAPRDefault)
200 result = WMGetTextFieldText(panel->text);
201 else
202 result = NULL;
204 wUnmanageWindow(wwin, False, False);
206 WMDestroyInputPanel(panel);
208 XDestroyWindow(dpy, parent);
210 if (result==NULL)
211 return False;
212 else {
213 if (*text)
214 wfree(*text);
215 *text = result;
217 return True;
223 *****************************************************************
224 * Icon Selection Panel
225 *****************************************************************
228 typedef struct IconPanel {
230 WScreen *scr;
232 WMWindow *win;
234 WMLabel *dirLabel;
235 WMLabel *iconLabel;
237 WMList *dirList;
238 WMList *iconList;
239 WMFont *normalfont;
241 WMButton *previewButton;
243 WMLabel *iconView;
245 WMLabel *fileLabel;
246 WMTextField *fileField;
248 WMButton *okButton;
249 WMButton *cancelButton;
250 #if 0
251 WMButton *chooseButton;
252 #endif
253 short done;
254 short result;
255 short preview;
256 } IconPanel;
260 static void
261 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
263 struct dirent *dentry;
264 DIR *dir;
265 char pbuf[PATH_MAX+16];
266 char *apath;
267 IconPanel *panel = WMGetHangedData(lPtr);
269 panel->preview = False;
271 apath = wexpandpath(path);
272 dir = opendir(apath);
274 if (!dir) {
275 char *msg;
276 char *tmp;
277 tmp = _("Could not open directory ");
278 msg = wmalloc(strlen(tmp)+strlen(path)+6);
279 strcpy(msg, tmp);
280 strcat(msg, path);
282 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
283 wfree(msg);
284 wfree(apath);
285 return;
288 /* list contents in the column */
289 while ((dentry = readdir(dir))) {
290 struct stat statb;
292 if (strcmp(dentry->d_name, ".")==0 ||
293 strcmp(dentry->d_name, "..")==0)
294 continue;
296 strcpy(pbuf, apath);
297 strcat(pbuf, "/");
298 strcat(pbuf, dentry->d_name);
300 if (stat(pbuf, &statb)<0)
301 continue;
303 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
304 && statb.st_mode & (S_IFREG|S_IFLNK)) {
305 WMAddListItem(lPtr, dentry->d_name);
308 WMSortListItems(lPtr);
310 closedir(dir);
311 wfree(apath);
312 panel->preview = True;
317 static void
318 setViewedImage(IconPanel *panel, char *file)
320 WMPixmap *pixmap;
321 RColor color;
323 color.red = 0xae;
324 color.green = 0xaa;
325 color.blue = 0xae;
326 color.alpha = 0;
327 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
328 file, &color);
329 if (!pixmap) {
330 WMSetButtonEnabled(panel->okButton, False);
332 WMSetLabelText(panel->iconView, _("Could not load image file "));
334 WMSetLabelImage(panel->iconView, NULL);
335 } else {
336 WMSetButtonEnabled(panel->okButton, True);
338 WMSetLabelText(panel->iconView, NULL);
339 WMSetLabelImage(panel->iconView, pixmap);
340 WMReleasePixmap(pixmap);
345 static void
346 listCallback(void *self, void *data)
348 WMList *lPtr = (WMList*)self;
349 IconPanel *panel = (IconPanel*)data;
350 char *path;
352 if (lPtr==panel->dirList) {
353 WMListItem *item = WMGetListSelectedItem(lPtr);
355 if (item == NULL)
356 return;
357 path = item->text;
359 WMSetTextFieldText(panel->fileField, path);
361 WMSetLabelImage(panel->iconView, NULL);
363 WMSetButtonEnabled(panel->okButton, False);
365 WMClearList(panel->iconList);
366 listPixmaps(panel->scr, panel->iconList, path);
367 } else {
368 char *tmp, *iconFile;
369 WMListItem *item = WMGetListSelectedItem(panel->dirList);
371 if (item == NULL)
372 return;
373 path = item->text;
374 tmp = wexpandpath(path);
376 item = WMGetListSelectedItem(panel->iconList);
377 if (item == NULL)
378 return;
379 iconFile = item->text;
381 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
382 strcpy(path, tmp);
383 strcat(path, "/");
384 strcat(path, iconFile);
385 wfree(tmp);
386 WMSetTextFieldText(panel->fileField, path);
387 setViewedImage(panel, path);
388 wfree(path);
393 static void
394 listIconPaths(WMList *lPtr)
396 char *paths;
397 char *path;
399 paths = wstrdup(wPreferences.icon_path);
401 path = strtok(paths, ":");
403 do {
404 char *tmp;
406 tmp = wexpandpath(path);
407 /* do not sort, because the order implies the order of
408 * directories searched */
409 if (access(tmp, X_OK)==0)
410 WMAddListItem(lPtr, path);
411 wfree(tmp);
412 } while ((path=strtok(NULL, ":"))!=NULL);
414 wfree(paths);
418 void
419 drawIconProc(WMList *lPtr, int index, Drawable d, char *text,
420 int state, WMRect *rect)
422 IconPanel *panel = WMGetHangedData(lPtr);
423 GC gc = panel->scr->draw_gc;
424 GC copygc = panel->scr->copy_gc;
425 char *file, *dirfile;
426 WMPixmap *pixmap;
427 WMColor *blackcolor;
428 WMColor *whitecolor;
429 WMSize size;
430 WMScreen *wmscr = WMWidgetScreen(panel->win);
431 RColor color;
432 int width;
434 if(!panel->preview) return;
436 width = rect->size.width;
438 blackcolor = WMBlackColor(wmscr);
439 whitecolor = WMWhiteColor(wmscr);
441 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
443 int len = strlen(dirfile)+strlen(text)+4;
444 file = wmalloc(len);
445 snprintf(file, len, "%s/%s", dirfile, text);
447 wfree(dirfile);
449 if ((state & WLDSSelected) != 0) {
450 color.red = color.green = color.blue = 0xff;
451 color.alpha = 0;
452 } else {
453 color.red = color.blue = 0xae;
454 color.green = 0xaa; color.alpha = 0;
456 pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
457 wfree(file);
459 if (!pixmap) {
460 WMRemoveListItem(lPtr, index);
461 return;
464 XClearArea(dpy, d, rect->pos.x, rect->pos.y, width, rect->size.height,
465 False);
466 XSetClipMask(dpy, gc, None);
468 XDrawRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x + 5,
469 rect->pos.y +5, width - 10, 54);
471 XDrawLine(dpy, d, WMColorGC(whitecolor), rect->pos.x,
472 rect->pos.y+rect->size.height-1, rect->pos.x+width,
473 rect->pos.y+rect->size.height-1);
476 if (state&WLDSSelected) {
477 XFillRectangle(dpy, d, WMColorGC(whitecolor), rect->pos.x,
478 rect->pos.y, width, rect->size.height);
481 size = WMGetPixmapSize(pixmap);
483 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
484 XSetClipOrigin(dpy, copygc, rect->pos.x + (width-size.width)/2,
485 rect->pos.y+2);
486 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
487 size.width>100?100:size.width, size.height>64?64:size.height,
488 rect->pos.x + (width-size.width)/2, rect->pos.y+2);
491 int i,j;
492 int fheight = WMFontHeight(panel->normalfont);
493 int tlen = strlen(text);
494 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
495 int ofx, ofy;
497 ofx = rect->pos.x + (width - twidth)/2;
498 ofy = rect->pos.y + 64 - fheight;
500 for(i=-1;i<2;i++)
501 for(j=-1;j<2;j++)
502 WMDrawString(wmscr, d, WMColorGC(whitecolor),
503 panel->normalfont, ofx+i, ofy+j,
504 text, tlen);
506 WMDrawString(wmscr, d, WMColorGC(blackcolor), panel->normalfont,
507 ofx, ofy, text, tlen);
510 WMReleasePixmap(pixmap);
511 /* I hope it is better to do not use cache / on my box it is fast nuff */
512 XFlush(dpy);
514 WMReleaseColor(blackcolor);
515 WMReleaseColor(whitecolor);
519 static void
520 buttonCallback(void *self, void *clientData)
522 WMButton *bPtr = (WMButton*)self;
523 IconPanel *panel = (IconPanel*)clientData;
526 if (bPtr==panel->okButton) {
527 panel->done = True;
528 panel->result = True;
529 } else if (bPtr==panel->cancelButton) {
530 panel->done = True;
531 panel->result = False;
532 } else if (bPtr==panel->previewButton) {
533 /**** Previewer ****/
534 WMSetButtonEnabled(bPtr, False);
535 WMSetListUserDrawItemHeight(panel->iconList, 68);
536 WMSetListUserDrawProc(panel->iconList, drawIconProc);
537 WMRedisplayWidget(panel->iconList);
538 /* for draw proc to access screen/gc */
539 /*** end preview ***/
541 #if 0
542 else if (bPtr==panel->chooseButton) {
543 WMOpenPanel *op;
545 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
547 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
548 char *path;
549 path = WMGetFilePanelFile(op);
550 WMSetTextFieldText(panel->fileField, path);
551 setViewedImage(panel, path);
552 wfree(path);
554 WMDestroyFilePanel(op);
556 #endif
560 static void
561 keyPressHandler(XEvent *event, void *data)
563 IconPanel *panel = (IconPanel*)data;
564 char buffer[32];
565 int count;
566 KeySym ksym;
567 int iidx;
568 int didx;
569 int item;
570 WMList *list = NULL;
572 if (event->type == KeyRelease)
573 return;
575 buffer[0] = 0;
576 count = XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
579 iidx = WMGetListSelectedItemRow(panel->iconList);
580 didx = WMGetListSelectedItemRow(panel->dirList);
582 switch (ksym) {
583 case XK_Up:
584 if (iidx > 0)
585 item = iidx-1;
586 else
587 item = iidx;
588 list = panel->iconList;
589 break;
590 case XK_Down:
591 if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
592 item = iidx+1;
593 else
594 item = iidx;
595 list = panel->iconList;
596 break;
597 case XK_Home:
598 item = 0;
599 list = panel->iconList;
600 break;
601 case XK_End:
602 item = WMGetListNumberOfRows(panel->iconList) - 1;
603 list = panel->iconList;
604 break;
605 case XK_Next:
606 if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
607 item = didx + 1;
608 else
609 item = didx;
610 list = panel->dirList;
611 break;
612 case XK_Prior:
613 if (didx > 0)
614 item = didx - 1;
615 else
616 item = 0;
617 list = panel->dirList;
618 break;
619 case XK_Return:
620 WMPerformButtonClick(panel->okButton);
621 break;
622 case XK_Escape:
623 WMPerformButtonClick(panel->cancelButton);
624 break;
627 if (list) {
628 WMSelectListItem(list, item);
629 WMSetListPosition(list, item - 5);
630 listCallback(list, panel);
636 Bool
637 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
639 WWindow *wwin;
640 Window parent;
641 IconPanel *panel;
642 WMColor *color;
643 WMFont *boldFont;
645 panel = wmalloc(sizeof(IconPanel));
646 memset(panel, 0, sizeof(IconPanel));
648 panel->scr = scr;
650 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
651 WMResizeWidget(panel->win, 450, 280);
653 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask|KeyReleaseMask,
654 keyPressHandler, panel);
657 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
658 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
660 panel->dirLabel = WMCreateLabel(panel->win);
661 WMResizeWidget(panel->dirLabel, 200, 20);
662 WMMoveWidget(panel->dirLabel, 10, 7);
663 WMSetLabelText(panel->dirLabel, _("Directories"));
664 WMSetLabelFont(panel->dirLabel, boldFont);
665 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
667 WMSetLabelRelief(panel->dirLabel, WRSunken);
669 panel->iconLabel = WMCreateLabel(panel->win);
670 WMResizeWidget(panel->iconLabel, 140, 20);
671 WMMoveWidget(panel->iconLabel, 215, 7);
672 WMSetLabelText(panel->iconLabel, _("Icons"));
673 WMSetLabelFont(panel->iconLabel, boldFont);
674 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
676 WMReleaseFont(boldFont);
678 color = WMWhiteColor(scr->wmscreen);
679 WMSetLabelTextColor(panel->dirLabel, color);
680 WMSetLabelTextColor(panel->iconLabel, color);
681 WMReleaseColor(color);
683 color = WMDarkGrayColor(scr->wmscreen);
684 WMSetWidgetBackgroundColor(panel->iconLabel, color);
685 WMSetWidgetBackgroundColor(panel->dirLabel, color);
686 WMReleaseColor(color);
688 WMSetLabelRelief(panel->iconLabel, WRSunken);
690 panel->dirList = WMCreateList(panel->win);
691 WMResizeWidget(panel->dirList, 200, 170);
692 WMMoveWidget(panel->dirList, 10, 30);
693 WMSetListAction(panel->dirList, listCallback, panel);
695 panel->iconList = WMCreateList(panel->win);
696 WMResizeWidget(panel->iconList, 140, 170);
697 WMMoveWidget(panel->iconList, 215, 30);
698 WMSetListAction(panel->iconList, listCallback, panel);
700 WMHangData(panel->iconList,panel);
702 panel->previewButton = WMCreateCommandButton(panel->win);
703 WMResizeWidget(panel->previewButton, 75, 26);
704 WMMoveWidget(panel->previewButton, 365, 130);
705 WMSetButtonText(panel->previewButton, _("Preview"));
706 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
708 panel->iconView = WMCreateLabel(panel->win);
709 WMResizeWidget(panel->iconView, 75, 75);
710 WMMoveWidget(panel->iconView, 365, 40);
711 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
712 WMSetLabelRelief(panel->iconView, WRSunken);
713 WMSetLabelTextAlignment(panel->iconView, WACenter);
715 panel->fileLabel = WMCreateLabel(panel->win);
716 WMResizeWidget(panel->fileLabel, 80, 20);
717 WMMoveWidget(panel->fileLabel, 10, 210);
718 WMSetLabelText(panel->fileLabel, _("File Name:"));
720 panel->fileField = WMCreateTextField(panel->win);
721 WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
722 WMResizeWidget(panel->fileField, 345, 20);
723 WMMoveWidget(panel->fileField, 95, 210);
724 WMSetTextFieldEditable(panel->fileField, False);
726 panel->okButton = WMCreateCommandButton(panel->win);
727 WMResizeWidget(panel->okButton, 80, 26);
728 WMMoveWidget(panel->okButton, 360, 240);
729 WMSetButtonText(panel->okButton, _("OK"));
730 WMSetButtonEnabled(panel->okButton, False);
731 WMSetButtonAction(panel->okButton, buttonCallback, panel);
733 panel->cancelButton = WMCreateCommandButton(panel->win);
734 WMResizeWidget(panel->cancelButton, 80, 26);
735 WMMoveWidget(panel->cancelButton, 270, 240);
736 WMSetButtonText(panel->cancelButton, _("Cancel"));
737 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
738 #if 0
739 panel->chooseButton = WMCreateCommandButton(panel->win);
740 WMResizeWidget(panel->chooseButton, 110, 26);
741 WMMoveWidget(panel->chooseButton, 150, 240);
742 WMSetButtonText(panel->chooseButton, _("Choose File"));
743 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
744 #endif
745 WMRealizeWidget(panel->win);
746 WMMapSubwidgets(panel->win);
748 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
750 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
753 char *tmp;
754 int len = (instance ? strlen(instance) : 0)
755 + (class ? strlen(class) : 0) + 32;
757 tmp = wmalloc(len);
759 if (tmp && (instance || class))
760 snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
761 else
762 strcpy(tmp, _("Icon Chooser"));
764 wwin = wManageInternalWindow(scr, parent, None, tmp,
765 (scr->scr_width - 450)/2,
766 (scr->scr_height - 280)/2, 450, 280);
767 wfree(tmp);
770 /* put icon paths in the list */
771 listIconPaths(panel->dirList);
773 WMMapWidget(panel->win);
775 wWindowMap(wwin);
777 while (!panel->done) {
778 XEvent event;
780 WMNextEvent(dpy, &event);
781 WMHandleEvent(&event);
784 if (panel->result) {
785 char *defaultPath, *wantedPath;
787 /* check if the file the user selected is not the one that
788 * would be loaded by default with the current search path */
789 *file = WMGetListSelectedItem(panel->iconList)->text;
790 if ((*file)[0]==0) {
791 wfree(*file);
792 *file = NULL;
793 } else {
794 defaultPath = FindImage(wPreferences.icon_path, *file);
795 wantedPath = WMGetTextFieldText(panel->fileField);
796 /* if the file is not the default, use full path */
797 if (strcmp(wantedPath, defaultPath)!=0) {
798 *file = wantedPath;
799 } else {
800 *file = wstrdup(*file);
801 wfree(wantedPath);
803 wfree(defaultPath);
805 } else {
806 *file = NULL;
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 panel->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 WMLabel *name2L;
843 WMLabel *versionL;
845 WMLabel *infoL;
847 WMLabel *copyrL;
849 #ifdef SILLYNESS
850 WMHandlerID timer;
851 int cycle;
852 RImage *icon;
853 RImage *pic;
854 WMPixmap *oldPix;
855 WMFont *oldFont;
856 char *str;
857 int x;
858 #endif
859 } InfoPanel;
863 #define COPYRIGHT_TEXT \
864 "Copyright \xa9 1997~2001 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
865 "Copyright \xa9 1998~2001 Dan Pascu <dan@windowmaker.org>"
869 static InfoPanel *thePanel = NULL;
871 static void
872 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
874 #ifdef SILLYNESS
875 if (thePanel->timer) {
876 WMDeleteTimerHandler(thePanel->timer);
878 if (thePanel->oldPix) {
879 WMReleasePixmap(thePanel->oldPix);
881 if (thePanel->oldFont) {
882 WMReleaseFont(thePanel->oldFont);
884 if (thePanel->icon) {
885 RReleaseImage(thePanel->icon);
887 if (thePanel->pic) {
888 RReleaseImage(thePanel->pic);
890 #endif /* SILLYNESS */
891 WMUnmapWidget(thePanel);
893 wUnmanageWindow(thePanel->wwin, False, False);
895 WMDestroyWidget(thePanel->win);
897 wfree(thePanel);
899 thePanel = NULL;
903 WMPixmap*
904 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
906 WMPixmap *wpix = NULL;
907 Pixmap grad = None;
908 Pixmap mask = None;
909 RContext *rc = WMScreenRContext(scr);
910 XFontStruct *f = NULL;
911 int w, h;
912 GC gc = None;
914 f = XLoadQueryFont(dpy, font);
915 if (!f)
916 return NULL;
918 w = XTextWidth(f, text, strlen(text));
919 h = f->ascent+f->descent;
921 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
922 gc = XCreateGC(dpy, mask, 0, NULL);
923 XSetForeground(dpy, gc, 0);
924 XSetFont(dpy, gc, f->fid);
925 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
927 XSetForeground(dpy, gc, 1);
928 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
929 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
930 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
932 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
934 WMColor *color;
936 color = WMBlackColor(scr);
937 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
938 WMReleaseColor(color);
941 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
943 if (gc)
944 XFreeGC(dpy, gc);
945 XFreeFont(dpy, f);
947 return wpix;
950 #ifdef SILLYNESS
952 extern WMPixmap *DoXThing();
953 extern Bool InitXThing();
955 static void
956 logoPushCallback(void *data)
958 InfoPanel *panel = (InfoPanel*)data;
959 char buffer[512];
960 int i;
961 static int oldi = 0;
962 int len;
963 static int jingobeu[] = {
964 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
965 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
966 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
968 static int c = 0;
970 if (panel->x) {
971 XKeyboardControl kc;
973 if (panel->x > 0) {
974 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
975 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
976 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
977 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
978 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
979 XBell(dpy,50);XFlush(dpy);}else{c--;}}
980 if (!(panel->cycle % 4)) {
981 WMPixmap *p;
983 p = DoXThing(panel->wwin);
984 WMSetLabelImage(panel->logoL, p);
986 } else if (panel->cycle < 30) {
987 RImage *image;
988 WMPixmap *pix;
989 RColor gray;
991 gray.red = 0xae; gray.green = 0xaa;
992 gray.blue = 0xae; gray.alpha = 0;
994 image = RScaleImage(panel->icon, panel->pic->width, panel->pic->height);
995 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
996 pix = WMCreateBlendedPixmapFromRImage(panel->scr->wmscreen, image, &gray);
997 RReleaseImage(image);
998 WMSetLabelImage(panel->logoL, pix);
999 WMReleasePixmap(pix);
1002 /* slow down text a little */
1003 i = (int)(panel->cycle * 50.0/85.0)%200;
1005 if (i != oldi) {
1006 len = strlen(panel->str);
1008 strncpy(buffer, panel->str, i<len ? i : len);
1009 if (i >= len)
1010 memset(&buffer[len], ' ', i-len);
1012 strncpy(buffer, panel->str, i<len ? i : len);
1013 if (i >= len)
1014 memset(&buffer[len], ' ', i-len);
1015 buffer[i]=0;
1017 WMSetLabelText(panel->versionL, buffer);
1019 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1021 oldi = i;
1024 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1025 panel->cycle++;
1029 static void
1030 handleLogoPush(XEvent *event, void *data)
1032 InfoPanel *panel = (InfoPanel*)data;
1033 static int broken = 0;
1034 static int clicks = 0;
1035 static char *pic_data[] = {
1036 "45 45 57 1",
1037 " c None",
1038 ". c #000000",
1039 "X c #383C00",
1040 "o c #515500",
1041 "O c #616100",
1042 "+ c #616900",
1043 "@ c #696D00",
1044 "# c #697100",
1045 "$ c #495100",
1046 "% c #202800",
1047 "& c #969600",
1048 "* c #CFCF00",
1049 "= c #D7DB00",
1050 "- c #D7D700",
1051 "; c #C7CB00",
1052 ": c #A6AA00",
1053 "> c #494900",
1054 ", c #8E8E00",
1055 "< c #DFE700",
1056 "1 c #F7FF00",
1057 "2 c #FFFF00",
1058 "3 c #E7EB00",
1059 "4 c #B6B600",
1060 "5 c #595900",
1061 "6 c #717500",
1062 "7 c #AEB200",
1063 "8 c #CFD300",
1064 "9 c #E7EF00",
1065 "0 c #EFF300",
1066 "q c #9EA200",
1067 "w c #F7FB00",
1068 "e c #F7F700",
1069 "r c #BEBE00",
1070 "t c #8E9200",
1071 "y c #EFF700",
1072 "u c #969A00",
1073 "i c #414500",
1074 "p c #595D00",
1075 "a c #E7E700",
1076 "s c #C7C700",
1077 "d c #797D00",
1078 "f c #BEC300",
1079 "g c #DFE300",
1080 "h c #868600",
1081 "j c #EFEF00",
1082 "k c #9E9E00",
1083 "l c #616500",
1084 "z c #DFDF00",
1085 "x c #868A00",
1086 "c c #969200",
1087 "v c #B6BA00",
1088 "b c #A6A600",
1089 "n c #8E8A00",
1090 "m c #717100",
1091 "M c #AEAE00",
1092 "N c #AEAA00",
1093 "B c #868200",
1094 " ............... ",
1095 " ....XoO+@##+O$%.... ",
1096 " ...%X&*========-;;:o... ",
1097 " ...>.>,<122222222222134@... ",
1098 " ..>5678912222222222222220q%.. ",
1099 " ..$.&-w2222222222222222222er>.. ",
1100 " ..O.t31222222222222222222222y4>.. ",
1101 " ...O5u3222222222222222222222222yri... ",
1102 " ..>p&a22222222222222222222222222wso.. ",
1103 " ..ids91222222222222222222222222222wfi.. ",
1104 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
1105 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
1106 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
1107 " ..o7y22222222v...r222222223hX.i82222221si.. ",
1108 "..io*222222222&...u22222222yt..%*22222220:%. ",
1109 "..>k02222222227...f222222222v..X=222222229t. ",
1110 "..dz12222222220ui:y2222222223d%qw222222221g. ",
1111 ".%vw222222222221y2222222222219*y2222222222wd.",
1112 ".X;2222222222222222222222222222222222222222b.",
1113 ".i*2222222222222222222222222222222222222222v.",
1114 ".i*2222222222222222222222222222222222222222;.",
1115 ".i*22222222222222222222222222222222222222228.",
1116 ".>*2222222222222222222222222222222222222222=.",
1117 ".i*22222222222222222222222222222222222222228.",
1118 ".i*2222222222222222222222222222222222222222;.",
1119 ".X*222222222222222222222222222222we12222222r.",
1120 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
1121 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
1122 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
1123 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
1124 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
1125 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
1126 " ...:e2222218mdz22222222222222a&$vw222220@...",
1127 " ...O-122222y:.u02222222222229q$uj222221r... ",
1128 " ..%&a1222223&573w2222222219NOxz122221z>... ",
1129 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
1130 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
1131 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
1132 " ..Xb9122222109g-****;<y22221zn%... ",
1133 " ..X&801222222222222222222w-h.... ",
1134 " ...o:=022222222222222221=lX... ",
1135 " ..X@:;3w2222222222210fO... ",
1136 " ...XX&v8<30000003-N@... ",
1137 " .....XmnbN:q&Bo.... ",
1138 " ............ "
1140 static char *msgs[] = {
1141 "Have a nice day!",
1142 "Focus follow mouse users will burn in hell!!!",
1143 "Mooo Canada!!!!",
1144 "Hi! My name is bobby...",
1145 "AHH! The neurotic monkeys are after me!",
1146 "WE GET SIGNAL",
1147 "HOW ARE YOU GENTLEMEN?",
1148 "WHAT YOU SAY??",
1149 "SOMEBODY SET UP US THE BOMB",
1150 "ALL YOUR BASE ARE BELONG TO US!",
1151 "Oh My God!!! Larry is back!"
1155 clicks++;
1157 if (!panel->timer && !broken && clicks > 0) {
1158 WMFont *font;
1160 panel->x = 0;
1161 clicks = 0;
1162 if (!panel->icon) {
1163 panel->icon = WMGetApplicationIconImage(panel->scr->wmscreen);
1164 if (!panel->icon) {
1165 broken = 1;
1166 return;
1167 } else {
1168 RColor color;
1170 color.red = 0xae; color.green = 0xaa;
1171 color.blue = 0xae; color.alpha = 0;
1173 panel->icon = RCloneImage(panel->icon);
1174 RCombineImageWithColor(panel->icon, &color);
1177 if (!panel->pic) {
1178 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
1179 if (!panel->pic) {
1180 broken = 1;
1181 RReleaseImage(panel->icon);
1182 panel->icon = NULL;
1183 return;
1187 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
1189 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
1190 panel->cycle = 0;
1191 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1192 /* If we don't use a fixed font, scrolling will be jumpy */
1193 /* Alternatively we can draw text in a pixmap and scroll it smoothly */
1194 if ((panel->oldFont = WMGetLabelFont(panel->versionL))!=NULL)
1195 WMRetainFont(panel->oldFont);
1196 font = WMCreateFont(WMWidgetScreen(panel->versionL), "-*-fixed-*-*-*-*-14-*-*-*-*-*-*-*");
1197 if (font) {
1198 WMSetLabelFont(panel->versionL, font);
1199 WMReleaseFont(font);
1201 WMSetLabelText(panel->versionL, "");
1202 } else if (panel->timer) {
1203 char version[20];
1205 panel->x = 0;
1206 clicks = 0;
1207 WMSetLabelImage(panel->logoL, panel->oldPix);
1208 WMReleasePixmap(panel->oldPix);
1209 panel->oldPix = NULL;
1211 WMDeleteTimerHandler(panel->timer);
1212 panel->timer = NULL;
1214 WMSetLabelFont(panel->versionL, panel->oldFont);
1215 if (panel->oldFont) {
1216 WMReleaseFont(panel->oldFont);
1217 panel->oldFont = NULL;
1219 snprintf(version, sizeof(version), _("Version %s"), VERSION);
1220 WMSetLabelText(panel->versionL, version);
1221 XFlush(WMScreenDisplay(WMWidgetScreen(panel->versionL)));
1225 XEvent ev;
1226 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
1227 ButtonPress, &ev));
1230 #endif /* SILLYNESS */
1233 void
1234 wShowInfoPanel(WScreen *scr)
1236 InfoPanel *panel;
1237 WMPixmap *logo;
1238 WMSize size;
1239 WMFont *font;
1240 char *strbuf = NULL;
1241 char buffer[256];
1242 Window parent;
1243 WWindow *wwin;
1244 RColor color1, color2;
1245 char **strl;
1246 int i;
1247 char *visuals[] = {
1248 "StaticGray",
1249 "GrayScale",
1250 "StaticColor",
1251 "PseudoColor",
1252 "TrueColor",
1253 "DirectColor"
1257 if (thePanel) {
1258 if (thePanel->scr == scr) {
1259 wRaiseFrame(thePanel->wwin->frame->core);
1260 wSetFocusTo(scr, thePanel->wwin);
1262 return;
1265 panel = wmalloc(sizeof(InfoPanel));
1266 memset(panel, 0, sizeof(InfoPanel));
1268 panel->scr = scr;
1270 panel->win = WMCreateWindow(scr->wmscreen, "info");
1271 WMResizeWidget(panel->win, 382, 230);
1273 logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor*)NULL);
1274 if (!logo) {
1275 logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
1277 if (logo) {
1278 size = WMGetPixmapSize(logo);
1279 panel->logoL = WMCreateLabel(panel->win);
1280 WMResizeWidget(panel->logoL, 64, 64);
1281 WMMoveWidget(panel->logoL, 30, 20);
1282 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1283 WMSetLabelImage(panel->logoL, logo);
1284 #ifdef SILLYNESS
1285 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
1286 handleLogoPush, panel);
1287 #endif
1288 WMReleasePixmap(logo);
1291 panel->name1L = WMCreateLabel(panel->win);
1292 WMResizeWidget(panel->name1L, 240, 30);
1293 WMMoveWidget(panel->name1L, 100, 30);
1294 color1.red = 0;
1295 color1.green = 0;
1296 color1.blue = 0;
1297 color2.red = 0x50;
1298 color2.green = 0x50;
1299 color2.blue = 0x70;
1300 logo = renderText(scr->wmscreen, "GNU Window Maker",
1301 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1302 if (logo) {
1303 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1304 WMSetLabelImage(panel->name1L, logo);
1305 WMReleasePixmap(logo);
1306 } else {
1307 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1308 if (font) {
1309 WMSetLabelFont(panel->name1L, font);
1310 WMReleaseFont(font);
1312 WMSetLabelTextAlignment(panel->name1L, WACenter);
1313 WMSetLabelText(panel->name1L, "GNU Window Maker");
1316 panel->name2L = WMCreateLabel(panel->win);
1317 WMResizeWidget(panel->name2L, 240, 24);
1318 WMMoveWidget(panel->name2L, 100, 60);
1319 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1320 if (font) {
1321 WMSetLabelFont(panel->name2L, font);
1322 WMReleaseFont(font);
1323 font = NULL;
1325 WMSetLabelTextAlignment(panel->name2L, WACenter);
1326 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1329 snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
1330 panel->versionL = WMCreateLabel(panel->win);
1331 WMResizeWidget(panel->versionL, 310, 16);
1332 WMMoveWidget(panel->versionL, 30, 95);
1333 WMSetLabelTextAlignment(panel->versionL, WARight);
1334 WMSetLabelText(panel->versionL, buffer);
1335 WMSetLabelWraps(panel->versionL, False);
1337 panel->copyrL = WMCreateLabel(panel->win);
1338 WMResizeWidget(panel->copyrL, 340, 40);
1339 WMMoveWidget(panel->copyrL, 15, 185);
1340 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1341 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1342 /* we want the (c) character in the helvetica font */
1343 font = WMCreateNormalFont(scr->wmscreen, HELVETICA10_FONT);
1344 if (font) {
1345 WMSetLabelFont(panel->copyrL, font);
1348 strbuf = NULL;
1349 snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
1350 (unsigned)scr->w_visual->visualid,
1351 visuals[scr->w_visual->class], scr->w_depth);
1353 strbuf = wstrappend(strbuf, buffer);
1355 switch (scr->w_depth) {
1356 case 15:
1357 strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
1358 break;
1359 case 16:
1360 strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
1361 break;
1362 case 24:
1363 case 32:
1364 strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
1365 break;
1366 default:
1367 snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1<<scr->w_depth);
1368 strbuf = wstrappend(strbuf, buffer);
1369 break;
1373 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1375 struct mallinfo ma = mallinfo();
1376 snprintf(buffer, sizeof(buffer),
1377 _("Total allocated memory: %i kB. Total memory in use: %i kB.\n"),
1378 (ma.arena+ma.hblkhd)/1024, (ma.uordblks+ma.hblkhd)/1024);
1380 strbuf = wstrappend(strbuf, buffer);
1382 #endif
1384 strbuf = wstrappend(strbuf, _("Supported image formats: "));
1385 strl = RSupportedFileFormats();
1386 for (i=0; strl[i]!=NULL; i++) {
1387 strbuf = wstrappend(strbuf, strl[i]);
1388 strbuf = wstrappend(strbuf, " ");
1391 strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
1393 char *list[8];
1394 char buf[80];
1395 int j = 0;
1397 #ifdef MWM_HINTS
1398 list[j++] = "MWM";
1399 #endif
1400 #ifdef KWM_HINTS
1401 list[j++] = "KDE";
1402 #endif
1403 #ifdef GNOME_STUFF
1404 list[j++] = "GNOME";
1405 #endif
1406 #ifdef OLWM_HINTS
1407 list[j++] = "OLWM";
1408 #endif
1410 buf[0] = 0;
1411 for (i = 0; i < j; i++) {
1412 if (i > 0) {
1413 if (i == j - 1)
1414 strcat(buf, _(" and "));
1415 else
1416 strcat(buf, ", ");
1418 strcat(buf, list[i]);
1420 strbuf = wstrappend(strbuf, buf);
1423 if (wPreferences.no_sound) {
1424 strbuf = wstrappend(strbuf, _("\nSound disabled"));
1425 } else {
1426 strbuf = wstrappend(strbuf, _("\nSound enabled"));
1430 panel->infoL = WMCreateLabel(panel->win);
1431 WMResizeWidget(panel->infoL, 350, 75);
1432 WMMoveWidget(panel->infoL, 15, 115);
1433 WMSetLabelText(panel->infoL, strbuf);
1434 if (font) {
1435 WMSetLabelFont(panel->infoL, font);
1436 WMReleaseFont(font);
1438 wfree(strbuf);
1441 WMRealizeWidget(panel->win);
1442 WMMapSubwidgets(panel->win);
1444 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1446 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1448 WMMapWidget(panel->win);
1450 wwin = wManageInternalWindow(scr, parent, None, _("Info"),
1451 (scr->scr_width - 382)/2,
1452 (scr->scr_height - 230)/2, 382, 230);
1454 WSETUFLAG(wwin, no_closable, 0);
1455 WSETUFLAG(wwin, no_close_button, 0);
1456 #ifdef XKB_BUTTON_HINT
1457 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1458 #endif
1459 wWindowUpdateButtonImages(wwin);
1460 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1461 wwin->frame->on_click_right = destroyInfoPanel;
1463 wWindowMap(wwin);
1465 panel->wwin = wwin;
1467 thePanel = panel;
1468 #ifdef SILLYNESS
1469 if (InitXThing(panel->scr)) {
1470 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1471 panel->cycle = 0;
1472 panel->x = 1;
1473 panel->str = _("Merry X'mas!");
1474 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1476 #endif
1481 ***********************************************************************
1482 * Legal Panel
1483 ***********************************************************************
1486 typedef struct {
1487 WScreen *scr;
1489 WWindow *wwin;
1491 WMWindow *win;
1493 WMLabel *licenseL;
1494 } LegalPanel;
1497 static LegalPanel *legalPanel = NULL;
1499 static void
1500 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1502 WMUnmapWidget(legalPanel->win);
1504 WMDestroyWidget(legalPanel->win);
1506 wUnmanageWindow(legalPanel->wwin, False, False);
1508 wfree(legalPanel);
1510 legalPanel = NULL;
1514 void
1515 wShowLegalPanel(WScreen *scr)
1517 LegalPanel *panel;
1518 Window parent;
1519 WWindow *wwin;
1521 if (legalPanel) {
1522 if (legalPanel->scr == scr) {
1523 wRaiseFrame(legalPanel->wwin->frame->core);
1524 wSetFocusTo(scr, legalPanel->wwin);
1526 return;
1529 panel = wmalloc(sizeof(LegalPanel));
1531 panel->scr = scr;
1533 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1534 WMResizeWidget(panel->win, 420, 250);
1537 panel->licenseL = WMCreateLabel(panel->win);
1538 WMSetLabelWraps(panel->licenseL, True);
1539 WMResizeWidget(panel->licenseL, 400, 230);
1540 WMMoveWidget(panel->licenseL, 10, 10);
1541 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1542 WMSetLabelText(panel->licenseL,
1543 _(" Window Maker is free software; you can redistribute it and/or\n"
1544 "modify it under the terms of the GNU General Public License as\n"
1545 "published by the Free Software Foundation; either version 2 of the\n"
1546 "License, or (at your option) any later version.\n\n\n"
1547 " Window Maker is distributed in the hope that it will be useful,\n"
1548 "but WITHOUT ANY WARRANTY; without even the implied warranty\n"
1549 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
1550 "See the GNU General Public License for more details.\n\n\n"
1551 " You should have received a copy of the GNU General Public\n"
1552 "License along with this program; if not, write to the Free Software\n"
1553 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
1554 "02111-1307, USA."));
1555 WMSetLabelRelief(panel->licenseL, WRGroove);
1557 WMRealizeWidget(panel->win);
1558 WMMapSubwidgets(panel->win);
1560 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1562 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1564 wwin = wManageInternalWindow(scr, parent, None, _("Legal"),
1565 (scr->scr_width - 420)/2,
1566 (scr->scr_height - 250)/2, 420, 250);
1568 WSETUFLAG(wwin, no_closable, 0);
1569 WSETUFLAG(wwin, no_close_button, 0);
1570 wWindowUpdateButtonImages(wwin);
1571 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1572 #ifdef XKB_BUTTON_HINT
1573 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1574 #endif
1575 wwin->frame->on_click_right = destroyLegalPanel;
1577 panel->wwin = wwin;
1579 WMMapWidget(panel->win);
1581 wWindowMap(wwin);
1583 legalPanel = panel;
1588 ***********************************************************************
1589 * Crashing Dialog Panel
1590 ***********************************************************************
1593 extern WDDomain *WDWindowAttributes;
1596 typedef struct _CrashPanel {
1597 WMWindow *win; /* main window */
1599 WMLabel *iconL; /* application icon */
1600 WMLabel *nameL; /* title of panel */
1602 WMFrame *sepF; /* separator frame */
1604 WMLabel *noteL; /* Title of note */
1605 WMLabel *note2L; /* body of note with what happened */
1607 WMFrame *whatF; /* "what to do next" frame */
1608 WMPopUpButton *whatP; /* action selection popup button */
1610 WMButton *okB; /* ok button */
1612 Bool done; /* if finished with this dialog */
1613 int action; /* what to do after */
1615 KeyCode retKey;
1617 } CrashPanel;
1620 static void
1621 handleKeyPress(XEvent *event, void *clientData)
1623 CrashPanel *panel = (CrashPanel*)clientData;
1625 if (event->xkey.keycode == panel->retKey) {
1626 WMPerformButtonClick(panel->okB);
1631 static void
1632 okButtonCallback(void *self, void *clientData)
1634 CrashPanel *panel = (CrashPanel*)clientData;
1636 panel->done = True;
1640 static void
1641 setCrashAction(void *self, void *clientData)
1643 WMPopUpButton *pop = (WMPopUpButton*)self;
1644 CrashPanel *panel = (CrashPanel*)clientData;
1646 panel->action = WMGetPopUpButtonSelectedItem(pop);
1650 static WMPixmap*
1651 getWindowMakerIconImage(WMScreen *scr)
1653 WMPropList *dict, *key, *option, *value=NULL;
1654 WMPixmap *pix=NULL;
1655 char *path;
1657 WMPLSetCaseSensitive(True);
1659 key = WMCreatePLString("Logo.WMPanel");
1660 option = WMCreatePLString("Icon");
1662 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
1664 if (dict) {
1665 value = WMGetFromPLDictionary(dict, option);
1668 WMReleasePropList(key);
1669 WMReleasePropList(option);
1671 WMPLSetCaseSensitive(False);
1673 if (value && WMIsPLString(value)) {
1674 path = FindImage(wPreferences.icon_path, WMGetFromPLString(value));
1676 if (path) {
1677 RColor gray;
1679 gray.red = 0xae; gray.green = 0xaa;
1680 gray.blue = 0xae; gray.alpha = 0;
1682 pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
1683 wfree(path);
1687 return pix;
1691 #define PWIDTH 295
1692 #define PHEIGHT 345
1696 wShowCrashingDialogPanel(int whatSig)
1698 CrashPanel *panel;
1699 WMScreen *scr;
1700 WMFont *font;
1701 WMPixmap *logo;
1702 int screen_no, scr_width, scr_height;
1703 int action;
1704 char buf[256];
1706 panel = wmalloc(sizeof(CrashPanel));
1707 memset(panel, 0, sizeof(CrashPanel));
1709 screen_no = DefaultScreen(dpy);
1710 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1711 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1713 scr = WMCreateScreen(dpy, screen_no);
1714 if (!scr) {
1715 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
1716 return WMAbort;
1719 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1721 panel->win = WMCreateWindow(scr, "crashingDialog");
1722 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1723 WMMoveWidget(panel->win, (scr_width - PWIDTH)/2, (scr_height - PHEIGHT)/2);
1725 logo = getWindowMakerIconImage(scr);
1726 if (logo) {
1727 panel->iconL = WMCreateLabel(panel->win);
1728 WMResizeWidget(panel->iconL, 64, 64);
1729 WMMoveWidget(panel->iconL, 10, 10);
1730 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1731 WMSetLabelImage(panel->iconL, logo);
1734 panel->nameL = WMCreateLabel(panel->win);
1735 WMResizeWidget(panel->nameL, 190, 18);
1736 WMMoveWidget(panel->nameL, 80, 35);
1737 WMSetLabelTextAlignment(panel->nameL, WALeft);
1738 font = WMBoldSystemFontOfSize(scr, 18);
1739 WMSetLabelFont(panel->nameL, font);
1740 WMReleaseFont(font);
1741 WMSetLabelText(panel->nameL, _("Fatal error"));
1743 panel->sepF = WMCreateFrame(panel->win);
1744 WMResizeWidget(panel->sepF, PWIDTH+4, 2);
1745 WMMoveWidget(panel->sepF, -2, 80);
1747 panel->noteL = WMCreateLabel(panel->win);
1748 WMResizeWidget(panel->noteL, PWIDTH-20, 40);
1749 WMMoveWidget(panel->noteL, 10, 90);
1750 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1751 #ifdef SYS_SIGLIST_DECLARED
1752 snprintf(buf, sizeof(buf), _("Window Maker received signal %i\n(%s)."),
1753 whatSig, sys_siglist[whatSig]);
1754 #else
1755 snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
1756 #endif
1757 WMSetLabelText(panel->noteL, buf);
1759 panel->note2L = WMCreateLabel(panel->win);
1760 WMResizeWidget(panel->note2L, PWIDTH-20, 100);
1761 WMMoveWidget(panel->note2L, 10, 130);
1762 WMSetLabelTextAlignment(panel->note2L, WALeft);
1763 WMSetLabelText(panel->note2L,
1764 _(" This fatal error occured probably due to a bug."
1765 " Please fill the included BUGFORM and "
1766 "report it to bugs@windowmaker.org."));
1767 WMSetLabelWraps(panel->note2L, True);
1770 panel->whatF = WMCreateFrame(panel->win);
1771 WMResizeWidget(panel->whatF, PWIDTH-20, 50);
1772 WMMoveWidget(panel->whatF, 10, 240);
1773 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1775 panel->whatP = WMCreatePopUpButton(panel->whatF);
1776 WMResizeWidget(panel->whatP, PWIDTH-20-70, 20);
1777 WMMoveWidget(panel->whatP, 35, 20);
1778 WMSetPopUpButtonPullsDown(panel->whatP, False);
1779 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1780 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1781 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1782 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1783 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1784 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1785 panel->action = WMRestart;
1787 WMMapSubwidgets(panel->whatF);
1789 panel->okB = WMCreateCommandButton(panel->win);
1790 WMResizeWidget(panel->okB, 80, 26);
1791 WMMoveWidget(panel->okB, 205, 309);
1792 WMSetButtonText(panel->okB, _("OK"));
1793 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1794 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1795 WMSetButtonImagePosition(panel->okB, WIPRight);
1796 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1798 panel->done = 0;
1800 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask,
1801 handleKeyPress, panel);
1803 WMRealizeWidget(panel->win);
1804 WMMapSubwidgets(panel->win);
1806 WMMapWidget(panel->win);
1808 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1810 while (!panel->done) {
1811 XEvent event;
1813 WMNextEvent(dpy, &event);
1814 WMHandleEvent(&event);
1817 action = panel->action;
1819 WMUnmapWidget(panel->win);
1820 WMDestroyWidget(panel->win);
1821 wfree(panel);
1823 return action;
1829 /*****************************************************************************
1830 * About GNUstep Panel
1831 *****************************************************************************/
1834 static void
1835 drawGNUstepLogo(Display *dpy, Drawable d, int width, int height,
1836 unsigned long blackPixel, unsigned long whitePixel)
1838 GC gc;
1839 XGCValues gcv;
1840 XRectangle rects[3];
1842 gcv.foreground = blackPixel;
1843 gc = XCreateGC(dpy, d, GCForeground, &gcv);
1845 XFillArc(dpy, d, gc, width/45, height/45,
1846 width - 2*width/45, height - 2*height/45, 0, 360*64);
1848 rects[0].x = 0;
1849 rects[0].y = 37*height/45;
1850 rects[0].width = width/3;
1851 rects[0].height = height - rects[0].y;
1853 rects[1].x = rects[0].width;
1854 rects[1].y = height/2;
1855 rects[1].width = width - 2*width/3;
1856 rects[1].height = height - rects[1].y;
1858 rects[2].x = 2*width/3;
1859 rects[2].y = height - 37*height/45;
1860 rects[2].width = width/3;
1861 rects[2].height = height - rects[2].y;
1863 XSetClipRectangles(dpy, gc, 0, 0, rects, 3, Unsorted);
1864 XFillRectangle(dpy, d, gc, 0, 0, width, height);
1866 XSetForeground(dpy, gc, whitePixel);
1867 XFillArc(dpy, d, gc, width/45, height/45,
1868 width - 2*width/45, height - 2*height/45, 0, 360*64);
1870 XFreeGC(dpy, gc);
1874 typedef struct {
1875 WScreen *scr;
1877 WWindow *wwin;
1879 WMWindow *win;
1881 WMLabel *gstepL;
1882 WMLabel *textL;
1883 } GNUstepPanel;
1886 static GNUstepPanel *gnustepPanel = NULL;
1888 static void
1889 destroyGNUstepPanel(WCoreWindow *foo, void *data, XEvent *event)
1891 WMUnmapWidget(gnustepPanel->win);
1893 WMDestroyWidget(gnustepPanel->win);
1895 wUnmanageWindow(gnustepPanel->wwin, False, False);
1897 wfree(gnustepPanel);
1899 gnustepPanel = NULL;
1903 void
1904 wShowGNUstepPanel(WScreen *scr)
1906 GNUstepPanel *panel;
1907 Window parent;
1908 WWindow *wwin;
1909 WMPixmap *pixmap;
1910 WMColor *color;
1912 if (gnustepPanel) {
1913 if (gnustepPanel->scr == scr) {
1914 wRaiseFrame(gnustepPanel->wwin->frame->core);
1915 wSetFocusTo(scr, gnustepPanel->wwin);
1917 return;
1920 panel = wmalloc(sizeof(GNUstepPanel));
1922 panel->scr = scr;
1924 panel->win = WMCreateWindow(scr->wmscreen, "About GNUstep");
1925 WMResizeWidget(panel->win, 325, 200);
1927 pixmap = WMCreatePixmap(scr->wmscreen, 130, 130,
1928 WMScreenDepth(scr->wmscreen), True);
1930 color = WMCreateNamedColor(scr->wmscreen, "gray50", True);
1932 drawGNUstepLogo(dpy, WMGetPixmapXID(pixmap), 130, 130,
1933 WMColorPixel(color), scr->white_pixel);
1935 WMReleaseColor(color);
1937 XSetForeground(dpy, scr->mono_gc, 0);
1938 XFillRectangle(dpy, WMGetPixmapMaskXID(pixmap), scr->mono_gc, 0, 0,
1939 130, 130);
1940 drawGNUstepLogo(dpy, WMGetPixmapMaskXID(pixmap), 130, 130, 1, 1);
1942 panel->gstepL = WMCreateLabel(panel->win);
1943 WMResizeWidget(panel->gstepL, 285, 64);
1944 WMMoveWidget(panel->gstepL, 20, 0);
1945 WMSetLabelTextAlignment(panel->gstepL, WARight);
1946 WMSetLabelText(panel->gstepL, "GNUstep");
1948 WMFont *font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
1950 WMSetLabelFont(panel->gstepL, font);
1951 WMReleaseFont(font);
1954 panel->textL = WMCreateLabel(panel->win);
1955 WMResizeWidget(panel->textL, 275, 130);
1956 WMMoveWidget(panel->textL, 30, 50);
1957 WMSetLabelTextAlignment(panel->textL, WARight);
1958 WMSetLabelImagePosition(panel->textL, WIPOverlaps);
1959 WMSetLabelText(panel->textL,
1960 _("Window Maker is part of the GNUstep project.\n"\
1961 "The GNUstep project aims to create a free\n"\
1962 "implementation of the OpenStep(tm) specification\n"\
1963 "which is a object-oriented framework for\n"\
1964 "creating advanced graphical, multi-platform\n"\
1965 "applications. Additionally, a development and\n"\
1966 "user desktop enviroment will be created on top\n"\
1967 "of the framework. For more information about\n"\
1968 "GNUstep, please visit: www.gnustep.org"));
1969 WMSetLabelImage(panel->textL, pixmap);
1971 WMReleasePixmap(pixmap);
1973 WMRealizeWidget(panel->win);
1974 WMMapSubwidgets(panel->win);
1976 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 325, 200, 0, 0, 0);
1978 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1980 wwin = wManageInternalWindow(scr, parent, None, _("About GNUstep"),
1981 (scr->scr_width - 325)/2,
1982 (scr->scr_height - 200)/2, 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;