Re: rewrite question:how to attach a pixmap to a GtkWindow as the background




Jiang XU <jiang.xu@echostar.com> writes:

> I have been driven crazy!!
> 
> But, first thanks Todd!, at least I can get the GdkWindow.
> But I still can not put the pixmap as the background of the GtkWIndow. It
> doesn't show up!!
> So, I guess I still need Help!!
> Thanks very much!!
> 
> The following is the source code (test example), it only include one table and
> one button:
> I use gtk_window_new to create window1 and use gtk_widget_realize to set
> window1->window, then I use gdk_window_set_back_pixmap to set the pixmap as
> the background. but when run the application, it does not show the pixmap.  I
> wonder what's wrong!
> 
> Need help!!
> Thanks very very much!
> 
> #include <sys/stat.h>
> #include <unistd.h>
> #include <string.h>
> #include <gtk/gtk.h>
> #include "interface.h"
> 
> GtkWidget*
> create_window1 ()
> {
>   GtkWidget *window1;
>   GtkWidget *table1;
>   GtkWidget *button1;
>   GdkPixmap *pixmap;
>   GdkBitmap *mask;
>   GtkStyle *style;
> 
>   window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>   gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
>   gtk_widget_set_usize (window1, 640, 480);
>   gtk_window_set_title (GTK_WINDOW (window1), "window1");
>   //set windows->window, which is GdkWindow
>   gtk_widget_realize(window1);
> 
>   //create table
>   table1 = gtk_table_new (10, 10, FALSE);
>   gtk_widget_ref (table1);
>   gtk_object_set_data_full (GTK_OBJECT (window1), "table1", table1,
>                             (GtkDestroyNotify) gtk_widget_unref);
>   gtk_widget_show (table1);
>   gtk_container_add (GTK_CONTAINER (window1), table1);
> 
>   //create button
>   button1 = gtk_button_new_with_label ("button1");
>   gtk_widget_ref (button1);
>   gtk_object_set_data_full (GTK_OBJECT (window1), "button1", button1,
>                             (GtkDestroyNotify) gtk_widget_unref);
>   gtk_widget_show (button1);
>   gtk_table_attach (GTK_TABLE (table1), button1, 4, 5, 8, 9,
>                     (GtkAttachOptions) (0),
>                     (GtkAttachOptions) (0), 0, 0);
> 
>   //create pixmap
>   style=gtk_widget_get_style(window1);
> 
> pixmap=gdk_pixmap_create_from_xpm(window1->window,&mask,&style->bg[GTK_STATE_NORMAL],"./BACKGROUND.XPM");
> 
>   gdk_window_set_back_pixmap(window1->window,pixmap,0);
> 
>   gdk_window_show(window1->window);
> 
>    return window1;
> }

You want something like:

   /* Realize the GtkWindow so the GdkWindow exists */
   gtk_widget_realize (window1);

   /* We need to realize the widget or call gtk_widget_ensure_style()
    * _before_ we get the style. Also, the widget needs to be
    * realized to access widget->window
    */
   style = gtk_widget_get_style (window1);

   pixmap = gdk_pixmap_create_from_xpm(window1->window,&mask,&style->bg[GTK_STATE_NORMAL],"./BACKGROUND.XPM");
   
   /* Notify GTK+ that we will be drawing the window's background
   gtk_widget_set_app_paintable (window1->window, TRUE);

   gdk_window_set_back_pixmap (window1->window, pixmap, FALSE);

   /* Show the widget, and GTK+ will take care of widget->window */
   gtk_widget_show (window1);
   
Regards,
                                        Owen

    
  
    



  



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