From 2798e153edf68de89ca2ea53732d01ef7c7f0b64 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Mon, 14 Mar 2005 20:51:40 +0000 Subject: [PATCH] Started EvasObject callback implementation. --- ChangeLog | 7 +- src/Makefile.am | 3 +- src/rb_evas_main.c | 4 +- src/rb_evas_object.c | 4 +- src/rb_evas_object.h | 3 +- src/rb_evas_object_events.c | 129 ++++++++++++++++++++++++++++++++++++ src/rb_evas_object_events.h | 26 ++++++++ 7 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 src/rb_evas_object_events.c create mode 100644 src/rb_evas_object_events.h diff --git a/ChangeLog b/ChangeLog index 519b521..1024168 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -$Id: ChangeLog 63 2004-08-12 19:36:40Z tilman $ +$Id: ChangeLog 281 2005-03-14 20:51:40Z tilman $ + +2005-03-14 Tilman Sauerbeck (tilman at code-monkey de) + * src/Makefile.am, src/rb_evas_object_events.[ch], + src/rb_evas_main.c, src/rb_evas_object.[ch]: Started EvasObject + callback implementation 2004-08-12 Tilman Sauerbeck (tilman at code-monkey de) * Makefile.am, src/Makefile.am, src/rb_evas_main.c, diff --git a/src/Makefile.am b/src/Makefile.am index 860f5b8..d1e46b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am 118 2004-10-18 20:16:11Z tilman $ +## $Id: Makefile.am 281 2005-03-14 20:51:40Z tilman $ AM_CFLAGS = $(EVAS_CFLAGS) INCLUDES = -I$(RUBYDIR) @@ -9,6 +9,7 @@ extdir = $(RUBYSITEDIR) evas_la_SOURCES = rb_evas_main.c rb_evas_main.h \ rb_evas.c rb_evas.h \ rb_evas_object.c rb_evas_object.h \ + rb_evas_object_events.c rb_evas_object_events.h \ rb_rectangle.c rb_rectangle.h \ rb_line.c rb_line.h \ rb_gradient.c rb_gradient.h \ diff --git a/src/rb_evas_main.c b/src/rb_evas_main.c index 958e877..1c8b812 100644 --- a/src/rb_evas_main.c +++ b/src/rb_evas_main.c @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_main.c 61 2004-08-12 10:04:07Z tilman $ + * $Id: rb_evas_main.c 281 2005-03-14 20:51:40Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -25,6 +25,7 @@ #include "rb_evas_main.h" #include "rb_evas.h" #include "rb_evas_object.h" +#include "rb_evas_object_events.h" #include "rb_rectangle.h" #include "rb_line.h" #include "rb_gradient.h" @@ -39,6 +40,7 @@ void Init_evas (void) Init_Evas (); Init_EvasObject (); + Init_EvasObjectEvents (); Init_Rectangle (); Init_Line (); Init_Gradient (); diff --git a/src/rb_evas_object.c b/src/rb_evas_object.c index 4487d1d..b32f2b8 100644 --- a/src/rb_evas_object.c +++ b/src/rb_evas_object.c @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_object.c 106 2004-08-29 15:56:35Z tilman $ + * $Id: rb_evas_object.c 281 2005-03-14 20:51:40Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -49,6 +49,7 @@ VALUE TO_EVAS_OBJECT (Evas_Object *o) void c_evas_object_mark (RbEvasObject *e) { rb_gc_mark (e->parent); + rb_gc_mark (e->callbacks); } void c_evas_object_free (RbEvasObject *e, bool free_mem) @@ -68,6 +69,7 @@ static VALUE c_init (VALUE self, VALUE parent) evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self); e->parent = parent; + e->callbacks = rb_hash_new (); return self; } diff --git a/src/rb_evas_object.h b/src/rb_evas_object.h index 91a90c5..ae60574 100644 --- a/src/rb_evas_object.h +++ b/src/rb_evas_object.h @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_object.h 68 2004-08-16 15:42:19Z tilman $ + * $Id: rb_evas_object.h 281 2005-03-14 20:51:40Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -28,6 +28,7 @@ typedef struct { Evas_Object *real; VALUE parent; + VALUE callbacks; } RbEvasObject; void Init_EvasObject (void); diff --git a/src/rb_evas_object_events.c b/src/rb_evas_object_events.c new file mode 100644 index 0000000..2ac56fa --- /dev/null +++ b/src/rb_evas_object_events.c @@ -0,0 +1,129 @@ +/* + * $Id: rb_evas_object_events.c 281 2005-03-14 20:51:40Z tilman $ + * + * Copyright (C) 2005 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 + +#include "rb_evas_main.h" +#include "rb_evas.h" +#include "rb_evas_object.h" + +#define CALLBACK_HANDLER_FUNC(name) \ + static void on_##name (void *data, Evas *evas, \ + Evas_Object *evas_obj, void *event) \ +{ \ + RbEvasObject *e = (RbEvasObject *) data; \ + VALUE argv[1] = {(VALUE) event}, klass, cb, ev, s; \ +\ + s = rb_str_new2 (#name); \ + klass = rb_hash_aref (event_classes, s); \ + ev = rb_class_new_instance(1, argv, klass); \ + cb = rb_hash_aref (e->callbacks, s); \ +\ + rb_funcall (cb, rb_intern ("call"), 1, ev); \ +} + +#define CALLBACK_HANDLER_METHOD(name, callback) \ + GET_OBJ (self, RbEvasObject, e); \ +\ + if (!rb_block_given_p ()) \ + return Qnil; \ +\ + rb_hash_aset (e->callbacks, rb_str_new2 (#name), \ + rb_block_proc ()); \ + evas_object_event_callback_add (e->real, EVAS_CALLBACK_##callback, \ + on_##name, e); \ +\ + return Qnil; + +#define CALLBACK_REGISTER(name, clsname) \ + rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0); \ +\ + c = rb_define_class_under (mEvas, (clsname), rb_cObject); \ + rb_define_private_method (rb_singleton_class (c), "new", NULL, 0); \ + rb_define_private_method (c, "initialize", c_ev_##name##_init, 1); \ + rb_hash_aset (event_classes, rb_str_new2 (#name), c); + +static VALUE event_classes; + +static VALUE c_ev_mouse_down_init (VALUE self, VALUE ev) +{ + Evas_Event_Mouse_Down *e = (Evas_Event_Mouse_Down *) ev; + + rb_iv_set (self, "@button", INT2FIX (e->button)); + + return self; +} + +static VALUE c_ev_mouse_up_init (VALUE self, VALUE ev) +{ + Evas_Event_Mouse_Up *e = (Evas_Event_Mouse_Up *) ev; + + rb_iv_set (self, "@button", INT2FIX (e->button)); + + return self; +} + +static VALUE c_ev_mouse_move_init (VALUE self, VALUE ev) +{ + Evas_Event_Mouse_Move *e = (Evas_Event_Mouse_Move *) ev; + + rb_iv_set (self, "@buttons", INT2FIX (e->buttons)); + + return self; +} + +CALLBACK_HANDLER_FUNC (mouse_down); +CALLBACK_HANDLER_FUNC (mouse_up); +CALLBACK_HANDLER_FUNC (mouse_move); + +static VALUE c_on_mouse_down (VALUE self) +{ + CALLBACK_HANDLER_METHOD (mouse_down, MOUSE_DOWN); +} + +static VALUE c_on_mouse_up (VALUE self) +{ + CALLBACK_HANDLER_METHOD (mouse_up, MOUSE_UP); +} + +static VALUE c_on_mouse_move (VALUE self) +{ + CALLBACK_HANDLER_METHOD (mouse_move, MOUSE_MOVE); +} + +void Init_EvasObjectEvents (void) +{ + VALUE c; + + event_classes = rb_hash_new (); + rb_global_variable (&event_classes); + + CALLBACK_REGISTER (mouse_down, "MouseDownEvent"); + rb_define_attr (c, "button", 1, 0); + + CALLBACK_REGISTER (mouse_up, "MouseUpEvent"); + rb_define_attr (c, "button", 1, 0); + + CALLBACK_REGISTER (mouse_move, "MouseMoveEvent"); + rb_define_attr (c, "buttons", 1, 0); +} diff --git a/src/rb_evas_object_events.h b/src/rb_evas_object_events.h new file mode 100644 index 0000000..69d42b3 --- /dev/null +++ b/src/rb_evas_object_events.h @@ -0,0 +1,26 @@ +/* + * $Id: rb_evas_object_events.h 281 2005-03-14 20:51:40Z tilman $ + * + * Copyright (C) 2005 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 + */ + +#ifndef __RB_EVAS_OBJECT_EVENTS_H +#define __RB_EVAS_OBJECT_EVENTS_H + +void Init_EvasObjectEvents (void); + +#endif -- 2.30.2