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,
25 typedef struct _Panel
{
32 CallbackRec callbacks
;
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
);
63 WMPerformButtonClick(panel
->alinB
);
65 WMSetButtonSelected(panel
->wrapB
, GetBoolForKey("WrapMenus"));
67 WMSetButtonSelected(panel
->autoB
, GetBoolForKey("ScrollableMenus"));
70 static void storeData(_Panel
* panel
)
74 for (i
= 0; i
< 5; i
++) {
75 if (WMGetButtonSelected(panel
->scrB
[i
]))
78 SetSpeedForKey(i
, "MenuScrollSpeed");
80 SetBoolForKey(WMGetButtonSelected(panel
->aliyB
), "AlignSubmenus");
82 SetBoolForKey(WMGetButtonSelected(panel
->wrapB
), "WrapMenus");
83 SetBoolForKey(WMGetButtonSelected(panel
->autoB
), "ScrollableMenus");
86 static void createPanel(Panel
* p
)
88 _Panel
*panel
= (_Panel
*) p
;
89 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
95 panel
->box
= WMCreateBox(panel
->parent
);
96 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
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"));
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
);
113 WMGroupButtons(panel
->scrB
[0], panel
->scrB
[i
]);
115 sprintf(buf1
, SPEED_IMAGE
, i
);
116 sprintf(buf2
, SPEED_IMAGE_S
, i
);
117 path
= LocateImage(buf1
);
119 icon
= WMCreatePixmapFromFile(scr
, path
);
121 WMSetButtonImage(panel
->scrB
[i
], icon
);
122 WMReleasePixmap(icon
);
124 wwarning(_("could not load icon file %s"), path
);
128 path
= LocateImage(buf2
);
130 icon
= WMCreatePixmapFromFile(scr
, path
);
132 WMSetButtonAltImage(panel
->scrB
[i
], icon
);
133 WMReleasePixmap(icon
);
135 wwarning(_("could not load icon file %s"), path
);
143 WMMapSubwidgets(panel
->scrF
);
145 /***************** Submenu Alignment ****************/
147 panel
->aliF
= WMCreateFrame(panel
->box
);
148 WMResizeWidget(panel
->aliF
, 220, 90);
149 WMMoveWidget(panel
->aliF
, 280, 20);
150 WMSetFrameTitle(panel
->aliF
, _("Submenu Alignment"));
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
);
158 icon
= WMCreatePixmapFromFile(scr
, path
);
160 WMSetButtonImage(panel
->alinB
, icon
);
161 WMReleasePixmap(icon
);
163 wwarning(_("could not load icon file %s"), path
);
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
);
173 icon
= WMCreatePixmapFromFile(scr
, path
);
175 WMSetButtonImage(panel
->aliyB
, icon
);
176 WMReleasePixmap(icon
);
178 wwarning(_("could not load icon file %s"), path
);
182 WMGroupButtons(panel
->alinB
, panel
->aliyB
);
184 WMMapSubwidgets(panel
->aliF
);
186 /***************** Options ****************/
187 panel
->optF
= WMCreateFrame(panel
->box
);
188 WMResizeWidget(panel
->optF
, 475, 80);
189 WMMoveWidget(panel
->optF
, 25, 130);
191 panel
->wrapB
= WMCreateSwitchButton(panel
->optF
);
192 WMResizeWidget(panel
->wrapB
, 440, 32);
193 WMMoveWidget(panel
->wrapB
, 25, 8);
194 WMSetButtonText(panel
->wrapB
,
196 ("Always open submenus inside the screen, instead of scrolling.\nNote: this is annoying."));
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."));
203 WMMapSubwidgets(panel
->optF
);
205 WMRealizeWidget(panel
->box
);
206 WMMapSubwidgets(panel
->box
);
211 Panel
*InitMenuPreferences(WMScreen
* scr
, WMWidget
* parent
)
215 panel
= wmalloc(sizeof(_Panel
));
216 memset(panel
, 0, sizeof(_Panel
));
218 panel
->sectionName
= _("Menu Preferences");
220 panel
->description
= _("Menu usability related options. Scrolling speed,\n" "alignment of submenus etc.");
222 panel
->parent
= parent
;
224 panel
->callbacks
.createWidgets
= createPanel
;
225 panel
->callbacks
.updateDomain
= storeData
;
227 AddSection(panel
, ICON_FILE
);