2 * $Id: rb_ecore_evas.c 110 2004-09-02 17:06:54Z 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 rb_hash_aset (ee->callbacks, rb_str_new2 (#name), \
58 ecore_evas_callback_##name##_set (ee->real, on_##name); \
64 /* called by the child classes */
65 void c_ecore_evas_mark (RbEcoreEvas *ee)
67 if (!NIL_P (ee->evas))
68 rb_gc_mark (ee->evas);
70 rb_gc_mark (ee->callbacks);
73 void c_ecore_evas_free (RbEcoreEvas *ee, bool free_mem)
76 ecore_evas_free (ee->real);
78 ecore_evas_shutdown ();
86 static VALUE c_init (int argc, VALUE *argv, VALUE self)
88 GET_OBJ (self, RbEcoreEvas, ee);
91 ee->callbacks = rb_hash_new ();
93 ecore_evas_data_set (ee->real, RUBY_ECORE_EVAS_KEY, (void *) self);
99 static VALUE c_inspect (VALUE self)
101 INSPECT (self, RbEcoreEvas);
110 static VALUE c_show (VALUE self)
112 GET_OBJ (self, RbEcoreEvas, ee);
114 ecore_evas_show (ee->real);
125 static VALUE c_hide (VALUE self)
127 GET_OBJ (self, RbEcoreEvas, ee);
129 ecore_evas_hide (ee->real);
136 * ee.visible? => true or false
138 * Returns true if <i>ee</i> is visible, else returns false.
140 static VALUE c_visible_get (VALUE self)
142 GET_OBJ (self, RbEcoreEvas, ee);
144 return ecore_evas_visibility_get (ee->real) ? Qtrue : Qfalse;
153 static VALUE c_raise (VALUE self)
155 GET_OBJ (self, RbEcoreEvas, ee);
157 ecore_evas_raise (ee->real);
168 static VALUE c_lower (VALUE self)
170 GET_OBJ (self, RbEcoreEvas, ee);
172 ecore_evas_lower (ee->real);
181 * Returns the layer of <i>ee</i>.
183 static VALUE c_layer_get (VALUE self)
185 GET_OBJ (self, RbEcoreEvas, ee);
187 return INT2FIX (ecore_evas_layer_get (ee->real));
192 * ee.layer(fixnum) => fixnum
194 * Sets the layer of <i>ee</i>.
196 static VALUE c_layer_set (VALUE self, VALUE val)
198 GET_OBJ (self, RbEcoreEvas, ee);
200 Check_Type (val, T_FIXNUM);
202 ecore_evas_layer_set (ee->real, FIX2INT (val));
211 * Returns the <code>Evas::Evas</code> object for <i>ee</i>.
213 static VALUE c_evas_get (VALUE self)
215 GET_OBJ (self, RbEcoreEvas, ee);
217 if (NIL_P (ee->evas))
218 ee->evas = TO_EVAS (self, ecore_evas_get (ee->real));
225 * ee.geometry => array
227 * Returns an array containing the geometry of <i>ee</i>.
229 * ee.move(150, 300) #=> nil
230 * ee.resize(200, 200) #=> nil
231 * ee.geometry #=> [150, 300, 200, 200]
233 static VALUE c_geometry_get (VALUE self)
235 int x = 0, y = 0, w = 0, h = 0;
237 GET_OBJ (self, RbEcoreEvas, ee);
239 ecore_evas_geometry_get (ee->real, &x, &y, &w, &h);
241 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
242 INT2FIX (w), INT2FIX (h));
247 * ee.get_size_min => array
249 * Returns an array containing the minimum size of <i>ee</i>.
251 * ee.set_size_min(100, 200) #=> nil
252 * ee.get_size_min #=> [100, 200]
254 static VALUE c_get_size_min (VALUE self)
258 GET_OBJ (self, RbEcoreEvas, ee);
260 ecore_evas_size_min_get (ee->real, &w, &h);
262 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
267 * ee.set_size_min(width, height) => nil
269 * Sets the minimum size of <i>ee</i>.
271 * ee.set_size_min(100, 200) #=> nil
273 static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
275 GET_OBJ (self, RbEcoreEvas, ee);
277 Check_Type (w, T_FIXNUM);
278 Check_Type (h, T_FIXNUM);
280 ecore_evas_size_min_set (ee->real, FIX2INT (w), FIX2INT (h));
287 * ee.get_size_max => array
289 * Returns an array containing the maximum size of <i>ee</i>.
291 * ee.set_size_max(100, 200) #=> nil
292 * ee.get_size_max #=> [100, 200]
294 static VALUE c_get_size_max (VALUE self)
298 GET_OBJ (self, RbEcoreEvas, ee);
300 ecore_evas_size_max_get (ee->real, &w, &h);
302 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
307 * ee.set_size_max(width, height) => nil
309 * Sets the maximum size of <i>ee</i>.
311 * ee.set_size_max(100, 200) #=> nil
313 static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
315 GET_OBJ (self, RbEcoreEvas, ee);
317 Check_Type (w, T_FIXNUM);
318 Check_Type (h, T_FIXNUM);
320 ecore_evas_size_max_set (ee->real, FIX2INT (w), FIX2INT (h));
327 * ee.move(x, y) => nil
329 * Moves <i>ee</i> to the coordinates specified in
330 * <i>x</i> and <i>y</i>.
332 * ee.move(100, 200) #=> nil
334 static VALUE c_move (VALUE self, VALUE x, VALUE y)
336 GET_OBJ (self, RbEcoreEvas, ee);
338 Check_Type (x, T_FIXNUM);
339 Check_Type (y, T_FIXNUM);
341 ecore_evas_move (ee->real, FIX2INT (x), FIX2INT (y));
348 * ee.resize(width, height) => nil
350 * Resizes <i>ee</i> to width x height.
352 * ee.resize(100, 200) #=> nil
354 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
356 GET_OBJ (self, RbEcoreEvas, ee);
358 Check_Type (w, T_FIXNUM);
359 Check_Type (h, T_FIXNUM);
361 ecore_evas_resize (ee->real, FIX2INT (w), FIX2INT (h));
370 * Returns the title of <i>ee</i>.
372 static VALUE c_title_get (VALUE self)
376 GET_OBJ (self, RbEcoreEvas, ee);
378 if (!(tmp = ecore_evas_title_get (ee->real)))
381 return rb_str_new2 (tmp);
388 * Sets the title of <i>ee</i>.
390 static VALUE c_title_set (VALUE self, VALUE val)
392 GET_OBJ (self, RbEcoreEvas, ee);
394 Check_Type (val, T_STRING);
396 ecore_evas_title_set (ee->real, StringValuePtr (val));
403 * ee.borderless? => true or false
405 * Returns true if <i>ee</i> is borderless, else returns false.
407 static VALUE c_borderless_get (VALUE self)
409 GET_OBJ (self, RbEcoreEvas, ee);
411 return ecore_evas_borderless_get (ee->real) ? Qtrue : Qfalse;
416 * ee.borderless(true or false)
418 * Sets whether <i>ee</i> is borderless or not.
420 static VALUE c_borderless_set (VALUE self, VALUE val)
422 GET_OBJ (self, RbEcoreEvas, ee);
426 ecore_evas_borderless_set (ee->real, val == Qtrue);
433 * ee.shaped? => true or false
435 * Returns true if <i>ee</i> is shaped, else returns false.
437 static VALUE c_shaped_get (VALUE self)
439 GET_OBJ (self, RbEcoreEvas, ee);
441 return ecore_evas_shaped_get (ee->real) ? Qtrue : Qfalse;
446 * ee.shaped(true or false)
448 * Sets whether <i>ee</i> is shaped or not.
450 static VALUE c_shaped_set (VALUE self, VALUE val)
452 GET_OBJ (self, RbEcoreEvas, ee);
456 ecore_evas_shaped_set (ee->real, val == Qtrue);
463 * ee.sticky? => true or false
465 * Returns true if <i>ee</i> is sticky, else returns false.
467 static VALUE c_sticky_get (VALUE self)
469 GET_OBJ (self, RbEcoreEvas, ee);
471 return ecore_evas_sticky_get (ee->real) ? Qtrue : Qfalse;
476 * ee.sticky(true or false)
478 * Sets whether <i>ee</i> is sticky or not.
480 static VALUE c_sticky_set (VALUE self, VALUE val)
482 GET_OBJ (self, RbEcoreEvas, ee);
486 ecore_evas_sticky_set (ee->real, val == Qtrue);
493 * ee.rotation => fixnum
495 * Returns the rotation of <i>ee</i>.
497 static VALUE c_rotation_get (VALUE self)
499 GET_OBJ (self, RbEcoreEvas, ee);
501 return INT2FIX (ecore_evas_rotation_get (ee->real));
506 * ee.rotation(fixnum)
508 * Sets the rotation of <i>ee</i>.
510 static VALUE c_rotation_set (VALUE self, VALUE val)
512 GET_OBJ (self, RbEcoreEvas, ee);
514 Check_Type (val, T_FIXNUM);
516 ecore_evas_rotation_set (ee->real, FIX2INT (val));
521 /* FIXME: this is unsafe!
524 static VALUE c_delete (VALUE self)
526 GET_OBJ (self, RbEcoreEvas, ee);
528 /* reap our children */
531 ecore_evas_free (ee->real);
537 CALLBACK_DEFINE_HANDLER (resize);
538 CALLBACK_DEFINE_HANDLER (move);
539 CALLBACK_DEFINE_HANDLER (show);
540 CALLBACK_DEFINE_HANDLER (hide);
541 CALLBACK_DEFINE_HANDLER (delete_request);
542 CALLBACK_DEFINE_HANDLER (destroy);
543 CALLBACK_DEFINE_HANDLER (focus_in);
544 CALLBACK_DEFINE_HANDLER (focus_out);
545 CALLBACK_DEFINE_HANDLER (mouse_in);
546 CALLBACK_DEFINE_HANDLER (mouse_out);
547 CALLBACK_DEFINE_HANDLER (pre_render);
548 CALLBACK_DEFINE_HANDLER (post_render);
552 * ee.on_resize { block } => nil
554 * Sets the handler for the resize event.
556 static VALUE c_on_resize (VALUE self)
558 CALLBACK_REG_HANDLER (resize);
563 * ee.on_move { block } => nil
565 * Sets the handler for the move event.
567 static VALUE c_on_move (VALUE self)
569 CALLBACK_REG_HANDLER (move);
574 * ee.on_show { block } => nil
576 * Sets the handler for the show event.
578 static VALUE c_on_show (VALUE self)
580 CALLBACK_REG_HANDLER (show);
585 * ee.on_hide { block } => nil
587 * Sets the handler for the hide event.
589 static VALUE c_on_hide (VALUE self)
591 CALLBACK_REG_HANDLER (hide);
596 * ee.on_delete_request { block } => nil
598 * Sets the handler for the delete request event.
600 static VALUE c_on_delete_request (VALUE self)
602 CALLBACK_REG_HANDLER (delete_request);
607 * ee.on_destroy { block } => nil
609 * Sets the handler for the destroy event.
611 static VALUE c_on_destroy (VALUE self)
613 CALLBACK_REG_HANDLER (destroy);
618 * ee.on_focus_in { block } => nil
620 * Sets the handler for the focus in event.
622 static VALUE c_on_focus_in (VALUE self)
624 CALLBACK_REG_HANDLER (focus_in);
629 * ee.on_focus_out { block } => nil
631 * Sets the handler for the focus out event.
633 static VALUE c_on_focus_out (VALUE self)
635 CALLBACK_REG_HANDLER (focus_out);
640 * ee.on_mouse_in { block } => nil
642 * Sets the handler for the mouse in event.
644 static VALUE c_on_mouse_in (VALUE self)
646 CALLBACK_REG_HANDLER (mouse_in);
651 * ee.on_mouse_out { block } => nil
653 * Sets the handler for the mouse out event.
655 static VALUE c_on_mouse_out (VALUE self)
657 CALLBACK_REG_HANDLER (mouse_out);
662 * ee.on_pre_render { block } => nil
664 * Sets the handler for the pre render event.
666 static VALUE c_on_pre_render (VALUE self)
668 CALLBACK_REG_HANDLER (pre_render);
673 * ee.on_post_render { block } => nil
675 * Sets the handler for the post render event.
677 static VALUE c_on_post_render (VALUE self)
679 CALLBACK_REG_HANDLER (post_render);
682 void Init_EcoreEvas (void)
684 cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
686 rb_define_private_method (rb_singleton_class (cEcoreEvas),
688 rb_define_method (cEcoreEvas, "initialize", c_init, -1);
689 rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
690 rb_define_method (cEcoreEvas, "delete", c_delete, 0);
691 rb_define_method (cEcoreEvas, "show", c_show, 0);
692 rb_define_method (cEcoreEvas, "hide", c_hide, 0);
693 rb_define_method (cEcoreEvas, "visible?", c_visible_get, 0);
694 rb_define_method (cEcoreEvas, "raise", c_raise, 0);
695 rb_define_method (cEcoreEvas, "lower", c_lower, 0);
696 rb_define_method (cEcoreEvas, "layer", c_layer_get, 0);
697 rb_define_method (cEcoreEvas, "layer=", c_layer_set, 1);
698 rb_define_method (cEcoreEvas, "evas", c_evas_get, 0);
699 rb_define_method (cEcoreEvas, "geometry", c_geometry_get, 0);
700 rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
701 rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
702 rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
703 rb_define_method (cEcoreEvas, "set_size_max", c_set_size_max, 2);
704 rb_define_method (cEcoreEvas, "move", c_move, 2);
705 rb_define_method (cEcoreEvas, "resize", c_resize, 2);
706 rb_define_method (cEcoreEvas, "title", c_title_get, 0);
707 rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
708 rb_define_method (cEcoreEvas, "borderless?", c_borderless_get, 0);
709 rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
710 rb_define_method (cEcoreEvas, "shaped?", c_shaped_get, 0);
711 rb_define_method (cEcoreEvas, "shaped=", c_shaped_set, 1);
712 rb_define_method (cEcoreEvas, "sticky?", c_sticky_get, 0);
713 rb_define_method (cEcoreEvas, "sticky=", c_sticky_set, 1);
714 rb_define_method (cEcoreEvas, "rotation", c_rotation_get, 0);
715 rb_define_method (cEcoreEvas, "rotation=", c_rotation_set, 1);
717 rb_define_method (cEcoreEvas, "on_resize", c_on_resize, 0);
718 rb_define_method (cEcoreEvas, "on_move", c_on_move, 0);
719 rb_define_method (cEcoreEvas, "on_show", c_on_show, 0);
720 rb_define_method (cEcoreEvas, "on_hide", c_on_hide, 0);
721 rb_define_method (cEcoreEvas, "on_delete_request", c_on_delete_request, 0);
722 rb_define_method (cEcoreEvas, "on_destroy", c_on_destroy, 0);
723 rb_define_method (cEcoreEvas, "on_focus_in", c_on_focus_in, 0);
724 rb_define_method (cEcoreEvas, "on_focus_out", c_on_focus_out, 0);
725 rb_define_method (cEcoreEvas, "on_mouse_in", c_on_mouse_in, 0);
726 rb_define_method (cEcoreEvas, "on_mouse_out", c_on_mouse_out, 0);
727 rb_define_method (cEcoreEvas, "on_pre_render", c_on_pre_render, 0);
728 rb_define_method (cEcoreEvas, "on_post_render", c_on_post_render, 0);