"Fossies" - the Fresh Open Source Software Archive

Member "FreeBASIC-1.05.0-linux-x86_64/examples/GUI/GTK+/text_buffer.bas" (31 Jan 2016, 2189 Bytes) of package /linux/privat/FreeBASIC-1.05.0-linux-x86_64.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Visual Basic source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 '' translated from an "C" example written by Vijay Kumar B.
    2 '
    3 ' Reviewed by TJF (2011)
    4 ' Details: http://developer.gnome.org/gtk/
    5 
    6 
    7 '#DEFINE __USE_GTK3__
    8 #include once "gtk/gtk.bi"
    9 
   10 #define NULL 0
   11 
   12 '':::::
   13 sub on_window_destroy cdecl (byval widget as GtkWidget ptr, byval userdata as gpointer)
   14   gtk_main_quit( )
   15 end sub
   16 
   17 '':::::
   18 '' Callback for close button
   19 sub on_button_clicked cdecl (byval button as GtkWidget ptr, byval buffer as GtkTextBuffer ptr)
   20   dim as GtkTextIter start, end_
   21   dim as gchar ptr text
   22 
   23   '' Obtain iters for the start and end of points of the buffer
   24   gtk_text_buffer_get_start_iter( buffer, @start )
   25   gtk_text_buffer_get_end_iter( buffer, @end_ )
   26 
   27   '' Get the entire buffer text.
   28   text = gtk_text_buffer_get_text( buffer, @start, @end_, FALSE )
   29 
   30   '' Print the text
   31   g_print( "%s", text )
   32 
   33   g_free( text )
   34 
   35   gtk_main_quit( )
   36 end sub
   37 
   38 '':::::
   39   dim as GtkWidget ptr win
   40   dim as GtkWidget ptr vbox
   41   dim as GtkWidget ptr text_view
   42   dim as GtkWidget ptr button
   43   dim as GtkTextBuffer ptr buffer
   44 
   45   gtk_init( NULL, NULL )
   46 
   47   '' Create a Window.
   48   win = gtk_window_new( GTK_WINDOW_TOPLEVEL )
   49   gtk_window_set_title( GTK_WINDOW( win ), "Simple Multiline Text Input" )
   50 
   51   '' Set a decent default size for the window.
   52   gtk_window_set_default_size( GTK_WINDOW( win ), 200, 200 )
   53   g_signal_connect( G_OBJECT( win ), "destroy", _
   54                     G_CALLBACK( @on_window_destroy ), _
   55                     NULL )
   56 
   57   vbox = gtk_vbox_new( FALSE, 2 )
   58   gtk_container_add( GTK_CONTAINER( win ), vbox )
   59 
   60   '' Create a multiline text widget.
   61   text_view = gtk_text_view_new( )
   62   gtk_box_pack_start( GTK_BOX( vbox ), text_view, 1, 1, 0 )
   63 
   64   '' Obtaining the buffer associated with the widget.
   65   buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_view ) )
   66   '' Set the default buffer text.
   67   gtk_text_buffer_set_text( buffer, "Hello Text View!", -1 )
   68 
   69   '' Create a close button.
   70   button = gtk_button_new_with_label( "Close" )
   71   gtk_box_pack_start( GTK_BOX( vbox ), button, 0, 0, 0)
   72   g_signal_connect( G_OBJECT( button ), "clicked", _
   73                     G_CALLBACK( @on_button_clicked ), _
   74                     buffer )
   75 
   76   gtk_widget_show_all( win )
   77 
   78   gtk_main( )