- wxIcon *sysIcon = 0;
- // temp. variable needed to fix Borland C++ 5.5.1 problem
- // with passing a return value through two functions
- wxIcon *tmp;
+ // optimize for the common case of icon bundles containing one icon only
+ wxIcon iconBest;
+ switch ( count )
+ {
+ case 0:
+ // nothing to do, iconBest is already invalid
+ break;
+
+ case 1:
+ iconBest = M_ICONBUNDLEDATA->m_icons[0];
+ break;
+
+ default:
+ // there is more than one icon, find the best match:
+ wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
+ sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
+
+ const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons;
+ for ( size_t i = 0; i < count; i++ )
+ {
+ const wxIcon& icon = iconArray[i];
+ wxCoord sx = icon.GetWidth(),
+ sy = icon.GetHeight();
+
+ // if we got an icon of exactly the requested size, we're done
+ if ( sx == size.x && sy == size.y )
+ {
+ iconBest = icon;
+ break;
+ }
+
+ // the best icon is by default (arbitrarily) the first one but
+ // if we find a system-sized icon, take it instead
+ if ( sx == sysX && sy == sysY || !iconBest.IsOk() )
+ iconBest = icon;
+ }
+ }