added balloon help
[wmaker-crm.git] / WPrefs.app / Configurations.c
blob9989d967127aefbffe9fa74d4e2dfaece8c9f8cb
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 char *description;
32 CallbackRec callbacks;
34 WMWindow *win;
36 WMFrame *icoF;
37 WMButton *icoB[5];
39 WMFrame *shaF;
40 WMButton *shaB[5];
42 WMFrame *titlF;
43 WMButton *oldsB;
44 WMButton *newsB;
46 WMFrame *animF;
47 WMButton *animB;
48 WMButton *supB;
49 WMButton *sfxB;
50 WMLabel *noteL;
52 WMFrame *dithF;
53 WMButton *dithB;
54 WMSlider *dithS;
55 WMLabel *dithL;
56 WMLabel *dith1L;
57 WMLabel *dith2L;
59 int cmapSize;
60 } _Panel;
64 #define ICON_FILE "configs"
66 #define OLDS_IMAGE "oldstyle"
67 #define NEWS_IMAGE "newstyle"
69 #define ANIM_IMAGE "animations"
70 #define SUPERF_IMAGE "moreanim"
71 #define SOUND_IMAGE "sound"
73 #define SPEED_IMAGE "speed%i"
74 #define SPEED_IMAGE_S "speed%is"
76 #define ARQUIVO_XIS "xis"
79 static void updateLabel(WMWidget *self, void *data);
82 static void
83 showData(_Panel *panel)
85 WMPerformButtonClick(panel->icoB[GetSpeedForKey("IconSlideSpeed")]);
87 WMPerformButtonClick(panel->shaB[GetSpeedForKey("ShadeSpeed")]);
89 if (GetBoolForKey("NewStyle")) {
90 WMPerformButtonClick(panel->newsB);
91 } else {
92 WMPerformButtonClick(panel->oldsB);
95 WMSetButtonSelected(panel->animB, !GetBoolForKey("DisableAnimations"));
97 WMSetButtonSelected(panel->supB, GetBoolForKey("Superfluous"));
99 WMSetButtonSelected(panel->sfxB, !GetBoolForKey("DisableSound"));
101 WMSetButtonSelected(panel->dithB, GetBoolForKey("DisableDithering"));
103 WMSetSliderValue(panel->dithS, GetIntegerForKey("ColormapSize"));
105 updateLabel(panel->dithS, panel);
109 static void
110 updateLabel(WMWidget *self, void *data)
112 WMSlider *sPtr = (WMSlider*)self;
113 _Panel *panel = (_Panel*)data;
114 char buffer[64];
115 float fl;
117 fl = WMGetSliderValue(sPtr);
119 panel->cmapSize = (int)fl;
121 sprintf(buffer, "%i", panel->cmapSize*panel->cmapSize*panel->cmapSize);
122 WMSetLabelText(panel->dithL, buffer);
126 static void
127 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
128 WMPixmap **icon1, WMPixmap **icon2)
130 RImage *icon;
131 char *path;
132 RColor gray = {0xae,0xaa,0xae};
134 *icon1 = NULL;
135 *icon2 = NULL;
137 path = LocateImage(file);
138 if (!path) {
139 return;
142 *icon1 = WMCreatePixmapFromFile(scr, path);
143 if (!*icon1) {
144 wwarning(_("could not load icon %s"), path);
145 free(path);
146 return;
148 icon = RLoadImage(rc, path, 0);
149 if (!icon) {
150 wwarning(_("could not load icon %s"), path);
151 free(path);
152 return;
154 RCombineImageWithColor(icon, &gray);
155 if (xis) {
156 RCombineImagesWithOpaqueness(icon, xis, 180);
157 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127)))
158 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
160 RDestroyImage(icon);
161 free(path);
166 static void
167 createPanel(Panel *p)
169 _Panel *panel = (_Panel*)p;
170 WMScreen *scr = WMWidgetScreen(panel->win);
171 char *buf1, *buf2;
172 WMPixmap *icon, *altIcon;
173 RImage *xis = NULL;
174 int i;
175 RContext *rc = WMScreenRContext(scr);
176 WMFont *font = WMSystemFontOfSize(scr, 10);
177 char *path;
179 path = LocateImage(ARQUIVO_XIS);
180 if (path) {
181 xis = RLoadImage(rc, path, 0);
182 if (!xis) {
183 wwarning(_("could not load image file %s"), path);
185 free(path);
188 panel->frame = WMCreateFrame(panel->win);
189 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
190 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
192 /*********** Icon Slide Speed **********/
194 panel->icoF = WMCreateFrame(panel->frame);
195 WMResizeWidget(panel->icoF, 230, 55);
196 WMMoveWidget(panel->icoF, 15, 10);
197 WMSetFrameTitle(panel->icoF, _("Icon Slide Speed"));
199 /*********** Shade Animation Speed **********/
200 panel->shaF = WMCreateFrame(panel->frame);
201 WMResizeWidget(panel->shaF, 230, 55);
202 WMMoveWidget(panel->shaF, 15, 70);
203 WMSetFrameTitle(panel->shaF, _("Shade Animation Speed"));
206 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
207 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
209 for (i = 0; i < 5; i++) {
210 panel->icoB[i] = WMCreateCustomButton(panel->icoF, WBBStateChangeMask);
211 panel->shaB[i] = WMCreateCustomButton(panel->shaF, WBBStateChangeMask);
212 WMResizeWidget(panel->icoB[i], 40, 35);
213 WMMoveWidget(panel->icoB[i], 10+(40*i), 15);
214 WMResizeWidget(panel->shaB[i], 40, 35);
215 WMMoveWidget(panel->shaB[i], 10+(40*i), 15);
216 WMSetButtonBordered(panel->icoB[i], False);
217 WMSetButtonImagePosition(panel->icoB[i], WIPImageOnly);
218 if (i > 0) {
219 WMGroupButtons(panel->icoB[0], panel->icoB[i]);
221 WMSetButtonBordered(panel->shaB[i], False);
222 WMSetButtonImagePosition(panel->shaB[i], WIPImageOnly);
223 if (i > 0) {
224 WMGroupButtons(panel->shaB[0], panel->shaB[i]);
226 sprintf(buf1, SPEED_IMAGE, i);
227 sprintf(buf2, SPEED_IMAGE_S, i);
228 path = LocateImage(buf1);
229 if (path) {
230 icon = WMCreatePixmapFromFile(scr, path);
231 if (icon) {
232 WMSetButtonImage(panel->icoB[i], icon);
233 WMSetButtonImage(panel->shaB[i], icon);
234 WMReleasePixmap(icon);
235 } else {
236 wwarning(_("could not load icon file %s"), path);
238 free(path);
240 path = LocateImage(buf2);
241 if (path) {
242 icon = WMCreatePixmapFromFile(scr, path);
243 if (icon) {
244 WMSetButtonAltImage(panel->icoB[i], icon);
245 WMSetButtonAltImage(panel->shaB[i], icon);
246 WMReleasePixmap(icon);
247 } else {
248 wwarning(_("could not load icon file %s"), path);
250 free(path);
253 free(buf1);
254 free(buf2);
257 WMMapSubwidgets(panel->icoF);
258 WMMapSubwidgets(panel->shaF);
260 /***************** Titlebar Style Size ****************/
261 panel->titlF = WMCreateFrame(panel->frame);
262 WMResizeWidget(panel->titlF, 230, 95);
263 WMMoveWidget(panel->titlF, 15, 130);
264 WMSetFrameTitle(panel->titlF, _("Titlebar Style"));
266 panel->newsB = WMCreateButton(panel->titlF, WBTOnOff);
267 WMResizeWidget(panel->newsB, 90, 60);
268 WMMoveWidget(panel->newsB, 25, 20);
269 WMSetButtonImagePosition(panel->newsB, WIPImageOnly);
270 path = LocateImage(NEWS_IMAGE);
271 if (path) {
272 icon = WMCreatePixmapFromFile(scr, path);
273 if (icon) {
274 WMSetButtonImage(panel->newsB, icon);
275 WMReleasePixmap(icon);
279 panel->oldsB = WMCreateButton(panel->titlF, WBTOnOff);
280 WMResizeWidget(panel->oldsB, 90, 60);
281 WMMoveWidget(panel->oldsB, 115, 20);
282 WMSetButtonImagePosition(panel->oldsB, WIPImageOnly);
283 path = LocateImage(OLDS_IMAGE);
284 if (path) {
285 icon = WMCreatePixmapFromFile(scr, path);
286 if (icon) {
287 WMSetButtonImage(panel->oldsB, icon);
288 WMReleasePixmap(icon);
292 WMGroupButtons(panel->newsB, panel->oldsB);
294 WMMapSubwidgets(panel->titlF);
296 /**************** Features ******************/
298 panel->animF = WMCreateFrame(panel->frame);
299 WMResizeWidget(panel->animF, 255, 115);
300 WMMoveWidget(panel->animF, 255, 10);
301 WMSetFrameTitle(panel->animF, _("Animations and Sound"));
303 panel->animB = WMCreateButton(panel->animF, WBTToggle);
304 WMResizeWidget(panel->animB, 64, 64);
305 WMMoveWidget(panel->animB, 15, 20);
306 WMSetButtonFont(panel->animB, font);
307 WMSetButtonText(panel->animB, _("Animations"));
308 WMSetButtonImagePosition(panel->animB, WIPAbove);
309 createImages(scr, rc, xis, ANIM_IMAGE, &altIcon, &icon);
310 if (icon) {
311 WMSetButtonImage(panel->animB, icon);
312 WMReleasePixmap(icon);
314 if (altIcon) {
315 WMSetButtonAltImage(panel->animB, altIcon);
316 WMReleasePixmap(altIcon);
318 WMSetBalloonTextForView(_("Disable/enable animations such as those shown\n"
319 "for window miniaturization, shading etc."),
320 WMWidgetView(panel->animB));
322 panel->supB = WMCreateButton(panel->animF, WBTToggle);
323 WMResizeWidget(panel->supB, 64, 64);
324 WMMoveWidget(panel->supB, 95, 20);
325 WMSetButtonFont(panel->supB, font);
326 WMSetButtonText(panel->supB, _("Superfluous"));
327 WMSetButtonImagePosition(panel->supB, WIPAbove);
328 createImages(scr, rc, xis, SUPERF_IMAGE, &altIcon, &icon);
329 if (icon) {
330 WMSetButtonImage(panel->supB, icon);
331 WMReleasePixmap(icon);
333 if (altIcon) {
334 WMSetButtonAltImage(panel->supB, altIcon);
335 WMReleasePixmap(altIcon);
337 WMSetBalloonTextForView(_("Disable/enable `superfluous' features and\n"
338 "animations. These include the `ghosting' of the\n"
339 "dock when it's being moved to the another side\n"
340 "and the explosion animation for undocked icons."),
341 WMWidgetView(panel->supB));
343 panel->sfxB = WMCreateButton(panel->animF, WBTToggle);
344 WMResizeWidget(panel->sfxB, 64, 64);
345 WMMoveWidget(panel->sfxB, 175, 20);
346 WMSetButtonFont(panel->sfxB, font);
347 WMSetButtonText(panel->sfxB, _("Sounds"));
348 WMSetButtonImagePosition(panel->sfxB, WIPAbove);
349 createImages(scr, rc, xis, SOUND_IMAGE, &altIcon, &icon);
350 if (icon) {
351 WMSetButtonImage(panel->sfxB, icon);
352 WMReleasePixmap(icon);
354 if (altIcon) {
355 WMSetButtonAltImage(panel->sfxB, altIcon);
356 WMReleasePixmap(altIcon);
358 WMSetBalloonTextForView(_("Disable/enable support for sound effects played\n"
359 "for actions like shading and closing a window.\n"
360 "You will need a module distributed separately\n"
361 "for this. You can get it at:\n"
362 "http://www.frontiernet.net/~southgat/wmsound"),
363 WMWidgetView(panel->sfxB));
365 panel->noteL = WMCreateLabel(panel->animF);
366 WMResizeWidget(panel->noteL, 235, 28);
367 WMMoveWidget(panel->noteL, 10, 85);
368 WMSetLabelFont(panel->noteL, font);
369 WMSetLabelText(panel->noteL, _("Note: sound requires a module distributed separately"));
371 WMMapSubwidgets(panel->animF);
373 /*********** Dithering **********/
374 panel->cmapSize = 4;
376 panel->dithF = WMCreateFrame(panel->frame);
377 WMResizeWidget(panel->dithF, 255, 95);
378 WMMoveWidget(panel->dithF, 255, 130);
379 WMSetFrameTitle(panel->dithF, _("Dithering colormap for 8bpp"));
381 WMSetBalloonTextForView(_("Number of colors to reserve for Window Maker\n"
382 "on displays that support only 8bpp (PseudoColor)."),
383 WMWidgetView(panel->dithF));
385 panel->dithB = WMCreateSwitchButton(panel->dithF);
386 WMResizeWidget(panel->dithB, 235, 32);
387 WMMoveWidget(panel->dithB, 15, 15);
388 WMSetButtonText(panel->dithB, _("Disable dithering in any visual/depth"));
390 panel->dithL = WMCreateLabel(panel->dithF);
391 WMResizeWidget(panel->dithL, 75, 16);
392 WMMoveWidget(panel->dithL, 90, 50);
393 WMSetLabelTextAlignment(panel->dithL, WACenter);
394 WMSetLabelText(panel->dithL, "64");
396 panel->dithS = WMCreateSlider(panel->dithF);
397 WMResizeWidget(panel->dithS, 95, 16);
398 WMMoveWidget(panel->dithS, 80, 65);
399 WMSetSliderMinValue(panel->dithS, 2);
400 WMSetSliderMaxValue(panel->dithS, 6);
401 WMSetSliderContinuous(panel->dithS, True);
402 WMSetSliderAction(panel->dithS, updateLabel, panel);
404 panel->dith1L = WMCreateLabel(panel->dithF);
405 WMResizeWidget(panel->dith1L, 70, 35);
406 WMMoveWidget(panel->dith1L, 5, 50);
407 WMSetLabelTextAlignment(panel->dith1L, WACenter);
408 WMSetLabelFont(panel->dith1L, font);
409 WMSetLabelText(panel->dith1L, _("More colors for applications"));
411 panel->dith2L = WMCreateLabel(panel->dithF);
412 WMResizeWidget(panel->dith2L, 70, 35);
413 WMMoveWidget(panel->dith2L, 180, 50);
414 WMSetLabelTextAlignment(panel->dith2L, WACenter);
415 WMSetLabelFont(panel->dith2L, font);
416 WMSetLabelText(panel->dith2L, _("More colors for WindowMaker"));
418 WMMapSubwidgets(panel->dithF);
420 WMRealizeWidget(panel->frame);
421 WMMapSubwidgets(panel->frame);
423 if (xis)
424 RDestroyImage(xis);
425 WMReleaseFont(font);
427 showData(panel);
431 static void
432 storeData(_Panel *panel)
434 int i;
436 for (i=0; i<5; i++) {
437 if (WMGetButtonSelected(panel->icoB[i]))
438 break;
440 SetSpeedForKey(i, "IconSlideSpeed");
443 for (i=0; i<5; i++) {
444 if (WMGetButtonSelected(panel->shaB[i]))
445 break;
447 SetSpeedForKey(i, "ShadeSpeed");
449 SetBoolForKey(WMGetButtonSelected(panel->newsB), "NewStyle");
451 SetBoolForKey(!WMGetButtonSelected(panel->animB), "DisableAnimations");
452 SetBoolForKey(WMGetButtonSelected(panel->supB), "Superfluous");
453 SetBoolForKey(!WMGetButtonSelected(panel->sfxB), "DisableSound");
455 SetBoolForKey(WMGetButtonSelected(panel->dithB), "DisableDithering");
456 SetIntegerForKey(WMGetSliderValue(panel->dithS), "ColormapSize");
461 Panel*
462 InitConfigurations(WMScreen *scr, WMWindow *win)
464 _Panel *panel;
466 panel = wmalloc(sizeof(_Panel));
467 memset(panel, 0, sizeof(_Panel));
469 panel->sectionName = _("Other Configurations");
471 panel->description = _("Animation speeds, titlebar styles, various option\n"
472 "toggling and number of colors to reserve for\n"
473 "Window Maker in 8bit displays.");
475 panel->win = win;
477 panel->callbacks.createWidgets = createPanel;
478 panel->callbacks.updateDomain = storeData;
480 AddSection(panel, ICON_FILE);
482 return panel;