Updating to version 0.20.2
[wmaker-crm.git] / WPrefs.app / Workspace.c
blob80b58db70a61d3fc5d204e6d30729def75bc89b5
1 /* Workspace.c- workspace options
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"
27 typedef struct _Panel {
28 WMFrame *frame;
30 char *sectionName;
32 CallbackRec callbacks;
34 WMWindow *win;
36 WMFrame *navF;
37 WMButton *linkB;
38 WMButton *cyclB;
39 WMButton *newB;
40 WMLabel *linkL;
41 WMLabel *cyclL;
42 WMLabel *newL;
44 WMFrame *dockF;
45 WMButton *dockB;
46 WMButton *clipB;
47 } _Panel;
51 #define ICON_FILE "workspace"
53 #define ARQUIVO_XIS "xis"
54 #define DONT_LINK_FILE "dontlinkworkspaces"
55 #define CYCLE_FILE "cycleworkspaces"
56 #define ADVANCE_FILE "advancetonewworkspace"
57 #define DOCK_FILE "dock"
58 #define CLIP_FILE "clip"
62 static void
63 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
64 WMPixmap **icon1, WMPixmap **icon2)
66 RImage *icon;
67 RColor gray = {0xae,0xaa,0xae};
69 *icon1 = WMCreatePixmapFromFile(scr, file);
70 if (!*icon1) {
71 wwarning(_("could not load icon %s"), file);
72 *icon2 = NULL;
73 return;
75 icon = RLoadImage(rc, file, 0);
76 if (!icon) {
77 wwarning(_("could not load icon %s"), file);
78 *icon2 = NULL;
79 return;
81 RCombineImageWithColor(icon, &gray);
82 if (xis) {
83 RCombineImagesWithOpaqueness(icon, xis, 180);
84 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
85 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
86 *icon2 = NULL;
89 RDestroyImage(icon);
94 static void
95 showData(_Panel *panel)
97 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
99 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
101 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
103 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
105 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
110 static void
111 createPanel(Panel *p)
113 _Panel *panel = (_Panel*)p;
114 WMScreen *scr = WMWidgetScreen(panel->win);
115 WMPixmap *icon1, *icon2;
116 RImage *xis = NULL;
117 RContext *rc = WMScreenRContext(scr);
118 char *path;
120 path = LocateImage(ARQUIVO_XIS);
121 if (path) {
122 xis = RLoadImage(rc, path, 0);
123 if (!xis) {
124 wwarning(_("could not load image file %s"), path);
126 free(path);
129 panel->frame = WMCreateFrame(panel->win);
130 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
131 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
133 /***************** Workspace Navigation *****************/
134 panel->navF = WMCreateFrame(panel->frame);
135 WMResizeWidget(panel->navF, 365, 200);
136 WMMoveWidget(panel->navF, 20, 15);
137 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
139 panel->linkB = WMCreateButton(panel->navF, WBTToggle);
140 WMResizeWidget(panel->linkB, 60, 60);
141 WMMoveWidget(panel->linkB, 20, 25);
142 WMSetButtonImagePosition(panel->linkB, WIPImageOnly);
143 path = LocateImage(DONT_LINK_FILE);
144 if (path) {
145 createImages(scr, rc, xis, path, &icon1, &icon2);
146 if (icon2) {
147 WMSetButtonImage(panel->linkB, icon2);
148 WMReleasePixmap(icon2);
150 if (icon1) {
151 WMSetButtonAltImage(panel->linkB, icon1);
152 WMReleasePixmap(icon1);
154 free(path);
156 panel->linkL = WMCreateLabel(panel->navF);
157 WMResizeWidget(panel->linkL, 260, 38);
158 WMMoveWidget(panel->linkL, 85, 25);
159 WMSetLabelTextAlignment(panel->linkL, WALeft);
160 WMSetLabelText(panel->linkL,
161 _("drag windows between workspaces."));
164 panel->cyclB = WMCreateButton(panel->navF, WBTToggle);
165 WMResizeWidget(panel->cyclB, 60, 60);
166 WMMoveWidget(panel->cyclB, 285, 75);
167 WMSetButtonImagePosition(panel->cyclB, WIPImageOnly);
168 path = LocateImage(CYCLE_FILE);
169 if (path) {
170 createImages(scr, rc, xis, path, &icon1, &icon2);
171 if (icon2) {
172 WMSetButtonImage(panel->cyclB, icon2);
173 WMReleasePixmap(icon2);
175 if (icon1) {
176 WMSetButtonAltImage(panel->cyclB, icon1);
177 WMReleasePixmap(icon1);
179 free(path);
181 panel->cyclL = WMCreateLabel(panel->navF);
182 WMResizeWidget(panel->cyclL, 260, 38);
183 WMMoveWidget(panel->cyclL, 20, 85);
184 WMSetLabelTextAlignment(panel->cyclL, WARight);
185 WMSetLabelText(panel->cyclL,
186 _("switch to first workspace when switching past the last workspace and vice-versa"));
188 panel->newB = WMCreateButton(panel->navF, WBTToggle);
189 WMResizeWidget(panel->newB, 60, 60);
190 WMMoveWidget(panel->newB, 20, 125);
191 WMSetButtonImagePosition(panel->newB, WIPImageOnly);
192 path = LocateImage(ADVANCE_FILE);
193 if (path) {
194 createImages(scr, rc, xis, path, &icon1, &icon2);
195 if (icon2) {
196 WMSetButtonImage(panel->newB, icon2);
197 WMReleasePixmap(icon2);
199 if (icon1) {
200 WMSetButtonAltImage(panel->newB, icon1);
201 WMReleasePixmap(icon1);
203 free(path);
205 panel->newL = WMCreateLabel(panel->navF);
206 WMResizeWidget(panel->newL, 260, 38);
207 WMMoveWidget(panel->newL, 85, 140);
208 WMSetLabelTextAlignment(panel->newL, WALeft);
209 WMSetLabelText(panel->newL,
210 _("create a new workspace when switching past the last workspace."));
212 WMMapSubwidgets(panel->navF);
214 /***************** Dock/Clip *****************/
215 panel->dockF = WMCreateFrame(panel->frame);
216 WMResizeWidget(panel->dockF, 105, 200);
217 WMMoveWidget(panel->dockF, 400, 15);
218 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
220 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
221 WMResizeWidget(panel->dockB, 64, 64);
222 WMMoveWidget(panel->dockB, 20, 30);
223 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
224 path = LocateImage(DOCK_FILE);
225 if (path) {
226 createImages(scr, rc, xis, path, &icon1, &icon2);
227 if (icon2) {
228 WMSetButtonImage(panel->dockB, icon2);
229 WMReleasePixmap(icon2);
231 if (icon1) {
232 WMSetButtonAltImage(panel->dockB, icon1);
233 WMReleasePixmap(icon1);
235 free(path);
238 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
239 WMResizeWidget(panel->clipB, 64, 64);
240 WMMoveWidget(panel->clipB, 20, 110);
241 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
242 path = LocateImage(CLIP_FILE);
243 if (path) {
244 createImages(scr, rc, xis, path, &icon1, &icon2);
245 if (icon2) {
246 WMSetButtonImage(panel->clipB, icon2);
247 WMReleasePixmap(icon2);
249 if (icon1) {
250 WMSetButtonAltImage(panel->clipB, icon1);
251 WMReleasePixmap(icon1);
254 WMMapSubwidgets(panel->dockF);
256 if (xis)
257 RDestroyImage(xis);
259 WMRealizeWidget(panel->frame);
260 WMMapSubwidgets(panel->frame);
262 showData(panel);
266 static void
267 storeData(_Panel *panel)
269 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
270 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
271 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
273 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
274 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
279 Panel*
280 InitWorkspace(WMScreen *scr, WMWindow *win)
282 _Panel *panel;
284 panel = wmalloc(sizeof(_Panel));
285 memset(panel, 0, sizeof(_Panel));
287 panel->sectionName = _("Workspace Preferences");
289 panel->win = win;
291 panel->callbacks.createWidgets = createPanel;
292 panel->callbacks.updateDomain = storeData;
294 AddSection(panel, ICON_FILE);
296 return panel;