Store our own array with container items.
authorTilman Sauerbeck <tilman@code-monkey.de>
Tue, 15 Mar 2005 18:05:42 +0000 (18:05 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Tue, 15 Mar 2005 18:05:42 +0000 (18:05 +0000)
src/esmart_container/rb_esmart_container.c

index 453c103ff96dc788ad9f512e305cf3bb137bb7de..3269c37091bbc8105b5013027a3feca5af5d3211 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * $Id: rb_esmart_container.c 218 2005-02-10 14:53:47Z tilman $
+ * $Id: rb_esmart_container.c 286 2005-03-15 18:05:42Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
 
 #include "../rb_esmart.h"
 
 
 #include "../rb_esmart.h"
 
-static void c_free (RbEvasObject *e)
+typedef struct {
+       RbEvasObject real;
+       VALUE elements;
+} RbContainer;
+
+static void c_mark (RbContainer *e)
+{
+       c_evas_object_mark (&e->real);
+
+       rb_gc_mark (e->elements);
+}
+
+static void c_free (RbContainer *e)
 {
 {
-       c_evas_object_free (e, true);
+       c_evas_object_free (&e->real, false);
+
+       free (e);
 }
 
 static VALUE c_new (VALUE klass, VALUE evas)
 {
        VALUE self, argv[1];
 }
 
 static VALUE c_new (VALUE klass, VALUE evas)
 {
        VALUE self, argv[1];
-       RbEvasObject *cont;
+       RbContainer *cont;
 
        CHECK_CLASS (evas, cEvas);
        GET_OBJ (evas, RbEvas, e);
 
 
        CHECK_CLASS (evas, cEvas);
        GET_OBJ (evas, RbEvas, e);
 
-       self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
+       self = Data_Make_Struct (klass, RbContainer, c_mark,
                                 c_free, cont);
                                 c_free, cont);
-       cont->real = esmart_container_new (e->real);
+       cont->real.real = esmart_container_new (e->real);
 
        argv[0] = evas;
        rb_obj_call_init (self, 1, argv);
 
 
        argv[0] = evas;
        rb_obj_call_init (self, 1, argv);
 
+       rb_iv_set (self, "@elements", rb_ary_new ());
+
        return self;
 }
 
 static VALUE c_append_element (VALUE self, VALUE element)
 {
        return self;
 }
 
 static VALUE c_append_element (VALUE self, VALUE element)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
-       esmart_container_element_append (e->real, o->real);
+       esmart_container_element_append (e->real.real, o->real);
+       rb_ary_push (e->elements, element);
 
        return Qnil;
 }
 
 static VALUE c_prepend_element (VALUE self, VALUE element)
 {
 
        return Qnil;
 }
 
 static VALUE c_prepend_element (VALUE self, VALUE element)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
-       esmart_container_element_prepend (e->real, o->real);
+       esmart_container_element_prepend (e->real.real, o->real);
+       rb_ary_unshift (e->elements, element);
 
        return Qnil;
 }
 
 static VALUE c_remove_element (VALUE self, VALUE element)
 {
 
        return Qnil;
 }
 
 static VALUE c_remove_element (VALUE self, VALUE element)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
 
        CHECK_CLASS (element, cEvasObject);
        GET_OBJ (element, RbEvasObject, o);
 
-       esmart_container_element_remove (e->real, o->real);
+       esmart_container_element_remove (e->real.real, o->real);
+       rb_ary_delete (e->elements, element);
 
        return Qnil;
 }
 
        return Qnil;
 }
@@ -88,15 +107,11 @@ static VALUE c_remove_element (VALUE self, VALUE element)
 static VALUE c_elements_get (VALUE self)
 {
        VALUE ary;
 static VALUE c_elements_get (VALUE self)
 {
        VALUE ary;
-       Evas_List *list, *l;
-
-       GET_OBJ (self, RbEvasObject, e);
 
 
-       list = esmart_container_elements_get (e->real);
-       ary = rb_ary_new ();
+       GET_OBJ (self, RbContainer, e);
 
 
-       for (l = list; l; l = l->next)
-               rb_ary_push (ary, TO_EVAS_OBJECT (l->data));
+       ary = rb_ary_dup (e->elements);
+       OBJ_FREEZE (ary);
 
        return ary;
 }
 
        return ary;
 }
@@ -105,9 +120,9 @@ static VALUE c_elements_length_get (VALUE self)
 {
        double l;
 
 {
        double l;
 
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       l = esmart_container_elements_length_get (e->real);
+       l = esmart_container_elements_length_get (e->real.real);
 
        return rb_float_new (l);
 }
 
        return rb_float_new (l);
 }
@@ -116,81 +131,81 @@ static VALUE c_elements_orig_length_get (VALUE self)
 {
        double l;
 
 {
        double l;
 
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       l = esmart_container_elements_orig_length_get (e->real);
+       l = esmart_container_elements_orig_length_get (e->real.real);
 
        return rb_float_new (l);
 }
 
 static VALUE c_direction_get (VALUE self)
 {
 
        return rb_float_new (l);
 }
 
 static VALUE c_direction_get (VALUE self)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       return INT2FIX (esmart_container_direction_get (e->real));
+       return INT2FIX (esmart_container_direction_get (e->real.real));
 }
 
 static VALUE c_direction_set (VALUE self, VALUE val)
 {
 }
 
 static VALUE c_direction_set (VALUE self, VALUE val)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (val, T_FIXNUM);
 
 
        Check_Type (val, T_FIXNUM);
 
-       esmart_container_direction_set (e->real, FIX2INT (val));
+       esmart_container_direction_set (e->real.real, FIX2INT (val));
 
        return Qnil;
 }
 
 static VALUE c_spacing_get (VALUE self)
 {
 
        return Qnil;
 }
 
 static VALUE c_spacing_get (VALUE self)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       return INT2FIX (esmart_container_spacing_get (e->real));
+       return INT2FIX (esmart_container_spacing_get (e->real.real));
 }
 
 static VALUE c_spacing_set (VALUE self, VALUE val)
 {
 }
 
 static VALUE c_spacing_set (VALUE self, VALUE val)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (val, T_FIXNUM);
 
 
        Check_Type (val, T_FIXNUM);
 
-       esmart_container_spacing_set (e->real, FIX2INT (val));
+       esmart_container_spacing_set (e->real.real, FIX2INT (val));
 
        return Qnil;
 }
 
 static VALUE c_fill_policy_get (VALUE self)
 {
 
        return Qnil;
 }
 
 static VALUE c_fill_policy_get (VALUE self)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       return INT2FIX (esmart_container_fill_policy_get (e->real));
+       return INT2FIX (esmart_container_fill_policy_get (e->real.real));
 }
 
 static VALUE c_fill_policy_set (VALUE self, VALUE val)
 {
 }
 
 static VALUE c_fill_policy_set (VALUE self, VALUE val)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (val, T_FIXNUM);
 
 
        Check_Type (val, T_FIXNUM);
 
-       esmart_container_fill_policy_set (e->real, FIX2INT (val));
+       esmart_container_fill_policy_set (e->real.real, FIX2INT (val));
 
        return Qnil;
 }
 
 static VALUE c_alignment_get (VALUE self)
 {
 
        return Qnil;
 }
 
 static VALUE c_alignment_get (VALUE self)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       return INT2FIX (esmart_container_alignment_get (e->real));
+       return INT2FIX (esmart_container_alignment_get (e->real.real));
 }
 
 static VALUE c_alignment_set (VALUE self, VALUE val)
 {
 }
 
 static VALUE c_alignment_set (VALUE self, VALUE val)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (val, T_FIXNUM);
 
 
        Check_Type (val, T_FIXNUM);
 
-       esmart_container_alignment_set (e->real, FIX2INT (val));
+       esmart_container_alignment_set (e->real.real, FIX2INT (val));
 
        return Qnil;
 }
 
        return Qnil;
 }
@@ -200,9 +215,9 @@ static VALUE c_get_padding (VALUE self)
 {
        double l = 0, r = 0, t = 0, b = 0;
 
 {
        double l = 0, r = 0, t = 0, b = 0;
 
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
 
-       esmart_container_padding_get (e->real, &l, &r, &t, &b);
+       esmart_container_padding_get (e->real.real, &l, &r, &t, &b);
 
        return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
                            rb_float_new (t), rb_float_new (b));
 
        return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
                            rb_float_new (t), rb_float_new (b));
@@ -211,14 +226,14 @@ static VALUE c_get_padding (VALUE self)
 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
                             VALUE t, VALUE b)
 {
 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
                             VALUE t, VALUE b)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (l, T_FLOAT);
        Check_Type (r, T_FLOAT);
        Check_Type (t, T_FLOAT);
        Check_Type (b, T_FLOAT);
 
 
        Check_Type (l, T_FLOAT);
        Check_Type (r, T_FLOAT);
        Check_Type (t, T_FLOAT);
        Check_Type (b, T_FLOAT);
 
-       esmart_container_padding_set (e->real, NUM2DBL (l), NUM2DBL (r),
+       esmart_container_padding_set (e->real.real, NUM2DBL (l), NUM2DBL (r),
                                      NUM2DBL (t), NUM2DBL (b));
 
        return Qnil;
                                      NUM2DBL (t), NUM2DBL (b));
 
        return Qnil;
@@ -226,11 +241,11 @@ static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
 
 static VALUE c_scroll (VALUE self, VALUE val)
 {
 
 static VALUE c_scroll (VALUE self, VALUE val)
 {
-       GET_OBJ (self, RbEvasObject, e);
+       GET_OBJ (self, RbContainer, e);
 
        Check_Type (val, T_FIXNUM);
 
 
        Check_Type (val, T_FIXNUM);
 
-       esmart_container_scroll (e->real, FIX2INT (val));
+       esmart_container_scroll (e->real.real, FIX2INT (val));
 
        return Qnil;
 }
 
        return Qnil;
 }