--------------------------------------
-- ToolBar.exu
-- Demonstrates:
--	GTK ToolBar
--	GTK ToolTips
--	Generating tooltips from lists
--------------------------------------

include GtkEngine.e
include std/dll.e

sequence tips = {
	{"gtk-quit","Exit the program"},
	{"gtk-new","Create a new document"},
	{"gtk-open","Open a file"},
	{"gtk-select-color","Color"},
	{"gtk-help","Help me!"}}
	
constant msg_help =
"Help?\nWe don't need no steenkin' help!"

constant msg =
  "The Goggles!\nThey do nothing!\n"
		& "(Neither does that button)"

constant win = create(GtkWindow)
connect(win,"destroy",quit)
set(win,"position",GTK_WIN_POS_CENTER)
set(win,"default size",320,300)

-----------------------------------------------------
function create_toolitem(sequence txt, sequence tip)
-----------------------------------------------------
atom x = create(GtkToolButton,txt)
	set(x,"tooltip text",tip)
return x
end function

-----------------------------------------------------
function Help(atom ctl, atom id)
-----------------------------------------------------
object name = tips[id][2]
switch id do
	case 1 then if Question(win,"Quit?","Are you sure?",GTK_BUTTONS_YES_NO)  = -8 then
				call(quit)
			end if
			break
	case 2 then break 
	case 3 then break
	case 4 then return Info(win,name,msg)
	case 5 then return Info(win,name,msg_help)
end switch
return 0
end function
constant help = call_back(routine_id("Help"))

constant panel = create(GtkVBox)
add(win,panel)

constant toolbar  = create(GtkToolBar)
object tip
set(toolbar,"tooltips",TRUE)
for i = length(tips) to 1 by -1 do
	tip = create_toolitem(tips[i][1],tips[i][2])
	set(tip,"name",tips[i][2])
	connect(tip,"clicked",help,i)
	set(toolbar,"insert",tip)
end for

pack(panel,toolbar)

show_all(win)
main()

---------------------------------------------------------------
-- Copyright 2009 by Irv Mullins - code released under the LGPL
---------------------------------------------------------------