/* * $Id: rb_part.c 384 2006-07-23 08:21:33Z 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_edje_main.h" #include "rb_edje.h" static VALUE cPart; static inline char *GET_NAME (VALUE o) { static ID id; VALUE name; if (!id) id = rb_intern ("@name"); name = rb_ivar_get (o, id); return StringValuePtr (name); } static inline VALUE GET_EDJE (VALUE o) { static ID id; if (!id) id = rb_intern ("@edje"); return rb_ivar_get (o, id); } VALUE TO_PART (VALUE edje, VALUE name) { VALUE self; CHECK_CLASS (edje, cEdje); Check_Type (name, T_STRING); self = rb_obj_alloc (cPart); rb_iv_set (self, "@edje", edje); rb_iv_set (self, "@name", rb_str_dup (name)); rb_obj_call_init (self, 0, NULL); return self; } /* * call-seq: * part.geometry => array * * Returns an array containing the geometry of part. */ static VALUE c_geometry_get (VALUE self) { int x = 0, y = 0, w = 0, h = 0; GET_OBJ (GET_EDJE (self), RbEdje, e); edje_object_part_geometry_get (e->real.real, GET_NAME (self), (Evas_Coord *) &x, (Evas_Coord *) &y, (Evas_Coord *) &w, (Evas_Coord *) &h); return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w), INT2FIX (h)); } /* * call-seq: * part.swallow(evasobject) => nil * * Swallows an Evas::EvasObject into part. */ static VALUE c_swallow (VALUE self, VALUE target) { GET_OBJ (GET_EDJE (self), RbEdje, e); CHECK_CLASS (target, cEvasObject); GET_OBJ (target, RbEvasObject, t); edje_object_part_swallow (e->real.real, GET_NAME (self), t->real); rb_iv_set (self, "swallowed_obj", target); return Qnil; } /* * call-seq: * part.unswallow => nil * * Unswallows the Evas::EvasObject swallowed by * part. */ static VALUE c_unswallow (VALUE self) { Evas_Object *o; GET_OBJ (GET_EDJE (self), RbEdje, e); o = edje_object_part_swallow_get (e->real.real, GET_NAME (self)); if (!o) { rb_raise (rb_eException, "Part didn't swallow an EvasObject"); return Qnil; } edje_object_part_unswallow (e->real.real, o); rb_iv_set (self, "swallowed_obj", Qnil); return Qnil; } /* * call-seq: * part.swallowed_object => evasobject or nil * * Returns the Evas::EvasObject swallowed by * part or nil if part didn't swallow an * Evas::EvasObject. */ static VALUE c_swallowed_object_get (VALUE self) { Evas_Object *o; GET_OBJ (GET_EDJE (self), RbEdje, e); o = edje_object_part_swallow_get (e->real.real, GET_NAME (self)); if (!o) return Qnil; return TO_EVAS_OBJECT (o); } /* * call-seq: * part.text => string * * Returns the text of part. */ static VALUE c_text_get (VALUE self) { const char *s; GET_OBJ (GET_EDJE (self), RbEdje, e); s = edje_object_part_text_get (e->real.real, GET_NAME (self)); return s ? rb_str_new2 (s) : Qnil; } /* * call-seq: * part.text(string) * * Sets the text of part. */ static VALUE c_text_set (VALUE self, VALUE text) { GET_OBJ (GET_EDJE (self), RbEdje, e); Check_Type (text, T_STRING); edje_object_part_text_set (e->real.real, GET_NAME (self), StringValuePtr (text)); return Qnil; } /* * call-seq: * part.get_drag_value => array * * Returns the drag value of part. * * part.set_drag_value(1.5, 2.5) #=> nil * part.get_drag_value #=> [1.5, 2.5] */ static VALUE c_get_drag_value (VALUE self) { double dx = 0, dy = 0; GET_OBJ (GET_EDJE (self), RbEdje, e); edje_object_part_drag_value_get (e->real.real, GET_NAME (self), &dx, &dy); return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy)); } /* * call-seq: * part.set_drag_value(dx, dy) => nil * * Sets the drag value of part. * * part.set_drag_value(1.5, 2.5) #=> nil */ static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy) { GET_OBJ (GET_EDJE (self), RbEdje, e); if (!FIXNUM_P (dx)) Check_Type (dx, T_FLOAT); if (!FIXNUM_P (dy)) Check_Type (dy, T_FLOAT); edje_object_part_drag_value_set (e->real.real, GET_NAME (self), NUM2DBL (dx), NUM2DBL (dy)); return Qnil; } static VALUE c_state_get (VALUE self) { const char *name; double val = 0.0; GET_OBJ (GET_EDJE (self), RbEdje, e); name = edje_object_part_state_get (e->real.real, GET_NAME (self), &val); return rb_ary_new3 (2, rb_str_new2 (name), rb_float_new (val)); } void Init_Part (void) { cPart = rb_define_class_under (mEdje, "Part", rb_cObject); rb_define_attr (cPart, "edje", 1, 0); rb_define_attr (cPart, "name", 1, 0); /* not publically instantiable yet */ rb_define_private_method (rb_singleton_class (cPart), "new", NULL, 0); rb_define_method (cPart, "geometry", c_geometry_get, 0); rb_define_method (cPart, "swallow", c_swallow, 1); rb_define_method (cPart, "unswallow", c_unswallow, 1); rb_define_method (cPart, "swallowed_object", c_swallowed_object_get, 0); rb_define_method (cPart, "text", c_text_get, 0); rb_define_method (cPart, "text=", c_text_set, 1); rb_define_method (cPart, "get_drag_value", c_get_drag_value, 0); rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2); rb_define_method (cPart, "state", c_state_get, 0); }