From 134ea1493847ea65896430c446c471874d0cf4fa Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 9 Oct 2012 11:11:13 +0800 Subject: [PATCH] AxWin - Adding clientside RichText render --- AcessNative/ld-acess_src/exports.c | 4 +- .../axwin3_src/include/richtext_messages.h | 65 +++++++++++++ .../axwin3_src/include/widget_messages.h | 11 +++ .../axwin3_src/libaxwin3.so_src/Makefile | 1 + .../axwin3_src/libaxwin3.so_src/r_richtext.c | 91 +++++++++++++++++++ .../axwin3_src/libaxwin3.so_src/r_widget.c | 75 +++++++++++---- Usermode/Applications/gui_ate_src/main.c | 40 +++++--- .../include_exp/axwin3/richtext.h | 22 +++-- 8 files changed, 263 insertions(+), 46 deletions(-) create mode 100644 Usermode/Applications/axwin3_src/include/richtext_messages.h create mode 100644 Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 7e13134b..90eef865 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -342,9 +342,11 @@ const tSym caBuiltinSymbols[] = { DEFSYM(sleep), DEFSYM(waittid), + DEFSYM(gettid), DEFSYM(setuid), DEFSYM(setgid), - DEFSYM(gettid), + DEFSYM(getuid), + DEFSYM(getgid), DEFSYM(SysSendMessage), DEFSYM(SysGetMessage), diff --git a/Usermode/Applications/axwin3_src/include/richtext_messages.h b/Usermode/Applications/axwin3_src/include/richtext_messages.h new file mode 100644 index 00000000..6dcf9a2c --- /dev/null +++ b/Usermode/Applications/axwin3_src/include/richtext_messages.h @@ -0,0 +1,65 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * richtext_messages.h + * - Formatted Text Field + */ +#ifndef _RICHTEXT_MESSAGES_H_ +#define _RICHTEXT_MESSAGES_H_ + +enum eRichText_Attrs { + _ATTR_DEFBG, + _ATTR_DEFFG, + _ATTR_SCROLL, + _ATTR_LINECOUNT, + _ATTR_COLCOUNT, + _ATTR_CURSOR, + _ATTR_CURSORBLINK, + _ATTR_CURSORPOS, +}; + +enum +{ + // Calls + MSG_RICHTEXT_SETATTR, + MSG_RICHTEXT_SETFONT, + MSG_RICHTEXT_DELLINE, + MSG_RICHTEXT_ADDLINE, + + // Events + + MSG_RICHTEXT_SENDLINE, // Bi-directional + MSG_RICHTEXT_REQLINE // Bi-directional +}; + +struct sRichTextMsg_SetAttr +{ + uint32_t Attr; + uint32_t Value; +}; + +struct sRichTextMsg_SetFont +{ + uint16_t Size; + char Name[]; +}; + +struct sRichTextMsg_AddDelLine +{ + uint32_t Line; +}; + +struct sRichTextMsg_ReqLine +{ + uint32_t Line; +}; + +struct sRichTextMsg_SendLine +{ + uint32_t Line; + char LineData[]; +}; + +#endif + diff --git a/Usermode/Applications/axwin3_src/include/widget_messages.h b/Usermode/Applications/axwin3_src/include/widget_messages.h index 0a4b2505..f36c729c 100644 --- a/Usermode/Applications/axwin3_src/include/widget_messages.h +++ b/Usermode/Applications/axwin3_src/include/widget_messages.h @@ -12,6 +12,7 @@ enum { // Control (Client->Server) messages MSG_WIDGET_CREATE = 0x1000, + MSG_WIDGET_CREATESUBWIN, MSG_WIDGET_DELETE, MSG_WIDGET_SETFOCUS, MSG_WIDGET_SETFLAGS, @@ -39,6 +40,16 @@ typedef struct char DebugName[]; } tWidgetMsg_Create; +typedef struct +{ + uint32_t Parent; + uint32_t NewID; + uint32_t Type; + uint32_t Flags; + uint32_t WindowHandle; + char DebugName[]; +} tWidgetMsg_CreateSubWin; + typedef struct { uint32_t WidgetID; diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile b/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile index 3d37b5b5..f425cc75 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/Makefile @@ -8,6 +8,7 @@ CFLAGS += -Wall LDFLAGS += -lc -soname libaxwin3.so OBJ = main.o msg.o wm.o r_widget.o r_menu.o +OBJ += r_richtext.o BIN = libaxwin3.so include ../../../Libraries/Makefile.tpl diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c new file mode 100644 index 00000000..9ef16806 --- /dev/null +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_richtext.c @@ -0,0 +1,91 @@ +/* + * AxWin3 Interface Library + * - By John Hodge (thePowersGang) + * + * r_richtext.c + * - Formatted Text window type + */ +#include +#include +#include "include/internal.h" +#include + +// === TYPES === +typedef struct sRichText_Window +{ + tAxWin3_RichText_KeyHandler KeyCallback; + tAxWin3_RichText_MouseHandler MouseCallback; +// tAxWin3_RichText_LineHandler LineHandler; +} tRichText_Window; + +// === CODE === +int AxWin3_RichText_MessageHandler(tHWND Window, int MessageID, int Size, void *Data) +{ + return 0; +} + +static void _SendAttrib(tHWND Window, int Attr, uint32_t Value) +{ + struct sRichTextMsg_SetAttr msg; + msg.Attr = Attr; + msg.Value = Value; + AxWin3_SendMessage(Window, Window, MSG_RICHTEXT_SETATTR, sizeof(msg), &msg); +} + +tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags) +{ + tHWND ret = AxWin3_CreateWindow(Parent, "RichText", Flags, sizeof(tRichText_Window), AxWin3_RichText_MessageHandler); +// tRichText_Window *info = AxWin3_int_GetDataPtr(ret); + return ret; +} + +void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler) +{ + tRichText_Window *info = AxWin3_int_GetDataPtr(Window); + info->KeyCallback = Handler; +} + +void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler) +{ + tRichText_Window *info = AxWin3_int_GetDataPtr(Window); + info->MouseCallback = Handler; +} + +void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable) +{ + _SendAttrib(Window, _ATTR_SCROLL, bEnable); +} +void AxWin3_RichText_SetLineCount(tHWND Window, int Lines) +{ + _SendAttrib(Window, _ATTR_LINECOUNT, Lines); +} +void AxWin3_RichText_SetColCount(tHWND Window, int Cols) +{ + _SendAttrib(Window, _ATTR_COLCOUNT, Cols); +} +void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour) +{ + _SendAttrib(Window, _ATTR_DEFBG, ARGB_Colour); +} +void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour) +{ + _SendAttrib(Window, _ATTR_DEFFG, ARGB_Colour); +} +void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize) +{ + // TODO: Send message +} +void AxWin3_RichText_SetCursorType(tHWND Window, int Type) +{ + _SendAttrib(Window, _ATTR_CURSOR, Type); +} +void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink) +{ + _SendAttrib(Window, _ATTR_CURSORBLINK, bBlink); +} +void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column) +{ + if(Row < 0 || Row > 0xFFFFF || Column > 0xFFF || Column < 0) + return ; + _SendAttrib(Window, _ATTR_CURSORPOS, ((Row & 0xFFFFF) << 12) | (Column & 0xFFF)); +} 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 450e4b4f..10375222 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c @@ -46,6 +46,33 @@ tAxWin3_Widget *AxWin3_Widget_int_GetElementByID(tHWND Window, uint32_t ID) return info->Elements[ID]; } +uint32_t AxWin3_Widget_int_AllocateID(tWidgetWindowInfo *Info) +{ + uint32_t newID; + // BUG BUG BUG - Double Allocations! (citation needed) + // TODO: Atomicity + for( newID = Info->FirstFreeID; newID < Info->nElements; newID ++ ) + { + if( Info->Elements[newID] == NULL ) + break; + } + if( newID == Info->nElements ) + { + const int size_step = 4; + Info->nElements += 4; + Info->Elements = realloc(Info->Elements, sizeof(*Info->Elements)*Info->nElements); + newID = Info->nElements - 4; + memset( &Info->Elements[newID+1], 0, (size_step-1)*sizeof(Info->Elements)); + _SysDebug("Expanded to %i and allocated %i", Info->nElements, newID); + } + else + _SysDebug("Allocated %i", newID); + Info->Elements[newID] = (void*)-1; + + return newID; + +} + int AxWin3_Widget_MessageHandler(tHWND Window, int MessageID, int Size, void *Data) { tAxWin3_Widget *widget; @@ -108,26 +135,7 @@ tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Fl info = AxWin3_int_GetDataPtr(Parent->Window); - // Assign ID - // BUG BUG BUG - Double Allocations! - // TODO: Atomicity - for( newID = info->FirstFreeID; newID < info->nElements; newID ++ ) - { - if( info->Elements[newID] == NULL ) - break; - } - if( newID == info->nElements ) - { - const int size_step = 4; - info->nElements += 4; - info->Elements = realloc(info->Elements, sizeof(*info->Elements)*info->nElements); - newID = info->nElements - 4; - memset( &info->Elements[newID+1], 0, (size_step-1)*sizeof(info->Elements)); - _SysDebug("Expanded to %i and allocated %i", info->nElements, newID); - } - else - _SysDebug("Allocated %i", newID); - info->Elements[newID] = (void*)-1; + newID = AxWin3_Widget_int_AllocateID(info); // Create new widget structure ret = calloc(sizeof(tAxWin3_Widget), 1); @@ -151,6 +159,33 @@ 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) +{ + tWidgetWindowInfo *info = AxWin3_int_GetDataPtr(Parent->Window); + int newID = AxWin3_Widget_int_AllocateID(info); + + tAxWin3_Widget *ret = calloc(sizeof(tAxWin3_Widget), 1); + ret->Window = Parent->Window; + ret->ID = newID; + info->Elements[newID] = ret; + + // Send message + { + char tmp[sizeof(tWidgetMsg_CreateSubWin)+1]; + tWidgetMsg_CreateSubWin *msg = (void*)tmp; + msg->Parent = Parent->ID; + msg->NewID = newID; + msg->Type = ELETYPE_SUBWIN; + msg->Flags = 0; // TODO: Flags + msg->WindowHandle = AxWin3_int_GetWindowID(Window); + msg->DebugName[0] = '\0'; + AxWin3_SendMessage(ret->Window, ret->Window, MSG_WIDGET_CREATESUBWIN, sizeof(tmp), tmp); + } + + return ret; +} + + void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget) { tWidgetMsg_Delete msg; diff --git a/Usermode/Applications/gui_ate_src/main.c b/Usermode/Applications/gui_ate_src/main.c index cf2662d8..75f6c6ed 100644 --- a/Usermode/Applications/gui_ate_src/main.c +++ b/Usermode/Applications/gui_ate_src/main.c @@ -46,15 +46,15 @@ int main(int argc, char *argv[]) add_toolbar_button(gMainWindow_Toolbar, "BtnOpen", Toolbar_Open); add_toolbar_button(gMainWindow_Toolbar, "BtnOpen", Toolbar_Save); AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_SPACER, 0, ""); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnUndo"); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnRedo"); + add_toolbar_button(gMainWindow_Toolbar, "BtnUndo", NULL); + add_toolbar_button(gMainWindow_Toolbar, "BtnRedo", NULL); AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_SPACER, 0, ""); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnCut"); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnCopy"); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnPaste"); + add_toolbar_button(gMainWindow_Toolbar, "BtnCut", NULL); + add_toolbar_button(gMainWindow_Toolbar, "BtnCopy", NULL); + add_toolbar_button(gMainWindow_Toolbar, "BtnPaste", NULL); AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_SPACER, 0, ""); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnSearch"); - AxWin3_Widget_AddWidget(gMainWindow_Toolbar, ELETYPE_BUTTON, 0, "BtnReplace"); + add_toolbar_button(gMainWindow_Toolbar, "BtnSearch", NULL); + add_toolbar_button(gMainWindow_Toolbar, "BtnReplace", NULL); // TODO: Tab control? @@ -69,15 +69,9 @@ int main(int argc, char *argv[]) AxWin3_RichText_SetCursorType (gMainWindow_TextArea, AXWIN3_RICHTEXT_CURSOR_VLINE); AxWin3_RichText_SetCursorBlink (gMainWindow_TextArea, 1); // TODO: Status Bar? - - // Load a file - FILE *fp = fopen("", "r"); - if( !fp ) { - perror("fopen"); - return -1; - } - fclose(fp); + AxWin3_ShowWindow(gMainWindow, 1); + // Main loop AxWin3_MainLoop(); @@ -97,5 +91,21 @@ 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); + // TODO: Get image / text using `Ident` as a lookup key AxWin3_Widget_SetText(btn, Ident); + AxWin3_Widget_SetFireHandler(btn, Callback); } + +int Toolbar_New(tAxWin3_Widget *Widget) +{ + return 0; +} +int Toolbar_Open(tAxWin3_Widget *Widget) +{ + return 0; +} +int Toolbar_Save(tAxWin3_Widget *Widget) +{ + return 0; +} + diff --git a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h index 83ff3690..a50f4639 100644 --- a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h +++ b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h @@ -21,16 +21,18 @@ enum eAxWin3_RichText_CursorType { AXWIN3_RICHTEXT_CURSOR_INV, // Inverted }; -tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags); -void AxWin3_RichText_EnableScroll(tHWND Parent, int bEnable); -void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler); -void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler); -void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour); -void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour); -void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize); -void AxWin3_RichText_SetCursorType(tHWND Parent, int Type); -void AxWin3_RichText_SetCursorBlink(tHWND Parent, int bBlink); -void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column); +extern tHWND AxWin3_RichText_CreateWindow(tHWND Parent, int Flags); +extern void AxWin3_RichText_SetKeyHandler(tHWND Window, tAxWin3_RichText_KeyHandler Handler); +extern void AxWin3_RichText_SetMouseHandler(tHWND Window, tAxWin3_RichText_MouseHandler Handler); +extern void AxWin3_RichText_EnableScroll(tHWND Window, int bEnable); +extern void AxWin3_RichText_SetLineCount(tHWND Window, int Lines); +extern void AxWin3_RichText_SetColCount(tHWND Window, int Cols); +extern void AxWin3_RichText_SetBackground(tHWND Window, uint32_t ARGB_Colour); +extern void AxWin3_RichText_SetDefaultColour(tHWND Window, uint32_t ARGB_Colour); +extern void AxWin3_RichText_SetFont(tHWND Window, const char *FontName, int PointSize); +extern void AxWin3_RichText_SetCursorType(tHWND Window, int Type); +extern void AxWin3_RichText_SetCursorBlink(tHWND Window, int bBlink); +extern void AxWin3_RichText_SetCursorPos(tHWND Window, int Row, int Column); #endif -- 2.20.1