new italian po files.
[wmaker-crm.git] / WPrefs.app / Focus.c
blob0e9b62273205b6bfee18aa8821aaf0b2483742b4
1 /* Focus.c- input and colormap focus stuff
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998 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 *kfocF;
38 WMButton *kfocB[2];
40 WMFrame *cfocF;
41 WMButton *autB;
42 WMButton *manB;
44 WMFrame *raisF;
45 WMButton *raisB[5];
46 WMTextField *raisT;
47 WMLabel *raisL;
49 WMFrame *optF;
50 WMButton *ignB;
51 WMButton *newB;
53 char raiseDelaySelected;
54 } _Panel;
58 #define ICON_FILE "windowfocus"
60 #define DELAY_ICON "timer%i"
61 #define DELAY_ICON_S "timer%is"
63 static void changeFocusMode(WMWidget *w, void *data);
65 static void
66 showData(_Panel *panel)
68 char *str;
69 int i;
70 char buffer[32];
72 str = GetStringForKey("FocusMode");
73 if (!str)
74 str = "manual";
75 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
76 WMSetButtonSelected(panel->kfocB[0], 1);
77 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "semiauto")==0
78 || strcasecmp(str, "sloppy")==0)
79 WMSetButtonSelected(panel->kfocB[1], 1);
80 else {
81 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
82 str);
83 WMSetButtonSelected(panel->kfocB[0], 1);
86 /**/
87 str = GetStringForKey("ColormapMode");
88 if (!str)
89 str = "auto";
90 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
91 WMPerformButtonClick(panel->manB);
92 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
93 WMPerformButtonClick(panel->autB);
94 } else {
95 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
96 str);
97 WMPerformButtonClick(panel->manB);
100 /**/
101 i = GetIntegerForKey("RaiseDelay");
102 sprintf(buffer, "%i", i);
103 WMSetTextFieldText(panel->raisT, buffer);
105 switch (i) {
106 case 0:
107 WMPerformButtonClick(panel->raisB[0]);
108 break;
109 case 10:
110 WMPerformButtonClick(panel->raisB[1]);
111 break;
112 case 100:
113 WMPerformButtonClick(panel->raisB[2]);
114 break;
115 case 350:
116 WMPerformButtonClick(panel->raisB[3]);
117 break;
118 case 800:
119 WMPerformButtonClick(panel->raisB[4]);
120 break;
123 /**/
124 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
126 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
131 static void
132 storeData(_Panel *panel)
134 char *str;
135 int i;
137 if (WMGetButtonSelected(panel->kfocB[1]))
138 str = "sloppy";
139 else
140 str = "manual";
142 SetStringForKey(str, "FocusMode");
144 if (WMGetButtonSelected(panel->manB)) {
145 SetStringForKey("manual", "ColormapMode");
146 } else {
147 SetStringForKey("auto", "ColormapMode");
150 str = WMGetTextFieldText(panel->raisT);
151 if (sscanf(str, "%i", &i)!=1)
152 i = 0;
153 SetIntegerForKey(i, "RaiseDelay");
155 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
156 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
160 static void
161 pushDelayButton(WMWidget *w, void *data)
163 _Panel *panel = (_Panel*)data;
165 panel->raiseDelaySelected = 1;
166 if (w == panel->raisB[0]) {
167 WMSetTextFieldText(panel->raisT, "OFF");
168 } else if (w == panel->raisB[1]) {
169 WMSetTextFieldText(panel->raisT, "10");
170 } else if (w == panel->raisB[2]) {
171 WMSetTextFieldText(panel->raisT, "100");
172 } else if (w == panel->raisB[3]) {
173 WMSetTextFieldText(panel->raisT, "350");
174 } else if (w == panel->raisB[4]) {
175 WMSetTextFieldText(panel->raisT, "800");
180 static void
181 raiseTextChanged(void *observerData, WMNotification *notification)
183 _Panel *panel = (_Panel*)observerData;
184 int i;
186 if (panel->raiseDelaySelected) {
187 for (i=0; i<5; i++) {
188 WMSetButtonSelected(panel->raisB[i], False);
190 panel->raiseDelaySelected = 0;
197 static void
198 createPanel(Panel *p)
200 _Panel *panel = (_Panel*)p;
201 WMScreen *scr = WMWidgetScreen(panel->parent);
202 int i;
203 char *buf1, *buf2;
204 WMPixmap *icon;
205 WMColor *color;
206 WMFont *font;
208 panel->box = WMCreateBox(panel->parent);
209 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
211 /***************** Input Focus Mode *****************/
212 panel->kfocF = WMCreateFrame(panel->box);
213 WMResizeWidget(panel->kfocF, 240, 130);
214 WMMoveWidget(panel->kfocF, 15, 15);
215 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
218 WMBox *box = WMCreateBox(panel->kfocF);
219 WMSetViewExpandsToParent(WMWidgetView(box), 10, 15, 10, 10);
220 WMSetBoxHorizontal(box, False);
222 panel->kfocB[0] = WMCreateRadioButton(box);
223 WMSetButtonText(panel->kfocB[0], _("Manual: Click on the window to set "\
224 "keyboard input focus"));
225 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[0]), True, True,
226 20, 0, 0);
228 panel->kfocB[1] = WMCreateRadioButton(box);
229 WMGroupButtons(panel->kfocB[0], panel->kfocB[1]);
230 WMSetButtonText(panel->kfocB[1], _("Auto: Set keyboard input focus to "\
231 "the window under the mouse pointer"));
232 WMAddBoxSubview(box, WMWidgetView(panel->kfocB[1]), True, True,
233 20, 0, 0);
235 WMMapSubwidgets(box);
236 WMMapWidget(box);
239 /***************** Colormap Installation Mode ****************/
241 panel->cfocF = WMCreateFrame(panel->box);
242 WMResizeWidget(panel->cfocF, 240, 70);
243 WMMoveWidget(panel->cfocF, 15, 150);
244 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
246 panel->manB = WMCreateRadioButton(panel->cfocF);
247 WMResizeWidget(panel->manB, 220, 20);
248 WMMoveWidget(panel->manB, 15, 18);
249 WMSetButtonText(panel->manB, _("...that has the input focus."));
251 panel->autB = WMCreateRadioButton(panel->cfocF);
252 WMResizeWidget(panel->autB, 220, 20);
253 WMMoveWidget(panel->autB, 15, 40);
254 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
255 WMGroupButtons(panel->manB, panel->autB);
257 WMMapSubwidgets(panel->cfocF);
259 /***************** Automatic window raise delay *****************/
260 panel->raisF = WMCreateFrame(panel->box);
261 WMResizeWidget(panel->raisF, 245, 70);
262 WMMoveWidget(panel->raisF, 265, 15);
263 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
265 buf1 = wmalloc(strlen(DELAY_ICON)+1);
266 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
268 for (i = 0; i < 5; i++) {
269 char *path;
271 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
272 WBBStateChangeMask);
273 WMResizeWidget(panel->raisB[i], 25, 25);
274 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
275 WMSetButtonBordered(panel->raisB[i], False);
276 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
277 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
278 if (i>0)
279 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
280 sprintf(buf1, DELAY_ICON, i);
281 sprintf(buf2, DELAY_ICON_S, i);
282 path = LocateImage(buf1);
283 if (path) {
284 icon = WMCreatePixmapFromFile(scr, path);
285 if (icon) {
286 WMSetButtonImage(panel->raisB[i], icon);
287 WMReleasePixmap(icon);
288 } else {
289 wwarning(_("could not load icon file %s"), path);
291 wfree(path);
293 path = LocateImage(buf2);
294 if (path) {
295 icon = WMCreatePixmapFromFile(scr, path);
296 if (icon) {
297 WMSetButtonAltImage(panel->raisB[i], icon);
298 WMReleasePixmap(icon);
299 } else {
300 wwarning(_("could not load icon file %s"), path);
302 wfree(path);
305 wfree(buf1);
306 wfree(buf2);
308 panel->raisT = WMCreateTextField(panel->raisF);
309 WMResizeWidget(panel->raisT, 36, 20);
310 WMMoveWidget(panel->raisT, 165, 30);
311 WMAddNotificationObserver(raiseTextChanged, panel,
312 WMTextDidChangeNotification, panel->raisT);
314 color = WMDarkGrayColor(scr);
315 font = WMSystemFontOfSize(scr, 10);
317 panel->raisL = WMCreateLabel(panel->raisF);
318 WMResizeWidget(panel->raisL, 36, 16);
319 WMMoveWidget(panel->raisL, 205, 35);
320 WMSetLabelText(panel->raisL, _("msec"));
321 WMSetLabelTextColor(panel->raisL, color);
322 WMSetLabelFont(panel->raisL, font);
324 WMReleaseColor(color);
325 WMReleaseFont(font);
327 WMMapSubwidgets(panel->raisF);
329 /***************** Options ****************/
330 panel->optF = WMCreateFrame(panel->box);
331 WMResizeWidget(panel->optF, 245, 125);
332 WMMoveWidget(panel->optF, 265, 95);
334 panel->ignB = WMCreateSwitchButton(panel->optF);
335 WMResizeWidget(panel->ignB, 210, 50);
336 WMMoveWidget(panel->ignB, 15, 10);
337 WMSetButtonText(panel->ignB, _("Do not let applications receive\n"
338 "the click used to focus windows."));
340 panel->newB = WMCreateSwitchButton(panel->optF);
341 WMResizeWidget(panel->newB, 210, 35);
342 WMMoveWidget(panel->newB, 15, 70);
343 WMSetButtonText(panel->newB, _("Automatically focus new\nwindows."));
345 WMMapSubwidgets(panel->optF);
348 WMRealizeWidget(panel->box);
349 WMMapSubwidgets(panel->box);
351 showData(panel);
356 Panel*
357 InitFocus(WMScreen *scr, WMWindow *win)
359 _Panel *panel;
361 panel = wmalloc(sizeof(_Panel));
362 memset(panel, 0, sizeof(_Panel));
364 panel->sectionName = _("Window Focus Preferences");
366 panel->description = _("Keyboard focus switching policy, colormap switching\n"
367 "policy for 8bpp displays and other related options.");
369 panel->parent = win;
371 panel->callbacks.createWidgets = createPanel;
372 panel->callbacks.updateDomain = storeData;
374 AddSection(panel, ICON_FILE);
376 return panel;