Re: [GTK +] Problem with Pixmap



porte cyril wrote:
> void Affiche_Pixmap(GtkWidget *top_level_window,struct struct_outil
> *outil)
> {
> // top_level_window is the widget of my GTK_WINDOW_TOPLEVEL
> // struct_outil is a structure for some of my widget
> GtkStyle *style;
> GdkPixmap *pixmap;
> GdkBitmap *mask;
> GtkWidget *my_pixmap;
> 
> style = gtk_widget_get_style(top_level_window);
> pixmap =
> gdk_pixmap_create_from_xpm(top_level_window->window,&mask,&style->bg[GTK_STATE_NORMAL],
> "./PIXMAPS/Machine.OK.xpm");
> my_pixmap = gtk_pixmap_new(pixmap,mask);
> gtk_container_add (GTK_CONTAINER (outil->bouton.image_frame),
> my_pixmap);
> gtk_widget_show (my_pixmap);
> }

Hi Cyril, the problem is that your top_level_window is not realised when
you call gdk_pixmap_create_from_xpm(), so it has no underlying X window
yet, and no colormap.

I get around this problem by having an invisible top-level window for my
application. In main(), just after gtk_init(), I do:

        GtkWidget *main_window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
        gtk_widget_realize( main_window );
        GdkWindow *main_window_gdk = main_window->window;

Then anywhere in my app I can do:

	GdkPixmap *px = gdk_pixmap_create_from_xpm_d( 
	  main_window_gdk, &mask, NULL, blah_xpm );
	GtkPixmap *my_pixmap = gtk_pixmap_new( px, mask );

without having to worry about whether my windows are realised. There's
probably a better way :-)

HTH, John
-- 
John Cupitt, john cupitt ng-london org uk, +44 (0)20 7747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]