2 * AxWin3 Interface Library
3 * - By John Hodge (thePowersGang)
6 * - Core window management functions
8 #include <axwin3/axwin.h>
11 #include "include/ipc.h"
12 #include "include/internal.h"
14 #define WINDOWS_PER_ALLOC (63)
16 typedef struct sWindowBlock tWindowBlock;
18 typedef struct sAxWin3_Window tWindow;
24 tWindow *Windows[WINDOWS_PER_ALLOC];
28 int giAxWin3_LowestFreeWinID;
29 int giAxWin3_HighestUsedWinID;
30 tWindowBlock gAxWin3_WindowList;
33 tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes)
37 ret = calloc(sizeof(tWindow) + ExtraBytes, 1);
38 ret->ServerID = ServerID;
43 tHWND AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags, int DataBytes, void **DataPtr)
47 int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1;
48 tAxWin_IPCMessage *msg;
49 tIPCMsg_CreateWin *create_win;
51 // TODO: Validate `Parent`
53 // Allocate a window ID
56 tWindowBlock *block, *prev;
57 block = &gAxWin3_WindowList;
58 newWinID = giAxWin3_LowestFreeWinID;
59 for( idx = 0; block; newWinID ++ )
61 if( block->Windows[idx] == NULL )
64 if(idx == WINDOWS_PER_ALLOC) {
73 block = calloc(sizeof(tWindowBlock), 1);
78 ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes);
80 if(newWinID > giAxWin3_HighestUsedWinID)
81 giAxWin3_HighestUsedWinID = newWinID;
82 if(newWinID == giAxWin3_LowestFreeWinID)
83 giAxWin3_HighestUsedWinID ++;
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);
94 AxWin3_int_SendIPCMessage(msg);
97 // TODO: Detect errors in AxWin3_CreateWindow
100 if(DataPtr) *DataPtr = ret->Data;
104 void AxWin3_DestroyWindow(tHWND Window)