2006-10-22 22:28:37 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: collpane.cpp
|
|
|
|
// Purpose: wxCollapsiblePane sample
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Modified by:
|
|
|
|
// Created: 14/10/06
|
|
|
|
// Copyright: (c) Francesco Montorsi
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2006-10-22 22:28:37 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
|
|
|
|
#include "wx/scrolwin.h"
|
|
|
|
#include "wx/menu.h"
|
|
|
|
|
|
|
|
#include "wx/textdlg.h" // for wxGetTextFromUser
|
|
|
|
#endif
|
|
|
|
|
2016-02-08 00:02:07 +00:00
|
|
|
#include "wx/collheaderctrl.h"
|
2006-10-22 22:28:37 +00:00
|
|
|
#include "wx/collpane.h"
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/stattext.h"
|
|
|
|
#include "wx/clrpicker.h"
|
|
|
|
#include "wx/filepicker.h"
|
|
|
|
#include "wx/fontpicker.h"
|
2006-10-30 20:08:17 +00:00
|
|
|
#include "wx/aboutdlg.h"
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2012-03-04 00:28:58 +00:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-08 01:01:00 +00:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ID for the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2009-06-10 14:54:09 +00:00
|
|
|
PANE_COLLAPSE = 100,
|
2006-10-22 22:28:37 +00:00
|
|
|
PANE_EXPAND,
|
|
|
|
PANE_SETLABEL,
|
|
|
|
PANE_SHOWDLG,
|
2006-10-30 20:08:17 +00:00
|
|
|
PANE_ABOUT = wxID_ABOUT,
|
2009-01-31 19:15:25 +00:00
|
|
|
PANE_QUIT = wxID_EXIT,
|
2009-02-08 01:01:00 +00:00
|
|
|
|
2009-01-31 19:15:25 +00:00
|
|
|
PANE_BUTTON,
|
|
|
|
PANE_TEXTCTRL
|
2006-10-22 22:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// our classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyApp() { }
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(MyApp);
|
2006-10-22 22:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame();
|
|
|
|
virtual ~MyFrame();
|
|
|
|
|
|
|
|
// Menu commands
|
|
|
|
void OnCollapse(wxCommandEvent& event);
|
|
|
|
void OnExpand(wxCommandEvent& event);
|
|
|
|
void OnSetLabel(wxCommandEvent& event);
|
|
|
|
void OnShowDialog(wxCommandEvent& event);
|
|
|
|
void Quit(wxCommandEvent& event);
|
2006-10-30 20:08:17 +00:00
|
|
|
void OnAbout(wxCommandEvent& event);
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2007-02-08 15:04:24 +00:00
|
|
|
// UI update handlers
|
|
|
|
void OnCollapseUpdateUI(wxUpdateUIEvent& event);
|
|
|
|
void OnExpandUpdateUI(wxUpdateUIEvent& event);
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2016-02-08 00:02:07 +00:00
|
|
|
void OnCollapsibleHeaderChanged(wxCommandEvent& event);
|
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
private:
|
|
|
|
wxCollapsiblePane *m_collPane;
|
2016-02-08 00:02:07 +00:00
|
|
|
wxCollapsibleHeaderCtrl *m_collHeaderCtrl;
|
2009-01-31 19:15:25 +00:00
|
|
|
wxBoxSizer *m_paneSizer;
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(MyFrame);
|
2006-10-22 22:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyDialog : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyDialog(wxFrame *parent);
|
|
|
|
void OnToggleStatus(wxCommandEvent& WXUNUSED(ev));
|
2009-01-31 19:15:25 +00:00
|
|
|
void OnAlignButton(wxCommandEvent& WXUNUSED(ev));
|
2006-10-30 20:08:17 +00:00
|
|
|
void OnPaneChanged(wxCollapsiblePaneEvent& event);
|
2006-10-22 22:28:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxCollapsiblePane *m_collPane;
|
2009-01-31 19:15:25 +00:00
|
|
|
wxGridSizer *m_paneSizer;
|
2006-10-22 22:28:37 +00:00
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(MyDialog);
|
2006-10-22 22:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxIMPLEMENT_APP(MyApp);
|
2006-10-22 22:28:37 +00:00
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
// create and show the main frame
|
|
|
|
MyFrame* frame = new MyFrame;
|
|
|
|
|
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2006-10-22 22:28:37 +00:00
|
|
|
EVT_MENU(PANE_COLLAPSE, MyFrame::OnCollapse)
|
|
|
|
EVT_MENU(PANE_EXPAND, MyFrame::OnExpand)
|
|
|
|
EVT_MENU(PANE_SETLABEL, MyFrame::OnSetLabel)
|
|
|
|
EVT_MENU(PANE_SHOWDLG, MyFrame::OnShowDialog)
|
2006-10-30 20:08:17 +00:00
|
|
|
EVT_MENU(PANE_ABOUT, MyFrame::OnAbout)
|
2006-10-22 22:28:37 +00:00
|
|
|
EVT_MENU(PANE_QUIT, MyFrame::Quit)
|
|
|
|
|
2007-02-08 15:04:24 +00:00
|
|
|
EVT_UPDATE_UI(PANE_COLLAPSE, MyFrame::OnCollapseUpdateUI)
|
|
|
|
EVT_UPDATE_UI(PANE_EXPAND, MyFrame::OnExpandUpdateUI)
|
2016-02-08 00:02:07 +00:00
|
|
|
|
|
|
|
EVT_COLLAPSIBLEHEADER_CHANGED(wxID_ANY, MyFrame::OnCollapsibleHeaderChanged)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-10-22 22:28:37 +00:00
|
|
|
|
|
|
|
// My frame constructor
|
|
|
|
MyFrame::MyFrame()
|
2009-07-23 20:30:22 +00:00
|
|
|
: wxFrame(NULL, wxID_ANY, wxT("wxCollapsiblePane sample"),
|
2006-10-22 22:28:37 +00:00
|
|
|
wxDefaultPosition, wxSize(420, 300),
|
|
|
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
|
|
|
{
|
2009-02-08 01:01:00 +00:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
CreateStatusBar(2);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *paneMenu = new wxMenu;
|
2009-07-23 20:30:22 +00:00
|
|
|
paneMenu->Append(PANE_COLLAPSE, wxT("Collapse\tCtrl-C"));
|
|
|
|
paneMenu->Append(PANE_EXPAND, wxT("Expand\tCtrl-E"));
|
2006-10-22 22:28:37 +00:00
|
|
|
paneMenu->AppendSeparator();
|
2009-07-23 20:30:22 +00:00
|
|
|
paneMenu->Append(PANE_SETLABEL, wxT("Set label...\tCtrl-L"));
|
2006-10-22 22:28:37 +00:00
|
|
|
paneMenu->AppendSeparator();
|
2009-07-23 20:30:22 +00:00
|
|
|
paneMenu->Append(PANE_SHOWDLG, wxT("Show dialog...\tCtrl-S"));
|
2006-10-22 22:28:37 +00:00
|
|
|
paneMenu->AppendSeparator();
|
|
|
|
paneMenu->Append(PANE_QUIT);
|
|
|
|
|
2006-10-30 20:08:17 +00:00
|
|
|
wxMenu *helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(PANE_ABOUT);
|
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
2009-07-23 20:30:22 +00:00
|
|
|
menuBar->Append(paneMenu, wxT("&Pane"));
|
|
|
|
menuBar->Append(helpMenu, wxT("&Help"));
|
2006-10-22 22:28:37 +00:00
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2016-02-08 00:02:07 +00:00
|
|
|
m_collPane = new wxCollapsiblePane(this, -1, "This is a wxCollapsiblePane");
|
2006-10-22 22:28:37 +00:00
|
|
|
wxWindow *win = m_collPane->GetPane();
|
2009-02-08 01:01:00 +00:00
|
|
|
|
2011-12-28 13:51:21 +00:00
|
|
|
m_paneSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
wxBoxSizer* paneSubSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_paneSizer->AddSpacer( 20 );
|
|
|
|
m_paneSizer->Add( paneSubSizer, 1 );
|
|
|
|
|
|
|
|
paneSubSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT | wxALL, 3 );
|
|
|
|
paneSubSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT | wxALL, 3 );
|
|
|
|
paneSubSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT | wxALL, 3 );
|
|
|
|
paneSubSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT | wxALL, 3 );
|
|
|
|
|
2009-01-31 19:15:25 +00:00
|
|
|
win->SetSizer( m_paneSizer );
|
2016-02-08 00:02:07 +00:00
|
|
|
|
|
|
|
m_collHeaderCtrl = new wxCollapsibleHeaderCtrl(this, wxID_ANY, "Collapsed wxCollapsibleHeaderCtrl");
|
|
|
|
|
|
|
|
wxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sizerTop->Add(m_collPane, wxSizerFlags(1).Expand());
|
|
|
|
sizerTop->Add(m_collHeaderCtrl);
|
|
|
|
SetSizer(sizerTop);
|
2006-10-22 22:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// menu command handlers
|
|
|
|
|
|
|
|
void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCollapse(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
m_collPane->Collapse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnExpand(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
m_collPane->Expand();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnSetLabel(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2007-02-08 15:04:24 +00:00
|
|
|
wxString text = wxGetTextFromUser
|
|
|
|
(
|
|
|
|
wxT("Enter new label"),
|
|
|
|
wxGetTextFromUserPromptStr,
|
|
|
|
m_collPane->GetLabel()
|
|
|
|
);
|
2006-10-22 22:28:37 +00:00
|
|
|
m_collPane->SetLabel(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
MyDialog dlg(this);
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
2006-10-30 20:08:17 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxAboutDialogInfo info;
|
|
|
|
info.SetName(_("wxCollapsiblePane sample"));
|
|
|
|
info.SetDescription(_("This sample program demonstrates usage of wxCollapsiblePane"));
|
2009-07-23 20:30:22 +00:00
|
|
|
info.SetCopyright(wxT("(C) 2006 Francesco Montorsi <frm@users.sourceforge.net>"));
|
2006-10-30 20:08:17 +00:00
|
|
|
|
2017-03-20 22:27:57 +00:00
|
|
|
wxAboutBox(info, this);
|
2006-10-30 20:08:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-08 15:04:24 +00:00
|
|
|
void MyFrame::OnCollapseUpdateUI(wxUpdateUIEvent& event)
|
2006-10-22 22:28:37 +00:00
|
|
|
{
|
2007-02-08 15:04:24 +00:00
|
|
|
event.Enable(!m_collPane->IsCollapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnExpandUpdateUI(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable(m_collPane->IsCollapsed());
|
2006-10-22 22:28:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 00:02:07 +00:00
|
|
|
void MyFrame::OnCollapsibleHeaderChanged(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_collHeaderCtrl->SetLabel
|
|
|
|
(
|
|
|
|
wxString::Format
|
|
|
|
(
|
|
|
|
"%s wxCollapsibleHeaderCtrl",
|
|
|
|
m_collHeaderCtrl->IsCollapsed() ? "Collapsed" : "Expanded"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2006-10-30 20:08:17 +00:00
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyDialog
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PANEDLG_TOGGLESTATUS_BTN = wxID_HIGHEST
|
|
|
|
};
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MyDialog, wxDialog)
|
2006-10-22 22:28:37 +00:00
|
|
|
EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus)
|
2006-10-30 20:08:17 +00:00
|
|
|
EVT_COLLAPSIBLEPANE_CHANGED(wxID_ANY, MyDialog::OnPaneChanged)
|
2009-01-31 19:15:25 +00:00
|
|
|
EVT_BUTTON(PANE_BUTTON, MyDialog::OnAlignButton)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2006-10-22 22:28:37 +00:00
|
|
|
|
|
|
|
MyDialog::MyDialog(wxFrame *parent)
|
|
|
|
: wxDialog(parent, wxID_ANY, wxT("Test dialog"),
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE )
|
|
|
|
{
|
|
|
|
wxSizer *sz = new wxBoxSizer(wxVERTICAL);
|
2006-10-30 20:08:17 +00:00
|
|
|
sz->Add(new wxStaticText(this, -1,
|
2006-10-22 22:28:37 +00:00
|
|
|
wxT("This dialog allows you to test the wxCollapsiblePane control")),
|
|
|
|
0, wxALL, 5);
|
2006-10-30 20:08:17 +00:00
|
|
|
sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")),
|
2006-10-22 22:28:37 +00:00
|
|
|
1, wxGROW|wxALL, 5);
|
2006-10-30 20:08:17 +00:00
|
|
|
|
2006-10-22 22:28:37 +00:00
|
|
|
m_collPane = new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
|
2006-10-30 20:08:17 +00:00
|
|
|
sz->Add(m_collPane, 0, wxGROW|wxALL, 5);
|
2006-10-22 22:28:37 +00:00
|
|
|
sz->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW|wxALL, 5);
|
|
|
|
sz->AddSpacer(10);
|
|
|
|
sz->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5);
|
|
|
|
|
|
|
|
// now add test controls in the collapsible pane
|
|
|
|
wxWindow *win = m_collPane->GetPane();
|
2009-01-31 19:15:25 +00:00
|
|
|
m_paneSizer = new wxGridSizer(4, 1, 5, 5);
|
|
|
|
|
|
|
|
m_paneSizer->Add( new wxStaticText(win, -1, wxT("Static text") ), 0, wxALIGN_LEFT );
|
|
|
|
m_paneSizer->Add( new wxStaticText(win, -1, wxT("Yet another one!") ), 0, wxALIGN_LEFT );
|
|
|
|
m_paneSizer->Add( new wxTextCtrl(win, PANE_TEXTCTRL, wxT("Text control"), wxDefaultPosition, wxSize(80,-1) ), 0, wxALIGN_LEFT );
|
|
|
|
m_paneSizer->Add( new wxButton(win, PANE_BUTTON, wxT("Press to align right") ), 0, wxALIGN_LEFT );
|
|
|
|
win->SetSizer( m_paneSizer );
|
|
|
|
|
|
|
|
win->SetSizer( m_paneSizer );
|
|
|
|
m_paneSizer->SetSizeHints(win);
|
2006-10-22 22:28:37 +00:00
|
|
|
|
|
|
|
SetSizer(sz);
|
|
|
|
sz->SetSizeHints(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev))
|
|
|
|
{
|
|
|
|
m_collPane->Collapse(!m_collPane->IsCollapsed());
|
|
|
|
}
|
|
|
|
|
2009-01-31 19:15:25 +00:00
|
|
|
void MyDialog::OnAlignButton(wxCommandEvent& WXUNUSED(ev))
|
|
|
|
{
|
|
|
|
wxSizerItem *item = m_paneSizer->GetItem( FindWindow(PANE_TEXTCTRL), true );
|
|
|
|
item->SetFlag( wxALIGN_RIGHT );
|
2009-02-08 01:01:00 +00:00
|
|
|
|
2009-01-31 19:15:25 +00:00
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
2009-07-05 13:10:46 +00:00
|
|
|
void MyDialog::OnPaneChanged(wxCollapsiblePaneEvent& event)
|
2006-10-30 20:08:17 +00:00
|
|
|
{
|
2009-07-05 13:10:46 +00:00
|
|
|
wxLogMessage(wxT("The pane has just been %s by the user"),
|
2006-10-30 20:08:17 +00:00
|
|
|
event.GetCollapsed() ? wxT("collapsed") : wxT("expanded"));
|
|
|
|
}
|
|
|
|
|