X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/912c39325bfc8e9625d79d9114f67eb8d68326ce..3c01c5951189e13b8b4a5d7b288b54d4a57a30f8:/samples/collpane/collpane.cpp diff --git a/samples/collpane/collpane.cpp b/samples/collpane/collpane.cpp index 4d535eef94..86ab0252ed 100644 --- a/samples/collpane/collpane.cpp +++ b/samples/collpane/collpane.cpp @@ -44,6 +44,10 @@ #include "wx/fontpicker.h" #include "wx/aboutdlg.h" +#ifndef __WXMSW__ + #include "../sample.xpm" +#endif + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -51,12 +55,15 @@ // ID for the menu commands enum { - PANE_COLLAPSE, + PANE_COLLAPSE = 100, PANE_EXPAND, PANE_SETLABEL, PANE_SHOWDLG, PANE_ABOUT = wxID_ABOUT, - PANE_QUIT = wxID_EXIT + PANE_QUIT = wxID_EXIT, + + PANE_BUTTON, + PANE_TEXTCTRL }; @@ -71,7 +78,7 @@ public: virtual bool OnInit(); - DECLARE_NO_COPY_CLASS(MyApp) + wxDECLARE_NO_COPY_CLASS(MyApp); }; class MyFrame: public wxFrame @@ -88,14 +95,16 @@ public: 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; + wxBoxSizer *m_paneSizer; DECLARE_EVENT_TABLE() - DECLARE_NO_COPY_CLASS(MyFrame) + wxDECLARE_NO_COPY_CLASS(MyFrame); }; class MyDialog : public wxDialog @@ -103,13 +112,15 @@ class MyDialog : public wxDialog public: MyDialog(wxFrame *parent); void OnToggleStatus(wxCommandEvent& WXUNUSED(ev)); + void OnAlignButton(wxCommandEvent& WXUNUSED(ev)); void OnPaneChanged(wxCollapsiblePaneEvent& event); private: wxCollapsiblePane *m_collPane; + wxGridSizer *m_paneSizer; DECLARE_EVENT_TABLE() - DECLARE_NO_COPY_CLASS(MyDialog) + wxDECLARE_NO_COPY_CLASS(MyDialog); }; @@ -126,6 +137,9 @@ IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { + if ( !wxApp::OnInit() ) + return false; + // create and show the main frame MyFrame* frame = new MyFrame; @@ -146,7 +160,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) 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 @@ -155,6 +170,8 @@ MyFrame::MyFrame() wxDefaultPosition, wxSize(420, 300), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) { + SetIcon(wxICON(sample)); + #if wxUSE_STATUSBAR CreateStatusBar(2); #endif // wxUSE_STATUSBAR @@ -164,7 +181,7 @@ 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(); @@ -181,10 +198,12 @@ MyFrame::MyFrame() m_collPane = new wxCollapsiblePane(this, -1, wxT("test!")); wxWindow *win = m_collPane->GetPane(); - new wxStaticText(win, -1, wxT("Static control with absolute coords"), wxPoint(10,2)); - new wxStaticText(win, -1, wxT("Yet another one!"), wxPoint(30, 30)); - new wxTextCtrl(win, -1, wxT("You can place anything you like inside a wxCollapsiblePane"), - wxPoint(5, 60), wxSize(300, -1)); + m_paneSizer = new wxBoxSizer( wxVERTICAL ); + m_paneSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT ); + win->SetSizer( m_paneSizer ); } MyFrame::~MyFrame() @@ -210,7 +229,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); } @@ -230,10 +254,14 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) wxAboutBox(info); } -void MyFrame::UpdateUI(wxUpdateUIEvent& event) +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()); } @@ -249,6 +277,7 @@ enum BEGIN_EVENT_TABLE(MyDialog, wxDialog) EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus) EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY, MyDialog::OnPaneChanged) + EVT_BUTTON(PANE_BUTTON, MyDialog::OnAlignButton) END_EVENT_TABLE() MyDialog::MyDialog(wxFrame *parent) @@ -271,13 +300,16 @@ MyDialog::MyDialog(wxFrame *parent) // now add test controls in the collapsible pane wxWindow *win = m_collPane->GetPane(); - wxSizer *paneSz = new wxGridSizer(2, 2, 5, 5); - paneSz->Add(new wxColourPickerCtrl(win, -1), 1, wxGROW|wxALL, 2); - paneSz->Add(new wxFontPickerCtrl(win, -1), 1, wxGROW|wxALL, 2); - paneSz->Add(new wxFilePickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2); - paneSz->Add(new wxDirPickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2); - win->SetSizer(paneSz); - paneSz->SetSizeHints(win); + m_paneSizer = new wxGridSizer(4, 1, 5, 5); + + m_paneSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT ); + m_paneSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT ); + win->SetSizer( m_paneSizer ); + + win->SetSizer( m_paneSizer ); + m_paneSizer->SetSizeHints(win); SetSizer(sz); sz->SetSizeHints(this); @@ -288,6 +320,14 @@ void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev)) m_collPane->Collapse(!m_collPane->IsCollapsed()); } +void MyDialog::OnAlignButton(wxCommandEvent& WXUNUSED(ev)) +{ + wxSizerItem *item = m_paneSizer->GetItem( FindWindow(PANE_TEXTCTRL), true ); + item->SetFlag( wxALIGN_RIGHT ); + + Layout(); +} + void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent &event) { wxLogDebug(wxT("The pane has just been %s by the user"),