1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCollapsiblePane sample
4 // Author: Francesco Montorsi
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/scrolwin.h"
36 #include "wx/textdlg.h" // for wxGetTextFromUser
39 #include "wx/collpane.h"
41 #include "wx/stattext.h"
42 #include "wx/clrpicker.h"
43 #include "wx/filepicker.h"
44 #include "wx/fontpicker.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // ID for the menu commands
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 class MyApp
: public wxApp
70 virtual bool OnInit();
72 DECLARE_NO_COPY_CLASS(MyApp
)
75 class MyFrame
: public wxFrame
82 void OnCollapse(wxCommandEvent
& event
);
83 void OnExpand(wxCommandEvent
& event
);
84 void OnSetLabel(wxCommandEvent
& event
);
85 void OnShowDialog(wxCommandEvent
& event
);
86 void Quit(wxCommandEvent
& event
);
88 // Menu command update functions
89 void UpdateUI(wxUpdateUIEvent
& event
);
92 wxCollapsiblePane
*m_collPane
;
95 DECLARE_NO_COPY_CLASS(MyFrame
)
98 class MyDialog
: public wxDialog
101 MyDialog(wxFrame
*parent
);
102 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
105 wxCollapsiblePane
*m_collPane
;
107 DECLARE_EVENT_TABLE()
108 DECLARE_NO_COPY_CLASS(MyDialog
)
113 // ============================================================================
115 // ============================================================================
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
125 // create and show the main frame
126 MyFrame
* frame
= new MyFrame
;
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
138 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
139 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
140 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
141 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
142 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
144 EVT_UPDATE_UI(wxID_ANY
, MyFrame::UpdateUI
)
147 // My frame constructor
149 : wxFrame(NULL
, wxID_ANY
, _T("wxCollapsiblePane sample"),
150 wxDefaultPosition
, wxSize(420, 300),
151 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
155 #endif // wxUSE_STATUSBAR
158 wxMenu
*paneMenu
= new wxMenu
;
159 paneMenu
->Append(PANE_COLLAPSE
, _T("Collapse\tCtrl-C"));
160 paneMenu
->Append(PANE_EXPAND
, _T("Expand\tCtrl-E"));
161 paneMenu
->AppendSeparator();
162 paneMenu
->Append(PANE_SETLABEL
, _T("Set label...\tCtrl-S"));
163 paneMenu
->AppendSeparator();
164 paneMenu
->Append(PANE_SHOWDLG
, _T("Show dialog...\tCtrl-S"));
165 paneMenu
->AppendSeparator();
166 paneMenu
->Append(PANE_QUIT
);
168 wxMenuBar
*menuBar
= new wxMenuBar
;
169 menuBar
->Append(paneMenu
, _T("&Pane"));
172 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
173 wxWindow
*win
= m_collPane
->GetPane();
175 new wxStaticText(win
, -1, wxT("Static control with absolute coords"), wxPoint(10,2));
176 new wxStaticText(win
, -1, wxT("Yet another one!"), wxPoint(30, 30));
177 new wxTextCtrl(win
, -1, wxT("You can place anything you like inside a wxCollapsiblePane"),
178 wxPoint(5, 60), wxSize(300, -1));
185 // menu command handlers
187 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
192 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
194 m_collPane
->Collapse();
197 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
199 m_collPane
->Expand();
202 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
204 wxString text
= wxGetTextFromUser(wxT("Input the new label"));
205 m_collPane
->SetLabel(text
);
208 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
214 void MyFrame::UpdateUI(wxUpdateUIEvent
& event
)
216 GetMenuBar()->Enable(PANE_COLLAPSE
, !m_collPane
->IsCollapsed());
217 GetMenuBar()->Enable(PANE_EXPAND
, m_collPane
->IsCollapsed());
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
226 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
229 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
230 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
233 MyDialog::MyDialog(wxFrame
*parent
)
234 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
235 wxDefaultPosition
, wxDefaultSize
,
236 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
238 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
239 sz
->Add(new wxStaticText(this, -1,
240 wxT("This dialog allows you to test the wxCollapsiblePane control")),
242 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
245 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
246 sz
->Add(m_collPane
, 1, wxGROW
|wxALL
, 5);
247 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
249 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
251 // now add test controls in the collapsible pane
252 wxWindow
*win
= m_collPane
->GetPane();
253 wxSizer
*paneSz
= new wxGridSizer(2, 2, 5, 5);
254 paneSz
->Add(new wxColourPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
255 paneSz
->Add(new wxFontPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
256 paneSz
->Add(new wxFilePickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
257 paneSz
->Add(new wxDirPickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
258 win
->SetSizer(paneSz
);
259 paneSz
->SetSizeHints(win
);
262 sz
->SetSizeHints(this);
265 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
267 m_collPane
->Collapse(!m_collPane
->IsCollapsed());