1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCollapsiblePane sample
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
32 #include "wx/scrolwin.h"
35 #include "wx/textdlg.h" // for wxGetTextFromUser
38 #include "wx/collpane.h"
40 #include "wx/stattext.h"
41 #include "wx/clrpicker.h"
42 #include "wx/filepicker.h"
43 #include "wx/fontpicker.h"
44 #include "wx/aboutdlg.h"
46 #ifndef wxHAS_IMAGES_IN_RESOURCES
47 #include "../sample.xpm"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // ID for the menu commands
61 PANE_ABOUT
= wxID_ABOUT
,
62 PANE_QUIT
= wxID_EXIT
,
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 class MyApp
: public wxApp
78 virtual bool OnInit();
80 wxDECLARE_NO_COPY_CLASS(MyApp
);
83 class MyFrame
: public wxFrame
90 void OnCollapse(wxCommandEvent
& event
);
91 void OnExpand(wxCommandEvent
& event
);
92 void OnSetLabel(wxCommandEvent
& event
);
93 void OnShowDialog(wxCommandEvent
& event
);
94 void Quit(wxCommandEvent
& event
);
95 void OnAbout(wxCommandEvent
& event
);
98 void OnCollapseUpdateUI(wxUpdateUIEvent
& event
);
99 void OnExpandUpdateUI(wxUpdateUIEvent
& event
);
102 wxCollapsiblePane
*m_collPane
;
103 wxBoxSizer
*m_paneSizer
;
105 DECLARE_EVENT_TABLE()
106 wxDECLARE_NO_COPY_CLASS(MyFrame
);
109 class MyDialog
: public wxDialog
112 MyDialog(wxFrame
*parent
);
113 void OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
));
114 void OnAlignButton(wxCommandEvent
& WXUNUSED(ev
));
115 void OnPaneChanged(wxCollapsiblePaneEvent
& event
);
118 wxCollapsiblePane
*m_collPane
;
119 wxGridSizer
*m_paneSizer
;
121 DECLARE_EVENT_TABLE()
122 wxDECLARE_NO_COPY_CLASS(MyDialog
);
127 // ============================================================================
129 // ============================================================================
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
139 if ( !wxApp::OnInit() )
142 // create and show the main frame
143 MyFrame
* frame
= new MyFrame
;
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
155 EVT_MENU(PANE_COLLAPSE
, MyFrame::OnCollapse
)
156 EVT_MENU(PANE_EXPAND
, MyFrame::OnExpand
)
157 EVT_MENU(PANE_SETLABEL
, MyFrame::OnSetLabel
)
158 EVT_MENU(PANE_SHOWDLG
, MyFrame::OnShowDialog
)
159 EVT_MENU(PANE_ABOUT
, MyFrame::OnAbout
)
160 EVT_MENU(PANE_QUIT
, MyFrame::Quit
)
162 EVT_UPDATE_UI(PANE_COLLAPSE
, MyFrame::OnCollapseUpdateUI
)
163 EVT_UPDATE_UI(PANE_EXPAND
, MyFrame::OnExpandUpdateUI
)
166 // My frame constructor
168 : wxFrame(NULL
, wxID_ANY
, wxT("wxCollapsiblePane sample"),
169 wxDefaultPosition
, wxSize(420, 300),
170 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
)
172 SetIcon(wxICON(sample
));
176 #endif // wxUSE_STATUSBAR
179 wxMenu
*paneMenu
= new wxMenu
;
180 paneMenu
->Append(PANE_COLLAPSE
, wxT("Collapse\tCtrl-C"));
181 paneMenu
->Append(PANE_EXPAND
, wxT("Expand\tCtrl-E"));
182 paneMenu
->AppendSeparator();
183 paneMenu
->Append(PANE_SETLABEL
, wxT("Set label...\tCtrl-L"));
184 paneMenu
->AppendSeparator();
185 paneMenu
->Append(PANE_SHOWDLG
, wxT("Show dialog...\tCtrl-S"));
186 paneMenu
->AppendSeparator();
187 paneMenu
->Append(PANE_QUIT
);
189 wxMenu
*helpMenu
= new wxMenu
;
190 helpMenu
->Append(PANE_ABOUT
);
192 wxMenuBar
*menuBar
= new wxMenuBar
;
193 menuBar
->Append(paneMenu
, wxT("&Pane"));
194 menuBar
->Append(helpMenu
, wxT("&Help"));
197 m_collPane
= new wxCollapsiblePane(this, -1, wxT("test!"));
198 wxWindow
*win
= m_collPane
->GetPane();
200 m_paneSizer
= new wxBoxSizer( wxHORIZONTAL
);
201 wxBoxSizer
* paneSubSizer
= new wxBoxSizer( wxVERTICAL
);
202 m_paneSizer
->AddSpacer( 20 );
203 m_paneSizer
->Add( paneSubSizer
, 1 );
205 paneSubSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
| wxALL
, 3 );
206 paneSubSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
| wxALL
, 3 );
207 paneSubSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
| wxALL
, 3 );
208 paneSubSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
| wxALL
, 3 );
210 win
->SetSizer( m_paneSizer
);
217 // menu command handlers
219 void MyFrame::Quit(wxCommandEvent
& WXUNUSED(event
) )
224 void MyFrame::OnCollapse(wxCommandEvent
& WXUNUSED(event
) )
226 m_collPane
->Collapse();
229 void MyFrame::OnExpand(wxCommandEvent
& WXUNUSED(event
) )
231 m_collPane
->Expand();
234 void MyFrame::OnSetLabel(wxCommandEvent
& WXUNUSED(event
) )
236 wxString text
= wxGetTextFromUser
238 wxT("Enter new label"),
239 wxGetTextFromUserPromptStr
,
240 m_collPane
->GetLabel()
242 m_collPane
->SetLabel(text
);
245 void MyFrame::OnShowDialog(wxCommandEvent
& WXUNUSED(event
) )
251 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
253 wxAboutDialogInfo info
;
254 info
.SetName(_("wxCollapsiblePane sample"));
255 info
.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
256 info
.SetCopyright(wxT("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
261 void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent
& event
)
263 event
.Enable(!m_collPane
->IsCollapsed());
266 void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent
& event
)
268 event
.Enable(m_collPane
->IsCollapsed());
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
278 PANEDLG_TOGGLESTATUS_BTN
= wxID_HIGHEST
281 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
282 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN
, MyDialog::OnToggleStatus
)
283 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY
, MyDialog::OnPaneChanged
)
284 EVT_BUTTON(PANE_BUTTON
, MyDialog::OnAlignButton
)
287 MyDialog::MyDialog(wxFrame
*parent
)
288 : wxDialog(parent
, wxID_ANY
, wxT("Test dialog"),
289 wxDefaultPosition
, wxDefaultSize
,
290 wxRESIZE_BORDER
|wxDEFAULT_DIALOG_STYLE
)
292 wxSizer
*sz
= new wxBoxSizer(wxVERTICAL
);
293 sz
->Add(new wxStaticText(this, -1,
294 wxT("This dialog allows you to test the wxCollapsiblePane control")),
296 sz
->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN
, wxT("Change status")),
299 m_collPane
= new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
300 sz
->Add(m_collPane
, 0, wxGROW
|wxALL
, 5);
301 sz
->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW
|wxALL
, 5);
303 sz
->Add(new wxButton(this, wxID_OK
), 0, wxALIGN_RIGHT
|wxALL
, 5);
305 // now add test controls in the collapsible pane
306 wxWindow
*win
= m_collPane
->GetPane();
307 m_paneSizer
= new wxGridSizer(4, 1, 5, 5);
309 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Static text") ), 0, wxALIGN_LEFT
);
310 m_paneSizer
->Add( new wxStaticText(win
, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT
);
311 m_paneSizer
->Add( new wxTextCtrl(win
, PANE_TEXTCTRL
, wxT("Text control"), wxDefaultPosition
, wxSize(80,-1) ), 0, wxALIGN_LEFT
);
312 m_paneSizer
->Add( new wxButton(win
, PANE_BUTTON
, wxT("Press to align right") ), 0, wxALIGN_LEFT
);
313 win
->SetSizer( m_paneSizer
);
315 win
->SetSizer( m_paneSizer
);
316 m_paneSizer
->SetSizeHints(win
);
319 sz
->SetSizeHints(this);
322 void MyDialog::OnToggleStatus(wxCommandEvent
& WXUNUSED(ev
))
324 m_collPane
->Collapse(!m_collPane
->IsCollapsed());
327 void MyDialog::OnAlignButton(wxCommandEvent
& WXUNUSED(ev
))
329 wxSizerItem
*item
= m_paneSizer
->GetItem( FindWindow(PANE_TEXTCTRL
), true );
330 item
->SetFlag( wxALIGN_RIGHT
);
335 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent
& event
)
337 wxLogMessage(wxT("The pane has just been %s by the user"),
338 event
.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));