WINGs: Make fetchFile() more similar to copyFile() from getstyle.c
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
blob8d270ab15a13ad0be21008f4c2849b658bdf7810
1 /* MenuPreferences.c- menu related preferences
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 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 *scrF;
36 WMButton *scrB[5];
38 WMFrame *aliF;
39 WMButton *aliyB;
40 WMButton *alinB;
42 WMFrame *optF;
43 WMButton *autoB;
44 WMButton *wrapB;
46 } _Panel;
48 #define ICON_FILE "menuprefs"
49 #define SPEED_IMAGE "speed%i"
50 #define SPEED_IMAGE_S "speed%is"
52 #define MENU_ALIGN1 "menualign1"
53 #define MENU_ALIGN2 "menualign2"
55 static void showData(_Panel * panel)
57 WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
59 if (GetBoolForKey("AlignSubmenus"))
60 WMPerformButtonClick(panel->aliyB);
61 else
62 WMPerformButtonClick(panel->alinB);
64 WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
66 WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
69 static void storeData(_Panel * panel)
71 int i;
73 for (i = 0; i < 5; i++) {
74 if (WMGetButtonSelected(panel->scrB[i]))
75 break;
77 SetSpeedForKey(i, "MenuScrollSpeed");
79 SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
81 SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
82 SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
85 static void createPanel(Panel * p)
87 _Panel *panel = (_Panel *) p;
88 WMScreen *scr = WMWidgetScreen(panel->parent);
89 WMPixmap *icon;
90 int i;
91 char *buf1, *buf2;
92 char *path;
94 panel->box = WMCreateBox(panel->parent);
95 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
97 /***************** Menu Scroll Speed ****************/
98 panel->scrF = WMCreateFrame(panel->box);
99 WMResizeWidget(panel->scrF, 235, 90);
100 WMMoveWidget(panel->scrF, 25, 20);
101 WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
103 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
104 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
105 for (i = 0; i < 5; i++) {
106 panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
107 WMResizeWidget(panel->scrB[i], 40, 40);
108 WMMoveWidget(panel->scrB[i], 15 + (40 * i), 30);
109 WMSetButtonBordered(panel->scrB[i], False);
110 WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
111 if (i > 0) {
112 WMGroupButtons(panel->scrB[0], panel->scrB[i]);
114 sprintf(buf1, SPEED_IMAGE, i);
115 sprintf(buf2, SPEED_IMAGE_S, i);
116 path = LocateImage(buf1);
117 if (path) {
118 icon = WMCreatePixmapFromFile(scr, path);
119 if (icon) {
120 WMSetButtonImage(panel->scrB[i], icon);
121 WMReleasePixmap(icon);
122 } else {
123 wwarning(_("could not load icon file %s"), path);
125 wfree(path);
127 path = LocateImage(buf2);
128 if (path) {
129 icon = WMCreatePixmapFromFile(scr, path);
130 if (icon) {
131 WMSetButtonAltImage(panel->scrB[i], icon);
132 WMReleasePixmap(icon);
133 } else {
134 wwarning(_("could not load icon file %s"), path);
136 wfree(path);
139 wfree(buf1);
140 wfree(buf2);
142 WMMapSubwidgets(panel->scrF);
144 /***************** Submenu Alignment ****************/
146 panel->aliF = WMCreateFrame(panel->box);
147 WMResizeWidget(panel->aliF, 220, 90);
148 WMMoveWidget(panel->aliF, 280, 20);
149 WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
151 panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
152 WMResizeWidget(panel->alinB, 48, 48);
153 WMMoveWidget(panel->alinB, 56, 25);
154 WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
155 path = LocateImage(MENU_ALIGN1);
156 if (path) {
157 icon = WMCreatePixmapFromFile(scr, path);
158 if (icon) {
159 WMSetButtonImage(panel->alinB, icon);
160 WMReleasePixmap(icon);
161 } else {
162 wwarning(_("could not load icon file %s"), path);
164 wfree(path);
166 panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
167 WMResizeWidget(panel->aliyB, 48, 48);
168 WMMoveWidget(panel->aliyB, 120, 25);
169 WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
170 path = LocateImage(MENU_ALIGN2);
171 if (path) {
172 icon = WMCreatePixmapFromFile(scr, path);
173 if (icon) {
174 WMSetButtonImage(panel->aliyB, icon);
175 WMReleasePixmap(icon);
176 } else {
177 wwarning(_("could not load icon file %s"), path);
179 wfree(path);
181 WMGroupButtons(panel->alinB, panel->aliyB);
183 WMMapSubwidgets(panel->aliF);
185 /***************** Options ****************/
186 panel->optF = WMCreateFrame(panel->box);
187 WMResizeWidget(panel->optF, 475, 80);
188 WMMoveWidget(panel->optF, 25, 130);
190 panel->wrapB = WMCreateSwitchButton(panel->optF);
191 WMResizeWidget(panel->wrapB, 440, 32);
192 WMMoveWidget(panel->wrapB, 25, 8);
193 WMSetButtonText(panel->wrapB,
195 ("Always open submenus inside the screen, instead of scrolling.\nNote: this is annoying."));
197 panel->autoB = WMCreateSwitchButton(panel->optF);
198 WMResizeWidget(panel->autoB, 440, 32);
199 WMMoveWidget(panel->autoB, 25, 45);
200 WMSetButtonText(panel->autoB, _("Scroll off-screen menus when pointer is moved over them."));
202 WMMapSubwidgets(panel->optF);
204 WMRealizeWidget(panel->box);
205 WMMapSubwidgets(panel->box);
207 showData(panel);
210 Panel *InitMenuPreferences(WMScreen * scr, WMWidget * parent)
212 _Panel *panel;
214 panel = wmalloc(sizeof(_Panel));
215 memset(panel, 0, sizeof(_Panel));
217 panel->sectionName = _("Menu Preferences");
219 panel->description = _("Menu usability related options. Scrolling speed,\n" "alignment of submenus etc.");
221 panel->parent = parent;
223 panel->callbacks.createWidgets = createPanel;
224 panel->callbacks.updateDomain = storeData;
226 AddSection(panel, ICON_FILE);
228 return panel;