Custom (-ish) widget sizing question




Hi all,

First of all, my apologies if this is oft-covered ground, but I have been unable to find any insights on google.

I have this program:

#include <gtkmm.h>
#include <iostream>

using namespace std;
using namespace Gtk;

class Jim : public EventBox {
private:
	void on_size_request (Requisition* r) {
		r->width = 128;
		r->height = 128;
	}

	void on_size_allocate (Allocation& a) {
		EventBox::on_size_allocate (a);
	}
};

class Fred : public Window {
public:
	Fred () {
		_vbox.pack_start (*manage (new Label ("foo")), false, false);
		_vbox.pack_start (*manage (new Label ("bar")), false, false);
		_vbox.pack_start (_jim);
		add (_vbox);
		show_all ();
	}

private:
	VBox _vbox;
	Jim _jim;
};

int main (int argc, char* argv[])
{
	Main kit (argc, argv);

	Fred f;
	f.show ();

	Main::run (f);

	return 0;
}

When run, it opens a window with the Jim widget sized at 128 x 128. Imagine that Jim could have an arbitrary but /fixed/ maximum size, which could be larger than the screen.

How do I open the window so that it is big enough to contain Jim's maximum size (if that is possible without being larger than the screen)? But /without/ allocating Jim any more space than its maximum?

I have tried many approaches. The most likely to me seems to be some way of refusing an allocation from on_size_allocate and demanding a smaller one, but this does not seem to work.

Any hints much appreciated.

Thanks

Carl




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