...略...
//ここから追加
void set_treevw_def(GtkWidget *treeview)
{
GtkListStore *store;
// define table and create GtkListStore
store = gtk_list_store_new(
5, // number of columns in the list store
G_TYPE_INT, //all GType types for the columns, from first to last
G_TYPE_STRING,//all GType types for the columns, from first to last
G_TYPE_INT, //all GType types for the columns, from first to last
G_TYPE_INT, //all GType types for the columns, from first to last
G_TYPE_STRING //all GType types for the columns, from first to last
);
// set GtkListStore to GtkTreeView
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
// Decreases the reference count if object.
// When its reference count drops to 0, the object is finalized
// (i.e. its memory is freed).
g_object_unref(store);
}
void append_column_to_treeview( GtkWidget *treeview,
const char *title,
const int order )
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(
title,
renderer,
"text", order,
NULL
);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
}
void set_title(GtkWidget *treeview)
{
append_column_to_treeview( treeview, "Col 0", 0 );
append_column_to_treeview( treeview, "Col 1", 1 );
append_column_to_treeview( treeview, "Col 2", 2 );
append_column_to_treeview( treeview, "Col 3", 3 );
append_column_to_treeview( treeview, "Col 4", 4 );
}
void set_data(GtkWidget *treeview)
{
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW(treeview) ) );
gtk_list_store_clear(store);
// row 1st
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
0, 10,
1, "C1R1",
2, 12,
3, 13,
4, "C4R1",
-1
);
// row 2nd
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
0, 20,
1, "C1R2",
2, 22,
3, 23,
4, "C4R2",
-1
);
}
//ここまで
create_window1 (void)
{
GtkWidget *window1;
GtkWidget *scrolledwindow1;
GtkWidget *treeview1;
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window1), _("window1"));
scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow1);
gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
gtk_widget_set_size_request (scrolledwindow1, 400, 300);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN);
treeview1 = gtk_tree_view_new ();
//ここから追加
set_treevw_def(treeview1);
set_title(treeview1);
set_data(treeview1);
//ここまで
gtk_widget_show (treeview1);
gtk_container_add (GTK_CONTAINER (scrolledwindow1), treeview1);
/* Store pointers to all widgets, for use by lookup_widget(). */
GLADE_HOOKUP_OBJECT_NO_REF (window1, window1, "window1");
GLADE_HOOKUP_OBJECT (window1, scrolledwindow1, "scrolledwindow1");
GLADE_HOOKUP_OBJECT (window1, treeview1, "treeview1");
return window1;
}
|