2008-05-08 18:45:44 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wrapsizer.cpp
|
|
|
|
// Purpose: wxWidgets sample demonstrating wxWrapSizer use
|
|
|
|
// Author: Arne Steinarson
|
|
|
|
// Created: 21.01.2008
|
2009-02-07 20:01:00 -05:00
|
|
|
// RCS-ID: $Id$
|
2008-05-08 18:45:44 -04:00
|
|
|
// Copyright: (c) Arne Steinarson
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/log.h"
|
|
|
|
#include "wx/wrapsizer.h"
|
|
|
|
#include "wx/artprov.h"
|
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-07 20:01:00 -05:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// definitions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-05-08 18:45:44 -04:00
|
|
|
class WrapSizerFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2009-02-07 20:01:00 -05:00
|
|
|
WrapSizerFrame();
|
2008-05-08 18:45:44 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void OnButton(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddToolBarButton(wxToolBar *tb,
|
|
|
|
const wxString& label,
|
|
|
|
const wxString& artid)
|
|
|
|
{
|
|
|
|
wxBitmap
|
|
|
|
bm = wxArtProvider::GetBitmap(artid, wxART_TOOLBAR, wxSize(16, 16));
|
|
|
|
tb->AddTool(wxID_ANY, label, bm);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxToolBar *MakeToolBar()
|
|
|
|
{
|
2010-08-10 17:48:22 -04:00
|
|
|
wxToolBar *tb = new wxToolBar(m_panel, wxID_ANY,
|
2008-05-08 18:45:44 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTB_NODIVIDER);
|
|
|
|
AddToolBarButton(tb, "Help", wxART_HELP_BOOK);
|
|
|
|
tb->AddSeparator( );
|
|
|
|
AddToolBarButton(tb, "Open", wxART_FILE_OPEN);
|
|
|
|
tb->AddSeparator( );
|
|
|
|
AddToolBarButton(tb, "Up", wxART_GO_DIR_UP);
|
|
|
|
AddToolBarButton(tb, "Execute", wxART_EXECUTABLE_FILE);
|
|
|
|
|
|
|
|
tb->Realize( );
|
|
|
|
return tb;
|
|
|
|
}
|
2010-08-10 17:48:22 -04:00
|
|
|
|
|
|
|
wxPanel *m_panel;
|
2008-05-08 18:45:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class WrapSizerApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WrapSizerApp() {}
|
|
|
|
|
|
|
|
virtual bool OnInit()
|
|
|
|
{
|
|
|
|
new WrapSizerFrame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_APP(WrapSizerApp);
|
2009-02-07 20:01:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// WrapSizerFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
WrapSizerFrame::WrapSizerFrame()
|
|
|
|
: wxFrame(NULL, wxID_ANY, "wxWrapSizer Sample")
|
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2010-08-10 17:48:22 -04:00
|
|
|
m_panel = new wxPanel(this);
|
|
|
|
|
2009-02-07 20:01:00 -05:00
|
|
|
// Root sizer, vertical
|
|
|
|
wxSizer * const sizerRoot = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
// Some toolbars in a wrap sizer
|
|
|
|
wxSizer * const sizerTop = new wxWrapSizer( wxHORIZONTAL );
|
|
|
|
sizerTop->Add(MakeToolBar());
|
|
|
|
sizerTop->Add(20, 1);
|
|
|
|
sizerTop->Add(MakeToolBar());
|
|
|
|
sizerTop->Add(20, 1);
|
|
|
|
sizerTop->Add(MakeToolBar());
|
|
|
|
sizerRoot->Add(sizerTop, wxSizerFlags().Expand().Border());
|
|
|
|
|
|
|
|
// A number of checkboxes inside a wrap sizer
|
2010-08-10 17:48:22 -04:00
|
|
|
wxSizer *sizerMid = new wxStaticBoxSizer(wxVERTICAL, m_panel,
|
2009-02-07 20:01:00 -05:00
|
|
|
"With check-boxes");
|
|
|
|
wxSizer * const sizerMidWrap = new wxWrapSizer(wxHORIZONTAL);
|
|
|
|
for ( int nCheck = 0; nCheck < 6; nCheck++ )
|
|
|
|
{
|
|
|
|
wxCheckBox *chk = new wxCheckBox
|
|
|
|
(
|
2010-08-10 17:48:22 -04:00
|
|
|
m_panel,
|
2009-02-07 20:01:00 -05:00
|
|
|
wxID_ANY,
|
|
|
|
wxString::Format("Option %d", nCheck)
|
|
|
|
);
|
|
|
|
|
|
|
|
sizerMidWrap->Add(chk, wxSizerFlags().Centre().Border());
|
|
|
|
}
|
|
|
|
|
|
|
|
sizerMid->Add(sizerMidWrap, wxSizerFlags(100).Expand());
|
|
|
|
sizerRoot->Add(sizerMid, wxSizerFlags(100).Expand().Border());
|
|
|
|
|
|
|
|
|
|
|
|
// A shaped item inside a box sizer
|
2010-08-10 17:48:22 -04:00
|
|
|
wxSizer *sizerBottom = new wxStaticBoxSizer(wxVERTICAL, m_panel,
|
2009-02-07 20:01:00 -05:00
|
|
|
"With wxSHAPED item");
|
|
|
|
wxSizer *sizerBottomBox = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizerBottom->Add(sizerBottomBox, wxSizerFlags(100).Expand());
|
|
|
|
|
2010-08-10 17:48:22 -04:00
|
|
|
sizerBottomBox->Add(new wxListBox(m_panel, wxID_ANY,
|
2009-02-07 20:01:00 -05:00
|
|
|
wxPoint(0, 0), wxSize(70, 70)),
|
|
|
|
wxSizerFlags().Expand().Shaped());
|
|
|
|
sizerBottomBox->AddSpacer(10);
|
2010-08-10 17:48:22 -04:00
|
|
|
sizerBottomBox->Add(new wxCheckBox(m_panel, wxID_ANY,
|
2009-02-07 20:01:00 -05:00
|
|
|
"A much longer option..."),
|
|
|
|
wxSizerFlags(100).Border());
|
|
|
|
sizerRoot->Add(sizerBottom, wxSizerFlags(100).Expand().Border());
|
|
|
|
|
|
|
|
// OK Button
|
2010-08-10 17:48:22 -04:00
|
|
|
sizerRoot->Add(new wxButton(m_panel, wxID_OK),
|
2009-02-07 20:01:00 -05:00
|
|
|
wxSizerFlags().Centre().DoubleBorder());
|
|
|
|
Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
wxCommandEventHandler(WrapSizerFrame::OnButton));
|
|
|
|
|
2010-08-10 17:48:22 -04:00
|
|
|
// Set sizer for the panel
|
|
|
|
m_panel->SetSizer(sizerRoot);
|
2009-02-07 20:01:00 -05:00
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|