summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-09-09 17:06:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-09-10 11:47:32 +0200
commit9e67902277421aa3fae3bf10eb7bb8b70259c78e (patch)
treefe3defdcc6e0d9a545f369077c00c5f21ed399be
parent94c5c9281ac09186242143191f3e383bef2a89a7 (diff)
unique_ptr->optional for Graphic
Graphic is just a wrapper around shared_ptr, so no need to allocate this separately Change-Id: If4d6367d16d6ebc6c70c9cb39f8635ddaebccd72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139737 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/source/core/inc/UndoInsert.hxx4
-rw-r--r--sw/source/core/undo/unins.cxx8
-rw-r--r--sw/source/filter/ww8/ww8graf2.cxx18
-rw-r--r--sw/source/filter/ww8/ww8par.hxx3
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx42
-rw-r--r--sw/source/uibase/inc/swdtflvr.hxx5
6 files changed, 41 insertions, 39 deletions
diff --git a/sw/source/core/inc/UndoInsert.hxx b/sw/source/core/inc/UndoInsert.hxx
index 8a313ba50381..7602820ce313 100644
--- a/sw/source/core/inc/UndoInsert.hxx
+++ b/sw/source/core/inc/UndoInsert.hxx
@@ -25,12 +25,12 @@
#include <undobj.hxx>
#include <svx/svdtypes.hxx>
#include <rtl/ustring.hxx>
+#include <vcl/graph.hxx>
#include <swtypes.hxx>
#include <ndindex.hxx>
#include <IDocumentContentOperations.hxx>
#include <optional>
-class Graphic;
class SwGrfNode;
class SwUndoDelete;
class SwUndoFormatAttr;
@@ -138,7 +138,7 @@ private:
class SwUndoReRead final : public SwUndo
{
- std::unique_ptr<Graphic> mpGraphic;
+ std::optional<Graphic> moGraphic;
std::optional<OUString> maNm;
std::optional<OUString> maFltr;
SwNodeOffset mnPosition;
diff --git a/sw/source/core/undo/unins.cxx b/sw/source/core/undo/unins.cxx
index e69b6a311caf..29eb0408d5bc 100644
--- a/sw/source/core/undo/unins.cxx
+++ b/sw/source/core/undo/unins.cxx
@@ -780,7 +780,7 @@ void SwUndoReRead::SetAndSave(::sw::UndoRedoContext & rContext)
return ;
// cache the old values
- std::unique_ptr<Graphic> pOldGrf( mpGraphic ? new Graphic(*mpGraphic) : nullptr);
+ std::optional<Graphic> oOldGrf(moGraphic);
std::optional<OUString> aOldNm = maNm;
MirrorGraph nOldMirr = mnMirror;
// since all of them are cleared/modified by SaveGraphicData:
@@ -792,7 +792,7 @@ void SwUndoReRead::SetAndSave(::sw::UndoRedoContext & rContext)
}
else
{
- pGrfNd->ReRead( OUString(), OUString(), pOldGrf.get() );
+ pGrfNd->ReRead( OUString(), OUString(), oOldGrf ? &*oOldGrf : nullptr );
}
if( MirrorGraph::Dont != nOldMirr )
@@ -818,11 +818,11 @@ void SwUndoReRead::SaveGraphicData( const SwGrfNode& rGrfNd )
maNm = OUString();
maFltr = OUString();
rGrfNd.GetFileFilterNms(&*maNm, &*maFltr);
- mpGraphic.reset();
+ moGraphic.reset();
}
else
{
- mpGraphic.reset( new Graphic( rGrfNd.GetGrf(true) ) );
+ moGraphic.emplace( rGrfNd.GetGrf(true) );
maNm.reset();
maFltr.reset();
}
diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx
index a2de36616a3e..35219922db83 100644
--- a/sw/source/filter/ww8/ww8graf2.cxx
+++ b/sw/source/filter/ww8/ww8graf2.cxx
@@ -235,7 +235,7 @@ bool SwWW8ImplReader::GetPictGrafFromStream(Graphic& rGraphic, SvStream& rSrc)
return ERRCODE_NONE == GraphicFilter::GetGraphicFilter().ImportGraphic(rGraphic, u"", rSrc);
}
-bool SwWW8ImplReader::ReadGrafFile(OUString& rFileName, std::unique_ptr<Graphic>& rpGraphic,
+bool SwWW8ImplReader::ReadGrafFile(OUString& rFileName, std::optional<Graphic>& roGraphic,
const WW8_PIC& rPic, SvStream* pSt, sal_uLong nFilePos, bool* pbInDoc)
{ // Write the graphic to the file
*pbInDoc = true; // default
@@ -272,7 +272,7 @@ bool SwWW8ImplReader::ReadGrafFile(OUString& rFileName, std::unique_ptr<Graphic>
if (m_xWwFib->m_envr != 1) // !MAC as creator
{
- rpGraphic.reset(new Graphic(aWMF));
+ roGraphic.emplace(aWMF);
return true;
}
@@ -284,10 +284,10 @@ bool SwWW8ImplReader::ReadGrafFile(OUString& rFileName, std::unique_ptr<Graphic>
tools::Long nData = rPic.lcb - ( pSt->Tell() - nPosFc );
if (nData > 0)
{
- rpGraphic.reset(new Graphic());
- bOk = SwWW8ImplReader::GetPictGrafFromStream(*rpGraphic, *pSt);
+ roGraphic.emplace();
+ bOk = SwWW8ImplReader::GetPictGrafFromStream(*roGraphic, *pSt);
if (!bOk)
- rpGraphic.reset();
+ roGraphic.reset();
}
return bOk; // Contains graphic
}
@@ -415,8 +415,8 @@ SwFrameFormat* SwWW8ImplReader::ImportGraf1(WW8_PIC const & rPic, SvStream* pSt,
OUString aFileName;
bool bInDoc;
- std::unique_ptr<Graphic> pGraph;
- bool bOk = ReadGrafFile(aFileName, pGraph, rPic, pSt, nFilePos, &bInDoc);
+ std::optional<Graphic> oGraph;
+ bool bOk = ReadGrafFile(aFileName, oGraph, rPic, pSt, nFilePos, &bInDoc);
if (!bOk)
{
@@ -433,9 +433,9 @@ SwFrameFormat* SwWW8ImplReader::ImportGraf1(WW8_PIC const & rPic, SvStream* pSt,
}
if (m_xWFlyPara && m_xWFlyPara->bGrafApo)
- pRet = MakeGrafNotInContent(aPD, pGraph.get(), aFileName, aGrfSet);
+ pRet = MakeGrafNotInContent(aPD, oGraph ? &*oGraph : nullptr, aFileName, aGrfSet);
else
- pRet = MakeGrafInContent(rPic, aPD, pGraph.get(), aFileName, aGrfSet);
+ pRet = MakeGrafInContent(rPic, aPD, oGraph ? &*oGraph : nullptr, aFileName, aGrfSet);
return pRet;
}
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index fc0dcd521cdb..3a771e1076b4 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -36,6 +36,7 @@
#include <deque>
#include <map>
#include <memory>
+#include <optional>
#include "ww8struc.hxx"
#include "ww8scan.hxx"
@@ -1541,7 +1542,7 @@ private:
bool ProcessSpecial(bool &rbReSync, WW8_CP nStartCp);
sal_uInt16 TabRowSprm(int nLevel) const;
- bool ReadGrafFile(OUString& rFileName, std::unique_ptr<Graphic>& rpGraphic,
+ bool ReadGrafFile(OUString& rFileName, std::optional<Graphic>& rpGraphic,
const WW8_PIC& rPic, SvStream* pSt, sal_uLong nFilePos, bool* pDelIt);
static void ReplaceObj(const SdrObject &rReplaceTextObj,
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 79837db672b3..0907404dd0bc 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -494,12 +494,12 @@ bool SwTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDo
// SEL_GRF is from ContentType of editsh
if(bPending || ((SelectionType::Graphic | SelectionType::DrawObject | SelectionType::DbForm) & nSelectionType))
{
- m_pClpGraphic.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
- m_pOrigGraphic = m_pClpGraphic.get();
- m_pClpBitmap.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
- m_pOrigGraphic = m_pClpBitmap.get();
+ m_oClpGraphic.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_oClpGraphic ))
+ m_pOrigGraphic = &*m_oClpGraphic;
+ m_oClpBitmap.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_oClpBitmap ))
+ m_pOrigGraphic = &*m_oClpBitmap;
// is it a URL-Button ?
OUString sURL;
@@ -636,13 +636,13 @@ bool SwTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDo
case SotClipboardFormatId::GDIMETAFILE:
if( m_eBufferType & TransferBufferType::Graphic )
- bOK = SetGDIMetaFile( m_pClpGraphic->GetGDIMetaFile() );
+ bOK = SetGDIMetaFile( m_oClpGraphic->GetGDIMetaFile() );
break;
case SotClipboardFormatId::BITMAP:
case SotClipboardFormatId::PNG:
// Neither pClpBitmap nor pClpGraphic are necessarily set
- if( (m_eBufferType & TransferBufferType::Graphic) && (m_pClpBitmap != nullptr || m_pClpGraphic != nullptr))
- bOK = SetBitmapEx( (m_pClpBitmap ? m_pClpBitmap : m_pClpGraphic)->GetBitmapEx(), rFlavor );
+ if( (m_eBufferType & TransferBufferType::Graphic) && (m_oClpBitmap || m_oClpGraphic))
+ bOK = SetBitmapEx( (m_oClpBitmap ? m_oClpBitmap : m_oClpGraphic)->GetBitmapEx(), rFlavor );
break;
case SotClipboardFormatId::SVIM:
@@ -968,12 +968,12 @@ int SwTransferable::PrepareForCopy( bool bIsCut )
const SelectionType nSelection = m_pWrtShell->GetSelectionType();
if( nSelection == SelectionType::Graphic )
{
- m_pClpGraphic.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
- m_pOrigGraphic = m_pClpGraphic.get();
- m_pClpBitmap.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
- m_pOrigGraphic = m_pClpBitmap.get();
+ m_oClpGraphic.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_oClpGraphic ))
+ m_pOrigGraphic = &*m_oClpGraphic;
+ m_oClpBitmap.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_oClpBitmap ))
+ m_pOrigGraphic = &*m_oClpBitmap;
m_pClpDocFac.reset(new SwDocFac);
SwDoc& rDoc = lcl_GetDoc(*m_pClpDocFac);
@@ -1119,12 +1119,12 @@ int SwTransferable::PrepareForCopy( bool bIsCut )
}
m_eBufferType = static_cast<TransferBufferType>( TransferBufferType::Graphic | m_eBufferType );
- m_pClpGraphic.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_pClpGraphic ))
- m_pOrigGraphic = m_pClpGraphic.get();
- m_pClpBitmap.reset(new Graphic);
- if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_pClpBitmap ))
- m_pOrigGraphic = m_pClpBitmap.get();
+ m_oClpGraphic.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::GDIMETAFILE, *m_oClpGraphic ))
+ m_pOrigGraphic = &*m_oClpGraphic;
+ m_oClpBitmap.emplace();
+ if( !m_pWrtShell->GetDrawObjGraphic( SotClipboardFormatId::BITMAP, *m_oClpBitmap ))
+ m_pOrigGraphic = &*m_oClpBitmap;
// is it a URL-Button ?
OUString sURL;
diff --git a/sw/source/uibase/inc/swdtflvr.hxx b/sw/source/uibase/inc/swdtflvr.hxx
index b165cd7b6b4a..df16e3a8bd56 100644
--- a/sw/source/uibase/inc/swdtflvr.hxx
+++ b/sw/source/uibase/inc/swdtflvr.hxx
@@ -30,6 +30,7 @@
#include <o3tl/typed_flags_set.hxx>
#include <svx/swframetypes.hxx>
#include <memory>
+#include <optional>
#include <swdllapi.h>
@@ -84,8 +85,8 @@ class SW_DLLPUBLIC SwTransferable final : public TransferableHelper
SwWrtShell. */
const SwFrameShell *m_pCreatorView;
std::unique_ptr<SwDocFac, o3tl::default_delete<SwDocFac>> m_pClpDocFac;
- std::unique_ptr<Graphic> m_pClpGraphic;
- std::unique_ptr<Graphic> m_pClpBitmap;
+ std::optional<Graphic> m_oClpGraphic;
+ std::optional<Graphic> m_oClpBitmap;
Graphic *m_pOrigGraphic;
std::unique_ptr<INetBookmark> m_pBookmark; // URL and description!
std::unique_ptr<ImageMap> m_pImageMap;