[Elm] New Elm widget class: cointainer

This is for general purpose containers in Elm, those supporting
- elm_object_part_content_set()
- elm_object_part_content_get()
- elm_object_part_content_unset()



SVN revision: 70707
This commit is contained in:
Gustavo Lima Chaves 2012-05-03 22:41:21 +00:00
parent efec09ea74
commit d064f020c3
3 changed files with 205 additions and 1 deletions

View File

@ -41,7 +41,8 @@ Elementary_Cursor.h
includesdir = $(includedir)/elementary-@VMAJ@
includesunstable_HEADERS = \
elm_widget.h
elm_widget.h \
elm_widget_container.h
includesunstabledir = $(includedir)/elementary-@VMAJ@
includesub_HEADERS = \
@ -160,6 +161,7 @@ elm_cnp.c \
elm_colorselector.c \
elm_config.c \
elm_conform.c \
elm_container.c \
elm_datetime.c \
elm_diskselector.c \
elm_entry.c \

View File

@ -0,0 +1,68 @@
#include <Elementary.h>
#include "elm_priv.h"
#include "elm_widget_container.h"
static const char CONTAINER_SMART_NAME[] = "elm_container";
/* Elementary smart class for all widgets containing others */
EVAS_SMART_SUBCLASS_NEW
(CONTAINER_SMART_NAME, _elm_container, Elm_Container_Smart_Class,
Elm_Widget_Smart_Class, elm_widget_smart_class_get, NULL);
/* no *direct* instantiation of this class, so far */
__UNUSED__ static Evas_Smart *_elm_container_smart_class_new(void);
static Eina_Bool
_unimplemented_smart_content_set(Evas_Object *obj,
const char *name __UNUSED__,
Evas_Object *content __UNUSED__)
{
WRN("The %s widget does not implement the \"content_set()\" function.",
elm_widget_type_get(obj));
return EINA_FALSE;
}
static Evas_Object *
_unimplemented_smart_content_get(const Evas_Object *obj,
const char *name __UNUSED__)
{
WRN("The %s widget does not implement the \"content_get()\" function.",
elm_widget_type_get(obj));
return NULL;
}
static Evas_Object *
_unimplemented_smart_content_unset(Evas_Object *obj,
const char *name __UNUSED__)
{
WRN("The %s widunset does not implement the \"content_unset()\" function.",
elm_widget_type_get(obj));
return NULL;
}
EAPI const Elm_Container_Smart_Class *
elm_container_smart_class_get(void)
{
static Elm_Container_Smart_Class _sc =
ELM_CONTAINER_SMART_CLASS_INIT_NAME_VERSION(CONTAINER_SMART_NAME);
static const Elm_Container_Smart_Class *class = NULL;
if (class)
return class;
_elm_container_smart_set(&_sc);
class = &_sc;
return class;
}
static void
_elm_container_smart_set_user(Elm_Container_Smart_Class *sc)
{
sc->content_set = _unimplemented_smart_content_set;
sc->content_get = _unimplemented_smart_content_get;
sc->content_unset = _unimplemented_smart_content_unset;
}

View File

@ -0,0 +1,134 @@
#ifndef ELM_WIDGET_CONTAINER_H
#define ELM_WIDGET_CONTAINER_H
/**
* @addtogroup Widget
* @{
*
* @section elm-container-class The Elementary Container Class
*
* This class defines a common interface for objects acting like
* containers, i.e. objects parenting others and displaying their
* childs "inside" of them somehow.
*
* The container must define "parts" (or spots) into which child
* objects will be placed, inside of it. This is a way of handling
* more the one content object, by naming content locations
* properly. This is the role of the @c name argument of the virtual
* functions in the class.
*
* The following object functions are meant to be used with all
* container objects and derived ones:
*
* - elm_object_part_content_set()
* - elm_object_part_content_get()
* - elm_object_part_content_unset()
*/
/**
* @def ELM_CONTAINER_CLASS
*
* Use this macro to cast whichever subclass of
* #Elm_Container_Smart_Class into it, so to acess its fields.
*
* @ingroup Container
*/
#define ELM_CONTAINER_CLASS(x) ((Elm_Container_Smart_Class *) x)
/**
* @def ELM_CONTAINER_SMART_CLASS_VERSION
*
* Current version for Elementary container @b base smart class, a value
* which goes to _Elm_Container_Smart_Class::version.
*
* @ingroup Widget
*/
#define ELM_CONTAINER_SMART_CLASS_VERSION 1
/**
* @def ELM_CONTAINER_SMART_CLASS_INIT
*
* Initializer for a whole #Elm_Container_Smart_Class structure, with
* @c NULL values on its specific fields.
*
* @param smart_class_init initializer to use for the "base" field
* (#Evas_Smart_Class).
*
* @see EVAS_SMART_CLASS_INIT_NULL
* @see EVAS_SMART_CLASS_INIT_NAME_VERSION
* @see ELM_CONTAINER_SMART_CLASS_INIT_NULL
* @see ELM_CONTAINER_SMART_CLASS_INIT_NAME_VERSION
*
* @ingroup Widget
*/
#define ELM_CONTAINER_SMART_CLASS_INIT(smart_class_init) \
{smart_class_init, ELM_CONTAINER_SMART_CLASS_VERSION, NULL, NULL, NULL}
/**
* @def ELM_CONTAINER_SMART_CLASS_INIT_NULL
*
* Initializer to zero out a whole #Elm_Container_Smart_Class structure.
*
* @see ELM_CONTAINER_SMART_CLASS_INIT_NAME_VERSION
* @see ELM_CONTAINER_SMART_CLASS_INIT
*
* @ingroup Widget
*/
#define ELM_CONTAINER_SMART_CLASS_INIT_NULL \
ELM_CONTAINER_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
/**
* @def ELM_CONTAINER_SMART_CLASS_INIT_NAME_VERSION
*
* Initializer to zero out a whole #Elm_Container_Smart_Class structure and
* set its name and version.
*
* This is similar to #ELM_CONTAINER_SMART_CLASS_INIT_NULL, but it will
* also set the version field of #Elm_Container_Smart_Class (base field)
* to the latest #ELM_CONTAINER_SMART_CLASS_VERSION and name it to the
* specific value.
*
* It will keep a reference to the name field as a <c>"const char *"</c>,
* i.e., the name must be available while the structure is
* used (hint: static or global variable!) and must not be modified.
*
* @see ELM_CONTAINER_SMART_CLASS_INIT_NULL
* @see ELM_CONTAINER_SMART_CLASS_INIT
*
* @ingroup Widget
*/
#define ELM_CONTAINER_SMART_CLASS_INIT_NAME_VERSION(name) \
ELM_CONTAINER_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
/**
* Elementary container base smart class. This inherits directly from
* #Elm_Widget_Smart_Class and is meant to build widgets relying on an
* Edje container as a building block of its visuals.
*
* For instance, the elm_container @b widget itself is just a realization
* of this smart class (see the code for elm_container_add()). All of the
* functions listed on @ref Container namespace will work for objects
* deriving from #Elm_Container_Smart_Class.
*/
typedef struct _Elm_Container_Smart_Class
{
Elm_Widget_Smart_Class base; /**< Base Elementary widget class struct, since we're inheriting from it */
int version; /**< Version of this smart class definition */
Eina_Bool (*content_set)(Evas_Object *obj,
const char *part,
Evas_Object *content); /* 'Virtual' function on setting content on the object, at the given @a part part */
Evas_Object *(*content_get)(const Evas_Object * obj,
const char *part); /* 'Virtual' function on retrieving content from the object, at the given @a part part */
Evas_Object *(*content_unset)(Evas_Object * obj,
const char *part); /* 'Virtual' function on unsetting content from the object, at the given @a part part. Meant to return the content's pointer. */
} Elm_Container_Smart_Class;
/**
* @}
*/
EAPI const Elm_Container_Smart_Class *elm_container_smart_class_get(void);
#endif