[SLP Merge] Thu Jul 7 13:20:56 2011 +0900
[framework/uifw/elementary.git] / src / lib / elm_actionslider.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4 /*
5  * SLP
6  * Copyright (c) 2009 Samsung Electronics, Inc.
7  * All rights reserved.
8  *
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.
14  */
15
16 /**
17  *
18  * @defgroup Actionslider Actionslider
19  * @ingroup Elementary
20  *
21  * A magnet slider is a switcher for 3 labels with customizable
22  * magnet properties. When the position is set with magnet, the knob
23  * will be moved to it if it's nearest the magnetized position.
24  *
25  * Signals that you can add callbacks for are:
26  *
27  * "selected" - when user selects a position (the label is passed as
28  *              event info)".
29  * "pos_changed" - when a button reaches to the special position like
30  *                 "left", "right" and "center".
31  */
32
33 #include <Elementary.h>
34 #include <math.h>
35 #include "elm_priv.h"
36
37 /**
38  * internal data structure of actionslider object
39  */
40 typedef struct _Widget_Data Widget_Data;
41
42 struct _Widget_Data
43 {
44    Evas_Object  *as;            // actionslider
45    Evas_Object  *icon;          // an icon for a button or a bar
46    Evas_Object  *icon_fake;             // an icon for a button or a bar
47
48    // setting
49    Elm_Actionslider_Magnet_Pos  magnet_position, enabled_position;
50    const char *text_left, *text_right, *text_center, *text_button;
51
52    // status
53    Eina_Bool    mouse_down;
54    Eina_Bool    mouse_hold;
55
56    // icon animation
57    Ecore_Animator       *icon_animator;
58    double               final_position;
59 };
60
61 static void _del_hook(Evas_Object *obj);
62 static void _theme_hook(Evas_Object *obj);
63 static void _disable_hook(Evas_Object *obj);
64 static void _sizing_eval(Evas_Object *obj);
65 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
66
67 /*
68  * callback functions
69  */
70 static void _icon_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__);
71 static void _icon_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__);
72 static void _icon_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
73
74 /*
75  * internal functions
76  */
77 static Eina_Bool _icon_animation(void *data);
78
79 static const char *widtype = NULL;
80
81 static const char SIG_CHANGED[] = "pos_changed";
82 static const char SIG_SELECTED[] = "selected";
83
84 static const Evas_Smart_Cb_Description _signals[] =
85 {
86      {SIG_CHANGED, ""},
87      {SIG_SELECTED, ""},
88      {NULL, NULL}
89 };
90
91
92 static void
93 _del_hook(Evas_Object *obj)
94 {
95    Widget_Data *wd = elm_widget_data_get(obj);
96    if (!wd) return;
97    if (wd->icon) 
98      {
99         evas_object_del(wd->icon);
100         wd->icon = NULL;
101      }
102    if (wd->icon_fake) 
103      {
104         evas_object_del(wd->icon_fake);
105         wd->icon_fake = NULL;
106      }
107    if (wd->text_left) eina_stringshare_del(wd->text_left);
108    if (wd->text_right) eina_stringshare_del(wd->text_right);
109    if (wd->text_center) eina_stringshare_del(wd->text_center);
110    if (wd->text_button) eina_stringshare_del(wd->text_button);
111    if (wd->as) 
112      {
113         evas_object_smart_member_del(wd->as);
114         evas_object_del(wd->as);
115         wd->as = NULL;
116      }
117    free(wd);
118 }
119
120 static Elm_Actionslider_Indicator_Pos
121 _get_pos_by_orientation(const Evas_Object *obj, Elm_Actionslider_Indicator_Pos pos)
122 {
123    if (elm_widget_mirrored_get(obj))
124      {
125         switch (pos)
126           {
127            case ELM_ACTIONSLIDER_INDICATOR_LEFT:
128               pos = ELM_ACTIONSLIDER_INDICATOR_RIGHT;
129               break;
130            case ELM_ACTIONSLIDER_INDICATOR_RIGHT:
131               pos = ELM_ACTIONSLIDER_INDICATOR_LEFT;
132               break;
133            default:
134               break;
135           }
136      }
137    return pos;
138 }
139
140 static void
141 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
142 {
143    Widget_Data *wd = elm_widget_data_get(obj);
144    double pos;
145
146    if (!wd) return;
147    if (edje_object_mirrored_get(wd->as) == rtl)
148      return;
149
150    edje_object_mirrored_set(wd->as, rtl);
151    if (!elm_widget_mirrored_get(obj))
152      {
153         edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
154         edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
155      }
156    else
157      {
158         edje_object_part_text_set(wd->as, "elm.text.left", wd->text_right);
159         edje_object_part_text_set(wd->as, "elm.text.right", wd->text_left);
160      }
161    edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &pos, NULL);
162    edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", 1.0 - pos, 0.5);
163 }
164
165 static void
166 _sizing_eval(Evas_Object *obj)
167 {
168    Widget_Data *wd = elm_widget_data_get(obj);
169    Evas_Coord minw = -1, minh = -1;
170
171    if (!wd) return;
172    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
173    evas_object_size_hint_min_set(wd->icon, minw, minh);
174    evas_object_size_hint_max_set(wd->icon, -1, -1);
175
176    minw = -1;
177    minh = -1;
178    elm_coords_finger_size_adjust(3, &minw, 1, &minh);
179    edje_object_size_min_restricted_calc(wd->as, &minw, &minh, minw, minh);
180    evas_object_size_hint_min_set(obj, minw, minh);
181    evas_object_size_hint_max_set(obj, -1, -1);
182 }
183
184 static void
185 _theme_hook(Evas_Object *obj)
186 {
187    Widget_Data *wd = elm_widget_data_get(obj);
188    if (!wd) return;
189    _elm_widget_mirrored_reload(obj);
190    if (edje_object_part_swallow_get(wd->as, "elm.swallow.icon") == NULL) 
191      edje_object_part_unswallow(wd->as, wd->icon);
192    if (edje_object_part_swallow_get(wd->as, "elm.swallow.space") == NULL) 
193      edje_object_part_unswallow(wd->as, wd->icon_fake);
194
195    _elm_theme_object_set(obj, wd->as, "actionslider", "base", elm_widget_style_get(obj));
196    _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", elm_widget_style_get(obj));
197    _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", elm_widget_style_get(obj));
198    edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
199    edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
200
201    _mirrored_set(obj, elm_widget_mirrored_get(obj));
202    edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
203    edje_object_part_text_set(wd->as, "elm.text.button", wd->text_button);
204    edje_object_message_signal_process(wd->as);
205    //edje_object_scale_set(wd->as, elm_widget_scale_get(obj) * _elm_config->scale);
206    _sizing_eval(obj);
207 }
208
209 static void
210 _disable_hook(Evas_Object *obj)
211 {
212    Widget_Data *wd = elm_widget_data_get(obj);
213
214    if (elm_widget_disabled_get(obj))
215      edje_object_signal_emit(wd->icon, "elm,state,disabled", "elm");
216    else
217      edje_object_signal_emit(wd->icon, "elm,state,enabled", "elm");
218
219 }
220
221 static void
222 _icon_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
223 {
224    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
225    if (!wd) return;
226    wd->mouse_down = EINA_TRUE;
227 }
228
229 static void
230 _icon_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
231 {
232    Evas_Object *as = (Evas_Object *)data;
233    Widget_Data *wd = elm_widget_data_get(as);
234    double pos = 0.0;
235    if (!wd) return;
236    elm_actionslider_hold(as, EINA_FALSE);
237    if (wd->mouse_down == EINA_FALSE) return;
238
239    edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &pos, NULL);
240
241    if (pos == 0.0) 
242      evas_object_smart_callback_call(as, SIG_CHANGED, (void *) ((!elm_widget_mirrored_get(as)) ? "left" : "right"));
243    else if (pos == 1.0) 
244      evas_object_smart_callback_call(as, SIG_CHANGED, (void *) ((!elm_widget_mirrored_get(as)) ? "right" : "left"));
245    else if (pos >= 0.495 && pos <= 0.505) 
246      evas_object_smart_callback_call(as, SIG_CHANGED, (void *)"center");
247
248 /*
249  * TODO
250 if (wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
251 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
252 if (pos == 1.0) {
253 //edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
254 edje_object_signal_emit(wd->as, "elm,show,text,center", "elm");
255 } else {
256 //edje_object_signal_emit(wd->as, "elm,hide,bar,text,center", "elm");
257 edje_object_signal_emit(wd->as, "elm,hide,text,center", "elm");
258 }
259 }
260 */
261 }
262
263 static void
264 _icon_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
265 {
266    Evas_Object *as = (Evas_Object *)data;
267    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
268    double position = 0.0;
269
270    wd->mouse_down = EINA_FALSE;
271
272    if (wd->mouse_hold == EINA_FALSE) 
273      {
274         edje_object_part_drag_value_get(wd->as, "elm.drag_button_base", &position, NULL);
275
276         if ((wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_LEFT) && ((!elm_widget_mirrored_get(as) && position == 0.0) ||(elm_widget_mirrored_get(obj) && position == 1.0))) 
277           {
278              wd->final_position = 0.0;
279              evas_object_smart_callback_call(data, SIG_SELECTED,(void *) wd->text_left);
280           }
281         else if (position >= 0.495 && position <= 0.505 && (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_CENTER))
282           {
283              wd->final_position = 0.5;
284              evas_object_smart_callback_call(data, SIG_SELECTED,(void *)wd->text_center);
285           }
286         else if ((wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_RIGHT) && ((!elm_widget_mirrored_get(as) && position == 1.0) ||(elm_widget_mirrored_get(obj) && position == 0.0)))
287           {
288              wd->final_position = 1.0; 
289              evas_object_smart_callback_call(data, SIG_SELECTED, (void *) wd->text_right);
290           }
291         if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_NONE) return;
292
293         #define _FINAL_POS_BY_ORIENTATION(x) (x)
294         #define _POS_BY_ORIENTATION(x) ((!elm_widget_mirrored_get(as)) ? x : 1.0 - x)
295
296         position = _POS_BY_ORIENTATION(position);
297
298         if (position < 0.3)
299           {
300              if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_LEFT)
301                wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
302              else if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_CENTER)
303                wd->final_position = 0.5;
304              else if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_RIGHT)
305                wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
306           }
307         else if ((position >= 0.3) && (position <= 0.7))
308           {
309              if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_CENTER)
310                wd->final_position = 0.5;
311              else if (position < 0.5)
312                {
313                   if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_LEFT)
314                     wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
315                   else
316                     wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
317                }
318              else
319                {
320                   if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_RIGHT)
321                     wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
322                   else
323                     wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
324                }
325            }
326         else
327           {
328              if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_RIGHT)
329                wd->final_position = _FINAL_POS_BY_ORIENTATION(1);
330              else if (wd->magnet_position & ELM_ACTIONSLIDER_MAGNET_CENTER)
331                wd->final_position = 0.5;
332              else
333                wd->final_position = _FINAL_POS_BY_ORIENTATION(0);
334           }
335         wd->icon_animator = ecore_animator_add(_icon_animation, wd);
336
337         #undef _FINAL_POS_BY_ORIENTATION
338      }
339 }
340
341 static Eina_Bool
342 _icon_animation(void *data)
343 {
344    Evas_Object *as = data;
345    Widget_Data *wd = (Widget_Data *)data;
346    if (!wd)
347      {
348         wd->icon_animator = NULL;
349         return ECORE_CALLBACK_CANCEL;
350      }
351    double cur_position = 0.0, new_position = 0.0;
352    double move_amount = 0.05;
353    double adjusted_final;
354    Eina_Bool flag_finish_animation = EINA_FALSE;
355
356    edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &cur_position, NULL);
357    adjusted_final = (!elm_widget_mirrored_get(as)) ? wd->final_position : 1.0 - wd->final_position;
358
359    if ( (adjusted_final == 0.0) ||(adjusted_final == 0.5 && cur_position >= adjusted_final) ) 
360      {
361         new_position = cur_position - move_amount;
362         if (new_position <= adjusted_final) 
363           {
364              new_position = adjusted_final;
365              flag_finish_animation = EINA_TRUE;
366           }
367      } 
368    else if ((adjusted_final == 1.0) || (adjusted_final == 0.5 && cur_position < adjusted_final) ) 
369      {
370         new_position = cur_position + move_amount;
371         if (new_position >= adjusted_final) 
372           {
373              new_position = adjusted_final;
374              flag_finish_animation = EINA_TRUE;
375              /*
376              // TODO
377              if (wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
378                wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
379                edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
380              }
381              */
382           }
383      }
384    edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", new_position, 0.5);
385
386    if (flag_finish_animation)
387      {
388         if ((!wd->final_position) &&
389             (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_LEFT))
390           evas_object_smart_callback_call(data, SIG_SELECTED,
391                                           (void *)wd->text_left);
392         else if ((wd->final_position == 0.5) &&
393                  (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_CENTER))
394           evas_object_smart_callback_call(data, SIG_SELECTED,
395                                           (void *)wd->text_center);
396         else if ((wd->final_position == 1) &&
397                  (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_RIGHT))
398           evas_object_smart_callback_call(data, SIG_SELECTED,
399                                           (void *)wd->text_right);
400         wd->icon_animator = NULL;
401         return ECORE_CALLBACK_CANCEL;
402      }
403    return ECORE_CALLBACK_RENEW;
404
405 }
406
407 static void
408 _elm_actionslider_label_set(Evas_Object *obj, const char *item, const char *label)
409 {
410    ELM_CHECK_WIDTYPE(obj, widtype);
411    Widget_Data *wd = elm_widget_data_get(obj);
412    if (!wd) return;
413
414    if (!item || !strcmp(item, "default"))
415      {
416         eina_stringshare_replace(&wd->text_button, label);
417         edje_object_part_text_set(wd->as, "elm.text.button",
418               wd->text_button);
419      }
420    else if (!strcmp(item, "left"))
421      {
422         eina_stringshare_replace(&wd->text_left, label);
423         if (!elm_widget_mirrored_get(obj))
424           {
425              edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
426           }
427         else
428           {
429              edje_object_part_text_set(wd->as, "elm.text.right", wd->text_left);
430           }
431      }
432    else if (!strcmp(item, "center"))
433      {
434         eina_stringshare_replace(&wd->text_center, label);
435         edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
436      }
437    else if (!strcmp(item, "right"))
438      {
439         eina_stringshare_replace(&wd->text_right, label);
440         if (!elm_widget_mirrored_get(obj))
441           {
442              edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
443           }
444         else
445           {
446              edje_object_part_text_set(wd->as, "elm.text.left", wd->text_right);
447           }
448      }
449 }
450
451 static const char *
452 _elm_actionslider_label_get(const Evas_Object *obj, const char *item)
453 {
454    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
455    Widget_Data *wd = elm_widget_data_get(obj);
456    if (!wd) return NULL;
457
458    if (!item || !strcmp(item, "default"))
459      {
460         return wd->text_button;
461      }
462    else if (!strcmp(item, "left"))
463      {
464         return wd->text_left;
465      }
466    else if (!strcmp(item, "center"))
467      {
468         return wd->text_center;
469      }
470    else if (!strcmp(item, "right"))
471      {
472         return wd->text_right;
473      }
474
475    return NULL;
476 }
477
478 /**
479  * Add a new actionslider to the parent.
480  *
481  * @param[in] parent The parent object
482  * @return The new actionslider object or NULL if it cannot be created
483  *
484  * @ingroup Actionslider
485  */
486 EAPI Evas_Object *
487 elm_actionslider_add(Evas_Object *parent)
488 {
489    Evas_Object *obj;
490    Evas *e;
491    Widget_Data *wd = NULL;
492
493    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
494
495    ELM_SET_WIDTYPE(widtype, "actionslider");
496    elm_widget_type_set(obj, "actionslider");
497    elm_widget_sub_object_add(parent, obj);
498    elm_widget_data_set(obj, wd);
499
500    elm_widget_del_hook_set(obj, _del_hook);
501    elm_widget_theme_hook_set(obj, _theme_hook);
502    elm_widget_disable_hook_set(obj, _disable_hook);
503    elm_widget_text_set_hook_set(obj, _elm_actionslider_label_set);
504    elm_widget_text_get_hook_set(obj, _elm_actionslider_label_get);
505
506    wd->mouse_down = EINA_FALSE;
507    wd->mouse_hold = EINA_FALSE;
508    wd->enabled_position = ELM_ACTIONSLIDER_MAGNET_ALL;
509
510    // load background edj
511    wd->as = edje_object_add(e);
512    if(wd->as == NULL) 
513      {
514         printf("Cannot load actionslider edj!\n");
515         return NULL;
516      }
517    _elm_theme_object_set(obj, wd->as, "actionslider", "base", "default");
518    elm_widget_resize_object_set(obj, wd->as);
519
520    // load icon
521    wd->icon = edje_object_add(e);
522    if (wd->icon == NULL) 
523      {
524         printf("Cannot load acitionslider icon!\n");
525         return NULL;
526      }
527    evas_object_smart_member_add(wd->icon, obj);
528    _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", "default");
529    edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
530
531    wd->icon_fake = edje_object_add(e);
532    evas_object_smart_member_add(wd->icon_fake, obj);
533    _elm_theme_object_set(obj, wd->icon_fake, "actionslider", "icon", "default");
534    edje_object_part_swallow(wd->as, "elm.swallow.space", wd->icon_fake);
535
536    // event callbacks
537    evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_DOWN, _icon_down_cb, obj);
538    evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_MOVE, _icon_move_cb, obj);
539    evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_UP, _icon_up_cb, obj);
540
541    _mirrored_set(obj, elm_widget_mirrored_get(obj));
542
543    return obj;
544 }
545
546 /*
547 EAPI Evas_Object *
548 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)
549 {
550    Evas_Object *obj;
551
552    obj = elm_actionslider_add(parent);
553
554    elm_actionslider_icon_set(obj, pos);
555    elm_actionslider_magnet_set(obj, magnet);
556    if (label_left != NULL)
557      elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_LEFT, label_left);
558    if (label_center != NULL)
559      elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_CENTER, label_center);
560    if (label_right != NULL)
561      elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_RIGHT, label_right);
562
563    return obj;
564 }
565 */
566
567 /**
568  * Set actionslider indicator position. 
569  *
570  * @param[in] obj The actionslider object. 
571  * @param[in] pos The position of the indicator.
572  * (ELM_ACTIONSLIDER_INDICATOR_LEFT, ELM_ACTIONSLIDER_INDICATOR_RIGHT,
573  *  ELM_ACTIONSLIDER_INDICATOR_CENTER)
574  *
575  * @ingroup Actionslider
576  */
577 EAPI void
578 elm_actionslider_indicator_pos_set(Evas_Object *obj, Elm_Actionslider_Indicator_Pos pos)
579 {
580    ELM_CHECK_WIDTYPE(obj, widtype);
581
582    Widget_Data *wd = elm_widget_data_get(obj);
583    double position = 0.0;
584    if (!wd) return;
585
586    pos = _get_pos_by_orientation(obj, pos);
587    if (pos == ELM_ACTIONSLIDER_INDICATOR_LEFT) position = 0.0;
588    else if (pos == ELM_ACTIONSLIDER_INDICATOR_RIGHT) position = 1.0;
589    else if (pos == ELM_ACTIONSLIDER_INDICATOR_CENTER) position = 0.5;
590    else position = 0.0;
591
592    edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", position, 0.5);
593 }
594
595 /**
596  * Get actionslider indicator position.
597  *
598  * @param obj The actionslider object.
599  * @return The position of the indicator.
600  *
601  * @ingroup Actionslider
602  */
603 EAPI Elm_Actionslider_Indicator_Pos
604 elm_actionslider_indicator_pos_get(const Evas_Object *obj)
605 {
606    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_INDICATOR_NONE;
607    Widget_Data *wd = elm_widget_data_get(obj);
608    double position;
609    if (!wd) return ELM_ACTIONSLIDER_INDICATOR_NONE;
610
611    edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &position, NULL);
612    if (position < 0.3)
613      return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_INDICATOR_LEFT);
614    else if (position < 0.7)
615      return ELM_ACTIONSLIDER_INDICATOR_CENTER;
616    else
617      return _get_pos_by_orientation(obj, ELM_ACTIONSLIDER_INDICATOR_RIGHT);
618 }
619 /**
620  * Set actionslider magnet position. 
621  *
622  * @param[in] obj The actionslider object. 
623  * @param[in] pos The position of the magnet.
624  * (ELM_ACTIONSLIDER_MAGNET_LEFT, ELM_ACTIONSLIDER_MAGNET_RIGHT,
625  *  ELM_ACTIONSLIDER_MAGNET_BOTH, ELM_ACTIONSLIDER_MAGNET_CENTER)
626  *
627  * @ingroup Actionslider
628  */
629 EAPI void
630 elm_actionslider_magnet_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
631 {
632    ELM_CHECK_WIDTYPE(obj, widtype);
633    Widget_Data *wd = elm_widget_data_get(obj);
634    if (!wd) return;
635    wd->magnet_position = pos;
636 }
637
638 /**
639  * Get actionslider magnet position.
640  *
641  * @param obj The actionslider object.
642  * @return The positions with magnet property.
643  *
644  * @ingroup Actionslider
645  */
646 EAPI Elm_Actionslider_Magnet_Pos
647 elm_actionslider_magnet_pos_get(const Evas_Object *obj)
648 {
649    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_MAGNET_NONE;
650    Widget_Data *wd = elm_widget_data_get(obj);
651    if (!wd) return ELM_ACTIONSLIDER_MAGNET_NONE;
652    return wd->magnet_position;
653 }
654
655 /**
656  * Set actionslider enabled position.
657  *
658  * All the positions are enabled by default.
659  *
660  * @param obj The actionslider object.
661  * @param pos Bit mask indicating the enabled positions.
662  * Example: use (ELM_ACTIONSLIDER_MAGNET_LEFT | ELM_ACTIONSLIDER_MAGNET_RIGHT)
663  * to enable both positions, so the user can select it.
664  *
665  * @ingroup Actionslider
666  */
667 EAPI void
668 elm_actionslider_enabled_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
669 {
670    ELM_CHECK_WIDTYPE(obj, widtype);
671    Widget_Data *wd = elm_widget_data_get(obj);
672    if (!wd) return;
673    wd->enabled_position = pos;
674 }
675
676 /**
677  * Get actionslider enabled position.
678  *
679  * All the positions are enabled by default.
680  *
681  * @param obj The actionslider object.
682  * @return The enabled positions.
683  *
684  * @ingroup Actionslider
685  */
686 EAPI Elm_Actionslider_Magnet_Pos
687 elm_actionslider_enabled_pos_get(const Evas_Object *obj)
688 {
689    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ACTIONSLIDER_MAGNET_NONE;
690    Widget_Data *wd = elm_widget_data_get(obj);
691    if (!wd) return ELM_ACTIONSLIDER_MAGNET_NONE;
692    return wd->enabled_position;
693 }
694
695 /**
696  * Set actionslider label.
697  *
698  * @param[in] obj The actionslider object
699  * @param[in] pos The position of the label.
700  * (ELM_ACTIONSLIDER_LABEL_LEFT, ELM_ACTIONSLIDER_LABEL_RIGHT)
701  * @param label The label which is going to be set.
702  *
703  * @ingroup Actionslider
704  */
705 EAPI void 
706 elm_actionslider_label_set(Evas_Object *obj, Elm_Actionslider_Label_Pos pos, const char *label)
707 {
708    ELM_CHECK_WIDTYPE(obj, widtype);
709    Widget_Data *wd = elm_widget_data_get(obj);
710    if (!wd) return;
711
712    if(label == NULL) label = "";
713
714    if (pos == ELM_ACTIONSLIDER_LABEL_RIGHT) 
715      _elm_actionslider_label_set(obj, "right", label);
716    else if (pos == ELM_ACTIONSLIDER_LABEL_LEFT) 
717      _elm_actionslider_label_set(obj, "left", label);
718    else if (pos == ELM_ACTIONSLIDER_LABEL_CENTER) 
719      _elm_actionslider_label_set(obj, "center", label);
720    else if (pos == ELM_ACTIONSLIDER_LABEL_BUTTON)
721      {
722         _elm_actionslider_label_set(obj, NULL, label);
723
724         /* Resize button width */
725         Evas_Object *txt;
726         txt = (Evas_Object *)edje_object_part_object_get (wd->icon, "elm.text.button");
727         if (txt != NULL) 
728           {
729              evas_object_text_text_set (txt, wd->text_button);
730
731              Evas_Coord x,y,w,h;
732              evas_object_geometry_get (txt, &x,&y,&w,&h);
733
734              char *data_left = NULL, *data_right = NULL;
735              int pad_left = 0, pad_right = 0;
736
737              data_left = (char *)edje_object_data_get (wd->icon, "left");
738              data_right = (char *)edje_object_data_get (wd->icon, "right");
739
740              if (data_left) pad_left = atoi(data_left);
741              if (data_right) pad_right = atoi(data_right);
742
743              evas_object_size_hint_min_set (wd->icon, w + pad_left + pad_right, 0);
744              evas_object_size_hint_min_set (wd->icon_fake, w + pad_left + pad_right, 0);
745           }
746      }
747 }
748
749 /**
750  * Get actionslider labels.
751  *
752  * @param obj The actionslider object
753  * @param left_label A char** to place the left_label of @p obj into
754  * @param center_label A char** to place the center_label of @p obj into
755  * @param right_label A char** to place the right_label of @p obj into
756  *
757  * @ingroup Actionslider
758  */
759 EAPI void
760 elm_actionslider_labels_get(const Evas_Object *obj, const char **left_label, const char **center_label, const char **right_label)
761 {
762    if (left_label) *left_label = _elm_actionslider_label_get(obj, "left");
763    if (center_label) *center_label = _elm_actionslider_label_get(obj, "center");
764    if (right_label) *right_label = _elm_actionslider_label_get(obj, "right");
765 }
766
767 /**
768  * Get actionslider selected label.
769  *
770  * @param obj The actionslider object
771  * @return The selected label
772  *
773  * @ingroup Actionslider
774  */
775 EAPI const char *
776 elm_actionslider_selected_label_get(const Evas_Object *obj)
777 {
778    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
779    Widget_Data *wd = elm_widget_data_get(obj);
780    if (!wd) return NULL;
781
782    if ((wd->final_position == 0.0) &&
783        (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_LEFT))
784      return wd->text_left;
785
786    if ((wd->final_position == 0.5) &&
787        (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_CENTER))
788      return wd->text_center;
789
790    if ((wd->final_position == 1.0) &&
791        (wd->enabled_position & ELM_ACTIONSLIDER_MAGNET_RIGHT))
792      return wd->text_right;
793
794    return NULL;
795 }
796
797 /**
798  * Set the label used on the indicator object.
799  *
800  * @param obj The actionslider object
801  * @param label The label which is going to be set.
802  *
803  * @ingroup Actionslider
804  */
805 EAPI void 
806 elm_actionslider_indicator_label_set(Evas_Object *obj, const char *label)
807 {
808    _elm_actionslider_label_set(obj, NULL, label);
809 }
810
811 /**
812  * Get the label used on the indicator object.
813  *
814  * @param obj The actionslider object
815  * @return The indicator label
816  *
817  * @ingroup Actionslider
818  */
819 EAPI const char *
820 elm_actionslider_indicator_label_get(Evas_Object *obj)
821 {
822    return _elm_actionslider_label_get(obj, NULL);
823 }
824
825 /**
826  * Hold actionslider object movement.
827  *
828  * @param[in] obj The actionslider object
829  * @param[in] flag Actionslider hold/release
830  * (EINA_TURE = hold/EIN_FALSE = release)
831  *
832  * @ingroup Actionslider
833  */
834 EAPI void
835 elm_actionslider_hold(Evas_Object *obj, Eina_Bool flag)
836 {
837    ELM_CHECK_WIDTYPE(obj, widtype);
838    Widget_Data *wd = elm_widget_data_get(obj);
839
840    wd->mouse_hold = flag;
841 }