See-through container



Hi folks,

I previously posted a question about containers; specifically, i want to
have a layout container in which drawing
done to the parent window "shows through" layout where nothing is placed
on the layout.  Here's an example of what's not working for me.
The diagonal line is obscured by the inner_layout Layout container,
although I am setting the back_pixmap for the Layout's window and
bin_window to NULL, which is supposed to do what I want.  Anybody have
any suggestions?

#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

static gboolean layout_expose(GtkWidget *widget, GdkEventExpose *event) {
  printf("expose, %d, %d\n", event->area.width, event->area.height);
  GtkLayout *layout = GTK_LAYOUT(widget);
  gdk_draw_line (layout->bin_window,
         widget->style->black_gc,
         0, 0,
         widget->allocation.width, widget->allocation.height);
}

static gboolean inner_layout_realize(GtkWidget *widget, GdkEventExpose
*event) {
  printf("realize\n");
  GtkLayout *layout = GTK_LAYOUT(widget);
  gdk_window_set_back_pixmap(widget->window, NULL, FALSE);
  gdk_window_set_back_pixmap(layout->bin_window, NULL, FALSE);
}

int main( int   argc,
          char *argv[] ) {
  /* GtkWidget is the storage type for widgets */
  GtkWidget *window, *layout, *inner_layout, *label;
  GdkColor color;

  /* Initialise GTK */
  gtk_init (&argc, &argv);
    
  /* Create a new window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Frame Example");

  /* Here we connect the "destroy" event to a signal handler */
  g_signal_connect (G_OBJECT (window), "destroy",
            G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_set_size_request (window, 500, 500);

  /* Create a layout */
  layout = gtk_layout_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (window), layout);
  gtk_widget_set_size_request (layout, 500, 500);
  gtk_widget_show (layout);

  /* Create an inner layout */
  inner_layout = gtk_layout_new (NULL, NULL);
  gtk_layout_put (GTK_LAYOUT (layout), inner_layout, 100, 100);
  gtk_widget_set_size_request (inner_layout, 200, 200);
  gtk_widget_show (inner_layout);

  /* Create a label in inner layout */
  label = gtk_label_new ("Test");
  gtk_container_add (GTK_CONTAINER (inner_layout), label);
  gtk_widget_show (label);

  g_signal_connect (G_OBJECT (layout), "expose_event",
            G_CALLBACK (layout_expose), NULL);
  g_signal_connect (G_OBJECT (inner_layout), "realize",
            G_CALLBACK (inner_layout_realize), NULL);


  /* Create a layout inside the layout */
  /* Display the window */
  gtk_widget_show (window);
    
  /* Enter the event loop */
  gtk_main ();
    
  return 0;
}




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