Update for 0.51.2-pre2
[wmaker-crm.git] / src / dialog.c
blob33f03c50f6040d6eba8b010fb6ce0bd1986ea810
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 (WMRunModalFilePanelForDirectory(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 WMSetTextFieldEditable(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 int 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 wUnmanageWindow(thePanel->wwin, False, False);
619 WMDestroyWidget(thePanel->win);
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;
686 static int jingobeu[] = {
687 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
688 329, 150, -1, 100, 329, 150, -1, 100, 329, 300, -1, 250,
689 329, 150, 392, 150, 261, 150, 293, 150, 329, 400, -1, 400, 0
691 static int c = 0;
693 if (panel->x) {
694 XKeyboardControl kc;
696 if (panel->x > 0) {
697 if(jingobeu[panel->x-1]==0){panel->x=-1;}else if(jingobeu[panel->x
698 -1]<0){panel->x++;c=jingobeu[panel->x-1]/50;panel->x++;}else if(c==0){
699 kc.bell_pitch=jingobeu[panel->x-1];panel->x++;kc.bell_percent=50;c=
700 jingobeu[panel->x-1]/50;kc.bell_duration=jingobeu[panel->x-1];panel->x++;
701 XChangeKeyboardControl(dpy,KBBellPitch|KBBellDuration|KBBellPercent,&kc);
702 XBell(dpy,50);XFlush(dpy);}else{c--;}}
703 if (!(panel->cycle % 4)) {
704 WMPixmap *p;
706 p = DoXThing(panel->wwin);
707 WMSetLabelImage(panel->logoL, p);
709 } else if (panel->cycle < 30) {
710 RImage *image;
711 WMPixmap *pix;
713 image = RCloneImage(panel->icon);
714 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
715 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
716 RDestroyImage(image);
717 WMSetLabelImage(panel->logoL, pix);
718 WMReleasePixmap(pix);
721 i = panel->cycle%200;
723 len = strlen(panel->str);
725 strncpy(buffer, panel->str, i<len ? i : len);
726 if (i >= len)
727 memset(&buffer[len], ' ', i-len);
729 strncpy(buffer, panel->str, i<len ? i : len);
730 if (i >= len)
731 memset(&buffer[len], ' ', i-len);
732 buffer[i]=0;
733 WMSetLabelText(panel->versionL, buffer);
735 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
736 panel->cycle++;
740 static void
741 handleLogoPush(XEvent *event, void *data)
743 InfoPanel *panel = (InfoPanel*)data;
744 static int broken = 0;
745 static int clicks = 0;
746 static char *pic_data[] = {
747 "45 45 57 1",
748 " c None",
749 ". c #000000",
750 "X c #383C00",
751 "o c #515500",
752 "O c #616100",
753 "+ c #616900",
754 "@ c #696D00",
755 "# c #697100",
756 "$ c #495100",
757 "% c #202800",
758 "& c #969600",
759 "* c #CFCF00",
760 "= c #D7DB00",
761 "- c #D7D700",
762 "; c #C7CB00",
763 ": c #A6AA00",
764 "> c #494900",
765 ", c #8E8E00",
766 "< c #DFE700",
767 "1 c #F7FF00",
768 "2 c #FFFF00",
769 "3 c #E7EB00",
770 "4 c #B6B600",
771 "5 c #595900",
772 "6 c #717500",
773 "7 c #AEB200",
774 "8 c #CFD300",
775 "9 c #E7EF00",
776 "0 c #EFF300",
777 "q c #9EA200",
778 "w c #F7FB00",
779 "e c #F7F700",
780 "r c #BEBE00",
781 "t c #8E9200",
782 "y c #EFF700",
783 "u c #969A00",
784 "i c #414500",
785 "p c #595D00",
786 "a c #E7E700",
787 "s c #C7C700",
788 "d c #797D00",
789 "f c #BEC300",
790 "g c #DFE300",
791 "h c #868600",
792 "j c #EFEF00",
793 "k c #9E9E00",
794 "l c #616500",
795 "z c #DFDF00",
796 "x c #868A00",
797 "c c #969200",
798 "v c #B6BA00",
799 "b c #A6A600",
800 "n c #8E8A00",
801 "m c #717100",
802 "M c #AEAE00",
803 "N c #AEAA00",
804 "B c #868200",
805 " ............... ",
806 " ....XoO+@##+O$%.... ",
807 " ...%X&*========-;;:o... ",
808 " ...>.>,<122222222222134@... ",
809 " ..>5678912222222222222220q%.. ",
810 " ..$.&-w2222222222222222222er>.. ",
811 " ..O.t31222222222222222222222y4>.. ",
812 " ...O5u3222222222222222222222222yri... ",
813 " ..>p&a22222222222222222222222222wso.. ",
814 " ..ids91222222222222222222222222222wfi.. ",
815 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
816 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
817 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
818 " ..o7y22222222v...r222222223hX.i82222221si.. ",
819 "..io*222222222&...u22222222yt..%*22222220:%. ",
820 "..>k02222222227...f222222222v..X=222222229t. ",
821 "..dz12222222220ui:y2222222223d%qw222222221g. ",
822 ".%vw222222222221y2222222222219*y2222222222wd.",
823 ".X;2222222222222222222222222222222222222222b.",
824 ".i*2222222222222222222222222222222222222222v.",
825 ".i*2222222222222222222222222222222222222222;.",
826 ".i*22222222222222222222222222222222222222228.",
827 ".>*2222222222222222222222222222222222222222=.",
828 ".i*22222222222222222222222222222222222222228.",
829 ".i*2222222222222222222222222222222222222222;.",
830 ".X*222222222222222222222222222222we12222222r.",
831 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
832 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
833 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
834 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
835 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
836 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
837 " ...:e2222218mdz22222222222222a&$vw222220@...",
838 " ...O-122222y:.u02222222222229q$uj222221r... ",
839 " ..%&a1222223&573w2222222219NOxz122221z>... ",
840 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
841 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
842 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
843 " ..Xb9122222109g-****;<y22221zn%... ",
844 " ..X&801222222222222222222w-h.... ",
845 " ...o:=022222222222222221=lX... ",
846 " ..X@:;3w2222222222210fO... ",
847 " ...XX&v8<30000003-N@... ",
848 " .....XmnbN:q&Bo.... ",
849 " ............ "};
850 static char *msgs[] = {
851 "Sloppy focus is a *?#@",
852 "Repent! Sloppy focus users will burn in hell!!!",
853 "Have a nice day!"
857 clicks++;
858 if (!panel->timer && !broken && clicks > 2) {
859 char *file;
860 char *path;
862 panel->x = 0;
863 clicks = 0;
864 if (!panel->icon) {
865 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
866 if (!file) {
867 broken = 1;
868 return;
871 path = FindImage(wPreferences.icon_path, file);
872 if (!path) {
873 broken = 1;
874 return;
877 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
878 free(path);
879 if (!panel->icon) {
880 broken = 1;
881 return;
884 if (!panel->pic) {
885 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
886 if (!panel->pic || panel->icon->width!=panel->pic->width
887 || panel->icon->height!=panel->pic->height) {
888 broken = 1;
889 RDestroyImage(panel->icon);
890 panel->icon = NULL;
891 if (panel->pic) {
892 RDestroyImage(panel->pic);
893 panel->pic = NULL;
895 return;
899 RColor color;
900 color.red = 0xae;
901 color.green = 0xaa;
902 color.blue = 0xae;
903 color.alpha = 255;
904 RCombineImageWithColor(panel->icon, &color);
905 RCombineImageWithColor(panel->pic, &color);
909 panel->str = msgs[rand()%(sizeof(msgs)/sizeof(char*))];
911 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
912 panel->cycle = 0;
913 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
914 } else if (panel->timer) {
915 char version[20];
917 panel->x = 0;
918 clicks = 0;
919 WMSetLabelImage(panel->logoL, panel->oldPix);
920 WMReleasePixmap(panel->oldPix);
921 panel->oldPix = NULL;
923 WMDeleteTimerHandler(panel->timer);
924 panel->timer = NULL;
926 sprintf(version, "Version %s", VERSION);
927 WMSetLabelText(panel->versionL, version);
931 XEvent ev;
932 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
933 ButtonPress, &ev));
936 #endif /* SILLYNESS */
939 void
940 wShowInfoPanel(WScreen *scr)
942 InfoPanel *panel;
943 WMPixmap *logo;
944 WMSize size;
945 WMFont *font;
946 char version[32];
947 char buffer[512];
948 Window parent;
949 WWindow *wwin;
950 RColor color1, color2;
951 char **strl;
952 int i;
953 char *visuals[] = {
954 "StaticGray",
955 "GrayScale",
956 "StaticColor",
957 "PseudoColor",
958 "TrueColor",
959 "DirectColor"
963 if (thePanel) {
964 wRaiseFrame(thePanel->wwin->frame->core);
965 wSetFocusTo(scr, thePanel->wwin);
966 return;
969 panel = wmalloc(sizeof(InfoPanel));
970 memset(panel, 0, sizeof(InfoPanel));
972 panel->scr = scr;
974 panel->win = WMCreateWindow(scr->wmscreen, "info");
975 WMResizeWidget(panel->win, 382, 230);
977 logo = WMGetApplicationIconImage(scr->wmscreen);
978 if (logo) {
979 size = WMGetPixmapSize(logo);
980 panel->logoL = WMCreateLabel(panel->win);
981 WMResizeWidget(panel->logoL, 64, 64);
982 WMMoveWidget(panel->logoL, 30, 20);
983 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
984 WMSetLabelImage(panel->logoL, logo);
985 #ifdef SILLYNESS
986 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
987 handleLogoPush, panel);
988 #endif
991 panel->name1L = WMCreateLabel(panel->win);
992 WMResizeWidget(panel->name1L, 240, 30);
993 WMMoveWidget(panel->name1L, 100, 30);
994 color1.red = 0;
995 color1.green = 0;
996 color1.blue = 0;
997 color2.red = 0x50;
998 color2.green = 0x50;
999 color2.blue = 0x70;
1000 logo = renderText(scr->wmscreen, "GNU Window Maker",
1001 "-*-utopia-*-r-*-*-25-*", &color1, &color2);
1002 if (logo) {
1003 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
1004 WMSetLabelImage(panel->name1L, logo);
1005 WMReleasePixmap(logo);
1006 } else {
1007 font = WMBoldSystemFontOfSize(scr->wmscreen, 20);
1008 if (font) {
1009 WMSetLabelFont(panel->name1L, font);
1010 WMReleaseFont(font);
1012 WMSetLabelTextAlignment(panel->name1L, WACenter);
1013 WMSetLabelText(panel->name1L, "GNU Window Maker");
1016 panel->name2L = WMCreateLabel(panel->win);
1017 WMResizeWidget(panel->name2L, 240, 24);
1018 WMMoveWidget(panel->name2L, 100, 60);
1019 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
1020 if (font) {
1021 WMSetLabelFont(panel->name2L, font);
1022 WMReleaseFont(font);
1023 font = NULL;
1025 WMSetLabelTextAlignment(panel->name2L, WACenter);
1026 WMSetLabelText(panel->name2L, "Window Manager for X");
1029 sprintf(version, "Version %s", VERSION);
1030 panel->versionL = WMCreateLabel(panel->win);
1031 WMResizeWidget(panel->versionL, 310, 16);
1032 WMMoveWidget(panel->versionL, 30, 95);
1033 WMSetLabelTextAlignment(panel->versionL, WARight);
1034 WMSetLabelText(panel->versionL, version);
1035 WMSetLabelWraps(panel->versionL, False);
1037 panel->copyrL = WMCreateLabel(panel->win);
1038 WMResizeWidget(panel->copyrL, 340, 40);
1039 WMMoveWidget(panel->copyrL, 15, 185);
1040 WMSetLabelTextAlignment(panel->copyrL, WALeft);
1041 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
1042 /* we want the (c) character in the helvetica font */
1043 font = WMCreateFontInDefaultEncoding(scr->wmscreen, HELVETICA10_FONT);
1044 if (font) {
1045 WMSetLabelFont(panel->copyrL, font);
1048 switch (scr->w_depth) {
1049 case 15:
1050 strcpy(version, "32 thousand");
1051 break;
1052 case 16:
1053 strcpy(version, "64 thousand");
1054 break;
1055 case 24:
1056 case 32:
1057 strcpy(version, "16 million");
1058 break;
1059 default:
1060 sprintf(version, "%d", 1<<scr->w_depth);
1061 break;
1064 sprintf(buffer, "Using visual 0x%x: %s %ibpp (%s colors)\n",
1065 (unsigned)scr->w_visual->visualid,
1066 visuals[scr->w_visual->class], scr->w_depth, version);
1068 strcat(buffer, "Supported image formats: ");
1069 strl = RSupportedFileFormats();
1070 for (i=0; strl[i]!=NULL; i++) {
1071 strcat(buffer, strl[i]);
1072 strcat(buffer, " ");
1075 strcat(buffer, "\nAdditional Support For: ");
1077 char *list[8];
1078 char buf[80];
1079 int j = 0;
1081 #ifdef MWM_HINTS
1082 list[j++] = "MWM";
1083 #endif
1084 #ifdef KWM_HINTS
1085 list[j++] = "KDE";
1086 #endif
1087 #ifdef GNOME_STUFF
1088 list[j++] = "GNOME";
1089 #endif
1090 #ifdef OLWM_HINTS
1091 list[j++] = "OLWM";
1092 #endif
1093 #ifdef WMSOUND
1094 list[j++] = "Sound";
1095 #endif
1097 buf[0] = 0;
1098 for (i = 0; i < j; i++) {
1099 if (i > 0) {
1100 if (i == j - 1)
1101 strcat(buf, " and ");
1102 else
1103 strcat(buf, ", ");
1105 strcat(buf, list[i]);
1107 strcat(buffer, buf);
1111 panel->infoL = WMCreateLabel(panel->win);
1112 WMResizeWidget(panel->infoL, 350, 75);
1113 WMMoveWidget(panel->infoL, 15, 115);
1114 WMSetLabelText(panel->infoL, buffer);
1115 if (font) {
1116 WMSetLabelFont(panel->infoL, font);
1117 WMReleaseFont(font);
1121 WMRealizeWidget(panel->win);
1122 WMMapSubwidgets(panel->win);
1124 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1126 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1128 WMMapWidget(panel->win);
1130 wwin = wManageInternalWindow(scr, parent, None, "Info",
1131 (scr->scr_width - 382)/2,
1132 (scr->scr_height - 230)/2, 382, 230);
1134 WSETUFLAG(wwin, no_closable, 0);
1135 WSETUFLAG(wwin, no_close_button, 0);
1136 wWindowUpdateButtonImages(wwin);
1137 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1138 wwin->frame->on_click_right = destroyInfoPanel;
1140 wWindowMap(wwin);
1142 panel->wwin = wwin;
1144 thePanel = panel;
1145 #ifndef SILLYNESS
1146 if (InitXThing(panel->scr)) {
1147 panel->timer = WMAddTimerHandler(100, logoPushCallback, panel);
1148 panel->cycle = 0;
1149 panel->x = 1;
1150 panel->str = "Merry Christmas!";
1151 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
1153 #endif
1158 ***********************************************************************
1159 * Legal Panel
1160 ***********************************************************************
1163 typedef struct {
1164 WScreen *scr;
1166 WWindow *wwin;
1168 WMWindow *win;
1170 WMLabel *licenseL;
1171 } LegalPanel;
1175 #define LICENSE_TEXT \
1176 " Window Maker is free software; you can redistribute it and/or modify "\
1177 "it under the terms of the GNU General Public License as published "\
1178 "by the Free Software Foundation; either version 2 of the License, "\
1179 "or (at your option) any later version.\n\n\n"\
1180 " Window Maker is distributed in the hope that it will be useful, but "\
1181 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
1182 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
1183 "General Public License for more details.\n\n\n"\
1184 " You should have received a copy of the GNU General Public License "\
1185 "along with this program; if not, write to the Free Software "\
1186 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
1187 "02111-1307, USA."
1190 static LegalPanel *legalPanel = NULL;
1192 static void
1193 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1195 WMUnmapWidget(legalPanel->win);
1197 WMDestroyWidget(legalPanel->win);
1199 wUnmanageWindow(legalPanel->wwin, False, False);
1201 free(legalPanel);
1203 legalPanel = NULL;
1207 void
1208 wShowLegalPanel(WScreen *scr)
1210 LegalPanel *panel;
1211 Window parent;
1212 WWindow *wwin;
1214 if (legalPanel) {
1215 wRaiseFrame(legalPanel->wwin->frame->core);
1216 wSetFocusTo(scr, legalPanel->wwin);
1217 return;
1220 panel = wmalloc(sizeof(LegalPanel));
1222 panel->scr = scr;
1224 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1225 WMResizeWidget(panel->win, 420, 250);
1228 panel->licenseL = WMCreateLabel(panel->win);
1229 WMResizeWidget(panel->licenseL, 400, 230);
1230 WMMoveWidget(panel->licenseL, 10, 10);
1231 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1232 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
1233 WMSetLabelRelief(panel->licenseL, WRGroove);
1235 WMRealizeWidget(panel->win);
1236 WMMapSubwidgets(panel->win);
1238 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1240 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1242 wwin = wManageInternalWindow(scr, parent, None, "Legal",
1243 (scr->scr_width - 420)/2,
1244 (scr->scr_height - 250)/2, 420, 250);
1246 WSETUFLAG(wwin, no_closable, 0);
1247 WSETUFLAG(wwin, no_close_button, 0);
1248 wWindowUpdateButtonImages(wwin);
1249 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1250 wwin->frame->on_click_right = destroyLegalPanel;
1252 panel->wwin = wwin;
1254 WMMapWidget(panel->win);
1256 wWindowMap(wwin);
1258 legalPanel = panel;