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
39 Elm_Actionslider_Magnet_Pos magnet_position;
40 const char *text_left, *text_right, *text_center, *text_button;
47 Ecore_Animator *icon_animator;
48 double final_position;
51 static void _del_hook(Evas_Object *obj);
52 static void _theme_hook(Evas_Object *obj);
53 static void _disable_hook(Evas_Object *obj);
54 static void _sizing_eval(Evas_Object *obj);
55 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
60 static void _icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
61 static void _icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
62 static void _icon_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
67 static int _icon_animation(void *data);
70 _del_hook(Evas_Object *obj)
72 Widget_Data *wd = elm_widget_data_get(obj);
76 evas_object_del(wd->icon);
81 eina_stringshare_del(wd->text_left);
85 eina_stringshare_del(wd->text_right);
89 eina_stringshare_del(wd->text_center);
93 eina_stringshare_del(wd->text_button);
97 evas_object_smart_member_del(wd->as);
98 evas_object_del(wd->as);
105 _theme_hook(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
109 if (edje_object_part_swallow_get(wd->as, "elm.swallow.icon") == NULL)
111 edje_object_part_unswallow(wd->as, wd->icon);
114 _elm_theme_object_set(obj, wd->as, "actionslider", "base", elm_widget_style_get(obj));
115 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", elm_widget_style_get(obj));
116 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
117 edje_object_part_text_set(wd->as, "elm.text.left", wd->text_left);
118 edje_object_part_text_set(wd->as, "elm.text.right", wd->text_right);
119 edje_object_part_text_set(wd->as, "elm.text.center", wd->text_center);
120 edje_object_message_signal_process(wd->as);
121 //edje_object_scale_set(wd->as, elm_widget_scale_get(obj) * _elm_config->scale);
126 _disable_hook(Evas_Object *obj)
128 // Widget_Data *wd = elm_widget_data_get(obj);
131 if (elm_widget_disabled_get(obj))
132 edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
134 edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
139 _sizing_eval(Evas_Object *obj)
141 // Widget_Data *wd = elm_widget_data_get(obj);
145 _sub_del(void *data, Evas_Object *obj, void *event_info)
147 // Widget_Data *wd = elm_widget_data_get(obj);
148 // Evas_Object *sub = event_info;
152 _icon_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
154 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
156 wd->mouse_down = EINA_TRUE;
160 _icon_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
162 Evas_Object *as = (Evas_Object *)data;
163 Widget_Data *wd = elm_widget_data_get(as);
166 elm_actionslider_hold(as, EINA_FALSE);
167 if (wd->mouse_down == EINA_FALSE) return;
169 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &pos, NULL);
173 evas_object_smart_callback_call(as, "position", "left");
177 evas_object_smart_callback_call(as, "position", "right");
180 else if (pos >= 0.495 && pos <= 0.505)
182 evas_object_smart_callback_call(as, "position", "center");
187 if ( wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
188 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
190 //edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
191 edje_object_signal_emit(wd->as, "elm,show,text,center", "elm");
193 //edje_object_signal_emit(wd->as, "elm,hide,bar,text,center", "elm");
194 edje_object_signal_emit(wd->as, "elm,hide,text,center", "elm");
201 _icon_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
203 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
204 double position = 0.0;
206 wd->mouse_down = EINA_FALSE;
208 if (wd->mouse_hold == EINA_FALSE)
210 if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_LEFT)
212 wd->final_position = 0.0;
214 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_RIGHT)
216 wd->final_position = 1.0;
218 else if (wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_CENTER)
220 wd->final_position = 0.5;
222 else if ( wd->magnet_position == ELM_ACTIONSLIDER_MAGNET_BOTH)
224 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &position, NULL);
227 wd->final_position = 0.0;
231 wd->final_position = 1.0;
235 wd->icon_animator = ecore_animator_add(_icon_animation, wd);
240 _icon_animation(void *data)
242 Widget_Data *wd = (Widget_Data *)data;
243 double cur_position = 0.0, new_position = 0.0;
244 double move_amount = 0.05;
245 Eina_Bool flag_finish_animation = EINA_FALSE;
247 edje_object_part_drag_value_get(wd->as, "elm.swallow.icon", &cur_position, NULL);
249 if ( (wd->final_position == 0.0) ||
250 (wd->final_position == 0.5 && cur_position >= wd->final_position) )
252 new_position = cur_position - move_amount;
253 if (new_position <= wd->final_position)
255 new_position = wd->final_position;
256 flag_finish_animation = EINA_TRUE;
259 else if ( (wd->final_position == 1.0) ||
260 (wd->final_position == 0.5 && cur_position < wd->final_position) )
262 new_position = cur_position + move_amount;
263 if (new_position >= wd->final_position)
265 new_position = wd->final_position;
266 flag_finish_animation = EINA_TRUE;
269 if (wd->type == ELM_ACTIONSLIDER_TYPE_BAR_GREEN ||
270 wd->type == ELM_ACTIONSLIDER_TYPE_BAR_RED ) {
271 edje_object_signal_emit(wd->as, "elm,show,bar,text,center", "elm");
277 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", new_position, 0.5);
279 if (flag_finish_animation == EINA_TRUE)
290 * Add a new actionslider to the parent.
292 * @param parent The parent object
293 * @return The new actionslider object or NULL if it cannot be created
295 * @ingroup Actionslider
298 elm_actionslider_add(Evas_Object *parent)
302 Widget_Data *wd = NULL;
304 wd = ELM_NEW(Widget_Data);
305 e = evas_object_evas_get(parent);
306 if (e == NULL) return NULL;
307 obj = elm_widget_add(e);
308 elm_widget_type_set(obj, "actionslider");
309 elm_widget_sub_object_add(parent, obj);
310 elm_widget_data_set(obj, wd);
312 elm_widget_del_hook_set(obj, _del_hook);
313 elm_widget_theme_hook_set(obj, _theme_hook);
314 elm_widget_disable_hook_set(obj, _disable_hook);
316 wd->mouse_down = EINA_FALSE;
317 wd->mouse_hold = EINA_FALSE;
319 // load background edj
320 wd->as = edje_object_add(e);
323 printf("Cannot load actionslider edj!\n");
326 _elm_theme_object_set(obj, wd->as, "actionslider", "base", "default");
327 elm_widget_resize_object_set(obj, wd->as);
330 wd->icon = edje_object_add(e);
331 if (wd->icon == NULL)
333 printf("Cannot load acitionslider icon!\n");
336 evas_object_smart_member_add(wd->icon, obj);
337 _elm_theme_object_set(obj, wd->icon, "actionslider", "icon", "default");
338 edje_object_part_swallow(wd->as, "elm.swallow.icon", wd->icon);
341 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
342 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_DOWN, _icon_down_cb, obj);
343 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_MOVE, _icon_move_cb, obj);
344 evas_object_event_callback_add(wd->icon, EVAS_CALLBACK_MOUSE_UP, _icon_up_cb, obj);
351 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)
355 obj = elm_actionslider_add(parent);
357 elm_actionslider_icon_set(obj, pos);
358 elm_actionslider_magnet_set(obj, magnet);
359 if (label_left != NULL)
360 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_LEFT, label_left);
361 if (label_center != NULL)
362 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_CENTER, label_center);
363 if (label_right != NULL)
364 elm_actionslider_label_set(obj, ELM_ACTIONSLIDER_LABEL_RIGHT, label_right);
371 * Set actionslider indicator position.
373 * @param obj The actionslider object.
374 * @param pos The position of the indicator.
375 * (ELM_ACTIONSLIDER_INDICATOR_LEFT, ELM_ACTIONSLIDER_INDICATOR_RIGHT,
376 * ELM_ACTIONSLIDER_INDICATOR_CENTER)
378 * @ingroup Actionslider
381 elm_actionslider_indicator_pos_set(Evas_Object *obj, Elm_Actionslider_Indicator_Pos pos)
383 Widget_Data *wd = elm_widget_data_get(obj);
384 double position = 0.0;
386 if (pos == ELM_ACTIONSLIDER_INDICATOR_LEFT)
390 else if (pos == ELM_ACTIONSLIDER_INDICATOR_RIGHT)
394 else if (pos == ELM_ACTIONSLIDER_INDICATOR_CENTER)
403 edje_object_part_drag_value_set(wd->as, "elm.swallow.icon", position, 0.5);
407 * Set actionslider magnet position.
409 * @param obj The actionslider object.
410 * @param pos The position of the magnet.
411 * (ELM_ACTIONSLIDER_MAGNET_LEFT, ELM_ACTIONSLIDER_MAGNET_RIGHT,
412 * ELM_ACTIONSLIDER_MAGNET_BOTH, ELM_ACTIONSLIDER_MAGNET_CENTER)
414 * @ingroup Actionslider
417 elm_actionslider_magnet_pos_set(Evas_Object *obj, Elm_Actionslider_Magnet_Pos pos)
419 Widget_Data *wd = elm_widget_data_get(obj);
421 wd->magnet_position = pos;
425 * Set actionslider label.
427 * @param obj The actionslider object
428 * @param pos The position of the label.
429 * (ELM_ACTIONSLIDER_LABEL_LEFT, ELM_ACTIONSLIDER_LABEL_RIGHT)
430 * @param label The label which is going to be set.
432 * @ingroup Actionslider
435 elm_actionslider_label_set(Evas_Object *obj, Elm_Actionslider_Label_Pos pos, const char *label)
437 Widget_Data *wd = elm_widget_data_get(obj);
444 if (pos == ELM_ACTIONSLIDER_LABEL_RIGHT)
448 eina_stringshare_del(wd->text_right);
450 wd->text_right = eina_stringshare_add(label);
451 edje_object_part_text_set(wd->as, "elm.text.right", label);
453 else if (pos == ELM_ACTIONSLIDER_LABEL_LEFT)
457 eina_stringshare_del(wd->text_left);
459 wd->text_left = eina_stringshare_add(label);
460 edje_object_part_text_set(wd->as, "elm.text.left", label);
462 else if (pos == ELM_ACTIONSLIDER_LABEL_CENTER)
466 eina_stringshare_del(wd->text_center);
468 wd->text_center = eina_stringshare_add(label);
469 edje_object_part_text_set(wd->as, "elm.text.center", label);
471 else if (pos == ELM_ACTIONSLIDER_LABEL_BUTTON)
475 eina_stringshare_del(wd->text_button);
477 wd->text_button = eina_stringshare_add(label);
478 edje_object_part_text_set(wd->icon, "elm.text.button", label);
480 /* Resize button width */
482 txt = (Evas_Object *)edje_object_part_object_get (wd->icon, "elm.text.button");
485 evas_object_text_text_set (txt, wd->text_button);
488 evas_object_geometry_get (txt, &x,&y,&w,&h);
490 char *data_left = NULL, *data_right = NULL;
491 int pad_left = 0, pad_right = 0;
493 data_left = (char *)edje_object_data_get (wd->icon, "left");
494 data_right = (char *)edje_object_data_get (wd->icon, "right");
496 if (data_left) pad_left = atoi(data_left);
497 if (data_right) pad_right = atoi(data_right);
499 evas_object_size_hint_min_set (wd->icon, w + pad_left + pad_right, 0);
507 * Hold actionslider object movement.
509 * @param obj The actionslider object
510 * @param flag Actionslider hold/release
511 * (EINA_TURE = hold/EIN_FALSE = release)
513 * @ingroup Actionslider
516 elm_actionslider_hold(Evas_Object *obj, Eina_Bool flag)
518 Widget_Data *wd = elm_widget_data_get(obj);
520 wd->mouse_hold = flag;