Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
1 /* MenuPreferences.c- menu related preferences
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
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.
21  */
22
23 #include "WPrefs.h"
24
25 typedef struct _Panel {
26         WMBox *box;
27
28         char *sectionName;
29
30         char *description;
31
32         CallbackRec callbacks;
33
34         WMWidget *parent;
35
36         WMFrame *scrF;
37         WMButton *scrB[5];
38
39         WMFrame *aliF;
40         WMButton *aliyB;
41         WMButton *alinB;
42
43         WMFrame *optF;
44         WMButton *autoB;
45         WMButton *wrapB;
46
47 } _Panel;
48
49 #define ICON_FILE       "menuprefs"
50 #define SPEED_IMAGE "speed%i"
51 #define SPEED_IMAGE_S "speed%is"
52
53 #define MENU_ALIGN1 "menualign1"
54 #define MENU_ALIGN2 "menualign2"
55
56 static void showData(_Panel * panel)
57 {
58         WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
59
60         if (GetBoolForKey("AlignSubmenus"))
61                 WMPerformButtonClick(panel->aliyB);
62         else
63                 WMPerformButtonClick(panel->alinB);
64
65         WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
66
67         WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
68 }
69
70 static void storeData(_Panel * panel)
71 {
72         int i;
73
74         for (i = 0; i < 5; i++) {
75                 if (WMGetButtonSelected(panel->scrB[i]))
76                         break;
77         }
78         SetSpeedForKey(i, "MenuScrollSpeed");
79
80         SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
81
82         SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
83         SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
84 }
85
86 static void createPanel(Panel * p)
87 {
88         _Panel *panel = (_Panel *) p;
89         WMScreen *scr = WMWidgetScreen(panel->parent);
90         WMPixmap *icon;
91         int i;
92         char *buf1, *buf2;
93         char *path;
94
95         panel->box = WMCreateBox(panel->parent);
96         WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
97
98     /***************** Menu Scroll Speed ****************/
99         panel->scrF = WMCreateFrame(panel->box);
100         WMResizeWidget(panel->scrF, 235, 90);
101         WMMoveWidget(panel->scrF, 25, 20);
102         WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
103
104         buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
105         buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
106         for (i = 0; i < 5; i++) {
107                 panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
108                 WMResizeWidget(panel->scrB[i], 40, 40);
109                 WMMoveWidget(panel->scrB[i], 15 + (40 * i), 30);
110                 WMSetButtonBordered(panel->scrB[i], False);
111                 WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
112                 if (i > 0) {
113                         WMGroupButtons(panel->scrB[0], panel->scrB[i]);
114                 }
115                 sprintf(buf1, SPEED_IMAGE, i);
116                 sprintf(buf2, SPEED_IMAGE_S, i);
117                 path = LocateImage(buf1);
118                 if (path) {
119                         icon = WMCreatePixmapFromFile(scr, path);
120                         if (icon) {
121                                 WMSetButtonImage(panel->scrB[i], icon);
122                                 WMReleasePixmap(icon);
123                         } else {
124                                 wwarning(_("could not load icon file %s"), path);
125                         }
126                         wfree(path);
127                 }
128                 path = LocateImage(buf2);
129                 if (path) {
130                         icon = WMCreatePixmapFromFile(scr, path);
131                         if (icon) {
132                                 WMSetButtonAltImage(panel->scrB[i], icon);
133                                 WMReleasePixmap(icon);
134                         } else {
135                                 wwarning(_("could not load icon file %s"), path);
136                         }
137                         wfree(path);
138                 }
139         }
140         wfree(buf1);
141         wfree(buf2);
142
143         WMMapSubwidgets(panel->scrF);
144
145     /***************** Submenu Alignment ****************/
146
147         panel->aliF = WMCreateFrame(panel->box);
148         WMResizeWidget(panel->aliF, 220, 90);
149         WMMoveWidget(panel->aliF, 280, 20);
150         WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
151
152         panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
153         WMResizeWidget(panel->alinB, 48, 48);
154         WMMoveWidget(panel->alinB, 56, 25);
155         WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
156         path = LocateImage(MENU_ALIGN1);
157         if (path) {
158                 icon = WMCreatePixmapFromFile(scr, path);
159                 if (icon) {
160                         WMSetButtonImage(panel->alinB, icon);
161                         WMReleasePixmap(icon);
162                 } else {
163                         wwarning(_("could not load icon file %s"), path);
164                 }
165                 wfree(path);
166         }
167         panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
168         WMResizeWidget(panel->aliyB, 48, 48);
169         WMMoveWidget(panel->aliyB, 120, 25);
170         WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
171         path = LocateImage(MENU_ALIGN2);
172         if (path) {
173                 icon = WMCreatePixmapFromFile(scr, path);
174                 if (icon) {
175                         WMSetButtonImage(panel->aliyB, icon);
176                         WMReleasePixmap(icon);
177                 } else {
178                         wwarning(_("could not load icon file %s"), path);
179                 }
180                 wfree(path);
181         }
182         WMGroupButtons(panel->alinB, panel->aliyB);
183
184         WMMapSubwidgets(panel->aliF);
185
186     /***************** Options ****************/
187         panel->optF = WMCreateFrame(panel->box);
188         WMResizeWidget(panel->optF, 475, 80);
189         WMMoveWidget(panel->optF, 25, 130);
190
191         panel->wrapB = WMCreateSwitchButton(panel->optF);
192         WMResizeWidget(panel->wrapB, 440, 32);
193         WMMoveWidget(panel->wrapB, 25, 8);
194         WMSetButtonText(panel->wrapB,
195                         _
196                         ("Always open submenus inside the screen, instead of scrolling.\nNote: this is annoying."));
197
198         panel->autoB = WMCreateSwitchButton(panel->optF);
199         WMResizeWidget(panel->autoB, 440, 32);
200         WMMoveWidget(panel->autoB, 25, 45);
201         WMSetButtonText(panel->autoB, _("Scroll off-screen menus when pointer is moved over them."));
202
203         WMMapSubwidgets(panel->optF);
204
205         WMRealizeWidget(panel->box);
206         WMMapSubwidgets(panel->box);
207
208         showData(panel);
209 }
210
211 Panel *InitMenuPreferences(WMScreen * scr, WMWidget * parent)
212 {
213         _Panel *panel;
214
215         panel = wmalloc(sizeof(_Panel));
216         memset(panel, 0, sizeof(_Panel));
217
218         panel->sectionName = _("Menu Preferences");
219
220         panel->description = _("Menu usability related options. Scrolling speed,\n" "alignment of submenus etc.");
221
222         panel->parent = parent;
223
224         panel->callbacks.createWidgets = createPanel;
225         panel->callbacks.updateDomain = storeData;
226
227         AddSection(panel, ICON_FILE);
228
229         return panel;
230 }