/*
- * $Id: rb_edje.c 47 2004-07-26 13:24:50Z tilman $
+ * $Id: rb_edje.c 48 2004-07-31 13:46:07Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include "rb_edje_main.h"
#include "rb_part.h"
+typedef struct {
+ Evas_Object *real;
+ VALUE parts;
+ VALUE callbacks;
+} RbEdje;
+
VALUE cEdje;
-static VALUE part_hashes;
-static void c_free (Evas_Object **e)
+static void c_mark (RbEdje *e)
{
- c_evas_object_free (e);
+ c_evas_object_mark (&e->real);
+
+ rb_gc_mark (e->parts);
+ rb_gc_mark (e->callbacks);
+}
- rb_hash_aset (part_hashes, INT2NUM ((long) e), Qnil);
+static void c_free (RbEdje *e)
+{
+ c_evas_object_free (&e->real);
edje_shutdown ();
}
static VALUE c_new (VALUE klass, VALUE evas)
{
VALUE self, argv[1];
- Evas_Object **edje;
+ RbEdje *edje;
CHECK_CLASS (evas, cEvas);
GET_OBJ (evas, Evas *, e);
edje_init ();
- self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
- c_free, edje);
- *edje = edje_object_add (*e);
+ self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
+
+ edje->real = edje_object_add (*e);
+ edje->parts = rb_hash_new ();
+ edje->callbacks = rb_ary_new ();
argv[0] = evas;
rb_obj_call_init (self, 1, argv);
return self;
}
+static VALUE c_freeze (VALUE self)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ edje_object_freeze (e->real);
+
+ return Qnil;
+}
+
+static VALUE c_thaw (VALUE self)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ edje_object_thaw (e->real);
+
+ return Qnil;
+}
+
static VALUE c_load (VALUE self, VALUE eet, VALUE group)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
Check_Type (eet, T_STRING);
Check_Type (group, T_STRING);
- if (!edje_object_file_set (*e, StringValuePtr (eet),
+ if (!edje_object_file_set (e->real, StringValuePtr (eet),
StringValuePtr (group)))
rb_raise (rb_eException, "Cannot load eet");
{
int w = 0, h = 0;
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
- edje_object_size_min_get (*e, &w, &h);
+ edje_object_size_min_get (e->real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
{
int w = 0, h = 0;
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
- edje_object_size_max_get (*e, &w, &h);
+ edje_object_size_max_get (e->real, &w, &h);
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
{
int r;
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
Check_Type (name, T_STRING);
- r = edje_object_part_exists (*e, StringValuePtr (name));
+ r = edje_object_part_exists (e->real, StringValuePtr (name));
return r ? Qtrue : Qfalse;
}
static VALUE c_part_get (VALUE self, VALUE name)
{
- VALUE parts, part;
+ VALUE part;
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
Check_Type (name, T_STRING);
- if (!edje_object_part_exists (*e, StringValuePtr (name)))
+ if (!edje_object_part_exists (e->real, StringValuePtr (name)))
return Qnil;
- parts = rb_hash_aref (part_hashes, INT2NUM ((long) (e)));
- if (NIL_P (parts)) {
- parts = rb_hash_new ();
- rb_hash_aset (part_hashes, INT2NUM ((long) e), parts);
- }
-
- if (NIL_P (part = rb_hash_aref (parts, name))) {
+ if (NIL_P (part = rb_hash_aref (e->parts, name))) {
part = TO_PART (self, name);
- rb_hash_aset (parts, name, part);
+ rb_hash_aset (e->parts, name, part);
}
return part;
static VALUE c_on_text_changed (VALUE self)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
if (!rb_block_given_p ())
return Qnil;
- edje_object_text_change_cb_set (*e, on_text_changed,
+ edje_object_text_change_cb_set (e->real, on_text_changed,
(void *) rb_block_proc ());
return Qnil;
}
-static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source)
+static VALUE c_emit_signal (VALUE self, VALUE emission, VALUE source)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
Check_Type (emission, T_STRING);
Check_Type (source, T_STRING);
- edje_object_signal_emit (*e, StringValuePtr (emission),
+ edje_object_signal_emit (e->real, StringValuePtr (emission),
StringValuePtr (source));
return Qnil;
static void on_signal (void *data, Evas_Object *o,
const char *emission, const char *src)
{
- rb_funcall ((VALUE) data, rb_intern ("call"), 1,
+ rb_funcall ((VALUE) data, rb_intern ("call"), 2,
rb_str_new2 (emission), rb_str_new2 (src));
}
static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
{
- GET_OBJ (self, Evas_Object *, e);
+ VALUE cb;
+
+ GET_OBJ (self, RbEdje, e);
Check_Type (signal, T_STRING);
Check_Type (src, T_STRING);
if (!rb_block_given_p ())
return Qnil;
- edje_object_signal_callback_add (*e, StringValuePtr (signal),
+ cb = rb_block_proc ();
+ rb_ary_push (e->callbacks, cb);
+
+ edje_object_signal_callback_add (e->real, StringValuePtr (signal),
StringValuePtr (src), on_signal,
- (void *) rb_block_proc ());
+ (void *) cb);
return Qnil;
}
static VALUE c_play_get (VALUE self)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
- return edje_object_play_get (*e) ? Qtrue : Qfalse;
+ return edje_object_play_get (e->real) ? Qtrue : Qfalse;
}
static VALUE c_play_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
CHECK_BOOL(val);
- edje_object_play_set (*e, val == Qtrue);
+ edje_object_play_set (e->real, val == Qtrue);
return Qnil;
}
static VALUE c_animation_get (VALUE self)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
- return edje_object_animation_get (*e) ? Qtrue : Qfalse;
+ return edje_object_animation_get (e->real) ? Qtrue : Qfalse;
}
static VALUE c_animation_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Evas_Object *, e);
+ GET_OBJ (self, RbEdje, e);
CHECK_BOOL(val);
- edje_object_animation_set (*e, val == Qtrue);
+ edje_object_animation_set (e->real, val == Qtrue);
return Qnil;
}
cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
rb_define_singleton_method (cEdje, "new", c_new, 1);
+ rb_define_method (cEdje, "freeze", c_freeze, 0);
+ rb_define_method (cEdje, "thaw", c_thaw, 0);
rb_define_method (cEdje, "load", c_load, 2);
rb_define_method (cEdje, "get_size_min", c_get_size_min, 0);
rb_define_method (cEdje, "get_size_max", c_get_size_max, 0);
rb_define_method (cEdje, "part_exists?", c_part_exists_get, 1);
rb_define_method (cEdje, "part", c_part_get, 1);
rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
- rb_define_method (cEdje, "signal_emit", c_signal_emit, 1);
+ rb_define_method (cEdje, "emit_signal", c_emit_signal, 2);
rb_define_method (cEdje, "on_signal", c_on_signal, 2);
rb_define_method (cEdje, "play?", c_play_get, 0);
rb_define_method (cEdje, "play=", c_play_set, 1);
rb_define_method (cEdje, "animation?", c_animation_get, 0);
rb_define_method (cEdje, "animation=", c_animation_set, 1);
-
- part_hashes = rb_hash_new ();
- rb_global_variable (&part_hashes);
}