complains about wxSplitterWindow
Francesco Montorsi
f18m_cpp217828 at yahoo.it
Thu Feb 1 11:12:10 PST 2007
Vadim Zeitlin ha scritto:
> [I redirected this to wx-dev as I think it's more appropriate for it now]
>
> On Wed, 31 Jan 2007 12:49:31 +0100 Francesco Montorsi <f18m_cpp217828 at yahoo.it> wrote:
>
> FM> Vadim Zeitlin ha scritto:
> FM> > On Tue, 30 Jan 2007 00:14:47 +0100 Francesco Montorsi <f18m_cpp217828 at yahoo.it> wrote:
> FM> >
> FM> > FM> Maybe however this (the Split*() func should be called with windows with
> FM> > FM> minsize != -1;-1) should be better documented adding a note in
> FM> > FM> SplitHoriz/Vert.
> FM> >
> FM> > Sorry, I still don't understand what should be documented. It seems
> FM> > natural to me that if you don't set minimal size for a window it has no
> FM> > minimal size?
> FM> sure but the problem is (sorry if I was unclear) that I was setting the minsize
> FM> on the top/bottom panels only after the call to SplitHoriz/Vert so that
> FM> actually they did not have any effect.
>
> Ah, I see. This does look like a bug. Would you have found any simple way
> to correct this by chance?
unfortunately no, I haven't really looked at it deeply...
>
> FM> I.e. I think it would be very useful to be able to reduce the following code:
> FM>
> FM> wxSplitterWindow *mywin = new wxSplitterWindow(...);
> FM> wxPanel *panel1 = new wxPanel(mywin, ...);
> FM> wxPanel *panel2 = new wxPanel(mywin, ...);
> FM> wxSizer *sz1 = new wxBoxSizer(...);
> FM> wxSizer *sz2 = new wxBoxSizer(...);
> FM>
> FM> /* add controls to sz1 and to sz2 */
> FM> ...
> FM>
> FM> panel1->SetSizer(sz1);
> FM> sz1->SetSizeHints(panel1);
> FM> panel2->SetSizer(sz2);
> FM> sz2->SetSizeHints(panel2);
> FM>
> FM> mywin->SplitHoriz(panel1, panel2);
> FM>
> FM> to something shorter
>
> I [still] don't see how would it be helped by the style you proposed.
> Could you please show the (hypothetical) new version of the above code with
> it?
in fact a wxSP_CREATE_PANELS code would just replace the two lines above
which create the panels with:
wxPanel *panel1 = mywin->GetWindow1(); // the panel has been
created by the wxSplitterWindow itself...
wxPanel *panel2 = mywin->GetWindow2();
which is not very helpful.
No, a real advantage could be introduced only by a wxSplitterWindowSizer:
// creating a wxSplitterWindowSizer determines the creation of the
// wxSplitterWindow (we could also make a constructor like for
// wxStaticBoxSizer which allows attaching a pre-existing
wxSplitterWindow):
wxSplitterWindowSizer *sz = wxSplitterWindowSizer(...);
wxSizer *sz1 = new wxBoxSizer(...);
wxSizer *sz2 = new wxBoxSizer(...);
// when the wxSplitterWindowSizer::Add(wxSizer*) overload is used,
// wxSplitterWindowSizer creates the first wxPanel of the
wxSplitterWindow
// (if Add has never been called before) or the second wxPanel of
// the wxSplitterWindow (if Add has already been called once).
// after creating the panel, it sets the given sizer on that panel.
sz->Add(sz1);
sz->Add(sz2);
// we cannot add anything more to the 'sz' sizer as only two
children are allowed.
// if the wxSplitterWindowSizer::Add(wxWindow*) overload would have
// been used, then the wxSplitterWindowSizer would not have created
// internally a wxPanel but rather used the given window directly
// as child of the wxSplitterWindow.
/* now add controls to sz1 and to sz2:
those added to sz1 go in the first pane of the wxSplitterWindow,
those added to sz2 go in the second pane of the wxSplitterWindow
since sz1 has been added prior sz2 to the 'sz' sizer.
*/
...
// wxSplitterWindowSizer::SplitHoriz uses the wxPanel internally
// created in the Add() step or the window provided by the user
// (still in the Add step) to call the wxSplitterWindow::SplitHoriz
// function:
sz->SplitHoriz();
I hope I've been clear :)
There are two things which may not look so good IMO:
1) the wxSplitterWindowSizer should assert when trying to Add() more
than two windows/sizers to it
2) wxSplitterWindowSizer::Add() would not support adding a spacer
#2 is for me a very minor problem; #1 derives from the fact that adding
more than 2 children to a wxSplitterWindow makes no much sense (in fact
I think that the wxSplitterWindow::AddChild function should implement a
similar assert: when the count of children windows > 2 an assert should
fail warning the programmer).
Francesco
More information about the wx-dev
mailing list