WPrefs: Update translations
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob952fd260f9d4f758fb63cf4e9b5e9ccda6f8a710
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 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.
22 #include "WPrefs.h"
24 typedef struct _Panel {
25 WMBox *box;
26 char *sectionName;
28 char *description;
30 CallbackRec callbacks;
32 WMWidget *parent;
34 WMFrame *icoF;
35 WMButton *icoB[5];
37 WMFrame *shaF;
38 WMButton *shaB[5];
40 WMFrame *titlF;
41 WMButton *oldsB;
42 WMButton *newsB;
43 WMButton *nextB;
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 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"
74 static void updateLabel(WMWidget *self, void *data);
76 static void showData(_Panel *panel)
78 char *str;
80 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
81 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
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);
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);
100 static void updateLabel(WMWidget *self, void *data)
102 WMSlider *sPtr = (WMSlider *) self;
103 _Panel *panel = (_Panel *) data;
104 char buffer[64];
105 float fl;
107 fl = WMGetSliderValue(sPtr);
108 panel->cmapSize = (int)fl;
110 sprintf(buffer, "%i", panel->cmapSize * panel->cmapSize * panel->cmapSize);
111 WMSetLabelText(panel->dithL, buffer);
114 static void
115 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
116 WMPixmap **icon1, WMPixmap **icon2)
118 RImage *icon;
119 char *path;
120 RColor gray = { 0xae, 0xaa, 0xae, 0 };
122 *icon1 = NULL;
123 *icon2 = NULL;
125 path = LocateImage(file);
126 if (!path)
127 return;
129 *icon1 = WMCreatePixmapFromFile(scr, path);
130 if (!*icon1) {
131 wwarning(_("could not load icon %s"), path);
132 wfree(path);
133 return;
135 icon = RLoadImage(rc, path, 0);
136 if (!icon) {
137 wwarning(_("could not load icon %s"), path);
138 wfree(path);
139 return;
141 RCombineImageWithColor(icon, &gray);
142 if (xis) {
143 RCombineImagesWithOpaqueness(icon, xis, 180);
144 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
145 wwarning(_("could not process icon %s: %s"), file, RMessageForError(RErrorCode));
147 RReleaseImage(icon);
148 wfree(path);
151 static void createPanel(Panel *p)
153 _Panel *panel = (_Panel *) p;
154 WMScreen *scr = WMWidgetScreen(panel->parent);
155 char *buf1, *buf2;
156 WMPixmap *icon, *altIcon;
157 RImage *xis = NULL;
158 int i;
159 RContext *rc = WMScreenRContext(scr);
160 WMFont *font = WMSystemFontOfSize(scr, 10);
161 char *path;
163 path = LocateImage(ARQUIVO_XIS);
164 if (path) {
165 xis = RLoadImage(rc, path, 0);
166 if (!xis)
167 wwarning(_("could not load image file %s"), path);
168 wfree(path);
171 panel->box = WMCreateBox(panel->parent);
172 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
174 /*********** Icon Slide Speed **********/
175 panel->icoF = WMCreateFrame(panel->box);
176 WMResizeWidget(panel->icoF, 230, 45);
177 WMMoveWidget(panel->icoF, 15, 10);
178 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
180 /*********** Shade Animation Speed **********/
181 panel->shaF = WMCreateFrame(panel->box);
182 WMResizeWidget(panel->shaF, 230, 45);
183 WMMoveWidget(panel->shaF, 15, 60);
184 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
186 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
187 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
189 for (i = 0; i < 5; i++) {
190 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
191 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
192 WMResizeWidget(panel->icoB[i], 40, 24);
193 WMMoveWidget(panel->icoB[i], 10 + (40 * i), 15);
194 WMResizeWidget(panel->shaB[i], 40, 24);
195 WMMoveWidget(panel->shaB[i], 10 + (40 * i), 15);
196 WMSetButtonBordered(panel->icoB[i], False);
197 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
198 if (i > 0) {
199 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
201 WMSetButtonBordered(panel->shaB[i], False);
202 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
203 if (i > 0) {
204 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
206 sprintf(buf1, SPEED_IMAGE, i);
207 sprintf(buf2, SPEED_IMAGE_S, i);
208 path = LocateImage(buf1);
209 if (path) {
210 icon = WMCreatePixmapFromFile(scr, path);
211 if (icon) {
212 WMSetButtonImage(panel->icoB[i], icon);
213 WMSetButtonImage(panel->shaB[i], icon);
214 WMReleasePixmap(icon);
215 } else {
216 wwarning(_("could not load icon file %s"), path);
218 wfree(path);
220 path = LocateImage(buf2);
221 if (path) {
222 icon = WMCreatePixmapFromFile(scr, path);
223 if (icon) {
224 WMSetButtonAltImage(panel->icoB[i], icon);
225 WMSetButtonAltImage(panel->shaB[i], icon);
226 WMReleasePixmap(icon);
227 } else {
228 wwarning(_("could not load icon file %s"), path);
230 wfree(path);
233 wfree(buf1);
234 wfree(buf2);
236 WMMapSubwidgets(panel->icoF);
237 WMMapSubwidgets(panel->shaF);
239 /***************** Smoothed Scaling *****************/
240 panel->smoF = WMCreateFrame(panel->box);
241 WMResizeWidget(panel->smoF, 115, 110);
242 WMMoveWidget(panel->smoF, 18, 115);
243 WMSetFrameTitle(panel->smoF, _("Smooth Scaling"));
244 WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
245 "the `pixelization' effect. This will slow\n"
246 "down loading of background images considerably."), WMWidgetView(panel->smoF));
248 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
249 WMResizeWidget(panel->smoB, 64, 64);
250 WMMoveWidget(panel->smoB, 25, 25);
251 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
252 path = LocateImage(SMOOTH_IMAGE);
253 if (path) {
254 RImage *image, *scaled;
256 image = RLoadImage(WMScreenRContext(scr), path, 0);
257 wfree(path);
259 scaled = RScaleImage(image, 61, 61);
260 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
261 RReleaseImage(scaled);
262 if (icon) {
263 WMSetButtonImage(panel->smoB, icon);
264 WMReleasePixmap(icon);
267 scaled = RSmoothScaleImage(image, 61, 61);
268 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
269 RReleaseImage(scaled);
270 if (icon) {
271 WMSetButtonAltImage(panel->smoB, icon);
272 WMReleasePixmap(icon);
275 RReleaseImage(image);
278 WMMapSubwidgets(panel->smoF);
280 /***************** Titlebar Style Size ****************/
281 panel->titlF = WMCreateFrame(panel->box);
282 WMResizeWidget(panel->titlF, 105, 110);
283 WMMoveWidget(panel->titlF, 140, 115);
284 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
286 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
287 WMResizeWidget(panel->newsB, 74, 40);
288 WMMoveWidget(panel->newsB, 15, 20);
289 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
290 path = LocateImage(NEWS_IMAGE);
291 if (path) {
292 icon = WMCreatePixmapFromFile(scr, path);
293 if (icon) {
294 WMSetButtonImage(panel->newsB, icon);
295 WMReleasePixmap(icon);
297 wfree(path);
300 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
301 WMResizeWidget(panel->oldsB, 37, 40);
302 WMMoveWidget(panel->oldsB, 15, 60);
303 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
304 path = LocateImage(OLDS_IMAGE);
305 if (path) {
306 icon = WMCreatePixmapFromFile(scr, path);
307 if (icon) {
308 WMSetButtonImage(panel->oldsB, icon);
309 WMReleasePixmap(icon);
311 wfree(path);
314 panel->nextB = WMCreateButton(panel->titlF, WBTOnOff);
315 WMResizeWidget(panel->nextB, 37, 40);
316 WMMoveWidget(panel->nextB, 52, 60);
317 WMSetButtonImagePosition(panel->nextB, WIPImageOnly);
318 path = LocateImage(NEXT_IMAGE);
319 if (path) {
320 icon = WMCreatePixmapFromFile(scr, path);
321 if (icon) {
322 WMSetButtonImage(panel->nextB, icon);
323 WMReleasePixmap(icon);
325 wfree(path);
328 WMGroupButtons(panel->newsB, panel->oldsB);
329 WMGroupButtons(panel->newsB, panel->nextB);
331 WMMapSubwidgets(panel->titlF);
333 /**************** Features ******************/
334 panel->animF = WMCreateFrame(panel->box);
335 WMResizeWidget(panel->animF, 255, 115);
336 WMMoveWidget(panel->animF, 255, 10);
337 WMSetFrameTitle(panel->animF, _("Animations"));
339 panel->animB = WMCreateButton(panel->animF, WBTToggle);
340 WMResizeWidget(panel->animB, 64, 64);
341 WMMoveWidget(panel->animB, 15, 20);
342 WMSetButtonFont(panel->animB, font);
343 WMSetButtonText(panel->animB, _("Animations"));
344 WMSetButtonImagePosition(panel->animB, WIPAbove);
345 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
346 if (icon) {
347 WMSetButtonImage(panel->animB, icon);
348 WMReleasePixmap(icon);
350 if (altIcon) {
351 WMSetButtonAltImage(panel->animB, altIcon);
352 WMReleasePixmap(altIcon);
354 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
355 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
357 panel->supB = WMCreateButton(panel->animF, WBTToggle);
358 WMResizeWidget(panel->supB, 64, 64);
359 WMMoveWidget(panel->supB, 95, 20);
360 WMSetButtonFont(panel->supB, font);
361 WMSetButtonText(panel->supB, _("Superfluous"));
362 WMSetButtonImagePosition(panel->supB, WIPAbove);
363 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
364 if (icon) {
365 WMSetButtonImage(panel->supB, icon);
366 WMReleasePixmap(icon);
368 if (altIcon) {
369 WMSetButtonAltImage(panel->supB, altIcon);
370 WMReleasePixmap(altIcon);
372 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
373 "animations. These include the `ghosting' of the\n"
374 "dock when it's being moved to another side and\n"
375 "the explosion animation when undocking icons."), WMWidgetView(panel->supB));
377 WMMapSubwidgets(panel->animF);
379 /*********** Dithering **********/
380 panel->cmapSize = 4;
382 panel->dithF = WMCreateFrame(panel->box);
383 WMResizeWidget(panel->dithF, 255, 95);
384 WMMoveWidget(panel->dithF, 255, 130);
385 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
387 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
388 "on displays that support only 8bpp (PseudoColor)."),
389 WMWidgetView(panel->dithF));
391 panel->dithB = WMCreateSwitchButton(panel->dithF);
392 WMResizeWidget(panel->dithB, 235, 32);
393 WMMoveWidget(panel->dithB, 15, 15);
394 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
396 panel->dithL = WMCreateLabel(panel->dithF);
397 WMResizeWidget(panel->dithL, 75, 16);
398 WMMoveWidget(panel->dithL, 90, 50);
399 WMSetLabelTextAlignment(panel->dithL, WACenter);
400 WMSetLabelText(panel->dithL, "64");
402 panel->dithS = WMCreateSlider(panel->dithF);
403 WMResizeWidget(panel->dithS, 95, 16);
404 WMMoveWidget(panel->dithS, 80, 65);
405 WMSetSliderMinValue(panel->dithS, 2);
406 WMSetSliderMaxValue(panel->dithS, 6);
407 WMSetSliderContinuous(panel->dithS, True);
408 WMSetSliderAction(panel->dithS, updateLabel, panel);
410 panel->dith1L = WMCreateLabel(panel->dithF);
411 WMResizeWidget(panel->dith1L, 70, 35);
412 WMMoveWidget(panel->dith1L, 5, 50);
413 WMSetLabelTextAlignment(panel->dith1L, WACenter);
414 WMSetLabelFont(panel->dith1L, font);
415 WMSetLabelText(panel->dith1L, _("More colors for\napplications"));
417 panel->dith2L = WMCreateLabel(panel->dithF);
418 WMResizeWidget(panel->dith2L, 70, 35);
419 WMMoveWidget(panel->dith2L, 180, 50);
420 WMSetLabelTextAlignment(panel->dith2L, WACenter);
421 WMSetLabelFont(panel->dith2L, font);
422 WMSetLabelText(panel->dith2L, _("More colors for\nWindow Maker"));
424 WMMapSubwidgets(panel->dithF);
426 WMRealizeWidget(panel->box);
427 WMMapSubwidgets(panel->box);
429 if (xis)
430 RReleaseImage(xis);
431 WMReleaseFont(font);
432 showData(panel);
435 static void storeData(_Panel *panel)
437 int i;
439 for (i = 0; i < 5; i++) {
440 if (WMGetButtonSelected(panel->icoB[i]))
441 break;
443 SetSpeedForKey(i, "IconSlideSpeed");
445 for (i = 0; i < 5; i++) {
446 if (WMGetButtonSelected(panel->shaB[i]))
447 break;
449 SetSpeedForKey(i, "ShadeSpeed");
451 if (WMGetButtonSelected(panel->newsB)) {
452 SetStringForKey("new", "NewStyle");
453 } else if (WMGetButtonSelected(panel->oldsB)) {
454 SetStringForKey("old", "NewStyle");
455 } else {
456 SetStringForKey("next", "NewStyle");
458 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
459 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
460 SetBoolForKey(WMGetButtonSelected(panel->smoB), "SmoothWorkspaceBack");
461 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
462 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
465 Panel *InitConfigurations(WMScreen *scr, WMWidget *parent)
467 _Panel *panel;
469 panel = wmalloc(sizeof(_Panel));
471 panel->sectionName = _("Other Configurations");
472 panel->description = _("Animation speeds, titlebar styles, various option\n"
473 "toggling and number of colors to reserve for\n" "Window Maker on 8bit displays.");
475 panel->parent = parent;
476 panel->callbacks.createWidgets = createPanel;
477 panel->callbacks.updateDomain = storeData;
479 AddSection(panel, ICON_FILE);
481 return panel;