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)
128 void AxWin3_SendMessage(tHWND Window, tHWND Destination, int Message, int Length, void *Data)
130 tAxWin_IPCMessage *msg;
131 tIPCMsg_SendMsg *info;
133 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SENDMSG, 0, sizeof(*info)+Length);
134 info = (void*)msg->Data;
135 info->Dest = AxWin3_int_GetWindowID(Destination);
137 info->Length = Length;
138 memcpy(info->Data, Data, Length);
140 AxWin3_int_SendIPCMessage(msg);
144 void AxWin3_ShowWindow(tHWND Window, int bShow)
146 tAxWin_IPCMessage *msg;
147 tIPCMsg_ShowWindow *info;
149 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info));
150 info = (void*)msg->Data;
151 info->bShow = !!bShow;
153 AxWin3_int_SendIPCMessage(msg);
158 void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H)
160 tAxWin_IPCMessage *msg;
161 tIPCMsg_SetWindowPos *info;
163 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
164 info = (void*)msg->Data;
168 info->X = X; info->Y = Y;
169 info->W = W; info->H = H;
171 AxWin3_int_SendIPCMessage(msg);
175 void AxWin3_MoveWindow(tHWND Window, short X, short Y)
177 tAxWin_IPCMessage *msg;
178 tIPCMsg_SetWindowPos *info;
180 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
181 info = (void*)msg->Data;
188 AxWin3_int_SendIPCMessage(msg);
193 void AxWin3_ResizeWindow(tHWND Window, short W, short H)
195 tAxWin_IPCMessage *msg;
196 tIPCMsg_SetWindowPos *info;
198 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
199 info = (void*)msg->Data;
206 AxWin3_int_SendIPCMessage(msg);