
--------------------------------------------------------------
--# Custom (changeable) tooltips
--------------------------------------------------------------

include GtkEngine.e

constant docs = `<u><b>Custom Tooltip</b></u>
Mouse over the ok button to see it.
Move away,
Rinse, Repeat ...
`
integer ct = 99

constant win = create(GtkWindow,"size=300x100,border=10,position=1,$destroy=Quit")

constant panel = create(GtkBox,"orientation=VERTICAL")
	add(win,panel)

constant lbl1 = create(GtkLabel)
	set(lbl1,"markup",docs)
	add(panel,lbl1)

constant btn1 = create(GtkButton,"gtk-quit","Quit")
	set(btn1,"tooltip text","Click to end this program")

constant btn2 = create(GtkButton,"gtk-ok")
constant btnbox = create(GtkButtonBox)
	add(btnbox,{btn1,btn2})
	pack(panel,-btnbox)

-- create a custom tooltip:
constant ttwin = create(GtkWindow,GTK_WINDOW_POPUP)
	set(ttwin,{
	  {"decorated",FALSE},
	  {"border width",10},
	  {"background","skyblue"}})

constant ttpanel = create(GtkBox,VERTICAL)
	add(ttwin,ttpanel)

constant ttimage = create(GtkImage,"thumbnails/bar.gif")
	add(ttpanel,ttimage)

constant tip = create(GtkLabel)
	set(tip,"markup","<i><b>Tipsey</b></i> tip")
	add(ttpanel,tip)
	show_all(ttpanel)

set(btn2,"tooltip window",ttwin)
connect(btn2,"query-tooltip","ShowTip")
connect(btn2,"leave-notify-event","Drink")

object fmt = "%d bottles of beer on the wall,\n%d bottles of beer,\ntake one down,\ndrink it right down,\n%d bottles of beer on the wall!"

show_all(win)
main()

------------------------
global function Drink()
------------------------
ct -= 1
return ct
end function

----------------------------------------------------------------------------------------------
global function ShowTip(atom ctl, integer x, integer y, integer mode, atom t, atom data)
----------------------------------------------------------------------------------------------
set(tip,"markup",sprintf(fmt,{ct,ct,ct-1}))
return ct > 0 -- stops showing tip when ct = 0
end function

