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