X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin3_src%2FWM%2Frenderers%2Fwidget%2Ftextinput.c;h=de862bfe402efd0037fa21126e472e59343cc9f3;hb=8ae0b1147e613573a45fcd8e6f2f6af2aeff54ac;hp=2e21e7890362058cdb03f86d1aeb94173440ff50;hpb=f0c407e7d468bc5acfd8d436be7f79f6e6248421;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c index 2e21e789..de862bfe 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c @@ -10,9 +10,13 @@ #include #include "./common.h" #include "./colours.h" -#include +#include #include +// TODO: Include a proper keysym header +#define KEYSYM_LEFTARROW 0x50 +#define KEYSYM_RIGHTARROW 0x4F + struct sTextInputInfo { int DrawOfs; // Byte offset for the leftmost character @@ -113,6 +117,8 @@ void Widget_TextInput_Init(tElement *Element) info = Element->Data = malloc(sizeof(*info)); info->DrawOfs = 0; info->CursorXOfs = 0; + info->CursorByteOfs = 0; + info->Length = 0; // No need to explicitly update parent min dims, as the AddElement routine does that } @@ -128,7 +134,38 @@ int Widget_TextInput_KeyFire(tElement *Element, int KeySym, int Character) // _SysDebug("Key 0x%x fired ('%c')", Character, Character); if( Character == 0 ) + { + switch(KeySym) + { + case KEYSYM_LEFTARROW: + if( info->CursorByteOfs > 0 ) + { + len = ReadUTF8Rev(Element->Text, info->CursorByteOfs, &cp); + info->CursorByteOfs -= len; + WM_Render_GetTextDims( + gpTextInput_Font, + Element->Text+info->CursorByteOfs, + len, &w, 0 + ); + info->CursorXOfs -= w; + } + break; + case KEYSYM_RIGHTARROW: + if( info->CursorByteOfs < info->Length ) + { + len = ReadUTF8(Element->Text + info->CursorByteOfs, &cp); + WM_Render_GetTextDims( + gpTextInput_Font, + Element->Text+info->CursorByteOfs, + len, &w, 0 + ); + info->CursorByteOfs += len; + info->CursorXOfs += w; + } + break; + } return 0; + } // TODO: Don't hard code if(Character > 0x30000000) return 0; @@ -178,12 +215,12 @@ int Widget_TextInput_KeyFire(tElement *Element, int KeySym, int Character) } // TODO: Have a Widget_ function to do this instead - WM_Invalidate(Element->Window); + WM_Invalidate(Element->Window, 1); return 0; } -DEFWIDGETTYPE(ELETYPE_TEXTINPUT, +DEFWIDGETTYPE(ELETYPE_TEXTINPUT, "TextInput", WIDGETTYPE_FLAG_NOCHILDREN, .Render = Widget_TextInput_Render, .Init = Widget_TextInput_Init,