Using rulers (connecting signals)




Currently it is quite difficult to set up rulers properly.
You need to pass motion_notify_event signals from the 'canvas' area
to the rulers, so that they can update their little arrow markers.
testgtk uses this code:

      gtk_signal_connect_object (
        GTK_OBJECT (window), 
	"motion_notify_event",
	GTK_SIGNAL_FUNC(
          GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event),
	GTK_OBJECT (ruler));

This is too difficult for Glade to set up. My current solution is to
connect a simple motion_notify_event handler to the 'canvas' area
which does this:

gboolean
on_drawingarea1_motion_notify_event    (GtkWidget       *widget,
                                        GdkEventMotion  *event,
                                        gpointer         user_data)
{
  GtkWidgetClass *klass;
  GtkWidget *hruler, *vruler;

  hruler = lookup_widget (widget, "hruler1");
  vruler = lookup_widget (widget, "vruler1");

  klass = GTK_WIDGET_CLASS (GTK_OBJECT (hruler)->klass);
  (klass->motion_notify_event) (hruler, event);

  klass = GTK_WIDGET_CLASS (GTK_OBJECT (vruler)->klass);
  (klass->motion_notify_event) (vruler, event);

  return FALSE;
}

I'm not sure it is correct to call a class function like this
(though the testgtk code is doing something very similar).

It would be better if a similar convenience function were added
to GtkRuler.

Damon




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