From 374ae80f2c813475ad2f1e63041f3cd5f50e52d1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 5 Oct 2009 22:54:31 +0000 Subject: [PATCH] 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 --- include/wx/generic/infobar.h | 2 ++ include/wx/infobar.h | 4 ++++ samples/dialogs/dialogs.cpp | 13 ++++++++++++- src/generic/infobar.cpp | 17 ++++++++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/infobar.h b/include/wx/generic/infobar.h index f107549907..085bc40d50 100644 --- a/include/wx/generic/infobar.h +++ b/include/wx/generic/infobar.h @@ -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 // -------------------------------- diff --git a/include/wx/infobar.h b/include/wx/infobar.h index ffa7aadcd9..eb8b7e1703 100644 --- a/include/wx/infobar.h +++ b/include/wx/infobar.h @@ -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); }; diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index a45f416b92..d5e61a62c3 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -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 diff --git a/src/generic/infobar.cpp b/src/generic/infobar.cpp index 549f20617d..c5e84d838f 100644 --- a/src/generic/infobar.cpp +++ b/src/generic/infobar.cpp @@ -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(); -- 2.45.2