Re: How class deriving from GInitiallyUnowned should be wrapped?



On Thu, 2010-12-02 at 14:48 +0100, Murray Cumming wrote:
> On Tue, 2010-11-30 at 19:38 +0100, Krzesimir Nowak wrote:
> > Hi,
> > 
> > I'm looking at Gtk::CellRenderer and Gtk::FileFilter. Both C types
> > derives GInitiallyUnowned, but in gtkmm the former derives from
> > Gtk::Object and the latter - from Glib::Object. So first one can be
> > handled as a pointer, the second - as Glib::RefPtr only.
> 
> Yes, our Gtk::Object lets us avoid forcing use of RefPtr for many more
> types now that GtkObject is dead. I thought that using RefPtr for
> CellRenderer would be a step too far. I could change my mind though.

I was doing a Gsv::SourceGutterRenderer wrapper, so I too decided to
derive it from Gtk::Object instead of Glib::Object. Which leads me to
another question: how to wrap a function taking GType as a parameter?
Said function is:

GtkSourceGutterRenderer *
gtk_source_gutter_insertv (GtkSourceGutter *gutter,
                           GType            gtype,
                           gint             position,
                           guint            num_parameters,
                           GParameter      *parameters);

where gtype must be a GType deriving from GtkSourceGutterRenderer.

My idea was wrapping it as:
Gsv::SourceGutterRenderer*
Gsv::SourceGutter::insert(const Glib::ConstructParams& params,
                          int position);

If I could get a Glib::Class instance (or reference/pointer to it), then
inside the method I could use Glib::Class::get_type () to get C++ GType
and then somehow get its C counterpart. In that way I could obtain all
needed data for this C function. Additionally it would look nice - just
two parameters. But there are two unclear places - getting Glib::Class
instance and somehow getting its C counterpart. Also user should worry
about passing Stuff_Class things. 

During writing previous solution another one came to my mind - using a
method template:

template<typename SGRType> // SourceGutterRendererType
Gsv::SourceGutterRenderer*
Gsv::SourceGutter::insert(const Glib::ArrayHandle<GParameter>&
                                                            parameters,
                          int position)
{
  return Glib::wrap(gtk_source_gutter_insertv(gobj(),
                                              SGRType::get_base_type(),
                                              position,
                                              parameters.size(),
                                              parameters.data()));
}

Hm, looks like I probably answered myself my question. Sorry for the
blog style mail, but maybe this information will be useful for someone.

> FileFilter, RecentFilter, and Adjustment, however, must now (in gtkmm 3)
> be used via RefPtr.
> 
> >  With
> > GtkObject's demise should everything not deriving from GtkWidget or its
> > descendants be wrapped as Glib::Objects?  
> 
> Yes, that's generally true.
> 

Well, if the difference between Gtk::Object and Glib::Object is the same
as the one between GInitiallyUnowned and GObject (that is - both
primarily are used to have floating reference, or in other words - being
not owned by any portion of code) then I'm wondering if
GInitiallyUnowned should also be wrapped as Gtk::Object - constructor
will sink it anyway.



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