wIconChangeImageFile use set_icon_image_from_image
[wmaker-crm.git] / WPrefs.app / MenuPreferences.c
blobc93ee30c6dd813f6afc2c501018d6aeda1f16d67
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 *autoC;
45 WMButton *wrapB;
47 } _Panel;
49 #define ICON_FILE "menuprefs"
50 #define SPEED_IMAGE "speed%i"
51 #define SPEED_IMAGE_S "speed%is"
53 #define MENU_ALIGN1 "menualign1"
54 #define MENU_ALIGN2 "menualign2"
56 static void showData(_Panel * panel)
58 WMPerformButtonClick(panel->scrB[GetSpeedForKey("MenuScrollSpeed")]);
60 if (GetBoolForKey("AlignSubmenus"))
61 WMPerformButtonClick(panel->aliyB);
62 else
63 WMPerformButtonClick(panel->alinB);
65 WMSetButtonSelected(panel->wrapB, GetBoolForKey("WrapMenus"));
67 WMSetButtonSelected(panel->autoB, GetBoolForKey("ScrollableMenus"));
69 WMSetButtonSelected(panel->autoC, GetBoolForKey("ViKeyMenus"));
72 static void storeData(_Panel * panel)
74 int i;
76 for (i = 0; i < 5; i++) {
77 if (WMGetButtonSelected(panel->scrB[i]))
78 break;
80 SetSpeedForKey(i, "MenuScrollSpeed");
82 SetBoolForKey(WMGetButtonSelected(panel->aliyB), "AlignSubmenus");
84 SetBoolForKey(WMGetButtonSelected(panel->wrapB), "WrapMenus");
85 SetBoolForKey(WMGetButtonSelected(panel->autoB), "ScrollableMenus");
86 SetBoolForKey(WMGetButtonSelected(panel->autoC), "ViKeyMenus");
89 static void createPanel(Panel * p)
91 _Panel *panel = (_Panel *) p;
92 WMScreen *scr = WMWidgetScreen(panel->parent);
93 WMPixmap *icon;
94 int i;
95 char *buf1, *buf2;
96 char *path;
98 panel->box = WMCreateBox(panel->parent);
99 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
101 /***************** Menu Scroll Speed ****************/
102 panel->scrF = WMCreateFrame(panel->box);
103 WMResizeWidget(panel->scrF, 235, 90);
104 WMMoveWidget(panel->scrF, 25, 20);
105 WMSetFrameTitle(panel->scrF, _("Menu Scrolling Speed"));
107 buf1 = wmalloc(strlen(SPEED_IMAGE) + 1);
108 buf2 = wmalloc(strlen(SPEED_IMAGE_S) + 1);
109 for (i = 0; i < 5; i++) {
110 panel->scrB[i] = WMCreateCustomButton(panel->scrF, WBBStateChangeMask);
111 WMResizeWidget(panel->scrB[i], 40, 40);
112 WMMoveWidget(panel->scrB[i], 15 + (40 * i), 30);
113 WMSetButtonBordered(panel->scrB[i], False);
114 WMSetButtonImagePosition(panel->scrB[i], WIPImageOnly);
115 if (i > 0) {
116 WMGroupButtons(panel->scrB[0], panel->scrB[i]);
118 sprintf(buf1, SPEED_IMAGE, i);
119 sprintf(buf2, SPEED_IMAGE_S, i);
120 path = LocateImage(buf1);
121 if (path) {
122 icon = WMCreatePixmapFromFile(scr, path);
123 if (icon) {
124 WMSetButtonImage(panel->scrB[i], icon);
125 WMReleasePixmap(icon);
126 } else {
127 wwarning(_("could not load icon file %s"), path);
129 wfree(path);
131 path = LocateImage(buf2);
132 if (path) {
133 icon = WMCreatePixmapFromFile(scr, path);
134 if (icon) {
135 WMSetButtonAltImage(panel->scrB[i], icon);
136 WMReleasePixmap(icon);
137 } else {
138 wwarning(_("could not load icon file %s"), path);
140 wfree(path);
143 wfree(buf1);
144 wfree(buf2);
146 WMMapSubwidgets(panel->scrF);
148 /***************** Submenu Alignment ****************/
150 panel->aliF = WMCreateFrame(panel->box);
151 WMResizeWidget(panel->aliF, 220, 90);
152 WMMoveWidget(panel->aliF, 280, 20);
153 WMSetFrameTitle(panel->aliF, _("Submenu Alignment"));
155 panel->alinB = WMCreateButton(panel->aliF, WBTOnOff);
156 WMResizeWidget(panel->alinB, 48, 48);
157 WMMoveWidget(panel->alinB, 56, 25);
158 WMSetButtonImagePosition(panel->alinB, WIPImageOnly);
159 path = LocateImage(MENU_ALIGN1);
160 if (path) {
161 icon = WMCreatePixmapFromFile(scr, path);
162 if (icon) {
163 WMSetButtonImage(panel->alinB, icon);
164 WMReleasePixmap(icon);
165 } else {
166 wwarning(_("could not load icon file %s"), path);
168 wfree(path);
170 panel->aliyB = WMCreateButton(panel->aliF, WBTOnOff);
171 WMResizeWidget(panel->aliyB, 48, 48);
172 WMMoveWidget(panel->aliyB, 120, 25);
173 WMSetButtonImagePosition(panel->aliyB, WIPImageOnly);
174 path = LocateImage(MENU_ALIGN2);
175 if (path) {
176 icon = WMCreatePixmapFromFile(scr, path);
177 if (icon) {
178 WMSetButtonImage(panel->aliyB, icon);
179 WMReleasePixmap(icon);
180 } else {
181 wwarning(_("could not load icon file %s"), path);
183 wfree(path);
185 WMGroupButtons(panel->alinB, panel->aliyB);
187 WMMapSubwidgets(panel->aliF);
189 /***************** Options ****************/
190 panel->optF = WMCreateFrame(panel->box);
191 WMResizeWidget(panel->optF, 475, 96);
192 WMMoveWidget(panel->optF, 25, 120);
194 panel->wrapB = WMCreateSwitchButton(panel->optF);
195 WMResizeWidget(panel->wrapB, 440, 32);
196 WMMoveWidget(panel->wrapB, 25, 8);
197 WMSetButtonText(panel->wrapB, _("Always open submenus inside the screen, instead of scrolling."));
199 panel->autoB = WMCreateSwitchButton(panel->optF);
200 WMResizeWidget(panel->autoB, 440, 32);
201 WMMoveWidget(panel->autoB, 25, 34);
202 WMSetButtonText(panel->autoB, _("Scroll off-screen menus when pointer is moved over them."));
203 panel->autoC = WMCreateSwitchButton(panel->optF);
204 WMResizeWidget(panel->autoC, 440, 32);
205 WMMoveWidget(panel->autoC, 25, 58);
206 WMSetButtonText(panel->autoC, _("Use h/j/k/l keys to select menu options."));
208 WMMapSubwidgets(panel->optF);
210 WMRealizeWidget(panel->box);
211 WMMapSubwidgets(panel->box);
213 showData(panel);
216 Panel *InitMenuPreferences(WMScreen * scr, WMWidget * parent)
218 _Panel *panel;
220 panel = wmalloc(sizeof(_Panel));
222 panel->sectionName = _("Menu Preferences");
224 panel->description = _("Menu usability related options. Scrolling speed,\n" "alignment of submenus etc.");
226 panel->parent = parent;
228 panel->callbacks.createWidgets = createPanel;
229 panel->callbacks.updateDomain = storeData;
231 AddSection(panel, ICON_FILE);
233 return panel;