Add get_default_attributes and get_run_attributes for elm_popup.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Fri, 22 Nov 2013 09:03:20 +0000 (10:03 +0100)
committerKarol Furmaniak <k.furmaniak@samsung.com>
Fri, 22 Nov 2013 09:03:20 +0000 (10:03 +0100)
eail/eail/eail_entry.c
eail/eail/eail_label.c
eail/eail/eail_popup.c
eail/eail/eail_text.c
eail/eail/eail_utils.c
eail/eail/eail_utils.h

index 74e36b7..13e89f1 100644 (file)
@@ -567,31 +567,6 @@ eail_entry_get_character_count(AtkText *text)
 }
 
 /**
- * @brief Adds attribute to attribute set
- *
- * Creates an AtkAttribute from attr and value, and adds it
- * to attrib_set.
- *
- * @param attrib_set AtkAttributeSet instance to add the attribute to
- * @param attr AtkTextAttrribute instance which identifies the attribute to be added
- * @param value attribute value
- *
- * @returns: AtkAttributeSet representing the new attribute set
- **/
-AtkAttributeSet*
-eail_entry_add_attribute(AtkAttributeSet *attrib_set,
-                         AtkTextAttribute attr,
-                         gchar           *value)
-{
-   AtkAttributeSet *return_set;
-   AtkAttribute *at = g_malloc (sizeof (AtkAttribute));
-   at->name = g_strdup (atk_text_attribute_get_name (attr));
-   at->value = value;
-   return_set = g_slist_prepend(attrib_set, at);
-   return return_set;
-}
-
-/**
  * @brief Creates an AtkAttributeSet which consists of the default values of
  * attributes for the text
  *
@@ -603,21 +578,19 @@ eail_entry_add_attribute(AtkAttributeSet *attrib_set,
  * @returns AtkAttributeSet which contains the default values of attributes
  * at offset
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_entry_get_default_attributes(AtkText *text)
 {
    AtkAttributeSet *at_set = NULL;
 
-   at_set = eail_entry_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0)));
+        atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
 
-   at_set = eail_entry_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, TRUE)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, TRUE));
 
    return at_set;
 }
@@ -641,7 +614,7 @@ eail_entry_get_default_attributes(AtkText *text)
  * @returns AtkAttributeSet which contains the attributes explicitly set at
  * offset
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_entry_get_run_attributes(AtkText *text,
                               gint offset,
                               gint *start_offset,
@@ -664,18 +637,16 @@ eail_entry_get_run_attributes(AtkText *text,
    /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
     * no additional conversion is needed*/
    Elm_Wrap_Type wrap_type = elm_entry_line_wrap_get(widget);
-   at_set = eail_entry_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
 
    Eina_Bool editable = elm_entry_editable_get(widget);
-   at_set = eail_entry_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, editable)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, editable));
 
    return at_set;
 }
index 1c3b65a..60e62cd 100644 (file)
@@ -198,31 +198,6 @@ eail_label_get_character_count(AtkText *text)
 }
 
 /**
- * @brief Adds attribute to attribute set
- *
- * @param attrib_set AtkAttributeSet to add the attribute to
- * @param attr AtkTextAttrribute to be added
- * @param value attribute value
- *
- * Creates an AtkAttribute from attr and value, and adds it
- * to attrib_set.
- *
- * @returns AtkAttributeSet containing set with added attribute
- **/
-AtkAttributeSet*
-_eail_label_add_attribute(AtkAttributeSet *attrib_set,
-                          AtkTextAttribute attr,
-                          gchar           *value)
-{
-   AtkAttributeSet *return_set;
-   AtkAttribute *at = g_malloc (sizeof (AtkAttribute));
-   at->name = g_strdup (atk_text_attribute_get_name (attr));
-   at->value = value;
-   return_set = g_slist_prepend(attrib_set, at);
-   return return_set;
-}
-
-/**
  * @brief Creates an AtkAttributeSet which consists of the default values of
  * attributes for the text.
  *
@@ -234,21 +209,19 @@ _eail_label_add_attribute(AtkAttributeSet *attrib_set,
  * @returns AtkAttributeSet containing default values of attributes
  * at offset.
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_label_get_default_attributes(AtkText *text)
 {
    AtkAttributeSet *at_set = NULL;
 
-   at_set = _eail_label_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0)));
+        atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
 
-   at_set = _eail_label_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, FALSE)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
 
    return at_set;
 }
@@ -273,7 +246,7 @@ eail_label_get_default_attributes(AtkText *text)
  * @returns an AtkAttributeSet which contains the attributes explicitly set at
  * offset.
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_label_get_run_attributes(AtkText *text,
                               gint offset,
                               gint *start_offset,
@@ -297,17 +270,15 @@ eail_label_get_run_attributes(AtkText *text,
    /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
     * no additional conversion is needed*/
    Elm_Wrap_Type wrap_type = elm_label_line_wrap_get(widget);
-   at_set = _eail_label_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
 
-   at_set = _eail_label_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, FALSE)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
 
    return at_set;
 }
index 22bb2e8..81db2b0 100644 (file)
@@ -30,6 +30,7 @@
 #include "eail_factory.h"
 #include "eail_utils.h"
 #include "eail_priv.h"
+#include "eail_text.h"
 
 static void atk_text_interface_init(AtkTextIface *iface);
 
@@ -496,6 +497,92 @@ eail_popup_get_character_extents(AtkText *text,
     }
 }
 
+/*
+ * @brief Creates an AtkAttributeSet which consists of the attributes
+ * explicitly set at the position offset in the text.
+ *
+ * start_offset and end_offset are set to the start and end of the range around offset
+ * where the attributes are invariant.
+ *
+ * Note that end_offset is the offset of the first character after the range.
+ *
+ * This AtkAttributeSet should be freed by a call to
+ * atk_attribute_set_free()
+ *
+ * @param text AtkText instance
+ * @param offset the offset at which to get the attributes
+ * @param [out] start_offset start offset of the range
+ * @param [out] end_offset end offset of the range
+ *
+ * @returns an AtkAttributeSet which contains the attributes explicitly set at
+ * offset.
+ */
+static AtkAttributeSet *
+eail_popup_get_run_attributes(AtkText *text,
+                              gint offset,
+                              gint *start_offset,
+                              gint *end_offset)
+{
+   AtkAttributeSet *at_set = NULL;
+   Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
+   gint len = eail_popup_get_character_count(ATK_TEXT(text));
+
+   if (!widget || offset >= len)
+     {
+        *start_offset = -1;
+        *end_offset = -1;
+
+        return NULL;
+     }
+
+   *start_offset = 0;
+   *end_offset = len;
+
+   /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
+    * no additional conversion is needed*/
+   Elm_Wrap_Type wrap_type = elm_popup_content_text_wrap_type_get(widget);
+   at_set = eail_utils_text_add_attribute
+       (at_set, ATK_TEXT_ATTR_WRAP_MODE,
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
+
+   at_set = eail_utils_text_add_attribute
+       (at_set, ATK_TEXT_ATTR_EDITABLE,
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
+
+   return at_set;
+}
+
+/**
+ * @brief Creates an AtkAttributeSet which consists of the default values of
+ * attributes for the text.
+ *
+ * This AtkAttributeSet should be freed by a call to
+ * atk_attribute_set_free()
+ *
+ * @param text AtkText instance
+ *
+ * @returns AtkAttributeSet containing default values of attributes
+ * at offset.
+ */
+static AtkAttributeSet *
+eail_popup_get_default_attributes(AtkText *text)
+{
+   AtkAttributeSet *at_set = NULL;
+
+   at_set = eail_utils_text_add_attribute
+       (at_set, ATK_TEXT_ATTR_WRAP_MODE,
+        atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
+
+   at_set = eail_utils_text_add_attribute
+       (at_set, ATK_TEXT_ATTR_EDITABLE,
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
+
+   return at_set;
+}
+
 /**
  * @brief Initializer for AtkTextIface interface class
  *
@@ -510,4 +597,6 @@ atk_text_interface_init(AtkTextIface *iface)
     iface->get_character_at_offset = eail_popup_get_character_at_offset;
     iface->get_character_count = eail_popup_get_character_count;
     iface->get_character_extents = eail_popup_get_character_extents;
+    iface->get_run_attributes = eail_popup_get_run_attributes;
+    iface->get_default_attributes = eail_popup_get_default_attributes;
 }
index 7dcda24..9ebd8af 100644 (file)
@@ -182,31 +182,6 @@ eail_text_get_character_count(AtkText *text)
 }
 
 /**
- * @brief Adds attribute to attribute set
- *
- * @param attrib_set AtkAttributeSet to add the attribute to
- * @param attr AtkTextAttrribute to be added
- * @param value attribute value
- *
- * Creates an AtkAttribute from attr and value, and adds it
- * to attrib_set.
- *
- * @returns AtkAttributeSet containing set with added attribute
- **/
-AtkAttributeSet*
-_eail_text_add_attribute(AtkAttributeSet *attrib_set,
-                         AtkTextAttribute attr,
-                         gchar           *value)
-{
-   AtkAttributeSet *return_set;
-   AtkAttribute *at = g_malloc (sizeof (AtkAttribute));
-   at->name = g_strdup (atk_text_attribute_get_name (attr));
-   at->value = value;
-   return_set = g_slist_prepend(attrib_set, at);
-   return return_set;
-}
-
-/**
  * @brief Creates an AtkAttributeSet which consists of the default values of
  * attributes for the text.
  *
@@ -218,21 +193,19 @@ _eail_text_add_attribute(AtkAttributeSet *attrib_set,
  * @returns AtkAttributeSet containing default values of attributes
  * at offset.
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_text_get_default_attributes(AtkText *text)
 {
    AtkAttributeSet *at_set = NULL;
 
-   at_set = _eail_text_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0)));
+        atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
 
-   at_set = _eail_text_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, FALSE)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
 
    return at_set;
 }
@@ -257,7 +230,7 @@ eail_text_get_default_attributes(AtkText *text)
  * @returns an AtkAttributeSet which contains the attributes explicitly set at
  * offset.
  */
-AtkAttributeSet *
+static AtkAttributeSet *
 eail_text_get_run_attributes(AtkText *text,
                              gint offset,
                              gint *start_offset,
@@ -281,18 +254,16 @@ eail_text_get_run_attributes(AtkText *text,
    /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
     * no additional conversion is needed*/
    Elm_Wrap_Type wrap_type = ELM_WRAP_NONE;
-   at_set = _eail_text_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_WRAP_MODE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
 
 
-   at_set = _eail_text_add_attribute
+   at_set = eail_utils_text_add_attribute
        (at_set, ATK_TEXT_ATTR_EDITABLE,
-        g_strdup
-        (atk_text_attribute_get_value
-         (ATK_TEXT_ATTR_EDITABLE, FALSE)));
+        atk_text_attribute_get_value
+         (ATK_TEXT_ATTR_EDITABLE, FALSE));
 
    return at_set;
 }
index d721dc1..2c28496 100644 (file)
@@ -1347,3 +1347,28 @@ eail_get_text_before(const Evas_Object *textblock,
 
    return g_utf8_substring(text, start, end);
 }
+
+/*
+ * @brief Adds attribute to attribute set
+ *
+ * @param attrib_set AtkAttributeSet to add the attribute to
+ * @param attr AtkTextAttrribute to be added
+ * @param value attribute value
+ *
+ * Creates an AtkAttribute from attr and value, and adds it
+ * to attrib_set.
+ *
+ * @returns AtkAttributeSet containing set with added attribute
+ **/
+AtkAttributeSet*
+eail_utils_text_add_attribute(AtkAttributeSet *attrib_set,
+                              AtkTextAttribute attr,
+                              const gchar     *value)
+{
+   AtkAttributeSet *return_set;
+   AtkAttribute *at = g_malloc (sizeof (AtkAttribute));
+   at->name = g_strdup (atk_text_attribute_get_name (attr));
+   at->value = g_strdup(value);
+   return_set = g_slist_prepend(attrib_set, at);
+   return return_set;
+}
index d712b61..c20145e 100644 (file)
@@ -239,6 +239,22 @@ eail_get_text_before(const Evas_Object *textblock,
                      AtkTextBoundary boundary_type,
                      gint *start_offset,
                      gint *end_offset);
+/*
+ * @brief Helper function to add attribute to attribute set
+ *
+ * @param attrib_set AtkAttributeSet to add the attribute to
+ * @param attr AtkTextAttrribute to be added
+ * @param value attribute value
+ *
+ * Creates an AtkAttribute from attr and value, and adds it
+ * to attrib_set.
+ *
+ * @returns AtkAttributeSet containing set with added attribute
+ **/
+AtkAttributeSet*
+eail_utils_text_add_attribute(AtkAttributeSet *attrib_set,
+                              AtkTextAttribute attr,
+                              const gchar     *value);
 #ifdef __cplusplus
 }
 #endif