support items in anchorblock/view too.
authorCarsten Haitzler <raster@rasterman.com>
Wed, 28 Apr 2010 06:13:06 +0000 (06:13 +0000)
committerCarsten Haitzler <raster@rasterman.com>
Wed, 28 Apr 2010 06:13:06 +0000 (06:13 +0000)
SVN revision: 48384

src/bin/test_anchorblock.c
src/bin/test_anchorview.c
src/lib/Elementary.h.in
src/lib/elc_anchorblock.c
src/lib/elc_anchorview.c
src/lib/elm_entry.c

index 64d3530..44e5f5f 100644 (file)
@@ -185,7 +185,7 @@ test_anchorblock(void *data, Evas_Object *obj, void *event_info)
                           "of information. This of course can be later explicitly "
                           "done by links maybe running local apps or even being "
                           "web URL's too that launch the web browser and point it "
-                          "to that URL.");
+                          "to that URL. <item relsize=16x16 vsize=full href=emoticon/omg></item>");
    evas_object_smart_callback_add(av, "anchor,clicked", my_anchorblock_anchor, av);
    elm_bubble_content_set(bb, av);
    evas_object_show(av);
@@ -209,7 +209,7 @@ test_anchorblock(void *data, Evas_Object *obj, void *event_info)
    av = elm_anchorblock_add(win);
    elm_anchorblock_hover_style_set(av, "popout");
    elm_anchorblock_hover_parent_set(av, win);
-   elm_anchorblock_text_set(av, "This is a short message");
+   elm_anchorblock_text_set(av, "This is a short message. <item relsize=16x16 vsize=full href=emoticon/haha></item>");
    evas_object_smart_callback_add(av, "anchor,clicked", 
                                   my_anchorblock_anchor, av);
    elm_bubble_content_set(bb, av);
index b044047..690a448 100644 (file)
@@ -91,7 +91,7 @@ test_anchorview(void *data, Evas_Object *obj, void *event_info)
                       "<a href=X><link>links in the text</></a>, so enter text<br>"
                       "in here to edit it. By the way, links are<br>"
                       "called <a href=anc-02>Anchors</a> so you will need<br>"
-                      "to refer to them this way.");
+                      "to refer to them this way. <item relsize=16x16 vsize=full href=emoticon/guilty-smile></item>");
    evas_object_size_hint_weight_set(av, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_smart_callback_add(av, "anchor,clicked", my_anchorview_anchor, av);
    elm_win_resize_object_add(win, av);
index e33a068..cbd5fe8 100644 (file)
@@ -481,7 +481,7 @@ extern "C" {
    EAPI Eina_Bool    elm_label_line_wrap_get(const Evas_Object *obj);
    EAPI void         elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w);
    EAPI Evas_Coord   elm_label_wrap_width_get(const Evas_Object *obj);
-/* available styles:
+   /* available styles:
     * default
     * marker
     */
@@ -759,6 +759,9 @@ extern "C" {
    EAPI void         elm_anchorview_hover_style_set(Evas_Object *obj, const char *style);
    EAPI void         elm_anchorview_hover_end(Evas_Object *obj);
    EAPI void         elm_anchorview_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce);
+   EAPI void         elm_anchorview_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data);
+   EAPI void         elm_anchorview_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data);
+   EAPI void         elm_anchorview_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data);
    /* smart callbacks called:
     * "anchor,clicked" - achor called was clicked | event_info = Elm_Entry_Anchorview_Info
     */
@@ -784,6 +787,9 @@ extern "C" {
    EAPI void         elm_anchorblock_hover_parent_set(Evas_Object *obj, Evas_Object *parent);
    EAPI void         elm_anchorblock_hover_style_set(Evas_Object *obj, const char *style);
    EAPI void         elm_anchorblock_hover_end(Evas_Object *obj);
+   EAPI void         elm_anchorblock_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data);
+   EAPI void         elm_anchorblock_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data);
+   EAPI void         elm_anchorblock_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data);
    /* smart callbacks called:
     * "anchor,clicked" - achor called was clicked | event_info = Elm_Entry_Anchorblock_Info
     */
index 5917c39..11d21f3 100644 (file)
  * Elm_Entry_Anchorview_Info
  */
 typedef struct _Widget_Data Widget_Data;
+typedef struct _Elm_Anchorblock_Item_Provider Elm_Anchorblock_Item_Provider;
 
 struct _Widget_Data
 {
    Evas_Object *entry;
    Evas_Object *hover_parent;
    Evas_Object *pop, *hover;
+   Eina_List *item_providers;
    const char *hover_style;
 };
 
+struct _Elm_Anchorblock_Item_Provider
+{
+   Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item);
+   void *data;
+};
+
 static const char *widtype = NULL;
 
 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
@@ -56,8 +64,13 @@ static void
 _del_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
+   Elm_Anchorblock_Item_Provider *ip;
    if (!wd) return;
    if (wd->hover_style) eina_stringshare_del(wd->hover_style);
+   EINA_LIST_FREE(wd->item_providers, ip)
+     {
+        free(ip);
+     }
    free(wd);
 }
 
@@ -138,6 +151,22 @@ _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *e
    wd->hover_parent = NULL;
 }
 
+static Evas_Object *
+_item_provider(void *data, Evas_Object *entry, const char *item)
+{
+   Widget_Data *wd = elm_widget_data_get(data);
+   Evas_Object *o;
+   Eina_List *l;
+   Elm_Anchorblock_Item_Provider *ip;
+   
+   EINA_LIST_FOREACH(wd->item_providers, l, ip)
+     {
+        o = ip->func(ip->data, data, item);
+        if (o) return o;
+     }
+   return NULL;
+}
+
 /**
  * Add a new Anchorblock object
  *
@@ -164,6 +193,7 @@ elm_anchorblock_add(Evas_Object *parent)
    elm_widget_del_hook_set(obj, _del_hook);
 
    wd->entry = elm_entry_add(parent);
+   elm_entry_item_provider_prepend(wd->entry, _item_provider, obj);
    elm_widget_resize_object_set(obj, wd->entry);
    elm_entry_editable_set(wd->entry, 0);
    evas_object_size_hint_weight_set(wd->entry, 1.0, 1.0);
@@ -296,3 +326,91 @@ elm_anchorblock_hover_end(Evas_Object *obj)
    wd->hover = NULL;
    wd->pop = NULL;
 }
+
+/**
+ * This appends a custom item provider to the list for that anchorblock
+ *
+ * This appends the given callback. The list is walked from beginning to end
+ * with each function called given the item href string in the text. If the
+ * function returns an object handle other than NULL (it should create an
+ * and object to do this), then this object is used to replace that item. If
+ * not the next provider is called until one provides an item object, or the
+ * default provider in anchorblock does.
+ * 
+ * @param obj The anchorblock object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorblock
+ */
+EAPI void
+elm_anchorblock_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (!func) return;
+   Elm_Anchorblock_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorblock_Item_Provider));
+   if (!ip) return;
+   ip->func = func;
+   ip->data = data;
+   wd->item_providers = eina_list_append(wd->item_providers, ip);
+}
+
+/**
+ * This prepends a custom item provider to the list for that anchorblock
+ *
+ * This prepends the given callback. See elm_anchorblock_item_provider_append() for
+ * more information
+ * 
+ * @param obj The anchorblock object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorblock
+ */
+EAPI void
+elm_anchorblock_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (!func) return;
+   Elm_Anchorblock_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorblock_Item_Provider));
+   if (!ip) return;
+   ip->func = func;
+   ip->data = data;
+   wd->item_providers = eina_list_prepend(wd->item_providers, ip);
+}
+
+/**
+ * This removes a custom item provider to the list for that anchorblock
+ *
+ * This removes the given callback. See elm_anchorblock_item_provider_append() for
+ * more information
+ * 
+ * @param obj The anchorblock object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorblock
+ */
+EAPI void
+elm_anchorblock_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorblock, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Eina_List *l;
+   Elm_Anchorblock_Item_Provider *ip;
+   if (!wd) return;
+   if (!func) return;
+   EINA_LIST_FOREACH(wd->item_providers, l, ip)
+     {
+        if ((ip->func == func) && (ip->data == data))
+          {
+             wd->item_providers = eina_list_remove_list(wd->item_providers, l);
+             free(ip);
+             return;
+          }
+     }
+}
index 408e29f..2055bd3 100644 (file)
  * Elm_Entry_Anchorview_Info
  */
 typedef struct _Widget_Data Widget_Data;
+typedef struct _Elm_Anchorview_Item_Provider Elm_Anchorview_Item_Provider;
 
 struct _Widget_Data
 {
    Evas_Object *scroller, *entry;
    Evas_Object *hover_parent;
    Evas_Object *pop, *hover;
+   Eina_List *item_providers;
    const char *hover_style;
 };
 
+struct _Elm_Anchorview_Item_Provider
+{
+   Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item);
+   void *data;
+};
+
 static const char *widtype = NULL;
 
 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
@@ -49,8 +57,13 @@ static void
 _del_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
+   Elm_Anchorview_Item_Provider *ip;
    if (!wd) return;
    if (wd->hover_style) eina_stringshare_del(wd->hover_style);
+   EINA_LIST_FREE(wd->item_providers, ip)
+     {
+        free(ip);
+     }
    free(wd);
 }
 
@@ -129,6 +142,22 @@ _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *e
    wd->hover_parent = NULL;
 }
 
+static Evas_Object *
+_item_provider(void *data, Evas_Object *entry, const char *item)
+{
+   Widget_Data *wd = elm_widget_data_get(data);
+   Evas_Object *o;
+   Eina_List *l;
+   Elm_Anchorview_Item_Provider *ip;
+   
+   EINA_LIST_FOREACH(wd->item_providers, l, ip)
+     {
+        o = ip->func(ip->data, data, item);
+        if (o) return o;
+     }
+   return NULL;
+}
+
 /**
  * Add a new Anchorview object
  *
@@ -157,6 +186,7 @@ elm_anchorview_add(Evas_Object *parent)
    wd->scroller = elm_scroller_add(parent);
    elm_widget_resize_object_set(obj, wd->scroller);
    wd->entry = elm_entry_add(parent);
+   elm_entry_item_provider_prepend(wd->entry, _item_provider, obj);
    elm_entry_editable_set(wd->entry, 0);
    evas_object_size_hint_weight_set(wd->entry, 1.0, 1.0);
    evas_object_size_hint_align_set(wd->entry, -1.0, -1.0);
@@ -311,3 +341,91 @@ elm_anchorview_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_boun
    if (!wd) return;
    elm_scroller_bounce_set(wd->scroller, h_bounce, v_bounce);
 }
+
+/**
+ * This appends a custom item provider to the list for that anchorview
+ *
+ * This appends the given callback. The list is walked from beginning to end
+ * with each function called given the item href string in the text. If the
+ * function returns an object handle other than NULL (it should create an
+ * and object to do this), then this object is used to replace that item. If
+ * not the next provider is called until one provides an item object, or the
+ * default provider in anchorview does.
+ * 
+ * @param obj The anchorview object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorview
+ */
+EAPI void
+elm_anchorview_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (!func) return;
+   Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
+   if (!ip) return;
+   ip->func = func;
+   ip->data = data;
+   wd->item_providers = eina_list_append(wd->item_providers, ip);
+}
+
+/**
+ * This prepends a custom item provider to the list for that anchorview
+ *
+ * This prepends the given callback. See elm_anchorview_item_provider_append() for
+ * more information
+ * 
+ * @param obj The anchorview object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorview
+ */
+EAPI void
+elm_anchorview_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (!func) return;
+   Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
+   if (!ip) return;
+   ip->func = func;
+   ip->data = data;
+   wd->item_providers = eina_list_prepend(wd->item_providers, ip);
+}
+
+/**
+ * This removes a custom item provider to the list for that anchorview
+ *
+ * This removes the given callback. See elm_anchorview_item_provider_append() for
+ * more information
+ * 
+ * @param obj The anchorview object
+ * @param func The function called to provide the item object
+ * @param data The data passed to @p func
+ *
+ * @ingroup Anchorview
+ */
+EAPI void
+elm_anchorview_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Eina_List *l;
+   Elm_Anchorview_Item_Provider *ip;
+   if (!wd) return;
+   if (!func) return;
+   EINA_LIST_FOREACH(wd->item_providers, l, ip)
+     {
+        if ((ip->func == func) && (ip->data == data))
+          {
+             wd->item_providers = eina_list_remove_list(wd->item_providers, l);
+             free(ip);
+             return;
+          }
+     }
+}
index eaa0f79..06aa24c 100644 (file)
@@ -13,7 +13,7 @@
  * 
  * You can also insert "items" in the entry with:
  * 
- * <item size=16x16 vsize=full href=emoticon/haha></item>
+ * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
  * 
  * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
  * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry