Colored pixmap in a CList widget.
- From: Deganello Aligi <Aligi Deganello bologna marelli it>
- To: "'gtk-app-devel-list gnome org'" <gtk-app-devel-list gnome org>
- Subject: Colored pixmap in a CList widget.
- Date: Fri, 27 Jun 2003 17:14:30 +0200
Hi all,
I want to put a Color column in a clist and I want to show a monocolored
pixmap in every line. I wonder if it possible to change the foreground color
of the pixmap dynamically, that is I click on the column with the pixmap
inside and I'll get a colorselection window where I can set the foreground
color of the pixmap itself.
What I get in the example below is to set the foreground of the list.
Thanks in advance, Aligi.
/* example-start clist clist.c */
#include <gtk/gtk.h>
GdkPixmap *pixmap;
static const char bitmap_data[] =
{
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,1,1,1,1,0,0,
0,0,1,1,1,1,0,0,
0,0,1,1,1,1,0,0,
0,0,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
void selection_made( GtkWidget *clist,
gint row, gint column,
GdkEventButton *event,
gpointer data )
{
gchar *text;
GdkColor color = { 0, 0xffff, 0, 0 };
GdkColormap *colormap;
gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
g_print("You selected row %d and column %d, with text %s\n\n", row,
column, text);
/* Now I want to change foreground color to pixmap in column 3 */
colormap=gdk_window_get_colormap(clist->window);
gdk_colormap_alloc_color(colormap, &color, TRUE, TRUE);
gdk_gc_set_foreground(clist->style->black_gc, &color);
gtk_clist_set_pixmap( (GtkCList *) clist, 1, 2, pixmap, NULL);
return;
}
int main( int argc, gchar *argv[] )
{
gchar *drink[3][3] = { { "Milk", "3 Oz", "" },
{ "Water", "6 l", "" },
{ "Carrots", "2", "" } };
GtkWidget *window;
GtkWidget *clist;
GdkBitmap *mask;
GtkStyle *style;
gint indx;
gchar *titles[] = { "Ingredients", "Amount", "Color" };
gtk_init(&argc, &argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkCList Example");
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
clist = gtk_clist_new_with_titles( 3, titles);
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(selection_made), pixmap);
gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_OUT);
gtk_clist_set_column_width (GTK_CLIST(clist), 0, 120);
gtk_container_add(GTK_CONTAINER(window), clist);
gtk_widget_show(clist);
pixmap = gdk_bitmap_create_from_data( window->window, bitmap_data, 8, 8
);
for ( indx=0 ; indx < 3 ; indx++ )
{
gtk_clist_append( GTK_CLIST(clist), drink[indx]);
gtk_clist_set_pixmap( (GtkCList *) clist, indx, 2, pixmap, NULL);
}
gtk_widget_show(window);
gtk_main();
return(0);
}
/* example-end */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]