2 * AxWin3 Interface Library
3 * - By John Hodge (thePowersGang)
6 * - Core window management functions
8 #include <axwin3/axwin.h>
11 #include "include/internal.h"
12 #include "include/ipc.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 tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID)
46 tWindowBlock *block, *prev;
49 block = &gAxWin3_WindowList;
50 newWinID = giAxWin3_LowestFreeWinID;
51 for( idx = 0; block; newWinID ++ )
53 if( block->Windows[idx] == NULL )
56 if(idx == WINDOWS_PER_ALLOC) {
65 block = calloc(sizeof(tWindowBlock), 1);
70 ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes);
71 if(newWinID > giAxWin3_HighestUsedWinID)
72 giAxWin3_HighestUsedWinID = newWinID;
73 if(newWinID == giAxWin3_LowestFreeWinID)
74 giAxWin3_HighestUsedWinID ++;
76 if(WinID) *WinID = newWinID;
81 tHWND AxWin3_CreateWindow(
82 tHWND Parent, const char *Renderer, int RendererArg,
83 int DataBytes, tAxWin3_WindowMessageHandler MessageHandler
88 int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1;
89 tAxWin_IPCMessage *msg;
90 tIPCMsg_CreateWin *create_win;
92 // Allocate a window ID
93 ret = AxWin3_int_AllocateWindowInfo(DataBytes, &newWinID);
95 ret->Handler = MessageHandler;
98 msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize);
99 create_win = (void*)msg->Data;
100 create_win->NewWinID = newWinID;
101 create_win->RendererArg = RendererArg;
102 strcpy(create_win->Renderer, Renderer);
105 AxWin3_int_SendIPCMessage(msg);
108 // TODO: Detect and handle possible errors
114 void AxWin3_DestroyWindow(tHWND Window)
116 tAxWin_IPCMessage *msg;
118 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_DESTROYWIN, 0, 0);
119 AxWin3_int_SendIPCMessage(msg);
123 void *AxWin3_int_GetDataPtr(tHWND Window)
125 return &Window->Data;
128 void AxWin3_ShowWindow(tHWND Window, int bShow)
130 tAxWin_IPCMessage *msg;
131 tIPCMsg_ShowWindow *info;
133 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info));
134 info = (void*)msg->Data;
135 info->bShow = !!bShow;
137 AxWin3_int_SendIPCMessage(msg);
142 void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H)
144 tAxWin_IPCMessage *msg;
145 tIPCMsg_SetWindowPos *info;
147 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
148 info = (void*)msg->Data;
152 info->X = X; info->Y = Y;
153 info->W = W; info->H = H;
155 AxWin3_int_SendIPCMessage(msg);
159 void AxWin3_MoveWindow(tHWND Window, short X, short Y)
161 tAxWin_IPCMessage *msg;
162 tIPCMsg_SetWindowPos *info;
164 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
165 info = (void*)msg->Data;
172 AxWin3_int_SendIPCMessage(msg);
177 void AxWin3_ResizeWindow(tHWND Window, short W, short H)
179 tAxWin_IPCMessage *msg;
180 tIPCMsg_SetWindowPos *info;
182 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
183 info = (void*)msg->Data;
190 AxWin3_int_SendIPCMessage(msg);