Re: Displaying simple HTML in gtkmm app (got it!)



On Thursday 21 April 2005 19:06, erik_ohrnberger dme net wrote:

[snip]

>  The other thing that I noticed about this way of implementing this
> is that you are limited to a single instance of a window that can render
> HTML.  I was starting to create a C++ wrapper class, but found out that the
> lines:
>
>  g_signal_connect( G_OBJECT( document ), "request_url", G_CALLBACK(
> &gtkhtml::url_requested ), NULL );
>  g_signal_connect( G_OBJECT( document ), "link_clicked", G_CALLBACK(
> &gtkhtml::link_clicked ),  NULL );
>
>  are proving to be difficult to resolve.  How would you connect gtk+
> signals to a C++ class instance?  That appears to be the question now, for
> me at least.

I am not sure I have understood the question but if relates to making the 
callback aware of the class instance invoking the callback (say the one in 
whose constructor the call to g_signal_connect() was made) then pass the 
address of that instance (the this pointer) as the data argument, which is 
the last argument and is of type void*, thus:

  g_signal_connect( G_OBJECT( document ), "request_url",
                    G_CALLBACK(&gtkhtml::url_requested ), this );

then gtkhtml::url_requested() would use static_cast<>() to cast its last 
argument back to a pointer of the relevant type.

gtkhtml::url_requested() should have extern "C" linkage (and made a friend if 
it needs to have access to the class internals), but it looks as if it is a 
static class member function, which cannot have "C" linkage.  Using a static 
member function will work with some compilers (eg g++) but not with others - 
it is implementation dependent.

Chris.

-- 
Summer is y-cumen in, lhude sing, cuccu!
Groweth sed and bloweth med, springeth the wude nu.



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