diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-23 09:53:18 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-23 19:52:33 +0200 |
commit | 35614ba0eb64e40ec37f1c28e522229b7fc04b88 (patch) | |
tree | 094eb63db3be6c9debd546aae8607c061c192345 /framework/source | |
parent | 5ab9cbe7f8d0c0bfd6a2fe1de2e14dfe201d008b (diff) |
simplify framework image manager load/save code
most of this stuff is unused, and we only ever have one image-list
Change-Id: I2c7aba4b537b725a627df65609167aea3159553e
Reviewed-on: https://gerrit.libreoffice.org/76148
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'framework/source')
-rw-r--r-- | framework/source/uiconfiguration/imagemanagerimpl.cxx | 25 | ||||
-rw-r--r-- | framework/source/xml/imagesconfiguration.cxx | 4 | ||||
-rw-r--r-- | framework/source/xml/imagesdocumenthandler.cxx | 59 |
3 files changed, 23 insertions, 65 deletions
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index fc6a54d3d2c2..a962588441c4 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -322,21 +322,19 @@ void ImageManagerImpl::implts_loadUserImages( ElementModes::READ ); uno::Reference< XInputStream > xInputStream = xStream->getInputStream(); - ImageListsDescriptor aUserImageListInfo; + ImageItemDescriptorList aUserImageListInfo; ImagesConfiguration::LoadImages( m_xContext, xInputStream, aUserImageListInfo ); - if (( aUserImageListInfo.pImageList != nullptr ) && - ( !aUserImageListInfo.pImageList->empty() )) + if ( !aUserImageListInfo.empty() ) { - ImageListItemDescriptor* pList = aUserImageListInfo.pImageList->front().get(); - sal_Int32 nCount = pList->pImageItemList->size(); + sal_Int32 nCount = aUserImageListInfo.size(); std::vector< OUString > aUserImagesVector; aUserImagesVector.reserve(nCount); for ( sal_Int32 i=0; i < nCount; i++ ) { - const ImageItemDescriptor* pItem = (*pList->pImageItemList)[i].get(); - aUserImagesVector.push_back( pItem->aCommandURL ); + const ImageItemDescriptor& rItem = aUserImageListInfo[i]; + aUserImagesVector.push_back( rItem.aCommandURL ); } uno::Reference< XStream > xBitmapStream = xUserBitmapsStorage->openStreamElement( @@ -393,18 +391,13 @@ bool ImageManagerImpl::implts_storeUserImages( ImageList* pImageList = implts_getUserImageList( nImageType ); if ( pImageList->GetImageCount() > 0 ) { - ImageListsDescriptor aUserImageListInfo; - aUserImageListInfo.pImageList.reset( new ImageListDescriptor ); + ImageItemDescriptorList aUserImageListInfo; - ImageListItemDescriptor* pList = new ImageListItemDescriptor; - aUserImageListInfo.pImageList->push_back( std::unique_ptr<ImageListItemDescriptor>(pList) ); - - pList->pImageItemList.reset( new ImageItemListDescriptor ); for ( sal_uInt16 i=0; i < pImageList->GetImageCount(); i++ ) { - ImageItemDescriptor* pItem = new ImageItemDescriptor; - pItem->aCommandURL = pImageList->GetImageName( i ); - pList->pImageItemList->push_back( std::unique_ptr<ImageItemDescriptor>(pItem) ); + ImageItemDescriptor aItem; + aItem.aCommandURL = pImageList->GetImageName( i ); + aUserImageListInfo.push_back( aItem ); } uno::Reference< XTransactedObject > xTransaction; diff --git a/framework/source/xml/imagesconfiguration.cxx b/framework/source/xml/imagesconfiguration.cxx index 444cef4252cc..12fa4bd84aa8 100644 --- a/framework/source/xml/imagesconfiguration.cxx +++ b/framework/source/xml/imagesconfiguration.cxx @@ -43,7 +43,7 @@ namespace framework bool ImagesConfiguration::LoadImages( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::io::XInputStream >& rInputStream, - ImageListsDescriptor& rItems ) + ImageItemDescriptorList& rItems ) { Reference< XParser > xParser = Parser::create( rxContext ); @@ -81,7 +81,7 @@ bool ImagesConfiguration::LoadImages( bool ImagesConfiguration::StoreImages( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::io::XOutputStream >& rOutputStream, - const ImageListsDescriptor& rItems ) + const ImageItemDescriptorList& rItems ) { Reference< XWriter > xWriter = Writer::create(rxContext); xWriter->setOutputStream( rOutputStream ); diff --git a/framework/source/xml/imagesdocumenthandler.cxx b/framework/source/xml/imagesdocumenthandler.cxx index 7005a07b89ac..dd95ddbf22e7 100644 --- a/framework/source/xml/imagesdocumenthandler.cxx +++ b/framework/source/xml/imagesdocumenthandler.cxx @@ -98,12 +98,9 @@ ImageXMLEntryProperty const ImagesEntries[OReadImagesDocumentHandler::IMG_XML_EN { OReadImagesDocumentHandler::IMG_NS_IMAGE, ATTRIBUTE_HIGHCONTRASTMASKURL } }; -OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageListsDescriptor& aItems ) : - m_aImageList( aItems ), - m_pImages( nullptr ) +OReadImagesDocumentHandler::OReadImagesDocumentHandler( ImageItemDescriptorList& rItems ) : + m_rImageList( rItems ) { - m_aImageList.pImageList = nullptr; - m_nHashMaskModeBitmap = OUString( ATTRIBUTE_MASKMODE_BITMAP ).hashCode(); m_nHashMaskModeColor = OUString( ATTRIBUTE_MASKMODE_COLOR ).hashCode(); @@ -191,11 +188,7 @@ void SAL_CALL OReadImagesDocumentHandler::startElement( throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); } - if ( !m_aImageList.pImageList ) - m_aImageList.pImageList.reset( new ImageListDescriptor ); - m_bImagesStartFound = true; - m_pImages = new ImageListItemDescriptor; } break; @@ -204,19 +197,13 @@ void SAL_CALL OReadImagesDocumentHandler::startElement( // Check that image:entry is embedded into image:images! if ( !m_bImagesStartFound ) { - delete m_pImages; - m_pImages = nullptr; - OUString aErrorMessage = getErrorLineString(); aErrorMessage += "Element 'image:entry' must be embedded into element 'image:images'!"; throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); } - if ( !m_pImages->pImageItemList ) - m_pImages->pImageItemList.reset( new ImageItemListDescriptor ); - // Create new image item descriptor - std::unique_ptr<ImageItemDescriptor> pItem(new ImageItemDescriptor); + ImageItemDescriptor aItem; // Read attributes for this image definition for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ ) @@ -228,7 +215,7 @@ void SAL_CALL OReadImagesDocumentHandler::startElement( { case IMG_ATTRIBUTE_COMMAND: { - pItem->aCommandURL = xAttribs->getValueByIndex( n ); + aItem.aCommandURL = xAttribs->getValueByIndex( n ); } break; @@ -239,17 +226,14 @@ void SAL_CALL OReadImagesDocumentHandler::startElement( } // Check required attribute "command" - if ( pItem->aCommandURL.isEmpty() ) + if ( aItem.aCommandURL.isEmpty() ) { - delete m_pImages; - m_pImages = nullptr; - OUString aErrorMessage = getErrorLineString(); aErrorMessage += "Required attribute 'image:command' must have a value!"; throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); } - m_pImages->pImageItemList->push_back( std::move(pItem) ); + m_rImageList.push_back( aItem ); } break; @@ -276,12 +260,6 @@ void SAL_CALL OReadImagesDocumentHandler::endElement(const OUString& aName) case IMG_ELEMENT_IMAGES: { - if ( m_pImages ) - { - if ( m_aImageList.pImageList ) - m_aImageList.pImageList->push_back( std::unique_ptr<ImageListItemDescriptor>(m_pImages) ); - m_pImages = nullptr; - } m_bImagesStartFound = false; } break; @@ -328,9 +306,9 @@ OUString OReadImagesDocumentHandler::getErrorLineString() // OWriteImagesDocumentHandler OWriteImagesDocumentHandler::OWriteImagesDocumentHandler( - const ImageListsDescriptor& aItems, + const ImageItemDescriptorList& rItems, Reference< XDocumentHandler > const & rWriteDocumentHandler ) : - m_aImageListsItems( aItems ), + m_rImageItemList( rItems ), m_xWriteDocumentHandler( rWriteDocumentHandler ) { ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; @@ -373,16 +351,7 @@ void OWriteImagesDocumentHandler::WriteImagesDocument() m_xWriteDocumentHandler->startElement( ELEMENT_NS_IMAGESCONTAINER, pList.get() ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); - if ( m_aImageListsItems.pImageList ) - { - ImageListDescriptor* pImageList = m_aImageListsItems.pImageList.get(); - - for ( size_t i = 0; i < m_aImageListsItems.pImageList->size(); i++ ) - { - const ImageListItemDescriptor* pImageItems = (*pImageList)[i].get(); - WriteImageList( pImageItems ); - } - } + WriteImageList( &m_rImageItemList ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->endElement( ELEMENT_NS_IMAGESCONTAINER ); @@ -392,7 +361,7 @@ void OWriteImagesDocumentHandler::WriteImagesDocument() // protected member functions -void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* pImageList ) +void OWriteImagesDocumentHandler::WriteImageList( const ImageItemDescriptorList* pImageList ) { ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; Reference< XAttributeList > xList( static_cast<XAttributeList *>(pList) , UNO_QUERY ); @@ -405,12 +374,8 @@ void OWriteImagesDocumentHandler::WriteImageList( const ImageListItemDescriptor* m_xWriteDocumentHandler->startElement( ELEMENT_NS_IMAGES, xList ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); - ImageItemListDescriptor* pImageItemList = pImageList->pImageItemList.get(); - if ( pImageItemList ) - { - for (std::unique_ptr<ImageItemDescriptor> & i : *pImageItemList) - WriteImage( i.get() ); - } + for (const ImageItemDescriptor & i : *pImageList) + WriteImage( &i ); m_xWriteDocumentHandler->endElement( ELEMENT_NS_IMAGES ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); |