Getting (maximal) size of wxToolbook

Volker Bartheld dr_versaeg at freenet.de
Wed Sep 26 01:21:15 PDT 2007


Hi Vadim!

Thanks for your reply.

>  Apparently the control didn't lay out itself correctly as otherwise I
> don't understand how can it return the wrong size. If this is indeed the
> case, calling Layout() on its parent might help...

This is what I tried in my codesample (also see initial post):

      m_pToolbook=new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT);
      // ...
      m_pToolbook->AssignImageList(pToolimages);
      for(unsigned int u=0; u<7; ++u) m_pToolbook->AddPage(pMyTestPanel, wxString::Format(wxT("Tab %u"), u), false, 0);
      m_pToolbook->Fit();
      // ...
      Layout();
      pMainSizer->Fit(this);
      wxSize
        s0=pMyTestPanel->GetSize(),     // 248,138
        s1=pMyTestPanel->GetMinSize(),  // 248,138
        s2=pMyTestPanel->GetMaxSize(),  // -1,-1
        s3=m_pToolbook->GetSize(),      // 292,138
        s4=m_pToolbook->GetMinSize(),   // -1,-1
        s5=m_pToolbook->GetMaxSize();   // -1,-1
      // ...

- at least the way I understand it: Create wxApp, new wxFrame within, wxFrame
sets new sizer, creates wxToolbook with self as parent, assigns images and wxPanels
to toolbook, calls wxToolbook->Fit(), then adds toolbook to main sizer, sets
size hints on self, then calls Layout(), tries to fit main sizer around subitems
and then proceeds with size calculation.

By comparing my code with the notebook sample, I came up with a slightly different
solution [1] that changed close to nothing, because it still didn't return a
usable height. In the sample, I added

        wxSize
          s0=currBook->GetSize(),
          s1=currBook->GetMinSize(),
          s2=currBook->GetMaxSize();

MyFrame::OnAddPageNoSelect() but wasn't able to make it tell me the size or
auto-resize to fit the toolbook [2]


Greets,
Volker

[1]
class MyFrame : public wxFrame
{
public:
  MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title), m_pToolbook(NULL)
  {
    SetIcon(wxICON(sample));
    wxSizer *pMainSizer=new wxBoxSizer(wxVERTICAL);
    SetSizer(pMainSizer);
    m_pToolbook=new wxToolbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT);
    wxImageList* pToolimages=new wxImageList(32, 32, false);
    wxPanel* pMyTestPanel;
    pToolimages->Add(wxICON(sample));
    m_pToolbook->AssignImageList(pToolimages);
    for(unsigned int u=0; u<7; ++u)
    {
      pMyTestPanel=new wxPanel(m_pToolbook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
      MyTestPanel1(pMyTestPanel);
      m_pToolbook->AddPage(pMyTestPanel, wxString::Format(wxT("Tab %u"), u), false, 0);
    }
    m_pToolbook->ChangeSelection(0);
    m_pToolbook->Fit();
    pMainSizer->Add(m_pToolbook, wxGROW|wxEXPAND);
    pMainSizer->Show(m_pToolbook);
    pMainSizer->Layout();
    wxSize
      s0=pMyTestPanel->GetSize(),     // 248,0
      s1=pMyTestPanel->GetMinSize(),  // 248,138
      s2=pMyTestPanel->GetMaxSize(),  // -1,-1
      s3=m_pToolbook->GetSize(),      // 292,0
      s4=m_pToolbook->GetMinSize(),   // -1,-1
      s5=m_pToolbook->GetMaxSize();   // -1,-1
  }
  wxToolbook *m_pToolbook;
}; // class MyFrame : public wxFrame

-- 
mailto:  V B A R T H E L D at G M X dot D E






More information about the wx-users mailing list