2 * $Id: rb_ecore_evas.c 303 2005-03-22 17:42:04Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <Ecore_Evas.h>
26 #include <evas/rb_evas.h>
28 #define __RB_ECORE_EVAS_C
29 #include "../ecore/rb_ecore.h"
30 #include "rb_ecore_evas_main.h"
31 #include "rb_ecore_evas.h"
33 #define RUBY_ECORE_EVAS_KEY "__RB_ECORE_EVAS_KEY"
35 #define CALLBACK_DEFINE_HANDLER(name) \
36 static void on_##name (Ecore_Evas *real) \
41 self = (VALUE) ecore_evas_data_get (real, \
42 RUBY_ECORE_EVAS_KEY); \
43 GET_OBJ (self, RbEcoreEvas, ee); \
45 cb = rb_hash_aref (ee->callbacks, rb_str_new2 (#name)); \
46 rb_funcall (cb, rb_intern ("call"), 0); \
49 #define CALLBACK_REG_HANDLER(name) \
50 GET_OBJ (self, RbEcoreEvas, ee); \
52 if (!rb_block_given_p ()) \
55 if (NIL_P (ee->callbacks)) \
56 ee->callbacks = rb_hash_new (); \
58 rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
61 ecore_evas_callback_##name##_set (ee->real, on_##name); \
67 /* called by the child classes */
68 void c_ecore_evas_mark (RbEcoreEvas *ee)
70 if (!NIL_P (ee->evas))
71 rb_gc_mark (ee->evas);
73 if (!NIL_P (ee->callbacks))
74 rb_gc_mark (ee->callbacks);
77 void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
80 ecore_evas_free (ee->real);
82 ecore_evas_shutdown ();
90 static VALUE c_init (int argc, VALUE *argv, VALUE self)
92 GET_OBJ (self, RbEcoreEvas, ee);
97 ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
103 static VALUE c_inspect (VALUE self)
105 INSPECT (self, RbEcoreEvas);
114 static VALUE c_show (VALUE self)
116 GET_OBJ (self, RbEcoreEvas, ee);
118 ecore_evas_show (ee->real);
129 static VALUE c_hide (VALUE self)
131 GET_OBJ (self, RbEcoreEvas, ee);
133 ecore_evas_hide (ee->real);
140 * ee.visible? => true or false
142 * Returns true if <i>ee</i> is visible, else returns false.
144 static VALUE c_visible_get (VALUE self)
146 GET_OBJ (self, RbEcoreEvas, ee);
148 return ecore_evas_visibility_get (ee->real) ? Qtrue : Qfalse;
157 static VALUE c_raise (VALUE self)
159 GET_OBJ (self, RbEcoreEvas, ee);
161 ecore_evas_raise (ee->real);
172 static VALUE c_lower (VALUE self)
174 GET_OBJ (self, RbEcoreEvas, ee);
176 ecore_evas_lower (ee->real);
185 * Returns the layer of <i>ee</i>.
187 static VALUE c_layer_get (VALUE self)
189 GET_OBJ (self, RbEcoreEvas, ee);
191 return INT2FIX (ecore_evas_layer_get (ee->real));
196 * ee.layer(fixnum) => fixnum
198 * Sets the layer of <i>ee</i>.
200 static VALUE c_layer_set (VALUE self, VALUE val)
202 GET_OBJ (self, RbEcoreEvas, ee);
204 Check_Type (val, T_FIXNUM);
206 ecore_evas_layer_set (ee->real, FIX2INT (val));
215 * Returns the <code>Evas::Evas</code> object for <i>ee</i>.
217 static VALUE c_evas_get (VALUE self)
219 GET_OBJ (self, RbEcoreEvas, ee);
221 if (NIL_P (ee->evas))
222 ee->evas = TO_EVAS (self, ecore_evas_get (ee->real));
229 * ee.geometry => array
231 * Returns an array containing the geometry of <i>ee</i>.
233 * ee.move(150, 300) #=> nil
234 * ee.resize(200, 200) #=> nil
235 * ee.geometry #=> [150, 300, 200, 200]
237 static VALUE c_geometry_get (VALUE self)
239 int x = 0, y = 0, w = 0, h = 0;
241 GET_OBJ (self, RbEcoreEvas, ee);
243 ecore_evas_geometry_get (ee->real, &x, &y, &w, &h);
245 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
246 INT2FIX (w), INT2FIX (h));
251 * ee.get_size_min => array
253 * Returns an array containing the minimum size of <i>ee</i>.
255 * ee.set_size_min(100, 200) #=> nil
256 * ee.get_size_min #=> [100, 200]
258 static VALUE c_get_size_min (VALUE self)
262 GET_OBJ (self, RbEcoreEvas, ee);
264 ecore_evas_size_min_get (ee->real, &w, &h);
266 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
271 * ee.set_size_min(width, height) => nil
273 * Sets the minimum size of <i>ee</i>.
275 * ee.set_size_min(100, 200) #=> nil
277 static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
279 GET_OBJ (self, RbEcoreEvas, ee);
281 Check_Type (w, T_FIXNUM);
282 Check_Type (h, T_FIXNUM);
284 ecore_evas_size_min_set (ee->real, FIX2INT (w), FIX2INT (h));
291 * ee.get_size_max => array
293 * Returns an array containing the maximum size of <i>ee</i>.
295 * ee.set_size_max(100, 200) #=> nil
296 * ee.get_size_max #=> [100, 200]
298 static VALUE c_get_size_max (VALUE self)
302 GET_OBJ (self, RbEcoreEvas, ee);
304 ecore_evas_size_max_get (ee->real, &w, &h);
306 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
311 * ee.set_size_max(width, height) => nil
313 * Sets the maximum size of <i>ee</i>.
315 * ee.set_size_max(100, 200) #=> nil
317 static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
319 GET_OBJ (self, RbEcoreEvas, ee);
321 Check_Type (w, T_FIXNUM);
322 Check_Type (h, T_FIXNUM);
324 ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h));
331 * ee.move(x, y) => nil
333 * Moves <i>ee</i> to the coordinates specified in
334 * <i>x</i> and <i>y</i>.
336 * ee.move(100, 200) #=> nil
338 static VALUE c_move (VALUE self, VALUE x, VALUE y)
340 GET_OBJ (self, RbEcoreEvas, ee);
342 Check_Type (x, T_FIXNUM);
343 Check_Type (y, T_FIXNUM);
345 ecore_evas_move (ee->real, FIX2INT (x), FIX2INT (y));
352 * ee.resize(width, height) => nil
354 * Resizes <i>ee</i> to width x height.
356 * ee.resize(100, 200) #=> nil
358 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
360 GET_OBJ (self, RbEcoreEvas, ee);
362 Check_Type (w, T_FIXNUM);
363 Check_Type (h, T_FIXNUM);
365 ecore_evas_resize (ee->real, FIX2INT (w), FIX2INT (h));
374 * Returns the title of <i>ee</i>.
376 static VALUE c_title_get (VALUE self)
380 GET_OBJ (self, RbEcoreEvas, ee);
382 if (!(tmp = ecore_evas_title_get (ee->real)))
385 return rb_str_new2 (tmp);
392 * Sets the title of <i>ee</i>.
394 static VALUE c_title_set (VALUE self, VALUE val)
396 GET_OBJ (self, RbEcoreEvas, ee);
398 Check_Type (val, T_STRING);
400 ecore_evas_title_set (ee->real, StringValuePtr (val));
407 * ee.borderless? => true or false
409 * Returns true if <i>ee</i> is borderless, else returns false.
411 static VALUE c_borderless_get (VALUE self)
413 GET_OBJ (self, RbEcoreEvas, ee);
415 return ecore_evas_borderless_get (ee->real) ? Qtrue : Qfalse;
420 * ee.borderless(true or false)
422 * Sets whether <i>ee</i> is borderless or not.
424 static VALUE c_borderless_set (VALUE self, VALUE val)
426 GET_OBJ (self, RbEcoreEvas, ee);
430 ecore_evas_borderless_set (ee->real, val == Qtrue);
437 * ee.shaped? => true or false
439 * Returns true if <i>ee</i> is shaped, else returns false.
441 static VALUE c_shaped_get (VALUE self)
443 GET_OBJ (self, RbEcoreEvas, ee);
445 return ecore_evas_shaped_get (ee->real) ? Qtrue : Qfalse;
450 * ee.shaped(true or false)
452 * Sets whether <i>ee</i> is shaped or not.
454 static VALUE c_shaped_set (VALUE self, VALUE val)
456 GET_OBJ (self, RbEcoreEvas, ee);
460 ecore_evas_shaped_set (ee->real, val == Qtrue);
467 * ee.sticky? => true or false
469 * Returns true if <i>ee</i> is sticky, else returns false.
471 static VALUE c_sticky_get (VALUE self)
473 GET_OBJ (self, RbEcoreEvas, ee);
475 return ecore_evas_sticky_get (ee->real) ? Qtrue : Qfalse;
480 * ee.sticky(true or false)
482 * Sets whether <i>ee</i> is sticky or not.
484 static VALUE c_sticky_set (VALUE self, VALUE val)
486 GET_OBJ (self, RbEcoreEvas, ee);
490 ecore_evas_sticky_set (ee->real, val == Qtrue);
497 * ee.rotation => fixnum
499 * Returns the rotation of <i>ee</i>.
501 static VALUE c_rotation_get (VALUE self)
503 GET_OBJ (self, RbEcoreEvas, ee);
505 return INT2FIX (ecore_evas_rotation_get (ee->real));
510 * ee.rotation(fixnum)
512 * Sets the rotation of <i>ee</i>.
514 static VALUE c_rotation_set (VALUE self, VALUE val)
516 GET_OBJ (self, RbEcoreEvas, ee);
518 Check_Type (val, T_FIXNUM);
520 ecore_evas_rotation_set (ee->real, FIX2INT (val));
525 /* FIXME: this is unsafe!
528 static VALUE c_delete (VALUE self)
530 GET_OBJ (self, RbEcoreEvas, ee);
532 /* reap our children */
535 ecore_evas_free (ee->real);
541 CALLBACK_DEFINE_HANDLER (resize);
542 CALLBACK_DEFINE_HANDLER (move);
543 CALLBACK_DEFINE_HANDLER (show);
544 CALLBACK_DEFINE_HANDLER (hide);
545 CALLBACK_DEFINE_HANDLER (delete_request);
546 CALLBACK_DEFINE_HANDLER (destroy);
547 CALLBACK_DEFINE_HANDLER (focus_in);
548 CALLBACK_DEFINE_HANDLER (focus_out);
549 CALLBACK_DEFINE_HANDLER (mouse_in);
550 CALLBACK_DEFINE_HANDLER (mouse_out);
551 CALLBACK_DEFINE_HANDLER (pre_render);
552 CALLBACK_DEFINE_HANDLER (post_render);
556 * ee.on_resize { block } => nil
558 * Sets the handler for the resize event.
560 static VALUE c_on_resize (VALUE self)
562 CALLBACK_REG_HANDLER (resize);
567 * ee.on_move { block } => nil
569 * Sets the handler for the move event.
571 static VALUE c_on_move (VALUE self)
573 CALLBACK_REG_HANDLER (move);
578 * ee.on_show { block } => nil
580 * Sets the handler for the show event.
582 static VALUE c_on_show (VALUE self)
584 CALLBACK_REG_HANDLER (show);
589 * ee.on_hide { block } => nil
591 * Sets the handler for the hide event.
593 static VALUE c_on_hide (VALUE self)
595 CALLBACK_REG_HANDLER (hide);
600 * ee.on_delete_request { block } => nil
602 * Sets the handler for the delete request event.
604 static VALUE c_on_delete_request (VALUE self)
606 CALLBACK_REG_HANDLER (delete_request);
611 * ee.on_destroy { block } => nil
613 * Sets the handler for the destroy event.
615 static VALUE c_on_destroy (VALUE self)
617 CALLBACK_REG_HANDLER (destroy);
622 * ee.on_focus_in { block } => nil
624 * Sets the handler for the focus in event.
626 static VALUE c_on_focus_in (VALUE self)
628 CALLBACK_REG_HANDLER (focus_in);
633 * ee.on_focus_out { block } => nil
635 * Sets the handler for the focus out event.
637 static VALUE c_on_focus_out (VALUE self)
639 CALLBACK_REG_HANDLER (focus_out);
644 * ee.on_mouse_in { block } => nil
646 * Sets the handler for the mouse in event.
648 static VALUE c_on_mouse_in (VALUE self)
650 CALLBACK_REG_HANDLER (mouse_in);
655 * ee.on_mouse_out { block } => nil
657 * Sets the handler for the mouse out event.
659 static VALUE c_on_mouse_out (VALUE self)
661 CALLBACK_REG_HANDLER (mouse_out);
666 * ee.on_pre_render { block } => nil
668 * Sets the handler for the pre render event.
670 static VALUE c_on_pre_render (VALUE self)
672 CALLBACK_REG_HANDLER (pre_render);
677 * ee.on_post_render { block } => nil
679 * Sets the handler for the post render event.
681 static VALUE c_on_post_render (VALUE self)
683 CALLBACK_REG_HANDLER (post_render);
686 void Init_EcoreEvas (void)
688 cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
690 rb_define_private_method (rb_singleton_class (cEcoreEvas),
692 rb_define_method (cEcoreEvas, "initialize", c_init, -1);
693 rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
694 rb_define_method (cEcoreEvas, "delete", c_delete, 0);
695 rb_define_method (cEcoreEvas, "show", c_show, 0);
696 rb_define_method (cEcoreEvas, "hide", c_hide, 0);
697 rb_define_method (cEcoreEvas, "visible?", c_visible_get, 0);
698 rb_define_method (cEcoreEvas, "raise", c_raise, 0);
699 rb_define_method (cEcoreEvas, "lower", c_lower, 0);
700 rb_define_method (cEcoreEvas, "layer", c_layer_get, 0);
701 rb_define_method (cEcoreEvas, "layer=", c_layer_set, 1);
702 rb_define_method (cEcoreEvas, "evas", c_evas_get, 0);
703 rb_define_method (cEcoreEvas, "geometry", c_geometry_get, 0);
704 rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
705 rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
706 rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
707 rb_define_method (cEcoreEvas, "set_size_max", c_set_size_max, 2);
708 rb_define_method (cEcoreEvas, "move", c_move, 2);
709 rb_define_method (cEcoreEvas, "resize", c_resize, 2);
710 rb_define_method (cEcoreEvas, "title", c_title_get, 0);
711 rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
712 rb_define_method (cEcoreEvas, "borderless?", c_borderless_get, 0);
713 rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
714 rb_define_method (cEcoreEvas, "shaped?", c_shaped_get, 0);
715 rb_define_method (cEcoreEvas, "shaped=", c_shaped_set, 1);
716 rb_define_method (cEcoreEvas, "sticky?", c_sticky_get, 0);
717 rb_define_method (cEcoreEvas, "sticky=", c_sticky_set, 1);
718 rb_define_method (cEcoreEvas, "rotation", c_rotation_get, 0);
719 rb_define_method (cEcoreEvas, "rotation=", c_rotation_set, 1);
721 rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
722 rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);
723 rb_define_method (cEcoreEvas, "on_show", c_on_show, 0);
724 rb_define_method (cEcoreEvas, "on_hide", c_on_hide, 0);
725 rb_define_method (cEcoreEvas, "on_delete_request", c_on_delete_request, 0);
726 rb_define_method (cEcoreEvas, "on_destroy", c_on_destroy, 0);
727 rb_define_method (cEcoreEvas, "on_focus_in", c_on_focus_in, 0);
728 rb_define_method (cEcoreEvas, "on_focus_out", c_on_focus_out, 0);
729 rb_define_method (cEcoreEvas, "on_mouse_in", c_on_mouse_in, 0);
730 rb_define_method (cEcoreEvas, "on_mouse_out", c_on_mouse_out, 0);
731 rb_define_method (cEcoreEvas, "on_pre_render", c_on_pre_render, 0);
732 rb_define_method (cEcoreEvas, "on_post_render", c_on_post_render, 0);