Re: tooltips



Tristan Van Berkom wrote:
Paul Pogonyshev wrote:
[...]

But I have many areas, the widget is much like two-dimensional grid.
There can easily be like 100 areas.  Think of GtkTreeView with many
columns.

Besides, it seems that GtkTooltips works only with widgets.  So, I'd
have to wrap each `area' in a separate widget which is cumbersome.
The widget is scrollable and on overall, there can be thousands of
those areas.  This means that either the overhead would be really bad
or I'd have to write some evil code to create widgets for only those
areas that are visible in the viewport, gah...
 

Its not that bad, I'm sure many applications have the same need;
just install a handler for "motion-notify-event" (make sure that
your widget has been realized with the correct event mask)
and call gtk_tooltips_set_tip() whenever the tooltip should change.

You are probably right, but I haven't been able to make the tips show
up :(  I didn't even manage to add tooltips to a GtkTextView (not even
after gtk_widget_add_events (text_view, GDK_POINTER_MOTION_MASK) and
unwrapping it from GtkScrolledWindow.)

My widget uses two windows, but the `motion-notify-event' signal does
get emited on one of them, my handler is invoked.  But the tooltips
just don't appear :(

Window setup code is below.  Any ideas?

Paul



static void
gtk_sgf_tree_view_realize (GtkWidget *widget)
{
  GtkSgfTreeView *view = GTK_SGF_TREE_VIEW (widget);
  GdkWindowAttr attributes;
  const gint attributes_mask = (GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL
                                | GDK_WA_COLORMAP);
  const gint event_mask = (GDK_EXPOSURE_MASK
                           | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
                           | GDK_POINTER_MOTION_MASK);

  if (!view->hadjustment || !view->vadjustment)
    gtk_sgf_tree_view_set_scroll_adjustments (view, NULL, NULL);

  if (view->current_tree) {
    sgf_game_tree_get_map_dimensions (view->current_tree,
                                      &view->map_width, &view->map_height);

    update_view_port (view);
  }

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.event_mask  = 0;
  attributes.x           = widget->allocation.x;
  attributes.y           = widget->allocation.y;
  attributes.width       = widget->allocation.width;
  attributes.height      = widget->allocation.height;
  attributes.wclass      = GDK_INPUT_OUTPUT;
  attributes.visual      = gtk_widget_get_visual (widget);
  attributes.colormap    = gtk_widget_get_colormap (widget);
  attributes.window_type = GDK_WINDOW_CHILD;

  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                   &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, view);

  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);

  attributes.event_mask  = gtk_widget_get_events (widget) | event_mask;
  attributes.x           = - view->hadjustment->value;
  attributes.y           = - view->vadjustment->value;
  attributes.width       = view->hadjustment->upper;
  attributes.height      = view->vadjustment->upper;

  view->output_window = gdk_window_new (widget->window,
                                        &attributes, attributes_mask);
  gdk_window_set_user_data (view->output_window, view);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, view->output_window,
                            GTK_STATE_NORMAL);

  gdk_window_show (view->output_window);

  GTK_WIDGET_CLASS (parent_class)->realize (widget);
}



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