Renamed se.po to sv.po
[wmaker-crm.git] / WPrefs.app / Workspace.c
blob7fc6e9356fe9040deb2c38522d3509bdf2772f10
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;
40 WMButton *linkB;
41 WMButton *cyclB;
42 WMButton *newB;
43 WMLabel *linkL;
44 WMLabel *cyclL;
45 WMLabel *newL;
47 WMLabel *posiL;
48 WMLabel *posL;
49 WMPopUpButton *posP;
51 WMFrame *dockF;
52 WMButton *dockB;
53 WMButton *clipB;
54 } _Panel;
58 #define ICON_FILE "workspace"
60 #define ARQUIVO_XIS "xis"
61 #define DONT_LINK_FILE "dontlinkworkspaces"
62 #define CYCLE_FILE "cycleworkspaces"
63 #define ADVANCE_FILE "advancetonewworkspace"
64 #define WSNAME_FILE "workspacename"
65 #define DOCK_FILE "dock"
66 #define CLIP_FILE "clip"
69 static char *WSNamePositions[] = {
70 "none",
71 "center",
72 "top",
73 "bottom",
74 "topleft",
75 "topright",
76 "bottomleft",
77 "bottomright"
81 static void
82 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
83 WMPixmap **icon1, WMPixmap **icon2)
85 RImage *icon;
86 RColor gray = {0xae,0xaa,0xae};
88 *icon1 = WMCreatePixmapFromFile(scr, file);
89 if (!*icon1) {
90 wwarning(_("could not load icon %s"), file);
91 if (icon2)
92 *icon2 = NULL;
93 return;
96 if (!icon2)
97 return;
99 icon = RLoadImage(rc, file, 0);
100 if (!icon) {
101 wwarning(_("could not load icon %s"), file);
102 *icon2 = NULL;
103 return;
105 RCombineImageWithColor(icon, &gray);
106 if (xis) {
107 RCombineImagesWithOpaqueness(icon, xis, 180);
108 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
109 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
110 *icon2 = NULL;
113 RDestroyImage(icon);
118 static void
119 showData(_Panel *panel)
121 int i, idx;
122 char *str;
124 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
126 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
128 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
130 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
132 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
134 str = GetStringForKey("WorkspaceNameDisplayPosition");
135 if (!str)
136 str = "center";
138 idx = 1; /* center */
139 for (i = 0; i < sizeof(WSNamePositions)/sizeof(char*); i++) {
140 if (strcasecmp(WSNamePositions[i], str) == 0) {
141 idx = i;
142 break;
145 WMSetPopUpButtonSelectedItem(panel->posP, idx);
150 static void
151 createPanel(Panel *p)
153 _Panel *panel = (_Panel*)p;
154 WMScreen *scr = WMWidgetScreen(panel->win);
155 WMPixmap *icon1, *icon2;
156 RImage *xis = NULL;
157 RContext *rc = WMScreenRContext(scr);
158 char *path;
160 path = LocateImage(ARQUIVO_XIS);
161 if (path) {
162 xis = RLoadImage(rc, path, 0);
163 if (!xis) {
164 wwarning(_("could not load image file %s"), path);
166 wfree(path);
169 panel->frame = WMCreateFrame(panel->win);
170 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
171 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
173 /***************** Workspace Navigation *****************/
174 panel->navF = WMCreateFrame(panel->frame);
175 WMResizeWidget(panel->navF, 365, 210);
176 WMMoveWidget(panel->navF, 15, 10);
177 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
180 panel->cyclB = WMCreateSwitchButton(panel->navF);
181 WMResizeWidget(panel->cyclB, 280, 34);
182 WMMoveWidget(panel->cyclB, 75, 30);
183 WMSetButtonText(panel->cyclB,
184 _("wrap to the first workspace after the\nlast workspace."));
186 panel->cyclL = WMCreateLabel(panel->navF);
187 WMResizeWidget(panel->cyclL, 60, 60);
188 WMMoveWidget(panel->cyclL, 10, 15);
189 WMSetLabelImagePosition(panel->cyclL, WIPImageOnly);
190 path = LocateImage(CYCLE_FILE);
191 if (path) {
192 createImages(scr, rc, xis, path, &icon1, NULL);
193 if (icon1) {
194 WMSetLabelImage(panel->cyclL, icon1);
195 WMReleasePixmap(icon1);
197 wfree(path);
200 /**/
202 panel->linkB = WMCreateSwitchButton(panel->navF);
203 WMResizeWidget(panel->linkB, 280, 34);
204 WMMoveWidget(panel->linkB, 75, 75);
205 WMSetButtonText(panel->linkB,
206 _("switch workspaces while dragging windows."));
208 panel->linkL = WMCreateLabel(panel->navF);
209 WMResizeWidget(panel->linkL, 60, 40);
210 WMMoveWidget(panel->linkL, 10, 80);
211 WMSetLabelImagePosition(panel->linkL, WIPImageOnly);
212 path = LocateImage(DONT_LINK_FILE);
213 if (path) {
214 createImages(scr, rc, xis, path, &icon1, NULL);
215 if (icon1) {
216 WMSetLabelImage(panel->linkL, icon1);
217 WMReleasePixmap(icon1);
219 wfree(path);
222 /**/
224 panel->newB = WMCreateSwitchButton(panel->navF);
225 WMResizeWidget(panel->newB, 280, 34);
226 WMMoveWidget(panel->newB, 75, 120);
227 WMSetButtonText(panel->newB,
228 _("automatically create new workspaces."));
230 panel->newL = WMCreateLabel(panel->navF);
231 WMResizeWidget(panel->newL, 60, 20);
232 WMMoveWidget(panel->newL, 10, 130);
233 WMSetLabelImagePosition(panel->newL, WIPImageOnly);
234 path = LocateImage(ADVANCE_FILE);
235 if (path) {
236 createImages(scr, rc, xis, path, &icon1, NULL);
237 if (icon1) {
238 WMSetLabelImage(panel->newL, icon1);
239 WMReleasePixmap(icon1);
241 wfree(path);
244 /**/
246 panel->posL = WMCreateLabel(panel->navF);
247 WMResizeWidget(panel->posL, 140, 30);
248 WMMoveWidget(panel->posL, 75, 165);
249 WMSetLabelTextAlignment(panel->posL, WARight);
250 WMSetLabelText(panel->posL,
251 _("Position of workspace\nname display"));
253 panel->posiL = WMCreateLabel(panel->navF);
254 WMResizeWidget(panel->posiL, 60, 40);
255 WMMoveWidget(panel->posiL, 10, 160);
256 WMSetLabelImagePosition(panel->posiL, WIPImageOnly);
257 path = LocateImage(WSNAME_FILE);
258 if (path) {
259 createImages(scr, rc, xis, path, &icon1, NULL);
260 if (icon1) {
261 WMSetLabelImage(panel->posiL, icon1);
262 WMReleasePixmap(icon1);
264 wfree(path);
267 panel->posP = WMCreatePopUpButton(panel->navF);
268 WMResizeWidget(panel->posP, 125, 20);
269 WMMoveWidget(panel->posP, 225, 175);
270 WMAddPopUpButtonItem(panel->posP, _("Disable"));
271 WMAddPopUpButtonItem(panel->posP, _("Center"));
272 WMAddPopUpButtonItem(panel->posP, _("Top"));
273 WMAddPopUpButtonItem(panel->posP, _("Bottom"));
274 WMAddPopUpButtonItem(panel->posP, _("Top/left"));
275 WMAddPopUpButtonItem(panel->posP, _("Top/right"));
276 WMAddPopUpButtonItem(panel->posP, _("Bottom/left"));
277 WMAddPopUpButtonItem(panel->posP, _("Bottom/right"));
279 WMMapSubwidgets(panel->navF);
281 /***************** Dock/Clip *****************/
282 panel->dockF = WMCreateFrame(panel->frame);
283 WMResizeWidget(panel->dockF, 115, 210);
284 WMMoveWidget(panel->dockF, 390, 10);
285 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
287 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
288 WMResizeWidget(panel->dockB, 64, 64);
289 WMMoveWidget(panel->dockB, 25, 35);
290 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
291 path = LocateImage(DOCK_FILE);
292 if (path) {
293 createImages(scr, rc, xis, path, &icon1, &icon2);
294 if (icon2) {
295 WMSetButtonImage(panel->dockB, icon2);
296 WMReleasePixmap(icon2);
298 if (icon1) {
299 WMSetButtonAltImage(panel->dockB, icon1);
300 WMReleasePixmap(icon1);
302 wfree(path);
304 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
305 "vertical icon bar in the side of the screen)."),
306 WMWidgetView(panel->dockB));
308 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
309 WMResizeWidget(panel->clipB, 64, 64);
310 WMMoveWidget(panel->clipB, 25, 120);
311 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
312 path = LocateImage(CLIP_FILE);
313 if (path) {
314 createImages(scr, rc, xis, path, &icon1, &icon2);
315 if (icon2) {
316 WMSetButtonImage(panel->clipB, icon2);
317 WMReleasePixmap(icon2);
319 if (icon1) {
320 WMSetButtonAltImage(panel->clipB, icon1);
321 WMReleasePixmap(icon1);
323 wfree(path);
325 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
326 "a paper clip icon)."),
327 WMWidgetView(panel->clipB));
329 WMMapSubwidgets(panel->dockF);
331 if (xis)
332 RDestroyImage(xis);
334 WMRealizeWidget(panel->frame);
335 WMMapSubwidgets(panel->frame);
337 showData(panel);
341 static void
342 storeData(_Panel *panel)
344 SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
345 SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
346 SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
348 SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
349 SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
351 SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
352 "WorkspaceNameDisplayPosition");
357 Panel*
358 InitWorkspace(WMScreen *scr, WMWindow *win)
360 _Panel *panel;
362 panel = wmalloc(sizeof(_Panel));
363 memset(panel, 0, sizeof(_Panel));
365 panel->sectionName = _("Workspace Preferences");
367 panel->description = _("Workspace navigation features.\n"
368 "You can also enable/disable the Dock and Clip here.");
370 panel->win = win;
372 panel->callbacks.createWidgets = createPanel;
373 panel->callbacks.updateDomain = storeData;
375 AddSection(panel, ICON_FILE);
377 return panel;