views:

155

answers:

1

I am writing a custom widget for Gtkmm that is supposed to display a huge dataset (imagine something like a 4096x256 character datasheet).

Mostly for reasons of elegance, but also for a possible usage in a Glade/Gtk-Builder editor, I want this widget to support ScrolledWindow natively, that is, once it is set as the child of ScrolledWindow, it is recognized as a scrollable widget, allowing to set horizontal and vertical Adjustment objects on it, which it can subsequently tamper with.

It appears to do so, I need to do something like this in the constructor of my widget:

// get Gtk C type from wrapper class
GtkWidget* gwidget = this->gobj();

// imagine code here that magically creates a gobject signal, 
// that we can catch in C++.
// this is actually the part which I don't know how to do.
guint my_signal = magic_way_to_create_this_signal(
                   &MyClass::rainbow_unicorn_signal_handler);

// make ScrolledWindow recognize this window as scrollable
GTK_WIDGET_GET_CLASS(gwidget)->set_scroll_adjustments_signal = my_signal;

Later on, the signal emitted by ScrolledWindow when the widget is added needs to be caught by my Widget through a signal proxy method or something? I have no idea.

How can I do this?

A: 

The 'magic_way_to_create_this_signal' is g_signal_new(). You call it in your widget's my_widget_class_init() function which is part of the GObject way of defining a class. I'm not exactly sure what the equivalent is in Gtkmm.

See also the footnote in the GTK docs, where it is explained why making a widget natively scrollable is such a hassle.

You could also put your widget into a Gtk::Viewport which adds scrolling capabilities to its child widget.

ptomato
The C++ bindings use libsigc++ for signal management. I don't know how this will cope with plain C signals though...
ntd
Maybe it would make sense just to implement that signal in C, because the `guint` is a signal handler ID determined by GObject's internals.
ptomato