Support preedit style 68/66268/3
authorInHong Han <inhong1.han@samsung.com>
Mon, 18 Apr 2016 06:34:20 +0000 (15:34 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 18 Apr 2016 07:08:58 +0000 (16:08 +0900)
Change-Id: If05521efa3a9266adc17e40e97fe88bbf8dd38a2

ism/extras/wayland_immodule/wayland_imcontext.c
ism/modules/panelagent/wayland/isf_wsc_context.h
ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp

index d76f800..5053353 100644 (file)
@@ -614,12 +614,19 @@ text_input_preedit_styling(void                 *data,
     switch (style)
     {
         case WL_TEXT_INPUT_PREEDIT_STYLE_DEFAULT:
+            attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB1;
+            break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_UNDERLINE:
+            attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB1;
+            break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_INCORRECT:
+            break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT:
+            attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB3;
+            break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_ACTIVE:
+            break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_INACTIVE:
-            attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB1;
             break;
         case WL_TEXT_INPUT_PREEDIT_STYLE_SELECTION:
             attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2;
index 4d50af1..dc34fab 100644 (file)
@@ -86,7 +86,6 @@ struct _WSCContextISF {
     char *language;
 
     uint32_t serial;
-    uint32_t preedit_style;
     uint32_t content_hint;
     uint32_t content_purpose;
     uint32_t surrounding_cursor;
index 0ea0d9a..cee6093 100755 (executable)
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <malloc.h>
 #include <dlog.h>
+#include <glib.h>
 
 #include <Eina.h>
 #include <Ecore.h>
@@ -2015,11 +2016,99 @@ wsc_send_preedit (WSCContextISF* wsc_ctx, int32_t cursor)
 
     uint32_t index = strlen (wsc_ctx->preedit_str);
 
-    if (wsc_ctx->preedit_style)
-        wl_input_method_context_preedit_styling (wsc_ctx->im_ctx,
-                                                 0,
-                                                 strlen (wsc_ctx->preedit_str),
-                                                 wsc_ctx->preedit_style);
+    if (wsc_ctx && wsc_ctx->impl && wsc_ctx->impl->is_on) {
+        String mbs = utf8_wcstombs (wsc_ctx->impl->preedit_string);
+
+        if (!wsc_ctx->impl->preedit_attrlist.empty()) {
+            if (mbs.length ()) {
+                uint32_t preedit_style;
+                int start_index, end_index;
+                int wlen = wsc_ctx->impl->preedit_string.length ();
+                AttributeList::const_iterator i;
+                bool *attrs_flag = new bool [mbs.length ()];
+                memset (attrs_flag, 0, mbs.length () * sizeof (bool));
+                for (i = wsc_ctx->impl->preedit_attrlist.begin ();
+                    i != wsc_ctx->impl->preedit_attrlist.end (); ++i) {
+                    start_index = i->get_start ();
+                    end_index = i->get_end ();
+                    if (end_index <= wlen && start_index < end_index && i->get_type () != SCIM_ATTR_DECORATE_NONE) {
+                        start_index = g_utf8_offset_to_pointer (mbs.c_str (), i->get_start ()) - mbs.c_str ();
+                        end_index = g_utf8_offset_to_pointer (mbs.c_str (), i->get_end ()) - mbs.c_str ();
+                        if (i->get_type () == SCIM_ATTR_DECORATE) {
+                            switch (i->get_value ())
+                            {
+                                case SCIM_ATTR_DECORATE_UNDERLINE:
+                                    preedit_style = WL_TEXT_INPUT_PREEDIT_STYLE_UNDERLINE;
+                                    break;
+                                case SCIM_ATTR_DECORATE_REVERSE:
+                                    preedit_style = WL_TEXT_INPUT_PREEDIT_STYLE_SELECTION;
+                                    break;
+                                case SCIM_ATTR_DECORATE_HIGHLIGHT:
+                                    preedit_style = WL_TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT;
+                                    break;
+                                case SCIM_ATTR_DECORATE_BGCOLOR1:
+                                case SCIM_ATTR_DECORATE_BGCOLOR2:
+                                case SCIM_ATTR_DECORATE_BGCOLOR3:
+                                case SCIM_ATTR_DECORATE_BGCOLOR4:
+                                    preedit_style = WL_TEXT_INPUT_PREEDIT_STYLE_DEFAULT;
+                                    break;
+                                default:
+                                    break;
+                            }
+
+                            if (preedit_style)
+                                wl_input_method_context_preedit_styling (wsc_ctx->im_ctx,
+                                                                         start_index,
+                                                                         end_index,
+                                                                         preedit_style);
+                            switch (i->get_value ())
+                            {
+                                case SCIM_ATTR_DECORATE_UNDERLINE:
+                                case SCIM_ATTR_DECORATE_REVERSE:
+                                case SCIM_ATTR_DECORATE_HIGHLIGHT:
+                                case SCIM_ATTR_DECORATE_BGCOLOR1:
+                                case SCIM_ATTR_DECORATE_BGCOLOR2:
+                                case SCIM_ATTR_DECORATE_BGCOLOR3:
+                                case SCIM_ATTR_DECORATE_BGCOLOR4:
+                                    // Record which character has attribute.
+                                    for (int pos = start_index; pos < end_index; ++pos)
+                                        attrs_flag [pos] = 1;
+                                    break;
+                                default:
+                                    break;
+                            }
+                        } else if (i->get_type () == SCIM_ATTR_FOREGROUND) {
+                            SCIM_DEBUG_FRONTEND(4) << "SCIM_ATTR_FOREGROUND\n";
+                        } else if (i->get_type () == SCIM_ATTR_BACKGROUND) {
+                            SCIM_DEBUG_FRONTEND(4) << "SCIM_ATTR_BACKGROUND\n";
+                        }
+                    }
+                }
+                // Add underline for all characters which don't have attribute.
+                for (unsigned int pos = 0; pos < mbs.length (); ++pos) {
+                    if (!attrs_flag [pos]) {
+                        int begin_pos = pos;
+                        while (pos < mbs.length () && !attrs_flag [pos])
+                            ++pos;
+                        // use REVERSE style as default
+                        preedit_style = WL_TEXT_INPUT_PREEDIT_STYLE_UNDERLINE;
+                        start_index = begin_pos;
+                        end_index = pos;
+
+                        wl_input_method_context_preedit_styling (wsc_ctx->im_ctx,
+                                                                 start_index,
+                                                                 end_index,
+                                                                 preedit_style);
+                    }
+                }
+                delete [] attrs_flag;
+            }
+        }
+    } else {
+        if (!wsc_ctx->impl->preedit_attrlist.empty())
+            wsc_ctx->impl->preedit_attrlist.clear();
+    }
+
     if (cursor > 0)
         index = cursor;