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)
31 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
32 #include "mondrian.xpm"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class MyApp
: public wxApp
42 virtual bool OnInit();
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 class MyAppFrame
: public wxFrame
52 MyAppFrame(const wxString
& title
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
55 long style
= wxDEFAULT_FRAME_STYLE
);
58 void OnQuit(wxCommandEvent
& event
);
59 void OnAbout(wxCommandEvent
& event
);
60 void OnOrientation(wxCommandEvent
& event
);
62 // extra handlers for the bar, to show how it works
64 void OnCollapseMe(wxCommandEvent
&event
);
65 void OnExpandMe(wxCommandEvent
&event
);
68 wxMenuBar
*CreateMenuBar();
69 void CreateFoldBar(bool vertical
= true);
70 wxFoldPanelBar
*m_pnl
;
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
83 FoldPanelBarTest_Quit
= wxID_EXIT
,
84 FoldPanelBarTest_About
= wxID_ABOUT
,
85 ID_COLLAPSEME
= wxID_HIGHEST
,
87 FoldPanelBarTest_Horizontal
,
88 FoldPanelBarTest_Vertical
91 // ----------------------------------------------------------------------------
92 // event tables and other macros for wxWidgets
93 // ----------------------------------------------------------------------------
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
)
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
111 // MyApp Implementation
112 // ----------------------------------------------------------------------------
116 MyAppFrame
*frame
= new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
124 // ----------------------------------------------------------------------------
125 // MyAppFrame Implementation
126 // ----------------------------------------------------------------------------
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
)
131 SetIcon(wxICON(mondrian
));
133 SetMenuBar(CreateMenuBar());
138 SetStatusText(_T("Welcome to wxWidgets!"));
141 wxMenuBar
*MyAppFrame::CreateMenuBar()
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"));
149 wxMenu
*helpMenu
= new wxMenu
;
150 helpMenu
->Append(FoldPanelBarTest_About
, _T("&About...\tF1"), _T("Show about dialog"));
152 wxMenuBar
*value
= new wxMenuBar();
153 value
->Append(menuFile
, _T("&File"));
154 value
->Append(helpMenu
, _T("&Help"));
159 void MyAppFrame::CreateFoldBar(bool vertical
)
166 wxFoldPanelBar
*bar
= new wxFoldPanelBar(this,
170 wxFPB_DEFAULT_STYLE
| ( vertical
? wxFPB_VERTICAL
: wxFPB_HORIZONTAL
) ,
171 wxFPB_COLLAPSE_TO_BOTTOM
);
173 wxFoldPanel item
= bar
->AddFoldPanel(_T("Test me"), false);
174 bar
->AddFoldPanelWindow(item
, new wxButton(item
.GetParent(), ID_COLLAPSEME
, _T("Collapse Me")));
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
));
181 bar
->AddFoldPanelSeperator(item
);
183 bar
->AddFoldPanelWindow(item
, new wxTextCtrl(item
.GetParent(), wxID_ANY
, _T("Comment")), wxFPB_ALIGN_WIDTH
, wxFPB_DEFAULT_SPACING
, 20);
185 item
= bar
->AddFoldPanel(_T("Some opinions ..."), false);
186 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("I like this")));
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")));
194 bar
->AddFoldPanelSeperator(item
);
196 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("Check this too if you like")));
199 // do not add this for horizontal for better presentation
200 bar
->AddFoldPanelWindow(item
, new wxCheckBox(item
.GetParent(), wxID_ANY
, _T("What about this")));
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);
207 if (m_pnl
) m_pnl
->Destroy();
211 wxSize size
= GetClientSize();
212 m_pnl
->SetSize( 0, 0, size
.GetWidth(), size
.GetHeight() );
215 void MyAppFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
217 // true is to force the frame to close
221 void MyAppFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
224 msg
.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n")
225 _T("Welcome to %s"), wxVERSION_STRING
);
227 wxMessageBox(msg
, _T("About FoldPanelBarTest"), wxOK
| wxICON_INFORMATION
, this);
230 void MyAppFrame::OnOrientation(wxCommandEvent
& event
)
232 CreateFoldBar(event
.GetId()==FoldPanelBarTest_Vertical
);
235 void MyAppFrame::OnCollapseMe(wxCommandEvent
&WXUNUSED(event
))
237 wxFoldPanel item
= m_pnl
->Item(0);
238 m_pnl
->Collapse(item
);
241 void MyAppFrame::OnExpandMe(wxCommandEvent
&WXUNUSED(event
))
243 m_pnl
->Expand(m_pnl
->Item(0));
244 m_pnl
->Collapse(m_pnl
->Item(1));