Small fix for wmaker nightly build script 2
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob6f4fdf4133704444a97436b18073e82c4d9e1ca7
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 WMLabel *noteL;
50 WMFrame *smoF;
51 WMButton *smoB;
53 WMFrame *dithF;
54 WMButton *dithB;
55 WMSlider *dithS;
56 WMLabel *dithL;
57 WMLabel *dith1L;
58 WMLabel *dith2L;
60 int cmapSize;
61 } _Panel;
63 #define ICON_FILE "configs"
64 #define OLDS_IMAGE "oldstyle"
65 #define NEWS_IMAGE "newstyle"
66 #define ANIM_IMAGE "animations"
67 #define SUPERF_IMAGE "moreanim"
68 #define SMOOTH_IMAGE "smooth"
69 #define SPEED_IMAGE "speed%i"
70 #define SPEED_IMAGE_S "speed%is"
71 #define ARQUIVO_XIS "xis"
73 static void updateLabel(WMWidget *self, void *data);
75 static void showData(_Panel *panel)
77 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
78 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
80 if (GetBoolForKey("NewStyle"))
81 WMPerformButtonClick(panel->newsB);
82 else
83 WMPerformButtonClick(panel->oldsB);
85 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
86 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
87 WMSetButtonSelected(panel->smoB, GetBoolForKey("SmoothWorkspaceBack"));
88 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
89 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
90 updateLabel(panel->dithS, panel);
93 static void updateLabel(WMWidget *self, void *data)
95 WMSlider *sPtr = (WMSlider *) self;
96 _Panel *panel = (_Panel *) data;
97 char buffer[64];
98 float fl;
100 fl = WMGetSliderValue(sPtr);
101 panel->cmapSize = (int)fl;
103 sprintf(buffer, "%i", panel->cmapSize * panel->cmapSize * panel->cmapSize);
104 WMSetLabelText(panel->dithL, buffer);
107 static void
108 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
109 WMPixmap **icon1, WMPixmap **icon2)
111 RImage *icon;
112 char *path;
113 RColor gray = { 0xae, 0xaa, 0xae };
115 *icon1 = NULL;
116 *icon2 = NULL;
118 path = LocateImage(file);
119 if (!path)
120 return;
122 *icon1 = WMCreatePixmapFromFile(scr, path);
123 if (!*icon1) {
124 wwarning(_("could not load icon %s"), path);
125 wfree(path);
126 return;
128 icon = RLoadImage(rc, path, 0);
129 if (!icon) {
130 wwarning(_("could not load icon %s"), path);
131 wfree(path);
132 return;
134 RCombineImageWithColor(icon, &gray);
135 if (xis) {
136 RCombineImagesWithOpaqueness(icon, xis, 180);
137 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
138 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
140 RReleaseImage(icon);
141 wfree(path);
144 static void createPanel(Panel *p)
146 _Panel *panel = (_Panel *) p;
147 WMScreen *scr = WMWidgetScreen(panel->parent);
148 char *buf1, *buf2;
149 WMPixmap *icon, *altIcon;
150 RImage *xis = NULL;
151 int i;
152 RContext *rc = WMScreenRContext(scr);
153 WMFont *font = WMSystemFontOfSize(scr, 10);
154 char *path;
156 path = LocateImage(ARQUIVO_XIS);
157 if (path) {
158 xis = RLoadImage(rc, path, 0);
159 if (!xis)
160 wwarning(_("could not load image file %s"), path);
161 wfree(path);
164 panel->box = WMCreateBox(panel->parent);
165 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
167 /*********** Icon Slide Speed **********/
168 panel->icoF = WMCreateFrame(panel->box);
169 WMResizeWidget(panel->icoF, 230, 45);
170 WMMoveWidget(panel->icoF, 15, 10);
171 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
173 /*********** Shade Animation Speed **********/
174 panel->shaF = WMCreateFrame(panel->box);
175 WMResizeWidget(panel->shaF, 230, 45);
176 WMMoveWidget(panel->shaF, 15, 60);
177 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
179 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
180 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
182 for (i = 0; i < 5; i++) {
183 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
184 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
185 WMResizeWidget(panel->icoB[i], 40, 24);
186 WMMoveWidget(panel->icoB[i], 10 + (40 * i), 15);
187 WMResizeWidget(panel->shaB[i], 40, 24);
188 WMMoveWidget(panel->shaB[i], 10 + (40 * i), 15);
189 WMSetButtonBordered(panel->icoB[i], False);
190 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
191 if (i > 0) {
192 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
194 WMSetButtonBordered(panel->shaB[i], False);
195 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
196 if (i > 0) {
197 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
199 sprintf(buf1, SPEED_IMAGE, i);
200 sprintf(buf2, SPEED_IMAGE_S, i);
201 path = LocateImage(buf1);
202 if (path) {
203 icon = WMCreatePixmapFromFile(scr, path);
204 if (icon) {
205 WMSetButtonImage(panel->icoB[i], icon);
206 WMSetButtonImage(panel->shaB[i], icon);
207 WMReleasePixmap(icon);
208 } else {
209 wwarning(_("could not load icon file %s"), path);
211 wfree(path);
213 path = LocateImage(buf2);
214 if (path) {
215 icon = WMCreatePixmapFromFile(scr, path);
216 if (icon) {
217 WMSetButtonAltImage(panel->icoB[i], icon);
218 WMSetButtonAltImage(panel->shaB[i], icon);
219 WMReleasePixmap(icon);
220 } else {
221 wwarning(_("could not load icon file %s"), path);
223 wfree(path);
226 wfree(buf1);
227 wfree(buf2);
229 WMMapSubwidgets(panel->icoF);
230 WMMapSubwidgets(panel->shaF);
232 /***************** Smoothed Scaling *****************/
233 panel->smoF = WMCreateFrame(panel->box);
234 WMResizeWidget(panel->smoF, 115, 110);
235 WMMoveWidget(panel->smoF, 18, 115);
236 WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
237 WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
238 "the `pixelization' effect. This will slow\n"
239 "down loading of background images considerably."), WMWidgetView(panel->smoF));
241 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
242 WMResizeWidget(panel->smoB, 64, 64);
243 WMMoveWidget(panel->smoB, 25, 25);
244 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
245 path = LocateImage(SMOOTH_IMAGE);
246 if (path) {
247 RImage *image, *scaled;
249 image = RLoadImage(WMScreenRContext(scr), path, 0);
250 wfree(path);
252 scaled = RScaleImage(image, 61, 61);
253 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
254 RReleaseImage(scaled);
255 if (icon) {
256 WMSetButtonImage(panel->smoB, icon);
257 WMReleasePixmap(icon);
260 scaled = RSmoothScaleImage(image, 61, 61);
261 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
262 RReleaseImage(scaled);
263 if (icon) {
264 WMSetButtonAltImage(panel->smoB, icon);
265 WMReleasePixmap(icon);
268 RReleaseImage(image);
271 WMMapSubwidgets(panel->smoF);
273 /***************** Titlebar Style Size ****************/
274 panel->titlF = WMCreateFrame(panel->box);
275 WMResizeWidget(panel->titlF, 105, 110);
276 WMMoveWidget(panel->titlF, 140, 115);
277 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
279 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
280 WMResizeWidget(panel->newsB, 74, 40);
281 WMMoveWidget(panel->newsB, 15, 20);
282 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
283 path = LocateImage(NEWS_IMAGE);
284 if (path) {
285 icon = WMCreatePixmapFromFile(scr, path);
286 if (icon) {
287 WMSetButtonImage(panel->newsB, icon);
288 WMReleasePixmap(icon);
292 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
293 WMResizeWidget(panel->oldsB, 74, 40);
294 WMMoveWidget(panel->oldsB, 15, 60);
295 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
296 path = LocateImage(OLDS_IMAGE);
297 if (path) {
298 icon = WMCreatePixmapFromFile(scr, path);
299 if (icon) {
300 WMSetButtonImage(panel->oldsB, icon);
301 WMReleasePixmap(icon);
303 wfree(path);
306 WMGroupButtons(panel->newsB, panel->oldsB);
308 WMMapSubwidgets(panel->titlF);
310 /**************** Features ******************/
311 panel->animF = WMCreateFrame(panel->box);
312 WMResizeWidget(panel->animF, 255, 115);
313 WMMoveWidget(panel->animF, 255, 10);
314 WMSetFrameTitle(panel->animF, _("Animations"));
316 panel->animB = WMCreateButton(panel->animF, WBTToggle);
317 WMResizeWidget(panel->animB, 64, 64);
318 WMMoveWidget(panel->animB, 15, 20);
319 WMSetButtonFont(panel->animB, font);
320 WMSetButtonText(panel->animB, _("Animations"));
321 WMSetButtonImagePosition(panel->animB, WIPAbove);
322 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
323 if (icon) {
324 WMSetButtonImage(panel->animB, icon);
325 WMReleasePixmap(icon);
327 if (altIcon) {
328 WMSetButtonAltImage(panel->animB, altIcon);
329 WMReleasePixmap(altIcon);
331 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
332 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
334 panel->supB = WMCreateButton(panel->animF, WBTToggle);
335 WMResizeWidget(panel->supB, 64, 64);
336 WMMoveWidget(panel->supB, 95, 20);
337 WMSetButtonFont(panel->supB, font);
338 WMSetButtonText(panel->supB, _("Superfluous"));
339 WMSetButtonImagePosition(panel->supB, WIPAbove);
340 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
341 if (icon) {
342 WMSetButtonImage(panel->supB, icon);
343 WMReleasePixmap(icon);
345 if (altIcon) {
346 WMSetButtonAltImage(panel->supB, altIcon);
347 WMReleasePixmap(altIcon);
349 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
350 "animations. These include the `ghosting' of the\n"
351 "dock when it's being moved to another side and\n"
352 "the explosion animation when undocking icons."), WMWidgetView(panel->supB));
354 WMMapSubwidgets(panel->animF);
356 /*********** Dithering **********/
357 panel->cmapSize = 4;
359 panel->dithF = WMCreateFrame(panel->box);
360 WMResizeWidget(panel->dithF, 255, 95);
361 WMMoveWidget(panel->dithF, 255, 130);
362 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
364 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
365 "on displays that support only 8bpp (PseudoColor)."),
366 WMWidgetView(panel->dithF));
368 panel->dithB = WMCreateSwitchButton(panel->dithF);
369 WMResizeWidget(panel->dithB, 235, 32);
370 WMMoveWidget(panel->dithB, 15, 15);
371 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
373 panel->dithL = WMCreateLabel(panel->dithF);
374 WMResizeWidget(panel->dithL, 75, 16);
375 WMMoveWidget(panel->dithL, 90, 50);
376 WMSetLabelTextAlignment(panel->dithL, WACenter);
377 WMSetLabelText(panel->dithL, "64");
379 panel->dithS = WMCreateSlider(panel->dithF);
380 WMResizeWidget(panel->dithS, 95, 16);
381 WMMoveWidget(panel->dithS, 80, 65);
382 WMSetSliderMinValue(panel->dithS, 2);
383 WMSetSliderMaxValue(panel->dithS, 6);
384 WMSetSliderContinuous(panel->dithS, True);
385 WMSetSliderAction(panel->dithS, updateLabel, panel);
387 panel->dith1L = WMCreateLabel(panel->dithF);
388 WMResizeWidget(panel->dith1L, 70, 35);
389 WMMoveWidget(panel->dith1L, 5, 50);
390 WMSetLabelTextAlignment(panel->dith1L, WACenter);
391 WMSetLabelFont(panel->dith1L, font);
392 WMSetLabelText(panel->dith1L, _("More colors for\napplications"));
394 panel->dith2L = WMCreateLabel(panel->dithF);
395 WMResizeWidget(panel->dith2L, 70, 35);
396 WMMoveWidget(panel->dith2L, 180, 50);
397 WMSetLabelTextAlignment(panel->dith2L, WACenter);
398 WMSetLabelFont(panel->dith2L, font);
399 WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));
401 WMMapSubwidgets(panel->dithF);
403 WMRealizeWidget(panel->box);
404 WMMapSubwidgets(panel->box);
406 if (xis)
407 RReleaseImage(xis);
408 WMReleaseFont(font);
409 showData(panel);
412 static void storeData(_Panel *panel)
414 int i;
416 for (i = 0; i < 5; i++) {
417 if (WMGetButtonSelected(panel->icoB[i]))
418 break;
420 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");
429 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
430 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
431 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
432 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
433 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
436 Panel *InitConfigurations(WMScreen *scr, WMWidget *parent)
438 _Panel *panel;
440 panel = wmalloc(sizeof(_Panel));
441 memset(panel, 0, sizeof(_Panel));
443 panel->sectionName = _("Other Configurations");
444 panel->description = _("Animation speeds, titlebar styles, various option\n"
445 "toggling and number of colors to reserve for\n" "Window Maker on 8bit displays.");
447 panel->parent = parent;
448 panel->callbacks.createWidgets = createPanel;
449 panel->callbacks.updateDomain = storeData;
451 AddSection(panel, ICON_FILE);
453 return panel;