Generate the button clicks in GTK version of wxInfoBar.
Also add an example of handling info bar buttons events to the sample and mention that this must be done using Connect() or by deriving from wxInfoBar in the documentation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62279 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -116,10 +116,20 @@ public:
|
|||||||
(in LTR layout), with each successive button being added to the right
|
(in LTR layout), with each successive button being added to the right
|
||||||
of the previous one.
|
of the previous one.
|
||||||
|
|
||||||
Clicking the button will generate a normal event which can be handled
|
Clicking the button will generate a normal EVT_COMMAND_BUTTON_CLICKED
|
||||||
as usual. Notice that if you wish the info bar to be hidden when the
|
event which can be handled as usual. The default handler in wxInfoBar
|
||||||
button is clicked, simply call @c event.Skip() in the button handler to
|
itself closes the window whenever a button in it is clicked so if you
|
||||||
let the base class handler do it.
|
wish the info bar to be hidden when the button is clicked, simply call
|
||||||
|
@c event.Skip() in the button handler to let the base class handler do
|
||||||
|
it. On the other hand, if you don't skip the event, the info bar will
|
||||||
|
remain opened so make sure to do it for at least some buttons to allow
|
||||||
|
the user to close it.
|
||||||
|
|
||||||
|
Notice that the generic wxInfoBar implementation handles the button
|
||||||
|
events itself and so they are not propagated to the info bar parent and
|
||||||
|
you need to either inherit from wxInfoBar and handle them in your
|
||||||
|
derived class or use wxEvtHandler::Connect(), as is done in the dialogs
|
||||||
|
sample, to handle the button events in the parent frame.
|
||||||
|
|
||||||
@param btnid
|
@param btnid
|
||||||
Id of the button. It will be used in the button message clicking
|
Id of the button. It will be used in the button message clicking
|
||||||
|
@@ -528,21 +528,33 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
// an info bar can be created very simply and used without any extra effort
|
// an info bar can be created very simply and used without any extra effort
|
||||||
m_infoBarSimple = new wxInfoBar(this);
|
m_infoBarSimple = new wxInfoBar(this);
|
||||||
|
|
||||||
// or it can also be customized
|
// or it can also be customized by
|
||||||
m_infoBarAdvanced = new wxInfoBar(this);
|
m_infoBarAdvanced = new wxInfoBar(this);
|
||||||
|
|
||||||
|
// ... adding extra buttons (but more than two will usually be too many)
|
||||||
m_infoBarAdvanced->AddButton(wxID_UNDO);
|
m_infoBarAdvanced->AddButton(wxID_UNDO);
|
||||||
m_infoBarAdvanced->AddButton(wxID_REDO);
|
m_infoBarAdvanced->AddButton(wxID_REDO);
|
||||||
|
|
||||||
|
m_infoBarAdvanced->Connect(wxID_REDO, wxEVT_COMMAND_BUTTON_CLICKED,
|
||||||
|
wxCommandEventHandler(MyFrame::OnInfoBarRedo),
|
||||||
|
NULL,
|
||||||
|
this);
|
||||||
|
|
||||||
// adding and removing a button immediately doesn't make sense here, of
|
// adding and removing a button immediately doesn't make sense here, of
|
||||||
// course, it's done just to show that it is possible
|
// course, it's done just to show that it is possible
|
||||||
m_infoBarAdvanced->AddButton(wxID_EXIT);
|
m_infoBarAdvanced->AddButton(wxID_EXIT);
|
||||||
m_infoBarAdvanced->RemoveButton(wxID_EXIT);
|
m_infoBarAdvanced->RemoveButton(wxID_EXIT);
|
||||||
|
|
||||||
|
// ... changing the colours and/or fonts
|
||||||
m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff);
|
m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff);
|
||||||
|
m_infoBarAdvanced->SetFont(GetFont().Bold().Larger());
|
||||||
|
|
||||||
|
// ... and changing the effect (only does anything under MSW currently)
|
||||||
m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND,
|
m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND,
|
||||||
wxSHOW_EFFECT_EXPAND);
|
wxSHOW_EFFECT_EXPAND);
|
||||||
m_infoBarAdvanced->SetEffectDuration(1500);
|
m_infoBarAdvanced->SetEffectDuration(1500);
|
||||||
|
|
||||||
|
|
||||||
// to use the info bars we need to use sizer for the window layout
|
// to use the info bars we need to use sizer for the window layout
|
||||||
wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
|
wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
|
sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
|
||||||
@@ -709,6 +721,11 @@ void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
|
|||||||
m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
|
m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnInfoBarRedo(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_infoBarAdvanced->ShowMessage("Still no, sorry again.", wxICON_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_INFOBAR
|
#endif // wxUSE_INFOBAR
|
||||||
|
|
||||||
|
|
||||||
|
@@ -429,6 +429,8 @@ private:
|
|||||||
wxWindow *m_canvas;
|
wxWindow *m_canvas;
|
||||||
|
|
||||||
#if wxUSE_INFOBAR
|
#if wxUSE_INFOBAR
|
||||||
|
void OnInfoBarRedo(wxCommandEvent& event);
|
||||||
|
|
||||||
wxInfoBar *m_infoBarSimple,
|
wxInfoBar *m_infoBarSimple,
|
||||||
*m_infoBarAdvanced;
|
*m_infoBarAdvanced;
|
||||||
#endif // wxUSE_INFOBAR
|
#endif // wxUSE_INFOBAR
|
||||||
|
@@ -163,11 +163,17 @@ void wxInfoBar::ShowMessage(const wxString& msg, int flags)
|
|||||||
UpdateParent();
|
UpdateParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxInfoBar::GTKResponse(int WXUNUSED(btnid))
|
void wxInfoBar::GTKResponse(int btnid)
|
||||||
{
|
{
|
||||||
Hide();
|
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, btnid);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
|
||||||
UpdateParent();
|
if ( !HandleWindowEvent(event) )
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
|
||||||
|
UpdateParent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label)
|
void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label)
|
||||||
|
Reference in New Issue
Block a user