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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "WPrefs.h"
23
24 typedef struct _Panel {
25 WMBox *box;
26 char *sectionName;
27
28 char *description;
29
30 CallbackRec callbacks;
31
32 WMWidget *parent;
33
34 WMFrame *icoF;
35 WMButton *icoB[5];
36
37 WMFrame *shaF;
38 WMButton *shaB[5];
39
40 WMFrame *titlF;
41 WMButton *oldsB;
42 WMButton *newsB;
43 WMButton *nextB;
44
45 WMFrame *animF;
46 WMButton *animB;
47 WMButton *supB;
48 WMLabel *noteL;
49
50 WMFrame *smoF;
51 WMButton *smoB;
52
53 WMFrame *dithF;
54 WMButton *dithB;
55 WMSlider *dithS;
56 WMLabel *dithL;
57 WMLabel *dith1L;
58 WMLabel *dith2L;
59
60 int cmapSize;
61 } _Panel;
62
63 #define ICON_FILE "configs"
64 #define OLDS_IMAGE "oldstyle"
65 #define NEWS_IMAGE "newstyle"
66 #define NEXT_IMAGE "nextstyle"
67 #define ANIM_IMAGE "animations"
68 #define SUPERF_IMAGE "moreanim"
69 #define SMOOTH_IMAGE "smooth"
70 #define SPEED_IMAGE "speed%i"
71 #define SPEED_IMAGE_S "speed%is"
72 #define ARQUIVO_XIS "xis"
73
74 static void updateLabel(WMWidget *self, void *data);
75
showData(_Panel * panel)76 static void showData(_Panel *panel)
77 {
78 char *str;
79
80 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
81 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
82
83 str = GetStringForKey("NewStyle");
84 if (str && strcasecmp(str, "next") == 0) {
85 WMPerformButtonClick(panel->nextB);
86 } else if (str && strcasecmp(str, "old") == 0) {
87 WMPerformButtonClick(panel->oldsB);
88 } else {
89 WMPerformButtonClick(panel->newsB);
90 }
91
92 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
93 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
94 WMSetButtonSelected(panel->smoB, GetBoolForKey("SmoothWorkspaceBack"));
95 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
96 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
97 updateLabel(panel->dithS, panel);
98 }
99
updateLabel(WMWidget * self,void * data)100 static void updateLabel(WMWidget *self, void *data)
101 {
102 WMSlider *sPtr = (WMSlider *) self;
103 _Panel *panel = (_Panel *) data;
104 char buffer[64];
105 float fl;
106
107 fl = WMGetSliderValue(sPtr);
108 panel->cmapSize = (int)fl;
109
110 sprintf(buffer, "%i", panel->cmapSize * panel->cmapSize * panel->cmapSize);
111 WMSetLabelText(panel->dithL, buffer);
112 }
113
createPanel(Panel * p)114 static void createPanel(Panel *p)
115 {
116 _Panel *panel = (_Panel *) p;
117 WMScreen *scr = WMWidgetScreen(panel->parent);
118 char *buf1, *buf2;
119 WMPixmap *icon, *altIcon;
120 RImage *xis = NULL;
121 int i;
122 RContext *rc = WMScreenRContext(scr);
123 WMFont *font = WMSystemFontOfSize(scr, 10);
124 char *path;
125
126 path = LocateImage(ARQUIVO_XIS);
127 if (path) {
128 xis = RLoadImage(rc, path, 0);
129 if (!xis)
130 wwarning(_("could not load image file %s"), path);
131 wfree(path);
132 }
133
134 panel->box = WMCreateBox(panel->parent);
135 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
136
137 /*********** Icon Slide Speed **********/
138 panel->icoF = WMCreateFrame(panel->box);
139 WMResizeWidget(panel->icoF, 212, 45);
140 WMMoveWidget(panel->icoF, 15, 10);
141 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
142
143 /*********** Shade Animation Speed **********/
144 panel->shaF = WMCreateFrame(panel->box);
145 WMResizeWidget(panel->shaF, 212, 45);
146 WMMoveWidget(panel->shaF, 15, 65);
147 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
148
149 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
150 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
151
152 for (i = 0; i < 5; i++) {
153 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
154 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
155 WMResizeWidget(panel->icoB[i], 40, 24);
156 WMMoveWidget(panel->icoB[i], 2 + (40 * i), 15);
157 WMResizeWidget(panel->shaB[i], 40, 24);
158 WMMoveWidget(panel->shaB[i], 2 + (40 * i), 15);
159 WMSetButtonBordered(panel->icoB[i], False);
160 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
161 if (i > 0) {
162 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
163 }
164 WMSetButtonBordered(panel->shaB[i], False);
165 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
166 if (i > 0) {
167 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
168 }
169 sprintf(buf1, SPEED_IMAGE, i);
170 sprintf(buf2, SPEED_IMAGE_S, i);
171 path = LocateImage(buf1);
172 if (path) {
173 icon = WMCreatePixmapFromFile(scr, path);
174 if (icon) {
175 WMSetButtonImage(panel->icoB[i], icon);
176 WMSetButtonImage(panel->shaB[i], icon);
177 WMReleasePixmap(icon);
178 } else {
179 wwarning(_("could not load icon file %s"), path);
180 }
181 wfree(path);
182 }
183 path = LocateImage(buf2);
184 if (path) {
185 icon = WMCreatePixmapFromFile(scr, path);
186 if (icon) {
187 WMSetButtonAltImage(panel->icoB[i], icon);
188 WMSetButtonAltImage(panel->shaB[i], icon);
189 WMReleasePixmap(icon);
190 } else {
191 wwarning(_("could not load icon file %s"), path);
192 }
193 wfree(path);
194 }
195 }
196 wfree(buf1);
197 wfree(buf2);
198
199 WMMapSubwidgets(panel->icoF);
200 WMMapSubwidgets(panel->shaF);
201
202 /***************** Smoothed Scaling *****************/
203 panel->smoF = WMCreateFrame(panel->box);
204 WMResizeWidget(panel->smoF, 94, 100);
205 WMMoveWidget(panel->smoF, 420, 10);
206 WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
207
208 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
209 WMResizeWidget(panel->smoB, 64, 64);
210 WMMoveWidget(panel->smoB, 15, 23);
211 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
212 path = LocateImage(SMOOTH_IMAGE);
213 if (path) {
214 RImage *image, *scaled;
215
216 image = RLoadImage(WMScreenRContext(scr), path, 0);
217 wfree(path);
218
219 scaled = RScaleImage(image, 61, 61);
220 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
221 RReleaseImage(scaled);
222 if (icon) {
223 WMSetButtonImage(panel->smoB, icon);
224 WMReleasePixmap(icon);
225 }
226
227 scaled = RSmoothScaleImage(image, 61, 61);
228 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
229 RReleaseImage(scaled);
230 if (icon) {
231 WMSetButtonAltImage(panel->smoB, icon);
232 WMReleasePixmap(icon);
233 }
234
235 RReleaseImage(image);
236 }
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->smoB));
240
241 WMMapSubwidgets(panel->smoF);
242
243 /***************** Titlebar Style Size ****************/
244 panel->titlF = WMCreateFrame(panel->box);
245 WMResizeWidget(panel->titlF, 212, 97);
246 WMMoveWidget(panel->titlF, 15, 120);
247 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
248
249 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
250 WMResizeWidget(panel->oldsB, 60, 40);
251 WMMoveWidget(panel->oldsB, 16, 32);
252 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
253 path = LocateImage(OLDS_IMAGE);
254 if (path) {
255 icon = WMCreatePixmapFromFile(scr, path);
256 if (icon) {
257 WMSetButtonImage(panel->oldsB, icon);
258 WMReleasePixmap(icon);
259 }
260 wfree(path);
261 }
262
263 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
264 WMResizeWidget(panel->newsB, 60, 40);
265 WMMoveWidget(panel->newsB, 76, 32);
266 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
267 path = LocateImage(NEWS_IMAGE);
268 if (path) {
269 icon = WMCreatePixmapFromFile(scr, path);
270 if (icon) {
271 WMSetButtonImage(panel->newsB, icon);
272 WMReleasePixmap(icon);
273 }
274 wfree(path);
275 }
276
277 panel->nextB = WMCreateButton(panel->titlF, WBTOnOff);
278 WMResizeWidget(panel->nextB, 60, 40);
279 WMMoveWidget(panel->nextB, 136, 32);
280 WMSetButtonImagePosition(panel->nextB, WIPImageOnly);
281 path = LocateImage(NEXT_IMAGE);
282 if (path) {
283 icon = WMCreatePixmapFromFile(scr, path);
284 if (icon) {
285 WMSetButtonImage(panel->nextB, icon);
286 WMReleasePixmap(icon);
287 }
288 wfree(path);
289 }
290
291 WMGroupButtons(panel->newsB, panel->oldsB);
292 WMGroupButtons(panel->newsB, panel->nextB);
293
294 WMMapSubwidgets(panel->titlF);
295
296 /**************** Features ******************/
297 panel->animF = WMCreateFrame(panel->box);
298 WMResizeWidget(panel->animF, 173, 100);
299 WMMoveWidget(panel->animF, 237, 10);
300 WMSetFrameTitle(panel->animF, _("Animations"));
301
302 panel->animB = WMCreateButton(panel->animF, WBTToggle);
303 WMResizeWidget(panel->animB, 64, 64);
304 WMMoveWidget(panel->animB, 15, 23);
305 WMSetButtonFont(panel->animB, font);
306 WMSetButtonText(panel->animB, _("Animations"));
307 WMSetButtonImagePosition(panel->animB, WIPAbove);
308 CreateImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
309 if (icon) {
310 WMSetButtonImage(panel->animB, icon);
311 WMReleasePixmap(icon);
312 }
313 if (altIcon) {
314 WMSetButtonAltImage(panel->animB, altIcon);
315 WMReleasePixmap(altIcon);
316 }
317 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
318 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
319
320 panel->supB = WMCreateButton(panel->animF, WBTToggle);
321 WMResizeWidget(panel->supB, 64, 64);
322 WMMoveWidget(panel->supB, 94, 23);
323 WMSetButtonFont(panel->supB, font);
324 WMSetButtonText(panel->supB, _("Superfluous"));
325 WMSetButtonImagePosition(panel->supB, WIPAbove);
326 CreateImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
327 if (icon) {
328 WMSetButtonImage(panel->supB, icon);
329 WMReleasePixmap(icon);
330 }
331 if (altIcon) {
332 WMSetButtonAltImage(panel->supB, altIcon);
333 WMReleasePixmap(altIcon);
334 }
335 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
336 "animations. These include the `ghosting' of the\n"
337 "dock when it's being moved to another side and\n"
338 "the explosion animation when undocking icons."), WMWidgetView(panel->supB));
339
340 WMMapSubwidgets(panel->animF);
341
342 /*********** Dithering **********/
343 panel->cmapSize = 4;
344
345 panel->dithF = WMCreateFrame(panel->box);
346 WMResizeWidget(panel->dithF, 277, 97);
347 WMMoveWidget(panel->dithF, 237, 120);
348 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
349
350 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
351 "on displays that support only 8bpp (PseudoColor)."),
352 WMWidgetView(panel->dithF));
353
354 panel->dithB = WMCreateSwitchButton(panel->dithF);
355 WMResizeWidget(panel->dithB, 235, 32);
356 WMMoveWidget(panel->dithB, 15, 15);
357 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
358
359 panel->dithL = WMCreateLabel(panel->dithF);
360 WMResizeWidget(panel->dithL, 75, 16);
361 WMMoveWidget(panel->dithL, 98, 50);
362 WMSetLabelTextAlignment(panel->dithL, WACenter);
363 WMSetLabelText(panel->dithL, "64");
364
365 panel->dithS = WMCreateSlider(panel->dithF);
366 WMResizeWidget(panel->dithS, 95, 16);
367 WMMoveWidget(panel->dithS, 90, 65);
368 WMSetSliderMinValue(panel->dithS, 2);
369 WMSetSliderMaxValue(panel->dithS, 6);
370 WMSetSliderContinuous(panel->dithS, True);
371 WMSetSliderAction(panel->dithS, updateLabel, panel);
372
373 panel->dith1L = WMCreateLabel(panel->dithF);
374 WMResizeWidget(panel->dith1L, 80, 35);
375 WMMoveWidget(panel->dith1L, 5, 50);
376 WMSetLabelTextAlignment(panel->dith1L, WACenter);
377 WMSetLabelFont(panel->dith1L, font);
378 WMSetLabelText(panel->dith1L, _("More colors for\napplications"));
379
380 panel->dith2L = WMCreateLabel(panel->dithF);
381 WMResizeWidget(panel->dith2L, 80, 35);
382 WMMoveWidget(panel->dith2L, 190, 50);
383 WMSetLabelTextAlignment(panel->dith2L, WACenter);
384 WMSetLabelFont(panel->dith2L, font);
385 WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));
386
387 WMMapSubwidgets(panel->dithF);
388
389 WMRealizeWidget(panel->box);
390 WMMapSubwidgets(panel->box);
391
392 if (xis)
393 RReleaseImage(xis);
394 WMReleaseFont(font);
395 showData(panel);
396 }
397
storeData(_Panel * panel)398 static void storeData(_Panel *panel)
399 {
400 int i;
401
402 for (i = 0; i < 5; i++) {
403 if (WMGetButtonSelected(panel->icoB[i]))
404 break;
405 }
406 SetSpeedForKey(i, "IconSlideSpeed");
407
408 for (i = 0; i < 5; i++) {
409 if (WMGetButtonSelected(panel->shaB[i]))
410 break;
411 }
412 SetSpeedForKey(i, "ShadeSpeed");
413
414 if (WMGetButtonSelected(panel->newsB)) {
415 SetStringForKey("new", "NewStyle");
416 } else if (WMGetButtonSelected(panel->oldsB)) {
417 SetStringForKey("old", "NewStyle");
418 } else {
419 SetStringForKey("next", "NewStyle");
420 }
421 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
422 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
423 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
424 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
425 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
426 }
427
InitConfigurations(WMWidget * parent)428 Panel *InitConfigurations(WMWidget *parent)
429 {
430 _Panel *panel;
431
432 panel = wmalloc(sizeof(_Panel));
433
434 panel->sectionName = _("Other Configurations");
435 panel->description = _("Animation speeds, titlebar styles, various option\n"
436 "toggling and number of colors to reserve for\n" "Window Maker on 8bit displays.");
437
438 panel->parent = parent;
439 panel->callbacks.createWidgets = createPanel;
440 panel->callbacks.updateDomain = storeData;
441
442 AddSection(panel, ICON_FILE);
443
444 return panel;
445 }
446