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