Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Icons.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* Icons.c- icon preferences
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "WPrefs.h"
24
9d2e6ef9 scottc1998-09-29 22:36:29 +000025typedef struct _Panel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026 WMBox *box;
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028 char *sectionName;
9d2e6ef9 scottc1998-09-29 22:36:29 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 char *description;
d3f29988 kojima1999-04-25 01:49:46 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032 CallbackRec callbacks;
6830b057 dan2004-10-12 21:28:27 +000033
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 WMWidget *parent;
6830b057 dan2004-10-12 21:28:27 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 WMFrame *posF;
37 WMFrame *posVF;
38 WMFrame *posV;
9d2e6ef9 scottc1998-09-29 22:36:29 +000039
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020040 WMButton *posB[8];
9d2e6ef9 scottc1998-09-29 22:36:29 +000041
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020042 WMFrame *animF;
43 WMButton *animB[4];
9007a657 dan1998-11-23 11:32:19 +000044
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020045 WMFrame *optF;
46 WMButton *arrB;
47 WMButton *omnB;
6830b057 dan2004-10-12 21:28:27 +000048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020049 WMFrame *sizeF;
50 WMPopUpButton *sizeP;
9d2e6ef9 scottc1998-09-29 22:36:29 +000051
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020052 int iconPos;
9d2e6ef9 scottc1998-09-29 22:36:29 +000053} _Panel;
54
9d2e6ef9 scottc1998-09-29 22:36:29 +000055#define ICON_FILE "iconprefs"
56
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020057static void showIconLayout(WMWidget * widget, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +000058{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020059 _Panel *panel = (_Panel *) data;
60 int w, h;
61 int i;
62
63 for (i = 0; i < 8; i++) {
64 if (panel->posB[i] == widget) {
65 panel->iconPos = i;
66 break;
67 }
68 }
69
70 if (panel->iconPos & 1) {
71 w = 32;
72 h = 8;
73 } else {
74 w = 8;
75 h = 32;
76 }
77 WMResizeWidget(panel->posV, w, h);
78
79 switch (panel->iconPos & ~1) {
80 case 0:
81 WMMoveWidget(panel->posV, 2, 2);
82 break;
83 case 2:
84 WMMoveWidget(panel->posV, 95 - 2 - w, 2);
85 break;
86 case 4:
87 WMMoveWidget(panel->posV, 2, 70 - 2 - h);
88 break;
89 default:
90 WMMoveWidget(panel->posV, 95 - 2 - w, 70 - 2 - h);
91 break;
92 }
9d2e6ef9 scottc1998-09-29 22:36:29 +000093}
94
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020095static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +000096{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020097 int i;
98 char *str;
99 char *def = "blh";
100
101 WMSetButtonSelected(panel->arrB, GetBoolForKey("AutoArrangeIcons"));
102
103 WMSetButtonSelected(panel->omnB, GetBoolForKey("StickyIcons"));
104
105 str = GetStringForKey("IconPosition");
106 if (!str)
107 str = def;
108 if (strlen(str) != 3) {
109 wwarning("bad value %s for option IconPosition. Using default blh", str);
110 str = def;
111 }
112
113 if (str[0] == 't' || str[0] == 'T') {
114 i = 0;
115 } else {
116 i = 4;
117 }
118 if (str[1] == 'r' || str[1] == 'R') {
119 i += 2;
120 }
121 if (str[2] == 'v' || str[2] == 'V') {
122 i += 0;
123 } else {
124 i += 1;
125 }
126 panel->iconPos = i;
127 WMPerformButtonClick(panel->posB[i]);
128
129 i = GetIntegerForKey("IconSize");
130 i = (i - 24) / 8;
131
132 if (i < 0)
133 i = 0;
134 else if (i > 9)
135 i = 9;
136 WMSetPopUpButtonSelectedItem(panel->sizeP, i);
137
138 str = GetStringForKey("IconificationStyle");
139 if (!str)
140 str = "zoom";
141 if (strcasecmp(str, "none") == 0)
142 WMPerformButtonClick(panel->animB[3]);
143 else if (strcasecmp(str, "twist") == 0)
144 WMPerformButtonClick(panel->animB[1]);
145 else if (strcasecmp(str, "flip") == 0)
146 WMPerformButtonClick(panel->animB[2]);
147 else {
148 WMPerformButtonClick(panel->animB[0]);
149 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000150}
151
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200152static void createPanel(Panel * p)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000153{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200154 _Panel *panel = (_Panel *) p;
155 WMColor *color;
156 int i;
157 char buf[16];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000158
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200159 panel->box = WMCreateBox(panel->parent);
160 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
6830b057 dan2004-10-12 21:28:27 +0000161
9d2e6ef9 scottc1998-09-29 22:36:29 +0000162 /***************** Positioning of Icons *****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200163 panel->posF = WMCreateFrame(panel->box);
164 WMResizeWidget(panel->posF, 260, 135);
165 WMMoveWidget(panel->posF, 25, 10);
166 WMSetFrameTitle(panel->posF, _("Icon Positioning"));
167
168 for (i = 0; i < 8; i++) {
169 panel->posB[i] = WMCreateButton(panel->posF, WBTOnOff);
170 WMSetButtonAction(panel->posB[i], showIconLayout, panel);
171
172 if (i > 0)
173 WMGroupButtons(panel->posB[0], panel->posB[i]);
174 }
175 WMMoveWidget(panel->posB[1], 70, 23);
176 WMResizeWidget(panel->posB[1], 47, 15);
177 WMMoveWidget(panel->posB[3], 70 + 47, 23);
178 WMResizeWidget(panel->posB[3], 47, 15);
179
180 WMMoveWidget(panel->posB[0], 55, 38);
181 WMResizeWidget(panel->posB[0], 15, 35);
182 WMMoveWidget(panel->posB[4], 55, 38 + 35);
183 WMResizeWidget(panel->posB[4], 15, 35);
184
185 WMMoveWidget(panel->posB[5], 70, 38 + 70);
186 WMResizeWidget(panel->posB[5], 47, 15);
187 WMMoveWidget(panel->posB[7], 70 + 47, 38 + 70);
188 WMResizeWidget(panel->posB[7], 47, 15);
189
190 WMMoveWidget(panel->posB[2], 70 + 95, 38);
191 WMResizeWidget(panel->posB[2], 15, 35);
192 WMMoveWidget(panel->posB[6], 70 + 95, 38 + 35);
193 WMResizeWidget(panel->posB[6], 15, 35);
194
195 color = WMCreateRGBColor(WMWidgetScreen(panel->parent), 0x5100, 0x5100, 0x7100, True);
196 panel->posVF = WMCreateFrame(panel->posF);
197 WMResizeWidget(panel->posVF, 95, 70);
198 WMMoveWidget(panel->posVF, 70, 38);
199 WMSetFrameRelief(panel->posVF, WRSunken);
200 WMSetWidgetBackgroundColor(panel->posVF, color);
201 WMReleaseColor(color);
202
203 panel->posV = WMCreateFrame(panel->posVF);
204 WMSetFrameRelief(panel->posV, WRSimple);
205
206 WMMapSubwidgets(panel->posF);
6830b057 dan2004-10-12 21:28:27 +0000207
9007a657 dan1998-11-23 11:32:19 +0000208 /***************** Animation ****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200209 panel->animF = WMCreateFrame(panel->box);
210 WMResizeWidget(panel->animF, 205, 135);
211 WMMoveWidget(panel->animF, 295, 10);
212 WMSetFrameTitle(panel->animF, _("Iconification Animation"));
213
214 for (i = 0; i < 4; i++) {
215 panel->animB[i] = WMCreateRadioButton(panel->animF);
216 WMResizeWidget(panel->animB[i], 170, 20);
217 WMMoveWidget(panel->animB[i], 20, 24 + i * 25);
218 }
219 WMGroupButtons(panel->animB[0], panel->animB[1]);
220 WMGroupButtons(panel->animB[0], panel->animB[2]);
221 WMGroupButtons(panel->animB[0], panel->animB[3]);
222
223 WMSetButtonText(panel->animB[0], _("Shrinking/Zooming"));
224 WMSetButtonText(panel->animB[1], _("Spinning/Twisting"));
225 WMSetButtonText(panel->animB[2], _("3D-flipping"));
226 WMSetButtonText(panel->animB[3], _("None"));
227
228 WMMapSubwidgets(panel->animF);
9007a657 dan1998-11-23 11:32:19 +0000229
9d2e6ef9 scottc1998-09-29 22:36:29 +0000230 /***************** Options ****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200231 panel->optF = WMCreateFrame(panel->box);
232 WMResizeWidget(panel->optF, 260, 70);
233 WMMoveWidget(panel->optF, 25, 150);
234 /* WMSetFrameTitle(panel->optF, _("Icon Display")); */
6830b057 dan2004-10-12 21:28:27 +0000235
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200236 panel->arrB = WMCreateSwitchButton(panel->optF);
237 WMResizeWidget(panel->arrB, 235, 20);
238 WMMoveWidget(panel->arrB, 15, 15);
239 WMSetButtonText(panel->arrB, _("Auto-arrange icons"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000240
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200241 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."), WMWidgetView(panel->arrB));
d3f29988 kojima1999-04-25 01:49:46 +0000242
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200243 panel->omnB = WMCreateSwitchButton(panel->optF);
244 WMResizeWidget(panel->omnB, 235, 20);
245 WMMoveWidget(panel->omnB, 15, 40);
246 WMSetButtonText(panel->omnB, _("Omnipresent miniwindows"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000247
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200248 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."), WMWidgetView(panel->omnB));
d3f29988 kojima1999-04-25 01:49:46 +0000249
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200250 WMMapSubwidgets(panel->optF);
6830b057 dan2004-10-12 21:28:27 +0000251
9d2e6ef9 scottc1998-09-29 22:36:29 +0000252 /***************** Icon Size ****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200253 panel->sizeF = WMCreateFrame(panel->box);
254 WMResizeWidget(panel->sizeF, 205, 70);
255 WMMoveWidget(panel->sizeF, 295, 150);
256 WMSetFrameTitle(panel->sizeF, _("Icon Size"));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000257
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200258 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
259 WMWidgetView(panel->sizeF));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000260
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200261 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
262 WMResizeWidget(panel->sizeP, 156, 20);
263 WMMoveWidget(panel->sizeP, 25, 30);
264 for (i = 24; i <= 96; i += 8) {
265 sprintf(buf, "%ix%i", i, i);
266 WMAddPopUpButtonItem(panel->sizeP, buf);
267 }
6830b057 dan2004-10-12 21:28:27 +0000268
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200269 WMMapSubwidgets(panel->sizeF);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000270
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200271 WMRealizeWidget(panel->box);
272 WMMapSubwidgets(panel->box);
6830b057 dan2004-10-12 21:28:27 +0000273
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200274 showData(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000275}
276
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200277static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000278{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200279 char buf[8];
280
281 SetBoolForKey(WMGetButtonSelected(panel->arrB), "AutoArrangeIcons");
282 SetBoolForKey(WMGetButtonSelected(panel->omnB), "StickyIcons");
283
284 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel->sizeP) * 8 + 24, "IconSize");
285
286 buf[3] = 0;
287
288 if (panel->iconPos < 4) {
289 buf[0] = 't';
290 } else {
291 buf[0] = 'b';
292 }
293 if (panel->iconPos & 2) {
294 buf[1] = 'r';
295 } else {
296 buf[1] = 'l';
297 }
298 if (panel->iconPos & 1) {
299 buf[2] = 'h';
300 } else {
301 buf[2] = 'v';
302 }
303 SetStringForKey(buf, "IconPosition");
304
305 if (WMGetButtonSelected(panel->animB[0]))
306 SetStringForKey("zoom", "IconificationStyle");
307 else if (WMGetButtonSelected(panel->animB[1]))
308 SetStringForKey("twist", "IconificationStyle");
309 else if (WMGetButtonSelected(panel->animB[2]))
310 SetStringForKey("flip", "IconificationStyle");
311 else
312 SetStringForKey("none", "IconificationStyle");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000313}
314
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200315Panel *InitIcons(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000316{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200317 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000318
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200319 panel = wmalloc(sizeof(_Panel));
320 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000321
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200322 panel->sectionName = _("Icon Preferences");
d3f29988 kojima1999-04-25 01:49:46 +0000323
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200324 panel->description = _("Icon/Miniwindow handling options. Icon positioning\n"
325 "area, sizes of icons, miniaturization animation style.");
d3f29988 kojima1999-04-25 01:49:46 +0000326
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200327 panel->parent = parent;
d3f29988 kojima1999-04-25 01:49:46 +0000328
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200329 panel->callbacks.createWidgets = createPanel;
330 panel->callbacks.updateDomain = storeData;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000331
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200332 AddSection(panel, ICON_FILE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000333
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200334 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000335}