Re: Gtk2::MozEmbed + DOM



On Mon, 2005-03-21 at 10:55 +0100, Scott Lanning wrote:

Need a marshaller for dom event signals, apparently because of
the `gpointer dom_event' arguments?

Yes, like muppet said, the normal marshaller can't know how to convert
these pointers to Perl objects.  I think you can just use some standard
conversion stuff: Declare conversion functions that convert from pointer
to SV (wrap the pointer with an opaque scalar and bless that scalar into
some namespace) and from SV back to pointer (retrieve the pointer that
corresponds to the numerical value of the scalar our scalar points to):

SV *
newSVnsIDOMKeyEvent (nsIDOMKeyEvent *event)
{
        SV *sv = newSV (0);

        return sv_setref_pv (sv, "Gtk2::MozEmebd::KeyEvent", event);
}

nsIDOMKeyEvent *
SvnsIDOMKeyEvent (SV *event)
{
        return INT2PTR (nsIDOMKeyEvent *, SvIV (SvRV (event)));

}

If you follow the example of gtk2perl_moz_embed_new_window_marshal you
then just need to do:

XPUSHs (sv_2mortal (newSVnsIDOMKeyEvent ((nsIDOMKeyEvent *)
                     g_value_get_pointer (param_values + 1))));

in the marshaller.  (Man, Evolution crashed three times while editing
this paragraph.)

Then you add a new package to GtkMozEmbed.xs:

MODULE = Gtk2::MozEmbed PACKAGE = Gtk2::MozEmbed::KeyEvent

And bind whatever methods of nsIDOMKeyEvent you want.  For how to do
this, I think the "Using XS With C++" section of `perldoc perlxs` is
worth a read.  For the typemap you can just use:

TYPEMAP

nsIDOMKeyEvent *        T_GPERL_GENERIC_WRAPPER

And skip the OUTPUT and INPUT sections.  T_GPERL_GENERIC_WRAPPER will
automatically call newSVnsIDOMKeyEvent and SvnsIDOMKeyEvent for you.

-- 
HTH,
-Torsten




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]