wmaker: remove useless null pointer check (Coverity #109612)
[wmaker-crm.git] / WPrefs.app / Preferences.c
blob57f944619b9ea1374ecc0c1df2e85e921832acc1
1 /* Preferences.c- misc ergonomic 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"
25 /* Possible choices to display window information during a resize */
26 static const struct {
27 const char *db_value;
28 const char *label;
29 } resize_display[] = {
30 { "corner", N_("Corner of screen") },
31 { "center", N_("Center of screen") },
32 { "floating", N_("Center of resized window") },
33 { "line", N_("Technical drawing-like") },
34 { "none", N_("Disabled") }
37 /* Possible choices to display window information while a window is being moved */
38 static const struct {
39 const char *db_value;
40 const char *label;
41 } move_display[] = {
42 { "corner", N_("Corner of screen") },
43 { "center", N_("Center of screen") },
44 { "floating", N_("Center of resized window") },
45 { "none", N_("Disabled") }
48 /* All the places where a balloon can be used to display more stuff to user */
49 static const struct {
50 const char *db_key;
51 const char *label;
52 } balloon_choices[] = {
53 { "WindowTitleBalloons", N_("incomplete window titles"), },
54 { "MiniwindowTitleBalloons", N_("miniwindow titles"), },
55 { "AppIconBalloons", N_("application/dock icons"), },
56 { "HelpBalloons", N_("internal help"), }
59 static const struct {
60 const char *db_key;
61 int default_value;
62 const char *label;
63 const char *balloon_msg;
64 } appicon_bouncing[] = {
65 { "DoNotMakeAppIconsBounce", False, N_("Disable AppIcon bounce"),
66 N_("By default, the AppIcon bounces when the application is launched") },
68 { "BounceAppIconsWhenUrgent", True, N_("Bounce when the application wants attention"),
69 NULL },
71 { "RaiseAppIconsWhenBouncing", False, N_("Raise AppIcon when bouncing"),
72 N_("Otherwise you will not see it bouncing if\nthere is a window in front of the AppIcon") }
75 typedef struct _Panel {
76 WMBox *box;
78 char *sectionName;
80 char *description;
82 CallbackRec callbacks;
84 WMWidget *parent;
86 WMFrame *sizeF;
87 WMPopUpButton *sizeP;
89 WMFrame *posiF;
90 WMPopUpButton *posiP;
92 WMFrame *ballF;
93 WMButton *ballB[wlengthof_nocheck(balloon_choices)];
95 WMFrame *optF;
96 WMButton *bounceB[wlengthof_nocheck(appicon_bouncing)];
98 WMFrame *borderF;
99 WMSlider *borderS;
100 WMLabel *borderL;
101 WMButton *lrB;
102 WMButton *tbB;
104 } _Panel;
106 #define ICON_FILE "ergonomic"
108 static void borderCallback(WMWidget * w, void *data)
110 _Panel *panel = (_Panel *) data;
111 char buffer[64];
112 int i;
114 /* Parameter not used, but tell the compiler that it is ok */
115 (void) w;
117 i = WMGetSliderValue(panel->borderS);
119 if (i == 0)
120 sprintf(buffer, _("OFF"));
121 else if (i == 1)
122 sprintf(buffer, _("1 pixel"));
123 else if (i <= 4)
124 /* 2-4 */
125 sprintf(buffer, _("%i pixels"), i);
126 else
127 /* >4 */
128 sprintf(buffer, _("%i pixels "), i); /* note space! */
129 WMSetLabelText(panel->borderL, buffer);
132 static void showData(_Panel * panel)
134 char *str;
135 int x;
137 str = GetStringForKey("ResizeDisplay");
138 if (str != NULL) {
139 for (x = 0; x < wlengthof(resize_display); x++) {
140 if (strcasecmp(str, resize_display[x].db_value) == 0) {
141 WMSetPopUpButtonSelectedItem(panel->sizeP, x);
142 goto found_valid_resize_display;
145 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
146 str, "ResizeDisplay", resize_display[0].db_value);
148 WMSetPopUpButtonSelectedItem(panel->sizeP, 0);
149 found_valid_resize_display:
151 str = GetStringForKey("MoveDisplay");
152 if (str != NULL) {
153 for (x = 0; x < wlengthof(move_display); x++) {
154 if (strcasecmp(str, move_display[x].db_value) == 0) {
155 WMSetPopUpButtonSelectedItem(panel->posiP, x);
156 goto found_valid_move_display;
159 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
160 str, "MoveDisplay", move_display[0].db_value);
162 WMSetPopUpButtonSelectedItem(panel->posiP, 0);
163 found_valid_move_display:
165 x = GetIntegerForKey("WorkspaceBorderSize");
166 x = x < 0 ? 0 : x;
167 x = x > 5 ? 5 : x;
168 WMSetSliderValue(panel->borderS, x);
169 borderCallback(NULL, panel);
171 str = GetStringForKey("WorkspaceBorder");
172 if (!str)
173 str = "none";
174 if (strcasecmp(str, "LeftRight") == 0) {
175 WMSetButtonSelected(panel->lrB, True);
176 } else if (strcasecmp(str, "TopBottom") == 0) {
177 WMSetButtonSelected(panel->tbB, True);
178 } else if (strcasecmp(str, "AllDirections") == 0) {
179 WMSetButtonSelected(panel->tbB, True);
180 WMSetButtonSelected(panel->lrB, True);
183 for (x = 0; x < wlengthof(appicon_bouncing); x++) {
184 if (GetStringForKey(appicon_bouncing[x].db_key))
185 WMSetButtonSelected(panel->bounceB[x], GetBoolForKey(appicon_bouncing[x].db_key));
188 for (x = 0; x < wlengthof(balloon_choices); x++)
189 WMSetButtonSelected(panel->ballB[x], GetBoolForKey(balloon_choices[x].db_key));
192 static void storeData(_Panel * panel)
194 char *str;
195 Bool lr, tb;
196 int i;
198 i = WMGetPopUpButtonSelectedItem(panel->sizeP);
199 SetStringForKey(resize_display[i].db_value, "ResizeDisplay");
201 i = WMGetPopUpButtonSelectedItem(panel->posiP);
202 SetStringForKey(move_display[i].db_value, "MoveDisplay");
204 lr = WMGetButtonSelected(panel->lrB);
205 tb = WMGetButtonSelected(panel->tbB);
206 if (lr && tb)
207 str = "AllDirections";
208 else if (lr)
209 str = "LeftRight";
210 else if (tb)
211 str = "TopBottom";
212 else
213 str = "None";
214 SetStringForKey(str, "WorkspaceBorder");
215 SetIntegerForKey(WMGetSliderValue(panel->borderS), "WorkspaceBorderSize");
217 for (i = 0; i < wlengthof(appicon_bouncing); i++)
218 SetBoolForKey(WMGetButtonSelected(panel->bounceB[i]), appicon_bouncing[i].db_key);
220 for (i = 0; i < wlengthof(balloon_choices); i++)
221 SetBoolForKey(WMGetButtonSelected(panel->ballB[i]), balloon_choices[i].db_key);
224 static void createPanel(Panel * p)
226 _Panel *panel = (_Panel *) p;
227 int i;
229 panel->box = WMCreateBox(panel->parent);
230 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
232 /***************** Size Display ****************/
233 panel->sizeF = WMCreateFrame(panel->box);
234 WMResizeWidget(panel->sizeF, 255, 52);
235 WMMoveWidget(panel->sizeF, 15, 7);
236 WMSetFrameTitle(panel->sizeF, _("Size Display"));
238 WMSetBalloonTextForView(_("The position or style of the window size\n"
239 "display that's shown when a window is resized."), WMWidgetView(panel->sizeF));
241 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
242 WMResizeWidget(panel->sizeP, 227, 20);
243 WMMoveWidget(panel->sizeP, 14, 20);
244 for (i = 0; i < wlengthof(resize_display); i++)
245 WMAddPopUpButtonItem(panel->sizeP, _(resize_display[i].label));
247 WMMapSubwidgets(panel->sizeF);
249 /***************** Position Display ****************/
250 panel->posiF = WMCreateFrame(panel->box);
251 WMResizeWidget(panel->posiF, 255, 52);
252 WMMoveWidget(panel->posiF, 15, 66);
253 WMSetFrameTitle(panel->posiF, _("Position Display"));
255 WMSetBalloonTextForView(_("The position or style of the window position\n"
256 "display that's shown when a window is moved."), WMWidgetView(panel->posiF));
258 panel->posiP = WMCreatePopUpButton(panel->posiF);
259 WMResizeWidget(panel->posiP, 227, 20);
260 WMMoveWidget(panel->posiP, 14, 20);
261 for (i = 0; i < wlengthof(move_display); i++)
262 WMAddPopUpButtonItem(panel->posiP, _(move_display[i].label));
264 WMMapSubwidgets(panel->posiF);
266 /***************** Balloon Text ****************/
267 panel->ballF = WMCreateFrame(panel->box);
268 WMResizeWidget(panel->ballF, 220, 130);
269 WMMoveWidget(panel->ballF, 285, 7);
270 WMSetFrameTitle(panel->ballF, _("Show balloon for..."));
272 for (i = 0; i < wlengthof(balloon_choices); i++) {
273 panel->ballB[i] = WMCreateSwitchButton(panel->ballF);
274 WMResizeWidget(panel->ballB[i], 198, 20);
275 WMMoveWidget(panel->ballB[i], 11, 20 + i * 26);
276 WMSetButtonText(panel->ballB[i], _(balloon_choices[i].label));
279 WMMapSubwidgets(panel->ballF);
281 /***************** Options ****************/
282 panel->optF = WMCreateFrame(panel->box);
283 WMResizeWidget(panel->optF, 255, 94);
284 WMMoveWidget(panel->optF, 15, 125);
285 WMSetFrameTitle(panel->optF, _("AppIcon bouncing"));
287 for (i = 0; i < wlengthof(appicon_bouncing); i++) {
288 panel->bounceB[i] = WMCreateSwitchButton(panel->optF);
289 WMResizeWidget(panel->bounceB[i], 237, 26);
290 WMMoveWidget(panel->bounceB[i], 9, 14 + i * 25);
291 WMSetButtonText(panel->bounceB[i], _(appicon_bouncing[i].label));
293 if (appicon_bouncing[i].default_value)
294 WMSetButtonSelected(panel->bounceB[i], True);
296 if (appicon_bouncing[i].balloon_msg)
297 WMSetBalloonTextForView(_(appicon_bouncing[i].balloon_msg),
298 WMWidgetView(panel->bounceB[i]));
301 WMMapSubwidgets(panel->optF);
303 /***************** Workspace border ****************/
304 panel->borderF = WMCreateFrame(panel->box);
305 WMResizeWidget(panel->borderF, 220, 75);
306 WMMoveWidget(panel->borderF, 285, 144);
307 WMSetFrameTitle(panel->borderF, _("Workspace border"));
309 panel->borderS = WMCreateSlider(panel->borderF);
310 WMResizeWidget(panel->borderS, 80, 15);
311 WMMoveWidget(panel->borderS, 11, 22);
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, 22);
320 panel->lrB = WMCreateSwitchButton(panel->borderF);
321 WMMoveWidget(panel->lrB, 11, 40);
322 WMResizeWidget(panel->lrB, 95, 30);
323 WMSetButtonText(panel->lrB, _("Left/Right"));
325 panel->tbB = WMCreateSwitchButton(panel->borderF);
326 WMMoveWidget(panel->tbB, 110, 40);
327 WMResizeWidget(panel->tbB, 105, 30);
328 WMSetButtonText(panel->tbB, _("Top/Bottom"));
330 WMMapSubwidgets(panel->borderF);
332 WMRealizeWidget(panel->box);
333 WMMapSubwidgets(panel->box);
335 showData(panel);
338 Panel *InitPreferences(WMWidget *parent)
340 _Panel *panel;
342 panel = wmalloc(sizeof(_Panel));
344 panel->sectionName = _("Miscellaneous Ergonomic Preferences");
345 panel->description = _("Various settings like balloon text, geometry\n" "displays etc.");
347 panel->parent = parent;
349 panel->callbacks.createWidgets = createPanel;
350 panel->callbacks.updateDomain = storeData;
352 AddSection(panel, ICON_FILE);
354 return panel;