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