added better proplist warnings when reading non-digit proplist data and fixed screwed...
[wmaker-crm.git] / WPrefs.app / Icons.c
blob31470df633eb3fdd7b822aa01eed349d21fcd506
1 /* Icons.c- icon preferences
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2002 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 WMBox *box;
30 char *sectionName;
32 char *description;
34 CallbackRec callbacks;
36 WMWidget *parent;
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 static void
103 showData(_Panel *panel)
105 int i;
106 char *str;
107 char *def = "blh";
109 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
111 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
113 str = GetStringForKey("IconPosition");
114 if (!str)
115 str = def;
116 if (strlen(str)!=3) {
117 wwarning("bad value %s for option IconPosition. Using default blh",
118 str);
119 str = def;
122 if (str[0]=='t' || str[0]=='T') {
123 i = 0;
124 } else {
125 i = 4;
127 if (str[1]=='r' || str[1]=='R') {
128 i += 2;
130 if (str[2]=='v' || str[2]=='V') {
131 i += 0;
132 } else {
133 i += 1;
135 panel->iconPos = i;
136 WMPerformButtonClick(panel->posB[i]);
138 i = GetIntegerForKey("IconSize");
139 i = (i-24)/8;
141 if (i<0)
142 i = 0;
143 else if (i>9)
144 i = 9;
145 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
147 str = GetStringForKey("IconificationStyle");
148 if (!str)
149 str = "zoom";
150 if (strcasecmp(str, "none")==0)
151 WMPerformButtonClick(panel->animB[3]);
152 else if (strcasecmp(str, "twist")==0)
153 WMPerformButtonClick(panel->animB[1]);
154 else if (strcasecmp(str, "flip")==0)
155 WMPerformButtonClick(panel->animB[2]);
156 else {
157 WMPerformButtonClick(panel->animB[0]);
164 static void
165 createPanel(Panel *p)
167 _Panel *panel = (_Panel*)p;
168 WMColor *color;
169 int i;
170 char buf[16];
173 panel->box = WMCreateBox(panel->parent);
174 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
176 /***************** Positioning of Icons *****************/
177 panel->posF = WMCreateFrame(panel->box);
178 WMResizeWidget(panel->posF, 260, 135);
179 WMMoveWidget(panel->posF, 25, 10);
180 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
182 for (i=0; i<8; i++) {
183 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
184 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
186 if (i>0)
187 WMGroupButtons(panel->posB[0], panel->posB[i]);
189 WMMoveWidget(panel->posB[1], 70, 23);
190 WMResizeWidget(panel->posB[1], 47, 15);
191 WMMoveWidget(panel->posB[3], 70+47, 23);
192 WMResizeWidget(panel->posB[3], 47, 15);
194 WMMoveWidget(panel->posB[0], 55, 38);
195 WMResizeWidget(panel->posB[0], 15, 35);
196 WMMoveWidget(panel->posB[4], 55, 38+35);
197 WMResizeWidget(panel->posB[4], 15, 35);
199 WMMoveWidget(panel->posB[5], 70, 38+70);
200 WMResizeWidget(panel->posB[5], 47, 15);
201 WMMoveWidget(panel->posB[7], 70+47, 38+70);
202 WMResizeWidget(panel->posB[7], 47, 15);
204 WMMoveWidget(panel->posB[2], 70+95, 38);
205 WMResizeWidget(panel->posB[2], 15, 35);
206 WMMoveWidget(panel->posB[6], 70+95, 38+35);
207 WMResizeWidget(panel->posB[6], 15, 35);
209 color = WMCreateRGBColor(WMWidgetScreen(panel->parent), 0x5100, 0x5100,
210 0x7100, True);
211 panel->posVF = WMCreateFrame(panel->posF);
212 WMResizeWidget(panel->posVF, 95, 70);
213 WMMoveWidget(panel->posVF, 70, 38);
214 WMSetFrameRelief(panel->posVF, WRSunken);
215 WMSetWidgetBackgroundColor(panel->posVF, color);
216 WMReleaseColor(color);
218 panel->posV = WMCreateFrame(panel->posVF);
219 WMSetFrameRelief(panel->posV, WRSimple);
221 WMMapSubwidgets(panel->posF);
223 /***************** Animation ****************/
224 panel->animF = WMCreateFrame(panel->box);
225 WMResizeWidget(panel->animF, 205, 135);
226 WMMoveWidget(panel->animF, 295, 10);
227 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
229 for (i=0; i<4; i++) {
230 panel->animB[i] = WMCreateRadioButton(panel->animF);
231 WMResizeWidget(panel->animB[i], 170, 20);
232 WMMoveWidget(panel->animB[i], 20, 24+i*25);
234 WMGroupButtons(panel->animB[0], panel->animB[1]);
235 WMGroupButtons(panel->animB[0], panel->animB[2]);
236 WMGroupButtons(panel->animB[0], panel->animB[3]);
238 WMSetButtonText(panel->animB[0], _("Shrinking/Zooming"));
239 WMSetButtonText(panel->animB[1], _("Spinning/Twisting"));
240 WMSetButtonText(panel->animB[2], _("3D-flipping"));
241 WMSetButtonText(panel->animB[3], _("None"));
243 WMMapSubwidgets(panel->animF);
245 /***************** Options ****************/
246 panel->optF = WMCreateFrame(panel->box);
247 WMResizeWidget(panel->optF, 260, 70);
248 WMMoveWidget(panel->optF, 25, 150);
249 /* WMSetFrameTitle(panel->optF, _("Icon Display"));*/
251 panel->arrB = WMCreateSwitchButton(panel->optF);
252 WMResizeWidget(panel->arrB, 235, 20);
253 WMMoveWidget(panel->arrB, 15, 15);
254 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
256 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."),
257 WMWidgetView(panel->arrB));
259 panel->omnB = WMCreateSwitchButton(panel->optF);
260 WMResizeWidget(panel->omnB, 235, 20);
261 WMMoveWidget(panel->omnB, 15, 40);
262 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
264 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."),
265 WMWidgetView(panel->omnB));
267 WMMapSubwidgets(panel->optF);
269 /***************** Icon Size ****************/
270 panel->sizeF = WMCreateFrame(panel->box);
271 WMResizeWidget(panel->sizeF, 205, 70);
272 WMMoveWidget(panel->sizeF, 295, 150);
273 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
275 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
276 WMWidgetView(panel->sizeF));
278 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
279 WMResizeWidget(panel->sizeP, 156, 20);
280 WMMoveWidget(panel->sizeP, 25, 30);
281 for (i=24; i<=96; i+=8) {
282 sprintf(buf, "%ix%i", i, i);
283 WMAddPopUpButtonItem(panel->sizeP, buf);
286 WMMapSubwidgets(panel->sizeF);
288 WMRealizeWidget(panel->box);
289 WMMapSubwidgets(panel->box);
291 showData(panel);
295 static void
296 storeData(_Panel *panel)
298 char buf[8];
300 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
301 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
303 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP)*8+24,
304 "IconSize");
306 buf[3] = 0;
308 if (panel->iconPos < 4) {
309 buf[0] = 't';
310 } else {
311 buf[0] = 'b';
313 if (panel->iconPos & 2) {
314 buf[1] = 'r';
315 } else {
316 buf[1] = 'l';
318 if (panel->iconPos & 1) {
319 buf[2] = 'h';
320 } else {
321 buf[2] = 'v';
323 SetStringForKey(buf, "IconPosition");
325 if (WMGetButtonSelected(panel->animB[0]))
326 SetStringForKey("zoom", "IconificationStyle");
327 else if (WMGetButtonSelected(panel->animB[1]))
328 SetStringForKey("twist", "IconificationStyle");
329 else if (WMGetButtonSelected(panel->animB[2]))
330 SetStringForKey("flip", "IconificationStyle");
331 else
332 SetStringForKey("none", "IconificationStyle");
337 Panel*
338 InitIcons(WMScreen *scr, WMWidget *parent)
340 _Panel *panel;
342 panel = wmalloc(sizeof(_Panel));
343 memset(panel, 0, sizeof(_Panel));
345 panel->sectionName = _("Icon Preferences");
347 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
348 "area, sizes of icons, miniaturization animation style.");
350 panel->parent = parent;
352 panel->callbacks.createWidgets = createPanel;
353 panel->callbacks.updateDomain = storeData;
355 AddSection(panel, ICON_FILE);
357 return panel;