]> git.saurik.com Git - wxWidgets.git/blame - samples/collpane/collpane.cpp
use explicit this-> with non-dependent names (compilation fix for standard-conforming...
[wxWidgets.git] / samples / collpane / collpane.cpp
CommitLineData
3c1f8cb1
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: collpane.cpp
3// Purpose: wxCollapsiblePane sample
4// Author: Francesco Montorsi
5// Modified by:
6// Created: 14/10/06
7// RCS-ID: $Id$
8// Copyright: (c) Francesco Montorsi
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
28 #include "wx/log.h"
29
30 #include "wx/app.h"
31 #include "wx/frame.h"
32
33 #include "wx/scrolwin.h"
34 #include "wx/menu.h"
35
36 #include "wx/textdlg.h" // for wxGetTextFromUser
37#endif
38
39#include "wx/collpane.h"
40#include "wx/sizer.h"
41#include "wx/stattext.h"
42#include "wx/clrpicker.h"
43#include "wx/filepicker.h"
44#include "wx/fontpicker.h"
912c3932 45#include "wx/aboutdlg.h"
3c1f8cb1
VZ
46
47// ----------------------------------------------------------------------------
48// constants
49// ----------------------------------------------------------------------------
50
51// ID for the menu commands
52enum
53{
54 PANE_COLLAPSE,
55 PANE_EXPAND,
56 PANE_SETLABEL,
57 PANE_SHOWDLG,
912c3932 58 PANE_ABOUT = wxID_ABOUT,
491bb4ba
RR
59 PANE_QUIT = wxID_EXIT,
60
61 PANE_BUTTON,
62 PANE_TEXTCTRL
3c1f8cb1
VZ
63};
64
65
66// ----------------------------------------------------------------------------
67// our classes
68// ----------------------------------------------------------------------------
69
70class MyApp: public wxApp
71{
72public:
73 MyApp() { }
74
75 virtual bool OnInit();
76
77 DECLARE_NO_COPY_CLASS(MyApp)
78};
79
80class MyFrame: public wxFrame
81{
82public:
83 MyFrame();
84 virtual ~MyFrame();
85
86 // Menu commands
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);
912c3932 92 void OnAbout(wxCommandEvent& event);
3c1f8cb1 93
26ef973f
VZ
94 // UI update handlers
95 void OnCollapseUpdateUI(wxUpdateUIEvent& event);
96 void OnExpandUpdateUI(wxUpdateUIEvent& event);
3c1f8cb1
VZ
97
98private:
99 wxCollapsiblePane *m_collPane;
491bb4ba 100 wxBoxSizer *m_paneSizer;
3c1f8cb1
VZ
101
102 DECLARE_EVENT_TABLE()
103 DECLARE_NO_COPY_CLASS(MyFrame)
104};
105
106class MyDialog : public wxDialog
107{
108public:
109 MyDialog(wxFrame *parent);
110 void OnToggleStatus(wxCommandEvent& WXUNUSED(ev));
491bb4ba 111 void OnAlignButton(wxCommandEvent& WXUNUSED(ev));
912c3932 112 void OnPaneChanged(wxCollapsiblePaneEvent& event);
3c1f8cb1
VZ
113
114private:
115 wxCollapsiblePane *m_collPane;
491bb4ba 116 wxGridSizer *m_paneSizer;
3c1f8cb1
VZ
117
118 DECLARE_EVENT_TABLE()
119 DECLARE_NO_COPY_CLASS(MyDialog)
120};
121
122
123
124// ============================================================================
125// implementation
126// ============================================================================
127
128// ----------------------------------------------------------------------------
129// MyApp
130// ----------------------------------------------------------------------------
131
132IMPLEMENT_APP(MyApp)
133
134bool MyApp::OnInit()
135{
45e6e6f8
VZ
136 if ( !wxApp::OnInit() )
137 return false;
138
3c1f8cb1
VZ
139 // create and show the main frame
140 MyFrame* frame = new MyFrame;
141
142 frame->Show(true);
143
144 return true;
145}
146
147// ----------------------------------------------------------------------------
148// MyFrame
149// ----------------------------------------------------------------------------
150
151BEGIN_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)
912c3932 156 EVT_MENU(PANE_ABOUT, MyFrame::OnAbout)
3c1f8cb1
VZ
157 EVT_MENU(PANE_QUIT, MyFrame::Quit)
158
26ef973f
VZ
159 EVT_UPDATE_UI(PANE_COLLAPSE, MyFrame::OnCollapseUpdateUI)
160 EVT_UPDATE_UI(PANE_EXPAND, MyFrame::OnExpandUpdateUI)
3c1f8cb1
VZ
161END_EVENT_TABLE()
162
163// My frame constructor
164MyFrame::MyFrame()
165 : wxFrame(NULL, wxID_ANY, _T("wxCollapsiblePane sample"),
166 wxDefaultPosition, wxSize(420, 300),
167 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
168{
169#if wxUSE_STATUSBAR
170 CreateStatusBar(2);
171#endif // wxUSE_STATUSBAR
172
173 // Make a menubar
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();
26ef973f 178 paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-L"));
3c1f8cb1
VZ
179 paneMenu->AppendSeparator();
180 paneMenu->Append(PANE_SHOWDLG, _T("Show dialog...\tCtrl-S"));
181 paneMenu->AppendSeparator();
182 paneMenu->Append(PANE_QUIT);
183
912c3932
VZ
184 wxMenu *helpMenu = new wxMenu;
185 helpMenu->Append(PANE_ABOUT);
186
3c1f8cb1
VZ
187 wxMenuBar *menuBar = new wxMenuBar;
188 menuBar->Append(paneMenu, _T("&Pane"));
912c3932 189 menuBar->Append(helpMenu, _T("&Help"));
3c1f8cb1
VZ
190 SetMenuBar(menuBar);
191
192 m_collPane = new wxCollapsiblePane(this, -1, wxT("test!"));
193 wxWindow *win = m_collPane->GetPane();
491bb4ba
RR
194
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 );
3c1f8cb1
VZ
201}
202
203MyFrame::~MyFrame()
204{
205}
206
207// menu command handlers
208
209void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
210{
211 Close(true);
212}
213
214void MyFrame::OnCollapse(wxCommandEvent& WXUNUSED(event) )
215{
216 m_collPane->Collapse();
217}
218
219void MyFrame::OnExpand(wxCommandEvent& WXUNUSED(event) )
220{
221 m_collPane->Expand();
222}
223
224void MyFrame::OnSetLabel(wxCommandEvent& WXUNUSED(event) )
225{
26ef973f
VZ
226 wxString text = wxGetTextFromUser
227 (
228 wxT("Enter new label"),
229 wxGetTextFromUserPromptStr,
230 m_collPane->GetLabel()
231 );
3c1f8cb1
VZ
232 m_collPane->SetLabel(text);
233}
234
235void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event) )
236{
237 MyDialog dlg(this);
238 dlg.ShowModal();
239}
240
912c3932
VZ
241void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
242{
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>"));
247
248 wxAboutBox(info);
249}
250
26ef973f 251void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent& event)
3c1f8cb1 252{
26ef973f
VZ
253 event.Enable(!m_collPane->IsCollapsed());
254}
255
256void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent& event)
257{
258 event.Enable(m_collPane->IsCollapsed());
3c1f8cb1
VZ
259}
260
912c3932 261
3c1f8cb1
VZ
262// ----------------------------------------------------------------------------
263// MyDialog
264// ----------------------------------------------------------------------------
265
266enum
267{
268 PANEDLG_TOGGLESTATUS_BTN = wxID_HIGHEST
269};
270
271BEGIN_EVENT_TABLE(MyDialog, wxDialog)
272 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus)
912c3932 273 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY, MyDialog::OnPaneChanged)
491bb4ba 274 EVT_BUTTON(PANE_BUTTON, MyDialog::OnAlignButton)
3c1f8cb1
VZ
275END_EVENT_TABLE()
276
277MyDialog::MyDialog(wxFrame *parent)
278 : wxDialog(parent, wxID_ANY, wxT("Test dialog"),
279 wxDefaultPosition, wxDefaultSize,
280 wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE )
281{
282 wxSizer *sz = new wxBoxSizer(wxVERTICAL);
912c3932 283 sz->Add(new wxStaticText(this, -1,
3c1f8cb1
VZ
284 wxT("This dialog allows you to test the wxCollapsiblePane control")),
285 0, wxALL, 5);
912c3932 286 sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")),
3c1f8cb1 287 1, wxGROW|wxALL, 5);
912c3932 288
3c1f8cb1 289 m_collPane = new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
912c3932 290 sz->Add(m_collPane, 0, wxGROW|wxALL, 5);
3c1f8cb1
VZ
291 sz->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW|wxALL, 5);
292 sz->AddSpacer(10);
293 sz->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5);
294
295 // now add test controls in the collapsible pane
296 wxWindow *win = m_collPane->GetPane();
491bb4ba
RR
297 m_paneSizer = new wxGridSizer(4, 1, 5, 5);
298
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 );
304
305 win->SetSizer( m_paneSizer );
306 m_paneSizer->SetSizeHints(win);
3c1f8cb1
VZ
307
308 SetSizer(sz);
309 sz->SetSizeHints(this);
310}
311
312void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev))
313{
314 m_collPane->Collapse(!m_collPane->IsCollapsed());
315}
316
491bb4ba
RR
317void MyDialog::OnAlignButton(wxCommandEvent& WXUNUSED(ev))
318{
319 wxSizerItem *item = m_paneSizer->GetItem( FindWindow(PANE_TEXTCTRL), true );
320 item->SetFlag( wxALIGN_RIGHT );
321
322 Layout();
323}
324
912c3932
VZ
325void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent &event)
326{
327 wxLogDebug(wxT("The pane has just been %s by the user"),
328 event.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));
329}
330