]>
Commit | Line | Data |
---|---|---|
957f5ab7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f857e441 WS |
2 | // Name: foldpanelbartest.cpp |
3 | // Purpose: | |
4 | // Author: Jorgen Bodde | |
7a8d9418 WS |
5 | // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation |
6 | // : wxWidgets coding standards | |
f857e441 WS |
7 | // Created: 18/06/2004 |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Jorgen Bodde | |
957f5ab7 VZ |
10 | // Licence: wxWindows licence |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
957f5ab7 VZ |
23 | #include "wx/foldbar/foldpanelbar.h" |
24 | #include "foldtestpanel.h" | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // resources | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | // the application icon (under Windows and OS/2 it is in resources) | |
c74ca0c0 | 31 | #include "sample.xpm" |
957f5ab7 VZ |
32 | |
33 | // ---------------------------------------------------------------------------- | |
34 | // MyApp Class | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | class MyApp : public wxApp | |
38 | { | |
39 | public: | |
40 | virtual bool OnInit(); | |
41 | }; | |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // MyAppFrame Class | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | class MyAppFrame : public wxFrame | |
48 | { | |
49 | public: | |
7a8d9418 WS |
50 | MyAppFrame(const wxString& title, |
51 | const wxPoint& pos = wxDefaultPosition, | |
52 | const wxSize& size = wxDefaultSize, | |
53 | long style = wxDEFAULT_FRAME_STYLE); | |
957f5ab7 VZ |
54 | |
55 | private: | |
56 | void OnQuit(wxCommandEvent& event); | |
57 | void OnAbout(wxCommandEvent& event); | |
7a8d9418 | 58 | void OnOrientation(wxCommandEvent& event); |
957f5ab7 | 59 | |
f857e441 | 60 | // extra handlers for the bar, to show how it works |
957f5ab7 | 61 | |
f857e441 WS |
62 | void OnCollapseMe(wxCommandEvent &event); |
63 | void OnExpandMe(wxCommandEvent &event); | |
957f5ab7 VZ |
64 | |
65 | private: | |
f857e441 | 66 | wxMenuBar *CreateMenuBar(); |
7a8d9418 WS |
67 | void CreateFoldBar(bool vertical = true); |
68 | wxFoldPanelBar *m_pnl; | |
957f5ab7 VZ |
69 | |
70 | private: | |
71 | DECLARE_EVENT_TABLE() | |
72 | }; | |
73 | ||
74 | // ---------------------------------------------------------------------------- | |
75 | // constants | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | enum | |
79 | { | |
80 | // menu items | |
7a8d9418 WS |
81 | FoldPanelBarTest_Quit = wxID_EXIT, |
82 | FoldPanelBarTest_About = wxID_ABOUT, | |
83 | ID_COLLAPSEME = wxID_HIGHEST, | |
84 | ID_EXPANDME, | |
85 | FoldPanelBarTest_Horizontal, | |
86 | FoldPanelBarTest_Vertical | |
957f5ab7 VZ |
87 | }; |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
0b47cf6f | 90 | // event tables and other macros for wxWidgets |
957f5ab7 VZ |
91 | // ---------------------------------------------------------------------------- |
92 | ||
93 | BEGIN_EVENT_TABLE(MyAppFrame, wxFrame) | |
7a8d9418 WS |
94 | EVT_MENU(FoldPanelBarTest_Quit, MyAppFrame::OnQuit) |
95 | EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout) | |
96 | EVT_MENU(FoldPanelBarTest_Horizontal, MyAppFrame::OnOrientation) | |
97 | EVT_MENU(FoldPanelBarTest_Vertical, MyAppFrame::OnOrientation) | |
98 | EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe) | |
99 | EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe) | |
957f5ab7 VZ |
100 | END_EVENT_TABLE() |
101 | ||
102 | IMPLEMENT_APP(MyApp) | |
103 | ||
104 | // ============================================================================ | |
105 | // implementation | |
106 | // ============================================================================ | |
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // MyApp Implementation | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
112 | bool MyApp::OnInit() | |
113 | { | |
7a8d9418 | 114 | MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application")); |
957f5ab7 | 115 | |
f857e441 | 116 | SetTopWindow(frame); |
957f5ab7 | 117 | |
f857e441 WS |
118 | frame->Show(true); |
119 | return true; | |
957f5ab7 VZ |
120 | } |
121 | ||
122 | // ---------------------------------------------------------------------------- | |
123 | // MyAppFrame Implementation | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
126 | MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) | |
7a8d9418 | 127 | : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL) |
957f5ab7 | 128 | { |
c74ca0c0 | 129 | SetIcon(wxIcon(sample_xpm)); |
957f5ab7 VZ |
130 | |
131 | SetMenuBar(CreateMenuBar()); | |
132 | ||
7a8d9418 WS |
133 | CreateFoldBar(); |
134 | ||
957f5ab7 | 135 | CreateStatusBar(2); |
0b47cf6f | 136 | SetStatusText(_T("Welcome to wxWidgets!")); |
957f5ab7 VZ |
137 | } |
138 | ||
139 | wxMenuBar *MyAppFrame::CreateMenuBar() | |
140 | { | |
957f5ab7 | 141 | wxMenu *menuFile = new wxMenu; |
7a8d9418 WS |
142 | menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H")); |
143 | menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V")); | |
144 | menuFile->AppendSeparator(); | |
957f5ab7 VZ |
145 | menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); |
146 | ||
147 | wxMenu *helpMenu = new wxMenu; | |
148 | helpMenu->Append(FoldPanelBarTest_About, _T("&About...\tF1"), _T("Show about dialog")); | |
149 | ||
f857e441 | 150 | wxMenuBar *value = new wxMenuBar(); |
957f5ab7 VZ |
151 | value->Append(menuFile, _T("&File")); |
152 | value->Append(helpMenu, _T("&Help")); | |
f857e441 | 153 | |
957f5ab7 | 154 | return value; |
f857e441 | 155 | } |
957f5ab7 | 156 | |
7a8d9418 WS |
157 | void MyAppFrame::CreateFoldBar(bool vertical) |
158 | { | |
159 | if (vertical) | |
160 | SetSize(200,500); | |
161 | else | |
162 | SetSize(900,200); | |
163 | ||
164 | wxFoldPanelBar *bar = new wxFoldPanelBar(this, | |
165 | wxID_ANY, | |
166 | wxDefaultPosition, | |
167 | wxDefaultSize, | |
168 | wxFPB_DEFAULT_STYLE | ( vertical ? wxFPB_VERTICAL : wxFPB_HORIZONTAL ) , | |
169 | wxFPB_COLLAPSE_TO_BOTTOM); | |
170 | ||
171 | wxFoldPanel item = bar->AddFoldPanel(_T("Test me"), false); | |
172 | bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me"))); | |
173 | ||
174 | item = bar->AddFoldPanel(_T("Test me too!"), true); | |
175 | bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one"))); | |
176 | bar->AddFoldPanelSeperator(item); | |
177 | bar->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY)); | |
178 | ||
179 | bar->AddFoldPanelSeperator(item); | |
180 | ||
181 | bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20); | |
182 | ||
183 | item = bar->AddFoldPanel(_T("Some opinions ..."), false); | |
184 | bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this"))); | |
185 | if( vertical) | |
186 | { | |
187 | // do not add this for horizontal for better presentation | |
188 | bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this"))); | |
189 | bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too"))); | |
190 | } | |
191 | ||
192 | bar->AddFoldPanelSeperator(item); | |
193 | ||
194 | bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like"))); | |
195 | if( vertical) | |
196 | { | |
197 | // do not add this for horizontal for better presentation | |
198 | bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this"))); | |
199 | } | |
200 | ||
201 | item = bar->AddFoldPanel(_T("Choose one ..."), false); | |
202 | bar->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment"))); | |
203 | bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20); | |
204 | ||
205 | if (m_pnl) m_pnl->Destroy(); | |
206 | ||
207 | m_pnl = bar; | |
208 | ||
209 | wxSize size = GetClientSize(); | |
210 | m_pnl->SetSize( 0, 0, size.GetWidth(), size.GetHeight() ); | |
211 | } | |
957f5ab7 VZ |
212 | |
213 | void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
214 | { | |
f857e441 WS |
215 | // true is to force the frame to close |
216 | Close(true); | |
957f5ab7 VZ |
217 | } |
218 | ||
219 | void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
220 | { | |
221 | wxString msg; | |
222 | msg.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n") | |
223 | _T("Welcome to %s"), wxVERSION_STRING); | |
224 | ||
225 | wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this); | |
226 | } | |
227 | ||
7a8d9418 WS |
228 | void MyAppFrame::OnOrientation(wxCommandEvent& event) |
229 | { | |
230 | CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical); | |
231 | } | |
232 | ||
f857e441 | 233 | void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event)) |
957f5ab7 | 234 | { |
7a8d9418 WS |
235 | wxFoldPanel item = m_pnl->Item(0); |
236 | m_pnl->Collapse(item); | |
957f5ab7 VZ |
237 | } |
238 | ||
f857e441 | 239 | void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event)) |
957f5ab7 | 240 | { |
7a8d9418 WS |
241 | m_pnl->Expand(m_pnl->Item(0)); |
242 | m_pnl->Collapse(m_pnl->Item(1)); | |
957f5ab7 | 243 | } |