From: John Hodge Date: Tue, 8 Nov 2011 08:13:12 +0000 (+0800) Subject: Usermode/AxWin3 - Managed to pass input all the way back to client code :) X-Git-Tag: rel0.14~130 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=1314c5a4586315b526d84500d5b2ef5f7800b703;p=tpg%2Facess2.git Usermode/AxWin3 - Managed to pass input all the way back to client code :) --- diff --git a/Usermode/Applications/axwin3_src/Interface/main.c b/Usermode/Applications/axwin3_src/Interface/main.c index 4e4833be..19cd90e7 100644 --- a/Usermode/Applications/axwin3_src/Interface/main.c +++ b/Usermode/Applications/axwin3_src/Interface/main.c @@ -5,6 +5,7 @@ * main.c * - Interface core */ +#include #include #include #include @@ -19,8 +20,9 @@ tHWND gSidebar; tAxWin3_Widget *gSidebarRoot; // === CODE === -int sidebar_callback(tHWND Window, int Length, void *Data) +int systembutton_fire(tAxWin3_Widget *Widget) { + _SysDebug("SystemButton pressed"); return 0; } @@ -50,6 +52,7 @@ void create_sidebar(void) // - 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"); diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h index 4b9f2af1..6f5fcd56 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/include/ipc.h @@ -15,6 +15,7 @@ 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); +extern void AxWin3_int_HandleMessage(tAxWin_IPCMessage *Msg); #endif diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c index 3c7d109a..fcd572aa 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c @@ -27,10 +27,12 @@ void AxWin3_MainLoop(void) { 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); } diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c index 6fa8adaf..f63e0f7f 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c @@ -17,7 +17,12 @@ struct sAxWin3_Widget { 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 @@ -30,9 +35,33 @@ 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) @@ -99,10 +128,9 @@ tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Fl 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; @@ -135,6 +163,38 @@ void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget) 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; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c index 8b279668..fd91e883 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/wm.c @@ -40,6 +40,17 @@ 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; @@ -125,6 +136,24 @@ 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_SendMessage(tHWND Window, tHWND Destination, int Message, int Length, void *Data) { tAxWin_IPCMessage *msg; diff --git a/Usermode/include/axwin3/axwin.h b/Usermode/include/axwin3/axwin.h index 9066cde5..7d1d3f47 100644 --- a/Usermode/include/axwin3/axwin.h +++ b/Usermode/include/axwin3/axwin.h @@ -13,7 +13,7 @@ typedef unsigned int tAxWin3_Colour; // TODO: Actual 32-bit 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); diff --git a/Usermode/include/axwin3/widget.h b/Usermode/include/axwin3/widget.h index ca9b40fd..fca8f049 100644 --- a/Usermode/include/axwin3/widget.h +++ b/Usermode/include/axwin3/widget.h @@ -12,15 +12,29 @@ 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);