[gtkada] inserting a xpm image
Bobby D. Bryant
bdbryant at mail.utexas.edu
Wed Sep 20 05:32:55 CEST 2000
caleb baker wrote:
> hi
>
> i'm trying to load an xpm image into a gui and i'm using pixmap and i'm
> having trouble doing this.
>
> i'm using the code
>
> colour := white(Gtk.Widget.Get_Default_Colormap);
> Clear(Graphics_window);
> Set_Background (Graphics_window, colour);
> Gdk.Bitmap.Gdk_New (mask, Graphics_window, 250, 250);
> Create_From_Xpm (pic, Graphics_window, mask, colour, Image_file);
>
> and it's complaining that graphics_window is null, i have looked the the
> Gdk-window.ads and i can't find anything which sets what the graphics window
> actually has in it.
It's a bit hard to tell without seeing your declarations. I presume
Graphics_Window is a Gdk.Window.Gdk_Window? If so, you can initialize it by
calling Gtk.Window.Get_Window and passing your main Gtk_Window as an argument.
(That call finds the Gdk_Window associated with a Gtk_Window.)
However, you will have a similar problem if the Gtk_Window is null when you
make that call, so you need to either "show" or "realize" your Gtk_Window
before you try to find its associated Gdk_Window. Since your window is
apparently not ready for showing yet, I recommend calling Gtk.Window.Realize
and passing your main Gtk_Window as the argument, just before you try the call
above to find its Gdk_Window. (The .Realize apparently generates some internal
data structures that you need before making the Get_Window call.)
> also i'm not sure how to show it
I may not be doing this the most elegant way, but here's an overview of what
works for me:
o Create a Gdk_Pixmap for your "offscreen" pixmap, using Create_From_Xpm
similarly to above.
o Create a Gtk_Pixmap for you "onscreen" pixmap and simultaneously bind it to
your "offscreen" pixmap with Gtk.Pixmap.Gtk_New.
o Pack the Gtk_Pixmap into a Gtk_Window.
o Show the Gtk_Window.
You can find all this in the testgtk program that ships with GtkAda. Most of
the interesting stuff is in create_pixmap.adb, though the creation of the
top-level window is done elsewhere in the code.
Good luck,
Bobby Bryant
Austin, Texas
More information about the gtkada
mailing list