added nana stuff
[wmaker-crm.git] / WPrefs.app / Workspace.c
blobefd519717dd345b3cb0dd24a2da878153be10d47
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 DOCK_FILE "dock"
65 #define CLIP_FILE "clip"
68 static char *WSNamePositions[] = {
69 "none",
70 "center",
71 "top",
72 "bottom",
73 "topleft",
74 "topright",
75 "bottomleft",
76 "bottomright"
80 static void
81 createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
82 WMPixmap **icon1, WMPixmap **icon2)
84 RImage *icon;
85 RColor gray = {0xae,0xaa,0xae};
87 *icon1 = WMCreatePixmapFromFile(scr, file);
88 if (!*icon1) {
89 wwarning(_("could not load icon %s"), file);
90 if (icon2)
91 *icon2 = NULL;
92 return;
95 if (!icon2)
96 return;
98 icon = RLoadImage(rc, file, 0);
99 if (!icon) {
100 wwarning(_("could not load icon %s"), file);
101 *icon2 = NULL;
102 return;
104 RCombineImageWithColor(icon, &gray);
105 if (xis) {
106 RCombineImagesWithOpaqueness(icon, xis, 180);
107 if (!(*icon2 = WMCreatePixmapFromRImage(scr, icon, 127))) {
108 wwarning(_("could not process icon %s:"), file, RMessageForError(RErrorCode));
109 *icon2 = NULL;
112 RDestroyImage(icon);
117 static void
118 showData(_Panel *panel)
120 int i, idx;
121 char *str;
123 WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
125 WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
127 WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
129 WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
131 WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
133 str = GetStringForKey("WorkspaceNameDisplayPosition");
134 if (!str)
135 str = "center";
137 idx = 1; /* center */
138 for (i = 0; i < sizeof(WSNamePositions); i++) {
139 if (strcmp(WSNamePositions[i], str) == 0) {
140 idx = i;
141 break;
144 WMSetPopUpButtonSelectedItem(panel->posP, idx);
149 static void
150 createPanel(Panel *p)
152 _Panel *panel = (_Panel*)p;
153 WMScreen *scr = WMWidgetScreen(panel->win);
154 WMPixmap *icon1, *icon2;
155 RImage *xis = NULL;
156 RContext *rc = WMScreenRContext(scr);
157 char *path;
159 path = LocateImage(ARQUIVO_XIS);
160 if (path) {
161 xis = RLoadImage(rc, path, 0);
162 if (!xis) {
163 wwarning(_("could not load image file %s"), path);
165 free(path);
168 panel->frame = WMCreateFrame(panel->win);
169 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
170 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
172 /***************** Workspace Navigation *****************/
173 panel->navF = WMCreateFrame(panel->frame);
174 WMResizeWidget(panel->navF, 365, 210);
175 WMMoveWidget(panel->navF, 15, 10);
176 WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
179 panel->cyclB = WMCreateSwitchButton(panel->navF);
180 WMResizeWidget(panel->cyclB, 280, 34);
181 WMMoveWidget(panel->cyclB, 75, 30);
182 WMSetButtonText(panel->cyclB,
183 _("wrap to the first workspace after the last workspace."));
185 panel->cyclL = WMCreateLabel(panel->navF);
186 WMResizeWidget(panel->cyclL, 60, 60);
187 WMMoveWidget(panel->cyclL, 10, 15);
188 WMSetLabelImagePosition(panel->cyclL, WIPImageOnly);
189 path = LocateImage(CYCLE_FILE);
190 if (path) {
191 createImages(scr, rc, xis, path, &icon1, NULL);
192 if (icon1) {
193 WMSetLabelImage(panel->cyclL, icon1);
194 WMReleasePixmap(icon1);
196 free(path);
199 /**/
201 panel->linkB = WMCreateSwitchButton(panel->navF);
202 WMResizeWidget(panel->linkB, 280, 34);
203 WMMoveWidget(panel->linkB, 75, 75);
204 WMSetButtonText(panel->linkB,
205 _("switch workspaces while dragging windows."));
207 panel->linkL = WMCreateLabel(panel->navF);
208 WMResizeWidget(panel->linkL, 60, 40);
209 WMMoveWidget(panel->linkL, 10, 80);
210 WMSetLabelImagePosition(panel->linkL, WIPImageOnly);
211 path = LocateImage(DONT_LINK_FILE);
212 if (path) {
213 createImages(scr, rc, xis, path, &icon1, NULL);
214 if (icon1) {
215 WMSetLabelImage(panel->linkL, icon1);
216 WMReleasePixmap(icon1);
218 free(path);
221 /**/
223 panel->newB = WMCreateSwitchButton(panel->navF);
224 WMResizeWidget(panel->newB, 280, 34);
225 WMMoveWidget(panel->newB, 75, 120);
226 WMSetButtonText(panel->newB,
227 _("automatically create new workspaces."));
229 panel->newL = WMCreateLabel(panel->navF);
230 WMResizeWidget(panel->newL, 60, 20);
231 WMMoveWidget(panel->newL, 10, 130);
232 WMSetLabelImagePosition(panel->newL, WIPImageOnly);
233 path = LocateImage(ADVANCE_FILE);
234 if (path) {
235 createImages(scr, rc, xis, path, &icon1, NULL);
236 if (icon1) {
237 WMSetLabelImage(panel->newL, icon1);
238 WMReleasePixmap(icon1);
240 free(path);
243 /**/
245 panel->posL = WMCreateLabel(panel->navF);
246 WMResizeWidget(panel->posL, 140, 30);
247 WMMoveWidget(panel->posL, 75, 165);
248 WMSetLabelTextAlignment(panel->posL, WARight);
249 WMSetLabelText(panel->posL,
250 _("Position of workspace name display"));
252 #if 0
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(ADVANCE_FILE);
258 if (path) {
259 createImages(scr, rc, xis, path, &icon1, NULL);
260 if (icon1) {
261 WMSetLabelImage(panel->posiL, icon1);
262 WMReleasePixmap(icon1);
264 free(path);
266 #endif
268 panel->posP = WMCreatePopUpButton(panel->navF);
269 WMResizeWidget(panel->posP, 125, 20);
270 WMMoveWidget(panel->posP, 225, 175);
271 WMAddPopUpButtonItem(panel->posP, _("Disable"));
272 WMAddPopUpButtonItem(panel->posP, _("Center"));
273 WMAddPopUpButtonItem(panel->posP, _("Top"));
274 WMAddPopUpButtonItem(panel->posP, _("Bottom"));
275 WMAddPopUpButtonItem(panel->posP, _("Top/left"));
276 WMAddPopUpButtonItem(panel->posP, _("Top/right"));
277 WMAddPopUpButtonItem(panel->posP, _("Bottom/left"));
278 WMAddPopUpButtonItem(panel->posP, _("Bottom/right"));
280 WMMapSubwidgets(panel->navF);
282 /***************** Dock/Clip *****************/
283 panel->dockF = WMCreateFrame(panel->frame);
284 WMResizeWidget(panel->dockF, 115, 210);
285 WMMoveWidget(panel->dockF, 390, 10);
286 WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
288 panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
289 WMResizeWidget(panel->dockB, 64, 64);
290 WMMoveWidget(panel->dockB, 25, 35);
291 WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
292 path = LocateImage(DOCK_FILE);
293 if (path) {
294 createImages(scr, rc, xis, path, &icon1, &icon2);
295 if (icon2) {
296 WMSetButtonImage(panel->dockB, icon2);
297 WMReleasePixmap(icon2);
299 if (icon1) {
300 WMSetButtonAltImage(panel->dockB, icon1);
301 WMReleasePixmap(icon1);
303 free(path);
305 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
306 "vertical icon bar in the side of the screen)."),
307 WMWidgetView(panel->dockB));
309 panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
310 WMResizeWidget(panel->clipB, 64, 64);
311 WMMoveWidget(panel->clipB, 25, 120);
312 WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
313 path = LocateImage(CLIP_FILE);
314 if (path) {
315 createImages(scr, rc, xis, path, &icon1, &icon2);
316 if (icon2) {
317 WMSetButtonImage(panel->clipB, icon2);
318 WMReleasePixmap(icon2);
320 if (icon1) {
321 WMSetButtonAltImage(panel->clipB, icon1);
322 WMReleasePixmap(icon1);
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;