Move code that removes icons from a dock to new removeIcons function
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob55b153759d9a5725a5de54f766f1d31a5dde7d0c
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 createPanel(Panel *p)
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;
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);
134 panel->box = WMCreateBox(panel->parent);
135 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
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"));
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"));
149 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
150 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
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]);
164 WMSetButtonBordered(panel->shaB[i], False);
165 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
166 if (i > 0) {
167 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
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);
181 wfree(path);
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);
193 wfree(path);
196 wfree(buf1);
197 wfree(buf2);
199 WMMapSubwidgets(panel->icoF);
200 WMMapSubwidgets(panel->shaF);
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 WMSetBalloonTextForView(_("Smooth scaled background images, neutralizing\n"
208 "the `pixelization' effect. This will slow\n"
209 "down loading of background images considerably."), WMWidgetView(panel->smoF));
211 panel->smoB = WMCreateButton(panel->smoF, WBTToggle);
212 WMResizeWidget(panel->smoB, 64, 64);
213 WMMoveWidget(panel->smoB, 15, 23);
214 WMSetButtonImagePosition(panel->smoB, WIPImageOnly);
215 path = LocateImage(SMOOTH_IMAGE);
216 if (path) {
217 RImage *image, *scaled;
219 image = RLoadImage(WMScreenRContext(scr), path, 0);
220 wfree(path);
222 scaled = RScaleImage(image, 61, 61);
223 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
224 RReleaseImage(scaled);
225 if (icon) {
226 WMSetButtonImage(panel->smoB, icon);
227 WMReleasePixmap(icon);
230 scaled = RSmoothScaleImage(image, 61, 61);
231 icon = WMCreatePixmapFromRImage(scr, scaled, 128);
232 RReleaseImage(scaled);
233 if (icon) {
234 WMSetButtonAltImage(panel->smoB, icon);
235 WMReleasePixmap(icon);
238 RReleaseImage(image);
241 WMMapSubwidgets(panel->smoF);
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"));
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);
260 wfree(path);
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);
274 wfree(path);
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);
288 wfree(path);
291 WMGroupButtons(panel->newsB, panel->oldsB);
292 WMGroupButtons(panel->newsB, panel->nextB);
294 WMMapSubwidgets(panel->titlF);
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"));
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);
313 if (altIcon) {
314 WMSetButtonAltImage(panel->animB, altIcon);
315 WMReleasePixmap(altIcon);
317 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
318 "for window miniaturization, shading etc."), WMWidgetView(panel->animB));
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);
331 if (altIcon) {
332 WMSetButtonAltImage(panel->supB, altIcon);
333 WMReleasePixmap(altIcon);
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));
340 WMMapSubwidgets(panel->animF);
342 /*********** Dithering **********/
343 panel->cmapSize = 4;
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"));
350 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
351 "on displays that support only 8bpp (PseudoColor)."),
352 WMWidgetView(panel->dithF));
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"));
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");
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);
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"));
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"));
387 WMMapSubwidgets(panel->dithF);
389 WMRealizeWidget(panel->box);
390 WMMapSubwidgets(panel->box);
392 if (xis)
393 RReleaseImage(xis);
394 WMReleaseFont(font);
395 showData(panel);
398 static void storeData(_Panel *panel)
400 int i;
402 for (i = 0; i < 5; i++) {
403 if (WMGetButtonSelected(panel->icoB[i]))
404 break;
406 SetSpeedForKey(i, "IconSlideSpeed");
408 for (i = 0; i < 5; i++) {
409 if (WMGetButtonSelected(panel->shaB[i]))
410 break;
412 SetSpeedForKey(i, "ShadeSpeed");
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");
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");
428 Panel *InitConfigurations(WMScreen *scr, WMWidget *parent)
430 _Panel *panel;
432 panel = wmalloc(sizeof(_Panel));
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.");
438 panel->parent = parent;
439 panel->callbacks.createWidgets = createPanel;
440 panel->callbacks.updateDomain = storeData;
442 AddSection(panel, ICON_FILE);
444 return panel;