avmedia/source/viewer/mediawindow.cxx | 14 +++---- chart2/source/controller/dialogs/dlg_ObjectProperties.cxx | 8 ++-- chart2/source/controller/inc/dlg_ObjectProperties.hxx | 6 +-- chart2/source/controller/main/ChartController_Properties.cxx | 4 +- forms/source/component/imgprod.cxx | 22 +++++------ forms/source/component/imgprod.hxx | 7 ++- sc/source/filter/html/htmlpars.cxx | 10 ++--- sc/source/filter/inc/eeparser.hxx | 4 +- sc/source/filter/rtf/eeimpars.cxx | 6 +-- 9 files changed, 41 insertions(+), 40 deletions(-)
New commits: commit 16987d2aae9e0ed052de8a8f7155070c4b05cf4a Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Fri Sep 9 20:30:53 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Sep 10 12:19:13 2022 +0200 unique_ptr->optional for Graphic Graphic is just a wrapper around shared_ptr, so no need to allocate this separately Change-Id: Ie657dea1c021e66a6876e814090a44cb6f995b91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139739 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/avmedia/source/viewer/mediawindow.cxx b/avmedia/source/viewer/mediawindow.cxx index df8110f54e0d..27397fcbcf7a 100644 --- a/avmedia/source/viewer/mediawindow.cxx +++ b/avmedia/source/viewer/mediawindow.cxx @@ -369,7 +369,7 @@ MediaWindow::grabFrame(const uno::Reference<media::XPlayer>& xPlayer, const uno::Reference<graphic::XGraphic>& rGraphic) { uno::Reference< graphic::XGraphic > xRet; - std::unique_ptr< Graphic > xGraphic; + std::optional< Graphic > oGraphic; if( xPlayer.is() ) { @@ -392,22 +392,22 @@ MediaWindow::grabFrame(const uno::Reference<media::XPlayer>& xPlayer, if( !aPrefSize.Width && !aPrefSize.Height ) { const BitmapEx aBmpEx(AVMEDIA_BMP_AUDIOLOGO); - xGraphic.reset( new Graphic( aBmpEx ) ); + oGraphic.emplace( aBmpEx ); } } } - if (!xRet.is() && !xGraphic) + if (!xRet.is() && !oGraphic) { const BitmapEx aBmpEx(AVMEDIA_BMP_EMPTYLOGO); - xGraphic.reset( new Graphic( aBmpEx ) ); + oGraphic.emplace( aBmpEx ); } - if (xGraphic) + if (oGraphic) { if (rGraphic) - xGraphic.reset(new Graphic(rGraphic)); - xRet = xGraphic->GetXGraphic(); + oGraphic.emplace(rGraphic); + xRet = oGraphic->GetXGraphic(); } return xRet; diff --git a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx index bc5bc46a82e1..a838f784d1a4 100644 --- a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx +++ b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx @@ -316,10 +316,10 @@ void ObjectPropertiesDialogParameter::init( const rtl::Reference<::chart::ChartM const sal_uInt16 nNoArrowNoShadowDlg = 1101; void SchAttribTabDlg::setSymbolInformation( SfxItemSet&& rSymbolShapeProperties, - std::unique_ptr<Graphic> pAutoSymbolGraphic ) + std::optional<Graphic> oAutoSymbolGraphic ) { m_oSymbolShapeProperties.emplace(std::move(rSymbolShapeProperties)); - m_pAutoSymbolGraphic = std::move(pAutoSymbolGraphic); + m_oAutoSymbolGraphic = std::move(oAutoSymbolGraphic); } void SchAttribTabDlg::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth ) @@ -511,8 +511,8 @@ void SchAttribTabDlg::PageCreated(const OString& rId, SfxTabPage &rPage) aSet.Put(OfaPtrItem(SID_OBJECT_LIST,m_pViewElementListProvider->GetSymbolList())); if( m_oSymbolShapeProperties ) aSet.Put(SfxTabDialogItem(SID_ATTR_SET, *m_oSymbolShapeProperties)); - if( m_pAutoSymbolGraphic ) - aSet.Put(SvxGraphicItem(*m_pAutoSymbolGraphic)); + if( m_oAutoSymbolGraphic ) + aSet.Put(SvxGraphicItem(*m_oAutoSymbolGraphic)); } rPage.PageCreated(aSet); } diff --git a/chart2/source/controller/inc/dlg_ObjectProperties.hxx b/chart2/source/controller/inc/dlg_ObjectProperties.hxx index c4c1c0d83bf0..4311add0f733 100644 --- a/chart2/source/controller/inc/dlg_ObjectProperties.hxx +++ b/chart2/source/controller/inc/dlg_ObjectProperties.hxx @@ -20,9 +20,9 @@ #include <ObjectIdentifier.hxx> #include <sfx2/tabdlg.hxx> +#include <vcl/graph.hxx> namespace com::sun::star::util { class XNumberFormatsSupplier; } -class Graphic; namespace chart { @@ -115,7 +115,7 @@ private: SvNumberFormatter* m_pNumberFormatter; std::optional<SfxItemSet> m_oSymbolShapeProperties; - std::unique_ptr<Graphic> m_pAutoSymbolGraphic; + std::optional<Graphic> m_oAutoSymbolGraphic; double m_fAxisMinorStepWidthForErrorBarDecimals; bool m_bOKPressed; @@ -133,7 +133,7 @@ public: //pSymbolShapeProperties: Properties to be set on the symbollist shapes //pAutoSymbolGraphic: Graphic to be shown if AutoSymbol gets selected - void setSymbolInformation( SfxItemSet&& rSymbolShapeProperties, std::unique_ptr<Graphic> pAutoSymbolGraphic ); + void setSymbolInformation( SfxItemSet&& rSymbolShapeProperties, std::optional<Graphic> oAutoSymbolGraphic ); void SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth ); diff --git a/chart2/source/controller/main/ChartController_Properties.cxx b/chart2/source/controller/main/ChartController_Properties.cxx index a78bed1530e4..46dbe5431ff6 100644 --- a/chart2/source/controller/main/ChartController_Properties.cxx +++ b/chart2/source/controller/main/ChartController_Properties.cxx @@ -778,9 +778,9 @@ bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aSymbolItemConverter.FillItemSet( aSymbolShapeProperties ); sal_Int32 const nStandardSymbol=0;//@todo get from somewhere - std::unique_ptr<Graphic> pAutoSymbolGraphic(new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, &aSymbolShapeProperties ) )); + std::optional<Graphic> oAutoSymbolGraphic(std::in_place, aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, &aSymbolShapeProperties ) ); // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic - aDlg.setSymbolInformation( std::move(aSymbolShapeProperties), std::move(pAutoSymbolGraphic) ); + aDlg.setSymbolInformation( std::move(aSymbolShapeProperties), std::move(oAutoSymbolGraphic) ); } if( aDialogParameter.HasStatisticProperties() ) { diff --git a/forms/source/component/imgprod.cxx b/forms/source/component/imgprod.cxx index ce88a85c0c24..950a0848a84a 100644 --- a/forms/source/component/imgprod.cxx +++ b/forms/source/component/imgprod.cxx @@ -163,7 +163,7 @@ ImageProducer::ImageProducer() : mnTransIndex(0) , mbConsInit(false) { - mpGraphic.reset( new Graphic ); + moGraphic.emplace(); } ImageProducer::~ImageProducer() @@ -201,7 +201,7 @@ void ImageProducer::removeConsumer( const css::uno::Reference< css::awt::XImageC void ImageProducer::SetImage( const OUString& rPath ) { maURL = rPath; - mpGraphic->Clear(); + moGraphic->Clear(); mbConsInit = false; mpStm.reset(); @@ -221,7 +221,7 @@ void ImageProducer::SetImage( const OUString& rPath ) void ImageProducer::SetImage( SvStream& rStm ) { maURL.clear(); - mpGraphic->Clear(); + moGraphic->Clear(); mbConsInit = false; mpStm.reset( new SvStream( new ImgProdLockBytes( &rStm, false ) ) ); @@ -231,7 +231,7 @@ void ImageProducer::SetImage( SvStream& rStm ) void ImageProducer::setImage( css::uno::Reference< css::io::XInputStream > const & rInputStmRef ) { maURL.clear(); - mpGraphic->Clear(); + moGraphic->Clear(); mbConsInit = false; mpStm.reset(); @@ -242,7 +242,7 @@ void ImageProducer::setImage( css::uno::Reference< css::io::XInputStream > const void ImageProducer::NewDataAvailable() { - if( ( GraphicType::NONE == mpGraphic->GetType() ) || mpGraphic->GetReaderContext() ) + if( ( GraphicType::NONE == moGraphic->GetType() ) || moGraphic->GetReaderContext() ) startProduction(); } @@ -255,18 +255,18 @@ void ImageProducer::startProduction() bool bNotifyEmptyGraphics = false; // valid stream or filled graphic? => update consumers - if( mpStm || ( mpGraphic->GetType() != GraphicType::NONE ) ) + if( mpStm || ( moGraphic->GetType() != GraphicType::NONE ) ) { // if we already have a graphic, we don't have to import again; // graphic is cleared if a new Stream is set - if( ( mpGraphic->GetType() == GraphicType::NONE ) || mpGraphic->GetReaderContext() ) + if( ( moGraphic->GetType() == GraphicType::NONE ) || moGraphic->GetReaderContext() ) { - if ( ImplImportGraphic( *mpGraphic ) ) - maDoneHdl.Call( mpGraphic.get() ); + if ( ImplImportGraphic( *moGraphic ) ) + maDoneHdl.Call( &*moGraphic ); } - if( mpGraphic->GetType() != GraphicType::NONE ) - ImplUpdateData( *mpGraphic ); + if( moGraphic->GetType() != GraphicType::NONE ) + ImplUpdateData( *moGraphic ); else bNotifyEmptyGraphics = true; } diff --git a/forms/source/component/imgprod.hxx b/forms/source/component/imgprod.hxx index 0e746eb6bd5d..4b68a9fcfeb0 100644 --- a/forms/source/component/imgprod.hxx +++ b/forms/source/component/imgprod.hxx @@ -24,12 +24,13 @@ #include <com/sun/star/awt/XImageProducer.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <cppuhelper/weak.hxx> +#include <vcl/graph.hxx> #include <memory> +#include <optional> #include <vector> class SvStream; -class Graphic; namespace com::sun::star::io { class XInputStream; } @@ -43,8 +44,8 @@ private: OUString maURL; ConsumerList_t maConsList; - std::unique_ptr<Graphic> - mpGraphic; + std::optional<Graphic> + moGraphic; std::unique_ptr<SvStream> mpStm; sal_uInt32 mnTransIndex; diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index 52991dc2c5ec..c2414d858802 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -1319,10 +1319,10 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo ) } sal_uInt16 nFormat; - std::unique_ptr<Graphic> pGraphic(new Graphic); + std::optional<Graphic> oGraphic(std::in_place); GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); if ( ERRCODE_NONE != GraphicFilter::LoadGraphic( pImage->aURL, pImage->aFilterName, - *pGraphic, &rFilter, &nFormat ) ) + *oGraphic, &rFilter, &nFormat ) ) { return ; // Bad luck } @@ -1332,12 +1332,12 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo ) mxActEntry->aAltText.clear(); } pImage->aFilterName = rFilter.GetImportFormatName( nFormat ); - pImage->pGraphic = std::move( pGraphic ); + pImage->oGraphic = std::move( oGraphic ); if ( !(pImage->aSize.Width() && pImage->aSize.Height()) ) { OutputDevice* pDefaultDev = Application::GetDefaultDevice(); - pImage->aSize = pDefaultDev->LogicToPixel( pImage->pGraphic->GetPrefSize(), - pImage->pGraphic->GetPrefMapMode() ); + pImage->aSize = pDefaultDev->LogicToPixel( pImage->oGraphic->GetPrefSize(), + pImage->oGraphic->GetPrefMapMode() ); } if (mxActEntry->maImageList.empty()) return; diff --git a/sc/source/filter/inc/eeparser.hxx b/sc/source/filter/inc/eeparser.hxx index baab042ce055..737ff896bb21 100644 --- a/sc/source/filter/inc/eeparser.hxx +++ b/sc/source/filter/inc/eeparser.hxx @@ -41,8 +41,8 @@ struct ScHTMLImage Size aSize; Point aSpace; OUString aFilterName; - std::unique_ptr<Graphic> - pGraphic; // is taken over by WriteToDocument + std::optional<Graphic> + oGraphic; // is taken over by WriteToDocument char nDir; // 1==hori, 2==verti, 3==both ScHTMLImage() : diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index a36af94c2699..b9678e2fdd5f 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -492,7 +492,7 @@ bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, ScEEParseEntry* pE ) for (const std::unique_ptr<ScHTMLImage> & pImage : pE->maImageList) { ScHTMLImage* pI = pImage.get(); - if ( pI->pGraphic ) + if ( pI->oGraphic ) bHasGraphics = true; Size aSizePix = pI->aSize; aSizePix.AdjustWidth(2 * pI->aSpace.X() ); @@ -590,12 +590,12 @@ void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab, // Limit size ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() ); - if ( pI->pGraphic ) + if ( pI->oGraphic ) { tools::Rectangle aRect ( aInsertPos, aLogicSize ); rtl::Reference<SdrGrafObj> pObj = new SdrGrafObj( *pModel, - *pI->pGraphic, + *pI->oGraphic, aRect); // calling SetGraphicLink here doesn't work