changed top widget of panels from frame to box
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blob09d7c168db780b354ce02d3464d14e9368ee28e2
1 /* WindowHandling.c- options for handling windows
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 *placF;
38 WMPopUpButton *placP;
39 WMLabel *porigL;
40 WMLabel *porigvL;
41 WMFrame *porigF;
42 WMLabel *porigW;
44 WMSlider *vsli;
45 WMSlider *hsli;
47 WMFrame *resF;
48 WMSlider *resS;
49 WMLabel *resL;
50 WMButton *resaB;
51 WMButton *resrB;
53 WMFrame *maxiF;
54 WMButton *miconB;
55 WMButton *mdockB;
57 WMFrame *opaqF;
58 WMButton *opaqB;
60 WMFrame *tranF;
61 WMButton *tranB;
62 } _Panel;
65 #define ICON_FILE "whandling"
67 #define OPAQUE_MOVE_PIXMAP "opaque"
69 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
72 #define THUMB_SIZE 16
75 static char *placements[] = {
76 "auto",
77 "random",
78 "manual",
79 "cascade",
80 "smart"
84 static void
85 sliderCallback(WMWidget *w, void *data)
87 _Panel *panel = (_Panel*)data;
88 int x, y, rx, ry;
89 char buffer[64];
90 int swidth = WMGetSliderMaxValue(panel->hsli);
91 int sheight = WMGetSliderMaxValue(panel->vsli);
93 x = WMGetSliderValue(panel->hsli);
94 y = WMGetSliderValue(panel->vsli);
96 rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
97 ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
98 WMMoveWidget(panel->porigW, rx, ry);
100 sprintf(buffer, "(%i,%i)", x, y);
101 WMSetLabelText(panel->porigvL, buffer);
106 static void
107 resistanceCallback(WMWidget *w, void *data)
109 _Panel *panel = (_Panel*)data;
110 char buffer[64];
111 int i;
113 i = WMGetSliderValue(panel->resS);
115 if (i == 0)
116 WMSetLabelText(panel->resL, "OFF");
117 else {
118 sprintf(buffer, "%i", i);
119 WMSetLabelText(panel->resL, buffer);
124 static int
125 getPlacement(char *str)
127 if (!str)
128 return 0;
130 if (strcasecmp(str, "auto")==0)
131 return 0;
132 else if (strcasecmp(str, "random")==0)
133 return 1;
134 else if (strcasecmp(str, "manual")==0)
135 return 2;
136 else if (strcasecmp(str, "cascade")==0)
137 return 3;
138 else if (strcasecmp(str, "smart")==0)
139 return 4;
140 else
141 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
142 str);
143 return 0;
147 static void
148 showData(_Panel *panel)
150 char *str;
151 proplist_t arr;
152 int x, y;
154 str = GetStringForKey("WindowPlacement");
156 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
158 arr = GetObjectForKey("WindowPlaceOrigin");
160 x = 0;
161 y = 0;
162 if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
163 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
164 } else {
165 if (arr) {
166 x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
167 y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
171 WMSetSliderValue(panel->hsli, x);
172 WMSetSliderValue(panel->vsli, y);
174 sliderCallback(NULL, panel);
176 x = GetIntegerForKey("EdgeResistance");
177 WMSetSliderValue(panel->resS, x);
178 resistanceCallback(NULL, panel);
180 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
182 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
184 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
186 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
188 if (GetBoolForKey("Attraction"))
189 WMPerformButtonClick(panel->resrB);
190 else
191 WMPerformButtonClick(panel->resaB);
195 static void
196 storeData(_Panel *panel)
198 proplist_t arr;
199 char x[16], y[16];
201 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
202 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
203 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
204 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
205 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
206 "WindowPlacement");
207 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
208 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
209 arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
210 SetObjectForKey(arr, "WindowPlaceOrigin");
211 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
212 SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
213 PLRelease(arr);
217 static void
218 createPanel(Panel *p)
220 _Panel *panel = (Panel*)p;
221 WMScreen *scr = WMWidgetScreen(panel->parent);
222 WMColor *color;
223 WMPixmap *pixmap;
224 int width, height;
225 int swidth, sheight;
226 char *path;
227 WMBox *hbox;
229 panel->box = WMCreateBox(panel->parent);
230 WMSetBoxExpandsToParent(panel->box, 2, 2, 2, 2);
231 WMSetBoxHorizontal(panel->box, False);
232 WMSetBoxBorderWidth(panel->box, 8);
234 hbox = WMCreateBox(panel->box);
235 WMSetBoxHorizontal(hbox, True);
236 WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 110, 0, 10);
238 /************** Window Placement ***************/
239 panel->placF = WMCreateFrame(hbox);
240 WMMapWidget(panel->placF);
241 WMAddBoxSubview(hbox, WMWidgetView(panel->placF), True, True, 100, 0, 10);
243 WMSetFrameTitle(panel->placF, _("Window Placement"));
244 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
245 "on screen."), WMWidgetView(panel->placF));
247 panel->placP = WMCreatePopUpButton(panel->placF);
248 WMResizeWidget(panel->placP, 105, 20);
249 WMMoveWidget(panel->placP, 15, 20);
250 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
251 WMAddPopUpButtonItem(panel->placP, _("Random"));
252 WMAddPopUpButtonItem(panel->placP, _("Manual"));
253 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
254 WMAddPopUpButtonItem(panel->placP, _("Smart"));
256 panel->porigL = WMCreateLabel(panel->placF);
257 WMResizeWidget(panel->porigL, 120, 32);
258 WMMoveWidget(panel->porigL, 5, 45);
259 WMSetLabelTextAlignment(panel->porigL, WACenter);
260 WMSetLabelText(panel->porigL, _("Placement Origin"));
262 panel->porigvL = WMCreateLabel(panel->placF);
263 WMResizeWidget(panel->porigvL, 80, 20);
264 WMMoveWidget(panel->porigvL, 30, 75);
265 WMSetLabelTextAlignment(panel->porigvL, WACenter);
267 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
268 panel->porigF = WMCreateFrame(panel->placF);
269 WMSetWidgetBackgroundColor(panel->porigF, color);
270 WMReleaseColor(color);
271 WMSetFrameRelief(panel->porigF, WRSunken);
273 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
274 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
276 if (sheight > swidth) {
277 height = 70;
278 width = 70*swidth/sheight;
279 if (width > 240)
280 width = 240;
281 height = 240*sheight/swidth;
282 } else {
283 width = 240;
284 height = 240*sheight/swidth;
285 if (height > 70)
286 height = 70;
287 width = 70*swidth/sheight;
289 WMResizeWidget(panel->porigF, width, height);
290 WMMoveWidget(panel->porigF, 130+(240-width)/2, 20+(70-height)/2);
292 panel->porigW = WMCreateLabel(panel->porigF);
293 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
294 WMMoveWidget(panel->porigW, 2, 2);
295 WMSetLabelRelief(panel->porigW, WRRaised);
298 panel->hsli = WMCreateSlider(panel->placF);
299 WMResizeWidget(panel->hsli, width, 12);
300 WMMoveWidget(panel->hsli, 130+(240-width)/2, 20+(70-height)/2+height+2);
301 WMSetSliderAction(panel->hsli, sliderCallback, panel);
302 WMSetSliderMinValue(panel->hsli, 0);
303 WMSetSliderMaxValue(panel->hsli, swidth);
305 panel->vsli = WMCreateSlider(panel->placF);
306 WMResizeWidget(panel->vsli, 12, height);
307 WMMoveWidget(panel->vsli, 130+(240-width)/2+width+2, 20+(70-height)/2);
308 WMSetSliderAction(panel->vsli, sliderCallback, panel);
309 WMSetSliderMinValue(panel->vsli, 0);
310 WMSetSliderMaxValue(panel->vsli, sheight);
312 WMMapSubwidgets(panel->porigF);
314 WMMapSubwidgets(panel->placF);
316 /************** Opaque Move ***************/
317 panel->opaqF = WMCreateFrame(hbox);
318 WMMapWidget(panel->opaqF);
319 WMAddBoxSubview(hbox, WMWidgetView(panel->opaqF), False, True, 110, 0, 0);
321 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
322 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
323 "when dragging windows aroung or if only a\n"
324 "frame should be displayed.\n"),
325 WMWidgetView(panel->opaqF));
327 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
328 WMResizeWidget(panel->opaqB, 64, 64);
329 WMMoveWidget(panel->opaqB, 24, 25);
330 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
332 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
333 if (path) {
334 pixmap = WMCreatePixmapFromFile(scr, path);
335 if (pixmap) {
336 WMSetButtonImage(panel->opaqB, pixmap);
337 WMReleasePixmap(pixmap);
338 } else {
339 wwarning(_("could not load icon %s"), path);
341 wfree(path);
344 path = LocateImage(OPAQUE_MOVE_PIXMAP);
345 if (path) {
346 pixmap = WMCreatePixmapFromFile(scr, path);
347 if (pixmap) {
348 WMSetButtonAltImage(panel->opaqB, pixmap);
349 WMReleasePixmap(pixmap);
350 } else {
351 wwarning(_("could not load icon %s"), path);
353 wfree(path);
355 WMMapSubwidgets(panel->opaqF);
357 /**************** Account for Icon/Dock ***************/
358 panel->maxiF = WMCreateFrame(panel->box);
359 WMResizeWidget(panel->maxiF, 205, 95);
360 WMMoveWidget(panel->maxiF, 305, 125);
361 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
363 panel->miconB = WMCreateSwitchButton(panel->maxiF);
364 WMResizeWidget(panel->miconB, 190, 30);
365 WMMoveWidget(panel->miconB, 10, 18);
366 WMSetButtonText(panel->miconB, _("...do not cover icons"));
368 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
369 WMResizeWidget(panel->mdockB, 190, 30);
370 WMMoveWidget(panel->mdockB, 10, 53);
372 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
374 WMMapSubwidgets(panel->maxiF);
376 /**************** Edge Resistance ****************/
378 panel->resF = WMCreateFrame(panel->box);
379 WMResizeWidget(panel->resF, 285, 45);
380 WMMoveWidget(panel->resF, 8, 125);
381 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
383 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
384 "being moved further for the defined threshold\n"
385 "when moved against other windows or the edges\n"
386 "of the screen."), WMWidgetView(panel->resF));
388 panel->resS = WMCreateSlider(panel->resF);
389 WMResizeWidget(panel->resS, 80, 15);
390 WMMoveWidget(panel->resS, 10, 20);
391 WMSetSliderMinValue(panel->resS, 0);
392 WMSetSliderMaxValue(panel->resS, 80);
393 WMSetSliderAction(panel->resS, resistanceCallback, panel);
395 panel->resL = WMCreateLabel(panel->resF);
396 WMResizeWidget(panel->resL, 30, 15);
397 WMMoveWidget(panel->resL, 95, 20);
399 panel->resaB = WMCreateRadioButton(panel->resF);
400 WMMoveWidget(panel->resaB, 130, 12);
401 WMResizeWidget(panel->resaB, 70, 30);
402 WMSetButtonText(panel->resaB, _("Resist"));
404 panel->resrB = WMCreateRadioButton(panel->resF);
405 WMMoveWidget(panel->resrB, 200, 12);
406 WMResizeWidget(panel->resrB, 65, 30);
407 WMSetButtonText(panel->resrB, _("Attract"));
408 WMGroupButtons(panel->resrB, panel->resaB);
412 WMMapSubwidgets(panel->resF);
414 /**************** Transients on Parent Workspace ****************/
416 panel->tranF = WMCreateFrame(panel->box);
417 WMResizeWidget(panel->tranF, 285, 40);
418 WMMoveWidget(panel->tranF, 8, 180);
420 panel->tranB = WMCreateSwitchButton(panel->tranF);
421 WMMoveWidget(panel->tranB, 10, 5);
422 WMResizeWidget(panel->tranB, 250, 30);
423 WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
425 WMMapSubwidgets(panel->tranF);
427 WMRealizeWidget(panel->box);
428 WMMapSubwidgets(panel->box);
430 /* show the config data */
431 showData(panel);
435 static void
436 undo(_Panel *panel)
438 showData(panel);
442 Panel*
443 InitWindowHandling(WMScreen *scr, WMWidget *parent)
445 _Panel *panel;
447 panel = wmalloc(sizeof(_Panel));
448 memset(panel, 0, sizeof(_Panel));
450 panel->sectionName = _("Window Handling Preferences");
452 panel->description = _("Window handling options. Initial placement style\n"
453 "edge resistance, opaque move etc.");
455 panel->parent = parent;
457 panel->callbacks.createWidgets = createPanel;
458 panel->callbacks.updateDomain = storeData;
459 panel->callbacks.undoChanges = undo;
461 AddSection(panel, ICON_FILE);
463 return panel;