2 * AxWin3 Interface Library
3 * - By John Hodge (thePowersGang)
6 * - Menu renderer interface
9 #include <axwin3/axwin.h>
10 #include <axwin3/menu.h>
11 #include <menu_messages.h>
12 #include "include/internal.h"
16 typedef struct sMenuWindowInfo tMenuWindowInfo;
18 struct sAxWin3_MenuItem
22 tAxWin3_Menu_Callback Callback;
27 struct sMenuWindowInfo
30 tAxWin3_MenuItem *Items;
34 int AxWin3_Menu_int_Callback(tHWND Window, int Message, int Length, void *Data)
36 tMenuWindowInfo *info = AxWin3_int_GetDataPtr(Window);
39 case MSG_MENU_SELECT: {
40 tMenuMsg_Select *msg = Data;
41 tAxWin3_MenuItem *item;
42 if(Length < sizeof(tMenuMsg_Select)) return -1;
43 if(msg->ID >= info->nItems) return -1;
44 item = &info->Items[msg->ID];
45 if(item->Callback) item->Callback(item->CbPtr);
51 tHWND AxWin3_Menu_Create(tHWND Parent)
54 tMenuWindowInfo *info;
56 ret = AxWin3_CreateWindow(Parent, "Menu", 0, sizeof(*info), AxWin3_Menu_int_Callback);
59 info = AxWin3_int_GetDataPtr(ret);
66 void AxWin3_Menu_ShowAt(tHWND Menu, int X, int Y)
68 AxWin3_MoveWindow(Menu, X, Y);
69 AxWin3_ShowWindow(Menu, 1);
70 AxWin3_FocusWindow(Menu);
73 tAxWin3_MenuItem *AxWin3_Menu_AddItem(
74 tHWND Menu, const char *Label,
75 tAxWin3_Menu_Callback Cb, void *Ptr,
76 int Flags, tHWND SubMenu
79 tMenuWindowInfo *info;
80 tAxWin3_MenuItem *ret;
82 info = AxWin3_int_GetDataPtr(Menu);
85 info->Items = realloc(info->Items, sizeof(*info->Items)*info->nItems);
87 _SysDebug("ERROR: Realloc Failed");
91 ret = &info->Items[info->nItems-1];
92 ret->ID = info->nItems - 1;
96 ret->SubMenu = SubMenu;
99 tMenuMsg_AddItem *req;
101 if(!Label) Label = "";
102 data_size = sizeof(*req)+strlen(Label)+1;
103 req = malloc(data_size);
106 req->SubMenuID = AxWin3_int_GetWindowID(SubMenu);
107 strcpy(req->Label, Label);
108 AxWin3_SendMessage(Menu, Menu, MSG_MENU_ADDITEM, data_size, req);