Enlightenment CVS committal

Author  : moom
Project : e17
Module  : libs/etk

Dir     : e17/libs/etk/src/lib


Modified Files:
        etk_cache.c etk_tree2.c etk_tree2.h etk_tree2_model.c 
        etk_tree2_model.h 


Log Message:
* [Cache] Made a 2nd implementation of the cached, using only linked list
* [Tree2] The models now support caching, and it has been implemented in 
the "image" model
* [Tree2] Fix the width_get() method of all the models


===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_cache.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- etk_cache.c 5 Jan 2007 15:56:04 -0000       1.7
+++ etk_cache.c 5 Jan 2007 20:07:24 -0000       1.8
@@ -8,6 +8,8 @@
  * @addtogroup Etk_Cache
  * @{
  */
+
+#if 0
  
 static char *_etk_cache_hash_key_generate(const char *filename, const char 
*key);
 static Evas_Bool _etk_cache_hash_list_free(Evas_Hash *hash, const char *key, 
void *data, void *fdata);
@@ -340,5 +342,224 @@
    evas_list_free(data);
    return 1;
 }
+
+#else
+
+/**************************
+ *
+ * Implementation
+ *
+ **************************/
+ 
+typedef struct Etk_Cache_Item
+{
+   char *filename;
+   char *key;
+   Evas_Object *object;
+} Etk_Cache_Item;
+
+/**
+ * @brief Creates a new cache system that you can use to cache image objects 
or Edje objects. You usually don't need
+ * to use that, except if you are implementing your own widget or your own 
tree model which may need to load a lot
+ * of images efficiently
+ * @param size the max number of objects the cache system could store
+ * @return Returns the new cache system
+ * @note You will need to destroy it with etk_cache_destroy() when you no 
longer need it
+ */
+Etk_Cache *etk_cache_new(int size)
+{
+   Etk_Cache *cache;
+   
+   cache = malloc(sizeof(Etk_Cache));
+   cache->cached_objects = NULL;
+   cache->objects_hash = NULL;
+   cache->size = ETK_MAX(0, size);
+   
+   return cache;
+}
+
+/**
+ * @brief Destroys the cache system: it destroys all the cached objects, and 
frees the memory used by the cache system
+ * @param cache the cache system to destroy
+ */
+void etk_cache_destroy(Etk_Cache *cache)
+{
+   if (!cache)
+      return;
+   
+   etk_cache_clear(cache);
+   free(cache);
+}
+
+/**
+ * @brief Clears the cache system: it destroys all the cached objects. The 
cache system remains still usable
+ * @param cache the cache system to clear
+ */
+void etk_cache_clear(Etk_Cache *cache)
+{
+   Etk_Cache_Item *item;
+   
+   if (!cache)
+      return;
+   
+   while (cache->cached_objects)
+   {
+      item = cache->cached_objects->data;
+      evas_object_del(item->object);
+      free(item->filename);
+      free(item->key);
+      free(item);
+      
+      cache->cached_objects = evas_list_remove_list(cache->cached_objects, 
cache->cached_objects);
+   }
+}
+
+/**
+ * @brief Sets the max number of objects that the cache system can contain. If 
the new size is smaller than current
+ * number of objects in the cache, the oldest objects that can't fit in the 
new cache size will be destroyed
+ * @param cache the cache system to resize
+ * @param size the new size (max number of objects) of the cache system
+ */
+void etk_cache_size_set(Etk_Cache *cache, int size)
+{
+}
+
+/**
+ * @brief Gets the max number of objects that can be stored by the cache system
+ * @param cache a cache system
+ * @return Returns the max number of objects that can be stored by the cache 
system
+ */
+int etk_cache_size_get(Etk_Cache *cache)
+{
+   if (!cache)
+      return 0;
+   return cache->size;
+}
+
+/**
+ * @brief Gets the current number of objects stored in the cache system
+ * @param cache a cache system
+ * @return Returns the current number of objects stored by the cache system
+ */
+int etk_cache_num_objects_get(Etk_Cache *cache)
+{
+   if (!cache)
+      return 0;
+   return evas_list_count(cache->cached_objects);
+}
+
+/**
+ * @brief Adds an Evas image object or an Edje object in the cache system. If 
the cache is already full, the oldest
+ * object will be removed. The object to cache will also be automatically 
hidden
+ * @param cache a cache system
+ * @param object the Evas image object or the Edje object to cache
+ * @param filename the filename associated to the object
+ * @param key the key associated to the object (the group for an Edje object, 
the key for an image from an Eet file,
+ * or NULL otherwise)
+ * @note Once the object is added to the cache, you should keep no reference 
to it. It may for example be deleted if
+ * there is no more space in the cache system
+ */
+void etk_cache_add(Etk_Cache *cache, Evas_Object *object, const char 
*filename, const char *key)
+{
+   Etk_Cache_Item *item;
+   
+   if (!cache || !object || cache->size <= 0 || !filename)
+   {
+      if (object)
+         evas_object_del(object);
+      return;
+   }
+   
+   evas_object_hide(object);
+   
+   /* If no more space is available, we remove the oldest object of the cache 
*/
+   if (evas_list_count(cache->cached_objects) >= cache->size)
+   {
+      item = cache->cached_objects->data;
+      
+      evas_object_del(item->object);
+      free(item->filename);
+      free(item->key);
+      free(item);
+      
+      cache->cached_objects = evas_list_remove_list(cache->cached_objects, 
cache->cached_objects);
+   }
+   
+   /* We create a new cache-item for the object and we add it to the cache */
+   item = malloc(sizeof(Etk_Cache_Item));
+   item->filename = strdup(filename);
+   item->key = key ? strdup(key) : NULL;
+   item->object = object;
+   
+   cache->cached_objects = evas_list_append(cache->cached_objects, item);
+}
+
+/**
+ * @brief Removes an object from the cache. The object won't be destroyed.
+ * @param cache a cache system
+ * @param object the object to remove from the cache system
+ */
+void etk_cache_remove(Etk_Cache *cache, Evas_Object *object)
+{
+   Etk_Cache_Item *item;
+   Evas_List *l;
+   
+   if (!cache || !object)
+      return;
+   
+   for (l = cache->cached_objects; l; l = l->next)
+   {
+      item = l->data;
+      if (item->object == object)
+      {
+         /* We have found our object. We can now remove it */
+         free(item->filename);
+         free(item->key);
+         free(item);
+         
+         cache->cached_objects = evas_list_remove_list(cache->cached_objects, 
l);
+         return;
+      }
+   }
+}
+
+/**
+ * @brief Finds an object in the cache according to its filename and its key. 
If the object is present in the cache,
+ * it will be removed from the cache and returned. Otherwise NULL is returned
+ * @param cache the cache system where to find the object
+ * @param filename the filename of the object to find
+ * @param key the key associated to the object to find (the group for an Edje 
object, the key for an image from an
+ * Eet file, or NULL otherwise)
+ * @return Returns an object corresponding to the given filename and key, or 
NULL if no such object is cached
+ */
+Evas_Object *etk_cache_find(Etk_Cache *cache, const char *filename, const char 
*key)
+{
+   Etk_Cache_Item *item;
+   Evas_List *l;
+   Evas_Object *object;
+   
+   if (!cache || !filename)
+      return NULL;
+   
+   for (l = evas_list_last(cache->cached_objects); l; l = l->prev)
+   {
+      item = l->data;
+      if (strcmp(item->filename, filename) == 0
+         && ((!item->key && !key) || (item->key && key && strcmp(item->key, 
key) == 0)))
+      {
+         object = item->object;
+         free(item->filename);
+         free(item->key);
+         free(item);
+         
+         cache->cached_objects = evas_list_remove(cache->cached_objects, item);
+         return object;
+      }
+   }
+   
+   return NULL;
+}
+
+#endif
 
 /** @} */
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_tree2.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- etk_tree2.c 5 Jan 2007 15:56:04 -0000       1.9
+++ etk_tree2.c 5 Jan 2007 20:07:24 -0000       1.10
@@ -142,9 +142,6 @@
 static Etk_Signal *_etk_tree2_signals[ETK_TREE2_NUM_SIGNALS];
 static Etk_Signal *_etk_tree2_col_signals[ETK_TREE2_COL_NUM_SIGNALS];
 
-/* TODO: better doc of row_next_get()... (with a note about deleted rows...) */
-/* TODO: a fucntion to get the first/last visible rows.. we do it all the 
time.. */
-
 
 /**************************
  *
@@ -545,6 +542,19 @@
 }
 
 /**
+ * @brief Gets the column's header widget. This can be used if you want to 
detect clicks on it for example.
+ * The header widget is an Etk_Button
+ * @param col a column
+ * @return Returns the column's header widget
+ */
+Etk_Widget *etk_tree2_col_header_get(Etk_Tree2_Col *col)
+{
+   if (!col)
+      return NULL;
+   return col->header;
+}
+
+/**
  * @brief Sets the title of the column
  * @param col a column of a tree
  * @param title the title to set
@@ -1359,6 +1369,7 @@
    return row->last_child;
 }
 
+/* TODO: better doc of row_next_get()... (with a note about deleted rows...) */
 /**
  * @brief Gets the previous row before the specified row
  * @param row a row
@@ -2031,11 +2042,13 @@
                {
                   col = tree->columns[i];
                   if (col->visible && col->expand)
-                     col->visible_width += (float)freespace / 
(float)num_expand_cols;
+                  {
+                     columns_width += freespace / num_expand_cols;
+                     col->visible_width += freespace / num_expand_cols;
+                  }
                }
             }
-            else
-               last_visible_col->visible_width += freespace;
+            last_visible_col->visible_width += (geometry.w - columns_width);
          }
          
          /* Calculate the horizontal position of the visible columns */
@@ -2076,7 +2089,7 @@
          col_x1 = ETK_MAX(0, col->xoffset);
          col_x2 = ETK_MIN(geometry.w, col->xoffset + col->visible_width);
          
-         if (col_x1 < col_x2)
+         if (col_x1 <= col_x2)
          {
             evas_object_move(col->clip, geometry.x + col_x1, geometry.y);
             evas_object_resize(col->clip, col_x2 - col_x1 + 1, geometry.h);
@@ -2129,6 +2142,31 @@
          prev_visible_rows = evas_list_append(prev_visible_rows, 
row_object->row);
    }
    
+   /* Cache the row objects */
+   for (i = 0; i < tree->num_cols; i++)
+   {
+      Etk_Tree2_Row_Object *row_object;
+      
+      col = tree->columns[i];
+      for (j = 0; j < col->num_models; j++)
+      {
+         if (col->models[j]->objects_cache)
+         {
+            for (l = tree->row_objects; l; l = l->next)
+            {
+               row_object = l->data;
+               if (row_object->row)
+               {
+                  col->models[j]->objects_cache(col->models[j], 
row_object->row->cells_data[i][j],
+                     row_object->cells[i].objects[j]);
+               }
+               else
+                  col->models[j]->objects_cache(col->models[j], NULL, 
row_object->cells[i].objects[j]);
+            }
+         }
+      }
+   }
+   
    /* Create or destroy row objects if the height of the grid has changed */
    {
       int num_visible_rows;
@@ -2172,6 +2210,7 @@
       Etk_Bool show_expanders;
       Etk_Bool objects_created;
       Evas_List *l2;
+      int expander_w, expander_h;
       int x, y;
       int total_width, w;
       int row_id;
@@ -2231,15 +2270,15 @@
                   /* Render the expander of the row */
                   if (col == first_visible_col && show_expanders)
                   {
-                     /* TODO: 18 shouldn't be hardcoded... */
+                     edje_object_size_min_get(row_object->expander, 
&expander_w, &expander_h);
                      if (row->num_children > 0)
                      {
                         evas_object_move(row_object->expander,
-                           cell_geometry.x + (depth * 18), cell_geometry.y);
-                        evas_object_resize(row_object->expander, 18, 18);
+                           cell_geometry.x + (depth * expander_w), 
cell_geometry.y);
+                        evas_object_resize(row_object->expander, expander_w, 
expander_h);
                      }
-                     cell_geometry.x += ((depth + 1) * 18) + CELL_HMARGINS;
-                     cell_geometry.w -= ((depth + 1) * 18) + CELL_HMARGINS;
+                     cell_geometry.x += ((depth + 1) * expander_w) + 
CELL_HMARGINS;
+                     cell_geometry.w -= ((depth + 1) * expander_w) + 
CELL_HMARGINS;
                   }
                   
                   /* Render the sub-objects of the cell */
@@ -2257,7 +2296,8 @@
                         {
                            for (k = 0; k < MAX_OBJECTS_PER_MODEL; k++)
                            {
-                              if (row_object->cells[i].objects[j][k])
+                              if (row_object->cells[i].objects[j][k]
+                                 && 
!evas_object_smart_parent_get(row_object->cells[i].objects[j][k]))
                               {
                                  
evas_object_clip_set(row_object->cells[i].objects[j][k], col->clip);
                                  etk_widget_member_object_add(tree->grid, 
row_object->cells[i].objects[j][k]);
@@ -2312,6 +2352,7 @@
                }
             }
             
+            evas_object_lower(row_object->background);
             row_object->row = row;
          }
          else
@@ -2725,7 +2766,8 @@
    if (!tree)
       return;
    
-   /* First we dissociate the row objects from the rows that will be deleted */
+   /* First we dissociate the row objects from the rows that will be deleted,
+    * and we cache their row objects */
    for (l = tree->row_objects; l; l = l->next)
    {
       Etk_Tree2_Row_Object *row_object;
@@ -2733,6 +2775,19 @@
       row_object = l->data;
       if (row_object->row && row_object->row->delete_me)
       {
+         for (i = 0; i < tree->num_cols; i++)
+         {
+            col = tree->columns[i];
+            for (j = 0; j < col->num_models; j++)
+            {
+               if (col->models[j]->objects_cache)
+               {
+                  col->models[j]->objects_cache(col->models[j], 
row_object->row->cells_data[i][j],
+                     row_object->cells[i].objects[j]);
+               }
+            }
+         }
+         
          etk_signal_emit(_etk_tree2_signals[ETK_TREE2_ROW_HIDDEN_SIGNAL], 
ETK_OBJECT(tree), NULL, row_object->row);
          row_object->row = NULL;
       }
@@ -3040,7 +3095,8 @@
             col->models[j]->objects_create(col->models[j], 
row_object->cells[i].objects[j], evas);
             for (k = 0; k < MAX_OBJECTS_PER_MODEL; k++)
             {
-               if (row_object->cells[i].objects[j][k])
+               if (row_object->cells[i].objects[j][k]
+                  && 
!evas_object_smart_parent_get(row_object->cells[i].objects[j][k]))
                {
                   evas_object_clip_set(row_object->cells[i].objects[j][k], 
col->clip);
                   etk_widget_member_object_add(tree->grid, 
row_object->cells[i].objects[j][k]);
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_tree2.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- etk_tree2.h 5 Jan 2007 15:56:04 -0000       1.7
+++ etk_tree2.h 5 Jan 2007 20:07:24 -0000       1.8
@@ -173,6 +173,7 @@
 
 Etk_Tree2  *etk_tree2_col_tree_get(Etk_Tree2_Col *col);
 void        etk_tree2_col_model_add(Etk_Tree2_Col *col, Etk_Tree2_Model 
*model);
+Etk_Widget *etk_tree2_col_header_get(Etk_Tree2_Col *col);
 void        etk_tree2_col_title_set(Etk_Tree2_Col *col, const char *title);
 const char *etk_tree2_col_title_get(Etk_Tree2_Col *col);
 void        etk_tree2_col_width_set(Etk_Tree2_Col *col, int width);
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_tree2_model.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- etk_tree2_model.c   5 Jan 2007 15:56:04 -0000       1.5
+++ etk_tree2_model.c   5 Jan 2007 20:07:24 -0000       1.6
@@ -5,10 +5,19 @@
 #include <Evas.h>
 #include <Edje.h>
 #include "etk_tree2.h"
+#include "etk_cache.h"
 #include "etk_theme.h"
 #include "etk_signal.h"
 #include "etk_utils.h"
 
+/* Structure of the "image" model */
+typedef struct Etk_Tree2_Model_Image
+{
+   Etk_Tree2_Model model;
+   
+   Etk_Cache *cache;
+} Etk_Tree2_Model_Image;
+
 /* Data associated to the "image" model */
 typedef struct Etk_Tree2_Model_Image_Data
 {
@@ -50,9 +59,11 @@
 static Etk_Bool _double_render(Etk_Tree2_Model *model, Etk_Tree2_Row *row, 
Etk_Geometry geometry, void *cell_data, Evas_Object **cell_objects, Evas *evas);
 
 /* Image model */
+static void _image_model_free(Etk_Tree2_Model *model);
 static void _image_cell_data_free(Etk_Tree2_Model *model, void *cell_data);
 static void _image_cell_data_set(Etk_Tree2_Model *model, void *cell_data, 
va_list *args);
 static void _image_cell_data_get(Etk_Tree2_Model *model, void *cell_data, 
va_list *args);
+static void _image_objects_cache(Etk_Tree2_Model *model, void *cell_data, 
Evas_Object **cell_objects);
 static Etk_Bool _image_render(Etk_Tree2_Model *model, Etk_Tree2_Row *row, 
Etk_Geometry geometry, void *cell_data, Evas_Object **cell_objects, Evas *evas);
 static int _image_width_get(Etk_Tree2_Model *model, void *cell_data, 
Evas_Object **cell_objects);
 
@@ -156,14 +167,17 @@
 {
    Etk_Tree2_Model *model;
    
-   model = calloc(1, sizeof(Etk_Tree2_Model));
+   model = calloc(1, sizeof(Etk_Tree2_Model_Image));
    
    model->cell_data_size = sizeof(Etk_Tree2_Model_Image_Data);
+   model->model_free = _image_model_free;
    model->cell_data_free = _image_cell_data_free;
    model->cell_data_set = _image_cell_data_set;
    model->cell_data_get = _image_cell_data_get;
+   model->objects_cache = _image_objects_cache;
    model->render = _image_render;
    model->width_get = _image_width_get;
+   ((Etk_Tree2_Model_Image *)model)->cache = etk_cache_new(100);
    
    return model;
 }
@@ -258,8 +272,11 @@
       return;
    
    text = va_arg(*args, char *);
-   free(*text_data);
-   *text_data = text ? strdup(text) : NULL;
+   if (*text_data != text)
+   {
+      free(*text_data);
+      *text_data = text ? strdup(text) : NULL;
+   }
 }
 
 /* Text: cell_data_get() */
@@ -416,6 +433,16 @@
  * Image Model
  **************************/
 
+/* Image: model_free() */
+static void _image_model_free(Etk_Tree2_Model *model)
+{
+   Etk_Tree2_Model_Image *image_model;
+   
+   if (!(image_model = (Etk_Tree2_Model_Image *)model))
+      return;
+   etk_cache_destroy(image_model->cache);
+}
+
 /* Image: cell_data_free() */
 static void _image_cell_data_free(Etk_Tree2_Model *model, void *cell_data)
 {
@@ -437,17 +464,21 @@
    if (!(image_data = cell_data) || !args || !model)
       return;
    
-   free(image_data->filename);
-   free(image_data->key);
-   image_data->key = NULL;
-   image_data->filename = NULL;
-   image_data->type = ETK_TREE2_MODEL_UNKNOWN_YET;
-   
    /* Get the file and the key from the args */
    string = va_arg(*args, char *);
-   image_data->filename = string ? strdup(string) : NULL;
+   if (image_data->filename != string)
+   {
+      free(image_data->filename);
+      image_data->filename = string ? strdup(string) : NULL;
+   }
    string = va_arg(*args, char *);
-   image_data->key = string ? strdup(string) : NULL;
+   if (image_data->key != string)
+   {
+      free(image_data->key);
+      image_data->key = string ? strdup(string) : NULL;
+   }
+   
+   image_data->type = ETK_TREE2_MODEL_UNKNOWN_YET;
 }
 
 /* Image: cell_data_get() */
@@ -467,24 +498,39 @@
       *string = image_data->key;
 }
 
+/* Image: objects_cache() */
+static void _image_objects_cache(Etk_Tree2_Model *model, void *cell_data, 
Evas_Object **cell_objects)
+{
+   Etk_Tree2_Model_Image *image_model;
+   Etk_Tree2_Model_Image_Data *image_data;
+   
+   if (!(image_model = (Etk_Tree2_Model_Image *)model) || !cell_objects || 
!cell_objects[0])
+      return;
+   
+   image_data = cell_data;
+   if (image_data && (image_data->type == ETK_TREE2_MODEL_NORMAL || 
image_data->type == ETK_TREE2_MODEL_EDJE))
+      etk_cache_add(image_model->cache, cell_objects[0], image_data->filename, 
image_data->key);
+   else
+      evas_object_del(cell_objects[0]);
+   
+   cell_objects[0] = NULL;
+}
+
 /* Image: render() */
 static Etk_Bool _image_render(Etk_Tree2_Model *model, Etk_Tree2_Row *row, 
Etk_Geometry geometry, void *cell_data, Evas_Object **cell_objects, Evas *evas)
 {
+   Etk_Tree2_Model_Image *image_model;
    Etk_Tree2_Model_Image_Data *image_data;
    int image_width, image_height;
    Etk_Geometry image_geometry;
    Etk_Bool object_created = ETK_FALSE;
    char *ext;
    
-   if (!(image_data = cell_data) || !model || !cell_objects || !evas)
+   if (!(image_model = (Etk_Tree2_Model_Image *)model) || !(image_data = 
cell_data) || !cell_objects || !evas)
       return ETK_FALSE;
 
    if (!image_data->filename || image_data->type == ETK_TREE2_MODEL_NOT_FOUND)
-   {
-      if (cell_objects[0])
-         evas_object_hide(cell_objects[0]);
       return ETK_FALSE;
-   }
    
    /* If we don't know yet what the image's type is, we "guess" it */
    if (image_data->type == ETK_TREE2_MODEL_UNKNOWN_YET)
@@ -497,65 +543,50 @@
          image_data->type = ETK_TREE2_MODEL_EDJE;
    }
    
-   /* We load the image */
-   if (image_data->type == ETK_TREE2_MODEL_NORMAL)
+   /* If the object is not already in the cache, we load it */
+   if (!(cell_objects[0] = etk_cache_find(image_model->cache, 
image_data->filename, image_data->key)))
    {
-      /* We make sure the object is an Evas_Object_Image:
-       * An Edje-object is a smart object, so if 
"evas_object_smart_data_get(cell_objects[0])"
-       * is not NULL, it means the object is an Edje object */
-      if (cell_objects[0] && evas_object_smart_data_get(cell_objects[0]))
-      {
-         evas_object_del(cell_objects[0]);
-         cell_objects[0] = NULL;
-      }
-      if (!cell_objects[0])
+      if (image_data->type == ETK_TREE2_MODEL_NORMAL)
       {
          cell_objects[0] = evas_object_image_add(evas);
          evas_object_pass_events_set(cell_objects[0], 1);
-         object_created = ETK_TRUE;
+         
+         evas_object_image_file_set(cell_objects[0], image_data->filename, 
image_data->key);
+         if (!evas_object_image_load_error_get(cell_objects[0]))
+            object_created = ETK_TRUE;
+         else
+            image_data->type = ETK_TREE2_MODEL_NOT_FOUND;
       }
-      
-      /* Load the image file */
-      evas_object_image_file_set(cell_objects[0], image_data->filename, 
image_data->key);
-      if (!evas_object_image_load_error_get(cell_objects[0]))
-         evas_object_image_size_get(cell_objects[0], &image_width, 
&image_height);
+      /* If it's not a normal image file, then it's an Edje file... */
       else
-         image_data->type = ETK_TREE2_MODEL_NOT_FOUND;
-   }
-   /* If it's not a normal image file, then it's an Edje file... */
-   else
-   {
-      /* We make sure the object is an Edje_Object:
-       * An Edje-object is a smart object, so if 
"evas_object_smart_data_get(cell_objects[0])"
-       * is not NULL, it means the object is an Edje object */
-      if (cell_objects[0] && !evas_object_smart_data_get(cell_objects[0]))
-      {
-         evas_object_del(cell_objects[0]);
-         cell_objects[0] = NULL;
-      }
-      if (!cell_objects[0])
       {
          cell_objects[0] = edje_object_add(evas);
          evas_object_pass_events_set(cell_objects[0], 1);
-         object_created = ETK_TRUE;
+         
+         if (edje_object_file_set(cell_objects[0], image_data->filename, 
image_data->key))
+            object_created = ETK_TRUE;
+         else
+            image_data->type = ETK_TREE2_MODEL_NOT_FOUND;
       }
-      
-      /* Load the edje group from the file */
-      if (edje_object_file_set(cell_objects[0], image_data->filename, 
image_data->key))
-         edje_object_size_min_get(cell_objects[0], &image_width, 
&image_height);
-      else
-         image_data->type = ETK_TREE2_MODEL_NOT_FOUND;
    }
    
-   /* If the loading failed, we hide the object and return */
+   /* If loading the image has failed, we destroy the object and return */
    if (image_data->type == ETK_TREE2_MODEL_NOT_FOUND)
    {
       if (cell_objects[0])
-         evas_object_hide(cell_objects[0]);
-      return object_created;
+      {
+         evas_object_del(cell_objects[0]);
+         cell_objects[0] = NULL;
+      }
+      return ETK_FALSE;
    }
    
    /* The image is correctly loaded, we can now render it */
+   if (image_data->type == ETK_TREE2_MODEL_NORMAL)
+      evas_object_image_size_get(cell_objects[0], &image_width, &image_height);
+   else
+      edje_object_size_min_get(cell_objects[0], &image_width, &image_height);
+   
    if (image_width == 0 || image_height == 0)
    {
       image_geometry.w = geometry.h;
@@ -590,17 +621,12 @@
 /* Image: width_get() */
 static int _image_width_get(Etk_Tree2_Model *model, void *cell_data, 
Evas_Object **cell_objects)
 {
-   Etk_Tree2_Model_Image_Data *image_data;
    int w = 0;
    
-   if (!(image_data = cell_data) || !cell_objects || !cell_objects[0])
+   if (!cell_objects || !cell_objects[0])
       return 0;
    
-   if (image_data->type == ETK_TREE2_MODEL_NORMAL)
-      evas_object_image_size_get(cell_objects[0], &w, NULL);
-   else if (image_data->type == ETK_TREE2_MODEL_EDJE)
-      edje_object_size_min_get(cell_objects[0], &w, NULL);
-   
+   evas_object_geometry_get(cell_objects[0], NULL, NULL, &w, NULL);
    return w;
 }
 
@@ -673,10 +699,10 @@
 {
    int w;
    
-   if (!cell_objects[0])
+   if (!cell_objects || !cell_objects[0])
       return 0;
    
-   edje_object_size_min_get(cell_objects[0], &w, NULL);
+   evas_object_geometry_get(cell_objects[0], NULL, NULL, &w, NULL);
    return w;
 }
 
@@ -730,12 +756,13 @@
    if (!(pbar_data = cell_data) || !args)
       return;
    
-   free(pbar_data->text);
-   pbar_data->text = NULL;
-   
    pbar_data->fraction = va_arg(*args, double);
-   if ((text = va_arg(*args, char *)))
-      pbar_data->text = strdup(text);
+   text = va_arg(*args, char *);
+   if (pbar_data->text != text)
+   {
+      free(pbar_data->text);
+      pbar_data->text = text ? strdup(text) : NULL;
+   }
 }
 
 /* Progressbar: cell_data_get() */
@@ -754,7 +781,7 @@
    
    string = va_arg(*args, char **);
    if (string)
-      *string = pbar_data->text;         
+      *string = pbar_data->text;
 }
 
 /* Progressbar: objects_create() */
@@ -792,12 +819,12 @@
 
 /* Progressbar: width_get() */
 static int _progress_bar_width_get(Etk_Tree2_Model *model, void *cell_data, 
Evas_Object **cell_objects)
-{  
+{
    int w;
    
    if (!cell_objects || !cell_objects[0])
       return 0;
    
-   edje_object_size_min_get(cell_objects[0], &w, NULL);
+   evas_object_geometry_get(cell_objects[0], NULL, NULL, &w, NULL);
    return w;
 }
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_tree2_model.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- etk_tree2_model.h   5 Jan 2007 15:56:04 -0000       1.4
+++ etk_tree2_model.h   5 Jan 2007 20:07:24 -0000       1.5
@@ -28,8 +28,9 @@
    void (*cell_data_set)(Etk_Tree2_Model *model, void *cell_data, va_list 
*args);
    void (*cell_data_get)(Etk_Tree2_Model *model, void *cell_data, va_list 
*args);
    void (*objects_create)(Etk_Tree2_Model *model, Evas_Object **cell_objects, 
Evas *evas);
+   void (*objects_cache)(Etk_Tree2_Model *model, void *cell_data, Evas_Object 
**cell_objects);
    Etk_Bool (*render)(Etk_Tree2_Model *model, Etk_Tree2_Row *row, Etk_Geometry 
geometry, void *cell_data, Evas_Object **cell_objects, Evas *evas);
-   int  (*width_get)(Etk_Tree2_Model *model, void *cell_data, Evas_Object 
**cell_objects);
+   int (*width_get)(Etk_Tree2_Model *model, void *cell_data, Evas_Object 
**cell_objects);
 };
 
 Etk_Tree2_Model *etk_tree2_model_text_new(void);
@@ -39,9 +40,10 @@
 Etk_Tree2_Model *etk_tree2_model_checkbox_new(void);
 Etk_Tree2_Model *etk_tree2_model_progress_bar_new(void);
 
+void etk_tree2_model_free(Etk_Tree2_Model *model);
+
 /* TODO: image_width_set() */
 
-void etk_tree2_model_free(Etk_Tree2_Model *model);
 
 /** @} */
 



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to