Add API for updating the cursor position of preedit string 43/214843/20
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Sep 2019 12:51:33 +0000 (21:51 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 2 Feb 2021 07:46:10 +0000 (16:46 +0900)
Change-Id: Ib7fe9293abb69f70911cfdab0001940853da25eb
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
inputmethod/include/inputmethod.h
inputmethod/src/inputmethod.cpp

index 3ae712a..8e1db30 100644 (file)
@@ -1668,6 +1668,7 @@ int ime_hide_preedit_string(void);
  * @see ime_commit_string()
  * @see ime_show_preedit_string()
  * @see ime_hide_preedit_string()
+ * @see ime_update_preedit_cursor()
  *
  * @code
  {
@@ -1706,6 +1707,58 @@ int ime_hide_preedit_string(void);
 int ime_update_preedit_string(const char *str, Eina_List *attrs);
 
 /**
+ * @brief Updates the cursor position in the preedit string.
+ *
+ * @since_tizen 6.5
+ *
+ * @privlevel public
+ *
+ * @privilege %http://tizen.org/privilege/ime
+ *
+ * @param[in] pos The cursor position in the preedit string
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #IME_ERROR_NONE No error
+ * @retval #IME_ERROR_PERMISSION_DENIED The application does not have the privilege to call this function.
+ * @retval #IME_ERROR_NOT_RUNNING IME main loop is not started yet
+ *
+ * @post This function is supposed to be followed by the ime_update_preedit_string() function.
+ *
+ * @see ime_show_preedit_string()
+ * @see ime_hide_preedit_string()
+ * @see ime_update_preedit_string()
+ *
+ * @code
+ {
+        int ret;
+        Eina_List *list = NULL;
+
+        ime_preedit_attribute *attr = calloc(1, sizeof(ime_preedit_attribute));
+        attr->start = 0;
+        attr->length = 1;
+        attr->type = IME_ATTR_FONTSTYLE;
+        attr->value = IME_ATTR_FONTSTYLE_UNDERLINE;
+        list = eina_list_append(list, attr);
+
+        attr = calloc(1, sizeof(ime_preedit_attribute));
+        attr->start = 1;
+        attr->length = 3;
+        attr->type = IME_ATTR_FONTSTYLE;
+        attr->value = IME_ATTR_FONTSTYLE_REVERSAL;
+        list = eina_list_append(list, attr);
+
+        ret = ime_update_preedit_string("abcd", list);
+        if (ret != IME_ERROR_NONE) {
+                EINA_LIST_FREE(list, attr)
+                        free(attr);
+        }
+        ret = ime_update_preedit_cursor(1);
+ }
+ * @endcode
+ */
+int ime_update_preedit_cursor(unsigned int pos);
+
+/**
  * @brief Requests the surrounding text from the position of the cursor, asynchronously.
  *
  * @since_tizen @if MOBILE 2.4 @else 3.0 @endif
index e05d6be..94bbe76 100644 (file)
@@ -1353,6 +1353,23 @@ EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
     //LCOV_EXCL_STOP
 }
 
+EXPORT_API int ime_update_preedit_cursor(unsigned int pos)
+{
+    ime_error_e retVal = IME_ERROR_NONE;
+
+    if (!g_running) {
+        LOGW("IME_ERROR_NOT_RUNNING");
+        return IME_ERROR_NOT_RUNNING;
+    }
+
+    retVal = _check_privilege();
+    if (retVal != IME_ERROR_NONE) return retVal;
+
+    g_core.update_preedit_caret(pos);
+
+    return IME_ERROR_NONE;
+}
+
 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
 {
     ime_error_e retVal = IME_ERROR_NONE;