wmaker: Cleaned dangerous function prototype usage
[wmaker-crm.git] / WPrefs.app / Docks.c
blobbff87397702560ddaea2bf4efdbda21072616f96
1 /* Workspace.c- workspace options
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2012 Daniel Déchelotte (heavily inspired from file (c) Alfredo K. Kojima)
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 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.
22 #include "WPrefs.h"
24 typedef struct _Panel {
25 WMBox *box;
27 char *sectionName;
29 char *description;
31 CallbackRec callbacks;
33 WMWidget *parent;
35 WMFrame *autoDelayF[2];
36 WMLabel *autoDelayL[4];
37 WMButton *autoDelayB[4][5];
38 WMTextField *autoDelayT[4];
40 WMFrame *dockF;
41 WMButton *docksB[3];
42 } _Panel;
44 #define ICON_FILE "dockclipdrawersection"
46 #define ARQUIVO_XIS "xis"
47 #define DELAY_ICON "timer%i"
48 #define DELAY_ICON_S "timer%is"
50 static char *autoDelayStrings[4];
51 static char *autoDelayKeys[4] = { "ClipAutoexpandDelay", "ClipAutocollapseDelay", "ClipAutoraiseDelay", "ClipAutolowerDelay" };
52 static char *autoDelayPresetValues[5] = { "0", "100", "250", "600", "1000" };
53 static char *dockDisablingKeys[3] = { "DisableDock", "DisableClip", "DisableDrawers" };
54 static char *dockFiles[3] = { "dock", "clip", "drawer" };
56 static void showData(_Panel *panel);
57 static void storeData(_Panel *panel);
60 static void pushAutoDelayButton(WMWidget *w, void *data)
62 _Panel *panel = (_Panel *) data;
63 int i, j;
64 for (i = 0; i < 4; i++)
66 for (j = 0; j < 5; j++)
68 if (w == panel->autoDelayB[i][j])
70 WMSetTextFieldText(panel->autoDelayT[i], autoDelayPresetValues[j]);
71 return;
77 static void adjustButtonSelectionBasedOnValue(_Panel *panel, int row, const char *value)
79 int j;
81 if (!value)
82 return;
84 for (j = 0; j < 5; j++)
86 int isThatOne = !strcmp(autoDelayPresetValues[j], value);
87 WMSetButtonSelected(panel->autoDelayB[row][j], isThatOne);
88 if (isThatOne)
89 return;
93 static void autoDelayChanged(void *observerData, WMNotification *notification)
95 _Panel *panel = (_Panel *) observerData;
96 int row;
97 WMTextField *anAutoDelayT = (WMTextField *) WMGetNotificationObject(notification);
98 for (row = 0; row < 4; row++)
100 if (anAutoDelayT != panel->autoDelayT[row])
102 continue;
104 char *value = WMGetTextFieldText(anAutoDelayT);
105 adjustButtonSelectionBasedOnValue(panel, row, value);
106 return;
110 static void pushDockButton(WMWidget *w, void *data)
112 _Panel *panel = (_Panel *) data;
113 WMButton *button = (WMButton *) w;
114 if (button == panel->docksB[0] &&
115 !WMGetButtonSelected(panel->docksB[0]))
117 WMSetButtonSelected(panel->docksB[2], False);
119 if (button == panel->docksB[2] &&
120 WMGetButtonSelected(panel->docksB[2]))
122 WMSetButtonSelected(panel->docksB[0], True);
126 static void createPanel(Panel *p)
128 _Panel *panel = (_Panel *) p;
129 WMScreen *scr = WMWidgetScreen(panel->parent);
130 WMPixmap *icon1, *icon2;
131 RImage *xis = NULL;
132 RContext *rc = WMScreenRContext(scr);
133 char *path;
134 int i, j, k;
135 char *buf1, *buf2;
137 path = LocateImage(ARQUIVO_XIS);
138 if (path) {
139 xis = RLoadImage(rc, path, 0);
140 if (!xis) {
141 wwarning(_("could not load image file %s"), path);
143 wfree(path);
146 panel->box = WMCreateBox(panel->parent);
147 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
149 /***************** Auto-delays *****************/
150 buf1 = wmalloc(strlen(DELAY_ICON) + 1);
151 buf2 = wmalloc(strlen(DELAY_ICON_S) + 1);
153 for (k = 0; k < 2; k++)
155 panel->autoDelayF[k] = WMCreateFrame(panel->box);
156 WMResizeWidget(panel->autoDelayF[k], 365, 100);
157 WMMoveWidget(panel->autoDelayF[k], 15, 10 + k * 110);
158 if (k == 0)
159 WMSetFrameTitle(panel->autoDelayF[k], _("Delays in milliseconds for autocollapsing clips"));
160 else
161 WMSetFrameTitle(panel->autoDelayF[k], _("Delays in milliseconds for autoraising clips"));
163 for (i = 0; i < 2; i++)
165 panel->autoDelayL[i + k * 2] = WMCreateLabel(panel->autoDelayF[k]);
166 WMResizeWidget(panel->autoDelayL[i + k * 2], 165, 20);
167 WMMoveWidget(panel->autoDelayL[i + k * 2], 10, 27 + 40 * i);
168 WMSetLabelText(panel->autoDelayL[i + k * 2], autoDelayStrings[i + k * 2]);
169 WMSetLabelTextAlignment(panel->autoDelayL[i + k * 2], WARight);
171 for (j = 0; j < 5; j++)
173 panel->autoDelayB[i + k * 2][j] = WMCreateCustomButton(panel->autoDelayF[k], WBBStateChangeMask);
174 WMResizeWidget(panel->autoDelayB[i + k * 2][j], 25, 25);
175 WMMoveWidget(panel->autoDelayB[i + k * 2][j], 175 + (25 * j), 25 + 40 * i);
176 WMSetButtonBordered(panel->autoDelayB[i + k * 2][j], False);
177 WMSetButtonImagePosition(panel->autoDelayB[i + k * 2][j], WIPImageOnly);
178 WMSetButtonAction(panel->autoDelayB[i + k * 2][j], pushAutoDelayButton, panel);
179 if (j > 0)
180 WMGroupButtons(panel->autoDelayB[i + k * 2][0], panel->autoDelayB[i + k * 2][j]);
181 sprintf(buf1, DELAY_ICON, j);
182 CreateImages(scr, rc, NULL, buf1, &icon1, NULL);
183 if (icon1) {
184 WMSetButtonImage(panel->autoDelayB[i + k * 2][j], icon1);
185 WMReleasePixmap(icon1);
186 } else {
187 wwarning(_("could not load icon file %s"), buf1);
189 sprintf(buf2, DELAY_ICON_S, j);
190 CreateImages(scr, rc, NULL, buf2, &icon2, NULL);
191 if (icon2) {
192 WMSetButtonAltImage(panel->autoDelayB[i + k * 2][j], icon2);
193 WMReleasePixmap(icon2);
194 } else {
195 wwarning(_("could not load icon file %s"), buf2);
199 panel->autoDelayT[i + k * 2] = WMCreateTextField(panel->autoDelayF[k]);
200 WMResizeWidget(panel->autoDelayT[i + k * 2], 36, 20);
201 WMMoveWidget(panel->autoDelayT[i + k * 2], 310, 27 + 40 * i);
202 WMAddNotificationObserver(autoDelayChanged, panel, WMTextDidChangeNotification, panel->autoDelayT[i + k * 2]);
205 WMMapSubwidgets(panel->autoDelayF[k]);
207 wfree(buf1);
208 wfree(buf2);
210 /***************** Enable/disable clip/dock/drawers *****************/
211 panel->dockF = WMCreateFrame(panel->box);
212 WMResizeWidget(panel->dockF, 115, 210);
213 WMMoveWidget(panel->dockF, 390, 10);
214 WMSetFrameTitle(panel->dockF, _("Dock/Clip/Drawer"));
216 for (i = 0; i < 3; i++)
218 panel->docksB[i] = WMCreateButton(panel->dockF, WBTToggle);
219 WMResizeWidget(panel->docksB[i], 56, 56);
220 WMMoveWidget(panel->docksB[i], 30, 20 + 62 * i);
221 WMSetButtonImagePosition(panel->docksB[i], WIPImageOnly);
222 CreateImages(scr, rc, xis, dockFiles[i], &icon1, &icon2);
223 if (icon2) {
224 WMSetButtonImage(panel->docksB[i], icon2);
225 WMReleasePixmap(icon2);
227 if (icon1) {
228 WMSetButtonAltImage(panel->docksB[i], icon1);
229 WMReleasePixmap(icon1);
231 switch(i)
233 case 0:
234 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
235 "vertical icon bar in the side of the screen)."), WMWidgetView(panel->docksB[i]));
236 break;
237 case 1:
238 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
239 "a paper clip icon)."), WMWidgetView(panel->docksB[i]));
240 break;
241 case 2:
242 WMSetBalloonTextForView(_("Disable/enable Drawers (a dock that stores\n"
243 "application icons horizontally). The dock is required."), WMWidgetView(panel->docksB[i]));
244 break;
246 WMSetButtonAction(panel->docksB[i], pushDockButton, panel);
249 WMMapSubwidgets(panel->dockF);
251 if (xis)
252 RReleaseImage(xis);
254 WMRealizeWidget(panel->box);
255 WMMapSubwidgets(panel->box);
257 showData(panel);
260 static void storeData(_Panel *panel)
262 int i;
263 for (i = 0; i < 4; i++)
265 SetStringForKey(WMGetTextFieldText(panel->autoDelayT[i]), autoDelayKeys[i]);
267 for (i = 0; i < 3; i++)
269 SetBoolForKey(!WMGetButtonSelected(panel->docksB[i]), dockDisablingKeys[i]);
273 static void showData(_Panel *panel)
275 char *value;
276 int i;
277 for (i = 0; i < 4; i++)
279 value = GetStringForKey(autoDelayKeys[i]);
280 WMSetTextFieldText(panel->autoDelayT[i], value);
281 adjustButtonSelectionBasedOnValue(panel, i, value);
283 for (i = 0; i < 3; i++)
285 WMSetButtonSelected(panel->docksB[i], !GetBoolForKey(dockDisablingKeys[i]));
289 Panel *InitDocks(WMScreen *scr, WMWidget *parent)
291 _Panel *panel;
293 autoDelayStrings[0] = _("Delay before auto-expansion");
294 autoDelayStrings[1] = _("Delay before auto-collapsing");
295 autoDelayStrings[2] = _("Delay before auto-raise");
296 autoDelayStrings[3] = _("Delay before auto-lowering");
298 panel = wmalloc(sizeof(_Panel));
299 memset(panel, 0, sizeof(_Panel));
301 panel->sectionName = _("Dock Preferences");
303 panel->description = _("Dock and clip features.\n"
304 "Enable/disable the Dock and Clip, and tune some delays.");
306 panel->parent = parent;
308 panel->callbacks.createWidgets = createPanel;
309 panel->callbacks.updateDomain = storeData;
311 AddSection(panel, ICON_FILE);
313 return panel;