rendered paste body/* hello world for gtk with cairo support, by Øvyind Kolås */#include <gtk/gtk.h>#include <cairo.h>#include <pthread.h>#define DEFAULT_WIDTH 400#define DEFAULT_HEIGHT 200/* forward definition of actual painting function for our drawing area widget */int count= 0;void *paint(GtkWidget *widget){ gint width, height; gint i; cairo_t *cr; sleep(1); width = widget->allocation.width; height = widget->allocation.height; gdk_threads_enter(); cr = gdk_cairo_create (gtk_tree_view_get_bin_window(widget)); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 40); cairo_move_to (cr, 40, 60); cairo_set_source_rgb (cr, 0,0,0); cairo_show_text (cr, "Hello World"); cairo_destroy (cr); gdk_threads_leave(); return NULL;}gboolean change_color(GtkListStore *list){ GtkTreeIter iter,iter_c; char buffer[16]; gtk_tree_model_get_iter_from_string(list,&iter,"3"); switch(count){ case 0: gtk_list_store_set(list,&iter,1,"#666666",-1); count++; break; case 1: gtk_list_store_set(list,&iter,1,"#555555",-1); count++; break; case 2: gtk_list_store_set(list,&iter,1,"#444444",-1); count++; break; case 3: gtk_list_store_set(list,&iter,1,"#333333",-1); count++; break; case 4: gtk_list_store_set(list,&iter,1,"#444444",-1); count++; break; case 5: gtk_list_store_set(list,&iter,1,"#555555",-1); count =0; } return TRUE;}gintmain (gint argc, gchar **argv){ GtkWidget *window; GtkWidget *canvas; /* Secure glib */ if( ! g_thread_supported() ) g_thread_init( NULL ); /* Secure gtk */ gdk_threads_init(); gdk_threads_enter(); gtk_init(&argc,&argv); /* create a new top level window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); GtkWidget *swindow = gtk_scrolled_window_new(NULL,NULL); /* make the gtk terminate the process the close button is pressed */ g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING,G_TYPE_STRING); GtkTreeView *view = gtk_tree_view_new_with_model(list); gtk_tree_view_insert_column_with_attributes(view,0,"strings", gtk_cell_renderer_text_new(),"text",0,"background",1,NULL); int i; GtkTreeIter iter,iter_c; char buffer[16]; for(i=0;i<10;i++){ gtk_list_store_insert_before(list,&iter,NULL); gtk_list_store_set(list,&iter,0,"This is a really cool line of text ok",-1); } gtk_widget_set_size_request (view, DEFAULT_WIDTH, DEFAULT_HEIGHT); /* connect our drawing method to the "expose" signal g_signal_connect (G_OBJECT (view), "expose-event", G_CALLBACK (paint), NULL ); */ gtk_container_add (GTK_CONTAINER (swindow), view); gtk_container_add (GTK_CONTAINER (window), swindow); pthread_t tid; pthread_create(&tid,NULL,paint,view); gdk_threads_add_timeout(200,change_color,list); gtk_widget_show_all (window); gtk_main (); gdk_threads_leave(); return 0;}