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"
45 #include "wx/aboutdlg.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // ID for the menu commands
58 PANE_ABOUT
= wxID_ABOUT
,
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 class MyApp
: public wxApp
72 virtual bool OnInit();
74 DECLARE_NO_COPY_CLASS(MyApp
)
77 class MyFrame
: public wxFrame
84 void OnCollapse(wxCommandEvent
& event
);
85 void OnExpand(wxCommandEvent
& event
);
86 void OnSetLabel(wxCommandEvent
& event
);
87 void OnShowDialog(wxCommandEvent
& event
);
88 void Quit(wxCommandEvent
& event
);
89 void OnAbout(wxCommandEvent
& event
);
91 // Menu command update functions
92 void UpdateUI(wxUpdateUIEvent
& event
);
95 wxCollapsiblePane
*m_collPane
;
98 DECLARE_NO_COPY_CLASS(MyFrame
)
101 class MyDialog
: public wxDialog
104 MyDialog(wxFrame
*parent
);
105 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
106 void OnPaneChanged(wxCollapsiblePaneEvent
& event
);
109 wxCollapsiblePane
*m_collPane
;
111 DECLARE_EVENT_TABLE()
112 DECLARE_NO_COPY_CLASS(MyDialog
)
117 // ============================================================================
119 // ============================================================================
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
129 // create and show the main frame
130 MyFrame
* frame
= new MyFrame
;
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
142 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
143 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
144 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
145 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
146 EVT_MENU(PANE_ABOUT
, MyFrame::OnAbout
)
147 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
149 EVT_UPDATE_UI(wxID_ANY
, MyFrame::UpdateUI
)
152 // My frame constructor
154 : wxFrame(NULL
, wxID_ANY
, _T("wxCollapsiblePane sample"),
155 wxDefaultPosition
, wxSize(420, 300),
156 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
160 #endif // wxUSE_STATUSBAR
163 wxMenu
*paneMenu
= new wxMenu
;
164 paneMenu
->Append(PANE_COLLAPSE
, _T("Collapse\tCtrl-C"));
165 paneMenu
->Append(PANE_EXPAND
, _T("Expand\tCtrl-E"));
166 paneMenu
->AppendSeparator();
167 paneMenu
->Append(PANE_SETLABEL
, _T("Set label...\tCtrl-S"));
168 paneMenu
->AppendSeparator();
169 paneMenu
->Append(PANE_SHOWDLG
, _T("Show dialog...\tCtrl-S"));
170 paneMenu
->AppendSeparator();
171 paneMenu
->Append(PANE_QUIT
);
173 wxMenu
*helpMenu
= new wxMenu
;
174 helpMenu
->Append(PANE_ABOUT
);
176 wxMenuBar
*menuBar
= new wxMenuBar
;
177 menuBar
->Append(paneMenu
, _T("&Pane"));
178 menuBar
->Append(helpMenu
, _T("&Help"));
181 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
182 wxWindow
*win
= m_collPane
->GetPane();
184 new wxStaticText(win
, -1, wxT("Static control with absolute coords"), wxPoint(10,2));
185 new wxStaticText(win
, -1, wxT("Yet another one!"), wxPoint(30, 30));
186 new wxTextCtrl(win
, -1, wxT("You can place anything you like inside a wxCollapsiblePane"),
187 wxPoint(5, 60), wxSize(300, -1));
194 // menu command handlers
196 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
201 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
203 m_collPane
->Collapse();
206 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
208 m_collPane
->Expand();
211 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
213 wxString text
= wxGetTextFromUser(wxT("Input the new label"));
214 m_collPane
->SetLabel(text
);
217 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
223 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
225 wxAboutDialogInfo info
;
226 info
.SetName(_("wxCollapsiblePane sample"));
227 info
.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
228 info
.SetCopyright(_T("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
233 void MyFrame::UpdateUI(wxUpdateUIEvent
& event
)
235 GetMenuBar()->Enable(PANE_COLLAPSE
, !m_collPane
->IsCollapsed());
236 GetMenuBar()->Enable(PANE_EXPAND
, m_collPane
->IsCollapsed());
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
246 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
249 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
250 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
251 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY
, MyDialog::OnPaneChanged
)
254 MyDialog::MyDialog(wxFrame
*parent
)
255 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
256 wxDefaultPosition
, wxDefaultSize
,
257 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
259 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
260 sz
->Add(new wxStaticText(this, -1,
261 wxT("This dialog allows you to test the wxCollapsiblePane control")),
263 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
266 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
267 sz
->Add(m_collPane
, 0, wxGROW
|wxALL
, 5);
268 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
270 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
272 // now add test controls in the collapsible pane
273 wxWindow
*win
= m_collPane
->GetPane();
274 wxSizer
*paneSz
= new wxGridSizer(2, 2, 5, 5);
275 paneSz
->Add(new wxColourPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
276 paneSz
->Add(new wxFontPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
277 paneSz
->Add(new wxFilePickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
278 paneSz
->Add(new wxDirPickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
279 win
->SetSizer(paneSz
);
280 paneSz
->SetSizeHints(win
);
283 sz
->SetSizeHints(this);
286 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
288 m_collPane
->Collapse(!m_collPane
->IsCollapsed());
291 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent
&event
)
293 wxLogDebug(wxT("The pane has just been %s by the user"),
294 event
.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));