Add wxInfoBar::RemoveButton() method.
Also change the GTK implementation to use a separate wxInfoBarGTKImpl to store its data, this object won't be even allocated if a generic implementation is used under GTK. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62277 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -30,9 +30,41 @@
|
||||
#ifndef WX_PRECOMP
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/vector.h"
|
||||
|
||||
#include "wx/gtk/private.h"
|
||||
#include "wx/gtk/private/messagetype.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// local classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxInfoBarGTKImpl
|
||||
{
|
||||
public:
|
||||
wxInfoBarGTKImpl()
|
||||
{
|
||||
m_label = NULL;
|
||||
}
|
||||
|
||||
GtkWidget *m_label;
|
||||
|
||||
struct Button
|
||||
{
|
||||
Button(GtkWidget *button_, int id_)
|
||||
: button(button_),
|
||||
id(id_)
|
||||
{
|
||||
}
|
||||
|
||||
GtkWidget *button;
|
||||
int id;
|
||||
};
|
||||
typedef wxVector<Button> Buttons;
|
||||
|
||||
Buttons m_buttons;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// local functions
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -75,6 +107,8 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid)
|
||||
if ( !UseNative() )
|
||||
return wxInfoBarGeneric::Create(parent, winid);
|
||||
|
||||
m_impl = new wxInfoBarGTKImpl;
|
||||
|
||||
// this control is created initially hidden
|
||||
Hide();
|
||||
if ( !CreateBase(parent, winid) )
|
||||
@@ -86,13 +120,13 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid)
|
||||
g_object_ref(m_widget);
|
||||
|
||||
// also create a label which will be used to show our message
|
||||
m_label = gtk_label_new("");
|
||||
gtk_widget_show(m_label);
|
||||
m_impl->m_label = gtk_label_new("");
|
||||
gtk_widget_show(m_impl->m_label);
|
||||
|
||||
GtkWidget * const
|
||||
contentArea = gtk_info_bar_get_content_area(GTK_INFO_BAR(m_widget));
|
||||
wxCHECK_MSG( contentArea, false, "failed to get GtkInfoBar content area" );
|
||||
gtk_container_add(GTK_CONTAINER(contentArea), m_label);
|
||||
gtk_container_add(GTK_CONTAINER(contentArea), m_impl->m_label);
|
||||
|
||||
// finish creation and connect to all the signals we're interested in
|
||||
m_parent->DoAddChild(this);
|
||||
@@ -105,6 +139,11 @@ bool wxInfoBar::Create(wxWindow *parent, wxWindowID winid)
|
||||
return false;
|
||||
}
|
||||
|
||||
wxInfoBar::~wxInfoBar()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
void wxInfoBar::ShowMessage(const wxString& msg, int flags)
|
||||
{
|
||||
if ( !UseNative() )
|
||||
@@ -116,7 +155,7 @@ void wxInfoBar::ShowMessage(const wxString& msg, int flags)
|
||||
GtkMessageType type;
|
||||
if ( wxGTKImpl::ConvertMessageTypeFromWX(flags, &type) )
|
||||
gtk_info_bar_set_message_type(GTK_INFO_BAR(m_widget), type);
|
||||
gtk_label_set_text(GTK_LABEL(m_label), wxGTK_CONV(msg));
|
||||
gtk_label_set_text(GTK_LABEL(m_impl->m_label), wxGTK_CONV(msg));
|
||||
|
||||
if ( !IsShown() )
|
||||
Show();
|
||||
@@ -139,12 +178,42 @@ void wxInfoBar::AddButton(wxWindowID btnid, const wxString& label)
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_info_bar_add_button
|
||||
(
|
||||
GTK_INFO_BAR(m_widget),
|
||||
label.empty() ? GTKConvertMnemonics(wxGetStockGtkID(btnid)) : label,
|
||||
btnid
|
||||
);
|
||||
GtkWidget *button = gtk_info_bar_add_button
|
||||
(
|
||||
GTK_INFO_BAR(m_widget),
|
||||
label.empty()
|
||||
? GTKConvertMnemonics(wxGetStockGtkID(btnid))
|
||||
: label,
|
||||
btnid
|
||||
);
|
||||
wxCHECK_RET( button, "unexpectedly failed to add button to info bar" );
|
||||
|
||||
g_object_ref(button);
|
||||
m_impl->m_buttons.push_back(wxInfoBarGTKImpl::Button(button, btnid));
|
||||
}
|
||||
|
||||
void wxInfoBar::RemoveButton(wxWindowID btnid)
|
||||
{
|
||||
if ( !UseNative() )
|
||||
{
|
||||
wxInfoBarGeneric::RemoveButton(btnid);
|
||||
return;
|
||||
}
|
||||
|
||||
// as in the generic version, look for the button starting from the end
|
||||
wxInfoBarGTKImpl::Buttons& buttons = m_impl->m_buttons;
|
||||
for ( wxInfoBarGTKImpl::Buttons::reverse_iterator i = buttons.rbegin();
|
||||
i != buttons.rend();
|
||||
++i )
|
||||
{
|
||||
GtkWidget * const button = i->button;
|
||||
buttons.erase(i.base());
|
||||
gtk_widget_destroy(button);
|
||||
g_object_unref(button);
|
||||
return;
|
||||
}
|
||||
|
||||
wxFAIL_MSG( wxString::Format("button with id %d not found", btnid) );
|
||||
}
|
||||
|
||||
#endif // wxUSE_INFOBAR
|
||||
|
||||
Reference in New Issue
Block a user