bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fupage.cxx
blobba77b29c54ef60fcb26b0ca4ed0ddb3c6abea155
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <fupage.hxx>
22 // arrange Tab-Page
24 #include <sfx2/sfxdlg.hxx>
25 #include <svx/svxids.hrc>
26 #include <svl/itempool.hxx>
27 #include <sfx2/request.hxx>
28 #include <vcl/prntypes.hxx>
29 #include <stlsheet.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <svx/graphichelper.hxx>
33 #include <svx/xbtmpit.hxx>
34 #include <svx/xflbstit.hxx>
35 #include <svx/xflbmtit.hxx>
36 #include <editeng/ulspitem.hxx>
37 #include <editeng/lrspitem.hxx>
38 #include <svx/sdr/properties/properties.hxx>
39 #include <editeng/shaditem.hxx>
40 #include <editeng/boxitem.hxx>
41 #include <editeng/sizeitem.hxx>
42 #include <editeng/pbinitem.hxx>
43 #include <sfx2/opengrf.hxx>
45 #include <strings.hrc>
46 #include <sdpage.hxx>
47 #include <View.hxx>
48 #include <Window.hxx>
49 #include <pres.hxx>
50 #include <drawdoc.hxx>
51 #include <DrawDocShell.hxx>
52 #include <ViewShell.hxx>
53 #include <DrawViewShell.hxx>
54 #include <app.hrc>
55 #include <unchss.hxx>
56 #include <undoback.hxx>
57 #include <sdabstdlg.hxx>
58 #include <sdresid.hxx>
60 #include <memory>
62 using namespace com::sun::star;
64 namespace sd {
66 // 50 cm 28350
67 // adapted from writer
68 #define MAXHEIGHT 28350
69 #define MAXWIDTH 28350
72 static void mergeItemSetsImpl( SfxItemSet& rTarget, const SfxItemSet& rSource )
74 const sal_uInt16* pPtr = rSource.GetRanges();
75 sal_uInt16 p1, p2;
76 while( *pPtr )
78 p1 = pPtr[0];
79 p2 = pPtr[1];
81 // make ranges discrete
82 while(pPtr[2] && (pPtr[2] - p2 == 1))
84 p2 = pPtr[3];
85 pPtr += 2;
87 rTarget.MergeRange( p1, p2 );
88 pPtr += 2;
91 rTarget.Put(rSource);
94 FuPage::FuPage( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
95 SdDrawDocument* pDoc, SfxRequest& rReq )
96 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
97 mrReq(rReq),
98 mpArgs( rReq.GetArgs() ),
99 mbPageBckgrdDeleted( false ),
100 mbMasterPage( false ),
101 mbDisplayBackgroundTabPage( true ),
102 mpPage(nullptr),
103 mpDrawViewShell(nullptr)
107 rtl::Reference<FuPoor> FuPage::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
109 rtl::Reference<FuPoor> xFunc( new FuPage( pViewSh, pWin, pView, pDoc, rReq ) );
110 xFunc->DoExecute(rReq);
111 return xFunc;
114 void FuPage::DoExecute( SfxRequest& )
116 mpDrawViewShell = dynamic_cast<DrawViewShell*>(mpViewShell);
117 DBG_ASSERT( mpDrawViewShell, "sd::FuPage::FuPage(), called without a current DrawViewShell!" );
119 if( mpDrawViewShell )
121 mbMasterPage = mpDrawViewShell->GetEditMode() == EditMode::MasterPage;
122 // we don't really want to format page background with SID_ATTR_PAGE[_SIZE] slots
123 mbDisplayBackgroundTabPage = ( mpDrawViewShell->GetPageKind() == PageKind::Standard) &&
124 ( nSlotId != SID_ATTR_PAGE_SIZE) && ( nSlotId != SID_ATTR_PAGE );
125 mpPage = mpDrawViewShell->getCurrentPage();
128 if( !mpPage )
129 return;
131 // if there are no arguments given, open the dialog
132 if( !mpArgs )
134 mpView->SdrEndTextEdit();
135 mpArgs = ExecuteDialog(mpWindow ? mpWindow->GetFrameWeld() : nullptr);
138 // if we now have arguments, apply them to current page
139 if( mpArgs )
141 ApplyItemSet( mpArgs );
145 FuPage::~FuPage()
149 void FuPage::Activate()
153 void FuPage::Deactivate()
157 void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr)
159 if (bMasterPage)
161 if (pStyleSheet)
162 mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
164 else
166 // Only this page, get attributes for background fill
167 const SfxItemSet& rBackgroundAttributes = pPage->getSdrPageProperties().GetItemSet();
169 if(drawing::FillStyle_NONE != rBackgroundAttributes.Get(XATTR_FILLSTYLE).GetValue())
171 // page attributes are used, take them
172 rMergedAttr.Put(rBackgroundAttributes);
174 else
176 if(pStyleSheet
177 && drawing::FillStyle_NONE != pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE).GetValue())
179 // if the page has no fill style, use the settings from the
180 // background stylesheet (if used)
181 mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
183 else
185 // no fill style from page, start with no fill style
186 rMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
192 const SfxItemSet* FuPage::ExecuteDialog(weld::Window* pParent)
194 if (!mpDrawViewShell)
195 return nullptr;
197 SfxItemSet aNewAttr(mpDoc->GetPool(),
198 {{mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE),
199 mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE)},
200 {SID_ATTR_PAGE, SID_ATTR_PAGE_SHARED},
201 {SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_OUTER},
202 {SID_ATTR_BORDER_SHADOW, SID_ATTR_BORDER_SHADOW},
203 {XATTR_FILL_FIRST, XATTR_FILL_LAST},
204 {SID_ATTR_PAGE_COLOR,SID_ATTR_PAGE_FILLSTYLE},
205 {EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR}});
207 // Retrieve additional data for dialog
209 SvxShadowItem aShadowItem(SID_ATTR_BORDER_SHADOW);
210 aNewAttr.Put( aShadowItem );
211 SvxBoxItem aBoxItem( SID_ATTR_BORDER_OUTER );
212 aNewAttr.Put( aBoxItem );
214 aNewAttr.Put( SvxFrameDirectionItem(
215 mpDoc->GetDefaultWritingMode() == css::text::WritingMode_RL_TB ? SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB,
216 EE_PARA_WRITINGDIR ) );
218 // Retrieve page-data for dialog
220 SvxPageItem aPageItem( SID_ATTR_PAGE );
221 aPageItem.SetDescName( mpPage->GetName() );
222 aPageItem.SetPageUsage( SvxPageUsage::All );
223 aPageItem.SetLandscape( mpPage->GetOrientation() == Orientation::Landscape );
224 aPageItem.SetNumType( mpDoc->GetPageNumType() );
225 aNewAttr.Put( aPageItem );
227 // size
228 maSize = mpPage->GetSize();
229 SvxSizeItem aSizeItem( SID_ATTR_PAGE_SIZE, maSize );
230 aNewAttr.Put( aSizeItem );
232 // Max size
233 SvxSizeItem aMaxSizeItem( SID_ATTR_PAGE_MAXSIZE, Size( MAXWIDTH, MAXHEIGHT ) );
234 aNewAttr.Put( aMaxSizeItem );
236 // paperbin
237 SvxPaperBinItem aPaperBinItem( SID_ATTR_PAGE_PAPERBIN, static_cast<sal_uInt8>(mpPage->GetPaperBin()) );
238 aNewAttr.Put( aPaperBinItem );
240 SvxLRSpaceItem aLRSpaceItem( static_cast<sal_uInt16>(mpPage->GetLeftBorder()), static_cast<sal_uInt16>(mpPage->GetRightBorder()), 0, 0, mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE));
241 aNewAttr.Put( aLRSpaceItem );
243 SvxULSpaceItem aULSpaceItem( static_cast<sal_uInt16>(mpPage->GetUpperBorder()), static_cast<sal_uInt16>(mpPage->GetLowerBorder()), mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE));
244 aNewAttr.Put( aULSpaceItem );
246 // Application
247 bool bScale = mpDoc->GetDocumentType() != DocumentType::Draw;
248 aNewAttr.Put( SfxBoolItem( SID_ATTR_PAGE_EXT1, bScale ) );
250 bool bFullSize = mpPage->IsMasterPage() ?
251 mpPage->IsBackgroundFullSize() : static_cast<SdPage&>(mpPage->TRG_GetMasterPage()).IsBackgroundFullSize();
253 aNewAttr.Put( SfxBoolItem( SID_ATTR_PAGE_EXT2, bFullSize ) );
255 // Merge ItemSet for dialog
257 const sal_uInt16* pPtr = aNewAttr.GetRanges();
258 sal_uInt16 p1 = pPtr[0], p2 = pPtr[1];
259 while(pPtr[2] && (pPtr[2] - p2 == 1))
261 p2 = pPtr[3];
262 pPtr += 2;
264 SfxItemSet aMergedAttr( *aNewAttr.GetPool(), {{p1, p2}} );
266 mergeItemSetsImpl( aMergedAttr, aNewAttr );
268 SdStyleSheet* pStyleSheet = mpPage->getPresentationStyle(HID_PSEUDOSHEET_BACKGROUND);
270 // merge page background filling to the dialogs input set
271 if( mbDisplayBackgroundTabPage )
273 MergePageBackgroundFilling(mpPage, pStyleSheet, mbMasterPage, aMergedAttr);
276 std::unique_ptr< SfxItemSet > pTempSet;
278 const sal_uInt16 nId = GetSlotID();
279 if (nId == SID_SAVE_BACKGROUND)
281 const XFillStyleItem& rStyleItem = aMergedAttr.Get(XATTR_FILLSTYLE);
282 if (drawing::FillStyle_BITMAP == rStyleItem.GetValue())
284 const XFillBitmapItem& rBitmap = aMergedAttr.Get(XATTR_FILLBITMAP);
285 const GraphicObject& rGraphicObj = rBitmap.GetGraphicObject();
286 GraphicHelper::ExportGraphic(pParent, rGraphicObj.GetGraphic(), "");
289 else if (nId == SID_SELECT_BACKGROUND)
291 SvxOpenGraphicDialog aDlg(SdResId(STR_SET_BACKGROUND_PICTURE), pParent);
293 if( aDlg.Execute() == ERRCODE_NONE )
295 Graphic aGraphic;
296 ErrCode nError = aDlg.GetGraphic(aGraphic);
297 if( nError == ERRCODE_NONE )
299 pTempSet.reset( new SfxItemSet( mpDoc->GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}) );
301 pTempSet->Put( XFillStyleItem( drawing::FillStyle_BITMAP ) );
303 // MigrateItemSet makes sure the XFillBitmapItem will have a unique name
304 SfxItemSet aMigrateSet( mpDoc->GetPool(), svl::Items<XATTR_FILLBITMAP, XATTR_FILLBITMAP>{} );
305 aMigrateSet.Put(XFillBitmapItem("background", aGraphic));
306 SdrModel::MigrateItemSet( &aMigrateSet, pTempSet.get(), mpDoc );
308 pTempSet->Put( XFillBmpStretchItem( true ));
309 pTempSet->Put( XFillBmpTileItem( false ));
314 else
316 // create the dialog
317 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
318 ScopedVclPtr<SfxAbstractTabDialog> pDlg( pFact->CreateSdTabPageDialog(mpViewShell->GetFrameWeld(), &aMergedAttr, mpDocSh, mbDisplayBackgroundTabPage) );
319 if( pDlg->Execute() == RET_OK )
320 pTempSet.reset( new SfxItemSet(*pDlg->GetOutputItemSet()) );
323 if (pTempSet.get() && pStyleSheet)
325 pStyleSheet->AdjustToFontHeight(*pTempSet);
327 if( mbDisplayBackgroundTabPage )
329 // if some fillstyle-items are not set in the dialog, then
330 // try to use the items before
331 bool bChanges = false;
332 for( sal_uInt16 i=XATTR_FILL_FIRST; i<XATTR_FILL_LAST; i++ )
334 if( aMergedAttr.GetItemState( i ) != SfxItemState::DEFAULT )
336 if( pTempSet->GetItemState( i ) == SfxItemState::DEFAULT )
337 pTempSet->Put( aMergedAttr.Get( i ) );
338 else
339 if( aMergedAttr.GetItem( i ) != pTempSet->GetItem( i ) )
340 bChanges = true;
344 // if the background for this page was set to invisible, the background-object has to be deleted, too.
345 if( ( pTempSet->GetItem<XFillStyleItem>( XATTR_FILLSTYLE )->GetValue() == drawing::FillStyle_NONE ) ||
346 ( ( pTempSet->GetItemState( XATTR_FILLSTYLE ) == SfxItemState::DEFAULT ) &&
347 ( aMergedAttr.GetItem<XFillStyleItem>( XATTR_FILLSTYLE )->GetValue() == drawing::FillStyle_NONE ) ) )
348 mbPageBckgrdDeleted = true;
350 if( !mbMasterPage && bChanges && mbPageBckgrdDeleted )
352 mpBackgroundObjUndoAction.reset( new SdBackgroundObjUndoAction(
353 *mpDoc, *mpPage, mpPage->getSdrPageProperties().GetItemSet()) );
355 if(!mpPage->IsMasterPage())
357 // on normal pages, switch off fill attribute usage
358 SdrPageProperties& rPageProperties = mpPage->getSdrPageProperties();
359 rPageProperties.ClearItem( XATTR_FILLBITMAP );
360 rPageProperties.ClearItem( XATTR_FILLGRADIENT );
361 rPageProperties.ClearItem( XATTR_FILLHATCH );
362 rPageProperties.PutItem(XFillStyleItem(drawing::FillStyle_NONE));
367 /* Special treatment: reset the INVALIDS to
368 NULL-Pointer (otherwise INVALIDs or pointer point
369 to DefaultItems in the template; both would
370 prevent the attribute inheritance) */
371 pTempSet->ClearInvalidItems();
373 if( mbMasterPage )
375 mpDocSh->GetUndoManager()->AddUndoAction(std::make_unique<StyleSheetUndoAction>(
376 mpDoc, static_cast<SfxStyleSheet*>(pStyleSheet), &(*pTempSet)));
377 pStyleSheet->GetItemSet().Put( *pTempSet );
378 sdr::properties::CleanupFillProperties( pStyleSheet->GetItemSet() );
379 pStyleSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
382 // if background filling is set to master pages then clear from page set
383 if( mbMasterPage )
385 for( sal_uInt16 nWhich = XATTR_FILL_FIRST; nWhich <= XATTR_FILL_LAST; nWhich++ )
387 pTempSet->ClearItem( nWhich );
389 pTempSet->Put(XFillStyleItem(drawing::FillStyle_NONE));
392 const SfxPoolItem *pItem;
393 if( SfxItemState::SET == pTempSet->GetItemState( EE_PARA_WRITINGDIR, false, &pItem ) )
395 SvxFrameDirection nVal = static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue();
396 mpDoc->SetDefaultWritingMode( nVal == SvxFrameDirection::Horizontal_RL_TB ? css::text::WritingMode_RL_TB : css::text::WritingMode_LR_TB );
399 mpDoc->SetChanged();
401 // BackgroundFill of Masterpage: no hard attributes allowed
402 SdrPage& rUsedMasterPage = mpPage->IsMasterPage() ? *mpPage : mpPage->TRG_GetMasterPage();
403 OSL_ENSURE(rUsedMasterPage.IsMasterPage(), "No MasterPage (!)");
404 rUsedMasterPage.getSdrPageProperties().ClearItem();
405 OSL_ENSURE(nullptr != rUsedMasterPage.getSdrPageProperties().GetStyleSheet(),
406 "MasterPage without StyleSheet detected (!)");
409 aNewAttr.Put(*pTempSet);
410 mrReq.Done( aNewAttr );
412 return mrReq.GetArgs();
414 else
416 return nullptr;
420 void FuPage::ApplyItemSet( const SfxItemSet* pArgs )
422 if (!pArgs || !mpDrawViewShell)
423 return;
425 // Set new page-attributes
426 PageKind ePageKind = mpDrawViewShell->GetPageKind();
427 const SfxPoolItem* pPoolItem;
428 bool bSetPageSizeAndBorder = false;
429 Size aNewSize(maSize);
430 sal_Int32 nLeft = -1, nRight = -1, nUpper = -1, nLower = -1;
431 bool bScaleAll = true;
432 Orientation eOrientation = mpPage->GetOrientation();
433 SdPage* pMasterPage = mpPage->IsMasterPage() ? mpPage : &static_cast<SdPage&>(mpPage->TRG_GetMasterPage());
434 bool bFullSize = pMasterPage->IsBackgroundFullSize();
435 sal_uInt16 nPaperBin = mpPage->GetPaperBin();
437 if( pArgs->GetItemState(SID_ATTR_PAGE, true, &pPoolItem) == SfxItemState::SET )
439 mpDoc->SetPageNumType(static_cast<const SvxPageItem*>(pPoolItem)->GetNumType());
441 eOrientation = static_cast<const SvxPageItem*>(pPoolItem)->IsLandscape() ?
442 Orientation::Landscape : Orientation::Portrait;
444 if( mpPage->GetOrientation() != eOrientation )
445 bSetPageSizeAndBorder = true;
447 mpDrawViewShell->ResetActualPage();
450 if( pArgs->GetItemState(SID_ATTR_PAGE_SIZE, true, &pPoolItem) == SfxItemState::SET )
452 aNewSize = static_cast<const SvxSizeItem*>(pPoolItem)->GetSize();
454 if( mpPage->GetSize() != aNewSize )
455 bSetPageSizeAndBorder = true;
458 if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_LRSPACE),
459 true, &pPoolItem) == SfxItemState::SET )
461 nLeft = static_cast<const SvxLRSpaceItem*>(pPoolItem)->GetLeft();
462 nRight = static_cast<const SvxLRSpaceItem*>(pPoolItem)->GetRight();
464 if( mpPage->GetLeftBorder() != nLeft || mpPage->GetRightBorder() != nRight )
465 bSetPageSizeAndBorder = true;
469 if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_ULSPACE),
470 true, &pPoolItem) == SfxItemState::SET )
472 nUpper = static_cast<const SvxULSpaceItem*>(pPoolItem)->GetUpper();
473 nLower = static_cast<const SvxULSpaceItem*>(pPoolItem)->GetLower();
475 if( mpPage->GetUpperBorder() != nUpper || mpPage->GetLowerBorder() != nLower )
476 bSetPageSizeAndBorder = true;
479 if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_PAGE_EXT1), true, &pPoolItem) == SfxItemState::SET )
481 bScaleAll = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
484 if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_PAGE_EXT2), true, &pPoolItem) == SfxItemState::SET )
486 bFullSize = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
488 if(pMasterPage->IsBackgroundFullSize() != bFullSize )
489 bSetPageSizeAndBorder = true;
492 // Paper Bin
493 if( pArgs->GetItemState(mpDoc->GetPool().GetWhich(SID_ATTR_PAGE_PAPERBIN), true, &pPoolItem) == SfxItemState::SET )
495 nPaperBin = static_cast<const SvxPaperBinItem*>(pPoolItem)->GetValue();
497 if( mpPage->GetPaperBin() != nPaperBin )
498 bSetPageSizeAndBorder = true;
501 if (nLeft == -1 && nUpper != -1)
503 bSetPageSizeAndBorder = true;
504 nLeft = mpPage->GetLeftBorder();
505 nRight = mpPage->GetRightBorder();
507 else if (nLeft != -1 && nUpper == -1)
509 bSetPageSizeAndBorder = true;
510 nUpper = mpPage->GetUpperBorder();
511 nLower = mpPage->GetLowerBorder();
514 if( bSetPageSizeAndBorder || !mbMasterPage )
515 mpDrawViewShell->SetPageSizeAndBorder(ePageKind, aNewSize, nLeft, nRight, nUpper, nLower, bScaleAll, eOrientation, nPaperBin, bFullSize );
517 // if bMasterPage==sal_False then create a background-object for this page with the
518 // properties set in the dialog before, but if mbPageBckgrdDeleted==sal_True then
519 // the background of this page was set to invisible, so it would be a mistake
520 // to create a new background-object for this page !
522 if( mbDisplayBackgroundTabPage )
524 if( !mbMasterPage && !mbPageBckgrdDeleted )
526 // Only this page
527 mpBackgroundObjUndoAction.reset( new SdBackgroundObjUndoAction(
528 *mpDoc, *mpPage, mpPage->getSdrPageProperties().GetItemSet()) );
529 SfxItemSet aSet( *pArgs );
530 sdr::properties::CleanupFillProperties(aSet);
531 mpPage->getSdrPageProperties().ClearItem();
532 mpPage->getSdrPageProperties().PutItemSet(aSet);
536 // add undo action for background object
537 if( mpBackgroundObjUndoAction )
539 // set merge flag, because a SdUndoGroupAction could have been inserted before
540 mpDocSh->GetUndoManager()->AddUndoAction( std::move(mpBackgroundObjUndoAction), true );
543 // Objects can not be bigger than ViewSize
544 Size aPageSize = mpDoc->GetSdPage(0, ePageKind)->GetSize();
545 Size aViewSize(aPageSize.Width() * 3, aPageSize.Height() * 2);
546 mpDoc->SetMaxObjSize(aViewSize);
548 // if necessary, we tell Preview the new context
549 mpDrawViewShell->UpdatePreview( mpDrawViewShell->GetActualPage() );
552 } // end of namespace sd
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */