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, enabled_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;
72 #define SIG_CHANGED "position"
73 #define SIG_SELECTED "selected"
75 static const Evas_Smart_Cb_Description _signals[] =
84 _del_hook(Evas_Object *obj)
86 Widget_Data *wd = elm_widget_data_get(obj);
90 evas_object_del(wd->icon);
95 evas_object_del(wd->icon_fake);
98 if (wd->text_left) eina_stringshare_del(wd->text_left);
99 if (wd->text_right) eina_stringshare_del(wd->text_right);
100 if (wd->text_center) eina_stringshare_del(wd->text_center);
101 if (wd->text_button) eina_stringshare_del(wd->text_button);
104 evas_object_smart_member_del(wd->as);
105 evas_object_del(wd->as);
112 _sizing_eval(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
115 Evas_Coord minw = -1, minh = -1;
118 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
119 evas_object_size_hint_min_set(wd->icon, minw, minh);
120 evas_object_size_hint_max_set(wd->icon, -1, -1);
124 elm_coords_finger_size_adjust(3, &minw, 1, &minh);
125 edje_object_size_min_restricted_calc(wd->as, &minw, &minh, minw, minh);
126 evas_object_size_hint_min_set(obj, minw, minh);
127 evas_object_size_hint_max_set(obj, -1, -1);
131 _theme_hook(Evas_Object *obj)
133 Widget_Data *wd = elm_widget_data_get(obj);
135 if (edje_object_part_swallow_get(wd->as, "elm.swallow.icon") == NULL)
136 edje_object_part_unswallow(wd->as, wd->icon);
137 if (edje_object_part_swallow_get(wd->as, "elm.swallow.space") == NULL)
138 edje_object_part_unswallow(wd->as, wd->icon_fake);
140 _elm_theme_object_set(obj, wd->as, "actionslider", "base", elm_widget_style_get(obj));
141 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", elm_widget_style_get(obj));
142 _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", elm_widget_style_get(obj));
143 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
144 edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
145 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
146 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
147 edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
148 edje_object_message_signal_process(wd->as);
149 //edje_object_scale_set(wd->as, elm_widget_scale_get(obj) * _elm_config->scale);
154 _disable_hook(Evas_Object *obj)
156 // Widget_Data *wd = elm_widget_data_get(obj);
159 if (elm_widget_disabled_get(obj))
160 edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
162 edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
167 _sub_del(void *data, Evas_Object *obj, void *event_info)
169 // Widget_Data *wd = elm_widget_data_get(obj);
170 // Evas_Object *sub = event_info;
174 _icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
176 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
178 wd->mouse_down = EINA_TRUE;
182 _icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
184 Evas_Object *as = (Evas_Object *)data;
185 Widget_Data *wd = elm_widget_data_get(as);
188 elm_actionslider_hold(as, EINA_FALSE);
189 if (wd->mouse_down == EINA_FALSE) return;
191 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &pos, NULL);
194 evas_object_smart_callback_call(as, SIG_CHANGED, "left");
196 evas_object_smart_callback_call(as, SIG_CHANGED, "right");
197 else if (pos >= 0.495 && pos <= 0.505)
198 evas_object_smart_callback_call(as, SIG_CHANGED, "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)
226 wd->final_position = 0.0;
227 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_RIGHT)
228 wd->final_position = 1.0;
229 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_CENTER)
230 wd->final_position = 0.5;
231 else if ( wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_BOTH)
233 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &position, NULL);
235 wd->final_position = 0.0;
237 wd->final_position = 1.0;
239 wd->icon_animator = ecore_animator_add(_icon_animation, wd);
244 _icon_animation(void *data)
246 Widget_Data *wd = elm_widget_data_get(data);
247 double cur_position = 0.0, new_position = 0.0;
248 double move_amount = 0.05;
249 Eina_Bool flag_finish_animation = EINA_FALSE;
250 if (!wd) return EINA_FALSE;
252 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &cur_position, NULL);
254 if ( (wd->final_position == 0.0) ||(wd->final_position == 0.5 && cur_position >= wd->final_position) )
256 new_position = cur_position - move_amount;
257 if (new_position <= wd->final_position)
259 new_position = wd->final_position;
260 flag_finish_animation = EINA_TRUE;
263 else if ((wd->final_position == 1.0) || (wd->final_position == 0.5 && cur_position < wd->final_position) )
265 new_position = cur_position + move_amount;
266 if (new_position >= wd->final_position)
268 new_position = wd->final_position;
269 flag_finish_animation = EINA_TRUE;
272 if (wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
273 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
274 edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
279 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", new_position, 0.5);
281 if (flag_finish_animation)
283 if ((!wd->final_position) &&
284 (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_LEFT))
285 evas_object_smart_callback_call(data, SIG_SELECTED,
286 (void *)wd->text_left);
287 else if ((wd->final_position == 0.5) &&
288 (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_CENTER))
289 evas_object_smart_callback_call(data, SIG_SELECTED,
290 (void *)wd->text_center);
291 else if ((wd->final_position == 1) &&
292 (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_RIGHT))
293 evas_object_smart_callback_call(data, SIG_SELECTED,
294 (void *)wd->text_right);
302 * Add a new actionslider to the parent.
304 * @param[in] parent The parent object
305 * @return The new actionslider object or NULL if it cannot be created
307 * @ingroup Actionslider
310 elm_actionslider_add(Evas_Object *parent)
314 Widget_Data *wd = NULL;
316 wd = ELM_NEW(Widget_Data);
317 e = evas_object_evas_get(parent);
318 if (e == NULL) return NULL;
319 ELM_SET_WIDTYPE(widtype, "actionslider");
320 obj = elm_widget_add(e);
321 elm_widget_type_set(obj, "actionslider");
322 elm_widget_sub_object_add(parent, obj);
323 elm_widget_data_set(obj, wd);
325 elm_widget_del_hook_set(obj, _del_hook);
326 elm_widget_theme_hook_set(obj, _theme_hook);
327 elm_widget_disable_hook_set(obj, _disable_hook);
329 wd->mouse_down = EINA_FALSE;
330 wd->mouse_hold = EINA_FALSE;
331 wd->enabled_position = ELM_ACTIONSLIDER_MAGNET_ALL;
333 // load background edj
334 wd->as = edje_object_add(e);
337 printf("Cannot load actionslider edj!\n");
340 _elm_theme_object_set(obj, wd->as, "actionslider", "base", "default");
341 elm_widget_resize_object_set(obj, wd->as);
344 wd->icon = edje_object_add(e);
345 if (wd->icon == NULL)
347 printf("Cannot load acitionslider icon!\n");
350 evas_object_smart_member_add(wd->icon, obj);
351 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", "default");
352 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
354 wd->icon_fake = edje_object_add(e);
355 evas_object_smart_member_add(wd->icon_fake, obj);
356 _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", "default");
357 edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
360 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
361 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_DOWN, _icon_down_cb, obj);
362 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_MOVE, _icon_move_cb, obj);
363 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_UP, _icon_up_cb, obj);
370 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)
374 obj = elm_actionslider_add(parent);
376 elm_actionslider_icon_set(obj, pos);
377 elm_actionslider_magnet_set(obj, magnet);
378 if (label_left != NULL)
379 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_LEFT, label_left);
380 if (label_center != NULL)
381 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_CENTER, label_center);
382 if (label_right != NULL)
383 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_RIGHT, label_right);
390 * Set actionslider indicator position.
392 * @param[in] obj The actionslider object.
393 * @param[in] pos The position of the indicator.
394 * (ELM_ACTIONSLIDER_INDICATOR_LEFT, ELM_ACTIONSLIDER_INDICATOR_RIGHT,
395 * ELM_ACTIONSLIDER_INDICATOR_CENTER)
397 * @ingroup Actionslider
400 elm_actionslider_indicator_pos_set(Evas_Object *obj, Elm_Actionslider_Indicator_Pos pos)
402 ELM_CHECK_WIDTYPE(obj, widtype);
404 Widget_Data *wd = elm_widget_data_get(obj);
405 double position = 0.0;
407 if (pos == ELM_ACTIONSLIDER_INDICATOR_LEFT) position = 0.0;
408 else if (pos == ELM_ACTIONSLIDER_INDICATOR_RIGHT) position = 1.0;
409 else if (pos == ELM_ACTIONSLIDER_INDICATOR_CENTER) position = 0.5;
412 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", position, 0.5);
416 * Get actionslider indicator position.
418 * @param obj The actionslider object.
419 * @return The position of the indicator.
421 * @ingroup Actionslider
423 EAPI Elm_Actionslider_Indicator_Pos
424 elm_actionslider_indicator_pos_get(const Evas_Object *obj)
426 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_INDICATOR_NONE;
427 Widget_Data *wd = elm_widget_data_get(obj);
429 if (!wd) return ELM_ACTIONSLIDER_INDICATOR_NONE;
431 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &position, NULL);
433 return ELM_ACTIONSLIDER_INDICATOR_LEFT;
434 else if (position < 0.7)
435 return ELM_ACTIONSLIDER_INDICATOR_CENTER;
437 return ELM_ACTIONSLIDER_INDICATOR_RIGHT;
440 * Set actionslider magnet position.
442 * @param[in] obj The actionslider object.
443 * @param[in] pos The position of the magnet.
444 * (ELM_ACTIONSLIDER_MAGNET_LEFT, ELM_ACTIONSLIDER_MAGNET_RIGHT,
445 * ELM_ACTIONSLIDER_MAGNET_BOTH, ELM_ACTIONSLIDER_MAGNET_CENTER)
447 * @ingroup Actionslider
450 elm_actionslider_magnet_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
452 ELM_CHECK_WIDTYPE(obj, widtype);
453 Widget_Data *wd = elm_widget_data_get(obj);
454 wd->magnet_position = pos;
458 * Get actionslider magnet position.
460 * @param obj The actionslider object.
461 * @return The positions with magnet property.
463 * @ingroup Actionslider
465 EAPI Elm_Actionslider_Magnet_Pos
466 elm_actionslider_magnet_pos_get(const Evas_Object *obj)
468 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_MAGNET_NONE;
469 Widget_Data *wd = elm_widget_data_get(obj);
470 if (!wd) return ELM_ACTIONSLIDER_MAGNET_NONE;
471 return wd->magnet_position;
475 * Set actionslider enabled position.
477 * All the positions are enabled by default.
479 * @param obj The actionslider object.
480 * @param pos Bit mask indicating the enabled positions.
481 * Example: use (ELM_ACTIONSLIDER_MAGNET_LEFT | ELM_ACTIONSLIDER_MAGNET_RIGHT)
482 * to enable both positions, so the user can select it.
484 * @ingroup Actionslider
487 elm_actionslider_enabled_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
489 ELM_CHECK_WIDTYPE(obj, widtype);
490 Widget_Data *wd = elm_widget_data_get(obj);
492 wd->enabled_position = pos;
496 * Get actionslider enabled position.
498 * All the positions are enabled by default.
500 * @param obj The actionslider object.
501 * @return The enabled positions.
503 * @ingroup Actionslider
505 EAPI Elm_Actionslider_Magnet_Pos
506 elm_actionslider_enabled_pos_get(const Evas_Object *obj)
508 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_MAGNET_NONE;
509 Widget_Data *wd = elm_widget_data_get(obj);
510 if (!wd) return ELM_ACTIONSLIDER_MAGNET_NONE;
511 return wd->enabled_position;
515 * Set actionslider label.
517 * @param[in] obj The actionslider object
518 * @param[in] pos The position of the label.
519 * (ELM_ACTIONSLIDER_LABEL_LEFT, ELM_ACTIONSLIDER_LABEL_RIGHT)
520 * @param label The label which is going to be set.
522 * @ingroup Actionslider
525 elm_actionslider_label_set(Evas_Object *obj, Elm_Actionslider_Label_Pos pos, const char *label)
527 ELM_CHECK_WIDTYPE(obj, widtype);
528 Widget_Data *wd = elm_widget_data_get(obj);
530 if(label == NULL) label = "";
532 if (pos == ELM_ACTIONSLIDER_LABEL_RIGHT)
534 if (wd->text_right) eina_stringshare_del(wd->text_right);
535 wd->text_right = eina_stringshare_add(label);
536 edje_object_part_text_set(wd->as, "elm.text.right", label);
538 else if (pos == ELM_ACTIONSLIDER_LABEL_LEFT)
540 if (wd->text_left) eina_stringshare_del(wd->text_left);
541 wd->text_left = eina_stringshare_add(label);
542 edje_object_part_text_set(wd->as, "elm.text.left", label);
544 else if (pos == ELM_ACTIONSLIDER_LABEL_CENTER)
546 if (wd->text_center) eina_stringshare_del(wd->text_center);
547 wd->text_center = eina_stringshare_add(label);
548 edje_object_part_text_set(wd->as, "elm.text.center", label);
550 else if (pos == ELM_ACTIONSLIDER_LABEL_BUTTON)
552 if (wd->text_button) eina_stringshare_del(wd->text_button);
553 wd->text_button = eina_stringshare_add(label);
554 edje_object_part_text_set(wd->icon, "elm.text.button", label);
556 /* Resize button width */
558 txt = (Evas_Object *)edje_object_part_object_get (wd->icon, "elm.text.button");
561 evas_object_text_text_set (txt, wd->text_button);
564 evas_object_geometry_get (txt, &x,&y,&w,&h);
566 char *data_left = NULL, *data_right = NULL;
567 int pad_left = 0, pad_right = 0;
569 data_left = (char *)edje_object_data_get (wd->icon, "left");
570 data_right = (char *)edje_object_data_get (wd->icon, "right");
572 if (data_left) pad_left = atoi(data_left);
573 if (data_right) pad_right = atoi(data_right);
575 evas_object_size_hint_min_set (wd->icon, w + pad_left + pad_right, 0);
576 evas_object_size_hint_min_set (wd->icon_fake, w + pad_left + pad_right, 0);
583 * Get actionslider labels.
585 * @param obj The actionslider object
586 * @param left_label A char** to place the left_label of @p obj into
587 * @param center_label A char** to place the center_label of @p obj into
588 * @param right_label A char** to place the right_label of @p obj into
590 * @ingroup Actionslider
593 elm_actionslider_labels_get(const Evas_Object *obj, const char **left_label, const char **center_label, const char **right_label)
595 if (left_label) *left_label= NULL;
596 if (center_label) *center_label= NULL;
597 if (right_label) *right_label= NULL;
598 ELM_CHECK_WIDTYPE(obj, widtype);
599 Widget_Data *wd = elm_widget_data_get(obj);
601 if (left_label) *left_label = wd->text_left;
602 if (center_label) *center_label = wd->text_center;
603 if (right_label) *right_label = wd->text_right;
607 * Set the label used on the indicator object.
609 * @param obj The actionslider object
610 * @param label The label which is going to be set.
612 * @ingroup Actionslider
615 elm_actionslider_indicator_label_set(Evas_Object *obj, const char *label)
617 ELM_CHECK_WIDTYPE(obj, widtype);
618 Widget_Data *wd = elm_widget_data_get(obj);
621 eina_stringshare_replace(&wd->text_button, label);
622 edje_object_part_text_set(wd->as, "elm.text.button", wd->text_button);
626 * Get the label used on the indicator object.
628 * @param obj The actionslider object
629 * @return The indicator label
631 * @ingroup Actionslider
634 elm_actionslider_indicator_label_get(Evas_Object *obj)
636 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
637 Widget_Data *wd = elm_widget_data_get(obj);
638 if (!wd) return NULL;
639 return wd->text_button;
643 * Hold actionslider object movement.
645 * @param[in] obj The actionslider object
646 * @param[in] flag Actionslider hold/release
647 * (EINA_TURE = hold/EIN_FALSE = release)
649 * @ingroup Actionslider
652 elm_actionslider_hold(Evas_Object *obj, Eina_Bool flag)
654 ELM_CHECK_WIDTYPE(obj, widtype);
655 Widget_Data *wd = elm_widget_data_get(obj);
657 wd->mouse_hold = flag;