Usermode/AxWin3 - Implementing SendMessage for client
authorJohn Hodge <[email protected]>
Sat, 5 Nov 2011 08:18:43 +0000 (16:18 +0800)
committerJohn Hodge <[email protected]>
Sat, 5 Nov 2011 08:18:43 +0000 (16:18 +0800)
Usermode/Applications/axwin3_src/WM/include/renderer_widget.h
Usermode/Applications/axwin3_src/WM/renderer_widget.c
Usermode/Applications/axwin3_src/include/ipcmessages.h
Usermode/Applications/axwin3_src/include/widget_messages.h [new file with mode: 0644]
Usermode/Applications/axwin3_src/libaxwin3.so_src/include/internal.h
Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c
Usermode/include/axwin3/axwin.h

index fd79acf..35b767d 100644 (file)
 #include <wm_renderer.h>
 #include <axwin3/widget.h>
 
-enum
-{
-       MSG_WIDGET_CREATE,
-       MSG_WIDGET_DELETE,
-       MSG_WIDGET_SETTEXT
-};
-
-
-typedef struct
-{
-       uint32_t        Parent;
-       uint32_t        NewID;
-       char    DebugName[];
-} tWidgetMsg_Create;
+#include <widget_messages.h>
 
 #endif
 
index 53788da..3fbe3cb 100644 (file)
@@ -307,6 +307,3 @@ int Renderer_Widget_HandleMessage(tWindow *Target, int Msg, int Len, void *Data)
        }
 }
 
-
-
-
index e03c41c..b7e78e5 100644 (file)
@@ -16,6 +16,7 @@ typedef struct sIPCMsg_Return tIPCMsg_Return;
 typedef struct sIPCMsg_CreateWin       tIPCMsg_CreateWin;
 typedef struct sIPCMsg_ShowWindow      tIPCMsg_ShowWindow;
 typedef struct sIPCMsg_SetWindowPos    tIPCMsg_SetWindowPos;
+typedef struct sIPCMsg_SendMsg tIPCMsg_SendMsg;
 
 /**
  * \name Flags for IPC Messages
@@ -48,6 +49,14 @@ struct sIPCMsg_CreateWin
        char    Renderer[];
 };
 
+struct sIPCMsg_SendMsg
+{
+       uint32_t        Dest;
+        int    ID;
+       uint16_t        Length;
+       char    Data[];
+};
+
 struct sIPCMsg_ShowWindow
 {
        uint32_t        bShow;
diff --git a/Usermode/Applications/axwin3_src/include/widget_messages.h b/Usermode/Applications/axwin3_src/include/widget_messages.h
new file mode 100644 (file)
index 0000000..e4f09ed
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Acess2 Window Manager v3
+ * - By John Hodge (thePowersGang)
+ *
+ * widget_messages.h
+ * - AxWin2 Widget port
+ */
+#ifndef _WIDGET_MESSAGES_H_
+#define _WIDGET_MESSAGES_H_
+
+enum
+{
+       MSG_WIDGET_CREATE,
+       MSG_WIDGET_DELETE,
+       MSG_WIDGET_SETTEXT
+};
+
+
+typedef struct
+{
+       uint32_t        Parent;
+       uint32_t        NewID;
+       char    DebugName[];
+} tWidgetMsg_Create;
+
+#endif
+
index 4275356..f7fd257 100644 (file)
@@ -19,6 +19,7 @@ struct sAxWin3_Window
 };
 
 extern void    *AxWin3_int_GetDataPtr(tHWND Window);
+extern uint32_t        AxWin3_int_GetWindowID(tHWND Window);
 
 #endif
 
index 1059a0a..c3c6be7 100644 (file)
@@ -69,6 +69,14 @@ tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callba
        return old;
 }
 
+uint32_t AxWin3_int_GetWindowID(tHWND Window)
+{
+       if(Window)
+               return Window->ServerID;
+       else
+               return -1;
+}
+
 tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes)
 {
        tAxWin_IPCMessage       *ret;
@@ -76,10 +84,7 @@ tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int
        ret = malloc( sizeof(tAxWin_IPCMessage) + ExtraBytes );
        ret->Flags = Flags;
        ret->ID = Message;
-       if(Window)
-               ret->Window = Window->ServerID;
-       else
-               ret->Window = -1;
+       ret->Window = AxWin3_int_GetWindowID(Window);
        ret->Size = ExtraBytes;
        return ret;
 }
index 0c945d3..9eb55bb 100644 (file)
@@ -9,6 +9,7 @@
 #include <axwin3/widget.h>
 #include "include/internal.h"
 #include <stdlib.h>
+#include <widget_messages.h>
 
 // === STRUCTURES ===
 struct sAxWin3_Widget
@@ -22,6 +23,7 @@ typedef struct
 {
         int    nElements;
        tAxWin3_Widget  **Elements;
+        int    FirstFreeID;
        // Callbacks for each element
 } tWidgetWindowInfo;
 
@@ -45,6 +47,7 @@ tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags)
        info->nElements = 1;
        info->Elements = malloc(sizeof(tAxWin3_Widget*));
        info->Elements[0] = (void*)(info + 1);  // Get end of *info
+       info->FirstFreeID = 1;
 
        AxWin3_ResizeWindow(ret, W, H);
        
@@ -68,7 +71,46 @@ tAxWin3_Widget *AxWin3_Widget_GetRoot(tHWND Window)
 
 tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Flags, const char *DebugName)
 {
+        int    newID;
+       tWidgetWindowInfo       *info;
+       tAxWin3_Widget  *ret;
+
+       if(!Parent)     return NULL;
+
+       info = AxWin3_int_GetDataPtr(Parent->Window);
+       
        // Assign ID
+       // TODO: Atomicity
+       for( newID = info->FirstFreeID; newID < info->nElements; newID ++ )
+       {
+               if( info->Elements[newID] == NULL )
+                       break;
+       }
+       if( info->Elements[newID] )
+       {
+               info->nElements ++;
+               info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements);
+               newID = info->nElements - 1;
+       }
+       info->Elements[newID] = (void*)-1;
        
-       return NULL;
+       // Create new widget structure
+       ret = malloc(sizeof(tAxWin3_Widget));
+       ret->Window = Parent->Window;
+       ret->ID = newID;
+       ret->Callback = NULL;
+
+       info->Elements[newID] = ret;
+
+       // Send create widget message
+       {
+               char    tmp[sizeof(tWidgetMsg_Create)+1];
+               tWidgetMsg_Create       *msg = (void*)tmp;
+               msg->Parent = Parent->ID;
+               msg->NewID = newID;
+               msg->DebugName[0] = '\0';
+               AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATE, sizeof(tmp), tmp);
+       }
+
+       return ret;
 }
index 29038ae..fc5ed64 100644 (file)
@@ -125,6 +125,16 @@ void *AxWin3_int_GetDataPtr(tHWND Window)
        return &Window->Data;
 }
 
+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->Dest = AxWin3_int_GetWindowID(Destination);
+}
+
 void AxWin3_ShowWindow(tHWND Window, int bShow)
 {
        tAxWin_IPCMessage       *msg;
index b4ad45a..9066cde 100644 (file)
@@ -44,7 +44,7 @@ extern tHWND  AxWin3_CreateWindow(
 extern void    AxWin3_DestroyWindow(tHWND Window);
 
 // --- Core window management functions
-extern void    AxWin3_SendMessage(tHWND Window, int Length, void *Data);
+extern void    AxWin3_SendMessage(tHWND Window, tHWND Dest, int Message, int Length, void *Data);
 extern void    AxWin3_ShowWindow(tHWND Window, int bShow);
 extern void    AxWin3_SetWindowPos(tHWND Window, short X, short Y, short W, short H);
 extern void    AxWin3_MoveWindow(tHWND Window, short X, short Y);

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