2004-08-03 07:18:36 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2004-08-03 10:39:09 -04:00
|
|
|
// Name: foldpanelbartest.cpp
|
|
|
|
// Purpose:
|
|
|
|
// Author: Jorgen Bodde
|
2004-12-10 07:01:04 -05:00
|
|
|
// Modified by: ABX - 19/12/2004 : possibility of horizontal orientation
|
|
|
|
// : wxWidgets coding standards
|
2004-08-03 10:39:09 -04:00
|
|
|
// Created: 18/06/2004
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Jorgen Bodde
|
2004-08-03 07:18:36 -04:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/foldbar/foldpanelbar.h"
|
|
|
|
#include "foldtestpanel.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp Class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyAppFrame Class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyAppFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2004-12-10 07:01:04 -05:00
|
|
|
MyAppFrame(const wxString& title,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2004-12-10 07:01:04 -05:00
|
|
|
void OnOrientation(wxCommandEvent& event);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
// extra handlers for the bar, to show how it works
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
void OnCollapseMe(wxCommandEvent &event);
|
|
|
|
void OnExpandMe(wxCommandEvent &event);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
private:
|
2004-08-03 10:39:09 -04:00
|
|
|
wxMenuBar *CreateMenuBar();
|
2004-12-10 07:01:04 -05:00
|
|
|
void CreateFoldBar(bool vertical = true);
|
|
|
|
wxFoldPanelBar *m_pnl;
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
2004-12-10 07:01:04 -05:00
|
|
|
FoldPanelBarTest_Quit = wxID_EXIT,
|
|
|
|
FoldPanelBarTest_About = wxID_ABOUT,
|
|
|
|
ID_COLLAPSEME = wxID_HIGHEST,
|
|
|
|
ID_EXPANDME,
|
|
|
|
FoldPanelBarTest_Horizontal,
|
|
|
|
FoldPanelBarTest_Vertical
|
2004-08-03 07:18:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-11-07 14:20:20 -05:00
|
|
|
// event tables and other macros for wxWidgets
|
2004-08-03 07:18:36 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyAppFrame, wxFrame)
|
2004-12-10 07:01:04 -05:00
|
|
|
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)
|
2004-08-03 07:18:36 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp Implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2004-12-10 07:01:04 -05:00
|
|
|
MyAppFrame *frame = new MyAppFrame(_T("FoldPanelBarTest wxWidgets Test Application"));
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
SetTopWindow(frame);
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
frame->Show(true);
|
|
|
|
return true;
|
2004-08-03 07:18:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyAppFrame Implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyAppFrame::MyAppFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
|
2004-12-10 07:01:04 -05:00
|
|
|
: wxFrame(NULL, wxID_ANY, title, pos, size, style), m_pnl(NULL)
|
2004-08-03 07:18:36 -04:00
|
|
|
{
|
|
|
|
SetIcon(wxICON(mondrian));
|
|
|
|
|
|
|
|
SetMenuBar(CreateMenuBar());
|
|
|
|
|
2004-12-10 07:01:04 -05:00
|
|
|
CreateFoldBar();
|
|
|
|
|
2004-08-03 07:18:36 -04:00
|
|
|
CreateStatusBar(2);
|
2004-11-07 14:20:20 -05:00
|
|
|
SetStatusText(_T("Welcome to wxWidgets!"));
|
2004-08-03 07:18:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wxMenuBar *MyAppFrame::CreateMenuBar()
|
|
|
|
{
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
2004-12-10 07:01:04 -05:00
|
|
|
menuFile->Append(FoldPanelBarTest_Horizontal, _T("&Horizontal\tAlt-H"));
|
|
|
|
menuFile->Append(FoldPanelBarTest_Vertical, _T("&Vertical\tAlt-V"));
|
|
|
|
menuFile->AppendSeparator();
|
2004-08-03 07:18:36 -04:00
|
|
|
menuFile->Append(FoldPanelBarTest_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
|
|
|
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(FoldPanelBarTest_About, _T("&About...\tF1"), _T("Show about dialog"));
|
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
wxMenuBar *value = new wxMenuBar();
|
2004-08-03 07:18:36 -04:00
|
|
|
value->Append(menuFile, _T("&File"));
|
|
|
|
value->Append(helpMenu, _T("&Help"));
|
2004-08-03 10:39:09 -04:00
|
|
|
|
2004-08-03 07:18:36 -04:00
|
|
|
return value;
|
2004-08-03 10:39:09 -04:00
|
|
|
}
|
2004-08-03 07:18:36 -04:00
|
|
|
|
2004-12-10 07:01:04 -05:00
|
|
|
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() );
|
|
|
|
}
|
2004-08-03 07:18:36 -04:00
|
|
|
|
|
|
|
void MyAppFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-08-03 10:39:09 -04:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2004-08-03 07:18:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyAppFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _T("This is the About dialog of the FoldPanelBarTest application.\n")
|
|
|
|
_T("Welcome to %s"), wxVERSION_STRING);
|
|
|
|
|
|
|
|
wxMessageBox(msg, _T("About FoldPanelBarTest"), wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
2004-12-10 07:01:04 -05:00
|
|
|
void MyAppFrame::OnOrientation(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
CreateFoldBar(event.GetId()==FoldPanelBarTest_Vertical);
|
|
|
|
}
|
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
void MyAppFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
|
2004-08-03 07:18:36 -04:00
|
|
|
{
|
2004-12-10 07:01:04 -05:00
|
|
|
wxFoldPanel item = m_pnl->Item(0);
|
|
|
|
m_pnl->Collapse(item);
|
2004-08-03 07:18:36 -04:00
|
|
|
}
|
|
|
|
|
2004-08-03 10:39:09 -04:00
|
|
|
void MyAppFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
|
2004-08-03 07:18:36 -04:00
|
|
|
{
|
2004-12-10 07:01:04 -05:00
|
|
|
m_pnl->Expand(m_pnl->Item(0));
|
|
|
|
m_pnl->Collapse(m_pnl->Item(1));
|
2004-08-03 07:18:36 -04:00
|
|
|
}
|