]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp
Compile Int<->Hex functions only when necessary (warning fix).
[wxWidgets.git] / contrib / samples / foldbar / foldpanelbar / foldpanelbartest.cpp
CommitLineData
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)
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
39class MyApp : public wxApp
40{
41public:
42 virtual bool OnInit();
43};
44
45// ----------------------------------------------------------------------------
46// MyAppFrame Class
47// ----------------------------------------------------------------------------
48
49class MyAppFrame : public wxFrame
50{
51public:
7a8d9418
WS
52 MyAppFrame(const wxString& title,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = wxDEFAULT_FRAME_STYLE);
957f5ab7
VZ
56
57private:
58 void OnQuit(wxCommandEvent& event);
59 void OnAbout(wxCommandEvent& event);
7a8d9418 60 void OnOrientation(wxCommandEvent& event);
957f5ab7 61
f857e441 62 // extra handlers for the bar, to show how it works
957f5ab7 63
f857e441
WS
64 void OnCollapseMe(wxCommandEvent &event);
65 void OnExpandMe(wxCommandEvent &event);
957f5ab7
VZ
66
67private:
f857e441 68 wxMenuBar *CreateMenuBar();
7a8d9418
WS
69 void CreateFoldBar(bool vertical = true);
70 wxFoldPanelBar *m_pnl;
957f5ab7
VZ
71
72private:
73 DECLARE_EVENT_TABLE()
74};
75
76// ----------------------------------------------------------------------------
77// constants
78// ----------------------------------------------------------------------------
79
80enum
81{
82 // menu items
7a8d9418
WS
83 FoldPanelBarTest_Quit = wxID_EXIT,
84 FoldPanelBarTest_About = wxID_ABOUT,
85 ID_COLLAPSEME = wxID_HIGHEST,
86 ID_EXPANDME,
87 FoldPanelBarTest_Horizontal,
88 FoldPanelBarTest_Vertical
957f5ab7
VZ
89};
90
91// ----------------------------------------------------------------------------
0b47cf6f 92// event tables and other macros for wxWidgets
957f5ab7
VZ
93// ----------------------------------------------------------------------------
94
95BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
7a8d9418
WS
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)
957f5ab7
VZ
102END_EVENT_TABLE()
103
104IMPLEMENT_APP(MyApp)
105
106// ============================================================================
107// implementation
108// ============================================================================
109
110// ----------------------------------------------------------------------------
111// MyApp Implementation
112// ----------------------------------------------------------------------------
113
114bool MyApp::OnInit()
115{
7a8d9418 116 MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
957f5ab7 117
f857e441 118 SetTopWindow(frame);
957f5ab7 119
f857e441
WS
120 frame->Show(true);
121 return true;
957f5ab7
VZ
122}
123
124// ----------------------------------------------------------------------------
125// MyAppFrame Implementation
126// ----------------------------------------------------------------------------
127
128MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
7a8d9418 129 : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL)
957f5ab7
VZ
130{
131 SetIcon(wxICON(mondrian));
132
133 SetMenuBar(CreateMenuBar());
134
7a8d9418
WS
135 CreateFoldBar();
136
957f5ab7 137 CreateStatusBar(2);
0b47cf6f 138 SetStatusText(_T("Welcome to wxWidgets!"));
957f5ab7
VZ
139}
140
141wxMenuBar *MyAppFrame::CreateMenuBar()
142{
957f5ab7 143 wxMenu *menuFile = new wxMenu;
7a8d9418
WS
144 menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H"));
145 menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V"));
146 menuFile->AppendSeparator();
957f5ab7
VZ
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
f857e441 152 wxMenuBar *value = new wxMenuBar();
957f5ab7
VZ
153 value->Append(menuFile, _T("&File"));
154 value->Append(helpMenu, _T("&Help"));
f857e441 155
957f5ab7 156 return value;
f857e441 157}
957f5ab7 158
7a8d9418
WS
159void 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}
957f5ab7
VZ
214
215void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
216{
f857e441
WS
217 // true is to force the frame to close
218 Close(true);
957f5ab7
VZ
219}
220
221void 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
7a8d9418
WS
230void MyAppFrame::OnOrientation(wxCommandEvent& event)
231{
232 CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical);
233}
234
f857e441 235void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
957f5ab7 236{
7a8d9418
WS
237 wxFoldPanel item = m_pnl->Item(0);
238 m_pnl->Collapse(item);
957f5ab7
VZ
239}
240
f857e441 241void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
957f5ab7 242{
7a8d9418
WS
243 m_pnl->Expand(m_pnl->Item(0));
244 m_pnl->Collapse(m_pnl->Item(1));
957f5ab7 245}