WPrefs: add an image to represent the window in the Window Placement frame
[wmaker-crm.git] / WPrefs.app / Preferences.c
blobdfa042720d599e8784444719e34145be5fe6028b
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 { "MiniwindowApercuBalloons", N_("miniwindow apercus"), },
56 { "AppIconBalloons", N_("application/dock icons"), },
57 { "HelpBalloons", N_("internal help"), }
60 static const struct {
61 const char *db_key;
62 int default_value;
63 const char *label;
64 const char *balloon_msg;
65 } appicon_bouncing[] = {
66 { "DoNotMakeAppIconsBounce", False, N_("Disable AppIcon bounce"),
67 N_("By default, the AppIcon bounces when the application is launched") },
69 { "BounceAppIconsWhenUrgent", True, N_("Bounce when the application wants attention"),
70 NULL },
72 { "RaiseAppIconsWhenBouncing", False, N_("Raise AppIcon when bouncing"),
73 N_("Otherwise you will not see it bouncing if\nthere is a window in front of the AppIcon") }
76 typedef struct _Panel {
77 WMBox *box;
79 char *sectionName;
81 char *description;
83 CallbackRec callbacks;
85 WMWidget *parent;
87 WMFrame *sizeF;
88 WMPopUpButton *sizeP;
90 WMFrame *posiF;
91 WMPopUpButton *posiP;
93 WMFrame *ballF;
94 WMButton *ballB[wlengthof_nocheck(balloon_choices)];
96 WMFrame *optF;
97 WMButton *bounceB[wlengthof_nocheck(appicon_bouncing)];
99 WMFrame *borderF;
100 WMSlider *borderS;
101 WMLabel *borderL;
102 WMButton *lrB;
103 WMButton *tbB;
105 } _Panel;
107 #define ICON_FILE "ergonomic"
109 static void borderCallback(WMWidget * w, void *data)
111 _Panel *panel = (_Panel *) data;
112 char buffer[64];
113 int i;
115 /* Parameter not used, but tell the compiler that it is ok */
116 (void) w;
118 i = WMGetSliderValue(panel->borderS);
120 if (i == 0)
121 sprintf(buffer, _("OFF"));
122 else if (i == 1)
123 sprintf(buffer, _("1 pixel"));
124 else if (i <= 4)
125 /* 2-4 */
126 sprintf(buffer, _("%i pixels"), i);
127 else
128 /* >4 */
129 sprintf(buffer, _("%i pixels "), i); /* note space! */
130 WMSetLabelText(panel->borderL, buffer);
133 static void showData(_Panel * panel)
135 char *str;
136 int x;
138 str = GetStringForKey("ResizeDisplay");
139 if (str != NULL) {
140 for (x = 0; x < wlengthof(resize_display); x++) {
141 if (strcasecmp(str, resize_display[x].db_value) == 0) {
142 WMSetPopUpButtonSelectedItem(panel->sizeP, x);
143 goto found_valid_resize_display;
146 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
147 str, "ResizeDisplay", resize_display[0].db_value);
149 WMSetPopUpButtonSelectedItem(panel->sizeP, 0);
150 found_valid_resize_display:
152 str = GetStringForKey("MoveDisplay");
153 if (str != NULL) {
154 for (x = 0; x < wlengthof(move_display); x++) {
155 if (strcasecmp(str, move_display[x].db_value) == 0) {
156 WMSetPopUpButtonSelectedItem(panel->posiP, x);
157 goto found_valid_move_display;
160 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
161 str, "MoveDisplay", move_display[0].db_value);
163 WMSetPopUpButtonSelectedItem(panel->posiP, 0);
164 found_valid_move_display:
166 x = GetIntegerForKey("WorkspaceBorderSize");
167 x = x < 0 ? 0 : x;
168 x = x > 5 ? 5 : x;
169 WMSetSliderValue(panel->borderS, x);
170 borderCallback(NULL, panel);
172 str = GetStringForKey("WorkspaceBorder");
173 if (!str)
174 str = "none";
175 if (strcasecmp(str, "LeftRight") == 0) {
176 WMSetButtonSelected(panel->lrB, True);
177 } else if (strcasecmp(str, "TopBottom") == 0) {
178 WMSetButtonSelected(panel->tbB, True);
179 } else if (strcasecmp(str, "AllDirections") == 0) {
180 WMSetButtonSelected(panel->tbB, True);
181 WMSetButtonSelected(panel->lrB, True);
184 for (x = 0; x < wlengthof(appicon_bouncing); x++) {
185 if (GetStringForKey(appicon_bouncing[x].db_key))
186 WMSetButtonSelected(panel->bounceB[x], GetBoolForKey(appicon_bouncing[x].db_key));
189 for (x = 0; x < wlengthof(balloon_choices); x++)
190 WMSetButtonSelected(panel->ballB[x], GetBoolForKey(balloon_choices[x].db_key));
193 static void storeData(_Panel * panel)
195 char *str;
196 Bool lr, tb;
197 int i;
199 i = WMGetPopUpButtonSelectedItem(panel->sizeP);
200 SetStringForKey(resize_display[i].db_value, "ResizeDisplay");
202 i = WMGetPopUpButtonSelectedItem(panel->posiP);
203 SetStringForKey(move_display[i].db_value, "MoveDisplay");
205 lr = WMGetButtonSelected(panel->lrB);
206 tb = WMGetButtonSelected(panel->tbB);
207 if (lr && tb)
208 str = "AllDirections";
209 else if (lr)
210 str = "LeftRight";
211 else if (tb)
212 str = "TopBottom";
213 else
214 str = "None";
215 SetStringForKey(str, "WorkspaceBorder");
216 SetIntegerForKey(WMGetSliderValue(panel->borderS), "WorkspaceBorderSize");
218 for (i = 0; i < wlengthof(appicon_bouncing); i++)
219 SetBoolForKey(WMGetButtonSelected(panel->bounceB[i]), appicon_bouncing[i].db_key);
221 for (i = 0; i < wlengthof(balloon_choices); i++)
222 SetBoolForKey(WMGetButtonSelected(panel->ballB[i]), balloon_choices[i].db_key);
225 static void createPanel(Panel * p)
227 _Panel *panel = (_Panel *) p;
228 int i;
230 panel->box = WMCreateBox(panel->parent);
231 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
233 /***************** Size Display ****************/
234 panel->sizeF = WMCreateFrame(panel->box);
235 WMResizeWidget(panel->sizeF, 255, 52);
236 WMMoveWidget(panel->sizeF, 15, 7);
237 WMSetFrameTitle(panel->sizeF, _("Size Display"));
239 WMSetBalloonTextForView(_("The position or style of the window size\n"
240 "display that's shown when a window is resized."), WMWidgetView(panel->sizeF));
242 panel->sizeP = WMCreatePopUpButton(panel->sizeF);
243 WMResizeWidget(panel->sizeP, 227, 20);
244 WMMoveWidget(panel->sizeP, 14, 20);
245 for (i = 0; i < wlengthof(resize_display); i++)
246 WMAddPopUpButtonItem(panel->sizeP, _(resize_display[i].label));
248 WMMapSubwidgets(panel->sizeF);
250 /***************** Position Display ****************/
251 panel->posiF = WMCreateFrame(panel->box);
252 WMResizeWidget(panel->posiF, 255, 52);
253 WMMoveWidget(panel->posiF, 15, 66);
254 WMSetFrameTitle(panel->posiF, _("Position Display"));
256 WMSetBalloonTextForView(_("The position or style of the window position\n"
257 "display that's shown when a window is moved."), WMWidgetView(panel->posiF));
259 panel->posiP = WMCreatePopUpButton(panel->posiF);
260 WMResizeWidget(panel->posiP, 227, 20);
261 WMMoveWidget(panel->posiP, 14, 20);
262 for (i = 0; i < wlengthof(move_display); i++)
263 WMAddPopUpButtonItem(panel->posiP, _(move_display[i].label));
265 WMMapSubwidgets(panel->posiF);
267 /***************** Balloon Text ****************/
268 panel->ballF = WMCreateFrame(panel->box);
269 WMResizeWidget(panel->ballF, 220, 132);
270 WMMoveWidget(panel->ballF, 285, 7);
271 WMSetFrameTitle(panel->ballF, _("Show balloon for..."));
273 for (i = 0; i < wlengthof(balloon_choices); i++) {
274 panel->ballB[i] = WMCreateSwitchButton(panel->ballF);
275 WMResizeWidget(panel->ballB[i], 198, 20);
276 WMMoveWidget(panel->ballB[i], 11, 16 + i * 22);
277 WMSetButtonText(panel->ballB[i], _(balloon_choices[i].label));
280 WMMapSubwidgets(panel->ballF);
282 /***************** Options ****************/
283 panel->optF = WMCreateFrame(panel->box);
284 WMResizeWidget(panel->optF, 255, 94);
285 WMMoveWidget(panel->optF, 15, 125);
286 WMSetFrameTitle(panel->optF, _("AppIcon bouncing"));
288 for (i = 0; i < wlengthof(appicon_bouncing); i++) {
289 panel->bounceB[i] = WMCreateSwitchButton(panel->optF);
290 WMResizeWidget(panel->bounceB[i], 237, 26);
291 WMMoveWidget(panel->bounceB[i], 9, 14 + i * 25);
292 WMSetButtonText(panel->bounceB[i], _(appicon_bouncing[i].label));
294 if (appicon_bouncing[i].default_value)
295 WMSetButtonSelected(panel->bounceB[i], True);
297 if (appicon_bouncing[i].balloon_msg)
298 WMSetBalloonTextForView(_(appicon_bouncing[i].balloon_msg),
299 WMWidgetView(panel->bounceB[i]));
302 WMMapSubwidgets(panel->optF);
304 /***************** Workspace border ****************/
305 panel->borderF = WMCreateFrame(panel->box);
306 WMResizeWidget(panel->borderF, 220, 75);
307 WMMoveWidget(panel->borderF, 285, 144);
308 WMSetFrameTitle(panel->borderF, _("Workspace border"));
310 panel->borderS = WMCreateSlider(panel->borderF);
311 WMResizeWidget(panel->borderS, 80, 15);
312 WMMoveWidget(panel->borderS, 11, 22);
313 WMSetSliderMinValue(panel->borderS, 0);
314 WMSetSliderMaxValue(panel->borderS, 5);
315 WMSetSliderAction(panel->borderS, borderCallback, panel);
317 panel->borderL = WMCreateLabel(panel->borderF);
318 WMResizeWidget(panel->borderL, 100, 15);
319 WMMoveWidget(panel->borderL, 105, 22);
321 panel->lrB = WMCreateSwitchButton(panel->borderF);
322 WMMoveWidget(panel->lrB, 11, 40);
323 WMResizeWidget(panel->lrB, 95, 30);
324 WMSetButtonText(panel->lrB, _("Left/Right"));
326 panel->tbB = WMCreateSwitchButton(panel->borderF);
327 WMMoveWidget(panel->tbB, 110, 40);
328 WMResizeWidget(panel->tbB, 105, 30);
329 WMSetButtonText(panel->tbB, _("Top/Bottom"));
331 WMMapSubwidgets(panel->borderF);
333 WMRealizeWidget(panel->box);
334 WMMapSubwidgets(panel->box);
336 showData(panel);
339 Panel *InitPreferences(WMWidget *parent)
341 _Panel *panel;
343 panel = wmalloc(sizeof(_Panel));
345 panel->sectionName = _("Miscellaneous Ergonomic Preferences");
346 panel->description = _("Various settings like balloon text, geometry\n" "displays etc.");
348 panel->parent = parent;
350 panel->callbacks.createWidgets = createPanel;
351 panel->callbacks.updateDomain = storeData;
353 AddSection(panel, ICON_FILE);
355 return panel;