Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Configurations.c
1 /* Configurations.c- misc. configurations
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2003 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.
11 *
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.
16 *
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.
21 */
22
23 #include "WPrefs.h"
24
25 typedef struct _Panel {
26 WMBox *box;
27 char *sectionName;
28
29 char *description;
30
31 CallbackRec callbacks;
32
33 WMWidget *parent;
34
35 WMFrame *icoF;
36 WMButton *icoB[5];
37
38 WMFrame *shaF;
39 WMButton *shaB[5];
40
41 WMFrame *titlF;
42 WMButton *oldsB;
43 WMButton *newsB;
44
45 WMFrame *animF;
46 WMButton *animB;
47 WMButton *supB;
48 WMButton *sfxB;
49 WMLabel *noteL;
50
51 WMFrame *smoF;
52 WMButton *smoB;
53
54 WMFrame *dithF;
55 WMButton *dithB;
56 WMSlider *dithS;
57 WMLabel *dithL;
58 WMLabel *dith1L;
59 WMLabel *dith2L;
60
61 int cmapSize;
62 } _Panel;
63
64 #define ICON_FILE "configs"
65
66 #define OLDS_IMAGE "oldstyle"
67 #define NEWS_IMAGE "newstyle"
68
69 #define ANIM_IMAGE "animations"
70 #define SUPERF_IMAGE "moreanim"
71 #define SOUND_IMAGE "sound"
72 #define SMOOTH_IMAGE "smooth"
73
74 #define SPEED_IMAGE "speed%i"
75 #define SPEED_IMAGE_S "speed%is"
76
77 #define ARQUIVO_XIS "xis"
78
79 static void updateLabel(WMWidget * self, void *data);
80
81 static void showData(_Panel * panel)
82 {
83 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
84
85 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
86
87 if (GetBoolForKey("NewStyle")) {
88 WMPerformButtonClick(panel->newsB);
89 } else {
90 WMPerformButtonClick(panel->oldsB);
91 }
92
93 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
94
95 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
96
97 WMSetButtonSelected(panel->sfxB, !GetBoolForKey("DisableSound"));
98
99 WMSetButtonSelected(panel->smoB, GetBoolForKey("SmoothWorkspaceBack"));
100
101 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
102
103 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
104
105 updateLabel(panel->dithS, panel);
106 }
107
108 static void updateLabel(WMWidget * self, void *data)
109 {
110 WMSlider *sPtr = (WMSlider *) self;
111 _Panel *panel = (_Panel *) data;
112 char buffer[64];
113 float fl;
114
115 fl = WMGetSliderValue(sPtr);
116
117 panel->cmapSize = (int)fl;
118
119 sprintf(buffer, "%i", panel->cmapSize * panel->cmapSize * panel->cmapSize);
120 WMSetLabelText(panel->dithL, buffer);
121 }
122
123 static void
124 createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2)
125 {
126 RImage *icon;
127 char *path;
128 RColor gray = { 0xae, 0xaa, 0xae };
129
130 *icon1 = NULL;
131 *icon2 = NULL;
132
133 path = LocateImage(file);
134 if (!path) {
135 return;
136 }
137
138 *icon1 = WMCreatePixmapFromFile(scr, path);
139 if (!*icon1) {
140 wwarning(_("could not load icon %s"), path);
141 wfree(path);
142 return;
143 }
144 icon = RLoadImage(rc, path, 0);
145 if (!icon) {
146 wwarning(_("could not load icon %s"), path);
147 wfree(path);
148 return;
149 }
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));
155 }
156 RReleaseImage(icon);
157 wfree(path);
158 }
159
160 static void createPanel(Panel * p)
161 {
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;
171
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);
177 }
178 wfree(path);
179 }
180
181 panel->box = WMCreateBox(panel->parent);
182 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
183
184 /*********** Icon Slide Speed **********/
185
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"));
190
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"));
196
197 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
198 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
199
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]);
211 }
212 WMSetButtonBordered(panel->shaB[i], False);
213 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
214 if (i > 0) {
215 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
216 }
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);
228 }
229 wfree(path);
230 }
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);
240 }
241 wfree(path);
242 }
243 }
244 wfree(buf1);
245 wfree(buf2);
246
247 WMMapSubwidgets(panel->icoF);
248 WMMapSubwidgets(panel->shaF);
249
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));
258
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;
266
267 image = RLoadImage(WMScreenRContext(scr), path, 0);
268 wfree(path);
269
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);
276 }
277
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);
284 }
285
286 RReleaseImage(image);
287 }
288
289 WMMapSubwidgets(panel->smoF);
290
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"));
296
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);
307 }
308 }
309
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);
320 }
321 wfree(path);
322 }
323
324 WMGroupButtons(panel->newsB, panel->oldsB);
325
326 WMMapSubwidgets(panel->titlF);
327
328 /**************** Features ******************/
329
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"));
334
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);
345 }
346 if (altIcon) {
347 WMSetButtonAltImage(panel->animB, altIcon);
348 WMReleasePixmap(altIcon);
349 }
350 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
351 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
352
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);
363 }
364 if (altIcon) {
365 WMSetButtonAltImage(panel->supB, altIcon);
366 WMReleasePixmap(altIcon);
367 }
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));
372
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);
383 }
384 if (altIcon) {
385 WMSetButtonAltImage(panel->sfxB, altIcon);
386 WMReleasePixmap(altIcon);
387 }
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));
394
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"));
400
401 WMMapSubwidgets(panel->animF);
402
403 /*********** Dithering **********/
404 panel->cmapSize = 4;
405
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"));
410
411 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
412 "on displays that support only 8bpp (PseudoColor)."),
413 WMWidgetView(panel->dithF));
414
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"));
419
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");
425
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);
433
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"));
440
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"));
447
448 WMMapSubwidgets(panel->dithF);
449
450 WMRealizeWidget(panel->box);
451 WMMapSubwidgets(panel->box);
452
453 if (xis)
454 RReleaseImage(xis);
455 WMReleaseFont(font);
456
457 showData(panel);
458 }
459
460 static void storeData(_Panel * panel)
461 {
462 int i;
463
464 for (i = 0; i < 5; i++) {
465 if (WMGetButtonSelected(panel->icoB[i]))
466 break;
467 }
468 SetSpeedForKey(i, "IconSlideSpeed");
469
470 for (i = 0; i < 5; i++) {
471 if (WMGetButtonSelected(panel->shaB[i]))
472 break;
473 }
474 SetSpeedForKey(i, "ShadeSpeed");
475
476 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
477
478 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
479 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
480 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
481
482 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
483
484 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
485 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
486 }
487
488 Panel *InitConfigurations(WMScreen * scr, WMWidget * parent)
489 {
490 _Panel *panel;
491
492 panel = wmalloc(sizeof(_Panel));
493 memset(panel, 0, sizeof(_Panel));
494
495 panel->sectionName = _("Other Configurations");
496
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.");
499
500 panel->parent = parent;
501
502 panel->callbacks.createWidgets = createPanel;
503 panel->callbacks.updateDomain = storeData;
504
505 AddSection(panel, ICON_FILE);
506
507 return panel;
508 }