/* * $Id: rb_smart.c 387 2006-09-23 19:52:31Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "rb_evas_main.h" #include "rb_evas.h" #include "rb_evas_object.h" #define SMART_CB_BODY(name) \ VALUE self = TO_EVAS_OBJECT (o); \ static ID id; \ \ if (!id) \ id = rb_intern ("smart_"#name); \ \ if (!rb_respond_to (self, id)) \ return; #define SMART_CB(name) \ static void smart_##name (Evas_Object *o) \ { \ SMART_CB_BODY (name); \ rb_funcall (self, id, 0); \ } #define SMART_CB_OBJ(name) \ static void smart_##name (Evas_Object *o, Evas_Object *other) \ { \ SMART_CB_BODY (name); \ rb_funcall (self, id, 1, TO_EVAS_OBJECT (other)); \ } #define SMART_CB_COORD(name) \ static void smart_##name (Evas_Object *o, Evas_Coord a, Evas_Coord b) \ { \ SMART_CB_BODY (name); \ rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \ } static ID id_smart_object; SMART_CB (delete); SMART_CB (show); SMART_CB (hide); SMART_CB (clip_unset); SMART_CB_OBJ (clip_set); SMART_CB_COORD (move); SMART_CB_COORD (resize); static void smart_color_set (Evas_Object *o, int r, int g, int b, int a) { SMART_CB_BODY (color_set); rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b), INT2FIX (a)); } static VALUE c_inherited (VALUE klass, VALUE child) { rb_const_set (child, id_smart_object, Qnil); return Qnil; } static VALUE c_init (VALUE self, VALUE evas) { VALUE klass, smart, name; Evas_Smart **s = NULL; CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); GET_OBJ (self, RbEvasObject, s2); klass = rb_obj_class (self); /* check whether the smart object has been created already */ smart = rb_const_get (klass, id_smart_object); if (!NIL_P (smart)) Data_Get_Struct (smart, Evas_Smart *, s); else { name = rb_class_path (klass); smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s); *s = evas_smart_new (StringValuePtr (name), NULL, smart_delete, NULL, NULL, NULL, NULL, NULL, smart_move, smart_resize, smart_show, smart_hide, smart_color_set, smart_clip_set, smart_clip_unset, NULL); rb_mod_remove_const(klass, ID2SYM (id_smart_object)); rb_const_set (klass, id_smart_object, smart); } s2->real = evas_object_smart_add (e->real, *s); rb_call_super (1, &evas); return self; } static VALUE c_add_member (VALUE self, VALUE member) { GET_OBJ (self, RbEvasObject, e); GET_OBJ (member, RbEvasObject, e2); /* weird order of arguments */ evas_object_smart_member_add (e2->real, e->real); return Qnil; } void Init_Smart (void) { VALUE c = rb_define_class_under (mEvas, "Smart", cEvasObject); rb_define_singleton_method (c, "inherited", c_inherited, 1); rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "add_member", c_add_member, 1); id_smart_object = rb_intern ("SMART_OBJECT"); }