changed indentation to use spaces only
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob8f3ad3426517e483c599df47a373608deab17c68
1 /* Configurations.c- misc. configurations
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 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,
20 * USA.
24 #include "WPrefs.h"
26 typedef struct _Panel {
27 WMBox *box;
28 char *sectionName;
30 char *description;
32 CallbackRec callbacks;
34 WMWidget *parent;
36 WMFrame *icoF;
37 WMButton *icoB[5];
39 WMFrame *shaF;
40 WMButton *shaB[5];
42 WMFrame *titlF;
43 WMButton *oldsB;
44 WMButton *newsB;
46 WMFrame *animF;
47 WMButton *animB;
48 WMButton *supB;
49 WMButton *sfxB;
50 WMLabel *noteL;
52 WMFrame *smoF;
53 WMButton *smoB;
55 WMFrame *dithF;
56 WMButton *dithB;
57 WMSlider *dithS;
58 WMLabel *dithL;
59 WMLabel *dith1L;
60 WMLabel *dith2L;
62 int cmapSize;
63 } _Panel;
67 #define ICON_FILE "configs"
69 #define OLDS_IMAGE "oldstyle"
70 #define NEWS_IMAGE "newstyle"
72 #define ANIM_IMAGE "animations"
73 #define SUPERF_IMAGE "moreanim"
74 #define SOUND_IMAGE "sound"
75 #define SMOOTH_IMAGE "smooth"
77 #define SPEED_IMAGE "speed%i"
78 #define SPEED_IMAGE_S "speed%is"
80 #define ARQUIVO_XIS "xis"
83 static void updateLabel(WMWidget *self, void *data);
86 static void
87 showData(_Panel *panel)
89 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
91 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
93 if (GetBoolForKey("NewStyle")) {
94 WMPerformButtonClick(panel->newsB);
95 } else {
96 WMPerformButtonClick(panel->oldsB);
99 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
101 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
103 WMSetButtonSelected(panel->sfxB, !GetBoolForKey("DisableSound"));
105 WMSetButtonSelected(panel->smoB, GetBoolForKey("SmoothWorkspaceBack"));
107 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
109 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
111 updateLabel(panel->dithS, panel);
115 static void
116 updateLabel(WMWidget *self, void *data)
118 WMSlider *sPtr = (WMSlider*)self;
119 _Panel *panel = (_Panel*)data;
120 char buffer[64];
121 float fl;
123 fl = WMGetSliderValue(sPtr);
125 panel->cmapSize = (int)fl;
127 sprintf(buffer, "%i", panel->cmapSize*panel->cmapSize*panel->cmapSize);
128 WMSetLabelText(panel->dithL, buffer);
132 static void
133 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
134 WMPixmap **icon1, WMPixmap **icon2)
136 RImage *icon;
137 char *path;
138 RColor gray = {0xae,0xaa,0xae};
140 *icon1 = NULL;
141 *icon2 = NULL;
143 path = LocateImage(file);
144 if (!path) {
145 return;
148 *icon1 = WMCreatePixmapFromFile(scr, path);
149 if (!*icon1) {
150 wwarning(_("could not load icon %s"), path);
151 wfree(path);
152 return;
154 icon = RLoadImage(rc, path, 0);
155 if (!icon) {
156 wwarning(_("could not load icon %s"), path);
157 wfree(path);
158 return;
160 RCombineImageWithColor(icon, &gray);
161 if (xis) {
162 RCombineImagesWithOpaqueness(icon, xis, 180);
163 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
164 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
166 RReleaseImage(icon);
167 wfree(path);
171 static void
172 createPanel(Panel *p)
174 _Panel *panel = (_Panel*)p;
175 WMScreen *scr = WMWidgetScreen(panel->parent);
176 char *buf1, *buf2;
177 WMPixmap *icon, *altIcon;
178 RImage *xis = NULL;
179 int i;
180 RContext *rc = WMScreenRContext(scr);
181 WMFont *font = WMSystemFontOfSize(scr, 10);
182 char *path;
184 path = LocateImage(ARQUIVO_XIS);
185 if (path) {
186 xis = RLoadImage(rc, path, 0);
187 if (!xis) {
188 wwarning(_("could not load image file %s"), path);
190 wfree(path);
194 panel->box = WMCreateBox(panel->parent);
195 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
197 /*********** Icon Slide Speed **********/
199 panel->icoF = WMCreateFrame(panel->box);
200 WMResizeWidget(panel->icoF, 230, 45);
201 WMMoveWidget(panel->icoF, 15, 10);
202 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
204 /*********** Shade Animation Speed **********/
205 panel->shaF = WMCreateFrame(panel->box);
206 WMResizeWidget(panel->shaF, 230, 45);
207 WMMoveWidget(panel->shaF, 15, 60);
208 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
211 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
212 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
214 for (i = 0; i < 5; i++) {
215 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
216 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
217 WMResizeWidget(panel->icoB[i], 40, 24);
218 WMMoveWidget(panel->icoB[i], 10+(40*i), 15);
219 WMResizeWidget(panel->shaB[i], 40, 24);
220 WMMoveWidget(panel->shaB[i], 10+(40*i), 15);
221 WMSetButtonBordered(panel->icoB[i], False);
222 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
223 if (i > 0) {
224 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
226 WMSetButtonBordered(panel->shaB[i], False);
227 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
228 if (i > 0) {
229 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
231 sprintf(buf1, SPEED_IMAGE, i);
232 sprintf(buf2, SPEED_IMAGE_S, i);
233 path = LocateImage(buf1);
234 if (path) {
235 icon = WMCreatePixmapFromFile(scr, path);
236 if (icon) {
237 WMSetButtonImage(panel->icoB[i], icon);
238 WMSetButtonImage(panel->shaB[i], icon);
239 WMReleasePixmap(icon);
240 } else {
241 wwarning(_("could not load icon file %s"), path);
243 wfree(path);
245 path = LocateImage(buf2);
246 if (path) {
247 icon = WMCreatePixmapFromFile(scr, path);
248 if (icon) {
249 WMSetButtonAltImage(panel->icoB[i], icon);
250 WMSetButtonAltImage(panel->shaB[i], icon);
251 WMReleasePixmap(icon);
252 } else {
253 wwarning(_("could not load icon file %s"), path);
255 wfree(path);
258 wfree(buf1);
259 wfree(buf2);
262 WMMapSubwidgets(panel->icoF);
263 WMMapSubwidgets(panel->shaF);
266 /***************** Smoothed Scaling *****************/
267 panel->smoF = WMCreateFrame(panel->box);
268 WMResizeWidget(panel->smoF, 115, 110);
269 WMMoveWidget(panel->smoF, 18, 115);
270 WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
271 WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
272 "the `pixelization' effect. This will slow\n"
273 "down loading of background images considerably."),
274 WMWidgetView(panel->smoF));
276 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
277 WMResizeWidget(panel->smoB, 64, 64);
278 WMMoveWidget(panel->smoB, 25, 25);
279 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
280 path = LocateImage(SMOOTH_IMAGE);
281 if (path) {
282 RImage *image, *scaled;
284 image = RLoadImage(WMScreenRContext(scr), path, 0);
285 wfree(path);
287 scaled = RScaleImage(image, 61, 61);
288 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
289 RReleaseImage(scaled);
290 if (icon) {
291 WMSetButtonImage(panel->smoB, icon);
292 WMReleasePixmap(icon);
295 scaled = RSmoothScaleImage(image, 61, 61);
296 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
297 RReleaseImage(scaled);
298 if (icon) {
299 WMSetButtonAltImage(panel->smoB, icon);
300 WMReleasePixmap(icon);
303 RReleaseImage(image);
306 WMMapSubwidgets(panel->smoF);
308 /***************** Titlebar Style Size ****************/
309 panel->titlF = WMCreateFrame(panel->box);
310 WMResizeWidget(panel->titlF, 105, 110);
311 WMMoveWidget(panel->titlF, 140, 115);
312 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
314 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
315 WMResizeWidget(panel->newsB, 74, 40);
316 WMMoveWidget(panel->newsB, 15, 20);
317 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
318 path = LocateImage(NEWS_IMAGE);
319 if (path) {
320 icon = WMCreatePixmapFromFile(scr, path);
321 if (icon) {
322 WMSetButtonImage(panel->newsB, icon);
323 WMReleasePixmap(icon);
327 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
328 WMResizeWidget(panel->oldsB, 74, 40);
329 WMMoveWidget(panel->oldsB, 15, 60);
330 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
331 path = LocateImage(OLDS_IMAGE);
332 if (path) {
333 icon = WMCreatePixmapFromFile(scr, path);
334 if (icon) {
335 WMSetButtonImage(panel->oldsB, icon);
336 WMReleasePixmap(icon);
338 wfree(path);
341 WMGroupButtons(panel->newsB, panel->oldsB);
343 WMMapSubwidgets(panel->titlF);
345 /**************** Features ******************/
347 panel->animF = WMCreateFrame(panel->box);
348 WMResizeWidget(panel->animF, 255, 115);
349 WMMoveWidget(panel->animF, 255, 10);
350 WMSetFrameTitle(panel->animF, _("Animations and Sound"));
352 panel->animB = WMCreateButton(panel->animF, WBTToggle);
353 WMResizeWidget(panel->animB, 64, 64);
354 WMMoveWidget(panel->animB, 15, 20);
355 WMSetButtonFont(panel->animB, font);
356 WMSetButtonText(panel->animB, _("Animations"));
357 WMSetButtonImagePosition(panel->animB, WIPAbove);
358 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
359 if (icon) {
360 WMSetButtonImage(panel->animB, icon);
361 WMReleasePixmap(icon);
363 if (altIcon) {
364 WMSetButtonAltImage(panel->animB, altIcon);
365 WMReleasePixmap(altIcon);
367 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
368 "for window miniaturization, shading etc."),
369 WMWidgetView(panel->animB));
371 panel->supB = WMCreateButton(panel->animF, WBTToggle);
372 WMResizeWidget(panel->supB, 64, 64);
373 WMMoveWidget(panel->supB, 95, 20);
374 WMSetButtonFont(panel->supB, font);
375 WMSetButtonText(panel->supB, _("Superfluous"));
376 WMSetButtonImagePosition(panel->supB, WIPAbove);
377 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
378 if (icon) {
379 WMSetButtonImage(panel->supB, icon);
380 WMReleasePixmap(icon);
382 if (altIcon) {
383 WMSetButtonAltImage(panel->supB, altIcon);
384 WMReleasePixmap(altIcon);
386 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
387 "animations. These include the `ghosting' of the\n"
388 "dock when it's being moved to another side and\n"
389 "the explosion animation when undocking icons."),
390 WMWidgetView(panel->supB));
392 panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
393 WMResizeWidget(panel->sfxB, 64, 64);
394 WMMoveWidget(panel->sfxB, 175, 20);
395 WMSetButtonFont(panel->sfxB, font);
396 WMSetButtonText(panel->sfxB, _("Sounds"));
397 WMSetButtonImagePosition(panel->sfxB, WIPAbove);
398 createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
399 if (icon) {
400 WMSetButtonImage(panel->sfxB, icon);
401 WMReleasePixmap(icon);
403 if (altIcon) {
404 WMSetButtonAltImage(panel->sfxB, altIcon);
405 WMReleasePixmap(altIcon);
407 WMSetBalloonTextForView(_("Disable/enable support for sound effects played\n"
408 "for actions like shading and closing a window.\n"
409 "You will need a module distributed separately\n"
410 "for this. You can get it at:\n"
411 "http://shadowmere.student.utwente.nl/"),
412 WMWidgetView(panel->sfxB));
414 panel->noteL = WMCreateLabel(panel->animF);
415 WMResizeWidget(panel->noteL, 235, 28);
416 WMMoveWidget(panel->noteL, 10, 85);
417 WMSetLabelFont(panel->noteL, font);
418 WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed\nseparately"));
420 WMMapSubwidgets(panel->animF);
422 /*********** Dithering **********/
423 panel->cmapSize = 4;
425 panel->dithF = WMCreateFrame(panel->box);
426 WMResizeWidget(panel->dithF, 255, 95);
427 WMMoveWidget(panel->dithF, 255, 130);
428 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
430 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
431 "on displays that support only 8bpp (PseudoColor)."),
432 WMWidgetView(panel->dithF));
434 panel->dithB = WMCreateSwitchButton(panel->dithF);
435 WMResizeWidget(panel->dithB, 235, 32);
436 WMMoveWidget(panel->dithB, 15, 15);
437 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
439 panel->dithL = WMCreateLabel(panel->dithF);
440 WMResizeWidget(panel->dithL, 75, 16);
441 WMMoveWidget(panel->dithL, 90, 50);
442 WMSetLabelTextAlignment(panel->dithL, WACenter);
443 WMSetLabelText(panel->dithL, "64");
445 panel->dithS = WMCreateSlider(panel->dithF);
446 WMResizeWidget(panel->dithS, 95, 16);
447 WMMoveWidget(panel->dithS, 80, 65);
448 WMSetSliderMinValue(panel->dithS, 2);
449 WMSetSliderMaxValue(panel->dithS, 6);
450 WMSetSliderContinuous(panel->dithS, True);
451 WMSetSliderAction(panel->dithS, updateLabel, panel);
453 panel->dith1L = WMCreateLabel(panel->dithF);
454 WMResizeWidget(panel->dith1L, 70, 35);
455 WMMoveWidget(panel->dith1L, 5, 50);
456 WMSetLabelTextAlignment(panel->dith1L, WACenter);
457 WMSetLabelFont(panel->dith1L, font);
458 WMSetLabelText(panel->dith1L, _("More colors for\napplications"));
460 panel->dith2L = WMCreateLabel(panel->dithF);
461 WMResizeWidget(panel->dith2L, 70, 35);
462 WMMoveWidget(panel->dith2L, 180, 50);
463 WMSetLabelTextAlignment(panel->dith2L, WACenter);
464 WMSetLabelFont(panel->dith2L, font);
465 WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));
467 WMMapSubwidgets(panel->dithF);
469 WMRealizeWidget(panel->box);
470 WMMapSubwidgets(panel->box);
472 if (xis)
473 RReleaseImage(xis);
474 WMReleaseFont(font);
476 showData(panel);
480 static void
481 storeData(_Panel *panel)
483 int i;
485 for (i=0; i<5; i++) {
486 if (WMGetButtonSelected(panel->icoB[i]))
487 break;
489 SetSpeedForKey(i, "IconSlideSpeed");
492 for (i=0; i<5; i++) {
493 if (WMGetButtonSelected(panel->shaB[i]))
494 break;
496 SetSpeedForKey(i, "ShadeSpeed");
498 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
500 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
501 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
502 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
504 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
506 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
507 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
512 Panel*
513 InitConfigurations(WMScreen *scr, WMWidget *parent)
515 _Panel *panel;
517 panel = wmalloc(sizeof(_Panel));
518 memset(panel, 0, sizeof(_Panel));
520 panel->sectionName = _("Other Configurations");
522 panel->description = _("Animation speeds, titlebar styles, various option\n"
523 "toggling and number of colors to reserve for\n"
524 "Window Maker on 8bit displays.");
526 panel->parent = parent;
528 panel->callbacks.createWidgets = createPanel;
529 panel->callbacks.updateDomain = storeData;
531 AddSection(panel, ICON_FILE);
533 return panel;