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);
84 for( newID = info->FirstFreeID; newID < info->nElements; newID ++ )
86 if( info->Elements[newID] == NULL )
89 if( info->nElements == 0 || info->Elements[newID] )
92 info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements);
93 newID = info->nElements - 1;
95 info->Elements[newID] = (void*)-1;
97 // Create new widget structure
98 ret = malloc(sizeof(tAxWin3_Widget));
99 ret->Window = Parent->Window;
101 ret->Callback = NULL;
103 info->Elements[newID] = ret;
105 // Send create widget message
107 char tmp[sizeof(tWidgetMsg_Create)+1];
108 tWidgetMsg_Create *msg = (void*)tmp;
109 msg->Parent = Parent->ID;
111 msg->DebugName[0] = '\0';
112 AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATE, sizeof(tmp), tmp);
118 void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget)
120 tWidgetMsg_Delete msg;
121 tWidgetWindowInfo *info = AxWin3_int_GetDataPtr(Widget->Window);
123 msg.WidgetID = Widget->ID;
124 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_DELETE, sizeof(msg), &msg);
126 info->Elements[Widget->ID] = NULL;
127 if(Widget->ID < info->FirstFreeID)
128 info->FirstFreeID = Widget->ID;
132 void AxWin3_Widget_SetSize(tAxWin3_Widget *Widget, int Size)
134 tWidgetMsg_SetSize msg;
136 msg.WidgetID = Widget->ID;
138 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETSIZE, sizeof(msg), &msg);
141 void AxWin3_Widget_SetText(tAxWin3_Widget *Widget, const char *Text)
143 char buf[sizeof(tWidgetMsg_SetText) + strlen(Text) + 1];
144 tWidgetMsg_SetText *msg = (void*)buf;
146 msg->WidgetID = Widget->ID;
147 strcpy(msg->Text, Text);
149 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETTEXT, sizeof(buf), buf);
152 void AxWin3_Widget_SetColour(tAxWin3_Widget *Widget, int Index, tAxWin3_Colour Colour)
154 tWidgetMsg_SetColour msg;
156 msg.WidgetID = Widget->ID;
159 AxWin3_SendMessage(Widget->Window, Widget->Window, MSG_WIDGET_SETCOLOUR, sizeof(msg), &msg);