virtual void ShowMessage(const wxString& msg, int flags = wxICON_NONE);
+ virtual void AddButton(wxWindowID btnid, const wxString& label = wxString());
+
// methods specific to this version
// --------------------------------
// 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);
};
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
}
void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
{
+ m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
}
#endif // wxUSE_INFOBAR
#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"
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());
}
}
+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();