Fixes missing appicons after restarting Window Maker
[wmaker-crm.git] / WINGs / wmenuitem.c
blobac813c5bd8b397d7509556e98604b8969797e402
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 /* Parameter not used, but tell the compiler that it is ok */
37 (void) item;
39 return False;
42 WMMenuItem *WMCreateMenuItem(void)
44 WMMenuItem *item;
46 item = wmalloc(sizeof(MenuItem));
48 item->flags.enabled = 1;
50 return item;
53 void WMDestroyMenuItem(WMMenuItem * item)
55 if (item->title)
56 wfree(item->title);
58 if (item->image)
59 WMReleasePixmap(item->image);
61 if (item->shortcutKey)
62 wfree(item->shortcutKey);
64 if (item->onStateImage)
65 WMReleasePixmap(item->onStateImage);
67 if (item->offStateImage)
68 WMReleasePixmap(item->offStateImage);
70 if (item->mixedStateImage)
71 WMReleasePixmap(item->mixedStateImage);
74 Bool WMGetMenuItemEnabled(WMMenuItem * item)
76 return item->flags.enabled;
79 void WMSetMenuItemEnabled(WMMenuItem * item, Bool flag)
81 item->flags.enabled = ((flag == 0) ? 0 : 1);
84 char *WMGetMenuItemShortcut(WMMenuItem * item)
86 return item->shortcutKey;
89 unsigned WMGetMenuItemShortcutModifierMask(WMMenuItem * item)
91 return item->shortcutModifierMask;
94 void WMSetMenuItemShortcut(WMMenuItem * item, const char *shortcut)
96 if (item->shortcutKey)
97 wfree(item->shortcutKey);
99 item->shortcutKey = wstrdup(shortcut);
102 void WMSetMenuItemShortcutModifierMask(WMMenuItem * item, unsigned mask)
104 item->shortcutModifierMask = mask;
107 void *WMGetMenuItemRepresentedObject(WMMenuItem * item)
109 return item->object;
112 void WMSetMenuItemRepresentedObject(WMMenuItem * item, void *object)
114 item->object = object;
117 void WMSetMenuItemAction(WMMenuItem * item, WMAction * action, void *data)
119 item->action = action;
120 item->data = data;
123 WMAction *WMGetMenuItemAction(WMMenuItem * item)
125 return item->action;
128 void *WMGetMenuItemData(WMMenuItem * item)
130 return item->data;
133 void WMSetMenuItemTitle(WMMenuItem * item, const char *title)
135 if (item->title)
136 wfree(item->title);
138 if (title)
139 item->title = wstrdup(title);
140 else
141 item->title = NULL;
144 char *WMGetMenuItemTitle(WMMenuItem * item)
146 return item->title;
149 void WMSetMenuItemState(WMMenuItem * item, int state)
151 item->flags.state = state;
154 int WMGetMenuItemState(WMMenuItem * item)
156 return item->flags.state;
159 void WMSetMenuItemPixmap(WMMenuItem * item, WMPixmap * pixmap)
161 if (item->image)
162 WMReleasePixmap(item->image);
164 item->image = WMRetainPixmap(pixmap);
167 WMPixmap *WMGetMenuItemPixmap(WMMenuItem * item)
169 return item->image;
172 void WMSetMenuItemOnStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
174 if (item->onStateImage)
175 WMReleasePixmap(item->onStateImage);
177 item->onStateImage = WMRetainPixmap(pixmap);
180 WMPixmap *WMGetMenuItemOnStatePixmap(WMMenuItem * item)
182 return item->onStateImage;
185 void WMSetMenuItemOffStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
187 if (item->offStateImage)
188 WMReleasePixmap(item->offStateImage);
190 item->offStateImage = WMRetainPixmap(pixmap);
193 WMPixmap *WMGetMenuItemOffStatePixmap(WMMenuItem * item)
195 return item->offStateImage;
198 void WMSetMenuItemMixedStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
200 if (item->mixedStateImage)
201 WMReleasePixmap(item->mixedStateImage);
203 item->mixedStateImage = WMRetainPixmap(pixmap);
206 WMPixmap *WMGetMenuItemMixedStatePixmap(WMMenuItem * item)
208 return item->mixedStateImage;
211 #if 0
212 void WMSetMenuItemSubmenu(WMMenuItem * item, WMMenu * submenu)
214 item->submenu = submenu;
217 WMMenu *WMGetMenuItemSubmenu(WMMenuItem * item)
219 return item->submenu;
222 Bool WMGetMenuItemHasSubmenu(WMMenuItem * item)
224 return item->submenu != NULL;
226 #endif