From fe97acf0e3b423984fb615c0ce060d9f00f6f0f8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 23 Oct 2010 18:56:13 +0000 Subject: [PATCH] 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 --- docs/doxygen/overviews/xrc_format.h | 2 +- src/xrc/xmlres.cpp | 30 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index 75ec8c814b..7f966cce6a 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -934,7 +934,7 @@ The available properties are: @row3col{mask, @ref overview_xrcformat_type_bool, If masks should be created for all images (default: true).} @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 Example: diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index cd053af857..ba4a986bb3 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1493,18 +1493,13 @@ wxImageList *wxXmlResourceHandler::GetImageList(const wxString& param) wxXmlNode * const oldnode = m_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(); - size.SetDefaults(wxSize(wxSystemSettings::GetMetric(wxSYS_ICON_X), - wxSystemSettings::GetMetric(wxSYS_ICON_Y))); - - // mask: true by default - bool mask = HasParam(wxT("mask")) ? GetBool(wxT("mask"), true) : true; - // now we have everything we need to create the image list - wxImageList *imagelist = new wxImageList(size.x, size.y, mask); - - // add images + // Start adding images, we'll create the image list when adding the first + // one. + wxImageList * imagelist = NULL; wxString parambitmap = wxT("bitmap"); if ( HasParam(parambitmap) ) { @@ -1513,8 +1508,21 @@ wxImageList *wxXmlResourceHandler::GetImageList(const wxString& param) { 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 - imagelist->Add(GetIcon(n)); + imagelist->Add(icon); } n = n->GetNext(); } -- 2.47.2