This update includes the 0.20.3pre3 code
[wmaker-crm.git] / WPrefs.app / Icons.c
bloba90711d8abc3b492c3c2e79ad255b99b086183a5
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 *nwB;
41 WMButton *neB;
42 WMButton *swB;
43 WMButton *seB;
44 WMButton *verB;
45 WMButton *horB;
47 WMFrame *animF;
48 WMButton *animB[4];
50 WMFrame *optF;
51 WMButton *arrB;
52 WMButton *omnB;
54 WMFrame *sizeF;
55 WMPopUpButton *sizeP;
57 } _Panel;
61 #define ICON_FILE "iconprefs"
64 static void
65 showIconLayout(WMWidget *widget, void *data)
67 _Panel *panel = (_Panel*)data;
68 int w, h;
70 if (WMGetButtonSelected(panel->horB)) {
71 w = 32;
72 h = 8;
73 } else {
74 w = 8;
75 h = 32;
77 WMResizeWidget(panel->posV, w, h);
79 if (WMGetButtonSelected(panel->nwB)) {
80 WMMoveWidget(panel->posV, 2, 2);
81 } else if (WMGetButtonSelected(panel->neB)) {
82 WMMoveWidget(panel->posV, 95-2-w, 2);
83 } else if (WMGetButtonSelected(panel->swB)) {
84 WMMoveWidget(panel->posV, 2, 70-2-h);
85 } else {
86 WMMoveWidget(panel->posV, 95-2-w, 70-2-h);
91 #define MIN(a,b) ((a) < (b) ? (a) : (b))
93 static void
94 showData(_Panel *panel)
96 int i;
97 char *str;
98 char *def = "blh";
100 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
102 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
104 str = GetStringForKey("IconPosition");
105 if (!str)
106 str = def;
107 if (strlen(str)!=3) {
108 wwarning("bad value %s for option IconPosition. Using default blh",
109 str);
110 str = def;
113 if (str[0]=='t' || str[0]=='T') {
114 if (str[1]=='r' || str[1]=='R') {
115 WMPerformButtonClick(panel->neB);
116 } else {
117 WMPerformButtonClick(panel->nwB);
119 } else {
120 if (str[1]=='r' || str[1]=='R') {
121 WMPerformButtonClick(panel->seB);
122 } else {
123 WMPerformButtonClick(panel->swB);
126 if (str[2]=='v' || str[2]=='V') {
127 WMPerformButtonClick(panel->verB);
128 } else {
129 WMPerformButtonClick(panel->horB);
132 i = GetIntegerForKey("IconSize");
133 i = (i-24)/8;
135 if (i<0)
136 i = 0;
137 else if (i>9)
138 i = 9;
139 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
141 str = GetStringForKey("IconificationStyle");
142 if (strcasecmp(str, "none")==0)
143 WMPerformButtonClick(panel->animB[3]);
144 else if (strcasecmp(str, "twist")==0)
145 WMPerformButtonClick(panel->animB[1]);
146 else if (strcasecmp(str, "flip")==0)
147 WMPerformButtonClick(panel->animB[2]);
148 else {
149 WMPerformButtonClick(panel->animB[0]);
156 static void
157 createPanel(Panel *p)
159 _Panel *panel = (_Panel*)p;
160 WMColor *color;
161 int i;
162 char buf[16];
164 panel->frame = WMCreateFrame(panel->win);
165 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
166 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
168 /***************** Positioning of Icons *****************/
169 panel->posF = WMCreateFrame(panel->frame);
170 WMResizeWidget(panel->posF, 260, 135);
171 WMMoveWidget(panel->posF, 25, 10);
172 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
174 panel->nwB = WMCreateButton(panel->posF, WBTOnOff);
175 WMResizeWidget(panel->nwB, 24, 24);
176 WMMoveWidget(panel->nwB, 15, 25);
177 WMSetButtonAction(panel->nwB, showIconLayout, panel);
179 panel->neB = WMCreateButton(panel->posF, WBTOnOff);
180 WMResizeWidget(panel->neB, 24, 24);
181 WMMoveWidget(panel->neB, 115, 25);
182 WMSetButtonAction(panel->neB, showIconLayout, panel);
184 panel->swB = WMCreateButton(panel->posF, WBTOnOff);
185 WMResizeWidget(panel->swB, 24, 24);
186 WMMoveWidget(panel->swB, 15, 100);
187 WMSetButtonAction(panel->swB, showIconLayout, panel);
189 panel->seB = WMCreateButton(panel->posF, WBTOnOff);
190 WMResizeWidget(panel->seB, 24, 24);
191 WMMoveWidget(panel->seB, 115, 100);
192 WMSetButtonAction(panel->seB, showIconLayout, panel);
194 WMGroupButtons(panel->nwB, panel->neB);
195 WMGroupButtons(panel->nwB, panel->seB);
196 WMGroupButtons(panel->nwB, panel->swB);
198 color = WMCreateRGBColor(WMWidgetScreen(panel->win), 0x5100, 0x5100,
199 0x7100, True);
200 panel->posVF = WMCreateFrame(panel->posF);
201 WMResizeWidget(panel->posVF, 95, 70);
202 WMMoveWidget(panel->posVF, 30, 38);
203 WMSetFrameRelief(panel->posVF, WRSunken);
204 WMSetWidgetBackgroundColor(panel->posVF, color);
205 WMReleaseColor(color);
207 panel->posV = WMCreateFrame(panel->posVF);
208 WMSetFrameRelief(panel->posV, WRSimple);
210 panel->verB = WMCreateRadioButton(panel->posF);
211 WMResizeWidget(panel->verB, 105, 20);
212 WMMoveWidget(panel->verB, 150, 45);
213 WMSetButtonText(panel->verB, "Vertical");
214 WMSetButtonAction(panel->verB, showIconLayout, panel);
216 panel->horB = WMCreateRadioButton(panel->posF);
217 WMResizeWidget(panel->horB, 105, 20);
218 WMMoveWidget(panel->horB, 150, 75);
219 WMSetButtonText(panel->horB, "Horizontal");
220 WMSetButtonAction(panel->horB, showIconLayout, panel);
223 WMGroupButtons(panel->horB, panel->verB);
225 WMMapSubwidgets(panel->posF);
227 /***************** Animation ****************/
228 panel->animF = WMCreateFrame(panel->frame);
229 WMResizeWidget(panel->animF, 205, 135);
230 WMMoveWidget(panel->animF, 295, 10);
231 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
233 for (i=0; i<4; i++) {
234 panel->animB[i] = WMCreateRadioButton(panel->animF);
235 WMResizeWidget(panel->animB[i], 170, 20);
236 WMMoveWidget(panel->animB[i], 20, 24+i*25);
238 WMGroupButtons(panel->animB[0], panel->animB[1]);
239 WMGroupButtons(panel->animB[0], panel->animB[2]);
240 WMGroupButtons(panel->animB[0], panel->animB[3]);
242 WMSetButtonText(panel->animB[0], _("Shrinking/Zooming"));
243 WMSetButtonText(panel->animB[1], _("Spinning/Twisting"));
244 WMSetButtonText(panel->animB[2], _("3D-flipping"));
245 WMSetButtonText(panel->animB[3], _("None"));
247 WMMapSubwidgets(panel->animF);
249 /***************** Options ****************/
250 panel->optF = WMCreateFrame(panel->frame);
251 WMResizeWidget(panel->optF, 260, 65);
252 WMMoveWidget(panel->optF, 25, 155);
254 panel->arrB = WMCreateSwitchButton(panel->optF);
255 WMResizeWidget(panel->arrB, 235, 20);
256 WMMoveWidget(panel->arrB, 15, 10);
257 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
259 panel->omnB = WMCreateSwitchButton(panel->optF);
260 WMResizeWidget(panel->omnB, 235, 20);
261 WMMoveWidget(panel->omnB, 15, 35);
262 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
264 WMMapSubwidgets(panel->optF);
266 /***************** Icon Size ****************/
267 panel->sizeF = WMCreateFrame(panel->frame);
268 WMResizeWidget(panel->sizeF, 205, 70);
269 WMMoveWidget(panel->sizeF, 295, 150);
270 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
273 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
274 WMResizeWidget(panel->sizeP, 156, 20);
275 WMMoveWidget(panel->sizeP, 25, 30);
276 for (i=24; i<=96; i+=8) {
277 sprintf(buf, "%ix%i", i, i);
278 WMAddPopUpButtonItem(panel->sizeP, buf);
281 WMMapSubwidgets(panel->sizeF);
283 WMRealizeWidget(panel->frame);
284 WMMapSubwidgets(panel->frame);
286 showData(panel);
290 static void
291 storeData(_Panel *panel)
293 char buf[8];
295 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
296 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
298 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP)*8+24,
299 "IconSize");
301 buf[3] = 0;
302 if (WMGetButtonSelected(panel->nwB)) {
303 buf[0] = 't';
304 buf[1] = 'l';
305 } else if (WMGetButtonSelected(panel->neB)) {
306 buf[0] = 't';
307 buf[1] = 'r';
308 } else if (WMGetButtonSelected(panel->swB)) {
309 buf[0] = 'b';
310 buf[1] = 'l';
311 } else {
312 buf[0] = 'b';
313 buf[1] = 'r';
316 if (WMGetButtonSelected(panel->horB)) {
317 buf[2] = 'h';
318 } else {
319 buf[2] = 'v';
321 SetStringForKey(buf, "IconPosition");
323 if (WMGetButtonSelected(panel->animB[0]))
324 SetStringForKey("zoom", "IconificationStyle");
325 else if (WMGetButtonSelected(panel->animB[1]))
326 SetStringForKey("twist", "IconificationStyle");
327 else if (WMGetButtonSelected(panel->animB[2]))
328 SetStringForKey("flip", "IconificationStyle");
329 else
330 SetStringForKey("none", "IconificationStyle");
335 Panel*
336 InitIcons(WMScreen *scr, WMWindow *win)
338 _Panel *panel;
340 panel = wmalloc(sizeof(_Panel));
341 memset(panel, 0, sizeof(_Panel));
343 panel->sectionName = _("Icon Preferences");
345 panel->win = win;
347 panel->callbacks.createWidgets = createPanel;
348 panel->callbacks.updateDomain = storeData;
350 AddSection(panel, ICON_FILE);
352 return panel;