Made EcoreEvas.new public for now.
[ruby-ecore.git] / src / ecore_evas / rb_ecore_evas.c
index 9b2ad29a2bd77a657f19c8c1a6b75dff4aaac389..1e08533fca5997fc91968cd94f2bee81a0a4f42f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_evas.c 110 2004-09-02 17:06:54Z tilman $
+ * $Id: rb_ecore_evas.c 353 2006-02-10 17:00:24Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -51,6 +51,9 @@
 \
                if (!rb_block_given_p ()) \
                        return Qnil; \
+\
+               if (NIL_P (ee->callbacks)) \
+                       ee->callbacks = rb_hash_new (); \
 \
                rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
                              rb_block_proc ()); \
@@ -67,7 +70,8 @@ void c_ecore_evas_mark (RbEcoreEvas *ee)
        if (!NIL_P (ee->evas))
                rb_gc_mark (ee->evas);
 
-       rb_gc_mark (ee->callbacks);
+       if (!NIL_P (ee->callbacks))
+               rb_gc_mark (ee->callbacks);
 }
 
 void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
@@ -88,7 +92,7 @@ static VALUE c_init (int argc, VALUE *argv, VALUE self)
        GET_OBJ (self, RbEcoreEvas, ee);
 
        ee->evas = Qnil;
-       ee->callbacks = rb_hash_new ();
+       ee->callbacks = Qnil;
 
        ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
 
@@ -518,6 +522,38 @@ static VALUE c_rotation_set (VALUE self, VALUE val)
        return Qnil;
 }
 
+static VALUE c_name_class_get (VALUE self)
+{
+       const char *name = NULL, *klass = NULL;
+
+       GET_OBJ (self, RbEcoreEvas, ee);
+
+       ecore_evas_name_class_get (ee->real, &name, &klass);
+
+       return rb_ary_new3 (2, name ? rb_str_new2 (name) : Qnil,
+                           klass ? rb_str_new2 (klass) : Qnil);
+}
+
+static VALUE c_name_class_set (VALUE self, VALUE ary)
+{
+       VALUE s1, s2;
+
+       GET_OBJ (self, RbEcoreEvas, ee);
+
+       Check_Type (ary, T_ARRAY);
+
+       s1 = rb_ary_shift (ary);
+       s2 = rb_ary_shift (ary);
+
+       StringValue (s1);
+       StringValue (s2);
+
+       ecore_evas_name_class_set (ee->real, StringValuePtr (s1),
+                                  StringValuePtr (s2));
+
+       return Qnil;
+}
+
 /* FIXME: this is unsafe!
  * :nodoc:
  */
@@ -683,8 +719,6 @@ void Init_EcoreEvas (void)
 {
        cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
 
-       rb_define_private_method (rb_singleton_class (cEcoreEvas),
-                                 "new", NULL, 0);
        rb_define_method (cEcoreEvas, "initialize", c_init, -1);
        rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
        rb_define_method (cEcoreEvas, "delete", c_delete, 0);
@@ -713,6 +747,8 @@ void Init_EcoreEvas (void)
        rb_define_method (cEcoreEvas, "sticky=", c_sticky_set, 1);
        rb_define_method (cEcoreEvas, "rotation", c_rotation_get, 0);
        rb_define_method (cEcoreEvas, "rotation=", c_rotation_set, 1);
+       rb_define_method (cEcoreEvas, "name_class", c_name_class_get, 0);
+       rb_define_method (cEcoreEvas, "name_class=", c_name_class_set, 1);
 
        rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
        rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);