changed indentation to use spaces only
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
blobcf4e3245169769a09493c6ebf6ee3a68baa607e3
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
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 WMBox *box;
29 char *sectionName;
31 char *description;
33 CallbackRec callbacks;
35 WMWidget *parent;
37 WMFrame *scrF;
38 WMButton *scrB[5];
40 WMFrame *aliF;
41 WMButton *aliyB;
42 WMButton *alinB;
44 WMFrame *optF;
45 WMButton *autoB;
46 WMButton *wrapB;
48 } _Panel;
52 #define ICON_FILE "menuprefs"
53 #define SPEED_IMAGE "speed%i"
54 #define SPEED_IMAGE_S "speed%is"
56 #define MENU_ALIGN1 "menualign1"
57 #define MENU_ALIGN2 "menualign2"
60 static void
61 showData(_Panel *panel)
63 WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
65 if (GetBoolForKey("AlignSubmenus"))
66 WMPerformButtonClick(panel->aliyB);
67 else
68 WMPerformButtonClick(panel->alinB);
70 WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
72 WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
76 static void
77 storeData(_Panel *panel)
79 int i;
81 for (i=0; i<5; i++) {
82 if (WMGetButtonSelected(panel->scrB[i]))
83 break;
85 SetSpeedForKey(i, "MenuScrollSpeed");
87 SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
89 SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
90 SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
94 static void
95 createPanel(Panel *p)
97 _Panel *panel = (_Panel*)p;
98 WMScreen *scr = WMWidgetScreen(panel->parent);
99 WMPixmap *icon;
100 int i;
101 char *buf1, *buf2;
102 char *path;
104 panel->box = WMCreateBox(panel->parent);
105 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
107 /***************** Menu Scroll Speed ****************/
108 panel->scrF = WMCreateFrame(panel->box);
109 WMResizeWidget(panel->scrF, 235, 90);
110 WMMoveWidget(panel->scrF, 25, 20);
111 WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
114 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
115 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
116 for (i = 0; i < 5; i++) {
117 panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
118 WMResizeWidget(panel->scrB[i], 40, 40);
119 WMMoveWidget(panel->scrB[i], 15+(40*i), 30);
120 WMSetButtonBordered(panel->scrB[i], False);
121 WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
122 if (i > 0) {
123 WMGroupButtons(panel->scrB[0], panel->scrB[i]);
125 sprintf(buf1, SPEED_IMAGE, i);
126 sprintf(buf2, SPEED_IMAGE_S, i);
127 path = LocateImage(buf1);
128 if (path) {
129 icon = WMCreatePixmapFromFile(scr, path);
130 if (icon) {
131 WMSetButtonImage(panel->scrB[i], icon);
132 WMReleasePixmap(icon);
133 } else {
134 wwarning(_("could not load icon file %s"), path);
136 wfree(path);
138 path = LocateImage(buf2);
139 if (path) {
140 icon = WMCreatePixmapFromFile(scr, path);
141 if (icon) {
142 WMSetButtonAltImage(panel->scrB[i], icon);
143 WMReleasePixmap(icon);
144 } else {
145 wwarning(_("could not load icon file %s"), path);
147 wfree(path);
150 wfree(buf1);
151 wfree(buf2);
153 WMMapSubwidgets(panel->scrF);
155 /***************** Submenu Alignment ****************/
157 panel->aliF = WMCreateFrame(panel->box);
158 WMResizeWidget(panel->aliF, 220, 90);
159 WMMoveWidget(panel->aliF, 280, 20);
160 WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
162 panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
163 WMResizeWidget(panel->alinB, 48, 48);
164 WMMoveWidget(panel->alinB, 56, 25);
165 WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
166 path = LocateImage(MENU_ALIGN1);
167 if (path) {
168 icon = WMCreatePixmapFromFile(scr, path);
169 if (icon) {
170 WMSetButtonImage(panel->alinB, icon);
171 WMReleasePixmap(icon);
172 } else {
173 wwarning(_("could not load icon file %s"), path);
175 wfree(path);
177 panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
178 WMResizeWidget(panel->aliyB, 48, 48);
179 WMMoveWidget(panel->aliyB, 120, 25);
180 WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
181 path = LocateImage(MENU_ALIGN2);
182 if (path) {
183 icon = WMCreatePixmapFromFile(scr, path);
184 if (icon) {
185 WMSetButtonImage(panel->aliyB, icon);
186 WMReleasePixmap(icon);
187 } else {
188 wwarning(_("could not load icon file %s"), path);
190 wfree(path);
192 WMGroupButtons(panel->alinB, panel->aliyB);
194 WMMapSubwidgets(panel->aliF);
196 /***************** Options ****************/
197 panel->optF = WMCreateFrame(panel->box);
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 is annoying."));
206 panel->autoB = WMCreateSwitchButton(panel->optF);
207 WMResizeWidget(panel->autoB, 440, 32);
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->box);
214 WMMapSubwidgets(panel->box);
216 showData(panel);
221 Panel*
222 InitMenuPreferences(WMScreen *scr, WMWidget *parent)
224 _Panel *panel;
226 panel = wmalloc(sizeof(_Panel));
227 memset(panel, 0, sizeof(_Panel));
229 panel->sectionName = _("Menu Preferences");
231 panel->description = _("Menu usability related options. Scrolling speed,\n"
232 "alignment of submenus etc.");
234 panel->parent = parent;
236 panel->callbacks.createWidgets = createPanel;
237 panel->callbacks.updateDomain = storeData;
239 AddSection(panel, ICON_FILE);
241 return panel;