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
);
92 void OnCollapseUpdateUI(wxUpdateUIEvent
& event
);
93 void OnExpandUpdateUI(wxUpdateUIEvent
& event
);
96 wxCollapsiblePane
*m_collPane
;
99 DECLARE_NO_COPY_CLASS(MyFrame
)
102 class MyDialog
: public wxDialog
105 MyDialog(wxFrame
*parent
);
106 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
107 void OnPaneChanged(wxCollapsiblePaneEvent
& event
);
110 wxCollapsiblePane
*m_collPane
;
112 DECLARE_EVENT_TABLE()
113 DECLARE_NO_COPY_CLASS(MyDialog
)
118 // ============================================================================
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
130 if ( !wxApp::OnInit() )
133 // create and show the main frame
134 MyFrame
* frame
= new MyFrame
;
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
146 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
147 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
148 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
149 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
150 EVT_MENU(PANE_ABOUT
, MyFrame::OnAbout
)
151 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
153 EVT_UPDATE_UI(PANE_COLLAPSE
, MyFrame::OnCollapseUpdateUI
)
154 EVT_UPDATE_UI(PANE_EXPAND
, MyFrame::OnExpandUpdateUI
)
157 // My frame constructor
159 : wxFrame(NULL
, wxID_ANY
, _T("wxCollapsiblePane sample"),
160 wxDefaultPosition
, wxSize(420, 300),
161 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
165 #endif // wxUSE_STATUSBAR
168 wxMenu
*paneMenu
= new wxMenu
;
169 paneMenu
->Append(PANE_COLLAPSE
, _T("Collapse\tCtrl-C"));
170 paneMenu
->Append(PANE_EXPAND
, _T("Expand\tCtrl-E"));
171 paneMenu
->AppendSeparator();
172 paneMenu
->Append(PANE_SETLABEL
, _T("Set label...\tCtrl-L"));
173 paneMenu
->AppendSeparator();
174 paneMenu
->Append(PANE_SHOWDLG
, _T("Show dialog...\tCtrl-S"));
175 paneMenu
->AppendSeparator();
176 paneMenu
->Append(PANE_QUIT
);
178 wxMenu
*helpMenu
= new wxMenu
;
179 helpMenu
->Append(PANE_ABOUT
);
181 wxMenuBar
*menuBar
= new wxMenuBar
;
182 menuBar
->Append(paneMenu
, _T("&Pane"));
183 menuBar
->Append(helpMenu
, _T("&Help"));
186 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
187 wxWindow
*win
= m_collPane
->GetPane();
189 new wxStaticText(win
, -1, wxT("Static control with absolute coords"), wxPoint(10,2));
190 new wxStaticText(win
, -1, wxT("Yet another one!"), wxPoint(30, 30));
191 new wxTextCtrl(win
, -1, wxT("You can place anything you like inside a wxCollapsiblePane"),
192 wxPoint(5, 60), wxSize(300, -1));
199 // menu command handlers
201 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
206 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
208 m_collPane
->Collapse();
211 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
213 m_collPane
->Expand();
216 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
218 wxString text
= wxGetTextFromUser
220 wxT("Enter new label"),
221 wxGetTextFromUserPromptStr
,
222 m_collPane
->GetLabel()
224 m_collPane
->SetLabel(text
);
227 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
233 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
235 wxAboutDialogInfo info
;
236 info
.SetName(_("wxCollapsiblePane sample"));
237 info
.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
238 info
.SetCopyright(_T("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
243 void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent
& event
)
245 event
.Enable(!m_collPane
->IsCollapsed());
248 void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent
& event
)
250 event
.Enable(m_collPane
->IsCollapsed());
254 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
260 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
263 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
264 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
265 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY
, MyDialog::OnPaneChanged
)
268 MyDialog::MyDialog(wxFrame
*parent
)
269 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
270 wxDefaultPosition
, wxDefaultSize
,
271 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
273 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
274 sz
->Add(new wxStaticText(this, -1,
275 wxT("This dialog allows you to test the wxCollapsiblePane control")),
277 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
280 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
281 sz
->Add(m_collPane
, 0, wxGROW
|wxALL
, 5);
282 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
284 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
286 // now add test controls in the collapsible pane
287 wxWindow
*win
= m_collPane
->GetPane();
288 wxSizer
*paneSz
= new wxGridSizer(2, 2, 5, 5);
289 paneSz
->Add(new wxColourPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
290 paneSz
->Add(new wxFontPickerCtrl(win
, -1), 1, wxGROW
|wxALL
, 2);
291 paneSz
->Add(new wxFilePickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
292 paneSz
->Add(new wxDirPickerCtrl(win
, -1), 1, wxALL
|wxALIGN_CENTER
, 2);
293 win
->SetSizer(paneSz
);
294 paneSz
->SetSizeHints(win
);
297 sz
->SetSizeHints(this);
300 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
302 m_collPane
->Collapse(!m_collPane
->IsCollapsed());
305 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent
&event
)
307 wxLogDebug(wxT("The pane has just been %s by the user"),
308 event
.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));