text: Add delete_surrounding_text to protocol
[profile/ivi/weston.git] / src / text-backend.c
index 7ae023a..b2f9094 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "compositor.h"
 #include "text-server-protocol.h"
+#include "input-method-server-protocol.h"
 
 struct input_method;
 struct input_method_context;
@@ -109,7 +110,9 @@ destroy_text_model(struct wl_resource *resource)
 static void
 text_model_set_surrounding_text(struct wl_client *client,
                                struct wl_resource *resource,
-                               const char *text)
+                               const char *text,
+                               uint32_t cursor,
+                               uint32_t anchor)
 {
        struct text_model *text_model = resource->data;
        struct input_method *input_method, *next;
@@ -117,18 +120,14 @@ text_model_set_surrounding_text(struct wl_client *client,
        wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
                if (!input_method->context)
                        continue;
-               input_method_context_send_set_surrounding_text(&input_method->context->resource, text);
+               input_method_context_send_surrounding_text(&input_method->context->resource,
+                                                          text,
+                                                          cursor,
+                                                          anchor);
        }
 }
 
 static void
-text_model_set_cursor_index(struct wl_client *client,
-                           struct wl_resource *resource,
-                           uint32_t index)
-{
-}
-
-static void
 text_model_activate(struct wl_client *client,
                    struct wl_resource *resource,
                    struct wl_resource *seat,
@@ -174,14 +173,6 @@ text_model_deactivate(struct wl_client *client,
 }
 
 static void
-text_model_set_selected_text(struct wl_client *client,
-                            struct wl_resource *resource,
-                            const char *text,
-                            int32_t index)
-{
-}
-
-static void
 text_model_set_micro_focus(struct wl_client *client,
                           struct wl_resource *resource,
                           int32_t x,
@@ -205,10 +196,8 @@ text_model_set_content_type(struct wl_client *client,
 
 static const struct text_model_interface text_model_implementation = {
        text_model_set_surrounding_text,
-       text_model_set_cursor_index,
        text_model_activate,
        text_model_deactivate,
-       text_model_set_selected_text,
        text_model_set_micro_focus,
        text_model_set_preedit,
        text_model_set_content_type
@@ -305,9 +294,33 @@ input_method_context_commit_string(struct wl_client *client,
        text_model_send_commit_string(&context->model->resource, text, index);
 }
 
+static void
+input_method_context_preedit_string(struct wl_client *client,
+                                  struct wl_resource *resource,
+                                  const char *text,
+                                  uint32_t index)
+{
+       struct input_method_context *context = resource->data;
+
+       text_model_send_preedit_string(&context->model->resource, text, index);
+}
+
+static void
+input_method_context_delete_surrounding_text(struct wl_client *client,
+                                            struct wl_resource *resource,
+                                            int32_t index,
+                                            uint32_t length)
+{
+       struct input_method_context *context = resource->data;
+
+       text_model_send_delete_surrounding_text(&context->model->resource, index, length);
+}
+
 static const struct input_method_context_interface input_method_context_implementation = {
        input_method_context_destroy,
-       input_method_context_commit_string
+       input_method_context_commit_string,
+       input_method_context_preedit_string,
+       input_method_context_delete_surrounding_text
 };
 
 static void