Hello for read GTK_Text_View in FreeBASIC you have to use a syntax like C
Before you have to set the Var and Pointer because you cant read directly the TextView but only the Buffer.
Dim As String ReadSource_Text ' Variable where you put the text
Dim as zstring PTR WriteSource_Text ' Pointer where you store the Text Buffer
DIM AS GtkTextBuffer PTR ReadBuffer ' Pointer to the GTK Text Buffer
then you have to get the buffer from glade interface
ReadBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(TextView_Left))
And now using the Iter for know the Offset where start and end the text you can extract the text from buffer
DIM AS GtkTextIter start_, end_
gtk_text_buffer_get_iter_at_offset(ReadBuffer, @start_, 0)
gtk_text_buffer_get_iter_at_offset(ReadBuffer, @end_, -1)
' 0 is the start, and -1 are the end of the buffer
' you can have a little part of the buffer like start 50 end 55
'This store in ReadSource_Text var the buffer readed
ReadSource_Text = *gtk_text_buffer_get_text(ReadBuffer, @start_, @end_, TRUE)
ReadSource_Text is a String variable with * before you can put text from a pointer
ReadSource_Text = *gtk_text_buffer_get_text(ReadBuffer, @start_, @end_, TRUE)
End Explanation.
There you have your code with missing part:
You can copy and paste inside to your program and compile for see how work
'We start with the first Handler
SUB on_ButtonLeftToRight_clicked CDECL ALIAS "on_ButtonLeftToRight_clicked" ( _
BYVAL menuitem AS GtkMenuItem PTR, _
BYVAL user_data AS gpointer) EXPORT
dim MyString as String
MyString = Read_Text( "left", "right", "")
END SUB
SUB on_ButtonRightToLeft_clicked CDECL ALIAS "on_ButtonRightToLeft_clicked" ( _
BYVAL menuitem AS GtkMenuItem PTR, _
BYVAL user_data AS gpointer) EXPORT
dim MyString as String
MyString = Read_Text( "right", "left", "")
END SUB
SUB on_ButtonWriteInsideLeft_clicked CDECL ALIAS "on_ButtonWriteInsideLeft_clicked" ( _
BYVAL menuitem AS GtkMenuItem PTR, _
BYVAL user_data AS gpointer) EXPORT
dim MyString as String
MyString = Read_Text( "intext", "left", "This is my Hello for")
END SUB
SUB on_ButtonWriteInsideRight_clicked CDECL ALIAS "on_ButtonWriteInsideRight_clicked" ( _
BYVAL menuitem AS GtkMenuItem PTR, _
BYVAL user_data AS gpointer) EXPORT
dim MyString as String
MyString = Read_Text( "intext", "right", "This is my Hello")
END SUB
SUB on_ButtonExit_clicked CDECL ALIAS "on_ButtonExit_clicked" ( _
BYVAL menuitem AS GtkMenuItem PTR, _
BYVAL user_data AS gpointer) EXPORT
end
END SUB
'I created a function to avoid replicating long codes on each handler
'I wrote the code fast and crude but I hope it's understandable.
'The function is called with syntax MyString = Read_Text( "left", "right", "intext")
Function Read_Text( ByVal Source as String, ByVal Target as String, ByVal InText As String) As String
Dim As String ReadSource_Text ' Variable where you put the text
Dim as zstring PTR WriteSource_Text ' Pointer where you store the Text Buffer
DIM AS GtkTextBuffer PTR ReadBuffer ' Pointer to the GTK Text Buffer
' This Condition are for select the source left, right, or intext your personal string
if Source = "left" then ReadBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(TextView_Left))
if Source = "right" then ReadBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(TextView_Right))
' if you want use your surce string instead here the third option
if Source = "intext" then
'This store in ReadSource_Text var the text inside the var InText
ReadSource_Text = InText
Else
' Now we ave to set the Offset from buffer and then get the stored text
DIM AS GtkTextIter start_, end_
gtk_text_buffer_get_iter_at_offset(ReadBuffer, @start_, 0)
gtk_text_buffer_get_iter_at_offset(ReadBuffer, @end_, -1)
' 0 is the start, and -1 are the end of the buffer
' you can have a little part of the buffer like start 50 end 55
'This store in ReadSource_Text var the buffer readed
ReadSource_Text = *gtk_text_buffer_get_text(ReadBuffer, @start_, @end_, TRUE)
end if
' If you want use the text live string var then we ave to convert from Pointer to string
WriteSource_Text = StrPtr(ReadSource_Text)
' Now we make a TextBuffer where whe use to write in target textview
DIM AS GtkTextBuffer PTR WriteBuffer
if Target = "left" then WriteBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(TextView_Left))
if Target = "right" then WriteBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(TextView_Right))
if Target = "out" then Return ReadSource_Text ' if you want use the text out from function
gtk_text_buffer_set_text(WriteBuffer, WriteSource_Text, -1) ' and the we store the text inside the textbuffer
End Function