Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Preferences.c
1 /* Preferences.c- misc personal preferences
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2003 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.
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
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
21 */
22
23 #include "WPrefs.h"
24
25 typedef struct _Panel {
26 WMBox *box;
27
28 char *sectionName;
29
30 char *description;
31
32 CallbackRec callbacks;
33
34 WMWidget *parent;
35
36 WMFrame *sizeF;
37 WMPopUpButton *sizeP;
38
39 WMFrame *posiF;
40 WMPopUpButton *posiP;
41
42 WMFrame *ballF;
43 WMButton *ballB[4];
44
45 WMFrame *optF;
46 WMButton *raisB;
47 #ifdef XKB_MODELOCK
48 WMButton *modeB;
49 #endif /* XKB_MODELOCK */
50
51 WMFrame *borderF;
52 WMSlider *borderS;
53 WMLabel *borderL;
54 WMButton *lrB;
55 WMButton *tbB;
56
57 } _Panel;
58
59 #define ICON_FILE "ergonomic"
60
61 static void borderCallback(WMWidget * w, void *data)
62 {
63 _Panel *panel = (_Panel *) data;
64 char buffer[64];
65 int i;
66
67 i = WMGetSliderValue(panel->borderS);
68
69 if (i == 0)
70 sprintf(buffer, _("OFF"));
71 else if (i == 1)
72 sprintf(buffer, _("1 pixel"));
73 else if (i <= 4)
74 /* 2-4 */
75 sprintf(buffer, _("%i pixels"), i);
76 else
77 /* >4 */
78 sprintf(buffer, _("%i pixels "), i); /* note space! */
79 WMSetLabelText(panel->borderL, buffer);
80 }
81
82 static void showData(_Panel * panel)
83 {
84 char *str;
85 int x;
86
87 str = GetStringForKey("ResizeDisplay");
88 if (!str)
89 str = "corner";
90 if (strcasecmp(str, "corner") == 0)
91 WMSetPopUpButtonSelectedItem(panel->sizeP, 0);
92 else if (strcasecmp(str, "center") == 0)
93 WMSetPopUpButtonSelectedItem(panel->sizeP, 1);
94 else if (strcasecmp(str, "floating") == 0)
95 WMSetPopUpButtonSelectedItem(panel->sizeP, 2);
96 else if (strcasecmp(str, "line") == 0)
97 WMSetPopUpButtonSelectedItem(panel->sizeP, 3);
98 else if (strcasecmp(str, "none") == 0)
99 WMSetPopUpButtonSelectedItem(panel->sizeP, 4);
100
101 str = GetStringForKey("MoveDisplay");
102 if (!str)
103 str = "corner";
104 if (strcasecmp(str, "corner") == 0)
105 WMSetPopUpButtonSelectedItem(panel->posiP, 0);
106 else if (strcasecmp(str, "center") == 0)
107 WMSetPopUpButtonSelectedItem(panel->posiP, 1);
108 else if (strcasecmp(str, "floating") == 0)
109 WMSetPopUpButtonSelectedItem(panel->posiP, 2);
110 else if (strcasecmp(str, "none") == 0)
111 WMSetPopUpButtonSelectedItem(panel->posiP, 3);
112
113 x = GetIntegerForKey("WorkspaceBorderSize");
114 x = x < 0 ? 0 : x;
115 x = x > 5 ? 5 : x;
116 WMSetSliderValue(panel->borderS, x);
117 borderCallback(NULL, panel);
118
119 str = GetStringForKey("WorkspaceBorder");
120 if (!str)
121 str = "none";
122 if (strcasecmp(str, "LeftRight") == 0) {
123 WMSetButtonSelected(panel->lrB, True);
124 } else if (strcasecmp(str, "TopBottom") == 0) {
125 WMSetButtonSelected(panel->tbB, True);
126 } else if (strcasecmp(str, "AllDirections") == 0) {
127 WMSetButtonSelected(panel->tbB, True);
128 WMSetButtonSelected(panel->lrB, True);
129 }
130
131 WMSetButtonSelected(panel->raisB, GetBoolForKey("CirculateRaise"));
132 #ifdef XKB_MODELOCK
133 WMSetButtonSelected(panel->modeB, GetBoolForKey("KbdModeLock"));
134 #endif /* XKB_MODELOCK */
135
136 WMSetButtonSelected(panel->ballB[0], GetBoolForKey("WindowTitleBalloons"));
137 WMSetButtonSelected(panel->ballB[1], GetBoolForKey("MiniwindowTitleBalloons"));
138 WMSetButtonSelected(panel->ballB[2], GetBoolForKey("AppIconBalloons"));
139 WMSetButtonSelected(panel->ballB[3], GetBoolForKey("HelpBalloons"));
140 }
141
142 static void storeData(_Panel * panel)
143 {
144 char *str;
145 Bool lr, tb;
146
147 switch (WMGetPopUpButtonSelectedItem(panel->sizeP)) {
148 case 0:
149 str = "corner";
150 break;
151 case 1:
152 str = "center";
153 break;
154 case 2:
155 str = "floating";
156 break;
157 case 4:
158 str = "none";
159 break;
160 default:
161 str = "line";
162 break;
163 }
164 SetStringForKey(str, "ResizeDisplay");
165
166 switch (WMGetPopUpButtonSelectedItem(panel->posiP)) {
167 case 0:
168 str = "corner";
169 break;
170 case 1:
171 str = "center";
172 break;
173 case 3:
174 str = "none";
175 break;
176 default:
177 str = "floating";
178 break;
179 }
180 SetStringForKey(str, "MoveDisplay");
181
182 lr = WMGetButtonSelected(panel->lrB);
183 tb = WMGetButtonSelected(panel->tbB);
184 if (lr && tb)
185 str = "AllDirections";
186 else if (lr)
187 str = "LeftRight";
188 else if (tb)
189 str = "TopBottom";
190 else
191 str = "None";
192 SetStringForKey(str, "WorkspaceBorder");
193 SetIntegerForKey(WMGetSliderValue(panel->borderS), "WorkspaceBorderSize");
194
195 SetBoolForKey(WMGetButtonSelected(panel->raisB), "CirculateRaise");
196 #ifdef XKB_MODELOCK
197 SetBoolForKey(WMGetButtonSelected(panel->modeB), "KbdModeLock");
198 #endif /* XKB_MODELOCK */
199 SetBoolForKey(WMGetButtonSelected(panel->ballB[0]), "WindowTitleBalloons");
200 SetBoolForKey(WMGetButtonSelected(panel->ballB[1]), "MiniwindowTitleBalloons");
201 SetBoolForKey(WMGetButtonSelected(panel->ballB[2]), "AppIconBalloons");
202 SetBoolForKey(WMGetButtonSelected(panel->ballB[3]), "HelpBalloons");
203 }
204
205 static void createPanel(Panel * p)
206 {
207 _Panel *panel = (_Panel *) p;
208 int i;
209
210 panel->box = WMCreateBox(panel->parent);
211 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
212
213 /***************** Size Display ****************/
214 panel->sizeF = WMCreateFrame(panel->box);
215 WMResizeWidget(panel->sizeF, 240, 60);
216 WMMoveWidget(panel->sizeF, 20, 10);
217 WMSetFrameTitle(panel->sizeF, _("Size Display"));
218
219 WMSetBalloonTextForView(_("The position or style of the window size\n"
220 "display that's shown when a window is resized."), WMWidgetView(panel->sizeF));
221
222 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
223 WMResizeWidget(panel->sizeP, 200, 20);
224 WMMoveWidget(panel->sizeP, 22, 24);
225 WMAddPopUpButtonItem(panel->sizeP, _("Corner of screen"));
226 WMAddPopUpButtonItem(panel->sizeP, _("Center of screen"));
227 WMAddPopUpButtonItem(panel->sizeP, _("Center of resized window"));
228 WMAddPopUpButtonItem(panel->sizeP, _("Technical drawing-like"));
229 WMAddPopUpButtonItem(panel->sizeP, _("Disabled"));
230
231 WMMapSubwidgets(panel->sizeF);
232
233 /***************** Position Display ****************/
234 panel->posiF = WMCreateFrame(panel->box);
235 WMResizeWidget(panel->posiF, 240, 60);
236 WMMoveWidget(panel->posiF, 20, 75);
237 WMSetFrameTitle(panel->posiF, _("Position Display"));
238
239 WMSetBalloonTextForView(_("The position or style of the window position\n"
240 "display that's shown when a window is moved."), WMWidgetView(panel->posiF));
241
242 panel->posiP = WMCreatePopUpButton(panel->posiF);
243 WMResizeWidget(panel->posiP, 200, 20);
244 WMMoveWidget(panel->posiP, 22, 24);
245 WMAddPopUpButtonItem(panel->posiP, _("Corner of screen"));
246 WMAddPopUpButtonItem(panel->posiP, _("Center of screen"));
247 WMAddPopUpButtonItem(panel->posiP, _("Center of resized window"));
248 WMAddPopUpButtonItem(panel->posiP, _("Disabled"));
249
250 WMMapSubwidgets(panel->posiF);
251
252 /***************** Balloon Text ****************/
253 panel->ballF = WMCreateFrame(panel->box);
254 WMResizeWidget(panel->ballF, 235, 125);
255 WMMoveWidget(panel->ballF, 270, 10);
256 WMSetFrameTitle(panel->ballF, _("Show balloon text for..."));
257
258 for (i = 0; i < 4; i++) {
259 panel->ballB[i] = WMCreateSwitchButton(panel->ballF);
260 WMResizeWidget(panel->ballB[i], 205, 20);
261 WMMoveWidget(panel->ballB[i], 15, 20 + i * 25);
262 }
263 WMSetButtonText(panel->ballB[0], _("incomplete window titles"));
264 WMSetButtonText(panel->ballB[1], _("miniwindow titles"));
265 WMSetButtonText(panel->ballB[2], _("application/dock icons"));
266 WMSetButtonText(panel->ballB[3], _("internal help"));
267
268 WMMapSubwidgets(panel->ballF);
269
270 /***************** Options ****************/
271 panel->optF = WMCreateFrame(panel->box);
272 WMResizeWidget(panel->optF, 235, 75);
273 WMMoveWidget(panel->optF, 270, 145);
274
275 panel->raisB = WMCreateSwitchButton(panel->optF);
276 WMResizeWidget(panel->raisB, 210, 30);
277 WMMoveWidget(panel->raisB, 15, 7);
278 WMSetButtonText(panel->raisB, _("Raise window when switching\nfocus with keyboard."));
279
280 #ifdef XKB_MODELOCK
281 panel->modeB = WMCreateSwitchButton(panel->optF);
282 WMResizeWidget(panel->modeB, 210, 30);
283 WMMoveWidget(panel->modeB, 15, 40);
284 WMSetButtonText(panel->modeB, _("Enable keyboard language\nswitch button in window titlebars."));
285 #endif
286
287 WMMapSubwidgets(panel->optF);
288
289 /***************** Workspace border ****************/
290 panel->borderF = WMCreateFrame(panel->box);
291 WMResizeWidget(panel->borderF, 240, 75);
292 WMMoveWidget(panel->borderF, 20, 145);
293 WMSetFrameTitle(panel->borderF, _("Workspace border"));
294
295 panel->borderS = WMCreateSlider(panel->borderF);
296 WMResizeWidget(panel->borderS, 80, 15);
297 WMMoveWidget(panel->borderS, 20, 20);
298 WMSetSliderMinValue(panel->borderS, 0);
299 WMSetSliderMaxValue(panel->borderS, 5);
300 WMSetSliderAction(panel->borderS, borderCallback, panel);
301
302 panel->borderL = WMCreateLabel(panel->borderF);
303 WMResizeWidget(panel->borderL, 100, 15);
304 WMMoveWidget(panel->borderL, 105, 20);
305
306 panel->lrB = WMCreateSwitchButton(panel->borderF);
307 WMMoveWidget(panel->lrB, 20, 40);
308 WMResizeWidget(panel->lrB, 100, 30);
309 WMSetButtonText(panel->lrB, _("Left/Right"));
310
311 panel->tbB = WMCreateSwitchButton(panel->borderF);
312 WMMoveWidget(panel->tbB, 120, 40);
313 WMResizeWidget(panel->tbB, 100, 30);
314 WMSetButtonText(panel->tbB, _("Top/Bottom"));
315
316 WMMapSubwidgets(panel->borderF);
317
318 WMRealizeWidget(panel->box);
319 WMMapSubwidgets(panel->box);
320
321 showData(panel);
322 }
323
324 Panel *InitPreferences(WMScreen * scr, WMWidget * parent)
325 {
326 _Panel *panel;
327
328 panel = wmalloc(sizeof(_Panel));
329 memset(panel, 0, sizeof(_Panel));
330
331 panel->sectionName = _("Miscellaneous Ergonomic Preferences");
332 panel->description = _("Various settings like balloon text, geometry\n" "displays etc.");
333
334 panel->parent = parent;
335
336 panel->callbacks.createWidgets = createPanel;
337 panel->callbacks.updateDomain = storeData;
338
339 AddSection(panel, ICON_FILE);
340
341 return panel;
342 }