1 /////////////////////////////////////////////////////////////////////////////
2 // Name: foldpanelbartest.cpp
4 // Author: Jorgen Bodde
5 // Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
6 // : wxWidgets coding standards
9 // Copyright: (c) Jorgen Bodde
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/wxprec.h"
23 #include "wx/foldbar/foldpanelbar.h"
24 #include "foldtestpanel.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // the application icon (under Windows and OS/2 it is in resources)
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class MyApp
: public wxApp
40 virtual bool OnInit();
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 class MyAppFrame
: public wxFrame
50 MyAppFrame(const wxString
& title
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
53 long style
= wxDEFAULT_FRAME_STYLE
);
56 void OnQuit(wxCommandEvent
& event
);
57 void OnAbout(wxCommandEvent
& event
);
58 void OnOrientation(wxCommandEvent
& event
);
60 // extra handlers for the bar, to show how it works
62 void OnCollapseMe(wxCommandEvent
&event
);
63 void OnExpandMe(wxCommandEvent
&event
);
66 wxMenuBar
*CreateMenuBar();
67 void CreateFoldBar(bool vertical
= true);
68 wxFoldPanelBar
*m_pnl
;
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
81 FoldPanelBarTest_Quit
= wxID_EXIT
,
82 FoldPanelBarTest_About
= wxID_ABOUT
,
83 ID_COLLAPSEME
= wxID_HIGHEST
,
85 FoldPanelBarTest_Horizontal
,
86 FoldPanelBarTest_Vertical
89 // ----------------------------------------------------------------------------
90 // event tables and other macros for wxWidgets
91 // ----------------------------------------------------------------------------
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
)
104 // ============================================================================
106 // ============================================================================
108 // ----------------------------------------------------------------------------
109 // MyApp Implementation
110 // ----------------------------------------------------------------------------
114 MyAppFrame
*frame
= new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
122 // ----------------------------------------------------------------------------
123 // MyAppFrame Implementation
124 // ----------------------------------------------------------------------------
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
)
129 SetIcon(wxIcon(sample_xpm
));
131 SetMenuBar(CreateMenuBar());
136 SetStatusText(_T("Welcome to wxWidgets!"));
139 wxMenuBar
*MyAppFrame::CreateMenuBar()
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"));
147 wxMenu
*helpMenu
= new wxMenu
;
148 helpMenu
->Append(FoldPanelBarTest_About
, _T("&About...\tF1"), _T("Show about dialog"));
150 wxMenuBar
*value
= new wxMenuBar();
151 value
->Append(menuFile
, _T("&File"));
152 value
->Append(helpMenu
, _T("&Help"));
157 void MyAppFrame::CreateFoldBar(bool vertical
)
164 wxFoldPanelBar
*bar
= new wxFoldPanelBar(this,
168 wxFPB_DEFAULT_STYLE
| ( vertical
? wxFPB_VERTICAL
: wxFPB_HORIZONTAL
) ,
169 wxFPB_COLLAPSE_TO_BOTTOM
);
171 wxFoldPanel item
= bar
->AddFoldPanel(_T("Test me"), false);
172 bar
->AddFoldPanelWindow(item
, new wxButton(item
.GetParent(), ID_COLLAPSEME
, _T("Collapse Me")));
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
));
179 bar
->AddFoldPanelSeperator(item
);
181 bar
->AddFoldPanelWindow(item
, new wxTextCtrl(item
.GetParent(), wxID_ANY
, _T("Comment")), wxFPB_ALIGN_WIDTH
, wxFPB_DEFAULT_SPACING
, 20);
183 item
= bar
->AddFoldPanel(_T("Some opinions ..."), false);
184 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("I like this")));
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")));
192 bar
->AddFoldPanelSeperator(item
);
194 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("Check this too if you like")));
197 // do not add this for horizontal for better presentation
198 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("What about this")));
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);
205 if (m_pnl
) m_pnl
->Destroy();
209 wxSize size
= GetClientSize();
210 m_pnl
->SetSize( 0, 0, size
.GetWidth(), size
.GetHeight() );
213 void MyAppFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
215 // true is to force the frame to close
219 void MyAppFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
222 msg
.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n")
223 _T("Welcome to %s"), wxVERSION_STRING
);
225 wxMessageBox(msg
, _T("About FoldPanelBarTest"), wxOK
| wxICON_INFORMATION
, this);
228 void MyAppFrame::OnOrientation(wxCommandEvent
& event
)
230 CreateFoldBar(event
.GetId()==FoldPanelBarTest_Vertical
);
233 void MyAppFrame::OnCollapseMe(wxCommandEvent
&WXUNUSED(event
))
235 wxFoldPanel item
= m_pnl
->Item(0);
236 m_pnl
->Collapse(item
);
239 void MyAppFrame::OnExpandMe(wxCommandEvent
&WXUNUSED(event
))
241 m_pnl
->Expand(m_pnl
->Item(0));
242 m_pnl
->Collapse(m_pnl
->Item(1));