Allow access to the currently shown wxInfoBar buttons.
Add wxInfoBar::GetButtonCount(), GetButtonId() and HasButtonId() methods. Closes #15110. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76651 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -277,6 +277,110 @@ void wxInfoBarGeneric::AddButton(wxWindowID btnid, const wxString& label)
|
||||
sizer->Add(button, wxSizerFlags().Centre().DoubleBorder());
|
||||
}
|
||||
|
||||
size_t wxInfoBarGeneric::GetButtonCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
wxSizer * const sizer = GetSizer();
|
||||
if ( !sizer )
|
||||
return 0;
|
||||
|
||||
// iterate over the sizer items in reverse order
|
||||
const wxSizerItemList& items = sizer->GetChildren();
|
||||
for ( wxSizerItemList::compatibility_iterator node = items.GetLast();
|
||||
node != items.GetFirst();
|
||||
node = node->GetPrevious() )
|
||||
{
|
||||
const wxSizerItem * const item = node->GetData();
|
||||
|
||||
// if we reached the spacer separating the buttons from the text
|
||||
// break the for-loop.
|
||||
if ( item->IsSpacer() )
|
||||
break;
|
||||
|
||||
// if the standard button is shown, there must be no other ones
|
||||
if ( item->GetWindow() == m_button )
|
||||
return 0;
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
wxWindowID wxInfoBarGeneric::GetButtonId(size_t idx) const
|
||||
{
|
||||
wxCHECK_MSG( idx < GetButtonCount(), wxID_NONE,
|
||||
"Invalid infobar button position" );
|
||||
|
||||
wxSizer * const sizer = GetSizer();
|
||||
if ( !sizer )
|
||||
return wxID_NONE;
|
||||
|
||||
bool foundSpacer = false;
|
||||
|
||||
size_t count = 0;
|
||||
const wxSizerItemList& items = sizer->GetChildren();
|
||||
for ( wxSizerItemList::compatibility_iterator node = items.GetLast();
|
||||
node != items.GetFirst() || node != items.GetLast();
|
||||
)
|
||||
{
|
||||
const wxSizerItem * const item = node->GetData();
|
||||
|
||||
if ( item->IsSpacer() )
|
||||
foundSpacer = true;
|
||||
|
||||
if ( foundSpacer )
|
||||
{
|
||||
if ( !item->IsSpacer() )
|
||||
{
|
||||
if ( count == idx )
|
||||
{
|
||||
if ( item->GetWindow() != m_button )
|
||||
return item->GetWindow()->GetId();
|
||||
}
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
node = node->GetPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
return wxID_NONE;
|
||||
}
|
||||
|
||||
bool wxInfoBarGeneric::HasButtonId(wxWindowID btnid) const
|
||||
{
|
||||
wxSizer * const sizer = GetSizer();
|
||||
if ( !sizer )
|
||||
return false;
|
||||
|
||||
// iterate over the sizer items in reverse order to find the last added
|
||||
// button with this id
|
||||
const wxSizerItemList& items = sizer->GetChildren();
|
||||
for ( wxSizerItemList::compatibility_iterator node = items.GetLast();
|
||||
node != items.GetFirst();
|
||||
node = node->GetPrevious() )
|
||||
{
|
||||
const wxSizerItem * const item = node->GetData();
|
||||
|
||||
// if we reached the spacer separating the buttons from the text
|
||||
// then the wanted ID is not inside.
|
||||
if ( item->IsSpacer() )
|
||||
return false;
|
||||
|
||||
// check if we found our button
|
||||
if ( item->GetWindow()->GetId() == btnid )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxInfoBarGeneric::RemoveButton(wxWindowID btnid)
|
||||
{
|
||||
wxSizer * const sizer = GetSizer();
|
||||
|
||||
Reference in New Issue
Block a user