#!/usr/bin/gtkbasic002

HERE = xwin_getdir(command(2))
HERE &= "/resource" 
xwin_cd(HERE)
//gins_main()
//-- load  file and show the window
gins_glade("testlists.glade")
gins_main()
gtk("gtk_decorated_window_move_resize_window" , "window1" , "10" , "11", "301","300",0  )

gins_set("button1" , "label" , "clist-demo" , "<str>")


//-- manipulate a widget, e.g. move the window
gins_set("window1" , "10" , "10" , "<uposition>")

gtk("gtk_label_set_text", "label1" , "wait and watch..." ,0,0,0,0)
print "-"


// -- create List no. 1 --

filllists=1

gtk_createobject("GtkBasicList" , "mylist1", ":window1" , ":scrolledwindow1")
gtk("gtk_widget_show" , ":mylist1" , 0 ,0,0,0,0)

if filllists=1 then
	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "0" , "0", "I am list 1 row 0",0,0)
	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "1" , "0", "I am list 1 row 1",0,0)
	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "2" , "0", "I am list 1 row 2",0,0)

	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "3" , "0", "I am list 1 row 3",0,0)
	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "4" , "0", "I am list 1 row 4",0,0)
	gtk("gtk_clist_append", ":mylist1" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist1" , "5" , "0", "I am list 1 row 5",0,0)

end if

// -- create List no. 2 --

gtk_createobject("GtkBasicList" , "mylist2", ":window1" , ":scrolledwindow2")
gtk("gtk_widget_show" , ":mylist2" , 0 ,0,0,0,0)

if filllists=1 then
	gtk("gtk_clist_append", ":mylist2" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist2" , "0" , "0", "I am list 2 row 0",0,0)
	gtk("gtk_clist_append", ":mylist2" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist2" , "1" , "0", "I am list 2 row 1",0,0)
	gtk("gtk_clist_append", ":mylist2" , "" ,0,0,0,0)
	gtk("gtk_clist_set_text", ":mylist2" , "2" , "0", "I am list 2 row 2",0,0)
end if

demomode()

sub demomode()
xwin_system("sleep 5")
//-- some action --

gtk("gtk_label_set_text", "label1" , "now selecting a row, wait..." ,0,0,0,0)
print "-"

xwin_system("sleep 5")

gtk("gtk_clist_select_row" , ":mylist1" , "2" , "0", 0,0,0  )
a = gtk_get_list_selection(":mylist1")

gtk("gtk_label_set_text", "label1" , "row \"" & a & "\" was selected, wait..." ,0,0,0,0)
print "-"

xwin_system("sleep 5")

  //--------------------------
 // this returns a NUMBER!
// To get the text, you must get it from an internal argumentbuffer 3
gtk("gtk_clist_get_text", ":mylist1" , "2" , "0" , 0,0,0)
a = gtk_returntext("3")


gtk("gtk_label_set_text", "label1" , "it has the text: \"" & a  & "\" - wait..." ,0,0,0,0)
print "-a"



xwin_system("sleep 5")
gtk("gtk_label_set_text", "label1" , "now changing text in list 2 - wait..." ,0,0,0,0)
print "-b"


xwin_system("sleep 5")

gtk("gtk_clist_get_text", ":mylist1" , "1" , "0" , 0,0,0)
a = gtk_returntext("3")
print a

gtk("gtk_clist_set_text", ":mylist2" , "1" , "0", "test",0,0)


a = gtk_count_list_rows(":mylist1")
print "number of rows (list1): " & a

gtk("gtk_label_set_text", "label1" , "list 1 has " & a & " lines." ,0,0,0,0)
print "-c"

xwin_system("sleep 6")
gtk("gtk_label_set_text", "label1" , "Finished, bye! Now drag some rows around..." ,0,0,0,0)
print "-d"
'gdk_flush()
'gtk("gtk_decorated_window_move_resize_window" , "window1" , "10" , "11", "300","300",0  )

end sub

//xwin_system("sleep 20")

//-- mainloop with eventhandling
while 1

  checkclose()
  widget , event , pdata = gins_event()

  if widget != Nothing then
   ' print widget
    print event
   ' print pdata

    if event = "GDK_DELETE" then
      gins_exit()
      end
    end if

    if event = "GDK_BUTTON_RELEASE" then
   ' print widget
   ' print event
   ' print pdata

     if widget = "button1" then
          gins_set("button1" , "label" , time() , "<str>")
     end if
    end if


  end if

  xwin_usleep(2000)

wend

 //------------------------------------------------------------
// this function exits Basic, if the grafical interface crashed
sub checkclose()
	a=gins_get("window1" , "name" , "<str>")
	if a = Nothing then
		print "window was closed, exiting..."
		gins_exit()
		end
	end if
end sub

