Updating to version 0.20.2
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob8095f809a86c602e18bd02c8f5c79d338276fc78
1 /* Configurations.c- misc. configurations
2 *
3 * WPrefs - Window Maker 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;
130 RColor gray = {0xae,0xaa,0xae};
132 *icon1 = NULL;
133 *icon2 = NULL;
135 path = LocateImage(file);
136 if (!path) {
137 return;
140 *icon1 = WMCreatePixmapFromFile(scr, path);
141 if (!*icon1) {
142 wwarning(_("could not load icon %s"), path);
143 free(path);
144 return;
146 icon = RLoadImage(rc, path, 0);
147 if (!icon) {
148 wwarning(_("could not load icon %s"), path);
149 free(path);
150 return;
152 RCombineImageWithColor(icon, &gray);
153 if (xis) {
154 RCombineImagesWithOpaqueness(icon, xis, 180);
155 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
156 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
158 RDestroyImage(icon);
159 free(path);
164 static void
165 createPanel(Panel *p)
167 _Panel *panel = (_Panel*)p;
168 WMScreen *scr = WMWidgetScreen(panel->win);
169 char *buf1, *buf2;
170 WMPixmap *icon, *altIcon;
171 RImage *xis = NULL;
172 int i;
173 RContext *rc = WMScreenRContext(scr);
174 WMFont *font = WMSystemFontOfSize(scr, 10);
175 char *path;
177 path = LocateImage(ARQUIVO_XIS);
178 if (path) {
179 xis = RLoadImage(rc, path, 0);
180 if (!xis) {
181 wwarning(_("could not load image file %s"), path);
183 free(path);
186 panel->frame = WMCreateFrame(panel->win);
187 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
188 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
190 /*********** Icon Slide Speed **********/
192 panel->icoF = WMCreateFrame(panel->frame);
193 WMResizeWidget(panel->icoF, 230, 55);
194 WMMoveWidget(panel->icoF, 15, 10);
195 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
197 /*********** Shade Animation Speed **********/
198 panel->shaF = WMCreateFrame(panel->frame);
199 WMResizeWidget(panel->shaF, 230, 55);
200 WMMoveWidget(panel->shaF, 15, 70);
201 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
204 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
205 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
207 for (i = 0; i < 5; i++) {
208 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
209 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
210 WMResizeWidget(panel->icoB[i], 40, 35);
211 WMMoveWidget(panel->icoB[i], 10+(40*i), 15);
212 WMResizeWidget(panel->shaB[i], 40, 35);
213 WMMoveWidget(panel->shaB[i], 10+(40*i), 15);
214 WMSetButtonBordered(panel->icoB[i], False);
215 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
216 if (i > 0) {
217 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
219 WMSetButtonBordered(panel->shaB[i], False);
220 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
221 if (i > 0) {
222 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
224 sprintf(buf1, SPEED_IMAGE, i);
225 sprintf(buf2, SPEED_IMAGE_S, i);
226 path = LocateImage(buf1);
227 if (path) {
228 icon = WMCreatePixmapFromFile(scr, path);
229 if (icon) {
230 WMSetButtonImage(panel->icoB[i], icon);
231 WMSetButtonImage(panel->shaB[i], icon);
232 WMReleasePixmap(icon);
233 } else {
234 wwarning(_("could not load icon file %s"), path);
236 free(path);
238 path = LocateImage(buf2);
239 if (path) {
240 icon = WMCreatePixmapFromFile(scr, path);
241 if (icon) {
242 WMSetButtonAltImage(panel->icoB[i], icon);
243 WMSetButtonAltImage(panel->shaB[i], icon);
244 WMReleasePixmap(icon);
245 } else {
246 wwarning(_("could not load icon file %s"), path);
248 free(path);
251 free(buf1);
252 free(buf2);
255 WMMapSubwidgets(panel->icoF);
256 WMMapSubwidgets(panel->shaF);
258 /***************** Titlebar Style Size ****************/
259 panel->titlF = WMCreateFrame(panel->frame);
260 WMResizeWidget(panel->titlF, 230, 95);
261 WMMoveWidget(panel->titlF, 15, 130);
262 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
264 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
265 WMResizeWidget(panel->newsB, 90, 60);
266 WMMoveWidget(panel->newsB, 25, 20);
267 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
268 path = LocateImage(NEWS_IMAGE);
269 if (path) {
270 icon = WMCreatePixmapFromFile(scr, path);
271 if (icon) {
272 WMSetButtonImage(panel->newsB, icon);
273 WMReleasePixmap(icon);
277 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
278 WMResizeWidget(panel->oldsB, 90, 60);
279 WMMoveWidget(panel->oldsB, 115, 20);
280 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
281 path = LocateImage(OLDS_IMAGE);
282 if (path) {
283 icon = WMCreatePixmapFromFile(scr, path);
284 if (icon) {
285 WMSetButtonImage(panel->oldsB, icon);
286 WMReleasePixmap(icon);
290 WMGroupButtons(panel->newsB, panel->oldsB);
292 WMMapSubwidgets(panel->titlF);
294 /**************** Features ******************/
296 panel->animF = WMCreateFrame(panel->frame);
297 WMResizeWidget(panel->animF, 255, 115);
298 WMMoveWidget(panel->animF, 255, 10);
299 WMSetFrameTitle(panel->animF, _("Animations and Sound"));
301 panel->animB = WMCreateButton(panel->animF, WBTToggle);
302 WMResizeWidget(panel->animB, 64, 64);
303 WMMoveWidget(panel->animB, 15, 20);
304 WMSetButtonFont(panel->animB, font);
305 WMSetButtonText(panel->animB, _("Animations"));
306 WMSetButtonImagePosition(panel->animB, WIPAbove);
307 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
308 if (icon) {
309 WMSetButtonImage(panel->animB, icon);
310 WMReleasePixmap(icon);
312 if (altIcon) {
313 WMSetButtonAltImage(panel->animB, altIcon);
314 WMReleasePixmap(altIcon);
317 panel->supB = WMCreateButton(panel->animF, WBTToggle);
318 WMResizeWidget(panel->supB, 64, 64);
319 WMMoveWidget(panel->supB, 95, 20);
320 WMSetButtonFont(panel->supB, font);
321 WMSetButtonText(panel->supB, _("Superfluous"));
322 WMSetButtonImagePosition(panel->supB, WIPAbove);
323 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
324 if (icon) {
325 WMSetButtonImage(panel->supB, icon);
326 WMReleasePixmap(icon);
328 if (altIcon) {
329 WMSetButtonAltImage(panel->supB, altIcon);
330 WMReleasePixmap(altIcon);
333 panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
334 WMResizeWidget(panel->sfxB, 64, 64);
335 WMMoveWidget(panel->sfxB, 175, 20);
336 WMSetButtonFont(panel->sfxB, font);
337 WMSetButtonText(panel->sfxB, _("Sounds"));
338 WMSetButtonImagePosition(panel->sfxB, WIPAbove);
339 createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
340 if (icon) {
341 WMSetButtonImage(panel->sfxB, icon);
342 WMReleasePixmap(icon);
344 if (altIcon) {
345 WMSetButtonAltImage(panel->sfxB, altIcon);
346 WMReleasePixmap(altIcon);
350 panel->noteL = WMCreateLabel(panel->animF);
351 WMResizeWidget(panel->noteL, 235, 28);
352 WMMoveWidget(panel->noteL, 10, 85);
353 WMSetLabelFont(panel->noteL, font);
354 WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed separately"));
356 WMMapSubwidgets(panel->animF);
358 /*********** Dithering **********/
359 panel->cmapSize = 4;
361 panel->dithF = WMCreateFrame(panel->frame);
362 WMResizeWidget(panel->dithF, 255, 95);
363 WMMoveWidget(panel->dithF, 255, 130);
364 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
366 panel->dithB = WMCreateSwitchButton(panel->dithF);
367 WMResizeWidget(panel->dithB, 235, 32);
368 WMMoveWidget(panel->dithB, 15, 15);
369 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
371 panel->dithL = WMCreateLabel(panel->dithF);
372 WMResizeWidget(panel->dithL, 75, 16);
373 WMMoveWidget(panel->dithL, 90, 50);
374 WMSetLabelTextAlignment(panel->dithL, WACenter);
375 WMSetLabelText(panel->dithL, "64");
377 panel->dithS = WMCreateSlider(panel->dithF);
378 WMResizeWidget(panel->dithS, 95, 16);
379 WMMoveWidget(panel->dithS, 80, 65);
380 WMSetSliderMinValue(panel->dithS, 2);
381 WMSetSliderMaxValue(panel->dithS, 6);
382 WMSetSliderContinuous(panel->dithS, True);
383 WMSetSliderAction(panel->dithS, updateLabel, panel);
385 panel->dith1L = WMCreateLabel(panel->dithF);
386 WMResizeWidget(panel->dith1L, 70, 35);
387 WMMoveWidget(panel->dith1L, 5, 50);
388 WMSetLabelTextAlignment(panel->dith1L, WACenter);
389 WMSetLabelFont(panel->dith1L, font);
390 WMSetLabelText(panel->dith1L, _("More colors for applications"));
392 panel->dith2L = WMCreateLabel(panel->dithF);
393 WMResizeWidget(panel->dith2L, 70, 35);
394 WMMoveWidget(panel->dith2L, 180, 50);
395 WMSetLabelTextAlignment(panel->dith2L, WACenter);
396 WMSetLabelFont(panel->dith2L, font);
397 WMSetLabelText(panel->dith2L, _("More colors for WindowMaker"));
399 WMMapSubwidgets(panel->dithF);
401 WMRealizeWidget(panel->frame);
402 WMMapSubwidgets(panel->frame);
404 if (xis)
405 RDestroyImage(xis);
406 WMReleaseFont(font);
408 showData(panel);
412 static void
413 storeData(_Panel *panel)
415 int i;
417 for (i=0; i<5; i++) {
418 if (WMGetButtonSelected(panel->icoB[i]))
419 break;
421 SetSpeedForKey(i, "IconSlideSpeed");
424 for (i=0; i<5; i++) {
425 if (WMGetButtonSelected(panel->shaB[i]))
426 break;
428 SetSpeedForKey(i, "ShadeSpeed");
430 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
432 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
433 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
434 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
436 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
437 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
442 Panel*
443 InitConfigurations(WMScreen *scr, WMWindow *win)
445 _Panel *panel;
447 panel = wmalloc(sizeof(_Panel));
448 memset(panel, 0, sizeof(_Panel));
450 panel->sectionName = _("Other Configurations");
452 panel->win = win;
454 panel->callbacks.createWidgets = createPanel;
455 panel->callbacks.updateDomain = storeData;
457 AddSection(panel, ICON_FILE);
459 return panel;