1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <fupage.hxx>
21 
22 // arrange Tab-Page
23 
24 #include <sfx2/sfxdlg.hxx>
25 #include <svx/pageitem.hxx>
26 #include <svx/svxids.hrc>
27 #include <svl/itempool.hxx>
28 #include <svl/grabbagitem.hxx>
29 #include <sfx2/request.hxx>
30 #include <vcl/prntypes.hxx>
31 #include <vcl/graphicfilter.hxx>
32 #include <stlsheet.hxx>
33 #include <editeng/eeitem.hxx>
34 #include <editeng/frmdiritem.hxx>
35 #include <svx/graphichelper.hxx>
36 #include <svx/xfillit0.hxx>
37 #include <svx/xbtmpit.hxx>
38 #include <svx/xflbstit.hxx>
39 #include <svx/xflbmtit.hxx>
40 #include <svx/xflgrit.hxx>
41 #include <svx/xflhtit.hxx>
42 #include <editeng/ulspitem.hxx>
43 #include <editeng/lrspitem.hxx>
44 #include <svx/sdr/properties/properties.hxx>
45 #include <editeng/shaditem.hxx>
46 #include <editeng/boxitem.hxx>
47 #include <editeng/sizeitem.hxx>
48 #include <editeng/pbinitem.hxx>
49 #include <sfx2/opengrf.hxx>
50 
51 #include <strings.hrc>
52 #include <sdpage.hxx>
53 #include <View.hxx>
54 #include <Window.hxx>
55 #include <pres.hxx>
56 #include <drawdoc.hxx>
57 #include <DrawDocShell.hxx>
58 #include <ViewShell.hxx>
59 #include <DrawViewShell.hxx>
60 #include <app.hrc>
61 #include <unchss.hxx>
62 #include <undoback.hxx>
63 #include <sdabstdlg.hxx>
64 #include <sdresid.hxx>
65 
66 #include <memory>
67 
68 using namespace com::sun::star;
69 
70 namespace sd {
71 
72 // 50 cm 28350
73 // adapted from writer
74 #define MAXHEIGHT 28350
75 #define MAXWIDTH  28350
76 
77 
mergeItemSetsImpl(SfxItemSet & rTarget,const SfxItemSet & rSource)78 static void mergeItemSetsImpl( SfxItemSet& rTarget, const SfxItemSet& rSource )
79 {
80     const sal_uInt16* pPtr = rSource.GetRanges();
81     sal_uInt16 p1, p2;
82     while( *pPtr )
83     {
84         p1 = pPtr[0];
85         p2 = pPtr[1];
86 
87         // make ranges discrete
88         while(pPtr[2] && (pPtr[2] - p2 == 1))
89         {
90             p2 = pPtr[3];
91             pPtr += 2;
92         }
93         rTarget.MergeRange( p1, p2 );
94         pPtr += 2;
95     }
96 
97     rTarget.Put(rSource);
98 }
99 
FuPage(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)100 FuPage::FuPage( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
101                  SdDrawDocument* pDoc, SfxRequest& rReq )
102 :   FuPoor(pViewSh, pWin, pView, pDoc, rReq),
103     mrReq(rReq),
104     mpArgs( rReq.GetArgs() ),
105     mbPageBckgrdDeleted( false ),
106     mbMasterPage( false ),
107     mbDisplayBackgroundTabPage( true ),
108     mpPage(nullptr),
109     mpDrawViewShell(nullptr)
110 {
111 }
112 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)113 rtl::Reference<FuPoor> FuPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
114 {
115     rtl::Reference<FuPoor> xFunc( new FuPage( pViewSh, pWin, pView, pDoc, rReq ) );
116     xFunc->DoExecute(rReq);
117     return xFunc;
118 }
119 
DoExecute(SfxRequest & rReq)120 void FuPage::DoExecute(SfxRequest& rReq)
121 {
122     mpDrawViewShell = dynamic_cast<DrawViewShell*>(mpViewShell);
123     DBG_ASSERT( mpDrawViewShell, "sd::FuPage::FuPage(), called without a current DrawViewShell!" );
124 
125     if( mpDrawViewShell )
126     {
127         mbMasterPage = mpDrawViewShell->GetEditMode() == EditMode::MasterPage;
128         // we don't really want to format page background with SID_ATTR_PAGE[_SIZE] slots
129         mbDisplayBackgroundTabPage = ( mpDrawViewShell->GetPageKind() == PageKind::Standard) &&
130                                       ( nSlotId != SID_ATTR_PAGE_SIZE) && ( nSlotId != SID_ATTR_PAGE );
131         mpPage = mpDrawViewShell->getCurrentPage();
132     }
133 
134     if( !mpPage )
135         return;
136 
137     // if there are no arguments given, open the dialog
138     const SfxPoolItem* pItem;
139     if (!mpArgs || mpArgs->GetItemState(SID_SELECT_BACKGROUND, true, &pItem) == SfxItemState::SET)
140     {
141         mpView->SdrEndTextEdit();
142         mpArgs = ExecuteDialog(mpWindow ? mpWindow->GetFrameWeld() : nullptr, rReq);
143     }
144 
145     // if we now have arguments, apply them to current page
146     if( mpArgs )
147     {
148         ApplyItemSet( mpArgs );
149     }
150 }
151 
~FuPage()152 FuPage::~FuPage()
153 {
154 }
155 
Activate()156 void FuPage::Activate()
157 {
158 }
159 
Deactivate()160 void FuPage::Deactivate()
161 {
162 }
163 
MergePageBackgroundFilling(SdPage * pPage,SdStyleSheet * pStyleSheet,bool bMasterPage,SfxItemSet & rMergedAttr)164 void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr)
165 {
166     if (bMasterPage)
167     {
168         if (pStyleSheet)
169             mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
170     }
171     else
172     {
173         // Only this page, get attributes for background fill
174         const SfxItemSet& rBackgroundAttributes = pPage->getSdrPageProperties().GetItemSet();
175 
176         if(drawing::FillStyle_NONE != rBackgroundAttributes.Get(XATTR_FILLSTYLE).GetValue())
177         {
178             // page attributes are used, take them
179             rMergedAttr.Put(rBackgroundAttributes);
180         }
181         else
182         {
183             if(pStyleSheet
184                 && drawing::FillStyle_NONE != pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE).GetValue())
185             {
186                 // if the page has no fill style, use the settings from the
187                 // background stylesheet (if used)
188                 mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
189             }
190             else
191             {
192                 // no fill style from page, start with no fill style
193                 rMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
194             }
195         }
196     }
197 }
198 
ExecuteDialog(weld::Window * pParent,const SfxRequest & rReq)199 const SfxItemSet* FuPage::ExecuteDialog(weld::Window* pParent, const SfxRequest& rReq)
200 {
201     if (!mpDrawViewShell)
202         return nullptr;
203 
204     SfxItemSet aNewAttr(mpDoc->GetPool(), {
205                                               { XATTR_FILL_FIRST, XATTR_FILL_LAST },
206                                               { EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR },
207                                               { SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_OUTER },
208                                               { SID_ATTR_BORDER_SHADOW, SID_ATTR_BORDER_SHADOW },
209                                               { SID_ATTR_PAGE, SID_ATTR_PAGE_SHARED },
210                                               { SID_ATTR_CHAR_GRABBAG, SID_ATTR_CHAR_GRABBAG },
211                                               { SID_ATTR_PAGE_COLOR, SID_ATTR_PAGE_FILLSTYLE },
212                                           });
213     // Keep it sorted
214     aNewAttr.MergeRange(mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE),
215                         mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE));
216 
217     // Retrieve additional data for dialog
218 
219     SvxShadowItem aShadowItem(SID_ATTR_BORDER_SHADOW);
220     aNewAttr.Put( aShadowItem );
221     SvxBoxItem aBoxItem( SID_ATTR_BORDER_OUTER );
222     aNewAttr.Put( aBoxItem );
223 
224     aNewAttr.Put( SvxFrameDirectionItem(
225         mpDoc->GetDefaultWritingMode() == css::text::WritingMode_RL_TB ? SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB,
226         EE_PARA_WRITINGDIR ) );
227 
228     // Retrieve page-data for dialog
229 
230     SvxPageItem aPageItem( SID_ATTR_PAGE );
231     aPageItem.SetDescName( mpPage->GetName() );
232     aPageItem.SetPageUsage( SvxPageUsage::All );
233     aPageItem.SetLandscape( mpPage->GetOrientation() == Orientation::Landscape );
234     aPageItem.SetNumType( mpDoc->GetPageNumType() );
235     aNewAttr.Put( aPageItem );
236 
237     // size
238     maSize = mpPage->GetSize();
239     SvxSizeItem aSizeItem( SID_ATTR_PAGE_SIZE, maSize );
240     aNewAttr.Put( aSizeItem );
241 
242     // Max size
243     SvxSizeItem aMaxSizeItem( SID_ATTR_PAGE_MAXSIZE, Size( MAXWIDTH, MAXHEIGHT ) );
244     aNewAttr.Put( aMaxSizeItem );
245 
246     // paperbin
247     SvxPaperBinItem aPaperBinItem( SID_ATTR_PAGE_PAPERBIN, static_cast<sal_uInt8>(mpPage->GetPaperBin()) );
248     aNewAttr.Put( aPaperBinItem );
249 
250     SvxLRSpaceItem aLRSpaceItem( static_cast<sal_uInt16>(mpPage->GetLeftBorder()), static_cast<sal_uInt16>(mpPage->GetRightBorder()), 0, 0, mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE));
251     aNewAttr.Put( aLRSpaceItem );
252 
253     SvxULSpaceItem aULSpaceItem( static_cast<sal_uInt16>(mpPage->GetUpperBorder()), static_cast<sal_uInt16>(mpPage->GetLowerBorder()), mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE));
254     aNewAttr.Put( aULSpaceItem );
255 
256     // Application
257     bool bScale = mpDoc->GetDocumentType() != DocumentType::Draw;
258     aNewAttr.Put( SfxBoolItem( SID_ATTR_PAGE_EXT1, bScale ) );
259 
260     bool bFullSize = mpPage->IsMasterPage() ?
261         mpPage->IsBackgroundFullSize() : static_cast<SdPage&>(mpPage->TRG_GetMasterPage()).IsBackgroundFullSize();
262 
263     SfxGrabBagItem grabBag(SID_ATTR_CHAR_GRABBAG);
264     grabBag.GetGrabBag()["BackgroundFullSize"] <<= bFullSize;
265     aNewAttr.Put(grabBag);
266 
267     // Merge ItemSet for dialog
268 
269     const sal_uInt16* pPtr = aNewAttr.GetRanges();
270     sal_uInt16 p1 = pPtr[0], p2 = pPtr[1];
271     while(pPtr[2] && (pPtr[2] - p2 == 1))
272     {
273         p2 = pPtr[3];
274         pPtr += 2;
275     }
276     SfxItemSet aMergedAttr( *aNewAttr.GetPool(), {{p1, p2}} );
277 
278     mergeItemSetsImpl( aMergedAttr, aNewAttr );
279 
280     SdStyleSheet* pStyleSheet = mpPage->getPresentationStyle(HID_PSEUDOSHEET_BACKGROUND);
281 
282     // merge page background filling to the dialogs input set
283     if( mbDisplayBackgroundTabPage )
284     {
285         MergePageBackgroundFilling(mpPage, pStyleSheet, mbMasterPage, aMergedAttr);
286     }
287 
288     std::unique_ptr< SfxItemSet > pTempSet;
289 
290     const sal_uInt16 nId = GetSlotID();
291     if (nId == SID_SAVE_BACKGROUND)
292     {
293         const XFillStyleItem& rStyleItem = aMergedAttr.Get(XATTR_FILLSTYLE);
294         if (drawing::FillStyle_BITMAP == rStyleItem.GetValue())
295         {
296             const XFillBitmapItem& rBitmap = aMergedAttr.Get(XATTR_FILLBITMAP);
297             const GraphicObject& rGraphicObj = rBitmap.GetGraphicObject();
298             GraphicHelper::ExportGraphic(pParent, rGraphicObj.GetGraphic(), "");
299         }
300     }
301     else if (nId == SID_SELECT_BACKGROUND)
302     {
303         Graphic aGraphic;
304         ErrCode nError = ERRCODE_GRFILTER_OPENERROR;
305 
306         const SfxItemSet* pArgs = rReq.GetArgs();
307         const SfxPoolItem* pItem;
308 
309         if (pArgs && pArgs->GetItemState(SID_SELECT_BACKGROUND, true, &pItem) == SfxItemState::SET)
310         {
311             OUString aFileName(static_cast<const SfxStringItem*>(pItem)->GetValue());
312             OUString aFilterName;
313 
314             if (pArgs->GetItemState(FN_PARAM_FILTER, true, &pItem) == SfxItemState::SET)
315                 aFilterName = static_cast<const SfxStringItem*>(pItem)->GetValue();
316 
317             nError = GraphicFilter::LoadGraphic(aFileName, aFilterName, aGraphic,
318                                                 &GraphicFilter::GetGraphicFilter());
319         }
320         else
321         {
322             SvxOpenGraphicDialog aDlg(SdResId(STR_SET_BACKGROUND_PICTURE), pParent);
323 
324             nError = aDlg.Execute();
325             if (nError == ERRCODE_NONE)
326             {
327                 nError = aDlg.GetGraphic(aGraphic);
328             }
329         }
330 
331         if (nError == ERRCODE_NONE)
332         {
333             pTempSet.reset( new SfxItemSet( mpDoc->GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}) );
334 
335             pTempSet->Put( XFillStyleItem( drawing::FillStyle_BITMAP ) );
336 
337             // MigrateItemSet makes sure the XFillBitmapItem will have a unique name
338             SfxItemSet aMigrateSet( mpDoc->GetPool(), svl::Items<XATTR_FILLBITMAP, XATTR_FILLBITMAP>{} );
339             aMigrateSet.Put(XFillBitmapItem("background", aGraphic));
340             SdrModel::MigrateItemSet( &aMigrateSet, pTempSet.get(), mpDoc );
341 
342             pTempSet->Put( XFillBmpStretchItem( true ));
343             pTempSet->Put( XFillBmpTileItem( false ));
344         }
345     }
346 
347     else
348     {
349         bool bIsImpressDoc = mpDrawViewShell->GetDoc()->GetDocumentType() == DocumentType::Impress;
350 
351         // create the dialog
352         SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
353         ScopedVclPtr<SfxAbstractTabDialog> pDlg( pFact->CreateSdTabPageDialog(mpViewShell->GetFrameWeld(), &aMergedAttr, mpDocSh, mbDisplayBackgroundTabPage, bIsImpressDoc) );
354         if( pDlg->Execute() == RET_OK )
355             pTempSet.reset( new SfxItemSet(*pDlg->GetOutputItemSet()) );
356     }
357 
358     if (pTempSet && pStyleSheet)
359     {
360         pStyleSheet->AdjustToFontHeight(*pTempSet);
361 
362         if( mbDisplayBackgroundTabPage )
363         {
364             // if some fillstyle-items are not set in the dialog, then
365             // try to use the items before
366             bool bChanges = false;
367             for( sal_uInt16 i=XATTR_FILL_FIRST; i<XATTR_FILL_LAST; i++ )
368             {
369                 if( aMergedAttr.GetItemState( i ) != SfxItemState::DEFAULT )
370                 {
371                     if( pTempSet->GetItemState( i ) == SfxItemState::DEFAULT )
372                         pTempSet->Put( aMergedAttr.Get( i ) );
373                     else
374                         if( aMergedAttr.GetItem( i ) != pTempSet->GetItem( i ) )
375                             bChanges = true;
376                 }
377             }
378 
379             // if the background for this page was set to invisible, the background-object has to be deleted, too.
380             const XFillStyleItem* pTempFillStyleItem = pTempSet->GetItem<XFillStyleItem>(XATTR_FILLSTYLE);
381             assert(pTempFillStyleItem);
382             if (pTempFillStyleItem->GetValue() == drawing::FillStyle_NONE)
383                 mbPageBckgrdDeleted = true;
384             else
385             {
386                 if (pTempSet->GetItemState(XATTR_FILLSTYLE) == SfxItemState::DEFAULT)
387                 {
388                     const XFillStyleItem* pMergedFillStyleItem = aMergedAttr.GetItem<XFillStyleItem>(XATTR_FILLSTYLE);
389                     assert(pMergedFillStyleItem);
390                     if (pMergedFillStyleItem->GetValue() == drawing::FillStyle_NONE)
391                         mbPageBckgrdDeleted = true;
392                 }
393             }
394 
395             const XFillGradientItem* pTempGradItem = pTempSet->GetItem<XFillGradientItem>(XATTR_FILLGRADIENT);
396             if (pTempGradItem && pTempGradItem->GetName().isEmpty())
397             {
398                 // MigrateItemSet guarantees unique gradient names
399                 SfxItemSet aMigrateSet( mpDoc->GetPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} );
400                 aMigrateSet.Put( XFillGradientItem("gradient", pTempGradItem->GetGradientValue()) );
401                 SdrModel::MigrateItemSet( &aMigrateSet, pTempSet.get(), mpDoc);
402             }
403 
404             const XFillHatchItem* pTempHatchItem = pTempSet->GetItem<XFillHatchItem>(XATTR_FILLHATCH);
405             if (pTempHatchItem && pTempHatchItem->GetName().isEmpty())
406             {
407                 // MigrateItemSet guarantees unique hatch names
408                 SfxItemSet aMigrateSet( mpDoc->GetPool(), svl::Items<XATTR_FILLHATCH, XATTR_FILLHATCH>{} );
409                 aMigrateSet.Put( XFillHatchItem("hatch", pTempHatchItem->GetHatchValue()) );
410                 SdrModel::MigrateItemSet( &aMigrateSet, pTempSet.get(), mpDoc);
411             }
412 
413             if( !mbMasterPage && bChanges && mbPageBckgrdDeleted )
414             {
415                  mpBackgroundObjUndoAction.reset( new SdBackgroundObjUndoAction(
416                      *mpDoc, *mpPage, mpPage->getSdrPageProperties().GetItemSet()) );
417 
418                  if(!mpPage->IsMasterPage())
419                  {
420                      // on normal pages, switch off fill attribute usage
421                      SdrPageProperties& rPageProperties = mpPage->getSdrPageProperties();
422                      rPageProperties.ClearItem( XATTR_FILLBITMAP );
423                      rPageProperties.ClearItem( XATTR_FILLGRADIENT );
424                      rPageProperties.ClearItem( XATTR_FILLHATCH );
425                      rPageProperties.PutItem(XFillStyleItem(drawing::FillStyle_NONE));
426                  }
427             }
428 
429 
430             /* Special treatment: reset the INVALIDS to
431                NULL-Pointer (otherwise INVALIDs or pointer point
432                to DefaultItems in the template; both would
433                prevent the attribute inheritance) */
434             pTempSet->ClearInvalidItems();
435 
436             if( mbMasterPage )
437             {
438                 mpDocSh->GetUndoManager()->AddUndoAction(std::make_unique<StyleSheetUndoAction>(
439                     mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), &(*pTempSet)));
440                 pStyleSheet->GetItemSet().Put( *pTempSet );
441                 sdr::properties::CleanupFillProperties( pStyleSheet->GetItemSet() );
442                 pStyleSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
443             }
444 
445             // if background filling is set to master pages then clear from page set
446             if( mbMasterPage )
447             {
448                 for( sal_uInt16 nWhich = XATTR_FILL_FIRST; nWhich <= XATTR_FILL_LAST; nWhich++ )
449                 {
450                     pTempSet->ClearItem( nWhich );
451                 }
452                 pTempSet->Put(XFillStyleItem(drawing::FillStyle_NONE));
453             }
454 
455             const SfxPoolItem *pItem;
456             if( SfxItemState::SET == pTempSet->GetItemState( EE_PARA_WRITINGDIR, false, &pItem ) )
457             {
458                 SvxFrameDirection nVal = static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue();
459                 mpDoc->SetDefaultWritingMode( nVal == SvxFrameDirection::Horizontal_RL_TB ? css::text::WritingMode_RL_TB : css::text::WritingMode_LR_TB );
460             }
461 
462             mpDoc->SetChanged();
463 
464             // BackgroundFill of Masterpage: no hard attributes allowed
465             SdrPage& rUsedMasterPage = mpPage->IsMasterPage() ? *mpPage : mpPage->TRG_GetMasterPage();
466             OSL_ENSURE(rUsedMasterPage.IsMasterPage(), "No MasterPage (!)");
467             rUsedMasterPage.getSdrPageProperties().ClearItem();
468             OSL_ENSURE(nullptr != rUsedMasterPage.getSdrPageProperties().GetStyleSheet(),
469                 "MasterPage without StyleSheet detected (!)");
470         }
471 
472         aNewAttr.Put(*pTempSet);
473         mrReq.Done( aNewAttr );
474 
475         return mrReq.GetArgs();
476     }
477     else
478     {
479         return nullptr;
480     }
481 }
482 
ApplyItemSet(const SfxItemSet * pArgs)483 void FuPage::ApplyItemSet( const SfxItemSet* pArgs )
484 {
485     if (!pArgs || !mpDrawViewShell)
486         return;
487 
488     // Set new page-attributes
489     PageKind ePageKind = mpDrawViewShell->GetPageKind();
490     const SfxPoolItem*  pPoolItem;
491     bool                bSetPageSizeAndBorder = false;
492     Size                aNewSize(maSize);
493     sal_Int32               nLeft  = -1, nRight = -1, nUpper = -1, nLower = -1;
494     bool                bScaleAll = true;
495     Orientation         eOrientation = mpPage->GetOrientation();
496     SdPage*             pMasterPage = mpPage->IsMasterPage() ? mpPage : &static_cast<SdPage&>(mpPage->TRG_GetMasterPage());
497     bool                bFullSize = pMasterPage->IsBackgroundFullSize();
498     sal_uInt16          nPaperBin = mpPage->GetPaperBin();
499 
500     if( pArgs->GetItemState(SID_ATTR_PAGE, true, &pPoolItem) == SfxItemState::SET )
501     {
502         mpDoc->SetPageNumType(static_cast<const SvxPageItem*>(pPoolItem)->GetNumType());
503 
504         eOrientation = static_cast<const SvxPageItem*>(pPoolItem)->IsLandscape() ?
505             Orientation::Landscape : Orientation::Portrait;
506 
507         if( mpPage->GetOrientation() != eOrientation )
508             bSetPageSizeAndBorder = true;
509 
510         mpDrawViewShell->ResetActualPage();
511     }
512 
513     if( pArgs->GetItemState(SID_ATTR_PAGE_SIZE, true, &pPoolItem) == SfxItemState::SET )
514     {
515         aNewSize = static_cast<const SvxSizeItem*>(pPoolItem)->GetSize();
516 
517         if( mpPage->GetSize() != aNewSize )
518             bSetPageSizeAndBorder = true;
519     }
520 
521     if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE),
522                             true, &pPoolItem) == SfxItemState::SET )
523     {
524         nLeft = static_cast<const SvxLRSpaceItem*>(pPoolItem)->GetLeft();
525         nRight = static_cast<const SvxLRSpaceItem*>(pPoolItem)->GetRight();
526 
527         if( mpPage->GetLeftBorder() != nLeft || mpPage->GetRightBorder() != nRight )
528             bSetPageSizeAndBorder = true;
529 
530     }
531 
532     if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE),
533                             true, &pPoolItem) == SfxItemState::SET )
534     {
535         nUpper = static_cast<const SvxULSpaceItem*>(pPoolItem)->GetUpper();
536         nLower = static_cast<const SvxULSpaceItem*>(pPoolItem)->GetLower();
537 
538         if( mpPage->GetUpperBorder() != nUpper || mpPage->GetLowerBorder() != nLower )
539             bSetPageSizeAndBorder = true;
540     }
541 
542     if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_PAGE_EXT1), true, &pPoolItem) == SfxItemState::SET )
543     {
544         bScaleAll = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
545     }
546 
547     if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_CHAR_GRABBAG, true, &pPoolItem))
548     {
549         SfxGrabBagItem const*const pGrabBag(static_cast<SfxGrabBagItem const*>(pPoolItem));
550         if (pGrabBag->GetGrabBag().find("BackgroundFullSize")->second >>= bFullSize)
551         {
552             if (pMasterPage->IsBackgroundFullSize() != bFullSize)
553             {
554                 bSetPageSizeAndBorder = true;
555             }
556         }
557     }
558 
559     // Paper Bin
560     if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_PAGE_PAPERBIN), true, &pPoolItem) == SfxItemState::SET )
561     {
562         nPaperBin = static_cast<const SvxPaperBinItem*>(pPoolItem)->GetValue();
563 
564         if( mpPage->GetPaperBin() != nPaperBin )
565             bSetPageSizeAndBorder = true;
566     }
567 
568     if (nLeft == -1 && nUpper != -1)
569     {
570         bSetPageSizeAndBorder = true;
571         nLeft  = mpPage->GetLeftBorder();
572         nRight = mpPage->GetRightBorder();
573     }
574     else if (nLeft != -1 && nUpper == -1)
575     {
576         bSetPageSizeAndBorder = true;
577         nUpper = mpPage->GetUpperBorder();
578         nLower = mpPage->GetLowerBorder();
579     }
580 
581     if( bSetPageSizeAndBorder || !mbMasterPage )
582         mpDrawViewShell->SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
583 
584     // if bMasterPage==sal_False then create a background-object for this page with the
585     // properties set in the dialog before, but if mbPageBckgrdDeleted==sal_True then
586     // the background of this page was set to invisible, so it would be a mistake
587     // to create a new background-object for this page !
588 
589     if( mbDisplayBackgroundTabPage )
590     {
591         if( !mbMasterPage && !mbPageBckgrdDeleted )
592         {
593             // Only this page
594             mpBackgroundObjUndoAction.reset( new SdBackgroundObjUndoAction(
595                 *mpDoc, *mpPage, mpPage->getSdrPageProperties().GetItemSet()) );
596             SfxItemSet aSet( *pArgs );
597             sdr::properties::CleanupFillProperties(aSet);
598             mpPage->getSdrPageProperties().ClearItem();
599             mpPage->getSdrPageProperties().PutItemSet(aSet);
600         }
601     }
602 
603     // add undo action for background object
604     if( mpBackgroundObjUndoAction )
605     {
606         // set merge flag, because a SdUndoGroupAction could have been inserted before
607         mpDocSh->GetUndoManager()->AddUndoAction( std::move(mpBackgroundObjUndoAction), true );
608     }
609 
610     // Objects can not be bigger than ViewSize
611     Size aPageSize = mpDoc->GetSdPage(0, ePageKind)->GetSize();
612     Size aViewSize(aPageSize.Width() * 3, aPageSize.Height() * 2);
613     mpDoc->SetMaxObjSize(aViewSize);
614 
615     // if necessary, we tell Preview the new context
616     mpDrawViewShell->UpdatePreview( mpDrawViewShell->GetActualPage() );
617 }
618 
619 } // end of namespace sd
620 
621 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
622