fixed bug in repainting empty popup buttons
[wmaker-crm.git] / WINGs / wmenuitem.c
blob3007faf6db12f3ab876d179dde3337b3d6ee3ad7
5 #include "WINGsP.h"
9 typedef struct W_MenuItem {
10 char *title;
12 WMPixmap *image;
14 char *shortcutKey;
15 int shortcutModifierMask;
17 WMAction *action;
18 void *data;
20 struct W_Menu *submenu;
22 void *object;
24 WMPixmap *onStateImage;
25 WMPixmap *offStateImage;
26 WMPixmap *mixedStateImage;
28 struct {
29 unsigned enabled:1;
30 unsigned state:2;
31 } flags;
32 } MenuItem;
38 WMMenuItem*
39 WMGetSeparatorMenuItem(void)
41 return NULL;
45 Bool
46 WMMenuItemIsSeparator(WMMenuItem *item)
48 return False;
52 WMMenuItem*
53 WMCreateMenuItem(void)
55 WMMenuItem *item;
57 item = wmalloc(sizeof(WMMenuItem));
58 memset(item, 0, sizeof(WMMenuItem));
60 item->flags.enabled = 1;
62 return item;
66 void
67 WMDestroyMenuItem(WMMenuItem *item)
69 if (item->title)
70 free(item->title);
72 if (item->image)
73 WMReleasePixmap(item->image);
75 if (item->shortcutKey)
76 free(item->shortcutKey);
78 if (item->onStateImage)
79 WMReleasePixmap(item->onStateImage);
81 if (item->offStateImage)
82 WMReleasePixmap(item->offStateImage);
84 if (item->mixedStateImage)
85 WMReleasePixmap(item->mixedStateImage);
89 Bool
90 WMGetMenuItemEnabled(WMMenuItem *item)
92 return item->flags.enabled;
96 void
97 WMSetMenuItemEnabled(WMMenuItem *item, Bool flag)
99 item->flags.enabled = flag;
103 char*
104 WMGetMenuItemShortcut(WMMenuItem *item)
106 return item->shortcutKey;
110 unsigned
111 WMGetMenuItemShortcutModifierMask(WMMenuItem *item)
113 return item->shortcutModifierMask;
118 void
119 WMSetMenuItemShortcut(WMMenuItem *item, char *shortcut)
121 if (item->shortcutKey)
122 wfree(item->shortcutKey);
124 item->shortcutKey = wstrdup(shortcut);
128 void
129 WMSetMenuItemShortcutModifierMask(WMMenuItem *item, unsigned mask)
131 item->shortcutModifierMask = mask;
135 void*
136 WMGetMenuItemRepresentedObject(WMMenuItem *item)
138 return item->object;
142 void
143 WMSetMenuItemRepresentedObject(WMMenuItem *item, void *object)
145 item->object = object;
149 void
150 WMSetMenuItemAction(WMMenuItem *item, WMAction *action, void *data)
152 item->action = action;
153 item->data = data;
157 WMAction*
158 WMGetMenuItemAction(WMMenuItem *item)
160 return item->action;
164 void*
165 WMGetMenuItemData(WMMenuItem *item)
167 return item->data;
171 void
172 WMSetMenuItemTitle(WMMenuItem *item, char *title)
174 if (item->title)
175 wfree(item->title);
177 if (title)
178 item->title = wstrdup(title);
179 else
180 item->title = NULL;
184 char*
185 WMGetMenuItemTitle(WMMenuItem *item)
187 return item->title;
191 void
192 WMSetMenuItemState(WMMenuItem *item, int state)
194 item->flags.state = state;
199 WMGetMenuItemState(WMMenuItem *item)
201 return item->flags.state;
205 void
206 WMSetMenuItemPixmap(WMMenuItem *item, WMPixmap *pixmap)
208 if (item->image)
209 WMReleasePixmap(item->image);
211 item->image = WMRetainPixmap(pixmap);
215 WMPixmap*
216 WMGetMenuItemPixmap(WMMenuItem *item)
218 return item->image;
222 void
223 WMSetMenuItemOnStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
225 if (item->onStateImage)
226 WMReleasePixmap(item->onStateImage);
228 item->onStateImage = WMRetainPixmap(pixmap);
232 WMPixmap*
233 WMGetMenuItemOnStatePixmap(WMMenuItem *item)
235 return item->onStateImage;
239 void
240 WMSetMenuItemOffStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
242 if (item->offStateImage)
243 WMReleasePixmap(item->offStateImage);
245 item->offStateImage = WMRetainPixmap(pixmap);
249 WMPixmap*
250 WMGetMenuItemOffStatePixmap(WMMenuItem *item)
252 return item->offStateImage;
257 void
258 WMSetMenuItemMixedStatePixmap(WMMenuItem *item, WMPixmap *pixmap)
260 if (item->mixedStateImage)
261 WMReleasePixmap(item->mixedStateImage);
263 item->mixedStateImage = WMRetainPixmap(pixmap);
267 WMPixmap*
268 WMGetMenuItemMixedStatePixmap(WMMenuItem *item)
270 return item->mixedStateImage;
275 void
276 WMSetMenuItemSubmenu(WMMenuItem *item, WMMenu *submenu)
278 item->submenu = submenu;
282 WMMenu*
283 WMGetMenuItemSubmenu(WMMenuItem *item)
285 return item->submenu;
290 Bool
291 WMGetMenuItemHasSubmenu(WMMenuItem *item)
293 return item->submenu != NULL;