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