Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Workspace.c
blobe4fcf74f6854337dd27ee8b110f5e0b3ff0da5ab
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
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.
23 #include "WPrefs.h"
25 typedef struct _Panel {
26 WMBox *box;
28 char *sectionName;
30 char *description;
32 CallbackRec callbacks;
34 WMWidget *parent;
36 WMFrame *navF;
38 WMButton *linkB;
39 WMButton *cyclB;
40 WMButton *newB;
41 WMLabel *linkL;
42 WMLabel *cyclL;
43 WMLabel *newL;
45 WMLabel *posiL;
46 WMLabel *posL;
47 WMPopUpButton *posP;
49 WMFrame *dockF;
50 WMButton *dockB;
51 WMButton *clipB;
52 } _Panel;
54 #define ICON_FILE "workspace"
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"
64 static char *WSNamePositions[] = {
65 "none",
66 "center",
67 "top",
68 "bottom",
69 "topleft",
70 "topright",
71 "bottomleft",
72 "bottomright"
75 static void
76 createImages(WMScreen * scr, RContext * rc, RImage * xis, char *file, WMPixmap ** icon1, WMPixmap ** icon2)
78 RImage *icon;
79 RColor gray = { 0xae, 0xaa, 0xae };
81 *icon1 = WMCreatePixmapFromFile(scr, file);
82 if (!*icon1) {
83 wwarning(_("could not load icon %s"), file);
84 if (icon2)
85 *icon2 = NULL;
86 return;
89 if (!icon2)
90 return;
92 icon = RLoadImage(rc, file, 0);
93 if (!icon) {
94 wwarning(_("could not load icon %s"), file);
95 *icon2 = NULL;
96 return;
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;
106 RReleaseImage(icon);
109 static void showData(_Panel * panel)
111 int i, idx;
112 char *str;
114 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
116 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
118 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
120 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
122 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
124 str = GetStringForKey("WorkspaceNameDisplayPosition");
125 if (!str)
126 str = "center";
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;
135 WMSetPopUpButtonSelectedItem(panel->posP, idx);
138 static void createPanel(Panel * p)
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;
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);
153 wfree(path);
156 panel->box = WMCreateBox(panel->parent);
157 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
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"));
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."));
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);
181 wfree(path);
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."));
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);
200 wfree(path);
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."));
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);
219 wfree(path);
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"));
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);
239 wfree(path);
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"));
254 WMMapSubwidgets(panel->navF);
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"));
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);
273 if (icon1) {
274 WMSetButtonAltImage(panel->dockB, icon1);
275 WMReleasePixmap(icon1);
277 wfree(path);
279 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
280 "vertical icon bar in the side of the screen)."), WMWidgetView(panel->dockB));
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);
293 if (icon1) {
294 WMSetButtonAltImage(panel->clipB, icon1);
295 WMReleasePixmap(icon1);
297 wfree(path);
299 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
300 "a paper clip icon)."), WMWidgetView(panel->clipB));
302 WMMapSubwidgets(panel->dockF);
304 if (xis)
305 RReleaseImage(xis);
307 WMRealizeWidget(panel->box);
308 WMMapSubwidgets(panel->box);
310 showData(panel);
313 static void storeData(_Panel * panel)
315 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
316 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
317 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
319 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
320 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
322 SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
323 "WorkspaceNameDisplayPosition");
326 Panel *InitWorkspace(WMScreen * scr, WMWidget * parent)
328 _Panel *panel;
330 panel = wmalloc(sizeof(_Panel));
331 memset(panel, 0, sizeof(_Panel));
333 panel->sectionName = _("Workspace Preferences");
335 panel->description = _("Workspace navigation features.\n"
336 "You can also enable/disable the Dock and Clip here.");
338 panel->parent = parent;
340 panel->callbacks.createWidgets = createPanel;
341 panel->callbacks.updateDomain = storeData;
343 AddSection(panel, ICON_FILE);
345 return panel;