Don't use global variables for the Ruby classes.
[ruby-ecore.git] / src / ecore_evas / rb_ecore_evas.c
index b81cdf46472b1a3164c6ce63e634937704bcfbc4..18ac0e02d00992bf0d81d9a89171718f6cb71590 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_evas.c 12 2004-06-19 20:15:40Z tilman $
+ * $Id: rb_ecore_evas.c 25 2004-06-26 23:07:01Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
                return Qnil; \
        }
 
+#define CHECK_BOOL(val) \
+       if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
+               rb_raise (rb_eTypeError, \
+                         "wrong argument type %s (expected true or false)", \
+                         rb_obj_classname ((val))); \
+               return Qnil; \
+       }
+
 /* called by the child classes */
 void c_ecore_evas_free (Ecore_Evas **ee)
 {
@@ -45,17 +53,17 @@ void c_ecore_evas_free (Ecore_Evas **ee)
        free (ee);
 }
 
-#if 0
-static VALUE c_init (int argc, VALUE argv, VALUE self)
+static VALUE c_inspect (VALUE self)
 {
-       rb_iv_set (self, "@title", rb_str_new2 (""));
-       rb_iv_set (self, "@name", rb_str_new2 (""));
-       rb_iv_set (self, "@class", rb_str_new2 (""));
-       rb_iv_set (self, "@name", rb_str_new2 (""));
+       char buf[128];
+
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       snprintf (buf, sizeof (buf), "#<EcoreEvas:%p ptr=%p>",
+                 (void *) self, *ee);
 
-       return self;
+       return rb_str_new2 (buf);
 }
-#endif
 
 static VALUE c_show (VALUE self)
 {
@@ -75,13 +83,49 @@ static VALUE c_hide (VALUE self)
        return Qnil;
 }
 
-static VALUE c_is_visible (VALUE self)
+static VALUE c_visible_get (VALUE self)
 {
        GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
 
        return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
 }
 
+static VALUE c_raise (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       ecore_evas_raise (*ee);
+
+       return Qnil;
+}
+
+static VALUE c_lower (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       ecore_evas_lower (*ee);
+
+       return Qnil;
+}
+
+static VALUE c_layer_get (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       return INT2FIX (ecore_evas_layer_get (*ee));
+}
+
+static VALUE c_layer_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       Check_Type (val, T_FIXNUM);
+
+       ecore_evas_layer_set (*ee, FIX2INT (val));
+
+       return Qnil;
+}
+
 static VALUE c_evas (VALUE self)
 {
        GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
@@ -89,6 +133,64 @@ static VALUE c_evas (VALUE self)
        return TO_EVAS (self, ecore_evas_get (*ee));
 }
 
+static VALUE c_get_size_min (VALUE self)
+{
+       int w = 0, h = 0;
+
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       ecore_evas_size_min_get (*ee, &w, &h);
+
+       return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       Check_Type (w, T_FIXNUM);
+       Check_Type (h, T_FIXNUM);
+
+       ecore_evas_size_min_set (*ee, FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
+static VALUE c_get_size_max (VALUE self)
+{
+       int w = 0, h = 0;
+
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       ecore_evas_size_max_get (*ee, &w, &h);
+
+       return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       Check_Type (w, T_FIXNUM);
+       Check_Type (h, T_FIXNUM);
+
+       ecore_evas_size_max_set (*ee, FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
+static VALUE c_move (VALUE self, VALUE x, VALUE y)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       Check_Type (x, T_FIXNUM);
+       Check_Type (y, T_FIXNUM);
+
+       ecore_evas_move (*ee, FIX2INT (x), FIX2INT (y));
+
+       return Qnil;
+}
+
 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
 {
        GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
@@ -119,7 +221,7 @@ static VALUE c_title_set (VALUE self, VALUE val)
 
        Check_Type (val, T_STRING);
 
-       ecore_evas_title_set (*ee, STR2CSTR (val));
+       ecore_evas_title_set (*ee, StringValuePtr (val));
 
        return Qnil;
 }
@@ -135,19 +237,67 @@ static VALUE c_borderless_set (VALUE self, VALUE val)
 {
        GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
 
-       /* make sure we're passed a boolean */
-       if (TYPE (val) != T_TRUE && TYPE (val) != T_FALSE) {
-               rb_raise (rb_eTypeError,
-                         "wrong argument type %s (expected true or false)",
-                         rb_obj_classname (val));
-               return Qnil;
-       }
+       CHECK_BOOL (val);
 
        ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0);
 
        return Qnil;
 }
 
+static VALUE c_shaped_get (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       return ecore_evas_shaped_get (*ee) ? Qtrue : Qfalse;
+}
+
+static VALUE c_shaped_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       CHECK_BOOL (val);
+
+       ecore_evas_shaped_set (*ee, val == Qtrue ? 1 : 0);
+
+       return Qnil;
+}
+
+static VALUE c_sticky_get (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       return ecore_evas_sticky_get (*ee) ? Qtrue : Qfalse;
+}
+
+static VALUE c_sticky_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       CHECK_BOOL (val);
+
+       ecore_evas_sticky_set (*ee, val == Qtrue ? 1 : 0);
+
+       return Qnil;
+}
+
+static VALUE c_rotation_get (VALUE self)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       return INT2FIX (ecore_evas_rotation_get (*ee));
+}
+
+static VALUE c_rotation_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
+
+       Check_Type (val, T_FIXNUM);
+
+       ecore_evas_rotation_set (*ee, FIX2INT (val));
+
+       return Qnil;
+}
+
 static VALUE c_delete (VALUE self)
 {
        GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
@@ -167,16 +317,30 @@ void Init_EcoreEvas (void)
 
        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);
        rb_define_method (cEcoreEvas, "show", c_show, 0);
        rb_define_method (cEcoreEvas, "hide", c_hide, 0);
-       rb_define_method (cEcoreEvas, "visible?", c_is_visible, 0);
+       rb_define_method (cEcoreEvas, "visible?", c_visible_get, 0);
+       rb_define_method (cEcoreEvas, "raise", c_raise, 0);
+       rb_define_method (cEcoreEvas, "lower", c_lower, 0);
+       rb_define_method (cEcoreEvas, "layer", c_layer_get, 0);
+       rb_define_method (cEcoreEvas, "layer=", c_layer_set, 1);
        rb_define_method (cEcoreEvas, "evas", c_evas, 0);
+       rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
+       rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
+       rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
+       rb_define_method (cEcoreEvas, "set_size_max", c_set_size_max, 2);
+       rb_define_method (cEcoreEvas, "move", c_move, 2);
        rb_define_method (cEcoreEvas, "resize", c_resize, 2);
        rb_define_method (cEcoreEvas, "title", c_title_get, 0);
        rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
-       rb_define_method (cEcoreEvas, "borderless", c_borderless_get, 0);
+       rb_define_method (cEcoreEvas, "borderless?", c_borderless_get, 0);
        rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
+       rb_define_method (cEcoreEvas, "shaped?", c_shaped_get, 0);
+       rb_define_method (cEcoreEvas, "shaped=", c_shaped_set, 1);
+       rb_define_method (cEcoreEvas, "sticky?", c_sticky_get, 0);
+       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);
 }
-