2 * AxWin3 Interface Library
3 * - By John Hodge (thePowersGang)
6 * - Entrypoint and setup
8 #include <axwin3/axwin.h>
9 #include <axwin3/widget.h>
10 #include "include/internal.h"
12 #include <widget_messages.h>
20 tAxWin3_Widget_Callback Callback;
26 tAxWin3_Widget **Elements;
28 tAxWin3_Widget RootElement;
29 // Callbacks for each element
33 int AxWin3_Widget_MessageHandler(tHWND Window, int Size, void *Data)
38 tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags)
41 tWidgetWindowInfo *info;
43 ret = AxWin3_CreateWindow(
44 Parent, "Widget", RootEleFlags,
45 sizeof(*info) + sizeof(tAxWin3_Widget), AxWin3_Widget_MessageHandler
47 info = AxWin3_int_GetDataPtr(ret);
49 info->RootElement.Window = ret;
50 info->RootElement.ID = -1;
52 AxWin3_ResizeWindow(ret, W, H);
57 void AxWin3_Widget_DestroyWindow(tHWND Window)
59 // Free all element structures
63 // Request window to be destroyed (will clean up any data stored in tHWND)
66 tAxWin3_Widget *AxWin3_Widget_GetRoot(tHWND Window)
68 tWidgetWindowInfo *info = AxWin3_int_GetDataPtr(Window);
69 return &info->RootElement;
72 tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Flags, const char *DebugName)
75 tWidgetWindowInfo *info;
78 if(!Parent) return NULL;
80 info = AxWin3_int_GetDataPtr(Parent->Window);
83 // BUG BUG BUG - Double Allocations!
85 for( newID = info->FirstFreeID; newID < info->nElements; newID ++ )
87 if( info->Elements[newID] == NULL )
90 if( newID == info->nElements )
93 info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements);
94 newID = info->nElements - 1;
95 _SysDebug("Expanded and allocated %i", newID);
98 _SysDebug("Allocated %i", newID);
99 info->Elements[newID] = (void*)-1;
101 // Create new widget structure
102 ret = malloc(sizeof(tAxWin3_Widget));
103 ret->Window = Parent->Window;
105 ret->Callback = NULL;
107 info->Elements[newID] = ret;
109 // Send create widget message
111 char tmp[sizeof(tWidgetMsg_Create)+1];
112 tWidgetMsg_Create *msg = (void*)tmp;
113 msg->Parent = Parent->ID;
117 msg->DebugName[0] = '\0';
118 AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATE, sizeof(tmp), tmp);
124 void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget)
126 tWidgetMsg_Delete msg;
127 tWidgetWindowInfo *info = AxWin3_int_GetDataPtr(Widget->Window);
129 msg.WidgetID = Widget->ID;
130 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_DELETE, sizeof(msg), &msg);
132 info->Elements[Widget->ID] = NULL;
133 if(Widget->ID < info->FirstFreeID)
134 info->FirstFreeID = Widget->ID;
138 void AxWin3_Widget_SetFlags(tAxWin3_Widget *Widget, int FlagSet, int FlagMask)
140 tWidgetMsg_SetFlags msg;
141 msg.WidgetID = Widget->ID;
145 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETFLAGS, sizeof(msg), &msg);
148 void AxWin3_Widget_SetSize(tAxWin3_Widget *Widget, int Size)
150 tWidgetMsg_SetSize msg;
152 msg.WidgetID = Widget->ID;
154 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETSIZE, sizeof(msg), &msg);
157 void AxWin3_Widget_SetText(tAxWin3_Widget *Widget, const char *Text)
159 char buf[sizeof(tWidgetMsg_SetText) + strlen(Text) + 1];
160 tWidgetMsg_SetText *msg = (void*)buf;
162 msg->WidgetID = Widget->ID;
163 strcpy(msg->Text, Text);
165 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETTEXT, sizeof(buf), buf);
168 void AxWin3_Widget_SetColour(tAxWin3_Widget *Widget, int Index, tAxWin3_Colour Colour)
170 tWidgetMsg_SetColour msg;
172 msg.WidgetID = Widget->ID;
175 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETCOLOUR, sizeof(msg), &msg);