summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-02-08 16:05:44 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-02-08 16:05:44 +0000
commit59d24187f757463b1fef6c8c9ba4ebbc1952f74d (patch)
tree71f402267ac7a4e4a148a7008956a26ee95db91d /desktop
parent0a4e1a05e3a916fb13948e3801571131ffd10766 (diff)
downloadnetsurf-59d24187f757463b1fef6c8c9ba4ebbc1952f74d.tar.gz
netsurf-59d24187f757463b1fef6c8c9ba4ebbc1952f74d.tar.bz2
Support dropping text file on textarea widget.
Diffstat (limited to 'desktop')
-rw-r--r--desktop/textarea.c46
-rw-r--r--desktop/textarea.h10
2 files changed, 56 insertions, 0 deletions
diff --git a/desktop/textarea.c b/desktop/textarea.c
index 25630e464..7324b821b 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -1111,6 +1111,52 @@ bool textarea_set_text(struct textarea *ta, const char *text)
/* exported interface, documented in textarea.h */
+bool textarea_drop_text(struct textarea *ta, const char *text,
+ size_t text_length)
+{
+ struct textarea_msg msg;
+ unsigned int caret_pos;
+ size_t text_chars;
+
+ if (ta->flags & TEXTAREA_READONLY)
+ return false;
+
+ if (text == NULL)
+ return false;
+
+ text_chars = utf8_bounded_length(text, text_length);
+ caret_pos = textarea_get_caret(ta);
+
+ if (ta->sel_start != -1) {
+ if (!textarea_replace_text(ta, ta->sel_start, ta->sel_end,
+ text, text_length, false))
+ return false;
+
+ caret_pos = ta->sel_start + text_chars;
+ ta->sel_start = ta->sel_end = -1;
+ } else {
+ if (!textarea_replace_text(ta, caret_pos, caret_pos,
+ text, text_length, false))
+ return false;
+ caret_pos += text_chars;
+ }
+
+ textarea_set_caret(ta, caret_pos);
+
+ msg.ta = ta;
+ msg.type = TEXTAREA_MSG_REDRAW_REQUEST;
+ msg.data.redraw.x0 = 0;
+ msg.data.redraw.y0 = 0;
+ msg.data.redraw.x1 = ta->vis_width;
+ msg.data.redraw.y1 = ta->vis_height;
+
+ ta->callback(ta->data, &msg);
+
+ return true;
+}
+
+
+/* exported interface, documented in textarea.h */
int textarea_get_text(struct textarea *ta, char *buf, unsigned int len)
{
if (buf == NULL && len == 0) {
diff --git a/desktop/textarea.h b/desktop/textarea.h
index 560f1ca28..566e0cf6c 100644
--- a/desktop/textarea.h
+++ b/desktop/textarea.h
@@ -124,6 +124,16 @@ void textarea_destroy(struct textarea *ta);
bool textarea_set_text(struct textarea *ta, const char *text);
/**
+ * Insert the text in a text area at the caret, replacing any selection.
+ *
+ * \param ta Text area
+ * \param text UTF-8 text to set text area's contents to
+ * \return true on success, false on memory exhaustion or if ta lacks caret
+ */
+bool textarea_drop_text(struct textarea *ta, const char *text,
+ size_t text_length);
+
+/**
* Extract the text from a text area
*
* \param ta Text area