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
,
59 PANE_QUIT
= wxID_EXIT
,
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 class MyApp
: public wxApp
75 virtual bool OnInit();
77 DECLARE_NO_COPY_CLASS(MyApp
)
80 class MyFrame
: public wxFrame
87 void OnCollapse(wxCommandEvent
& event
);
88 void OnExpand(wxCommandEvent
& event
);
89 void OnSetLabel(wxCommandEvent
& event
);
90 void OnShowDialog(wxCommandEvent
& event
);
91 void Quit(wxCommandEvent
& event
);
92 void OnAbout(wxCommandEvent
& event
);
95 void OnCollapseUpdateUI(wxUpdateUIEvent
& event
);
96 void OnExpandUpdateUI(wxUpdateUIEvent
& event
);
99 wxCollapsiblePane
*m_collPane
;
100 wxBoxSizer
*m_paneSizer
;
102 DECLARE_EVENT_TABLE()
103 DECLARE_NO_COPY_CLASS(MyFrame
)
106 class MyDialog
: public wxDialog
109 MyDialog(wxFrame
*parent
);
110 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
111 void OnAlignButton(wxCommandEvent
& WXUNUSED(ev
));
112 void OnPaneChanged(wxCollapsiblePaneEvent
& event
);
115 wxCollapsiblePane
*m_collPane
;
116 wxGridSizer
*m_paneSizer
;
118 DECLARE_EVENT_TABLE()
119 DECLARE_NO_COPY_CLASS(MyDialog
)
124 // ============================================================================
126 // ============================================================================
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
136 if ( !wxApp::OnInit() )
139 // create and show the main frame
140 MyFrame
* frame
= new MyFrame
;
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
152 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
153 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
154 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
155 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
156 EVT_MENU(PANE_ABOUT
, MyFrame::OnAbout
)
157 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
159 EVT_UPDATE_UI(PANE_COLLAPSE
, MyFrame::OnCollapseUpdateUI
)
160 EVT_UPDATE_UI(PANE_EXPAND
, MyFrame::OnExpandUpdateUI
)
163 // My frame constructor
165 : wxFrame(NULL
, wxID_ANY
, _T("wxCollapsiblePane sample"),
166 wxDefaultPosition
, wxSize(420, 300),
167 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
171 #endif // wxUSE_STATUSBAR
174 wxMenu
*paneMenu
= new wxMenu
;
175 paneMenu
->Append(PANE_COLLAPSE
, _T("Collapse\tCtrl-C"));
176 paneMenu
->Append(PANE_EXPAND
, _T("Expand\tCtrl-E"));
177 paneMenu
->AppendSeparator();
178 paneMenu
->Append(PANE_SETLABEL
, _T("Set label...\tCtrl-L"));
179 paneMenu
->AppendSeparator();
180 paneMenu
->Append(PANE_SHOWDLG
, _T("Show dialog...\tCtrl-S"));
181 paneMenu
->AppendSeparator();
182 paneMenu
->Append(PANE_QUIT
);
184 wxMenu
*helpMenu
= new wxMenu
;
185 helpMenu
->Append(PANE_ABOUT
);
187 wxMenuBar
*menuBar
= new wxMenuBar
;
188 menuBar
->Append(paneMenu
, _T("&Pane"));
189 menuBar
->Append(helpMenu
, _T("&Help"));
192 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
193 wxWindow
*win
= m_collPane
->GetPane();
195 m_paneSizer
= new wxBoxSizer( wxVERTICAL
);
196 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
);
197 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
);
198 m_paneSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
);
199 m_paneSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
);
200 win
->SetSizer( m_paneSizer
);
207 // menu command handlers
209 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
214 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
216 m_collPane
->Collapse();
219 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
221 m_collPane
->Expand();
224 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
226 wxString text
= wxGetTextFromUser
228 wxT("Enter new label"),
229 wxGetTextFromUserPromptStr
,
230 m_collPane
->GetLabel()
232 m_collPane
->SetLabel(text
);
235 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
241 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
243 wxAboutDialogInfo info
;
244 info
.SetName(_("wxCollapsiblePane sample"));
245 info
.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
246 info
.SetCopyright(_T("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
251 void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent
& event
)
253 event
.Enable(!m_collPane
->IsCollapsed());
256 void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent
& event
)
258 event
.Enable(m_collPane
->IsCollapsed());
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
268 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
271 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
272 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
273 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY
, MyDialog::OnPaneChanged
)
274 EVT_BUTTON(PANE_BUTTON
, MyDialog::OnAlignButton
)
277 MyDialog::MyDialog(wxFrame
*parent
)
278 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
279 wxDefaultPosition
, wxDefaultSize
,
280 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
282 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
283 sz
->Add(new wxStaticText(this, -1,
284 wxT("This dialog allows you to test the wxCollapsiblePane control")),
286 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
289 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
290 sz
->Add(m_collPane
, 0, wxGROW
|wxALL
, 5);
291 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
293 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
295 // now add test controls in the collapsible pane
296 wxWindow
*win
= m_collPane
->GetPane();
297 m_paneSizer
= new wxGridSizer(4, 1, 5, 5);
299 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
);
300 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
);
301 m_paneSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
);
302 m_paneSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
);
303 win
->SetSizer( m_paneSizer
);
305 win
->SetSizer( m_paneSizer
);
306 m_paneSizer
->SetSizeHints(win
);
309 sz
->SetSizeHints(this);
312 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
314 m_collPane
->Collapse(!m_collPane
->IsCollapsed());
317 void MyDialog::OnAlignButton(wxCommandEvent
& WXUNUSED(ev
))
319 wxSizerItem
*item
= m_paneSizer
->GetItem( FindWindow(PANE_TEXTCTRL
), true );
320 item
->SetFlag( wxALIGN_RIGHT
);
325 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent
&event
)
327 wxLogDebug(wxT("The pane has just been %s by the user"),
328 event
.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));