2008-09-29 23:58:56 -07:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Box Box
|
|
|
|
*
|
2009-07-03 04:16:16 -07:00
|
|
|
* A box object arranges objects in a single row within a box. Sub objects can
|
|
|
|
* be added at the start, end or before or after any existing object in the
|
|
|
|
* box already. It can have its orientation changed too. How a child object is
|
|
|
|
* sized and otherwise arranged within the box depends on evas hints.
|
|
|
|
* evas_object_size_hint_align_set() will set either the alignment within its
|
|
|
|
* region if the region allocated is bigger than the object size. If you want
|
|
|
|
* the sub object sized up to fill the allocated region, use -1.0 for the
|
|
|
|
* apporpriate horizontal or vertical axes. evas_object_size_hint_weight_set()
|
|
|
|
* will set the packing weight. The weights of all items being packed are added
|
|
|
|
* up and if items are to be sized up to fit, those with the higher weights get
|
|
|
|
* proportionally more space.
|
2009-07-03 04:04:25 -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 *box;
|
2008-09-29 23:58:56 -07:00
|
|
|
};
|
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
static void _del_hook(Evas_Object *obj);
|
|
|
|
static void _sizing_eval(Evas_Object *obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
|
|
|
static void _sub_del(void *data, Evas_Object *obj, void *event_info);
|
2008-10-06 18:23:49 -07:00
|
|
|
|
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);
|
|
|
|
free(wd);
|
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;
|
|
|
|
Evas_Coord w, h;
|
|
|
|
|
|
|
|
evas_object_size_hint_min_get(wd->box, &minw, &minh);
|
|
|
|
evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
evas_object_size_hint_max_set(obj, maxw, maxh);
|
|
|
|
evas_object_geometry_get(obj, NULL, NULL, &w, &h);
|
|
|
|
if (w < minw) w = minw;
|
|
|
|
if (h < minh) h = minh;
|
|
|
|
if ((maxw >= 0) && (w > maxw)) w = maxw;
|
|
|
|
if ((maxh >= 0) && (h > maxh)) h = maxh;
|
|
|
|
evas_object_resize(obj, w, h);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-06 18:23:49 -07:00
|
|
|
_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
_sizing_eval(data);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-06 23:55:11 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_sub_del(void *data, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *sub = event_info;
|
|
|
|
evas_object_event_callback_del
|
|
|
|
(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new box to the parent
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return The new object or NULL if it cannot be created
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_box_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);
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "box");
|
|
|
|
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);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
wd->box = _els_smart_box_add(e);
|
|
|
|
evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
|
|
|
_changed_size_hints, obj);
|
2008-10-06 23:55:11 -07:00
|
|
|
elm_widget_resize_object_set(obj, wd->box);
|
|
|
|
|
|
|
|
evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-10-06 18:23:49 -07:00
|
|
|
return obj;
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* Set the horizontal orientation
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* By default box object arrange their contents vertically from top to bottom.
|
|
|
|
* By calling this and providing @p orizontal as true, the box will become
|
|
|
|
* horizontal arranging contents left to right.
|
|
|
|
*
|
|
|
|
* @param obj The box object
|
|
|
|
* @param horizontal The horizontal flag (1 = horizontal, 0 = vertical)
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_box_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
_els_smart_box_orientation_set(wd->box, horizontal);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* Set homogenous layout
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* If enabled, homogenous layout makes all items the same size. This size is
|
|
|
|
* of course governed by the size of the largest item in the box.
|
|
|
|
*
|
|
|
|
* @param obj The box object
|
|
|
|
* @param homogenous The homogenous flag (1 = on, 2 = off)
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
2009-06-17 08:35:19 -07:00
|
|
|
elm_box_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
_els_smart_box_homogenous_set(wd->box, homogenous);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2008-10-02 05:45:23 -07:00
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* This adds a box at the start of the box (top or left based on orientation)
|
|
|
|
*
|
|
|
|
* This will add the @p subobj to the box object indicated at the beginning
|
|
|
|
* of the box (the left or top end).
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @param obj The box object
|
|
|
|
* @param subobj The object to add to the box
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_box_pack_start(Evas_Object *obj, Evas_Object *subobj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
elm_widget_sub_object_add(obj, subobj);
|
2008-10-08 01:14:25 -07:00
|
|
|
_els_smart_box_pack_start(wd->box, subobj);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* This adds a box at the end of the box (bottom or right based on orientation)
|
|
|
|
*
|
|
|
|
* This will add the @p subobj to the box object indicated at the end
|
|
|
|
* of the box (the right or bottom end).
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @param obj The box object
|
|
|
|
* @param subobj The object to add to the box
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
elm_widget_sub_object_add(obj, subobj);
|
2008-10-08 01:14:25 -07:00
|
|
|
_els_smart_box_pack_end(wd->box, subobj);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* This adds adds an object to the box before the indicated object
|
|
|
|
*
|
|
|
|
* This will add the @p subobj to the box indicated before the object
|
|
|
|
* indicated with @p before. If @p before is not already in the box, results
|
|
|
|
* are undefined. Before means either to the left of the indicated object or
|
|
|
|
* above it depending on orientation.
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @param obj The box object
|
|
|
|
* @param subobj The object to add to the box
|
|
|
|
* @param before The object before which to add it
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before)
|
2008-09-29 23:58:56 -07:00
|
|
|
{
|
2008-10-06 18:23:49 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
elm_widget_sub_object_add(obj, subobj);
|
2008-10-08 01:14:25 -07:00
|
|
|
_els_smart_box_pack_before(wd->box, subobj, before);
|
2008-10-06 18:23:49 -07:00
|
|
|
}
|
2008-09-29 23:58:56 -07:00
|
|
|
|
2009-07-03 04:04:25 -07:00
|
|
|
/**
|
|
|
|
* This adds adds an object to the box after the indicated object
|
|
|
|
*
|
|
|
|
* This will add the @p subobj to the box indicated after the object
|
|
|
|
* indicated with @p after. If @p after is not already in the box, results
|
|
|
|
* are undefined. After means either to the right of the indicated object or
|
|
|
|
* below it depending on orientation.
|
2009-07-06 23:46:51 -07:00
|
|
|
*
|
2009-07-03 04:04:25 -07:00
|
|
|
* @param obj The box object
|
|
|
|
* @param subobj The object to add to the box
|
|
|
|
* @param after The object after which to add it
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
2008-10-06 18:23:49 -07:00
|
|
|
EAPI void
|
|
|
|
elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
elm_widget_sub_object_add(obj, subobj);
|
2008-10-08 01:14:25 -07:00
|
|
|
_els_smart_box_pack_after(wd->box, subobj, after);
|
2008-09-29 23:58:56 -07:00
|
|
|
}
|
2009-09-11 06:43:02 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This clears the box items
|
|
|
|
*
|
|
|
|
* This delete all members of the box object, but not the box itself.
|
|
|
|
*
|
|
|
|
* @param obj The box object
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
elm_box_clear(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
_els_smart_box_clear(wd->box);
|
|
|
|
}
|
2009-09-20 06:01:25 -07:00
|
|
|
|
|
|
|
/**
|
2009-09-21 11:09:51 -07:00
|
|
|
* This unpack a box item
|
2009-09-20 06:01:25 -07:00
|
|
|
*
|
2009-09-21 11:09:51 -07:00
|
|
|
* This unpack the selected member from the box object, but does not delete
|
|
|
|
* the box itself or the packed items.
|
2009-09-20 06:01:25 -07:00
|
|
|
*
|
2009-09-21 11:09:51 -07:00
|
|
|
* @param obj The box object
|
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
elm_box_unpack(Evas_Object *obj, Evas_Object *subobj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
_els_smart_box_unpack(wd->box, subobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This unpack the box items
|
|
|
|
*
|
|
|
|
* This unpack all members from the box object, but does not delete
|
|
|
|
* the box itself or the packed items.
|
|
|
|
*
|
|
|
|
* @param obj The box object
|
2009-09-20 06:01:25 -07:00
|
|
|
*
|
|
|
|
* @ingroup Box
|
|
|
|
*/
|
|
|
|
EAPI void
|
2009-09-21 11:09:51 -07:00
|
|
|
elm_box_unpack_all(Evas_Object *obj)
|
2009-09-20 06:01:25 -07:00
|
|
|
{
|
2009-09-21 11:09:51 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
_els_smart_box_unpack_all(wd->box);
|
2009-09-20 06:01:25 -07:00
|
|
|
}
|