changed top widget of panels from frame to box
[wmaker-crm.git] / WPrefs.app / Focus.c
bloba33db8b008c7a4539aada40993f5c764d2a1d074
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 WMPopUpButton *kfocP;
39 WMLabel *kfocL;
41 WMFrame *cfocF;
42 WMButton *autB;
43 WMButton *manB;
45 WMFrame *raisF;
46 WMButton *raisB[5];
47 WMTextField *raisT;
48 WMLabel *raisL;
50 WMFrame *optF;
51 WMButton *ignB;
52 WMButton *newB;
54 char raiseDelaySelected;
55 } _Panel;
59 #define ICON_FILE "windowfocus"
61 #define DELAY_ICON "timer%i"
62 #define DELAY_ICON_S "timer%is"
64 static void changeFocusMode(WMWidget *w, void *data);
66 static void
67 showData(_Panel *panel)
69 char *str;
70 int i;
71 char buffer[32];
73 str = GetStringForKey("FocusMode");
74 if (!str)
75 str = "manual";
76 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
77 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
78 else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0)
79 WMSetPopUpButtonSelectedItem(panel->kfocP, 1);
80 else if (strcasecmp(str, "semiauto")==0 || strcasecmp(str, "sloppy")==0)
81 WMSetPopUpButtonSelectedItem(panel->kfocP, 2);
82 else {
83 wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
84 str);
85 WMSetPopUpButtonSelectedItem(panel->kfocP, 0);
87 changeFocusMode(panel->kfocP, panel);
89 /**/
90 str = GetStringForKey("ColormapMode");
91 if (!str)
92 str = "auto";
93 if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
94 WMPerformButtonClick(panel->manB);
95 } else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
96 WMPerformButtonClick(panel->autB);
97 } else {
98 wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
99 str);
100 WMPerformButtonClick(panel->manB);
103 /**/
104 i = GetIntegerForKey("RaiseDelay");
105 sprintf(buffer, "%i", i);
106 WMSetTextFieldText(panel->raisT, buffer);
108 switch (i) {
109 case 0:
110 WMPerformButtonClick(panel->raisB[0]);
111 break;
112 case 10:
113 WMPerformButtonClick(panel->raisB[1]);
114 break;
115 case 100:
116 WMPerformButtonClick(panel->raisB[2]);
117 break;
118 case 350:
119 WMPerformButtonClick(panel->raisB[3]);
120 break;
121 case 800:
122 WMPerformButtonClick(panel->raisB[4]);
123 break;
126 /**/
127 WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
129 WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
134 static void
135 storeData(_Panel *panel)
137 char *str;
138 int i;
140 switch (WMGetPopUpButtonSelectedItem(panel->kfocP)) {
141 case 1:
142 str = "auto";
143 break;
144 case 2:
145 str = "sloppy";
146 break;
147 default:
148 str = "manual";
149 break;
151 SetStringForKey(str, "FocusMode");
153 if (WMGetButtonSelected(panel->manB)) {
154 SetStringForKey("manual", "ColormapMode");
155 } else {
156 SetStringForKey("auto", "ColormapMode");
159 str = WMGetTextFieldText(panel->raisT);
160 if (sscanf(str, "%i", &i)!=1)
161 i = 0;
162 SetIntegerForKey(i, "RaiseDelay");
164 SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
165 SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
169 static void
170 pushDelayButton(WMWidget *w, void *data)
172 _Panel *panel = (_Panel*)data;
174 panel->raiseDelaySelected = 1;
175 if (w == panel->raisB[0]) {
176 WMSetTextFieldText(panel->raisT, "OFF");
177 } else if (w == panel->raisB[1]) {
178 WMSetTextFieldText(panel->raisT, "10");
179 } else if (w == panel->raisB[2]) {
180 WMSetTextFieldText(panel->raisT, "100");
181 } else if (w == panel->raisB[3]) {
182 WMSetTextFieldText(panel->raisT, "350");
183 } else if (w == panel->raisB[4]) {
184 WMSetTextFieldText(panel->raisT, "800");
189 static void
190 changeFocusMode(WMWidget *w, void *data)
192 _Panel *panel = (_Panel*)data;
194 switch (WMGetPopUpButtonSelectedItem(w)) {
195 case 0:
196 WMSetLabelText(panel->kfocL, _("Click on the window to set\n"\
197 "keyboard input focus."));
198 break;
199 case 1:
200 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
201 "the window under the mouse pointer,\n"\
202 "including the root window."));
203 break;
204 case 2:
205 WMSetLabelText(panel->kfocL, _("Set keyboard input focus to\n"\
206 "the window under the mouse pointer,\n"\
207 "except the root window."));
208 break;
213 static void
214 raiseTextChanged(void *observerData, WMNotification *notification)
216 _Panel *panel = (_Panel*)observerData;
217 int i;
219 if (panel->raiseDelaySelected) {
220 for (i=0; i<5; i++) {
221 WMSetButtonSelected(panel->raisB[i], False);
223 panel->raiseDelaySelected = 0;
230 static void
231 createPanel(Panel *p)
233 _Panel *panel = (_Panel*)p;
234 WMScreen *scr = WMWidgetScreen(panel->parent);
235 int i;
236 char *buf1, *buf2;
237 WMPixmap *icon;
238 WMColor *color;
239 WMFont *font;
241 panel->box = WMCreateBox(panel->parent);
242 WMSetBoxExpandsToParent(panel->box, 2, 2, 0, 0);
244 /***************** Input Focus Mode *****************/
245 panel->kfocF = WMCreateFrame(panel->box);
246 WMResizeWidget(panel->kfocF, 240, 130);
247 WMMoveWidget(panel->kfocF, 15, 15);
248 WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
250 panel->kfocP = WMCreatePopUpButton(panel->kfocF);
251 WMResizeWidget(panel->kfocP, 210, 20);
252 WMMoveWidget(panel->kfocP, 15, 30);
253 WMAddPopUpButtonItem(panel->kfocP, _("Click window to focus"));
254 WMAddPopUpButtonItem(panel->kfocP, _("Focus follows mouse"));
255 WMAddPopUpButtonItem(panel->kfocP, _("\"Sloppy\" focus"));
256 WMSetPopUpButtonAction(panel->kfocP, changeFocusMode, panel);
258 panel->kfocL = WMCreateLabel(panel->kfocF);
259 WMResizeWidget(panel->kfocL, 211, 68);
260 WMMoveWidget(panel->kfocL, 15, 55);
261 WMSetLabelTextAlignment(panel->kfocL, WACenter);
263 WMMapSubwidgets(panel->kfocF);
265 /***************** Colormap Installation Mode ****************/
267 panel->cfocF = WMCreateFrame(panel->box);
268 WMResizeWidget(panel->cfocF, 240, 70);
269 WMMoveWidget(panel->cfocF, 15, 150);
270 WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
272 panel->manB = WMCreateRadioButton(panel->cfocF);
273 WMResizeWidget(panel->manB, 220, 20);
274 WMMoveWidget(panel->manB, 15, 18);
275 WMSetButtonText(panel->manB, _("...that has the input focus."));
277 panel->autB = WMCreateRadioButton(panel->cfocF);
278 WMResizeWidget(panel->autB, 220, 20);
279 WMMoveWidget(panel->autB, 15, 40);
280 WMSetButtonText(panel->autB, _("...that is under the mouse pointer."));
281 WMGroupButtons(panel->manB, panel->autB);
283 WMMapSubwidgets(panel->cfocF);
285 /***************** Automatic window raise delay *****************/
286 panel->raisF = WMCreateFrame(panel->box);
287 WMResizeWidget(panel->raisF, 245, 70);
288 WMMoveWidget(panel->raisF, 265, 15);
289 WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
291 buf1 = wmalloc(strlen(DELAY_ICON)+1);
292 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
294 for (i = 0; i < 5; i++) {
295 char *path;
297 panel->raisB[i] = WMCreateCustomButton(panel->raisF,
298 WBBStateChangeMask);
299 WMResizeWidget(panel->raisB[i], 25, 25);
300 WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
301 WMSetButtonBordered(panel->raisB[i], False);
302 WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
303 WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
304 if (i>0)
305 WMGroupButtons(panel->raisB[0], panel->raisB[i]);
306 sprintf(buf1, DELAY_ICON, i);
307 sprintf(buf2, DELAY_ICON_S, i);
308 path = LocateImage(buf1);
309 if (path) {
310 icon = WMCreatePixmapFromFile(scr, path);
311 if (icon) {
312 WMSetButtonImage(panel->raisB[i], icon);
313 WMReleasePixmap(icon);
314 } else {
315 wwarning(_("could not load icon file %s"), path);
317 wfree(path);
319 path = LocateImage(buf2);
320 if (path) {
321 icon = WMCreatePixmapFromFile(scr, path);
322 if (icon) {
323 WMSetButtonAltImage(panel->raisB[i], icon);
324 WMReleasePixmap(icon);
325 } else {
326 wwarning(_("could not load icon file %s"), path);
328 wfree(path);
331 wfree(buf1);
332 wfree(buf2);
334 panel->raisT = WMCreateTextField(panel->raisF);
335 WMResizeWidget(panel->raisT, 36, 20);
336 WMMoveWidget(panel->raisT, 165, 30);
337 WMAddNotificationObserver(raiseTextChanged, panel,
338 WMTextDidChangeNotification, panel->raisT);
340 color = WMDarkGrayColor(scr);
341 font = WMSystemFontOfSize(scr, 10);
343 panel->raisL = WMCreateLabel(panel->raisF);
344 WMResizeWidget(panel->raisL, 36, 16);
345 WMMoveWidget(panel->raisL, 205, 35);
346 WMSetLabelText(panel->raisL, _("msec"));
347 WMSetLabelTextColor(panel->raisL, color);
348 WMSetLabelFont(panel->raisL, font);
350 WMReleaseColor(color);
351 WMReleaseFont(font);
353 WMMapSubwidgets(panel->raisF);
355 /***************** Options ****************/
356 panel->optF = WMCreateFrame(panel->box);
357 WMResizeWidget(panel->optF, 245, 125);
358 WMMoveWidget(panel->optF, 265, 95);
360 panel->ignB = WMCreateSwitchButton(panel->optF);
361 WMResizeWidget(panel->ignB, 210, 50);
362 WMMoveWidget(panel->ignB, 15, 10);
363 WMSetButtonText(panel->ignB, _("Do not let applications receive\n"
364 "the click used to focus windows."));
366 panel->newB = WMCreateSwitchButton(panel->optF);
367 WMResizeWidget(panel->newB, 210, 35);
368 WMMoveWidget(panel->newB, 15, 70);
369 WMSetButtonText(panel->newB, _("Automatically focus new\nwindows."));
371 WMMapSubwidgets(panel->optF);
374 WMRealizeWidget(panel->box);
375 WMMapSubwidgets(panel->box);
377 showData(panel);
382 Panel*
383 InitFocus(WMScreen *scr, WMWindow *win)
385 _Panel *panel;
387 panel = wmalloc(sizeof(_Panel));
388 memset(panel, 0, sizeof(_Panel));
390 panel->sectionName = _("Window Focus Preferences");
392 panel->description = _("Keyboard focus switching policy, colormap switching\n"
393 "policy for 8bpp displays and other related options.");
395 panel->parent = win;
397 panel->callbacks.createWidgets = createPanel;
398 panel->callbacks.updateDomain = storeData;
400 AddSection(panel, ICON_FILE);
402 return panel;