From 507f19941f45bca7c1de783a394f56b15f10be4d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 12 Oct 2012 20:30:01 +0800 Subject: [PATCH] Usermode - Working on AxWin3 SubWin widget (also API change for SysSpawn) --- .../Applications/axwin3_src/Interface/main.c | 2 +- Usermode/Applications/axwin3_src/WM/Makefile | 1 + .../Applications/axwin3_src/WM/include/wm.h | 1 + Usermode/Applications/axwin3_src/WM/ipc.c | 1 - .../axwin3_src/WM/renderers/richtext.c | 3 +- .../axwin3_src/WM/renderers/widget.c | 99 ++++++++++++------- .../axwin3_src/WM/renderers/widget/subwin.c | 23 +++++ Usermode/Applications/axwin3_src/WM/wm.c | 6 ++ .../axwin3_src/libaxwin3.so_src/r_widget.c | 4 +- Usermode/Applications/gui_ate_src/main.c | 14 +-- Usermode/Applications/telnetd_src/main.c | 2 +- .../include_exp/acess/syscall_types.h | 40 ++++++++ .../ld-acess.so_src/include_exp/sys/types.h | 27 +---- .../include_exp/axwin3/widget.h | 2 +- 14 files changed, 151 insertions(+), 74 deletions(-) create mode 100644 Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c create mode 100644 Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h diff --git a/Usermode/Applications/axwin3_src/Interface/main.c b/Usermode/Applications/axwin3_src/Interface/main.c index 8695d49b..e8b58348 100644 --- a/Usermode/Applications/axwin3_src/Interface/main.c +++ b/Usermode/Applications/axwin3_src/Interface/main.c @@ -113,7 +113,7 @@ void mainmenu_app_textedit(void *unused) { const char *args[] = {"ate",NULL}; // _SysDebug("TODO: Launch text editor"); - _SysSpawn("/Acess/Apps/AxWin/3.0/ate", args, (const char **)gEnvion, 0, NULL); + _SysSpawn("/Acess/Apps/AxWin/3.0/ate", args, (const char **)gEnvion, 0, NULL, NULL); } void mainmenu_app_terminal(void *unused) diff --git a/Usermode/Applications/axwin3_src/WM/Makefile b/Usermode/Applications/axwin3_src/WM/Makefile index b39f68b2..972f72fe 100644 --- a/Usermode/Applications/axwin3_src/WM/Makefile +++ b/Usermode/Applications/axwin3_src/WM/Makefile @@ -21,6 +21,7 @@ OBJ += renderers/widget/image.o OBJ += renderers/widget/disptext.o OBJ += renderers/widget/textinput.o OBJ += renderers/widget/spacer.o +OBJ += renderers/widget/subwin.o LDFLAGS += -limage_sif -luri -lnet diff --git a/Usermode/Applications/axwin3_src/WM/include/wm.h b/Usermode/Applications/axwin3_src/WM/include/wm.h index 7807c901..27890bab 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm.h @@ -45,6 +45,7 @@ typedef struct sIPC_Client tIPC_Client; // === FUNCTIONS === // --- Management extern tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int Flags, const char *Renderer); +extern tWindow *WM_GetWindowByID(tWindow *Requester, uint32_t ID); extern void WM_Invalidate(tWindow *Window); extern void WM_SetWindowTitle(tWindow *Window, const char *Title); extern void WM_FocusWindow(tWindow *Destination); diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c index 1d4ac33c..bc38fb55 100644 --- a/Usermode/Applications/axwin3_src/WM/ipc.c +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -244,7 +244,6 @@ tWindow *IPC_int_GetWindow(tIPC_Client *Client, uint32_t WindowID) return NULL; if( WindowID >= Client->nWindows ) { -// _SysDebug("Window %i out of range for %p (%i)", WindowID, Client, Client->nWindows); return NULL; } diff --git a/Usermode/Applications/axwin3_src/WM/renderers/richtext.c b/Usermode/Applications/axwin3_src/WM/renderers/richtext.c index 9ad384c3..eca5765b 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/richtext.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/richtext.c @@ -105,7 +105,8 @@ void Renderer_RichText_RenderText(tWindow *Window, int Line, const char *Text) if( ch == 0 ) break; if( ch <=3 && bRender ) { // Render previous characters - curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, oldtext, Text - oldtext, fg, bg); + curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, + oldtext, Text - oldtext, fg, bg); oldtext = Text; } switch(ch) diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget.c b/Usermode/Applications/axwin3_src/WM/renderers/widget.c index 46b3198a..88529543 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget.c @@ -423,11 +423,52 @@ tElement *Widget_GetElementById(tWidgetWin *Info, uint32_t ID) return ele; } +tElement *Widget_int_Create(tWidgetWin *Info, tElement *Parent, int ID, int Type, int Flags) +{ + if( Widget_GetElementById(Info, ID) ) + return NULL; + + // Create new element + tElement *new = calloc(sizeof(tElement), 1); + new->Window = Parent->Window; + new->ID = ID; + new->Type = Type; + new->Parent = Parent; + new->Flags = Flags; + new->PaddingT = 2; + new->PaddingB = 2; + new->PaddingL = 2; + new->PaddingR = 2; + new->CachedX = -1; + + if( gaWM_WidgetTypes[Type]->Init ) + gaWM_WidgetTypes[Type]->Init(new); + + // Add to parent's list + if(Parent->LastChild) + Parent->LastChild->NextSibling = new; + else + Parent->FirstChild = new; + Parent->LastChild = new; + + // Add to info + { + tElement *ele, *prev = NULL; + for(ele = Info->ElementTable[new->ID % Info->TableSize]; ele; prev = ele, ele = ele->ListNext); + if(prev) + prev->ListNext = new; + else + Info->ElementTable[new->ID % Info->TableSize] = new; + } + + return new; +} + // --- Message Handlers --- void Widget_NewWidget(tWidgetWin *Info, size_t Len, const tWidgetMsg_Create *Msg) { const int max_debugname_len = Len - sizeof(tWidgetMsg_Create); - tElement *parent, *new; + tElement *parent; // Sanity check if( Len < sizeof(*Msg) ) @@ -452,43 +493,28 @@ void Widget_NewWidget(tWidgetWin *Info, size_t Len, const tWidgetMsg_Create *Msg return ; } - // Check if the ID is already in use - if( Widget_GetElementById(Info, Msg->NewID) ) - return ; + Widget_int_Create(Info, parent, Msg->NewID, Msg->Type, Msg->Flags); - // Create new element - new = calloc(sizeof(tElement), 1); - new->Window = parent->Window; - new->ID = Msg->NewID; - new->Type = Msg->Type; - new->Parent = parent; - new->Flags = Msg->Flags; - new->PaddingT = 2; - new->PaddingB = 2; - new->PaddingL = 2; - new->PaddingR = 2; - new->CachedX = -1; - - if( gaWM_WidgetTypes[new->Type]->Init ) - gaWM_WidgetTypes[new->Type]->Init(new); - - // Add to parent's list - if(parent->LastChild) - parent->LastChild->NextSibling = new; - else - parent->FirstChild = new; - parent->LastChild = new; + Widget_UpdateMinDims(parent); +} - // Add to info - { - tElement *ele, *prev = NULL; - for(ele = Info->ElementTable[new->ID % Info->TableSize]; ele; prev = ele, ele = ele->ListNext); - if(prev) - prev->ListNext = new; - else - Info->ElementTable[new->ID % Info->TableSize] = new; - } +void Widget_NewWidgetSubwin(tWidgetWin *Info, size_t Len, const tWidgetMsg_CreateSubWin *Msg) +{ + const int max_debugname_len = Len - sizeof(tWidgetMsg_CreateSubWin); + tElement *parent, *new; + // Sanity check + if( Len < sizeof(*Msg) ) + return ; + if( strnlen(Msg->DebugName, max_debugname_len) == max_debugname_len ) + return ; + + parent = Widget_GetElementById(Info, Msg->Parent); + if(!parent) return; + if( Widget_GetElementById(Info, Msg->NewID) ) return ; + + new = Widget_int_Create(Info, parent, Msg->NewID, Msg->Type, Msg->Flags); + new->Data = WM_GetWindowByID(parent->Window, Msg->WindowHandle); Widget_UpdateMinDims(parent); } @@ -689,6 +715,9 @@ int Renderer_Widget_HandleMessage(tWindow *Target, int Msg, int Len, const void case MSG_WIDGET_CREATE: Widget_NewWidget(info, Len, Data); return 0; + case MSG_WIDGET_CREATESUBWIN: + Widget_NewWidgetSubwin(info, Len, Data); + return 0; // Delete a widget case MSG_WIDGET_DELETE: diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c new file mode 100644 index 00000000..4cdaabad --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c @@ -0,0 +1,23 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * renderer/widget/subwin.c + * - Embedded Window Widget Type + */ +#include +#include "./common.h" +#include "./colours.h" + +void Widget_SubWin_Render(tWindow *Window, tElement *Element) +{ + // Note: Doesn't actually render, but does poke the child window + WM_MoveWindow(Element->Data, Element->CachedX, Element->CachedY); + WM_ResizeWindow(Element->Data, Element->CachedW, Element->CachedH); +} + +DEFWIDGETTYPE(ELETYPE_SUBWIN, + WIDGETTYPE_FLAG_NOCHILDREN, + .Render = Widget_SubWin_Render + ) + diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index 24781512..cb591545 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -15,6 +15,7 @@ // === IMPORTS === extern void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, int Msg, int Len, const void *Data); +extern tWindow *IPC_int_GetWindow(tIPC_Client *Client, uint32_t ID); // === GLOBALS === tWMRenderer *gpWM_Renderers; @@ -92,6 +93,11 @@ tWindow *WM_CreateWindow(tWindow *Parent, tIPC_Client *Client, uint32_t ID, int return ret; } +tWindow *WM_GetWindowByID(tWindow *Requester, uint32_t ID) +{ + return IPC_int_GetWindow(Requester->Client, ID); +} + tWindow *WM_CreateWindowStruct(size_t ExtraSize) { tWindow *ret; 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 10375222..c050e90c 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c @@ -159,7 +159,7 @@ tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Fl return ret; } -tAxWin3_Widget *AxWin3_Widget_AddWidget_SubWindow(tAxWin3_Widget *Parent, tHWND Window, const char *DebugName) +tAxWin3_Widget *AxWin3_Widget_AddWidget_SubWindow(tAxWin3_Widget *Parent, tHWND Window, int Flags, const char *DbgName) { tWidgetWindowInfo *info = AxWin3_int_GetDataPtr(Parent->Window); int newID = AxWin3_Widget_int_AllocateID(info); @@ -176,7 +176,7 @@ tAxWin3_Widget *AxWin3_Widget_AddWidget_SubWindow(tAxWin3_Widget *Parent, tHWND msg->Parent = Parent->ID; msg->NewID = newID; msg->Type = ELETYPE_SUBWIN; - msg->Flags = 0; // TODO: Flags + msg->Flags = Flags; // TODO: Flags msg->WindowHandle = AxWin3_int_GetWindowID(Window); msg->DebugName[0] = '\0'; AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATESUBWIN, sizeof(tmp), tmp); diff --git a/Usermode/Applications/gui_ate_src/main.c b/Usermode/Applications/gui_ate_src/main.c index 75f6c6ed..77800752 100644 --- a/Usermode/Applications/gui_ate_src/main.c +++ b/Usermode/Applications/gui_ate_src/main.c @@ -33,7 +33,8 @@ int main(int argc, char *argv[]) AxWin3_Connect(NULL); // --- Build up window - gMainWindow = AxWin3_Widget_CreateWindow(NULL, 320, 200, ELEFLAG_VERTICAL); + gMainWindow = AxWin3_Widget_CreateWindow(NULL, 400, 600, ELEFLAG_VERTICAL); + AxWin3_SetWindowTitle(gMainWindow, "Acess Text Editor"); // TODO: Update title with other info gMainWindow_Root = AxWin3_Widget_GetRoot(gMainWindow); //gMainWindow_MenuBar = AxWin3_Menu_Create(gMainWindow); @@ -41,10 +42,10 @@ int main(int argc, char *argv[]) // TODO: Populate menu // Create toolbar - gMainWindow_Toolbar = AxWin3_Widget_AddWidget(gMainWindow_Root, ELETYPE_TOOLBAR, 0, "Toolbar"); + gMainWindow_Toolbar = AxWin3_Widget_AddWidget(gMainWindow_Root, ELETYPE_TOOLBAR, ELEFLAG_NOSTRETCH, "Toolbar"); add_toolbar_button(gMainWindow_Toolbar, "BtnNew", Toolbar_New); add_toolbar_button(gMainWindow_Toolbar, "BtnOpen", Toolbar_Open); - add_toolbar_button(gMainWindow_Toolbar, "BtnOpen", Toolbar_Save); + add_toolbar_button(gMainWindow_Toolbar, "BtnSave", Toolbar_Save); AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_SPACER, 0, ""); add_toolbar_button(gMainWindow_Toolbar, "BtnUndo", NULL); add_toolbar_button(gMainWindow_Toolbar, "BtnRedo", NULL); @@ -59,7 +60,7 @@ int main(int argc, char *argv[]) // TODO: Tab control? gMainWindow_TextArea = AxWin3_RichText_CreateWindow(gMainWindow, 0); - AxWin3_Widget_AddWidget_SubWindow(gMainWindow_Root, gMainWindow_TextArea, "TextArea"); + AxWin3_Widget_AddWidget_SubWindow(gMainWindow_Root, gMainWindow_TextArea, 0, "TextArea"); AxWin3_RichText_SetKeyHandler (gMainWindow_TextArea, TextArea_KeyHandler); AxWin3_RichText_SetMouseHandler (gMainWindow_TextArea, TextArea_MouseHandler); AxWin3_RichText_SetBackground (gMainWindow_TextArea, 0xFFFFFF); @@ -90,9 +91,10 @@ int TextArea_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col void add_toolbar_button(tAxWin3_Widget *Toolbar, const char *Ident, tAxWin3_Widget_FireCb Callback) { - tAxWin3_Widget *btn = AxWin3_Widget_AddWidget(Toolbar, ELETYPE_BUTTON, 0, Ident); + tAxWin3_Widget *btn = AxWin3_Widget_AddWidget(Toolbar, ELETYPE_BUTTON, ELEFLAG_NOSTRETCH, Ident); + tAxWin3_Widget *txt = AxWin3_Widget_AddWidget(btn, ELETYPE_TEXT, 0, Ident); // TODO: Get image / text using `Ident` as a lookup key - AxWin3_Widget_SetText(btn, Ident); + AxWin3_Widget_SetText(txt, Ident); AxWin3_Widget_SetFireHandler(btn, Callback); } diff --git a/Usermode/Applications/telnetd_src/main.c b/Usermode/Applications/telnetd_src/main.c index 8a66ad7a..a62d0dd3 100644 --- a/Usermode/Applications/telnetd_src/main.c +++ b/Usermode/Applications/telnetd_src/main.c @@ -132,7 +132,7 @@ void Server_NewClient(int FD) { int fds[3] = {clt->stdin, clt->stdout, clt->stdout}; const char *argv[] = {NULL}; - _SysSpawn("/Acess/SBin/login", argv, argv, 3, fds); + _SysSpawn("/Acess/SBin/login", argv, argv, 3, fds, NULL); } } diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h new file mode 100644 index 00000000..2da73331 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h @@ -0,0 +1,40 @@ +/* + * Acess2 Dynamic Linker + * - By John Hodge (thePowersGang) + * + * acess/syscall_types.h + * - Structures used for syscalls + */ + +#ifndef _ACESS__SYSCALL_TYPES_H_ +#define _ACESS__SYSCALL_TYPES_H_ + +struct s_sysACL { + unsigned long object; /*!< Group or user (bit 31 determines) */ + unsigned long perms; /*!< Inverted by bit 31 */ +}; +struct s_sysFInfo { + unsigned int mount; + unsigned long long inode; + unsigned int uid; + unsigned int gid; + unsigned int flags; + unsigned long long size; + time_t atime; + time_t mtime; + time_t ctime; + int numacls; + struct s_sysACL acls[]; +} __attribute__((packed)); +typedef struct s_sysFInfo t_sysFInfo; +typedef struct s_sysACL t_sysACL; + +struct s_sys_spawninfo +{ + unsigned int flags; + unsigned int uid; + unsigned int gid; +}; + +#endif + diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h index 78cf0351..f71aed21 100644 --- a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h +++ b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h @@ -30,32 +30,7 @@ typedef struct fd_set_ent_t flags[FD_SETSIZE/16]; } fd_set; -struct s_sysACL { - unsigned long object; /*!< Group or user (bit 31 determines) */ - unsigned long perms; /*!< Inverted by bit 31 */ -}; -struct s_sysFInfo { - unsigned int mount; - unsigned long long inode; - unsigned int uid; - unsigned int gid; - unsigned int flags; - unsigned long long size; - time_t atime; - time_t mtime; - time_t ctime; - int numacls; - struct s_sysACL acls[]; -} __attribute__((packed)); -typedef struct s_sysFInfo t_sysFInfo; -typedef struct s_sysACL t_sysACL; - -struct s_sys_spawninfo -{ - unsigned int flags; - unsigned int uid; - unsigned int gid; -}; +#include "../acess/syscall_types.h" extern void FD_ZERO(fd_set *fdsetp); extern void FD_CLR(int fd, fd_set *fdsetp); diff --git a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h index eb9aff61..58386ebd 100644 --- a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h +++ b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h @@ -26,7 +26,7 @@ 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 tAxWin3_Widget *AxWin3_Widget_AddWidget_SubWindow(tAxWin3_Widget *Parent, tHWND Window, const char *DebugName); +extern tAxWin3_Widget *AxWin3_Widget_AddWidget_SubWindow(tAxWin3_Widget *Parent, tHWND Window, int Flags, const char *DebugName); extern void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget); // --- Callbacks -- 2.20.1