Re: scrolled window vadj not being set



Thank you for your response. I already had a connection to a size_allocate signal but that is not triggered by splitting the display.

I have made a little progress, but still don't have the answer. The splitting process consists of making a new paned object, adding a frame to that and reparenting the scrolled window into the frame, before adding a second frame as child2 for the new scrolled window.

At the point of reparenting, the original scrolled window allocation height is reset from the correct value to 1, and thereafter the new one's allocation height is also 1.

Now clearly _something_ out there knows what size to make these widgets, since they end up the right size, but I can't find out what it is, nor how to access the sizes.

I attach a small programme to demo the problem. I actually threw away most of the code and what's left doesn't actually split the screen so much as destroy the previous scrolled window, canvas, etc, and create a new set in their place. The effect is the same - before I hit the button I have a useable page size, afterwards I don't.

Hope someone can help
Rob Clack


Vladislav Grinchenko wrote:
Rob,

have you tried to connect to size_allocate signal?

-Vlad

On Mon, 2004-11-15 at 07:58, Rob Clack wrote:

My application allows the user to split the display as many times as she wants. Each time she does so, I add an hpane or vpane as child2 to the existing hpane or vpane, then add a scrolled window. (I might not do it in precisely that order, but I'm hoping that won't matter.)

For various reasons, I need to know the size of the display in pixels, which is where the problem arises. I use gtk_window_set_default_size() to control the initial display (size_request would prevent the user from shrinking the window) and gtk_scrolled_window_get_vadjustment() to get the vertical height.

On initial display, the height in the adjustment is correct, but when I split the display, the exact same piece of code returns an adjustment containing mostly zeroes. Specifically, Upper is set, but step and page increments and page size are all zero.

How can I reliably obtain the display height and width in pixels?

My GTK is 2.0 and I'm running Red Hat 9.

Thanks
Rob Clack
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

make with:

FOOCFLAGS = -v -g -Wall `pkg-config --cflags libfoocanvas`
FOOLDFLAGS = `pkg-config --libs libfoocanvas`

test : test.c
        cc -g -o test $(FOOCFLAGS) -L../foocanvas $(FOOLDFLAGS) test.c


/******************* test.c ******************************************/
/*  Last edited: Nov 23 16:52 2004 (rnc) */

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <libfoocanvas/libfoocanvas.h>

static void SplitPane(GtkWidget *widget, gpointer data);


GtkWidget *window, *vpane;
GtkWidget *vbox, *toolbar, *swindow, *frame;
FooCanvas *canvas;


static void Quit(GtkWidget *widget, gpointer data)
{
  gtk_main_quit();
  return;
}


/* Build the top level window, add a vbox, hbox, two toolbars */
static void createMainWindow()
{
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (Quit), window);

  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  gtk_window_set_default_size (GTK_WINDOW(window), 750, 550);

    /* add a vbox for the toolbar and main pane */
  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);

  toolbar = gtk_toolbar_new();

gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "H-Split","Split Window Horizontally",
                          NULL, NULL, GTK_SIGNAL_FUNC(SplitPane), window );

  gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);

  vpane = gtk_vpaned_new();
  gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 0);

  return;
}


static void addPane()
{
  GtkWidget *w;
  int width = 1000, height = 50000;
  GdkColor color;
  GtkAdjustment *adj;
  GtkScrolledWindow *scrolledWindow;

  gtk_window_set_default_size (GTK_WINDOW(window), 750, 550);

  /* set up splitPane for this window */
  frame        = gtk_frame_new(NULL);
  swindow      = gtk_scrolled_window_new (NULL, NULL);

  /* draw the canvas */
  w = foo_canvas_new();

  canvas = FOO_CANVAS(w);
  foo_canvas_set_scroll_region(canvas, 0.0, 0.0, width, height);
  gdk_color_parse("white", &color);
  gtk_widget_modify_bg(GTK_WIDGET(canvas), GTK_STATE_NORMAL, &color);

  /* add the canvas to the scrolled window */
  gtk_container_add(GTK_CONTAINER(swindow),w);

  gtk_paned_pack1(GTK_PANED(vpane), frame, TRUE, TRUE);

  /* add the scrolled window to the frame */
  gtk_container_add(GTK_CONTAINER(frame),swindow);

  gtk_widget_show_all (window);

  scrolledWindow = GTK_SCROLLED_WINDOW(swindow);
  adj = gtk_range_get_adjustment(GTK_RANGE(scrolledWindow->vscrollbar));
  printf("Add: page size %.0f\n", adj->page_size );

  adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(swindow));
  printf("Add: page size %.0f\n", adj->page_size );

  return;
}


static void shrinkPane()
{
  gtk_widget_destroy(GTK_WIDGET(canvas));
  gtk_widget_destroy(GTK_WIDGET(swindow));
  gtk_widget_destroy(GTK_WIDGET(frame));
  gtk_widget_destroy(GTK_WIDGET(vpane));
  gtk_widget_destroy(GTK_WIDGET(toolbar));
  gtk_widget_destroy(GTK_WIDGET(vbox));

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);

  toolbar = gtk_toolbar_new();

gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "H-Split","Split Window Horizontally",
                          NULL, NULL, GTK_SIGNAL_FUNC(SplitPane), window );

  gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);

  vpane = gtk_vpaned_new();
  gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 0);

  return;
}


static void SplitPane(GtkWidget *widget, gpointer data)
{

  shrinkPane(window);

  addPane   (window, 'h');

  return;
}

int main( int   argc,
          char *argv[] )
{
  gtk_init (&argc, &argv);

  createMainWindow();

  addPane ();

  gtk_main ();

  return 0;
}
/********************* end of file ********************************/

--
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ignorance is not the same as stupidity, but in my case, they come pretty close.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Rob Clack                        Acedb Development,  Informatics Group
 email: rnc sanger ac uk                Wellcome Trust Sanger Institute
 Tel: +44 1223 494883                   Wellcome Trust Genome Campus
 Fax: +44 1223 494919                   Hinxton  Cambridge    CB10 1SA



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