Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* MenuPreferences.c- menu related preferences
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "WPrefs.h"
24
25typedef struct _Panel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026 WMBox *box;
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028 char *sectionName;
9d2e6ef9 scottc1998-09-29 22:36:29 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 char *description;
d3f29988 kojima1999-04-25 01:49:46 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032 CallbackRec callbacks;
6830b057 dan2004-10-12 21:28:27 +000033
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 WMWidget *parent;
9d2e6ef9 scottc1998-09-29 22:36:29 +000035
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020036 WMFrame *scrF;
37 WMButton *scrB[5];
6830b057 dan2004-10-12 21:28:27 +000038
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020039 WMFrame *aliF;
40 WMButton *aliyB;
41 WMButton *alinB;
6830b057 dan2004-10-12 21:28:27 +000042
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020043 WMFrame *optF;
44 WMButton *autoB;
45 WMButton *wrapB;
9d2e6ef9 scottc1998-09-29 22:36:29 +000046
47} _Panel;
48
9d2e6ef9 scottc1998-09-29 22:36:29 +000049#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
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020056static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +000057{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020058 WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
6830b057 dan2004-10-12 21:28:27 +000059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020060 if (GetBoolForKey("AlignSubmenus"))
61 WMPerformButtonClick(panel->aliyB);
62 else
63 WMPerformButtonClick(panel->alinB);
6830b057 dan2004-10-12 21:28:27 +000064
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020065 WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
6830b057 dan2004-10-12 21:28:27 +000066
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067 WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
9d2e6ef9 scottc1998-09-29 22:36:29 +000068}
69
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020070static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +000071{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020072 int i;
6830b057 dan2004-10-12 21:28:27 +000073
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020074 for (i = 0; i < 5; i++) {
75 if (WMGetButtonSelected(panel->scrB[i]))
76 break;
77 }
78 SetSpeedForKey(i, "MenuScrollSpeed");
9d2e6ef9 scottc1998-09-29 22:36:29 +000079
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020080 SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
9d2e6ef9 scottc1998-09-29 22:36:29 +000081
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020082 SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
83 SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
9d2e6ef9 scottc1998-09-29 22:36:29 +000084}
85
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020086static void createPanel(Panel * p)
9d2e6ef9 scottc1998-09-29 22:36:29 +000087{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020088 _Panel *panel = (_Panel *) p;
89 WMScreen *scr = WMWidgetScreen(panel->parent);
90 WMPixmap *icon;
91 int i;
92 char *buf1, *buf2;
93 char *path;
6830b057 dan2004-10-12 21:28:27 +000094
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020095 panel->box = WMCreateBox(panel->parent);
96 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
6830b057 dan2004-10-12 21:28:27 +000097
9d2e6ef9 scottc1998-09-29 22:36:29 +000098 /***************** Menu Scroll Speed ****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020099 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000144
145 /***************** Submenu Alignment ****************/
6830b057 dan2004-10-12 21:28:27 +0000146
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200147 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);
6830b057 dan2004-10-12 21:28:27 +0000185
9d2e6ef9 scottc1998-09-29 22:36:29 +0000186 /***************** Options ****************/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200187 panel->optF = WMCreateFrame(panel->box);
188 WMResizeWidget(panel->optF, 475, 80);
189 WMMoveWidget(panel->optF, 25, 130);
6830b057 dan2004-10-12 21:28:27 +0000190
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200191 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."));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000197
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200198 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."));
6830b057 dan2004-10-12 21:28:27 +0000202
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200203 WMMapSubwidgets(panel->optF);
6830b057 dan2004-10-12 21:28:27 +0000204
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200205 WMRealizeWidget(panel->box);
206 WMMapSubwidgets(panel->box);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000207
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200208 showData(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000209}
210
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200211Panel *InitMenuPreferences(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000212{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200213 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000214
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200215 panel = wmalloc(sizeof(_Panel));
216 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000217
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200218 panel->sectionName = _("Menu Preferences");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000219
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200220 panel->description = _("Menu usability related options. Scrolling speed,\n" "alignment of submenus etc.");
d3f29988 kojima1999-04-25 01:49:46 +0000221
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200222 panel->parent = parent;
6830b057 dan2004-10-12 21:28:27 +0000223
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200224 panel->callbacks.createWidgets = createPanel;
225 panel->callbacks.updateDomain = storeData;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000226
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200227 AddSection(panel, ICON_FILE);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000228
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200229 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000230}