Update for 0.51.0
[wmaker-crm.git] / src / dialog.c
blob51cf5cb1e74734c0422d447aa34fcebcad9c6671
1 /* dialog.c - dialog windows for internal use
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * 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 #ifndef PATH_MAX
39 #define PATH_MAX DEFAULT_PATH_MAX
40 #endif
42 #include "WindowMaker.h"
43 #include "GNUstep.h"
44 #include "screen.h"
45 #include "dialog.h"
46 #include "funcs.h"
47 #include "stacking.h"
48 #include "framewin.h"
49 #include "window.h"
50 #include "actions.h"
51 #include "defaults.h"
54 extern WPreferences wPreferences;
58 int
59 wMessageDialog(WScreen *scr, char *title, char *message,
60 char *defBtn, char *altBtn, char *othBtn)
62 WMAlertPanel *panel;
63 Window parent;
64 WWindow *wwin;
65 int result;
67 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
68 defBtn, altBtn, othBtn);
70 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
72 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
74 wwin = wManageInternalWindow(scr, parent, None, NULL,
75 (scr->scr_width - 400)/2,
76 (scr->scr_height - 180)/2, 400, 180);
77 wwin->client_leader = WMWidgetXID(panel->win);
79 WMMapWidget(panel->win);
81 wWindowMap(wwin);
83 while (!panel->done) {
84 XEvent event;
86 WMNextEvent(dpy, &event);
87 WMHandleEvent(&event);
90 result = panel->result;
92 WMUnmapWidget(panel->win);
94 wUnmanageWindow(wwin, False, False);
96 WMDestroyAlertPanel(panel);
98 XDestroyWindow(dpy, parent);
100 return result;
106 wInputDialog(WScreen *scr, char *title, char *message, char **text)
108 WWindow *wwin;
109 Window parent;
110 WMInputPanel *panel;
111 char *result;
114 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
115 _("OK"), _("Cancel"));
118 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
119 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
121 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
123 wwin = wManageInternalWindow(scr, parent, None, NULL,
124 (scr->scr_width - 320)/2,
125 (scr->scr_height - 160)/2, 320, 160);
127 wwin->client_leader = WMWidgetXID(panel->win);
129 WMMapWidget(panel->win);
131 wWindowMap(wwin);
133 while (!panel->done) {
134 XEvent event;
136 WMNextEvent(dpy, &event);
137 WMHandleEvent(&event);
140 if (panel->result == WAPRDefault)
141 result = WMGetTextFieldText(panel->text);
142 else
143 result = NULL;
145 wUnmanageWindow(wwin, False, False);
147 WMDestroyInputPanel(panel);
149 XDestroyWindow(dpy, parent);
151 if (result==NULL)
152 return False;
153 else {
154 if (*text)
155 free(*text);
156 *text = result;
158 return True;
164 *****************************************************************
165 * Icon Selection Panel
166 *****************************************************************
169 typedef struct IconPanel {
171 WScreen *scr;
173 WMWindow *win;
175 WMLabel *dirLabel;
176 WMLabel *iconLabel;
178 WMList *dirList;
179 WMList *iconList;
181 WMLabel *iconView;
183 WMLabel *fileLabel;
184 WMTextField *fileField;
186 WMButton *okButton;
187 WMButton *cancelButton;
188 #if 0
189 WMButton *chooseButton;
190 #endif
191 short done;
192 short result;
193 } IconPanel;
197 static void
198 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
200 struct dirent *dentry;
201 DIR *dir;
202 char pbuf[PATH_MAX+16];
203 char *apath;
205 apath = wexpandpath(path);
206 dir = opendir(apath);
208 if (!dir) {
209 char *msg;
210 char *tmp;
211 tmp = _("Could not open directory ");
212 msg = wmalloc(strlen(tmp)+strlen(path)+6);
213 strcpy(msg, tmp);
214 strcat(msg, path);
216 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
217 free(msg);
218 free(apath);
219 return;
222 /* list contents in the column */
223 while ((dentry = readdir(dir))) {
224 struct stat statb;
226 if (strcmp(dentry->d_name, ".")==0 ||
227 strcmp(dentry->d_name, "..")==0)
228 continue;
230 strcpy(pbuf, apath);
231 strcat(pbuf, "/");
232 strcat(pbuf, dentry->d_name);
234 if (stat(pbuf, &statb)<0)
235 continue;
237 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
238 && statb.st_mode & (S_IFREG|S_IFLNK)) {
239 WMAddSortedListItem(lPtr, dentry->d_name);
243 closedir(dir);
244 free(apath);
249 static void
250 setViewedImage(IconPanel *panel, char *file)
252 WMPixmap *pixmap;
253 RColor color;
255 color.red = 0xae;
256 color.green = 0xaa;
257 color.blue = 0xae;
258 color.alpha = 0;
259 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
260 file, &color);
261 if (!pixmap) {
262 char *msg;
263 char *tmp;
265 WMSetButtonEnabled(panel->okButton, False);
267 tmp = _("Could not load image file ");
268 msg = wmalloc(strlen(tmp)+strlen(file)+6);
269 strcpy(msg, tmp);
270 strcat(msg, file);
272 wMessageDialog(panel->scr, _("Error"), msg, _("OK"), NULL, NULL);
273 free(msg);
275 WMSetLabelImage(panel->iconView, NULL);
276 } else {
277 WMSetButtonEnabled(panel->okButton, True);
279 WMSetLabelImage(panel->iconView, pixmap);
280 WMReleasePixmap(pixmap);
285 static void
286 listCallback(void *self, void *data)
288 WMList *lPtr = (WMList*)self;
289 IconPanel *panel = (IconPanel*)data;
290 char *path;
292 if (lPtr==panel->dirList) {
293 path = WMGetListSelectedItem(lPtr)->text;
295 WMSetTextFieldText(panel->fileField, path);
297 WMSetLabelImage(panel->iconView, NULL);
299 WMSetButtonEnabled(panel->okButton, False);
301 WMClearList(panel->iconList);
302 listPixmaps(panel->scr, panel->iconList, path);
303 } else {
304 char *tmp, *iconFile;
306 path = WMGetListSelectedItem(panel->dirList)->text;
307 tmp = wexpandpath(path);
309 iconFile = WMGetListSelectedItem(panel->iconList)->text;
311 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
312 strcpy(path, tmp);
313 strcat(path, "/");
314 strcat(path, iconFile);
315 free(tmp);
316 WMSetTextFieldText(panel->fileField, path);
317 setViewedImage(panel, path);
318 free(path);
323 static void
324 listIconPaths(WMList *lPtr)
326 char *paths;
327 char *path;
329 paths = wstrdup(wPreferences.icon_path);
331 path = strtok(paths, ":");
333 do {
334 char *tmp;
336 tmp = wexpandpath(path);
337 /* do not sort, because the order implies the order of
338 * directories searched */
339 if (access(tmp, X_OK)==0)
340 WMAddListItem(lPtr, tmp);
341 free(tmp);
342 } while ((path=strtok(NULL, ":"))!=NULL);
344 free(paths);
349 static void
350 buttonCallback(void *self, void *clientData)
352 WMButton *bPtr = (WMButton*)self;
353 IconPanel *panel = (IconPanel*)clientData;
356 if (bPtr==panel->okButton) {
357 panel->done = True;
358 panel->result = True;
359 } else if (bPtr==panel->cancelButton) {
360 panel->done = True;
361 panel->result = False;
363 #if 0
364 else if (bPtr==panel->chooseButton) {
365 WMOpenPanel *op;
367 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
369 if (WMRunModalOpenPanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
370 char *path;
371 path = WMGetFilePanelFile(op);
372 WMSetTextFieldText(panel->fileField, path);
373 setViewedImage(panel, path);
374 free(path);
376 WMDestroyFilePanel(op);
378 #endif
382 Bool
383 wIconChooserDialog(WScreen *scr, char **file, char *instance, char *class)
385 WWindow *wwin;
386 Window parent;
387 IconPanel *panel;
388 WMColor *color;
389 WMFont *boldFont;
391 panel = wmalloc(sizeof(IconPanel));
392 memset(panel, 0, sizeof(IconPanel));
394 panel->scr = scr;
396 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
397 WMResizeWidget(panel->win, 450, 280);
399 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
401 panel->dirLabel = WMCreateLabel(panel->win);
402 WMResizeWidget(panel->dirLabel, 200, 20);
403 WMMoveWidget(panel->dirLabel, 10, 7);
404 WMSetLabelText(panel->dirLabel, _("Directories"));
405 WMSetLabelFont(panel->dirLabel, boldFont);
406 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
408 WMSetLabelRelief(panel->dirLabel, WRSunken);
410 panel->iconLabel = WMCreateLabel(panel->win);
411 WMResizeWidget(panel->iconLabel, 140, 20);
412 WMMoveWidget(panel->iconLabel, 215, 7);
413 WMSetLabelText(panel->iconLabel, _("Icons"));
414 WMSetLabelFont(panel->iconLabel, boldFont);
415 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
417 WMReleaseFont(boldFont);
419 color = WMWhiteColor(scr->wmscreen);
420 WMSetLabelTextColor(panel->dirLabel, color);
421 WMSetLabelTextColor(panel->iconLabel, color);
422 WMReleaseColor(color);
424 color = WMDarkGrayColor(scr->wmscreen);
425 WMSetWidgetBackgroundColor(panel->iconLabel, color);
426 WMSetWidgetBackgroundColor(panel->dirLabel, color);
427 WMReleaseColor(color);
429 WMSetLabelRelief(panel->iconLabel, WRSunken);
431 panel->dirList = WMCreateList(panel->win);
432 WMResizeWidget(panel->dirList, 200, 170);
433 WMMoveWidget(panel->dirList, 10, 30);
434 WMSetListAction(panel->dirList, listCallback, panel);
436 panel->iconList = WMCreateList(panel->win);
437 WMResizeWidget(panel->iconList, 140, 170);
438 WMMoveWidget(panel->iconList, 215, 30);
439 WMSetListAction(panel->iconList, listCallback, panel);
441 panel->iconView = WMCreateLabel(panel->win);
442 WMResizeWidget(panel->iconView, 75, 75);
443 WMMoveWidget(panel->iconView, 365, 60);
444 WMSetLabelImagePosition(panel->iconView, WIPImageOnly);
445 WMSetLabelRelief(panel->iconView, WRSunken);
447 panel->fileLabel = WMCreateLabel(panel->win);
448 WMResizeWidget(panel->fileLabel, 80, 20);
449 WMMoveWidget(panel->fileLabel, 10, 210);
450 WMSetLabelText(panel->fileLabel, _("File Name:"));
452 panel->fileField = WMCreateTextField(panel->win);
453 WMResizeWidget(panel->fileField, 345, 20);
454 WMMoveWidget(panel->fileField, 95, 210);
455 WMSetTextFieldEnabled(panel->fileField, False);
457 panel->okButton = WMCreateCommandButton(panel->win);
458 WMResizeWidget(panel->okButton, 80, 26);
459 WMMoveWidget(panel->okButton, 360, 240);
460 WMSetButtonText(panel->okButton, _("OK"));
461 WMSetButtonEnabled(panel->okButton, False);
462 WMSetButtonAction(panel->okButton, buttonCallback, panel);
464 panel->cancelButton = WMCreateCommandButton(panel->win);
465 WMResizeWidget(panel->cancelButton, 80, 26);
466 WMMoveWidget(panel->cancelButton, 270, 240);
467 WMSetButtonText(panel->cancelButton, _("Cancel"));
468 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
469 #if 0
470 panel->chooseButton = WMCreateCommandButton(panel->win);
471 WMResizeWidget(panel->chooseButton, 110, 26);
472 WMMoveWidget(panel->chooseButton, 150, 240);
473 WMSetButtonText(panel->chooseButton, _("Choose File"));
474 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
475 #endif
476 WMRealizeWidget(panel->win);
477 WMMapSubwidgets(panel->win);
479 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
481 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
484 char *tmp;
486 tmp = malloc((instance ? strlen(instance) : 0)
487 + (class ? strlen(class) : 0) + 32);
489 if (tmp && (instance || class))
490 sprintf(tmp, "%s [%s.%s]", _("Icon Chooser"), instance, class);
491 else
492 tmp = _("Icon Chooser");
494 wwin = wManageInternalWindow(scr, parent, None, tmp,
495 (scr->scr_width - 450)/2,
496 (scr->scr_height - 280)/2, 450, 280);
497 free(tmp);
500 /* put icon paths in the list */
501 listIconPaths(panel->dirList);
503 WMMapWidget(panel->win);
505 wWindowMap(wwin);
507 while (!panel->done) {
508 XEvent event;
510 WMNextEvent(dpy, &event);
511 WMHandleEvent(&event);
514 if (panel->result) {
515 char *defaultPath, *wantedPath;
517 /* check if the file the user selected is not the one that
518 * would be loaded by default with the current search path */
519 *file = WMGetListSelectedItem(panel->iconList)->text;
520 if ((*file)[0]==0) {
521 free(*file);
522 *file = NULL;
523 } else {
524 defaultPath = FindImage(wPreferences.icon_path, *file);
525 wantedPath = WMGetTextFieldText(panel->fileField);
526 /* if the file is not the default, use full path */
527 if (strcmp(wantedPath, defaultPath)!=0) {
528 *file = wantedPath;
529 } else {
530 *file = wstrdup(*file);
531 free(wantedPath);
533 free(defaultPath);
535 } else {
536 *file = NULL;
539 WMUnmapWidget(panel->win);
541 WMDestroyWidget(panel->win);
543 wUnmanageWindow(wwin, False, False);
545 free(panel);
547 XDestroyWindow(dpy, parent);
549 return panel->result;
554 ***********************************************************************
555 * Info Panel
556 ***********************************************************************
560 typedef struct {
561 WScreen *scr;
563 WWindow *wwin;
565 WMWindow *win;
567 WMLabel *logoL;
568 WMLabel *name1L;
569 WMLabel *name2L;
571 WMLabel *versionL;
573 WMLabel *infoL;
575 WMLabel *copyrL;
577 #ifdef SILLYNESS
578 WMHandlerID timer;
579 int cycle;
580 RImage *icon;
581 RImage *pic;
582 WMPixmap *oldPix;
583 char *str;
584 char x;
585 #endif
586 } InfoPanel;
590 #define COPYRIGHT_TEXT \
591 "Copyright \xa9 1997~1999 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
592 "Copyright \xa9 1998,1999 Dan Pascu <dan@windowmaker.org>"
596 static InfoPanel *thePanel = NULL;
598 static void
599 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
601 #ifdef SILLYNESS
602 if (thePanel->timer) {
603 WMDeleteTimerHandler(thePanel->timer);
605 if (thePanel->oldPix) {
606 WMReleasePixmap(thePanel->oldPix);
608 if (thePanel->icon) {
609 RDestroyImage(thePanel->icon);
611 if (thePanel->pic) {
612 RDestroyImage(thePanel->pic);
614 #endif /* SILLYNESS */
615 WMUnmapWidget(thePanel);
617 WMDestroyWidget(thePanel->win);
619 wUnmanageWindow(thePanel->wwin, False, False);
621 free(thePanel);
623 thePanel = NULL;
627 WMPixmap*
628 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
630 WMPixmap *wpix = NULL;
631 Pixmap grad = None;
632 Pixmap mask = None;
633 RContext *rc = WMScreenRContext(scr);
634 XFontStruct *f = NULL;
635 int w, h;
636 GC gc = None;
638 f = XLoadQueryFont(dpy, font);
639 if (!f)
640 return NULL;
642 w = XTextWidth(f, text, strlen(text));
643 h = f->ascent+f->descent;
645 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
646 gc = XCreateGC(dpy, mask, 0, NULL);
647 XSetForeground(dpy, gc, 0);
648 XSetFont(dpy, gc, f->fid);
649 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
651 XSetForeground(dpy, gc, 1);
652 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
653 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
654 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
656 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
658 WMColor *color;
660 color = WMBlackColor(scr);
661 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
662 WMReleaseColor(color);
665 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
667 if (gc)
668 XFreeGC(dpy, gc);
669 XFreeFont(dpy, f);
671 return wpix;
674 #ifdef SILLYNESS
676 extern WMPixmap *DoXThing();
677 extern Bool InitXThing();
679 static void
680 logoPushCallback(void *data)
682 InfoPanel *panel = (InfoPanel*)data;
683 char buffer[512];
684 int i;
685 int len;
687 if (panel->x) {
688 if (!(panel->cycle % 4)) {
689 WMPixmap *p;
691 p = DoXThing(panel->wwin);
692 WMSetLabelImage(panel->logoL, p);
694 } else if (panel->cycle < 30) {
695 RImage *image;
696 WMPixmap *pix;
698 image = RCloneImage(panel->icon);
699 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
700 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
701 RDestroyImage(image);
702 WMSetLabelImage(panel->logoL, pix);
703 WMReleasePixmap(pix);
706 i = panel->cycle%200;
708 len = strlen(panel->str);
710 strncpy(buffer, panel->str, i<len ? i : len);
711 if (i >= len)
712 memset(&buffer[len], ' ', i-len);
714 strncpy(buffer, panel->str, i<len ? i : len);
715 if (i >= len)
716 memset(&buffer[len], ' ', i-len);
717 buffer[i]=0;
718 WMSetLabelText(panel->versionL, buffer);
720 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
721 panel->cycle++;
725 static void
726 handleLogoPush(XEvent *event, void *data)
728 InfoPanel *panel = (InfoPanel*)data;
729 static int broken = 0;
730 static int clicks = 0;
731 static char *pic_data[] = {
732 "45 45 57 1",
733 " c None",
734 ". c #000000",
735 "X c #383C00",
736 "o c #515500",
737 "O c #616100",
738 "+ c #616900",
739 "@ c #696D00",
740 "# c #697100",
741 "$ c #495100",
742 "% c #202800",
743 "& c #969600",
744 "* c #CFCF00",
745 "= c #D7DB00",
746 "- c #D7D700",
747 "; c #C7CB00",
748 ": c #A6AA00",
749 "> c #494900",
750 ", c #8E8E00",
751 "< c #DFE700",
752 "1 c #F7FF00",
753 "2 c #FFFF00",
754 "3 c #E7EB00",
755 "4 c #B6B600",
756 "5 c #595900",
757 "6 c #717500",
758 "7 c #AEB200",
759 "8 c #CFD300",
760 "9 c #E7EF00",
761 "0 c #EFF300",
762 "q c #9EA200",
763 "w c #F7FB00",
764 "e c #F7F700",
765 "r c #BEBE00",
766 "t c #8E9200",
767 "y c #EFF700",
768 "u c #969A00",
769 "i c #414500",
770 "p c #595D00",
771 "a c #E7E700",
772 "s c #C7C700",
773 "d c #797D00",
774 "f c #BEC300",
775 "g c #DFE300",
776 "h c #868600",
777 "j c #EFEF00",
778 "k c #9E9E00",
779 "l c #616500",
780 "z c #DFDF00",
781 "x c #868A00",
782 "c c #969200",
783 "v c #B6BA00",
784 "b c #A6A600",
785 "n c #8E8A00",
786 "m c #717100",
787 "M c #AEAE00",
788 "N c #AEAA00",
789 "B c #868200",
790 " ............... ",
791 " ....XoO+@##+O$%.... ",
792 " ...%X&*========-;;:o... ",
793 " ...>.>,<122222222222134@... ",
794 " ..>5678912222222222222220q%.. ",
795 " ..$.&-w2222222222222222222er>.. ",
796 " ..O.t31222222222222222222222y4>.. ",
797 " ...O5u3222222222222222222222222yri... ",
798 " ..>p&a22222222222222222222222222wso.. ",
799 " ..ids91222222222222222222222222222wfi.. ",
800 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
801 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
802 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
803 " ..o7y22222222v...r222222223hX.i82222221si.. ",
804 "..io*222222222&...u22222222yt..%*22222220:%. ",
805 "..>k02222222227...f222222222v..X=222222229t. ",
806 "..dz12222222220ui:y2222222223d%qw222222221g. ",
807 ".%vw222222222221y2222222222219*y2222222222wd.",
808 ".X;2222222222222222222222222222222222222222b.",
809 ".i*2222222222222222222222222222222222222222v.",
810 ".i*2222222222222222222222222222222222222222;.",
811 ".i*22222222222222222222222222222222222222228.",
812 ".>*2222222222222222222222222222222222222222=.",
813 ".i*22222222222222222222222222222222222222228.",
814 ".i*2222222222222222222222222222222222222222;.",
815 ".X*222222222222222222222222222222we12222222r.",
816 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
817 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
818 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
819 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
820 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
821 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
822 " ...:e2222218mdz22222222222222a&$vw222220@...",
823 " ...O-122222y:.u02222222222229q$uj222221r... ",
824 " ..%&a1222223&573w2222222219NOxz122221z>... ",
825 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
826 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
827 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
828 " ..Xb9122222109g-****;<y22221zn%... ",
829 " ..X&801222222222222222222w-h.... ",
830 " ...o:=022222222222222221=lX... ",
831 " ..X@:;3w2222222222210fO... ",
832 " ...XX&v8<30000003-N@... ",
833 " .....XmnbN:q&Bo.... ",
834 " ............ "};
835 static char *msgs[] = {
836 "Sloppy focus is a *?#@",
837 "Repent! Sloppy focus users will burn in hell!!!",
838 "Have a nice day!"
841 clicks++;
842 if (!panel->timer && !broken && clicks > 2) {
843 char *file;
844 char *path;
846 panel->x = 0;
847 clicks = 0;
848 if (!panel->icon) {
849 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
850 if (!file) {
851 broken = 1;
852 return;
855 path = FindImage(wPreferences.icon_path, file);
856 if (!path) {
857 broken = 1;
858 return;
861 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
862 free(path);
863 if (!panel->icon) {
864 broken = 1;
865 return;
868 if (!panel->pic) {
869 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
870 if (!panel->pic || panel->icon->width!=panel->pic->width
871 || panel->icon->height!=panel->pic->height) {
872 broken = 1;
873 RDestroyImage(panel->icon);
874 panel->icon = NULL;
875 if (panel->pic) {
876 RDestroyImage(panel->pic);
877 panel->pic = NULL;
879 return;
883 RColor color;
884 color.red = 0xae;
885 color.green = 0xaa;
886 color.blue = 0xae;
887 color.alpha = 255;
888 RCombineImageWithColor(panel->icon, &color);
889 RCombineImageWithColor(panel->pic, &color);
893 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
895 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
896 panel->cycle = 0;
897 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
898 } else if (panel->timer) {
899 char version[20];
901 panel->x = 0;
902 clicks = 0;
903 WMSetLabelImage(panel->logoL, panel->oldPix);
904 WMReleasePixmap(panel->oldPix);
905 panel->oldPix = NULL;
907 WMDeleteTimerHandler(panel->timer);
908 panel->timer = NULL;
910 sprintf(version, "Version %s", VERSION);
911 WMSetLabelText(panel->versionL, version);
915 XEvent ev;
916 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
917 ButtonPress, &ev));
920 #endif /* SILLYNESS */
923 void
924 wShowInfoPanel(WScreen *scr)
926 InfoPanel *panel;
927 WMPixmap *logo;
928 WMSize size;
929 WMFont *font;
930 char version[32];
931 char buffer[512];
932 Window parent;
933 WWindow *wwin;
934 RColor color1, color2;
935 char **strl;
936 int i;
937 char *visuals[] = {
938 "StaticGray",
939 "GrayScale",
940 "StaticColor",
941 "PseudoColor",
942 "TrueColor",
943 "DirectColor"
947 if (thePanel) {
948 wRaiseFrame(thePanel->wwin->frame->core);
949 wSetFocusTo(scr, thePanel->wwin);
950 return;
953 panel = wmalloc(sizeof(InfoPanel));
954 memset(panel, 0, sizeof(InfoPanel));
956 panel->scr = scr;
958 panel->win = WMCreateWindow(scr->wmscreen, "info");
959 WMResizeWidget(panel->win, 382, 230);
961 logo = WMGetApplicationIconImage(scr->wmscreen);
962 if (logo) {
963 size = WMGetPixmapSize(logo);
964 panel->logoL = WMCreateLabel(panel->win);
965 WMResizeWidget(panel->logoL, 64, 64);
966 WMMoveWidget(panel->logoL, 30, 20);
967 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
968 WMSetLabelImage(panel->logoL, logo);
969 #ifdef SILLYNESS
970 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
971 handleLogoPush, panel);
972 #endif
975 panel->name1L = WMCreateLabel(panel->win);
976 WMResizeWidget(panel->name1L, 200, 30);
977 WMMoveWidget(panel->name1L, 120, 30);
978 color1.red = 0;
979 color1.green = 0;
980 color1.blue = 0;
981 color2.red = 0x50;
982 color2.green = 0x50;
983 color2.blue = 0x70;
984 logo = renderText(scr->wmscreen, " Window Maker ",
985 "-*-times-bold-r-*-*-24-*", &color1, &color2);
986 if (logo) {
987 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
988 WMSetLabelImage(panel->name1L, logo);
989 WMReleasePixmap(logo);
990 } else {
991 font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
992 if (font) {
993 WMSetLabelFont(panel->name1L, font);
994 WMReleaseFont(font);
996 WMSetLabelText(panel->name1L, "Window Maker");
999 panel->name2L = WMCreateLabel(panel->win);
1000 WMResizeWidget(panel->name2L, 200, 24);
1001 WMMoveWidget(panel->name2L, 120, 60);
1002 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1003 if (font) {
1004 WMSetLabelFont(panel->name2L, font);
1005 WMReleaseFont(font);
1006 font = NULL;
1008 WMSetLabelText(panel->name2L, "X11 Window Manager");
1011 sprintf(version, "Version %s", VERSION);
1012 panel->versionL = WMCreateLabel(panel->win);
1013 WMResizeWidget(panel->versionL, 310, 16);
1014 WMMoveWidget(panel->versionL, 30, 95);
1015 WMSetLabelTextAlignment(panel->versionL, WARight);
1016 WMSetLabelText(panel->versionL, version);
1017 WMSetLabelWraps(panel->versionL, False);
1019 panel->copyrL = WMCreateLabel(panel->win);
1020 WMResizeWidget(panel->copyrL, 340, 40);
1021 WMMoveWidget(panel->copyrL, 15, 185);
1022 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1023 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1024 /* we want the (c) character in the helvetica font */
1025 font = WMCreateFontInDefaultEncoding(scr->wmscreen, HELVETICA10_FONT);
1026 if (font) {
1027 WMSetLabelFont(panel->copyrL, font);
1030 switch (scr->w_depth) {
1031 case 15:
1032 strcpy(version, "32 thousand");
1033 break;
1034 case 16:
1035 strcpy(version, "64 thousand");
1036 break;
1037 case 24:
1038 case 32:
1039 strcpy(version, "16 million");
1040 break;
1041 default:
1042 sprintf(version, "%d", 1<<scr->w_depth);
1043 break;
1046 sprintf(buffer, "Using visual 0x%x: %s %ibpp (%s colors)\n",
1047 (unsigned)scr->w_visual->visualid,
1048 visuals[scr->w_visual->class], scr->w_depth, version);
1050 strcat(buffer, "Supported image formats: ");
1051 strl = RSupportedFileFormats();
1052 for (i=0; strl[i]!=NULL; i++) {
1053 strcat(buffer, strl[i]);
1054 strcat(buffer, " ");
1057 strcat(buffer, "\nAdditional Support For: ");
1059 char *list[8];
1060 char buf[80];
1061 int j = 0;
1063 #ifdef MWM_HINTS
1064 list[j++] = "MWM";
1065 #endif
1066 #ifdef KWM_HINTS
1067 list[j++] = "KDE";
1068 #endif
1069 #ifdef GNOME_STUFF
1070 list[j++] = "GNOME";
1071 #endif
1072 #ifdef OLWM_HINTS
1073 list[j++] = "OLWM";
1074 #endif
1075 #ifdef WMSOUND
1076 list[j++] = "Sound";
1077 #endif
1079 buf[0] = 0;
1080 for (i = 0; i < j; i++) {
1081 if (i > 0) {
1082 if (i == j - 1)
1083 strcat(buf, " and ");
1084 else
1085 strcat(buf, ", ");
1087 strcat(buf, list[i]);
1089 strcat(buffer, buf);
1093 panel->infoL = WMCreateLabel(panel->win);
1094 WMResizeWidget(panel->infoL, 350, 75);
1095 WMMoveWidget(panel->infoL, 15, 115);
1096 WMSetLabelText(panel->infoL, buffer);
1097 if (font) {
1098 WMSetLabelFont(panel->infoL, font);
1099 WMReleaseFont(font);
1103 WMRealizeWidget(panel->win);
1104 WMMapSubwidgets(panel->win);
1106 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1108 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1110 WMMapWidget(panel->win);
1112 wwin = wManageInternalWindow(scr, parent, None, "Info",
1113 (scr->scr_width - 382)/2,
1114 (scr->scr_height - 230)/2, 382, 230);
1116 WSETUFLAG(wwin, no_closable, 0);
1117 WSETUFLAG(wwin, no_close_button, 0);
1118 wWindowUpdateButtonImages(wwin);
1119 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1120 wwin->frame->on_click_right = destroyInfoPanel;
1122 wWindowMap(wwin);
1124 panel->wwin = wwin;
1126 thePanel = panel;
1128 if (InitXThing(panel->scr)) {
1129 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1130 panel->cycle = 0;
1131 panel->x = 1;
1132 panel->str = "Merry X'mas!";
1133 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1139 ***********************************************************************
1140 * Legal Panel
1141 ***********************************************************************
1144 typedef struct {
1145 WScreen *scr;
1147 WWindow *wwin;
1149 WMWindow *win;
1151 WMLabel *licenseL;
1152 } LegalPanel;
1156 #define LICENSE_TEXT \
1157 " Window Maker is free software; you can redistribute it and/or modify "\
1158 "it under the terms of the GNU General Public License as published "\
1159 "by the Free Software Foundation; either version 2 of the License, "\
1160 "or (at your option) any later version.\n\n\n"\
1161 " Window Maker is distributed in the hope that it will be useful, but "\
1162 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
1163 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
1164 "General Public License for more details.\n\n\n"\
1165 " You should have received a copy of the GNU General Public License "\
1166 "along with this program; if not, write to the Free Software "\
1167 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
1168 "02111-1307, USA."
1171 static LegalPanel *legalPanel = NULL;
1173 static void
1174 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1176 WMUnmapWidget(legalPanel->win);
1178 WMDestroyWidget(legalPanel->win);
1180 wUnmanageWindow(legalPanel->wwin, False, False);
1182 free(legalPanel);
1184 legalPanel = NULL;
1188 void
1189 wShowLegalPanel(WScreen *scr)
1191 LegalPanel *panel;
1192 Window parent;
1193 WWindow *wwin;
1195 if (legalPanel) {
1196 wRaiseFrame(legalPanel->wwin->frame->core);
1197 wSetFocusTo(scr, legalPanel->wwin);
1198 return;
1201 panel = wmalloc(sizeof(LegalPanel));
1203 panel->scr = scr;
1205 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1206 WMResizeWidget(panel->win, 420, 250);
1209 panel->licenseL = WMCreateLabel(panel->win);
1210 WMResizeWidget(panel->licenseL, 400, 230);
1211 WMMoveWidget(panel->licenseL, 10, 10);
1212 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1213 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
1214 WMSetLabelRelief(panel->licenseL, WRGroove);
1216 WMRealizeWidget(panel->win);
1217 WMMapSubwidgets(panel->win);
1219 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1221 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1223 wwin = wManageInternalWindow(scr, parent, None, "Legal",
1224 (scr->scr_width - 420)/2,
1225 (scr->scr_height - 250)/2, 420, 250);
1227 WSETUFLAG(wwin, no_closable, 0);
1228 WSETUFLAG(wwin, no_close_button, 0);
1229 wWindowUpdateButtonImages(wwin);
1230 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1231 wwin->frame->on_click_right = destroyLegalPanel;
1233 panel->wwin = wwin;
1235 WMMapWidget(panel->win);
1237 wWindowMap(wwin);
1239 legalPanel = panel;