Code refactoring: replaced macro 'HAVE_XRANDR' by 'USE_XRANDR' for consistency
[wmaker-crm.git] / src / dialog.c
blob43f12fcbb5d87d69548e048ce15b239b2d304667
1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <dirent.h>
36 #include <limits.h>
38 #ifdef HAVE_MALLOC_H
39 #include <malloc.h>
40 #endif
42 #include <signal.h>
43 #ifdef __FreeBSD__
44 #include <sys/signal.h>
45 #endif
47 #ifndef PATH_MAX
48 #define PATH_MAX DEFAULT_PATH_MAX
49 #endif
51 #include "WindowMaker.h"
52 #include "GNUstep.h"
53 #include "screen.h"
54 #include "window.h"
55 #include "dialog.h"
56 #include "misc.h"
57 #include "stacking.h"
58 #include "framewin.h"
59 #include "window.h"
60 #include "actions.h"
61 #include "xinerama.h"
64 static WMPoint getCenter(WScreen * scr, int width, int height)
66 return wGetPointToCenterRectInHead(scr, wGetHeadForPointerLocation(scr), width, height);
69 int wMessageDialog(WScreen *scr, const char *title, const char *message, const char *defBtn, const char *altBtn, const char *othBtn)
71 WMAlertPanel *panel;
72 Window parent;
73 WWindow *wwin;
74 int result;
75 WMPoint center;
77 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn);
79 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
81 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
83 center = getCenter(scr, 400, 180);
84 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180);
85 wwin->client_leader = WMWidgetXID(panel->win);
87 WMMapWidget(panel->win);
89 wWindowMap(wwin);
91 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
93 result = panel->result;
95 WMUnmapWidget(panel->win);
97 wUnmanageWindow(wwin, False, False);
99 WMDestroyAlertPanel(panel);
101 XDestroyWindow(dpy, parent);
103 return result;
106 static void toggleSaveSession(WMWidget *w, void *data)
108 /* Parameter not used, but tell the compiler that it is ok */
109 (void) data;
111 wPreferences.save_session_on_exit = WMGetButtonSelected((WMButton *) w);
114 int wExitDialog(WScreen *scr, const char *title, const char *message, const char *defBtn, const char *altBtn, const char *othBtn)
116 WMAlertPanel *panel;
117 WMButton *saveSessionBtn;
118 Window parent;
119 WWindow *wwin;
120 WMPoint center;
121 int result;
123 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn);
125 /* add save session button */
126 saveSessionBtn = WMCreateSwitchButton(panel->hbox);
127 WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
128 WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn), False, True, 200, 0, 0);
129 WMSetButtonText(saveSessionBtn, _("Save workspace state"));
130 WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
131 WMRealizeWidget(saveSessionBtn);
132 WMMapWidget(saveSessionBtn);
134 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
136 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
138 center = getCenter(scr, 400, 180);
139 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180);
141 wwin->client_leader = WMWidgetXID(panel->win);
143 WMMapWidget(panel->win);
145 wWindowMap(wwin);
147 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
149 result = panel->result;
151 WMUnmapWidget(panel->win);
153 wUnmanageWindow(wwin, False, False);
155 WMDestroyAlertPanel(panel);
157 XDestroyWindow(dpy, parent);
159 return result;
162 typedef struct _WMInputPanelWithHistory {
163 WMInputPanel *panel;
164 WMArray *history;
165 int histpos;
166 char *prefix;
167 char *suffix;
168 char *rest;
169 WMArray *variants;
170 int varpos;
171 } WMInputPanelWithHistory;
173 static char *HistoryFileName(const char *name)
175 char *filename = NULL;
177 filename = wstrdup(wusergnusteppath());
178 filename = wstrappend(filename, "/.AppInfo/WindowMaker/History");
179 if (name && strlen(name)) {
180 filename = wstrappend(filename, ".");
181 filename = wstrappend(filename, name);
183 return filename;
186 static int strmatch(const void *str1, const void *str2)
188 return !strcmp((const char *)str1, (const char *)str2);
191 static WMArray *LoadHistory(const char *filename, int max)
193 WMPropList *plhistory;
194 WMPropList *plitem;
195 WMArray *history;
196 int i, num;
197 char *str;
199 history = WMCreateArrayWithDestructor(1, wfree);
200 WMAddToArray(history, wstrdup(""));
202 plhistory = WMReadPropListFromFile(filename);
204 if (plhistory) {
205 if (WMIsPLArray(plhistory)) {
206 num = WMGetPropListItemCount(plhistory);
208 for (i = 0; i < num; ++i) {
209 plitem = WMGetFromPLArray(plhistory, i);
210 if (WMIsPLString(plitem)) {
211 str = WMGetFromPLString(plitem);
212 if (WMFindInArray(history, strmatch, str) == WANotFound) {
214 * The string here is duplicated because it will be freed
215 * automatically when the array is deleted. This is not really
216 * great because it is already an allocated string,
217 * unfortunately we cannot re-use it because it will be freed
218 * when we discard the PL (and we don't want to waste the PL's
219 * memory either)
221 WMAddToArray(history, wstrdup(str));
222 if (--max <= 0)
223 break;
228 WMReleasePropList(plhistory);
231 return history;
234 static void SaveHistory(WMArray * history, const char *filename)
236 int i;
237 WMPropList *plhistory;
239 plhistory = WMCreatePLArray(NULL);
241 for (i = 0; i < WMGetArrayItemCount(history); ++i)
242 WMAddToPLArray(plhistory, WMCreatePLString(WMGetFromArray(history, i)));
244 WMWritePropListToFile(plhistory, filename);
245 WMReleasePropList(plhistory);
248 static int pstrcmp(const char **str1, const char **str2)
250 return strcmp(*str1, *str2);
253 static void
254 ScanFiles(const char *dir, const char *prefix, unsigned acceptmask, unsigned declinemask, WMArray * result)
256 int prefixlen;
257 DIR *d;
258 struct dirent *de;
259 struct stat sb;
260 char *fullfilename, *suffix;
262 prefixlen = strlen(prefix);
263 if ((d = opendir(dir)) != NULL) {
264 while ((de = readdir(d)) != NULL) {
265 if (strlen(de->d_name) > prefixlen &&
266 !strncmp(prefix, de->d_name, prefixlen) &&
267 strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..")) {
268 fullfilename = wstrconcat((char *)dir, "/");
269 fullfilename = wstrappend(fullfilename, de->d_name);
271 if (stat(fullfilename, &sb) == 0 &&
272 (sb.st_mode & acceptmask) &&
273 !(sb.st_mode & declinemask) &&
274 WMFindInArray(result, (WMMatchDataProc *) strmatch,
275 de->d_name + prefixlen) == WANotFound) {
276 suffix = wstrdup(de->d_name + prefixlen);
277 if (sb.st_mode & S_IFDIR)
278 wstrappend(suffix,"/");
279 WMAddToArray(result, suffix);
281 wfree(fullfilename);
284 closedir(d);
288 static WMArray *GenerateVariants(const char *complete)
290 Bool firstWord = True;
291 WMArray *variants = NULL;
292 char *pos = NULL, *path = NULL, *tmp = NULL, *dir = NULL, *prefix = NULL;
294 variants = WMCreateArrayWithDestructor(0, wfree);
296 while (*complete == ' ')
297 ++complete;
299 if ((pos = strrchr(complete, ' ')) != NULL) {
300 complete = pos + 1;
301 firstWord = False;
304 if ((pos = strrchr(complete, '/')) != NULL) {
305 tmp = wstrndup((char *)complete, pos - complete + 1);
306 if (*tmp == '~' && *(tmp + 1) == '/' && getenv("HOME")) {
307 dir = wstrdup(getenv("HOME"));
308 dir = wstrappend(dir, tmp + 1);
309 wfree(tmp);
310 } else {
311 dir = tmp;
313 prefix = wstrdup(pos + 1);
314 ScanFiles(dir, prefix, (unsigned)-1, 0, variants);
315 wfree(dir);
316 wfree(prefix);
317 } else if (*complete == '~') {
318 WMAddToArray(variants, wstrdup("/"));
319 } else if (firstWord) {
320 path = getenv("PATH");
321 while (path) {
322 pos = strchr(path, ':');
323 if (pos) {
324 tmp = wstrndup(path, pos - path);
325 path = pos + 1;
326 } else if (*path != '\0') {
327 tmp = wstrdup(path);
328 path = NULL;
329 } else
330 break;
331 ScanFiles(tmp, complete, S_IXOTH | S_IXGRP | S_IXUSR, S_IFDIR, variants);
332 wfree(tmp);
336 WMSortArray(variants, (WMCompareDataProc *) pstrcmp);
337 return variants;
340 static void handleHistoryKeyPress(XEvent * event, void *clientData)
342 char *text;
343 unsigned pos;
344 WMInputPanelWithHistory *p = (WMInputPanelWithHistory *) clientData;
345 KeySym ksym;
347 ksym = XLookupKeysym(&event->xkey, 0);
349 switch (ksym) {
350 case XK_Up:
351 if (p->histpos < WMGetArrayItemCount(p->history) - 1) {
352 if (p->histpos == 0)
353 wfree(WMReplaceInArray(p->history, 0, WMGetTextFieldText(p->panel->text)));
354 p->histpos++;
355 WMSetTextFieldText(p->panel->text, WMGetFromArray(p->history, p->histpos));
357 break;
358 case XK_Down:
359 if (p->histpos > 0) {
360 p->histpos--;
361 WMSetTextFieldText(p->panel->text, WMGetFromArray(p->history, p->histpos));
363 break;
364 case XK_Tab:
365 if (!p->variants) {
366 text = WMGetTextFieldText(p->panel->text);
367 pos = WMGetTextFieldCursorPosition(p->panel->text);
368 p->prefix = wstrndup(text, pos);
369 p->suffix = wstrdup(text + pos);
370 wfree(text);
371 p->variants = GenerateVariants(p->prefix);
372 p->varpos = 0;
373 if (!p->variants) {
374 wfree(p->prefix);
375 wfree(p->suffix);
376 p->prefix = NULL;
377 p->suffix = NULL;
380 if (p->variants && p->prefix && p->suffix) {
381 p->varpos++;
382 if (p->varpos > WMGetArrayItemCount(p->variants))
383 p->varpos = 0;
384 if (p->varpos > 0)
385 text = wstrconcat(p->prefix, WMGetFromArray(p->variants, p->varpos - 1));
386 else
387 text = wstrdup(p->prefix);
388 pos = strlen(text);
389 text = wstrappend(text, p->suffix);
390 WMSetTextFieldText(p->panel->text, text);
391 WMSetTextFieldCursorPosition(p->panel->text, pos);
392 wfree(text);
394 break;
396 if (ksym != XK_Tab) {
397 if (p->prefix) {
398 wfree(p->prefix);
399 p->prefix = NULL;
401 if (p->suffix) {
402 wfree(p->suffix);
403 p->suffix = NULL;
405 if (p->variants) {
406 WMFreeArray(p->variants);
407 p->variants = NULL;
412 int wAdvancedInputDialog(WScreen *scr, const char *title, const char *message, const char *name, char **text)
414 WWindow *wwin;
415 Window parent;
416 char *result;
417 WMPoint center;
418 WMInputPanelWithHistory *p;
419 char *filename;
421 filename = HistoryFileName(name);
422 p = wmalloc(sizeof(WMInputPanelWithHistory));
423 p->panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel"));
424 p->history = LoadHistory(filename, wPreferences.history_lines);
425 p->histpos = 0;
426 p->prefix = NULL;
427 p->suffix = NULL;
428 p->rest = NULL;
429 p->variants = NULL;
430 p->varpos = 0;
431 WMCreateEventHandler(WMWidgetView(p->panel->text), KeyPressMask, handleHistoryKeyPress, p);
433 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
434 XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
436 XReparentWindow(dpy, WMWidgetXID(p->panel->win), parent, 0, 0);
438 center = getCenter(scr, 320, 160);
439 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 320, 160);
441 wwin->client_leader = WMWidgetXID(p->panel->win);
443 WMMapWidget(p->panel->win);
445 wWindowMap(wwin);
447 WMRunModalLoop(WMWidgetScreen(p->panel->win), WMWidgetView(p->panel->win));
449 if (p->panel->result == WAPRDefault) {
450 result = WMGetTextFieldText(p->panel->text);
451 wfree(WMReplaceInArray(p->history, 0, wstrdup(result)));
452 SaveHistory(p->history, filename);
453 } else
454 result = NULL;
456 wUnmanageWindow(wwin, False, False);
458 WMDestroyInputPanel(p->panel);
459 WMFreeArray(p->history);
460 wfree(p);
461 wfree(filename);
463 XDestroyWindow(dpy, parent);
465 if (result == NULL)
466 return False;
467 else {
468 if (*text)
469 wfree(*text);
470 *text = result;
472 return True;
476 int wInputDialog(WScreen *scr, const char *title, const char *message, char **text)
478 WWindow *wwin;
479 Window parent;
480 WMInputPanel *panel;
481 char *result;
482 WMPoint center;
484 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel"));
486 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
487 XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
489 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
491 center = getCenter(scr, 320, 160);
492 wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 320, 160);
494 wwin->client_leader = WMWidgetXID(panel->win);
496 WMMapWidget(panel->win);
498 wWindowMap(wwin);
500 WMRunModalLoop(WMWidgetScreen(panel->win), WMWidgetView(panel->win));
502 if (panel->result == WAPRDefault)
503 result = WMGetTextFieldText(panel->text);
504 else
505 result = NULL;
507 wUnmanageWindow(wwin, False, False);
509 WMDestroyInputPanel(panel);
511 XDestroyWindow(dpy, parent);
513 if (result == NULL)
514 return False;
515 else {
516 if (*text)
517 wfree(*text);
518 *text = result;
520 return True;
525 *****************************************************************
526 * Icon Selection Panel
527 *****************************************************************
530 typedef struct IconPanel {
532 WScreen *scr;
534 WMWindow *win;
536 WMLabel *dirLabel;
537 WMLabel *iconLabel;
539 WMList *dirList;
540 WMList *iconList;
541 WMFont *normalfont;
543 WMButton *previewButton;
545 WMLabel *iconView;
547 WMLabel *fileLabel;
548 WMTextField *fileField;
550 WMButton *okButton;
551 WMButton *cancelButton;
552 #if 0
553 WMButton *chooseButton;
554 #endif
555 short done;
556 short result;
557 short preview;
558 } IconPanel;
560 static void listPixmaps(WScreen *scr, WMList *lPtr, const char *path)
562 struct dirent *dentry;
563 DIR *dir;
564 char pbuf[PATH_MAX + 16];
565 char *apath;
566 IconPanel *panel = WMGetHangedData(lPtr);
568 panel->preview = False;
570 apath = wexpandpath(path);
571 dir = opendir(apath);
573 if (!dir) {
574 char *msg;
575 char *tmp;
576 tmp = _("Could not open directory ");
577 msg = wmalloc(strlen(tmp) + strlen(path) + 6);
578 strcpy(msg, tmp);
579 strcat(msg, path);
581 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
582 wfree(msg);
583 wfree(apath);
584 return;
587 /* list contents in the column */
588 while ((dentry = readdir(dir))) {
589 struct stat statb;
591 if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
592 continue;
594 strcpy(pbuf, apath);
595 strcat(pbuf, "/");
596 strcat(pbuf, dentry->d_name);
598 if (stat(pbuf, &statb) < 0)
599 continue;
601 if (statb.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)
602 && statb.st_mode & (S_IFREG | S_IFLNK)) {
603 WMAddListItem(lPtr, dentry->d_name);
606 WMSortListItems(lPtr);
608 closedir(dir);
609 wfree(apath);
610 panel->preview = True;
613 static void setViewedImage(IconPanel *panel, const char *file)
615 WMPixmap *pixmap;
616 RColor color;
618 color.red = 0xae;
619 color.green = 0xaa;
620 color.blue = 0xae;
621 color.alpha = 0;
622 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win), file, &color);
623 if (!pixmap) {
624 WMSetButtonEnabled(panel->okButton, False);
626 WMSetLabelText(panel->iconView, _("Could not load image file "));
628 WMSetLabelImage(panel->iconView, NULL);
629 } else {
630 WMSetButtonEnabled(panel->okButton, True);
632 WMSetLabelText(panel->iconView, NULL);
633 WMSetLabelImage(panel->iconView, pixmap);
634 WMReleasePixmap(pixmap);
638 static void listCallback(void *self, void *data)
640 WMList *lPtr = (WMList *) self;
641 IconPanel *panel = (IconPanel *) data;
642 char *path;
644 if (lPtr == panel->dirList) {
645 WMListItem *item = WMGetListSelectedItem(lPtr);
647 if (item == NULL)
648 return;
649 path = item->text;
651 WMSetTextFieldText(panel->fileField, path);
653 WMSetLabelImage(panel->iconView, NULL);
655 WMSetButtonEnabled(panel->okButton, False);
657 WMClearList(panel->iconList);
658 listPixmaps(panel->scr, panel->iconList, path);
659 } else {
660 char *tmp, *iconFile;
661 WMListItem *item = WMGetListSelectedItem(panel->dirList);
663 if (item == NULL)
664 return;
665 path = item->text;
666 tmp = wexpandpath(path);
668 item = WMGetListSelectedItem(panel->iconList);
669 if (item == NULL)
670 return;
671 iconFile = item->text;
673 path = wmalloc(strlen(tmp) + strlen(iconFile) + 4);
674 strcpy(path, tmp);
675 strcat(path, "/");
676 strcat(path, iconFile);
677 wfree(tmp);
678 WMSetTextFieldText(panel->fileField, path);
679 setViewedImage(panel, path);
680 wfree(path);
684 static void listIconPaths(WMList * lPtr)
686 char *paths;
687 char *path;
689 paths = wstrdup(wPreferences.icon_path);
691 path = strtok(paths, ":");
693 do {
694 char *tmp;
696 tmp = wexpandpath(path);
697 /* do not sort, because the order implies the order of
698 * directories searched */
699 if (access(tmp, X_OK) == 0)
700 WMAddListItem(lPtr, path);
701 wfree(tmp);
702 } while ((path = strtok(NULL, ":")) != NULL);
704 wfree(paths);
707 static void drawIconProc(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
709 IconPanel *panel = WMGetHangedData(lPtr);
710 WScreen *scr = panel->scr;
711 GC gc = scr->draw_gc;
712 GC copygc = scr->copy_gc;
713 char *file, *dirfile;
714 WMPixmap *pixmap;
715 WMColor *back;
716 WMSize size;
717 WMScreen *wmscr = WMWidgetScreen(panel->win);
718 RColor color;
719 int x, y, width, height, len;
721 /* Parameter not used, but tell the compiler that it is ok */
722 (void) index;
724 if (!panel->preview)
725 return;
727 x = rect->pos.x;
728 y = rect->pos.y;
729 width = rect->size.width;
730 height = rect->size.height;
732 back = (state & WLDSSelected) ? scr->white : scr->gray;
734 dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text);
735 len = strlen(dirfile) + strlen(text) + 4;
736 file = wmalloc(len);
737 snprintf(file, len, "%s/%s", dirfile, text);
738 wfree(dirfile);
740 color.red = WMRedComponentOfColor(back) >> 8;
741 color.green = WMGreenComponentOfColor(back) >> 8;
742 color.blue = WMBlueComponentOfColor(back) >> 8;
743 color.alpha = WMGetColorAlpha(back) >> 8;
745 pixmap = WMCreateBlendedPixmapFromFile(wmscr, file, &color);
746 wfree(file);
748 if (!pixmap) {
749 /*WMRemoveListItem(lPtr, index); */
750 return;
753 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
755 XSetClipMask(dpy, gc, None);
756 /*XDrawRectangle(dpy, d, WMColorGC(white), x+5, y+5, width-10, 54); */
757 XDrawLine(dpy, d, WMColorGC(scr->white), x, y + height - 1, x + width, y + height - 1);
759 size = WMGetPixmapSize(pixmap);
761 XSetClipMask(dpy, copygc, WMGetPixmapMaskXID(pixmap));
762 XSetClipOrigin(dpy, copygc, x + (width - size.width) / 2, y + 2);
763 XCopyArea(dpy, WMGetPixmapXID(pixmap), d, copygc, 0, 0,
764 size.width > 100 ? 100 : size.width, size.height > 64 ? 64 : size.height,
765 x + (width - size.width) / 2, y + 2);
768 int i, j;
769 int fheight = WMFontHeight(panel->normalfont);
770 int tlen = strlen(text);
771 int twidth = WMWidthOfString(panel->normalfont, text, tlen);
772 int ofx, ofy;
774 ofx = x + (width - twidth) / 2;
775 ofy = y + 64 - fheight;
777 for (i = -1; i < 2; i++)
778 for (j = -1; j < 2; j++)
779 WMDrawString(wmscr, d, scr->white, panel->normalfont,
780 ofx + i, ofy + j, text, tlen);
782 WMDrawString(wmscr, d, scr->black, panel->normalfont, ofx, ofy, text, tlen);
785 WMReleasePixmap(pixmap);
786 /* I hope it is better to do not use cache / on my box it is fast nuff */
787 XFlush(dpy);
790 static void buttonCallback(void *self, void *clientData)
792 WMButton *bPtr = (WMButton *) self;
793 IconPanel *panel = (IconPanel *) clientData;
795 if (bPtr == panel->okButton) {
796 panel->done = True;
797 panel->result = True;
798 } else if (bPtr == panel->cancelButton) {
799 panel->done = True;
800 panel->result = False;
801 } else if (bPtr == panel->previewButton) {
802 /**** Previewer ****/
803 WMSetButtonEnabled(bPtr, False);
804 WMSetListUserDrawItemHeight(panel->iconList, 68);
805 WMSetListUserDrawProc(panel->iconList, drawIconProc);
806 WMRedisplayWidget(panel->iconList);
807 /* for draw proc to access screen/gc */
808 /*** end preview ***/
810 #if 0
811 else if (bPtr == panel->chooseButton) {
812 WMOpenPanel *op;
814 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
816 if (WMRunModalFilePanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
817 char *path;
818 path = WMGetFilePanelFile(op);
819 WMSetTextFieldText(panel->fileField, path);
820 setViewedImage(panel, path);
821 wfree(path);
823 WMDestroyFilePanel(op);
825 #endif
828 static void keyPressHandler(XEvent * event, void *data)
830 IconPanel *panel = (IconPanel *) data;
831 char buffer[32];
832 KeySym ksym;
833 int iidx;
834 int didx;
835 int item = 0;
836 WMList *list = NULL;
838 if (event->type == KeyRelease)
839 return;
841 buffer[0] = 0;
842 XLookupString(&event->xkey, buffer, sizeof(buffer), &ksym, NULL);
844 iidx = WMGetListSelectedItemRow(panel->iconList);
845 didx = WMGetListSelectedItemRow(panel->dirList);
847 switch (ksym) {
848 case XK_Up:
849 if (iidx > 0)
850 item = iidx - 1;
851 else
852 item = iidx;
853 list = panel->iconList;
854 break;
855 case XK_Down:
856 if (iidx < WMGetListNumberOfRows(panel->iconList) - 1)
857 item = iidx + 1;
858 else
859 item = iidx;
860 list = panel->iconList;
861 break;
862 case XK_Home:
863 item = 0;
864 list = panel->iconList;
865 break;
866 case XK_End:
867 item = WMGetListNumberOfRows(panel->iconList) - 1;
868 list = panel->iconList;
869 break;
870 case XK_Next:
871 if (didx < WMGetListNumberOfRows(panel->dirList) - 1)
872 item = didx + 1;
873 else
874 item = didx;
875 list = panel->dirList;
876 break;
877 case XK_Prior:
878 if (didx > 0)
879 item = didx - 1;
880 else
881 item = 0;
882 list = panel->dirList;
883 break;
884 case XK_Return:
885 WMPerformButtonClick(panel->okButton);
886 break;
887 case XK_Escape:
888 WMPerformButtonClick(panel->cancelButton);
889 break;
892 if (list) {
893 WMSelectListItem(list, item);
894 WMSetListPosition(list, item - 5);
895 listCallback(list, panel);
899 Bool wIconChooserDialog(WScreen *scr, char **file, const char *instance, const char *class)
901 WWindow *wwin;
902 Window parent;
903 IconPanel *panel;
904 WMColor *color;
905 WMFont *boldFont;
906 Bool result;
908 panel = wmalloc(sizeof(IconPanel));
910 panel->scr = scr;
912 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
913 WMResizeWidget(panel->win, 450, 280);
915 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask | KeyReleaseMask, keyPressHandler, panel);
917 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
918 panel->normalfont = WMSystemFontOfSize(WMWidgetScreen(panel->win), 12);
920 panel->dirLabel = WMCreateLabel(panel->win);
921 WMResizeWidget(panel->dirLabel, 200, 20);
922 WMMoveWidget(panel->dirLabel, 10, 7);
923 WMSetLabelText(panel->dirLabel, _("Directories"));
924 WMSetLabelFont(panel->dirLabel, boldFont);
925 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
927 WMSetLabelRelief(panel->dirLabel, WRSunken);
929 panel->iconLabel = WMCreateLabel(panel->win);
930 WMResizeWidget(panel->iconLabel, 140, 20);
931 WMMoveWidget(panel->iconLabel, 215, 7);
932 WMSetLabelText(panel->iconLabel, _("Icons"));
933 WMSetLabelFont(panel->iconLabel, boldFont);
934 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
936 WMReleaseFont(boldFont);
938 color = WMWhiteColor(scr->wmscreen);
939 WMSetLabelTextColor(panel->dirLabel, color);
940 WMSetLabelTextColor(panel->iconLabel, color);
941 WMReleaseColor(color);
943 color = WMDarkGrayColor(scr->wmscreen);
944 WMSetWidgetBackgroundColor(panel->iconLabel, color);
945 WMSetWidgetBackgroundColor(panel->dirLabel, color);
946 WMReleaseColor(color);
948 WMSetLabelRelief(panel->iconLabel, WRSunken);
950 panel->dirList = WMCreateList(panel->win);
951 WMResizeWidget(panel->dirList, 200, 170);
952 WMMoveWidget(panel->dirList, 10, 30);
953 WMSetListAction(panel->dirList, listCallback, panel);
955 panel->iconList = WMCreateList(panel->win);
956 WMResizeWidget(panel->iconList, 140, 170);
957 WMMoveWidget(panel->iconList, 215, 30);
958 WMSetListAction(panel->iconList, listCallback, panel);
960 WMHangData(panel->iconList, panel);
962 panel->previewButton = WMCreateCommandButton(panel->win);
963 WMResizeWidget(panel->previewButton, 75, 26);
964 WMMoveWidget(panel->previewButton, 365, 130);
965 WMSetButtonText(panel->previewButton, _("Preview"));
966 WMSetButtonAction(panel->previewButton, buttonCallback, panel);
968 panel->iconView = WMCreateLabel(panel->win);
969 WMResizeWidget(panel->iconView, 75, 75);
970 WMMoveWidget(panel->iconView, 365, 40);
971 WMSetLabelImagePosition(panel->iconView, WIPOverlaps);
972 WMSetLabelRelief(panel->iconView, WRSunken);
973 WMSetLabelTextAlignment(panel->iconView, WACenter);
975 panel->fileLabel = WMCreateLabel(panel->win);
976 WMResizeWidget(panel->fileLabel, 80, 20);
977 WMMoveWidget(panel->fileLabel, 10, 210);
978 WMSetLabelText(panel->fileLabel, _("File Name:"));
980 panel->fileField = WMCreateTextField(panel->win);
981 WMSetViewNextResponder(WMWidgetView(panel->fileField), WMWidgetView(panel->win));
982 WMResizeWidget(panel->fileField, 345, 20);
983 WMMoveWidget(panel->fileField, 95, 210);
984 WMSetTextFieldEditable(panel->fileField, False);
986 panel->okButton = WMCreateCommandButton(panel->win);
987 WMResizeWidget(panel->okButton, 80, 26);
988 WMMoveWidget(panel->okButton, 360, 240);
989 WMSetButtonText(panel->okButton, _("OK"));
990 WMSetButtonEnabled(panel->okButton, False);
991 WMSetButtonAction(panel->okButton, buttonCallback, panel);
993 panel->cancelButton = WMCreateCommandButton(panel->win);
994 WMResizeWidget(panel->cancelButton, 80, 26);
995 WMMoveWidget(panel->cancelButton, 270, 240);
996 WMSetButtonText(panel->cancelButton, _("Cancel"));
997 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
998 #if 0
999 panel->chooseButton = WMCreateCommandButton(panel->win);
1000 WMResizeWidget(panel->chooseButton, 110, 26);
1001 WMMoveWidget(panel->chooseButton, 150, 240);
1002 WMSetButtonText(panel->chooseButton, _("Choose File"));
1003 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
1004 #endif
1005 WMRealizeWidget(panel->win);
1006 WMMapSubwidgets(panel->win);
1008 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
1010 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1013 char *tmp;
1014 int len = (instance ? strlen(instance) : 0)
1015 + (class ? strlen(class) : 0) + 32;
1016 WMPoint center;
1018 tmp = wmalloc(len);
1020 if (tmp && (instance || class))
1021 snprintf(tmp, len, "%s [%s.%s]", _("Icon Chooser"), instance, class);
1022 else
1023 strcpy(tmp, _("Icon Chooser"));
1025 center = getCenter(scr, 450, 280);
1027 wwin = wManageInternalWindow(scr, parent, None, tmp, center.x, center.y, 450, 280);
1028 wfree(tmp);
1031 /* put icon paths in the list */
1032 listIconPaths(panel->dirList);
1034 WMMapWidget(panel->win);
1036 wWindowMap(wwin);
1038 while (!panel->done) {
1039 XEvent event;
1041 WMNextEvent(dpy, &event);
1042 WMHandleEvent(&event);
1045 if (panel->result) {
1046 char *defaultPath, *wantedPath;
1048 /* check if the file the user selected is not the one that
1049 * would be loaded by default with the current search path */
1050 *file = WMGetListSelectedItem(panel->iconList)->text;
1051 if (**file == 0) {
1052 wfree(*file);
1053 *file = NULL;
1054 } else {
1055 defaultPath = FindImage(wPreferences.icon_path, *file);
1056 wantedPath = WMGetTextFieldText(panel->fileField);
1057 /* if the file is not the default, use full path */
1058 if (strcmp(wantedPath, defaultPath) != 0) {
1059 *file = wantedPath;
1060 } else {
1061 *file = wstrdup(*file);
1062 wfree(wantedPath);
1064 wfree(defaultPath);
1066 } else {
1067 *file = NULL;
1070 result = panel->result;
1072 WMReleaseFont(panel->normalfont);
1074 WMUnmapWidget(panel->win);
1076 WMDestroyWidget(panel->win);
1078 wUnmanageWindow(wwin, False, False);
1080 wfree(panel);
1082 XDestroyWindow(dpy, parent);
1084 return result;
1088 ***********************************************************************
1089 * Info Panel
1090 ***********************************************************************
1093 typedef struct {
1094 WScreen *scr;
1095 WWindow *wwin;
1096 WMWindow *win;
1097 WMLabel *logoL;
1098 WMLabel *name1L;
1099 WMFrame *lineF;
1100 WMLabel *name2L;
1101 WMLabel *versionL;
1102 WMLabel *infoL;
1103 WMLabel *copyrL;
1104 } InfoPanel;
1106 #define COPYRIGHT_TEXT \
1107 "Copyright \xc2\xa9 1997-2006 Alfredo K. Kojima\n"\
1108 "Copyright \xc2\xa9 1998-2006 Dan Pascu\n"\
1109 "Copyright \xc2\xa9 2013 Window Maker Developers Team"
1111 static InfoPanel *thePanel = NULL;
1113 static void destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
1115 /* Parameter not used, but tell the compiler that it is ok */
1116 (void) foo;
1117 (void) data;
1118 (void) event;
1120 WMUnmapWidget(thePanel);
1121 wUnmanageWindow(thePanel->wwin, False, False);
1122 WMDestroyWidget(thePanel->win);
1123 wfree(thePanel);
1124 thePanel = NULL;
1127 void wShowInfoPanel(WScreen *scr)
1129 const int win_width = 382;
1130 const int win_height = 250;
1131 InfoPanel *panel;
1132 WMPixmap *logo;
1133 WMFont *font;
1134 char *name, *strbuf = NULL;
1135 const char *separator;
1136 char buffer[256];
1137 Window parent;
1138 WWindow *wwin;
1139 WMPoint center;
1140 char **strl;
1141 int i, width = 50, sepHeight;
1142 char *visuals[] = {
1143 "StaticGray",
1144 "GrayScale",
1145 "StaticColor",
1146 "PseudoColor",
1147 "TrueColor",
1148 "DirectColor"
1151 if (thePanel) {
1152 if (thePanel->scr == scr) {
1153 wRaiseFrame(thePanel->wwin->frame->core);
1154 wSetFocusTo(scr, thePanel->wwin);
1156 return;
1159 panel = wmalloc(sizeof(InfoPanel));
1161 panel->scr = scr;
1163 panel->win = WMCreateWindow(scr->wmscreen, "info");
1164 WMResizeWidget(panel->win, win_width, win_height);
1166 logo = WMCreateApplicationIconBlendedPixmap(scr->wmscreen, (RColor *) NULL);
1167 if (!logo) {
1168 logo = WMRetainPixmap(WMGetApplicationIconPixmap(scr->wmscreen));
1170 if (logo) {
1171 panel->logoL = WMCreateLabel(panel->win);
1172 WMResizeWidget(panel->logoL, 64, 64);
1173 WMMoveWidget(panel->logoL, 30, 20);
1174 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
1175 WMSetLabelImage(panel->logoL, logo);
1176 WMReleasePixmap(logo);
1179 sepHeight = 3;
1180 panel->name1L = WMCreateLabel(panel->win);
1181 WMResizeWidget(panel->name1L, 240, 30 + 2);
1182 WMMoveWidget(panel->name1L, 100, 30 - 2 - sepHeight);
1184 name = "Lucida Sans,Comic Sans MS,URW Gothic L,Trebuchet MS" ":italic:pixelsize=28:antialias=true";
1185 font = WMCreateFont(scr->wmscreen, name);
1186 strbuf = "Window Maker";
1187 if (font) {
1188 width = WMWidthOfString(font, strbuf, strlen(strbuf));
1189 WMSetLabelFont(panel->name1L, font);
1190 WMReleaseFont(font);
1192 WMSetLabelTextAlignment(panel->name1L, WACenter);
1193 WMSetLabelText(panel->name1L, strbuf);
1195 panel->lineF = WMCreateFrame(panel->win);
1196 WMResizeWidget(panel->lineF, width, sepHeight);
1197 WMMoveWidget(panel->lineF, 100 + (240 - width) / 2, 60 - sepHeight);
1198 WMSetFrameRelief(panel->lineF, WRSimple);
1199 WMSetWidgetBackgroundColor(panel->lineF, scr->black);
1201 panel->name2L = WMCreateLabel(panel->win);
1202 WMResizeWidget(panel->name2L, 240, 24);
1203 WMMoveWidget(panel->name2L, 100, 60);
1204 name = "URW Gothic L,Nimbus Sans L:pixelsize=16:antialias=true";
1205 font = WMCreateFont(scr->wmscreen, name);
1206 if (font) {
1207 WMSetLabelFont(panel->name2L, font);
1208 WMReleaseFont(font);
1209 font = NULL;
1211 WMSetLabelTextAlignment(panel->name2L, WACenter);
1212 WMSetLabelText(panel->name2L, _("Window Manager for X"));
1214 snprintf(buffer, sizeof(buffer), _("Version %s"), VERSION);
1215 panel->versionL = WMCreateLabel(panel->win);
1216 WMResizeWidget(panel->versionL, 310, 16);
1217 WMMoveWidget(panel->versionL, 30, 95);
1218 WMSetLabelTextAlignment(panel->versionL, WARight);
1219 WMSetLabelText(panel->versionL, buffer);
1220 WMSetLabelWraps(panel->versionL, False);
1222 panel->copyrL = WMCreateLabel(panel->win);
1223 WMResizeWidget(panel->copyrL, 360, 60);
1224 WMMoveWidget(panel->copyrL, 15, 185);
1225 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1226 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1227 font = WMSystemFontOfSize(scr->wmscreen, 11);
1228 if (font) {
1229 WMSetLabelFont(panel->copyrL, font);
1230 WMReleaseFont(font);
1231 font = NULL;
1234 strbuf = NULL;
1235 snprintf(buffer, sizeof(buffer), _("Using visual 0x%x: %s %ibpp "),
1236 (unsigned)scr->w_visual->visualid, visuals[scr->w_visual->class], scr->w_depth);
1238 strbuf = wstrappend(strbuf, buffer);
1240 switch (scr->w_depth) {
1241 case 15:
1242 strbuf = wstrappend(strbuf, _("(32 thousand colors)\n"));
1243 break;
1244 case 16:
1245 strbuf = wstrappend(strbuf, _("(64 thousand colors)\n"));
1246 break;
1247 case 24:
1248 case 32:
1249 strbuf = wstrappend(strbuf, _("(16 million colors)\n"));
1250 break;
1251 default:
1252 snprintf(buffer, sizeof(buffer), _("(%d colors)\n"), 1 << scr->w_depth);
1253 strbuf = wstrappend(strbuf, buffer);
1254 break;
1257 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
1259 struct mallinfo ma = mallinfo();
1260 snprintf(buffer, sizeof(buffer),
1261 #ifdef DEBUG
1262 _("Total memory allocated: %i kB (in use: %i kB, %d free chunks).\n"),
1263 #else
1264 _("Total memory allocated: %i kB (in use: %i kB).\n"),
1265 #endif
1266 (ma.arena + ma.hblkhd) / 1024,
1267 (ma.uordblks + ma.hblkhd) / 1024
1268 #ifdef DEBUG
1270 * This information is representative of the memory
1271 * fragmentation. In ideal case it should be 1, but
1272 * that is never possible
1274 , ma.ordblks
1275 #endif
1278 strbuf = wstrappend(strbuf, buffer);
1280 #endif
1282 strbuf = wstrappend(strbuf, _("Supported image formats: "));
1283 strl = RSupportedFileFormats();
1284 separator = NULL;
1285 for (i = 0; strl[i] != NULL; i++) {
1286 if (separator != NULL)
1287 strbuf = wstrappend(strbuf, separator);
1288 strbuf = wstrappend(strbuf, strl[i]);
1289 separator = ", ";
1292 strbuf = wstrappend(strbuf, _("\nAdditional support for: "));
1293 strbuf = wstrappend(strbuf, "WMSPEC");
1295 #ifdef USE_XRANDR
1296 strbuf = wstrappend(strbuf, ", XRandR ");
1297 if (w_global.xext.randr.supported)
1298 strbuf = wstrappend(strbuf, _("(Supported)"));
1299 else
1300 strbuf = wstrappend(strbuf, _("(Unsupported)"));
1301 #endif
1303 #ifdef MWM_HINTS
1304 strbuf = wstrappend(strbuf, ", MWM");
1305 #endif
1307 #ifdef USE_XINERAMA
1308 strbuf = wstrappend(strbuf, _("\n"));
1309 #ifdef SOLARIS_XINERAMA
1310 strbuf = wstrappend(strbuf, _("Solaris "));
1311 #endif
1312 strbuf = wstrappend(strbuf, _("Xinerama: "));
1314 char tmp[128];
1315 snprintf(tmp, sizeof(tmp) - 1, _("%d heads found."), scr->xine_info.count);
1316 strbuf = wstrappend(strbuf, tmp);
1318 #endif
1320 panel->infoL = WMCreateLabel(panel->win);
1321 WMResizeWidget(panel->infoL, 350, 75);
1322 WMMoveWidget(panel->infoL, 15, 115);
1323 WMSetLabelText(panel->infoL, strbuf);
1324 font = WMSystemFontOfSize(scr->wmscreen, 11);
1325 if (font) {
1326 WMSetLabelFont(panel->infoL, font);
1327 WMReleaseFont(font);
1328 font = NULL;
1330 wfree(strbuf);
1332 WMRealizeWidget(panel->win);
1333 WMMapSubwidgets(panel->win);
1335 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, win_width, win_height, 0, 0, 0);
1337 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1339 WMMapWidget(panel->win);
1341 center = getCenter(scr, win_width, win_height);
1342 wwin = wManageInternalWindow(scr, parent, None, _("Info"), center.x, center.y, win_width, win_height);
1344 WSETUFLAG(wwin, no_closable, 0);
1345 WSETUFLAG(wwin, no_close_button, 0);
1346 #ifdef XKB_BUTTON_HINT
1347 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1348 #endif
1349 wWindowUpdateButtonImages(wwin);
1350 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1351 wwin->frame->on_click_right = destroyInfoPanel;
1353 wWindowMap(wwin);
1355 panel->wwin = wwin;
1356 thePanel = panel;
1360 ***********************************************************************
1361 * Legal Panel
1362 ***********************************************************************
1365 typedef struct {
1366 WScreen *scr;
1367 WWindow *wwin;
1368 WMWindow *win;
1369 WMLabel *licenseL;
1370 } LegalPanel;
1372 static LegalPanel *legalPanel = NULL;
1374 static void destroyLegalPanel(WCoreWindow * foo, void *data, XEvent * event)
1376 /* Parameter not used, but tell the compiler that it is ok */
1377 (void) foo;
1378 (void) data;
1379 (void) event;
1381 WMUnmapWidget(legalPanel->win);
1382 WMDestroyWidget(legalPanel->win);
1383 wUnmanageWindow(legalPanel->wwin, False, False);
1384 wfree(legalPanel);
1385 legalPanel = NULL;
1388 void wShowLegalPanel(WScreen *scr)
1390 const int win_width = 420;
1391 const int win_height = 250;
1392 const int margin = 10;
1393 LegalPanel *panel;
1394 Window parent;
1395 WWindow *wwin;
1396 WMPoint center;
1398 if (legalPanel) {
1399 if (legalPanel->scr == scr) {
1400 wRaiseFrame(legalPanel->wwin->frame->core);
1401 wSetFocusTo(scr, legalPanel->wwin);
1403 return;
1406 panel = wmalloc(sizeof(LegalPanel));
1407 panel->scr = scr;
1408 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1409 WMResizeWidget(panel->win, win_width, win_height);
1411 panel->licenseL = WMCreateLabel(panel->win);
1412 WMSetLabelWraps(panel->licenseL, True);
1413 WMResizeWidget(panel->licenseL, win_width - (2 * margin), win_height - (2 * margin));
1414 WMMoveWidget(panel->licenseL, margin, margin);
1415 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1416 WMSetLabelText(panel->licenseL,
1417 _(" Window Maker is free software; you can redistribute it and/or "
1418 "modify it under the terms of the GNU General Public License as "
1419 "published by the Free Software Foundation; either version 2 of the "
1420 "License, or (at your option) any later version.\n\n"
1421 " Window Maker is distributed in the hope that it will be useful, "
1422 "but WITHOUT ANY WARRANTY; without even the implied warranty "
1423 "of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. "
1424 "See the GNU General Public License for more details.\n\n"
1425 " You should have received a copy of the GNU General Public "
1426 "License along with this program; if not, write to the Free Software "
1427 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA"
1428 "02110-1301 USA."));
1429 WMSetLabelRelief(panel->licenseL, WRGroove);
1431 WMRealizeWidget(panel->win);
1432 WMMapSubwidgets(panel->win);
1434 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, win_width, win_height, 0, 0, 0);
1435 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1436 center = getCenter(scr, win_width, win_height);
1437 wwin = wManageInternalWindow(scr, parent, None, _("Legal"), center.x, center.y, win_width, win_height);
1439 WSETUFLAG(wwin, no_closable, 0);
1440 WSETUFLAG(wwin, no_close_button, 0);
1441 wWindowUpdateButtonImages(wwin);
1442 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1443 #ifdef XKB_BUTTON_HINT
1444 wFrameWindowHideButton(wwin->frame, WFF_LANGUAGE_BUTTON);
1445 #endif
1446 wwin->frame->on_click_right = destroyLegalPanel;
1447 panel->wwin = wwin;
1449 WMMapWidget(panel->win);
1450 wWindowMap(wwin);
1451 legalPanel = panel;
1455 ***********************************************************************
1456 * Crashing Dialog Panel
1457 ***********************************************************************
1460 typedef struct _CrashPanel {
1461 WMWindow *win; /* main window */
1463 WMLabel *iconL; /* application icon */
1464 WMLabel *nameL; /* title of panel */
1466 WMFrame *sepF; /* separator frame */
1468 WMLabel *noteL; /* Title of note */
1469 WMLabel *note2L; /* body of note with what happened */
1471 WMFrame *whatF; /* "what to do next" frame */
1472 WMPopUpButton *whatP; /* action selection popup button */
1474 WMButton *okB; /* ok button */
1476 Bool done; /* if finished with this dialog */
1477 int action; /* what to do after */
1479 KeyCode retKey;
1481 } CrashPanel;
1483 static void handleKeyPress(XEvent * event, void *clientData)
1485 CrashPanel *panel = (CrashPanel *) clientData;
1487 if (event->xkey.keycode == panel->retKey) {
1488 WMPerformButtonClick(panel->okB);
1492 static void okButtonCallback(void *self, void *clientData)
1494 CrashPanel *panel = (CrashPanel *) clientData;
1496 /* Parameter not used, but tell the compiler that it is ok */
1497 (void) self;
1499 panel->done = True;
1502 static void setCrashAction(void *self, void *clientData)
1504 WMPopUpButton *pop = (WMPopUpButton *) self;
1505 CrashPanel *panel = (CrashPanel *) clientData;
1507 panel->action = WMGetPopUpButtonSelectedItem(pop);
1510 /* Make this read the logo from a compiled in pixmap -Dan */
1511 static WMPixmap *getWindowMakerIconImage(WMScreen *scr)
1513 WMPixmap *pix = NULL;
1514 char *path = NULL;
1516 /* Get the Logo icon, without the default icon */
1517 path = get_icon_filename("Logo", "WMPanel", NULL, False);
1519 if (path) {
1520 RColor gray;
1522 gray.red = 0xae;
1523 gray.green = 0xaa;
1524 gray.blue = 0xae;
1525 gray.alpha = 0;
1527 pix = WMCreateBlendedPixmapFromFile(scr, path, &gray);
1528 wfree(path);
1531 return pix;
1534 #define PWIDTH 295
1535 #define PHEIGHT 345
1537 int wShowCrashingDialogPanel(int whatSig)
1539 CrashPanel *panel;
1540 WMScreen *scr;
1541 WMFont *font;
1542 WMPixmap *logo;
1543 int screen_no, scr_width, scr_height;
1544 int action;
1545 char buf[256];
1547 panel = wmalloc(sizeof(CrashPanel));
1549 screen_no = DefaultScreen(dpy);
1550 scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_no));
1551 scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_no));
1553 scr = WMCreateScreen(dpy, screen_no);
1554 if (!scr) {
1555 werror(_("cannot open connection for crashing dialog panel. Aborting."));
1556 return WMAbort;
1559 panel->retKey = XKeysymToKeycode(dpy, XK_Return);
1561 panel->win = WMCreateWindow(scr, "crashingDialog");
1562 WMResizeWidget(panel->win, PWIDTH, PHEIGHT);
1563 WMMoveWidget(panel->win, (scr_width - PWIDTH) / 2, (scr_height - PHEIGHT) / 2);
1565 logo = getWindowMakerIconImage(scr);
1566 if (logo) {
1567 panel->iconL = WMCreateLabel(panel->win);
1568 WMResizeWidget(panel->iconL, 64, 64);
1569 WMMoveWidget(panel->iconL, 10, 10);
1570 WMSetLabelImagePosition(panel->iconL, WIPImageOnly);
1571 WMSetLabelImage(panel->iconL, logo);
1574 panel->nameL = WMCreateLabel(panel->win);
1575 WMResizeWidget(panel->nameL, 200, 30);
1576 WMMoveWidget(panel->nameL, 80, 25);
1577 WMSetLabelTextAlignment(panel->nameL, WALeft);
1578 font = WMBoldSystemFontOfSize(scr, 24);
1579 WMSetLabelFont(panel->nameL, font);
1580 WMReleaseFont(font);
1581 WMSetLabelText(panel->nameL, _("Fatal error"));
1583 panel->sepF = WMCreateFrame(panel->win);
1584 WMResizeWidget(panel->sepF, PWIDTH + 4, 2);
1585 WMMoveWidget(panel->sepF, -2, 80);
1587 panel->noteL = WMCreateLabel(panel->win);
1588 WMResizeWidget(panel->noteL, PWIDTH - 20, 40);
1589 WMMoveWidget(panel->noteL, 10, 90);
1590 WMSetLabelTextAlignment(panel->noteL, WAJustified);
1591 snprintf(buf, sizeof(buf), _("Window Maker received signal %i."), whatSig);
1592 WMSetLabelText(panel->noteL, buf);
1594 panel->note2L = WMCreateLabel(panel->win);
1595 WMResizeWidget(panel->note2L, PWIDTH - 20, 100);
1596 WMMoveWidget(panel->note2L, 10, 130);
1597 WMSetLabelTextAlignment(panel->note2L, WALeft);
1598 WMSetLabelText(panel->note2L,
1599 _(" This fatal error occured probably due to a bug."
1600 " Please fill the included BUGFORM and " "report it to bugs@windowmaker.info."));
1601 WMSetLabelWraps(panel->note2L, True);
1603 panel->whatF = WMCreateFrame(panel->win);
1604 WMResizeWidget(panel->whatF, PWIDTH - 20, 50);
1605 WMMoveWidget(panel->whatF, 10, 240);
1606 WMSetFrameTitle(panel->whatF, _("What do you want to do now?"));
1608 panel->whatP = WMCreatePopUpButton(panel->whatF);
1609 WMResizeWidget(panel->whatP, PWIDTH - 20 - 70, 20);
1610 WMMoveWidget(panel->whatP, 35, 20);
1611 WMSetPopUpButtonPullsDown(panel->whatP, False);
1612 WMSetPopUpButtonText(panel->whatP, _("Select action"));
1613 WMAddPopUpButtonItem(panel->whatP, _("Abort and leave a core file"));
1614 WMAddPopUpButtonItem(panel->whatP, _("Restart Window Maker"));
1615 WMAddPopUpButtonItem(panel->whatP, _("Start alternate window manager"));
1616 WMSetPopUpButtonAction(panel->whatP, setCrashAction, panel);
1617 WMSetPopUpButtonSelectedItem(panel->whatP, WMRestart);
1618 panel->action = WMRestart;
1620 WMMapSubwidgets(panel->whatF);
1622 panel->okB = WMCreateCommandButton(panel->win);
1623 WMResizeWidget(panel->okB, 80, 26);
1624 WMMoveWidget(panel->okB, 205, 309);
1625 WMSetButtonText(panel->okB, _("OK"));
1626 WMSetButtonImage(panel->okB, WMGetSystemPixmap(scr, WSIReturnArrow));
1627 WMSetButtonAltImage(panel->okB, WMGetSystemPixmap(scr, WSIHighlightedReturnArrow));
1628 WMSetButtonImagePosition(panel->okB, WIPRight);
1629 WMSetButtonAction(panel->okB, okButtonCallback, panel);
1631 panel->done = 0;
1633 WMCreateEventHandler(WMWidgetView(panel->win), KeyPressMask, handleKeyPress, panel);
1635 WMRealizeWidget(panel->win);
1636 WMMapSubwidgets(panel->win);
1638 WMMapWidget(panel->win);
1640 XSetInputFocus(dpy, WMWidgetXID(panel->win), RevertToParent, CurrentTime);
1642 while (!panel->done) {
1643 XEvent event;
1645 WMNextEvent(dpy, &event);
1646 WMHandleEvent(&event);
1649 action = panel->action;
1651 WMUnmapWidget(panel->win);
1652 WMDestroyWidget(panel->win);
1653 wfree(panel);
1655 return action;