Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Workspace.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* Workspace.c- workspace options
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "WPrefs.h"
24
9d2e6ef9 scottc1998-09-29 22:36:29 +000025typedef struct _Panel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026 WMBox *box;
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028 char *sectionName;
9d2e6ef9 scottc1998-09-29 22:36:29 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 char *description;
d3f29988 kojima1999-04-25 01:49:46 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032 CallbackRec callbacks;
5e4625da kojima1999-05-29 21:41:25 +000033
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 WMWidget *parent;
5e4625da kojima1999-05-29 21:41:25 +000035
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020036 WMFrame *navF;
eb87c409 kojima1999-10-20 03:25:06 +000037
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020038 WMButton *linkB;
39 WMButton *cyclB;
40 WMButton *newB;
41 WMLabel *linkL;
42 WMLabel *cyclL;
43 WMLabel *newL;
5e4625da kojima1999-05-29 21:41:25 +000044
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020045 WMLabel *posiL;
46 WMLabel *posL;
47 WMPopUpButton *posP;
eb87c409 kojima1999-10-20 03:25:06 +000048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020049 WMFrame *dockF;
50 WMButton *dockB;
51 WMButton *clipB;
9d2e6ef9 scottc1998-09-29 22:36:29 +000052} _Panel;
53
9d2e6ef9 scottc1998-09-29 22:36:29 +000054#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"
8163b93a kojima1999-10-23 21:57:52 +000060#define WSNAME_FILE "workspacename"
9d2e6ef9 scottc1998-09-29 22:36:29 +000061#define DOCK_FILE "dock"
62#define CLIP_FILE "clip"
63
eb87c409 kojima1999-10-20 03:25:06 +000064static char *WSNamePositions[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 "none",
66 "center",
67 "top",
68 "bottom",
69 "topleft",
70 "topright",
71 "bottomleft",
72 "bottomright"
eb87c409 kojima1999-10-20 03:25:06 +000073};
74
9d2e6ef9 scottc1998-09-29 22:36:29 +000075static void
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2)
9d2e6ef9 scottc1998-09-29 22:36:29 +000077{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020078 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000107}
108
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200109static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000110{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200111 int i, idx;
112 char *str;
eb87c409 kojima1999-10-20 03:25:06 +0000113
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200114 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
6830b057 dan2004-10-12 21:28:27 +0000115
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200116 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
6830b057 dan2004-10-12 21:28:27 +0000117
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200118 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
6830b057 dan2004-10-12 21:28:27 +0000119
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200120 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
6830b057 dan2004-10-12 21:28:27 +0000121
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200122 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
eb87c409 kojima1999-10-20 03:25:06 +0000123
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200124 str = GetStringForKey("WorkspaceNameDisplayPosition");
125 if (!str)
126 str = "center";
eb87c409 kojima1999-10-20 03:25:06 +0000127
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200128 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000136}
137
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200138static void createPanel(Panel * p)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000139{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200140 _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);
6830b057 dan2004-10-12 21:28:27 +0000158
9d2e6ef9 scottc1998-09-29 22:36:29 +0000159 /***************** Workspace Navigation *****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200160 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000255
256 /***************** Dock/Clip *****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200257 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000311}
312
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200313static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000314{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200315 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
316 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
317 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
6830b057 dan2004-10-12 21:28:27 +0000318
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200319 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
320 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
6830b057 dan2004-10-12 21:28:27 +0000321
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200322 SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
323 "WorkspaceNameDisplayPosition");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000324}
325
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200326Panel *InitWorkspace(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000327{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200328 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000329
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200330 panel = wmalloc(sizeof(_Panel));
331 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000332
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200333 panel->sectionName = _("Workspace Preferences");
d3f29988 kojima1999-04-25 01:49:46 +0000334
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200335 panel->description = _("Workspace navigation features.\n"
336 "You can also enable/disable the Dock and Clip here.");
d3f29988 kojima1999-04-25 01:49:46 +0000337
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200338 panel->parent = parent;
6830b057 dan2004-10-12 21:28:27 +0000339
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200340 panel->callbacks.createWidgets = createPanel;
341 panel->callbacks.updateDomain = storeData;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000342
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200343 AddSection(panel, ICON_FILE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000344
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200345 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000346}