2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Icon Icon
|
|
|
|
*
|
|
|
|
* A standard icon that may be provided by the theme (delete, edit,
|
|
|
|
* arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
|
|
|
|
* icon. The Icon may scale or not and of course... support alpha
|
|
|
|
* channels.
|
2009-10-14 01:41:36 -07:00
|
|
|
*
|
|
|
|
* Signals that you can add callbacks for are:
|
|
|
|
*
|
|
|
|
* clicked - This is called when a user has clicked the icon
|
2009-09-17 15:39:18 -07:00
|
|
|
*/
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
struct _Widget_Data
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Object *img;
|
2009-09-26 11:41:19 -07:00
|
|
|
const char *stdicon;
|
|
|
|
Eina_Bool scale_up : 1;
|
|
|
|
Eina_Bool scale_down : 1;
|
|
|
|
Eina_Bool smooth : 1;
|
|
|
|
Eina_Bool fill_outside : 1;
|
|
|
|
Eina_Bool no_scale : 1;
|
2008-09-29 23:58:56 -07:00
|
|
|
};
|
|
|
|
|
2010-03-08 22:15:39 -08:00
|
|
|
static const char *widtype = NULL;
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _del_hook(Evas_Object *obj);
|
2008-11-15 05:58:50 -08:00
|
|
|
static void _theme_hook(Evas_Object *obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _sizing_eval(Evas_Object *obj);
|
2009-02-25 07:54:26 -08:00
|
|
|
static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_del_hook(Evas_Object *obj)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-11-15 05:58:50 -08:00
|
|
|
if (wd->stdicon) eina_stringshare_del(wd->stdicon);
|
2008-10-06 18:23:49 -07:00
|
|
|
free(wd);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2008-11-15 05:58:50 -08:00
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-11-15 05:58:50 -08:00
|
|
|
if (wd->stdicon)
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_icon_set(obj, wd->img, wd->stdicon, "default");
|
2008-11-15 05:58:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2008-09-29 23:58:56 -07:00
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(Evas_Object *obj)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
|
|
|
int w, h;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
_els_smart_icon_size_get(wd->img, &w, &h);
|
|
|
|
_els_smart_icon_scale_up_set(wd->img, wd->scale_up);
|
|
|
|
_els_smart_icon_scale_down_set(wd->img, wd->scale_down);
|
|
|
|
_els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
|
|
|
|
_els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
|
|
|
|
if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
|
|
|
|
else
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2009-07-06 23:46:51 -07:00
|
|
|
_els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) *
|
|
|
|
_elm_config->scale);
|
2008-10-09 03:39:05 -07:00
|
|
|
_els_smart_icon_size_get(wd->img, &w, &h);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-06 18:23:49 -07:00
|
|
|
if (!wd->scale_down)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
minw = w;
|
|
|
|
minh = h;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-06 18:23:49 -07:00
|
|
|
if (!wd->scale_up)
|
|
|
|
{
|
|
|
|
maxw = w;
|
|
|
|
maxh = h;
|
|
|
|
}
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
evas_object_size_hint_max_set(obj, maxw, maxh);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2008-10-08 02:33:05 -07:00
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
2008-10-08 02:33:05 -07:00
|
|
|
{
|
2010-01-22 04:36:32 -08:00
|
|
|
Evas_Event_Mouse_Up *ev = event_info;
|
|
|
|
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
|
2009-05-14 14:03:20 -07:00
|
|
|
evas_object_smart_callback_call(data, "clicked", event_info);
|
2008-10-08 02:33:05 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Add a new icon to the parent
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return The new object or NULL if it cannot be created
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_icon_add(Evas_Object *parent)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd = ELM_NEW(Widget_Data);
|
|
|
|
e = evas_object_evas_get(parent);
|
|
|
|
obj = elm_widget_add(e);
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "icon");
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "icon");
|
|
|
|
elm_widget_sub_object_add(parent, obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
2008-11-15 05:58:50 -08:00
|
|
|
elm_widget_theme_hook_set(obj, _theme_hook);
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_widget_can_focus_set(obj, 0);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->img = _els_smart_icon_add(e);
|
2008-10-08 02:33:05 -07:00
|
|
|
evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
|
|
|
|
_mouse_up, obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
evas_object_repeat_events_set(wd->img, 1);
|
2009-07-06 23:46:51 -07:00
|
|
|
elm_widget_resize_object_set(obj, wd->img);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2009-06-17 08:35:19 -07:00
|
|
|
wd->smooth = EINA_TRUE;
|
|
|
|
wd->scale_up = EINA_TRUE;
|
|
|
|
wd->scale_down = EINA_TRUE;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the file that will be used as icon
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param file The path to file that will be used as icon
|
|
|
|
* @param group The group that the icon belongs in edje file
|
|
|
|
*
|
|
|
|
* @return (1 = sucess, 0 = error)
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2009-04-03 14:52:01 -07:00
|
|
|
EAPI Eina_Bool
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
|
|
|
|
{
|
2010-03-08 23:30:48 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-04-03 14:52:01 -07:00
|
|
|
Eina_Bool ret;
|
2008-10-06 18:23:49 -07:00
|
|
|
const char *p;
|
2009-04-03 14:52:01 -07:00
|
|
|
|
2010-03-08 23:30:48 -08:00
|
|
|
if ((!wd) || (!file)) return EINA_FALSE;
|
2008-11-15 05:58:50 -08:00
|
|
|
if (wd->stdicon) eina_stringshare_del(wd->stdicon);
|
|
|
|
wd->stdicon = NULL;
|
2008-10-06 18:23:49 -07:00
|
|
|
if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
|
2009-04-03 14:52:01 -07:00
|
|
|
ret = _els_smart_icon_file_edje_set(wd->img, file, group);
|
|
|
|
else
|
|
|
|
ret = _els_smart_icon_file_key_set(wd->img, file, group);
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
2009-04-03 14:52:01 -07:00
|
|
|
return ret;
|
2008-10-06 18:23:49 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the theme, as standard, for a icon
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param name The theme name
|
|
|
|
*
|
2009-12-19 16:26:12 -08:00
|
|
|
* @return (1 = sucess, 0 = error)
|
|
|
|
*
|
2009-09-17 15:39:18 -07:00
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2009-12-19 16:26:12 -08:00
|
|
|
EAPI Eina_Bool
|
2008-10-08 02:33:05 -07:00
|
|
|
elm_icon_standard_set(Evas_Object *obj, const char *name)
|
|
|
|
{
|
2010-03-08 23:30:48 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2008-10-08 02:33:05 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-12-19 16:26:12 -08:00
|
|
|
Eina_Bool ret;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-02-11 08:13:41 -08:00
|
|
|
if ((!wd) || (!name)) return EINA_FALSE;
|
2010-03-13 13:01:26 -08:00
|
|
|
eina_stringshare_replace(&wd->stdicon, name);
|
2010-05-11 18:03:46 -07:00
|
|
|
ret = _elm_theme_object_icon_set(obj, wd->img, name, "default");
|
2008-10-08 02:33:05 -07:00
|
|
|
_sizing_eval(obj);
|
2009-12-19 16:26:12 -08:00
|
|
|
return ret;
|
2008-10-08 02:33:05 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the smooth effect for a icon
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param smooth A bool to set (or no) smooth effect
|
|
|
|
* (1 = smooth, 0 = not smooth)
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_icon_smooth_set(Evas_Object *obj, Eina_Bool smooth)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->smooth = smooth;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set if the object are scalable
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param no_scale A bool to set scale (or no)
|
|
|
|
* (1 = no_scale, 0 = scale)
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_icon_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->no_scale = no_scale;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set if the object is (up/down) scalable
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param scale_up A bool to set if the object is scalable up
|
|
|
|
* @param scale_down A bool to set if the object is scalable down
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_icon_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->scale_up = scale_up;
|
|
|
|
wd->scale_down = scale_down;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set if the object is filled outside
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param fill_outside A bool to set if the object is filled outside
|
|
|
|
* (1 = filled, 0 = no filled)
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_icon_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->fill_outside = fill_outside;
|
|
|
|
_sizing_eval(obj);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2009-03-12 22:50:38 -07:00
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the prescale size for the icon
|
|
|
|
*
|
|
|
|
* @param obj The icon object
|
|
|
|
* @param size The prescale size
|
|
|
|
*
|
|
|
|
* @ingroup Icon
|
|
|
|
*/
|
2009-03-12 22:50:38 -07:00
|
|
|
EAPI void
|
|
|
|
elm_icon_prescale_set(Evas_Object *obj, int size)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-03-12 22:50:38 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 11:41:19 -07:00
|
|
|
|
2009-03-12 22:50:38 -07:00
|
|
|
if (!wd) return;
|
|
|
|
_els_smart_icon_scale_size_set(wd->img, size);
|
|
|
|
}
|