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