The Window expose-event with gtk_window_resize() problem:



Hi,
        The following program is very simple, just draw a rectangle on
the GtkWindow. But it give me problems, It draw 2 lines when I use
gtk_window_resize function.
        Following program when I click mouse button, it show 2 lines.
        
        Thanks.
Tom.

//---------------------------------------
#include "gtk/gtk.h"
#include "stdio.h"

static gboolean expose(GtkWidget * widget, GdkEvent *event, gpointer
data)
{
        int x,y,w,h;
        x=y=0;
        w=widget->allocation.width;
        h=widget->allocation.height;
        fprintf(stderr,"Debug:%s,%d:expose:wid:%d,hi:%d,\n",
                __FILE__,__LINE__,w,h);
        gdk_window_clear(widget->window);// clear all this window;
        gdk_draw_rectangle(widget->window,(widget->style->black_gc),
                false,5,5,w-10,h-10);
        return FALSE;
}
static gboolean press(GtkWidget * widget, GdkEvent *event, gpointer
data)
{
        
gtk_window_resize(GTK_WINDOW(widget),widget->allocation.width+20,
                widget->allocation.height+20);
        return FALSE;
}

int main( int   argc, char *argv[] )
{
        GtkWidget *window;
        gtk_init (&argc, &argv);
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_app_paintable(window, TRUE);
        gtk_widget_set_events(window,GDK_BUTTON_PRESS_MASK|
GDK_EXPOSURE_MASK);
    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK
(gtk_main_quit), NULL);
        g_signal_connect(G_OBJECT(window),"expose-event",
G_CALLBACK(expose),NULL);
        g_signal_connect(G_OBJECT(window), "button_press_event",
G_CALLBACK(press), NULL);

        gtk_widget_show(window);
        gtk_main ();
    return 0;

}




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