diff options
author | Thomas Martitz <kugel@rockbox.org> | 2016-05-17 22:11:17 +0200 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2016-05-17 22:11:17 +0200 |
commit | ace28857b70d8a8fe97cdf29f937614eb13de781 (patch) | |
tree | 11c759eaec999dd5a934797546b35a1fa5d42179 /gtk | |
parent | 99d52264a609b61e8639f3c1087a78fedb0b9de8 (diff) | |
download | scintilla-mirror-ace28857b70d8a8fe97cdf29f937614eb13de781.tar.gz |
Enable g-ir-scanner to scan ScintillaObject signals
Currently, the ScintillaObject signals can't be used from python code via
gobject-introspection. This is because g-ir-scanner does not properly scan
the signals.
For signals, there is the additional requirement that parameters have are
registered GTypes. For the sci-notify signal, this can be accomplished by
boxing SCNotification.
In addition, g-ir-scanner also runs on Scintilla.h where it picks up
additional structs.
test/gi/ is updated accordingly. The test python script is enhanced
to showcase the signals (some fixes to the makefile are included as well).
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/ScintillaGTK.cxx | 35 | ||||
-rw-r--r-- | gtk/scintilla-marshal.c | 65 | ||||
-rw-r--r-- | gtk/scintilla-marshal.h | 25 | ||||
-rw-r--r-- | gtk/scintilla-marshal.list | 3 |
4 files changed, 96 insertions, 32 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 9fc8e4cc4..f9adbc9ce 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -3162,9 +3162,6 @@ void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_ container_class->forall = MainForAll; } -#define SIG_MARSHAL scintilla_marshal_NONE__INT_POINTER -#define MARSHAL_ARGUMENTS G_TYPE_INT, G_TYPE_POINTER - static void scintilla_class_init(ScintillaClass *klass) { try { OBJECT_CLASS *object_class = (OBJECT_CLASS*) klass; @@ -3179,20 +3176,20 @@ static void scintilla_class_init(ScintillaClass *klass) { G_STRUCT_OFFSET(ScintillaClass, command), NULL, //(GSignalAccumulator) NULL, //(gpointer) - SIG_MARSHAL, + scintilla_marshal_VOID__INT_OBJECT, G_TYPE_NONE, - 2, MARSHAL_ARGUMENTS); + 2, G_TYPE_INT, GTK_TYPE_WIDGET); scintilla_signals[NOTIFY_SIGNAL] = g_signal_new( SCINTILLA_NOTIFY, G_TYPE_FROM_CLASS(object_class), sigflags, G_STRUCT_OFFSET(ScintillaClass, notify), - NULL, - NULL, - SIG_MARSHAL, + NULL, //(GSignalAccumulator) + NULL, //(gpointer) + scintilla_marshal_VOID__INT_BOXED, G_TYPE_NONE, - 2, MARSHAL_ARGUMENTS); + 2, G_TYPE_INT, SCINTILLA_TYPE_NOTIFICATION); klass->command = NULL; klass->notify = NULL; @@ -3233,3 +3230,23 @@ void scintilla_release_resources(void) { } catch (...) { } } + +/* Define a dummy boxed type because g-ir-scanner is unable to + * recognize gpointer-derived types. Note that SCNotificaiton + * is always allocated on stack so copying is not appropriate. */ +static void *copy_(void *src) { return src; } +static void free_(void *doc) { } + +GType scnotification_get_type(void) +{ + static gsize type_id = 0; + if (g_once_init_enter (&type_id)) + { + gsize id = (gsize) g_boxed_type_register_static( + g_intern_static_string ("SCNotification"), + (GBoxedCopyFunc) copy_, + (GBoxedFreeFunc) free_); + g_once_init_leave(&type_id, id); + } + return (GType) type_id; +} diff --git a/gtk/scintilla-marshal.c b/gtk/scintilla-marshal.c index 5470a5ba5..c91bd0bcd 100644 --- a/gtk/scintilla-marshal.c +++ b/gtk/scintilla-marshal.c @@ -49,20 +49,20 @@ #endif /* !G_ENABLE_DEBUG */ -/* NONE:INT,POINTER (scintilla-marshal.list:1) */ +/* NONE:INT,OBJECT (scintilla-marshal.list:1) */ void -scintilla_marshal_VOID__INT_POINTER (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) +scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, + GValue *return_value G_GNUC_UNUSED, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint G_GNUC_UNUSED, + gpointer marshal_data) { - typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1, - gint arg_1, - gpointer arg_2, - gpointer data2); - GMarshalFunc_VOID__INT_POINTER callback; + typedef void (*GMarshalFunc_VOID__INT_OBJECT) (gpointer data1, + gint arg_1, + gpointer arg_2, + gpointer data2); + GMarshalFunc_VOID__INT_OBJECT callback; GCClosure *cc = (GCClosure*) closure; gpointer data1, data2; @@ -78,11 +78,48 @@ scintilla_marshal_VOID__INT_POINTER (GClosure *closure, data1 = g_value_peek_pointer (param_values + 0); data2 = closure->data; } - callback = (GMarshalFunc_VOID__INT_POINTER) (marshal_data ? marshal_data : cc->callback); + callback = (GMarshalFunc_VOID__INT_OBJECT) (marshal_data ? marshal_data : cc->callback); callback (data1, g_marshal_value_peek_int (param_values + 1), - g_marshal_value_peek_pointer (param_values + 2), + g_marshal_value_peek_object (param_values + 2), + data2); +} + +/* NONE:INT,BOXED (scintilla-marshal.list:2) */ +void +scintilla_marshal_VOID__INT_BOXED (GClosure *closure, + GValue *return_value G_GNUC_UNUSED, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint G_GNUC_UNUSED, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__INT_BOXED) (gpointer data1, + gint arg_1, + gpointer arg_2, + gpointer data2); + GMarshalFunc_VOID__INT_BOXED callback; + GCClosure *cc = (GCClosure*) closure; + gpointer data1, data2; + + g_return_if_fail (n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__INT_BOXED) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_int (param_values + 1), + g_marshal_value_peek_boxed (param_values + 2), data2); } diff --git a/gtk/scintilla-marshal.h b/gtk/scintilla-marshal.h index 9116a56c9..7d5e17bba 100644 --- a/gtk/scintilla-marshal.h +++ b/gtk/scintilla-marshal.h @@ -6,14 +6,23 @@ G_BEGIN_DECLS -/* NONE:INT,POINTER (scintilla-marshal.list:1) */ -extern void scintilla_marshal_VOID__INT_POINTER (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); -#define scintilla_marshal_NONE__INT_POINTER scintilla_marshal_VOID__INT_POINTER +/* NONE:INT,OBJECT (scintilla-marshal.list:1) */ +extern void scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +#define scintilla_marshal_NONE__INT_OBJECT scintilla_marshal_VOID__INT_OBJECT + +/* NONE:INT,BOXED (scintilla-marshal.list:2) */ +extern void scintilla_marshal_VOID__INT_BOXED (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); +#define scintilla_marshal_NONE__INT_BOXED scintilla_marshal_VOID__INT_BOXED G_END_DECLS diff --git a/gtk/scintilla-marshal.list b/gtk/scintilla-marshal.list index e5750ecb6..ddc8ae87e 100644 --- a/gtk/scintilla-marshal.list +++ b/gtk/scintilla-marshal.list @@ -1 +1,2 @@ -NONE:INT,POINTER +NONE:INT,OBJECT +NONE:INT,BOXED |