
--------------------------------------------------------------------------
--# Locale Monetary symbols
--------------------------------------------------------------------------

include GtkEngine.e
include std/locale.e

ifdef WINDOWS then
    Warn(,,"Windows has trouble with locale currency chars.")
end ifdef

constant docs = `<b><u>Locale</u></b>
This demonstrates how to add local currency symbols to
your display. I don't know if all these are correct.
Hey, it's just a demo!
`
constant text = allocate_string("text")

constant win = gtk:create(GtkWindow,"size=450x500,border=10,position=1,$destroy=Quit") 

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

constant lbl = create(GtkLabel)
    gtk:set(lbl,"markup",docs)
    gtk:add(panel,lbl)
	
constant scroller = create(GtkScrolledWindow)
    gtk:pack(panel,scroller,TRUE,TRUE)

object data = {
    {"Emperor Norton I","San Francisco, CA",44.95},
    {"Alphie Packer","Donner, CA",-30.00,"en_US.utf8"},
    {"John Deighton","Vancouver, BC",15.88,"en_CA.utf8"},
    {"Dikka Khan","Madras, India",49.30,"en_IN.utf8"},
    {"Choy Lee","Hong Kong",45.67,"en_HK.utf8"},
    {"Bridget Murphy","Shannon, Ireland",48.54,"en_IE.utf8"},
    {"Randy de Rand","Cape Town, South Africa",49.22,"en_ZA.utf8"},
    {"Reginald Parsley","London, England",22.75,"en_GB.utf8"},
    {"Jean le Bloop","Paris, France",123.45,"en_IE.utf8"}}
    
constant
    rend1 = gtk:create(GtkCellRendererText),
    col1 = gtk:create(GtkTreeViewColumn)
    gtk:set(col1,"pack start",rend1)
    gtk:set(col1,"add attribute",rend1,"text",1)

constant
    rend2 = gtk:create(GtkCellRendererText),
    col2 = gtk:create(GtkTreeViewColumn)
    gtk:set(col2,"pack start",rend2)
    gtk:set(col2,"add attribute",rend2,"text",2)

constant
    rend3 = gtk:create(GtkCellRendererText),
    col3 = gtk:create(GtkTreeViewColumn)
    gtk:set(col3,"pack start",rend3)
    gtk:set(col3,"add attribute",rend3,"text",3)
    gtk:set(rend3,"xalign",0.9) -- money looks better when right aligned;
      gtk:set(col3,"cell data func",rend3,_("Money"))
  
constant
    rend4 = gtk:create(GtkCellRendererText),
    col4 = gtk:create(GtkTreeViewColumn)
    gtk:set(col4,"pack start",rend4)
    gtk:set(col4,"add attribute",rend4,"text",4)
   

constant store = gtk:create(GtkListStore,{gSTR,gSTR,gFLT,gSTR})

constant view = gtk:create(GtkTreeView)
    gtk:set(view,"model",store)
    gtk:add(scroller,view)
    gtk:add(view,{col1,col2,col3})
    gtk:set(store,"data",data)
    
gtk:show_all(win)
gtk:main()

---------------------------------------------------------------
function Money(atom layout, atom rend, atom mdl, atom iter)
---------------------------------------------------------------
atom val = gtk:get(mdl,"col data from iter",iter,3) -- amount;
object loc = gtk:get(mdl,"col data from iter",iter,4) -- specified locale;

if atom(loc) then -- no locale was specified, fallback to local;
    locale:set(getenv("LANG")) 
else 
    locale:set(loc)
end if

gtk:set(rend,"property","text",locale:money(val)) -- note: must use 'property'; 

return 1
end function

