Fix atk_text_selection functions for elm_multibuttonentry
authorAgnieszka Janowicz <a.janowicz@partner.samsung.com>
Fri, 8 Nov 2013 14:38:59 +0000 (15:38 +0100)
committerAgnieszka Janowicz <a.janowicz@partner.samsung.com>
Wed, 20 Nov 2013 12:02:34 +0000 (13:02 +0100)
Add atk_text_add_selection, atk_text_remove_selection, atk_text_get_n_selections,
atk_text_set_selection and atk_text_get_selection for multibuttonentry widget.

eail/eail/eail_multibuttonentry.c
eail/eail/eail_multibuttonentry.h

index ad54229..d57c394 100644 (file)
@@ -305,6 +305,180 @@ eail_multibuttonentry_get_character_extents(AtkText *text,
 }
 
 /**
+ * @brief Adds a selection bounded by the specified offsets
+ *
+ * @param text AtkText instance
+ * @param start_offset start position of the selection
+ * @param end_offset offset of the first character after selection
+ * @returns TRUE on success, FALSE otherwise
+ */
+static gboolean
+eail_multibuttonentry_add_selection(AtkText *text,
+                         gint start_offset,
+                         gint end_offset)
+{
+   Evas_Object *widget;
+   Evas_Object *entry;
+
+   widget = eail_widget_get_widget(EAIL_WIDGET(text));
+   if (!widget)
+     return FALSE;
+
+   entry = elm_multibuttonentry_entry_get(widget);
+   if (!entry)
+     return FALSE;
+
+   elm_entry_cursor_pos_set(entry, start_offset);
+   elm_entry_cursor_selection_begin(entry);
+   elm_entry_cursor_pos_set(entry, end_offset);
+   elm_entry_cursor_selection_end(entry);
+
+   EAIL_MULTIBUTTONENTRY(text)->selection_start = start_offset;
+   EAIL_MULTIBUTTONENTRY(text)->selection_end = end_offset;
+
+   return TRUE;
+}
+
+/**
+ * @brief Removes text selection
+ *
+ * This widget supports only one selection
+ * so selection_num should always be 0.
+ *
+ * @param text AtkText instance
+ * @param selection_num selection number
+ * @return TRUE on success, FALSE otherwise
+ */
+static gboolean
+eail_multibuttonentry_remove_selection(AtkText *text,
+                            gint selection_num)
+{
+   Evas_Object *widget;
+   Evas_Object *entry;
+
+   widget = eail_widget_get_widget(EAIL_WIDGET(text));
+   if (!widget)
+     return FALSE;
+
+   entry = elm_multibuttonentry_entry_get(widget);
+   if (!entry)
+     return FALSE;
+
+   if (selection_num != 0 || !elm_entry_selection_get(entry))
+     return FALSE;
+
+   elm_entry_select_none(entry);
+   EAIL_MULTIBUTTONENTRY(text)->selection_start = 0;
+   EAIL_MULTIBUTTONENTRY(text)->selection_end = 0;
+
+   return TRUE;
+}
+
+/**
+ * @brief Sets text selection for multibuttonentry
+ *
+ * This widget supports only one selection
+ * so selection_num should always be 0.
+ *
+ * @param text AtkText instance
+ * @param selection_num selection number
+ * @param start_pos start position of the selected region
+ * @param end_pos end position of the selected region
+ *
+ * @returns TRUE on success, FALSE otherwise
+ */
+static gboolean
+eail_multibuttonentry_set_selection(AtkText *text,
+                         gint     selection_num,
+                         gint     start_pos,
+                         gint     end_pos)
+{
+   if (0 != selection_num)
+     return FALSE;
+
+   return eail_multibuttonentry_add_selection(text, start_pos, end_pos);
+}
+
+/**
+ * @brief Gets text selection from multibuttonentry
+ *
+ * Use g_free() to free the returned string.
+ *
+ * This widget supports only one selection
+ * so selection_num should always be 0.
+ *
+ * @param text AtkText instance
+ * @param selection_num selection number
+ * @param start_offset start position of the selected region
+ * @param end_offset end position of the selected region
+ *
+ * @returns newly allocated string containing the selected text
+ */
+static gchar *
+eail_multibuttonentry_get_selection(AtkText *text,
+                         gint     selection_num,
+                         gint    *start_offset,
+                         gint    *end_offset)
+{
+   const char* selection;
+   Evas_Object *widget;
+   Evas_Object *entry;
+
+   if (0 != selection_num)
+     return g_strdup("");
+
+   widget = eail_widget_get_widget(EAIL_WIDGET(text));
+   if (!widget)
+     return g_strdup("");
+
+   entry = elm_multibuttonentry_entry_get(widget);
+   if (!widget)
+     return g_strdup("");
+
+   selection = elm_entry_selection_get(entry);
+   if (selection)
+   {
+     *start_offset = EAIL_MULTIBUTTONENTRY(text)->selection_start;
+     *end_offset = EAIL_MULTIBUTTONENTRY(text)->selection_end;
+     return g_strdup(selection);
+   }
+
+   return g_strdup("");
+}
+
+
+/**
+ * @brief Gets the number of selected text regions
+ *
+ * Only one selection is supported by this widget
+ * so the returned value is 0 or 1.
+ *
+ * @param text AtkText instance
+ * @returns integer representing the number of
+ * selected text regions
+ */
+static gint
+eail_multibuttonentry_get_n_selections(AtkText *text)
+{
+   Evas_Object *widget;
+   Evas_Object *entry;
+
+   widget = eail_widget_get_widget(EAIL_WIDGET(text));
+   if (!widget)
+     return 0;
+
+   entry = elm_multibuttonentry_entry_get(widget);
+   if (!entry)
+     return 0;
+
+   if (elm_entry_selection_get(entry))
+     return 1;
+
+   return 0;
+}
+
+
+/**
  * @brief AktText initialization function
  *
  * @param iface AtkTextIface instance
@@ -318,6 +492,11 @@ atk_text_interface_init(AtkTextIface *iface)
    iface->get_caret_offset = eail_multibuttonentry_get_caret_offset;
    iface->set_caret_offset = eail_multibuttonentry_set_caret_offset;
    iface->get_character_extents = eail_multibuttonentry_get_character_extents;
+   iface->add_selection    = eail_multibuttonentry_add_selection;
+   iface->remove_selection = eail_multibuttonentry_remove_selection;
+   iface->get_selection    = eail_multibuttonentry_get_selection;
+   iface->set_selection    = eail_multibuttonentry_set_selection;
+   iface->get_n_selections = eail_multibuttonentry_get_n_selections;
 }
 
 /**
@@ -694,6 +873,8 @@ eail_multibuttonentry_initialize(AtkObject *obj, gpointer data)
 static void
 eail_multibuttonentry_init(EailMultibuttonentry *multibuttonentry)
 {
+   multibuttonentry->selection_start = 0;
+   multibuttonentry->selection_end = 0;
 }
 
 /**
index 80dc082..1152954 100644 (file)
@@ -82,6 +82,10 @@ struct _EailMultibuttonentry
 {
    /** @brief Parent widget whose functionality is being extended*/
    EailActionWidget parent;
+   /** @brief Selection region start */
+   gint selection_start;
+   /** @brief Selection region end */
+   gint selection_end;
 };
 
 /** @brief Definition of object class for Atk EailMultibuttonentry*/