1 #include <Elementary.h>
4 #include "elm_widget_actionslider.h"
6 EAPI const char ELM_ACTIONSLIDER_SMART_NAME[] = "elm_actionslider";
8 static const Elm_Layout_Part_Alias_Description _text_aliases[] =
10 {"indicator", "elm.text.indicator"},
11 {"left", "elm.text.left"},
12 {"right", "elm.text.right"},
13 {"center", "elm.text.center"},
17 static const char SIG_CHANGED[] = "pos_changed";
18 static const char SIG_SELECTED[] = "selected";
19 static const Evas_Smart_Cb_Description _smart_callbacks[] =
26 EVAS_SMART_SUBCLASS_NEW
27 (ELM_ACTIONSLIDER_SMART_NAME, _elm_actionslider,
28 Elm_Actionslider_Smart_Class, Elm_Layout_Smart_Class,
29 elm_layout_smart_class_get, _smart_callbacks);
31 static Elm_Actionslider_Pos
32 _get_pos_by_orientation(const Evas_Object *obj,
33 Elm_Actionslider_Pos pos)
35 if (elm_widget_mirrored_get(obj))
39 case ELM_ACTIONSLIDER_LEFT:
40 pos = ELM_ACTIONSLIDER_RIGHT;
43 case ELM_ACTIONSLIDER_RIGHT:
44 pos = ELM_ACTIONSLIDER_LEFT;
55 _elm_actionslider_smart_sizing_eval(Evas_Object *obj)
57 Evas_Coord minw = -1, minh = -1;
59 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
61 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
62 evas_object_size_hint_min_set(sd->drag_button_base, minw, minh);
63 evas_object_size_hint_max_set(sd->drag_button_base, -1, -1);
67 elm_coords_finger_size_adjust(3, &minw, 1, &minh);
68 edje_object_size_min_restricted_calc
69 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
70 evas_object_size_hint_min_set(obj, minw, minh);
71 evas_object_size_hint_max_set(obj, -1, -1);
75 _mirroredness_change_eval(Evas_Object *obj)
80 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
82 left = (char *)elm_layout_text_get(obj, "elm.text.left");
83 if (left) left = strdup(left);
86 (obj, "elm.text.left", elm_layout_text_get(obj, "elm.text.right"));
87 elm_layout_text_set(obj, "elm.text.right", left);
91 edje_object_part_drag_value_get
92 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", &pos, NULL);
93 edje_object_part_drag_value_set
94 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", 1.0 - pos, 0.5);
98 _elm_actionslider_smart_theme(Evas_Object *obj)
102 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
104 mirrored = elm_object_mirrored_get(obj);
106 if (!ELM_WIDGET_CLASS(_elm_actionslider_parent_sc)->theme(obj))
109 if (elm_object_mirrored_get(obj) != mirrored)
110 _mirroredness_change_eval(obj);
112 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
118 _drag_button_down_cb(void *data,
119 Evas_Object *o __UNUSED__,
120 const char *emission __UNUSED__,
121 const char *source __UNUSED__)
123 Elm_Actionslider_Smart_Data *sd = data;
125 sd->mouse_down = EINA_TRUE;
129 _drag_button_move_cb(void *data,
130 Evas_Object *o __UNUSED__,
131 const char *emission __UNUSED__,
132 const char *source __UNUSED__)
134 Evas_Object *obj = data;
137 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
139 if (!sd->mouse_down) return;
141 edje_object_part_drag_value_get
142 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", &pos, NULL);
144 evas_object_smart_callback_call
145 (obj, SIG_CHANGED, !elm_widget_mirrored_get(obj) ? "left" : "right");
147 evas_object_smart_callback_call
148 (obj, SIG_CHANGED, !elm_widget_mirrored_get(obj) ? "right" : "left");
149 else if (pos >= 0.45 && pos <= 0.55)
150 evas_object_smart_callback_call(obj, SIG_CHANGED, "center");
154 _text_get(const Evas_Object *obj,
159 /* mirroredness already evaluated by the two calls below */
160 *left = elm_layout_text_get(obj, "left");
161 *right = elm_layout_text_get(obj, "right");
162 *center = elm_layout_text_get(obj, "center");
166 _button_animator(void *data)
168 Evas_Object *obj = data;
169 double move_amount = 0.05;
170 Eina_Bool flag_finish_animation = EINA_FALSE;
171 double cur_position = 0.0, new_position = 0.0;
173 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
175 edje_object_part_drag_value_get
176 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base",
177 &cur_position, NULL);
179 double adjusted_final;
181 adjusted_final = (!elm_widget_mirrored_get(obj)) ?
182 sd->final_position : 1.0 - sd->final_position;
184 if ((adjusted_final == 0.0) ||
185 (adjusted_final == 0.5 && cur_position >= adjusted_final))
187 new_position = cur_position - move_amount;
189 if (new_position <= adjusted_final)
191 new_position = adjusted_final;
192 flag_finish_animation = EINA_TRUE;
195 else if ((adjusted_final == 1.0) ||
196 (adjusted_final == 0.5 && cur_position < adjusted_final))
198 new_position = cur_position + move_amount;
200 if (new_position >= adjusted_final)
202 new_position = adjusted_final;
203 flag_finish_animation = EINA_TRUE;
206 edje_object_part_drag_value_set
207 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base",
211 if (flag_finish_animation)
213 const char *left, *right, *center;
215 _text_get(obj, &left, &right, ¢er);
217 if ((!sd->final_position) &&
218 (sd->enabled_position & ELM_ACTIONSLIDER_LEFT))
219 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)left);
220 else if ((sd->final_position == 0.5) &&
221 (sd->enabled_position & ELM_ACTIONSLIDER_CENTER))
222 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)center);
223 else if ((sd->final_position == 1) &&
224 (sd->enabled_position & ELM_ACTIONSLIDER_RIGHT))
225 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)right);
227 sd->button_animator = NULL;
229 return ECORE_CALLBACK_CANCEL;
232 return ECORE_CALLBACK_RENEW;
236 _drag_button_up_cb(void *data,
237 Evas_Object *o __UNUSED__,
238 const char *emission __UNUSED__,
239 const char *source __UNUSED__)
241 Evas_Object *obj = data;
242 double position = 0.0;
244 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
246 sd->mouse_down = EINA_FALSE;
248 edje_object_part_drag_value_get
249 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", &position,
252 const char *left, *right, *center;
254 _text_get(obj, &left, &right, ¢er);
256 if ((sd->enabled_position & ELM_ACTIONSLIDER_LEFT) &&
257 ((!elm_widget_mirrored_get(obj) && position == 0.0) ||
258 (elm_widget_mirrored_get(obj) && position == 1.0)))
260 sd->final_position = 0;
261 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)left);
266 if (position >= 0.45 && position <= 0.55 &&
267 (sd->enabled_position & ELM_ACTIONSLIDER_CENTER))
269 sd->final_position = 0.5;
270 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)center);
272 if (sd->button_animator) ecore_animator_del(sd->button_animator);
273 sd->button_animator = ecore_animator_add(_button_animator, obj);
278 if ((sd->enabled_position & ELM_ACTIONSLIDER_RIGHT) &&
279 ((!elm_widget_mirrored_get(obj) && position == 1.0) ||
280 (elm_widget_mirrored_get(obj) && position == 0.0)))
282 sd->final_position = 1;
283 evas_object_smart_callback_call(obj, SIG_SELECTED, (char *)right);
287 if (sd->magnet_position == ELM_ACTIONSLIDER_NONE) return;
289 #define _FIX_POS_ON_MIRROREDNESS(x) \
290 ((!elm_widget_mirrored_get(obj)) ? x : 1.0 - x)
292 position = _FIX_POS_ON_MIRROREDNESS(position);
296 if (sd->magnet_position & ELM_ACTIONSLIDER_LEFT)
297 sd->final_position = 0;
298 else if (sd->magnet_position & ELM_ACTIONSLIDER_CENTER)
299 sd->final_position = 0.5;
300 else if (sd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
301 sd->final_position = 1;
303 else if ((position >= 0.3) && (position <= 0.7))
305 if (sd->magnet_position & ELM_ACTIONSLIDER_CENTER)
306 sd->final_position = 0.5;
307 else if (position < 0.5)
309 if (sd->magnet_position & ELM_ACTIONSLIDER_LEFT)
310 sd->final_position = 0;
312 sd->final_position = 1;
316 if (sd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
317 sd->final_position = 1;
319 sd->final_position = 0;
324 if (sd->magnet_position & ELM_ACTIONSLIDER_RIGHT)
325 sd->final_position = 1;
326 else if (sd->magnet_position & ELM_ACTIONSLIDER_CENTER)
327 sd->final_position = 0.5;
329 sd->final_position = 0;
331 if (sd->button_animator) ecore_animator_del(sd->button_animator);
332 sd->button_animator = ecore_animator_add(_button_animator, obj);
334 #undef _FINAL_FIX_POS_ON_MIRROREDNESS
338 _mirrored_part_fix(const Evas_Object *obj,
341 if (elm_widget_mirrored_get(obj))
343 /* exchange left and right */
344 if (!strcmp(*part, "left")) *part = "right";
345 else if (!strcmp(*part, "right"))
347 else if (!strcmp(*part, "elm.text.right"))
348 *part = "elm.text.left";
349 else if (!strcmp(*part, "elm.text.left"))
350 *part = "elm.text.right";
355 _elm_actionslider_smart_text_set(Evas_Object *obj,
359 _mirrored_part_fix(obj, &item);
361 return _elm_actionslider_parent_sc->text_set(obj, item, label);
365 _elm_actionslider_smart_text_get(const Evas_Object *obj,
368 _mirrored_part_fix(obj, &item);
370 return _elm_actionslider_parent_sc->text_get(obj, item);
374 _elm_actionslider_smart_add(Evas_Object *obj)
376 EVAS_SMART_DATA_ALLOC(obj, Elm_Actionslider_Smart_Data);
378 ELM_WIDGET_CLASS(_elm_actionslider_parent_sc)->base.add(obj);
380 priv->mouse_down = EINA_FALSE;
381 priv->enabled_position = ELM_ACTIONSLIDER_ALL;
383 priv->drag_button_base =
384 evas_object_rectangle_add(evas_object_evas_get(obj));
385 evas_object_color_set(priv->drag_button_base, 0, 0, 0, 0);
387 edje_object_signal_callback_add
388 (ELM_WIDGET_DATA(priv)->resize_obj, "elm.drag_button,mouse,up", "",
389 _drag_button_up_cb, obj);
390 edje_object_signal_callback_add
391 (ELM_WIDGET_DATA(priv)->resize_obj, "elm.drag_button,mouse,down", "",
392 _drag_button_down_cb, priv);
393 edje_object_signal_callback_add
394 (ELM_WIDGET_DATA(priv)->resize_obj, "elm.drag_button,mouse,move", "",
395 _drag_button_move_cb, obj);
398 (obj, "actionslider", "base", elm_widget_style_get(obj));
400 elm_layout_content_set(obj, "elm.drag_button_base", priv->drag_button_base);
402 elm_layout_sizing_eval(obj);
406 _elm_actionslider_smart_set_user(Elm_Actionslider_Smart_Class *sc)
408 ELM_WIDGET_CLASS(sc)->base.add = _elm_actionslider_smart_add;
410 /* not a 'focus chain manager' */
411 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
412 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
414 ELM_WIDGET_CLASS(sc)->theme = _elm_actionslider_smart_theme;
416 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_actionslider_smart_sizing_eval;
417 ELM_LAYOUT_CLASS(sc)->text_set = _elm_actionslider_smart_text_set;
418 ELM_LAYOUT_CLASS(sc)->text_get = _elm_actionslider_smart_text_get;
420 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
423 EAPI const Elm_Actionslider_Smart_Class *
424 elm_actionslider_smart_class_get(void)
426 static Elm_Actionslider_Smart_Class _sc =
427 ELM_ACTIONSLIDER_SMART_CLASS_INIT_NAME_VERSION
428 (ELM_ACTIONSLIDER_SMART_NAME);
429 static const Elm_Actionslider_Smart_Class *class = NULL;
430 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
435 _elm_actionslider_smart_set(&_sc);
436 esc->callbacks = _smart_callbacks;
443 elm_actionslider_add(Evas_Object *parent)
447 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
449 obj = elm_widget_add(_elm_actionslider_smart_class_new(), parent);
450 if (!obj) return NULL;
452 if (!elm_widget_sub_object_add(parent, obj))
453 ERR("could not add %p as sub object of %p", obj, parent);
459 elm_actionslider_indicator_pos_set(Evas_Object *obj,
460 Elm_Actionslider_Pos pos)
462 double position = 0.0;
464 ELM_ACTIONSLIDER_CHECK(obj);
465 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
467 pos = _get_pos_by_orientation(obj, pos);
468 if (pos == ELM_ACTIONSLIDER_CENTER) position = 0.5;
469 else if (pos == ELM_ACTIONSLIDER_RIGHT)
472 edje_object_part_drag_value_set
473 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", position, 0.5);
476 EAPI Elm_Actionslider_Pos
477 elm_actionslider_indicator_pos_get(const Evas_Object *obj)
481 ELM_ACTIONSLIDER_CHECK(obj) ELM_ACTIONSLIDER_NONE;
482 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
484 edje_object_part_drag_value_get
485 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.drag_button_base", &position,
488 return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_LEFT);
489 else if (position < 0.7)
490 return ELM_ACTIONSLIDER_CENTER;
492 return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_RIGHT);
496 elm_actionslider_magnet_pos_set(Evas_Object *obj,
497 Elm_Actionslider_Pos pos)
499 ELM_ACTIONSLIDER_CHECK(obj);
500 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
502 sd->magnet_position = pos;
505 EAPI Elm_Actionslider_Pos
506 elm_actionslider_magnet_pos_get(const Evas_Object *obj)
508 ELM_ACTIONSLIDER_CHECK(obj) ELM_ACTIONSLIDER_NONE;
509 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
511 return sd->magnet_position;
515 elm_actionslider_enabled_pos_set(Evas_Object *obj,
516 Elm_Actionslider_Pos pos)
518 ELM_ACTIONSLIDER_CHECK(obj);
519 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
521 sd->enabled_position = pos;
524 EAPI Elm_Actionslider_Pos
525 elm_actionslider_enabled_pos_get(const Evas_Object *obj)
527 ELM_ACTIONSLIDER_CHECK(obj) ELM_ACTIONSLIDER_NONE;
528 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
530 return sd->enabled_position;
534 elm_actionslider_selected_label_get(const Evas_Object *obj)
536 const char *left, *right, *center;
538 ELM_ACTIONSLIDER_CHECK(obj) NULL;
539 ELM_ACTIONSLIDER_DATA_GET(obj, sd);
541 _text_get(obj, &left, &right, ¢er);
543 if ((sd->final_position == 0.0) &&
544 (sd->enabled_position & ELM_ACTIONSLIDER_LEFT))
547 if ((sd->final_position == 0.5) &&
548 (sd->enabled_position & ELM_ACTIONSLIDER_CENTER))
551 if ((sd->final_position == 1.0) &&
552 (sd->enabled_position & ELM_ACTIONSLIDER_RIGHT))