]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp
wxFoldBar now also horizontal (with API methods renamed to mean length rather than...
[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 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
32 #include "mondrian.xpm"
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // MyApp Class
37 // ----------------------------------------------------------------------------
38
39 class MyApp : public wxApp
40 {
41 public:
42 virtual bool OnInit();
43 };
44
45 // ----------------------------------------------------------------------------
46 // MyAppFrame Class
47 // ----------------------------------------------------------------------------
48
49 class MyAppFrame : public wxFrame
50 {
51 public:
52 MyAppFrame(const wxString& title,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = wxDEFAULT_FRAME_STYLE);
56
57 private:
58 void OnQuit(wxCommandEvent& event);
59 void OnAbout(wxCommandEvent& event);
60 void OnOrientation(wxCommandEvent& event);
61
62 // extra handlers for the bar, to show how it works
63
64 void OnCollapseMe(wxCommandEvent &event);
65 void OnExpandMe(wxCommandEvent &event);
66
67 private:
68 wxMenuBar *CreateMenuBar();
69 void CreateFoldBar(bool vertical = true);
70 wxFoldPanelBar *m_pnl;
71
72 private:
73 DECLARE_EVENT_TABLE()
74 };
75
76 // ----------------------------------------------------------------------------
77 // constants
78 // ----------------------------------------------------------------------------
79
80 enum
81 {
82 // menu items
83 FoldPanelBarTest_Quit = wxID_EXIT,
84 FoldPanelBarTest_About = wxID_ABOUT,
85 ID_COLLAPSEME = wxID_HIGHEST,
86 ID_EXPANDME,
87 FoldPanelBarTest_Horizontal,
88 FoldPanelBarTest_Vertical
89 };
90
91 // ----------------------------------------------------------------------------
92 // event tables and other macros for wxWidgets
93 // ----------------------------------------------------------------------------
94
95 BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
96 EVT_MENU(FoldPanelBarTest_Quit, MyAppFrame::OnQuit)
97 EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout)
98 EVT_MENU(FoldPanelBarTest_Horizontal, MyAppFrame::OnOrientation)
99 EVT_MENU(FoldPanelBarTest_Vertical, MyAppFrame::OnOrientation)
100 EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe)
101 EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe)
102 END_EVENT_TABLE()
103
104 IMPLEMENT_APP(MyApp)
105
106 // ============================================================================
107 // implementation
108 // ============================================================================
109
110 // ----------------------------------------------------------------------------
111 // MyApp Implementation
112 // ----------------------------------------------------------------------------
113
114 bool MyApp::OnInit()
115 {
116 MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
117
118 SetTopWindow(frame);
119
120 frame->Show(true);
121 return true;
122 }
123
124 // ----------------------------------------------------------------------------
125 // MyAppFrame Implementation
126 // ----------------------------------------------------------------------------
127
128 MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
129 : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL)
130 {
131 SetIcon(wxICON(mondrian));
132
133 SetMenuBar(CreateMenuBar());
134
135 CreateFoldBar();
136
137 CreateStatusBar(2);
138 SetStatusText(_T("Welcome to wxWidgets!"));
139 }
140
141 wxMenuBar *MyAppFrame::CreateMenuBar()
142 {
143 wxMenu *menuFile = new wxMenu;
144 menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H"));
145 menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V"));
146 menuFile->AppendSeparator();
147 menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
148
149 wxMenu *helpMenu = new wxMenu;
150 helpMenu->Append(FoldPanelBarTest_About, _T("&About...\tF1"), _T("Show about dialog"));
151
152 wxMenuBar *value = new wxMenuBar();
153 value->Append(menuFile, _T("&File"));
154 value->Append(helpMenu, _T("&Help"));
155
156 return value;
157 }
158
159 void MyAppFrame::CreateFoldBar(bool vertical)
160 {
161 if (vertical)
162 SetSize(200,500);
163 else
164 SetSize(900,200);
165
166 wxFoldPanelBar *bar = new wxFoldPanelBar(this,
167 wxID_ANY,
168 wxDefaultPosition,
169 wxDefaultSize,
170 wxFPB_DEFAULT_STYLE | ( vertical ? wxFPB_VERTICAL : wxFPB_HORIZONTAL ) ,
171 wxFPB_COLLAPSE_TO_BOTTOM);
172
173 wxFoldPanel item = bar->AddFoldPanel(_T("Test me"), false);
174 bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me")));
175
176 item = bar->AddFoldPanel(_T("Test me too!"), true);
177 bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one")));
178 bar->AddFoldPanelSeperator(item);
179 bar->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY));
180
181 bar->AddFoldPanelSeperator(item);
182
183 bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20);
184
185 item = bar->AddFoldPanel(_T("Some opinions ..."), false);
186 bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this")));
187 if( vertical)
188 {
189 // do not add this for horizontal for better presentation
190 bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this")));
191 bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too")));
192 }
193
194 bar->AddFoldPanelSeperator(item);
195
196 bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like")));
197 if( vertical)
198 {
199 // do not add this for horizontal for better presentation
200 bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this")));
201 }
202
203 item = bar->AddFoldPanel(_T("Choose one ..."), false);
204 bar->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment")));
205 bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20);
206
207 if (m_pnl) m_pnl->Destroy();
208
209 m_pnl = bar;
210
211 wxSize size = GetClientSize();
212 m_pnl->SetSize( 0, 0, size.GetWidth(), size.GetHeight() );
213 }
214
215 void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
216 {
217 // true is to force the frame to close
218 Close(true);
219 }
220
221 void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
222 {
223 wxString msg;
224 msg.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n")
225 _T("Welcome to %s"), wxVERSION_STRING);
226
227 wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this);
228 }
229
230 void MyAppFrame::OnOrientation(wxCommandEvent& event)
231 {
232 CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical);
233 }
234
235 void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
236 {
237 wxFoldPanel item = m_pnl->Item(0);
238 m_pnl->Collapse(item);
239 }
240
241 void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
242 {
243 m_pnl->Expand(m_pnl->Item(0));
244 m_pnl->Collapse(m_pnl->Item(1));
245 }