]> Pileus Git - ~andy/gtk/blobdiff - tests/testtreeview.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testtreeview.c
index 5115ae4f360b170cc2487868a418a63d0ed1b14f..9816540de424cf93134023149ab4b023f25b4c07 100644 (file)
@@ -13,9 +13,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <string.h>
@@ -351,7 +349,7 @@ set_columns_type (GtkTreeView *tree_view, ColumnsType type)
       gtk_tree_view_set_rules_hint (tree_view, TRUE);
       
       rend = gtk_cell_renderer_text_new ();
-      
+
       col = gtk_tree_view_column_new_with_attributes ("Column 1",
                                                       rend,
                                                       "text", 1,
@@ -626,17 +624,14 @@ create_tree_model (void)
   GtkTreeStore *store;
   gint i;
   GType *t;
-  volatile GType dummy; /* G_GNUC_CONST makes the optimizer remove
-                         * get_type calls if you don't do something
-                         * like this
-                         */
   
   /* Make the tree more interesting */
-  dummy = gtk_scrolled_window_get_type ();
-  dummy = gtk_label_get_type ();
-  dummy = gtk_hscrollbar_get_type ();
-  dummy = gtk_vscrollbar_get_type ();
-  dummy = pango_layout_get_type ();
+  /* - we need this magic here so we are sure the type ends up being
+   * registered and gcc doesn't optimize away the code */
+  g_type_class_unref (g_type_class_ref (gtk_scrolled_window_get_type ()));
+  g_type_class_unref (g_type_class_ref (gtk_label_get_type ()));
+  g_type_class_unref (g_type_class_ref (gtk_scrollbar_get_type ()));
+  g_type_class_unref (g_type_class_ref (pango_layout_get_type ()));
 
   t = get_model_types ();
   
@@ -684,6 +679,14 @@ columns_selected (GtkComboBox *combo_box, gpointer data)
     }
 }
 
+void
+on_row_activated (GtkTreeView       *tree_view,
+                  GtkTreePath       *path,
+                  GtkTreeViewColumn *column,
+                  gpointer           user_data)
+{
+  g_print ("Row activated\n");
+}
 
 enum
 {
@@ -702,13 +705,16 @@ main (int    argc,
   GtkWidget *window;
   GtkWidget *sw;
   GtkWidget *tv;
-  GtkWidget *table;
+  GtkWidget *box;
   GtkWidget *combo_box;
   GtkTreeModel *model;
   gint i;
   
   gtk_init (&argc, &argv);
 
+  if (g_getenv ("RTL"))
+    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
+
   our_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) book_closed_xpm);  
   
 #if 0
@@ -736,12 +742,13 @@ main (int    argc,
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
   gtk_window_set_default_size (GTK_WINDOW (window), 430, 400);
 
-  table = gtk_table_new (3, 1, FALSE);
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
-  gtk_container_add (GTK_CONTAINER (window), table);
+  gtk_container_add (GTK_CONTAINER (window), box);
 
   tv = gtk_tree_view_new_with_model (models[0]);
-  
+  g_signal_connect (tv, "row-activated", G_CALLBACK (on_row_activated), NULL);
+
   gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tv),
                                          GDK_BUTTON1_MASK,
                                          row_targets,
@@ -754,29 +761,24 @@ main (int    argc,
                                        GDK_ACTION_MOVE | GDK_ACTION_COPY);
   
   /* Model menu */
-  combo_box = gtk_combo_box_new_text ();
+  combo_box = gtk_combo_box_text_new ();
+  gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
   for (i = 0; i < MODEL_LAST; i++)
-      gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), model_names[i]);
-  
-  gtk_table_attach (GTK_TABLE (table), combo_box,
-                    0, 1, 0, 1,
-                    0, 0, 
-                    0, 0);
+      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), model_names[i]);
 
+  gtk_container_add (GTK_CONTAINER (box), combo_box);
   g_signal_connect (combo_box,
                     "changed",
                     G_CALLBACK (model_selected),
                    tv);
   
   /* Columns menu */
-  combo_box = gtk_combo_box_new_text ();
+  combo_box = gtk_combo_box_text_new ();
+  gtk_widget_set_halign (combo_box, GTK_ALIGN_CENTER);
   for (i = 0; i < COLUMNS_LAST; i++)
-      gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), column_type_names[i]);
-  
-  gtk_table_attach (GTK_TABLE (table), combo_box,
-                    0, 1, 1, 2,
-                    0, 0, 
-                    0, 0);
+      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), column_type_names[i]);
+
+  gtk_container_add (GTK_CONTAINER (box), combo_box);
 
   set_columns_type (GTK_TREE_VIEW (tv), COLUMNS_LOTS);
   gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), COLUMNS_LOTS);
@@ -787,18 +789,19 @@ main (int    argc,
                     tv);
   
   sw = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_hexpand (sw, TRUE);
+  gtk_widget_set_vexpand (sw, TRUE);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                   GTK_POLICY_AUTOMATIC,
                                   GTK_POLICY_AUTOMATIC);
   
-  gtk_table_attach (GTK_TABLE (table), sw,
-                    0, 1, 2, 3,
-                    GTK_EXPAND | GTK_FILL,
-                    GTK_EXPAND | GTK_FILL,
-                    0, 0);
+  gtk_container_add (GTK_CONTAINER (box), sw);
   
   gtk_container_add (GTK_CONTAINER (sw), tv);
   
+  create_prop_editor (G_OBJECT (tv), GTK_TYPE_TREE_VIEW);
+  create_prop_editor (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tv))), GTK_TYPE_TREE_SELECTION);
+
   gtk_widget_show_all (window);
   
   gtk_main ();