Coverage Report

Created: 2026-05-16 09:25

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