Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wmenuitem.c
bloba9568614b5e6ef71b59c319286b7603e907c0865
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));
44 memset(item, 0, sizeof(MenuItem));
46 item->flags.enabled = 1;
48 return item;
51 void WMDestroyMenuItem(WMMenuItem * item)
53 if (item->title)
54 wfree(item->title);
56 if (item->image)
57 WMReleasePixmap(item->image);
59 if (item->shortcutKey)
60 wfree(item->shortcutKey);
62 if (item->onStateImage)
63 WMReleasePixmap(item->onStateImage);
65 if (item->offStateImage)
66 WMReleasePixmap(item->offStateImage);
68 if (item->mixedStateImage)
69 WMReleasePixmap(item->mixedStateImage);
72 Bool WMGetMenuItemEnabled(WMMenuItem * item)
74 return item->flags.enabled;
77 void WMSetMenuItemEnabled(WMMenuItem * item, Bool flag)
79 item->flags.enabled = ((flag == 0) ? 0 : 1);
82 char *WMGetMenuItemShortcut(WMMenuItem * item)
84 return item->shortcutKey;
87 unsigned WMGetMenuItemShortcutModifierMask(WMMenuItem * item)
89 return item->shortcutModifierMask;
92 void WMSetMenuItemShortcut(WMMenuItem * item, char *shortcut)
94 if (item->shortcutKey)
95 wfree(item->shortcutKey);
97 item->shortcutKey = wstrdup(shortcut);
100 void WMSetMenuItemShortcutModifierMask(WMMenuItem * item, unsigned mask)
102 item->shortcutModifierMask = mask;
105 void *WMGetMenuItemRepresentedObject(WMMenuItem * item)
107 return item->object;
110 void WMSetMenuItemRepresentedObject(WMMenuItem * item, void *object)
112 item->object = object;
115 void WMSetMenuItemAction(WMMenuItem * item, WMAction * action, void *data)
117 item->action = action;
118 item->data = data;
121 WMAction *WMGetMenuItemAction(WMMenuItem * item)
123 return item->action;
126 void *WMGetMenuItemData(WMMenuItem * item)
128 return item->data;
131 void WMSetMenuItemTitle(WMMenuItem * item, char *title)
133 if (item->title)
134 wfree(item->title);
136 if (title)
137 item->title = wstrdup(title);
138 else
139 item->title = NULL;
142 char *WMGetMenuItemTitle(WMMenuItem * item)
144 return item->title;
147 void WMSetMenuItemState(WMMenuItem * item, int state)
149 item->flags.state = state;
152 int WMGetMenuItemState(WMMenuItem * item)
154 return item->flags.state;
157 void WMSetMenuItemPixmap(WMMenuItem * item, WMPixmap * pixmap)
159 if (item->image)
160 WMReleasePixmap(item->image);
162 item->image = WMRetainPixmap(pixmap);
165 WMPixmap *WMGetMenuItemPixmap(WMMenuItem * item)
167 return item->image;
170 void WMSetMenuItemOnStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
172 if (item->onStateImage)
173 WMReleasePixmap(item->onStateImage);
175 item->onStateImage = WMRetainPixmap(pixmap);
178 WMPixmap *WMGetMenuItemOnStatePixmap(WMMenuItem * item)
180 return item->onStateImage;
183 void WMSetMenuItemOffStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
185 if (item->offStateImage)
186 WMReleasePixmap(item->offStateImage);
188 item->offStateImage = WMRetainPixmap(pixmap);
191 WMPixmap *WMGetMenuItemOffStatePixmap(WMMenuItem * item)
193 return item->offStateImage;
196 void WMSetMenuItemMixedStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
198 if (item->mixedStateImage)
199 WMReleasePixmap(item->mixedStateImage);
201 item->mixedStateImage = WMRetainPixmap(pixmap);
204 WMPixmap *WMGetMenuItemMixedStatePixmap(WMMenuItem * item)
206 return item->mixedStateImage;
209 #if 0
210 void WMSetMenuItemSubmenu(WMMenuItem * item, WMMenu * submenu)
212 item->submenu = submenu;
215 WMMenu *WMGetMenuItemSubmenu(WMMenuItem * item)
217 return item->submenu;
220 Bool WMGetMenuItemHasSubmenu(WMMenuItem * item)
222 return item->submenu != NULL;
224 #endif