Updating to version 0.20.2
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
blobe4cd6d21d5e6980a03fcb318e402057a04989046
1 /* MenuPreferences.c- menu related preferences
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"
26 typedef struct _Panel {
27 WMFrame *frame;
29 char *sectionName;
31 CallbackRec callbacks;
33 WMWindow *win;
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;
50 #define ICON_FILE "menuprefs"
51 #define SPEED_IMAGE "speed%i"
52 #define SPEED_IMAGE_S "speed%is"
54 #define MENU_ALIGN1 "menualign1"
55 #define MENU_ALIGN2 "menualign2"
58 static void
59 showData(_Panel *panel)
61 WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
63 if (GetBoolForKey("AlignSubmenus"))
64 WMPerformButtonClick(panel->aliyB);
65 else
66 WMPerformButtonClick(panel->alinB);
68 WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
70 WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
74 static void
75 storeData(_Panel *panel)
77 int i;
79 for (i=0; i<5; i++) {
80 if (WMGetButtonSelected(panel->scrB[i]))
81 break;
83 SetSpeedForKey(i, "MenuScrollSpeed");
85 SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
87 SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
88 SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
92 static void
93 createPanel(Panel *p)
95 _Panel *panel = (_Panel*)p;
96 WMScreen *scr = WMWidgetScreen(panel->win);
98 WMPixmap *icon;
99 int i;
100 char *buf1, *buf2;
101 char *path;
103 panel->frame = WMCreateFrame(panel->win);
104 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
105 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
108 /***************** Menu Scroll Speed ****************/
109 panel->scrF = WMCreateFrame(panel->frame);
110 WMResizeWidget(panel->scrF, 235, 90);
111 WMMoveWidget(panel->scrF, 25, 20);
112 WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
115 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
116 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
117 for (i = 0; i < 5; i++) {
118 panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
119 WMResizeWidget(panel->scrB[i], 40, 40);
120 WMMoveWidget(panel->scrB[i], 15+(40*i), 30);
121 WMSetButtonBordered(panel->scrB[i], False);
122 WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
123 if (i > 0) {
124 WMGroupButtons(panel->scrB[0], panel->scrB[i]);
126 sprintf(buf1, SPEED_IMAGE, i);
127 sprintf(buf2, SPEED_IMAGE_S, i);
128 path = LocateImage(buf1);
129 if (path) {
130 icon = WMCreatePixmapFromFile(scr, path);
131 if (icon) {
132 WMSetButtonImage(panel->scrB[i], icon);
133 WMReleasePixmap(icon);
134 } else {
135 wwarning(_("could not load icon file %s"), path);
137 free(path);
139 path = LocateImage(buf2);
140 if (path) {
141 icon = WMCreatePixmapFromFile(scr, path);
142 if (icon) {
143 WMSetButtonAltImage(panel->scrB[i], icon);
144 WMReleasePixmap(icon);
145 } else {
146 wwarning(_("could not load icon file %s"), path);
148 free(path);
151 free(buf1);
152 free(buf2);
154 WMMapSubwidgets(panel->scrF);
156 /***************** Submenu Alignment ****************/
158 panel->aliF = WMCreateFrame(panel->frame);
159 WMResizeWidget(panel->aliF, 220, 90);
160 WMMoveWidget(panel->aliF, 280, 20);
161 WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
163 panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
164 WMResizeWidget(panel->alinB, 48, 48);
165 WMMoveWidget(panel->alinB, 56, 25);
166 WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
167 path = LocateImage(MENU_ALIGN1);
168 if (path) {
169 icon = WMCreatePixmapFromFile(scr, path);
170 if (icon) {
171 WMSetButtonImage(panel->alinB, icon);
172 WMReleasePixmap(icon);
173 } else {
174 wwarning(_("could not load icon file %s"), path);
176 free(path);
178 panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
179 WMResizeWidget(panel->aliyB, 48, 48);
180 WMMoveWidget(panel->aliyB, 120, 25);
181 WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
182 path = LocateImage(MENU_ALIGN2);
183 if (path) {
184 icon = WMCreatePixmapFromFile(scr, path);
185 if (icon) {
186 WMSetButtonImage(panel->aliyB, icon);
187 WMReleasePixmap(icon);
188 } else {
189 wwarning(_("could not load icon file %s"), path);
192 WMGroupButtons(panel->alinB, panel->aliyB);
194 WMMapSubwidgets(panel->aliF);
196 /***************** Options ****************/
197 panel->optF = WMCreateFrame(panel->frame);
198 WMResizeWidget(panel->optF, 475, 80);
199 WMMoveWidget(panel->optF, 25, 130);
201 panel->wrapB = WMCreateSwitchButton(panel->optF);
202 WMResizeWidget(panel->wrapB, 440, 32);
203 WMMoveWidget(panel->wrapB, 25, 8);
204 WMSetButtonText(panel->wrapB, _("Always open submenus inside the screen, instead of scrolling.\nNote: this can be an annoyance at some circumstances."));
206 panel->autoB = WMCreateSwitchButton(panel->optF);
207 WMResizeWidget(panel->autoB, 440, 20);
208 WMMoveWidget(panel->autoB, 25, 45);
209 WMSetButtonText(panel->autoB, _("Scroll off-screen menus when pointer is moved over them."));
211 WMMapSubwidgets(panel->optF);
213 WMRealizeWidget(panel->frame);
214 WMMapSubwidgets(panel->frame);
216 showData(panel);
221 Panel*
222 InitMenuPreferences(WMScreen *scr, WMWindow *win)
224 _Panel *panel;
226 panel = wmalloc(sizeof(_Panel));
227 memset(panel, 0, sizeof(_Panel));
229 panel->sectionName = _("Menu Preferences");
231 panel->win = win;
233 panel->callbacks.createWidgets = createPanel;
234 panel->callbacks.updateDomain = storeData;
236 AddSection(panel, ICON_FILE);
238 return panel;