improve variable scope

Change-Id: I1207c570c4bceac73b3197e11bcefcf73837d1b3
This commit is contained in:
Caolán McNamara
2017-07-15 15:02:38 +01:00
parent cbf34897f0
commit fe2dfdba10

View File

@@ -1756,15 +1756,87 @@ void DrawViewShell::GetPageProperties( SfxItemSet &rSet )
void DrawViewShell::SetPageProperties (SfxRequest& rReq) void DrawViewShell::SetPageProperties (SfxRequest& rReq)
{ {
SdPage *pPage = getCurrentPage(); SdPage *pPage = getCurrentPage();
if (!pPage)
return;
sal_uInt16 nSlotId = rReq.GetSlot(); sal_uInt16 nSlotId = rReq.GetSlot();
const SfxItemSet *pArgs = rReq.GetArgs(); 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(); SdrPageProperties& rPageProperties = pPage->getSdrPageProperties();
PageKind ePageKind = GetPageKind(); 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<const XFillStyleItem&>(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<const XFillColorItem&>(pArgs->Get( XATTR_FILLCOLOR )) );
rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) );
rPageProperties.PutItem( aColorItem );
}
break;
case(SID_ATTR_PAGE_GRADIENT):
{
XFillGradientItem aGradientItem( static_cast<const XFillGradientItem&>(pArgs->Get( XATTR_FILLGRADIENT )) );
// MigrateItemSet guarantees unique gradient names
SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} );
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<const XFillHatchItem&>(pArgs->Get( XATTR_FILLHATCH )) );
rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) );
rPageProperties.PutItem( aHatchItem );
}
break;
case(SID_ATTR_PAGE_BITMAP):
{
XFillBitmapItem aBitmapItem( static_cast<const XFillBitmapItem&>(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; const SfxPoolItem* pPoolItem = nullptr;
Size aNewSize(aSize); Size aNewSize(pPage->GetSize());
sal_Int32 nLeft = -1, nRight = -1, nUpper = -1, nLower = -1; sal_Int32 nLeft = -1, nRight = -1, nUpper = -1, nLower = -1;
bool bScaleAll = true; bool bScaleAll = true;
Orientation eOrientation = pPage->GetOrientation(); Orientation eOrientation = pPage->GetOrientation();
@@ -1772,117 +1844,44 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq)
bool bFullSize = pMasterPage->IsBackgroundFullSize(); bool bFullSize = pMasterPage->IsBackgroundFullSize();
sal_uInt16 nPaperBin = pPage->GetPaperBin(); sal_uInt16 nPaperBin = pPage->GetPaperBin();
if ( ( nSlotId >= SID_ATTR_PAGE_COLOR ) && ( nSlotId <= SID_ATTR_PAGE_FILLSTYLE ) ) switch (nSlotId)
{ {
SdrPageProperties& rPageProperties = pPage->getSdrPageProperties(); case SID_ATTR_PAGE_LRSPACE:
const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet(); if( pArgs->GetItemState(GetPool().GetWhich(SID_ATTR_PAGE_LRSPACE),
SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool()); true,&pPoolItem) == SfxItemState::SET )
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<const XFillStyleItem&>(pArgs->Get( XATTR_FILLSTYLE )) ); nLeft = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetLeft();
drawing::FillStyle eXFS = aFSItem.GetValue(); nRight = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetRight();
if (nLeft != -1 && nUpper == -1)
if ( eXFS == drawing::FillStyle_NONE )
rPageProperties.PutItem( XFillStyleItem( eXFS ) );
}
break;
case(SID_ATTR_PAGE_COLOR):
{
XFillColorItem aColorItem( static_cast<const XFillColorItem&>(pArgs->Get( XATTR_FILLCOLOR )) );
rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_SOLID ) );
rPageProperties.PutItem( aColorItem );
}
break;
case(SID_ATTR_PAGE_GRADIENT):
{
XFillGradientItem aGradientItem( static_cast<const XFillGradientItem&>(pArgs->Get( XATTR_FILLGRADIENT )) );
// MigrateItemSet guarantees unique gradient names
SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} );
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<const XFillHatchItem&>(pArgs->Get( XATTR_FILLHATCH )) );
rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_HATCH ) );
rPageProperties.PutItem( aHatchItem );
}
break;
case(SID_ATTR_PAGE_BITMAP):
{
XFillBitmapItem aBitmapItem( static_cast<const XFillBitmapItem&>(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<const SvxLongLRSpaceItem*>(pPoolItem)->GetLeft(); nUpper = pPage->GetUppBorder();
nRight = static_cast<const SvxLongLRSpaceItem*>(pPoolItem)->GetRight(); nLower = pPage->GetLwrBorder();
if (nLeft != -1 && nUpper == -1)
{
nUpper = pPage->GetUppBorder();
nLower = pPage->GetLwrBorder();
}
SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
} }
break; SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
}
case SID_ATTR_PAGE_ULSPACE:
if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE,
true,&pPoolItem) == SfxItemState::SET )
{
nUpper = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetUpper();
nLower = static_cast<const SvxLongULSpaceItem*>(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; break;
}
case SID_ATTR_PAGE_ULSPACE:
if( pArgs->GetItemState(SID_ATTR_PAGE_ULSPACE,
true,&pPoolItem) == SfxItemState::SET )
{
nUpper = static_cast<const SvxLongULSpaceItem*>(pPoolItem)->GetUpper();
nLower = static_cast<const SvxLongULSpaceItem*>(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) void DrawViewShell::GetState (SfxItemSet& rSet)
{ {
// Iterate over all requested items in the set. // Iterate over all requested items in the set.