Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Workspace.c
1 /* Workspace.c- workspace options
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2003 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.
11 *
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.
16 *
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.
21 */
22
23 #include "WPrefs.h"
24
25 typedef struct _Panel {
26 WMBox *box;
27
28 char *sectionName;
29
30 char *description;
31
32 CallbackRec callbacks;
33
34 WMWidget *parent;
35
36 WMFrame *navF;
37
38 WMButton *linkB;
39 WMButton *cyclB;
40 WMButton *newB;
41 WMLabel *linkL;
42 WMLabel *cyclL;
43 WMLabel *newL;
44
45 WMLabel *posiL;
46 WMLabel *posL;
47 WMPopUpButton *posP;
48
49 WMFrame *dockF;
50 WMButton *dockB;
51 WMButton *clipB;
52 } _Panel;
53
54 #define ICON_FILE "workspace"
55
56 #define ARQUIVO_XIS "xis"
57 #define DONT_LINK_FILE "dontlinkworkspaces"
58 #define CYCLE_FILE "cycleworkspaces"
59 #define ADVANCE_FILE "advancetonewworkspace"
60 #define WSNAME_FILE "workspacename"
61 #define DOCK_FILE "dock"
62 #define CLIP_FILE "clip"
63
64 static char *WSNamePositions[] = {
65 "none",
66 "center",
67 "top",
68 "bottom",
69 "topleft",
70 "topright",
71 "bottomleft",
72 "bottomright"
73 };
74
75 static void
76 createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2)
77 {
78 RImage *icon;
79 RColor gray = { 0xae, 0xaa, 0xae };
80
81 *icon1 = WMCreatePixmapFromFile(scr, file);
82 if (!*icon1) {
83 wwarning(_("could not load icon %s"), file);
84 if (icon2)
85 *icon2 = NULL;
86 return;
87 }
88
89 if (!icon2)
90 return;
91
92 icon = RLoadImage(rc, file, 0);
93 if (!icon) {
94 wwarning(_("could not load icon %s"), file);
95 *icon2 = NULL;
96 return;
97 }
98 RCombineImageWithColor(icon, &gray);
99 if (xis) {
100 RCombineImagesWithOpaqueness(icon, xis, 180);
101 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
102 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
103 *icon2 = NULL;
104 }
105 }
106 RReleaseImage(icon);
107 }
108
109 static void showData(_Panel * panel)
110 {
111 int i, idx;
112 char *str;
113
114 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
115
116 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
117
118 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
119
120 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
121
122 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
123
124 str = GetStringForKey("WorkspaceNameDisplayPosition");
125 if (!str)
126 str = "center";
127
128 idx = 1; /* center */
129 for (i = 0; i < sizeof(WSNamePositions) / sizeof(char *); i++) {
130 if (strcasecmp(WSNamePositions[i], str) == 0) {
131 idx = i;
132 break;
133 }
134 }
135 WMSetPopUpButtonSelectedItem(panel->posP, idx);
136 }
137
138 static void createPanel(Panel * p)
139 {
140 _Panel *panel = (_Panel *) p;
141 WMScreen *scr = WMWidgetScreen(panel->parent);
142 WMPixmap *icon1, *icon2;
143 RImage *xis = NULL;
144 RContext *rc = WMScreenRContext(scr);
145 char *path;
146
147 path = LocateImage(ARQUIVO_XIS);
148 if (path) {
149 xis = RLoadImage(rc, path, 0);
150 if (!xis) {
151 wwarning(_("could not load image file %s"), path);
152 }
153 wfree(path);
154 }
155
156 panel->box = WMCreateBox(panel->parent);
157 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
158
159 /***************** Workspace Navigation *****************/
160 panel->navF = WMCreateFrame(panel->box);
161 WMResizeWidget(panel->navF, 365, 210);
162 WMMoveWidget(panel->navF, 15, 10);
163 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
164
165 panel->cyclB = WMCreateSwitchButton(panel->navF);
166 WMResizeWidget(panel->cyclB, 280, 34);
167 WMMoveWidget(panel->cyclB, 75, 30);
168 WMSetButtonText(panel->cyclB, _("Wrap to the first workspace from the last workspace."));
169
170 panel->cyclL = WMCreateLabel(panel->navF);
171 WMResizeWidget(panel->cyclL, 60, 60);
172 WMMoveWidget(panel->cyclL, 10, 15);
173 WMSetLabelImagePosition(panel->cyclL, WIPImageOnly);
174 path = LocateImage(CYCLE_FILE);
175 if (path) {
176 createImages(scr, rc, xis, path, &icon1, NULL);
177 if (icon1) {
178 WMSetLabelImage(panel->cyclL, icon1);
179 WMReleasePixmap(icon1);
180 }
181 wfree(path);
182 }
183
184 /**/ panel->linkB = WMCreateSwitchButton(panel->navF);
185 WMResizeWidget(panel->linkB, 280, 34);
186 WMMoveWidget(panel->linkB, 75, 75);
187 WMSetButtonText(panel->linkB, _("Switch workspaces while dragging windows."));
188
189 panel->linkL = WMCreateLabel(panel->navF);
190 WMResizeWidget(panel->linkL, 60, 40);
191 WMMoveWidget(panel->linkL, 10, 80);
192 WMSetLabelImagePosition(panel->linkL, WIPImageOnly);
193 path = LocateImage(DONT_LINK_FILE);
194 if (path) {
195 createImages(scr, rc, xis, path, &icon1, NULL);
196 if (icon1) {
197 WMSetLabelImage(panel->linkL, icon1);
198 WMReleasePixmap(icon1);
199 }
200 wfree(path);
201 }
202
203 /**/ panel->newB = WMCreateSwitchButton(panel->navF);
204 WMResizeWidget(panel->newB, 280, 34);
205 WMMoveWidget(panel->newB, 75, 120);
206 WMSetButtonText(panel->newB, _("Automatically create new workspaces."));
207
208 panel->newL = WMCreateLabel(panel->navF);
209 WMResizeWidget(panel->newL, 60, 20);
210 WMMoveWidget(panel->newL, 10, 130);
211 WMSetLabelImagePosition(panel->newL, WIPImageOnly);
212 path = LocateImage(ADVANCE_FILE);
213 if (path) {
214 createImages(scr, rc, xis, path, &icon1, NULL);
215 if (icon1) {
216 WMSetLabelImage(panel->newL, icon1);
217 WMReleasePixmap(icon1);
218 }
219 wfree(path);
220 }
221
222 /**/ panel->posL = WMCreateLabel(panel->navF);
223 WMResizeWidget(panel->posL, 140, 30);
224 WMMoveWidget(panel->posL, 75, 165);
225 WMSetLabelTextAlignment(panel->posL, WARight);
226 WMSetLabelText(panel->posL, _("Position of workspace\nname display"));
227
228 panel->posiL = WMCreateLabel(panel->navF);
229 WMResizeWidget(panel->posiL, 60, 40);
230 WMMoveWidget(panel->posiL, 10, 160);
231 WMSetLabelImagePosition(panel->posiL, WIPImageOnly);
232 path = LocateImage(WSNAME_FILE);
233 if (path) {
234 createImages(scr, rc, xis, path, &icon1, NULL);
235 if (icon1) {
236 WMSetLabelImage(panel->posiL, icon1);
237 WMReleasePixmap(icon1);
238 }
239 wfree(path);
240 }
241
242 panel->posP = WMCreatePopUpButton(panel->navF);
243 WMResizeWidget(panel->posP, 125, 20);
244 WMMoveWidget(panel->posP, 225, 175);
245 WMAddPopUpButtonItem(panel->posP, _("Disable"));
246 WMAddPopUpButtonItem(panel->posP, _("Center"));
247 WMAddPopUpButtonItem(panel->posP, _("Top"));
248 WMAddPopUpButtonItem(panel->posP, _("Bottom"));
249 WMAddPopUpButtonItem(panel->posP, _("Top/Left"));
250 WMAddPopUpButtonItem(panel->posP, _("Top/Right"));
251 WMAddPopUpButtonItem(panel->posP, _("Bottom/Left"));
252 WMAddPopUpButtonItem(panel->posP, _("Bottom/Right"));
253
254 WMMapSubwidgets(panel->navF);
255
256 /***************** Dock/Clip *****************/
257 panel->dockF = WMCreateFrame(panel->box);
258 WMResizeWidget(panel->dockF, 115, 210);
259 WMMoveWidget(panel->dockF, 390, 10);
260 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
261
262 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
263 WMResizeWidget(panel->dockB, 64, 64);
264 WMMoveWidget(panel->dockB, 25, 35);
265 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
266 path = LocateImage(DOCK_FILE);
267 if (path) {
268 createImages(scr, rc, xis, path, &icon1, &icon2);
269 if (icon2) {
270 WMSetButtonImage(panel->dockB, icon2);
271 WMReleasePixmap(icon2);
272 }
273 if (icon1) {
274 WMSetButtonAltImage(panel->dockB, icon1);
275 WMReleasePixmap(icon1);
276 }
277 wfree(path);
278 }
279 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
280 "vertical icon bar in the side of the screen)."), WMWidgetView(panel->dockB));
281
282 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
283 WMResizeWidget(panel->clipB, 64, 64);
284 WMMoveWidget(panel->clipB, 25, 120);
285 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
286 path = LocateImage(CLIP_FILE);
287 if (path) {
288 createImages(scr, rc, xis, path, &icon1, &icon2);
289 if (icon2) {
290 WMSetButtonImage(panel->clipB, icon2);
291 WMReleasePixmap(icon2);
292 }
293 if (icon1) {
294 WMSetButtonAltImage(panel->clipB, icon1);
295 WMReleasePixmap(icon1);
296 }
297 wfree(path);
298 }
299 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
300 "a paper clip icon)."), WMWidgetView(panel->clipB));
301
302 WMMapSubwidgets(panel->dockF);
303
304 if (xis)
305 RReleaseImage(xis);
306
307 WMRealizeWidget(panel->box);
308 WMMapSubwidgets(panel->box);
309
310 showData(panel);
311 }
312
313 static void storeData(_Panel * panel)
314 {
315 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
316 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
317 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
318
319 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
320 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
321
322 SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
323 "WorkspaceNameDisplayPosition");
324 }
325
326 Panel *InitWorkspace(WMScreen * scr, WMWidget * parent)
327 {
328 _Panel *panel;
329
330 panel = wmalloc(sizeof(_Panel));
331 memset(panel, 0, sizeof(_Panel));
332
333 panel->sectionName = _("Workspace Preferences");
334
335 panel->description = _("Workspace navigation features.\n"
336 "You can also enable/disable the Dock and Clip here.");
337
338 panel->parent = parent;
339
340 panel->callbacks.createWidgets = createPanel;
341 panel->callbacks.updateDomain = storeData;
342
343 AddSection(panel, ICON_FILE);
344
345 return panel;
346 }