Altough the code worked, there where some GUI quirks.
I coded a simple test that displays 25 tabs and simple event handling. It works perfectly well.
Code: Select all
BEGIN_EVENT_TABLE(myDialogWithTabs ,wxDialog)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY,myDialogWithTabs::OnPageChanged)
END_EVENT_TABLE()
myDialogWithTabs ::myDialogWithTabs ( class Interface * const inter,wxWindow * parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style )
: wxDialog( parent, id, title, position, size, style | wxCAPTION | wxRESIZE_BORDER | wxCLIP_CHILDREN | wxSYSTEM_MENU | wxTHICK_FRAME | wxCLOSE_BOX)
, m_interface(inter)
{
// TODO: Enter construction code here
this->CreateMainInterface(this);
SetSize(size);
Centre();
}
myDialogWithTabs ::~myDialogWithTabs ()
{
// TODO: Enter destruction code here
//Actually there's none needed, as when the parent is deleted, so will be its children.
}
void myDialogWithTabs ::CreateMainInterface(wxWindow *parent)
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
m_mainNoteBook = new wxNotebook(parent, wxID_ANY,wxDefaultPosition,wxDefaultSize, wxFULL_REPAINT_ON_RESIZE | wxNB_TOP | wxNB_MULTILINE);
for(int i=0; i < 25; i++)
{ wxPanel *panel = new wxPanel(m_mainNoteBook, wxID_ANY);
m_mainNoteBook->AddPage(panel, wxString::Format("Tab %d",i+1));
panel->SetBackgroundColour(wxColour(0,i*10,0));
}
mainSizer->Add(m_mainNoteBook,1,wxEXPAND,0);
parent->SetSizer( mainSizer ); // use the sizer for layout
mainSizer->Fit(parent);
mainSizer->SetSizeHints( parent );
parent->Layout();
}
void myDialogWithTabs::OnPageChanged(wxNotebookEvent& e)
{
wxMessageBox(wxString::Format("selection changed from %d to %d.",
e.GetOldSelection()+1,
e.GetSelection()+1));
}
1. mainSizer->Fit(parent);
2. parent->Layout();
3. SetSize(size). (after creating the interface).
The last step is needed as the GUI will "shrink" when using the sizer, so you'll have to resize again.