Added wxInfoBar::AddButton().
Allow adding custom buttons to wxInfoBar and show this in the sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62270 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -40,6 +40,8 @@ public:
|
||||
|
||||
virtual void ShowMessage(const wxString& msg, int flags = wxICON_NONE);
|
||||
|
||||
virtual void AddButton(wxWindowID btnid, const wxString& label = wxString());
|
||||
|
||||
|
||||
// methods specific to this version
|
||||
// --------------------------------
|
||||
|
@@ -35,6 +35,10 @@ public:
|
||||
// show the info bar with the given message and optionally an icon
|
||||
virtual void ShowMessage(const wxString& msg, int flags = wxICON_NONE) = 0;
|
||||
|
||||
// add an extra button to the bar, near the message
|
||||
virtual void AddButton(wxWindowID btnid,
|
||||
const wxString& label = wxString()) = 0;
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(wxInfoBarBase);
|
||||
};
|
||||
|
@@ -525,13 +525,23 @@ MyFrame::MyFrame(const wxString& title)
|
||||
m_canvas = new MyCanvas(this);
|
||||
|
||||
#if wxUSE_INFOBAR
|
||||
// an info bar can be created very simply and used without any extra effort
|
||||
m_infoBarSimple = new wxInfoBar(this);
|
||||
m_infoBarAdvanced = NULL;
|
||||
|
||||
// or it can also be customized
|
||||
m_infoBarAdvanced = new wxInfoBar(this);
|
||||
m_infoBarAdvanced->AddButton(wxID_UNDO);
|
||||
|
||||
m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff);
|
||||
m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND,
|
||||
wxSHOW_EFFECT_EXPAND);
|
||||
m_infoBarAdvanced->SetEffectDuration(1500);
|
||||
|
||||
// to use the info bars we need to use sizer for the window layout
|
||||
wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
|
||||
sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
|
||||
sizer->Add(m_canvas, wxSizerFlags(1).Expand());
|
||||
sizer->Add(m_infoBarAdvanced, wxSizerFlags().Expand());
|
||||
SetSizer(sizer);
|
||||
#endif // wxUSE_INFOBAR
|
||||
}
|
||||
@@ -690,6 +700,7 @@ void MyFrame::InfoBarSimple(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
|
||||
}
|
||||
|
||||
#endif // wxUSE_INFOBAR
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/artprov.h"
|
||||
#include "wx/bmpbuttn.h"
|
||||
#include "wx/button.h"
|
||||
#include "wx/settings.h"
|
||||
#include "wx/statbmp.h"
|
||||
#include "wx/stattext.h"
|
||||
@@ -96,7 +97,11 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid)
|
||||
this
|
||||
);
|
||||
|
||||
// Center the text inside the sizer.
|
||||
// center the text inside the sizer with an icon to the left of it and a
|
||||
// button at the very right
|
||||
//
|
||||
// NB: AddButton() relies on the button being the last control in the sizer
|
||||
// and being preceded by a spacer
|
||||
wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->AddStretchSpacer();
|
||||
sizer->Add(m_icon, wxSizerFlags().Centre().DoubleBorder());
|
||||
@@ -239,6 +244,16 @@ void wxInfoBar::ShowMessage(const wxString& msg, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label)
|
||||
{
|
||||
wxSizer * const sizer = GetSizer();
|
||||
wxCHECK_RET( sizer, "must be created first" );
|
||||
|
||||
sizer->Insert(sizer->GetItemCount() - 2,
|
||||
new wxButton(this, btnid, label),
|
||||
wxSizerFlags().Centre().DoubleBorder());
|
||||
}
|
||||
|
||||
void wxInfoBar::OnButton(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
DoHide();
|
||||
|
Reference in New Issue
Block a user