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