From: John Hodge Date: Fri, 4 Nov 2011 11:12:04 +0000 (+0800) Subject: Usermode/AxWin3 - Moved interface library to Applications tree X-Git-Tag: rel0.14~151 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=184cdb36faa9cdf7e71af47a49c140b6fc4cebef;p=tpg%2Facess2.git Usermode/AxWin3 - Moved interface library to Applications tree --- diff --git a/Makefile b/Makefile index d3171645..9821d169 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ SUBMAKE = $(MAKE) --no-print-directory USRLIBS := crt0.o acess.ld ld-acess.so libgcc.so libc.so USRLIBS += libreadline.so libnet.so liburi.so -USRLIBS += libaxwin2.so libaxwin3.so libimage_sif.so +USRLIBS += libaxwin2.so libimage_sif.so USRAPPS := init login CLIShell cat ls mount USRAPPS += bomb diff --git a/Usermode/Applications/axwin3_src/Makefile b/Usermode/Applications/axwin3_src/Makefile index 3523ded8..59ab3cdf 100644 --- a/Usermode/Applications/axwin3_src/Makefile +++ b/Usermode/Applications/axwin3_src/Makefile @@ -1,6 +1,6 @@ NAME = AxWin3 -DIRS = WM Interface +DIRS = WM libaxwin3.so_src Interface SUBMAKE = $(MAKE) --no-print-directory diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile b/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile new file mode 100644 index 00000000..6e6c3e5a --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile @@ -0,0 +1,13 @@ +# Acess 2 - AxWin GUI Library +# + +include ../../../Libraries/Makefile.cfg + +CPPFLAGS += +CFLAGS += -Wall +LDFLAGS += -lc -soname libaxwin3.so + +OBJ = main.o msg.o wm.o r_widget.o +BIN = libaxwin3.so + +include ../../../Libraries/Makefile.tpl diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/internal.h b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/internal.h new file mode 100644 index 00000000..52910bd3 --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/internal.h @@ -0,0 +1,26 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * internal.h + * - Internal definitions + */ +#ifndef _INTERNAL_H_ +#define _INTERNAL_H_ + +struct sAxWin3_Window +{ + uint32_t ServerID; + tAxWin3_WindowMessageHandler Handler; + + char Data[]; +}; + +extern const char *gsAxWin3_int_ServerDesc; + +extern tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes); +extern void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg); +extern tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void); + +#endif + diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h new file mode 100644 index 00000000..36865937 --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h @@ -0,0 +1,14 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * ipcmessages.h + * - IPC Message format definition + */ +#ifndef _IPCMESSAGES_LIB_H_ +#define _IPCMESSAGES_LIB_H_ + +#include "../../WM/include/ipcmessages.h" + +#endif + diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c new file mode 100644 index 00000000..3fba042f --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c @@ -0,0 +1,32 @@ +/* + * AxWin3 Interface Library + * - By John Hodge (thePowersGang) + * + * main.c + * - Entrypoint and setup + */ +#include +#include "include/ipc.h" +#include "include/internal.h" + +// === CODE === +int SoMain(void *Base, int argc, const char *argv[], const char **envp) +{ + // TODO: Parse the environment for the AXWIN3_SERVER variable + gsAxWin3_int_ServerDesc = getenv("AXWIN3_SERVER"); + return 0; +} + +void AxWin3_MainLoop(void) +{ + tAxWin_IPCMessage *msg; + int bExit = 0; + + while(!bExit) + { + msg = AxWin3_int_GetIPCMessage(); + + // TODO: Handle message + } +} + diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c new file mode 100644 index 00000000..76b38c2d --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c @@ -0,0 +1,156 @@ +/* + * AxWin3 Interface Library + * - By John Hodge (thePowersGang) + * + * msg.c + * - Message handling / IPC + */ +#include +#include +#include +#include +#include "include/ipc.h" +#include "include/internal.h" + +// === CONSTANTS === +enum eConnectionType +{ + CONNTYPE_SENDMESSAGE, + CONNTYPE_UDP, + CONNTYPE_TCP +}; + +// === GLOBALS === +enum eConnectionType giConnectionType; +int giConnectionNum; // FD or PID +char gaAxWin3_int_UDPHeader[] = {5,16,0,0}; // Port 4101 + int giAxWin3_int_UDPHeaderLen = sizeof(gaAxWin3_int_UDPHeader); +const char *gsAxWin3_int_ServerDesc; +tAxWin3_MessageCallback gAxWin3_MessageCallback; + +// === CODE === +void AxWin3_Connect(const char *ServerDesc) +{ + _SysDebug("ServerDesc = %s", ServerDesc); + if( !ServerDesc ) + { + ServerDesc = gsAxWin3_int_ServerDesc; + } + _SysDebug("ServerDesc = %s", ServerDesc); + if( !ServerDesc ) + { + // TODO: Error out + return ; + } + switch(ServerDesc[0]) + { + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': case '0': + giConnectionType = CONNTYPE_SENDMESSAGE; + giConnectionNum = atoi(ServerDesc); + break; + case 'u': + while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; + ServerDesc ++; + // TODO: Open socket and create UDP header + break; + case 't': + while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; + ServerDesc ++; + // TODO: Open socket + break; + } +} + +tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback) +{ + tAxWin3_MessageCallback old = gAxWin3_MessageCallback; + gAxWin3_MessageCallback = Callback; + return old; +} + +tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes) +{ + tAxWin_IPCMessage *ret; + + ret = malloc( sizeof(tAxWin_IPCMessage) + ExtraBytes ); + ret->Flags = Flags; + ret->ID = Message; + if(Window) + ret->Window = Window->ServerID; + else + ret->Window = -1; + ret->Size = ExtraBytes; + return ret; +} + +void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) +{ + int size = sizeof(tAxWin_IPCMessage) + Msg->Size; + switch(giConnectionType) + { + case CONNTYPE_SENDMESSAGE: + SysSendMessage(giConnectionNum, size, Msg); + break; + case CONNTYPE_UDP: { + // Create UDP header + char tmpbuf[giAxWin3_int_UDPHeaderLen + size]; + memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen); + memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size); + write(giConnectionNum, tmpbuf, sizeof(tmpbuf)); + } + break; + case CONNTYPE_TCP: + write(giConnectionNum, Msg, size); + break; + default: + break; + } +} + +tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void) +{ + int len; + tAxWin_IPCMessage *ret = NULL; + switch(giConnectionType) + { + case CONNTYPE_SENDMESSAGE: + // TODO: Less hack, I need a version of select for GetMessage etc + if(SysGetMessage(NULL, NULL) == 0) sleep(); + while(SysGetMessage(NULL, NULL)) + { + pid_t tid; + len = SysGetMessage(&tid, NULL); + // Check if the message came from the server + if(tid != giConnectionNum) + { + // If not, pass the buck (or ignore) + if( gAxWin3_MessageCallback ) + gAxWin3_MessageCallback(tid, len); + else + SysGetMessage(NULL, GETMSG_IGNORE); + continue ; + } + + // If it's from the server, allocate a buffer and return it + ret = malloc(len); + if(ret == NULL) return NULL; + SysGetMessage(NULL, ret); + break; + } + break; + default: + // TODO: Implement + _SysDebug("TODO: Implement AxWin3_int_GetIPCMessage for TCP/UDP"); + break; + } + + // No message? + if( ret == NULL ) + return NULL; + + // TODO: Sanity checks, so a stupid server can't crash us + + return ret; +} + diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c new file mode 100644 index 00000000..e69de29b diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c new file mode 100644 index 00000000..9f15ad7e --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c @@ -0,0 +1,188 @@ +/* + * AxWin3 Interface Library + * - By John Hodge (thePowersGang) + * + * wm.c + * - Core window management functions + */ +#include +#include +#include +#include "include/ipc.h" +#include "include/internal.h" + +#define WINDOWS_PER_ALLOC (63) + +typedef struct sWindowBlock tWindowBlock; + +typedef struct sAxWin3_Window tWindow; + +// === STRUCTURES === +struct sWindowBlock +{ + tWindowBlock *Next; + tWindow *Windows[WINDOWS_PER_ALLOC]; +}; + +// === GLOBALS === + int giAxWin3_LowestFreeWinID; + int giAxWin3_HighestUsedWinID; +tWindowBlock gAxWin3_WindowList; + +// === CODE === +tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes) +{ + tWindow *ret; + + ret = calloc(sizeof(tWindow) + ExtraBytes, 1); + ret->ServerID = ServerID; + + return ret; +} + +tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID) +{ + int idx, newWinID; + tWindowBlock *block, *prev; + tWindow *ret; + + block = &gAxWin3_WindowList; + newWinID = giAxWin3_LowestFreeWinID; + for( idx = 0; block; newWinID ++ ) + { + if( block->Windows[idx] == NULL ) + break; + idx ++; + if(idx == WINDOWS_PER_ALLOC) { + prev = block; + block = block->Next; + idx = 0; + } + } + + if( !block ) + { + block = calloc(sizeof(tWindowBlock), 1); + prev->Next = block; + idx = 0; + } + + ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes); + if(newWinID > giAxWin3_HighestUsedWinID) + giAxWin3_HighestUsedWinID = newWinID; + if(newWinID == giAxWin3_LowestFreeWinID) + giAxWin3_HighestUsedWinID ++; + + if(WinID) *WinID = newWinID; + + return ret; +} + +tHWND AxWin3_CreateWindow( + tHWND Parent, const char *Renderer, int Flags, + int DataBytes, void **DataPtr, + tAxWin3_WindowMessageHandler MessageHandler + ) +{ + tWindow *ret; + int newWinID; + int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1; + tAxWin_IPCMessage *msg; + tIPCMsg_CreateWin *create_win; + + // Allocate a window ID + ret = AxWin3_int_AllocateWindowInfo(DataBytes, &newWinID); + if(!ret) return NULL; + ret->Handler = MessageHandler; + + // Create message + msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize); + create_win = (void*)msg->Data; + create_win->NewWinID = newWinID; + create_win->Flags = Flags; + strcpy(create_win->Renderer, Renderer); + + // Send and clean up + AxWin3_int_SendIPCMessage(msg); + free(msg); + + // TODO: Detect and handle possible errors + + // Return success + if(DataPtr) *DataPtr = ret->Data; + return ret; +} + +void AxWin3_DestroyWindow(tHWND Window) +{ + tAxWin_IPCMessage *msg; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_DESTROYWIN, 0, 0); + AxWin3_int_SendIPCMessage(msg); + free(msg); +} + +void AxWin3_ShowWindow(tHWND Window, int bShow) +{ + tAxWin_IPCMessage *msg; + tIPCMsg_ShowWindow *info; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info)); + info = (void*)msg->Data; + info->bShow = !!bShow; + + AxWin3_int_SendIPCMessage(msg); + + free(msg); +} + +void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H) +{ + tAxWin_IPCMessage *msg; + tIPCMsg_SetWindowPos *info; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); + info = (void*)msg->Data; + + info->Fields = 0xF; + info->X = X; info->Y = Y; + info->W = W; info->H = H; + + AxWin3_int_SendIPCMessage(msg); + free(msg); +} + +void AxWin3_MoveWindow(tHWND Window, short X, short Y) +{ + tAxWin_IPCMessage *msg; + tIPCMsg_SetWindowPos *info; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); + info = (void*)msg->Data; + + info->Fields = 0x3; + info->X = X; + info->Y = Y; + + AxWin3_int_SendIPCMessage(msg); + + free(msg); +} + +void AxWin3_ResizeWindow(tHWND Window, short W, short H) +{ + tAxWin_IPCMessage *msg; + tIPCMsg_SetWindowPos *info; + + msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); + info = (void*)msg->Data; + + info->Fields = 0xC; + info->W = W; + info->H = H; + + AxWin3_int_SendIPCMessage(msg); + + free(msg); +} + diff --git a/Usermode/Libraries/libaxwin3.so_src/Makefile b/Usermode/Libraries/libaxwin3.so_src/Makefile deleted file mode 100644 index 8a910abd..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# Acess 2 - AxWin GUI Library -# - -include ../Makefile.cfg - -CPPFLAGS += -CFLAGS += -Wall -LDFLAGS += -lc -soname libaxwin3.so - -OBJ = main.o msg.o wm.o r_widget.o -BIN = libaxwin3.so - -include ../Makefile.tpl diff --git a/Usermode/Libraries/libaxwin3.so_src/include/internal.h b/Usermode/Libraries/libaxwin3.so_src/include/internal.h deleted file mode 100644 index 52910bd3..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/include/internal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Acess2 Window Manager v3 - * - By John Hodge (thePowersGang) - * - * internal.h - * - Internal definitions - */ -#ifndef _INTERNAL_H_ -#define _INTERNAL_H_ - -struct sAxWin3_Window -{ - uint32_t ServerID; - tAxWin3_WindowMessageHandler Handler; - - char Data[]; -}; - -extern const char *gsAxWin3_int_ServerDesc; - -extern tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes); -extern void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg); -extern tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void); - -#endif - diff --git a/Usermode/Libraries/libaxwin3.so_src/include/ipc.h b/Usermode/Libraries/libaxwin3.so_src/include/ipc.h deleted file mode 100644 index 8cbe20d8..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/include/ipc.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Acess2 Window Manager v3 - * - By John Hodge (thePowersGang) - * - * ipcmessages.h - * - IPC Message format definition - */ -#ifndef _IPCMESSAGES_LIB_H_ -#define _IPCMESSAGES_LIB_H_ - -#include "../../../Applications/axwin3_src/WM/include/ipcmessages.h" - -#endif - diff --git a/Usermode/Libraries/libaxwin3.so_src/main.c b/Usermode/Libraries/libaxwin3.so_src/main.c deleted file mode 100644 index 3fba042f..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/main.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * AxWin3 Interface Library - * - By John Hodge (thePowersGang) - * - * main.c - * - Entrypoint and setup - */ -#include -#include "include/ipc.h" -#include "include/internal.h" - -// === CODE === -int SoMain(void *Base, int argc, const char *argv[], const char **envp) -{ - // TODO: Parse the environment for the AXWIN3_SERVER variable - gsAxWin3_int_ServerDesc = getenv("AXWIN3_SERVER"); - return 0; -} - -void AxWin3_MainLoop(void) -{ - tAxWin_IPCMessage *msg; - int bExit = 0; - - while(!bExit) - { - msg = AxWin3_int_GetIPCMessage(); - - // TODO: Handle message - } -} - diff --git a/Usermode/Libraries/libaxwin3.so_src/msg.c b/Usermode/Libraries/libaxwin3.so_src/msg.c deleted file mode 100644 index 76b38c2d..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/msg.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * AxWin3 Interface Library - * - By John Hodge (thePowersGang) - * - * msg.c - * - Message handling / IPC - */ -#include -#include -#include -#include -#include "include/ipc.h" -#include "include/internal.h" - -// === CONSTANTS === -enum eConnectionType -{ - CONNTYPE_SENDMESSAGE, - CONNTYPE_UDP, - CONNTYPE_TCP -}; - -// === GLOBALS === -enum eConnectionType giConnectionType; -int giConnectionNum; // FD or PID -char gaAxWin3_int_UDPHeader[] = {5,16,0,0}; // Port 4101 - int giAxWin3_int_UDPHeaderLen = sizeof(gaAxWin3_int_UDPHeader); -const char *gsAxWin3_int_ServerDesc; -tAxWin3_MessageCallback gAxWin3_MessageCallback; - -// === CODE === -void AxWin3_Connect(const char *ServerDesc) -{ - _SysDebug("ServerDesc = %s", ServerDesc); - if( !ServerDesc ) - { - ServerDesc = gsAxWin3_int_ServerDesc; - } - _SysDebug("ServerDesc = %s", ServerDesc); - if( !ServerDesc ) - { - // TODO: Error out - return ; - } - switch(ServerDesc[0]) - { - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': case '0': - giConnectionType = CONNTYPE_SENDMESSAGE; - giConnectionNum = atoi(ServerDesc); - break; - case 'u': - while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; - ServerDesc ++; - // TODO: Open socket and create UDP header - break; - case 't': - while(*ServerDesc && *ServerDesc != ':') ServerDesc ++; - ServerDesc ++; - // TODO: Open socket - break; - } -} - -tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback) -{ - tAxWin3_MessageCallback old = gAxWin3_MessageCallback; - gAxWin3_MessageCallback = Callback; - return old; -} - -tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes) -{ - tAxWin_IPCMessage *ret; - - ret = malloc( sizeof(tAxWin_IPCMessage) + ExtraBytes ); - ret->Flags = Flags; - ret->ID = Message; - if(Window) - ret->Window = Window->ServerID; - else - ret->Window = -1; - ret->Size = ExtraBytes; - return ret; -} - -void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) -{ - int size = sizeof(tAxWin_IPCMessage) + Msg->Size; - switch(giConnectionType) - { - case CONNTYPE_SENDMESSAGE: - SysSendMessage(giConnectionNum, size, Msg); - break; - case CONNTYPE_UDP: { - // Create UDP header - char tmpbuf[giAxWin3_int_UDPHeaderLen + size]; - memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen); - memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size); - write(giConnectionNum, tmpbuf, sizeof(tmpbuf)); - } - break; - case CONNTYPE_TCP: - write(giConnectionNum, Msg, size); - break; - default: - break; - } -} - -tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void) -{ - int len; - tAxWin_IPCMessage *ret = NULL; - switch(giConnectionType) - { - case CONNTYPE_SENDMESSAGE: - // TODO: Less hack, I need a version of select for GetMessage etc - if(SysGetMessage(NULL, NULL) == 0) sleep(); - while(SysGetMessage(NULL, NULL)) - { - pid_t tid; - len = SysGetMessage(&tid, NULL); - // Check if the message came from the server - if(tid != giConnectionNum) - { - // If not, pass the buck (or ignore) - if( gAxWin3_MessageCallback ) - gAxWin3_MessageCallback(tid, len); - else - SysGetMessage(NULL, GETMSG_IGNORE); - continue ; - } - - // If it's from the server, allocate a buffer and return it - ret = malloc(len); - if(ret == NULL) return NULL; - SysGetMessage(NULL, ret); - break; - } - break; - default: - // TODO: Implement - _SysDebug("TODO: Implement AxWin3_int_GetIPCMessage for TCP/UDP"); - break; - } - - // No message? - if( ret == NULL ) - return NULL; - - // TODO: Sanity checks, so a stupid server can't crash us - - return ret; -} - diff --git a/Usermode/Libraries/libaxwin3.so_src/r_widget.c b/Usermode/Libraries/libaxwin3.so_src/r_widget.c deleted file mode 100644 index e69de29b..00000000 diff --git a/Usermode/Libraries/libaxwin3.so_src/wm.c b/Usermode/Libraries/libaxwin3.so_src/wm.c deleted file mode 100644 index 9f15ad7e..00000000 --- a/Usermode/Libraries/libaxwin3.so_src/wm.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * AxWin3 Interface Library - * - By John Hodge (thePowersGang) - * - * wm.c - * - Core window management functions - */ -#include -#include -#include -#include "include/ipc.h" -#include "include/internal.h" - -#define WINDOWS_PER_ALLOC (63) - -typedef struct sWindowBlock tWindowBlock; - -typedef struct sAxWin3_Window tWindow; - -// === STRUCTURES === -struct sWindowBlock -{ - tWindowBlock *Next; - tWindow *Windows[WINDOWS_PER_ALLOC]; -}; - -// === GLOBALS === - int giAxWin3_LowestFreeWinID; - int giAxWin3_HighestUsedWinID; -tWindowBlock gAxWin3_WindowList; - -// === CODE === -tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes) -{ - tWindow *ret; - - ret = calloc(sizeof(tWindow) + ExtraBytes, 1); - ret->ServerID = ServerID; - - return ret; -} - -tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID) -{ - int idx, newWinID; - tWindowBlock *block, *prev; - tWindow *ret; - - block = &gAxWin3_WindowList; - newWinID = giAxWin3_LowestFreeWinID; - for( idx = 0; block; newWinID ++ ) - { - if( block->Windows[idx] == NULL ) - break; - idx ++; - if(idx == WINDOWS_PER_ALLOC) { - prev = block; - block = block->Next; - idx = 0; - } - } - - if( !block ) - { - block = calloc(sizeof(tWindowBlock), 1); - prev->Next = block; - idx = 0; - } - - ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes); - if(newWinID > giAxWin3_HighestUsedWinID) - giAxWin3_HighestUsedWinID = newWinID; - if(newWinID == giAxWin3_LowestFreeWinID) - giAxWin3_HighestUsedWinID ++; - - if(WinID) *WinID = newWinID; - - return ret; -} - -tHWND AxWin3_CreateWindow( - tHWND Parent, const char *Renderer, int Flags, - int DataBytes, void **DataPtr, - tAxWin3_WindowMessageHandler MessageHandler - ) -{ - tWindow *ret; - int newWinID; - int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1; - tAxWin_IPCMessage *msg; - tIPCMsg_CreateWin *create_win; - - // Allocate a window ID - ret = AxWin3_int_AllocateWindowInfo(DataBytes, &newWinID); - if(!ret) return NULL; - ret->Handler = MessageHandler; - - // Create message - msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize); - create_win = (void*)msg->Data; - create_win->NewWinID = newWinID; - create_win->Flags = Flags; - strcpy(create_win->Renderer, Renderer); - - // Send and clean up - AxWin3_int_SendIPCMessage(msg); - free(msg); - - // TODO: Detect and handle possible errors - - // Return success - if(DataPtr) *DataPtr = ret->Data; - return ret; -} - -void AxWin3_DestroyWindow(tHWND Window) -{ - tAxWin_IPCMessage *msg; - - msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_DESTROYWIN, 0, 0); - AxWin3_int_SendIPCMessage(msg); - free(msg); -} - -void AxWin3_ShowWindow(tHWND Window, int bShow) -{ - tAxWin_IPCMessage *msg; - tIPCMsg_ShowWindow *info; - - msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info)); - info = (void*)msg->Data; - info->bShow = !!bShow; - - AxWin3_int_SendIPCMessage(msg); - - free(msg); -} - -void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H) -{ - tAxWin_IPCMessage *msg; - tIPCMsg_SetWindowPos *info; - - msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); - info = (void*)msg->Data; - - info->Fields = 0xF; - info->X = X; info->Y = Y; - info->W = W; info->H = H; - - AxWin3_int_SendIPCMessage(msg); - free(msg); -} - -void AxWin3_MoveWindow(tHWND Window, short X, short Y) -{ - tAxWin_IPCMessage *msg; - tIPCMsg_SetWindowPos *info; - - msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); - info = (void*)msg->Data; - - info->Fields = 0x3; - info->X = X; - info->Y = Y; - - AxWin3_int_SendIPCMessage(msg); - - free(msg); -} - -void AxWin3_ResizeWindow(tHWND Window, short W, short H) -{ - tAxWin_IPCMessage *msg; - tIPCMsg_SetWindowPos *info; - - msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info)); - info = (void*)msg->Data; - - info->Fields = 0xC; - info->W = W; - info->H = H; - - AxWin3_int_SendIPCMessage(msg); - - free(msg); -} -