Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 7th, 2013  |  syntax: C  |  size: 2.82 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <gtk/gtk.h>
  2.  
  3. int main(int argc, char *argv[]) {
  4.     gtk_init(&argc, &argv);
  5.    
  6.     // Creating tree view stuff
  7.     GtkListStore *store1 = gtk_list_store_new(1, G_TYPE_STRING),
  8.         *store2 = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
  9.    
  10.     GtkWidget *tree_view1 = gtk_tree_view_new(),
  11.         *tree_view2 = gtk_tree_view_new();
  12.    
  13.     gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view1), GTK_TREE_MODEL(store1));
  14.     gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view2), GTK_TREE_MODEL(store2));
  15.    
  16.     // Creating columns
  17.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view1),
  18.                                                 -1, "Left", gtk_cell_renderer_text_new(),
  19.                                                 "text", 0, NULL);
  20.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view2),
  21.                                                 -1, "Number", gtk_cell_renderer_text_new(),
  22.                                                 "text", 0, NULL);
  23.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view2),
  24.                                                 -1, "Right", gtk_cell_renderer_text_new(),
  25.                                                 "text", 1, NULL);
  26.  
  27.     // Populating models
  28.     GtkTreeIter iter;
  29.     gtk_list_store_append(store1, &iter);
  30.     gtk_list_store_set(store1, &iter, 0, "left 1", -1);
  31.     gtk_list_store_append(store1, &iter);
  32.     gtk_list_store_set(store1, &iter, 0, "left 2", -1);
  33.    
  34.     gtk_list_store_append(store2, &iter);
  35.     gtk_list_store_set(store2, &iter, 0, 42, -1);
  36.     gtk_list_store_set(store2, &iter, 1, "right 1", -1);
  37.     gtk_list_store_append(store2, &iter);
  38.     gtk_list_store_set(store2, &iter, 0, 13, -1);
  39.     gtk_list_store_set(store2, &iter, 1, "right 2", -1);
  40.     gtk_list_store_append(store2, &iter);
  41.     gtk_list_store_set(store2, &iter, 0, 9, -1);
  42.     gtk_list_store_set(store2, &iter, 1, "right 3", -1);
  43.    
  44.     // Packing together
  45.     GtkWidget *paned = gtk_hpaned_new();
  46.     GtkWidget *scrolled_window1 = gtk_scrolled_window_new(NULL, NULL),
  47.         *scrolled_window2 = gtk_scrolled_window_new(NULL, NULL);
  48.     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  49.     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  50.     gtk_widget_show(tree_view1);
  51.     gtk_container_add(GTK_CONTAINER(scrolled_window1), tree_view1);
  52.     gtk_container_add(GTK_CONTAINER(scrolled_window2), tree_view2);
  53.     gtk_paned_add1(GTK_PANED(paned), scrolled_window1);
  54.     gtk_paned_add2(GTK_PANED(paned), scrolled_window2);
  55.    
  56.     GtkRequisition req;
  57.     gtk_widget_size_request(tree_view1, &req);  // get tree's preferred size
  58.     gtk_paned_set_position(GTK_PANED(paned), req.width);
  59.        
  60.     GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  61.     gtk_container_add(GTK_CONTAINER(window), paned);
  62.     gtk_window_set_default_size(GTK_WINDOW(window), 600, 600);
  63.  
  64.     gtk_widget_show_all(window);
  65.    
  66.  
  67.     gtk_main();
  68.    
  69.     return 0;
  70. }