]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/samples/foldbar/foldpanelbar/foldpanelbartest.cpp
Rebake after MSLU and other changes
[wxWidgets.git] / contrib / samples / foldbar / foldpanelbar / foldpanelbartest.cpp
index cd615c7cf69c2763b7ed9f032eaa4d93449a2ba1..2a17ea90f560ede0a318ca4f6d32b90ba357f699 100644 (file)
@@ -2,7 +2,8 @@
 // Name:        foldpanelbartest.cpp
 // Purpose:
 // Author:      Jorgen Bodde
-// Modified by:
+// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
+//                               : wxWidgets coding standards
 // Created:     18/06/2004
 // RCS-ID:      $Id$
 // Copyright:   (c) Jorgen Bodde
     #include "wx/wx.h"
 #endif
 
-enum
-{
-    ID_COLLAPSEME = 10000,
-    ID_EXPANDME
-};
-
 #include "wx/foldbar/foldpanelbar.h"
 #include "foldtestpanel.h"
 
@@ -33,9 +28,7 @@ enum
 // ----------------------------------------------------------------------------
 
 // the application icon (under Windows and OS/2 it is in resources)
-#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
-    #include "mondrian.xpm"
-#endif
+#include "sample.xpm"
 
 // ----------------------------------------------------------------------------
 // MyApp Class
@@ -54,12 +47,15 @@ public:
 class MyAppFrame : public wxFrame
 {
 public:
-    MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
-            long style = wxDEFAULT_FRAME_STYLE);
+    MyAppFrame(const wxString& title,
+               const wxPoint& pos = wxDefaultPosition,
+               const wxSize& size = wxDefaultSize,
+               long style = wxDEFAULT_FRAME_STYLE);
 
 private:
     void OnQuit(wxCommandEvent& event);
     void OnAbout(wxCommandEvent& event);
+    void OnOrientation(wxCommandEvent& event);
 
     // extra handlers for the bar, to show how it works
 
@@ -68,7 +64,8 @@ private:
 
 private:
     wxMenuBar *CreateMenuBar();
-    wxFoldPanelBar *_pnl;
+    void CreateFoldBar(bool vertical = true);
+    wxFoldPanelBar *m_pnl;
 
 private:
     DECLARE_EVENT_TABLE()
@@ -81,8 +78,12 @@ private:
 enum
 {
     // menu items
-    FoldPanelBarTest_Quit = 1,
-    FoldPanelBarTest_About = wxID_ABOUT
+    FoldPanelBarTest_Quit = wxID_EXIT,
+    FoldPanelBarTest_About = wxID_ABOUT,
+    ID_COLLAPSEME = wxID_HIGHEST,
+    ID_EXPANDME,
+    FoldPanelBarTest_Horizontal,
+    FoldPanelBarTest_Vertical
 };
 
 // ----------------------------------------------------------------------------
@@ -90,10 +91,12 @@ enum
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
-    EVT_MENU(FoldPanelBarTest_Quit,  MyAppFrame::OnQuit)
-    EVT_MENU(FoldPanelBarTest_About, MyAppFrame::OnAbout)
-    EVT_BUTTON(ID_COLLAPSEME, MyAppFrame::OnCollapseMe)
-    EVT_BUTTON(ID_EXPANDME, MyAppFrame::OnExpandMe)
+    EVT_MENU(FoldPanelBarTest_Quit,       MyAppFrame::OnQuit)
+    EVT_MENU(FoldPanelBarTest_About,      MyAppFrame::OnAbout)
+    EVT_MENU(FoldPanelBarTest_Horizontal, MyAppFrame::OnOrientation)
+    EVT_MENU(FoldPanelBarTest_Vertical,   MyAppFrame::OnOrientation)
+    EVT_BUTTON(ID_COLLAPSEME,             MyAppFrame::OnCollapseMe)
+    EVT_BUTTON(ID_EXPANDME,               MyAppFrame::OnExpandMe)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
@@ -108,8 +111,7 @@ IMPLEMENT_APP(MyApp)
 
 bool MyApp::OnInit()
 {
-    MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"),
-                                 wxPoint(50, 50), wxSize(200, 500));
+    MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
 
     SetTopWindow(frame);
 
@@ -122,49 +124,24 @@ bool MyApp::OnInit()
 // ----------------------------------------------------------------------------
 
 MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
-       : wxFrame(NULL, wxID_ANY, title, pos, size, style)
+       : wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL)
 {
-    SetIcon(wxICON(mondrian));
+    SetIcon(wxIcon(sample_xpm));
 
     SetMenuBar(CreateMenuBar());
 
+    CreateFoldBar();
+
     CreateStatusBar(2);
     SetStatusText(_T("Welcome to wxWidgets!"));
-
-    _pnl = new wxFoldPanelBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, wxFPB_COLLAPSE_TO_BOTTOM);
-
-    wxFoldPanel item = _pnl->AddFoldPanel(_T("Test me"), false);
-    _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me")));
-
-    item = _pnl->AddFoldPanel(_T("Test me too!"), true);
-    _pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one")));
-    _pnl->AddFoldPanelSeperator(item);
-    _pnl->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY));
-
-    _pnl->AddFoldPanelSeperator(item);
-
-    _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20);
-
-    item = _pnl->AddFoldPanel(_T("Some opinions ..."), false);
-    _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this")));
-    _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this")));
-    _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too")));
-
-    _pnl->AddFoldPanelSeperator(item);
-
-    _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like")));
-    _pnl->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this")));
-
-
-    item = _pnl->AddFoldPanel(_T("Choose one ..."), false);
-    _pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment")));
-    _pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_YSPACING, 20);
-
 }
 
 wxMenuBar *MyAppFrame::CreateMenuBar()
 {
     wxMenu *menuFile = new wxMenu;
+    menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H"));
+    menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V"));
+    menuFile->AppendSeparator();
     menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
 
     wxMenu *helpMenu = new wxMenu;
@@ -177,9 +154,61 @@ wxMenuBar *MyAppFrame::CreateMenuBar()
     return value;
 }
 
-// event handlers
-
-
+void MyAppFrame::CreateFoldBar(bool vertical)
+{
+    if (vertical)
+        SetSize(200,500);
+    else
+        SetSize(900,200);
+
+    wxFoldPanelBar *bar = new wxFoldPanelBar(this,
+                                             wxID_ANY,
+                                             wxDefaultPosition,
+                                             wxDefaultSize,
+                                             wxFPB_DEFAULT_STYLE | ( vertical ? wxFPB_VERTICAL : wxFPB_HORIZONTAL ) ,
+                                             wxFPB_COLLAPSE_TO_BOTTOM);
+
+    wxFoldPanel item = bar->AddFoldPanel(_T("Test me"), false);
+    bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse Me")));
+
+    item = bar->AddFoldPanel(_T("Test me too!"), true);
+    bar->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_EXPANDME, _T("Expand first one")));
+    bar->AddFoldPanelSeperator(item);
+    bar->AddFoldPanelWindow(item, new FoldTestPanel(item.GetParent(), wxID_ANY));
+
+    bar->AddFoldPanelSeperator(item);
+
+    bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20);
+
+    item = bar->AddFoldPanel(_T("Some opinions ..."), false);
+    bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("I like this")));
+    if( vertical)
+    {
+        // do not add this for horizontal for better presentation
+        bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And also this")));
+        bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("And gimme this too")));
+    }
+
+    bar->AddFoldPanelSeperator(item);
+
+    bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("Check this too if you like")));
+    if( vertical)
+    {
+        // do not add this for horizontal for better presentation
+        bar->AddFoldPanelWindow(item, new wxCheckBox(item.GetParent(), wxID_ANY, _T("What about this")));
+    }
+
+    item = bar->AddFoldPanel(_T("Choose one ..."), false);
+    bar->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter your comment")));
+    bar->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comment")), wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 20);
+
+    if (m_pnl) m_pnl->Destroy();
+
+    m_pnl = bar;
+
+    wxSize size = GetClientSize();
+    m_pnl->SetSize( 0, 0, size.GetWidth(), size.GetHeight() );
+}
 
 void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 {
@@ -196,14 +225,19 @@ void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
     wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this);
 }
 
+void MyAppFrame::OnOrientation(wxCommandEvent& event)
+{
+    CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical);
+}
+
 void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
 {
-    wxFoldPanel item = _pnl->Item(0);
-    _pnl->Collapse(item);
+    wxFoldPanel item = m_pnl->Item(0);
+    m_pnl->Collapse(item);
 }
 
 void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
 {
-    _pnl->Expand(_pnl->Item(0));
-    _pnl->Collapse(_pnl->Item(1));
+    m_pnl->Expand(m_pnl->Item(0));
+    m_pnl->Collapse(m_pnl->Item(1));
 }