Update Serbian translation from master branch
[wmaker-crm.git] / WPrefs.app / Preferences.c
blob6a9f8276fe6f19b6c820fbc5906866ec6ed7adf8
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 if (i < 0)
200 return;
201 SetStringForKey(resize_display[i].db_value, "ResizeDisplay");
203 i = WMGetPopUpButtonSelectedItem(panel->posiP);
204 if (i < 0)
205 return;
206 SetStringForKey(move_display[i].db_value, "MoveDisplay");
208 lr = WMGetButtonSelected(panel->lrB);
209 tb = WMGetButtonSelected(panel->tbB);
210 if (lr && tb)
211 str = "AllDirections";
212 else if (lr)
213 str = "LeftRight";
214 else if (tb)
215 str = "TopBottom";
216 else
217 str = "None";
218 SetStringForKey(str, "WorkspaceBorder");
219 SetIntegerForKey(WMGetSliderValue(panel->borderS), "WorkspaceBorderSize");
221 for (i = 0; i < wlengthof(appicon_bouncing); i++)
222 SetBoolForKey(WMGetButtonSelected(panel->bounceB[i]), appicon_bouncing[i].db_key);
224 for (i = 0; i < wlengthof(balloon_choices); i++)
225 SetBoolForKey(WMGetButtonSelected(panel->ballB[i]), balloon_choices[i].db_key);
228 static void createPanel(Panel * p)
230 _Panel *panel = (_Panel *) p;
231 int i;
233 panel->box = WMCreateBox(panel->parent);
234 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
236 /***************** Size Display ****************/
237 panel->sizeF = WMCreateFrame(panel->box);
238 WMResizeWidget(panel->sizeF, 255, 52);
239 WMMoveWidget(panel->sizeF, 15, 7);
240 WMSetFrameTitle(panel->sizeF, _("Size Display"));
242 WMSetBalloonTextForView(_("The position or style of the window size\n"
243 "display that's shown when a window is resized."), WMWidgetView(panel->sizeF));
245 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
246 WMResizeWidget(panel->sizeP, 227, 20);
247 WMMoveWidget(panel->sizeP, 14, 20);
248 for (i = 0; i < wlengthof(resize_display); i++)
249 WMAddPopUpButtonItem(panel->sizeP, _(resize_display[i].label));
251 WMMapSubwidgets(panel->sizeF);
253 /***************** Position Display ****************/
254 panel->posiF = WMCreateFrame(panel->box);
255 WMResizeWidget(panel->posiF, 255, 52);
256 WMMoveWidget(panel->posiF, 15, 66);
257 WMSetFrameTitle(panel->posiF, _("Position Display"));
259 WMSetBalloonTextForView(_("The position or style of the window position\n"
260 "display that's shown when a window is moved."), WMWidgetView(panel->posiF));
262 panel->posiP = WMCreatePopUpButton(panel->posiF);
263 WMResizeWidget(panel->posiP, 227, 20);
264 WMMoveWidget(panel->posiP, 14, 20);
265 for (i = 0; i < wlengthof(move_display); i++)
266 WMAddPopUpButtonItem(panel->posiP, _(move_display[i].label));
268 WMMapSubwidgets(panel->posiF);
270 /***************** Balloon Text ****************/
271 panel->ballF = WMCreateFrame(panel->box);
272 WMResizeWidget(panel->ballF, 220, 130);
273 WMMoveWidget(panel->ballF, 285, 7);
274 WMSetFrameTitle(panel->ballF, _("Show balloon for..."));
276 for (i = 0; i < wlengthof(balloon_choices); i++) {
277 panel->ballB[i] = WMCreateSwitchButton(panel->ballF);
278 WMResizeWidget(panel->ballB[i], 198, 20);
279 WMMoveWidget(panel->ballB[i], 11, 20 + i * 26);
280 WMSetButtonText(panel->ballB[i], _(balloon_choices[i].label));
283 WMMapSubwidgets(panel->ballF);
285 /***************** Options ****************/
286 panel->optF = WMCreateFrame(panel->box);
287 WMResizeWidget(panel->optF, 255, 94);
288 WMMoveWidget(panel->optF, 15, 125);
289 WMSetFrameTitle(panel->optF, _("AppIcon bouncing"));
291 for (i = 0; i < wlengthof(appicon_bouncing); i++) {
292 panel->bounceB[i] = WMCreateSwitchButton(panel->optF);
293 WMResizeWidget(panel->bounceB[i], 237, 26);
294 WMMoveWidget(panel->bounceB[i], 9, 14 + i * 25);
295 WMSetButtonText(panel->bounceB[i], _(appicon_bouncing[i].label));
297 if (appicon_bouncing[i].default_value)
298 WMSetButtonSelected(panel->bounceB[i], True);
300 if (appicon_bouncing[i].balloon_msg)
301 WMSetBalloonTextForView(_(appicon_bouncing[i].balloon_msg),
302 WMWidgetView(panel->bounceB[i]));
305 WMMapSubwidgets(panel->optF);
307 /***************** Workspace border ****************/
308 panel->borderF = WMCreateFrame(panel->box);
309 WMResizeWidget(panel->borderF, 220, 75);
310 WMMoveWidget(panel->borderF, 285, 144);
311 WMSetFrameTitle(panel->borderF, _("Workspace border"));
313 panel->borderS = WMCreateSlider(panel->borderF);
314 WMResizeWidget(panel->borderS, 80, 15);
315 WMMoveWidget(panel->borderS, 11, 22);
316 WMSetSliderMinValue(panel->borderS, 0);
317 WMSetSliderMaxValue(panel->borderS, 5);
318 WMSetSliderAction(panel->borderS, borderCallback, panel);
320 panel->borderL = WMCreateLabel(panel->borderF);
321 WMResizeWidget(panel->borderL, 100, 15);
322 WMMoveWidget(panel->borderL, 105, 22);
324 panel->lrB = WMCreateSwitchButton(panel->borderF);
325 WMMoveWidget(panel->lrB, 11, 40);
326 WMResizeWidget(panel->lrB, 95, 30);
327 WMSetButtonText(panel->lrB, _("Left/Right"));
329 panel->tbB = WMCreateSwitchButton(panel->borderF);
330 WMMoveWidget(panel->tbB, 110, 40);
331 WMResizeWidget(panel->tbB, 105, 30);
332 WMSetButtonText(panel->tbB, _("Top/Bottom"));
334 WMMapSubwidgets(panel->borderF);
336 WMRealizeWidget(panel->box);
337 WMMapSubwidgets(panel->box);
339 showData(panel);
342 Panel *InitPreferences(WMWidget *parent)
344 _Panel *panel;
346 panel = wmalloc(sizeof(_Panel));
348 panel->sectionName = _("Miscellaneous Ergonomic Preferences");
349 panel->description = _("Various settings like balloon text, geometry\n" "displays etc.");
351 panel->parent = parent;
353 panel->callbacks.createWidgets = createPanel;
354 panel->callbacks.updateDomain = storeData;
356 AddSection(panel, ICON_FILE);
358 return panel;