+
+ m_panel = new wxPanel(this, wxID_ANY);
+#if USE_UNMANAGED_TOOLBAR
+ m_extraToolBar = new wxToolBar(m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_TEXT|wxTB_FLAT|wxTB_TOP);
+ PopulateToolbar(m_extraToolBar);
+#endif
+
+ m_textWindow = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
+
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ m_panel->SetSizer(sizer);
+#if USE_UNMANAGED_TOOLBAR
+ if (m_extraToolBar)
+ sizer->Add(m_extraToolBar, 0, wxEXPAND, 0);
+#endif
+ sizer->Add(m_textWindow, 1, wxEXPAND, 0);
+}
+
+MyFrame::~MyFrame()
+{
+ if ( m_searchTool && !m_searchTool->GetToolBar() )
+ {
+ // we currently can't delete a toolbar tool ourselves, so we have to
+ // attach it to the toolbar just for it to be deleted, this is pretty
+ // ugly and will need to be changed
+ GetToolBar()->AddTool(m_searchTool);
+ }
+}
+
+void MyFrame::LayoutChildren()
+{
+ wxSize size = GetClientSize();
+
+ int offset;
+ if ( m_tbar )
+ {
+ m_tbar->SetSize(0, 0, wxDefaultCoord, size.y);
+
+ offset = m_tbar->GetSize().x;
+ }
+ else
+ {
+ offset = 0;
+ }
+
+ m_panel->SetSize(offset, 0, size.x - offset, size.y);
+}
+
+void MyFrame::OnSize(wxSizeEvent& event)
+{
+ if ( m_tbar )
+ {
+ LayoutChildren();
+ }
+ else
+ {
+ event.Skip();
+ }
+}
+
+void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
+{
+ wxToolBar *tbar = GetToolBar();
+
+ if ( !tbar )
+ {
+ RecreateToolbar();
+ }
+ else
+ {
+ // notice that there is no need to call SetToolBar(NULL) here (although
+ // this it is harmless to do and it must be called if you do not delete
+ // the toolbar but keep it for later reuse), just delete the toolbar
+ // directly and it will reset the associated frame toolbar pointer
+ delete tbar;
+ }
+}
+
+void MyFrame::OnToggleHorizontalText(wxCommandEvent& WXUNUSED(event))
+{
+ m_horzText = !m_horzText;
+
+ RecreateToolbar();
+}
+
+void MyFrame::OnToggleAnotherToolbar(wxCommandEvent& WXUNUSED(event))
+{
+ if ( m_tbar )
+ {
+ delete m_tbar;
+ m_tbar = NULL;
+ }
+ else
+ {
+ long style = GetToolBar() ? GetToolBar()->GetWindowStyle()
+ : TOOLBAR_STYLE;
+ style &= ~wxTB_HORIZONTAL;
+ style |= wxTB_VERTICAL;
+
+ m_tbar = new wxToolBar(this, wxID_ANY,
+ wxDefaultPosition, wxDefaultSize,
+ style);
+
+ m_tbar->SetMargins(4, 4);
+
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_1, wxT("First"), wxBITMAP(new));
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_2, wxT("Second"), wxBITMAP(open));
+ m_tbar->AddRadioTool(IDM_TOOLBAR_OTHER_3, wxT("Third"), wxBITMAP(save));
+ m_tbar->AddSeparator();
+ m_tbar->AddTool(wxID_HELP, wxT("Help"), wxBITMAP(help));
+
+ m_tbar->Realize();
+ }
+
+ LayoutChildren();