2 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <Ecore_Evas.h>
24 #include <evas/rb_evas.h>
26 #define __RB_ECORE_EVAS_C
27 #include "../ecore/rb_ecore.h"
28 #include "rb_ecore_evas_main.h"
29 #include "rb_ecore_evas.h"
31 #define RUBY_ECORE_EVAS_KEY "__RB_ECORE_EVAS_KEY"
33 #define CALLBACK_DEFINE_HANDLER(name) \
34 static void on_##name (Ecore_Evas *real) \
38 self = (VALUE) ecore_evas_data_get (real, \
39 RUBY_ECORE_EVAS_KEY); \
40 GET_OBJ (self, RbEcoreEvas, ee); \
42 cb = rb_hash_aref (ee->callbacks, \
43 LONG2NUM ((long) ecore_evas_callback_##name##_set)); \
44 rb_funcall (cb, rb_intern ("call"), 0); \
47 #define CALLBACK_REG_HANDLER(name) \
48 GET_OBJ (self, RbEcoreEvas, ee); \
50 if (!rb_block_given_p ()) \
53 if (NIL_P (ee->callbacks)) \
54 ee->callbacks = rb_hash_new (); \
56 rb_hash_aset (ee->callbacks, \
57 LONG2NUM ((long) ecore_evas_callback_##name##_set), \
60 ecore_evas_callback_##name##_set (ee->real, on_##name); \
66 /* called by the child classes */
67 void c_ecore_evas_mark (RbEcoreEvas *ee)
69 if (!NIL_P (ee->evas))
70 rb_gc_mark (ee->evas);
72 if (!NIL_P (ee->callbacks))
73 rb_gc_mark (ee->callbacks);
76 void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
79 ecore_evas_free (ee->real);
81 ecore_evas_shutdown ();
89 static VALUE c_init (int argc, VALUE *argv, VALUE self)
91 GET_OBJ (self, RbEcoreEvas, ee);
96 ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
102 static VALUE c_inspect (VALUE self)
104 INSPECT (self, RbEcoreEvas);
113 static VALUE c_show (VALUE self)
115 GET_OBJ (self, RbEcoreEvas, ee);
117 ecore_evas_show (ee->real);
128 static VALUE c_hide (VALUE self)
130 GET_OBJ (self, RbEcoreEvas, ee);
132 ecore_evas_hide (ee->real);
139 * ee.visible? => true or false
141 * Returns true if <i>ee</i> is visible, else returns false.
143 static VALUE c_visible_get (VALUE self)
145 GET_OBJ (self, RbEcoreEvas, ee);
147 return ecore_evas_visibility_get (ee->real) ? Qtrue : Qfalse;
156 static VALUE c_raise (VALUE self)
158 GET_OBJ (self, RbEcoreEvas, ee);
160 ecore_evas_raise (ee->real);
171 static VALUE c_lower (VALUE self)
173 GET_OBJ (self, RbEcoreEvas, ee);
175 ecore_evas_lower (ee->real);
184 * Returns the layer of <i>ee</i>.
186 static VALUE c_layer_get (VALUE self)
188 GET_OBJ (self, RbEcoreEvas, ee);
190 return INT2FIX (ecore_evas_layer_get (ee->real));
195 * ee.layer(fixnum) => fixnum
197 * Sets the layer of <i>ee</i>.
199 static VALUE c_layer_set (VALUE self, VALUE val)
201 GET_OBJ (self, RbEcoreEvas, ee);
203 Check_Type (val, T_FIXNUM);
205 ecore_evas_layer_set (ee->real, FIX2INT (val));
214 * Returns the <code>Evas::Evas</code> object for <i>ee</i>.
216 static VALUE c_evas_get (VALUE self)
218 GET_OBJ (self, RbEcoreEvas, ee);
220 if (NIL_P (ee->evas))
221 ee->evas = TO_EVAS (self, ecore_evas_get (ee->real));
228 * ee.geometry => array
230 * Returns an array containing the geometry of <i>ee</i>.
232 * ee.move(150, 300) #=> nil
233 * ee.resize(200, 200) #=> nil
234 * ee.geometry #=> [150, 300, 200, 200]
236 static VALUE c_geometry_get (VALUE self)
238 int x = 0, y = 0, w = 0, h = 0;
240 GET_OBJ (self, RbEcoreEvas, ee);
242 ecore_evas_geometry_get (ee->real, &x, &y, &w, &h);
244 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
245 INT2FIX (w), INT2FIX (h));
250 * ee.get_size_min => array
252 * Returns an array containing the minimum size of <i>ee</i>.
254 * ee.set_size_min(100, 200) #=> nil
255 * ee.get_size_min #=> [100, 200]
257 static VALUE c_get_size_min (VALUE self)
261 GET_OBJ (self, RbEcoreEvas, ee);
263 ecore_evas_size_min_get (ee->real, &w, &h);
265 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
270 * ee.set_size_min(width, height) => nil
272 * Sets the minimum size of <i>ee</i>.
274 * ee.set_size_min(100, 200) #=> nil
276 static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
278 GET_OBJ (self, RbEcoreEvas, ee);
280 Check_Type (w, T_FIXNUM);
281 Check_Type (h, T_FIXNUM);
283 ecore_evas_size_min_set (ee->real, FIX2INT (w), FIX2INT (h));
290 * ee.get_size_max => array
292 * Returns an array containing the maximum size of <i>ee</i>.
294 * ee.set_size_max(100, 200) #=> nil
295 * ee.get_size_max #=> [100, 200]
297 static VALUE c_get_size_max (VALUE self)
301 GET_OBJ (self, RbEcoreEvas, ee);
303 ecore_evas_size_max_get (ee->real, &w, &h);
305 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
310 * ee.set_size_max(width, height) => nil
312 * Sets the maximum size of <i>ee</i>.
314 * ee.set_size_max(100, 200) #=> nil
316 static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
318 GET_OBJ (self, RbEcoreEvas, ee);
320 Check_Type (w, T_FIXNUM);
321 Check_Type (h, T_FIXNUM);
323 ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h));
330 * ee.move(x, y) => nil
332 * Moves <i>ee</i> to the coordinates specified in
333 * <i>x</i> and <i>y</i>.
335 * ee.move(100, 200) #=> nil
337 static VALUE c_move (VALUE self, VALUE x, VALUE y)
339 GET_OBJ (self, RbEcoreEvas, ee);
341 Check_Type (x, T_FIXNUM);
342 Check_Type (y, T_FIXNUM);
344 ecore_evas_move (ee->real, FIX2INT (x), FIX2INT (y));
351 * ee.resize(width, height) => nil
353 * Resizes <i>ee</i> to width x height.
355 * ee.resize(100, 200) #=> nil
357 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
359 GET_OBJ (self, RbEcoreEvas, ee);
361 Check_Type (w, T_FIXNUM);
362 Check_Type (h, T_FIXNUM);
364 ecore_evas_resize (ee->real, FIX2INT (w), FIX2INT (h));
373 * Returns the title of <i>ee</i>.
375 static VALUE c_title_get (VALUE self)
379 GET_OBJ (self, RbEcoreEvas, ee);
381 if (!(tmp = ecore_evas_title_get (ee->real)))
384 return rb_str_new2 (tmp);
391 * Sets the title of <i>ee</i>.
393 static VALUE c_title_set (VALUE self, VALUE val)
395 GET_OBJ (self, RbEcoreEvas, ee);
397 Check_Type (val, T_STRING);
399 ecore_evas_title_set (ee->real, StringValuePtr (val));
406 * ee.borderless? => true or false
408 * Returns true if <i>ee</i> is borderless, else returns false.
410 static VALUE c_borderless_get (VALUE self)
412 GET_OBJ (self, RbEcoreEvas, ee);
414 return ecore_evas_borderless_get (ee->real) ? Qtrue : Qfalse;
419 * ee.borderless(true or false)
421 * Sets whether <i>ee</i> is borderless or not.
423 static VALUE c_borderless_set (VALUE self, VALUE val)
425 GET_OBJ (self, RbEcoreEvas, ee);
429 ecore_evas_borderless_set (ee->real, val == Qtrue);
436 * ee.shaped? => true or false
438 * Returns true if <i>ee</i> is shaped, else returns false.
440 static VALUE c_shaped_get (VALUE self)
442 GET_OBJ (self, RbEcoreEvas, ee);
444 return ecore_evas_shaped_get (ee->real) ? Qtrue : Qfalse;
449 * ee.shaped(true or false)
451 * Sets whether <i>ee</i> is shaped or not.
453 static VALUE c_shaped_set (VALUE self, VALUE val)
455 GET_OBJ (self, RbEcoreEvas, ee);
459 ecore_evas_shaped_set (ee->real, val == Qtrue);
466 * ee.sticky? => true or false
468 * Returns true if <i>ee</i> is sticky, else returns false.
470 static VALUE c_sticky_get (VALUE self)
472 GET_OBJ (self, RbEcoreEvas, ee);
474 return ecore_evas_sticky_get (ee->real) ? Qtrue : Qfalse;
479 * ee.sticky(true or false)
481 * Sets whether <i>ee</i> is sticky or not.
483 static VALUE c_sticky_set (VALUE self, VALUE val)
485 GET_OBJ (self, RbEcoreEvas, ee);
489 ecore_evas_sticky_set (ee->real, val == Qtrue);
496 * ee.rotation => fixnum
498 * Returns the rotation of <i>ee</i>.
500 static VALUE c_rotation_get (VALUE self)
502 GET_OBJ (self, RbEcoreEvas, ee);
504 return INT2FIX (ecore_evas_rotation_get (ee->real));
509 * ee.rotation(fixnum)
511 * Sets the rotation of <i>ee</i>.
513 static VALUE c_rotation_set (VALUE self, VALUE val)
515 GET_OBJ (self, RbEcoreEvas, ee);
517 Check_Type (val, T_FIXNUM);
519 ecore_evas_rotation_set (ee->real, FIX2INT (val));
524 static VALUE c_name_class_get (VALUE self)
526 const char *name = NULL, *klass = NULL;
528 GET_OBJ (self, RbEcoreEvas, ee);
530 ecore_evas_name_class_get (ee->real, &name, &klass);
532 return rb_ary_new3 (2, name ? rb_str_new2 (name) : Qnil,
533 klass ? rb_str_new2 (klass) : Qnil);
536 static VALUE c_name_class_set (VALUE self, VALUE ary)
540 GET_OBJ (self, RbEcoreEvas, ee);
542 Check_Type (ary, T_ARRAY);
544 s1 = rb_ary_shift (ary);
545 s2 = rb_ary_shift (ary);
550 ecore_evas_name_class_set (ee->real, StringValuePtr (s1),
551 StringValuePtr (s2));
558 * ee.iconified? => true or false
560 * Returns true if <i>ee</i> is iconified, else returns false.
562 static VALUE c_iconified_get (VALUE self)
564 GET_OBJ (self, RbEcoreEvas, ee);
566 return ecore_evas_iconified_get (ee->real) ? Qtrue : Qfalse;
571 * ee.iconified(true or false)
573 * Sets whether <i>ee</i> is iconified or not.
575 static VALUE c_iconified_set (VALUE self, VALUE val)
577 GET_OBJ (self, RbEcoreEvas, ee);
581 ecore_evas_iconified_set (ee->real, val == Qtrue);
588 * ee.has_alpha? => true or false
590 * Returns true if <i>ee</i> has an alpha channel, else returns false.
592 static VALUE c_has_alpha_get (VALUE self)
594 GET_OBJ (self, RbEcoreEvas, ee);
596 return ecore_evas_alpha_get (ee->real) ? Qtrue : Qfalse;
601 * ee.has_alpha(true or false)
603 * Sets whether <i>ee</i> has an alpha channel or not.
605 static VALUE c_has_alpha_set (VALUE self, VALUE val)
607 GET_OBJ (self, RbEcoreEvas, ee);
611 ecore_evas_alpha_set (ee->real, val == Qtrue);
616 /* FIXME: this is unsafe!
619 static VALUE c_delete (VALUE self)
621 GET_OBJ (self, RbEcoreEvas, ee);
623 /* reap our children */
626 ecore_evas_free (ee->real);
632 CALLBACK_DEFINE_HANDLER (resize);
633 CALLBACK_DEFINE_HANDLER (move);
634 CALLBACK_DEFINE_HANDLER (show);
635 CALLBACK_DEFINE_HANDLER (hide);
636 CALLBACK_DEFINE_HANDLER (delete_request);
637 CALLBACK_DEFINE_HANDLER (destroy);
638 CALLBACK_DEFINE_HANDLER (focus_in);
639 CALLBACK_DEFINE_HANDLER (focus_out);
640 CALLBACK_DEFINE_HANDLER (mouse_in);
641 CALLBACK_DEFINE_HANDLER (mouse_out);
642 CALLBACK_DEFINE_HANDLER (pre_render);
643 CALLBACK_DEFINE_HANDLER (post_render);
647 * ee.on_resize { block } => nil
649 * Sets the handler for the resize event.
651 static VALUE c_on_resize (VALUE self)
653 CALLBACK_REG_HANDLER (resize);
658 * ee.on_move { block } => nil
660 * Sets the handler for the move event.
662 static VALUE c_on_move (VALUE self)
664 CALLBACK_REG_HANDLER (move);
669 * ee.on_show { block } => nil
671 * Sets the handler for the show event.
673 static VALUE c_on_show (VALUE self)
675 CALLBACK_REG_HANDLER (show);
680 * ee.on_hide { block } => nil
682 * Sets the handler for the hide event.
684 static VALUE c_on_hide (VALUE self)
686 CALLBACK_REG_HANDLER (hide);
691 * ee.on_delete_request { block } => nil
693 * Sets the handler for the delete request event.
695 static VALUE c_on_delete_request (VALUE self)
697 CALLBACK_REG_HANDLER (delete_request);
702 * ee.on_destroy { block } => nil
704 * Sets the handler for the destroy event.
706 static VALUE c_on_destroy (VALUE self)
708 CALLBACK_REG_HANDLER (destroy);
713 * ee.on_focus_in { block } => nil
715 * Sets the handler for the focus in event.
717 static VALUE c_on_focus_in (VALUE self)
719 CALLBACK_REG_HANDLER (focus_in);
724 * ee.on_focus_out { block } => nil
726 * Sets the handler for the focus out event.
728 static VALUE c_on_focus_out (VALUE self)
730 CALLBACK_REG_HANDLER (focus_out);
735 * ee.on_mouse_in { block } => nil
737 * Sets the handler for the mouse in event.
739 static VALUE c_on_mouse_in (VALUE self)
741 CALLBACK_REG_HANDLER (mouse_in);
746 * ee.on_mouse_out { block } => nil
748 * Sets the handler for the mouse out event.
750 static VALUE c_on_mouse_out (VALUE self)
752 CALLBACK_REG_HANDLER (mouse_out);
757 * ee.on_pre_render { block } => nil
759 * Sets the handler for the pre render event.
761 static VALUE c_on_pre_render (VALUE self)
763 CALLBACK_REG_HANDLER (pre_render);
768 * ee.on_post_render { block } => nil
770 * Sets the handler for the post render event.
772 static VALUE c_on_post_render (VALUE self)
774 CALLBACK_REG_HANDLER (post_render);
777 void Init_EcoreEvas (void)
779 cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
781 rb_define_method (cEcoreEvas, "initialize", c_init, -1);
782 rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
783 rb_define_method (cEcoreEvas, "delete", c_delete, 0);
784 rb_define_method (cEcoreEvas, "show", c_show, 0);
785 rb_define_method (cEcoreEvas, "hide", c_hide, 0);
786 rb_define_method (cEcoreEvas, "visible?", c_visible_get, 0);
787 rb_define_method (cEcoreEvas, "raise", c_raise, 0);
788 rb_define_method (cEcoreEvas, "lower", c_lower, 0);
789 rb_define_method (cEcoreEvas, "layer", c_layer_get, 0);
790 rb_define_method (cEcoreEvas, "layer=", c_layer_set, 1);
791 rb_define_method (cEcoreEvas, "evas", c_evas_get, 0);
792 rb_define_method (cEcoreEvas, "geometry", c_geometry_get, 0);
793 rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
794 rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
795 rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
796 rb_define_method (cEcoreEvas, "set_size_max", c_set_size_max, 2);
797 rb_define_method (cEcoreEvas, "move", c_move, 2);
798 rb_define_method (cEcoreEvas, "resize", c_resize, 2);
799 rb_define_method (cEcoreEvas, "title", c_title_get, 0);
800 rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
801 rb_define_method (cEcoreEvas, "borderless?", c_borderless_get, 0);
802 rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
803 rb_define_method (cEcoreEvas, "shaped?", c_shaped_get, 0);
804 rb_define_method (cEcoreEvas, "shaped=", c_shaped_set, 1);
805 rb_define_method (cEcoreEvas, "sticky?", c_sticky_get, 0);
806 rb_define_method (cEcoreEvas, "sticky=", c_sticky_set, 1);
807 rb_define_method (cEcoreEvas, "rotation", c_rotation_get, 0);
808 rb_define_method (cEcoreEvas, "rotation=", c_rotation_set, 1);
809 rb_define_method (cEcoreEvas, "name_class", c_name_class_get, 0);
810 rb_define_method (cEcoreEvas, "name_class=", c_name_class_set, 1);
811 rb_define_method (cEcoreEvas, "iconified?", c_iconified_get, 0);
812 rb_define_method (cEcoreEvas, "iconified=", c_iconified_set, 1);
813 rb_define_method (cEcoreEvas, "has_alpha?", c_has_alpha_get, 0);
814 rb_define_method (cEcoreEvas, "has_alpha=", c_has_alpha_set, 1);
816 rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
817 rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);
818 rb_define_method (cEcoreEvas, "on_show", c_on_show, 0);
819 rb_define_method (cEcoreEvas, "on_hide", c_on_hide, 0);
820 rb_define_method (cEcoreEvas, "on_delete_request", c_on_delete_request, 0);
821 rb_define_method (cEcoreEvas, "on_destroy", c_on_destroy, 0);
822 rb_define_method (cEcoreEvas, "on_focus_in", c_on_focus_in, 0);
823 rb_define_method (cEcoreEvas, "on_focus_out", c_on_focus_out, 0);
824 rb_define_method (cEcoreEvas, "on_mouse_in", c_on_mouse_in, 0);
825 rb_define_method (cEcoreEvas, "on_mouse_out", c_on_mouse_out, 0);
826 rb_define_method (cEcoreEvas, "on_pre_render", c_on_pre_render, 0);
827 rb_define_method (cEcoreEvas, "on_post_render", c_on_post_render, 0);