fixed bug of handling non string values in string type options in defaults.c
[wmaker-crm.git] / WPrefs.app / Icons.c
blobe7244bb2bae049497a3408df88f2670d01407285
1 /* Icons.c- icon preferences
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"
27 typedef struct _Panel {
28 WMFrame *frame;
30 char *sectionName;
32 char *description;
34 CallbackRec callbacks;
36 WMWindow *win;
38 WMFrame *posF;
39 WMFrame *posVF;
40 WMFrame *posV;
42 WMButton *posB[8];
44 WMFrame *animF;
45 WMButton *animB[4];
47 WMFrame *optF;
48 WMButton *arrB;
49 WMButton *omnB;
51 WMFrame *sizeF;
52 WMPopUpButton *sizeP;
54 int iconPos;
55 } _Panel;
59 #define ICON_FILE "iconprefs"
62 static void
63 showIconLayout(WMWidget *widget, void *data)
65 _Panel *panel = (_Panel*)data;
66 int w, h;
67 int i;
69 for (i=0; i<8; i++) {
70 if (panel->posB[i] == widget) {
71 panel->iconPos = i;
72 break;
76 if (panel->iconPos & 1) {
77 w = 32;
78 h = 8;
79 } else {
80 w = 8;
81 h = 32;
83 WMResizeWidget(panel->posV, w, h);
85 switch (panel->iconPos & ~1) {
86 case 0:
87 WMMoveWidget(panel->posV, 2, 2);
88 break;
89 case 2:
90 WMMoveWidget(panel->posV, 95-2-w, 2);
91 break;
92 case 4:
93 WMMoveWidget(panel->posV, 2, 70-2-h);
94 break;
95 default:
96 WMMoveWidget(panel->posV, 95-2-w, 70-2-h);
97 break;
102 #define MIN(a,b) ((a) < (b) ? (a) : (b))
104 static void
105 showData(_Panel *panel)
107 int i;
108 char *str;
109 char *def = "blh";
111 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
113 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
115 str = GetStringForKey("IconPosition");
116 if (!str)
117 str = def;
118 if (strlen(str)!=3) {
119 wwarning("bad value %s for option IconPosition. Using default blh",
120 str);
121 str = def;
124 if (str[0]=='t' || str[0]=='T') {
125 i = 0;
126 } else {
127 i = 4;
129 if (str[1]=='r' || str[1]=='R') {
130 i += 2;
132 if (str[2]=='v' || str[2]=='V') {
133 i += 0;
134 } else {
135 i += 1;
137 panel->iconPos = i;
138 WMPerformButtonClick(panel->posB[i]);
140 i = GetIntegerForKey("IconSize");
141 i = (i-24)/8;
143 if (i<0)
144 i = 0;
145 else if (i>9)
146 i = 9;
147 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
149 str = GetStringForKey("IconificationStyle");
150 if (!str)
151 str = "zoom";
152 if (strcasecmp(str, "none")==0)
153 WMPerformButtonClick(panel->animB[3]);
154 else if (strcasecmp(str, "twist")==0)
155 WMPerformButtonClick(panel->animB[1]);
156 else if (strcasecmp(str, "flip")==0)
157 WMPerformButtonClick(panel->animB[2]);
158 else {
159 WMPerformButtonClick(panel->animB[0]);
166 static void
167 createPanel(Panel *p)
169 _Panel *panel = (_Panel*)p;
170 WMColor *color;
171 int i;
172 char buf[16];
174 panel->frame = WMCreateFrame(panel->win);
175 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
176 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
178 /***************** Positioning of Icons *****************/
179 panel->posF = WMCreateFrame(panel->frame);
180 WMResizeWidget(panel->posF, 260, 135);
181 WMMoveWidget(panel->posF, 25, 10);
182 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
184 for (i=0; i<8; i++) {
185 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
186 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
188 if (i>0)
189 WMGroupButtons(panel->posB[0], panel->posB[i]);
191 WMMoveWidget(panel->posB[1], 70, 23);
192 WMResizeWidget(panel->posB[1], 47, 15);
193 WMMoveWidget(panel->posB[3], 70+47, 23);
194 WMResizeWidget(panel->posB[3], 47, 15);
196 WMMoveWidget(panel->posB[0], 55, 38);
197 WMResizeWidget(panel->posB[0], 15, 35);
198 WMMoveWidget(panel->posB[4], 55, 38+35);
199 WMResizeWidget(panel->posB[4], 15, 35);
201 WMMoveWidget(panel->posB[5], 70, 38+70);
202 WMResizeWidget(panel->posB[5], 47, 15);
203 WMMoveWidget(panel->posB[7], 70+47, 38+70);
204 WMResizeWidget(panel->posB[7], 47, 15);
206 WMMoveWidget(panel->posB[2], 70+95, 38);
207 WMResizeWidget(panel->posB[2], 15, 35);
208 WMMoveWidget(panel->posB[6], 70+95, 38+35);
209 WMResizeWidget(panel->posB[6], 15, 35);
211 color = WMCreateRGBColor(WMWidgetScreen(panel->win), 0x5100, 0x5100,
212 0x7100, True);
213 panel->posVF = WMCreateFrame(panel->posF);
214 WMResizeWidget(panel->posVF, 95, 70);
215 WMMoveWidget(panel->posVF, 70, 38);
216 WMSetFrameRelief(panel->posVF, WRSunken);
217 WMSetWidgetBackgroundColor(panel->posVF, color);
218 WMReleaseColor(color);
220 panel->posV = WMCreateFrame(panel->posVF);
221 WMSetFrameRelief(panel->posV, WRSimple);
223 WMMapSubwidgets(panel->posF);
225 /***************** Animation ****************/
226 panel->animF = WMCreateFrame(panel->frame);
227 WMResizeWidget(panel->animF, 205, 135);
228 WMMoveWidget(panel->animF, 295, 10);
229 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
231 for (i=0; i<4; i++) {
232 panel->animB[i] = WMCreateRadioButton(panel->animF);
233 WMResizeWidget(panel->animB[i], 170, 20);
234 WMMoveWidget(panel->animB[i], 20, 24+i*25);
236 WMGroupButtons(panel->animB[0], panel->animB[1]);
237 WMGroupButtons(panel->animB[0], panel->animB[2]);
238 WMGroupButtons(panel->animB[0], panel->animB[3]);
240 WMSetButtonText(panel->animB[0], _("Shrinking/Zooming"));
241 WMSetButtonText(panel->animB[1], _("Spinning/Twisting"));
242 WMSetButtonText(panel->animB[2], _("3D-flipping"));
243 WMSetButtonText(panel->animB[3], _("None"));
245 WMMapSubwidgets(panel->animF);
247 /***************** Options ****************/
248 panel->optF = WMCreateFrame(panel->frame);
249 WMResizeWidget(panel->optF, 260, 70);
250 WMMoveWidget(panel->optF, 25, 150);
251 /* WMSetFrameTitle(panel->optF, _("Icon Display"));*/
253 panel->arrB = WMCreateSwitchButton(panel->optF);
254 WMResizeWidget(panel->arrB, 235, 20);
255 WMMoveWidget(panel->arrB, 15, 15);
256 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
258 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."),
259 WMWidgetView(panel->arrB));
261 panel->omnB = WMCreateSwitchButton(panel->optF);
262 WMResizeWidget(panel->omnB, 235, 20);
263 WMMoveWidget(panel->omnB, 15, 40);
264 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
266 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."),
267 WMWidgetView(panel->omnB));
269 WMMapSubwidgets(panel->optF);
271 /***************** Icon Size ****************/
272 panel->sizeF = WMCreateFrame(panel->frame);
273 WMResizeWidget(panel->sizeF, 205, 70);
274 WMMoveWidget(panel->sizeF, 295, 150);
275 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
277 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
278 WMWidgetView(panel->sizeF));
280 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
281 WMResizeWidget(panel->sizeP, 156, 20);
282 WMMoveWidget(panel->sizeP, 25, 30);
283 for (i=24; i<=96; i+=8) {
284 sprintf(buf, "%ix%i", i, i);
285 WMAddPopUpButtonItem(panel->sizeP, buf);
288 WMMapSubwidgets(panel->sizeF);
290 WMRealizeWidget(panel->frame);
291 WMMapSubwidgets(panel->frame);
293 showData(panel);
297 static void
298 storeData(_Panel *panel)
300 char buf[8];
302 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
303 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
305 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP)*8+24,
306 "IconSize");
308 buf[3] = 0;
310 if (panel->iconPos < 4) {
311 buf[0] = 't';
312 } else {
313 buf[0] = 'b';
315 if (panel->iconPos & 2) {
316 buf[1] = 'r';
317 } else {
318 buf[1] = 'l';
320 if (panel->iconPos & 1) {
321 buf[2] = 'h';
322 } else {
323 buf[2] = 'v';
325 SetStringForKey(buf, "IconPosition");
327 if (WMGetButtonSelected(panel->animB[0]))
328 SetStringForKey("zoom", "IconificationStyle");
329 else if (WMGetButtonSelected(panel->animB[1]))
330 SetStringForKey("twist", "IconificationStyle");
331 else if (WMGetButtonSelected(panel->animB[2]))
332 SetStringForKey("flip", "IconificationStyle");
333 else
334 SetStringForKey("none", "IconificationStyle");
339 Panel*
340 InitIcons(WMScreen *scr, WMWindow *win)
342 _Panel *panel;
344 panel = wmalloc(sizeof(_Panel));
345 memset(panel, 0, sizeof(_Panel));
347 panel->sectionName = _("Icon Preferences");
349 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
350 "area, sizes of icons, miniaturization animation style.");
352 panel->win = win;
354 panel->callbacks.createWidgets = createPanel;
355 panel->callbacks.updateDomain = storeData;
357 AddSection(panel, ICON_FILE);
359 return panel;