/*
- * $Id: rb_edje.c 48 2004-07-31 13:46:07Z tilman $
+ * $Id: rb_edje.c 51 2004-08-01 10:19:02Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include <ruby.h>
#include <Edje.h>
-#include <rb_evas.h>
-#include <rb_evas_object.h>
+#include <evas/rb_evas.h>
+#include <evas/rb_evas_object.h>
#define __RB_EDJE_C
+#include "rb_edje.h"
#include "rb_edje_main.h"
#include "rb_part.h"
-typedef struct {
- Evas_Object *real;
- VALUE parts;
- VALUE callbacks;
-} RbEdje;
-
VALUE cEdje;
static void c_mark (RbEdje *e)
rb_gc_mark (e->parts);
rb_gc_mark (e->callbacks);
+
+ if (!NIL_P (e->on_text_changed_cb))
+ rb_gc_mark (e->on_text_changed_cb);
}
static void c_free (RbEdje *e)
{
- c_evas_object_free (&e->real);
+ c_evas_object_free (&e->real, false);
edje_shutdown ();
}
static VALUE c_new (VALUE klass, VALUE evas)
{
VALUE self, argv[1];
- RbEdje *edje;
+ RbEdje *edje = NULL;
CHECK_CLASS (evas, cEvas);
- GET_OBJ (evas, Evas *, e);
+ GET_OBJ (evas, RbEvas, e);
edje_init ();
self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
- edje->real = edje_object_add (*e);
+ edje->real.real = edje_object_add (e->real);
edje->parts = rb_hash_new ();
edje->callbacks = rb_ary_new ();
+ edje->on_text_changed_cb = Qnil;
argv[0] = evas;
rb_obj_call_init (self, 1, argv);
{
GET_OBJ (self, RbEdje, e);
- edje_object_freeze (e->real);
+ edje_object_freeze (e->real.real);
return Qnil;
}
{
GET_OBJ (self, RbEdje, e);
- edje_object_thaw (e->real);
+ edje_object_thaw (e->real.real);
return Qnil;
}
Check_Type (eet, T_STRING);
Check_Type (group, T_STRING);
- if (!edje_object_file_set (e->real, StringValuePtr (eet),
+ if (!edje_object_file_set (e->real.real, StringValuePtr (eet),
StringValuePtr (group)))
rb_raise (rb_eException, "Cannot load eet");
GET_OBJ (self, RbEdje, e);
- edje_object_size_min_get (e->real, &w, &h);
+ edje_object_size_min_get (e->real.real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
GET_OBJ (self, RbEdje, e);
- edje_object_size_max_get (e->real, &w, &h);
+ edje_object_size_max_get (e->real.real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
Check_Type (name, T_STRING);
- r = edje_object_part_exists (e->real, StringValuePtr (name));
+ r = edje_object_part_exists (e->real.real, StringValuePtr (name));
return r ? Qtrue : Qfalse;
}
VALUE part;
GET_OBJ (self, RbEdje, e);
-
Check_Type (name, T_STRING);
- if (!edje_object_part_exists (e->real, StringValuePtr (name)))
+ if (!edje_object_part_exists (e->real.real, StringValuePtr (name)))
return Qnil;
if (NIL_P (part = rb_hash_aref (e->parts, name))) {
return part;
}
-static void on_text_changed (void *data, Evas_Object *e,
- const char *part)
+static void on_text_changed (void *data, Evas_Object *eo,
+ const char *part_name)
{
- rb_funcall ((VALUE) data, rb_intern ("call"), 1,
- rb_str_new2 (part));
+ VALUE self = (VALUE) data, part, name;
+
+ GET_OBJ (self, RbEdje, e);
+
+ name = rb_str_new2 (part_name);
+
+ if (NIL_P (part = rb_hash_aref (e->parts, name))) {
+ part = TO_PART (self, name);
+ rb_hash_aset (e->parts, name, part);
+ }
+
+ rb_funcall (e->on_text_changed_cb,
+ rb_intern ("call"), 1, part);
}
static VALUE c_on_text_changed (VALUE self)
if (!rb_block_given_p ())
return Qnil;
- edje_object_text_change_cb_set (e->real, on_text_changed,
- (void *) rb_block_proc ());
+ e->on_text_changed_cb = rb_block_proc ();
+
+ edje_object_text_change_cb_set (e->real.real, on_text_changed,
+ (void *) self);
return Qnil;
}
Check_Type (emission, T_STRING);
Check_Type (source, T_STRING);
- edje_object_signal_emit (e->real, StringValuePtr (emission),
+ edje_object_signal_emit (e->real.real, StringValuePtr (emission),
StringValuePtr (source));
return Qnil;
cb = rb_block_proc ();
rb_ary_push (e->callbacks, cb);
- edje_object_signal_callback_add (e->real, StringValuePtr (signal),
+ edje_object_signal_callback_add (e->real.real,
+ StringValuePtr (signal),
StringValuePtr (src), on_signal,
(void *) cb);
{
GET_OBJ (self, RbEdje, e);
- return edje_object_play_get (e->real) ? Qtrue : Qfalse;
+ return edje_object_play_get (e->real.real) ? Qtrue : Qfalse;
}
static VALUE c_play_set (VALUE self, VALUE val)
CHECK_BOOL(val);
- edje_object_play_set (e->real, val == Qtrue);
+ edje_object_play_set (e->real.real, val == Qtrue);
return Qnil;
}
{
GET_OBJ (self, RbEdje, e);
- return edje_object_animation_get (e->real) ? Qtrue : Qfalse;
+ return edje_object_animation_get (e->real.real) ? Qtrue : Qfalse;
}
static VALUE c_animation_set (VALUE self, VALUE val)
CHECK_BOOL(val);
- edje_object_animation_set (e->real, val == Qtrue);
+ edje_object_animation_set (e->real.real, val == Qtrue);
return Qnil;
}
/*
- * $Id: rb_part.c 48 2004-07-31 13:46:07Z tilman $
+ * $Id: rb_part.c 51 2004-08-01 10:19:02Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include <ruby.h>
#include <Edje.h>
-#include <rb_evas.h>
-#include <rb_evas_object.h>
#include "rb_edje_main.h"
#include "rb_edje.h"
return rb_ivar_get (o, id);
}
-static void c_mark (VALUE *self)
-{
- rb_gc_mark (GET_EDJE (*self));
-}
-
-static void c_free (VALUE *self)
-{
- edje_shutdown ();
-
- free (self);
-}
-
VALUE TO_PART (VALUE edje, VALUE name)
{
- VALUE self, *self2;
+ VALUE self;
CHECK_CLASS (edje, cEdje);
Check_Type (name, T_STRING);
- edje_init ();
-
- /* we only use Data_Make_Struct to be able to specify
- * mark and sweep hooks
- */
- self = Data_Make_Struct (cPart, VALUE, c_mark, c_free, self2);
- self2 = &self;
+ self = rb_obj_alloc (cPart);
rb_iv_set (self, "@edje", edje);
rb_iv_set (self, "@name", rb_str_dup (name));
{
int x = 0, y = 0, w = 0, h = 0;
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
- edje_object_part_geometry_get (*e, GET_NAME (self),
+ edje_object_part_geometry_get (e->real.real, GET_NAME (self),
(Evas_Coord *) &x,
(Evas_Coord *) &y,
(Evas_Coord *) &w,
static VALUE c_swallow (VALUE self, VALUE target)
{
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
CHECK_CLASS (target, cEvasObject);
- GET_OBJ (target, Evas_Object *, target2);
+ GET_OBJ (target, RbEvasObject, t);
- edje_object_part_swallow (*e, GET_NAME (self), *target2);
+ edje_object_part_swallow (e->real.real, GET_NAME (self), t->real);
return Qnil;
}
{
Evas_Object *o;
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
- if (!(o = edje_object_part_swallow_get (*e, GET_NAME (self)))) {
+ 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, o);
+ edje_object_part_unswallow (e->real.real, o);
return Qnil;
}
Evas_Object *o;
void *obj;
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
- if (!(o = edje_object_part_swallow_get (*e, GET_NAME (self))))
+ o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
+ if (!o)
return Qnil;
if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
{
const char *s;
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
- if (!(s = edje_object_part_text_get (*e, GET_NAME (self))))
- return Qnil;
- else
- return rb_str_new2 (s);
+ s = edje_object_part_text_get (e->real.real, GET_NAME (self));
+
+ return s ? rb_str_new2 (s) : Qnil;
}
static VALUE c_text_set (VALUE self, VALUE text)
{
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
Check_Type (text, T_STRING);
- edje_object_part_text_set (*e, GET_NAME (self),
+ edje_object_part_text_set (e->real.real, GET_NAME (self),
StringValuePtr (text));
return Qnil;
{
double dx = 0, dy = 0;
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ GET_OBJ (GET_EDJE (self), RbEdje, e);
- edje_object_part_drag_value_get (*e, GET_NAME (self), &dx, &dy);
+ 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));
}
static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
{
- GET_OBJ (GET_EDJE (self), Evas_Object *, e);
+ 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, GET_NAME (self),
+ edje_object_part_drag_value_set (e->real.real, GET_NAME (self),
NUM2DBL (dx), NUM2DBL (dy));
return Qnil;