+/*
+ * $Id$
+ *
+ * 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 <ruby.h>
+
+#include <Ecore_Evas.h>
+#include <rb_evas.h>
+
+#include "rb_ecore_evas_main.h"
+#include "rb_ecore_evas.h"
+
+#define GET_OBJ(obj, ee) \
+ Ecore_Evas **(ee) = NULL; \
+\
+ Data_Get_Struct ((obj), Ecore_Evas *, (ee)); \
+\
+ if (!*(ee)) { \
+ rb_raise (rb_eException, "EcoreEvas destroyed already"); \
+ return Qnil; \
+ }
+
+/* called by the child classes */
+void c_ecore_evas_free (Ecore_Evas **ee)
+{
+ if (*ee)
+ ecore_evas_free (*ee);
+
+ free (ee);
+}
+
+#if 0
+static VALUE c_init (int argc, VALUE argv, VALUE self)
+{
+ rb_iv_set (self, "@title", rb_str_new2 (""));
+ rb_iv_set (self, "@name", rb_str_new2 (""));
+ rb_iv_set (self, "@class", rb_str_new2 (""));
+ rb_iv_set (self, "@name", rb_str_new2 (""));
+
+ return self;
+}
+#endif
+
+static VALUE c_show (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ ecore_evas_show (*ee);
+
+ return Qnil;
+}
+
+static VALUE c_hide (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ ecore_evas_hide (*ee);
+
+ return Qnil;
+}
+
+static VALUE c_is_visible (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
+}
+
+static VALUE c_evas (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ return TO_EVAS (self, ecore_evas_get (*ee));
+}
+
+static VALUE c_resize (VALUE self, VALUE w, VALUE h)
+{
+ GET_OBJ (self, ee);
+
+ Check_Type (w, T_FIXNUM);
+ Check_Type (h, T_FIXNUM);
+
+ ecore_evas_resize (*ee, FIX2INT (w), FIX2INT (h));
+
+ return Qnil;
+}
+
+static VALUE c_title_get (VALUE self)
+{
+ const char *tmp;
+
+ GET_OBJ (self, ee);
+
+ if (!(tmp = ecore_evas_title_get (*ee)))
+ return Qnil;
+ else
+ return rb_str_new2 (tmp);
+}
+
+static VALUE c_title_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, ee);
+
+ Check_Type (val, T_STRING);
+
+ ecore_evas_title_set (*ee, STR2CSTR (val));
+
+ return Qnil;
+}
+
+static VALUE c_borderless_get (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
+}
+
+static VALUE c_borderless_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, ee);
+
+ /* make sure we're passed a boolean */
+ if (TYPE (val) != T_TRUE && TYPE (val) != T_FALSE) {
+ rb_raise (rb_eTypeError,
+ "wrong argument type %s (expected true or false)",
+ rb_obj_classname (val));
+ return Qnil;
+ }
+
+ ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0);
+
+ return Qnil;
+}
+
+static VALUE c_delete (VALUE self)
+{
+ GET_OBJ (self, ee);
+
+ /* reap our children */
+ rb_gc_start ();
+
+ ecore_evas_free (*ee);
+ *ee = NULL;
+
+ return Qnil;
+}
+
+void Init_EcoreEvas (void)
+{
+ cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
+
+ rb_define_private_method (rb_singleton_class (cEcoreEvas),
+ "new", NULL, 0);
+ /*rb_define_method (cEcoreEvas, "initialize", c_init, -1);*/
+ rb_define_method (cEcoreEvas, "delete", c_delete, 0);
+ rb_define_method (cEcoreEvas, "show", c_show, 0);
+ rb_define_method (cEcoreEvas, "hide", c_hide, 0);
+ rb_define_method (cEcoreEvas, "visible?", c_is_visible, 0);
+ rb_define_method (cEcoreEvas, "evas", c_evas, 0);
+ rb_define_method (cEcoreEvas, "resize", c_resize, 2);
+ rb_define_method (cEcoreEvas, "title", c_title_get, 0);
+ rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
+ rb_define_method (cEcoreEvas, "borderless", c_borderless_get, 0);
+ rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
+}
+