2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
6 * Copyright (c) 2009 Samsung Electronics, Inc.
9 * This software is a confidential and proprietary information
10 * of Samsung Electronics, Inc. ("Confidential Information"). You
11 * shall not disclose such Confidential Information and shall use
12 * it only in accordance with the terms of the license agreement
13 * you entered into with Samsung Electronics.
18 * @defgroup Actionslider Actionslider
21 * This is an actionslider.
24 #include <Elementary.h>
29 * internal data structure of actionslider object
31 typedef struct _Widget_Data Widget_Data;
35 Evas_Object *as; // actionslider
36 Evas_Object *icon; // an icon for a button or a bar
37 Evas_Object *icon_fake; // an icon for a button or a bar
40 Elm_Actionslider_Magnet_Pos magnet_position;
41 const char *text_left, *text_right, *text_center, *text_button;
48 Ecore_Animator *icon_animator;
49 double final_position;
52 static void _del_hook(Evas_Object *obj);
53 static void _theme_hook(Evas_Object *obj);
54 static void _disable_hook(Evas_Object *obj);
55 static void _sizing_eval(Evas_Object *obj);
56 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
61 static void _icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
62 static void _icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
63 static void _icon_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
68 static Eina_Bool _icon_animation(void *data);
70 static const char *widtype = NULL;
74 _del_hook(Evas_Object *obj)
76 Widget_Data *wd = elm_widget_data_get(obj);
80 evas_object_del(wd->icon);
85 evas_object_del(wd->icon_fake);
90 eina_stringshare_del(wd->text_left);
94 eina_stringshare_del(wd->text_right);
98 eina_stringshare_del(wd->text_center);
102 eina_stringshare_del(wd->text_button);
106 evas_object_smart_member_del(wd->as);
107 evas_object_del(wd->as);
114 _theme_hook(Evas_Object *obj)
116 Widget_Data *wd = elm_widget_data_get(obj);
118 if (edje_object_part_swallow_get(wd->as, "elm.swallow.icon") == NULL)
120 edje_object_part_unswallow(wd->as, wd->icon);
122 if (edje_object_part_swallow_get(wd->as, "elm.swallow.space") == NULL)
124 edje_object_part_unswallow(wd->as, wd->icon_fake);
127 _elm_theme_object_set(obj, wd->as, "actionslider", "base", elm_widget_style_get(obj));
128 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", elm_widget_style_get(obj));
129 _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", elm_widget_style_get(obj));
130 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
131 edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
132 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
133 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
134 edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
135 edje_object_message_signal_process(wd->as);
136 //edje_object_scale_set(wd->as, elm_widget_scale_get(obj) * _elm_config->scale);
141 _disable_hook(Evas_Object *obj)
143 // Widget_Data *wd = elm_widget_data_get(obj);
146 if (elm_widget_disabled_get(obj))
147 edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
149 edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
154 _sizing_eval(Evas_Object *obj)
156 // Widget_Data *wd = elm_widget_data_get(obj);
160 _sub_del(void *data, Evas_Object *obj, void *event_info)
162 // Widget_Data *wd = elm_widget_data_get(obj);
163 // Evas_Object *sub = event_info;
167 _icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
169 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
171 wd->mouse_down = EINA_TRUE;
175 _icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
177 Evas_Object *as = (Evas_Object *)data;
178 Widget_Data *wd = elm_widget_data_get(as);
181 elm_actionslider_hold(as, EINA_FALSE);
182 if (wd->mouse_down == EINA_FALSE) return;
184 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &pos, NULL);
188 evas_object_smart_callback_call(as, "position", "left");
192 evas_object_smart_callback_call(as, "position", "right");
195 else if (pos >= 0.495 && pos <= 0.505)
197 evas_object_smart_callback_call(as, "position", "center");
202 if ( wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
203 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
205 //edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
206 edje_object_signal_emit(wd->as, "elm,show,text,center", "elm");
208 //edje_object_signal_emit(wd->as, "elm,hide,bar,text,center", "elm");
209 edje_object_signal_emit(wd->as, "elm,hide,text,center", "elm");
216 _icon_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
218 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
219 double position = 0.0;
221 wd->mouse_down = EINA_FALSE;
223 if (wd->mouse_hold == EINA_FALSE)
225 if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_LEFT)
227 wd->final_position = 0.0;
229 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_RIGHT)
231 wd->final_position = 1.0;
233 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_CENTER)
235 wd->final_position = 0.5;
237 else if ( wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_BOTH)
239 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &position, NULL);
242 wd->final_position = 0.0;
246 wd->final_position = 1.0;
250 wd->icon_animator = ecore_animator_add(_icon_animation, wd);
255 _icon_animation(void *data)
257 Widget_Data *wd = (Widget_Data *)data;
258 double cur_position = 0.0, new_position = 0.0;
259 double move_amount = 0.05;
260 Eina_Bool flag_finish_animation = EINA_FALSE;
262 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &cur_position, NULL);
264 if ( (wd->final_position == 0.0) ||
265 (wd->final_position == 0.5 && cur_position >= wd->final_position) )
267 new_position = cur_position - move_amount;
268 if (new_position <= wd->final_position)
270 new_position = wd->final_position;
271 flag_finish_animation = EINA_TRUE;
274 else if ( (wd->final_position == 1.0) ||
275 (wd->final_position == 0.5 && cur_position < wd->final_position) )
277 new_position = cur_position + move_amount;
278 if (new_position >= wd->final_position)
280 new_position = wd->final_position;
281 flag_finish_animation = EINA_TRUE;
284 if (wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
285 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
286 edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
292 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", new_position, 0.5);
294 if (flag_finish_animation == EINA_TRUE)
305 * Add a new actionslider to the parent.
307 * @param parent The parent object
308 * @return The new actionslider object or NULL if it cannot be created
310 * @ingroup Actionslider
313 elm_actionslider_add(Evas_Object *parent)
317 Widget_Data *wd = NULL;
319 wd = ELM_NEW(Widget_Data);
320 e = evas_object_evas_get(parent);
321 if (e == NULL) return NULL;
322 ELM_SET_WIDTYPE(widtype, "actionslider");
323 obj = elm_widget_add(e);
324 elm_widget_type_set(obj, "actionslider");
325 elm_widget_sub_object_add(parent, obj);
326 elm_widget_data_set(obj, wd);
328 elm_widget_del_hook_set(obj, _del_hook);
329 elm_widget_theme_hook_set(obj, _theme_hook);
330 elm_widget_disable_hook_set(obj, _disable_hook);
332 wd->mouse_down = EINA_FALSE;
333 wd->mouse_hold = EINA_FALSE;
335 // load background edj
336 wd->as = edje_object_add(e);
339 printf("Cannot load actionslider edj!\n");
342 _elm_theme_object_set(obj, wd->as, "actionslider", "base", "default");
343 elm_widget_resize_object_set(obj, wd->as);
346 wd->icon = edje_object_add(e);
347 if (wd->icon == NULL)
349 printf("Cannot load acitionslider icon!\n");
352 evas_object_smart_member_add(wd->icon, obj);
353 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", "default");
354 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
356 wd->icon_fake = edje_object_add(e);
357 evas_object_smart_member_add(wd->icon_fake, obj);
358 _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", "default");
359 edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
362 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
363 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_DOWN, _icon_down_cb, obj);
364 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_MOVE, _icon_move_cb, obj);
365 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_UP, _icon_up_cb, obj);
372 elm_actionslider_add_with_set(Evas_Object *parent, Elm_Actionslider_Icon_Pos pos, Elm_Actionslider_Magnet_Pos magnet, const char* label_left, const char* label_center, const char* label_right)
376 obj = elm_actionslider_add(parent);
378 elm_actionslider_icon_set(obj, pos);
379 elm_actionslider_magnet_set(obj, magnet);
380 if (label_left != NULL)
381 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_LEFT, label_left);
382 if (label_center != NULL)
383 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_CENTER, label_center);
384 if (label_right != NULL)
385 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_RIGHT, label_right);
392 * Set actionslider indicator position.
394 * @param obj The actionslider object.
395 * @param pos The position of the indicator.
396 * (ELM_ACTIONSLIDER_INDICATOR_LEFT, ELM_ACTIONSLIDER_INDICATOR_RIGHT,
397 * ELM_ACTIONSLIDER_INDICATOR_CENTER)
399 * @ingroup Actionslider
402 elm_actionslider_indicator_pos_set(Evas_Object *obj, Elm_Actionslider_Indicator_Pos pos)
404 ELM_CHECK_WIDTYPE(obj, widtype);
406 Widget_Data *wd = elm_widget_data_get(obj);
407 double position = 0.0;
409 if (pos == ELM_ACTIONSLIDER_INDICATOR_LEFT)
413 else if (pos == ELM_ACTIONSLIDER_INDICATOR_RIGHT)
417 else if (pos == ELM_ACTIONSLIDER_INDICATOR_CENTER)
426 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", position, 0.5);
430 * Set actionslider magnet position.
432 * @param obj The actionslider object.
433 * @param pos The position of the magnet.
434 * (ELM_ACTIONSLIDER_MAGNET_LEFT, ELM_ACTIONSLIDER_MAGNET_RIGHT,
435 * ELM_ACTIONSLIDER_MAGNET_BOTH, ELM_ACTIONSLIDER_MAGNET_CENTER)
437 * @ingroup Actionslider
440 elm_actionslider_magnet_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
442 ELM_CHECK_WIDTYPE(obj, widtype);
443 Widget_Data *wd = elm_widget_data_get(obj);
444 wd->magnet_position = pos;
448 * Set actionslider label.
450 * @param obj The actionslider object
451 * @param pos The position of the label.
452 * (ELM_ACTIONSLIDER_LABEL_LEFT, ELM_ACTIONSLIDER_LABEL_RIGHT)
453 * @param label The label which is going to be set.
455 * @ingroup Actionslider
458 elm_actionslider_label_set(Evas_Object *obj, Elm_Actionslider_Label_Pos pos, const char *label)
460 ELM_CHECK_WIDTYPE(obj, widtype);
461 Widget_Data *wd = elm_widget_data_get(obj);
468 if (pos == ELM_ACTIONSLIDER_LABEL_RIGHT)
472 eina_stringshare_del(wd->text_right);
474 wd->text_right = eina_stringshare_add(label);
475 edje_object_part_text_set(wd->as, "elm.text.right", label);
477 else if (pos == ELM_ACTIONSLIDER_LABEL_LEFT)
481 eina_stringshare_del(wd->text_left);
483 wd->text_left = eina_stringshare_add(label);
484 edje_object_part_text_set(wd->as, "elm.text.left", label);
486 else if (pos == ELM_ACTIONSLIDER_LABEL_CENTER)
490 eina_stringshare_del(wd->text_center);
492 wd->text_center = eina_stringshare_add(label);
493 edje_object_part_text_set(wd->as, "elm.text.center", label);
495 else if (pos == ELM_ACTIONSLIDER_LABEL_BUTTON)
499 eina_stringshare_del(wd->text_button);
501 wd->text_button = eina_stringshare_add(label);
502 edje_object_part_text_set(wd->icon, "elm.text.button", label);
504 /* Resize button width */
506 txt = (Evas_Object *)edje_object_part_object_get (wd->icon, "elm.text.button");
509 evas_object_text_text_set (txt, wd->text_button);
512 evas_object_geometry_get (txt, &x,&y,&w,&h);
514 char *data_left = NULL, *data_right = NULL;
515 int pad_left = 0, pad_right = 0;
517 data_left = (char *)edje_object_data_get (wd->icon, "left");
518 data_right = (char *)edje_object_data_get (wd->icon, "right");
520 if (data_left) pad_left = atoi(data_left);
521 if (data_right) pad_right = atoi(data_right);
523 evas_object_size_hint_min_set (wd->icon, w + pad_left + pad_right, 0);
524 evas_object_size_hint_min_set (wd->icon_fake, w + pad_left + pad_right, 0);
531 * Hold actionslider object movement.
533 * @param obj The actionslider object
534 * @param flag Actionslider hold/release
535 * (EINA_TURE = hold/EIN_FALSE = release)
537 * @ingroup Actionslider
540 elm_actionslider_hold(Evas_Object *obj, Eina_Bool flag)
542 ELM_CHECK_WIDTYPE(obj, widtype);
543 Widget_Data *wd = elm_widget_data_get(obj);
545 wd->mouse_hold = flag;