

--# calendar demo

include GtkEngine.e
include std/datetime.e
include std/search.e
include std/math.e

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

constant panel = create(GtkBox,0,10)
    gtk:add(win,panel)

constant cal1 = create(GtkCalendar,{
    {"select day",0},
    {"background","gray90"},
    {"override background color",4,"blue"},
    {"display options",
        GTK_CALENDAR_SHOW_HEADING +
        GTK_CALENDAR_SHOW_DAY_NAMES +
        GTK_CALENDAR_NO_MONTH_CHANGE}})

constant sep1 = create(GtkSeparator,1)

constant cal2 = create(GtkCalendar,{
    {"background","white"},
    {"override background color",4,"red"}})
        
constant sep2 = create(GtkSeparator,1)

constant cal3 = create(GtkCalendar,{
        {"select day",0},
        {"background","gray90"},
	{"override background color",4,"green"},
	{"display options",
	    GTK_CALENDAR_SHOW_HEADING +
	    GTK_CALENDAR_SHOW_DAY_NAMES +
	    GTK_CALENDAR_NO_MONTH_CHANGE}})
 
    gtk:add(panel,{cal1,sep1,cal2,sep2,cal3})
    
integer 
    month = get(cal2,"month"), 
    year = get(cal2,"year")
    
object dt = datetime:now()
    gtk:set(cal1,"select month",month-1,year)
    gtk:set(cal3,"select month",month+1,year)
    connect(cal2,"next-month","Update")
    connect(cal2,"prev-month","Update")
    connect(cal2,"next-year","Update")
    connect(cal2,"prev-year","Update")

    gtk:set(win,"title",datetime:format(dt,"  Today is %A, %B %d, %Y"))
    gtk:set(win,"icon","stock_calendar")
    
show_all(win)
main()

--------------------------------
global function Update(atom cal)
--------------------------------
object today = date() 
atom m = get(cal,"month"), y = get(cal,"year")
    gtk:set(cal1,"select month",m-1,y)
    gtk:set(cal3,"select month",m+1,y)
    
    object d1 = get(cal1,"eu date")
    if equal(today[1..2],d1[1..2]) then 
        gtk:set(cal1,"select day",today[3])
    else
        gtk:set(cal1,"select day",0) 
    end if
    
    object d2 = get(cal2,"eu date")
    if equal(today[1..2],d2[1..2]) then 
        gtk:set(cal2,"select day",today[3])
    else
        gtk:set(cal2,"select day",0) 
    end if
    
    object d3 = get(cal3,"eu date")
    if equal(today[1..2],d3[1..2]) then 
        gtk:set(cal3,"select day",today[3])
    else
        gtk:set(cal3,"select day",0) 
    end if
return 1
end function



