Fix possible problems with other subsystems depending on X11 display
[framework/uifw/elementary.git] / src / lib / elm_bubble.c
index 2ee7a2e..0f35578 100644 (file)
@@ -1,17 +1,6 @@
 #include <Elementary.h>
 #include "elm_priv.h"
 
-/**
- * @defgroup Bubble Bubble
- *
- * The Bubble is an widget used to show a text in a frame as speech is
- * represented in comics.
- *
- * Signals that you can add callbacks for are:
- *
- * "clicked" - This is called when a user has clicked the bubble.
- */
-
 typedef struct _Widget_Data Widget_Data;
 
 struct _Widget_Data
@@ -19,11 +8,15 @@ struct _Widget_Data
    Evas_Object *bbl;
    Evas_Object *content, *icon;
    const char *label, *info, *corner;
+   Elm_Bubble_Pos pos;
 };
 
 static const char *widtype = NULL;
 static void _del_hook(Evas_Object *obj);
 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
+static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
+static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
+static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
 static void _theme_hook(Evas_Object *obj);
 static void _sizing_eval(Evas_Object *obj);
 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
@@ -37,6 +30,14 @@ static const Evas_Smart_Cb_Description _signals[] =
      {NULL, NULL}
 };
 
+static const char *corner_string[] =
+{
+    "top_left",
+    "top_right",
+    "bottom_left",
+    "bottom_right"
+};
+
 static void
 _del_hook(Evas_Object *obj)
 {
@@ -63,12 +64,12 @@ _theme_hook(Evas_Object *obj)
    if (!wd) return;
    _elm_widget_mirrored_reload(obj);
    _mirrored_set(obj, elm_widget_mirrored_get(obj));
-   _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
+   _elm_theme_object_set(obj, wd->bbl, "bubble", corner_string[wd->pos],
                          elm_widget_style_get(obj));
-   edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
+   edje_object_part_text_escaped_set(wd->bbl, "elm.text", wd->label);
    if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
    else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
-   edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
+   edje_object_part_text_escaped_set(wd->bbl, "elm.info", wd->info);
    if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
    else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
    if (wd->content)
@@ -85,6 +86,118 @@ _theme_hook(Evas_Object *obj)
    _sizing_eval(obj);
 }
 
+static void
+_content_set(Evas_Object *obj, Evas_Object *content)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   if (wd->content == content) return;
+   if (wd->content) evas_object_del(wd->content);
+   wd->content = content;
+   if (content)
+     {
+        elm_widget_sub_object_add(obj, content);
+        evas_object_event_callback_add(content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+        edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
+     }
+   _sizing_eval(obj);
+}
+
+static Evas_Object *
+_content_unset(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Object *content;
+   if (!wd) return NULL;
+   if (!wd->content) return NULL;
+   content = wd->content;
+   elm_widget_sub_object_del(obj, content);
+   evas_object_event_callback_del_full(content,
+                                       EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+   edje_object_part_unswallow(wd->bbl, content);
+   wd->content = NULL;
+   return content;
+}
+
+static void
+_icon_set(Evas_Object *obj, Evas_Object* icon)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   if (wd->icon == icon) return;
+   if (wd->icon) evas_object_del(wd->icon);
+   wd->icon = icon;
+   if (icon)
+     {
+        elm_widget_sub_object_add(obj, icon);
+        edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
+        evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+        edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
+        edje_object_message_signal_process(wd->bbl);
+     }
+   _sizing_eval(obj);
+}
+
+static Evas_Object *
+_icon_unset(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Object *icon;
+   if (!wd) return NULL;
+   if (!wd->icon) return NULL;
+   icon = wd->icon;
+   elm_widget_sub_object_del(obj, icon);
+   evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+                                       _changed_size_hints, obj);
+   edje_object_part_unswallow(wd->bbl, icon);
+   wd->icon = NULL;
+   return icon;
+}
+
+static void
+_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   if (!part || !strcmp(part, "default"))
+     _content_set(obj, content);
+   else if (!strcmp(part, "icon"))
+     _icon_set(obj, content);
+}
+
+static Evas_Object *
+_content_get_hook(const Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   if (!part || !strcmp(part, "default"))
+     return wd->content;
+   else if (!strcmp(part, "icon"))
+     return wd->icon;
+   return NULL;
+}
+
+static Evas_Object *
+_content_unset_hook(Evas_Object *obj, const char *part)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+   if (!part || !strcmp(part, "default"))
+     return _content_unset(obj);
+   else if (!strcmp(part, "icon"))
+     return _icon_unset(obj);
+   return NULL;
+}
+
 static Eina_Bool
 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
 {
@@ -147,16 +260,52 @@ _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *eve
    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
 }
 
-/**
- * Add a new bubble to the parent
- *
- * @param parent The parent object
- * @return The new object or NULL if it cannot be created
- *
- * This function adds a text bubble to the given parent evas object.
- *
- * @ingroup Bubble
- */
+static void
+_elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   if (!item || !strcmp(item, "default"))
+     {
+        eina_stringshare_replace(&wd->label, label);
+        edje_object_part_text_escaped_set(wd->bbl, "elm.text", label);
+        if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
+                                           "elm");
+        else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
+        _sizing_eval(obj);
+     }
+   else if (!strcmp(item, "info"))
+     {
+        eina_stringshare_replace(&wd->info, label);
+        edje_object_part_text_escaped_set(wd->bbl, "elm.info", label);
+        if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
+                                           "elm");
+        else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
+        _sizing_eval(obj);
+     }
+}
+
+static const char*
+_elm_bubble_label_get(const Evas_Object *obj, const char *item)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return NULL;
+
+   if (!item || !strcmp(item, "default"))
+     {
+        return wd->label;
+     }
+   else if (!strcmp(item, "info"))
+     {
+        return wd->info;
+     }
+
+   return NULL;
+}
+
 EAPI Evas_Object *
 elm_bubble_add(Evas_Object *parent)
 {
@@ -174,8 +323,14 @@ elm_bubble_add(Evas_Object *parent)
    elm_widget_theme_hook_set(obj, _theme_hook);
    elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
    elm_widget_can_focus_set(obj, EINA_FALSE);
+   elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
+   elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
+   elm_widget_content_set_hook_set(obj, _content_set_hook);
+   elm_widget_content_get_hook_set(obj, _content_get_hook);
+   elm_widget_content_unset_hook_set(obj, _content_unset_hook);
 
    wd->corner = eina_stringshare_add("base");
+   wd->pos = ELM_BUBBLE_POS_TOP_LEFT; //default
 
    wd->bbl = edje_object_add(e);
    elm_widget_resize_object_set(obj, wd->bbl);
@@ -192,295 +347,22 @@ elm_bubble_add(Evas_Object *parent)
    return obj;
 }
 
-/**
- * Set the label of the bubble
- *
- * @param obj The bubble object
- * @param label The string to set in the label
- *
- * This function sets the title of the bubble that is shown on top of
- * the bubble.
- *
- * @ingroup Bubble
- */
 EAPI void
-elm_bubble_label_set(Evas_Object *obj, const char *label)
+elm_bubble_pos_set(Evas_Object *obj, Elm_Bubble_Pos pos)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return;
-   eina_stringshare_replace(&wd->label, label);
-   edje_object_part_text_set(wd->bbl, "elm.text", label);
-   if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
-   else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
-   _sizing_eval(obj);
-}
-
-/**
- * Get the label of the bubble
- *
- * @param obj The bubble object
- * @return The string of set in the label
- *
- * This function gets the title of the bubble that is shown on top of
- * the bubble.
- *
- * @ingroup Bubble
- */
-EAPI const char*
-elm_bubble_label_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->label;
-}
-
-/**
- * Set the info of the bubble
- *
- * @param obj The bubble object
- * @param info The given info about the bubble
- *
- * This function sets the text shown on the top right of bubble.
- * In the Anchorblock example of the Elementary tests application it
- * shows time.
- *
- * @ingroup Bubble
- *
- */
-EAPI void
-elm_bubble_info_set(Evas_Object *obj, const char *info)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   eina_stringshare_replace(&wd->info, info);
-   edje_object_part_text_set(wd->bbl, "elm.info", info);
-   if (info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
-   else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
-   _sizing_eval(obj);
-}
-
-/**
- * Get the info of the bubble
- *
- * @param obj The bubble object
- *
- * @return The "info" string of the bubble
- *
- * This function gets the text set to be displayed at the top right of
- * the bubble.
- *
- * @ingroup Bubble
- *
- */
-EAPI const char *
-elm_bubble_info_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->info;
-}
-
-/**
- * Set the content to be shown in the bubble
- *
- * Once the content object is set, a previously set one will be deleted.
- * If you want to keep the old content object, use the
- * elm_bubble_content_unset() function.
- *
- * @param obj The bubble object
- * @param content The given content of the bubble
- *
- * This function sets the content shown on the middle of the bubble.
- * In the Anchorblock example of the Elementary tests application it
- * shows time.
- *
- * @ingroup Bubble
- */
-EAPI void
-elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   if (wd->content == content) return;
-   if (wd->content) evas_object_del(wd->content);
-   wd->content = content;
-   if (content)
-     {
-        elm_widget_sub_object_add(obj, content);
-        evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
-                                       _changed_size_hints, obj);
-        edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
-     }
-   _sizing_eval(obj);
-}
-
-/**
- * Get the content shown in the bubble
- *
- * Return the content object which is set for this widget.
- *
- * @param obj The bubble object
- * @return The content that is being used
- *
- * @ingroup Bubble
- */
-EAPI Evas_Object *
-elm_bubble_content_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->content;
-}
-
-/**
- * Unset the content shown in the bubble
- *
- * Unparent and return the content object which was set for this widget.
- *
- * @param obj The bubble object
- * @return The content that was being used
- *
- * @ingroup Bubble
- */
-EAPI Evas_Object *
-elm_bubble_content_unset(Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Evas_Object *content;
-   if (!wd) return NULL;
-   if (!wd->content) return NULL;
-   content = wd->content;
-   elm_widget_sub_object_del(obj, content);
-   edje_object_part_unswallow(wd->bbl, content);
-   wd->content = NULL;
-   return content;
-}
-
-/**
- * Set the icon of the bubble
- *
- * Once the icon object is set, a previously set one will be deleted.
- * If you want to keep the old content object, use the
- * elm_icon_content_unset() function.
- *
- * @param obj The bubble object
- * @param icon The given icon for the bubble
- *
- * @ingroup Bubble
- */
-EAPI void
-elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   if (wd->icon == icon) return;
-   if (wd->icon) evas_object_del(wd->icon);
-   wd->icon = icon;
-   if (icon)
-     {
-        elm_widget_sub_object_add(obj, icon);
-        edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
-        evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
-                                       _changed_size_hints, obj);
-        edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
-        edje_object_message_signal_process(wd->bbl);
-     }
-   _sizing_eval(obj);
-}
-
-/**
- * Get the icon of the bubble
- *
- * @param obj The bubble object
- * @return The icon for the bubble
- *
- * This function gets the icon shown on the top left of bubble.
- *
- * @ingroup Bubble
- */
-EAPI Evas_Object *
-elm_bubble_icon_get(const Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->icon;
-}
-
-/**
- * Unset the icon of the bubble
- *
- * Unparent and return the icon object which was set for this widget.
- *
- * @param obj The bubble object
- * @return The icon that was being used
- *
- * @ingroup Bubble
- */
-EAPI Evas_Object *
-elm_bubble_icon_unset(Evas_Object *obj)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
-   Widget_Data *wd = elm_widget_data_get(obj);
-   Evas_Object *icon;
-   if (!wd) return NULL;
-   if (!wd->icon) return NULL;
-   icon = wd->icon;
-   elm_widget_sub_object_del(obj, icon);
-   edje_object_part_unswallow(wd->bbl, icon);
-   wd->icon = NULL;
-   return icon;
-}
-
-/**
- * Set the corner of the bubble
- *
- * @param obj The bubble object.
- * @param corner The given corner for the bubble.
- *
- * This function sets the corner of the bubble.
- * The corner will be used to find the group in the theme
- * For example, if you set the corner to "bottom_right",
- * the following group will be searched:
- * "elm/bubble/bottom_right/default",
- * considering default style.
- *
- * @ingroup Bubble
- */
-EAPI void
-elm_bubble_corner_set(Evas_Object *obj, const char *corner)
-{
-   ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return;
-   EINA_SAFETY_ON_NULL_RETURN(corner);
-   eina_stringshare_replace(&wd->corner, corner);
+   if (pos<ELM_BUBBLE_POS_TOP_LEFT || pos>ELM_BUBBLE_POS_BOTTOM_RIGHT) return;
+   wd->pos = pos;
    _theme_hook(obj);
 }
 
-/**
- * Get the corner of the bubble
- *
- * @param obj The bubble object.
- * @return The given corner for the bubble.
- *
- * This function gets the corner of the bubble.
- *
- * @ingroup Bubble
- */
-EAPI const char*
-elm_bubble_corner_get(const Evas_Object *obj)
+EAPI Elm_Bubble_Pos
+elm_bubble_pos_get(const Evas_Object *obj)
 {
-   ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+   ELM_CHECK_WIDTYPE(obj, widtype) ELM_BUBBLE_POS_INVALID;
    Widget_Data *wd = elm_widget_data_get(obj);
-   if (!wd) return NULL;
-   return wd->corner;
+   if (!wd) return ELM_BUBBLE_POS_INVALID;
+   return wd->pos;
 }