some classes for ETK C++ binding implemented

SVN revision: 38350
This commit is contained in:
Andreas Volz 2008-12-29 23:48:49 +00:00
parent c55c98b2f7
commit a18c2d9c3e
6 changed files with 506 additions and 71 deletions

2
TODO
View File

@ -3,3 +3,5 @@
* wrap evas_color_* functions (e.g. evas_color_argb_premul)
* move all #include <config.h> from *.h to *.cpp
* split eflpp into seperate libs (e.g. eflpp-edje, eflpp-evas, ...)
* replace char* with string
* create a wrap() function for all classes

View File

@ -192,14 +192,8 @@ void EdjePart::unswallow( EvasObject* object )
CountedPtr <EvasObject> EdjePart::swallow()
{
Evas_Object *eo = edje_object_part_swallow_get( _parent->obj(), _partname );
const char *t = evas_object_type_get( eo );
EvasObject *ret_o = NULL;
if( !strcmp( t,"edje" ) )
{
ret_o = EvasEdje::wrap (eo);
}
// TODO: support other types
EvasObject *ret_o = EvasObject::wrap (eo);
return CountedPtr <EvasObject> (ret_o);
}

View File

@ -7,6 +7,7 @@
#include <iostream>
#include <cstring>
#include <assert.h>
using namespace std;
namespace efl {
@ -103,19 +104,6 @@ bool EtkWidget::isVisible() const
return etk_widget_is_visible( ETK_WIDGET(_o) );
}
void EtkWidget::setVisibilityLock( bool b )
{
// hack: [audifahrer]
//etk_widget_visibility_locked_set( ETK_WIDGET(_o), b );
}
bool EtkWidget::visibilityLock() const
{
// hack: [audifahrer]
//return etk_widget_visibility_locked_get( ETK_WIDGET(_o) );
return false;
}
//==========================================================================//
// EtkContainer
//==========================================================================//
@ -126,18 +114,59 @@ EtkContainer::EtkContainer( EtkObject* parent, const char* type, const char* nam
init( );
}
EtkContainer::EtkContainer (Etk_Object *o)
{
_o = o;
_managed = false;
}
EtkContainer::~EtkContainer()
{
}
void EtkContainer::appendChild( EtkWidget* child )
void EtkContainer::add( EtkWidget* child )
{
etk_container_add( ETK_CONTAINER(_o), ETK_WIDGET(child->obj()) );
}
void EtkContainer::remove (EtkWidget *widget)
{
etk_container_remove (ETK_WIDGET (widget->obj ()));
}
void EtkContainer::removeAll ()
{
etk_container_remove_all (ETK_CONTAINER(_o));
}
void EtkContainer::setBorderWidth( int width )
{
etk_container_border_width_set( ETK_CONTAINER(_o), 5);
etk_container_border_width_set( ETK_CONTAINER (_o), width);
}
int EtkContainer::getBorderWidth ()
{
return etk_container_border_width_get (ETK_CONTAINER (_o));
}
Eina_List *EtkContainer::getChildren ()
{
return etk_container_children_get (ETK_CONTAINER (_o));
}
bool EtkContainer::isChild (EtkWidget *widget)
{
return etk_container_is_child(ETK_CONTAINER (_o), ETK_WIDGET (widget->obj ()));
}
void EtkContainer::fillChildSpace (EtkWidget *child, Etk_Geometry &out_child_space, bool hfill, bool vfill, float xalign, float yalign)
{
etk_container_child_space_fill (ETK_WIDGET (child->obj ()), &out_child_space, hfill, vfill, xalign, yalign);
}
EtkContainer *EtkContainer::wrap( Etk_Object* o )
{
return new EtkContainer (o);
}
//==========================================================================//
@ -260,6 +289,133 @@ EtkImage::EtkImage( Etk_Object *o )
_managed = false;
}
void EtkImage::setFromFile( const string &filename, const string &key )
{
etk_image_set_from_file( ETK_IMAGE( _o ), filename.c_str (), key.c_str () );
}
void EtkImage::getFile( string &outFilename, string &outKey, bool eetLoaded )
{
char *filename = NULL;
char *key = NULL;
etk_image_file_get( ETK_IMAGE( _o ), &filename, &key);
outFilename = filename;
if (key)
{
outKey = key;
eetLoaded = true;
}
else
{
eetLoaded = false;
}
}
void EtkImage::setFromEdje (const string &filename, const string &group)
{
etk_image_set_from_edje (ETK_IMAGE( _o ), filename.c_str (), group.c_str ());
}
void EtkImage::getEdje (string &outFilename, string &outGroup)
{
char *filename = NULL;
char *group = NULL;
etk_image_edje_get( ETK_IMAGE( _o ), &filename, &group);
outFilename = filename;
outGroup = group;
}
void EtkImage::setFromStock (Etk_Stock_Id stock_id, Etk_Stock_Size stock_size)
{
etk_image_set_from_stock (ETK_IMAGE( _o ), stock_id, stock_size);
}
Etk_Stock_Id EtkImage::getStockId ()
{
Etk_Stock_Id stock_id;
etk_image_stock_get (ETK_IMAGE (_o), &stock_id, NULL);
return stock_id;
}
Etk_Stock_Size EtkImage::getStockSize ()
{
Etk_Stock_Size stock_size;
etk_image_stock_get (ETK_IMAGE (_o), NULL, &stock_size);
return stock_size;
}
void EtkImage::setFromEvasObject (const EvasObject &eo)
{
etk_image_set_from_evas_object (ETK_IMAGE (_o), eo.obj ());
}
CountedPtr <EvasObject> EtkImage::getEvasObject ()
{
Evas_Object *eo = etk_image_evas_object_get (ETK_IMAGE (_o));
return CountedPtr <EvasObject> (EvasObject::wrap (eo));
}
void EtkImage::setFromData (int width, int height, void *data, bool copy)
{
etk_image_set_from_data (ETK_IMAGE (_o), width, height, data, copy);
}
void *EtkImage::getData (bool for_writing)
{
return etk_image_data_get (ETK_IMAGE (_o), for_writing);
}
Etk_Image_Source EtkImage::getSource ()
{
return etk_image_source_get (ETK_IMAGE (_o));
}
void EtkImage::update ()
{
etk_image_update (ETK_IMAGE (_o));
}
void EtkImage::rectUpdate (int x, int y, int w, int h)
{
etk_image_update_rect (ETK_IMAGE (_o), x, y, w, h);
}
int EtkImage::getWidth ()
{
int width;
etk_image_size_get (ETK_IMAGE (_o), &width, NULL);
return width;
}
int EtkImage::getHeight ()
{
int height;
etk_image_size_get (ETK_IMAGE (_o), NULL, &height);
return height;
}
void EtkImage::setAspect (bool keep_aspect)
{
etk_image_keep_aspect_set (ETK_IMAGE (_o), keep_aspect);
}
bool EtkImage::getKeepAspect ()
{
return etk_image_keep_aspect_get (ETK_IMAGE (_o));
}
void EtkImage::setRatio (double aspect_ratio)
{
etk_image_aspect_ratio_set (ETK_IMAGE (_o), aspect_ratio);
}
double EtkImage::getRatio ()
{
return etk_image_aspect_ratio_get (ETK_IMAGE (_o));
}
EtkImage *EtkImage::wrap( Etk_Object* o )
{
return new EtkImage( o );
@ -273,13 +429,13 @@ EtkButton::EtkButton( EtkObject* parent, const char* type, const char* name )
:EtkBox( parent, type, name )
{
init( );
setText( name ? name : "unnamed" );
setLabel( name ? name : "unnamed" );
}
EtkButton::EtkButton( const char* text, EtkObject* parent, const char* type, const char* name )
:EtkBox( parent, type, name )
{
setText( text );
setLabel( text );
}
EtkButton::EtkButton( Etk_Object *o )
@ -292,12 +448,12 @@ EtkButton::~EtkButton()
{
}
void EtkButton::setText( const char* text )
void EtkButton::setLabel( const string &label )
{
etk_button_label_set( ETK_BUTTON(_o), const_cast<char*>( text ) );
etk_button_label_set( ETK_BUTTON(_o), label.c_str () );
}
const char *EtkButton::getText( )
const string EtkButton::getLabel( )
{
return etk_button_label_get (ETK_BUTTON(_o));
}

View File

@ -5,15 +5,21 @@
#include <config.h>
#endif
/* STL */
#include <string>
/* EFL++ */
#include <eflpp_common.h>
#include <eflpp_evas.h>
#include <eflpp_countedptr.h>
/* EFL */
#include <etk/Etk.h>
#define etkApp EtkApplication::application()
using std::string;
namespace efl {
class EtkObject;
@ -53,8 +59,6 @@ class EtkWidget : public EtkObject
void hideAll();
bool isVisible() const;
void setVisibilityLock( bool );
bool visibilityLock() const;
};
class EtkContainer : public EtkWidget
@ -63,8 +67,87 @@ class EtkContainer : public EtkWidget
EtkContainer( EtkObject* parent = 0, const char* type = "Container", const char* name = 0 );
virtual ~EtkContainer();
void appendChild( EtkWidget* child );
/**
* @brief Adds a child to the container
* @param widget the widget to add
*/
void add( EtkWidget* child );
/**
* @brief Removes a child from its container. It is equivalent to setParent (NULL)
* @param widget the widget to remove
*/
void remove (EtkWidget *widget);
/**
* @brief Unpacks all the children of the container
*/
void removeAll ();
/**
* @brief Sets the border width of a container. The border width is the amount of space left around the inside of
* the container. To add free space around the outside of a container, you can use etk_widget_padding_set()
* @param border_width the border width to set
* @see setPadding()
*/
void setBorderWidth( int );
/**
* @brief Gets the border width of the container
* @return Returns the border width of the container
*/
int getBorderWidth ();
/**
* @brief Gets the list of the children of the container. It simply calls the "childrend_get()" method of the container
* @return Returns the list of the container's children
* @note The returned list will have to be freed with eina_list_free() when you no longer need it
* @todo wrap Eina_List
*/
Eina_List *getChildren ();
/**
* @brief Gets whether the widget is a child of the container
* @param widget the widget you want to check if it is a child of the container
* @return Returns true if the widget is a child of the container, false otherwise
*/
bool isChild (EtkWidget *widget);
/**
* @brief Calls @a for_each_cb(child) for each child of the container
* @param for_each_cb the function to call
* @todo do it with sigc++
*/
//void etk_container_for_each(Etk_Container *container, void (*for_each_cb)(Etk_Widget *child))
/**
* @brief Calls @a for_each_cb(child, data) for each child of the container
* @param for_each_cb the function to call
* @param data the data to pass as the second argument of @a for_each_cb()
* @todo do it with sigc++
*/
//void etk_container_for_each_data(Etk_Container *container, void (*for_each_cb)(Etk_Widget *child, void *data), void *data)
/**
* @brief A utility function that resizes the given space according to the specified fill-policy.
* It is mainly used by container implementations
* @param child a child
* @param child_space the space for the child. It will be modified according to the fill options
* @param hfill if @a hfill == true, the child will fill the space horizontally
* @param vfill if @a vfill == true, the child will fill the space vertically
* @param xalign the horizontal alignment of the child widget in the child space (has no effect if @a hfill is true)
* @param yalign the vertical alignment of the child widget in the child space (has no effect if @a vfill is true)
*/
static void fillChildSpace (EtkWidget *child, Etk_Geometry &out_child_space, bool hfill, bool vfill, float xalign, float yalign);
/**
* @brief C object wrapper factory method
* Only for internal usage!
*/
static EtkContainer *wrap( Etk_Object* o );
private:
EtkContainer (Etk_Object *o);
};
class EtkTopLevelWidget : public EtkContainer
@ -98,6 +181,185 @@ class EtkVBox : public EtkBox
class EtkImage : public EtkWidget
{
public:
/*
Etk_Widget * etk_image_new (void)
Creates a new empty image.
Etk_Widget * etk_image_new_from_file (const char *filename, const char *key)
Creates a new image and loads the image from an image file.
Etk_Widget * etk_image_new_from_edje (const char *filename, const char *group)
Creates a new image and loads the image from an edje-file.
Etk_Widget * etk_image_new_from_stock (Etk_Stock_Id stock_id, Etk_Stock_Size stock_size)
Creates a new image and loads the image corresponding to the stock id.
Etk_Widget * etk_image_new_from_evas_object (Evas_Object *evas_object)
Creates a new image from the given evas object.
Etk_Widget * etk_image_new_from_data (int width, int height, void *data, Etk_Bool copy)
Creates a new image from the given pixel data.
*/
/**
* @brief Loads the image from a file.
* @param filename the path to the file to load
* @param key the key to load (only used if the file is an Eet file, otherwise you can set it to NULL)
*/
void setFromFile( const string &filename, const string &key );
/**
* @brief Gets the path to the file used by the image.
* @param outFilename the location where to store the path to the loaded file
* @param outKey the location where to store the key of the loaded image
* @param false if the file is not loaded from an Eet file
*/
void getFile( string &outFilename, string &outKey, bool eetLoaded );
/**
* @brief Loads the image from an edje file
* @param filename the path to the edje-file to load
* @param group the name of the edje-group to load
*/
void setFromEdje (const string &filename, const string &group);
/**
* @brief Gets the filename and the group of the edje-object used for the image
* @param outFilename the location to store the path to the edje-file used
* @param outGroup the location to store the name of the edje-group used
*/
void getEdje (string &outFilename, string &outGroup);
/**
* @brief Loads the image corresponding to the given stock-id
* @param stock_id the stock-id corresponding to the icon to load
* @param stock_size the size of the stock-icon
*/
void setFromStock (Etk_Stock_Id stock_id, Etk_Stock_Size stock_size);
/**
* @brief Gets the stock-id used by the image
* @return stock id used by the image
*/
Etk_Stock_Id getStockId ();
/**
* @brief Gets the stock-size used by the image
* @return stock size used by the image
*/
Etk_Stock_Size getStockSize ();
/**
* @brief Loads the image from an Evas object
* @param evas_object the Evas object to use. The object can be anything (image, edje object, emotion object, ...)
*/
void setFromEvasObject (const EvasObject &evas_object);
/**
* @brief Gets the Evas object used by the image. You can call this function even if you have not explicitly set the
* Evas object used by this image. For example, if you have loaded the image from a file, this function will return the
* corresponding Evas image object. You should just be careful by manipulating it (don't use Edje functions on an image
* object for example).
* @return Returns the EvasObject of the image
*/
CountedPtr <EvasObject> getEvasObject ();
/**
* @brief Sets the pixels of the image
* @param width the width of the image
* @param height the height of the image
* @param data a pointer to the pixels: the pixels have to be stored in the premul'ed ARGB format
* @param copy whether the pixels should be copied or not. If you decide not to copy the pixels, you have to make sure
* the memory area where the pixels are stored is valid during all the lifetime of the image
* @return Returns the new image widget
*/
void setFromData (int width, int height, void *data, bool copy);
/**
* @brief Gets a pointer to the image pixels. This function only works if the image has been loaded from a file or if
* you have explicitely set its pixels with etk_image_set_from_data().
* @param for_writing whether or not you want to be able to modify the pixels of the image. If so, call
* update() once you have finished.
* @return Returns a pointer to the location of the pixels (stored in premul'ed ARGB format)
* @note If the image is loaded from a file, it has to be realized. Otherwise it will return NULL
*/
void *getData (bool for_writing);
/**
* @brief Gets the source of the image (file, edje-file, stock, Evas object or pixel data)
* @return Returns the source of the image
*/
Etk_Image_Source getSource ();
/**
* @brief Updates all the pixels of the image (to be called after you have modified the pixel buffer for example).
* Same as rectUpdate(0, 0, image_width, image_height)
*/
void update ();
/**
* @brief Updates a rectangle of the pixels of the image (to be called after you have modified the pixel buffer
* for example). It only has effect on image loaded from a pixel buffer
* @param x the x position of the top-left corner of the rectangle to update
* @param y the y position of the top-left corner of the rectangle to update
* @param w the width of the rectangle to update
* @param h the height of the rectangle to update
*/
void rectUpdate (int x, int y, int w, int h);
/**
* @brief Gets the native width of the image. If the image is loaded from a file or from given pixels, it returns the
* native size of the image. If the image is loaded from an Edje file or a stock-id, it returns the minimum size of the
* Edje object (a stock image is an Edje object). Otherwise, the returned size is 0x0
* @return native width of the image
*/
int getWidth ();
/**
* @brief Gets the native height of the image. If the image is loaded from a file or from given pixels, it returns the
* native size of the image. If the image is loaded from an Edje file or a stock-id, it returns the minimum size of the
* Edje object (a stock image is an Edje object). Otherwise, the returned size is 0x0
* @return native height of the image
*/
int getHeight ();
/**
* @brief Sets if the image should keep its aspect ratio when it is resized
* @param keep_aspect if @a keep_aspect is true, the image will keep its aspect ratio when it is resized
*/
void setAspect (bool keep_aspect);
/**
* @brief Gets whether the image keeps its aspect ratio when it is resized
* @return Returns true if the image keeps its aspect ratio when it is resized
*/
bool getKeepAspect ();
/**
* @brief Sets (forces) the aspect ratio of the image. You can use this function for example to set the aspect-ratio
* when you set the image from an Evas object with etk_image_set_from_evas_object().
* @param aspect_ratio the aspect ratio to set, or 0.0 to make Etk calculates automatically the aspect ratio
*/
void setRatio (double aspect_ratio);
/**
* @brief Gets the aspect ratio you set to the image. If no aspect ratio has been set, it will return 0.0.
* To know the native aspect ratio, call etk_image_size_get() to get the native size of the image and calculate the
* aspect ratio from these values.
* @return Returns the aspect ratio you set to the image, or 0.0 if no aspect ratio has been set
*/
double getRatio ();
/**
* @brief Copies the image @a src_image to @a dest_image
* @param dest_image the destination image
* @param src_image the image to copy
* @note If @a src_image is an edje image, the current state of the edje animation won't be copied
*/
/*
TODO: copy constructor:
void etk_image_copy (Etk_Image *dest_image, Etk_Image *src_image)
*/
/**
* @brief C object wrapper factory method
* Only for internal usage!
*/
static EtkImage *wrap( Etk_Object* o );
private:
@ -128,61 +390,85 @@ void etk_button_click (Etk_Button *button)
Clicks on the button.
*/
/*!
* Sets the text of the button's label.
/**
* @brief Sets the text of the button's label
* @param label the text to set to the button's label
*/
void setText( const char* text );
void setLabel( const string &label );
/*!
* Gets the text of the button's label.
/**
* @brief Gets the text of the button's label
* @return Returns the text of the button's label
*/
const char *getText( );
const string getLabel( );
/*!
* Sets the image of the button.
/**
* @brief Sets the image of the button
* @param image the image to set
* @note If the button already has an image, the current image will just be unpacked, it will not be destroyed
* @note The image will be automatically shown, but you can still manually hide it with calling etk_widget_hide()
* after having called etk_button_image_set()
* @todo Change usage to CountedPtr!
*/
void setImage( EtkImage *image );
/*!
* Gets the image of the button.
/**
* @brief Gets the image of the button
* @return Returns the image of the button, or NULL if the button has no image
* @todo Change usage to CountedPtr!
*/
EtkImage *getImage( );
/*!
* Sets the label and the image of the button from a stock-id.
/**
* @brief Sets the label and the image of the button from a stock-id
* @param stock_id the stock-id to use
* @note For some stock-id, the label is empty
*/
void setFromStock( Etk_Stock_Id stock_id );
/*!
* Sets the style of the button (icon, text, both vertically, both horizontally).
/**
* @brief Sets the style of the button (icon, text, both vertically, both horizontally)
* @param style the style to give to the button
*/
void setStyle( Etk_Button_Style style );
/*!
* Gets the style of the button.
/**
* @brief Gets the style of the button
* @return Returns the button's style
*/
Etk_Button_Style getStyle( );
/*!
* Sets the stock-size of the button's image.
/**
* @brief Sets the stock-size of the button's image
* @param size the stock-size
*/
void setStockSize( Etk_Stock_Size size );
/*!
* Gets the stock-size of the button's image.
/**
* @brief Gets the stock-size of the button's image
* @return Returns the stock-size of the button's image
*/
Etk_Stock_Size getStockSize( );
/*!
* Sets the alignment of the child of the button.
/**
* @brief Sets the alignment of the child of the button
* @param xalign the horizontal alignment (0.0 = left, 0.5 = center, 1.0 = right, ...)
* @param yalign the vertical alignment (0.0 = top, 0.5 = center, 1.0 = bottom, ...)
* @note It only has effect if the child is a label or an alignment
*/
void setAlignment( float xalign, float yalign );
/*!
* Gets the alignment of the button's child.
/**
* @brief Gets the alignment of the button's child
* @param xalign the location where to store the horizontal alignment
* @param yalign the location where to store the vertical alignment
*/
void getAlignment( float &xalign, float &yalign );
/**
* @brief C object wrapper factory method
* Only for internal usage!
*/
static EtkButton *wrap( Etk_Object* o );
private:

View File

@ -193,14 +193,13 @@ EvasObject* EvasCanvas::objectAtBottom() const
EvasObject::EvasObject (Evas_Object *eo)
{
o = eo;
mManaged = false;
}
/*EvasObject::EvasObject( EvasCanvas* canvas, const char* name )
: _canvas( canvas )
EvasObject *EvasObject::wrap( Evas_Object* o )
{
AllocTag( this, type );
Dout( dc::notice, "EvasObject::Object " << "created new " << type << " (" << ( name ? name : "null" ) << ")" );
}*/
return new EvasObject (o);
}
void EvasObject::init (const char *name)
{

View File

@ -111,23 +111,13 @@ class EvasObject
protected:
EvasObject () {}
// construction/destruction
//EvasObject( EvasCanvas* canvas,
// const char* name = "(null)" );
public:
/*!
* Construct from existing Evas_Object
*/
EvasObject (Evas_Object *eo);
public:
virtual ~EvasObject();
bool operator==(const EvasObject& rhs) { return rhs.o == o; };
/* don't use these */
Evas_Object* obj() const { return o; };
//EvasCanvas* canvas() const { return _canvas; }; // FIXME: Rename to parent() ?
/* event signals */
sigc::signal <void, const EvasMouseInEvent&> signalHandleMouseIn;
@ -199,6 +189,8 @@ class EvasObject
/* Focus */
virtual void setFocus( bool focus );
virtual bool hasFocus() const;
static EvasObject *wrap( Evas_Object* o );
private:
static EvasObject* objectLink( Evas_Object* evas_object = 0 );
@ -214,6 +206,12 @@ class EvasObject
private:
//EvasObject(); // disable default constructor
/*!
* Construct from existing Evas_Object
*/
EvasObject (Evas_Object *eo);
EvasObject( const EvasObject& ); // disable copy constructor
bool operator=(const EvasObject& ); // disable assignment operator
};