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 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
28 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
29 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
31 static void _activate(Evas_Object *obj);
32 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
33 Evas_Callback_Type type, void *event_info);
35 static const char SIG_CHANGED[] = "changed";
36 static const Evas_Smart_Cb_Description _signals[] = {
42 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
44 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
45 Evas_Event_Key_Down *ev = event_info;
46 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
47 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
48 if ((strcmp(ev->keyname, "Return")) &&
49 (strcmp(ev->keyname, "KP_Enter")) &&
50 (strcmp(ev->keyname, "space")))
53 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
59 _del_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
63 if (wd->label) eina_stringshare_del(wd->label);
68 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
72 if (elm_widget_focus_get(obj))
74 edje_object_signal_emit(wd->chk, "elm,action,focus", "elm");
75 evas_object_focus_set(wd->chk, EINA_TRUE);
79 edje_object_signal_emit(wd->chk, "elm,action,unfocus", "elm");
80 evas_object_focus_set(wd->chk, EINA_FALSE);
85 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
87 Widget_Data *wd = elm_widget_data_get(obj);
89 edje_object_mirrored_set(wd->chk, rtl);
93 _theme_hook(Evas_Object *obj)
95 unsigned int counter = 0;
97 unsigned int length = 0;
98 const char *str = NULL;
100 char buffer[PATH_MAX]={'\0',};
101 char s1[PATH_MAX] = {'\0',};
102 Widget_Data *wd = elm_widget_data_get(obj);
105 _elm_widget_mirrored_reload(obj);
106 _mirrored_set(obj, elm_widget_mirrored_get(obj));
107 _elm_theme_object_set(obj, wd->chk, "check", "base", elm_widget_style_get(obj));
109 edje_object_signal_emit(wd->chk, "elm,state,icon,visible", "elm");
111 edje_object_signal_emit(wd->chk, "elm,state,icon,hidden", "elm");
113 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
115 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
117 edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
119 edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
120 edje_object_part_text_set(wd->chk, "elm.text", wd->label);
121 if (elm_widget_disabled_get(obj))
122 edje_object_signal_emit(wd->chk, "elm,state,disabled", "elm");
123 edje_object_message_signal_process(wd->chk);
124 edje_object_scale_set(wd->chk, elm_widget_scale_get(obj) * _elm_config->scale);
126 //introduced internationalization of additional text parts used in style
129 // s1 is used to store part name while buffer is used to store the part's value string
130 snprintf(labels,sizeof(labels),"label_%d",i++);
131 str = edje_object_data_get(wd->chk,labels);
133 length = strlen(str);
134 while ((str[counter]!= ' ') && (counter < length))
136 if (counter == length)
138 strncpy(s1, str, counter);
140 strncpy(buffer, str + counter, sizeof(buffer));
141 edje_object_part_text_set(wd->chk, s1, E_(buffer));
147 _disable_hook(Evas_Object *obj)
149 Widget_Data *wd = elm_widget_data_get(obj);
151 if (elm_widget_disabled_get(obj))
152 edje_object_signal_emit(wd->chk, "elm,state,disabled", "elm");
154 edje_object_signal_emit(wd->chk, "elm,state,enabled", "elm");
158 _sizing_eval(Evas_Object *obj)
160 Widget_Data *wd = elm_widget_data_get(obj);
161 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
163 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
164 edje_object_size_min_restricted_calc(wd->chk, &minw, &minh, minw, minh);
165 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
166 evas_object_size_hint_min_set(obj, minw, minh);
167 evas_object_size_hint_max_set(obj, maxw, maxh);
171 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
173 Widget_Data *wd = elm_widget_data_get(data);
175 if (obj != wd->icon) return;
177 evas_object_size_hint_min_get(obj, &mw, &mh);
182 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
184 Widget_Data *wd = elm_widget_data_get(obj);
185 Evas_Object *sub = event_info;
189 edje_object_signal_emit(wd->chk, "elm,state,icon,hidden", "elm");
190 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
191 _changed_size_hints, obj);
194 edje_object_message_signal_process(wd->chk);
199 _signal_check_off(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
201 Widget_Data *wd = elm_widget_data_get(data);
203 wd->state = EINA_FALSE;
204 if (wd->statep) *wd->statep = wd->state;
205 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
206 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
210 _signal_check_on(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
212 Widget_Data *wd = elm_widget_data_get(data);
214 wd->state = EINA_TRUE;
215 if (wd->statep) *wd->statep = wd->state;
216 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
217 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
221 _signal_check_toggle(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
227 _activate_hook(Evas_Object *obj)
233 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content)
235 ELM_CHECK_WIDTYPE(obj, widtype);
236 Widget_Data *wd = elm_widget_data_get(obj);
238 if (wd->icon == content) return;
239 if (wd->icon) evas_object_del(wd->icon);
243 elm_widget_sub_object_add(obj, content);
244 evas_object_event_callback_add(content,
245 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
246 _changed_size_hints, obj);
247 edje_object_part_swallow(wd->chk, "elm.swallow.content", content);
248 edje_object_signal_emit(wd->chk, "elm,state,icon,visible", "elm");
249 edje_object_message_signal_process(wd->chk);
255 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
257 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
258 Widget_Data *wd = elm_widget_data_get(obj);
259 if (!wd) return NULL;
264 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
266 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
267 Widget_Data *wd = elm_widget_data_get(obj);
268 if (!wd) return NULL;
269 if (!wd->icon) return NULL;
270 Evas_Object *icon = wd->icon;
271 elm_widget_sub_object_del(obj, wd->icon);
272 evas_object_event_callback_del_full(wd->icon,
273 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
274 _changed_size_hints, obj);
275 edje_object_part_unswallow(wd->chk, wd->icon);
281 _activate(Evas_Object *obj)
283 Widget_Data *wd = elm_widget_data_get(obj);
285 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
286 (_elm_access_2nd_click_timeout(obj)))
288 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
289 wd->state = !wd->state;
290 if (wd->statep) *wd->statep = wd->state;
293 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
294 _elm_access_say(E_("State: On"));
298 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
299 _elm_access_say(E_("State: Off"));
301 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
306 _elm_check_label_set(Evas_Object *obj, const char *item, const char *label)
308 ELM_CHECK_WIDTYPE(obj, widtype);
309 Widget_Data *wd = elm_widget_data_get(obj);
310 if (item && strcmp(item, "default")) return;
312 eina_stringshare_replace(&wd->label, label);
314 edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
316 edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
317 edje_object_message_signal_process(wd->chk);
318 edje_object_part_text_set(wd->chk, "elm.text", label);
323 _elm_check_label_get(const Evas_Object *obj, const char *item)
325 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
326 Widget_Data *wd = elm_widget_data_get(obj);
327 if (item && strcmp(item, "default")) return NULL;
328 if (!wd) return NULL;
333 _access_info_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Widget_Item *item __UNUSED__)
335 char *txt = (char *)elm_widget_access_info_get(obj);
336 if (!txt) txt = (char *)_elm_check_label_get(obj, NULL);
337 if (txt) return strdup(txt);
342 _access_state_cb(void *data, Evas_Object *obj, Elm_Widget_Item *item __UNUSED__)
344 Evas_Object *o = data;
345 Widget_Data *wd = elm_widget_data_get(o);
346 if (!wd) return NULL;
347 if (elm_widget_disabled_get(obj))
348 return strdup(E_("State: Disabled"));
350 return strdup(E_("State: On"));
351 return strdup(E_("State: Off"));
355 elm_check_add(Evas_Object *parent)
361 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
363 ELM_SET_WIDTYPE(widtype, "check");
364 elm_widget_type_set(obj, "check");
365 elm_widget_sub_object_add(parent, obj);
366 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
367 elm_widget_data_set(obj, wd);
368 elm_widget_del_hook_set(obj, _del_hook);
369 elm_widget_theme_hook_set(obj, _theme_hook);
370 elm_widget_disable_hook_set(obj, _disable_hook);
371 elm_widget_can_focus_set(obj, EINA_TRUE);
372 elm_widget_activate_hook_set(obj, _activate_hook);
373 elm_widget_event_hook_set(obj, _event_hook);
374 elm_widget_text_set_hook_set(obj, _elm_check_label_set);
375 elm_widget_text_get_hook_set(obj, _elm_check_label_get);
376 elm_widget_content_set_hook_set(obj, _content_set_hook);
377 elm_widget_content_get_hook_set(obj, _content_get_hook);
378 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
380 wd->chk = edje_object_add(e);
381 _elm_theme_object_set(obj, wd->chk, "check", "base", "default");
382 edje_object_signal_callback_add(wd->chk, "elm,action,check,on", "",
383 _signal_check_on, obj);
384 edje_object_signal_callback_add(wd->chk, "elm,action,check,off", "",
385 _signal_check_off, obj);
386 edje_object_signal_callback_add(wd->chk, "elm,action,check,toggle", "",
387 _signal_check_toggle, obj);
388 elm_widget_resize_object_set(obj, wd->chk);
390 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
392 _mirrored_set(obj, elm_widget_mirrored_get(obj));
395 // TODO: convert Elementary to subclassing of Evas_Smart_Class
396 // TODO: and save some bytes, making descriptions per-class and not instance!
397 evas_object_smart_callbacks_descriptions_set(obj, _signals);
399 _elm_access_object_register(obj, wd->chk);
400 _elm_access_text_set(_elm_access_object_get(obj),
401 ELM_ACCESS_TYPE, E_("Check"));
402 _elm_access_callback_set(_elm_access_object_get(obj),
403 ELM_ACCESS_INFO, _access_info_cb, obj);
404 _elm_access_callback_set(_elm_access_object_get(obj),
405 ELM_ACCESS_STATE, _access_state_cb, obj);
410 elm_check_label_set(Evas_Object *obj, const char *label)
412 _elm_check_label_set(obj, NULL, label);
416 elm_check_label_get(const Evas_Object *obj)
418 return _elm_check_label_get(obj, NULL);
422 elm_check_icon_set(Evas_Object *obj, Evas_Object *icon)
424 _content_set_hook(obj, NULL, icon);
428 elm_check_icon_get(const Evas_Object *obj)
430 return _content_get_hook(obj, NULL);
434 elm_check_icon_unset(Evas_Object *obj)
436 return _content_unset_hook(obj, NULL);
440 elm_check_state_set(Evas_Object *obj, Eina_Bool state)
442 ELM_CHECK_WIDTYPE(obj, widtype);
443 Widget_Data *wd = elm_widget_data_get(obj);
445 if (state != wd->state)
448 if (wd->statep) *wd->statep = wd->state;
450 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
452 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
454 edje_object_message_signal_process(wd->chk);
458 elm_check_state_get(const Evas_Object *obj)
460 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
461 Widget_Data *wd = elm_widget_data_get(obj);
462 if (!wd) return EINA_FALSE;
467 elm_check_state_pointer_set(Evas_Object *obj, Eina_Bool *statep)
469 ELM_CHECK_WIDTYPE(obj, widtype);
470 Widget_Data *wd = elm_widget_data_get(obj);
475 if (*wd->statep != wd->state)
477 wd->state = *wd->statep;
479 edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
481 edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");