]> git.saurik.com Git - wxWidgets.git/blob - samples/collpane/collpane.cpp
reSWIGged
[wxWidgets.git] / samples / collpane / collpane.cpp
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"
45 #include "wx/aboutdlg.h"
46
47 // ----------------------------------------------------------------------------
48 // constants
49 // ----------------------------------------------------------------------------
50
51 // ID for the menu commands
52 enum
53 {
54 PANE_COLLAPSE,
55 PANE_EXPAND,
56 PANE_SETLABEL,
57 PANE_SHOWDLG,
58 PANE_ABOUT = wxID_ABOUT,
59 PANE_QUIT = wxID_EXIT
60 };
61
62
63 // ----------------------------------------------------------------------------
64 // our classes
65 // ----------------------------------------------------------------------------
66
67 class MyApp: public wxApp
68 {
69 public:
70 MyApp() { }
71
72 virtual bool OnInit();
73
74 DECLARE_NO_COPY_CLASS(MyApp)
75 };
76
77 class MyFrame: public wxFrame
78 {
79 public:
80 MyFrame();
81 virtual ~MyFrame();
82
83 // Menu commands
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);
90
91 // Menu command update functions
92 void UpdateUI(wxUpdateUIEvent& event);
93
94 private:
95 wxCollapsiblePane *m_collPane;
96
97 DECLARE_EVENT_TABLE()
98 DECLARE_NO_COPY_CLASS(MyFrame)
99 };
100
101 class MyDialog : public wxDialog
102 {
103 public:
104 MyDialog(wxFrame *parent);
105 void OnToggleStatus(wxCommandEvent& WXUNUSED(ev));
106 void OnPaneChanged(wxCollapsiblePaneEvent& event);
107
108 private:
109 wxCollapsiblePane *m_collPane;
110
111 DECLARE_EVENT_TABLE()
112 DECLARE_NO_COPY_CLASS(MyDialog)
113 };
114
115
116
117 // ============================================================================
118 // implementation
119 // ============================================================================
120
121 // ----------------------------------------------------------------------------
122 // MyApp
123 // ----------------------------------------------------------------------------
124
125 IMPLEMENT_APP(MyApp)
126
127 bool MyApp::OnInit()
128 {
129 if ( !wxApp::OnInit() )
130 return false;
131
132 // create and show the main frame
133 MyFrame* frame = new MyFrame;
134
135 frame->Show(true);
136
137 return true;
138 }
139
140 // ----------------------------------------------------------------------------
141 // MyFrame
142 // ----------------------------------------------------------------------------
143
144 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
145 EVT_MENU(PANE_COLLAPSE, MyFrame::OnCollapse)
146 EVT_MENU(PANE_EXPAND, MyFrame::OnExpand)
147 EVT_MENU(PANE_SETLABEL, MyFrame::OnSetLabel)
148 EVT_MENU(PANE_SHOWDLG, MyFrame::OnShowDialog)
149 EVT_MENU(PANE_ABOUT, MyFrame::OnAbout)
150 EVT_MENU(PANE_QUIT, MyFrame::Quit)
151
152 EVT_UPDATE_UI(wxID_ANY, MyFrame::UpdateUI)
153 END_EVENT_TABLE()
154
155 // My frame constructor
156 MyFrame::MyFrame()
157 : wxFrame(NULL, wxID_ANY, _T("wxCollapsiblePane sample"),
158 wxDefaultPosition, wxSize(420, 300),
159 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
160 {
161 #if wxUSE_STATUSBAR
162 CreateStatusBar(2);
163 #endif // wxUSE_STATUSBAR
164
165 // Make a menubar
166 wxMenu *paneMenu = new wxMenu;
167 paneMenu->Append(PANE_COLLAPSE, _T("Collapse\tCtrl-C"));
168 paneMenu->Append(PANE_EXPAND, _T("Expand\tCtrl-E"));
169 paneMenu->AppendSeparator();
170 paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-S"));
171 paneMenu->AppendSeparator();
172 paneMenu->Append(PANE_SHOWDLG, _T("Show dialog...\tCtrl-S"));
173 paneMenu->AppendSeparator();
174 paneMenu->Append(PANE_QUIT);
175
176 wxMenu *helpMenu = new wxMenu;
177 helpMenu->Append(PANE_ABOUT);
178
179 wxMenuBar *menuBar = new wxMenuBar;
180 menuBar->Append(paneMenu, _T("&Pane"));
181 menuBar->Append(helpMenu, _T("&Help"));
182 SetMenuBar(menuBar);
183
184 m_collPane = new wxCollapsiblePane(this, -1, wxT("test!"));
185 wxWindow *win = m_collPane->GetPane();
186
187 new wxStaticText(win, -1, wxT("Static control with absolute coords"), wxPoint(10,2));
188 new wxStaticText(win, -1, wxT("Yet another one!"), wxPoint(30, 30));
189 new wxTextCtrl(win, -1, wxT("You can place anything you like inside a wxCollapsiblePane"),
190 wxPoint(5, 60), wxSize(300, -1));
191 }
192
193 MyFrame::~MyFrame()
194 {
195 }
196
197 // menu command handlers
198
199 void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
200 {
201 Close(true);
202 }
203
204 void MyFrame::OnCollapse(wxCommandEvent& WXUNUSED(event) )
205 {
206 m_collPane->Collapse();
207 }
208
209 void MyFrame::OnExpand(wxCommandEvent& WXUNUSED(event) )
210 {
211 m_collPane->Expand();
212 }
213
214 void MyFrame::OnSetLabel(wxCommandEvent& WXUNUSED(event) )
215 {
216 wxString text = wxGetTextFromUser(wxT("Input the new label"));
217 m_collPane->SetLabel(text);
218 }
219
220 void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event) )
221 {
222 MyDialog dlg(this);
223 dlg.ShowModal();
224 }
225
226 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
227 {
228 wxAboutDialogInfo info;
229 info.SetName(_("wxCollapsiblePane sample"));
230 info.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
231 info.SetCopyright(_T("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
232
233 wxAboutBox(info);
234 }
235
236 void MyFrame::UpdateUI(wxUpdateUIEvent& event)
237 {
238 GetMenuBar()->Enable(PANE_COLLAPSE, !m_collPane->IsCollapsed());
239 GetMenuBar()->Enable(PANE_EXPAND, m_collPane->IsCollapsed());
240 }
241
242
243 // ----------------------------------------------------------------------------
244 // MyDialog
245 // ----------------------------------------------------------------------------
246
247 enum
248 {
249 PANEDLG_TOGGLESTATUS_BTN = wxID_HIGHEST
250 };
251
252 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
253 EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus)
254 EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY, MyDialog::OnPaneChanged)
255 END_EVENT_TABLE()
256
257 MyDialog::MyDialog(wxFrame *parent)
258 : wxDialog(parent, wxID_ANY, wxT("Test dialog"),
259 wxDefaultPosition, wxDefaultSize,
260 wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE )
261 {
262 wxSizer *sz = new wxBoxSizer(wxVERTICAL);
263 sz->Add(new wxStaticText(this, -1,
264 wxT("This dialog allows you to test the wxCollapsiblePane control")),
265 0, wxALL, 5);
266 sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")),
267 1, wxGROW|wxALL, 5);
268
269 m_collPane = new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
270 sz->Add(m_collPane, 0, wxGROW|wxALL, 5);
271 sz->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW|wxALL, 5);
272 sz->AddSpacer(10);
273 sz->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5);
274
275 // now add test controls in the collapsible pane
276 wxWindow *win = m_collPane->GetPane();
277 wxSizer *paneSz = new wxGridSizer(2, 2, 5, 5);
278 paneSz->Add(new wxColourPickerCtrl(win, -1), 1, wxGROW|wxALL, 2);
279 paneSz->Add(new wxFontPickerCtrl(win, -1), 1, wxGROW|wxALL, 2);
280 paneSz->Add(new wxFilePickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2);
281 paneSz->Add(new wxDirPickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2);
282 win->SetSizer(paneSz);
283 paneSz->SetSizeHints(win);
284
285 SetSizer(sz);
286 sz->SetSizeHints(this);
287 }
288
289 void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev))
290 {
291 m_collPane->Collapse(!m_collPane->IsCollapsed());
292 }
293
294 void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent &event)
295 {
296 wxLogDebug(wxT("The pane has just been %s by the user"),
297 event.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));
298 }
299