Re: Difference between Gtk2 and Gtk3 output



Try setting the size_request of your scrolledwindow. Gtk seems to
always give the minimum space possible to scrolledwindows. It may be a
bug, I don't know. One would assume that setting the vbox homogeneous
should have that effect but it appears not...

You could also try putting the scrolled window inside another widget
(eg an hbox or eventbox) which may or may not work. Or try putting
both widgets inside a vertical GtkPaned which most likely will work
better.



Regards,
Salsaman.

http://lives.sourceforge.net
https://www.ohloh.net/accounts/salsaman


On Fri, Feb 15, 2013 at 5:13 PM, HW Krus <hwkrus gmail com> wrote:
Hi all,

Working through the text and examples contained in Foundations of Gtk+
Development using Gtk3 I stumbled on the following problem:

--- begin gtk2 code ---
#include <gtk/gtk.h>

int main (int argc,
          char *argv[])
{
  GtkWidget *window, *swin, *viewport, *table1, *table2, *vbox;
  GtkAdjustment *horizontal, *vertical;
  GtkWidget *buttons1[10][10], *buttons2[10][10];
  unsigned int i, j;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Scrolled Windows &
Viewports");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_widget_set_size_request (window, 400, 300);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  table1 = gtk_table_new (10, 10, TRUE);
  table2 = gtk_table_new (10, 10, TRUE);
  gtk_table_set_row_spacings (GTK_TABLE (table1), 5);
  gtk_table_set_row_spacings (GTK_TABLE (table2), 5);
  gtk_table_set_col_spacings (GTK_TABLE (table1), 5);
  gtk_table_set_col_spacings (GTK_TABLE (table2), 5);

  /* Pack each table with 100 buttons. */
  for (i = 0; i < 10; i++)
  {
    for (j = 0; j < 10; j++)
    {
      buttons1[i][j] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
      buttons2[i][j] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
      gtk_button_set_relief (GTK_BUTTON (buttons1[i][j]), GTK_RELIEF_NONE);
      gtk_button_set_relief (GTK_BUTTON (buttons2[i][j]), GTK_RELIEF_NONE);

      gtk_table_attach_defaults (GTK_TABLE (table1), buttons1[i][j],
                                 i, i + 1, j, j + 1);
      gtk_table_attach_defaults (GTK_TABLE (table2), buttons2[i][j],
                                 i, i + 1, j, j + 1);
    }
  }

  /* Create a scrolled window and a viewport, each with one table. Use the
   * adjustments in the scrolled window to synchronize both containers. */
  swin = gtk_scrolled_window_new (NULL, NULL);
  horizontal = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW
(swin));
  vertical = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(swin));
  viewport = gtk_viewport_new (horizontal, vertical);

  gtk_container_set_border_width (GTK_CONTAINER (swin), 5);
  gtk_container_set_border_width (GTK_CONTAINER (viewport), 5);

  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
                                  GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swin),
table1);
  gtk_container_add (GTK_CONTAINER (viewport), table2);

  /* Pack the widgets into a GtkVBox and then into the window. */
  vbox = gtk_vbox_new (TRUE, 5);
  gtk_box_pack_start_defaults (GTK_BOX (vbox), viewport);
  gtk_box_pack_start_defaults (GTK_BOX (vbox), swin);

  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show_all (window);

  gtk_main();
  return 0;
}
--- end gtk2 code ---

Compiling with:

gcc -o scrolledwindows scrolledwindows.c -Wall -g `pkg-config --cflags
--libs gtk+-2.0`

Results in: http://img580.imageshack.us/img580/1460/scrolledwindowgtk2.png

First I changed it into Gtk3 syntax using grid instead of table, gtk_box_new
instead of gtk_vbox_new etc (3.4.2 on a Ubuntu 12.04 64bit system). But the
result did not look like the Gtk2 version, not even close. Next step was to
roll back the changes using deprecated calls as much as possible. Finally
only three lines were different:

 61,63c61,63
<   vbox = gtk_vbox_new (TRUE, 5);
<   gtk_box_pack_start_defaults (GTK_BOX (vbox), viewport);
<   gtk_box_pack_start_defaults (GTK_BOX (vbox), swin);
---
  vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
  gtk_box_pack_start(GTK_BOX (vbox), viewport, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX (vbox), swin,     TRUE, TRUE, 0);

gcc -o scrolledwindows3 scrolledwindows3.c -Wall -g `pkg-config --cflags
--libs gtk+-3.0`

Results in:  http://img96.imageshack.us/img96/430/scrolledwindowgtk3.png

Not quite the same. The sizes differ, the two rectangles disappeared, the
lower box with the scrollbars is reduced to one row of buttons only, the
upper box is enlarged and shows all the buttons, and -in order to do that-
the size has changed. Only the box-function changed slightly and the
defaults were used for the pack-function.

What did I overlook? What am I missing here?

Thanks for all the hints and suggestions!

Regards






_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list



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