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 along
18  *  with this program; if not, write to the Free Software Foundation, Inc.,
19  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #include "WPrefs.h"
23 
24 typedef struct _Panel {
25 	WMBox *box;
26 
27 	char *sectionName;
28 
29 	char *description;
30 
31 	CallbackRec callbacks;
32 
33 	WMWidget *parent;
34 
35 	WMFrame *navF;
36 
37 	WMButton *linkB;
38 	WMButton *cyclB;
39 	WMButton *newB;
40 	WMLabel *linkL;
41 	WMLabel *cyclL;
42 	WMLabel *newL;
43 
44 	WMLabel *posiL;
45 	WMLabel *posL;
46 	WMPopUpButton *posP;
47 } _Panel;
48 
49 #define ICON_FILE	"workspace"
50 
51 #define ARQUIVO_XIS	"xis"
52 #define DONT_LINK_FILE	"dontlinkworkspaces"
53 #define CYCLE_FILE	"cycleworkspaces"
54 #define ADVANCE_FILE	"advancetonewworkspace"
55 #define WSNAME_FILE 	"workspacename"
56 
57 static char *WSNamePositions[] = {
58 	"none",
59 	"center",
60 	"top",
61 	"bottom",
62 	"topleft",
63 	"topright",
64 	"bottomleft",
65 	"bottomright"
66 };
67 
showData(_Panel * panel)68 static void showData(_Panel * panel)
69 {
70 	int i, idx;
71 	char *str;
72 
73 	WMSetButtonSelected(panel->linkB, !GetBoolForKey("DontLinkWorkspaces"));
74 
75 	WMSetButtonSelected(panel->cyclB, GetBoolForKey("CycleWorkspaces"));
76 
77 	WMSetButtonSelected(panel->newB, GetBoolForKey("AdvanceToNewWorkspace"));
78 
79 	str = GetStringForKey("WorkspaceNameDisplayPosition");
80 	if (!str)
81 		str = "center";
82 
83 	idx = 1;		/* center */
84 	for (i = 0; i < wlengthof(WSNamePositions); i++) {
85 		if (strcasecmp(WSNamePositions[i], str) == 0) {
86 			idx = i;
87 			break;
88 		}
89 	}
90 	WMSetPopUpButtonSelectedItem(panel->posP, idx);
91 }
92 
createPanel(Panel * p)93 static void createPanel(Panel * p)
94 {
95 	_Panel *panel = (_Panel *) p;
96 	WMScreen *scr = WMWidgetScreen(panel->parent);
97 	WMPixmap *icon1;
98 	RImage *xis = NULL;
99 	RContext *rc = WMScreenRContext(scr);
100 	char *path;
101 
102 	path = LocateImage(ARQUIVO_XIS);
103 	if (path) {
104 		xis = RLoadImage(rc, path, 0);
105 		if (!xis) {
106 			wwarning(_("could not load image file %s"), path);
107 		}
108 		wfree(path);
109 	}
110 
111 	panel->box = WMCreateBox(panel->parent);
112 	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
113 
114     /***************** Workspace Navigation *****************/
115 	panel->navF = WMCreateFrame(panel->box);
116 	WMResizeWidget(panel->navF, 490, 210);
117 	WMMoveWidget(panel->navF, 15, 8);
118 	WMSetFrameTitle(panel->navF, _("Workspace Navigation"));
119 
120 	panel->cyclB = WMCreateSwitchButton(panel->navF);
121 	WMResizeWidget(panel->cyclB, 410, 34);
122 	WMMoveWidget(panel->cyclB, 75, 26);
123 	WMSetButtonText(panel->cyclB, _("Wrap to the first workspace from the last workspace"));
124 
125 	panel->cyclL = WMCreateLabel(panel->navF);
126 	WMResizeWidget(panel->cyclL, 60, 60);
127 	WMMoveWidget(panel->cyclL, 10, 12);
128 	WMSetLabelImagePosition(panel->cyclL, WIPImageOnly);
129 	CreateImages(scr, rc, xis, CYCLE_FILE, &icon1, NULL);
130 	if (icon1)
131 	{
132 		WMSetLabelImage(panel->cyclL, icon1);
133 		WMReleasePixmap(icon1);
134 	}
135 
136 	/**/ panel->linkB = WMCreateSwitchButton(panel->navF);
137 	WMResizeWidget(panel->linkB, 410, 34);
138 	WMMoveWidget(panel->linkB, 75, 73);
139 	WMSetButtonText(panel->linkB, _("Switch workspaces while dragging windows"));
140 
141 	panel->linkL = WMCreateLabel(panel->navF);
142 	WMResizeWidget(panel->linkL, 60, 40);
143 	WMMoveWidget(panel->linkL, 10, 77);
144 	WMSetLabelImagePosition(panel->linkL, WIPImageOnly);
145 	CreateImages(scr, rc, xis, DONT_LINK_FILE, &icon1, NULL);
146 	if (icon1)
147 	{
148 		WMSetLabelImage(panel->linkL, icon1);
149 		WMReleasePixmap(icon1);
150 	}
151 
152 	/**/ panel->newB = WMCreateSwitchButton(panel->navF);
153 	WMResizeWidget(panel->newB, 410, 34);
154 	WMMoveWidget(panel->newB, 75, 115);
155 	WMSetButtonText(panel->newB, _("Automatically create new workspaces"));
156 
157 	panel->newL = WMCreateLabel(panel->navF);
158 	WMResizeWidget(panel->newL, 60, 20);
159 	WMMoveWidget(panel->newL, 10, 123);
160 	WMSetLabelImagePosition(panel->newL, WIPImageOnly);
161 	CreateImages(scr, rc, xis, ADVANCE_FILE, &icon1, NULL);
162 	if (icon1)
163 	{
164 		WMSetLabelImage(panel->newL, icon1);
165 		WMReleasePixmap(icon1);
166 	}
167 
168 	/**/ panel->posL = WMCreateLabel(panel->navF);
169 	WMResizeWidget(panel->posL, 275, 30);
170 	WMMoveWidget(panel->posL, 75, 161);
171 	// WMSetLabelTextAlignment(panel->posL, WARight);
172 	WMSetLabelText(panel->posL, _("Position of workspace name display"));
173 
174 	panel->posiL = WMCreateLabel(panel->navF);
175 	WMResizeWidget(panel->posiL, 60, 40);
176 	WMMoveWidget(panel->posiL, 10, 156);
177 	WMSetLabelImagePosition(panel->posiL, WIPImageOnly);
178 	CreateImages(scr, rc, xis, WSNAME_FILE, &icon1, NULL);
179 	if (icon1)
180 	{
181 		WMSetLabelImage(panel->posiL, icon1);
182 		WMReleasePixmap(icon1);
183 	}
184 
185 	panel->posP = WMCreatePopUpButton(panel->navF);
186 	WMResizeWidget(panel->posP, 125, 20);
187 	WMMoveWidget(panel->posP, 350, 166);
188 	WMAddPopUpButtonItem(panel->posP, _("Disable"));
189 	WMAddPopUpButtonItem(panel->posP, _("Center"));
190 	WMAddPopUpButtonItem(panel->posP, _("Top"));
191 	WMAddPopUpButtonItem(panel->posP, _("Bottom"));
192 	WMAddPopUpButtonItem(panel->posP, _("Top/Left"));
193 	WMAddPopUpButtonItem(panel->posP, _("Top/Right"));
194 	WMAddPopUpButtonItem(panel->posP, _("Bottom/Left"));
195 	WMAddPopUpButtonItem(panel->posP, _("Bottom/Right"));
196 
197 	WMMapSubwidgets(panel->navF);
198 
199 	if (xis)
200 		RReleaseImage(xis);
201 
202 	WMRealizeWidget(panel->box);
203 	WMMapSubwidgets(panel->box);
204 
205 	showData(panel);
206 }
207 
storeData(_Panel * panel)208 static void storeData(_Panel * panel)
209 {
210 	SetBoolForKey(!WMGetButtonSelected(panel->linkB), "DontLinkWorkspaces");
211 	SetBoolForKey(WMGetButtonSelected(panel->cyclB), "CycleWorkspaces");
212 	SetBoolForKey(WMGetButtonSelected(panel->newB), "AdvanceToNewWorkspace");
213 
214 	SetStringForKey(WSNamePositions[WMGetPopUpButtonSelectedItem(panel->posP)],
215 			"WorkspaceNameDisplayPosition");
216 }
217 
InitWorkspace(WMWidget * parent)218 Panel *InitWorkspace(WMWidget *parent)
219 {
220 	_Panel *panel;
221 
222 	panel = wmalloc(sizeof(_Panel));
223 
224 	panel->sectionName = _("Workspace Preferences");
225 
226 	panel->description = _("Workspace navigation features\n"
227 			       "and workspace name display settings.");
228 
229 	panel->parent = parent;
230 
231 	panel->callbacks.createWidgets = createPanel;
232 	panel->callbacks.updateDomain = storeData;
233 
234 	AddSection(panel, ICON_FILE);
235 
236 	return panel;
237 }
238