Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_nocontents.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup NoContents NoContents
6  * @ingroup Elementary
7  *
8  */
9
10 typedef struct _Widget_Data Widget_Data;
11
12 struct _Widget_Data
13 {
14    Evas_Object *noc;
15    Evas_Object *custom;
16    const char *label;
17 };
18
19 static const char *widtype = NULL;
20 static void _del_hook(Evas_Object *obj);
21 static void _theme_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23
24 static void
25 _del_hook(Evas_Object *obj)
26 {
27    Widget_Data *wd = elm_widget_data_get(obj);
28    if (!wd) return;
29    free(wd);
30 }
31
32 static void
33 _theme_hook(Evas_Object *obj)
34 {
35    Widget_Data *wd = elm_widget_data_get(obj);
36    if (!wd) return;
37      _elm_theme_object_set(obj, wd->noc, "nocontents", "base", elm_widget_style_get(obj));
38      edje_object_part_text_set(wd->noc, "elm.text", wd->label);
39      edje_object_message_signal_process(wd->noc);
40    edje_object_scale_set(wd->noc, elm_widget_scale_get(obj) * _elm_config->scale);
41    _sizing_eval(obj);
42 }
43
44 static void
45 _sizing_eval(Evas_Object *obj)
46 {
47    Widget_Data *wd = elm_widget_data_get(obj);
48    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
49    if (!wd) return;
50    edje_object_size_min_calc(wd->noc, &minw, &minh);
51    evas_object_size_hint_min_set(obj, minw, minh);
52    evas_object_size_hint_max_set(obj, maxw, maxh);
53    evas_object_size_hint_align_set(obj, maxw, maxh);
54 }
55
56 /**
57  * Add a nocontents object to @p parent
58  *
59  * @param parent The parent object
60  *
61  * @return The nocontents object, or NULL upon failure
62  *
63  * @ingroup NoContents
64  */
65 EAPI Evas_Object *
66 elm_nocontents_add(Evas_Object *parent)
67 {
68    Evas_Object *obj;
69    Evas *e;
70    Widget_Data *wd;
71
72    wd = ELM_NEW(Widget_Data);
73    e = evas_object_evas_get(parent);
74    obj = elm_widget_add(e);
75    ELM_SET_WIDTYPE(widtype, "nocontents");
76    elm_widget_type_set(obj, "nocontents");
77    elm_widget_sub_object_add(parent, obj);
78    elm_widget_data_set(obj, wd);
79    elm_widget_del_hook_set(obj, _del_hook);
80    elm_widget_theme_hook_set(obj, _theme_hook);
81    elm_widget_can_focus_set(obj, 0);
82
83    wd->label = NULL;
84    wd->custom = NULL;
85
86    wd->noc = edje_object_add(e);
87    _elm_theme_object_set(obj, wd->noc, "nocontents", "base", "default");
88    elm_widget_resize_object_set(obj, wd->noc);
89    _sizing_eval(obj);
90    return obj;
91 }
92
93 /**
94  * Set the label on the nocontents object
95  *
96  * @param obj The nocontents object
97  * @param label The label will be used on the nocontents object
98  *
99  * @ingroup NoContents
100  */
101 EAPI void
102 elm_nocontents_label_set(Evas_Object *obj, const char *label)
103 {
104    ELM_CHECK_WIDTYPE(obj, widtype);
105    Widget_Data *wd = elm_widget_data_get(obj);
106    if (!wd) return;
107    if (!label) label = "";
108    eina_stringshare_replace(&wd->label, label);
109    edje_object_part_text_set(wd->noc, "elm.text", label);
110    _sizing_eval(obj);
111 }
112
113 /**
114  * Get the label used on the nocontents object
115  *
116  * @param obj The nocontentsl object
117  * @return The string inside the label
118  * @ingroup NoContents
119  */
120 EAPI const char *
121 elm_nocontents_label_get(const Evas_Object *obj)
122 {
123    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
124    Widget_Data *wd = elm_widget_data_get(obj);
125    if (!wd) return NULL;
126    return wd->label;
127 }
128
129 /**
130  * Set the custom object used on the nocontents object
131  *
132  * @param obj The nocontentsl object
133  * @param custom The custom object will be used on the nocontents object
134  * @ingroup NoContents
135  */
136 EAPI void 
137 elm_nocontents_custom_set(const Evas_Object *obj, Evas_Object *custom)
138 {
139    ELM_CHECK_WIDTYPE(obj, widtype);
140    Widget_Data *wd = elm_widget_data_get(obj);
141
142    if (!wd) return;
143    if (!custom) return;
144    elm_widget_sub_object_add((Evas_Object *)obj, custom);
145    edje_object_part_swallow(wd->noc, "custom", custom);
146    wd->custom = custom;
147 }
148
149 /**
150  * Get the custom object used on the nocontents object
151  *
152  * @param obj The nocontentsl object
153  * @return The custom object inside the nocontents
154  * @ingroup NoContents
155  */
156 EAPI Evas_Object *
157 elm_nocontents_custom_get(const Evas_Object *obj)
158 {
159    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
160    Widget_Data *wd = elm_widget_data_get(obj);
161    if (!wd) return NULL;
162    return wd->custom;
163 }