added balloon help
[wmaker-crm.git] / WPrefs.app / Workspace.c
blobdcea228c8ccea2d690d18586f1b3b103610fba75
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 char *description;
34 CallbackRec callbacks;
36 WMWindow *win;
38 WMFrame *navF;
39 WMButton *linkB;
40 WMButton *cyclB;
41 WMButton *newB;
42 WMLabel *linkL;
43 WMLabel *cyclL;
44 WMLabel *newL;
46 WMFrame *dockF;
47 WMButton *dockB;
48 WMButton *clipB;
49 } _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 DOCK_FILE "dock"
60 #define CLIP_FILE "clip"
64 static void
65 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
66 WMPixmap **icon1, WMPixmap **icon2)
68 RImage *icon;
69 RColor gray = {0xae,0xaa,0xae};
71 *icon1 = WMCreatePixmapFromFile(scr, file);
72 if (!*icon1) {
73 wwarning(_("could not load icon %s"), file);
74 *icon2 = NULL;
75 return;
77 icon = RLoadImage(rc, file, 0);
78 if (!icon) {
79 wwarning(_("could not load icon %s"), file);
80 *icon2 = NULL;
81 return;
83 RCombineImageWithColor(icon, &gray);
84 if (xis) {
85 RCombineImagesWithOpaqueness(icon, xis, 180);
86 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
87 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
88 *icon2 = NULL;
91 RDestroyImage(icon);
96 static void
97 showData(_Panel *panel)
99 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
101 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
103 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
105 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
107 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
112 static void
113 createPanel(Panel *p)
115 _Panel *panel = (_Panel*)p;
116 WMScreen *scr = WMWidgetScreen(panel->win);
117 WMPixmap *icon1, *icon2;
118 RImage *xis = NULL;
119 RContext *rc = WMScreenRContext(scr);
120 char *path;
122 path = LocateImage(ARQUIVO_XIS);
123 if (path) {
124 xis = RLoadImage(rc, path, 0);
125 if (!xis) {
126 wwarning(_("could not load image file %s"), path);
128 free(path);
131 panel->frame = WMCreateFrame(panel->win);
132 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
133 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
135 /***************** Workspace Navigation *****************/
136 panel->navF = WMCreateFrame(panel->frame);
137 WMResizeWidget(panel->navF, 365, 200);
138 WMMoveWidget(panel->navF, 20, 15);
139 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
141 panel->linkB = WMCreateButton(panel->navF, WBTToggle);
142 WMResizeWidget(panel->linkB, 60, 60);
143 WMMoveWidget(panel->linkB, 20, 25);
144 WMSetButtonImagePosition(panel->linkB, WIPImageOnly);
145 path = LocateImage(DONT_LINK_FILE);
146 if (path) {
147 createImages(scr, rc, xis, path, &icon1, &icon2);
148 if (icon2) {
149 WMSetButtonImage(panel->linkB, icon2);
150 WMReleasePixmap(icon2);
152 if (icon1) {
153 WMSetButtonAltImage(panel->linkB, icon1);
154 WMReleasePixmap(icon1);
156 free(path);
158 panel->linkL = WMCreateLabel(panel->navF);
159 WMResizeWidget(panel->linkL, 260, 38);
160 WMMoveWidget(panel->linkL, 85, 25);
161 WMSetLabelTextAlignment(panel->linkL, WALeft);
162 WMSetLabelText(panel->linkL,
163 _("drag windows between workspaces."));
166 panel->cyclB = WMCreateButton(panel->navF, WBTToggle);
167 WMResizeWidget(panel->cyclB, 60, 60);
168 WMMoveWidget(panel->cyclB, 285, 75);
169 WMSetButtonImagePosition(panel->cyclB, WIPImageOnly);
170 path = LocateImage(CYCLE_FILE);
171 if (path) {
172 createImages(scr, rc, xis, path, &icon1, &icon2);
173 if (icon2) {
174 WMSetButtonImage(panel->cyclB, icon2);
175 WMReleasePixmap(icon2);
177 if (icon1) {
178 WMSetButtonAltImage(panel->cyclB, icon1);
179 WMReleasePixmap(icon1);
181 free(path);
183 panel->cyclL = WMCreateLabel(panel->navF);
184 WMResizeWidget(panel->cyclL, 260, 38);
185 WMMoveWidget(panel->cyclL, 20, 85);
186 WMSetLabelTextAlignment(panel->cyclL, WARight);
187 WMSetLabelText(panel->cyclL,
188 _("switch to first workspace when switching past the last workspace and vice-versa"));
190 panel->newB = WMCreateButton(panel->navF, WBTToggle);
191 WMResizeWidget(panel->newB, 60, 60);
192 WMMoveWidget(panel->newB, 20, 125);
193 WMSetButtonImagePosition(panel->newB, WIPImageOnly);
194 path = LocateImage(ADVANCE_FILE);
195 if (path) {
196 createImages(scr, rc, xis, path, &icon1, &icon2);
197 if (icon2) {
198 WMSetButtonImage(panel->newB, icon2);
199 WMReleasePixmap(icon2);
201 if (icon1) {
202 WMSetButtonAltImage(panel->newB, icon1);
203 WMReleasePixmap(icon1);
205 free(path);
207 panel->newL = WMCreateLabel(panel->navF);
208 WMResizeWidget(panel->newL, 260, 38);
209 WMMoveWidget(panel->newL, 85, 140);
210 WMSetLabelTextAlignment(panel->newL, WALeft);
211 WMSetLabelText(panel->newL,
212 _("create a new workspace when switching past the last workspace."));
214 WMMapSubwidgets(panel->navF);
216 /***************** Dock/Clip *****************/
217 panel->dockF = WMCreateFrame(panel->frame);
218 WMResizeWidget(panel->dockF, 105, 200);
219 WMMoveWidget(panel->dockF, 400, 15);
220 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
222 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
223 WMResizeWidget(panel->dockB, 64, 64);
224 WMMoveWidget(panel->dockB, 20, 30);
225 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
226 path = LocateImage(DOCK_FILE);
227 if (path) {
228 createImages(scr, rc, xis, path, &icon1, &icon2);
229 if (icon2) {
230 WMSetButtonImage(panel->dockB, icon2);
231 WMReleasePixmap(icon2);
233 if (icon1) {
234 WMSetButtonAltImage(panel->dockB, icon1);
235 WMReleasePixmap(icon1);
237 free(path);
239 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
240 "vertical icon bar in the side of the screen)."),
241 WMWidgetView(panel->dockB));
243 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
244 WMResizeWidget(panel->clipB, 64, 64);
245 WMMoveWidget(panel->clipB, 20, 110);
246 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
247 path = LocateImage(CLIP_FILE);
248 if (path) {
249 createImages(scr, rc, xis, path, &icon1, &icon2);
250 if (icon2) {
251 WMSetButtonImage(panel->clipB, icon2);
252 WMReleasePixmap(icon2);
254 if (icon1) {
255 WMSetButtonAltImage(panel->clipB, icon1);
256 WMReleasePixmap(icon1);
259 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
260 "a paper clip icon)."),
261 WMWidgetView(panel->clipB));
263 WMMapSubwidgets(panel->dockF);
265 if (xis)
266 RDestroyImage(xis);
268 WMRealizeWidget(panel->frame);
269 WMMapSubwidgets(panel->frame);
271 showData(panel);
275 static void
276 storeData(_Panel *panel)
278 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
279 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
280 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
282 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
283 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
288 Panel*
289 InitWorkspace(WMScreen *scr, WMWindow *win)
291 _Panel *panel;
293 panel = wmalloc(sizeof(_Panel));
294 memset(panel, 0, sizeof(_Panel));
296 panel->sectionName = _("Workspace Preferences");
298 panel->description = _("Workspace navigation features.\n"
299 "You can also enable/disable the Dock and Clip here.");
301 panel->win = win;
303 panel->callbacks.createWidgets = createPanel;
304 panel->callbacks.updateDomain = storeData;
306 AddSection(panel, ICON_FILE);
308 return panel;