2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
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;
|
2008-11-15 05:58:50 -08:00
|
|
|
const char *stdicon;
|
2008-10-06 18:23:49 -07:00
|
|
|
Evas_Bool scale_up : 1;
|
|
|
|
Evas_Bool scale_down : 1;
|
|
|
|
Evas_Bool smooth : 1;
|
|
|
|
Evas_Bool fill_outside : 1;
|
|
|
|
Evas_Bool no_scale : 1;
|
2008-09-29 23:58:56 -07:00
|
|
|
};
|
|
|
|
|
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-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)
|
|
|
|
_elm_theme_icon_set(wd->img, wd->stdicon, "default");
|
|
|
|
_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;
|
|
|
|
|
|
|
|
_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-02-02 21:09:03 -08: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
|
2009-02-25 07:54:26 -08:00
|
|
|
_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
2008-10-08 02:33:05 -07:00
|
|
|
{
|
|
|
|
evas_object_smart_callback_call(data, "clicked", NULL);
|
|
|
|
}
|
|
|
|
|
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;
|
2008-09-29 23:58:56 -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);
|
|
|
|
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);
|
2008-09-29 23:58:56 -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);
|
|
|
|
elm_widget_resize_object_set(obj, wd->img);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->smooth = 1;
|
|
|
|
wd->scale_up = 1;
|
|
|
|
wd->scale_down = 1;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
|
|
|
|
{
|
|
|
|
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
|
|
|
const char *p;
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
if (!file) return;
|
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")))
|
|
|
|
_els_smart_icon_file_edje_set(wd->img, file, group);
|
|
|
|
else
|
|
|
|
_els_smart_icon_file_key_set(wd->img, file, group);
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2008-10-08 02:33:05 -07:00
|
|
|
EAPI void
|
|
|
|
elm_icon_standard_set(Evas_Object *obj, const char *name)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-01-08 06:29:13 -08:00
|
|
|
if (!wd) return;
|
2008-10-08 02:33:05 -07:00
|
|
|
|
|
|
|
if (!name) return;
|
2008-11-15 05:58:50 -08:00
|
|
|
if (wd->stdicon) eina_stringshare_del(wd->stdicon);
|
|
|
|
wd->stdicon = eina_stringshare_add(name);
|
2008-10-08 02:33:05 -07:00
|
|
|
_elm_theme_icon_set(wd->img, name, "default");
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_icon_smooth_set(Evas_Object *obj, Evas_Bool smooth)
|
|
|
|
{
|
|
|
|
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
|
|
|
wd->smooth = smooth;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_icon_no_scale_set(Evas_Object *obj, Evas_Bool no_scale)
|
|
|
|
{
|
|
|
|
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
|
|
|
wd->no_scale = no_scale;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_icon_scale_set(Evas_Object *obj, Evas_Bool scale_up, Evas_Bool scale_down)
|
|
|
|
{
|
|
|
|
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
|
|
|
wd->scale_up = scale_up;
|
|
|
|
wd->scale_down = scale_down;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_icon_fill_outside_set(Evas_Object *obj, Evas_Bool fill_outside)
|
|
|
|
{
|
|
|
|
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
|
|
|
wd->fill_outside = fill_outside;
|
|
|
|
_sizing_eval(obj);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2009-03-12 22:50:38 -07:00
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_icon_prescale_set(Evas_Object *obj, int size)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
_els_smart_icon_scale_size_set(wd->img, size);
|
|
|
|
}
|