Code cleaning: removing trailing space
[wmaker-crm.git] / WPrefs.app / Icons.c
blob510a437f9e88a2284964c766b7411b73a99b8902
1 /* Icons.c- icon preferences
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"
25 static const struct {
26 const char *db_value;
27 const char *label;
28 } icon_animation[] = {
29 { "zoom", N_("Shrinking/Zooming") },
30 { "twist", N_("Spinning/Twisting") },
31 { "flip", N_("3D-flipping") },
32 { "none", N_("None") }
36 * The code is using a convenient trick to make the link between the icon
37 * position and its representing number:
38 * bit[0] tell if the icon are arranged horizontally or vertically
39 * bit[2:1] tell the corner to which they are starting from:
40 * bit[2] is for Top or Bottom choice
41 * bit[1] is for Left or Right choice
43 static const char icon_position_dbvalue[][4] = {
44 /* 000: */ "tlv",
45 /* 001: */ "tlh",
46 /* 010: */ "trv",
47 /* 011: */ "trh",
48 /* 100: */ "blv",
49 /* 101: */ "blh",
50 /* 110: */ "brv",
51 /* 111: */ "brh"
54 typedef struct _Panel {
55 WMBox *box;
57 char *sectionName;
59 char *description;
61 CallbackRec callbacks;
63 WMWidget *parent;
65 WMFrame *posF;
66 WMFrame *posVF;
67 WMFrame *posV;
69 struct {
70 int width, height;
71 } icon_position;
73 WMButton *posB[wlengthof_nocheck(icon_position_dbvalue)];
75 WMFrame *animF;
76 WMPopUpButton *animP;
78 WMFrame *optF;
79 WMButton *arrB;
80 WMButton *omnB;
81 WMButton *sclB;
82 WMButton *marginB;
84 struct {
85 WMFrame *frame;
86 WMSlider *slider;
87 WMLabel *label;
88 } minipreview;
90 WMFrame *sizeF;
91 WMPopUpButton *sizeP;
93 int iconPos;
94 } _Panel;
97 * Minimum size for a Mini-Preview:
98 * This value is actually twice the size of the minimum icon size choosable.
99 * We set the slider min to taht number minus one, because when set to this
100 * value WPrefs will consider that the user wants the feature turned off.
102 static const int minipreview_minimum_size = 2 * 24 - 1;
104 static const int minipreview_maximum_size = 512; /* Arbitrary limit for the slider */
106 #define ICON_FILE "iconprefs"
108 static void showIconLayout(WMWidget * widget, void *data)
110 _Panel *panel = (_Panel *) data;
111 int w, h;
112 int i;
114 for (i = 0; i < wlengthof(panel->posB); i++) {
115 if (panel->posB[i] == widget) {
116 panel->iconPos = i;
117 break;
121 if (panel->iconPos & 1) {
122 w = 32;
123 h = 8;
124 } else {
125 w = 8;
126 h = 32;
128 WMResizeWidget(panel->posV, w, h);
130 switch (panel->iconPos & ~1) {
131 case 0:
132 WMMoveWidget(panel->posV, 2, 2);
133 break;
134 case 2:
135 WMMoveWidget(panel->posV, panel->icon_position.width - 2 - w, 2);
136 break;
137 case 4:
138 WMMoveWidget(panel->posV, 2, panel->icon_position.height - 2 - h);
139 break;
140 default:
141 WMMoveWidget(panel->posV, panel->icon_position.width - 2 - w, panel->icon_position.height - 2 - h);
142 break;
146 static void minipreview_slider_changed(WMWidget *w, void *data)
148 _Panel *panel = (_Panel *) data;
149 char buffer[64];
150 int value;
152 /* Parameter is not used, but tell the compiler that it is ok */
153 (void) w;
155 value = WMGetSliderValue(panel->minipreview.slider);
157 /* Round the value to a multiple of 8 because it makes the displayed value look better */
158 value &= ~7;
160 if (value <= minipreview_minimum_size)
161 sprintf(buffer, _("OFF"));
162 else
163 sprintf(buffer, "%i", value);
165 WMSetLabelText(panel->minipreview.label, buffer);
168 static void showData(_Panel * panel)
170 int i;
171 char *str;
172 Bool b;
174 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
175 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
176 WMSetButtonSelected(panel->sclB, GetBoolForKey("SingleClickLaunch"));
177 WMSetButtonSelected(panel->marginB, GetBoolForKey("EnforceIconMargin"));
179 str = GetStringForKey("IconPosition");
180 if (str != NULL) {
181 for (i = 0; i < wlengthof(icon_position_dbvalue); i++)
182 if (strcmp(str, icon_position_dbvalue[i]) == 0) {
183 panel->iconPos = i;
184 goto found_position_value;
186 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
187 str, "IconPosition", icon_position_dbvalue[5]);
189 panel->iconPos = 5;
190 found_position_value:
191 WMPerformButtonClick(panel->posB[panel->iconPos]);
193 i = GetIntegerForKey("IconSize");
194 i = (i - 24) / 8;
196 if (i < 0)
197 i = 0;
198 else if (i > 29)
199 i = 29;
200 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
202 /* Mini-Previews for Icons */
204 str = GetStringForKey("MiniwindowPreviewBalloons");
205 if (str != NULL) {
206 /* New names found, use them in priority */
207 b = GetBoolForKey("MiniwindowPreviewBalloons");
208 if (b) {
209 i = GetIntegerForKey("MiniPreviewSize");
210 if (i <= minipreview_minimum_size)
211 i = minipreview_minimum_size;
212 } else {
213 i = minipreview_minimum_size;
216 WMSetSliderValue(panel->minipreview.slider, i);
217 minipreview_slider_changed(panel->minipreview.slider, panel);
219 /* Animation */
220 str = GetStringForKey("IconificationStyle");
221 if (str != NULL) {
222 for (i = 0; i < wlengthof(icon_animation); i++) {
223 if (strcasecmp(str, icon_animation[i].db_value) == 0) {
224 WMSetPopUpButtonSelectedItem(panel->animP, i);
225 goto found_animation_value;
228 wwarning(_("animation style \"%s\" is unknown, resetting to \"%s\""),
229 str, icon_animation[0].db_value);
231 /* If we're here, no valid value have been found so we fall-back to the default */
232 WMSetPopUpButtonSelectedItem(panel->animP, 0);
233 found_animation_value:
237 static void createPanel(Panel * p)
239 _Panel *panel = (_Panel *) p;
240 WMScreen *scr;
241 WMColor *color;
242 int i;
243 char buf[16];
244 int swidth, sheight;
245 int width, height;
246 int startx, starty;
248 panel->box = WMCreateBox(panel->parent);
249 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
251 /***************** Positioning of Icons *****************/
252 panel->posF = WMCreateFrame(panel->box);
253 WMResizeWidget(panel->posF, 268, 155);
254 WMMoveWidget(panel->posF, 12, 6);
255 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
258 * There is an available area of 240 x 122, starting at x=14 y=20
259 * We have to keep 14 pixels on each side for the buttons,
260 * and an extra pixel for spacing. We also want the final dimension
261 * to be an even number so we can have the 2 buttons per side of
262 * the same size.
263 * In this area, we want to have a rectangle with the same aspect
264 * ratio as the screen.
266 scr = WMWidgetScreen(panel->parent);
267 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
268 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
270 width = swidth * (122 - 15 * 2) / sheight;
271 if (width <= (240 - 15 * 2)) {
272 height = 122 - 15 * 2;
273 } else {
274 width = 240 - 15 * 2;
275 height = sheight * (240 - 15 * 2) / swidth;
278 panel->icon_position.width = width;
279 panel->icon_position.height = height;
281 startx = 14 + (240 - 15 * 2 - width) / 2;
282 starty = 20 + (122 - 15 * 2 - height) / 2;
284 for (i = 0; i < wlengthof(icon_position_dbvalue); i++) {
285 int x, y, w, h;
287 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
288 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
290 if (i > 0)
291 WMGroupButtons(panel->posB[0], panel->posB[i]);
293 if (i & 1) { /* 0=Vertical, 1=Horizontal */
294 w = width / 2;
295 h = 14;
296 } else {
297 w = 14;
298 h = height / 2;
300 WMResizeWidget(panel->posB[i], w, h);
302 x = startx;
303 y = starty;
304 switch (i) {
305 case 0: x += 0; y += 15; break;
306 case 1: x += 15; y += 0; break;
307 case 2: x += 15 + width; y += 15; break;
308 case 3: x += 15 + w; y += 0; break;
309 case 4: x += 0; y += 15 + h; break;
310 case 5: x += 15; y += 15 + height; break;
311 case 6: x += 15 + width; y += 15 + h; break;
312 case 7: x += 15 + w; y += 15 + height; break;
314 WMMoveWidget(panel->posB[i], x, y);
317 color = WMCreateRGBColor(WMWidgetScreen(panel->parent), 0x5100, 0x5100, 0x7100, True);
318 panel->posVF = WMCreateFrame(panel->posF);
319 WMResizeWidget(panel->posVF, width, height);
320 WMMoveWidget(panel->posVF, startx + 15, starty + 15);
321 WMSetFrameRelief(panel->posVF, WRSunken);
322 WMSetWidgetBackgroundColor(panel->posVF, color);
323 WMReleaseColor(color);
325 panel->posV = WMCreateFrame(panel->posVF);
326 WMSetFrameRelief(panel->posV, WRSimple);
328 WMMapSubwidgets(panel->posF);
330 /***************** Icon Size ****************/
331 panel->sizeF = WMCreateFrame(panel->box);
332 WMResizeWidget(panel->sizeF, 100, 52);
333 WMMoveWidget(panel->sizeF, 12, 168);
334 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
336 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
337 WMWidgetView(panel->sizeF));
339 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
340 WMResizeWidget(panel->sizeP, 80, 20);
341 WMMoveWidget(panel->sizeP, 10, 19);
342 for (i = 24; i <= 256; i += 8) {
343 sprintf(buf, "%ix%i", i, i);
344 WMAddPopUpButtonItem(panel->sizeP, buf);
347 WMMapSubwidgets(panel->sizeF);
349 /***************** Mini-Previews ****************/
350 panel->minipreview.frame = WMCreateFrame(panel->box);
351 WMResizeWidget(panel->minipreview.frame, 156, 52);
352 WMMoveWidget(panel->minipreview.frame, 124, 168);
353 WMSetFrameTitle(panel->minipreview.frame, _("Mini-Previews for Icons"));
355 WMSetBalloonTextForView(_("The Mini-Preview provides a small view of the content of the\n"
356 "window when the mouse is placed over the icon."),
357 WMWidgetView(panel->minipreview.frame));
359 panel->minipreview.slider = WMCreateSlider(panel->minipreview.frame);
360 WMResizeWidget(panel->minipreview.slider, 109, 15);
361 WMMoveWidget(panel->minipreview.slider, 11, 23);
362 WMSetSliderMinValue(panel->minipreview.slider, minipreview_minimum_size);
363 WMSetSliderMaxValue(panel->minipreview.slider, minipreview_maximum_size);
364 WMSetSliderAction(panel->minipreview.slider, minipreview_slider_changed, panel);
366 panel->minipreview.label = WMCreateLabel(panel->minipreview.frame);
367 WMResizeWidget(panel->minipreview.label, 33, 15);
368 WMMoveWidget(panel->minipreview.label, 120, 23);
369 WMSetLabelText(panel->minipreview.label, _("OFF"));
371 WMMapSubwidgets(panel->minipreview.frame);
373 /***************** Animation ****************/
374 panel->animF = WMCreateFrame(panel->box);
375 WMResizeWidget(panel->animF, 215, 52);
376 WMMoveWidget(panel->animF, 292, 6);
377 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
379 panel->animP = WMCreatePopUpButton(panel->animF);
380 WMResizeWidget(panel->animP, 195, 20);
381 WMMoveWidget(panel->animP, 10, 19);
382 for (i = 0; i < wlengthof(icon_animation); i++)
383 WMAddPopUpButtonItem(panel->animP, _(icon_animation[i].label));
385 WMMapSubwidgets(panel->animF);
387 /***************** Options ****************/
388 panel->optF = WMCreateFrame(panel->box);
389 WMResizeWidget(panel->optF, 215, 148);
390 WMMoveWidget(panel->optF, 292, 72);
391 /* WMSetFrameTitle(panel->optF, _("Icon Display")); */
392 starty = 8 + 14; /* the last term centers the checkboxes within the panel; subtract 13 for a new option */
394 panel->arrB = WMCreateSwitchButton(panel->optF);
395 WMResizeWidget(panel->arrB, 198, 26);
396 WMMoveWidget(panel->arrB, 12, starty);
397 starty += 26;
398 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
400 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."), WMWidgetView(panel->arrB));
402 panel->omnB = WMCreateSwitchButton(panel->optF);
403 WMResizeWidget(panel->omnB, 198, 26);
404 WMMoveWidget(panel->omnB, 12, starty);
405 starty += 26;
406 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
408 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."), WMWidgetView(panel->omnB));
410 panel->sclB = WMCreateSwitchButton(panel->optF);
411 WMResizeWidget(panel->sclB, 198, 26);
412 WMMoveWidget(panel->sclB, 12, starty);
413 starty += 26;
414 WMSetButtonText(panel->sclB, _("Single click activation"));
416 WMSetBalloonTextForView(_("Launch applications and restore windows with a single click."), WMWidgetView(panel->sclB));
418 panel->marginB = WMCreateSwitchButton(panel->optF);
419 WMResizeWidget(panel->marginB, 198, 26);
420 WMMoveWidget(panel->marginB, 12, starty);
421 starty += 26;
422 WMSetButtonText(panel->marginB, _("Enforce icon margin"));
424 WMSetBalloonTextForView(_("Make sure that the icon image does not protrude into the icon frame."), WMWidgetView(panel->marginB));
426 WMMapSubwidgets(panel->optF);
428 WMRealizeWidget(panel->box);
429 WMMapSubwidgets(panel->box);
431 showData(panel);
434 static void storeData(_Panel * panel)
436 int i;
438 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
439 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
440 SetBoolForKey(WMGetButtonSelected(panel->sclB), "SingleClickLaunch");
441 SetBoolForKey(WMGetButtonSelected(panel->marginB), "EnforceIconMargin");
443 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP) * 8 + 24, "IconSize");
445 SetStringForKey(icon_position_dbvalue[panel->iconPos], "IconPosition");
447 i = WMGetSliderValue(panel->minipreview.slider);
448 if (i <= minipreview_minimum_size) {
449 SetBoolForKey(False, "MiniwindowPreviewBalloons");
450 } else {
451 SetBoolForKey(True, "MiniwindowPreviewBalloons");
452 if (i < minipreview_maximum_size) {
454 * If the value is bigger, it means it was edited by the user manually
455 * so we keep as-is. Otherwise, we round it to a multiple of 8 like it
456 * was done for display
458 i &= ~7;
460 SetIntegerForKey(i, "MiniPreviewSize");
463 SetStringForKey(icon_animation[WMGetPopUpButtonSelectedItem(panel->animP)].db_value, "IconificationStyle");
466 Panel *InitIcons(WMWidget *parent)
468 _Panel *panel;
470 panel = wmalloc(sizeof(_Panel));
472 panel->sectionName = _("Icon Preferences");
474 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
475 "area, sizes of icons, miniaturization animation style.");
477 panel->parent = parent;
479 panel->callbacks.createWidgets = createPanel;
480 panel->callbacks.updateDomain = storeData;
482 AddSection(panel, ICON_FILE);
484 return panel;