X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/117cced850ee369803e12df0c3ef4bc40ce8bfb1..4e15d1caa03346c126015019c1fdf093033ef40b:/samples/collpane/collpane.cpp diff --git a/samples/collpane/collpane.cpp b/samples/collpane/collpane.cpp index dbc8cbf4a7..27cccb9f77 100644 --- a/samples/collpane/collpane.cpp +++ b/samples/collpane/collpane.cpp @@ -6,7 +6,7 @@ // Created: 14/10/06 // RCS-ID: $Id$ // Copyright: (c) Francesco Montorsi -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -44,6 +44,10 @@ #include "wx/fontpicker.h" #include "wx/aboutdlg.h" +#ifndef wxHAS_IMAGES_IN_RESOURCES + #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 @@ -94,9 +101,10 @@ public: private: wxCollapsiblePane *m_collPane; + wxBoxSizer *m_paneSizer; DECLARE_EVENT_TABLE() - DECLARE_NO_COPY_CLASS(MyFrame) + wxDECLARE_NO_COPY_CLASS(MyFrame); }; class MyDialog : public wxDialog @@ -104,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); }; @@ -156,22 +166,24 @@ END_EVENT_TABLE() // My frame constructor MyFrame::MyFrame() - : wxFrame(NULL, wxID_ANY, _T("wxCollapsiblePane sample"), + : wxFrame(NULL, wxID_ANY, wxT("wxCollapsiblePane sample"), wxDefaultPosition, wxSize(420, 300), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) { + SetIcon(wxICON(sample)); + #if wxUSE_STATUSBAR CreateStatusBar(2); #endif // wxUSE_STATUSBAR // Make a menubar wxMenu *paneMenu = new wxMenu; - paneMenu->Append(PANE_COLLAPSE, _T("Collapse\tCtrl-C")); - paneMenu->Append(PANE_EXPAND, _T("Expand\tCtrl-E")); + paneMenu->Append(PANE_COLLAPSE, wxT("Collapse\tCtrl-C")); + paneMenu->Append(PANE_EXPAND, wxT("Expand\tCtrl-E")); paneMenu->AppendSeparator(); - paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-L")); + paneMenu->Append(PANE_SETLABEL, wxT("Set label...\tCtrl-L")); paneMenu->AppendSeparator(); - paneMenu->Append(PANE_SHOWDLG, _T("Show dialog...\tCtrl-S")); + paneMenu->Append(PANE_SHOWDLG, wxT("Show dialog...\tCtrl-S")); paneMenu->AppendSeparator(); paneMenu->Append(PANE_QUIT); @@ -179,17 +191,24 @@ MyFrame::MyFrame() helpMenu->Append(PANE_ABOUT); wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(paneMenu, _T("&Pane")); - menuBar->Append(helpMenu, _T("&Help")); + menuBar->Append(paneMenu, wxT("&Pane")); + menuBar->Append(helpMenu, wxT("&Help")); SetMenuBar(menuBar); 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( wxHORIZONTAL ); + wxBoxSizer* paneSubSizer = new wxBoxSizer( wxVERTICAL ); + m_paneSizer->AddSpacer( 20 ); + m_paneSizer->Add( paneSubSizer, 1 ); + + paneSubSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT | wxALL, 3 ); + paneSubSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT | wxALL, 3 ); + paneSubSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT | wxALL, 3 ); + paneSubSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT | wxALL, 3 ); + + win->SetSizer( m_paneSizer ); } MyFrame::~MyFrame() @@ -235,7 +254,7 @@ 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 ")); + info.SetCopyright(wxT("(C) 2006 Francesco Montorsi ")); wxAboutBox(info); } @@ -263,6 +282,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) @@ -285,13 +305,16 @@ MyDialog::MyDialog(wxFrame *parent) // now add test controls in the collapsible pane wxWindow *win = m_collPane->GetPane(); - wxSizer *paneSz = new wxGridSizer(4, 1, 5, 5); - paneSz->Add(new wxColourPickerCtrl(win, -1), 1, wxALL|wxALIGN_LEFT, 2); - paneSz->Add(new wxFontPickerCtrl(win, -1), 1, wxALL|wxALIGN_LEFT, 2); - paneSz->Add(new wxFilePickerCtrl(win, -1), 1, wxALL|wxALIGN_LEFT, 2); - paneSz->Add(new wxDirPickerCtrl(win, -1), 1, wxALL|wxALIGN_LEFT, 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); @@ -302,9 +325,17 @@ void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev)) m_collPane->Collapse(!m_collPane->IsCollapsed()); } -void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent &event) +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"), + wxLogMessage(wxT("The pane has just been %s by the user"), event.GetCollapsed() ? wxT("collapsed") : wxT("expanded")); }