]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp
Fix previous change in case somebody is still using
[wxWidgets.git] / contrib / samples / foldbar / foldpanelbar / foldpanelbartest.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelbartest.cpp
3 // Purpose:
4 // Author: Jorgen Bodde
5 // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6 // : wxWidgets coding standards
7 // Created: 18/06/2004
8 // RCS-ID: $Id$
9 // Copyright: (c) Jorgen Bodde
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
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)
31 #include "sample.xpm"
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:
50 MyAppFrame(const wxString& title,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = wxDEFAULT_FRAME_STYLE);
54
55 private:
56 void OnQuit(wxCommandEvent& event);
57 void OnAbout(wxCommandEvent& event);
58 void OnOrientation(wxCommandEvent& event);
59
60 // extra handlers for the bar, to show how it works
61
62 void OnCollapseMe(wxCommandEvent &event);
63 void OnExpandMe(wxCommandEvent &event);
64
65 private:
66 wxMenuBar *CreateMenuBar();
67 void CreateFoldBar(bool vertical = true);
68 wxFoldPanelBar *m_pnl;
69
70 private:
71 DECLARE_EVENT_TABLE()
72 };
73
74 // ----------------------------------------------------------------------------
75 // constants
76 // ----------------------------------------------------------------------------
77
78 enum
79 {
80 // menu items
81 FoldPanelBarTest_Quit = wxID_EXIT,
82 FoldPanelBarTest_About = wxID_ABOUT,
83 ID_COLLAPSEME = wxID_HIGHEST,
84 ID_EXPANDME,
85 FoldPanelBarTest_Horizontal,
86 FoldPanelBarTest_Vertical
87 };
88
89 // ----------------------------------------------------------------------------
90 // event tables and other macros for wxWidgets
91 // ----------------------------------------------------------------------------
92
93 BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
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)
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 {
114 MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
115
116 SetTopWindow(frame);
117
118 frame->Show(true);
119 return true;
120 }
121
122 // ----------------------------------------------------------------------------
123 // MyAppFrame Implementation
124 // ----------------------------------------------------------------------------
125
126 MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
127 : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL)
128 {
129 SetIcon(wxIcon(sample_xpm));
130
131 SetMenuBar(CreateMenuBar());
132
133 CreateFoldBar();
134
135 CreateStatusBar(2);
136 SetStatusText(_T("Welcome to wxWidgets!"));
137 }
138
139 wxMenuBar *MyAppFrame::CreateMenuBar()
140 {
141 wxMenu *menuFile = new wxMenu;
142 menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H"));
143 menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V"));
144 menuFile->AppendSeparator();
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
150 wxMenuBar *value = new wxMenuBar();
151 value->Append(menuFile, _T("&File"));
152 value->Append(helpMenu, _T("&Help"));
153
154 return value;
155 }
156
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 }
212
213 void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
214 {
215 // true is to force the frame to close
216 Close(true);
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
228 void MyAppFrame::OnOrientation(wxCommandEvent& event)
229 {
230 CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical);
231 }
232
233 void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
234 {
235 wxFoldPanel item = m_pnl->Item(0);
236 m_pnl->Collapse(item);
237 }
238
239 void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
240 {
241 m_pnl->Expand(m_pnl->Item(0));
242 m_pnl->Collapse(m_pnl->Item(1));
243 }