2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Frame Frame
|
|
|
|
*
|
|
|
|
* This holds some content and has a title. Looks like a frame, but
|
|
|
|
* supports styles so multple frames are avaible
|
|
|
|
*/
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
|
|
|
struct _Widget_Data
|
|
|
|
{
|
|
|
|
Evas_Object *frm;
|
2008-10-06 23:55:11 -07:00
|
|
|
Evas_Object *content;
|
2010-09-23 22:11:33 -07:00
|
|
|
const char *label;
|
2008-10-06 18:23:49 -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);
|
2011-02-08 04:08:28 -08:00
|
|
|
static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
|
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);
|
|
|
|
static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
2008-10-06 23:55:11 -07:00
|
|
|
static void _sub_del(void *data, Evas_Object *obj, void *event_info);
|
2008-10-06 18:23:49 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-09-23 22:11:33 -07:00
|
|
|
if (wd->label) eina_stringshare_del(wd->label);
|
2008-10-06 18:23:49 -07:00
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
2011-02-08 04:08:28 -08:00
|
|
|
static void
|
|
|
|
_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
edje_object_mirrored_set(wd->frm, rtl);
|
|
|
|
}
|
|
|
|
|
2008-11-15 05:58:50 -08:00
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object *obj)
|
|
|
|
{
|
2008-12-08 01:24:46 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2011-02-08 04:08:28 -08:00
|
|
|
_mirrored_set(obj, elm_widget_mirrored_get(obj));
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->frm, "frame", "base", elm_widget_style_get(obj));
|
2010-09-23 22:11:33 -07:00
|
|
|
edje_object_part_text_set(wd->frm, "elm.text", wd->label);
|
2008-12-08 01:24:46 -08:00
|
|
|
if (wd->content)
|
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
|
2009-02-02 21:09:03 -08:00
|
|
|
edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
|
2008-11-15 05:58:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2010-10-01 12:02:58 -07:00
|
|
|
static Eina_Bool
|
2010-10-06 13:24:19 -07:00
|
|
|
_elm_frame_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
|
2010-10-01 12:02:58 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *cur;
|
|
|
|
|
|
|
|
if ((!wd) || (!wd->content))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
cur = wd->content;
|
|
|
|
|
|
|
|
/* Try Focus cycle in subitem */
|
2010-10-06 13:24:13 -07:00
|
|
|
return elm_widget_focus_next_get(cur, dir, next);
|
2010-10-01 12:02:58 -07:00
|
|
|
}
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
static void
|
|
|
|
_sizing_eval(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2009-11-09 04:32:10 -08:00
|
|
|
Evas_Coord minw = -1, minh = -1;
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 18:23:49 -07:00
|
|
|
edje_object_size_min_calc(wd->frm, &minw, &minh);
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
2009-11-09 04:32:10 -08:00
|
|
|
evas_object_size_hint_max_set(obj, -1, -1);
|
2008-10-06 18:23:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2008-10-06 18:23:49 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
2009-10-26 01:27:08 -07:00
|
|
|
// FIXME: why is this needed? how does edje get this unswallowed or
|
|
|
|
// lose its callbacks to edje
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2009-10-26 01:27:08 -07:00
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(data);
|
|
|
|
}
|
|
|
|
|
2008-10-06 23:55:11 -07:00
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
|
2008-10-06 23:55:11 -07:00
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *sub = event_info;
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2008-10-06 23:55:11 -07:00
|
|
|
if (sub == wd->content)
|
|
|
|
{
|
2009-10-22 14:46:54 -07:00
|
|
|
evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
2009-10-25 22:54:22 -07:00
|
|
|
_changed_size_hints, obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
wd->content = NULL;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Add a new frame to the parent
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return The new object or NULL if it cannot be created
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_frame_add(Evas_Object *parent)
|
|
|
|
{
|
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-12-03 06:08:33 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd = ELM_NEW(Widget_Data);
|
|
|
|
e = evas_object_evas_get(parent);
|
2010-12-12 11:12:43 -08:00
|
|
|
if (!e) return NULL;
|
2008-10-06 18:23:49 -07:00
|
|
|
obj = elm_widget_add(e);
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "frame");
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "frame");
|
|
|
|
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);
|
2010-10-06 13:24:13 -07:00
|
|
|
elm_widget_focus_next_hook_set(obj, _elm_frame_focus_next_hook);
|
2010-09-29 05:22:30 -07:00
|
|
|
elm_widget_can_focus_set(obj, EINA_FALSE);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->frm = edje_object_add(e);
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->frm, "frame", "base", "default");
|
2008-10-06 18:23:49 -07:00
|
|
|
elm_widget_resize_object_set(obj, wd->frm);
|
2008-10-06 23:55:11 -07:00
|
|
|
|
|
|
|
evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2011-02-08 04:08:28 -08:00
|
|
|
_mirrored_set(obj, elm_widget_mirrored_get(obj));
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the frame label
|
|
|
|
*
|
|
|
|
* @param obj The frame object
|
|
|
|
* @param label The label of this frame object
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_frame_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-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-09-23 22:11:33 -07:00
|
|
|
eina_stringshare_replace(&(wd->label), label);
|
|
|
|
edje_object_part_text_set(wd->frm, "elm.text", wd->label);
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Get the frame label
|
|
|
|
*
|
|
|
|
* @param obj The frame object
|
|
|
|
*
|
|
|
|
* @return The label of this frame objet or NULL if unable to get frame
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
2010-03-09 03:42:53 -08:00
|
|
|
EAPI const char *
|
2010-03-23 20:06:00 -07:00
|
|
|
elm_frame_label_get(const Evas_Object *obj)
|
2009-08-11 03:44:49 -07:00
|
|
|
{
|
2010-03-09 03:42:53 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2009-08-11 03:44:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-09-23 22:11:33 -07:00
|
|
|
if (!wd) return NULL;
|
|
|
|
return wd->label;
|
2009-08-11 03:44:49 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
2010-06-16 13:58:09 -07:00
|
|
|
* Set the content of the frame widget
|
|
|
|
*
|
|
|
|
* Once the content object is set, a previously set one will be deleted.
|
|
|
|
* If you want to keep that old content object, use the
|
|
|
|
* elm_frame_content_unset() function.
|
2009-09-17 15:39:18 -07:00
|
|
|
*
|
|
|
|
* @param obj The frame object
|
|
|
|
* @param content The content will be filled in this frame object
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_frame_content_set(Evas_Object *obj, Evas_Object *content)
|
|
|
|
{
|
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-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-06-16 13:58:09 -07:00
|
|
|
if (wd->content == content) return;
|
|
|
|
if (wd->content) evas_object_del(wd->content);
|
2008-10-06 23:55:11 -07:00
|
|
|
wd->content = content;
|
|
|
|
if (content)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 23:55:11 -07:00
|
|
|
elm_widget_sub_object_add(obj, content);
|
2010-06-16 13:58:09 -07:00
|
|
|
evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
2008-10-06 23:55:11 -07:00
|
|
|
_changed_size_hints, obj);
|
2009-12-07 06:19:20 -08:00
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2010-06-16 13:58:09 -07:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2010-10-14 11:54:42 -07:00
|
|
|
/**
|
|
|
|
* Get the content of the frame widget
|
|
|
|
*
|
|
|
|
* Return the content object which is set for this widget
|
|
|
|
*
|
|
|
|
* @param obj The frame object
|
|
|
|
* @return The content that is being used
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_frame_content_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return NULL;
|
|
|
|
return wd->content;
|
|
|
|
}
|
|
|
|
|
2010-06-16 13:58:09 -07:00
|
|
|
/**
|
|
|
|
* Unset the content of the frame widget
|
|
|
|
*
|
|
|
|
* Unparent and return the content object which was set for this widget
|
|
|
|
*
|
|
|
|
* @param obj The frame object
|
|
|
|
* @return The content that was being used
|
|
|
|
*
|
|
|
|
* @ingroup Frame
|
|
|
|
*/
|
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_frame_content_unset(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *content;
|
|
|
|
if (!wd) return NULL;
|
2010-06-23 20:01:47 -07:00
|
|
|
if (!wd->content) return NULL;
|
2010-06-16 13:58:09 -07:00
|
|
|
content = wd->content;
|
|
|
|
elm_widget_sub_object_del(obj, wd->content);
|
|
|
|
edje_object_part_unswallow(wd->frm, wd->content);
|
|
|
|
wd->content = NULL;
|
|
|
|
return content;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|