Code update for Window Maker version 0.50.0
[wmaker-crm.git] / src / dialog.c
blob37d08eb0ba1cda26c05f0d743a0f777ab80bdfe3
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);
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);
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)
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);
483 wwin = wManageInternalWindow(scr, parent, None, _("Icon Chooser"),
484 (scr->scr_width - 450)/2,
485 (scr->scr_height - 280)/2, 450, 280);
488 /* put icon paths in the list */
489 listIconPaths(panel->dirList);
491 WMMapWidget(panel->win);
493 wWindowMap(wwin);
495 while (!panel->done) {
496 XEvent event;
498 WMNextEvent(dpy, &event);
499 WMHandleEvent(&event);
502 if (panel->result) {
503 char *defaultPath, *wantedPath;
505 /* check if the file the user selected is not the one that
506 * would be loaded by default with the current search path */
507 *file = WMGetListSelectedItem(panel->iconList)->text;
508 if ((*file)[0]==0) {
509 free(*file);
510 *file = NULL;
511 } else {
512 defaultPath = FindImage(wPreferences.icon_path, *file);
513 wantedPath = WMGetTextFieldText(panel->fileField);
514 /* if the file is not the default, use full path */
515 if (strcmp(wantedPath, defaultPath)!=0) {
516 *file = wantedPath;
517 } else {
518 *file = wstrdup(*file);
519 free(wantedPath);
521 free(defaultPath);
523 } else {
524 *file = NULL;
527 WMUnmapWidget(panel->win);
529 WMDestroyWidget(panel->win);
531 wUnmanageWindow(wwin, False);
533 free(panel);
535 XDestroyWindow(dpy, parent);
537 return panel->result;
542 ***********************************************************************
543 * Info Panel
544 ***********************************************************************
548 typedef struct {
549 WScreen *scr;
551 WWindow *wwin;
553 WMWindow *win;
555 WMLabel *logoL;
556 WMLabel *name1L;
557 WMLabel *name2L;
559 WMLabel *versionL;
561 WMLabel *infoL;
563 WMLabel *copyrL;
565 #ifdef SILLYNESS
566 WMHandlerID timer;
567 int cycle;
568 RImage *icon;
569 RImage *pic;
570 WMPixmap *oldPix;
571 #endif
572 } InfoPanel;
576 #define COPYRIGHT_TEXT \
577 "Copyright \xa9 1997, 1998 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
578 "Copyright \xa9 1998 Dan Pascu <dan@windowmaker.org>"
582 static InfoPanel *thePanel = NULL;
584 static void
585 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
587 #ifdef SILLYNESS
588 if (thePanel->timer) {
589 WMDeleteTimerHandler(thePanel->timer);
591 if (thePanel->oldPix) {
592 WMReleasePixmap(thePanel->oldPix);
594 if (thePanel->icon) {
595 RDestroyImage(thePanel->icon);
597 if (thePanel->pic) {
598 RDestroyImage(thePanel->pic);
600 #endif /* SILLYNESS */
601 WMUnmapWidget(thePanel);
603 WMDestroyWidget(thePanel->win);
605 wUnmanageWindow(thePanel->wwin, False);
607 free(thePanel);
609 thePanel = NULL;
613 WMPixmap*
614 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
616 WMPixmap *wpix = NULL;
617 Pixmap grad = None;
618 Pixmap mask = None;
619 RContext *rc = WMScreenRContext(scr);
620 XFontStruct *f = NULL;
621 int w, h;
622 GC gc = None;
624 f = XLoadQueryFont(dpy, font);
625 if (!f)
626 return NULL;
628 w = XTextWidth(f, text, strlen(text));
629 h = f->ascent+f->descent;
631 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
632 gc = XCreateGC(dpy, mask, 0, NULL);
633 XSetForeground(dpy, gc, 0);
634 XSetFont(dpy, gc, f->fid);
635 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
637 XSetForeground(dpy, gc, 1);
638 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
639 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
640 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
642 grad = XCreatePixmap(dpy, rc->drawable, w, h, rc->depth);
644 WMColor *color;
646 color = WMBlackColor(scr);
647 XFillRectangle(dpy, grad, WMColorGC(color), 0, 0, w, h);
648 WMReleaseColor(color);
651 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
653 if (gc)
654 XFreeGC(dpy, gc);
655 XFreeFont(dpy, f);
657 return wpix;
660 #ifdef SILLYNESS
661 static void
662 logoPushCallback(void *data)
664 InfoPanel *panel = (InfoPanel*)data;
665 char buffer[512];
666 int i;
668 if (panel->cycle < 30) {
669 RImage *image;
670 WMPixmap *pix;
672 image = RCloneImage(panel->icon);
673 RCombineImagesWithOpaqueness(image, panel->pic, panel->cycle*255/30);
674 pix = WMCreatePixmapFromRImage(panel->scr->wmscreen, image, 128);
675 RDestroyImage(image);
676 WMSetLabelImage(panel->logoL, pix);
677 WMReleasePixmap(pix);
680 i = panel->cycle%150;
682 strncpy(buffer, "Sloppy focus is a *?#@", i<22 ? i : 22);
683 if (i >= 22)
684 memset(&buffer[22], ' ', i-22);
685 buffer[i]=0;
686 WMSetLabelText(panel->versionL, buffer);
688 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
689 panel->cycle++;
693 static void
694 handleLogoPush(XEvent *event, void *data)
696 InfoPanel *panel = (InfoPanel*)data;
697 static int broken = 0;
698 static int clicks = 0;
699 static char *pic_data[] = {
700 "45 45 57 1",
701 " c None",
702 ". c #000000",
703 "X c #383C00",
704 "o c #515500",
705 "O c #616100",
706 "+ c #616900",
707 "@ c #696D00",
708 "# c #697100",
709 "$ c #495100",
710 "% c #202800",
711 "& c #969600",
712 "* c #CFCF00",
713 "= c #D7DB00",
714 "- c #D7D700",
715 "; c #C7CB00",
716 ": c #A6AA00",
717 "> c #494900",
718 ", c #8E8E00",
719 "< c #DFE700",
720 "1 c #F7FF00",
721 "2 c #FFFF00",
722 "3 c #E7EB00",
723 "4 c #B6B600",
724 "5 c #595900",
725 "6 c #717500",
726 "7 c #AEB200",
727 "8 c #CFD300",
728 "9 c #E7EF00",
729 "0 c #EFF300",
730 "q c #9EA200",
731 "w c #F7FB00",
732 "e c #F7F700",
733 "r c #BEBE00",
734 "t c #8E9200",
735 "y c #EFF700",
736 "u c #969A00",
737 "i c #414500",
738 "p c #595D00",
739 "a c #E7E700",
740 "s c #C7C700",
741 "d c #797D00",
742 "f c #BEC300",
743 "g c #DFE300",
744 "h c #868600",
745 "j c #EFEF00",
746 "k c #9E9E00",
747 "l c #616500",
748 "z c #DFDF00",
749 "x c #868A00",
750 "c c #969200",
751 "v c #B6BA00",
752 "b c #A6A600",
753 "n c #8E8A00",
754 "m c #717100",
755 "M c #AEAE00",
756 "N c #AEAA00",
757 "B c #868200",
758 " ............... ",
759 " ....XoO+@##+O$%.... ",
760 " ...%X&*========-;;:o... ",
761 " ...>.>,<122222222222134@... ",
762 " ..>5678912222222222222220q%.. ",
763 " ..$.&-w2222222222222222222er>.. ",
764 " ..O.t31222222222222222222222y4>.. ",
765 " ...O5u3222222222222222222222222yri... ",
766 " ..>p&a22222222222222222222222222wso.. ",
767 " ..ids91222222222222222222222222222wfi.. ",
768 " ..X.7w222222wgs-w2222222213=g0222222<hi.. ",
769 " ..Xuj2222222<@X5=222222229k@l:022222y4i.. ",
770 " .Xdz22222222*X%.s22222222axo%$-222222<c>.. ",
771 " ..o7y22222222v...r222222223hX.i82222221si.. ",
772 "..io*222222222&...u22222222yt..%*22222220:%. ",
773 "..>k02222222227...f222222222v..X=222222229t. ",
774 "..dz12222222220ui:y2222222223d%qw222222221g. ",
775 ".%vw222222222221y2222222222219*y2222222222wd.",
776 ".X;2222222222222222222222222222222222222222b.",
777 ".i*2222222222222222222222222222222222222222v.",
778 ".i*2222222222222222222222222222222222222222;.",
779 ".i*22222222222222222222222222222222222222228.",
780 ".>*2222222222222222222222222222222222222222=.",
781 ".i*22222222222222222222222222222222222222228.",
782 ".i*2222222222222222222222222222222222222222;.",
783 ".X*222222222222222222222222222222we12222222r.",
784 ".Xs12222222w3aw22222222222222222y8s0222222wk.",
785 ".Xq02222222a,na22222222222222222zm6zwy2222gi.",
786 "..>*22222y<:Xcj22222222222222222-o$k;;02228..",
787 "..i7y2220rhX.:y22222222222222222jtiXd,a220,..",
788 " .X@z222a,do%kj2222222222222222wMX5q;gw228%..",
789 " ..58222wagsh6ry222222222222221;>Of0w222y:...",
790 " ...:e2222218mdz22222222222222a&$vw222220@...",
791 " ...O-122222y:.u02222222222229q$uj222221r... ",
792 " ..%&a1222223&573w2222222219NOxz122221z>... ",
793 " ...t3222221-l$nr8ay1222yzbo,=12222w-5... ",
794 " ..X:022222w-k+>o,7s**s7xOn=12221<f5... ",
795 " ..o:9222221j8:&Bl>>>>ihv<12221=dX... ",
796 " ..Xb9122222109g-****;<y22221zn%... ",
797 " ..X&801222222222222222222w-h.... ",
798 " ...o:=022222222222222221=lX... ",
799 " ..X@:;3w2222222222210fO... ",
800 " ...XX&v8<30000003-N@... ",
801 " .....XmnbN:q&Bo.... ",
802 " ............ "};
804 clicks++;
805 if (!panel->timer && !broken && clicks > 2) {
806 char *file;
807 char *path;
809 clicks = 0;
810 if (!panel->icon) {
811 file = wDefaultGetIconFile(panel->scr, "Logo", "WMPanel", False);
812 if (!file) {
813 broken = 1;
814 return;
817 path = FindImage(wPreferences.icon_path, file);
818 if (!path) {
819 broken = 1;
820 return;
823 panel->icon = RLoadImage(panel->scr->rcontext, path, 0);
824 free(path);
825 if (!panel->icon) {
826 broken = 1;
827 return;
830 if (!panel->pic) {
831 panel->pic = RGetImageFromXPMData(panel->scr->rcontext, pic_data);
832 if (!panel->pic || panel->icon->width!=panel->pic->width
833 || panel->icon->height!=panel->pic->height) {
834 broken = 1;
835 RDestroyImage(panel->icon);
836 panel->icon = NULL;
837 if (panel->pic) {
838 RDestroyImage(panel->pic);
839 panel->pic = NULL;
841 return;
845 RColor color;
846 color.red = 0xae;
847 color.green = 0xaa;
848 color.blue = 0xae;
849 color.alpha = 255;
850 RCombineImageWithColor(panel->icon, &color);
851 RCombineImageWithColor(panel->pic, &color);
854 panel->timer = WMAddTimerHandler(50, logoPushCallback, panel);
855 panel->cycle = 0;
856 panel->oldPix = WMRetainPixmap(WMGetLabelImage(panel->logoL));
857 } else if (panel->timer) {
858 char version[20];
860 clicks = 0;
861 WMSetLabelImage(panel->logoL, panel->oldPix);
862 WMReleasePixmap(panel->oldPix);
863 panel->oldPix = NULL;
865 WMDeleteTimerHandler(panel->timer);
866 panel->timer = NULL;
868 sprintf(version, "Version %s", VERSION);
869 WMSetLabelText(panel->versionL, version);
873 XEvent ev;
874 while (XCheckTypedWindowEvent(dpy, WMWidgetXID(panel->versionL),
875 ButtonPress, &ev));
878 #endif /* SILLYNESS */
880 void
881 wShowInfoPanel(WScreen *scr)
883 InfoPanel *panel;
884 WMPixmap *logo;
885 WMSize size;
886 WMFont *font;
887 char version[32];
888 char buffer[512];
889 Window parent;
890 WWindow *wwin;
891 RColor color1, color2;
892 char **strl;
893 int i;
894 char *visuals[] = {
895 "StaticGray",
896 "GrayScale",
897 "StaticColor",
898 "PseudoColor",
899 "TrueColor",
900 "DirectColor"
903 if (thePanel) {
904 wRaiseFrame(thePanel->wwin->frame->core);
905 wSetFocusTo(scr, thePanel->wwin);
906 return;
909 panel = wmalloc(sizeof(InfoPanel));
910 memset(panel, 0, sizeof(InfoPanel));
912 panel->scr = scr;
914 panel->win = WMCreateWindow(scr->wmscreen, "info");
915 WMResizeWidget(panel->win, 382, 230);
917 logo = WMGetApplicationIconImage(scr->wmscreen);
918 if (logo) {
919 size = WMGetPixmapSize(logo);
920 panel->logoL = WMCreateLabel(panel->win);
921 WMResizeWidget(panel->logoL, 64, 64);
922 WMMoveWidget(panel->logoL, 30, 20);
923 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
924 WMSetLabelImage(panel->logoL, logo);
925 #ifdef SILLYNESS
926 WMCreateEventHandler(WMWidgetView(panel->logoL), ButtonPressMask,
927 handleLogoPush, panel);
928 #endif
931 panel->name1L = WMCreateLabel(panel->win);
932 WMResizeWidget(panel->name1L, 200, 30);
933 WMMoveWidget(panel->name1L, 120, 30);
934 color1.red = 0;
935 color1.green = 0;
936 color1.blue = 0;
937 color2.red = 0x50;
938 color2.green = 0x50;
939 color2.blue = 0x70;
940 logo = renderText(scr->wmscreen, " Window Maker ",
941 "-*-times-bold-r-*-*-24-*", &color1, &color2);
942 if (logo) {
943 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
944 WMSetLabelImage(panel->name1L, logo);
945 WMReleasePixmap(logo);
946 } else {
947 font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
948 if (font) {
949 WMSetLabelFont(panel->name1L, font);
950 WMReleaseFont(font);
952 WMSetLabelText(panel->name1L, "Window Maker");
955 panel->name2L = WMCreateLabel(panel->win);
956 WMResizeWidget(panel->name2L, 200, 24);
957 WMMoveWidget(panel->name2L, 120, 60);
958 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
959 if (font) {
960 WMSetLabelFont(panel->name2L, font);
961 WMReleaseFont(font);
962 font = NULL;
964 WMSetLabelText(panel->name2L, "X11 Window Manager");
967 sprintf(version, "Version %s", VERSION);
968 panel->versionL = WMCreateLabel(panel->win);
969 WMResizeWidget(panel->versionL, 310, 16);
970 WMMoveWidget(panel->versionL, 30, 95);
971 WMSetLabelTextAlignment(panel->versionL, WARight);
972 WMSetLabelText(panel->versionL, version);
973 WMSetLabelWraps(panel->versionL, False);
975 panel->copyrL = WMCreateLabel(panel->win);
976 WMResizeWidget(panel->copyrL, 340, 40);
977 WMMoveWidget(panel->copyrL, 15, 185);
978 WMSetLabelTextAlignment(panel->copyrL, WALeft);
979 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
980 /* we want the (c) character in the helvetica font */
981 font = WMCreateFontInDefaultEncoding(scr->wmscreen, HELVETICA10_FONT);
982 if (font) {
983 WMSetLabelFont(panel->copyrL, font);
986 switch (scr->w_depth) {
987 case 15:
988 strcpy(version, "32 thousand");
989 break;
990 case 16:
991 strcpy(version, "64 thousand");
992 break;
993 case 24:
994 case 32:
995 strcpy(version, "16 million");
996 break;
997 default:
998 sprintf(version, "%d", 1<<scr->w_depth);
999 break;
1002 sprintf(buffer, "Using visual 0x%x: %s %ibpp (%s colors)\n",
1003 (unsigned)scr->w_visual->visualid,
1004 visuals[scr->w_visual->class], scr->w_depth, version);
1006 strcat(buffer, "Supported image formats: ");
1007 strl = RSupportedFileFormats();
1008 for (i=0; strl[i]!=NULL; i++) {
1009 strcat(buffer, strl[i]);
1010 strcat(buffer, " ");
1013 strcat(buffer, "\nAdditional Support For: ");
1015 char *list[8];
1016 char buf[80];
1017 int j = 0;
1019 #ifdef MWM_HINTS
1020 list[j++] = "MWM";
1021 #endif
1022 #ifdef KWM_HINTS
1023 list[j++] = "KDE";
1024 #endif
1025 #ifdef GNOME_STUFF
1026 list[j++] = "GNOME";
1027 #endif
1028 #ifdef OLWM_HINTS
1029 list[j++] = "OLWM";
1030 #endif
1031 #ifdef WMSOUND
1032 list[j++] = "Sound";
1033 #endif
1035 buf[0] = 0;
1036 for (i = 0; i < j; i++) {
1037 if (i > 0) {
1038 if (i == j - 1)
1039 strcat(buf, " and ");
1040 else
1041 strcat(buf, ", ");
1043 strcat(buf, list[i]);
1045 strcat(buffer, buf);
1049 panel->infoL = WMCreateLabel(panel->win);
1050 WMResizeWidget(panel->infoL, 350, 75);
1051 WMMoveWidget(panel->infoL, 15, 115);
1052 WMSetLabelText(panel->infoL, buffer);
1053 if (font) {
1054 WMSetLabelFont(panel->infoL, font);
1055 WMReleaseFont(font);
1059 WMRealizeWidget(panel->win);
1060 WMMapSubwidgets(panel->win);
1062 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
1064 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1066 WMMapWidget(panel->win);
1068 wwin = wManageInternalWindow(scr, parent, None, "Info",
1069 (scr->scr_width - 382)/2,
1070 (scr->scr_height - 230)/2, 382, 230);
1072 WSETUFLAG(wwin, no_closable, 0);
1073 WSETUFLAG(wwin, no_close_button, 0);
1074 wWindowUpdateButtonImages(wwin);
1075 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1076 wwin->frame->on_click_right = destroyInfoPanel;
1078 wWindowMap(wwin);
1080 panel->wwin = wwin;
1082 thePanel = panel;
1087 ***********************************************************************
1088 * Legal Panel
1089 ***********************************************************************
1092 typedef struct {
1093 WScreen *scr;
1095 WWindow *wwin;
1097 WMWindow *win;
1099 WMLabel *licenseL;
1100 } LegalPanel;
1104 #define LICENSE_TEXT \
1105 " Window Maker is free software; you can redistribute it and/or modify "\
1106 "it under the terms of the GNU General Public License as published "\
1107 "by the Free Software Foundation; either version 2 of the License, "\
1108 "or (at your option) any later version.\n\n\n"\
1109 " Window Maker is distributed in the hope that it will be useful, but "\
1110 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
1111 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
1112 "General Public License for more details.\n\n\n"\
1113 " You should have received a copy of the GNU General Public License "\
1114 "along with this program; if not, write to the Free Software "\
1115 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
1116 "02111-1307, USA."
1119 static LegalPanel *legalPanel = NULL;
1121 static void
1122 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
1124 WMUnmapWidget(legalPanel->win);
1126 WMDestroyWidget(legalPanel->win);
1128 wUnmanageWindow(legalPanel->wwin, False);
1130 free(legalPanel);
1132 legalPanel = NULL;
1136 void
1137 wShowLegalPanel(WScreen *scr)
1139 LegalPanel *panel;
1140 Window parent;
1141 WWindow *wwin;
1143 if (legalPanel) {
1144 wRaiseFrame(legalPanel->wwin->frame->core);
1145 wSetFocusTo(scr, legalPanel->wwin);
1146 return;
1149 panel = wmalloc(sizeof(LegalPanel));
1151 panel->scr = scr;
1153 panel->win = WMCreateWindow(scr->wmscreen, "legal");
1154 WMResizeWidget(panel->win, 420, 250);
1157 panel->licenseL = WMCreateLabel(panel->win);
1158 WMResizeWidget(panel->licenseL, 400, 230);
1159 WMMoveWidget(panel->licenseL, 10, 10);
1160 WMSetLabelTextAlignment(panel->licenseL, WALeft);
1161 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
1162 WMSetLabelRelief(panel->licenseL, WRGroove);
1164 WMRealizeWidget(panel->win);
1165 WMMapSubwidgets(panel->win);
1167 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
1169 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
1171 wwin = wManageInternalWindow(scr, parent, None, "Legal",
1172 (scr->scr_width - 420)/2,
1173 (scr->scr_height - 250)/2, 420, 250);
1175 WSETUFLAG(wwin, no_closable, 0);
1176 WSETUFLAG(wwin, no_close_button, 0);
1177 wWindowUpdateButtonImages(wwin);
1178 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
1179 wwin->frame->on_click_right = destroyLegalPanel;
1181 panel->wwin = wwin;
1183 WMMapWidget(panel->win);
1185 wWindowMap(wwin);
1187 legalPanel = panel;