#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
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
char Renderer[];
};
+struct sIPCMsg_SendMsg
+{
+ uint32_t Dest;
+ int ID;
+ uint16_t Length;
+ char Data[];
+};
+
struct sIPCMsg_ShowWindow
{
uint32_t bShow;
--- /dev/null
+/*
+ * 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
+
};
extern void *AxWin3_int_GetDataPtr(tHWND Window);
+extern uint32_t AxWin3_int_GetWindowID(tHWND Window);
#endif
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;
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;
}
#include <axwin3/widget.h>
#include "include/internal.h"
#include <stdlib.h>
+#include <widget_messages.h>
// === STRUCTURES ===
struct sAxWin3_Widget
{
int nElements;
tAxWin3_Widget **Elements;
+ int FirstFreeID;
// Callbacks for each element
} tWidgetWindowInfo;
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);
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;
}
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;
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);