Removed RCS-style IDs.
[ruby-edje.git] / src / rb_edje.c
index 6a9b7f7ca48b77d92fe81a16d6bf17acb663ca9c..a899ea466d7379086fe6e8d161bea437a12db4e2 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: rb_edje.c 331 2005-04-28 18:17:21Z tilman $
- *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
  * This library is free software; you can redistribute it and/or
@@ -55,31 +53,49 @@ static void c_free (RbEdje *e)
        edje_shutdown ();
 }
 
+static VALUE c_alloc (VALUE klass)
+{
+       RbEdje *e = NULL;
+
+       edje_init ();
+
+       return Data_Make_Struct (klass, RbEdje, c_mark, c_free, e);
+}
+
 /*
  * call-seq:
  *  Edje::Edje.new(evas) => edje
  *
  * Creates an Edje::Edje object.
  */
-static VALUE c_new (VALUE klass, VALUE evas)
+static VALUE c_init (VALUE self, VALUE evas)
 {
-       VALUE self, argv[1];
-       RbEdje *edje = NULL;
-
        CHECK_CLASS (evas, cEvas);
        GET_OBJ (evas, RbEvas, e);
+       GET_OBJ (self, RbEdje, edje);
 
-       edje_init ();
-
-       self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
+       /* c_new_from_pointer() might already have initialized the pointer */
+       if (!edje->real.real)
+               edje->real.real = edje_object_add (e->real);
 
-       edje->real.real = edje_object_add (e->real);
        edje->parts = Qnil;
        edje->callbacks = Qnil;
        edje->on_text_changed_cb = Qnil;
 
-       argv[0] = evas;
-       rb_obj_call_init (self, 1, argv);
+       rb_call_super (1, &evas);
+
+       return self;
+}
+
+static VALUE c_new_from_pointer (VALUE klass, VALUE evas, VALUE ptr)
+{
+       VALUE self = rb_obj_alloc (klass);
+
+       GET_OBJ (self, RbEdje, edje);
+
+       edje->real.real = (Evas_Object *) ptr;
+
+       rb_obj_call_init (self, 1, &evas);
 
        return self;
 }
@@ -308,7 +324,7 @@ static void on_signal (void *data, Evas_Object *o,
 static VALUE c_on_signal (int argc, VALUE *argv, VALUE self)
 {
        VALUE signal, src, cb;
-       char *ssrc = "*";
+       const char *ssrc = "*";
 
        GET_OBJ (self, RbEdje, e);
 
@@ -515,11 +531,12 @@ static VALUE c_send_message (VALUE self, VALUE msg)
 
        CHECK_CLASS (msg, cMsg);
 
-       id = NUM2INT (rb_iv_get (msg, "@id"));
+       id = FIX2INT (rb_iv_get (msg, "@id"));
        v = rb_iv_get (msg, "@value");
 
        type = get_msg_type (v);
-       ary = rb_check_array_type (v);
+       if (!NIL_P (ary = rb_check_array_type (v)))
+               len = RARRAY (ary)->len;
 
        switch (type) {
                case EDJE_MESSAGE_NONE:
@@ -640,11 +657,16 @@ static VALUE c_send_message (VALUE self, VALUE msg)
 
 static VALUE c_msg_init (int argc, VALUE *argv, VALUE self)
 {
-       VALUE val;
+       VALUE id, val;
+
+       if (argc == 2)
+               rb_scan_args (argc, argv, "11", &id, &val);
+       else
+               rb_scan_args (argc, argv, "1*", &id, &val);
 
-       rb_scan_args (argc, argv, "01", &val);
+       Check_Type (id, T_FIXNUM);
 
-       rb_iv_set (self, "@id", UINT2NUM (0));
+       rb_iv_set (self, "@id", id);
        rb_iv_set (self, "@value", val);
 
        return self;
@@ -654,7 +676,10 @@ void Init_Edje (void)
 {
        cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
 
-       rb_define_singleton_method (cEdje, "new", c_new, 1);
+       rb_define_alloc_func (cEdje, c_alloc);
+       rb_define_singleton_method (cEdje, "new_from_pointer",
+                                   c_new_from_pointer, 2);
+       rb_define_method (cEdje, "initialize", c_init, 1);
        rb_define_method (cEdje, "freeze", c_freeze, 0);
        rb_define_method (cEdje, "thaw", c_thaw, 0);
        rb_define_method (cEdje, "load", c_load, 2);