From 5a39774e6ed9002de3f0ec1f2cdbba2ebbe9fbde Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 11 Jul 2020 21:56:33 +0200 Subject: String copy/paste implemented --- code/fe310/eos/eve/widget/Makefile | 2 +- code/fe310/eos/eve/widget/clipb.c | 19 +++++++++++++++++++ code/fe310/eos/eve/widget/clipb.h | 6 ++++++ code/fe310/eos/eve/widget/strw.c | 32 ++++++++++++++++++++++++-------- code/fe310/eos/eve/widget/textw.c | 28 ++++++++++++++++++++-------- 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 code/fe310/eos/eve/widget/clipb.c create mode 100644 code/fe310/eos/eve/widget/clipb.h diff --git a/code/fe310/eos/eve/widget/Makefile b/code/fe310/eos/eve/widget/Makefile index 50bb26e..065cab0 100644 --- a/code/fe310/eos/eve/widget/Makefile +++ b/code/fe310/eos/eve/widget/Makefile @@ -2,7 +2,7 @@ include ../../../common.mk CFLAGS += -I. -I.. -I../.. -obj = label.o widget.o pagew.o strw.o textw.o +obj = clipb.o label.o widget.o pagew.o strw.o textw.o %.o: %.c %.h diff --git a/code/fe310/eos/eve/widget/clipb.c b/code/fe310/eos/eve/widget/clipb.c new file mode 100644 index 0000000..f480d83 --- /dev/null +++ b/code/fe310/eos/eve/widget/clipb.c @@ -0,0 +1,19 @@ +#include + +#include "eve.h" +#include "clipb.h" + +static char _clipb[EVE_CLIPB_SIZE_BUF]; + +int eve_clipb_push(char *str, uint16_t len) { + if (len >= EVE_CLIPB_SIZE_BUF) return EVE_ERR; + + memcpy(_clipb, str, len); + _clipb[len] = '\0'; + + return EVE_OK; +} + +char *eve_clipb_get(void) { + return _clipb; +} \ No newline at end of file diff --git a/code/fe310/eos/eve/widget/clipb.h b/code/fe310/eos/eve/widget/clipb.h new file mode 100644 index 0000000..8b3e980 --- /dev/null +++ b/code/fe310/eos/eve/widget/clipb.h @@ -0,0 +1,6 @@ +#include + +#define EVE_CLIPB_SIZE_BUF 256 + +int eve_clipb_push(char *str, uint16_t len); +char *eve_clipb_get(void); \ No newline at end of file diff --git a/code/fe310/eos/eve/widget/strw.c b/code/fe310/eos/eve/widget/strw.c index 82e86b7..519f171 100644 --- a/code/fe310/eos/eve/widget/strw.c +++ b/code/fe310/eos/eve/widget/strw.c @@ -10,6 +10,7 @@ #include "screen/page.h" #include "screen/font.h" +#include "clipb.h" #include "label.h" #include "widget.h" #include "strw.h" @@ -192,6 +193,7 @@ uint8_t eve_strw_draw(EVEWidget *_widget, EVEPage *page, uint8_t tag0) { widget->tag = tag0; if (tag0 != EVE_TAG_NOTAG) { eve_cmd_dl(TAG(tag0)); + eve_touch_set_opt(tag0, EVE_TOUCH_OPT_LPRESS); tag0++; } @@ -263,6 +265,7 @@ void eve_strw_putc(void *_page, int c) { EVEStrCursor *cursor1 = &widget->cursor1; EVEStrCursor *cursor2 = &widget->cursor2; char *str; + char *clipb = NULL; int w0 = widget->font->w; int w1 = widget->w.g.w - widget->font->w; @@ -277,7 +280,6 @@ void eve_strw_putc(void *_page, int c) { if (cursor2->on) { EVEStrCursor *c1; EVEStrCursor *c2; - char *clipb = NULL; int ins_c = 0, del_c = 0; int ins_ch_w = 0, del_ch_w = 0; @@ -293,19 +295,17 @@ void eve_strw_putc(void *_page, int c) { del_c = c2->ch - c1->ch; del_ch_w = eve_font_buf_w(widget->font, str, del_c); if ((c == CH_CTRLX) || (c == CH_CTRLC)) { - // eve_clipb_push(str, del_c); + eve_clipb_push(str, del_c); if (c == CH_CTRLC) return; } if (CHAR_VALID_INPUT(c) && (widget->str_len < widget->str_size + del_c - 1)) { ins_c = 1; ins_ch_w = widget->font->w_ch[c]; } else if (c == CH_CTRLV) { - // clipb = eve_clipb_pop(); + clipb = eve_clipb_get(); ins_c = clipb ? strlen(clipb) : 0; - if (ins_c) { - if (widget->str_len >= widget->str_size - (ins_c - del_c)) ins_c = widget->str_size - widget->str_len + del_c - 1; - ins_ch_w = eve_font_buf_w(widget->font, clipb, ins_c); - } + if (widget->str_len >= widget->str_size - (ins_c - del_c)) ins_c = widget->str_size - widget->str_len + del_c - 1; + ins_ch_w = eve_font_buf_w(widget->font, clipb, ins_c); } if (ins_c != del_c) memmove(str + ins_c, str + del_c, widget->str_len - c2->ch + 1); if (ins_c) { @@ -322,7 +322,8 @@ void eve_strw_putc(void *_page, int c) { if (c1 == cursor2) widget->cursor1 = widget->cursor2; eve_strw_cursor_clear(widget, cursor2); } else { - uint8_t ch_w; + int ch_w = 0; + int c_len; str = widget->str + cursor1->ch; switch (c) { @@ -346,6 +347,21 @@ void eve_strw_putc(void *_page, int c) { } break; + case CH_CTRLV: + clipb = eve_clipb_get(); + c_len = clipb ? strlen(clipb) : 0; + if (widget->str_len >= widget->str_size - c_len) c_len = widget->str_size - widget->str_len - 1; + ch_w = eve_font_buf_w(widget->font, clipb, c_len); + if (c_len) { + memmove(str + c_len, str, widget->str_len - cursor1->ch + 1); + memcpy(str, clipb, c_len); + widget->str_len += c_len; + widget->str_g.w += ch_w; + cursor1->ch += c_len; + cursor1->x += ch_w; + } + break; + default: if (CHAR_VALID_INPUT(c) && (widget->str_len < widget->str_size - 1)) { ch_w = widget->font->w_ch[c]; diff --git a/code/fe310/eos/eve/widget/textw.c b/code/fe310/eos/eve/widget/textw.c index 0f230aa..e72bb8c 100644 --- a/code/fe310/eos/eve/widget/textw.c +++ b/code/fe310/eos/eve/widget/textw.c @@ -10,6 +10,7 @@ #include "screen/page.h" #include "screen/font.h" +#include "clipb.h" #include "label.h" #include "widget.h" #include "textw.h" @@ -278,7 +279,9 @@ void eve_textw_putc(void *_page, int c) { EVETextCursor *cursor1 = &widget->cursor1; EVETextCursor *cursor2 = &widget->cursor2; char *text; - int i, r, ins_c = 0, del_c = 0; + char *clipb = NULL; + int i, r; + int ins_c = 0, del_c = 0; int ch_w = 0; if (c == CH_EOF) { @@ -292,7 +295,6 @@ void eve_textw_putc(void *_page, int c) { if (cursor2->on) { EVETextCursor *c1; EVETextCursor *c2; - char *clipb = NULL; if (cursor1->ch <= cursor2->ch) { c1 = cursor1; @@ -305,19 +307,17 @@ void eve_textw_putc(void *_page, int c) { text = widget->text + c1->ch; del_c = c2->ch - c1->ch; if ((c == CH_CTRLX) || (c == CH_CTRLC)) { - // eve_clipb_push(text, del_c); + eve_clipb_push(text, del_c); if (c == CH_CTRLC) return; } if (CHAR_VALID_INPUT(c) && (widget->text_len < widget->text_size + del_c - 1)) { ins_c = 1; ch_w = widget->font->w_ch[c]; } else if (c == CH_CTRLV) { - // clipb = eve_clipb_pop(); + clipb = eve_clipb_get(); ins_c = clipb ? strlen(clipb) : 0; - if (ins_c) { - if (widget->text_len >= widget->text_size - (ins_c - del_c)) ins_c = widget->text_size - widget->text_len + del_c - 1; - ch_w = eve_font_buf_w(widget->font, clipb, ins_c); - } + if (widget->text_len >= widget->text_size - (ins_c - del_c)) ins_c = widget->text_size - widget->text_len + del_c - 1; + ch_w = eve_font_buf_w(widget->font, clipb, ins_c); } if (ins_c != del_c) memmove(text + ins_c, text + del_c, widget->text_len - c2->ch + 1); if (ins_c) { @@ -350,6 +350,18 @@ void eve_textw_putc(void *_page, int c) { } break; + case CH_CTRLV: + clipb = eve_clipb_get(); + ins_c = clipb ? strlen(clipb) : 0; + if (widget->text_len >= widget->text_size - ins_c) ins_c = widget->text_size - widget->text_len - 1; + ch_w = eve_font_buf_w(widget->font, clipb, ins_c); + if (ins_c) { + memmove(text + ins_c, text, widget->text_len - cursor1->ch + 1); + memcpy(text, clipb, ins_c); + cursor1->ch += ins_c; + } + break; + default: if (CHAR_VALID_INPUT(c) && (widget->text_len < widget->text_size - 1)) { ch_w = widget->font->w_ch[c]; -- cgit v1.2.3