Kaydet (Commit) 98194383 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SfxCommonTemplateDialog_Impl

Change-Id: I204d9ea555e35d8822c01f43172dad53b04c60fb
Reviewed-on: https://gerrit.libreoffice.org/54171Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 0f53efef
...@@ -679,9 +679,6 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl ...@@ -679,9 +679,6 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl
aFmtLb->SetFont( aFont ); aFmtLb->SetFont( aFont );
aPreviewCheckbox->Check(officecfg::Office::Common::StylesAndFormatting::Preview::get()); aPreviewCheckbox->Check(officecfg::Office::Common::StylesAndFormatting::Preview::get());
aPreviewCheckbox->SetText( SfxResId(STR_PREVIEW_CHECKBOX) ); aPreviewCheckbox->SetText( SfxResId(STR_PREVIEW_CHECKBOX) );
memset(pBoundItems, 0, sizeof(pBoundItems));
memset(pFamilyState, 0, sizeof(pFamilyState));
} }
sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId) sal_uInt16 SfxCommonTemplateDialog_Impl::StyleNrToInfoOffset(sal_uInt16 nId)
...@@ -700,16 +697,16 @@ void SfxTemplateDialog_Impl::EnableEdit(bool bEnable) ...@@ -700,16 +697,16 @@ void SfxTemplateDialog_Impl::EnableEdit(bool bEnable)
void SfxCommonTemplateDialog_Impl::ReadResource() void SfxCommonTemplateDialog_Impl::ReadResource()
{ {
// Read global user resource // Read global user resource
for(SfxTemplateItem* & rp : pFamilyState) for (auto & i : pFamilyState)
rp = nullptr; i.reset();
SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame(); SfxViewFrame* pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame();
pCurObjShell = pViewFrame->GetObjectShell(); pCurObjShell = pViewFrame->GetObjectShell();
pModule = pCurObjShell ? pCurObjShell->GetModule() : nullptr; pModule = pCurObjShell ? pCurObjShell->GetModule() : nullptr;
if (pModule) if (pModule)
pStyleFamilies = pModule->CreateStyleFamilies(); pStyleFamilies.reset(pModule->CreateStyleFamilies());
if (!pStyleFamilies) if (!pStyleFamilies)
pStyleFamilies = new SfxStyleFamilies; pStyleFamilies.reset(new SfxStyleFamilies);
nActFilter = 0xffff; nActFilter = 0xffff;
if (pCurObjShell) if (pCurObjShell)
...@@ -745,25 +742,25 @@ void SfxCommonTemplateDialog_Impl::ReadResource() ...@@ -745,25 +742,25 @@ void SfxCommonTemplateDialog_Impl::ReadResource()
nSlot = SID_STYLE_FAMILY6; break; nSlot = SID_STYLE_FAMILY6; break;
default: OSL_FAIL("unknown StyleFamily"); break; default: OSL_FAIL("unknown StyleFamily"); break;
} }
pBoundItems[i] = pBoundItems[i].reset(
new SfxTemplateControllerItem(nSlot, *this, *pBindings); new SfxTemplateControllerItem(nSlot, *this, *pBindings) );
} }
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_WATERCAN, *this, *pBindings); SID_STYLE_WATERCAN, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings); SID_STYLE_NEW_BY_EXAMPLE, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings); SID_STYLE_UPDATE_BY_EXAMPLE, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_NEW, *this, *pBindings); SID_STYLE_NEW, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_DRAGHIERARCHIE, *this, *pBindings); SID_STYLE_DRAGHIERARCHIE, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_EDIT, *this, *pBindings); SID_STYLE_EDIT, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_DELETE, *this, *pBindings); SID_STYLE_DELETE, *this, *pBindings) );
pBoundItems[i++] = new SfxTemplateControllerItem( pBoundItems[i++].reset( new SfxTemplateControllerItem(
SID_STYLE_FAMILY, *this, *pBindings); SID_STYLE_FAMILY, *this, *pBindings) );
pBindings->LEAVEREGISTRATIONS(); pBindings->LEAVEREGISTRATIONS();
for(; i < COUNT_BOUND_FUNC; ++i) for(; i < COUNT_BOUND_FUNC; ++i)
...@@ -805,13 +802,11 @@ void SfxCommonTemplateDialog_Impl::ClearResource() ...@@ -805,13 +802,11 @@ void SfxCommonTemplateDialog_Impl::ClearResource()
void SfxCommonTemplateDialog_Impl::impl_clear() void SfxCommonTemplateDialog_Impl::impl_clear()
{ {
delete pStyleFamilies; pStyleFamilies.reset();
pStyleFamilies = nullptr; for (auto & i : pFamilyState)
sal_uInt16 i; i.reset();
for ( i = 0; i < MAX_FAMILIES; ++i ) for (auto & i : pBoundItems)
DELETEZ(pFamilyState[i]); i.reset();
for ( i = 0; i < COUNT_BOUND_FUNC; ++i )
delete pBoundItems[i];
pCurObjShell = nullptr; pCurObjShell = nullptr;
} }
...@@ -1053,7 +1048,7 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox() ...@@ -1053,7 +1048,7 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
EnableItem(SID_STYLE_WATERCAN, false); EnableItem(SID_STYLE_WATERCAN, false);
SfxTemplateItem* pState = pFamilyState[nActFamily - 1]; SfxTemplateItem* pState = pFamilyState[nActFamily - 1].get();
if (nCount) if (nCount)
pTreeBox->Expand(pTreeBox->First()); pTreeBox->Expand(pTreeBox->First());
...@@ -1089,16 +1084,14 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(StyleFlags nFlags) ...@@ -1089,16 +1084,14 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(StyleFlags nFlags)
if (!pItem) if (!pItem)
{ {
// Is the case for the template catalog // Is the case for the template catalog
SfxTemplateItem **ppItem = pFamilyState;
const size_t nFamilyCount = pStyleFamilies->size(); const size_t nFamilyCount = pStyleFamilies->size();
size_t n; size_t n;
for( n = 0; n < nFamilyCount; n++ ) for( n = 0; n < nFamilyCount; n++ )
if( ppItem[ StyleNrToInfoOffset(n) ] ) break; if( pFamilyState[ StyleNrToInfoOffset(n) ] ) break;
if ( n == nFamilyCount ) if ( n == nFamilyCount )
// It happens sometimes, God knows why // It happens sometimes, God knows why
return; return;
ppItem += StyleNrToInfoOffset(n); nAppFilter = pFamilyState[StyleNrToInfoOffset(n)]->GetValue();
nAppFilter = (*ppItem)->GetValue();
FamilySelect( StyleNrToInfoOffset(n)+1 ); FamilySelect( StyleNrToInfoOffset(n)+1 );
pItem = GetFamilyItem_Impl(); pItem = GetFamilyItem_Impl();
} }
...@@ -1211,7 +1204,7 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(StyleFlags nFlags) ...@@ -1211,7 +1204,7 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(StyleFlags nFlags)
aFmtLb->SetUpdateMode(true); aFmtLb->SetUpdateMode(true);
} }
// Selects the current style if any // Selects the current style if any
SfxTemplateItem *pState = pFamilyState[nActFamily-1]; SfxTemplateItem *pState = pFamilyState[nActFamily-1].get();
OUString aStyle; OUString aStyle;
if(pState) if(pState)
aStyle = pState->GetStyleName(); aStyle = pState->GetStyleName();
...@@ -1256,7 +1249,7 @@ void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem) ...@@ -1256,7 +1249,7 @@ void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
pBindings->EnterRegistrations(); pBindings->EnterRegistrations();
for(size_t n = 0; n < nCount; n++) for(size_t n = 0; n < nCount; n++)
{ {
SfxControllerItem *pCItem=pBoundItems[n]; SfxControllerItem *pCItem=pBoundItems[n].get();
bool bChecked = pItem && pItem->GetValue(); bool bChecked = pItem && pItem->GetValue();
if( pCItem->IsBound() == bChecked ) if( pCItem->IsBound() == bChecked )
{ {
...@@ -1275,9 +1268,9 @@ void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem) ...@@ -1275,9 +1268,9 @@ void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem)
void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem ) void SfxCommonTemplateDialog_Impl::SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* pItem )
{ {
sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START; sal_uInt16 nIdx = nSlotId - SID_STYLE_FAMILY_START;
DELETEZ(pFamilyState[nIdx]); pFamilyState[nIdx].reset();
if ( pItem ) if ( pItem )
pFamilyState[nIdx] = new SfxTemplateItem(*pItem); pFamilyState[nIdx].reset( new SfxTemplateItem(*pItem) );
bUpdate = true; bUpdate = true;
// If used templates (how the hell you find this out??) // If used templates (how the hell you find this out??)
...@@ -1330,19 +1323,18 @@ void SfxCommonTemplateDialog_Impl::Update_Impl() ...@@ -1330,19 +1323,18 @@ void SfxCommonTemplateDialog_Impl::Update_Impl()
SfxTemplateItem *pItem = nullptr; SfxTemplateItem *pItem = nullptr;
// current region not within the allowed region or default // current region not within the allowed region or default
if(nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1] ) ) if(nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1].get() ) )
{ {
CheckItem(nActFamily, false); CheckItem(nActFamily, false);
SfxTemplateItem **ppItem = pFamilyState;
const size_t nFamilyCount = pStyleFamilies->size(); const size_t nFamilyCount = pStyleFamilies->size();
size_t n; size_t n;
for( n = 0; n < nFamilyCount; n++ ) for( n = 0; n < nFamilyCount; n++ )
if( ppItem[ StyleNrToInfoOffset(n) ] ) break; if( pFamilyState[ StyleNrToInfoOffset(n) ] ) break;
ppItem+=StyleNrToInfoOffset(n);
nAppFilter = (*ppItem)->GetValue(); std::unique_ptr<SfxTemplateItem> & pNewItem = pFamilyState[StyleNrToInfoOffset(n)];
nAppFilter = pNewItem->GetValue();
FamilySelect( StyleNrToInfoOffset(n) + 1 ); FamilySelect( StyleNrToInfoOffset(n) + 1 );
pItem = *ppItem; pItem = pNewItem.get();
} }
else if( bDocChanged ) else if( bDocChanged )
{ {
...@@ -1393,7 +1385,7 @@ IMPL_LINK_NOARG( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, void ) ...@@ -1393,7 +1385,7 @@ IMPL_LINK_NOARG( SfxCommonTemplateDialog_Impl, TimeOut, Timer *, void )
else else
{ {
FillTreeBox(); FillTreeBox();
SfxTemplateItem *pState = pFamilyState[nActFamily-1]; SfxTemplateItem *pState = pFamilyState[nActFamily-1].get();
if(pState) if(pState)
{ {
const OUString aStyle(pState->GetStyleName()); const OUString aStyle(pState->GetStyleName());
......
...@@ -23,6 +23,7 @@ class SfxTemplateControllerItem; ...@@ -23,6 +23,7 @@ class SfxTemplateControllerItem;
#include <sal/config.h> #include <sal/config.h>
#include <array>
#include <memory> #include <memory>
#include <vcl/button.hxx> #include <vcl/button.hxx>
...@@ -170,7 +171,7 @@ protected: ...@@ -170,7 +171,7 @@ protected:
friend class SfxTemplateControllerItem; friend class SfxTemplateControllerItem;
SfxBindings* pBindings; SfxBindings* pBindings;
SfxTemplateControllerItem* pBoundItems[COUNT_BOUND_FUNC]; std::array<std::unique_ptr<SfxTemplateControllerItem>, COUNT_BOUND_FUNC> pBoundItems;
VclPtr<vcl::Window> pWindow; VclPtr<vcl::Window> pWindow;
std::unique_ptr<VclBuilder> mxBuilder; std::unique_ptr<VclBuilder> mxBuilder;
...@@ -179,8 +180,8 @@ protected: ...@@ -179,8 +180,8 @@ protected:
SfxModule* pModule; SfxModule* pModule;
std::unique_ptr<Idle> pIdle; std::unique_ptr<Idle> pIdle;
SfxStyleFamilies* pStyleFamilies; std::unique_ptr<SfxStyleFamilies> pStyleFamilies;
SfxTemplateItem* pFamilyState[MAX_FAMILIES]; std::array<std::unique_ptr<SfxTemplateItem>, MAX_FAMILIES> pFamilyState;
SfxStyleSheetBasePool* pStyleSheetPool; SfxStyleSheetBasePool* pStyleSheetPool;
VclPtr<StyleTreeListBox_Impl> pTreeBox; VclPtr<StyleTreeListBox_Impl> pTreeBox;
SfxObjectShell* pCurObjShell; SfxObjectShell* pCurObjShell;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment