Files
wmaker/WPrefs.app/WPrefs.c
T

1080 lines
26 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* WPrefs.c- main window and other basic stuff
2004-10-12 21:28:27 +00:00
*
1998-10-21 14:43:47 +00:00
* WPrefs - Window Maker Preferences Program
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1998-09-29 22:36:29 +00:00
* USA.
*/
#include "WPrefs.h"
#include <assert.h>
extern Panel *InitWindowHandling(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitKeyboardSettings(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitMouseSettings(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitKeyboardShortcuts(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitWorkspace(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitFocus(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitPreferences(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitFont(WMScreen *scr, WMWidget *parent);
2004-10-13 23:39:29 +00:00
extern Panel *InitFontSimple(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitConfigurations(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitPaths(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitMenu(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitExpert(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitMenuPreferences(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitIcons(WMScreen *scr, WMWidget *parent);
1998-09-29 22:36:29 +00:00
extern Panel *InitThemes(WMScreen *scr, WMWidget *parent);
1999-01-06 15:22:33 +00:00
extern Panel *InitAppearance(WMScreen *scr, WMWidget *parent);
1999-01-06 15:22:33 +00:00
1998-09-29 22:36:29 +00:00
2000-03-28 02:48:32 +00:00
#define ICON_TITLE_FONT "sans serif:pixelsize=9"
#define ICON_TITLE_VFONT "sans serif:pixelsize=9:weight=100"
2000-03-28 02:48:32 +00:00
1998-09-29 22:36:29 +00:00
#define MAX_SECTIONS 16
2004-10-12 21:28:27 +00:00
typedef struct _WPrefs {
1998-09-29 22:36:29 +00:00
WMWindow *win;
WMScrollView *scrollV;
WMFrame *buttonF;
WMButton *sectionB[MAX_SECTIONS];
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
int sectionCount;
WMButton *saveBtn;
WMButton *closeBtn;
WMButton *undoBtn;
WMButton *undosBtn;
1999-04-25 21:43:50 +00:00
WMButton *balloonBtn;
1998-09-29 22:36:29 +00:00
WMFrame *banner;
WMLabel *nameL;
WMLabel *versionL;
WMLabel *statusL;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
Panel *currentPanel;
} _WPrefs;
static _WPrefs WPrefs;
/* system wide defaults dictionary. Read-only */
static WMPropList *GlobalDB = NULL;
1998-09-29 22:36:29 +00:00
/* user defaults dictionary */
static WMPropList *WindowMakerDB = NULL;
static char *WindowMakerDBPath = NULL;
1998-09-29 22:36:29 +00:00
static Bool TIFFOK = False;
#define INITIALIZED_PANEL (1<<0)
static void loadConfigurations(WMScreen *scr, WMWindow *mainw);
static void savePanelData(Panel *panel);
static void prepareForClose();
1998-09-29 22:36:29 +00:00
void
quit(WMWidget *w, void *data)
{
prepareForClose();
1998-09-29 22:36:29 +00:00
exit(0);
}
static void
save(WMWidget *w, void *data)
{
int i;
WMPropList *p1, *p2;
WMPropList *keyList;
WMPropList *key;
1999-04-03 03:51:17 +00:00
char *msg = "Reconfigure";
XEvent ev;
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
/* puts("gathering data");*/
1998-09-29 22:36:29 +00:00
for (i=0; i<WPrefs.sectionCount; i++) {
2004-10-12 21:28:27 +00:00
PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
if ((rec->callbacks.flags & INITIALIZED_PANEL))
savePanelData((Panel*)rec);
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
/* puts("compressing data");*/
1998-09-29 22:36:29 +00:00
/* compare the user dictionary with the global and remove redundant data */
keyList = WMGetPLDictionaryKeys(GlobalDB);
2004-10-12 21:28:27 +00:00
/* puts(WMGetPropListDescription(WindowMakerDB, False));*/
for (i=0; i<WMGetPropListItemCount(keyList); i++) {
2004-10-12 21:28:27 +00:00
key = WMGetFromPLArray(keyList, i);
/* We don't have this value anyway, so no problem.
* Probably a new option */
p1 = WMGetFromPLDictionary(WindowMakerDB, key);
if (!p1)
continue;
/* The global doesn't have it, so no problem either. */
p2 = WMGetFromPLDictionary(GlobalDB, key);
if (!p2)
continue;
/* If both values are the same, don't save. */
if (WMIsPropListEqualTo(p1, p2))
WMRemoveFromPLDictionary(WindowMakerDB, key);
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
/* puts(WMGetPropListDescription(WindowMakerDB, False));*/
WMReleasePropList(keyList);
2004-10-12 21:28:27 +00:00
/* puts("storing data");*/
1998-09-29 22:36:29 +00:00
WMWritePropListToFile(WindowMakerDB, WindowMakerDBPath, True);
1999-04-03 03:51:17 +00:00
memset(&ev, 0, sizeof(XEvent));
2004-10-12 21:28:27 +00:00
1999-04-03 03:51:17 +00:00
ev.xclient.type = ClientMessage;
ev.xclient.message_type = XInternAtom(WMScreenDisplay(WMWidgetScreen(w)),
2004-10-12 21:28:27 +00:00
"_WINDOWMAKER_COMMAND", False);
1999-04-03 03:51:17 +00:00
ev.xclient.window = DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w)));
ev.xclient.format = 8;
for (i = 0; i <= strlen(msg); i++) {
2004-10-12 21:28:27 +00:00
ev.xclient.data.b[i] = msg[i];
1999-04-03 03:51:17 +00:00
}
2004-10-12 21:28:27 +00:00
XSendEvent(WMScreenDisplay(WMWidgetScreen(w)),
DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w))),
False, SubstructureRedirectMask, &ev);
1999-04-03 03:51:17 +00:00
XFlush(WMScreenDisplay(WMWidgetScreen(w)));
1998-09-29 22:36:29 +00:00
}
1998-09-29 22:36:29 +00:00
static void
undo(WMWidget *w, void *data)
{
PanelRec *rec = (PanelRec*)WPrefs.currentPanel;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!rec)
2004-10-12 21:28:27 +00:00
return;
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
if (rec->callbacks.undoChanges
&& (rec->callbacks.flags & INITIALIZED_PANEL)) {
(*rec->callbacks.undoChanges)(WPrefs.currentPanel);
1998-09-29 22:36:29 +00:00
}
}
static void
undoAll(WMWidget *w, void *data)
{
int i;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
for (i=0; i<WPrefs.sectionCount; i++) {
2004-10-12 21:28:27 +00:00
PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
if (rec->callbacks.undoChanges
&& (rec->callbacks.flags & INITIALIZED_PANEL))
(*rec->callbacks.undoChanges)((Panel*)rec);
1998-09-29 22:36:29 +00:00
}
}
static void
prepareForClose()
{
int i;
1999-04-25 21:43:50 +00:00
for (i=0; i<WPrefs.sectionCount; i++) {
2004-10-12 21:28:27 +00:00
PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
2004-10-12 21:28:27 +00:00
if (rec->callbacks.prepareForClose
&& (rec->callbacks.flags & INITIALIZED_PANEL))
(*rec->callbacks.prepareForClose)((Panel*)rec);
}
}
1999-04-25 21:43:50 +00:00
void
toggleBalloons(WMWidget *w, void *data)
{
WMUserDefaults *udb = WMGetStandardUserDefaults();
Bool flag;
flag = WMGetButtonSelected(WPrefs.balloonBtn);
WMSetBalloonEnabled(WMWidgetScreen(WPrefs.win), flag);
WMSetUDBoolForKey(udb, flag, "BalloonHelp");
}
1998-09-29 22:36:29 +00:00
static void
createMainWindow(WMScreen *scr)
{
WMScroller *scroller;
WMFont *font;
char buffer[128];
WPrefs.win = WMCreateWindow(scr, "wprefs");
WMResizeWidget(WPrefs.win, 520, 390);
1998-10-21 14:43:47 +00:00
WMSetWindowTitle(WPrefs.win, _("Window Maker Preferences"));
1998-09-29 22:36:29 +00:00
WMSetWindowCloseAction(WPrefs.win, quit, NULL);
WMSetWindowMaxSize(WPrefs.win, 520, 390);
WMSetWindowMinSize(WPrefs.win, 520, 390);
WMSetWindowMiniwindowTitle(WPrefs.win, "Preferences");
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WPrefs.scrollV = WMCreateScrollView(WPrefs.win);
WMResizeWidget(WPrefs.scrollV, 500, 87);
WMMoveWidget(WPrefs.scrollV, 10, 10);
WMSetScrollViewRelief(WPrefs.scrollV, WRSunken);
WMSetScrollViewHasHorizontalScroller(WPrefs.scrollV, True);
WMSetScrollViewHasVerticalScroller(WPrefs.scrollV, False);
scroller = WMGetScrollViewHorizontalScroller(WPrefs.scrollV);
WMSetScrollerArrowsPosition(scroller, WSANone);
WPrefs.buttonF = WMCreateFrame(WPrefs.win);
WMSetFrameRelief(WPrefs.buttonF, WRFlat);
WMSetScrollViewContentView(WPrefs.scrollV, WMWidgetView(WPrefs.buttonF));
WPrefs.undosBtn = WMCreateCommandButton(WPrefs.win);
WMResizeWidget(WPrefs.undosBtn, 90, 28);
WMMoveWidget(WPrefs.undosBtn, 135, 350);
WMSetButtonText(WPrefs.undosBtn, _("Revert Page"));
WMSetButtonAction(WPrefs.undosBtn, undo, NULL);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WPrefs.undoBtn = WMCreateCommandButton(WPrefs.win);
WMResizeWidget(WPrefs.undoBtn, 90, 28);
WMMoveWidget(WPrefs.undoBtn, 235, 350);
WMSetButtonText(WPrefs.undoBtn, _("Revert All"));
WMSetButtonAction(WPrefs.undoBtn, undoAll, NULL);
WPrefs.saveBtn = WMCreateCommandButton(WPrefs.win);
WMResizeWidget(WPrefs.saveBtn, 80, 28);
WMMoveWidget(WPrefs.saveBtn, 335, 350);
WMSetButtonText(WPrefs.saveBtn, _("Save"));
WMSetButtonAction(WPrefs.saveBtn, save, NULL);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WPrefs.closeBtn = WMCreateCommandButton(WPrefs.win);
WMResizeWidget(WPrefs.closeBtn, 80, 28);
WMMoveWidget(WPrefs.closeBtn, 425, 350);
WMSetButtonText(WPrefs.closeBtn, _("Close"));
WMSetButtonAction(WPrefs.closeBtn, quit, NULL);
1999-04-25 21:43:50 +00:00
WPrefs.balloonBtn = WMCreateSwitchButton(WPrefs.win);
WMResizeWidget(WPrefs.balloonBtn, 200, 28);
WMMoveWidget(WPrefs.balloonBtn, 15, 350);
WMSetButtonText(WPrefs.balloonBtn, _("Balloon Help"));
WMSetButtonAction(WPrefs.balloonBtn, toggleBalloons, NULL);
{
2004-10-12 21:28:27 +00:00
WMUserDefaults *udb = WMGetStandardUserDefaults();
Bool flag = WMGetUDBoolForKey(udb, "BalloonHelp");
1999-04-25 21:43:50 +00:00
2004-10-12 21:28:27 +00:00
WMSetButtonSelected(WPrefs.balloonBtn, flag);
WMSetBalloonEnabled(scr, flag);
1999-04-25 21:43:50 +00:00
}
1998-09-29 22:36:29 +00:00
/* banner */
WPrefs.banner = WMCreateFrame(WPrefs.win);
WMResizeWidget(WPrefs.banner, FRAME_WIDTH, FRAME_HEIGHT);
WMMoveWidget(WPrefs.banner, FRAME_LEFT, FRAME_TOP);
WMSetFrameRelief(WPrefs.banner, WRFlat);
font = WMCreateFont(scr, "Lucida Sans,URW Gothic L,Times New Roman,serif"
":bold:pixelsize=26:antialias=true");
1998-09-29 22:36:29 +00:00
WPrefs.nameL = WMCreateLabel(WPrefs.banner);
WMSetLabelTextAlignment(WPrefs.nameL, WACenter);
2004-10-19 02:37:58 +00:00
WMResizeWidget(WPrefs.nameL, FRAME_WIDTH-20, 60);
WMMoveWidget(WPrefs.nameL, 10, 50);
1998-09-29 22:36:29 +00:00
WMSetLabelFont(WPrefs.nameL, font);
2004-10-19 02:37:58 +00:00
WMSetLabelText(WPrefs.nameL, _("Window Maker Preferences"));
1998-09-29 22:36:29 +00:00
WMReleaseFont(font);
WPrefs.versionL = WMCreateLabel(WPrefs.banner);
WMResizeWidget(WPrefs.versionL, FRAME_WIDTH-20, 20);
2004-10-19 03:29:52 +00:00
WMMoveWidget(WPrefs.versionL, 10, 120);
1998-09-29 22:36:29 +00:00
WMSetLabelTextAlignment(WPrefs.versionL, WACenter);
2004-10-19 02:37:58 +00:00
sprintf(buffer, _("Version %s"), VERSION);
1998-09-29 22:36:29 +00:00
WMSetLabelText(WPrefs.versionL, buffer);
WPrefs.statusL = WMCreateLabel(WPrefs.banner);
WMResizeWidget(WPrefs.statusL, FRAME_WIDTH-20, 60);
2004-10-19 02:37:58 +00:00
WMMoveWidget(WPrefs.statusL, 10, 150);
1998-09-29 22:36:29 +00:00
WMSetLabelTextAlignment(WPrefs.statusL, WACenter);
WMSetLabelText(WPrefs.statusL, _("Starting..."));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(WPrefs.win);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMUnmapWidget(WPrefs.undosBtn);
WMUnmapWidget(WPrefs.undoBtn);
WMUnmapWidget(WPrefs.saveBtn);
}
static void
showPanel(Panel *panel)
{
PanelRec *rec = (PanelRec*)panel;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!(rec->callbacks.flags & INITIALIZED_PANEL)) {
2004-10-12 21:28:27 +00:00
(*rec->callbacks.createWidgets)(panel);
rec->callbacks.flags |= INITIALIZED_PANEL;
1998-09-29 22:36:29 +00:00
}
WMSetWindowTitle(WPrefs.win, rec->sectionName);
2004-10-12 21:28:27 +00:00
2000-07-14 05:48:35 +00:00
if (rec->callbacks.showPanel)
2004-10-12 21:28:27 +00:00
(*rec->callbacks.showPanel)(panel);
2000-07-14 05:48:35 +00:00
WMMapWidget(rec->box);
1998-09-29 22:36:29 +00:00
}
static void
hidePanel(Panel *panel)
{
2004-10-12 21:28:27 +00:00
PanelRec *rec = (PanelRec*)panel;
WMUnmapWidget(rec->box);
2004-10-12 21:28:27 +00:00
2000-07-14 05:48:35 +00:00
if (rec->callbacks.hidePanel)
2004-10-12 21:28:27 +00:00
(*rec->callbacks.hidePanel)(panel);
1998-09-29 22:36:29 +00:00
}
static void
savePanelData(Panel *panel)
{
2004-10-12 21:28:27 +00:00
PanelRec *rec = (PanelRec*)panel;
1998-09-29 22:36:29 +00:00
if (rec->callbacks.updateDomain) {
2004-10-12 21:28:27 +00:00
(*rec->callbacks.updateDomain)(panel);
1998-09-29 22:36:29 +00:00
}
}
2004-10-12 21:28:27 +00:00
static void
1998-09-29 22:36:29 +00:00
changeSection(WMWidget *self, void *data)
{
2001-01-06 22:38:07 +00:00
if (WPrefs.currentPanel == data)
2004-10-12 21:28:27 +00:00
return;
if (WPrefs.currentPanel == NULL) {
2004-10-12 21:28:27 +00:00
WMDestroyWidget(WPrefs.nameL);
WMDestroyWidget(WPrefs.versionL);
WMDestroyWidget(WPrefs.statusL);
2004-10-12 21:28:27 +00:00
WMSetFrameRelief(WPrefs.banner, WRGroove);
2004-10-12 21:28:27 +00:00
/* WMMapWidget(WPrefs.undosBtn);
WMMapWidget(WPrefs.undoBtn);
*/
WMMapWidget(WPrefs.saveBtn);
1998-09-29 22:36:29 +00:00
}
1998-09-29 22:36:29 +00:00
showPanel(data);
1998-09-29 22:36:29 +00:00
if (WPrefs.currentPanel)
2004-10-12 21:28:27 +00:00
hidePanel(WPrefs.currentPanel);
1998-09-29 22:36:29 +00:00
WPrefs.currentPanel = data;
}
char*
LocateImage(char *name)
{
char *path;
char *tmp = wmalloc(strlen(name)+8);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (TIFFOK) {
2004-10-12 21:28:27 +00:00
sprintf(tmp, "%s.tiff", name);
path = WMPathForResourceOfType(tmp, "tiff");
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
sprintf(tmp, "%s.xpm", name);
path = WMPathForResourceOfType(tmp, "xpm");
1998-09-29 22:36:29 +00:00
}
wfree(tmp);
1998-09-29 22:36:29 +00:00
if (!path) {
2004-10-12 21:28:27 +00:00
wwarning(_("could not locate image file %s\n"), name);
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
return path;
}
2000-03-28 02:48:32 +00:00
static WMPixmap*
makeTitledIcon(WMScreen *scr, WMPixmap *icon, char *title1, char *title2)
{
return WMRetainPixmap(icon);
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
#if 0
static GC gc = NULL;
static XFontStruct *hfont = NULL;
static XFontStruct *vfont = NULL;
WMPixmap *tmp;
Pixmap pix, mask;
Display *dpy = WMScreenDisplay(scr);
WMColor *black = WMBlackColor(scr);
GC fgc;
WMSize size = WMGetPixmapSize(icon);
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
tmp = WMCreatePixmap(scr, 60, 60, WMScreenDepth(scr), True);
pix = WMGetPixmapXID(tmp);
mask = WMGetPixmapMaskXID(tmp);
if (gc == NULL) {
2004-10-12 21:28:27 +00:00
gc = XCreateGC(dpy, mask, 0, NULL);
2000-03-28 02:48:32 +00:00
2004-10-12 21:28:27 +00:00
hfont = XLoadQueryFont(dpy, ICON_TITLE_FONT);
vfont = XLoadQueryFont(dpy, ICON_TITLE_VFONT);
2000-03-28 02:48:32 +00:00
}
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
if (hfont == NULL) {
2004-10-12 21:28:27 +00:00
return WMRetainPixmap(icon);
2000-03-28 02:48:32 +00:00
}
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
XSetForeground(dpy, gc, 0);
XFillRectangle(dpy, mask, gc, 0, 0, 60, 60);
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
fgc = WMColorGC(black);
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
XSetForeground(dpy, gc, 1);
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
XCopyArea(dpy, WMGetPixmapXID(icon), pix, fgc, 0, 0,
2004-10-12 21:28:27 +00:00
size.width, size.height, 12, 12);
2000-03-28 02:48:32 +00:00
if (WMGetPixmapMaskXID(icon) != None)
2004-10-12 21:28:27 +00:00
XCopyPlane(dpy, WMGetPixmapMaskXID(icon), mask, gc, 0, 0,
size.width, size.height, 12, 12, 1);
2000-03-28 02:48:32 +00:00
else
2004-10-12 21:28:27 +00:00
XFillRectangle(dpy, mask, gc, 12, 12, 48, 48);
2000-03-28 02:48:32 +00:00
if (title1) {
2004-10-12 21:28:27 +00:00
XSetFont(dpy, fgc, vfont->fid);
XSetFont(dpy, gc, vfont->fid);
XDrawString(dpy, pix, fgc, 0, vfont->ascent,
title1, strlen(title1));
XDrawString(dpy, mask, gc, 0, vfont->ascent,
title1, strlen(title1));
2000-03-28 02:48:32 +00:00
}
if (title2) {
2004-10-12 21:28:27 +00:00
XSetFont(dpy, fgc, hfont->fid);
XSetFont(dpy, gc, hfont->fid);
XDrawString(dpy, pix, fgc, (title1 ? 12 : 0), hfont->ascent,
title2, strlen(title2));
XDrawString(dpy, mask, gc, (title1 ? 12 : 0), hfont->ascent,
title2, strlen(title2));
2000-03-28 02:48:32 +00:00
}
return tmp;
#endif
}
1998-09-29 22:36:29 +00:00
void
2000-03-28 02:48:32 +00:00
SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, char *file,
2004-10-12 21:28:27 +00:00
char *title1, char *title2)
1998-09-29 22:36:29 +00:00
{
WMPixmap *icon;
2000-03-28 02:48:32 +00:00
WMPixmap *icon2;
1998-09-29 22:36:29 +00:00
RColor color;
char *iconPath;
1999-03-09 14:58:01 +00:00
iconPath = LocateImage(file);
1998-09-29 22:36:29 +00:00
color.red = 0xae;
color.green = 0xaa;
color.blue = 0xae;
color.alpha = 0;
if (iconPath) {
2004-10-12 21:28:27 +00:00
icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
if (!icon)
wwarning(_("could not load icon file %s"), iconPath);
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
icon = NULL;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
if (icon) {
2004-10-12 21:28:27 +00:00
icon2 = makeTitledIcon(scr, icon, title1, title2);
if (icon)
WMReleasePixmap(icon);
2000-03-28 02:48:32 +00:00
} else {
2004-10-12 21:28:27 +00:00
icon2 = NULL;
2000-03-28 02:48:32 +00:00
}
2004-10-12 21:28:27 +00:00
2000-03-28 02:48:32 +00:00
WMSetButtonImage(bPtr, icon2);
1998-09-29 22:36:29 +00:00
2000-03-28 02:48:32 +00:00
if (icon2)
2004-10-12 21:28:27 +00:00
WMReleasePixmap(icon2);
1998-09-29 22:36:29 +00:00
color.red = 0xff;
color.green = 0xff;
color.blue = 0xff;
color.alpha = 0;
if (iconPath) {
2004-10-12 21:28:27 +00:00
icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
if (!icon)
wwarning(_("could not load icon file %s"), iconPath);
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
icon = NULL;
1998-09-29 22:36:29 +00:00
}
WMSetButtonAltImage(bPtr, icon);
if (icon)
2004-10-12 21:28:27 +00:00
WMReleasePixmap(icon);
1998-09-29 22:36:29 +00:00
1999-03-09 14:58:01 +00:00
if (iconPath)
2004-10-12 21:28:27 +00:00
wfree(iconPath);
1999-03-09 14:58:01 +00:00
}
void
AddSection(Panel *panel, char *iconFile)
{
WMButton *bPtr;
assert(WPrefs.sectionCount < MAX_SECTIONS);
2004-10-12 21:28:27 +00:00
1999-03-09 14:58:01 +00:00
bPtr = WMCreateCustomButton(WPrefs.buttonF, WBBStateLightMask
2004-10-12 21:28:27 +00:00
|WBBStateChangeMask);
1999-03-09 14:58:01 +00:00
WMResizeWidget(bPtr, 64, 64);
WMMoveWidget(bPtr, WPrefs.sectionCount*64, 0);
WMSetButtonImagePosition(bPtr, WIPImageOnly);
WMSetButtonAction(bPtr, changeSection, panel);
WMHangData(bPtr, panel);
2004-10-12 21:28:27 +00:00
WMSetBalloonTextForView(((PanelRec*)panel)->description,
WMWidgetView(bPtr));
1999-04-25 01:49:46 +00:00
2000-03-28 02:48:32 +00:00
{
2004-10-12 21:28:27 +00:00
char *t1, *t2;
t1 = wstrdup(((PanelRec*)panel)->sectionName);
t2 = strchr(t1, ' ');
if (t2) {
*t2 = 0;
t2++;
}
SetButtonAlphaImage(WMWidgetScreen(bPtr), bPtr, iconFile,
t1, t2);
wfree(t1);
2000-03-28 02:48:32 +00:00
}
1998-09-29 22:36:29 +00:00
WMMapWidget(bPtr);
WPrefs.sectionB[WPrefs.sectionCount] = bPtr;
if (WPrefs.sectionCount > 0) {
2004-10-12 21:28:27 +00:00
WMGroupButtons(WPrefs.sectionB[0], bPtr);
1998-09-29 22:36:29 +00:00
}
1999-04-25 01:49:46 +00:00
1998-09-29 22:36:29 +00:00
WPrefs.sectionCount++;
1999-04-25 01:49:46 +00:00
1998-09-29 22:36:29 +00:00
WMResizeWidget(WPrefs.buttonF, WPrefs.sectionCount*64, 64);
}
void
Initialize(WMScreen *scr)
{
char **list;
int i;
char *path;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
list = RSupportedFileFormats();
for (i=0; list[i]!=NULL; i++) {
2004-10-12 21:28:27 +00:00
if (strcmp(list[i], "TIFF")==0) {
TIFFOK = True;
break;
}
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (TIFFOK)
2004-10-12 21:28:27 +00:00
path = WMPathForResourceOfType("WPrefs.tiff", NULL);
1998-09-29 22:36:29 +00:00
else
2004-10-12 21:28:27 +00:00
path = WMPathForResourceOfType("WPrefs.xpm", NULL);
1998-09-29 22:36:29 +00:00
if (path) {
2004-10-12 21:28:27 +00:00
RImage *tmp;
tmp = RLoadImage(WMScreenRContext(scr), path, 0);
if (!tmp) {
wwarning(_("could not load image file %s:%s"), path,
RMessageForError(RErrorCode));
} else {
2004-10-23 21:07:13 +00:00
WMSetApplicationIconImage(scr, tmp);
2004-10-12 21:28:27 +00:00
RReleaseImage(tmp);
}
wfree(path);
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
memset(&WPrefs, 0, sizeof(_WPrefs));
createMainWindow(scr);
WMRealizeWidget(WPrefs.win);
2004-10-23 21:07:13 +00:00
WMSetWindowMiniwindowImage(WPrefs.win, WMGetApplicationIconImage(scr));
1998-09-29 22:36:29 +00:00
WMMapWidget(WPrefs.win);
XFlush(WMScreenDisplay(scr));
1998-10-21 14:43:47 +00:00
WMSetLabelText(WPrefs.statusL, _("Loading Window Maker configuration files..."));
1998-09-29 22:36:29 +00:00
XFlush(WMScreenDisplay(scr));
loadConfigurations(scr, WPrefs.win);
WMSetLabelText(WPrefs.statusL, _("Initializing configuration panels..."));
1999-03-09 14:58:01 +00:00
InitFocus(scr, WPrefs.banner);
InitWindowHandling(scr, WPrefs.banner);
InitMenuPreferences(scr, WPrefs.banner);
InitIcons(scr, WPrefs.banner);
InitPreferences(scr, WPrefs.banner);
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
InitPaths(scr, WPrefs.banner);
InitWorkspace(scr, WPrefs.banner);
InitConfigurations(scr, WPrefs.banner);
1999-03-09 14:58:01 +00:00
InitMenu(scr, WPrefs.banner);
1999-03-09 14:58:01 +00:00
1998-09-29 22:36:29 +00:00
#ifdef not_yet_fully_implemented
InitKeyboardSettings(scr, WPrefs.banner);
1998-09-29 22:36:29 +00:00
#endif
InitKeyboardShortcuts(scr, WPrefs.banner);
InitMouseSettings(scr, WPrefs.banner);
InitAppearance(scr, WPrefs.banner);
2002-10-08 08:26:06 +00:00
2004-10-13 23:39:29 +00:00
InitFontSimple(scr, WPrefs.banner);
2002-10-08 08:26:06 +00:00
#ifdef not_yet_fully_implemented
InitThemes(scr, WPrefs.banner);
1998-09-29 22:36:29 +00:00
#endif
InitExpert(scr, WPrefs.banner);
1999-03-09 14:58:01 +00:00
1998-09-29 22:36:29 +00:00
WMRealizeWidget(WPrefs.scrollV);
2004-10-19 02:37:58 +00:00
WMSetLabelText(WPrefs.statusL, "");
1998-09-29 22:36:29 +00:00
}
WMWindow*
GetWindow(Panel *panel)
{
return WPrefs.win;
}
static void
loadConfigurations(WMScreen *scr, WMWindow *mainw)
{
WMPropList *db, *gdb;
1998-09-29 22:36:29 +00:00
char *path;
FILE *file;
char buffer[1024];
char mbuf[1024];
int v1, v2, v3;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
path = wdefaultspathfordomain("WindowMaker");
WindowMakerDBPath = path;
2004-10-12 21:28:27 +00:00
db = WMReadPropListFromFile(path);
1998-09-29 22:36:29 +00:00
if (db) {
2004-10-12 21:28:27 +00:00
if (!WMIsPLDictionary(db)) {
WMReleasePropList(db);
db = NULL;
sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), path);
WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
}
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
sprintf(mbuf, _("Could not load Window Maker domain (%s) from defaults database."),
path);
WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
1998-09-29 22:36:29 +00:00
}
path = getenv("WMAKER_BIN_NAME");
if (!path)
2004-10-12 21:28:27 +00:00
path = "wmaker";
2000-07-14 05:48:35 +00:00
{
2004-10-12 21:28:27 +00:00
char *command;
2004-10-12 21:28:27 +00:00
command = wstrconcat(path, " --version");
file = popen(command, "r");
wfree(command);
2000-07-14 05:48:35 +00:00
}
1998-09-29 22:36:29 +00:00
if (!file || !fgets(buffer, 1023, file)) {
2004-10-12 21:28:27 +00:00
wsyserror(_("could not extract version information from Window Maker"));
wfatal(_("Make sure wmaker is in your search path."));
WMRunAlertPanel(scr, mainw, _("Error"),
_("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
_("OK"), NULL, NULL);
exit(1);
1998-09-29 22:36:29 +00:00
}
if (file)
2004-10-12 21:28:27 +00:00
pclose(file);
1998-10-21 14:43:47 +00:00
if (sscanf(buffer, "Window Maker %i.%i.%i",&v1,&v2,&v3)!=3
2004-10-12 21:28:27 +00:00
&& sscanf(buffer, "WindowMaker %i.%i.%i",&v1,&v2,&v3)!=3) {
WMRunAlertPanel(scr, mainw, _("Error"),
_("Could not extract version from Window Maker. "
"Make sure it is correctly installed and the path "
"where it installed is in the PATH environment "
"variable."), _("OK"), NULL, NULL);
exit(1);
1998-09-29 22:36:29 +00:00
}
if (v1 == 0 && (v2 < 18 || v3 < 0)) {
2004-10-12 21:28:27 +00:00
sprintf(mbuf, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
"The version installed is %i.%i.%i\n"), v1, v2, v3);
WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
exit(1);
1998-09-29 22:36:29 +00:00
}
if (v1 > 1 || (v1 == 1 && (v2 > 0))) {
2004-10-12 21:28:27 +00:00
sprintf(mbuf, _("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
v1, v2, v3);
WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL);
1998-09-29 22:36:29 +00:00
}
2000-07-14 05:48:35 +00:00
{
2004-10-12 21:28:27 +00:00
char *command;
command = wstrconcat(path, " --global_defaults_path");
file = popen(command, "r");
wfree(command);
2000-07-14 05:48:35 +00:00
}
1998-09-29 22:36:29 +00:00
if (!file || !fgets(buffer, 1023, file)) {
2004-10-12 21:28:27 +00:00
wsyserror(_("could not run \"%s --global_defaults_path\"."), path);
exit(1);
} else {
2004-10-12 21:28:27 +00:00
char *ptr;
ptr = strchr(buffer, '\n');
if (ptr)
*ptr = 0;
strcat(buffer, "/WindowMaker");
1998-09-29 22:36:29 +00:00
}
1998-09-29 22:36:29 +00:00
if (file)
2004-10-12 21:28:27 +00:00
pclose(file);
1998-09-29 22:36:29 +00:00
gdb = WMReadPropListFromFile(buffer);
1998-09-29 22:36:29 +00:00
if (gdb) {
2004-10-12 21:28:27 +00:00
if (!WMIsPLDictionary(gdb)) {
WMReleasePropList(gdb);
gdb = NULL;
sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), buffer);
WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
}
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
sprintf(mbuf, _("Could not load global Window Maker domain (%s)."),
buffer);
WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
1998-09-29 22:36:29 +00:00
}
if (!db) {
2004-10-12 21:28:27 +00:00
db = WMCreatePLDictionary(NULL, NULL);
1998-09-29 22:36:29 +00:00
}
if (!gdb) {
2004-10-12 21:28:27 +00:00
gdb = WMCreatePLDictionary(NULL, NULL);
1998-09-29 22:36:29 +00:00
}
GlobalDB = gdb;
WindowMakerDB = db;
}
WMPropList*
1998-09-29 22:36:29 +00:00
GetObjectForKey(char *defaultName)
{
WMPropList *object = NULL;
WMPropList *key = WMCreatePLString(defaultName);
1998-09-29 22:36:29 +00:00
object = WMGetFromPLDictionary(WindowMakerDB, key);
1998-09-29 22:36:29 +00:00
if (!object)
2004-10-12 21:28:27 +00:00
object = WMGetFromPLDictionary(GlobalDB, key);
1998-09-29 22:36:29 +00:00
WMReleasePropList(key);
1998-09-29 22:36:29 +00:00
return object;
}
void
SetObjectForKey(WMPropList *object, char *defaultName)
1998-09-29 22:36:29 +00:00
{
WMPropList *key = WMCreatePLString(defaultName);
1998-09-29 22:36:29 +00:00
WMPutInPLDictionary(WindowMakerDB, key, object);
WMReleasePropList(key);
1998-09-29 22:36:29 +00:00
}
void
RemoveObjectForKey(char *defaultName)
{
WMPropList *key = WMCreatePLString(defaultName);
2004-10-12 21:28:27 +00:00
WMRemoveFromPLDictionary(WindowMakerDB, key);
2004-10-12 21:28:27 +00:00
WMReleasePropList(key);
1998-09-29 22:36:29 +00:00
}
char*
GetStringForKey(char *defaultName)
{
WMPropList *val;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
val = GetObjectForKey(defaultName);
if (!val)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
if (!WMIsPLString(val))
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
return WMGetFromPLString(val);
1998-09-29 22:36:29 +00:00
}
WMPropList*
1998-09-29 22:36:29 +00:00
GetArrayForKey(char *defaultName)
{
WMPropList *val;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
val = GetObjectForKey(defaultName);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!val)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
if (!WMIsPLArray(val))
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
return val;
}
WMPropList*
1998-09-29 22:36:29 +00:00
GetDictionaryForKey(char *defaultName)
{
WMPropList *val;
1998-09-29 22:36:29 +00:00
val = GetObjectForKey(defaultName);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!val)
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
if (!WMIsPLDictionary(val))
2004-10-12 21:28:27 +00:00
return NULL;
1998-09-29 22:36:29 +00:00
return val;
}
int
GetIntegerForKey(char *defaultName)
{
WMPropList *val;
1998-09-29 22:36:29 +00:00
char *str;
int value;
val = GetObjectForKey(defaultName);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!val)
2004-10-12 21:28:27 +00:00
return 0;
1998-09-29 22:36:29 +00:00
if (!WMIsPLString(val))
2004-10-12 21:28:27 +00:00
return 0;
str = WMGetFromPLString(val);
1998-09-29 22:36:29 +00:00
if (!str)
2004-10-12 21:28:27 +00:00
return 0;
1998-09-29 22:36:29 +00:00
if (sscanf(str, "%i", &value)!=1)
2004-10-12 21:28:27 +00:00
return 0;
1998-09-29 22:36:29 +00:00
return value;
}
Bool
GetBoolForKey(char *defaultName)
{
int value;
char *str;
str = GetStringForKey(defaultName);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (!str)
2004-10-12 21:28:27 +00:00
return False;
1998-09-29 22:36:29 +00:00
if (sscanf(str, "%i", &value)==1 && value!=0)
2004-10-12 21:28:27 +00:00
return True;
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "YES")==0)
2004-10-12 21:28:27 +00:00
return True;
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "Y")==0)
2004-10-12 21:28:27 +00:00
return True;
1998-09-29 22:36:29 +00:00
return False;
}
void
SetIntegerForKey(int value, char *defaultName)
{
WMPropList *object;
1998-09-29 22:36:29 +00:00
char buffer[128];
sprintf(buffer, "%i", value);
object = WMCreatePLString(buffer);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
SetObjectForKey(object, defaultName);
WMReleasePropList(object);
1998-09-29 22:36:29 +00:00
}
void
SetStringForKey(char *value, char *defaultName)
{
WMPropList *object;
1998-09-29 22:36:29 +00:00
object = WMCreatePLString(value);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
SetObjectForKey(object, defaultName);
WMReleasePropList(object);
1998-09-29 22:36:29 +00:00
}
void
SetBoolForKey(Bool value, char *defaultName)
{
static WMPropList *yes = NULL, *no = NULL;
1998-09-29 22:36:29 +00:00
if (!yes) {
2004-10-12 21:28:27 +00:00
yes = WMCreatePLString("YES");
no = WMCreatePLString("NO");
1998-09-29 22:36:29 +00:00
}
SetObjectForKey(value ? yes : no, defaultName);
}
void
SetSpeedForKey(int speed, char *defaultName)
{
char *str;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
switch (speed) {
2004-10-12 21:28:27 +00:00
case 0:
str = "ultraslow";
break;
case 1:
str = "slow";
break;
case 2:
str = "medium";
break;
case 3:
str = "fast";
break;
case 4:
str = "ultrafast";
break;
default:
str = NULL;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (str)
2004-10-12 21:28:27 +00:00
SetStringForKey(str, defaultName);
1998-09-29 22:36:29 +00:00
}
int
GetSpeedForKey(char *defaultName)
{
char *str;
int i;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
str = GetStringForKey(defaultName);
if (!str)
2004-10-12 21:28:27 +00:00
return 2;
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "ultraslow")==0)
2004-10-12 21:28:27 +00:00
i = 0;
1998-09-29 22:36:29 +00:00
else if (strcasecmp(str, "slow")==0)
2004-10-12 21:28:27 +00:00
i = 1;
1998-09-29 22:36:29 +00:00
else if (strcasecmp(str, "medium")==0)
2004-10-12 21:28:27 +00:00
i = 2;
1998-09-29 22:36:29 +00:00
else if (strcasecmp(str, "fast")==0)
2004-10-12 21:28:27 +00:00
i = 3;
1998-09-29 22:36:29 +00:00
else if (strcasecmp(str, "ultrafast")==0)
2004-10-12 21:28:27 +00:00
i = 4;
1998-09-29 22:36:29 +00:00
else {
2004-10-12 21:28:27 +00:00
wwarning(_("bad speed value for option %s\n. Using default Medium"),
defaultName);
i = 2;
1998-09-29 22:36:29 +00:00
}
return i;
}