~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WPrefs.app/Workspace.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Workspace.c- workspace options
 
2
 *
 
3
 *  WPrefs - Window Maker Preferences Program
 
4
 *
 
5
 *  Copyright (c) 1998-2003 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.
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 */
 
22
 
 
23
 
 
24
#include "WPrefs.h"
 
25
 
 
26
 
 
27
typedef struct _Panel {
 
28
    WMBox *box;
 
29
 
 
30
    char *sectionName;
 
31
 
 
32
    char *description;
 
33
 
 
34
    CallbackRec callbacks;
 
35
 
 
36
    WMWidget *parent;
 
37
 
 
38
    WMFrame *navF;
 
39
 
 
40
    WMButton *linkB;
 
41
    WMButton *cyclB;
 
42
    WMButton *newB;
 
43
    WMLabel *linkL;
 
44
    WMLabel *cyclL;
 
45
    WMLabel *newL;
 
46
 
 
47
    WMLabel *posiL;
 
48
    WMLabel *posL;
 
49
    WMPopUpButton *posP;
 
50
 
 
51
    WMFrame *dockF;
 
52
    WMButton *dockB;
 
53
    WMButton *clipB;
 
54
} _Panel;
 
55
 
 
56
 
 
57
 
 
58
#define ICON_FILE       "workspace"
 
59
 
 
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"
 
67
 
 
68
 
 
69
static char *WSNamePositions[] = {
 
70
    "none",
 
71
    "center",
 
72
    "top",
 
73
    "bottom",
 
74
    "topleft",
 
75
    "topright",
 
76
    "bottomleft",
 
77
    "bottomright"
 
78
};
 
79
 
 
80
 
 
81
static void
 
82
createImages(WMScreen *scr, RContext *rc, RImage *xis, char *file,
 
83
             WMPixmap **icon1,  WMPixmap **icon2)
 
84
{
 
85
    RImage *icon;
 
86
    RColor gray = {0xae,0xaa,0xae};
 
87
 
 
88
    *icon1 = WMCreatePixmapFromFile(scr, file);
 
89
    if (!*icon1) {
 
90
        wwarning(_("could not load icon %s"), file);
 
91
        if (icon2)
 
92
            *icon2 = NULL;
 
93
        return;
 
94
    }
 
95
 
 
96
    if (!icon2)
 
97
        return;
 
98
 
 
99
    icon = RLoadImage(rc, file, 0);
 
100
    if (!icon) {
 
101
        wwarning(_("could not load icon %s"), file);
 
102
        *icon2 = NULL;
 
103
        return;
 
104
    }
 
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;
 
111
        }
 
112
    }
 
113
    RReleaseImage(icon);
 
114
}
 
115
 
 
116
 
 
117
 
 
118
static void
 
119
showData(_Panel *panel)
 
120
{
 
121
    int i, idx;
 
122
    char *str;
 
123
 
 
124
    WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
 
125
 
 
126
    WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
 
127
 
 
128
    WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
 
129
 
 
130
    WMSetButtonSelected(panel->dockB, !GetBoolForKey("DisableDock"));
 
131
 
 
132
    WMSetButtonSelected(panel->clipB, !GetBoolForKey("DisableClip"));
 
133
 
 
134
    str = GetStringForKey("WorkspaceNameDisplayPosition");
 
135
    if (!str)
 
136
        str = "center";
 
137
 
 
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;
 
143
        }
 
144
    }
 
145
    WMSetPopUpButtonSelectedItem(panel->posP, idx);
 
146
}
 
147
 
 
148
 
 
149
 
 
150
static void
 
151
createPanel(Panel *p)
 
152
{
 
153
    _Panel *panel = (_Panel*)p;
 
154
    WMScreen *scr = WMWidgetScreen(panel->parent);
 
155
    WMPixmap *icon1, *icon2;
 
156
    RImage *xis = NULL;
 
157
    RContext *rc = WMScreenRContext(scr);
 
158
    char *path;
 
159
 
 
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);
 
165
        }
 
166
        wfree(path);
 
167
    }
 
168
 
 
169
    panel->box = WMCreateBox(panel->parent);
 
170
    WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
 
171
 
 
172
    /***************** Workspace Navigation *****************/
 
173
    panel->navF = WMCreateFrame(panel->box);
 
174
    WMResizeWidget(panel->navF, 365, 210);
 
175
    WMMoveWidget(panel->navF, 15, 10);
 
176
    WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
 
177
 
 
178
 
 
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 from the last workspace."));
 
184
 
 
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);
 
195
        }
 
196
        wfree(path);
 
197
    }
 
198
 
 
199
    /**/
 
200
 
 
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."));
 
206
 
 
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);
 
217
        }
 
218
        wfree(path);
 
219
    }
 
220
 
 
221
    /**/
 
222
 
 
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."));
 
228
 
 
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);
 
239
        }
 
240
        wfree(path);
 
241
    }
 
242
 
 
243
    /**/
 
244
 
 
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\nname display"));
 
251
 
 
252
    panel->posiL = WMCreateLabel(panel->navF);
 
253
    WMResizeWidget(panel->posiL, 60, 40);
 
254
    WMMoveWidget(panel->posiL, 10, 160);
 
255
    WMSetLabelImagePosition(panel->posiL, WIPImageOnly);
 
256
    path = LocateImage(WSNAME_FILE);
 
257
    if (path) {
 
258
        createImages(scr, rc, xis, path, &icon1, NULL);
 
259
        if (icon1) {
 
260
            WMSetLabelImage(panel->posiL, icon1);
 
261
            WMReleasePixmap(icon1);
 
262
        }
 
263
        wfree(path);
 
264
    }
 
265
 
 
266
    panel->posP = WMCreatePopUpButton(panel->navF);
 
267
    WMResizeWidget(panel->posP, 125, 20);
 
268
    WMMoveWidget(panel->posP, 225, 175);
 
269
    WMAddPopUpButtonItem(panel->posP, _("Disable"));
 
270
    WMAddPopUpButtonItem(panel->posP, _("Center"));
 
271
    WMAddPopUpButtonItem(panel->posP, _("Top"));
 
272
    WMAddPopUpButtonItem(panel->posP, _("Bottom"));
 
273
    WMAddPopUpButtonItem(panel->posP, _("Top/Left"));
 
274
    WMAddPopUpButtonItem(panel->posP, _("Top/Right"));
 
275
    WMAddPopUpButtonItem(panel->posP, _("Bottom/Left"));
 
276
    WMAddPopUpButtonItem(panel->posP, _("Bottom/Right"));
 
277
 
 
278
    WMMapSubwidgets(panel->navF);
 
279
 
 
280
    /***************** Dock/Clip *****************/
 
281
    panel->dockF = WMCreateFrame(panel->box);
 
282
    WMResizeWidget(panel->dockF, 115, 210);
 
283
    WMMoveWidget(panel->dockF, 390, 10);
 
284
    WMSetFrameTitle(panel->dockF, _("Dock/Clip"));
 
285
 
 
286
    panel->dockB = WMCreateButton(panel->dockF, WBTToggle);
 
287
    WMResizeWidget(panel->dockB, 64, 64);
 
288
    WMMoveWidget(panel->dockB, 25, 35);
 
289
    WMSetButtonImagePosition(panel->dockB, WIPImageOnly);
 
290
    path = LocateImage(DOCK_FILE);
 
291
    if (path) {
 
292
        createImages(scr, rc, xis, path, &icon1, &icon2);
 
293
        if (icon2) {
 
294
            WMSetButtonImage(panel->dockB, icon2);
 
295
            WMReleasePixmap(icon2);
 
296
        }
 
297
        if (icon1) {
 
298
            WMSetButtonAltImage(panel->dockB, icon1);
 
299
            WMReleasePixmap(icon1);
 
300
        }
 
301
        wfree(path);
 
302
    }
 
303
    WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
 
304
                              "vertical icon bar in the side of the screen)."),
 
305
                            WMWidgetView(panel->dockB));
 
306
 
 
307
    panel->clipB = WMCreateButton(panel->dockF, WBTToggle);
 
308
    WMResizeWidget(panel->clipB, 64, 64);
 
309
    WMMoveWidget(panel->clipB, 25, 120);
 
310
    WMSetButtonImagePosition(panel->clipB, WIPImageOnly);
 
311
    path = LocateImage(CLIP_FILE);
 
312
    if (path) {
 
313
        createImages(scr, rc, xis, path, &icon1, &icon2);
 
314
        if (icon2) {
 
315
            WMSetButtonImage(panel->clipB, icon2);
 
316
            WMReleasePixmap(icon2);
 
317
        }
 
318
        if (icon1) {
 
319
            WMSetButtonAltImage(panel->clipB, icon1);
 
320
            WMReleasePixmap(icon1);
 
321
        }
 
322
        wfree(path);
 
323
    }
 
324
    WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
 
325
                              "a paper clip icon)."),
 
326
                            WMWidgetView(panel->clipB));
 
327
 
 
328
    WMMapSubwidgets(panel->dockF);
 
329
 
 
330
    if (xis)
 
331
        RReleaseImage(xis);
 
332
 
 
333
    WMRealizeWidget(panel->box);
 
334
    WMMapSubwidgets(panel->box);
 
335
 
 
336
    showData(panel);
 
337
}
 
338
 
 
339
 
 
340
static void
 
341
storeData(_Panel *panel)
 
342
{
 
343
    SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
 
344
    SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
 
345
    SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
 
346
 
 
347
    SetBoolForKey(!WMGetButtonSelected(panel->dockB), "DisableDock");
 
348
    SetBoolForKey(!WMGetButtonSelected(panel->clipB), "DisableClip");
 
349
 
 
350
    SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
 
351
                    "WorkspaceNameDisplayPosition");
 
352
}
 
353
 
 
354
 
 
355
 
 
356
Panel*
 
357
InitWorkspace(WMScreen *scr, WMWidget *parent)
 
358
{
 
359
    _Panel *panel;
 
360
 
 
361
    panel = wmalloc(sizeof(_Panel));
 
362
    memset(panel, 0, sizeof(_Panel));
 
363
 
 
364
    panel->sectionName = _("Workspace Preferences");
 
365
 
 
366
    panel->description = _("Workspace navigation features.\n"
 
367
                           "You can also enable/disable the Dock and Clip here.");
 
368
 
 
369
    panel->parent = parent;
 
370
 
 
371
    panel->callbacks.createWidgets = createPanel;
 
372
    panel->callbacks.updateDomain = storeData;
 
373
 
 
374
    AddSection(panel, ICON_FILE);
 
375
 
 
376
    return panel;
 
377
}
 
378