Re: tooltips and refcounts



On Mon, Aug 10, 1998 at 11:59:42AM +0200, Tim Janik wrote:
> > 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.

well the thing is ... without the tips .. everything works perfectly just
by destroying the parent ... all it's widgets get killed as well ...

I don't remove the tip when it's reparented .. but before it's destroyed
.... right now I  put in code that traps the destroy on the panel widget
and sets tooltips to null on all it's widgets ... but that seems very
ugly to me ...

I have also just realized I have some code at work which has some major
memory leaks due to this .. since I don't keep around pointers to the
widgets that I set tooltips on .. I only destroy their parent (those are
dynamically added and removed) ... so now I need to either parse the widget
tree and remove all tips before that .. or store pointers to the widgets ...
both of which would be fairly ugly

I would have thought that the philosophy would be more owner->slave ...

the tip doesn't gain anything by keeping the widget alive for itself ...

I would have thought it would be the other way around .. the widget keeping
a refcount for the tip ... since we care about the tip staying around as
long as the widget does .. not the other way around

I don't think the tip should be removed when reparented ... but I think it
shouldn't raise the refcount ... it should just "autoclean" itself when the
widget is gone ...

the entire point of refcounts IS that if you have a reference to something
you want that something to stay around .. however a tooltip doesn't need
that something to stay around ... it should be tied to that something and
die when the widget dies ...

> 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);

that won't work right ... I don't want to kill the tip when the widget
has no parent .. that would kill it during reparent ... right now I have
to write code that tracks when the widget should be destroyed and hunt
those down ... I still don't see why a refcount for tooltips is justified

George

-- 
------------------------------------------------------------------------------
George Lebl <jirka@5z.com> http://www.5z.com/jirka/
------------------------------------------------------------------------------
  The following implements RSA in perl and is illegal to export from the US:

          #!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
          $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
          lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)



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