bug in gtklayout? (take two)




The code below displays a arrow when run.

When you press the button, then the arrow should disappear
because of the gtk_widget_hide() call and another appear.
But the arrow don't disappear until the window is redrawn
(for example by moving another window over it with the mouse).





#include <gtk/gtk.h>

/* XPM */
static char * pc_xpm[] = {
"14 14 2 1",
"       c None",
".      c #009B1C",
"              ",
"              ",
"       .      ",
"       ..     ",
"        ..    ",
"        ...   ",
"............  ",
"............. ",
"............  ",
"        ...   ",
"        ..    ",
"       ..     ",
"       .      ",
"              "};

GtkWidget *layout, *widget2, *widget1;

void func(GtkWidget *w, gpointer data)
{
    gtk_layout_move(GTK_LAYOUT(layout), widget2, 10, 120);
    
    // uncommenting this makes it work
 //   while(gtk_events_pending())  
 //       gtk_main_iteration();   
        
    gtk_widget_hide(widget1);
}

int main(int argc, char *argv[])
{
    GtkWidget *window, *hbox, *button;

    GtkStyle *style=NULL;
    GdkBitmap *mask;
    GdkPixmap *pixmap;
    
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window),300,100);
    gtk_widget_show(window);
    hbox = gtk_hbox_new(0,0);
    gtk_widget_show(hbox);
    gtk_container_add(GTK_CONTAINER(window),hbox);

    button = gtk_button_new_with_label("scroll");
    gtk_signal_connect(GTK_OBJECT(button),"button_press_event",
                    GTK_SIGNAL_FUNC(func),NULL);
    gtk_widget_show(button);
    gtk_box_pack_start_defaults(GTK_BOX(hbox),button);
    
    layout = gtk_layout_new(NULL,NULL);
    gtk_widget_show(layout);
    gtk_layout_set_size(GTK_LAYOUT(layout),200,400);
    gtk_box_pack_start_defaults(GTK_BOX(hbox),layout);

    style = gtk_widget_get_style(window);
    pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,
                                             &style->bg[GTK_STATE_NORMAL],
                                                   (gchar**)pc_xpm);

    // widget1 won't go away when button is pressed
    widget1 = gtk_pixmap_new(pixmap,mask);
    gtk_widget_show(widget1);
    gtk_layout_put(GTK_LAYOUT(layout),widget1,5,180);

    // widget2 is ok
    widget2 = gtk_pixmap_new(pixmap,mask);
    gtk_widget_show(widget2);
    gtk_layout_put(GTK_LAYOUT(layout),widget2,5,22);

    gtk_adjustment_set_value(GTK_ADJUSTMENT(GTK_LAYOUT(layout)->vadjustment),100);

    gtk_main();

   return 0;   
}


/ Ralf



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