Re: Manipulating viewport in scrolled window



Simon Gornall wrote:
> Hmm. Perhaps I'm missing something to do with "after you connected..."
> then because I'm still getting the same problem - the scrollbars are
> scrolling to the correct point (adj->upper should just be 'big' BTW)
> but the window view remains resolutely at (0,0).

This is pretty odd :-(, I don't know what else might be wrong. Here's a tiny
test prog (I expect the formatting will get messed up):

--
#include <gtk/gtk.h>

#define WIDTH (1000)
#define HEIGHT (1000)
#define ADDR( X, Y ) (image + ((Y) * WIDTH + (X)) * 3)

static unsigned char image[WIDTH * HEIGHT * 3];

static void
init_image( void )
{
        int x, y;

        for( y = 0; y < HEIGHT; y++ ) 
                for( x = 0; x < WIDTH; x++ ) {
                        unsigned char * const p = ADDR( x, y );

                        p[0] = (256 * x) / WIDTH;
                        p[1] = (256 * y) / HEIGHT;
                        p[2] = x + y;
                }
}

static gint
expose( GtkWidget *darea, GdkEventExpose *event )
{
        const unsigned char *buf = ADDR( event->area.x, event->area.y );

        gdk_draw_rgb_image( darea->window,
                darea->style->white_gc,
                event->area.x, event->area.y,
                event->area.width, event->area.height,
                GDK_RGB_DITHER_MAX,
                (guchar *) buf, WIDTH * 3 );

        return( FALSE );
}

void
adj_centre( GtkAdjustment *adj )
{
        const double range = adj->upper - adj->lower - adj->page_size;

        gtk_adjustment_set_value( adj, adj->lower + range / 2 );
}

int
main( int argc, char **argv )
{
        GtkWidget *window;
        GtkWidget *swin;
        GtkWidget *darea;

        GtkAdjustment *hadj;
        GtkAdjustment *vadj;

        gtk_set_locale();
        gtk_init( &argc, &argv );
        init_image();
        gdk_rgb_init();
        gtk_widget_set_default_colormap( gdk_rgb_get_cmap() );
        gtk_widget_set_default_visual( gdk_rgb_get_visual() );

        darea = gtk_drawing_area_new();
        gtk_drawing_area_size( GTK_DRAWING_AREA( darea ), WIDTH, HEIGHT );
        gtk_signal_connect( GTK_OBJECT( darea ), "expose_event",
                GTK_SIGNAL_FUNC( expose ), NULL );

        swin = gtk_scrolled_window_new( NULL, NULL );
        gtk_scrolled_window_add_with_viewport( 
                GTK_SCROLLED_WINDOW( swin ), darea );
        hadj = gtk_scrolled_window_get_hadjustment( 
                GTK_SCROLLED_WINDOW( swin ) );
        vadj = gtk_scrolled_window_get_vadjustment( 
                GTK_SCROLLED_WINDOW( swin ) );

        window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
        gtk_container_add( GTK_CONTAINER( window ), swin );
        gtk_widget_set_usize( window, 500, 500 );

        gtk_widget_show_all( window );

        adj_centre( hadj );
        adj_centre( vadj );

        gtk_main();

        return( 0 );
}
-- 

This works for me. Does this help?

John




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