* main.c
* - Interface core
*/
+#include <acess/sys.h>
#include <stdlib.h>
#include <axwin3/axwin.h>
#include <axwin3/widget.h>
tAxWin3_Widget *gSidebarRoot;
// === CODE ===
-int sidebar_callback(tHWND Window, int Length, void *Data)
+int systembutton_fire(tAxWin3_Widget *Widget)
{
+ _SysDebug("SystemButton pressed");
return 0;
}
// - Main menu
btn = AxWin3_Widget_AddWidget(gSidebarRoot, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH, "SystemButton");
AxWin3_Widget_SetSize(btn, SIDEBAR_WIDTH);
+ AxWin3_Widget_SetFireHandler(btn, systembutton_fire);
txt = AxWin3_Widget_AddWidget(btn, ELETYPE_IMAGE, 0, "SystemLogo");
AxWin3_Widget_SetText(txt, "file:///Acess/Apps/AxWin/3.0/AcessLogoSmall.sif");
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);
+extern void AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg);
#endif
{
msg = AxWin3_int_GetIPCMessage();
if(!msg) continue;
-
+
// TODO: Handle message
_SysDebug("oh look, a message (Type=%i, Window=%i, Len=%i)",
msg->ID, msg->Window, msg->Size);
+
+ AxWin3_int_HandleMessage( msg );
free(msg);
}
{
tHWND Window;
uint32_t ID;
- tAxWin3_Widget_Callback Callback;
+ // Callbacks
+ tAxWin3_Widget_FireCb Fire;
+ tAxWin3_Widget_KeyUpDownCb KeyUpDown;
+ tAxWin3_Widget_KeyFireCb KeyFire;
+ tAxWin3_Widget_MouseMoveCb MouseMove;
+ tAxWin3_Widget_MouseBtnCb MouseButton;
};
typedef struct
} tWidgetWindowInfo;
// === CODE ===
-int AxWin3_Widget_MessageHandler(tHWND Window, int Size, void *Data)
+tAxWin3_Widget *AxWin3_Widget_int_GetElementByID(tHWND Window, uint32_t ID)
{
- return 0;
+ tWidgetWindowInfo *info;
+ if(!Window) return NULL;
+
+ info = AxWin3_int_GetDataPtr(Window);
+ if(ID >= info->nElements) return NULL;
+
+ return info->Elements[ID];
+}
+
+int AxWin3_Widget_MessageHandler(tHWND Window, int MessageID, int Size, void *Data)
+{
+ tAxWin3_Widget *widget;
+
+ switch(MessageID)
+ {
+ case MSG_WIDGET_FIRE: {
+ tWidgetMsg_Fire *msg = Data;
+ if(Size < sizeof(*msg)) return -1;
+ widget = AxWin3_Widget_int_GetElementByID(Window, msg->WidgetID);
+ if(widget->Fire) widget->Fire(widget);
+
+ return 0; }
+ default:
+ return 0;
+ }
}
tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags)
info->Elements[newID] = (void*)-1;
// Create new widget structure
- ret = malloc(sizeof(tAxWin3_Widget));
+ ret = calloc(sizeof(tAxWin3_Widget), 1);
ret->Window = Parent->Window;
ret->ID = newID;
- ret->Callback = NULL;
info->Elements[newID] = ret;
free(Widget);
}
+// --- Callbacks
+void AxWin3_Widget_SetFireHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_FireCb Callback)
+{
+ if(!Widget) return;
+ Widget->Fire = Callback;
+}
+
+void AxWin3_Widget_SetKeyHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_KeyUpDownCb Callback)
+{
+ if(!Widget) return;
+ Widget->KeyUpDown = Callback;
+}
+
+void AxWin3_Widget_SetKeyFireHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_KeyFireCb Callback)
+{
+ if(!Widget) return;
+ Widget->KeyFire = Callback;
+}
+
+void AxWin3_Widget_SetMouseMoveHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_MouseMoveCb Callback)
+{
+ if(!Widget) return;
+ Widget->MouseMove = Callback;
+}
+
+void AxWin3_Widget_SetMouseButtonHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_MouseBtnCb Callback)
+{
+ if(!Widget) return;
+ Widget->MouseButton = Callback;
+}
+
+// --- Manipulation
void AxWin3_Widget_SetFlags(tAxWin3_Widget *Widget, int FlagSet, int FlagMask)
{
tWidgetMsg_SetFlags msg;
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;
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_SendMessage(tHWND Window, tHWND Destination, int Message, int Length, void *Data)
{
tAxWin_IPCMessage *msg;
typedef void (*tAxWin3_MessageCallback)(int SourceTID, int Length);
-typedef int (*tAxWin3_WindowMessageHandler)(tHWND Window, int Length, void *Data);
+typedef int (*tAxWin3_WindowMessageHandler)(tHWND Window, int Message, int Length, void *Data);
// --- Connection management
extern void AxWin3_Connect(const char *ServerDesc);
typedef struct sAxWin3_Widget tAxWin3_Widget;
-typedef int (*tAxWin3_Widget_Callback)(tAxWin3_Widget Widget, int EventType, unsigned long EventArg);
+// --- Callback types
+typedef int (*tAxWin3_Widget_FireCb)(tAxWin3_Widget *Widget);
+typedef int (*tAxWin3_Widget_KeyUpDownCb)(tAxWin3_Widget *Widget, int KeySym);
+typedef int (*tAxWin3_Widget_KeyFireCb)(tAxWin3_Widget *Widget, int KeySym, int Character);
+typedef int (*tAxWin3_Widget_MouseMoveCb)(tAxWin3_Widget *Widget, int X, int Y);
+typedef int (*tAxWin3_Widget_MouseBtnCb)(tAxWin3_Widget *Widget, int X, int Y, int Button, int bPressed);
+// --- Windows
extern tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags);
extern void AxWin3_Widget_DestroyWindow(tHWND Window);
extern tAxWin3_Widget *AxWin3_Widget_GetRoot(tHWND Window);
+// --- Element Creation
extern tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Flags, const char *DebugName);
extern void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget);
+// --- Callbacks
+extern void AxWin3_Widget_SetFireHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_FireCb Callback);
+extern void AxWin3_Widget_SetKeyHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_KeyUpDownCb Callback);
+extern void AxWin3_Widget_SetKeyFireHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_KeyFireCb Callback);
+extern void AxWin3_Widget_SetMouseMoveHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_MouseMoveCb Callback);
+extern void AxWin3_Widget_SetMouseButtonHandler(tAxWin3_Widget *Widget, tAxWin3_Widget_MouseBtnCb Callback);
+// --- Manipulation
extern void AxWin3_Widget_SetFlags(tAxWin3_Widget *Widget, int FlagSet, int FlagMask);
extern void AxWin3_Widget_SetSize(tAxWin3_Widget *Widget, int Size);
extern void AxWin3_Widget_SetText(tAxWin3_Widget *Widget, const char *Text);