X-Git-Url: http://git.code-monkey.de/?p=ruby-ecore.git;a=blobdiff_plain;f=src%2Fecore_evas%2Frb_ecore_evas.c;h=e51a4f42b79f5a7cce78ce4847aec0ba8249b369;hp=040ac6848275e0eee27a8a156ac4155fe6fb417c;hb=45f545180849ddf721711df2469ea12f2ff9990a;hpb=f007c429dfb7b76be36317212a0585401e13984a diff --git a/src/ecore_evas/rb_ecore_evas.c b/src/ecore_evas/rb_ecore_evas.c index 040ac68..e51a4f4 100644 --- a/src/ecore_evas/rb_ecore_evas.c +++ b/src/ecore_evas/rb_ecore_evas.c @@ -1,7 +1,7 @@ /* - * $Id: rb_ecore_evas.c 9 2004-06-19 19:53:47Z 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 @@ -19,164 +19,781 @@ */ #include +#include +#include #include -#include +#include +#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 RUBY_ECORE_EVAS_KEY "__RB_ECORE_EVAS_KEY" + +#define CALLBACK_DEFINE_HANDLER(name) \ + static void on_##name (Ecore_Evas *real) \ + { \ + 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, \ + LONG2NUM ((long) ecore_evas_callback_##name##_set)); \ + rb_funcall (cb, rb_intern ("call"), 0); \ + } \ + +#define CALLBACK_REG_HANDLER(name) \ + GET_OBJ (self, RbEcoreEvas, ee); \ +\ + if (!rb_block_given_p ()) \ + return Qnil; \ \ - Data_Get_Struct ((obj), Ecore_Evas *, (ee)); \ + if (NIL_P (ee->callbacks)) \ + ee->callbacks = rb_hash_new (); \ \ - if (!*(ee)) { \ - rb_raise (rb_eException, "EcoreEvas destroyed already"); \ - return Qnil; \ - } + rb_hash_aset (ee->callbacks, \ + LONG2NUM ((long) ecore_evas_callback_##name##_set), \ + rb_block_proc ()); \ +\ + ecore_evas_callback_##name##_set (ee->real, on_##name); \ +\ + return Qnil; + +VALUE cEcoreEvas; /* 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); + + if (!NIL_P (ee->callbacks)) + 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); - free (ee); + ecore_evas_shutdown (); + ecore_shutdown (); + + 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 = Qnil; - return self; + ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self); + + return Qnil; +} + +/* :nodoc: */ +static VALUE c_inspect (VALUE self) +{ + INSPECT (self, RbEcoreEvas); } -#endif +/* + * call-seq: + * ee.show => nil + * + * Shows ee. + */ 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 ee. + */ 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 ee 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 ee. + */ +static VALUE c_raise (VALUE self) +{ + GET_OBJ (self, RbEcoreEvas, ee); + + ecore_evas_raise (ee->real); + + return Qnil; +} + +/* + * call-seq: + * ee.lower => nil + * + * Lowers ee. + */ +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 ee. + */ +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 ee. + */ +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 Evas::Evas object for ee. + */ +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 ee. + * + * 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_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 ee. + * + * 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; - ecore_evas_hide (*ee); + 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 ee. + * + * 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 ee. + * + * 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 ee. + * + * 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); + + Check_Type (w, T_FIXNUM); + Check_Type (h, T_FIXNUM); + + ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h)); - return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse; + return Qnil; } -static VALUE c_evas (VALUE self) +/* + * call-seq: + * ee.move(x, y) => nil + * + * Moves ee to the coordinates specified in + * x and y. + * + * 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 ee 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 ee. + */ 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 ee. + */ 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 ee 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 ee 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->real, val == Qtrue); + + return Qnil; +} - ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0); +/* + * call-seq: + * ee.shaped? => true or false + * + * Returns true if ee 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 ee 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 ee 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 ee 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 ee. + */ +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 ee. + */ +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; +} + +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 ee 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 ee 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: + */ 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); + 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, "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); + 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); } -