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"
48 #include "../sample.xpm"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // ID for the menu commands
62 PANE_ABOUT
= wxID_ABOUT
,
63 PANE_QUIT
= wxID_EXIT
,
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 class MyApp
: public wxApp
79 virtual bool OnInit();
81 wxDECLARE_NO_COPY_CLASS(MyApp
);
84 class MyFrame
: public wxFrame
91 void OnCollapse(wxCommandEvent
& event
);
92 void OnExpand(wxCommandEvent
& event
);
93 void OnSetLabel(wxCommandEvent
& event
);
94 void OnShowDialog(wxCommandEvent
& event
);
95 void Quit(wxCommandEvent
& event
);
96 void OnAbout(wxCommandEvent
& event
);
99 void OnCollapseUpdateUI(wxUpdateUIEvent
& event
);
100 void OnExpandUpdateUI(wxUpdateUIEvent
& event
);
103 wxCollapsiblePane
*m_collPane
;
104 wxBoxSizer
*m_paneSizer
;
106 DECLARE_EVENT_TABLE()
107 wxDECLARE_NO_COPY_CLASS(MyFrame
);
110 class MyDialog
: public wxDialog
113 MyDialog(wxFrame
*parent
);
114 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
115 void OnAlignButton(wxCommandEvent
& WXUNUSED(ev
));
116 void OnPaneChanged(wxCollapsiblePaneEvent
& event
);
119 wxCollapsiblePane
*m_collPane
;
120 wxGridSizer
*m_paneSizer
;
122 DECLARE_EVENT_TABLE()
123 wxDECLARE_NO_COPY_CLASS(MyDialog
);
128 // ============================================================================
130 // ============================================================================
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
140 if ( !wxApp::OnInit() )
143 // create and show the main frame
144 MyFrame
* frame
= new MyFrame
;
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
156 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
157 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
158 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
159 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
160 EVT_MENU(PANE_ABOUT
, MyFrame::OnAbout
)
161 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
163 EVT_UPDATE_UI(PANE_COLLAPSE
, MyFrame::OnCollapseUpdateUI
)
164 EVT_UPDATE_UI(PANE_EXPAND
, MyFrame::OnExpandUpdateUI
)
167 // My frame constructor
169 : wxFrame(NULL
, wxID_ANY
, _T("wxCollapsiblePane sample"),
170 wxDefaultPosition
, wxSize(420, 300),
171 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
173 SetIcon(wxICON(sample
));
177 #endif // wxUSE_STATUSBAR
180 wxMenu
*paneMenu
= new wxMenu
;
181 paneMenu
->Append(PANE_COLLAPSE
, _T("Collapse\tCtrl-C"));
182 paneMenu
->Append(PANE_EXPAND
, _T("Expand\tCtrl-E"));
183 paneMenu
->AppendSeparator();
184 paneMenu
->Append(PANE_SETLABEL
, _T("Set label...\tCtrl-L"));
185 paneMenu
->AppendSeparator();
186 paneMenu
->Append(PANE_SHOWDLG
, _T("Show dialog...\tCtrl-S"));
187 paneMenu
->AppendSeparator();
188 paneMenu
->Append(PANE_QUIT
);
190 wxMenu
*helpMenu
= new wxMenu
;
191 helpMenu
->Append(PANE_ABOUT
);
193 wxMenuBar
*menuBar
= new wxMenuBar
;
194 menuBar
->Append(paneMenu
, _T("&Pane"));
195 menuBar
->Append(helpMenu
, _T("&Help"));
198 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
199 wxWindow
*win
= m_collPane
->GetPane();
201 m_paneSizer
= new wxBoxSizer( wxVERTICAL
);
202 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
);
203 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
);
204 m_paneSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
);
205 m_paneSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
);
206 win
->SetSizer( m_paneSizer
);
213 // menu command handlers
215 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
220 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
222 m_collPane
->Collapse();
225 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
227 m_collPane
->Expand();
230 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
232 wxString text
= wxGetTextFromUser
234 wxT("Enter new label"),
235 wxGetTextFromUserPromptStr
,
236 m_collPane
->GetLabel()
238 m_collPane
->SetLabel(text
);
241 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
247 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
249 wxAboutDialogInfo info
;
250 info
.SetName(_("wxCollapsiblePane sample"));
251 info
.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
252 info
.SetCopyright(_T("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
257 void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent
& event
)
259 event
.Enable(!m_collPane
->IsCollapsed());
262 void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent
& event
)
264 event
.Enable(m_collPane
->IsCollapsed());
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
274 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
277 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
278 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
279 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY
, MyDialog::OnPaneChanged
)
280 EVT_BUTTON(PANE_BUTTON
, MyDialog::OnAlignButton
)
283 MyDialog::MyDialog(wxFrame
*parent
)
284 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
285 wxDefaultPosition
, wxDefaultSize
,
286 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
288 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
289 sz
->Add(new wxStaticText(this, -1,
290 wxT("This dialog allows you to test the wxCollapsiblePane control")),
292 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
295 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
296 sz
->Add(m_collPane
, 0, wxGROW
|wxALL
, 5);
297 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
299 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
301 // now add test controls in the collapsible pane
302 wxWindow
*win
= m_collPane
->GetPane();
303 m_paneSizer
= new wxGridSizer(4, 1, 5, 5);
305 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
);
306 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
);
307 m_paneSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
);
308 m_paneSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
);
309 win
->SetSizer( m_paneSizer
);
311 win
->SetSizer( m_paneSizer
);
312 m_paneSizer
->SetSizeHints(win
);
315 sz
->SetSizeHints(this);
318 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
320 m_collPane
->Collapse(!m_collPane
->IsCollapsed());
323 void MyDialog::OnAlignButton(wxCommandEvent
& WXUNUSED(ev
))
325 wxSizerItem
*item
= m_paneSizer
->GetItem( FindWindow(PANE_TEXTCTRL
), true );
326 item
->SetFlag( wxALIGN_RIGHT
);
331 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent
&event
)
333 wxLogDebug(wxT("The pane has just been %s by the user"),
334 event
.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));