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_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);
138 void AxWin3_ShowWindow(tHWND Window, int bShow)
140 tAxWin_IPCMessage *msg;
141 tIPCMsg_ShowWindow *info;
143 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info));
144 info = (void*)msg->Data;
145 info->bShow = !!bShow;
147 AxWin3_int_SendIPCMessage(msg);
152 void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H)
154 tAxWin_IPCMessage *msg;
155 tIPCMsg_SetWindowPos *info;
157 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
158 info = (void*)msg->Data;
162 info->X = X; info->Y = Y;
163 info->W = W; info->H = H;
165 AxWin3_int_SendIPCMessage(msg);
169 void AxWin3_MoveWindow(tHWND Window, short X, short Y)
171 tAxWin_IPCMessage *msg;
172 tIPCMsg_SetWindowPos *info;
174 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
175 info = (void*)msg->Data;
182 AxWin3_int_SendIPCMessage(msg);
187 void AxWin3_ResizeWindow(tHWND Window, short W, short H)
189 tAxWin_IPCMessage *msg;
190 tIPCMsg_SetWindowPos *info;
192 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
193 info = (void*)msg->Data;
200 AxWin3_int_SendIPCMessage(msg);