From: John Hodge Date: Mon, 8 Oct 2012 04:59:33 +0000 (+0800) Subject: AxWin3 - Designing a text editor (and related APIs) X-Git-Tag: rel0.15~689 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e860a4f0bfc5843258f6ad89a5e8cebbf8816458;p=tpg%2Facess2.git AxWin3 - Designing a text editor (and related APIs) --- diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c index d8f6a61f..0c641cd4 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/main.c @@ -28,7 +28,7 @@ void AxWin3_MainLoop(void) msg = AxWin3_int_GetIPCMessage(); if(!msg) continue; - _SysDebug("oh look, a message (Type=%i, Window=%i, Len=%i)", + _SysDebug("AxWin3_MainLoop - Message (Type=%i, Window=%i, Len=%i)", msg->ID, msg->Window, msg->Size); AxWin3_int_HandleMessage( msg ); diff --git a/Usermode/Applications/gui_ate_src/Makefile b/Usermode/Applications/gui_ate_src/Makefile new file mode 100644 index 00000000..569e1417 --- /dev/null +++ b/Usermode/Applications/gui_ate_src/Makefile @@ -0,0 +1,11 @@ +# Project: [GUI] Acess Text Editor (ATE) + +-include ../Makefile.cfg + +LDFLAGS += -laxwin3 + +OBJ = main.o +BIN = ate +DIR := Apps/AxWin/3.0 + +-include ../Makefile.tpl diff --git a/Usermode/Applications/gui_ate_src/main.c b/Usermode/Applications/gui_ate_src/main.c new file mode 100644 index 00000000..cf2662d8 --- /dev/null +++ b/Usermode/Applications/gui_ate_src/main.c @@ -0,0 +1,101 @@ +/* + * Acess Text Editor (ATE) + * - By John Hodge (thePowersGang) + * + * main.c + * - Core + */ +#include +#include +#include +#include +#include + +// === PROTOTYPES === + int main(int argc, char *argv[]); + int TextArea_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated); + 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); + int Toolbar_New(tAxWin3_Widget *Widget); + int Toolbar_Open(tAxWin3_Widget *Widget); + int Toolbar_Save(tAxWin3_Widget *Widget); + +// === GLOBALS === +tHWND gMainWindow; +tAxWin3_Widget *gMainWindow_Root; +tHWND gMainWindow_MenuBar; +tAxWin3_Widget *gMainWindow_Toolbar; +tHWND gMainWindow_TextArea; + +// === CODE === +int main(int argc, char *argv[]) +{ + AxWin3_Connect(NULL); + + // --- Build up window + gMainWindow = AxWin3_Widget_CreateWindow(NULL, 320, 200, ELEFLAG_VERTICAL); + gMainWindow_Root = AxWin3_Widget_GetRoot(gMainWindow); + + //gMainWindow_MenuBar = AxWin3_Menu_Create(gMainWindow); + //AxWin3_Widget_AddWidget_SubWindow(gMainWindow_Root, gMainWindow_MenuBar); + // TODO: Populate menu + + // Create toolbar + gMainWindow_Toolbar = AxWin3_Widget_AddWidget(gMainWindow_Root, ELETYPE_TOOLBAR, 0, "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); + 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"); + 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"); + 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"); + + // TODO: Tab control? + + gMainWindow_TextArea = AxWin3_RichText_CreateWindow(gMainWindow, 0); + AxWin3_Widget_AddWidget_SubWindow(gMainWindow_Root, gMainWindow_TextArea, "TextArea"); + AxWin3_RichText_SetKeyHandler (gMainWindow_TextArea, TextArea_KeyHandler); + AxWin3_RichText_SetMouseHandler (gMainWindow_TextArea, TextArea_MouseHandler); + AxWin3_RichText_SetBackground (gMainWindow_TextArea, 0xFFFFFF); + AxWin3_RichText_SetDefaultColour(gMainWindow_TextArea, 0x000000); + AxWin3_RichText_SetFont (gMainWindow_TextArea, "#monospace", 10); + AxWin3_RichText_SetCursorPos (gMainWindow_TextArea, 0, 0); + 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); + + // Main loop + AxWin3_MainLoop(); + + return 0; +} + +int TextArea_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated) +{ + return 0; +} + +int TextArea_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col) +{ + return 0; +} + +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); + AxWin3_Widget_SetText(btn, Ident); +} diff --git a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h new file mode 100644 index 00000000..83ff3690 --- /dev/null +++ b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/richtext.h @@ -0,0 +1,36 @@ +/* + * Acess2 GUI Version 3 (AxWin3) + * - By John Hodge (thePowersGang) + * + * richtext.h + * - Rich Text line editor + */ +#ifndef _AXWIN3_RICHTEXT_H_ +#define _AXWIN3_RICHTEXT_H_ + +#include + +typedef int (*tAxWin3_RichText_KeyHandler)(tHWND Window, int bPress, uint32_t Sym, uint32_t Unicode); +typedef int (*tAxWin3_RichText_MouseHandler)(tHWND Window, int bPress, int Button, int Row, int Col); + +#define AXWIN3_RICHTEXT_NOSCROLL 0x0001 +enum eAxWin3_RichText_CursorType { + AXWIN3_RICHTEXT_CURSOR_NONE, + AXWIN3_RICHTEXT_CURSOR_VLINE, // Vertical line + AXWIN3_RICHTEXT_CURSOR_ULINE, // Underline + 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); + +#endif + 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 9eca0b0d..eb9aff61 100644 --- a/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h +++ b/Usermode/Libraries/libaxwin3.so_src/include_exp/axwin3/widget.h @@ -26,6 +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 void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget); // --- Callbacks