/*
- * $Id$
+ * $Id: rb_ecore_evas.c 77 2004-08-19 17:39:29Z 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 <ruby.h>
+#include <stdbool.h>
+#include <Ecore.h>
#include <Ecore_Evas.h>
-#include <rb_evas.h>
+#include <evas/rb_evas.h>
+#define __RB_ECORE_EVAS_C
+#include "../ecore/rb_ecore.h"
#include "rb_ecore_evas_main.h"
#include "rb_ecore_evas.h"
-#define GET_OBJ(obj, ee) \
- Ecore_Evas **(ee) = NULL; \
+#define CALLBACK_DEFINE_HANDLER(name) \
+ static void on_##name (Ecore_Evas *real) \
+ { \
+ VALUE self = rb_hash_aref (objects, INT2NUM ((long) real)); \
+ VALUE cb; \
\
- Data_Get_Struct ((obj), Ecore_Evas *, (ee)); \
+ GET_OBJ (self, RbEcoreEvas, ee); \
\
- if (!*(ee)) { \
- rb_raise (rb_eException, "EcoreEvas destroyed already"); \
- return Qnil; \
- }
+ cb = rb_hash_aref (ee->callbacks, rb_str_new2 (#name)); \
+ rb_funcall (cb, rb_intern ("call"), 0); \
+ } \
+
+#define CALLBACK_REG_HANDLER(name) \
+ GET_OBJ (self, RbEcoreEvas, ee); \
+\
+ if (!rb_block_given_p ()) \
+ return Qnil; \
+\
+ rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
+ rb_block_proc ()); \
+\
+ ecore_evas_callback_##name##_set (ee->real, on_##name); \
+\
+ return Qnil;
+
+VALUE cEcoreEvas;
+static VALUE objects;
/* called by the child classes */
-void c_ecore_evas_free (Ecore_Evas **ee)
+void c_ecore_evas_mark (RbEcoreEvas *ee)
+{
+ if (!NIL_P (ee->evas))
+ rb_gc_mark (ee->evas);
+
+ rb_gc_mark (ee->callbacks);
+}
+
+void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
{
- if (*ee)
- ecore_evas_free (*ee);
+ if (ee->real)
+ ecore_evas_free (ee->real);
+
+ ecore_evas_shutdown ();
+ ecore_shutdown ();
- free (ee);
+ if (free_mem)
+ free (ee);
}
-#if 0
-static VALUE c_init (int argc, VALUE argv, VALUE self)
+/* :nodoc: */
+static VALUE c_init (int argc, VALUE *argv, 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 (""));
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ee->evas = Qnil;
+ ee->callbacks = rb_hash_new ();
+
+ rb_hash_aset (objects, INT2NUM ((long) ee->real), self);
- return self;
+ return Qnil;
+}
+
+/* :nodoc: */
+static VALUE c_inspect (VALUE self)
+{
+ INSPECT (self, RbEcoreEvas);
}
-#endif
+/*
+ * call-seq:
+ * ee.show => nil
+ *
+ * Shows <i>ee</i>.
+ */
static VALUE c_show (VALUE self)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_show (*ee);
+ ecore_evas_show (ee->real);
return Qnil;
}
+/*
+ * call-seq:
+ * ee.hide => nil
+ *
+ * Hides <i>ee</i>.
+ */
static VALUE c_hide (VALUE self)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ecore_evas_hide (ee->real);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.visible? => true or false
+ *
+ * Returns true if <i>ee</i> is visible, else returns false.
+ */
+static VALUE c_visible_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ return ecore_evas_visibility_get (ee->real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * ee.raise => nil
+ *
+ * Raises <i>ee</i>.
+ */
+static VALUE c_raise (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ecore_evas_raise (ee->real);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.lower => nil
+ *
+ * Lowers <i>ee</i>.
+ */
+static VALUE c_lower (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ecore_evas_lower (ee->real);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.layer => fixnum
+ *
+ * Returns the layer of <i>ee</i>.
+ */
+static VALUE c_layer_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ return INT2FIX (ecore_evas_layer_get (ee->real));
+}
+
+/*
+ * call-seq:
+ * ee.layer(fixnum) => fixnum
+ *
+ * Sets the layer of <i>ee</i>.
+ */
+static VALUE c_layer_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ Check_Type (val, T_FIXNUM);
+
+ ecore_evas_layer_set (ee->real, FIX2INT (val));
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.evas => evas
+ *
+ * Returns the <code>Evas::Evas</code> object for <i>ee</i>.
+ */
+static VALUE c_evas_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ if (NIL_P (ee->evas))
+ ee->evas = TO_EVAS (self, ecore_evas_get (ee->real));
+
+ return ee->evas;
+}
+
+/*
+ * call-seq:
+ * ee.geometry => array
+ *
+ * Returns an array containing the geometry of <i>ee</i>.
+ *
+ * ee.move(150, 300) #=> nil
+ * ee.resize(200, 200) #=> nil
+ * ee.geometry #=> [150, 300, 200, 200]
+ */
+static VALUE c_geometry_get (VALUE self)
+{
+ int x = 0, y = 0, w = 0, h = 0;
+
+ GET_OBJ (self, RbEcoreEvas, ee);
- ecore_evas_hide (*ee);
+ ecore_evas_geometry_get (ee->real, &x, &y, &w, &h);
+
+ return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
+ INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ * ee.get_size_min => array
+ *
+ * Returns an array containing the minimum size of <i>ee</i>.
+ *
+ * ee.set_size_min(100, 200) #=> nil
+ * ee.get_size_min #=> [100, 200]
+ */
+static VALUE c_get_size_min (VALUE self)
+{
+ int w = 0, h = 0;
+
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ecore_evas_size_min_get (ee->real, &w, &h);
+
+ return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ * ee.set_size_min(width, height) => nil
+ *
+ * Sets the minimum size of <i>ee</i>.
+ *
+ * ee.set_size_min(100, 200) #=> nil
+ */
+static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ Check_Type (w, T_FIXNUM);
+ Check_Type (h, T_FIXNUM);
+
+ ecore_evas_size_min_set (ee->real, FIX2INT (w), FIX2INT (h));
return Qnil;
}
-static VALUE c_is_visible (VALUE self)
+/*
+ * call-seq:
+ * ee.get_size_max => array
+ *
+ * Returns an array containing the maximum size of <i>ee</i>.
+ *
+ * ee.set_size_max(100, 200) #=> nil
+ * ee.get_size_max #=> [100, 200]
+ */
+static VALUE c_get_size_max (VALUE self)
+{
+ int w = 0, h = 0;
+
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ ecore_evas_size_max_get (ee->real, &w, &h);
+
+ return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ * ee.set_size_max(width, height) => nil
+ *
+ * Sets the maximum size of <i>ee</i>.
+ *
+ * ee.set_size_max(100, 200) #=> nil
+ */
+static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
+ Check_Type (w, T_FIXNUM);
+ Check_Type (h, T_FIXNUM);
+
+ ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h));
+
+ return Qnil;
}
-static VALUE c_evas (VALUE self)
+/*
+ * call-seq:
+ * ee.move(x, y) => nil
+ *
+ * Moves <i>ee</i> to the coordinates specified in
+ * <i>x</i> and <i>y</i>.
+ *
+ * ee.move(100, 200) #=> nil
+ */
+static VALUE c_move (VALUE self, VALUE x, VALUE y)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return TO_EVAS (self, ecore_evas_get (*ee));
+ Check_Type (x, T_FIXNUM);
+ Check_Type (y, T_FIXNUM);
+
+ ecore_evas_move (ee->real, FIX2INT (x), FIX2INT (y));
+
+ return Qnil;
}
+/*
+ * call-seq:
+ * ee.resize(width, height) => nil
+ *
+ * Resizes <i>ee</i> to width x height.
+ *
+ * ee.resize(100, 200) #=> nil
+ */
static VALUE c_resize (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
- ecore_evas_resize (*ee, FIX2INT (w), FIX2INT (h));
+ ecore_evas_resize (ee->real, FIX2INT (w), FIX2INT (h));
return Qnil;
}
+/*
+ * call-seq:
+ * ee.title => string
+ *
+ * Returns the title of <i>ee</i>.
+ */
static VALUE c_title_get (VALUE self)
{
const char *tmp;
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- if (!(tmp = ecore_evas_title_get (*ee)))
+ if (!(tmp = ecore_evas_title_get (ee->real)))
return Qnil;
else
return rb_str_new2 (tmp);
}
+/*
+ * call-seq:
+ * ee.title(string)
+ *
+ * Sets the title of <i>ee</i>.
+ */
static VALUE c_title_set (VALUE self, VALUE val)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
Check_Type (val, T_STRING);
- ecore_evas_title_set (*ee, STR2CSTR (val));
+ ecore_evas_title_set (ee->real, StringValuePtr (val));
return Qnil;
}
+/*
+ * call-seq:
+ * ee.borderless? => true or false
+ *
+ * Returns true if <i>ee</i> is borderless, else returns false.
+ */
static VALUE c_borderless_get (VALUE self)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
+ return ecore_evas_borderless_get (ee->real) ? Qtrue : Qfalse;
}
+/*
+ * call-seq:
+ * ee.borderless(true or false)
+ *
+ * Sets whether <i>ee</i> is borderless or not.
+ */
static VALUE c_borderless_set (VALUE self, VALUE val)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
- /* 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);
+ ecore_evas_borderless_set (ee->real, val == Qtrue);
return Qnil;
}
+/*
+ * call-seq:
+ * ee.shaped? => true or false
+ *
+ * Returns true if <i>ee</i> is shaped, else returns false.
+ */
+static VALUE c_shaped_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ return ecore_evas_shaped_get (ee->real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * ee.shaped(true or false)
+ *
+ * Sets whether <i>ee</i> is shaped or not.
+ */
+static VALUE c_shaped_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ CHECK_BOOL (val);
+
+ ecore_evas_shaped_set (ee->real, val == Qtrue);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.sticky? => true or false
+ *
+ * Returns true if <i>ee</i> is sticky, else returns false.
+ */
+static VALUE c_sticky_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ return ecore_evas_sticky_get (ee->real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * ee.sticky(true or false)
+ *
+ * Sets whether <i>ee</i> is sticky or not.
+ */
+static VALUE c_sticky_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ CHECK_BOOL (val);
+
+ ecore_evas_sticky_set (ee->real, val == Qtrue);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * ee.rotation => fixnum
+ *
+ * Returns the rotation of <i>ee</i>.
+ */
+static VALUE c_rotation_get (VALUE self)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ return INT2FIX (ecore_evas_rotation_get (ee->real));
+}
+
+/*
+ * call-seq:
+ * ee.rotation(fixnum)
+ *
+ * Sets the rotation of <i>ee</i>.
+ */
+static VALUE c_rotation_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEcoreEvas, ee);
+
+ Check_Type (val, T_FIXNUM);
+
+ ecore_evas_rotation_set (ee->real, FIX2INT (val));
+
+ return Qnil;
+}
+
+/* FIXME: this is unsafe!
+ * :nodoc:
+ */
static VALUE c_delete (VALUE self)
{
- GET_OBJ (self, ee);
+ GET_OBJ (self, RbEcoreEvas, ee);
/* reap our children */
rb_gc_start ();
- ecore_evas_free (*ee);
- *ee = NULL;
+ ecore_evas_free (ee->real);
+ rb_hash_aset (objects, INT2NUM ((long) ee->real), Qnil);
+ ee->real = NULL;
return Qnil;
}
+CALLBACK_DEFINE_HANDLER (resize);
+CALLBACK_DEFINE_HANDLER (move);
+CALLBACK_DEFINE_HANDLER (show);
+CALLBACK_DEFINE_HANDLER (hide);
+CALLBACK_DEFINE_HANDLER (delete_request);
+CALLBACK_DEFINE_HANDLER (destroy);
+CALLBACK_DEFINE_HANDLER (focus_in);
+CALLBACK_DEFINE_HANDLER (focus_out);
+CALLBACK_DEFINE_HANDLER (mouse_in);
+CALLBACK_DEFINE_HANDLER (mouse_out);
+CALLBACK_DEFINE_HANDLER (pre_render);
+CALLBACK_DEFINE_HANDLER (post_render);
+
+/*
+ * call-seq:
+ * ee.on_resize { block } => nil
+ *
+ * Sets the handler for the resize event.
+ */
+static VALUE c_on_resize (VALUE self)
+{
+ CALLBACK_REG_HANDLER (resize);
+}
+
+/*
+ * call-seq:
+ * ee.on_move { block } => nil
+ *
+ * Sets the handler for the move event.
+ */
+static VALUE c_on_move (VALUE self)
+{
+ CALLBACK_REG_HANDLER (move);
+}
+
+/*
+ * call-seq:
+ * ee.on_show { block } => nil
+ *
+ * Sets the handler for the show event.
+ */
+static VALUE c_on_show (VALUE self)
+{
+ CALLBACK_REG_HANDLER (show);
+}
+
+/*
+ * call-seq:
+ * ee.on_hide { block } => nil
+ *
+ * Sets the handler for the hide event.
+ */
+static VALUE c_on_hide (VALUE self)
+{
+ CALLBACK_REG_HANDLER (hide);
+}
+
+/*
+ * call-seq:
+ * ee.on_delete_request { block } => nil
+ *
+ * Sets the handler for the delete request event.
+ */
+static VALUE c_on_delete_request (VALUE self)
+{
+ CALLBACK_REG_HANDLER (delete_request);
+}
+
+/*
+ * call-seq:
+ * ee.on_destroy { block } => nil
+ *
+ * Sets the handler for the destroy event.
+ */
+static VALUE c_on_destroy (VALUE self)
+{
+ CALLBACK_REG_HANDLER (destroy);
+}
+
+/*
+ * call-seq:
+ * ee.on_focus_in { block } => nil
+ *
+ * Sets the handler for the focus in event.
+ */
+static VALUE c_on_focus_in (VALUE self)
+{
+ CALLBACK_REG_HANDLER (focus_in);
+}
+
+/*
+ * call-seq:
+ * ee.on_focus_out { block } => nil
+ *
+ * Sets the handler for the focus out event.
+ */
+static VALUE c_on_focus_out (VALUE self)
+{
+ CALLBACK_REG_HANDLER (focus_out);
+}
+
+/*
+ * call-seq:
+ * ee.on_mouse_in { block } => nil
+ *
+ * Sets the handler for the mouse in event.
+ */
+static VALUE c_on_mouse_in (VALUE self)
+{
+ CALLBACK_REG_HANDLER (mouse_in);
+}
+
+/*
+ * call-seq:
+ * ee.on_mouse_out { block } => nil
+ *
+ * Sets the handler for the mouse out event.
+ */
+static VALUE c_on_mouse_out (VALUE self)
+{
+ CALLBACK_REG_HANDLER (mouse_out);
+}
+
+/*
+ * call-seq:
+ * ee.on_pre_render { block } => nil
+ *
+ * Sets the handler for the pre render event.
+ */
+static VALUE c_on_pre_render (VALUE self)
+{
+ CALLBACK_REG_HANDLER (pre_render);
+}
+
+/*
+ * call-seq:
+ * ee.on_post_render { block } => nil
+ *
+ * Sets the handler for the post render event.
+ */
+static VALUE c_on_post_render (VALUE self)
+{
+ CALLBACK_REG_HANDLER (post_render);
+}
+
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, "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, "evas", c_evas, 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_get, 0);
+ rb_define_method (cEcoreEvas, "geometry", c_geometry_get, 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);
+
+ rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
+ rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);
+ rb_define_method (cEcoreEvas, "on_show", c_on_show, 0);
+ rb_define_method (cEcoreEvas, "on_hide", c_on_hide, 0);
+ rb_define_method (cEcoreEvas, "on_delete_request", c_on_delete_request, 0);
+ rb_define_method (cEcoreEvas, "on_destroy", c_on_destroy, 0);
+ rb_define_method (cEcoreEvas, "on_focus_in", c_on_focus_in, 0);
+ rb_define_method (cEcoreEvas, "on_focus_out", c_on_focus_out, 0);
+ rb_define_method (cEcoreEvas, "on_mouse_in", c_on_mouse_in, 0);
+ 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);
}
-