Re: tooltips




Original message written by someone, somewhen...

I wish it was possible to control tooltips position (they are
always at the bottom of the widget an I cannot visually tie them
to the appropriate `area') and use marked up text, like bold and
stuff.

The tooltips code is really quite straight forward.  I ended up a while back, derriving my own tooltip object 
from the GTK source, which added support for Pango markup and tooltip shown/hidden signals.

Adding Pango markup support was fairly simple, I just found the line that sets the tooltip label, and made it 
check the start of the string for the <markup> tag.  If it was found, then it checked the string for valid 
markup (or just tried to render it with a function that returns an error if it fails anything, I can't 
remember exactly off-hand).  But at any rate, if the text contained a LEADING <markup> tag, then it was 
rendered as markup.  If not, it went through the usual set text function which doesn't look for tags or any 
of the other things markup tries to interpret (angled brackets, for example).

Likewise the tooltip shown signal (I included as an argument, the tooltip object being shown, or NULL if the 
tooltip was being hidden) was just a case of defining a new signal, and dropping a few emits around the 
place.  By including a pointer to the tooltip object being displayed, my program could check the pointer 
against the one it saved when it created the tooltip, and set or clear a flag or whatever else it wanted to 
do.  What I did with it, when the tooltip object pointer matched the one I was interested in, was to call a 
function to update the text (there was a reasonable amount of humming around every second to generate the new 
tooltip, and the the signal was emitted just before the text was rendered), and then set a timeout to call 
that function every second there-after to update with any changes.  Likewise if the pointer didn't match, the 
handler simply de-registered the timeout if it was currently active.  A more specific show/hide callback 
would certainly have 
been a better way to go (every handler was being called for every time the tooltip changed to a new widget), 
but I only had a few tooltips in the only program I have that actually uses those signals (the only other one 
that needs to update tooltips, only does so once each half hour, so it just goes ahead and does it 
regardless).

What you want, being able to position the tooltip, would undoubtedly be a little more involved.  The easiest 
option there may be just to swipe the code for building the little window, and do it yourself.  Or, if you 
particularly want it to fit in smoothly with the tooltip mechanism, then something like what I did to be 
informed just before a tooltip opened up on my widget, might work for you too.  You could catch the 
creation/update of the tooltip window, and allow your program to manage it itself.

In either case, it pretty much means building your own tooltip widget out of the GTK sources, unless they've 
made the tooltip widget a whole lot more derrivation-friendly since I last looked at it.  But it's perfectly 
do-able.  And last I saw, you can have two tooltip objects going at a time, or even perhaps just create a 
"popup tooltip-like window" widget by canibilizing the relevant parts of the GTK source for your positioned 
one.  (If they're really nice, maybe they'll make it easier sometime...)


Fredderic

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!





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