]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp
added foldbar contrib
[wxWidgets.git] / contrib / samples / foldbar / foldpanelbar / foldpanelbartest.cpp
1
2 /////////////////////////////////////////////////////////////////////////////
3 // Name: FoldPanelBarTest.cpp
4 // Purpose: FoldPanelBarTest Test application
5 // Created: 06/18/04
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #include "wx/wxprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14
15 #ifndef WX_PRECOMP
16 #include "wx/wx.h"
17 #endif
18
19 enum
20 {
21 ID_COLLAPSEME = 10000,
22 ID_EXPANDME
23 };
24
25 #include "wx/foldbar/foldpanelbar.h"
26 #include "foldtestpanel.h"
27
28 // ----------------------------------------------------------------------------
29 // resources
30 // ----------------------------------------------------------------------------
31
32 // the application icon (under Windows and OS/2 it is in resources)
33 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
34 #include "mondrian.xpm"
35 #endif
36
37 // ----------------------------------------------------------------------------
38 // MyApp Class
39 // ----------------------------------------------------------------------------
40
41 class MyApp : public wxApp
42 {
43 public:
44 virtual bool OnInit();
45 };
46
47 // ----------------------------------------------------------------------------
48 // MyAppFrame Class
49 // ----------------------------------------------------------------------------
50
51 class MyAppFrame : public wxFrame
52 {
53 public:
54 MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
55 long style = wxDEFAULT_FRAME_STYLE);
56
57 private:
58 void OnQuit(wxCommandEvent& event);
59 void OnAbout(wxCommandEvent& event);
60
61 // extra handlers for the bar, to show how it works
62
63 void OnCollapseMe(wxCommandEvent &event);
64 void OnExpandMe(wxCommandEvent &event);
65
66 private:
67 wxMenuBar *CreateMenuBar();
68 wxFoldPanelBar *_pnl;
69
70 private:
71 DECLARE_EVENT_TABLE()
72 };
73
74 // ----------------------------------------------------------------------------
75 // constants
76 // ----------------------------------------------------------------------------
77
78 enum
79 {
80 // menu items
81 FoldPanelBarTest_Quit = 1,
82 FoldPanelBarTest_About = wxID_ABOUT
83 };
84
85 // ----------------------------------------------------------------------------
86 // event tables and other macros for wxWindows
87 // ----------------------------------------------------------------------------
88
89 BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
90 EVT_MENU(FoldPanelBarTest_Quit, MyAppFrame::OnQuit)
91 EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout)
92 EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe)
93 EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe)
94 END_EVENT_TABLE()
95
96 IMPLEMENT_APP(MyApp)
97
98 // ============================================================================
99 // implementation
100 // ============================================================================
101
102 // ----------------------------------------------------------------------------
103 // MyApp Implementation
104 // ----------------------------------------------------------------------------
105
106 bool MyApp::OnInit()
107 {
108 MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWindows Test Application"),
109 wxPoint(50, 50), wxSize(200, 500));
110
111 SetTopWindow(frame);
112
113 frame->Show(TRUE);
114 return TRUE;
115 }
116
117 // ----------------------------------------------------------------------------
118 // MyAppFrame Implementation
119 // ----------------------------------------------------------------------------
120
121 MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
122 : wxFrame(NULL, -1, title, pos, size, style)
123 {
124 SetIcon(wxICON(mondrian));
125
126 SetMenuBar(CreateMenuBar());
127
128 CreateStatusBar(2);
129 SetStatusText(_T("Welcome to wxWindows!"));
130
131 _pnl = new wxFoldPanelBar(this, -1, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM);
132
133 wxFoldPanel item = _pnl->AddFoldPanel("Test me", false);
134 _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, "Collapse Me"));
135
136 item = _pnl->AddFoldPanel("Test me too!", true);
137 _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, "Expand first one"));
138 _pnl->AddFoldPanelSeperator(item);
139 _pnl->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), -1));
140
141 _pnl->AddFoldPanelSeperator(item);
142
143 _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comment"), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20);
144
145 item = _pnl->AddFoldPanel("Some opinions ...", false);
146 _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "I like this"));
147 _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "And also this"));
148 _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "And gimme this too"));
149
150 _pnl->AddFoldPanelSeperator(item);
151
152 _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "Check this too if you like"));
153 _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), -1, "What about this"));
154
155
156 item = _pnl->AddFoldPanel("Choose one ...", false);
157 _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), -1, "Enter your comment"));
158 _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), -1, "Comment"), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20);
159
160 }
161
162 wxMenuBar *MyAppFrame::CreateMenuBar()
163 {
164 wxMenuBar *value = 0;
165
166 wxMenu *menuFile = new wxMenu;
167 menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
168
169 wxMenu *helpMenu = new wxMenu;
170 helpMenu->Append(FoldPanelBarTest_About, _T("&About...\tF1"), _T("Show about dialog"));
171
172 value = new wxMenuBar();
173 value->Append(menuFile, _T("&File"));
174 value->Append(helpMenu, _T("&Help"));
175
176 return value;
177 }
178
179 // event handlers
180
181
182
183 void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
184 {
185 // TRUE is to force the frame to close
186 Close(TRUE);
187 }
188
189 void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
190 {
191 wxString msg;
192 msg.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n")
193 _T("Welcome to %s"), wxVERSION_STRING);
194
195 wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this);
196 }
197
198 void MyAppFrame::OnCollapseMe(wxCommandEvent &event)
199 {
200 wxFoldPanel item = _pnl->Item(0);
201 _pnl->Collapse(item);
202 }
203
204 void MyAppFrame::OnExpandMe(wxCommandEvent &event)
205 {
206 _pnl->Expand(_pnl->Item(0));
207 _pnl->Collapse(_pnl->Item(1));
208 }