Initial revision
[wmaker-crm.git] / WPrefs.app / Configurations.c
blobf9556cf24ab11747dc54d0f6d8a066deb088c8e9
1 /* Configurations.c- misc. configurations
2 *
3 * WPrefs - WindowMaker Preferences Program
4 *
5 * Copyright (c) 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.
24 #include "WPrefs.h"
26 typedef struct _Panel {
27 WMFrame *frame;
28 char *sectionName;
30 CallbackRec callbacks;
32 WMWindow *win;
34 WMFrame *icoF;
35 WMButton *icoB[5];
37 WMFrame *shaF;
38 WMButton *shaB[5];
40 WMFrame *titlF;
41 WMButton *oldsB;
42 WMButton *newsB;
44 WMFrame *animF;
45 WMButton *animB;
46 WMButton *supB;
47 WMButton *sfxB;
48 WMLabel *noteL;
50 WMFrame *dithF;
51 WMButton *dithB;
52 WMSlider *dithS;
53 WMLabel *dithL;
54 WMLabel *dith1L;
55 WMLabel *dith2L;
57 int cmapSize;
58 } _Panel;
62 #define ICON_FILE "configs"
64 #define OLDS_IMAGE "oldstyle"
65 #define NEWS_IMAGE "newstyle"
67 #define ANIM_IMAGE "animations"
68 #define SUPERF_IMAGE "moreanim"
69 #define SOUND_IMAGE "sound"
71 #define SPEED_IMAGE "speed%i"
72 #define SPEED_IMAGE_S "speed%is"
74 #define ARQUIVO_XIS "xis"
77 static void updateLabel(WMWidget *self, void *data);
80 static void
81 showData(_Panel *panel)
83 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
85 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
87 if (GetBoolForKey("NewStyle")) {
88 WMPerformButtonClick(panel->newsB);
89 } else {
90 WMPerformButtonClick(panel->oldsB);
93 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
95 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
97 WMSetButtonSelected(panel->sfxB, !GetBoolForKey("DisableSound"));
99 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
101 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
103 updateLabel(panel->dithS, panel);
107 static void
108 updateLabel(WMWidget *self, void *data)
110 WMSlider *sPtr = (WMSlider*)self;
111 _Panel *panel = (_Panel*)data;
112 char buffer[64];
113 float fl;
115 fl = WMGetSliderValue(sPtr);
117 panel->cmapSize = (int)fl;
119 sprintf(buffer, "%i", panel->cmapSize*panel->cmapSize*panel->cmapSize);
120 WMSetLabelText(panel->dithL, buffer);
124 static void
125 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
126 WMPixmap **icon1, WMPixmap **icon2)
128 RImage *icon;
129 char *path;
131 *icon1 = NULL;
132 *icon2 = NULL;
134 path = LocateImage(file);
135 if (!path) {
136 return;
139 *icon1 = WMCreatePixmapFromFile(scr, path);
140 if (!*icon1) {
141 wwarning(_("could not load icon %s"), path);
142 free(path);
143 return;
145 icon = RLoadImage(rc, path, 0);
146 if (!icon) {
147 wwarning(_("could not load icon %s"), path);
148 free(path);
149 return;
151 if (xis) {
152 RCombineImages(icon, xis);
153 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
154 wwarning(_("could not process icon %s:"), file, RErrorString);
156 RDestroyImage(icon);
157 free(path);
162 static void
163 createPanel(Panel *p)
165 _Panel *panel = (_Panel*)p;
166 WMScreen *scr = WMWidgetScreen(panel->win);
167 char *buf1, *buf2;
168 WMPixmap *icon, *altIcon;
169 RImage *xis = NULL;
170 int i;
171 RContext *rc = WMScreenRContext(scr);
172 WMFont *font = WMSystemFontOfSize(scr, 10);
173 char *path;
175 path = LocateImage(ARQUIVO_XIS);
176 if (path) {
177 xis = RLoadImage(rc, path, 0);
178 if (!xis) {
179 wwarning(_("could not load image file %s"), path);
181 free(path);
184 panel->frame = WMCreateFrame(panel->win);
185 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
186 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
188 /*********** Icon Slide Speed **********/
190 panel->icoF = WMCreateFrame(panel->frame);
191 WMResizeWidget(panel->icoF, 230, 55);
192 WMMoveWidget(panel->icoF, 15, 10);
193 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
195 /*********** Shade Animation Speed **********/
196 panel->shaF = WMCreateFrame(panel->frame);
197 WMResizeWidget(panel->shaF, 230, 55);
198 WMMoveWidget(panel->shaF, 15, 70);
199 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
202 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
203 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
205 for (i = 0; i < 5; i++) {
206 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
207 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
208 WMResizeWidget(panel->icoB[i], 40, 35);
209 WMMoveWidget(panel->icoB[i], 10+(40*i), 15);
210 WMResizeWidget(panel->shaB[i], 40, 35);
211 WMMoveWidget(panel->shaB[i], 10+(40*i), 15);
212 WMSetButtonBordered(panel->icoB[i], False);
213 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
214 if (i > 0) {
215 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
217 WMSetButtonBordered(panel->shaB[i], False);
218 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
219 if (i > 0) {
220 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
222 sprintf(buf1, SPEED_IMAGE, i);
223 sprintf(buf2, SPEED_IMAGE_S, i);
224 path = LocateImage(buf1);
225 if (path) {
226 icon = WMCreatePixmapFromFile(scr, path);
227 if (icon) {
228 WMSetButtonImage(panel->icoB[i], icon);
229 WMSetButtonImage(panel->shaB[i], icon);
230 WMReleasePixmap(icon);
231 } else {
232 wwarning(_("could not load icon file %s"), path);
234 free(path);
236 path = LocateImage(buf2);
237 if (path) {
238 icon = WMCreatePixmapFromFile(scr, path);
239 if (icon) {
240 WMSetButtonAltImage(panel->icoB[i], icon);
241 WMSetButtonAltImage(panel->shaB[i], icon);
242 WMReleasePixmap(icon);
243 } else {
244 wwarning(_("could not load icon file %s"), path);
246 free(path);
249 free(buf1);
250 free(buf2);
253 WMMapSubwidgets(panel->icoF);
254 WMMapSubwidgets(panel->shaF);
256 /***************** Titlebar Style Size ****************/
257 panel->titlF = WMCreateFrame(panel->frame);
258 WMResizeWidget(panel->titlF, 230, 95);
259 WMMoveWidget(panel->titlF, 15, 130);
260 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
262 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
263 WMResizeWidget(panel->newsB, 90, 60);
264 WMMoveWidget(panel->newsB, 25, 20);
265 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
266 path = LocateImage(NEWS_IMAGE);
267 if (path) {
268 icon = WMCreatePixmapFromFile(scr, path);
269 if (icon) {
270 WMSetButtonImage(panel->newsB, icon);
271 WMReleasePixmap(icon);
275 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
276 WMResizeWidget(panel->oldsB, 90, 60);
277 WMMoveWidget(panel->oldsB, 115, 20);
278 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
279 path = LocateImage(OLDS_IMAGE);
280 if (path) {
281 icon = WMCreatePixmapFromFile(scr, path);
282 if (icon) {
283 WMSetButtonImage(panel->oldsB, icon);
284 WMReleasePixmap(icon);
288 WMGroupButtons(panel->newsB, panel->oldsB);
290 WMMapSubwidgets(panel->titlF);
292 /**************** Features ******************/
294 panel->animF = WMCreateFrame(panel->frame);
295 WMResizeWidget(panel->animF, 255, 115);
296 WMMoveWidget(panel->animF, 255, 10);
297 WMSetFrameTitle(panel->animF, _("Animations and Sound"));
299 panel->animB = WMCreateButton(panel->animF, WBTToggle);
300 WMResizeWidget(panel->animB, 64, 64);
301 WMMoveWidget(panel->animB, 15, 20);
302 WMSetButtonFont(panel->animB, font);
303 WMSetButtonText(panel->animB, _("Animations"));
304 WMSetButtonImagePosition(panel->animB, WIPAbove);
305 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
306 if (icon) {
307 WMSetButtonImage(panel->animB, icon);
308 WMReleasePixmap(icon);
310 if (altIcon) {
311 WMSetButtonAltImage(panel->animB, altIcon);
312 WMReleasePixmap(altIcon);
315 panel->supB = WMCreateButton(panel->animF, WBTToggle);
316 WMResizeWidget(panel->supB, 64, 64);
317 WMMoveWidget(panel->supB, 95, 20);
318 WMSetButtonFont(panel->supB, font);
319 WMSetButtonText(panel->supB, _("Superfluous"));
320 WMSetButtonImagePosition(panel->supB, WIPAbove);
321 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
322 if (icon) {
323 WMSetButtonImage(panel->supB, icon);
324 WMReleasePixmap(icon);
326 if (altIcon) {
327 WMSetButtonAltImage(panel->supB, altIcon);
328 WMReleasePixmap(altIcon);
331 panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
332 WMResizeWidget(panel->sfxB, 64, 64);
333 WMMoveWidget(panel->sfxB, 175, 20);
334 WMSetButtonFont(panel->sfxB, font);
335 WMSetButtonText(panel->sfxB, _("Sounds"));
336 WMSetButtonImagePosition(panel->sfxB, WIPAbove);
337 createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
338 if (icon) {
339 WMSetButtonImage(panel->sfxB, icon);
340 WMReleasePixmap(icon);
342 if (altIcon) {
343 WMSetButtonAltImage(panel->sfxB, altIcon);
344 WMReleasePixmap(altIcon);
348 panel->noteL = WMCreateLabel(panel->animF);
349 WMResizeWidget(panel->noteL, 235, 28);
350 WMMoveWidget(panel->noteL, 10, 85);
351 WMSetLabelFont(panel->noteL, font);
352 WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed separately"));
354 WMMapSubwidgets(panel->animF);
356 /*********** Dithering **********/
357 panel->cmapSize = 4;
359 panel->dithF = WMCreateFrame(panel->frame);
360 WMResizeWidget(panel->dithF, 255, 95);
361 WMMoveWidget(panel->dithF, 255, 130);
362 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
364 panel->dithB = WMCreateSwitchButton(panel->dithF);
365 WMResizeWidget(panel->dithB, 235, 32);
366 WMMoveWidget(panel->dithB, 15, 15);
367 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
369 panel->dithL = WMCreateLabel(panel->dithF);
370 WMResizeWidget(panel->dithL, 75, 16);
371 WMMoveWidget(panel->dithL, 90, 50);
372 WMSetLabelTextAlignment(panel->dithL, WACenter);
373 WMSetLabelText(panel->dithL, "64");
375 panel->dithS = WMCreateSlider(panel->dithF);
376 WMResizeWidget(panel->dithS, 95, 16);
377 WMMoveWidget(panel->dithS, 80, 65);
378 WMSetSliderMinValue(panel->dithS, 2);
379 WMSetSliderMaxValue(panel->dithS, 6);
380 WMSetSliderContinuous(panel->dithS, True);
381 WMSetSliderAction(panel->dithS, updateLabel, panel);
383 panel->dith1L = WMCreateLabel(panel->dithF);
384 WMResizeWidget(panel->dith1L, 70, 35);
385 WMMoveWidget(panel->dith1L, 5, 50);
386 WMSetLabelTextAlignment(panel->dith1L, WACenter);
387 WMSetLabelFont(panel->dith1L, font);
388 WMSetLabelText(panel->dith1L, _("More colors for applications"));
390 panel->dith2L = WMCreateLabel(panel->dithF);
391 WMResizeWidget(panel->dith2L, 70, 35);
392 WMMoveWidget(panel->dith2L, 180, 50);
393 WMSetLabelTextAlignment(panel->dith2L, WACenter);
394 WMSetLabelFont(panel->dith2L, font);
395 WMSetLabelText(panel->dith2L, _("More colors for WindowMaker"));
397 WMMapSubwidgets(panel->dithF);
399 WMRealizeWidget(panel->frame);
400 WMMapSubwidgets(panel->frame);
402 if (xis)
403 RDestroyImage(xis);
404 WMReleaseFont(font);
406 showData(panel);
410 static void
411 storeData(_Panel *panel)
413 int i;
415 for (i=0; i<5; i++) {
416 if (WMGetButtonSelected(panel->icoB[i]))
417 break;
419 SetSpeedForKey(i, "IconSlideSpeed");
422 for (i=0; i<5; i++) {
423 if (WMGetButtonSelected(panel->shaB[i]))
424 break;
426 SetSpeedForKey(i, "ShadeSpeed");
428 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
430 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
431 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
432 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
434 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
435 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
440 Panel*
441 InitConfigurations(WMScreen *scr, WMWindow *win)
443 _Panel *panel;
445 panel = wmalloc(sizeof(_Panel));
446 memset(panel, 0, sizeof(_Panel));
448 panel->sectionName = _("Other Configurations");
450 panel->win = win;
452 panel->callbacks.createWidgets = createPanel;
453 panel->callbacks.updateDomain = storeData;
455 AddSection(panel, ICON_FILE);
457 return panel;