remove some warnings
[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_scale_set(wd->noc, elm_widget_scale_get(obj) * _elm_config->scale);
39    _sizing_eval(obj);
40 }
41
42 static void
43 _sizing_eval(Evas_Object *obj)
44 {
45    Widget_Data *wd = elm_widget_data_get(obj);
46    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
47    if (!wd) return;
48    edje_object_size_min_calc(wd->noc, &minw, &minh);
49    evas_object_size_hint_min_set(obj, minw, minh);
50    evas_object_size_hint_max_set(obj, maxw, maxh);
51    evas_object_size_hint_align_set(obj, maxw, maxh);
52 }
53
54 /**
55  * Add a nocontents object to @p parent
56  *
57  * @param parent The parent object
58  *
59  * @return The nocontents object, or NULL upon failure
60  *
61  * @ingroup NoContents
62  */
63 EAPI Evas_Object *
64 elm_nocontents_add(Evas_Object *parent)
65 {
66    Evas_Object *obj;
67    Evas *e;
68    Widget_Data *wd;
69
70    wd = ELM_NEW(Widget_Data);
71    e = evas_object_evas_get(parent);
72    obj = elm_widget_add(e);
73    ELM_SET_WIDTYPE(widtype, "nocontents");
74    elm_widget_type_set(obj, "nocontents");
75    elm_widget_sub_object_add(parent, obj);
76    elm_widget_data_set(obj, wd);
77    elm_widget_del_hook_set(obj, _del_hook);
78    elm_widget_theme_hook_set(obj, _theme_hook);
79    elm_widget_can_focus_set(obj, 0);
80
81    wd->label = NULL;
82    wd->custom = NULL;
83
84    wd->noc = edje_object_add(e);
85    _elm_theme_object_set(obj, wd->noc, "nocontents", "base", "default");
86    elm_widget_resize_object_set(obj, wd->noc);
87    _sizing_eval(obj);
88    return obj;
89 }
90
91 /**
92  * Set the label on the nocontents object
93  *
94  * @param obj The nocontents object
95  * @param label The label will be used on the nocontents object
96  *
97  * @ingroup NoContents
98  */
99 EAPI void
100 elm_nocontents_label_set(Evas_Object *obj, const char *label)
101 {
102    ELM_CHECK_WIDTYPE(obj, widtype);
103    Widget_Data *wd = elm_widget_data_get(obj);
104    if (!wd) return;
105    if (!label) label = "";
106    eina_stringshare_replace(&wd->label, label);
107    edje_object_part_text_set(wd->noc, "elm.text", label);
108    _sizing_eval(obj);
109 }
110
111 /**
112  * Get the label used on the nocontents object
113  *
114  * @param obj The nocontentsl object
115  * @return The string inside the label
116  * @ingroup NoContents
117  */
118 EAPI const char *
119 elm_nocontents_label_get(const Evas_Object *obj)
120 {
121    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
122    Widget_Data *wd = elm_widget_data_get(obj);
123    if (!wd) return NULL;
124    return wd->label;
125 }
126
127 /**
128  * Set the custom object used on the nocontents object
129  *
130  * @param obj The nocontentsl object
131  * @param custom The custom object will be used on the nocontents object
132  * @ingroup NoContents
133  */
134 EAPI void 
135 elm_nocontents_custom_set(const Evas_Object *obj, Evas_Object *custom)
136 {
137    ELM_CHECK_WIDTYPE(obj, widtype);
138    Widget_Data *wd = elm_widget_data_get(obj);
139    if (!wd) return;
140    if (!custom) return;
141    edje_object_part_swallow(wd->noc, "custom", custom);
142    wd->custom = custom;
143 }
144
145 /**
146  * Get the custom object used on the nocontents object
147  *
148  * @param obj The nocontentsl object
149  * @return The custom object inside the nocontents
150  * @ingroup NoContents
151  */
152 EAPI Evas_Object *
153 elm_nocontents_custom_get(const Evas_Object *obj)
154 {
155    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
156    Widget_Data *wd = elm_widget_data_get(obj);
157    if (!wd) return NULL;
158    return wd->custom;
159 }