Initial revision
[wmaker-crm.git] / src / dialog.c
blob0f4ab25094f8d24844179a07b188f5ee51cb8263
1 /* dialog.c - dialog windows for internal use
2 *
3 * WindowMaker 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"
53 extern WPreferences wPreferences;
57 int
58 wMessageDialog(WScreen *scr, char *title, char *message,
59 char *defBtn, char *altBtn, char *othBtn)
61 WMAlertPanel *panel;
62 Window parent;
63 WWindow *wwin;
64 int result;
66 panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message,
67 defBtn, altBtn, othBtn);
69 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
71 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
73 wwin = wManageInternalWindow(scr, parent, None, NULL,
74 (scr->scr_width - 400)/2,
75 (scr->scr_height - 180)/2, 400, 180);
76 wwin->client_leader = WMWidgetXID(panel->win);
78 WMMapWidget(panel->win);
80 wWindowMap(wwin);
82 while (!panel->done) {
83 XEvent event;
85 WMNextEvent(dpy, &event);
86 WMHandleEvent(&event);
89 result = panel->result;
91 WMUnmapWidget(panel->win);
93 wUnmanageWindow(wwin, False);
95 WMDestroyAlertPanel(panel);
97 XDestroyWindow(dpy, parent);
99 return result;
105 wInputDialog(WScreen *scr, char *title, char *message, char **text)
107 WWindow *wwin;
108 Window parent;
109 WMInputPanel *panel;
110 char *result;
113 panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text,
114 _("OK"), _("Cancel"));
117 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0);
118 XSelectInput(dpy, parent, KeyPressMask|KeyReleaseMask);
120 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
122 wwin = wManageInternalWindow(scr, parent, None, NULL,
123 (scr->scr_width - 320)/2,
124 (scr->scr_height - 160)/2, 320, 160);
126 wwin->client_leader = WMWidgetXID(panel->win);
128 WMMapWidget(panel->win);
130 wWindowMap(wwin);
132 while (!panel->done) {
133 XEvent event;
135 WMNextEvent(dpy, &event);
136 WMHandleEvent(&event);
139 if (panel->result == WAPRDefault)
140 result = WMGetTextFieldText(panel->text);
141 else
142 result = NULL;
144 wUnmanageWindow(wwin, False);
146 WMDestroyInputPanel(panel);
148 XDestroyWindow(dpy, parent);
150 if (result==NULL)
151 return WDB_CANCEL;
152 else {
153 if (*text)
154 free(*text);
155 *text = result;
157 return WDB_OK;
163 *****************************************************************
164 * Icon Selection Panel
165 *****************************************************************
168 typedef struct IconPanel {
170 WScreen *scr;
172 WMWindow *win;
174 WMLabel *dirLabel;
175 WMLabel *iconLabel;
177 WMList *dirList;
178 WMList *iconList;
180 WMLabel *iconView;
182 WMLabel *fileLabel;
183 WMTextField *fileField;
185 WMButton *okButton;
186 WMButton *cancelButton;
187 #if 0
188 WMButton *chooseButton;
189 #endif
190 short done;
191 short result;
192 } IconPanel;
196 static void
197 listPixmaps(WScreen *scr, WMList *lPtr, char *path)
199 struct dirent *dentry;
200 DIR *dir;
201 char pbuf[PATH_MAX+16];
202 char *apath;
204 apath = wexpandpath(path);
205 dir = opendir(apath);
207 if (!dir) {
208 char *msg;
209 char *tmp;
210 tmp = _("Could not open directory ");
211 msg = wmalloc(strlen(tmp)+strlen(path)+6);
212 strcpy(msg, tmp);
213 strcat(msg, path);
215 wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
216 free(msg);
217 free(apath);
218 return;
221 /* list contents in the column */
222 while ((dentry = readdir(dir))) {
223 struct stat statb;
225 if (strcmp(dentry->d_name, ".")==0 ||
226 strcmp(dentry->d_name, "..")==0)
227 continue;
229 strcpy(pbuf, apath);
230 strcat(pbuf, "/");
231 strcat(pbuf, dentry->d_name);
233 if (stat(pbuf, &statb)<0)
234 continue;
236 if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)
237 && statb.st_mode & (S_IFREG|S_IFLNK)) {
238 WMAddSortedListItem(lPtr, dentry->d_name);
242 closedir(dir);
243 free(apath);
248 static void
249 setViewedImage(IconPanel *panel, char *file)
251 WMPixmap *pixmap;
252 RColor color;
254 color.red = 0xae;
255 color.green = 0xaa;
256 color.blue = 0xae;
257 color.alpha = 0;
258 pixmap = WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel->win),
259 file, &color);
260 if (!pixmap) {
261 char *msg;
262 char *tmp;
264 WMSetButtonEnabled(panel->okButton, False);
266 tmp = _("Could not load image file ");
267 msg = wmalloc(strlen(tmp)+strlen(file)+6);
268 strcpy(msg, tmp);
269 strcat(msg, file);
271 wMessageDialog(panel->scr, _("Error"), msg, _("OK"), NULL, NULL);
272 free(msg);
274 WMSetLabelImage(panel->iconView, NULL);
275 } else {
276 WMSetButtonEnabled(panel->okButton, True);
278 WMSetLabelImage(panel->iconView, pixmap);
279 WMReleasePixmap(pixmap);
284 static void
285 listCallback(void *self, void *data)
287 WMList *lPtr = (WMList*)self;
288 IconPanel *panel = (IconPanel*)data;
289 char *path;
291 if (lPtr==panel->dirList) {
292 path = WMGetListSelectedItem(lPtr)->text;
294 WMSetTextFieldText(panel->fileField, path);
296 WMSetLabelImage(panel->iconView, NULL);
298 WMSetButtonEnabled(panel->okButton, False);
300 WMClearList(panel->iconList);
301 listPixmaps(panel->scr, panel->iconList, path);
302 } else {
303 char *tmp, *iconFile;
305 path = WMGetListSelectedItem(panel->dirList)->text;
306 tmp = wexpandpath(path);
308 iconFile = WMGetListSelectedItem(panel->iconList)->text;
310 path = wmalloc(strlen(tmp)+strlen(iconFile)+4);
311 strcpy(path, tmp);
312 strcat(path, "/");
313 strcat(path, iconFile);
314 free(tmp);
315 WMSetTextFieldText(panel->fileField, path);
316 setViewedImage(panel, path);
317 free(path);
322 static void
323 listIconPaths(WMList *lPtr)
325 int i;
327 for (i=0; wPreferences.icon_path[i]!=NULL; i++) {
328 char *tmp;
329 tmp = wexpandpath(wPreferences.icon_path[i]);
330 /* do not sort, because the order implies the order of
331 * directories searched */
332 if (access(tmp, X_OK)==0)
333 WMAddListItem(lPtr, wPreferences.icon_path[i]);
334 free(tmp);
340 static void
341 buttonCallback(void *self, void *clientData)
343 WMButton *bPtr = (WMButton*)self;
344 IconPanel *panel = (IconPanel*)clientData;
347 if (bPtr==panel->okButton) {
348 panel->done = True;
349 panel->result = True;
350 } else if (bPtr==panel->cancelButton) {
351 panel->done = True;
352 panel->result = False;
354 #if 0
355 else if (bPtr==panel->chooseButton) {
356 WMOpenPanel *op;
358 op = WMCreateOpenPanel(WMWidgetScreen(bPtr));
360 if (WMRunModalOpenPanelForDirectory(op, NULL, "/usr/local", NULL, NULL)) {
361 char *path;
362 path = WMGetFilePanelFile(op);
363 WMSetTextFieldText(panel->fileField, path);
364 setViewedImage(panel, path);
365 free(path);
367 WMDestroyFilePanel(op);
369 #endif
373 Bool
374 wIconChooserDialog(WScreen *scr, char **file)
376 WWindow *wwin;
377 Window parent;
378 IconPanel *panel;
379 WMColor *color;
380 WMFont *boldFont;
382 panel = wmalloc(sizeof(IconPanel));
383 memset(panel, 0, sizeof(IconPanel));
385 panel->scr = scr;
387 panel->win = WMCreateWindow(scr->wmscreen, "iconChooser");
388 WMResizeWidget(panel->win, 450, 280);
390 boldFont = WMBoldSystemFontOfSize(scr->wmscreen, 12);
392 panel->dirLabel = WMCreateLabel(panel->win);
393 WMResizeWidget(panel->dirLabel, 200, 20);
394 WMMoveWidget(panel->dirLabel, 10, 7);
395 WMSetLabelText(panel->dirLabel, _("Directories"));
396 WMSetLabelFont(panel->dirLabel, boldFont);
397 WMSetLabelTextAlignment(panel->dirLabel, WACenter);
399 WMSetLabelRelief(panel->dirLabel, WRSunken);
401 panel->iconLabel = WMCreateLabel(panel->win);
402 WMResizeWidget(panel->iconLabel, 140, 20);
403 WMMoveWidget(panel->iconLabel, 215, 7);
404 WMSetLabelText(panel->iconLabel, _("Icons"));
405 WMSetLabelFont(panel->iconLabel, boldFont);
406 WMSetLabelTextAlignment(panel->iconLabel, WACenter);
408 WMReleaseFont(boldFont);
410 color = WMWhiteColor(scr->wmscreen);
411 WMSetLabelTextColor(panel->dirLabel, color);
412 WMSetLabelTextColor(panel->iconLabel, color);
413 WMReleaseColor(color);
415 color = WMDarkGrayColor(scr->wmscreen);
416 WMSetWidgetBackgroundColor(panel->iconLabel, color);
417 WMSetWidgetBackgroundColor(panel->dirLabel, color);
418 WMReleaseColor(color);
420 WMSetLabelRelief(panel->iconLabel, WRSunken);
422 panel->dirList = WMCreateList(panel->win);
423 WMResizeWidget(panel->dirList, 200, 170);
424 WMMoveWidget(panel->dirList, 10, 30);
425 WMSetListAction(panel->dirList, listCallback, panel);
427 panel->iconList = WMCreateList(panel->win);
428 WMResizeWidget(panel->iconList, 140, 170);
429 WMMoveWidget(panel->iconList, 215, 30);
430 WMSetListAction(panel->iconList, listCallback, panel);
432 panel->iconView = WMCreateLabel(panel->win);
433 WMResizeWidget(panel->iconView, 75, 75);
434 WMMoveWidget(panel->iconView, 365, 60);
435 WMSetLabelImagePosition(panel->iconView, WIPImageOnly);
436 WMSetLabelRelief(panel->iconView, WRSunken);
438 panel->fileLabel = WMCreateLabel(panel->win);
439 WMResizeWidget(panel->fileLabel, 80, 20);
440 WMMoveWidget(panel->fileLabel, 10, 210);
441 WMSetLabelText(panel->fileLabel, _("File Name:"));
443 panel->fileField = WMCreateTextField(panel->win);
444 WMResizeWidget(panel->fileField, 345, 20);
445 WMMoveWidget(panel->fileField, 95, 210);
446 WMSetTextFieldEnabled(panel->fileField, False);
448 panel->okButton = WMCreateCommandButton(panel->win);
449 WMResizeWidget(panel->okButton, 80, 26);
450 WMMoveWidget(panel->okButton, 360, 240);
451 WMSetButtonText(panel->okButton, _("OK"));
452 WMSetButtonEnabled(panel->okButton, False);
453 WMSetButtonAction(panel->okButton, buttonCallback, panel);
455 panel->cancelButton = WMCreateCommandButton(panel->win);
456 WMResizeWidget(panel->cancelButton, 80, 26);
457 WMMoveWidget(panel->cancelButton, 270, 240);
458 WMSetButtonText(panel->cancelButton, _("Cancel"));
459 WMSetButtonAction(panel->cancelButton, buttonCallback, panel);
460 #if 0
461 panel->chooseButton = WMCreateCommandButton(panel->win);
462 WMResizeWidget(panel->chooseButton, 110, 26);
463 WMMoveWidget(panel->chooseButton, 150, 240);
464 WMSetButtonText(panel->chooseButton, _("Choose File"));
465 WMSetButtonAction(panel->chooseButton, buttonCallback, panel);
466 #endif
467 WMRealizeWidget(panel->win);
468 WMMapSubwidgets(panel->win);
470 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 450, 280, 0, 0, 0);
472 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
474 wwin = wManageInternalWindow(scr, parent, None, _("Icon Chooser"),
475 (scr->scr_width - 450)/2,
476 (scr->scr_height - 280)/2, 450, 280);
479 /* put icon paths in the list */
480 listIconPaths(panel->dirList);
482 WMMapWidget(panel->win);
484 wWindowMap(wwin);
486 while (!panel->done) {
487 XEvent event;
489 WMNextEvent(dpy, &event);
490 WMHandleEvent(&event);
493 if (panel->result) {
494 char *defaultPath, *wantedPath;
496 /* check if the file the user selected is not the one that
497 * would be loaded by default with the current search path */
498 *file = WMGetListSelectedItem(panel->iconList)->text;
499 if ((*file)[0]==0) {
500 free(*file);
501 *file = NULL;
502 } else {
503 defaultPath = FindImage(wPreferences.icon_path, *file);
504 wantedPath = WMGetTextFieldText(panel->fileField);
505 /* if the file is not the default, use full path */
506 if (strcmp(wantedPath, defaultPath)!=0) {
507 *file = wantedPath;
508 } else {
509 *file = wstrdup(*file);
510 free(wantedPath);
512 free(defaultPath);
514 } else {
515 *file = NULL;
518 WMUnmapWidget(panel->win);
520 WMDestroyWidget(panel->win);
522 wUnmanageWindow(wwin, False);
524 free(panel);
526 XDestroyWindow(dpy, parent);
528 return panel->result;
533 ***********************************************************************
534 * Info Panel
535 ***********************************************************************
539 typedef struct {
540 WScreen *scr;
542 WWindow *wwin;
544 WMWindow *win;
546 WMLabel *logoL;
547 WMLabel *name1L;
548 WMLabel *name2L;
550 WMLabel *versionL;
552 WMLabel *infoL;
554 WMLabel *copyrL;
555 } InfoPanel;
559 #define COPYRIGHT_TEXT \
560 "Copyright \xa9 1997, 1998 Alfredo K. Kojima <kojima@windowmaker.org>\n"\
561 "Copyright \xa9 1998 Dan Pascu <dan@windowmaker.org>"
565 static InfoPanel *thePanel = NULL;
567 static void
568 destroyInfoPanel(WCoreWindow *foo, void *data, XEvent *event)
570 WMUnmapWidget(thePanel);
572 WMDestroyWidget(thePanel->win);
574 wUnmanageWindow(thePanel->wwin, False);
576 free(thePanel);
578 thePanel = NULL;
582 WMPixmap*
583 renderText(WMScreen *scr, char *text, char *font, RColor *from, RColor *to)
585 WMPixmap *wpix = NULL;
586 RImage *gradient = NULL;
587 Pixmap grad = None;
588 Pixmap mask = None;
589 RContext *rc = WMScreenRContext(scr);
590 XFontStruct *f = NULL;
591 int w, h;
592 GC gc = None;
594 f = XLoadQueryFont(dpy, font);
595 if (!f)
596 return NULL;
598 w = XTextWidth(f, text, strlen(text));
599 h = f->ascent+f->descent;
601 gradient = RRenderGradient(w, h, from, to, RVerticalGradient);
602 if (!gradient) {
603 wwarning("error doing image processing:%s", RErrorString);
604 goto bye;
606 if (!RConvertImage(rc, gradient, &grad)) {
607 wwarning("error doing image processing:%s", RErrorString);
608 goto bye;
611 mask = XCreatePixmap(dpy, rc->drawable, w, h, 1);
612 gc = XCreateGC(dpy, mask, 0, NULL);
613 XSetForeground(dpy, gc, rc->black);
614 XSetFont(dpy, gc, f->fid);
615 XFillRectangle(dpy, mask, gc, 0, 0, w, h);
617 XSetForeground(dpy, gc, rc->white);
618 XDrawString(dpy, mask, gc, 0, f->ascent, text, strlen(text));
620 XSetLineAttributes(dpy, gc, 3, LineSolid, CapRound, JoinMiter);
622 XDrawLine(dpy, mask, gc, 0, h-2, w, h-2);
624 wpix = WMCreatePixmapFromXPixmaps(scr, grad, mask, w, h, rc->depth);
626 bye:
627 if (gc)
628 XFreeGC(dpy, gc);
629 XFreeFont(dpy, f);
630 if (gradient)
631 RDestroyImage(gradient);
633 return wpix;
637 void
638 wShowInfoPanel(WScreen *scr)
640 InfoPanel *panel;
641 WMPixmap *logo;
642 WMSize size;
643 WMFont *font;
644 char version[32];
645 char buffer[256];
646 Window parent;
647 WWindow *wwin;
648 RColor color1, color2;
649 char **strl;
650 int i;
651 char *visuals[] = {
652 "StaticGray",
653 "GrayScale",
654 "StaticColor",
655 "PseudoColor",
656 "TrueColor",
657 "DirectColor"
660 if (thePanel) {
661 wRaiseFrame(thePanel->wwin->frame->core);
662 wSetFocusTo(scr, thePanel->wwin);
663 return;
666 panel = wmalloc(sizeof(InfoPanel));
668 panel->scr = scr;
670 panel->win = WMCreateWindow(scr->wmscreen, "info");
671 WMResizeWidget(panel->win, 382, 230);
673 logo = WMGetApplicationIconImage(scr->wmscreen);
674 if (logo) {
675 size = WMGetPixmapSize(logo);
676 panel->logoL = WMCreateLabel(panel->win);
677 WMResizeWidget(panel->logoL, 64, 64);
678 WMMoveWidget(panel->logoL, 30, 20);
679 WMSetLabelImagePosition(panel->logoL, WIPImageOnly);
680 WMSetLabelImage(panel->logoL, logo);
683 panel->name1L = WMCreateLabel(panel->win);
684 WMResizeWidget(panel->name1L, 200, 30);
685 WMMoveWidget(panel->name1L, 120, 30);
686 color1.red = 0;
687 color1.green = 0;
688 color1.blue = 0;
689 color2.red = 0x80;
690 color2.green = 0x80;
691 color2.blue = 0x80;
692 logo = renderText(scr->wmscreen, " WindowMaker ",
693 "-*-times-bold-r-*-*-24-*", &color1, &color2);
694 if (logo) {
695 WMSetLabelImagePosition(panel->name1L, WIPImageOnly);
696 WMSetLabelImage(panel->name1L, logo);
697 WMReleasePixmap(logo);
698 } else {
699 font = WMBoldSystemFontOfSize(scr->wmscreen, 24);
700 if (font) {
701 WMSetLabelFont(panel->name1L, font);
702 WMReleaseFont(font);
704 WMSetLabelText(panel->name1L, "WindowMaker");
707 panel->name2L = WMCreateLabel(panel->win);
708 WMResizeWidget(panel->name2L, 200, 24);
709 WMMoveWidget(panel->name2L, 120, 60);
710 font = WMBoldSystemFontOfSize(scr->wmscreen, 18);
711 if (font) {
712 WMSetLabelFont(panel->name2L, font);
713 WMReleaseFont(font);
714 font = NULL;
716 WMSetLabelText(panel->name2L, "X11 Window Manager");
719 sprintf(version, "Version %s", VERSION);
720 panel->versionL = WMCreateLabel(panel->win);
721 WMResizeWidget(panel->versionL, 150, 16);
722 WMMoveWidget(panel->versionL, 190, 95);
723 WMSetLabelTextAlignment(panel->versionL, WARight);
724 WMSetLabelText(panel->versionL, version);
727 panel->copyrL = WMCreateLabel(panel->win);
728 WMResizeWidget(panel->copyrL, 340, 40);
729 WMMoveWidget(panel->copyrL, 15, 185);
730 WMSetLabelTextAlignment(panel->copyrL, WALeft);
731 WMSetLabelText(panel->copyrL, COPYRIGHT_TEXT);
732 /* we want the (c) character in the helvetica font */
733 font = WMCreateFontInDefaultEncoding(scr->wmscreen, HELVETICA10_FONT);
734 if (font) {
735 WMSetLabelFont(panel->copyrL, font);
738 sprintf(buffer, "Using visual %s %ibpp (0x%x)\n",
739 visuals[scr->w_visual->class], scr->w_depth,
740 (unsigned)scr->w_visual->visualid);
741 strcat(buffer, "Supported image formats: ");
742 strl = RSupportedFileFormats();
743 for (i=0; strl[i]!=NULL; i++) {
744 strcat(buffer, strl[i]);
745 strcat(buffer, " ");
748 panel->infoL = WMCreateLabel(panel->win);
749 WMResizeWidget(panel->infoL, 350, 75);
750 WMMoveWidget(panel->infoL, 15, 115);
751 WMSetLabelText(panel->infoL, buffer);
752 if (font) {
753 WMSetLabelFont(panel->infoL, font);
754 WMReleaseFont(font);
758 WMRealizeWidget(panel->win);
759 WMMapSubwidgets(panel->win);
761 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 382, 230, 0, 0, 0);
763 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
765 WMMapWidget(panel->win);
767 wwin = wManageInternalWindow(scr, parent, None, "Info",
768 (scr->scr_width - 382)/2,
769 (scr->scr_height - 230)/2, 382, 230);
771 wwin->window_flags.no_closable = 0;
772 wwin->window_flags.no_close_button = 0;
773 wWindowUpdateButtonImages(wwin);
774 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
775 wwin->frame->on_click_right = destroyInfoPanel;
777 wWindowMap(wwin);
779 panel->wwin = wwin;
781 thePanel = panel;
786 ***********************************************************************
787 * Legal Panel
788 ***********************************************************************
791 typedef struct {
792 WScreen *scr;
794 WWindow *wwin;
796 WMWindow *win;
798 WMLabel *licenseL;
799 } LegalPanel;
803 #define LICENSE_TEXT \
804 " WindowMaker is free software; you can redistribute it and/or modify "\
805 "it under the terms of the GNU General Public License as published "\
806 "by the Free Software Foundation; either version 2 of the License, "\
807 "or (at your option) any later version.\n\n\n"\
808 " WindowMaker is distributed in the hope that it will be useful, but "\
809 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
810 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
811 "General Public License for more details.\n\n\n"\
812 " You should have received a copy of the GNU General Public License "\
813 "along with this program; if not, write to the Free Software "\
814 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
815 "02111-1307, USA."
818 static LegalPanel *legalPanel = NULL;
820 static void
821 destroyLegalPanel(WCoreWindow *foo, void *data, XEvent *event)
823 WMUnmapWidget(legalPanel->win);
825 WMDestroyWidget(legalPanel->win);
827 wUnmanageWindow(legalPanel->wwin, False);
829 free(legalPanel);
831 legalPanel = NULL;
835 void
836 wShowLegalPanel(WScreen *scr)
838 LegalPanel *panel;
839 Window parent;
840 WWindow *wwin;
842 if (legalPanel) {
843 wRaiseFrame(legalPanel->wwin->frame->core);
844 wSetFocusTo(scr, legalPanel->wwin);
845 return;
848 panel = wmalloc(sizeof(LegalPanel));
850 panel->scr = scr;
852 panel->win = WMCreateWindow(scr->wmscreen, "legal");
853 WMResizeWidget(panel->win, 420, 250);
856 panel->licenseL = WMCreateLabel(panel->win);
857 WMResizeWidget(panel->licenseL, 400, 230);
858 WMMoveWidget(panel->licenseL, 10, 10);
859 WMSetLabelTextAlignment(panel->licenseL, WALeft);
860 WMSetLabelText(panel->licenseL, LICENSE_TEXT);
861 WMSetLabelRelief(panel->licenseL, WRGroove);
863 WMRealizeWidget(panel->win);
864 WMMapSubwidgets(panel->win);
866 parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 420, 250, 0, 0, 0);
868 XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
870 wwin = wManageInternalWindow(scr, parent, None, "Legal",
871 (scr->scr_width - 420)/2,
872 (scr->scr_height - 250)/2, 420, 250);
874 wwin->window_flags.no_closable = 0;
875 wwin->window_flags.no_close_button = 0;
876 wWindowUpdateButtonImages(wwin);
877 wFrameWindowShowButton(wwin->frame, WFF_RIGHT_BUTTON);
878 wwin->frame->on_click_right = destroyLegalPanel;
880 panel->wwin = wwin;
882 WMMapWidget(panel->win);
884 wWindowMap(wwin);
886 legalPanel = panel;