1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <gtk/gtk.h>
#define NB_COLORS (sizeof (colors)/sizeof(colors[0]))
static const GdkColor colors[] = {
{0, 0xFFFF, 0xFFFF, 0xFFFF},
{0, 0xE0E0, 0xE0E0, 0xE0E0}
};
int main (int argc, char** argv)
{
GtkWidget* window = NULL;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "destroy", gtk_main_quit, NULL);
{
gint i=0;
GtkWidget* tree_view;
GtkListStore* list_store = NULL;
GtkCellRenderer *renderer = NULL;
GtkTreeViewColumn* column = NULL;
list_store = gtk_list_store_new ( 3, GDK_TYPE_COLOR, G_TYPE_STRING, G_TYPE_STRING);
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), true );
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("col1", renderer, "background-gdk", 0, "text", 1, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("col2", renderer, "background-gdk", 0, "markup", 2, NULL); // annotation 1
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
char *text1 = NULL;
char *text2 = NULL;
GtkTreeIter iter;
gtk_list_store_append (list_store, &iter);
text1 = g_strdup_printf ("Line %d", 1 );
text2 = g_strdup_printf ("<span background=\"blue\" size=\"x-large\">Blue text</span> is <i>cool</i>!" ); //annotation 2
gtk_list_store_set (list_store, &iter, 0, &colors[i%NB_COLORS], 1, text1, 2, text2, -1);
g_free (text1), text1 = NULL;
g_free (text2), text2 = NULL;
gtk_container_add (GTK_CONTAINER (window), tree_view);
}
gtk_widget_show_all (window);
gtk_main ();
return 0;
} |
Partager