1 /* dialog.c - dialog windows for internal use
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
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,
26 #include <X11/Xutil.h>
27 #include <X11/keysym.h>
33 #include <sys/types.h>
39 #define PATH_MAX DEFAULT_PATH_MAX
42 #include "WindowMaker.h"
53 extern WPreferences wPreferences
;
58 wMessageDialog(WScreen
*scr
, char *title
, char *message
,
59 char *defBtn
, char *altBtn
, char *othBtn
)
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
);
82 while (!panel
->done
) {
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
);
105 wInputDialog(WScreen
*scr
, char *title
, char *message
, char **text
)
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
);
132 while (!panel
->done
) {
135 WMNextEvent(dpy
, &event
);
136 WMHandleEvent(&event
);
139 if (panel
->result
== WAPRDefault
)
140 result
= WMGetTextFieldText(panel
->text
);
144 wUnmanageWindow(wwin
, False
);
146 WMDestroyInputPanel(panel
);
148 XDestroyWindow(dpy
, parent
);
163 *****************************************************************
164 * Icon Selection Panel
165 *****************************************************************
168 typedef struct IconPanel
{
183 WMTextField
*fileField
;
186 WMButton
*cancelButton
;
188 WMButton
*chooseButton
;
197 listPixmaps(WScreen
*scr
, WMList
*lPtr
, char *path
)
199 struct dirent
*dentry
;
201 char pbuf
[PATH_MAX
+16];
204 apath
= wexpandpath(path
);
205 dir
= opendir(apath
);
210 tmp
= _("Could not open directory ");
211 msg
= wmalloc(strlen(tmp
)+strlen(path
)+6);
215 wMessageDialog(scr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
221 /* list contents in the column */
222 while ((dentry
= readdir(dir
))) {
225 if (strcmp(dentry
->d_name
, ".")==0 ||
226 strcmp(dentry
->d_name
, "..")==0)
231 strcat(pbuf
, dentry
->d_name
);
233 if (stat(pbuf
, &statb
)<0)
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
);
249 setViewedImage(IconPanel
*panel
, char *file
)
258 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
264 WMSetButtonEnabled(panel
->okButton
, False
);
266 tmp
= _("Could not load image file ");
267 msg
= wmalloc(strlen(tmp
)+strlen(file
)+6);
271 wMessageDialog(panel
->scr
, _("Error"), msg
, _("OK"), NULL
, NULL
);
274 WMSetLabelImage(panel
->iconView
, NULL
);
276 WMSetButtonEnabled(panel
->okButton
, True
);
278 WMSetLabelImage(panel
->iconView
, pixmap
);
279 WMReleasePixmap(pixmap
);
285 listCallback(void *self
, void *data
)
287 WMList
*lPtr
= (WMList
*)self
;
288 IconPanel
*panel
= (IconPanel
*)data
;
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
);
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);
313 strcat(path
, iconFile
);
315 WMSetTextFieldText(panel
->fileField
, path
);
316 setViewedImage(panel
, path
);
323 listIconPaths(WMList
*lPtr
)
327 for (i
=0; wPreferences
.icon_path
[i
]!=NULL
; i
++) {
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
]);
341 buttonCallback(void *self
, void *clientData
)
343 WMButton
*bPtr
= (WMButton
*)self
;
344 IconPanel
*panel
= (IconPanel
*)clientData
;
347 if (bPtr
==panel
->okButton
) {
349 panel
->result
= True
;
350 } else if (bPtr
==panel
->cancelButton
) {
352 panel
->result
= False
;
355 else if (bPtr
==panel
->chooseButton
) {
358 op
= WMCreateOpenPanel(WMWidgetScreen(bPtr
));
360 if (WMRunModalOpenPanelForDirectory(op
, NULL
, "/usr/local", NULL
, NULL
)) {
362 path
= WMGetFilePanelFile(op
);
363 WMSetTextFieldText(panel
->fileField
, path
);
364 setViewedImage(panel
, path
);
367 WMDestroyFilePanel(op
);
374 wIconChooserDialog(WScreen
*scr
, char **file
)
382 panel
= wmalloc(sizeof(IconPanel
));
383 memset(panel
, 0, sizeof(IconPanel
));
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
);
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
);
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
);
486 while (!panel
->done
) {
489 WMNextEvent(dpy
, &event
);
490 WMHandleEvent(&event
);
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
;
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) {
509 *file
= wstrdup(*file
);
518 WMUnmapWidget(panel
->win
);
520 WMDestroyWidget(panel
->win
);
522 wUnmanageWindow(wwin
, False
);
526 XDestroyWindow(dpy
, parent
);
528 return panel
->result
;
533 ***********************************************************************
535 ***********************************************************************
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
;
568 destroyInfoPanel(WCoreWindow
*foo
, void *data
, XEvent
*event
)
570 WMUnmapWidget(thePanel
);
572 WMDestroyWidget(thePanel
->win
);
574 wUnmanageWindow(thePanel
->wwin
, False
);
583 renderText(WMScreen
*scr
, char *text
, char *font
, RColor
*from
, RColor
*to
)
585 WMPixmap
*wpix
= NULL
;
586 RImage
*gradient
= NULL
;
589 RContext
*rc
= WMScreenRContext(scr
);
590 XFontStruct
*f
= NULL
;
594 f
= XLoadQueryFont(dpy
, font
);
598 w
= XTextWidth(f
, text
, strlen(text
));
599 h
= f
->ascent
+f
->descent
;
601 gradient
= RRenderGradient(w
, h
, from
, to
, RVerticalGradient
);
603 wwarning("error doing image processing:%s",
604 RMessageForError(RErrorCode
));
607 if (!RConvertImage(rc
, gradient
, &grad
)) {
608 wwarning("error doing image processing:%s",
609 RMessageForError(RErrorCode
));
613 mask
= XCreatePixmap(dpy
, rc
->drawable
, w
, h
, 1);
614 gc
= XCreateGC(dpy
, mask
, 0, NULL
);
615 XSetForeground(dpy
, gc
, rc
->black
);
616 XSetFont(dpy
, gc
, f
->fid
);
617 XFillRectangle(dpy
, mask
, gc
, 0, 0, w
, h
);
619 XSetForeground(dpy
, gc
, rc
->white
);
620 XDrawString(dpy
, mask
, gc
, 0, f
->ascent
, text
, strlen(text
));
622 XSetLineAttributes(dpy
, gc
, 3, LineSolid
, CapRound
, JoinMiter
);
624 XDrawLine(dpy
, mask
, gc
, 0, h
-2, w
, h
-2);
626 wpix
= WMCreatePixmapFromXPixmaps(scr
, grad
, mask
, w
, h
, rc
->depth
);
633 RDestroyImage(gradient
);
640 wShowInfoPanel(WScreen
*scr
)
650 RColor color1
, color2
;
663 wRaiseFrame(thePanel
->wwin
->frame
->core
);
664 wSetFocusTo(scr
, thePanel
->wwin
);
668 panel
= wmalloc(sizeof(InfoPanel
));
672 panel
->win
= WMCreateWindow(scr
->wmscreen
, "info");
673 WMResizeWidget(panel
->win
, 382, 230);
675 logo
= WMGetApplicationIconImage(scr
->wmscreen
);
677 size
= WMGetPixmapSize(logo
);
678 panel
->logoL
= WMCreateLabel(panel
->win
);
679 WMResizeWidget(panel
->logoL
, 64, 64);
680 WMMoveWidget(panel
->logoL
, 30, 20);
681 WMSetLabelImagePosition(panel
->logoL
, WIPImageOnly
);
682 WMSetLabelImage(panel
->logoL
, logo
);
685 panel
->name1L
= WMCreateLabel(panel
->win
);
686 WMResizeWidget(panel
->name1L
, 200, 30);
687 WMMoveWidget(panel
->name1L
, 120, 30);
694 logo
= renderText(scr
->wmscreen
, " Window Maker ",
695 "-*-times-bold-r-*-*-24-*", &color1
, &color2
);
697 WMSetLabelImagePosition(panel
->name1L
, WIPImageOnly
);
698 WMSetLabelImage(panel
->name1L
, logo
);
699 WMReleasePixmap(logo
);
701 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 24);
703 WMSetLabelFont(panel
->name1L
, font
);
706 WMSetLabelText(panel
->name1L
, "Window Maker");
709 panel
->name2L
= WMCreateLabel(panel
->win
);
710 WMResizeWidget(panel
->name2L
, 200, 24);
711 WMMoveWidget(panel
->name2L
, 120, 60);
712 font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 18);
714 WMSetLabelFont(panel
->name2L
, font
);
718 WMSetLabelText(panel
->name2L
, "X11 Window Manager");
721 sprintf(version
, "Version %s", VERSION
);
722 panel
->versionL
= WMCreateLabel(panel
->win
);
723 WMResizeWidget(panel
->versionL
, 150, 16);
724 WMMoveWidget(panel
->versionL
, 190, 95);
725 WMSetLabelTextAlignment(panel
->versionL
, WARight
);
726 WMSetLabelText(panel
->versionL
, version
);
729 panel
->copyrL
= WMCreateLabel(panel
->win
);
730 WMResizeWidget(panel
->copyrL
, 340, 40);
731 WMMoveWidget(panel
->copyrL
, 15, 185);
732 WMSetLabelTextAlignment(panel
->copyrL
, WALeft
);
733 WMSetLabelText(panel
->copyrL
, COPYRIGHT_TEXT
);
734 /* we want the (c) character in the helvetica font */
735 font
= WMCreateFontInDefaultEncoding(scr
->wmscreen
, HELVETICA10_FONT
);
737 WMSetLabelFont(panel
->copyrL
, font
);
740 switch (scr
->w_depth
) {
742 strcpy(version
, "32 thousand");
745 strcpy(version
, "64 thousand");
749 strcpy(version
, "16 million");
752 sprintf(version
, "%d", 1<<scr
->w_depth
);
756 sprintf(buffer
, "Using visual 0x%x: %s %ibpp (%s colors)\n",
757 (unsigned)scr
->w_visual
->visualid
,
758 visuals
[scr
->w_visual
->class], scr
->w_depth
, version
);
760 strcat(buffer
, "Supported image formats: ");
761 strl
= RSupportedFileFormats();
762 for (i
=0; strl
[i
]!=NULL
; i
++) {
763 strcat(buffer
, strl
[i
]);
767 strcat(buffer
, "\nSound support compiled in");
769 strcat(buffer
, "\nSound support not available");
772 panel
->infoL
= WMCreateLabel(panel
->win
);
773 WMResizeWidget(panel
->infoL
, 350, 75);
774 WMMoveWidget(panel
->infoL
, 15, 115);
775 WMSetLabelText(panel
->infoL
, buffer
);
777 WMSetLabelFont(panel
->infoL
, font
);
782 WMRealizeWidget(panel
->win
);
783 WMMapSubwidgets(panel
->win
);
785 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 382, 230, 0, 0, 0);
787 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
789 WMMapWidget(panel
->win
);
791 wwin
= wManageInternalWindow(scr
, parent
, None
, "Info",
792 (scr
->scr_width
- 382)/2,
793 (scr
->scr_height
- 230)/2, 382, 230);
795 wwin
->window_flags
.no_closable
= 0;
796 wwin
->window_flags
.no_close_button
= 0;
797 wWindowUpdateButtonImages(wwin
);
798 wFrameWindowShowButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
799 wwin
->frame
->on_click_right
= destroyInfoPanel
;
810 ***********************************************************************
812 ***********************************************************************
827 #define LICENSE_TEXT \
828 " Window Maker is free software; you can redistribute it and/or modify "\
829 "it under the terms of the GNU General Public License as published "\
830 "by the Free Software Foundation; either version 2 of the License, "\
831 "or (at your option) any later version.\n\n\n"\
832 " Window Maker is distributed in the hope that it will be useful, but "\
833 "WITHOUT ANY WARRANTY; without even the implied warranty of "\
834 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "\
835 "General Public License for more details.\n\n\n"\
836 " You should have received a copy of the GNU General Public License "\
837 "along with this program; if not, write to the Free Software "\
838 "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA "\
842 static LegalPanel
*legalPanel
= NULL
;
845 destroyLegalPanel(WCoreWindow
*foo
, void *data
, XEvent
*event
)
847 WMUnmapWidget(legalPanel
->win
);
849 WMDestroyWidget(legalPanel
->win
);
851 wUnmanageWindow(legalPanel
->wwin
, False
);
860 wShowLegalPanel(WScreen
*scr
)
867 wRaiseFrame(legalPanel
->wwin
->frame
->core
);
868 wSetFocusTo(scr
, legalPanel
->wwin
);
872 panel
= wmalloc(sizeof(LegalPanel
));
876 panel
->win
= WMCreateWindow(scr
->wmscreen
, "legal");
877 WMResizeWidget(panel
->win
, 420, 250);
880 panel
->licenseL
= WMCreateLabel(panel
->win
);
881 WMResizeWidget(panel
->licenseL
, 400, 230);
882 WMMoveWidget(panel
->licenseL
, 10, 10);
883 WMSetLabelTextAlignment(panel
->licenseL
, WALeft
);
884 WMSetLabelText(panel
->licenseL
, LICENSE_TEXT
);
885 WMSetLabelRelief(panel
->licenseL
, WRGroove
);
887 WMRealizeWidget(panel
->win
);
888 WMMapSubwidgets(panel
->win
);
890 parent
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 420, 250, 0, 0, 0);
892 XReparentWindow(dpy
, WMWidgetXID(panel
->win
), parent
, 0, 0);
894 wwin
= wManageInternalWindow(scr
, parent
, None
, "Legal",
895 (scr
->scr_width
- 420)/2,
896 (scr
->scr_height
- 250)/2, 420, 250);
898 wwin
->window_flags
.no_closable
= 0;
899 wwin
->window_flags
.no_close_button
= 0;
900 wWindowUpdateButtonImages(wwin
);
901 wFrameWindowShowButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
902 wwin
->frame
->on_click_right
= destroyLegalPanel
;
906 WMMapWidget(panel
->win
);