Added Ecore::Evas::EcoreEvas#iconified? and #iconified=.
[ruby-ecore.git] / src / ecore_evas / rb_ecore_evas.c
index 07ec2b1bba809f204c4c2d723c775a60b938acea..e51a4f42b79f5a7cce78ce4847aec0ba8249b369 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Id: rb_ecore_evas.c 65 2004-08-12 19:37:37Z tilman $
+ * $Id: rb_ecore_evas.c 385 2006-08-20 15:21:14Z tilman $
  *
- * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include "rb_ecore_evas_main.h"
 #include "rb_ecore_evas.h"
 
+#define RUBY_ECORE_EVAS_KEY "__RB_ECORE_EVAS_KEY"
+
 #define CALLBACK_DEFINE_HANDLER(name) \
        static void on_##name (Ecore_Evas *real) \
        { \
-               VALUE self = rb_hash_aref (objects, INT2NUM ((long) real)); \
-               VALUE cb; \
+               VALUE self, cb; \
 \
+               self = (VALUE) ecore_evas_data_get (real, \
+                                                   RUBY_ECORE_EVAS_KEY); \
                GET_OBJ (self, RbEcoreEvas, ee); \
 \
-               cb = rb_hash_aref (ee->callbacks, rb_str_new2 (#name)); \
+               cb = rb_hash_aref (ee->callbacks, \
+                                  LONG2NUM ((long) ecore_evas_callback_##name##_set)); \
                rb_funcall (cb, rb_intern ("call"), 0); \
        } \
 
                if (!rb_block_given_p ()) \
                        return Qnil; \
 \
-               rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
+               if (NIL_P (ee->callbacks)) \
+                       ee->callbacks = rb_hash_new (); \
+\
+               rb_hash_aset (ee->callbacks, \
+                             LONG2NUM ((long) ecore_evas_callback_##name##_set), \
                              rb_block_proc ()); \
 \
                ecore_evas_callback_##name##_set (ee->real, on_##name); \
@@ -56,7 +64,6 @@
                return Qnil;
 
 VALUE cEcoreEvas;
-static VALUE objects;
 
 /* called by the child classes */
 void c_ecore_evas_mark (RbEcoreEvas *ee)
@@ -64,7 +71,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)
@@ -85,9 +93,9 @@ 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;
 
-       rb_hash_aset (objects, INT2NUM ((long) ee->real), self);
+       ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
 
        return Qnil;
 }
@@ -515,6 +523,69 @@ 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;
+}
+
+/*
+ * call-seq:
+ *  ee.iconified? => true or false
+ *
+ * Returns true if <i>ee</i> is iconified, else returns false.
+ */
+static VALUE c_iconified_get (VALUE self)
+{
+       GET_OBJ (self, RbEcoreEvas, ee);
+
+       return ecore_evas_iconified_get (ee->real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ *  ee.iconified(true or false)
+ *
+ * Sets whether <i>ee</i> is iconified or not.
+ */
+static VALUE c_iconified_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, RbEcoreEvas, ee);
+
+       CHECK_BOOL (val);
+
+       ecore_evas_iconified_set (ee->real, val == Qtrue);
+
+       return Qnil;
+}
+
+
 /* FIXME: this is unsafe!
  * :nodoc:
  */
@@ -526,7 +597,6 @@ static VALUE c_delete (VALUE self)
        rb_gc_start ();
 
        ecore_evas_free (ee->real);
-       rb_hash_aset (objects, INT2NUM ((long) ee->real), Qnil);
        ee->real = NULL;
 
        return Qnil;
@@ -681,8 +751,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);
@@ -711,6 +779,10 @@ 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, "iconified?", c_iconified_get, 0);
+       rb_define_method (cEcoreEvas, "iconified=", c_iconified_set, 1);
 
        rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
        rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);
@@ -724,7 +796,4 @@ void Init_EcoreEvas (void)
        rb_define_method (cEcoreEvas, "on_mouse_out", c_on_mouse_out, 0);
        rb_define_method (cEcoreEvas, "on_pre_render", c_on_pre_render, 0);
        rb_define_method (cEcoreEvas, "on_post_render", c_on_post_render, 0);
-
-       objects = rb_hash_new ();
-       rb_global_variable (&objects);
 }