From 0b1add25fdb6a625c7b2a07de7e3316d5a869b41 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 5 Oct 2009 22:56:07 +0000 Subject: [PATCH] Added wxInfoBar::Dismiss(). Add a method to conveniently hide the info bar and update the parent layout. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/infobar.h | 2 ++ include/wx/gtk/infobar.h | 2 ++ include/wx/infobar.h | 3 +++ interface/wx/infobar.h | 15 ++++++++++++--- src/generic/infobar.cpp | 5 +++++ src/gtk/infobar.cpp | 19 ++++++++++++++----- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/wx/generic/infobar.h b/include/wx/generic/infobar.h index db57ea31b1..a858c6d0d7 100644 --- a/include/wx/generic/infobar.h +++ b/include/wx/generic/infobar.h @@ -41,6 +41,8 @@ public: virtual void ShowMessage(const wxString& msg, int flags = wxICON_INFORMATION); + virtual void Dismiss(); + virtual void AddButton(wxWindowID btnid, const wxString& label = wxString()); virtual void RemoveButton(wxWindowID btnid); diff --git a/include/wx/gtk/infobar.h b/include/wx/gtk/infobar.h index ed4b0a08d7..31fe8571b5 100644 --- a/include/wx/gtk/infobar.h +++ b/include/wx/gtk/infobar.h @@ -41,6 +41,8 @@ public: virtual void ShowMessage(const wxString& msg, int flags = wxICON_INFORMATION); + virtual void Dismiss(); + virtual void AddButton(wxWindowID btnid, const wxString& label = wxString()); diff --git a/include/wx/infobar.h b/include/wx/infobar.h index 7d661283e0..0c9207207b 100644 --- a/include/wx/infobar.h +++ b/include/wx/infobar.h @@ -36,6 +36,9 @@ public: virtual void ShowMessage(const wxString& msg, int flags = wxICON_INFORMATION) = 0; + // hide the info bar + virtual void Dismiss() = 0; + // add an extra button to the bar, near the message (replacing the default // close button which is only shown if no extra buttons are used) virtual void AddButton(wxWindowID btnid, diff --git a/interface/wx/infobar.h b/interface/wx/infobar.h index 91360cf2d1..f79f3b110d 100644 --- a/interface/wx/infobar.h +++ b/interface/wx/infobar.h @@ -123,9 +123,10 @@ public: itself closes the window whenever a button in it is clicked so if you 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. + it (calling Dismiss() explicitly works too, of course). 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 @@ -143,6 +144,14 @@ public: */ void AddButton(wxWindowID btnid, const wxString& label = wxString()); + /** + Hide the info bar window. + + This method hides the window and lays out the parent window to account + for its disappearance (unlike a simple Hide()). + */ + void Dismiss(); + /** Remove a button previously added by AddButton(). diff --git a/src/generic/infobar.cpp b/src/generic/infobar.cpp index ae85d5d9d5..e23f356255 100644 --- a/src/generic/infobar.cpp +++ b/src/generic/infobar.cpp @@ -240,6 +240,11 @@ void wxInfoBarGeneric::ShowMessage(const wxString& msg, int flags) } } +void wxInfoBarGeneric::Dismiss() +{ + DoHide(); +} + void wxInfoBarGeneric::AddButton(wxWindowID btnid, const wxString& label) { wxSizer * const sizer = GetSizer(); diff --git a/src/gtk/infobar.cpp b/src/gtk/infobar.cpp index 275f0199a8..1069a86147 100644 --- a/src/gtk/infobar.cpp +++ b/src/gtk/infobar.cpp @@ -177,17 +177,26 @@ void wxInfoBar::ShowMessage(const wxString& msg, int flags) UpdateParent(); } +void wxInfoBar::Dismiss() +{ + if ( !UseNative() ) + { + wxInfoBarGeneric::Dismiss(); + return; + } + + Hide(); + + UpdateParent(); +} + void wxInfoBar::GTKResponse(int btnid) { wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, btnid); event.SetEventObject(this); if ( !HandleWindowEvent(event) ) - { - Hide(); - - UpdateParent(); - } + Dismiss(); } GtkWidget *wxInfoBar::GTKAddButton(wxWindowID btnid, const wxString& label) -- 2.45.2