Need layout help

Udo Baumgart ubit.de at gmx.de
Wed Jan 17 05:47:04 PST 2007


Hi,

this is (nearly) the smallest piece of code that show the effect:

----------------------------------------------------------
#include <wx/wxprec.h>

#ifdef __BORLANDC__
     #pragma hdrstop
#endif

#ifndef WX_PRECOMP
     #include <wx/wx.h>
#endif


class MyApp : public wxApp
{
	public:
		virtual bool OnInit();
};
IMPLEMENT_APP(MyApp);

class MyFrame: public wxFrame
{
	public:
		MyFrame(wxFrame *frame, const wxString& title);
		~MyFrame();
};

bool MyApp::OnInit()
{
	MyFrame* frame = new MyFrame(0L, _("wxWidgets Application Template"));
	frame->Show();
	return true;
}

MyFrame::MyFrame(wxFrame *frame, const wxString& title)
	: wxFrame(frame, -1, title)
{
     // Main Sizer = flexgrid with 2 columns
     wxFlexGridSizer* flexgrid = new wxFlexGridSizer(2,0,0);
     SetSizer(flexgrid);
     flexgrid->AddGrowableCol(1,1);

     // Scrolled window in first column of flexgrid
     wxScrolledWindow* sw = new wxScrolledWindow(this, wxID_ANY,
             wxDefaultPosition, wxDefaultSize,
             wxVSCROLL, wxT("scrolledwindow"));
     // Add as first column. Should expand with frame in height
     flexgrid->Add(sw, 0, wxEXPAND, 0);

     // Create a BoxSizer for children layout inside sw
     wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
     sw->SetSizer(vbox);

     // Add some dummy buttons to scrolledwindow
     wxButton* b = NULL;
     for (int i=0; i<10; i++) {
         b = new wxButton(sw, wxID_ANY, _("Dummy"));
         vbox->Add(b,0,0,0);
     }

     // Add some dummy content as second column of flexgrid
     wxTextCtrl* c = new wxTextCtrl(this, wxID_ANY, _("CONTENT"),
             wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
     flexgrid->Add(c, 1, wxEXPAND, 0);

     // Calculate Frame size to fit all elements
     Fit();

     // Set Scrollbars so that resizing frame makes appearing them
     sw->SetScrollbars(1,1,100,100,0,0,true);

     // Following seems to have no effect...
     sw->FitInside();
}

MyFrame::~MyFrame()
{
}
-------------------------------------------------------

Ciao, Udo




More information about the wx-users mailing list