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 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 Flags,
83 int DataBytes, void **DataPtr,
84 tAxWin3_WindowMessageHandler MessageHandler
89 int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1;
90 tAxWin_IPCMessage *msg;
91 tIPCMsg_CreateWin *create_win;
93 // Allocate a window ID
94 ret = AxWin3_int_AllocateWindowInfo(DataBytes, &newWinID);
96 ret->Handler = MessageHandler;
99 msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize);
100 create_win = (void*)msg->Data;
101 create_win->NewWinID = newWinID;
102 create_win->Flags = Flags;
103 strcpy(create_win->Renderer, Renderer);
106 AxWin3_int_SendIPCMessage(msg);
109 // TODO: Detect and handle possible errors
112 if(DataPtr) *DataPtr = ret->Data;
116 void AxWin3_DestroyWindow(tHWND Window)
118 tAxWin_IPCMessage *msg;
120 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_DESTROYWIN, 0, 0);
121 AxWin3_int_SendIPCMessage(msg);
125 void AxWin3_ShowWindow(tHWND Window, int bShow)
127 tAxWin_IPCMessage *msg;
128 tIPCMsg_ShowWindow *info;
130 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info));
131 info = (void*)msg->Data;
132 info->bShow = !!bShow;
134 AxWin3_int_SendIPCMessage(msg);
139 void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H)
141 tAxWin_IPCMessage *msg;
142 tIPCMsg_SetWindowPos *info;
144 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
145 info = (void*)msg->Data;
148 info->X = X; info->Y = Y;
149 info->W = W; info->H = H;
151 AxWin3_int_SendIPCMessage(msg);
155 void AxWin3_MoveWindow(tHWND Window, short X, short Y)
157 tAxWin_IPCMessage *msg;
158 tIPCMsg_SetWindowPos *info;
160 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
161 info = (void*)msg->Data;
167 AxWin3_int_SendIPCMessage(msg);
172 void AxWin3_ResizeWindow(tHWND Window, short W, short H)
174 tAxWin_IPCMessage *msg;
175 tIPCMsg_SetWindowPos *info;
177 msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
178 info = (void*)msg->Data;
184 AxWin3_int_SendIPCMessage(msg);