From fe2dfdba10a0b54bd915a4186a0347672c61fcec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sat, 15 Jul 2017 15:02:38 +0100 Subject: [PATCH] improve variable scope Change-Id: I1207c570c4bceac73b3197e11bcefcf73837d1b3 --- sd/source/ui/view/drviews7.cxx | 211 ++++++++++++++++----------------- 1 file changed, 105 insertions(+), 106 deletions(-) diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx index b95669665172..97a595cc1abc 100644 --- a/sd/source/ui/view/drviews7.cxx +++ b/sd/source/ui/view/drviews7.cxx @@ -1756,15 +1756,87 @@ void DrawViewShell::GetPageProperties( SfxItemSet &rSet ) void DrawViewShell::SetPageProperties (SfxRequest& rReq) { SdPage *pPage = getCurrentPage(); + if (!pPage) + return; sal_uInt16 nSlotId = rReq.GetSlot(); const SfxItemSet *pArgs = rReq.GetArgs(); + if (!pArgs) + return; - if ( pPage && pArgs ) + if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) ) { - Size aSize = pPage->GetSize(); - PageKind ePageKind = GetPageKind(); + SdrPageProperties& rPageProperties = pPage->getSdrPageProperties(); + const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet(); + SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool()); + + rPageProperties.ClearItem(XATTR_FILLSTYLE); + rPageProperties.ClearItem(XATTR_FILLGRADIENT); + rPageProperties.ClearItem(XATTR_FILLHATCH); + rPageProperties.ClearItem(XATTR_FILLBITMAP); + + switch (nSlotId) + { + case(SID_ATTR_PAGE_FILLSTYLE): + { + XFillStyleItem aFSItem( static_cast(pArgs->Get( XATTR_FILLSTYLE )) ); + drawing::FillStyle eXFS = aFSItem.GetValue(); + + if ( eXFS == drawing::FillStyle_NONE ) + rPageProperties.PutItem( XFillStyleItem( eXFS ) ); + } + break; + + case(SID_ATTR_PAGE_COLOR): + { + XFillColorItem aColorItem( static_cast(pArgs->Get( XATTR_FILLCOLOR )) ); + rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) ); + rPageProperties.PutItem( aColorItem ); + } + break; + + case(SID_ATTR_PAGE_GRADIENT): + { + XFillGradientItem aGradientItem( static_cast(pArgs->Get( XATTR_FILLGRADIENT )) ); + + // MigrateItemSet guarantees unique gradient names + SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items{} ); + aMigrateSet.Put( aGradientItem ); + SdrModel::MigrateItemSet( &aMigrateSet, pTempSet, mpDrawView->GetModel() ); + + rPageProperties.PutItemSet( *pTempSet ); + rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_GRADIENT ) ); + } + break; + + case(SID_ATTR_PAGE_HATCH): + { + XFillHatchItem aHatchItem( static_cast(pArgs->Get( XATTR_FILLHATCH )) ); + rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) ); + rPageProperties.PutItem( aHatchItem ); + } + break; + + case(SID_ATTR_PAGE_BITMAP): + { + XFillBitmapItem aBitmapItem( static_cast(pArgs->Get( XATTR_FILLBITMAP )) ); + rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_BITMAP ) ); + rPageProperties.PutItem( aBitmapItem ); + } + break; + + default: + break; + } + + delete pTempSet; + + rReq.Done(); + } + else + { + PageKind ePageKind = GetPageKind(); const SfxPoolItem* pPoolItem = nullptr; - Size aNewSize(aSize); + Size aNewSize(pPage->GetSize()); sal_Int32 nLeft = -1, nRight = -1, nUpper = -1, nLower = -1; bool bScaleAll = true; Orientation eOrientation = pPage->GetOrientation(); @@ -1772,117 +1844,44 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq) bool bFullSize = pMasterPage->IsBackgroundFullSize(); sal_uInt16 nPaperBin = pPage->GetPaperBin(); - if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) ) + switch (nSlotId) { - SdrPageProperties& rPageProperties = pPage->getSdrPageProperties(); - const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet(); - SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool()); - - rPageProperties.ClearItem(XATTR_FILLSTYLE); - rPageProperties.ClearItem(XATTR_FILLGRADIENT); - rPageProperties.ClearItem(XATTR_FILLHATCH); - rPageProperties.ClearItem(XATTR_FILLBITMAP); - - switch (nSlotId) - { - case(SID_ATTR_PAGE_FILLSTYLE): + case SID_ATTR_PAGE_LRSPACE: + if( pArgs->GetItemState(GetPool().GetWhich(SID_ATTR_PAGE_LRSPACE), + true,&pPoolItem) == SfxItemState::SET ) { - XFillStyleItem aFSItem( static_cast(pArgs->Get( XATTR_FILLSTYLE )) ); - drawing::FillStyle eXFS = aFSItem.GetValue(); - - if ( eXFS == drawing::FillStyle_NONE ) - rPageProperties.PutItem( XFillStyleItem( eXFS ) ); - } - break; - - case(SID_ATTR_PAGE_COLOR): - { - XFillColorItem aColorItem( static_cast(pArgs->Get( XATTR_FILLCOLOR )) ); - rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) ); - rPageProperties.PutItem( aColorItem ); - } - break; - - case(SID_ATTR_PAGE_GRADIENT): - { - XFillGradientItem aGradientItem( static_cast(pArgs->Get( XATTR_FILLGRADIENT )) ); - - // MigrateItemSet guarantees unique gradient names - SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items{} ); - aMigrateSet.Put( aGradientItem ); - SdrModel::MigrateItemSet( &aMigrateSet, pTempSet, mpDrawView->GetModel() ); - - rPageProperties.PutItemSet( *pTempSet ); - rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_GRADIENT ) ); - } - break; - - case(SID_ATTR_PAGE_HATCH): - { - XFillHatchItem aHatchItem( static_cast(pArgs->Get( XATTR_FILLHATCH )) ); - rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) ); - rPageProperties.PutItem( aHatchItem ); - } - break; - - case(SID_ATTR_PAGE_BITMAP): - { - XFillBitmapItem aBitmapItem( static_cast(pArgs->Get( XATTR_FILLBITMAP )) ); - rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_BITMAP ) ); - rPageProperties.PutItem( aBitmapItem ); - } - break; - - default: - break; - } - - delete pTempSet; - - rReq.Done(); - } - else - { - switch (nSlotId) - { - case SID_ATTR_PAGE_LRSPACE: - if( pArgs->GetItemState(GetPool().GetWhich(SID_ATTR_PAGE_LRSPACE), - true,&pPoolItem) == SfxItemState::SET ) + nLeft = static_cast(pPoolItem)->GetLeft(); + nRight = static_cast(pPoolItem)->GetRight(); + if (nLeft != -1 && nUpper == -1) { - nLeft = static_cast(pPoolItem)->GetLeft(); - nRight = static_cast(pPoolItem)->GetRight(); - if (nLeft != -1 && nUpper == -1) - { - nUpper = pPage->GetUppBorder(); - nLower = pPage->GetLwrBorder(); - } - SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize ); + nUpper = pPage->GetUppBorder(); + nLower = pPage->GetLwrBorder(); } - break; - - case SID_ATTR_PAGE_ULSPACE: - if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE, - true,&pPoolItem) == SfxItemState::SET ) - { - nUpper = static_cast(pPoolItem)->GetUpper(); - nLower = static_cast(pPoolItem)->GetLower(); - if (nLeft == -1 && nUpper != -1) - { - nLeft = pPage->GetLftBorder(); - nRight = pPage->GetRgtBorder(); - } - SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize ); - } - break; - - default: + SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize ); + } break; - } + + case SID_ATTR_PAGE_ULSPACE: + if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE, + true,&pPoolItem) == SfxItemState::SET ) + { + nUpper = static_cast(pPoolItem)->GetUpper(); + nLower = static_cast(pPoolItem)->GetLower(); + if (nLeft == -1 && nUpper != -1) + { + nLeft = pPage->GetLftBorder(); + nRight = pPage->GetRgtBorder(); + } + SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize ); + } + break; + + default: + break; } } } - void DrawViewShell::GetState (SfxItemSet& rSet) { // Iterate over all requested items in the set.