9eb55bbd30a9ba4264a49ca9896abc52968e9cbc
[tpg/acess2.git] / Usermode / Applications / axwin3_src / libaxwin3.so_src / r_widget.c
1 /*
2  * AxWin3 Interface Library
3  * - By John Hodge (thePowersGang)
4  *
5  * main.c
6  * - Entrypoint and setup
7  */
8 #include <axwin3/axwin.h>
9 #include <axwin3/widget.h>
10 #include "include/internal.h"
11 #include <stdlib.h>
12 #include <widget_messages.h>
13
14 // === STRUCTURES ===
15 struct sAxWin3_Widget
16 {
17         tHWND   Window;
18         uint32_t        ID;
19         tAxWin3_Widget_Callback Callback;
20 };
21
22 typedef struct
23 {
24          int    nElements;
25         tAxWin3_Widget  **Elements;
26          int    FirstFreeID;
27         // Callbacks for each element
28 } tWidgetWindowInfo;
29
30 // === CODE ===
31 int AxWin3_Widget_MessageHandler(tHWND Window, int Size, void *Data)
32 {
33         return 0;
34 }
35
36 tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags)
37 {
38         tHWND   ret;
39         tWidgetWindowInfo       *info;
40         
41         ret = AxWin3_CreateWindow(
42                 Parent, "Widget", RootEleFlags,
43                 sizeof(*info) + sizeof(tAxWin3_Widget), AxWin3_Widget_MessageHandler
44                 );
45         info = AxWin3_int_GetDataPtr(ret);
46
47         info->nElements = 1;
48         info->Elements = malloc(sizeof(tAxWin3_Widget*));
49         info->Elements[0] = (void*)(info + 1);  // Get end of *info
50         info->FirstFreeID = 1;
51
52         AxWin3_ResizeWindow(ret, W, H);
53         
54         return ret;
55 }
56
57 void AxWin3_Widget_DestroyWindow(tHWND Window)
58 {
59         // Free all element structures
60         
61         // Free array
62         
63         // Request window to be destroyed (will clean up any data stored in tHWND)
64 }
65
66 tAxWin3_Widget *AxWin3_Widget_GetRoot(tHWND Window)
67 {
68         tWidgetWindowInfo       *info = AxWin3_int_GetDataPtr(Window);
69         return info->Elements[0];
70 }
71
72 tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Flags, const char *DebugName)
73 {
74          int    newID;
75         tWidgetWindowInfo       *info;
76         tAxWin3_Widget  *ret;
77
78         if(!Parent)     return NULL;
79
80         info = AxWin3_int_GetDataPtr(Parent->Window);
81         
82         // Assign ID
83         // TODO: Atomicity
84         for( newID = info->FirstFreeID; newID < info->nElements; newID ++ )
85         {
86                 if( info->Elements[newID] == NULL )
87                         break;
88         }
89         if( info->Elements[newID] )
90         {
91                 info->nElements ++;
92                 info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements);
93                 newID = info->nElements - 1;
94         }
95         info->Elements[newID] = (void*)-1;
96         
97         // Create new widget structure
98         ret = malloc(sizeof(tAxWin3_Widget));
99         ret->Window = Parent->Window;
100         ret->ID = newID;
101         ret->Callback = NULL;
102
103         info->Elements[newID] = ret;
104
105         // Send create widget message
106         {
107                 char    tmp[sizeof(tWidgetMsg_Create)+1];
108                 tWidgetMsg_Create       *msg = (void*)tmp;
109                 msg->Parent = Parent->ID;
110                 msg->NewID = newID;
111                 msg->DebugName[0] = '\0';
112                 AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATE, sizeof(tmp), tmp);
113         }
114
115         return ret;
116 }

UCC git Repository :: git.ucc.asn.au