Initial revision
[wmaker-crm.git] / WPrefs.app / Workspace.c
blobfb9315d0dc300610e817f990275db0cff1ba029b
1 /* Workspace.c- workspace options
2 *
3 * WPrefs - WindowMaker 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;
68 *icon1 = WMCreatePixmapFromFile(scr, file);
69 if (!*icon1) {
70 wwarning(_("could not load icon %s"), file);
71 *icon2 = NULL;
72 return;
74 icon = RLoadImage(rc, file, 0);
75 if (!icon) {
76 wwarning(_("could not load icon %s"), file);
77 *icon2 = NULL;
78 return;
80 if (xis) {
81 RCombineImages(icon, xis);
82 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
83 wwarning(_("could not process icon %s:"), file, RErrorString);
84 *icon2 = NULL;
87 RDestroyImage(icon);
92 static void
93 showData(_Panel *panel)
95 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
97 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
99 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
101 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
103 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
108 static void
109 createPanel(Panel *p)
111 _Panel *panel = (_Panel*)p;
112 WMScreen *scr = WMWidgetScreen(panel->win);
113 WMPixmap *icon1, *icon2;
114 RImage *xis = NULL;
115 RContext *rc = WMScreenRContext(scr);
116 char *path;
118 path = LocateImage(ARQUIVO_XIS);
119 if (path) {
120 xis = RLoadImage(rc, path, 0);
121 if (!xis) {
122 wwarning(_("could not load image file %s"), path);
124 free(path);
127 panel->frame = WMCreateFrame(panel->win);
128 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
129 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
131 /***************** Workspace Navigation *****************/
132 panel->navF = WMCreateFrame(panel->frame);
133 WMResizeWidget(panel->navF, 365, 200);
134 WMMoveWidget(panel->navF, 20, 15);
135 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
137 panel->linkB = WMCreateButton(panel->navF, WBTToggle);
138 WMResizeWidget(panel->linkB, 60, 60);
139 WMMoveWidget(panel->linkB, 20, 25);
140 WMSetButtonImagePosition(panel->linkB, WIPImageOnly);
141 path = LocateImage(DONT_LINK_FILE);
142 if (path) {
143 createImages(scr, rc, xis, path, &icon1, &icon2);
144 if (icon2) {
145 WMSetButtonImage(panel->linkB, icon2);
146 WMReleasePixmap(icon2);
148 if (icon1) {
149 WMSetButtonAltImage(panel->linkB, icon1);
150 WMReleasePixmap(icon1);
152 free(path);
154 panel->linkL = WMCreateLabel(panel->navF);
155 WMResizeWidget(panel->linkL, 260, 38);
156 WMMoveWidget(panel->linkL, 85, 25);
157 WMSetLabelTextAlignment(panel->linkL, WALeft);
158 WMSetLabelText(panel->linkL,
159 _("drag windows between workspaces."));
162 panel->cyclB = WMCreateButton(panel->navF, WBTToggle);
163 WMResizeWidget(panel->cyclB, 60, 60);
164 WMMoveWidget(panel->cyclB, 285, 75);
165 WMSetButtonImagePosition(panel->cyclB, WIPImageOnly);
166 path = LocateImage(CYCLE_FILE);
167 if (path) {
168 createImages(scr, rc, xis, path, &icon1, &icon2);
169 if (icon2) {
170 WMSetButtonImage(panel->cyclB, icon2);
171 WMReleasePixmap(icon2);
173 if (icon1) {
174 WMSetButtonAltImage(panel->cyclB, icon1);
175 WMReleasePixmap(icon1);
177 free(path);
179 panel->cyclL = WMCreateLabel(panel->navF);
180 WMResizeWidget(panel->cyclL, 260, 38);
181 WMMoveWidget(panel->cyclL, 20, 85);
182 WMSetLabelTextAlignment(panel->cyclL, WARight);
183 WMSetLabelText(panel->cyclL,
184 _("switch to first workspace when switching past the last workspace and vice-versa"));
186 panel->newB = WMCreateButton(panel->navF, WBTToggle);
187 WMResizeWidget(panel->newB, 60, 60);
188 WMMoveWidget(panel->newB, 20, 125);
189 WMSetButtonImagePosition(panel->newB, WIPImageOnly);
190 path = LocateImage(ADVANCE_FILE);
191 if (path) {
192 createImages(scr, rc, xis, path, &icon1, &icon2);
193 if (icon2) {
194 WMSetButtonImage(panel->newB, icon2);
195 WMReleasePixmap(icon2);
197 if (icon1) {
198 WMSetButtonAltImage(panel->newB, icon1);
199 WMReleasePixmap(icon1);
201 free(path);
203 panel->newL = WMCreateLabel(panel->navF);
204 WMResizeWidget(panel->newL, 260, 38);
205 WMMoveWidget(panel->newL, 85, 140);
206 WMSetLabelTextAlignment(panel->newL, WALeft);
207 WMSetLabelText(panel->newL,
208 _("create a new workspace when switching past the last workspace."));
210 WMMapSubwidgets(panel->navF);
212 /***************** Dock/Clip *****************/
213 panel->dockF = WMCreateFrame(panel->frame);
214 WMResizeWidget(panel->dockF, 105, 200);
215 WMMoveWidget(panel->dockF, 400, 15);
216 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
218 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
219 WMResizeWidget(panel->dockB, 64, 64);
220 WMMoveWidget(panel->dockB, 20, 30);
221 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
222 path = LocateImage(DOCK_FILE);
223 if (path) {
224 createImages(scr, rc, xis, path, &icon1, &icon2);
225 if (icon2) {
226 WMSetButtonImage(panel->dockB, icon2);
227 WMReleasePixmap(icon2);
229 if (icon1) {
230 WMSetButtonAltImage(panel->dockB, icon1);
231 WMReleasePixmap(icon1);
233 free(path);
236 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
237 WMResizeWidget(panel->clipB, 64, 64);
238 WMMoveWidget(panel->clipB, 20, 110);
239 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
240 path = LocateImage(CLIP_FILE);
241 if (path) {
242 createImages(scr, rc, xis, path, &icon1, &icon2);
243 if (icon2) {
244 WMSetButtonImage(panel->clipB, icon2);
245 WMReleasePixmap(icon2);
247 if (icon1) {
248 WMSetButtonAltImage(panel->clipB, icon1);
249 WMReleasePixmap(icon1);
252 WMMapSubwidgets(panel->dockF);
254 if (xis)
255 RDestroyImage(xis);
257 WMRealizeWidget(panel->frame);
258 WMMapSubwidgets(panel->frame);
260 showData(panel);
264 static void
265 storeData(_Panel *panel)
267 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
268 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
269 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
271 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
272 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
277 Panel*
278 InitWorkspace(WMScreen *scr, WMWindow *win)
280 _Panel *panel;
282 panel = wmalloc(sizeof(_Panel));
283 memset(panel, 0, sizeof(_Panel));
285 panel->sectionName = _("Workspace Preferences");
287 panel->win = win;
289 panel->callbacks.createWidgets = createPanel;
290 panel->callbacks.updateDomain = storeData;
292 AddSection(panel, ICON_FILE);
294 return panel;