#!/usr/bin/gtkbasic003



//-- load  file and show the window
gins_glade("testtextview.glade")
gins_set("window1" , "100" , "100" , "<uposition>")
gtk("gtk_window_resize" ,"window1" ,  "300" , "300", 0,0,0)
gins_main()

//-- set some text to all labels

gins_set("button1" , "label" , "hide cursor" , "<str>")
gins_set("button2" , "label" , "show cursor" , "<str>")

gins_set("button3" , "label" , "copy all text to entry" , "<str>")
gins_set("button4" , "label" , "copy selection to entry" , "<str>")

gins_set("label1" , "label" , "1" , "<str>")



//-- assign a textbuffer to the textview

gtk("gtk_text_view_get_buffer" ,"textview1" ,  0 , 0, 0,0,0)
gtk_setobjectname("buf1")

//-- add some text in it
//gtk("gtk_text_buffer_set_text" ,":buf1" ,  "12345\n12345" , "11", 0,0,0)


gtk("gtk_text_buffer_set_text" ,"buf1" ,  "12:345" , "5", 0,0,0)


//-- test new objectstuff

gtk("gtk_button_new_with_label", "test" , 0,0,0,0,0)

gtk_setobjectname("button96")
gtk("gtk_button_set_label" , "button96", "replace selection with 'test'" ,0,0,0,0)
gtk("gtk_box_pack_start" , "vbox1" , "button96" , "0","0","0",0)
gtk("gtk_widget_show" , "button96" , 0 ,0,0,0,0)

//-- mainloop with eventhandling
while 1

  widget , event , pdata = gins_event()

  if widget != Nothing then
   //-- uncomment these lines to see ALL events in the console
   ' print widget,event,pdata

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

    if event = "GDK_BUTTON_RELEASE" then

      //-- example how to switch on/off attributes of a widget

      if widget = "button1" then
        gtk("gtk_text_view_set_cursor_visible" ,"textview1" ,  "0" , 0, 0,0,0)
        a = gtk("gtk_text_view_get_cursor_visible" ,"textview1" ,  0 , 0, 0,0,0)
         gins_set("label1" , "label" ,  a  , "<str>")
      end if

      if widget = "button2" then
        gtk("gtk_text_view_set_cursor_visible" ,"textview1" ,  "1" , 0, 0,0,0)
        a = gtk("gtk_text_view_get_cursor_visible" ,"textview1" ,  0 , 0, 0,0,0)
         gins_set("label1" , "label" ,  a  , "<str>")
      end if


      //-- copy all text from the textbuffer

      if widget = "button3" then

        gtk("gtk_text_buffer_get_bounds","buf1" , "1" , "2" , 0, 0,0 )
        a = gtk("gtk_text_buffer_get_text", "buf1" , "1" , "2" , "1", 0,0)
        gins_set("entry1" , "text" ,  a  , "<str>")

      end if

      //-- copy only selected text from the textbuffer

      if widget = "button4" then

        gtk("gtk_text_buffer_get_selection_bounds","buf1" , "1" , "2" , 0, 0,0 )
        a = gtk("gtk_text_buffer_get_text", "buf1" , "1" , "2" , "1", 0,0)


       // gtk("gtk_text_buffer_set_text", "buf1" , "TestText" , "3" , 0, 0,0)

        print a
        gins_set("entry1" , "text" , a  , "<str>")

      end if

      if widget = "button96" then

        gtk("gtk_text_buffer_get_selection_bounds","buf1" , "1" , "2" , 0, 0,0 )
        gtk("gtk_text_buffer_delete", "buf1" , "1" , "2" , "1", 0,0)
        gtk("gtk_text_buffer_place_cursor", "buf1" , "1" , 0 , 0, 0,0)
        gtk("gtk_text_buffer_insert_at_cursor", "buf1" , "test" , "4" , 0, 0,0)

      end if


    end if

  end if

  xwin_usleep(2000)

wend
