Re: ScrolledWindow - how to allow scrolling only in one direction?
- From: "Paul Davis" <pjdavis engineering uiowa edu>
- To: "Tom Bachmann" <e_mc_h2 web de>
- Cc: gtkmm-list gnome org
- Subject: Re: ScrolledWindow - how to allow scrolling only in one direction?
- Date: Mon, 2 Apr 2007 09:26:43 -0500
On 4/1/07, Tom Bachmann <e_mc_h2 web de> wrote:
-----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.
[snip]
You can inherit from Gtk::ScrolledWindow and override its
on_size_request function.
This seems to work:
#include <iostream>
#include <gtkmm.h>
class VScrolledWindow : public Gtk::ScrolledWindow
{
public:
VScrolledWindow()
{
set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS ) ;
}
virtual ~VScrolledWindow() {}
protected:
virtual void
on_size_request( Gtk::Requisition* requisition )
{
Gtk::ScrolledWindow::on_size_request( requisition ) ;
Gtk::Widget* child = get_child() ;
Gtk::Widget* vsb = get_vscrollbar() ;
Gtk::Requisition c_req = { 0, 0 } ;
Gtk::Requisition sb_req = { 0, 0 } ;
if( child && child->is_visible() )
{
c_req = child->size_request() ;
}
if( vsb && vsb->is_visible() )
{
sb_req = vsb->size_request() ;
}
}
} ;
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;
VScrolledWindow s1, s2, s3;
Gtk::Button b1, b2, b3;
public:
window2 ()
: b1 ("foo"), b2 ("foobarbazoo"), b3 ("foobar")
{
add (box);
int w, h ;
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;
}
I based this on the example here:
http://svn.gnome.org/viewcvs/gtkmm/trunk/examples/book/custom/custom_container/
HTH,
Paul Davis
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]