---------------------------------------------------
-- Assistant.exu  Aug.3, 2008
-- Demonstrates:
--  GtkAssistant - a series of attractive dialogs
--  which walk the user thru a process
--  such as installing or setting up accounts, etc.
----------------------------------------------------
include GtkEngine.e
include GtkEnums.e
include GtkRoutines.e
include dll.e

atom surebtn
boolean ok_to_close = FALSE
constant assistant = create(GtkAssistant)
	set(assistant,"default size",600,400)

-------------------------------------------
-- Allow page 3 => page 4 only if 
-- 'I'm sure' checkbox is selected
-------------------------------------------
function SureClick(atom ctl, atom page)
	ok_to_close = get(surebtn,"active")
	set(assistant,"page complete",page,TRUE)
return 1
end function
constant sure_click = call_back(routine_id("SureClick"))

------------------------------------------
-- Main Window
------------------------------------------
constant win = create(GtkWindow)
	connect(win,"destroy",quit)
	set(win,"position",GTK_WIN_POS_CENTER)
	set(win,"default size",200,200)

------------------------------------------
-- Vertical container for widgets
------------------------------------------
constant panel = create(GtkVBox)
	add(win,panel)

--------------------------------------------
-- Button from stock to get things started
--------------------------------------------
constant btn = create(GtkButton,"gtk-ok")
	pack(panel,-btn)
	set(btn,"tooltip text","Click here for a demonstration")

--------------------------------------------------------
-- Some images to use here and there...
--------------------------------------------------------
constant splash = create(GtkImage,"Jamie.jpg")
	add(panel,splash)

constant jamie = create(GdkPixbuf,"Jamie.jpg",200,-1)
constant jamie2 = create(GdkPixbuf,"jamie2.jpg",200,-1)

-------------------------------------------------------------------------------
-- A helper function to build assistant pages programmatically
-------------------------------------------------------------------------------
function CreateAssistantPage(integer pagetype,sequence title, boolean complete)
object page = create(GtkVBox)
	junk = get(assistant,"append page",page)
	set(assistant,"page type",page,pagetype)
	set(assistant,"page title",page,title)
	set(assistant,"page complete",page,complete)
return page
end function

------------------------------------------------------------------------------------
-- Create 4 pages for the assistant
------------------------------------------------------------------------------------
constant pg1 = CreateAssistantPage(GTK_ASSISTANT_PAGE_INTRO,"Page 1: Welcome!",TRUE)
-- photo for top banner on page;	
	set(assistant,"page header image",pg1,jamie)
-- text to display on page;
	constant pg1_text = create(GtkLabel)
  	set(pg1_text,"markup",
				"<b>Heading</b>\nHere you could put some text....\n" &
				"\tPreferably using <span color='red'>Pango Markup</span>")
	add(pg1,pg1_text)

constant pg2 = CreateAssistantPage(GTK_ASSISTANT_PAGE_CONTENT,"Page 2:",TRUE)
	set(assistant,"page side image",pg2,jamie2)
	add(pg2, create(GtkLabel,"You can have many 'content' pages"))

constant pg3 = CreateAssistantPage(GTK_ASSISTANT_PAGE_CONFIRM,"Page 3: Confirm",FALSE)
	add(pg3, create(GtkLabel,"Click below if you are sure all is correct..."))
	surebtn = create(GtkCheckButton,"Yes, I am sure!")
	connect(surebtn,"clicked",sure_click,pg3)
	pack(pg3, surebtn)

constant pg4 = CreateAssistantPage(GTK_ASSISTANT_PAGE_SUMMARY,"Page 4: Summary",TRUE)
	add(pg4, create(GtkLabel,"That's all, folks!\nHope you liked it!"))
	
----------------------------------------------
-- Display assistant when ok button is pressed
----------------------------------------------
function ShowAssistant()
	show_all(assistant)
return 1
end function
constant showAss = call_back(routine_id("ShowAssistant"))

-------------------------------------------------
-- Display events which may need to be handled by
-- your (real life) program
-------------------------------------------------
function Closed()
   puts(1,"Assistant closed!\n")
   set(assistant,"hide")
return 1
end function
constant closed = call_back(routine_id("Closed"))

function Cancelled()
	puts(1,"Assistant cancelled!\n")
	hide(assistant)
return 1
end function
constant cancelled = call_back(routine_id("Cancelled"))

----------------------------------------------
-- Set up call backs
----------------------------------------------
connect(btn,"clicked",showAss)
connect(assistant,"close",closed)
connect(assistant,"cancel",cancelled)

show_all(win)
main()

---------------------------------------------------------------
-- copyright 2008 by Irv Mullins, code released under the LGPL
---------------------------------------------------------------