Usermode/AxWin3 - Working on interface library
[tpg/acess2.git] / Usermode / Libraries / libaxwin3.so_src / wm.c
1 /*
2  * AxWin3 Interface Library
3  * - By John Hodge (thePowersGang)
4  *
5  * wm.c
6  * - Core window management functions
7  */
8 #include <axwin3/axwin.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "include/ipc.h"
12 #include "include/internal.h"
13
14 #define WINDOWS_PER_ALLOC       (63)
15
16 typedef struct sWindowBlock     tWindowBlock;
17
18 typedef struct sAxWin3_Window   tWindow;
19
20 // === STRUCTURES ===
21 struct sWindowBlock
22 {
23         tWindowBlock    *Next;
24         tWindow *Windows[WINDOWS_PER_ALLOC];
25 };
26
27 // === GLOBALS ===
28  int    giAxWin3_LowestFreeWinID;
29  int    giAxWin3_HighestUsedWinID;
30 tWindowBlock    gAxWin3_WindowList;
31
32 // === CODE ===
33 tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes)
34 {
35         tWindow *ret;
36         
37         ret = calloc(sizeof(tWindow) + ExtraBytes, 1);
38         ret->ServerID = ServerID;
39
40         return ret;
41 }
42
43 tHWND AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags, int DataBytes, void **DataPtr)
44 {
45         tWindow *ret;
46          int    newWinID;
47          int    dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1;
48         tAxWin_IPCMessage       *msg;
49         tIPCMsg_CreateWin       *create_win;
50
51         // TODO: Validate `Parent`
52         
53         // Allocate a window ID
54         {
55                  int    idx;
56                 tWindowBlock *block, *prev;
57                 block = &gAxWin3_WindowList;
58                 newWinID = giAxWin3_LowestFreeWinID;
59                 for( idx = 0; block; newWinID ++ )
60                 {
61                         if( block->Windows[idx] == NULL )
62                                 break;
63                         idx ++;
64                         if(idx == WINDOWS_PER_ALLOC) {
65                                 prev = block;
66                                 block = block->Next;
67                                 idx = 0;
68                         }
69                 }
70                 
71                 if( !block )
72                 {
73                         block = calloc(sizeof(tWindowBlock), 1);
74                         prev->Next = block;
75                         idx = 0;
76                 }
77                 
78                 ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes);
79
80                 if(newWinID > giAxWin3_HighestUsedWinID)
81                         giAxWin3_HighestUsedWinID = newWinID;
82                 if(newWinID == giAxWin3_LowestFreeWinID)
83                         giAxWin3_HighestUsedWinID ++;
84         }
85
86         // Create message
87         msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize);
88         create_win = (void*)msg->Data;  
89         create_win->NewWinID = newWinID;
90         create_win->Flags = Flags;
91         strcpy(create_win->Renderer, Renderer);
92
93         // Send and clean up
94         AxWin3_int_SendIPCMessage(msg);
95         free(msg);
96
97         // TODO: Detect errors in AxWin3_CreateWindow
98
99         // Return success
100         if(DataPtr)     *DataPtr = ret->Data;
101         return ret;
102 }
103
104 void AxWin3_DestroyWindow(tHWND Window)
105 {
106 }

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