Re: Reverse-wrapping gtkmm widgets to gtk+ (for glade3)



Murray Cumming schrieb:

> So we'd need some way to make sure that the properties are defined for
> our custom GType when that GType is defined, again maybe via a custom
> GObject init function.

Seems the properties get set by libglade, but are later overwritten by
the c'tor of the Glib::Property.

to test that, i derived the SimpleDraw not only from Gtk::DrawingArea
but also from a small class that takes a GObject in its c'tor and lists
the properties of the GObject like so i could see which properties
actually exist in the gobject (source code excerpts below):

the output then looks like this:

-------------------------------------
user-data: gpointer: NULL
name: gchararray: "simpledraw1"
parent: GtkContainer: ((gtkmm__GtkWindow*) 0x80a5860)
[...]
no-show-all: gboolean: FALSE

(simpledraw_gladetest:20042): glibmm-WARNING **: property.cc:117:
invalid property id 12 for "showblue" of type `GParamBoolean' in
`gtkmm__CustomObject_simpledraw'
showblue: gboolean: FALSE

(simpledraw_gladetest:20042): glibmm-WARNING **: property.cc:117:
invalid property id 40 for "redwidth" of type `GParamInt' in
`gtkmm__CustomObject_simpledraw'
redwidth: gint: 0
-------------------------------------

so it seems libglade even registered the custom_set_property_callback(),
which, of course cannot yet work because the Glib::Properties members of
the wrapper class do not yet exist.

Any idea how to temporarily disable the callbacks so we could just
remember the propertys values and re-set them later?

Another idea would be to patch the c'tor of Glib::Property so it reads
the current value of the gobjects property if lookup_property() succeeds
(property.h, l.130). but it still would first have to switch off the
callbacks. will investigate.


-------------------------------------
code excerpt:

class PropertySaver {
  public:
  PropertySaver() {}
    PropertySaver(GtkDrawingArea *gobject);
};

class SimpleDraw : public Gtk::DrawingArea, public PropertySaver {

[...]

PropertySaver::PropertySaver(GtkDrawingArea *gobject)
{

  guint n_properties;

  GParamSpec** props =
g_object_class_list_properties(G_OBJECT_GET_CLASS(gobject), &n_properties);

  GValue val;
  memset(&val, 0, sizeof(val));
  std::cout << "Properties: " << std::endl;
  for (int i=0; i<n_properties; i++) {
    std::cout << props[i]->name << ": " ;
    std::cout << g_type_name(props[i]->value_type) << ": ";

    g_value_unset(&val);
    g_value_init(&val, props[i]->value_type);
    g_object_get_property(G_OBJECT(gobject),props[i]->name,&val);
    gchar *tmp = g_strdup_value_contents(&val);
    std::cout << tmp << std::endl;
    g_free(tmp);
  }
}

[...]


  SimpleDraw::SimpleDraw(GtkDrawingArea* gobject)
  : PropertySaver(gobject),
    Gtk::DrawingArea(gobject),
    showblue(*this, "showblue", true),
    redwidth(*this, "redwidth", 42)
{

----------------------------------

  --o
-- 
Oliver Nittka
ESEM Grünau GmbH & Co. KG
Dornierstraße 6, 88677 Markdorf/Germany
phone: +49 7544 9583-25, fax: +49 7544 9583-60




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