1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
8 Evas_Object *chk, *icon;
14 static const char *widtype = NULL;
15 static void _del_hook(Evas_Object *obj);
16 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
17 static void _theme_hook(Evas_Object *obj);
18 static void _disable_hook(Evas_Object *obj);
19 static void _sizing_eval(Evas_Object *obj);
20 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
21 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
22 static void _signal_check_off(void *data, Evas_Object *obj, const char *emission, const char *source);
23 static void _signal_check_on(void *data, Evas_Object *obj, const char *emission, const char *source);
24 static void _signal_check_toggle(void *data, Evas_Object *obj, const char *emission, const char *source);
25 static void _on_focus_hook(void *data, Evas_Object *obj);
26 static void _activate_hook(Evas_Object *obj);
27 static void _activate(Evas_Object *obj);
28 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
29 Evas_Callback_Type type, void *event_info);
31 static const char SIG_CHANGED[] = "changed";
32 static const Evas_Smart_Cb_Description _signals[] = {
38 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
40 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
41 Evas_Event_Key_Down *ev = event_info;
42 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
43 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
44 if ((strcmp(ev->keyname, "Return")) &&
45 (strcmp(ev->keyname, "KP_Enter")) &&
46 (strcmp(ev->keyname, "space")))
49 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
55 _del_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
59 if (wd->label) eina_stringshare_del(wd->label);
64 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
66 Widget_Data *wd = elm_widget_data_get(obj);
68 if (elm_widget_focus_get(obj))
70 edje_object_signal_emit(wd->chk, "elm,action,focus", "elm");
71 evas_object_focus_set(wd->chk, EINA_TRUE);
75 edje_object_signal_emit(wd->chk, "elm,action,unfocus", "elm");
76 evas_object_focus_set(wd->chk, EINA_FALSE);
81 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
83 Widget_Data *wd = elm_widget_data_get(obj);
85 edje_object_mirrored_set(wd->chk, rtl);
89 _theme_hook(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
93 _elm_widget_mirrored_reload(obj);
94 _mirrored_set(obj, elm_widget_mirrored_get(obj));
95 _elm_theme_object_set(obj, wd->chk, "check", "base", elm_widget_style_get(obj));
97 edje_object_signal_emit(wd->chk, "elm,state,icon,visible", "elm");
99 edje_object_signal_emit(wd->chk, "elm,state,icon,hidden", "elm");
101 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
103 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
105 edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
107 edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
108 edje_object_part_text_set(wd->chk, "elm.text", wd->label);
109 if (elm_widget_disabled_get(obj))
110 edje_object_signal_emit(wd->chk, "elm,state,disabled", "elm");
111 edje_object_message_signal_process(wd->chk);
112 edje_object_scale_set(wd->chk, elm_widget_scale_get(obj) * _elm_config->scale);
117 _disable_hook(Evas_Object *obj)
119 Widget_Data *wd = elm_widget_data_get(obj);
121 if (elm_widget_disabled_get(obj))
122 edje_object_signal_emit(wd->chk, "elm,state,disabled", "elm");
124 edje_object_signal_emit(wd->chk, "elm,state,enabled", "elm");
128 _sizing_eval(Evas_Object *obj)
130 Widget_Data *wd = elm_widget_data_get(obj);
131 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
133 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
134 edje_object_size_min_restricted_calc(wd->chk, &minw, &minh, minw, minh);
135 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
136 evas_object_size_hint_min_set(obj, minw, minh);
137 evas_object_size_hint_max_set(obj, maxw, maxh);
141 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
143 Widget_Data *wd = elm_widget_data_get(data);
145 if (obj != wd->icon) return;
147 evas_object_size_hint_min_get(obj, &mw, &mh);
152 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
154 Widget_Data *wd = elm_widget_data_get(obj);
155 Evas_Object *sub = event_info;
159 edje_object_signal_emit(wd->chk, "elm,state,icon,hidden", "elm");
160 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
161 _changed_size_hints, obj);
164 edje_object_message_signal_process(wd->chk);
169 _signal_check_off(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
171 Widget_Data *wd = elm_widget_data_get(data);
173 wd->state = EINA_FALSE;
174 if (wd->statep) *wd->statep = wd->state;
175 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
176 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
180 _signal_check_on(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
182 Widget_Data *wd = elm_widget_data_get(data);
184 wd->state = EINA_TRUE;
185 if (wd->statep) *wd->statep = wd->state;
186 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
187 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
191 _signal_check_toggle(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
197 _activate_hook(Evas_Object *obj)
203 _activate(Evas_Object *obj)
205 Widget_Data *wd = elm_widget_data_get(obj);
207 wd->state = !wd->state;
208 if (wd->statep) *wd->statep = wd->state;
210 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
212 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
213 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
217 _elm_check_label_set(Evas_Object *obj, const char *item, const char *label)
219 ELM_CHECK_WIDTYPE(obj, widtype);
220 Widget_Data *wd = elm_widget_data_get(obj);
221 if (item && strcmp(item, "default")) return;
223 eina_stringshare_replace(&wd->label, label);
225 edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
227 edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
228 edje_object_message_signal_process(wd->chk);
229 edje_object_part_text_set(wd->chk, "elm.text", label);
234 _elm_check_label_get(const Evas_Object *obj, const char *item)
236 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
237 Widget_Data *wd = elm_widget_data_get(obj);
238 if (item && strcmp(item, "default")) return NULL;
239 if (!wd) return NULL;
244 elm_check_add(Evas_Object *parent)
250 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
252 ELM_SET_WIDTYPE(widtype, "check");
253 elm_widget_type_set(obj, "check");
254 elm_widget_sub_object_add(parent, obj);
255 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
256 elm_widget_data_set(obj, wd);
257 elm_widget_del_hook_set(obj, _del_hook);
258 elm_widget_theme_hook_set(obj, _theme_hook);
259 elm_widget_disable_hook_set(obj, _disable_hook);
260 elm_widget_can_focus_set(obj, EINA_TRUE);
261 elm_widget_activate_hook_set(obj, _activate_hook);
262 elm_widget_event_hook_set(obj, _event_hook);
263 elm_widget_text_set_hook_set(obj, _elm_check_label_set);
264 elm_widget_text_get_hook_set(obj, _elm_check_label_get);
266 wd->chk = edje_object_add(e);
267 _elm_theme_object_set(obj, wd->chk, "check", "base", "default");
268 edje_object_signal_callback_add(wd->chk, "elm,action,check,on", "",
269 _signal_check_on, obj);
270 edje_object_signal_callback_add(wd->chk, "elm,action,check,off", "",
271 _signal_check_off, obj);
272 edje_object_signal_callback_add(wd->chk, "elm,action,check,toggle", "",
273 _signal_check_toggle, obj);
274 elm_widget_resize_object_set(obj, wd->chk);
276 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
278 _mirrored_set(obj, elm_widget_mirrored_get(obj));
281 // TODO: convert Elementary to subclassing of Evas_Smart_Class
282 // TODO: and save some bytes, making descriptions per-class and not instance!
283 evas_object_smart_callbacks_descriptions_set(obj, _signals);
288 elm_check_label_set(Evas_Object *obj, const char *label)
290 _elm_check_label_set(obj, NULL, label);
294 elm_check_label_get(const Evas_Object *obj)
296 return _elm_check_label_get(obj, NULL);
300 elm_check_icon_set(Evas_Object *obj, Evas_Object *icon)
302 ELM_CHECK_WIDTYPE(obj, widtype);
303 Widget_Data *wd = elm_widget_data_get(obj);
305 if (wd->icon == icon) return;
306 if (wd->icon) evas_object_del(wd->icon);
310 elm_widget_sub_object_add(obj, icon);
311 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
312 _changed_size_hints, obj);
313 edje_object_part_swallow(wd->chk, "elm.swallow.content", icon);
314 edje_object_signal_emit(wd->chk, "elm,state,icon,visible", "elm");
315 edje_object_message_signal_process(wd->chk);
321 elm_check_icon_get(const Evas_Object *obj)
323 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
324 Widget_Data *wd = elm_widget_data_get(obj);
325 if (!wd) return NULL;
330 elm_check_icon_unset(Evas_Object *obj)
332 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
333 Widget_Data *wd = elm_widget_data_get(obj);
334 if (!wd) return NULL;
335 if (!wd->icon) return NULL;
336 Evas_Object *icon = wd->icon;
337 elm_widget_sub_object_del(obj, wd->icon);
338 edje_object_part_unswallow(wd->chk, wd->icon);
344 elm_check_state_set(Evas_Object *obj, Eina_Bool state)
346 ELM_CHECK_WIDTYPE(obj, widtype);
347 Widget_Data *wd = elm_widget_data_get(obj);
349 if (state != wd->state)
352 if (wd->statep) *wd->statep = wd->state;
354 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
356 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
361 elm_check_state_get(const Evas_Object *obj)
363 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
364 Widget_Data *wd = elm_widget_data_get(obj);
365 if (!wd) return EINA_FALSE;
370 elm_check_state_pointer_set(Evas_Object *obj, Eina_Bool *statep)
372 ELM_CHECK_WIDTYPE(obj, widtype);
373 Widget_Data *wd = elm_widget_data_get(obj);
378 if (*wd->statep != wd->state)
380 wd->state = *wd->statep;
382 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
384 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");