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