Thread: GTK Textarea

  1. #1
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101

    GTK Textarea

    Hi, after a lot of searching, I found a textarea widget for GTK+. Alas, a sample program I tried to compile failed:

    Code:
    /*
     *File name: text.c
     */
    
    #include <gtk/gtk.h>
    #include <glib.h>
    
    /*-- This function allows the program to exit properly when the window is closed --*/
    gint destroyapp (GtkWidget *widget, gpointer gdata)
    {
      g_print ("Quitting...\n");
      gtk_main_quit();
      return (FALSE);
    }
    
    int main (int argc, char *argv[])
    {
      /*-- Declare the GTK Widgets used in the program --*/
      GtkWidget *window;
      GtkWidget *text;
    
      gchar *buffer = "This is some sample text";
    
      /*--  Initialize GTK --*/
      gtk_init (&argc, &argv);
    
      /*-- Create the new window --*/
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    
      /*-- Create a text area --*/
      text = gtk_text_new(NULL, NULL);
    
      /*-- Set text area to be editable --*/
      gtk_text_set_editable(GTK_TEXT (text), TRUE);
    
      /*-- Connect the window to the destroyapp function  --*/
      gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);
    
      /*-- Add the text area to the window --*/
      gtk_container_add(GTK_CONTAINER(window), text);
    
      /*-- Add some text to the window --*/
      gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buffer, strlen(buffer));
    
    
      /*-- Set window border to zero so that text area takes up the whole window --*/
      gtk_container_border_width (GTK_CONTAINER (window), 0);
    
      /*-- Set the window to be 640 x 200 pixels --*/
      gtk_window_set_default_size (GTK_WINDOW(window), 640, 200);
    
      /*-- Set the window title --*/
      gtk_window_set_title(GTK_WINDOW (window), "Text Area");
    
      /*-- Display the widgets --*/
      gtk_widget_show(text);
      gtk_widget_show(window);
    
      /*-- Start the GTK event loop --*/
      gtk_main();
    
      /*-- Return 0 if exit is successful --*/
      return 0;
    }
    Code:
    $ gcc test.c -o test `pkg-config --cflags --libs gtk+-2.0`
    test.c: In function ‘main’:
    test.c:32: warning: assignment makes pointer from integer without a cast
    /tmp/ccoT6Lyf.o: In function `main':
    test.c:(.text+0x74): undefined reference to `GTK_TEXT'
    test.c:(.text+0x123): undefined reference to `GTK_TEXT'
    collect2: ld returned 1 exit status
    I think the code is pretty old and gcc is having problems with gtk_text_new(NULL, NULL). I have seen code like this on the gtk website, and they use the same conventions. Any ideas?

  2. #2
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101
    It seems GtkText is deprecated. I have to use GtkTextView instead. Glad to see gtk.org is up to date though, that's really handy. Man, the lack of (up to date) GTK+ tutorials is rather annoying. Could be a project for the future if I manage to progress any further.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW32 and gtk setup in Windows
    By Joelito in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-05-2009, 11:39 AM
  2. Replies: 1
    Last Post: 09-22-2008, 04:49 AM
  3. Help on GTK
    By kakashi in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2006, 02:33 AM
  4. GTK troubles...again...
    By cornholio in forum Linux Programming
    Replies: 4
    Last Post: 01-16-2006, 01:37 AM
  5. GTK Help
    By Cronkilla in forum C Programming
    Replies: 2
    Last Post: 08-24-2004, 06:23 PM