don't crash when IsEmpty() is called on invalid bundle; don't assert if GetIcon(-1) is called on an invalid or empty bundle as existing code expects to be able to do it
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45320 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -149,11 +149,7 @@ void wxIconBundle::AddIcon(const wxString& file, long type)
|
|||||||
|
|
||||||
wxIcon wxIconBundle::GetIcon(const wxSize& size) const
|
wxIcon wxIconBundle::GetIcon(const wxSize& size) const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxNullIcon, _T("invalid icon bundle") );
|
const size_t count = GetIconCount();
|
||||||
|
|
||||||
const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons;
|
|
||||||
|
|
||||||
const size_t count = iconArray.size();
|
|
||||||
|
|
||||||
// optimize for the common case of icon bundles containing one icon only
|
// optimize for the common case of icon bundles containing one icon only
|
||||||
wxIcon iconBest;
|
wxIcon iconBest;
|
||||||
@@ -164,7 +160,7 @@ wxIcon wxIconBundle::GetIcon(const wxSize& size) const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
iconBest = iconArray[0];
|
iconBest = M_ICONBUNDLEDATA->m_icons[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -172,6 +168,7 @@ wxIcon wxIconBundle::GetIcon(const wxSize& size) const
|
|||||||
wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
|
wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
|
||||||
sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
|
sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
|
||||||
|
|
||||||
|
const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons;
|
||||||
for ( size_t i = 0; i < count; i++ )
|
for ( size_t i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
const wxIcon& icon = iconArray[i];
|
const wxIcon& icon = iconArray[i];
|
||||||
@@ -227,11 +224,13 @@ void wxIconBundle::AddIcon(const wxIcon& icon)
|
|||||||
|
|
||||||
size_t wxIconBundle::GetIconCount() const
|
size_t wxIconBundle::GetIconCount() const
|
||||||
{
|
{
|
||||||
return M_ICONBUNDLEDATA->m_icons.size();
|
return IsOk() ? M_ICONBUNDLEDATA->m_icons.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxIcon wxIconBundle::GetIconByIndex(size_t n) const
|
wxIcon wxIconBundle::GetIconByIndex(size_t n) const
|
||||||
{
|
{
|
||||||
|
wxCHECK_MSG( n < GetIconCount(), wxNullIcon, _T("invalid index") );
|
||||||
|
|
||||||
return M_ICONBUNDLEDATA->m_icons[n];
|
return M_ICONBUNDLEDATA->m_icons[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user