X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c1f8cb1f5cbef0f7699110fd28027948e644c6f..b70362998b8f562923f6ed6708f06537ac056cd4:/samples/collpane/collpane.cpp?ds=sidebyside diff --git a/samples/collpane/collpane.cpp b/samples/collpane/collpane.cpp index f693d52d71..74ea1e83c9 100644 --- a/samples/collpane/collpane.cpp +++ b/samples/collpane/collpane.cpp @@ -42,6 +42,7 @@ #include "wx/clrpicker.h" #include "wx/filepicker.h" #include "wx/fontpicker.h" +#include "wx/aboutdlg.h" // ---------------------------------------------------------------------------- // constants @@ -54,6 +55,7 @@ enum PANE_EXPAND, PANE_SETLABEL, PANE_SHOWDLG, + PANE_ABOUT = wxID_ABOUT, PANE_QUIT = wxID_EXIT }; @@ -84,9 +86,11 @@ public: void OnSetLabel(wxCommandEvent& event); void OnShowDialog(wxCommandEvent& event); void Quit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); - // Menu command update functions - void UpdateUI(wxUpdateUIEvent& event); + // UI update handlers + void OnCollapseUpdateUI(wxUpdateUIEvent& event); + void OnExpandUpdateUI(wxUpdateUIEvent& event); private: wxCollapsiblePane *m_collPane; @@ -100,6 +104,7 @@ class MyDialog : public wxDialog public: MyDialog(wxFrame *parent); void OnToggleStatus(wxCommandEvent& WXUNUSED(ev)); + void OnPaneChanged(wxCollapsiblePaneEvent& event); private: wxCollapsiblePane *m_collPane; @@ -122,6 +127,9 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // create and show the main frame MyFrame* frame = new MyFrame; @@ -139,9 +147,11 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(PANE_EXPAND, MyFrame::OnExpand) EVT_MENU(PANE_SETLABEL, MyFrame::OnSetLabel) EVT_MENU(PANE_SHOWDLG, MyFrame::OnShowDialog) + EVT_MENU(PANE_ABOUT, MyFrame::OnAbout) EVT_MENU(PANE_QUIT, MyFrame::Quit) - EVT_UPDATE_UI(wxID_ANY, MyFrame::UpdateUI) + EVT_UPDATE_UI(PANE_COLLAPSE, MyFrame::OnCollapseUpdateUI) + EVT_UPDATE_UI(PANE_EXPAND, MyFrame::OnExpandUpdateUI) END_EVENT_TABLE() // My frame constructor @@ -159,14 +169,18 @@ MyFrame::MyFrame() paneMenu->Append(PANE_COLLAPSE, _T("Collapse\tCtrl-C")); paneMenu->Append(PANE_EXPAND, _T("Expand\tCtrl-E")); paneMenu->AppendSeparator(); - paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-S")); + paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-L")); paneMenu->AppendSeparator(); paneMenu->Append(PANE_SHOWDLG, _T("Show dialog...\tCtrl-S")); paneMenu->AppendSeparator(); paneMenu->Append(PANE_QUIT); + wxMenu *helpMenu = new wxMenu; + helpMenu->Append(PANE_ABOUT); + wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(paneMenu, _T("&Pane")); + menuBar->Append(helpMenu, _T("&Help")); SetMenuBar(menuBar); m_collPane = new wxCollapsiblePane(this, -1, wxT("test!")); @@ -201,7 +215,12 @@ void MyFrame::OnExpand(wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnSetLabel(wxCommandEvent& WXUNUSED(event) ) { - wxString text = wxGetTextFromUser(wxT("Input the new label")); + wxString text = wxGetTextFromUser + ( + wxT("Enter new label"), + wxGetTextFromUserPromptStr, + m_collPane->GetLabel() + ); m_collPane->SetLabel(text); } @@ -211,12 +230,27 @@ void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event) ) dlg.ShowModal(); } -void MyFrame::UpdateUI(wxUpdateUIEvent& event) +void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) +{ + wxAboutDialogInfo info; + info.SetName(_("wxCollapsiblePane sample")); + info.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane")); + info.SetCopyright(_T("(C) 2006 Francesco Montorsi ")); + + wxAboutBox(info); +} + +void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent& event) +{ + event.Enable(!m_collPane->IsCollapsed()); +} + +void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent& event) { - GetMenuBar()->Enable(PANE_COLLAPSE, !m_collPane->IsCollapsed()); - GetMenuBar()->Enable(PANE_EXPAND, m_collPane->IsCollapsed()); + event.Enable(m_collPane->IsCollapsed()); } + // ---------------------------------------------------------------------------- // MyDialog // ---------------------------------------------------------------------------- @@ -228,6 +262,7 @@ enum BEGIN_EVENT_TABLE(MyDialog, wxDialog) EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus) + EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY, MyDialog::OnPaneChanged) END_EVENT_TABLE() MyDialog::MyDialog(wxFrame *parent) @@ -236,14 +271,14 @@ MyDialog::MyDialog(wxFrame *parent) wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE ) { wxSizer *sz = new wxBoxSizer(wxVERTICAL); - sz->Add(new wxStaticText(this, -1, + sz->Add(new wxStaticText(this, -1, wxT("This dialog allows you to test the wxCollapsiblePane control")), 0, wxALL, 5); - sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")), + sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")), 1, wxGROW|wxALL, 5); - + m_collPane = new wxCollapsiblePane(this, -1, wxT("Click here for a surprise")); - sz->Add(m_collPane, 1, wxGROW|wxALL, 5); + sz->Add(m_collPane, 0, wxGROW|wxALL, 5); sz->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW|wxALL, 5); sz->AddSpacer(10); sz->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5); @@ -267,3 +302,9 @@ void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev)) m_collPane->Collapse(!m_collPane->IsCollapsed()); } +void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent &event) +{ + wxLogDebug(wxT("The pane has just been %s by the user"), + event.GetCollapsed() ? wxT("collapsed") : wxT("expanded")); +} +