colour question
- From: ashley maher <ashley maher didymodesigns com au>
- To: gtk-list gnome org
- Subject: colour question
- Date: Wed, 02 Nov 2005 16:39:54 +1100
G'day,
Trying to get my head around gtk2 I put together the code below from
examples in the gtktree tutorial and the colour example code I found in
the mailing list.
ie.
http://mail.gnome.org/archives/gtk-app-devel-list/2002-November/msg00249.html
It compiles, and runs.
Unfortunately it colours the entire background blue and all fonts are
white. Not just the right hand column as in the example and as I wanted.
Could somebody please point me to where I stuffed up in the code below,
and or where to get info to fix what I clearly have misunderstood.
And where can I find a reference for stippling the background of a cell?
Thanks in advance.
Regards,
Ashley
#################
/* -*-coding: utf-8;-*- */
/* colour_dump.c -- demonstrate GtkTreeView */
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
const char *numbers[] = { "Zero", "One", "Two", "Three", "Four",
"Five" };
const char *keys[] = {"AA", "ZB", "TY", "T6", "9T", "56" };
enum {
COL_KEY = 0,
COL_INT,
COL_STRING,
COL_COLOUR_BG,
COL_COLOUR_FG,
N_COLUMNS
};
/* standard event handlers */
gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
return FALSE;
}
void end_program(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
static void
onSelectionChanged (GtkTreeSelection *sel, GtkListStore *liststore)
{
GtkTreeIter selected_row; /* the iter I've been loking at
*/
GtkTreeModel *model;
gchar *key;
/* Check if a row is selected or not */
/* This will only work in SINGLE or BROWSE mode! */
if (gtk_tree_selection_get_selected(sel, &model, &selected_row))
{
gtk_tree_model_get (model, &selected_row, COL_KEY, &key,
-1);
g_print ("Key for selected row is: %s\n\n", key);
g_free(key);
}
else
{
printf ("Something\n\n");
}
}
int main(int argc, char **argv)
{
GtkWindow *window;
GtkListStore *list;
GtkTreeIter iter;
GtkTreeView *view;
GtkTreeViewColumn *num_column, *word_column;
GtkCellRenderer *text_renderer;
gint i;
GtkTreeSelection *sel;
GdkColor colors[2];
gboolean success[2];
GtkWidget *tv;
/* initialize GTK+, create main window */
gtk_init(&argc, &argv);
/* setup the colours */
/*********************/
/* forground *********/
colors[0].red = 0;
colors[0].blue = 65535;
colors[0].green = 0;
/* background ********/
colors[1].red = 65535;
colors[1].blue = 65535;
colors[1].green = 65535;
/* map the colours **/
gdk_colormap_alloc_colors(
gdk_colormap_get_system(),
colors,
2,
FALSE,
FALSE,
success
);
/* initialize GTK+, create main window */
/* gtk_init(&argc, &argv); */
window = g_object_new(GTK_TYPE_WINDOW,
"title", "Two Column List",
"default-width", 300,
NULL);
/* connect standard handlers */
g_signal_connect(window, "delete_event", G_CALLBACK(delete_event),
NULL);
g_signal_connect(window, "destroy", G_CALLBACK(end_program), NULL);
/* create a two-column list */
list = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_INT,
G_TYPE_STRING, GDK_TYPE_COLOR, GDK_TYPE_COLOR);
/* put some data into the list */
for (i = 0; i < 5; i++)
{
gtk_list_store_append(list, &iter);
gtk_list_store_set(list, &iter,
COL_KEY, keys[i],
COL_INT, i,
COL_STRING, numbers[i],
COL_COLOUR_BG, &colors[0],
COL_COLOUR_FG, &colors[1],
-1);
}
/* create tree view for the list */
view = g_object_new(GTK_TYPE_TREE_VIEW,
"model", list,
"rules-hint", TRUE,
"headers-clickable", TRUE,
"reorderable", TRUE,
"enable-search", TRUE,
"search-column", COL_STRING,
NULL);
/* create and initialize text renderer for cells */
text_renderer = gtk_cell_renderer_text_new();
/* create column views */
num_column = gtk_tree_view_column_new_with_attributes("Numeral",
text_renderer,
"text", COL_INT,
NULL);
g_object_set(num_column,
"resizable", TRUE,
"clickable", TRUE,
"reorderable", TRUE,
NULL);
word_column = gtk_tree_view_column_new_with_attributes("Word",
text_renderer,
"text",
COL_STRING,
"background-gdk", COL_COLOUR_BG,
"foreground-gdk", COL_COLOUR_FG,
NULL);
g_object_set(word_column,
"resizable", TRUE,
"clickable", TRUE,
"reorderable", TRUE,
NULL);
/* insert columns into the view */
gtk_tree_view_append_column(view, num_column);
gtk_tree_view_append_column(view, word_column);
/* Get the selection code in */
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
g_signal_connect(sel, "changed", G_CALLBACK(onSelectionChanged),
list);
/* pack/show everything; start GTK+ main event loop */
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]