Re: tooltips and refcounts



On Mon, 10 Aug 1998, George wrote:

> ok .. this is kind of weird (I think so) ...
> 
> adding a tooltip to a widget increases it's refcount ...
> 
> this doesn't make sense to me really ... the tooltip doesn't own the widget
> but just the opposite ... the tooltip should bind the widgets destroy signal
> and die when the object is destroyed ...
> 
> I thought refcounts were an owner->slave relationship ...

hm, that's not perfectly true. you increase the ref count for a widget
if you are keeping a reference to it, which is what the tooltip does.

> this tooltip thing actually makes things complicated ... in the panel for
> example I have a lot of widgets for which I set tooltips ...
> 
> I have put a "set tooltip to NULL function" in the applet clean up code ...
> however that code isn't allways called ... for example when I remove a panel
> (a drawer) ... I rely on getting the destroy signal from the applet ...
> which however never comes .. as when the widget is unparented it still has
> a refcount hanging around .. and the widget will stay and eat up ram (plus
> I can't do cleanup) .... manually going in and setting all tooltips to NULL
> seems like a VERY UGLY solution ...

you most probably don't do the right thing in your code then.
you either just want to reparent a widget from one window to another (and
in this case there is no reason for gtk to implicitely remove the actual tip
you have set for this widget), or you want to destroy it, in which case the
tip will be removed. but either way, if you want widgets to be destroyed,
call gtk_widget_destroy (widget) on 'em, but don't unparent or remove
a widget and then wait for its destruction.

if you intend to remove the tip when the widget is reparented, you have to
care for it on your own, since gtk can not guess if you want that behaviour
or not.
out of the top of my head, you would do something like

static void
widget_remove_tip (GtkWidget   *widget)
{
  GtkTooltipsData *tdata;
  
  tdata = gtk_tooltips_data_get (widget);
  if (tdata)
  {
    /* catch the case where a widget gets its parent removed */
    if (widget->parent == NULL)
      gtk_tooltips_set_tip (tdata->tooltips, widget, NULL, NULL);
  }
}

[when you set the tip for a widget you do:]

  gtk_tooltips_set_tip (tooltip, widget, "I'm nice", "Kick me!");
  gtk_signal_connect (GTK_OBJECT (widget),
                      "parent_set",
                      widget_remove_tip,
                      NULL);


> 
> is there a good reason for the way it is now?
> 
> George
> 

---
ciaoTJ



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