clip arrow bevel
[wmaker-crm.git] / WPrefs.app / Icons.c
blobe5841ea76e3191a5c4ec02634fb1d099e68c564b
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 CallbackRec callbacks;
34 WMWindow *win;
36 WMFrame *posF;
37 WMFrame *posVF;
38 WMFrame *posV;
40 WMButton *posB[8];
42 WMFrame *animF;
43 WMButton *animB[4];
45 WMFrame *optF;
46 WMButton *arrB;
47 WMButton *omnB;
49 WMFrame *sizeF;
50 WMPopUpButton *sizeP;
52 int iconPos;
53 } _Panel;
57 #define ICON_FILE "iconprefs"
60 static void
61 showIconLayout(WMWidget *widget, void *data)
63 _Panel *panel = (_Panel*)data;
64 int w, h;
65 int i;
67 for (i=0; i<8; i++) {
68 if (panel->posB[i] == widget) {
69 panel->iconPos = i;
70 break;
74 if (panel->iconPos & 1) {
75 w = 32;
76 h = 8;
77 } else {
78 w = 8;
79 h = 32;
81 WMResizeWidget(panel->posV, w, h);
83 switch (panel->iconPos & ~1) {
84 case 0:
85 WMMoveWidget(panel->posV, 2, 2);
86 break;
87 case 2:
88 WMMoveWidget(panel->posV, 95-2-w, 2);
89 break;
90 case 4:
91 WMMoveWidget(panel->posV, 2, 70-2-h);
92 break;
93 default:
94 WMMoveWidget(panel->posV, 95-2-w, 70-2-h);
95 break;
100 #define MIN(a,b) ((a) < (b) ? (a) : (b))
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];
172 panel->frame = WMCreateFrame(panel->win);
173 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
174 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
176 /***************** Positioning of Icons *****************/
177 panel->posF = WMCreateFrame(panel->frame);
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->win), 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->frame);
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->frame);
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 panel->omnB = WMCreateSwitchButton(panel->optF);
257 WMResizeWidget(panel->omnB, 235, 20);
258 WMMoveWidget(panel->omnB, 15, 40);
259 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
261 WMMapSubwidgets(panel->optF);
263 /***************** Icon Size ****************/
264 panel->sizeF = WMCreateFrame(panel->frame);
265 WMResizeWidget(panel->sizeF, 205, 70);
266 WMMoveWidget(panel->sizeF, 295, 150);
267 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
270 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
271 WMResizeWidget(panel->sizeP, 156, 20);
272 WMMoveWidget(panel->sizeP, 25, 30);
273 for (i=24; i<=96; i+=8) {
274 sprintf(buf, "%ix%i", i, i);
275 WMAddPopUpButtonItem(panel->sizeP, buf);
278 WMMapSubwidgets(panel->sizeF);
280 WMRealizeWidget(panel->frame);
281 WMMapSubwidgets(panel->frame);
283 showData(panel);
287 static void
288 storeData(_Panel *panel)
290 char buf[8];
292 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
293 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
295 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP)*8+24,
296 "IconSize");
298 buf[3] = 0;
300 if (panel->iconPos < 4) {
301 buf[0] = 't';
302 } else {
303 buf[0] = 'b';
305 if (panel->iconPos & 2) {
306 buf[1] = 'r';
307 } else {
308 buf[1] = 'l';
310 if (panel->iconPos & 1) {
311 buf[2] = 'h';
312 } else {
313 buf[2] = 'v';
315 SetStringForKey(buf, "IconPosition");
317 if (WMGetButtonSelected(panel->animB[0]))
318 SetStringForKey("zoom", "IconificationStyle");
319 else if (WMGetButtonSelected(panel->animB[1]))
320 SetStringForKey("twist", "IconificationStyle");
321 else if (WMGetButtonSelected(panel->animB[2]))
322 SetStringForKey("flip", "IconificationStyle");
323 else
324 SetStringForKey("none", "IconificationStyle");
329 Panel*
330 InitIcons(WMScreen *scr, WMWindow *win)
332 _Panel *panel;
334 panel = wmalloc(sizeof(_Panel));
335 memset(panel, 0, sizeof(_Panel));
337 panel->sectionName = _("Icon Preferences");
339 panel->win = win;
341 panel->callbacks.createWidgets = createPanel;
342 panel->callbacks.updateDomain = storeData;
344 AddSection(panel, ICON_FILE);
346 return panel;