wmaker: Removed explicit callback type conversion
[wmaker-crm.git] / WINGs / wmenuitem.c
blob1f51bcaf52fe69eb8a09f2f89b4bf14329157dcf
2 #include "WINGsP.h"
4 typedef struct W_MenuItem {
5 char *title;
7 WMPixmap *image;
9 char *shortcutKey;
10 int shortcutModifierMask;
12 WMAction *action;
13 void *data;
15 struct W_Menu *submenu;
17 void *object;
19 WMPixmap *onStateImage;
20 WMPixmap *offStateImage;
21 WMPixmap *mixedStateImage;
23 struct {
24 unsigned enabled:1;
25 unsigned state:2;
26 } flags;
27 } MenuItem;
29 WMMenuItem *WMGetSeparatorMenuItem(void)
31 return NULL;
34 Bool WMMenuItemIsSeparator(WMMenuItem * item)
36 return False;
39 WMMenuItem *WMCreateMenuItem(void)
41 WMMenuItem *item;
43 item = wmalloc(sizeof(MenuItem));
45 item->flags.enabled = 1;
47 return item;
50 void WMDestroyMenuItem(WMMenuItem * item)
52 if (item->title)
53 wfree(item->title);
55 if (item->image)
56 WMReleasePixmap(item->image);
58 if (item->shortcutKey)
59 wfree(item->shortcutKey);
61 if (item->onStateImage)
62 WMReleasePixmap(item->onStateImage);
64 if (item->offStateImage)
65 WMReleasePixmap(item->offStateImage);
67 if (item->mixedStateImage)
68 WMReleasePixmap(item->mixedStateImage);
71 Bool WMGetMenuItemEnabled(WMMenuItem * item)
73 return item->flags.enabled;
76 void WMSetMenuItemEnabled(WMMenuItem * item, Bool flag)
78 item->flags.enabled = ((flag == 0) ? 0 : 1);
81 char *WMGetMenuItemShortcut(WMMenuItem * item)
83 return item->shortcutKey;
86 unsigned WMGetMenuItemShortcutModifierMask(WMMenuItem * item)
88 return item->shortcutModifierMask;
91 void WMSetMenuItemShortcut(WMMenuItem * item, const char *shortcut)
93 if (item->shortcutKey)
94 wfree(item->shortcutKey);
96 item->shortcutKey = wstrdup(shortcut);
99 void WMSetMenuItemShortcutModifierMask(WMMenuItem * item, unsigned mask)
101 item->shortcutModifierMask = mask;
104 void *WMGetMenuItemRepresentedObject(WMMenuItem * item)
106 return item->object;
109 void WMSetMenuItemRepresentedObject(WMMenuItem * item, void *object)
111 item->object = object;
114 void WMSetMenuItemAction(WMMenuItem * item, WMAction * action, void *data)
116 item->action = action;
117 item->data = data;
120 WMAction *WMGetMenuItemAction(WMMenuItem * item)
122 return item->action;
125 void *WMGetMenuItemData(WMMenuItem * item)
127 return item->data;
130 void WMSetMenuItemTitle(WMMenuItem * item, const char *title)
132 if (item->title)
133 wfree(item->title);
135 if (title)
136 item->title = wstrdup(title);
137 else
138 item->title = NULL;
141 char *WMGetMenuItemTitle(WMMenuItem * item)
143 return item->title;
146 void WMSetMenuItemState(WMMenuItem * item, int state)
148 item->flags.state = state;
151 int WMGetMenuItemState(WMMenuItem * item)
153 return item->flags.state;
156 void WMSetMenuItemPixmap(WMMenuItem * item, WMPixmap * pixmap)
158 if (item->image)
159 WMReleasePixmap(item->image);
161 item->image = WMRetainPixmap(pixmap);
164 WMPixmap *WMGetMenuItemPixmap(WMMenuItem * item)
166 return item->image;
169 void WMSetMenuItemOnStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
171 if (item->onStateImage)
172 WMReleasePixmap(item->onStateImage);
174 item->onStateImage = WMRetainPixmap(pixmap);
177 WMPixmap *WMGetMenuItemOnStatePixmap(WMMenuItem * item)
179 return item->onStateImage;
182 void WMSetMenuItemOffStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
184 if (item->offStateImage)
185 WMReleasePixmap(item->offStateImage);
187 item->offStateImage = WMRetainPixmap(pixmap);
190 WMPixmap *WMGetMenuItemOffStatePixmap(WMMenuItem * item)
192 return item->offStateImage;
195 void WMSetMenuItemMixedStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
197 if (item->mixedStateImage)
198 WMReleasePixmap(item->mixedStateImage);
200 item->mixedStateImage = WMRetainPixmap(pixmap);
203 WMPixmap *WMGetMenuItemMixedStatePixmap(WMMenuItem * item)
205 return item->mixedStateImage;
208 #if 0
209 void WMSetMenuItemSubmenu(WMMenuItem * item, WMMenu * submenu)
211 item->submenu = submenu;
214 WMMenu *WMGetMenuItemSubmenu(WMMenuItem * item)
216 return item->submenu;
219 Bool WMGetMenuItemHasSubmenu(WMMenuItem * item)
221 return item->submenu != NULL;
223 #endif