diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-06-15 10:07:09 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-06-15 10:07:09 +0200 |
commit | 1888cda3ff5f6e09b0778624fe5a4cf2aaecad50 (patch) | |
tree | 40213bdd7d3a8d9bd13e62019b54fb4cf4b4c897 /sw | |
parent | 7aee0ea7c5a780bca5193382b6f73599c2f025eb (diff) |
Use unique_ptr for SwFormatClipboard members
Change-Id: I2d37be7c86481040c64de87f188320cdc3258659
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/inc/formatclipboard.hxx | 11 | ||||
-rw-r--r-- | sw/source/uibase/uiview/formatclipboard.cxx | 43 |
2 files changed, 24 insertions, 30 deletions
diff --git a/sw/source/uibase/inc/formatclipboard.hxx b/sw/source/uibase/inc/formatclipboard.hxx index 11e35cf1209e..d5564ed5cc69 100644 --- a/sw/source/uibase/inc/formatclipboard.hxx +++ b/sw/source/uibase/inc/formatclipboard.hxx @@ -20,6 +20,10 @@ #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_FORMATCLIPBOARD_HXX #define INCLUDED_SW_SOURCE_UIBASE_INC_FORMATCLIPBOARD_HXX +#include <sal/config.h> + +#include <memory> + #include <wrtsh.hxx> #include <svl/itemset.hxx> #include <svl/style.hxx> @@ -31,7 +35,6 @@ class SwFormatClipboard { public: SwFormatClipboard(); - ~SwFormatClipboard(); /** * Test if the object contains text or paragraph attribute @@ -69,13 +72,13 @@ private: SelectionType m_nSelectionType; /** automatic/named character attribute set */ - SfxItemSet* m_pItemSet_TextAttr; + std::unique_ptr<SfxItemSet> m_pItemSet_TextAttr; /** automatic/named paragraph attribute set * (it can be character attribute applied to the paragraph) */ - SfxItemSet* m_pItemSet_ParAttr; + std::unique_ptr<SfxItemSet> m_pItemSet_ParAttr; /** table attribute set */ - SfxItemSet* m_pTableItemSet; + std::unique_ptr<SfxItemSet> m_pTableItemSet; /** name of the character format (if it exist) */ OUString m_aCharStyle; diff --git a/sw/source/uibase/uiview/formatclipboard.cxx b/sw/source/uibase/uiview/formatclipboard.cxx index ec7cccef746d..6fe524d0fdb8 100644 --- a/sw/source/uibase/uiview/formatclipboard.cxx +++ b/sw/source/uibase/uiview/formatclipboard.cxx @@ -18,8 +18,11 @@ */ #include <memory> +#include <utility> + #include "formatclipboard.hxx" +#include <o3tl/make_unique.hxx> #include <svx/svxids.hrc> #include <cmdid.h> #include <charfmt.hxx> @@ -59,12 +62,12 @@ RES_PARATR_BEGIN, RES_PARATR_END -1, \ RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END -1, \ FORMAT_PAINTBRUSH_FRAME_IDS -SfxItemSet* lcl_CreateEmptyItemSet( SelectionType nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false ) +std::unique_ptr<SfxItemSet> lcl_CreateEmptyItemSet( SelectionType nSelectionType, SfxItemPool& rPool, bool bNoParagraphFormats = false ) { - SfxItemSet* pItemSet = nullptr; + std::unique_ptr<SfxItemSet> pItemSet; if( nSelectionType & (SelectionType::Frame | SelectionType::Ole | SelectionType::Graphic) ) { - pItemSet = new SfxItemSet(rPool, + pItemSet = o3tl::make_unique<SfxItemSet>(rPool, FORMAT_PAINTBRUSH_FRAME_IDS 0); } @@ -75,11 +78,11 @@ SfxItemSet* lcl_CreateEmptyItemSet( SelectionType nSelectionType, SfxItemPool& r else if( nSelectionType & SelectionType::Text ) { if( bNoParagraphFormats ) - pItemSet = new SfxItemSet(rPool, + pItemSet = o3tl::make_unique<SfxItemSet>(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END - 1, 0); else - pItemSet = new SfxItemSet(rPool, + pItemSet = o3tl::make_unique<SfxItemSet>(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END - 1, FORMAT_PAINTBRUSH_PARAGRAPH_IDS 0); @@ -225,18 +228,9 @@ void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh ) SwFormatClipboard::SwFormatClipboard() : m_nSelectionType(SelectionType::NONE) - , m_pItemSet_TextAttr(nullptr) - , m_pItemSet_ParAttr(nullptr) - , m_pTableItemSet(nullptr) , m_bPersistentCopy(false) { } -SwFormatClipboard::~SwFormatClipboard() -{ - delete m_pItemSet_TextAttr; - delete m_pItemSet_ParAttr; - delete m_pTableItemSet; -} bool SwFormatClipboard::HasContent() const { @@ -281,8 +275,8 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP m_bPersistentCopy = bPersistentCopy; SelectionType nSelectionType = rWrtShell.GetSelectionType(); - SfxItemSet* pItemSet_TextAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true ); - SfxItemSet* pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool ); + auto pItemSet_TextAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool, true ); + auto pItemSet_ParAttr = lcl_CreateEmptyItemSet( nSelectionType, rPool ); rWrtShell.StartAction(); rWrtShell.Push(); @@ -369,7 +363,7 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP if( pDrawView->AreObjectsMarked() ) { bool bOnlyHardAttr = true; - pItemSet_TextAttr = new SfxItemSet( pDrawView->GetAttrFromMarked(bOnlyHardAttr) ); + pItemSet_TextAttr = o3tl::make_unique<SfxItemSet>( pDrawView->GetAttrFromMarked(bOnlyHardAttr) ); //remove attributes defining the type/data of custom shapes pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_ENGINE); pItemSet_TextAttr->ClearItem(SDRATTR_CUSTOMSHAPE_DATA); @@ -381,7 +375,7 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP if( nSelectionType & SelectionType::TableCell )//only copy table attributes if really cells are selected (not only text in tables) { - m_pTableItemSet = new SfxItemSet(rPool, + m_pTableItemSet = o3tl::make_unique<SfxItemSet>(rPool, SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_SHADOW, //SID_ATTR_BORDER_OUTER is inbetween RES_BACKGROUND, RES_SHADOW, //RES_BOX is inbetween SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE, @@ -399,8 +393,8 @@ void SwFormatClipboard::Copy( SwWrtShell& rWrtShell, SfxItemPool& rPool, bool bP } m_nSelectionType = nSelectionType; - m_pItemSet_TextAttr = pItemSet_TextAttr; - m_pItemSet_ParAttr = pItemSet_ParAttr; + m_pItemSet_TextAttr = std::move(pItemSet_TextAttr); + m_pItemSet_ParAttr = std::move(pItemSet_ParAttr); if( nSelectionType & SelectionType::Text ) { @@ -584,14 +578,11 @@ void SwFormatClipboard::Erase() { m_nSelectionType = SelectionType::NONE; - delete m_pItemSet_TextAttr; - m_pItemSet_TextAttr = nullptr; + m_pItemSet_TextAttr.reset(); - delete m_pItemSet_ParAttr; - m_pItemSet_ParAttr = nullptr; + m_pItemSet_ParAttr.reset(); - delete m_pTableItemSet; - m_pTableItemSet = nullptr; + m_pTableItemSet.reset(); if( !m_aCharStyle.isEmpty() ) m_aCharStyle.clear(); |