Coding style cleanup in dock.c
[wmaker-crm.git] / WPrefs.app / Icons.c
blob599dfb030df50617e200e1840adcb406463ffe7e
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"
24 typedef struct _Panel {
25 WMBox *box;
27 char *sectionName;
29 char *description;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMFrame *posF;
36 WMFrame *posVF;
37 WMFrame *posV;
39 WMButton *posB[8];
41 WMFrame *animF;
42 WMButton *animB[4];
44 WMFrame *optF;
45 WMButton *arrB;
46 WMButton *omnB;
48 WMFrame *sizeF;
49 WMPopUpButton *sizeP;
51 int iconPos;
52 } _Panel;
54 #define ICON_FILE "iconprefs"
56 static void showIconLayout(WMWidget * widget, void *data)
58 _Panel *panel = (_Panel *) data;
59 int w, h;
60 int i;
62 for (i = 0; i < 8; i++) {
63 if (panel->posB[i] == widget) {
64 panel->iconPos = i;
65 break;
69 if (panel->iconPos & 1) {
70 w = 32;
71 h = 8;
72 } else {
73 w = 8;
74 h = 32;
76 WMResizeWidget(panel->posV, w, h);
78 switch (panel->iconPos & ~1) {
79 case 0:
80 WMMoveWidget(panel->posV, 2, 2);
81 break;
82 case 2:
83 WMMoveWidget(panel->posV, 95 - 2 - w, 2);
84 break;
85 case 4:
86 WMMoveWidget(panel->posV, 2, 70 - 2 - h);
87 break;
88 default:
89 WMMoveWidget(panel->posV, 95 - 2 - w, 70 - 2 - h);
90 break;
94 static void 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", str);
109 str = def;
112 if (str[0] == 't' || str[0] == 'T') {
113 i = 0;
114 } else {
115 i = 4;
117 if (str[1] == 'r' || str[1] == 'R') {
118 i += 2;
120 if (str[2] == 'v' || str[2] == 'V') {
121 i += 0;
122 } else {
123 i += 1;
125 panel->iconPos = i;
126 WMPerformButtonClick(panel->posB[i]);
128 i = GetIntegerForKey("IconSize");
129 i = (i - 24) / 8;
131 if (i < 0)
132 i = 0;
133 else if (i > 9)
134 i = 9;
135 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
137 str = GetStringForKey("IconificationStyle");
138 if (!str)
139 str = "zoom";
140 if (strcasecmp(str, "none") == 0)
141 WMPerformButtonClick(panel->animB[3]);
142 else if (strcasecmp(str, "twist") == 0)
143 WMPerformButtonClick(panel->animB[1]);
144 else if (strcasecmp(str, "flip") == 0)
145 WMPerformButtonClick(panel->animB[2]);
146 else {
147 WMPerformButtonClick(panel->animB[0]);
151 static void createPanel(Panel * p)
153 _Panel *panel = (_Panel *) p;
154 WMColor *color;
155 int i;
156 char buf[16];
158 panel->box = WMCreateBox(panel->parent);
159 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
161 /***************** Positioning of Icons *****************/
162 panel->posF = WMCreateFrame(panel->box);
163 WMResizeWidget(panel->posF, 260, 135);
164 WMMoveWidget(panel->posF, 25, 10);
165 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
167 for (i = 0; i < 8; i++) {
168 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
169 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
171 if (i > 0)
172 WMGroupButtons(panel->posB[0], panel->posB[i]);
174 WMMoveWidget(panel->posB[1], 70, 23);
175 WMResizeWidget(panel->posB[1], 47, 15);
176 WMMoveWidget(panel->posB[3], 70 + 47, 23);
177 WMResizeWidget(panel->posB[3], 47, 15);
179 WMMoveWidget(panel->posB[0], 55, 38);
180 WMResizeWidget(panel->posB[0], 15, 35);
181 WMMoveWidget(panel->posB[4], 55, 38 + 35);
182 WMResizeWidget(panel->posB[4], 15, 35);
184 WMMoveWidget(panel->posB[5], 70, 38 + 70);
185 WMResizeWidget(panel->posB[5], 47, 15);
186 WMMoveWidget(panel->posB[7], 70 + 47, 38 + 70);
187 WMResizeWidget(panel->posB[7], 47, 15);
189 WMMoveWidget(panel->posB[2], 70 + 95, 38);
190 WMResizeWidget(panel->posB[2], 15, 35);
191 WMMoveWidget(panel->posB[6], 70 + 95, 38 + 35);
192 WMResizeWidget(panel->posB[6], 15, 35);
194 color = WMCreateRGBColor(WMWidgetScreen(panel->parent), 0x5100, 0x5100, 0x7100, True);
195 panel->posVF = WMCreateFrame(panel->posF);
196 WMResizeWidget(panel->posVF, 95, 70);
197 WMMoveWidget(panel->posVF, 70, 38);
198 WMSetFrameRelief(panel->posVF, WRSunken);
199 WMSetWidgetBackgroundColor(panel->posVF, color);
200 WMReleaseColor(color);
202 panel->posV = WMCreateFrame(panel->posVF);
203 WMSetFrameRelief(panel->posV, WRSimple);
205 WMMapSubwidgets(panel->posF);
207 /***************** Animation ****************/
208 panel->animF = WMCreateFrame(panel->box);
209 WMResizeWidget(panel->animF, 205, 135);
210 WMMoveWidget(panel->animF, 295, 10);
211 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
213 for (i = 0; i < 4; i++) {
214 panel->animB[i] = WMCreateRadioButton(panel->animF);
215 WMResizeWidget(panel->animB[i], 170, 20);
216 WMMoveWidget(panel->animB[i], 20, 24 + i * 25);
218 WMGroupButtons(panel->animB[0], panel->animB[1]);
219 WMGroupButtons(panel->animB[0], panel->animB[2]);
220 WMGroupButtons(panel->animB[0], panel->animB[3]);
222 WMSetButtonText(panel->animB[0], _("Shrinking/Zooming"));
223 WMSetButtonText(panel->animB[1], _("Spinning/Twisting"));
224 WMSetButtonText(panel->animB[2], _("3D-flipping"));
225 WMSetButtonText(panel->animB[3], _("None"));
227 WMMapSubwidgets(panel->animF);
229 /***************** Options ****************/
230 panel->optF = WMCreateFrame(panel->box);
231 WMResizeWidget(panel->optF, 260, 70);
232 WMMoveWidget(panel->optF, 25, 150);
233 /* WMSetFrameTitle(panel->optF, _("Icon Display")); */
235 panel->arrB = WMCreateSwitchButton(panel->optF);
236 WMResizeWidget(panel->arrB, 235, 20);
237 WMMoveWidget(panel->arrB, 15, 15);
238 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
240 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."), WMWidgetView(panel->arrB));
242 panel->omnB = WMCreateSwitchButton(panel->optF);
243 WMResizeWidget(panel->omnB, 235, 20);
244 WMMoveWidget(panel->omnB, 15, 40);
245 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
247 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."), WMWidgetView(panel->omnB));
249 WMMapSubwidgets(panel->optF);
251 /***************** Icon Size ****************/
252 panel->sizeF = WMCreateFrame(panel->box);
253 WMResizeWidget(panel->sizeF, 205, 70);
254 WMMoveWidget(panel->sizeF, 295, 150);
255 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
257 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
258 WMWidgetView(panel->sizeF));
260 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
261 WMResizeWidget(panel->sizeP, 156, 20);
262 WMMoveWidget(panel->sizeP, 25, 30);
263 for (i = 24; i <= 96; i += 8) {
264 sprintf(buf, "%ix%i", i, i);
265 WMAddPopUpButtonItem(panel->sizeP, buf);
268 WMMapSubwidgets(panel->sizeF);
270 WMRealizeWidget(panel->box);
271 WMMapSubwidgets(panel->box);
273 showData(panel);
276 static void storeData(_Panel * panel)
278 char buf[8];
280 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
281 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
283 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP) * 8 + 24, "IconSize");
285 buf[3] = 0;
287 if (panel->iconPos < 4) {
288 buf[0] = 't';
289 } else {
290 buf[0] = 'b';
292 if (panel->iconPos & 2) {
293 buf[1] = 'r';
294 } else {
295 buf[1] = 'l';
297 if (panel->iconPos & 1) {
298 buf[2] = 'h';
299 } else {
300 buf[2] = 'v';
302 SetStringForKey(buf, "IconPosition");
304 if (WMGetButtonSelected(panel->animB[0]))
305 SetStringForKey("zoom", "IconificationStyle");
306 else if (WMGetButtonSelected(panel->animB[1]))
307 SetStringForKey("twist", "IconificationStyle");
308 else if (WMGetButtonSelected(panel->animB[2]))
309 SetStringForKey("flip", "IconificationStyle");
310 else
311 SetStringForKey("none", "IconificationStyle");
314 Panel *InitIcons(WMScreen * scr, WMWidget * parent)
316 _Panel *panel;
318 panel = wmalloc(sizeof(_Panel));
320 panel->sectionName = _("Icon Preferences");
322 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
323 "area, sizes of icons, miniaturization animation style.");
325 panel->parent = parent;
327 panel->callbacks.createWidgets = createPanel;
328 panel->callbacks.updateDomain = storeData;
330 AddSection(panel, ICON_FILE);
332 return panel;