Left Half / Right Half Maximize
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob472ffe77ebaab60128ba8e83262fdd89be192ae9
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.
23 #include "WPrefs.h"
25 typedef struct _Panel {
26 WMBox *box;
27 char *sectionName;
29 char *description;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMFrame *icoF;
36 WMButton *icoB[5];
38 WMFrame *shaF;
39 WMButton *shaB[5];
41 WMFrame *titlF;
42 WMButton *oldsB;
43 WMButton *newsB;
45 WMFrame *animF;
46 WMButton *animB;
47 WMButton *supB;
48 WMButton *sfxB;
49 WMLabel *noteL;
51 WMFrame *smoF;
52 WMButton *smoB;
54 WMFrame *dithF;
55 WMButton *dithB;
56 WMSlider *dithS;
57 WMLabel *dithL;
58 WMLabel *dith1L;
59 WMLabel *dith2L;
61 int cmapSize;
62 } _Panel;
64 #define ICON_FILE "configs"
66 #define OLDS_IMAGE "oldstyle"
67 #define NEWS_IMAGE "newstyle"
69 #define ANIM_IMAGE "animations"
70 #define SUPERF_IMAGE "moreanim"
71 #define SOUND_IMAGE "sound"
72 #define SMOOTH_IMAGE "smooth"
74 #define SPEED_IMAGE "speed%i"
75 #define SPEED_IMAGE_S "speed%is"
77 #define ARQUIVO_XIS "xis"
79 static void updateLabel(WMWidget * self, void *data);
81 static void 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->smoB, GetBoolForKey("SmoothWorkspaceBack"));
101 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
103 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
105 updateLabel(panel->dithS, panel);
108 static void 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);
123 static void
124 createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2)
126 RImage *icon;
127 char *path;
128 RColor gray = { 0xae, 0xaa, 0xae };
130 *icon1 = NULL;
131 *icon2 = NULL;
133 path = LocateImage(file);
134 if (!path) {
135 return;
138 *icon1 = WMCreatePixmapFromFile(scr, path);
139 if (!*icon1) {
140 wwarning(_("could not load icon %s"), path);
141 wfree(path);
142 return;
144 icon = RLoadImage(rc, path, 0);
145 if (!icon) {
146 wwarning(_("could not load icon %s"), path);
147 wfree(path);
148 return;
150 RCombineImageWithColor(icon, &gray);
151 if (xis) {
152 RCombineImagesWithOpaqueness(icon, xis, 180);
153 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
154 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
156 RReleaseImage(icon);
157 wfree(path);
160 static void createPanel(Panel * p)
162 _Panel *panel = (_Panel *) p;
163 WMScreen *scr = WMWidgetScreen(panel->parent);
164 char *buf1, *buf2;
165 WMPixmap *icon, *altIcon;
166 RImage *xis = NULL;
167 int i;
168 RContext *rc = WMScreenRContext(scr);
169 WMFont *font = WMSystemFontOfSize(scr, 10);
170 char *path;
172 path = LocateImage(ARQUIVO_XIS);
173 if (path) {
174 xis = RLoadImage(rc, path, 0);
175 if (!xis) {
176 wwarning(_("could not load image file %s"), path);
178 wfree(path);
181 panel->box = WMCreateBox(panel->parent);
182 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
184 /*********** Icon Slide Speed **********/
186 panel->icoF = WMCreateFrame(panel->box);
187 WMResizeWidget(panel->icoF, 230, 45);
188 WMMoveWidget(panel->icoF, 15, 10);
189 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
191 /*********** Shade Animation Speed **********/
192 panel->shaF = WMCreateFrame(panel->box);
193 WMResizeWidget(panel->shaF, 230, 45);
194 WMMoveWidget(panel->shaF, 15, 60);
195 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
197 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
198 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
200 for (i = 0; i < 5; i++) {
201 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
202 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
203 WMResizeWidget(panel->icoB[i], 40, 24);
204 WMMoveWidget(panel->icoB[i], 10 + (40 * i), 15);
205 WMResizeWidget(panel->shaB[i], 40, 24);
206 WMMoveWidget(panel->shaB[i], 10 + (40 * i), 15);
207 WMSetButtonBordered(panel->icoB[i], False);
208 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
209 if (i > 0) {
210 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
212 WMSetButtonBordered(panel->shaB[i], False);
213 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
214 if (i > 0) {
215 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
217 sprintf(buf1, SPEED_IMAGE, i);
218 sprintf(buf2, SPEED_IMAGE_S, i);
219 path = LocateImage(buf1);
220 if (path) {
221 icon = WMCreatePixmapFromFile(scr, path);
222 if (icon) {
223 WMSetButtonImage(panel->icoB[i], icon);
224 WMSetButtonImage(panel->shaB[i], icon);
225 WMReleasePixmap(icon);
226 } else {
227 wwarning(_("could not load icon file %s"), path);
229 wfree(path);
231 path = LocateImage(buf2);
232 if (path) {
233 icon = WMCreatePixmapFromFile(scr, path);
234 if (icon) {
235 WMSetButtonAltImage(panel->icoB[i], icon);
236 WMSetButtonAltImage(panel->shaB[i], icon);
237 WMReleasePixmap(icon);
238 } else {
239 wwarning(_("could not load icon file %s"), path);
241 wfree(path);
244 wfree(buf1);
245 wfree(buf2);
247 WMMapSubwidgets(panel->icoF);
248 WMMapSubwidgets(panel->shaF);
250 /***************** Smoothed Scaling *****************/
251 panel->smoF = WMCreateFrame(panel->box);
252 WMResizeWidget(panel->smoF, 115, 110);
253 WMMoveWidget(panel->smoF, 18, 115);
254 WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
255 WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
256 "the `pixelization' effect. This will slow\n"
257 "down loading of background images considerably."), WMWidgetView(panel->smoF));
259 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
260 WMResizeWidget(panel->smoB, 64, 64);
261 WMMoveWidget(panel->smoB, 25, 25);
262 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
263 path = LocateImage(SMOOTH_IMAGE);
264 if (path) {
265 RImage *image, *scaled;
267 image = RLoadImage(WMScreenRContext(scr), path, 0);
268 wfree(path);
270 scaled = RScaleImage(image, 61, 61);
271 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
272 RReleaseImage(scaled);
273 if (icon) {
274 WMSetButtonImage(panel->smoB, icon);
275 WMReleasePixmap(icon);
278 scaled = RSmoothScaleImage(image, 61, 61);
279 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
280 RReleaseImage(scaled);
281 if (icon) {
282 WMSetButtonAltImage(panel->smoB, icon);
283 WMReleasePixmap(icon);
286 RReleaseImage(image);
289 WMMapSubwidgets(panel->smoF);
291 /***************** Titlebar Style Size ****************/
292 panel->titlF = WMCreateFrame(panel->box);
293 WMResizeWidget(panel->titlF, 105, 110);
294 WMMoveWidget(panel->titlF, 140, 115);
295 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
297 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
298 WMResizeWidget(panel->newsB, 74, 40);
299 WMMoveWidget(panel->newsB, 15, 20);
300 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
301 path = LocateImage(NEWS_IMAGE);
302 if (path) {
303 icon = WMCreatePixmapFromFile(scr, path);
304 if (icon) {
305 WMSetButtonImage(panel->newsB, icon);
306 WMReleasePixmap(icon);
310 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
311 WMResizeWidget(panel->oldsB, 74, 40);
312 WMMoveWidget(panel->oldsB, 15, 60);
313 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
314 path = LocateImage(OLDS_IMAGE);
315 if (path) {
316 icon = WMCreatePixmapFromFile(scr, path);
317 if (icon) {
318 WMSetButtonImage(panel->oldsB, icon);
319 WMReleasePixmap(icon);
321 wfree(path);
324 WMGroupButtons(panel->newsB, panel->oldsB);
326 WMMapSubwidgets(panel->titlF);
328 /**************** Features ******************/
330 panel->animF = WMCreateFrame(panel->box);
331 WMResizeWidget(panel->animF, 255, 115);
332 WMMoveWidget(panel->animF, 255, 10);
333 WMSetFrameTitle(panel->animF, _("Animations and Sound"));
335 panel->animB = WMCreateButton(panel->animF, WBTToggle);
336 WMResizeWidget(panel->animB, 64, 64);
337 WMMoveWidget(panel->animB, 15, 20);
338 WMSetButtonFont(panel->animB, font);
339 WMSetButtonText(panel->animB, _("Animations"));
340 WMSetButtonImagePosition(panel->animB, WIPAbove);
341 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
342 if (icon) {
343 WMSetButtonImage(panel->animB, icon);
344 WMReleasePixmap(icon);
346 if (altIcon) {
347 WMSetButtonAltImage(panel->animB, altIcon);
348 WMReleasePixmap(altIcon);
350 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
351 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
353 panel->supB = WMCreateButton(panel->animF, WBTToggle);
354 WMResizeWidget(panel->supB, 64, 64);
355 WMMoveWidget(panel->supB, 95, 20);
356 WMSetButtonFont(panel->supB, font);
357 WMSetButtonText(panel->supB, _("Superfluous"));
358 WMSetButtonImagePosition(panel->supB, WIPAbove);
359 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
360 if (icon) {
361 WMSetButtonImage(panel->supB, icon);
362 WMReleasePixmap(icon);
364 if (altIcon) {
365 WMSetButtonAltImage(panel->supB, altIcon);
366 WMReleasePixmap(altIcon);
368 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
369 "animations. These include the `ghosting' of the\n"
370 "dock when it's being moved to another side and\n"
371 "the explosion animation when undocking icons."), WMWidgetView(panel->supB));
373 panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
374 WMResizeWidget(panel->sfxB, 64, 64);
375 WMMoveWidget(panel->sfxB, 175, 20);
376 WMSetButtonFont(panel->sfxB, font);
377 WMSetButtonText(panel->sfxB, _("Sounds"));
378 WMSetButtonImagePosition(panel->sfxB, WIPAbove);
379 createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
380 if (icon) {
381 WMSetButtonImage(panel->sfxB, icon);
382 WMReleasePixmap(icon);
384 if (altIcon) {
385 WMSetButtonAltImage(panel->sfxB, altIcon);
386 WMReleasePixmap(altIcon);
388 WMSetBalloonTextForView(_("Disable/enable support for sound effects played\n"
389 "for actions like shading and closing a window.\n"
390 "You will need a module distributed separately\n"
391 "for this. You can get it at:\n"
392 "http://largo.windowmaker.info/files.php#WSoundServer"),
393 WMWidgetView(panel->sfxB));
395 panel->noteL = WMCreateLabel(panel->animF);
396 WMResizeWidget(panel->noteL, 235, 28);
397 WMMoveWidget(panel->noteL, 10, 85);
398 WMSetLabelFont(panel->noteL, font);
399 WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed\nseparately"));
401 WMMapSubwidgets(panel->animF);
403 /*********** Dithering **********/
404 panel->cmapSize = 4;
406 panel->dithF = WMCreateFrame(panel->box);
407 WMResizeWidget(panel->dithF, 255, 95);
408 WMMoveWidget(panel->dithF, 255, 130);
409 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
411 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
412 "on displays that support only 8bpp (PseudoColor)."),
413 WMWidgetView(panel->dithF));
415 panel->dithB = WMCreateSwitchButton(panel->dithF);
416 WMResizeWidget(panel->dithB, 235, 32);
417 WMMoveWidget(panel->dithB, 15, 15);
418 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
420 panel->dithL = WMCreateLabel(panel->dithF);
421 WMResizeWidget(panel->dithL, 75, 16);
422 WMMoveWidget(panel->dithL, 90, 50);
423 WMSetLabelTextAlignment(panel->dithL, WACenter);
424 WMSetLabelText(panel->dithL, "64");
426 panel->dithS = WMCreateSlider(panel->dithF);
427 WMResizeWidget(panel->dithS, 95, 16);
428 WMMoveWidget(panel->dithS, 80, 65);
429 WMSetSliderMinValue(panel->dithS, 2);
430 WMSetSliderMaxValue(panel->dithS, 6);
431 WMSetSliderContinuous(panel->dithS, True);
432 WMSetSliderAction(panel->dithS, updateLabel, panel);
434 panel->dith1L = WMCreateLabel(panel->dithF);
435 WMResizeWidget(panel->dith1L, 70, 35);
436 WMMoveWidget(panel->dith1L, 5, 50);
437 WMSetLabelTextAlignment(panel->dith1L, WACenter);
438 WMSetLabelFont(panel->dith1L, font);
439 WMSetLabelText(panel->dith1L, _("More colors for\napplications"));
441 panel->dith2L = WMCreateLabel(panel->dithF);
442 WMResizeWidget(panel->dith2L, 70, 35);
443 WMMoveWidget(panel->dith2L, 180, 50);
444 WMSetLabelTextAlignment(panel->dith2L, WACenter);
445 WMSetLabelFont(panel->dith2L, font);
446 WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));
448 WMMapSubwidgets(panel->dithF);
450 WMRealizeWidget(panel->box);
451 WMMapSubwidgets(panel->box);
453 if (xis)
454 RReleaseImage(xis);
455 WMReleaseFont(font);
457 showData(panel);
460 static void storeData(_Panel * panel)
462 int i;
464 for (i = 0; i < 5; i++) {
465 if (WMGetButtonSelected(panel->icoB[i]))
466 break;
468 SetSpeedForKey(i, "IconSlideSpeed");
470 for (i = 0; i < 5; i++) {
471 if (WMGetButtonSelected(panel->shaB[i]))
472 break;
474 SetSpeedForKey(i, "ShadeSpeed");
476 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
478 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
479 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
480 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
482 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
484 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
485 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
488 Panel *InitConfigurations(WMScreen * scr, WMWidget * parent)
490 _Panel *panel;
492 panel = wmalloc(sizeof(_Panel));
493 memset(panel, 0, sizeof(_Panel));
495 panel->sectionName = _("Other Configurations");
497 panel->description = _("Animation speeds, titlebar styles, various option\n"
498 "toggling and number of colors to reserve for\n" "Window Maker on 8bit displays.");
500 panel->parent = parent;
502 panel->callbacks.createWidgets = createPanel;
503 panel->callbacks.updateDomain = storeData;
505 AddSection(panel, ICON_FILE);
507 return panel;