Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wmenuitem.c
Commit [+]AuthorDateLineData
0faaf3fa kojima1999-10-20 03:33:19 +00001
0faaf3fa kojima1999-10-20 03:33:19 +00002#include "WINGsP.h"
3
0faaf3fa kojima1999-10-20 03:33:19 +00004typedef struct W_MenuItem {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02005 char *title;
0faaf3fa kojima1999-10-20 03:33:19 +00006
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02007 WMPixmap *image;
0faaf3fa kojima1999-10-20 03:33:19 +00008
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02009 char *shortcutKey;
10 int shortcutModifierMask;
0faaf3fa kojima1999-10-20 03:33:19 +000011
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020012 WMAction *action;
13 void *data;
0faaf3fa kojima1999-10-20 03:33:19 +000014
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020015 struct W_Menu *submenu;
0faaf3fa kojima1999-10-20 03:33:19 +000016
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020017 void *object;
6830b057 dan2004-10-12 21:28:27 +000018
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020019 WMPixmap *onStateImage;
20 WMPixmap *offStateImage;
21 WMPixmap *mixedStateImage;
0faaf3fa kojima1999-10-20 03:33:19 +000022
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020023 struct {
24 unsigned enabled:1;
25 unsigned state:2;
26 } flags;
0faaf3fa kojima1999-10-20 03:33:19 +000027} MenuItem;
28
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020029WMMenuItem *WMGetSeparatorMenuItem(void)
0faaf3fa kojima1999-10-20 03:33:19 +000030{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020031 return NULL;
0faaf3fa kojima1999-10-20 03:33:19 +000032}
33
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034Bool WMMenuItemIsSeparator(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +000035{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020036 return False;
0faaf3fa kojima1999-10-20 03:33:19 +000037}
38
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020039WMMenuItem *WMCreateMenuItem(void)
0faaf3fa kojima1999-10-20 03:33:19 +000040{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020041 WMMenuItem *item;
6830b057 dan2004-10-12 21:28:27 +000042
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020043 item = wmalloc(sizeof(MenuItem));
44 memset(item, 0, sizeof(MenuItem));
0faaf3fa kojima1999-10-20 03:33:19 +000045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020046 item->flags.enabled = 1;
6830b057 dan2004-10-12 21:28:27 +000047
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020048 return item;
0faaf3fa kojima1999-10-20 03:33:19 +000049}
50
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020051void WMDestroyMenuItem(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +000052{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020053 if (item->title)
54 wfree(item->title);
0faaf3fa kojima1999-10-20 03:33:19 +000055
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020056 if (item->image)
57 WMReleasePixmap(item->image);
0faaf3fa kojima1999-10-20 03:33:19 +000058
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020059 if (item->shortcutKey)
60 wfree(item->shortcutKey);
6830b057 dan2004-10-12 21:28:27 +000061
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020062 if (item->onStateImage)
63 WMReleasePixmap(item->onStateImage);
6830b057 dan2004-10-12 21:28:27 +000064
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 if (item->offStateImage)
66 WMReleasePixmap(item->offStateImage);
6830b057 dan2004-10-12 21:28:27 +000067
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020068 if (item->mixedStateImage)
69 WMReleasePixmap(item->mixedStateImage);
0faaf3fa kojima1999-10-20 03:33:19 +000070}
71
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020072Bool WMGetMenuItemEnabled(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +000073{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020074 return item->flags.enabled;
0faaf3fa kojima1999-10-20 03:33:19 +000075}
76
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020077void WMSetMenuItemEnabled(WMMenuItem * item, Bool flag)
0faaf3fa kojima1999-10-20 03:33:19 +000078{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020079 item->flags.enabled = ((flag == 0) ? 0 : 1);
0faaf3fa kojima1999-10-20 03:33:19 +000080}
81
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020082char *WMGetMenuItemShortcut(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +000083{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020084 return item->shortcutKey;
0faaf3fa kojima1999-10-20 03:33:19 +000085}
86
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020087unsigned WMGetMenuItemShortcutModifierMask(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +000088{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020089 return item->shortcutModifierMask;
0faaf3fa kojima1999-10-20 03:33:19 +000090}
91
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020092void WMSetMenuItemShortcut(WMMenuItem * item, char *shortcut)
0faaf3fa kojima1999-10-20 03:33:19 +000093{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020094 if (item->shortcutKey)
95 wfree(item->shortcutKey);
0faaf3fa kojima1999-10-20 03:33:19 +000096
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020097 item->shortcutKey = wstrdup(shortcut);
0faaf3fa kojima1999-10-20 03:33:19 +000098}
99
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200100void WMSetMenuItemShortcutModifierMask(WMMenuItem * item, unsigned mask)
0faaf3fa kojima1999-10-20 03:33:19 +0000101{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200102 item->shortcutModifierMask = mask;
0faaf3fa kojima1999-10-20 03:33:19 +0000103}
104
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200105void *WMGetMenuItemRepresentedObject(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000106{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200107 return item->object;
0faaf3fa kojima1999-10-20 03:33:19 +0000108}
109
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200110void WMSetMenuItemRepresentedObject(WMMenuItem * item, void *object)
0faaf3fa kojima1999-10-20 03:33:19 +0000111{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200112 item->object = object;
0faaf3fa kojima1999-10-20 03:33:19 +0000113}
114
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200115void WMSetMenuItemAction(WMMenuItem * item, WMAction * action, void *data)
0faaf3fa kojima1999-10-20 03:33:19 +0000116{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200117 item->action = action;
118 item->data = data;
0faaf3fa kojima1999-10-20 03:33:19 +0000119}
120
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200121WMAction *WMGetMenuItemAction(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000122{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 return item->action;
0faaf3fa kojima1999-10-20 03:33:19 +0000124}
125
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200126void *WMGetMenuItemData(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000127{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200128 return item->data;
0faaf3fa kojima1999-10-20 03:33:19 +0000129}
130
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200131void WMSetMenuItemTitle(WMMenuItem * item, char *title)
0faaf3fa kojima1999-10-20 03:33:19 +0000132{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200133 if (item->title)
134 wfree(item->title);
6830b057 dan2004-10-12 21:28:27 +0000135
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200136 if (title)
137 item->title = wstrdup(title);
138 else
139 item->title = NULL;
0faaf3fa kojima1999-10-20 03:33:19 +0000140}
141
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200142char *WMGetMenuItemTitle(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000143{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200144 return item->title;
0faaf3fa kojima1999-10-20 03:33:19 +0000145}
146
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200147void WMSetMenuItemState(WMMenuItem * item, int state)
0faaf3fa kojima1999-10-20 03:33:19 +0000148{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200149 item->flags.state = state;
0faaf3fa kojima1999-10-20 03:33:19 +0000150}
151
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200152int WMGetMenuItemState(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000153{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200154 return item->flags.state;
0faaf3fa kojima1999-10-20 03:33:19 +0000155}
156
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200157void WMSetMenuItemPixmap(WMMenuItem * item, WMPixmap * pixmap)
0faaf3fa kojima1999-10-20 03:33:19 +0000158{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200159 if (item->image)
160 WMReleasePixmap(item->image);
0faaf3fa kojima1999-10-20 03:33:19 +0000161
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200162 item->image = WMRetainPixmap(pixmap);
0faaf3fa kojima1999-10-20 03:33:19 +0000163}
164
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200165WMPixmap *WMGetMenuItemPixmap(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000166{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200167 return item->image;
0faaf3fa kojima1999-10-20 03:33:19 +0000168}
169
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200170void WMSetMenuItemOnStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
0faaf3fa kojima1999-10-20 03:33:19 +0000171{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172 if (item->onStateImage)
173 WMReleasePixmap(item->onStateImage);
6830b057 dan2004-10-12 21:28:27 +0000174
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200175 item->onStateImage = WMRetainPixmap(pixmap);
0faaf3fa kojima1999-10-20 03:33:19 +0000176}
177
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200178WMPixmap *WMGetMenuItemOnStatePixmap(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000179{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200180 return item->onStateImage;
0faaf3fa kojima1999-10-20 03:33:19 +0000181}
182
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200183void WMSetMenuItemOffStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
0faaf3fa kojima1999-10-20 03:33:19 +0000184{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200185 if (item->offStateImage)
186 WMReleasePixmap(item->offStateImage);
6830b057 dan2004-10-12 21:28:27 +0000187
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200188 item->offStateImage = WMRetainPixmap(pixmap);
0faaf3fa kojima1999-10-20 03:33:19 +0000189}
190
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200191WMPixmap *WMGetMenuItemOffStatePixmap(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000192{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200193 return item->offStateImage;
0faaf3fa kojima1999-10-20 03:33:19 +0000194}
195
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200196void WMSetMenuItemMixedStatePixmap(WMMenuItem * item, WMPixmap * pixmap)
0faaf3fa kojima1999-10-20 03:33:19 +0000197{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200198 if (item->mixedStateImage)
199 WMReleasePixmap(item->mixedStateImage);
6830b057 dan2004-10-12 21:28:27 +0000200
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200201 item->mixedStateImage = WMRetainPixmap(pixmap);
0faaf3fa kojima1999-10-20 03:33:19 +0000202}
203
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200204WMPixmap *WMGetMenuItemMixedStatePixmap(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000205{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200206 return item->mixedStateImage;
0faaf3fa kojima1999-10-20 03:33:19 +0000207}
208
6830b057 dan2004-10-12 21:28:27 +0000209#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200210void WMSetMenuItemSubmenu(WMMenuItem * item, WMMenu * submenu)
0faaf3fa kojima1999-10-20 03:33:19 +0000211{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200212 item->submenu = submenu;
0faaf3fa kojima1999-10-20 03:33:19 +0000213}
214
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200215WMMenu *WMGetMenuItemSubmenu(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000216{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200217 return item->submenu;
0faaf3fa kojima1999-10-20 03:33:19 +0000218}
219
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200220Bool WMGetMenuItemHasSubmenu(WMMenuItem * item)
0faaf3fa kojima1999-10-20 03:33:19 +0000221{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200222 return item->submenu != NULL;
0faaf3fa kojima1999-10-20 03:33:19 +0000223}
6830b057 dan2004-10-12 21:28:27 +0000224#endif