Pastey EuGTK UTF-8 test7.ex demo

include GtkEngine.e
include gunicode.e 
 
constant win = create(GtkWindow) 
	connect(win,"destroy",quit) 
	set(win,"title","Single-line Entry Widget") 
	set(win,"position",GTK_WIN_POS_CENTER) 
	set(win,"default size",350,100) 
	set(win,"border width",10) 
 
constant panel = create(GtkVBox) 
	add(win,panel) 
 
-- Add a Single-line Entry Control to container 
constant edt = create(GtkEntry) 
	set(edt,"text","Your Name Here") 
	add(panel,edt) 
 
function x() 
 
--get the UTF-8 text from the SLE 
sequence s = get(edt,"text") 
print(1, s) 
 
--get the UCS4 version of the UTF-8 text 
sequence t = g_utf8_to_ucs4_fast(s) 
print(1, t) 
 
--Grab a subsequence of the UCS4 text (the 2nd character), if it exists 
if length(t) > 2 then 
t = {t[2]} 
end if 
 
--set the SLE to what we just grabbed, converting to UTF-8 first 
set(edt, "text", g_ucs4_to_utf8(t)) 
 
return 0 
end function 
constant xcb = call_back(routine_id("x")) 
 
constant btn = create(GtkButton,"gtk-quit")  
	connect(btn,"clicked",xcb) 						 
	pack(panel,btn)										 
 
show_all(win) 
main()