/* * Build: * gcc $(pkg-config --cflags gtk+-3.0) sscce.c -o sscce $(pkg-config --libs gtk+-3.0) */ #include enum { MODEL_NAME = 0, N_COLUMNS }; void init_list (GtkWidget *list) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *store; column = gtk_tree_view_column_new (); gtk_tree_view_append_column (GTK_TREE_VIEW (list), column); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (column), renderer, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (column), renderer, "text", MODEL_NAME); g_object_set (G_OBJECT (renderer), "wrap-mode", PANGO_WRAP_WORD, NULL); store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING); gtk_tree_view_set_model (GTK_TREE_VIEW (list), GTK_TREE_MODEL (store)); g_object_unref (store); } void add_to_list (GtkWidget *list, const gchar *str) { GtkTreeIter iter; GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (list))); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, MODEL_NAME, str, -1); } int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *list; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); gtk_container_set_border_width (GTK_CONTAINER (window), 5); gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); list = gtk_tree_view_new (); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE); gtk_container_add (GTK_CONTAINER (window), list); init_list (list); add_to_list (list, "Lorem ipsum dolor sit amet"); add_to_list (list, "Consectetur adipiscing elit"); add_to_list (list, "Morbi aliquam volutpat augue"); add_to_list (list, "Eu condimentum lectus pretium vitae"); add_to_list (list, "Nullam est diam"); add_to_list (list, "Efficitur rhoncus tincidunt"); add_to_list (list, "Phasellus libero sem"); add_to_list (list, "Consectetur id magna nec"); add_to_list (list, "Tempor hendrerit ligula"); add_to_list (list, "Quisque a tincidunt metus"); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (window); gtk_main (); return 0; }