Usermode/AxWin3 - Bugfixing rendering/layout issues
[tpg/acess2.git] / Usermode / Applications / axwin3_src / libaxwin3.so_src / wm.c
index 9f15ad7..4a6242b 100644 (file)
@@ -8,8 +8,8 @@
 #include <axwin3/axwin.h>
 #include <stdlib.h>
 #include <string.h>
-#include "include/ipc.h"
 #include "include/internal.h"
+#include "include/ipc.h"
 
 #define WINDOWS_PER_ALLOC      (63)
 
@@ -40,10 +40,21 @@ tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes)
        return ret;
 }
 
+tWindow *AxWin3_int_GetWindowFromID(uint32_t ServerID)
+{
+       tWindowBlock    *block = &gAxWin3_WindowList;
+       while(block && ServerID > WINDOWS_PER_ALLOC) {
+               block = block->Next;
+               ServerID -= WINDOWS_PER_ALLOC;
+       }
+       if(!block)      return NULL;
+       return block->Windows[ServerID];
+}
+
 tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID)
 {
         int    idx, newWinID;
-       tWindowBlock *block, *prev;
+       tWindowBlock *block, *prev = NULL;
        tWindow *ret;   
 
        block = &gAxWin3_WindowList;
@@ -78,10 +89,51 @@ tWindow *AxWin3_int_AllocateWindowInfo(int DataBytes, int *WinID)
        return ret;
 }
 
+int AxWin3_GetDisplayCount(void)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_ReturnInt       *ret;
+        int    rv;
+       
+       msg = AxWin3_int_AllocateIPCMessage(NULL, IPCMSG_GETDISPLAYCOUNT, IPCMSG_FLAG_RETURN, 0);
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);      
+
+       msg = AxWin3_int_WaitIPCMessage(IPCMSG_GETDISPLAYCOUNT);
+       if(msg->Size < sizeof(*ret))    return -1;
+       ret = (void*)msg->Data;
+       rv = ret->Value;
+       free(msg);
+       return rv;
+}
+
+int AxWin3_GetDisplayDims(int Display, int *X, int *Y, int *Width, int *Height)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_GetDisplayDims  *req;
+       tIPCMsg_RetDisplayDims  *ret;
+       
+       msg = AxWin3_int_AllocateIPCMessage(NULL, IPCMSG_GETDISPLAYDIMS, IPCMSG_FLAG_RETURN, sizeof(*req));
+       req = (void*)msg->Data;
+       req->DisplayID = Display;
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);
+
+       msg = AxWin3_int_WaitIPCMessage(IPCMSG_GETDISPLAYDIMS);
+       if(msg->Size < sizeof(*ret))    return -1;
+       ret = (void*)msg->Data;
+       
+       if(X)   *X = ret->X;
+       if(X)   *X = ret->Y;
+       if(Width)       *Width = ret->W;
+       if(Height)      *Height = ret->H;
+       
+       return 0;
+}
+
 tHWND AxWin3_CreateWindow(
-       tHWND Parent, const char *Renderer, int Flags,
-       int DataBytes, void **DataPtr,
-       tAxWin3_WindowMessageHandler MessageHandler
+       tHWND Parent, const char *Renderer, int RendererArg,
+       int DataBytes, tAxWin3_WindowMessageHandler MessageHandler
        )
 {
        tWindow *ret;
@@ -99,7 +151,7 @@ tHWND AxWin3_CreateWindow(
        msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize);
        create_win = (void*)msg->Data;  
        create_win->NewWinID = newWinID;
-       create_win->Flags = Flags;
+       create_win->RendererArg = RendererArg;
        strcpy(create_win->Renderer, Renderer);
 
        // Send and clean up
@@ -109,7 +161,6 @@ tHWND AxWin3_CreateWindow(
        // TODO: Detect and handle possible errors
 
        // Return success
-       if(DataPtr)     *DataPtr = ret->Data;
        return ret;
 }
 
@@ -122,14 +173,90 @@ void AxWin3_DestroyWindow(tHWND Window)
        free(msg);
 }
 
+void *AxWin3_int_GetDataPtr(tHWND Window)
+{
+       return Window->Data;
+}
+
+void AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg)
+{
+       tWindow *dest;
+
+       dest = AxWin3_int_GetWindowFromID(Msg->Window);
+
+       switch(Msg->ID)
+       {
+       case IPCMSG_SENDMSG: {
+               tIPCMsg_SendMsg *info = (void*)Msg->Data;
+               if(Msg->Size < sizeof(*info))   return ;
+               if(Msg->Size < sizeof(*info) + info->Length)    return ;
+               if(!dest || !dest->Handler)     return ;
+               dest->Handler(dest, info->ID, info->Length, info->Data);
+               break; }
+       }
+}
+
+void AxWin3_SetWindowTitle(tHWND Window, const char *Title)
+{
+       tAxWin_IPCMessage       *msg;
+        int    len = strlen(Title);
+       
+       msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINTITLE, 0, len+1);
+       strcpy(msg->Data, Title);
+       
+       AxWin3_int_SendIPCMessage(msg);
+       
+       free(msg);
+}
+
+void AxWin3_SendMessage(tHWND Window, tHWND Destination, int Message, int Length, void *Data)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_SendMsg *info;
+       
+       msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SENDMSG, 0, sizeof(*info)+Length);
+       info = (void*)msg->Data;
+       info->Remote = AxWin3_int_GetWindowID(Destination);
+       info->ID = Message;
+       info->Length = Length;
+       memcpy(info->Data, Data, Length);
+       
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);
+}
+
+void AxWin3_FocusWindow(tHWND Window)
+{
+       tAxWin_IPCMessage       *msg;
+       
+       msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_FOCUSWINDOW, 0, 0);
+       
+       AxWin3_int_SendIPCMessage(msg);
+       free(msg);
+}
+
 void AxWin3_ShowWindow(tHWND Window, int bShow)
 {
        tAxWin_IPCMessage       *msg;
-       tIPCMsg_ShowWindow      *info;
+       tIPCMsg_Boolean *info;
 
        msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SHOWWINDOW, 0, sizeof(*info));
        info = (void*)msg->Data;
-       info->bShow = !!bShow;
+       info->Value = !!bShow;
+       
+       AxWin3_int_SendIPCMessage(msg);
+       
+       free(msg);
+}
+
+void AxWin3_DecorateWindow(tHWND Window, int bDecorate)
+{
+       tAxWin_IPCMessage       *msg;
+       tIPCMsg_Boolean *info;
+
+       msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_DECORATEWINDOW, 0, sizeof(*info));
+       info = (void*)msg->Data;
+       info->Value = !!bDecorate;
        
        AxWin3_int_SendIPCMessage(msg);
        
@@ -144,7 +271,8 @@ void AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H)
        msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
        info = (void*)msg->Data;
 
-       info->Fields = 0xF;
+       info->bSetPos = 1;
+       info->bSetDims = 1;
        info->X = X;    info->Y = Y;
        info->W = W;    info->H = H;
 
@@ -160,7 +288,8 @@ void AxWin3_MoveWindow(tHWND Window, short X, short Y)
        msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
        info = (void*)msg->Data;
 
-       info->Fields = 0x3;
+       info->bSetPos = 1;
+       info->bSetDims = 0;
        info->X = X;
        info->Y = Y;
        
@@ -177,7 +306,8 @@ void AxWin3_ResizeWindow(tHWND Window, short W, short H)
        msg = AxWin3_int_AllocateIPCMessage(Window, IPCMSG_SETWINPOS, 0, sizeof(*info));
        info = (void*)msg->Data;
 
-       info->Fields = 0xC;
+       info->bSetPos = 0;
+       info->bSetDims = 1;
        info->W = W;
        info->H = H;
        

UCC git Repository :: git.ucc.asn.au