2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Label Label
|
|
|
|
*
|
|
|
|
* Display text, with simple html-like markup. The theme of course
|
|
|
|
* can invent new markup tags and style them any way it likes
|
|
|
|
*/
|
|
|
|
|
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 *lbl;
|
2008-11-16 04:17:42 -08:00
|
|
|
const char *label;
|
2010-01-07 18:33:03 -08:00
|
|
|
Evas_Coord lastw;
|
|
|
|
Ecore_Job *deferred_recalc_job;
|
2010-01-26 00:42:37 -08:00
|
|
|
Evas_Coord wrap_w;
|
2009-10-10 22:57:05 -07:00
|
|
|
Eina_Bool linewrap : 1;
|
2010-01-07 18:33:03 -08:00
|
|
|
Eina_Bool changed : 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);
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2010-01-07 18:33:03 -08:00
|
|
|
static void
|
|
|
|
_elm_win_recalc_job(void *data)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
2010-03-08 23:30:48 -08:00
|
|
|
Evas_Coord minw = -1, minh = -1, maxh = -1;
|
2010-01-07 18:33:03 -08:00
|
|
|
Evas_Coord resw, resh, minminw;
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2010-01-07 18:33:03 -08:00
|
|
|
wd->deferred_recalc_job = NULL;
|
|
|
|
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
|
|
|
resh = 0;
|
|
|
|
minminw = 0;
|
|
|
|
edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, 0, 0);
|
|
|
|
minminw = minw;
|
2010-01-27 02:19:54 -08:00
|
|
|
if (wd->wrap_w >= resw)
|
|
|
|
{
|
|
|
|
resw = wd->wrap_w;
|
|
|
|
edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
|
|
|
|
evas_object_size_hint_min_set(data, minw, minh);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wd->wrap_w > minminw) minminw = wd->wrap_w;
|
|
|
|
edje_object_size_min_restricted_calc(wd->lbl, &minw, &minh, resw, 0);
|
|
|
|
evas_object_size_hint_min_set(data, minminw, minh);
|
|
|
|
}
|
2010-01-07 18:33:03 -08:00
|
|
|
maxh = minh;
|
|
|
|
evas_object_size_hint_max_set(data, -1, maxh);
|
|
|
|
}
|
|
|
|
|
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);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2010-01-07 18:33:03 -08:00
|
|
|
if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
|
2008-11-16 04:17:42 -08:00
|
|
|
if (wd->label) eina_stringshare_del(wd->label);
|
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)
|
|
|
|
{
|
2008-11-16 04:17:42 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2009-10-10 22:57:05 -07:00
|
|
|
if (wd->linewrap)
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
|
2009-10-10 22:57:05 -07:00
|
|
|
else
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
|
2008-11-16 04:17:42 -08:00
|
|
|
edje_object_part_text_set(wd->lbl, "elm.text", wd->label);
|
2009-09-26 12:16:51 -07:00
|
|
|
edje_object_scale_set(wd->lbl, elm_widget_scale_get(obj) *
|
|
|
|
_elm_config->scale);
|
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);
|
|
|
|
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
2010-03-08 23:30:48 -08:00
|
|
|
Evas_Coord resw, resh;
|
|
|
|
if (!wd) return;
|
2010-01-07 18:33:03 -08:00
|
|
|
if (wd->linewrap)
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
|
|
|
if ((resw == wd->lastw) && (!wd->changed)) return;
|
|
|
|
wd->changed = EINA_FALSE;
|
|
|
|
wd->lastw = resw;
|
2010-01-27 02:19:54 -08:00
|
|
|
_elm_win_recalc_job(obj);
|
|
|
|
// FIXME: works ok. but NOT for genlist. what should genlist do?
|
|
|
|
// if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
|
|
|
|
// wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
|
2010-01-07 18:33:03 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(wd->lbl, NULL, NULL, &resw, &resh);
|
|
|
|
edje_object_size_min_calc(wd->lbl, &minw, &minh);
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
maxh = minh;
|
|
|
|
evas_object_size_hint_max_set(obj, maxw, maxh);
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2010-01-07 18:33:03 -08:00
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2010-01-07 18:33:03 -08:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
|
|
|
if (wd->linewrap) _sizing_eval(data);
|
2010-01-07 18:33:03 -08:00
|
|
|
}
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Add a new label to the parent
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return The new object or NULL if it cannot be created
|
|
|
|
*
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_label_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, "label");
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "label");
|
|
|
|
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
|
|
|
|
2009-10-10 22:57:05 -07:00
|
|
|
wd->linewrap = EINA_FALSE;
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->lbl = edje_object_add(e);
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->lbl, "label", "base", "default");
|
2008-11-16 04:17:42 -08:00
|
|
|
wd->label = eina_stringshare_add("<br>");
|
|
|
|
edje_object_part_text_set(wd->lbl, "elm.text", "<br>");
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_widget_resize_object_set(obj, wd->lbl);
|
2010-01-07 18:33:03 -08:00
|
|
|
|
|
|
|
evas_object_event_callback_add(wd->lbl, EVAS_CALLBACK_RESIZE, _resize, obj);
|
|
|
|
|
|
|
|
wd->changed = 1;
|
2008-11-16 04:17:42 -08:00
|
|
|
_sizing_eval(obj);
|
2008-10-06 18:23:49 -07:00
|
|
|
return obj;
|
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the label on the label object
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
|
|
|
* @param label The label will be used on the label object
|
|
|
|
*
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_label_label_set(Evas_Object *obj, const char *label)
|
|
|
|
{
|
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);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2008-11-16 04:17:42 -08:00
|
|
|
if (!label) label = "";
|
2010-03-13 13:01:26 -08:00
|
|
|
eina_stringshare_replace(&wd->label, label);
|
2008-10-06 18:23:49 -07:00
|
|
|
edje_object_part_text_set(wd->lbl, "elm.text", label);
|
2010-01-07 18:33:03 -08:00
|
|
|
wd->changed = 1;
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2009-08-11 03:44:49 -07:00
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Get the label used on the label object
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
2010-01-26 00:42:37 -08:00
|
|
|
* @return The string inside the label
|
2009-09-17 15:39:18 -07:00
|
|
|
* @ingroup Label
|
|
|
|
*/
|
2010-01-26 00:42:37 -08:00
|
|
|
EAPI const char *
|
2010-03-23 20:06:00 -07:00
|
|
|
elm_label_label_get(const Evas_Object *obj)
|
2009-08-11 03:44:49 -07:00
|
|
|
{
|
2010-03-08 23:30:48 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2009-08-11 03:44:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-09-26 12:16:51 -07:00
|
|
|
if (!wd) return NULL;
|
2009-08-11 03:44:49 -07:00
|
|
|
return wd->label;
|
|
|
|
}
|
2009-10-10 22:57:05 -07:00
|
|
|
|
2010-01-26 00:42:37 -08:00
|
|
|
/**
|
|
|
|
* Set the wrapping behavior of the label
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
|
|
|
* @param wrap To wrap text or not
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
2009-10-10 22:57:05 -07:00
|
|
|
EAPI void
|
|
|
|
elm_label_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-10-10 22:57:05 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2009-10-10 22:57:05 -07:00
|
|
|
const char *t;
|
|
|
|
if (wd->linewrap == wrap) return;
|
|
|
|
wd->linewrap = wrap;
|
|
|
|
t = eina_stringshare_add(elm_label_label_get(obj));
|
|
|
|
if (wd->linewrap)
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->lbl, "label", "base_wrap", elm_widget_style_get(obj));
|
2009-10-10 22:57:05 -07:00
|
|
|
else
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->lbl, "label", "base", elm_widget_style_get(obj));
|
2009-10-10 22:57:05 -07:00
|
|
|
elm_label_label_set(obj, t);
|
|
|
|
eina_stringshare_del(t);
|
2010-01-07 18:33:03 -08:00
|
|
|
wd->changed = 1;
|
2009-10-10 22:57:05 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
2010-01-26 00:42:37 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the wrapping behavior of the label
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
|
|
|
* @return To wrap text or not
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_label_line_wrap_get(const Evas_Object *obj)
|
|
|
|
{
|
2010-03-08 23:30:48 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2010-01-26 00:42:37 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return EINA_FALSE;
|
2010-01-26 00:42:37 -08:00
|
|
|
return wd->linewrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set wrap width of the label
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
|
|
|
* @param w The wrap width in pixels at a minimum where words need to wrap
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
elm_label_wrap_width_set(Evas_Object *obj, Evas_Coord w)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2010-01-26 00:42:37 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return;
|
2010-01-26 00:42:37 -08:00
|
|
|
if (wd->wrap_w == w) return;
|
|
|
|
wd->wrap_w = w;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get wrap width of the label
|
|
|
|
*
|
|
|
|
* @param obj The label object
|
|
|
|
* @return The wrap width in pixels at a minimum where words need to wrap
|
|
|
|
* @ingroup Label
|
|
|
|
*/
|
|
|
|
EAPI Evas_Coord
|
|
|
|
elm_label_wrap_width_get(const Evas_Object *obj)
|
|
|
|
{
|
2010-03-08 23:30:48 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) 0;
|
2010-01-26 00:42:37 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-08 23:30:48 -08:00
|
|
|
if (!wd) return 0;
|
2010-01-26 00:42:37 -08:00
|
|
|
return wd->wrap_w;
|
|
|
|
}
|