Don't assume any particular default size for XRC image lists.

Let the image list deduce its size from the first bitmap in it. This is better
than the old behaviour of using the standard icon size as it allows to omit
the size from the image lists provided they contain the bitmaps of the same
size.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65884 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-10-23 18:56:13 +00:00
parent 814bfbb9c0
commit fe97acf0e3
2 changed files with 20 additions and 12 deletions

View File

@@ -934,7 +934,7 @@ The available properties are:
@row3col{mask, @ref overview_xrcformat_type_bool, @row3col{mask, @ref overview_xrcformat_type_bool,
If masks should be created for all images (default: true).} If masks should be created for all images (default: true).}
@row3col{size, @ref overview_xrcformat_type_size, @row3col{size, @ref overview_xrcformat_type_size,
The size of the images in the list (default: system default icon size)).} The size of the images in the list (default: the size of the first bitmap).}
@endTable @endTable
Example: Example:

View File

@@ -1493,18 +1493,13 @@ wxImageList *wxXmlResourceHandler::GetImageList(const wxString& param)
wxXmlNode * const oldnode = m_node; wxXmlNode * const oldnode = m_node;
m_node = imagelist_node; m_node = imagelist_node;
// size // Get the size if we have it, otherwise we will use the size of the first
// list element.
wxSize size = GetSize(); wxSize size = GetSize();
size.SetDefaults(wxSize(wxSystemSettings::GetMetric(wxSYS_ICON_X),
wxSystemSettings::GetMetric(wxSYS_ICON_Y)));
// mask: true by default // Start adding images, we'll create the image list when adding the first
bool mask = HasParam(wxT("mask")) ? GetBool(wxT("mask"), true) : true; // one.
wxImageList * imagelist = NULL;
// now we have everything we need to create the image list
wxImageList *imagelist = new wxImageList(size.x, size.y, mask);
// add images
wxString parambitmap = wxT("bitmap"); wxString parambitmap = wxT("bitmap");
if ( HasParam(parambitmap) ) if ( HasParam(parambitmap) )
{ {
@@ -1513,8 +1508,21 @@ wxImageList *wxXmlResourceHandler::GetImageList(const wxString& param)
{ {
if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == parambitmap) if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == parambitmap)
{ {
wxIcon icon = GetIcon(n);
if ( !imagelist )
{
// We need the real image list size to create it.
if ( size == wxDefaultSize )
size = icon.GetSize();
// We use the mask by default.
bool mask = !HasParam(wxS("mask")) || GetBool(wxS("mask"));
imagelist = new wxImageList(size.x, size.y, mask);
}
// add icon instead of bitmap to keep the bitmap mask // add icon instead of bitmap to keep the bitmap mask
imagelist->Add(GetIcon(n)); imagelist->Add(icon);
} }
n = n->GetNext(); n = n->GetNext();
} }