Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wmenuitem.c
1
2 #include "WINGsP.h"
3
4 typedef struct W_MenuItem {
5         char *title;
6
7         WMPixmap *image;
8
9         char *shortcutKey;
10         int shortcutModifierMask;
11
12         WMAction *action;
13         void *data;
14
15         struct W_Menu *submenu;
16
17         void *object;
18
19         WMPixmap *onStateImage;
20         WMPixmap *offStateImage;
21         WMPixmap *mixedStateImage;
22
23         struct {
24                 unsigned enabled:1;
25                 unsigned state:2;
26         } flags;
27 } MenuItem;
28
29 WMMenuItem *WMGetSeparatorMenuItem(void)
30 {
31         return NULL;
32 }
33
34 Bool WMMenuItemIsSeparator(WMMenuItem * item)
35 {
36         return False;
37 }
38
39 WMMenuItem *WMCreateMenuItem(void)
40 {
41         WMMenuItem *item;
42
43         item = wmalloc(sizeof(MenuItem));
44         memset(item, 0, sizeof(MenuItem));
45
46         item->flags.enabled = 1;
47
48         return item;
49 }
50
51 void WMDestroyMenuItem(WMMenuItem * item)
52 {
53         if (item->title)
54                 wfree(item->title);
55
56         if (item->image)
57                 WMReleasePixmap(item->image);
58
59         if (item->shortcutKey)
60                 wfree(item->shortcutKey);
61
62         if (item->onStateImage)
63                 WMReleasePixmap(item->onStateImage);
64
65         if (item->offStateImage)
66                 WMReleasePixmap(item->offStateImage);
67
68         if (item->mixedStateImage)
69                 WMReleasePixmap(item->mixedStateImage);
70 }
71
72 Bool WMGetMenuItemEnabled(WMMenuItem * item)
73 {
74         return item->flags.enabled;
75 }
76
77 void WMSetMenuItemEnabled(WMMenuItem * item, Bool flag)
78 {
79         item->flags.enabled = ((flag == 0) ? 0 : 1);
80 }
81
82 char *WMGetMenuItemShortcut(WMMenuItem * item)
83 {
84         return item->shortcutKey;
85 }
86
87 unsigned WMGetMenuItemShortcutModifierMask(WMMenuItem * item)
88 {
89         return item->shortcutModifierMask;
90 }
91
92 void WMSetMenuItemShortcut(WMMenuItem * item, char *shortcut)
93 {
94         if (item->shortcutKey)
95                 wfree(item->shortcutKey);
96
97         item->shortcutKey = wstrdup(shortcut);
98 }
99
100 void WMSetMenuItemShortcutModifierMask(WMMenuItem * item, unsigned mask)
101 {
102         item->shortcutModifierMask = mask;
103 }
104
105 void *WMGetMenuItemRepresentedObject(WMMenuItem * item)
106 {
107         return item->object;
108 }
109
110 void WMSetMenuItemRepresentedObject(WMMenuItem * item, void *object)
111 {
112         item->object = object;
113 }
114
115 void WMSetMenuItemAction(WMMenuItem * item, WMAction * action, void *data)
116 {
117         item->action = action;
118         item->data = data;
119 }
120
121 WMAction *WMGetMenuItemAction(WMMenuItem * item)
122 {
123         return item->action;
124 }
125
126 void *WMGetMenuItemData(WMMenuItem * item)
127 {
128         return item->data;
129 }
130
131 void WMSetMenuItemTitle(WMMenuItem * item, char *title)
132 {
133         if (item->title)
134                 wfree(item->title);
135
136         if (title)
137                 item->title = wstrdup(title);
138         else
139                 item->title = NULL;
140 }
141
142 char *WMGetMenuItemTitle(WMMenuItem * item)
143 {
144         return item->title;
145 }
146
147 void WMSetMenuItemState(WMMenuItem * item, int state)
148 {
149         item->flags.state = state;
150 }
151
152 int WMGetMenuItemState(WMMenuItem * item)
153 {
154         return item->flags.state;
155 }
156
157 void WMSetMenuItemPixmap(WMMenuItem * item, WMPixmap * pixmap)
158 {
159         if (item->image)
160                 WMReleasePixmap(item->image);
161
162         item->image = WMRetainPixmap(pixmap);
163 }
164
165 WMPixmap *WMGetMenuItemPixmap(WMMenuItem * item)
166 {
167         return item->image;
168 }
169
170 void WMSetMenuItemOnStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
171 {
172         if (item->onStateImage)
173                 WMReleasePixmap(item->onStateImage);
174
175         item->onStateImage = WMRetainPixmap(pixmap);
176 }
177
178 WMPixmap *WMGetMenuItemOnStatePixmap(WMMenuItem * item)
179 {
180         return item->onStateImage;
181 }
182
183 void WMSetMenuItemOffStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
184 {
185         if (item->offStateImage)
186                 WMReleasePixmap(item->offStateImage);
187
188         item->offStateImage = WMRetainPixmap(pixmap);
189 }
190
191 WMPixmap *WMGetMenuItemOffStatePixmap(WMMenuItem * item)
192 {
193         return item->offStateImage;
194 }
195
196 void WMSetMenuItemMixedStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
197 {
198         if (item->mixedStateImage)
199                 WMReleasePixmap(item->mixedStateImage);
200
201         item->mixedStateImage = WMRetainPixmap(pixmap);
202 }
203
204 WMPixmap *WMGetMenuItemMixedStatePixmap(WMMenuItem * item)
205 {
206         return item->mixedStateImage;
207 }
208
209 #if 0
210 void WMSetMenuItemSubmenu(WMMenuItem * item, WMMenu * submenu)
211 {
212         item->submenu = submenu;
213 }
214
215 WMMenu *WMGetMenuItemSubmenu(WMMenuItem * item)
216 {
217         return item->submenu;
218 }
219
220 Bool WMGetMenuItemHasSubmenu(WMMenuItem * item)
221 {
222         return item->submenu != NULL;
223 }
224 #endif