ScrolledWindow - how to allow scrolling only in one direction?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

[Please cc me, I'm not registered to the list. Also, I'm unsure if I'm
better advised to ask on the gtk list, please tell me if this is indeed
the case.]

I'm trying to create a ScrolledWindow (or something comparable) that
behaves like a normal container horizontally. That is, I don't want it
to display a scrollbar, I don't want it to allow resizing smaller (in x
direction) than the wrapped widget, and, most important, I want it to
create a size request (in x direction) that depends on the size of the
wrapped widget, where the last is most important. The reason is that I
want to stuff multiple such ScrolledWindows into a hbox, and I want them
to get space allocated (in x direction) proportional to the size of the
wrapped widgets, as would be the case when there's no wrapping
ScrolledWindow.

Here's a bit of sample code:

#include <gtkmm.h>

class window1
  : public Gtk::Window
{
private:
  Gtk::HBox box;
    Gtk::Button b1;
    Gtk::Button b2;
    Gtk::Button b3;

public:
  window1 ()
    : b1 ("foo"), b2 ("foobarbazoo"), b3 ("foobar")
  {
    add (box);
    box.add (b1);
    box.add (b2);
    box.add (b3);

    show_all_children ();
  }
};

class window2
  : public Gtk::Window
{
private:
  Gtk::HBox box;
    Gtk::ScrolledWindow s1, s2, s3;
    Gtk::Button b1, b2, b3;

public:
  window2 ()
    : b1 ("foo"), b2 ("foobarbazoo"), b3 ("foobar")
  {
    add (box);

    box.add (s1);
    s1.add (b1);

    box.add (s2);
    s2.add (b2);

    box.add (s3);
    s3.add (b3);

    show_all_children ();
  }
};

int
main (int argc, char** argv)
{
  Gtk::Main kit (argc, argv);

  window1 w1;
  window2 w2;
  w2.show ();

  Gtk::Main::run (w1);

  return 0;
}

In window1, the three buttons get space proportional to their sizes
(with the same proportionality factor, of course), while in window2 all
buttons (actually, the ScrolledWindows) get the same amount of space. I
know that this is obviously the expected behavior, as I use the
ScrolledWindows in the standard way, but this is just to illustrate the
problem statement (in case my description was not understandable..).

I tried the following:
o Set the scrolling policy to POLICIY_NEVER. This doesn't work as it
  just inhibits _displaying_ the scrollbar.
o set_size_request (b.get_width ()) - this doesn't work, as
  b.get_width () appareantly always returns 1.

thanks,
- --
- -ness-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGD5MavD/ijq9JWhsRAn89AJ44BpZMKFbp9F5RFsG2aPOFcK/uKwCeNTHw
O2Ab3l/frzcFLCB69V7c7qg=
=TMZb
-----END PGP SIGNATURE-----



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