Renamed "apercu" to "minipreview" in the source code
[wmaker-crm.git] / WPrefs.app / Icons.c
blobd8e11ab2b4ceec0b7db1c22a54315795418f5a93
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 WMButton *animB[wlengthof_nocheck(icon_animation)];
78 WMFrame *optF;
79 WMButton *arrB;
80 WMButton *omnB;
81 WMButton *sclB;
83 struct {
84 WMFrame *frame;
85 WMSlider *slider;
86 WMLabel *label;
87 } minipreview;
89 WMFrame *sizeF;
90 WMPopUpButton *sizeP;
92 int iconPos;
93 } _Panel;
96 * Minimum size for a Mini-Preview:
97 * This value is actually twice the size of the minimum icon size choosable.
98 * We set the slider min to taht number minus one, because when set to this
99 * value WPrefs will consider that the user wants the feature turned off.
101 static const int minipreview_minimum_size = 2 * 24 - 1;
103 static const int minipreview_maximum_size = 512; /* Arbitrary limit for the slider */
105 #define ICON_FILE "iconprefs"
107 static void showIconLayout(WMWidget * widget, void *data)
109 _Panel *panel = (_Panel *) data;
110 int w, h;
111 int i;
113 for (i = 0; i < wlengthof(panel->posB); i++) {
114 if (panel->posB[i] == widget) {
115 panel->iconPos = i;
116 break;
120 if (panel->iconPos & 1) {
121 w = 32;
122 h = 8;
123 } else {
124 w = 8;
125 h = 32;
127 WMResizeWidget(panel->posV, w, h);
129 switch (panel->iconPos & ~1) {
130 case 0:
131 WMMoveWidget(panel->posV, 2, 2);
132 break;
133 case 2:
134 WMMoveWidget(panel->posV, panel->icon_position.width - 2 - w, 2);
135 break;
136 case 4:
137 WMMoveWidget(panel->posV, 2, panel->icon_position.height - 2 - h);
138 break;
139 default:
140 WMMoveWidget(panel->posV, panel->icon_position.width - 2 - w, panel->icon_position.height - 2 - h);
141 break;
145 static void minipreview_slider_changed(WMWidget *w, void *data)
147 _Panel *panel = (_Panel *) data;
148 char buffer[64];
149 int value;
151 /* Parameter is not used, but tell the compiler that it is ok */
152 (void) w;
154 value = WMGetSliderValue(panel->minipreview.slider);
156 /* Round the value to a multiple of 8 because it makes the displayed value look better */
157 value &= ~7;
159 if (value <= minipreview_minimum_size)
160 sprintf(buffer, _("OFF"));
161 else
162 sprintf(buffer, "%i", value);
164 WMSetLabelText(panel->minipreview.label, buffer);
167 static void showData(_Panel * panel)
169 int i;
170 char *str;
171 Bool b;
173 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
174 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
175 WMSetButtonSelected(panel->sclB, GetBoolForKey("SingleClickLaunch"));
177 str = GetStringForKey("IconPosition");
178 if (str != NULL) {
179 for (i = 0; i < wlengthof(icon_position_dbvalue); i++)
180 if (strcmp(str, icon_position_dbvalue[i]) == 0) {
181 panel->iconPos = i;
182 goto found_position_value;
184 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
185 str, "IconPosition", icon_position_dbvalue[5]);
187 panel->iconPos = 5;
188 found_position_value:
189 WMPerformButtonClick(panel->posB[panel->iconPos]);
191 i = GetIntegerForKey("IconSize");
192 i = (i - 24) / 8;
194 if (i < 0)
195 i = 0;
196 else if (i > 9)
197 i = 9;
198 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
200 /* Mini-Previews for Icons */
201 b = GetBoolForKey("MiniwindowApercuBalloons");
202 if (b) {
203 i = GetIntegerForKey("ApercuSize");
204 if (i <= minipreview_minimum_size)
205 i = minipreview_minimum_size;
206 } else {
207 i = minipreview_minimum_size;
209 WMSetSliderValue(panel->minipreview.slider, i);
210 minipreview_slider_changed(panel->minipreview.slider, panel);
212 /* Animation */
213 str = GetStringForKey("IconificationStyle");
214 if (str != NULL) {
215 for (i = 0; i < wlengthof(icon_animation); i++) {
216 if (strcasecmp(str, icon_animation[i].db_value) == 0) {
217 WMPerformButtonClick(panel->animB[i]);
218 goto found_animation_value;
221 wwarning(_("animation style \"%s\" is unknown, resetting to \"%s\""),
222 str, icon_animation[0].db_value);
224 /* If we're here, no valid value have been found so we fall-back to the default */
225 WMPerformButtonClick(panel->animB[0]);
226 found_animation_value:
230 static void createPanel(Panel * p)
232 _Panel *panel = (_Panel *) p;
233 WMScreen *scr;
234 WMColor *color;
235 int i;
236 char buf[16];
237 int swidth, sheight;
238 int width, height;
239 int startx, starty;
241 panel->box = WMCreateBox(panel->parent);
242 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
244 /***************** Positioning of Icons *****************/
245 panel->posF = WMCreateFrame(panel->box);
246 WMResizeWidget(panel->posF, 268, 155);
247 WMMoveWidget(panel->posF, 12, 6);
248 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
251 * There is an available area of 240 x 122, starting at x=14 y=20
252 * We have to keep 14 pixels on each side for the buttons,
253 * and an extra pixel for spacing. We also want the final dimension
254 * to be an even number so we can have the 2 buttons per side of
255 * the same size.
256 * In this area, we want to have a rectangle with the same aspect
257 * ratio as the screen.
259 scr = WMWidgetScreen(panel->parent);
260 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
261 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
263 width = swidth * (122 - 15 * 2) / sheight;
264 if (width <= (240 - 15 * 2)) {
265 height = 122 - 15 * 2;
266 } else {
267 width = 240 - 15 * 2;
268 height = sheight * (240 - 15 * 2) / swidth;
271 panel->icon_position.width = width;
272 panel->icon_position.height = height;
274 startx = 14 + (240 - 15 * 2 - width) / 2;
275 starty = 20 + (122 - 15 * 2 - height) / 2;
277 for (i = 0; i < wlengthof(icon_position_dbvalue); i++) {
278 int x, y, w, h;
280 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
281 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
283 if (i > 0)
284 WMGroupButtons(panel->posB[0], panel->posB[i]);
286 if (i & 1) { /* 0=Vertical, 1=Horizontal */
287 w = width / 2;
288 h = 14;
289 } else {
290 w = 14;
291 h = height / 2;
293 WMResizeWidget(panel->posB[i], w, h);
295 x = startx;
296 y = starty;
297 switch (i) {
298 case 0: x += 0; y += 15; break;
299 case 1: x += 15; y += 0; break;
300 case 2: x += 15 + width; y += 15; break;
301 case 3: x += 15 + w; y += 0; break;
302 case 4: x += 0; y += 15 + h; break;
303 case 5: x += 15; y += 15 + height; break;
304 case 6: x += 15 + width; y += 15 + h; break;
305 case 7: x += 15 + w; y += 15 + height; break;
307 WMMoveWidget(panel->posB[i], x, y);
310 color = WMCreateRGBColor(WMWidgetScreen(panel->parent), 0x5100, 0x5100, 0x7100, True);
311 panel->posVF = WMCreateFrame(panel->posF);
312 WMResizeWidget(panel->posVF, width, height);
313 WMMoveWidget(panel->posVF, startx + 15, starty + 15);
314 WMSetFrameRelief(panel->posVF, WRSunken);
315 WMSetWidgetBackgroundColor(panel->posVF, color);
316 WMReleaseColor(color);
318 panel->posV = WMCreateFrame(panel->posVF);
319 WMSetFrameRelief(panel->posV, WRSimple);
321 WMMapSubwidgets(panel->posF);
323 /***************** Icon Size ****************/
324 panel->sizeF = WMCreateFrame(panel->box);
325 WMResizeWidget(panel->sizeF, 100, 52);
326 WMMoveWidget(panel->sizeF, 12, 168);
327 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
329 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
330 WMWidgetView(panel->sizeF));
332 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
333 WMResizeWidget(panel->sizeP, 80, 20);
334 WMMoveWidget(panel->sizeP, 10, 19);
335 for (i = 24; i <= 96; i += 8) {
336 sprintf(buf, "%ix%i", i, i);
337 WMAddPopUpButtonItem(panel->sizeP, buf);
340 WMMapSubwidgets(panel->sizeF);
342 /***************** Mini-Previews ****************/
343 panel->minipreview.frame = WMCreateFrame(panel->box);
344 WMResizeWidget(panel->minipreview.frame, 156, 52);
345 WMMoveWidget(panel->minipreview.frame, 124, 168);
346 WMSetFrameTitle(panel->minipreview.frame, _("Mini-Previews for Icons"));
348 WMSetBalloonTextForView(_("The Mini-Preview provides a small view of the content of the\n"
349 "window when the mouse is placed over the icon."),
350 WMWidgetView(panel->minipreview.frame));
352 panel->minipreview.slider = WMCreateSlider(panel->minipreview.frame);
353 WMResizeWidget(panel->minipreview.slider, 109, 15);
354 WMMoveWidget(panel->minipreview.slider, 11, 23);
355 WMSetSliderMinValue(panel->minipreview.slider, minipreview_minimum_size);
356 WMSetSliderMaxValue(panel->minipreview.slider, minipreview_maximum_size);
357 WMSetSliderAction(panel->minipreview.slider, minipreview_slider_changed, panel);
359 panel->minipreview.label = WMCreateLabel(panel->minipreview.frame);
360 WMResizeWidget(panel->minipreview.label, 33, 15);
361 WMMoveWidget(panel->minipreview.label, 120, 23);
362 WMSetLabelText(panel->minipreview.label, _("OFF"));
364 WMMapSubwidgets(panel->minipreview.frame);
366 /***************** Animation ****************/
367 panel->animF = WMCreateFrame(panel->box);
368 WMResizeWidget(panel->animF, 215, 110);
369 WMMoveWidget(panel->animF, 292, 6);
370 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
372 for (i = 0; i < wlengthof(icon_animation); i++) {
373 panel->animB[i] = WMCreateRadioButton(panel->animF);
374 WMResizeWidget(panel->animB[i], 192, 20);
375 WMMoveWidget(panel->animB[i], 12, 16 + i * 22);
377 if (i > 0)
378 WMGroupButtons(panel->animB[0], panel->animB[i]);
380 WMSetButtonText(panel->animB[i], _(icon_animation[i].label));
383 WMMapSubwidgets(panel->animF);
385 /***************** Options ****************/
386 panel->optF = WMCreateFrame(panel->box);
387 WMResizeWidget(panel->optF, 215, 90);
388 WMMoveWidget(panel->optF, 292, 130);
389 /* WMSetFrameTitle(panel->optF, _("Icon Display")); */
391 panel->arrB = WMCreateSwitchButton(panel->optF);
392 WMResizeWidget(panel->arrB, 198, 20);
393 WMMoveWidget(panel->arrB, 12, 10);
394 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
396 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."), WMWidgetView(panel->arrB));
398 panel->omnB = WMCreateSwitchButton(panel->optF);
399 WMResizeWidget(panel->omnB, 198, 20);
400 WMMoveWidget(panel->omnB, 12, 35);
401 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
403 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."), WMWidgetView(panel->omnB));
405 panel->sclB = WMCreateSwitchButton(panel->optF);
406 WMResizeWidget(panel->sclB, 198, 28);
407 WMMoveWidget(panel->sclB, 12, 56);
408 WMSetButtonText(panel->sclB, _("Single click activation"));
410 WMSetBalloonTextForView(_("Launch applications and restore windows with a single click."), WMWidgetView(panel->sclB));
412 WMMapSubwidgets(panel->optF);
414 WMRealizeWidget(panel->box);
415 WMMapSubwidgets(panel->box);
417 showData(panel);
420 static void storeData(_Panel * panel)
422 int i;
424 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
425 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
426 SetBoolForKey(WMGetButtonSelected(panel->sclB), "SingleClickLaunch");
428 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP) * 8 + 24, "IconSize");
430 SetStringForKey(icon_position_dbvalue[panel->iconPos], "IconPosition");
432 i = WMGetSliderValue(panel->minipreview.slider);
433 if (i <= minipreview_minimum_size) {
434 SetBoolForKey(False, "MiniwindowApercuBalloons");
435 } else {
436 SetBoolForKey(True, "MiniwindowApercuBalloons");
437 if (i < minipreview_maximum_size) {
439 * If the value is bigger, it means it was edited by the user manually
440 * so we keep as-is. Otherwise, we round it to a multiple of 8 like it
441 * was done for display
443 i &= ~7;
445 SetIntegerForKey(i, "ApercuSize");
448 for (i = 0; i < wlengthof(icon_animation); i++) {
449 if (WMGetButtonSelected(panel->animB[i])) {
450 SetStringForKey(icon_animation[i].db_value, "IconificationStyle");
451 break;
456 Panel *InitIcons(WMWidget *parent)
458 _Panel *panel;
460 panel = wmalloc(sizeof(_Panel));
462 panel->sectionName = _("Icon Preferences");
464 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
465 "area, sizes of icons, miniaturization animation style.");
467 panel->parent = parent;
469 panel->callbacks.createWidgets = createPanel;
470 panel->callbacks.updateDomain = storeData;
472 AddSection(panel, ICON_FILE);
474 return panel;