Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/dialog/hdft.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 <sal/config.h>
21
22
#include <o3tl/unit_conversion.hxx>
23
#include <svl/itemiter.hxx>
24
#include <sfx2/objsh.hxx>
25
#include <svx/svxids.hrc>
26
27
#include <svl/intitem.hxx>
28
#include <svtools/unitconv.hxx>
29
30
#include <svx/dialmgr.hxx>
31
#include <svx/hdft.hxx>
32
#include <svx/pageitem.hxx>
33
#include <svx/strings.hrc>
34
35
#include <svx/dlgutil.hxx>
36
#include <sfx2/htmlmode.hxx>
37
#include <osl/diagnose.h>
38
#include <tools/debug.hxx>
39
40
#include <editeng/brushitem.hxx>
41
#include <editeng/lrspitem.hxx>
42
#include <editeng/ulspitem.hxx>
43
#include <editeng/sizeitem.hxx>
44
#include <editeng/boxitem.hxx>
45
46
#include <svx/svxdlg.hxx>
47
#include <memory>
48
49
#include <svx/xdef.hxx>
50
#include <svx/xfillit0.hxx>
51
#include <svx/unobrushitemhelper.hxx>
52
53
using namespace com::sun::star;
54
55
// Word 97 incompatibility (#i19922#)
56
// #i19922# - tdf#126051 see cui/source/tabpages/page.cxx and sw/source/uibase/sidebar/PageMarginControl.hxx
57
constexpr tools::Long MINBODY = o3tl::toTwips(1, o3tl::Length::mm); // 1mm in twips rounded
58
59
// default distance to Header or footer
60
const tools::Long DEF_DIST_WRITER = 500;    // 5mm (Writer)
61
const tools::Long DEF_DIST_CALC = 250;      // 2.5mm (Calc)
62
63
const WhichRangesContainer SvxHFPage::pRanges(svl::Items<
64
    // Support DrawingLayer FillStyles (no real call to below GetRanges()
65
    // detected, still do the complete transition)
66
    XATTR_FILL_FIRST,        XATTR_FILL_LAST,
67
68
    SID_ATTR_BRUSH,          SID_ATTR_BRUSH,
69
    SID_ATTR_BORDER_INNER,   SID_ATTR_BORDER_INNER,
70
    SID_ATTR_BORDER_OUTER,   SID_ATTR_BORDER_OUTER,
71
    SID_ATTR_BORDER_SHADOW,  SID_ATTR_BORDER_SHADOW,
72
    SID_ATTR_LRSPACE,        SID_ATTR_LRSPACE,
73
    SID_ATTR_ULSPACE,        SID_ATTR_ULSPACE,
74
    SID_ATTR_PAGE_SIZE,      SID_ATTR_PAGE_SIZE,
75
    SID_ATTR_PAGE_HEADERSET, SID_ATTR_PAGE_HEADERSET,
76
    SID_ATTR_PAGE_FOOTERSET, SID_ATTR_PAGE_FOOTERSET,
77
    SID_ATTR_PAGE_ON,        SID_ATTR_PAGE_ON,
78
    SID_ATTR_PAGE_DYNAMIC,   SID_ATTR_PAGE_DYNAMIC,
79
    SID_ATTR_PAGE_SHARED,    SID_ATTR_PAGE_SHARED,
80
    SID_ATTR_HDFT_DYNAMIC_SPACING, SID_ATTR_HDFT_DYNAMIC_SPACING,
81
    SID_ATTR_PAGE_SHARED_FIRST,    SID_ATTR_PAGE_SHARED_FIRST
82
>);
83
84
namespace svx {
85
86
    bool ShowBorderBackgroundDlg(weld::Window* pParent, SfxItemSet* pBBSet)
87
0
    {
88
0
        bool bRes = false;
89
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
90
0
        ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxBorderBackgroundDlg(pParent, *pBBSet, true /*bEnableDrawingLayerFillStyles*/));
91
0
        if ( pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet() )
92
0
        {
93
0
            SfxItemIter aIter( *pDlg->GetOutputItemSet() );
94
95
0
            for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
96
0
            {
97
0
                if ( !IsInvalidItem( pItem ) )
98
0
                    pBBSet->Put( *pItem );
99
0
            }
100
0
            bRes = true;
101
0
        }
102
0
        return bRes;
103
0
    }
104
}
105
106
std::unique_ptr<SfxTabPage> SvxHeaderPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
107
0
{
108
0
    return std::make_unique<SvxHeaderPage>( pPage, pController, *rSet );
109
0
}
110
111
std::unique_ptr<SfxTabPage> SvxFooterPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
112
0
{
113
0
    return std::make_unique<SvxFooterPage>( pPage, pController, *rSet );
114
0
}
115
116
SvxHeaderPage::SvxHeaderPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr)
117
0
    : SvxHFPage( pPage, pController, rAttr, SID_ATTR_PAGE_HEADERSET )
118
0
{
119
0
}
120
121
SvxFooterPage::SvxFooterPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr)
122
0
    : SvxHFPage( pPage, pController, rAttr, SID_ATTR_PAGE_FOOTERSET )
123
0
{
124
0
}
125
126
SvxHFPage::SvxHFPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet, sal_uInt16 nSetId)
127
0
    : SfxTabPage(pPage, pController, u"svx/ui/headfootformatpage.ui"_ustr, u"HFFormatPage"_ustr, &rSet)
128
0
    , m_nId(nSetId)
129
0
    , mbDisableQueryBox(false)
130
0
    , mbEnableDrawingLayerFillStyles(false)
131
0
    , m_xCntSharedBox(m_xBuilder->weld_check_button(u"checkSameLR"_ustr))
132
0
    , m_xCntSharedFirstBox(m_xBuilder->weld_check_button(u"checkSameFP"_ustr))
133
0
    , m_xLMLbl(m_xBuilder->weld_label(u"labelLeftMarg"_ustr))
134
0
    , m_xLMEdit(m_xBuilder->weld_metric_spin_button(u"spinMargLeft"_ustr, FieldUnit::CM))
135
0
    , m_xRMLbl(m_xBuilder->weld_label(u"labelRightMarg"_ustr))
136
0
    , m_xRMEdit(m_xBuilder->weld_metric_spin_button(u"spinMargRight"_ustr, FieldUnit::CM))
137
0
    , m_xDistFT(m_xBuilder->weld_label(u"labelSpacing"_ustr))
138
0
    , m_xDistEdit(m_xBuilder->weld_metric_spin_button(u"spinSpacing"_ustr, FieldUnit::CM))
139
0
    , m_xDynSpacingCB(m_xBuilder->weld_check_button(u"checkDynSpacing"_ustr))
140
0
    , m_xHeightFT(m_xBuilder->weld_label(u"labelHeight"_ustr))
141
0
    , m_xHeightEdit(m_xBuilder->weld_metric_spin_button(u"spinHeight"_ustr, FieldUnit::CM))
142
0
    , m_xHeightDynBtn(m_xBuilder->weld_check_button(u"checkAutofit"_ustr))
143
0
    , m_xBackgroundBtn(m_xBuilder->weld_button(u"buttonMore"_ustr))
144
0
    , m_xFrame(m_xBuilder->weld_frame(u"frame1"_ustr))
145
0
    , m_xBspWin(new weld::CustomWeld(*m_xBuilder, u"drawingareaPageHF"_ustr, m_aBspWin))
146
0
{
147
0
    const SfxPoolItem* pExt1 = GetItem(rSet, SID_ATTR_PAGE_EXT1);
148
0
    const SfxPoolItem* pExt2 = GetItem(rSet, SID_ATTR_PAGE_EXT2);
149
0
    m_bIsCalc = dynamic_cast<const SfxBoolItem*>(pExt1) && dynamic_cast<const SfxBoolItem*>(pExt2);
150
151
    //swap header <-> footer in UI
152
0
    if (m_nId == SID_ATTR_PAGE_FOOTERSET)
153
0
    {
154
0
        m_xContainer->set_help_id(u"svx/ui/headfootformatpage/FFormatPage"_ustr);
155
0
        m_xFrame->set_label(SvxResId(RID_SVXSTR_FOOTER));
156
0
        m_xFrame->set_help_id(u"svx/ui/headfootformatpage/FFormatPage"_ustr);
157
0
        m_xTurnOnBox = m_xBuilder->weld_check_button(u"checkFooterOn"_ustr);
158
159
        /* Set custom HIDs for the Footer help page (shared/01/05040400.xhp)
160
        otherwise it would display the same extended help
161
        on both the Header and Footer tabs */
162
0
        m_xCntSharedBox->set_help_id( u"SVX_HID_FOOTER_CHECKSAMELR"_ustr );
163
0
        m_xCntSharedFirstBox->set_help_id( u"SVX_HID_FOOTER_CHECKSAMEFP"_ustr );
164
0
        m_xLMEdit->set_help_id( u"SVX_HID_FOOTER_SPINMARGLEFT"_ustr );
165
0
        m_xRMEdit->set_help_id( u"SVX_HID_FOOTER_SPINMARGRIGHT"_ustr );
166
0
        m_xDistEdit->set_help_id( u"SVX_HID_FOOTER_SPINSPACING"_ustr );
167
0
        m_xDynSpacingCB->set_help_id( u"SVX_HID_FOOTER_CHECKDYNSPACING"_ustr );
168
0
        m_xHeightEdit->set_help_id( u"SVX_HID_FOOTER_SPINHEIGHT"_ustr );
169
0
        m_xHeightDynBtn->set_help_id( u"SVX_HID_FOOTER_CHECKAUTOFIT"_ustr );
170
0
        m_xBackgroundBtn->set_help_id( u"SVX_HID_FOOTER_BUTTONMORE"_ustr );
171
172
        // uitest
173
0
        m_xCntSharedBox->set_buildable_name(m_xCntSharedBox->get_buildable_name() + "-footer");
174
0
        m_xCntSharedFirstBox->set_buildable_name(m_xCntSharedFirstBox->get_buildable_name() + "-footer");
175
0
    }
176
0
    else //Header
177
0
    {
178
0
        m_xContainer->set_help_id(u"svx/ui/headfootformatpage/HFormatPage"_ustr);
179
0
        m_xFrame->set_label(SvxResId(RID_SVXSTR_HEADER));
180
0
        m_xFrame->set_help_id(u"svx/ui/headfootformatpage/HFormatPage"_ustr);
181
0
        m_xTurnOnBox = m_xBuilder->weld_check_button(u"checkHeaderOn"_ustr);
182
183
        // uitest
184
0
        m_xCntSharedBox->set_buildable_name(m_xCntSharedBox->get_buildable_name() + "-header");
185
0
        m_xCntSharedFirstBox->set_buildable_name(m_xCntSharedFirstBox->get_buildable_name() + "-header");
186
0
    }
187
0
    m_xTurnOnBox->show();
188
189
0
    InitHandler();
190
0
    m_aBspWin.EnableRTL(false);
191
192
    // This Page needs ExchangeSupport
193
0
    SetExchangeSupport();
194
195
    // Set metrics
196
0
    FieldUnit eFUnit = GetModuleFieldUnit( rSet );
197
0
    SetFieldUnit( *m_xDistEdit, eFUnit );
198
0
    SetFieldUnit( *m_xHeightEdit, eFUnit );
199
0
    SetFieldUnit( *m_xLMEdit, eFUnit );
200
0
    SetFieldUnit( *m_xRMEdit, eFUnit );
201
0
}
202
203
SvxHFPage::~SvxHFPage()
204
0
{
205
0
}
206
207
bool SvxHFPage::FillItemSet( SfxItemSet* rSet )
208
0
{
209
0
    const sal_uInt16 nWSize = GetWhich(SID_ATTR_PAGE_SIZE);
210
0
    const sal_uInt16 nWLRSpace = GetWhich(SID_ATTR_LRSPACE);
211
0
    const sal_uInt16 nWULSpace = GetWhich(SID_ATTR_ULSPACE);
212
0
    const sal_uInt16 nWOn = GetWhich(SID_ATTR_PAGE_ON);
213
0
    const sal_uInt16 nWDynamic = GetWhich(SID_ATTR_PAGE_DYNAMIC);
214
0
    const sal_uInt16 nWDynSpacing = GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING);
215
0
    const sal_uInt16 nWShared = GetWhich(SID_ATTR_PAGE_SHARED);
216
0
    const sal_uInt16 nWSharedFirst = GetWhich( SID_ATTR_PAGE_SHARED_FIRST );
217
0
    const sal_uInt16 nWBrush = GetWhich(SID_ATTR_BRUSH);
218
0
    const sal_uInt16 nWBox = GetWhich(SID_ATTR_BORDER_OUTER);
219
0
    const sal_uInt16 nWBoxInfo = GetWhich(SID_ATTR_BORDER_INNER);
220
0
    const sal_uInt16 nWShadow = GetWhich(SID_ATTR_BORDER_SHADOW);
221
222
0
    const SfxItemSet& rOldSet = GetItemSet();
223
0
    SfxItemPool* pPool = rOldSet.GetPool();
224
0
    DBG_ASSERT(pPool,"no pool :-(");
225
0
    MapUnit eUnit = pPool->GetMetric(nWSize);
226
    // take over DrawingLayer FillStyles
227
0
    SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aSet(*pPool);
228
    // Keep it valid
229
0
    aSet.MergeRange(nWSize, nWSize);
230
0
    aSet.MergeRange(nWLRSpace, nWLRSpace);
231
0
    aSet.MergeRange(nWULSpace, nWULSpace);
232
0
    aSet.MergeRange(nWOn, nWOn);
233
0
    aSet.MergeRange(nWDynamic, nWDynamic);
234
0
    aSet.MergeRange(nWShared, nWShared);
235
0
    aSet.MergeRange(nWSharedFirst, nWSharedFirst);
236
0
    aSet.MergeRange(nWBrush, nWBrush);
237
0
    aSet.MergeRange(nWBoxInfo, nWBoxInfo);
238
0
    aSet.MergeRange(nWBox, nWBox);
239
0
    aSet.MergeRange(nWShadow, nWShadow);
240
0
    aSet.MergeRange(nWDynSpacing, nWDynSpacing);
241
242
0
    if(mbEnableDrawingLayerFillStyles)
243
0
    {
244
        // When using the XATTR_FILLSTYLE DrawingLayer FillStyle definition
245
        // extra action has to be done here since the pool default is drawing::FillStyle_SOLID
246
        // instead of drawing::FillStyle_NONE (to have the default blue fill color at start).
247
0
        aSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
248
0
    }
249
250
0
    aSet.Put( SfxBoolItem( nWOn,      m_xTurnOnBox->get_active() ) );
251
0
    aSet.Put( SfxBoolItem( nWDynamic, m_xHeightDynBtn->get_active() ) );
252
0
    aSet.Put( SfxBoolItem( nWShared,  m_xCntSharedBox->get_active() ) );
253
0
    if(m_xCntSharedFirstBox->get_visible())
254
0
        aSet.Put(SfxBoolItem(nWSharedFirst,  m_xCntSharedFirstBox->get_active()));
255
0
    if (m_xDynSpacingCB->get_visible() && SfxItemPool::IsWhich(nWDynSpacing))
256
0
    {
257
0
        std::unique_ptr<SfxBoolItem> pBoolItem(static_cast<SfxBoolItem*>(pPool->GetUserOrPoolDefaultItem(nWDynSpacing).Clone()));
258
0
        pBoolItem->SetValue(m_xDynSpacingCB->get_active());
259
0
        aSet.Put(std::move(pBoolItem));
260
0
    }
261
262
    // Size
263
0
    SvxSizeItem aSizeItem( static_cast<const SvxSizeItem&>(rOldSet.Get( nWSize )) );
264
0
    Size        aSize( aSizeItem.GetSize() );
265
0
    tools::Long        nDist = GetCoreValue( *m_xDistEdit, eUnit );
266
0
    tools::Long        nH    = GetCoreValue( *m_xHeightEdit, eUnit );
267
268
0
    nH += nDist; // add distance
269
0
    aSize.setHeight( nH );
270
0
    aSizeItem.SetSize( aSize );
271
0
    aSet.Put( aSizeItem );
272
273
    // Margins
274
0
    SvxLRSpaceItem aLR( nWLRSpace );
275
0
    aLR.SetLeft(SvxIndentValue::twips(GetCoreValue(*m_xLMEdit, eUnit)));
276
0
    aLR.SetRight(SvxIndentValue::twips(GetCoreValue(*m_xRMEdit, eUnit)));
277
0
    aSet.Put( aLR );
278
279
0
    SvxULSpaceItem aUL( nWULSpace );
280
0
    if ( m_nId == SID_ATTR_PAGE_HEADERSET )
281
0
        aUL.SetLower( static_cast<sal_uInt16>(nDist) );
282
0
    else
283
0
        aUL.SetUpper( static_cast<sal_uInt16>(nDist) );
284
0
    aSet.Put( aUL );
285
286
    // Background and border?
287
0
    if (m_pBBSet)
288
0
    {
289
0
        aSet.Put(*m_pBBSet);
290
0
    }
291
0
    else
292
0
    {
293
0
        const SfxPoolItem* pItem;
294
295
0
        if(SfxItemState::SET == GetItemSet().GetItemState(GetWhich(m_nId), false, &pItem))
296
0
        {
297
0
            const SfxItemSet* _pSet = &(static_cast< const SvxSetItem* >(pItem)->GetItemSet());
298
299
0
            if(_pSet->GetItemState(nWBrush) == SfxItemState::SET)
300
0
            {
301
0
                aSet.Put(_pSet->Get(nWBrush));
302
0
            }
303
304
0
            if(_pSet->GetItemState(nWBoxInfo) == SfxItemState::SET)
305
0
            {
306
0
                aSet.Put(_pSet->Get(nWBoxInfo));
307
0
            }
308
309
0
            if(_pSet->GetItemState(nWBox) == SfxItemState::SET)
310
0
            {
311
0
                aSet.Put(_pSet->Get(nWBox));
312
0
            }
313
314
0
            if(_pSet->GetItemState(nWShadow) == SfxItemState::SET)
315
0
            {
316
0
                aSet.Put(_pSet->Get(nWShadow));
317
0
            }
318
319
            // take care of [XATTR_XATTR_FILL_FIRST .. XATTR_FILL_LAST]
320
0
            for(sal_uInt16 nFillStyleId(XATTR_FILL_FIRST); nFillStyleId <= XATTR_FILL_LAST; nFillStyleId++)
321
0
            {
322
0
                if(_pSet->GetItemState(nFillStyleId) == SfxItemState::SET)
323
0
                {
324
0
                    aSet.Put(_pSet->Get(nFillStyleId));
325
0
                }
326
0
            }
327
0
        }
328
0
    }
329
330
    // Flush the SetItem
331
0
    SvxSetItem aSetItem( TypedWhichId<SvxSetItem>(GetWhich( m_nId )), aSet );
332
0
    rSet->Put( aSetItem );
333
334
0
    return true;
335
0
}
336
337
338
void SvxHFPage::Reset( const SfxItemSet* rSet )
339
0
{
340
0
    ActivatePage( *rSet );
341
0
    ResetBackground_Impl( *rSet );
342
343
0
    SfxItemPool* pPool = GetItemSet().GetPool();
344
0
    assert(pPool && "Where is the pool");
345
0
    MapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_PAGE_SIZE ) );
346
347
    // Evaluate header-/footer- attributes
348
0
    const SvxSetItem* pSetItem = nullptr;
349
350
0
    if ( SfxItemState::SET == rSet->GetItemState( GetWhich(m_nId), false,
351
0
                                            reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
352
0
    {
353
0
        const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
354
0
        const SfxBoolItem& rHeaderOn =
355
0
            rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ON));
356
357
0
        m_xTurnOnBox->set_active(rHeaderOn.GetValue());
358
359
0
        if ( rHeaderOn.GetValue() )
360
0
        {
361
0
            const SfxBoolItem& rDynamic =
362
0
                rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC ) );
363
0
            const SfxBoolItem& rShared =
364
0
                rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED ) );
365
0
            const SvxSizeItem& rSize =
366
0
                rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
367
0
            const SvxULSpaceItem& rUL = rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
368
0
            const SvxLRSpaceItem& rLR = rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
369
0
            if (m_xDynSpacingCB->get_visible())
370
0
            {
371
0
                const SfxBoolItem& rDynSpacing =
372
0
                    static_cast<const SfxBoolItem&>(rHeaderSet.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING)));
373
0
                m_xDynSpacingCB->set_active(rDynSpacing.GetValue());
374
0
            }
375
376
377
0
            if ( m_nId == SID_ATTR_PAGE_HEADERSET )
378
0
            {   // Header
379
0
                SetMetricValue( *m_xDistEdit, rUL.GetLower(), eUnit );
380
0
                SetMetricValue( *m_xHeightEdit, rSize.GetSize().Height() - rUL.GetLower(), eUnit );
381
0
            }
382
0
            else
383
0
            {   // Footer
384
0
                SetMetricValue( *m_xDistEdit, rUL.GetUpper(), eUnit );
385
0
                SetMetricValue( *m_xHeightEdit, rSize.GetSize().Height() - rUL.GetUpper(), eUnit );
386
0
            }
387
388
0
            m_xHeightDynBtn->set_active(rDynamic.GetValue());
389
0
            SetMetricValue(*m_xLMEdit, rLR.ResolveLeft({}), eUnit);
390
0
            SetMetricValue(*m_xRMEdit, rLR.ResolveRight({}), eUnit);
391
0
            m_xCntSharedBox->set_active(rShared.GetValue());
392
0
        }
393
0
        else
394
0
            pSetItem = nullptr;
395
0
    }
396
0
    else
397
0
    {
398
        // defaults for distance and height
399
0
        tools::Long nDefaultDist = m_bIsCalc ? DEF_DIST_CALC : DEF_DIST_WRITER;
400
0
        SetMetricValue( *m_xDistEdit, nDefaultDist, MapUnit::Map100thMM );
401
0
        SetMetricValue( *m_xHeightEdit, 500, MapUnit::Map100thMM );
402
0
    }
403
404
0
    if ( !pSetItem )
405
0
    {
406
0
        m_xTurnOnBox->set_active(false);
407
0
        m_xHeightDynBtn->set_active(true);
408
0
        m_xCntSharedBox->set_active(true);
409
0
    }
410
411
0
    TurnOn(nullptr);
412
413
0
    m_xTurnOnBox->save_state();
414
0
    m_xDistEdit->save_value();
415
0
    m_xHeightEdit->save_value();
416
0
    m_xHeightDynBtn->save_state();
417
0
    m_xLMEdit->save_value();
418
0
    m_xRMEdit->save_value();
419
0
    m_xCntSharedBox->save_state();
420
0
    RangeHdl();
421
422
0
    SfxObjectShell* pShell;
423
0
    const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_HTML_MODE, false);
424
0
    if(pItem  ||
425
0
        ( nullptr != (pShell = SfxObjectShell::Current()) &&
426
0
                    nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
427
0
    {
428
0
        sal_uInt16 nHtmlMode = pItem->GetValue();
429
0
        if (nHtmlMode & HTMLMODE_ON)
430
0
        {
431
0
            m_xCntSharedBox->hide();
432
0
            m_xBackgroundBtn->hide();
433
0
        }
434
0
    }
435
436
0
}
437
438
void SvxHFPage::InitHandler()
439
0
{
440
0
    m_xTurnOnBox->connect_toggled(LINK(this, SvxHFPage, TurnOnHdl));
441
0
    m_xDistEdit->connect_value_changed(LINK(this, SvxHFPage, ValueChangeHdl));
442
0
    m_xHeightEdit->connect_value_changed(LINK(this,SvxHFPage,ValueChangeHdl));
443
444
0
    m_xLMEdit->connect_value_changed(LINK(this,  SvxHFPage, ValueChangeHdl));
445
0
    m_xRMEdit->connect_value_changed(LINK(this,  SvxHFPage, ValueChangeHdl));
446
0
    m_xBackgroundBtn->connect_clicked(LINK(this,SvxHFPage, BackgroundHdl));
447
0
}
448
449
void SvxHFPage::TurnOn(const weld::Toggleable* pBox)
450
0
{
451
0
    if (m_xTurnOnBox->get_active())
452
0
    {
453
0
        m_xDistFT->set_sensitive(true);
454
0
        m_xDistEdit->set_sensitive(true);
455
0
        m_xDynSpacingCB->set_sensitive(true);
456
0
        m_xHeightFT->set_sensitive(true);
457
0
        m_xHeightEdit->set_sensitive(true);
458
0
        m_xHeightDynBtn->set_sensitive(true);
459
0
        m_xLMLbl->set_sensitive(true);
460
0
        m_xLMEdit->set_sensitive(true);
461
0
        m_xRMLbl->set_sensitive(true);
462
0
        m_xRMEdit->set_sensitive(true);
463
464
0
        SvxPageUsage nUsage = m_aBspWin.GetUsage();
465
466
0
        if( nUsage == SvxPageUsage::Right || nUsage == SvxPageUsage::Left )
467
0
            m_xCntSharedBox->set_sensitive(false);
468
0
        else
469
0
        {
470
0
            m_xCntSharedBox->set_sensitive(true);
471
0
            m_xCntSharedFirstBox->set_sensitive(true);
472
0
        }
473
0
        m_xBackgroundBtn->set_sensitive(true);
474
0
    }
475
0
    else
476
0
    {
477
0
        bool bDelete = true;
478
479
0
        if (!mbDisableQueryBox && pBox && m_xTurnOnBox->get_saved_state() == TRISTATE_TRUE)
480
0
        {
481
0
            short nResult;
482
0
            if (m_nId == SID_ATTR_PAGE_HEADERSET)
483
0
            {
484
0
                DeleteHeaderDialog aDlg(GetFrameWeld());
485
0
                nResult = aDlg.run();
486
0
            }
487
0
            else
488
0
            {
489
0
                DeleteFooterDialog aDlg(GetFrameWeld());
490
0
                nResult = aDlg.run();
491
0
            }
492
0
            bDelete = nResult == RET_YES;
493
0
        }
494
495
0
        if ( bDelete )
496
0
        {
497
0
            m_xDistFT->set_sensitive(false);
498
0
            m_xDistEdit->set_sensitive(false);
499
0
            m_xDynSpacingCB->set_sensitive(false);
500
0
            m_xHeightFT->set_sensitive(false);
501
0
            m_xHeightEdit->set_sensitive(false);
502
0
            m_xHeightDynBtn->set_sensitive(false);
503
504
0
            m_xLMLbl->set_sensitive(false);
505
0
            m_xLMEdit->set_sensitive(false);
506
0
            m_xRMLbl->set_sensitive(false);
507
0
            m_xRMEdit->set_sensitive(false);
508
509
0
            m_xCntSharedBox->set_sensitive(false);
510
0
            m_xBackgroundBtn->set_sensitive(false);
511
0
            m_xCntSharedFirstBox->set_sensitive(false);
512
0
        }
513
0
        else
514
0
            m_xTurnOnBox->set_active(true);
515
0
    }
516
0
    UpdateExample();
517
0
}
518
519
IMPL_LINK(SvxHFPage, TurnOnHdl, weld::Toggleable&, rBox, void)
520
0
{
521
0
    TurnOn(&rBox);
522
0
}
523
524
IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, weld::Button&, void)
525
0
{
526
0
    if(!m_pBBSet)
527
0
    {
528
        // Use only the necessary items for border and background
529
0
        const sal_uInt16 nOuter(GetWhich(SID_ATTR_BORDER_OUTER));
530
0
        const sal_uInt16 nInner(GetWhich(SID_ATTR_BORDER_INNER, false));
531
0
        const sal_uInt16 nShadow(GetWhich(SID_ATTR_BORDER_SHADOW));
532
533
0
        if(mbEnableDrawingLayerFillStyles)
534
0
        {
535
0
            m_pBBSet.reset(new SfxItemSetFixed
536
0
                            <XATTR_FILL_FIRST, XATTR_FILL_LAST,      // DrawingLayer FillStyle definitions
537
0
                             SID_COLOR_TABLE, SID_PATTERN_LIST> // XPropertyLists for Color, Gradient, Hatch and Graphic fills
538
0
                            (*GetItemSet().GetPool()));
539
            // Keep it valid
540
0
            m_pBBSet->MergeRange(nOuter, nOuter);
541
0
            m_pBBSet->MergeRange(nInner, nInner);
542
0
            m_pBBSet->MergeRange(nShadow, nShadow);
543
544
            // copy items for XPropertyList entries from the DrawModel so that
545
            // the Area TabPage can access them
546
0
            static const sal_uInt16 nCopyFlags[] = {
547
0
                SID_COLOR_TABLE,
548
0
                SID_GRADIENT_LIST,
549
0
                SID_HATCH_LIST,
550
0
                SID_BITMAP_LIST,
551
0
                SID_PATTERN_LIST,
552
0
                0
553
0
            };
554
555
0
            for(sal_uInt16 a(0); nCopyFlags[a]; a++)
556
0
            {
557
0
                const SfxPoolItem* pItem = GetItemSet().GetItem(nCopyFlags[a]);
558
559
0
                if(pItem)
560
0
                {
561
0
                    m_pBBSet->Put(*pItem);
562
0
                }
563
0
                else
564
0
                {
565
0
                    OSL_ENSURE(false, "XPropertyList missing (!)");
566
0
                }
567
0
            }
568
0
        }
569
0
        else
570
0
        {
571
0
            const sal_uInt16 nBrush(GetWhich(SID_ATTR_BRUSH));
572
573
0
            m_pBBSet.reset( new SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST>
574
0
                            (*GetItemSet().GetPool()) );
575
            // Keep it valid
576
0
            m_pBBSet->MergeRange(nBrush, nBrush);
577
0
            m_pBBSet->MergeRange(nOuter, nOuter);
578
0
            m_pBBSet->MergeRange(nInner, nInner);
579
0
            m_pBBSet->MergeRange(nShadow, nShadow);
580
0
        }
581
582
0
        const SfxPoolItem* pItem;
583
584
0
        if(SfxItemState::SET == GetItemSet().GetItemState(GetWhich(m_nId), false, &pItem))
585
0
        {
586
            // If a SfxItemSet from the SetItem for SID_ATTR_PAGE_HEADERSET or
587
            // SID_ATTR_PAGE_FOOTERSET exists, use its content
588
0
            m_pBBSet->Put(static_cast<const SvxSetItem*>(pItem)->GetItemSet());
589
0
        }
590
0
        else
591
0
        {
592
0
            if(mbEnableDrawingLayerFillStyles)
593
0
            {
594
                // The style for header/footer is not yet created, need to reset
595
                // XFillStyleItem to drawing::FillStyle_NONE which is the same as in the style
596
                // initialization. This needs to be done since the pool default for
597
                // XFillStyleItem is drawing::FillStyle_SOLID
598
0
                m_pBBSet->Put(XFillStyleItem(drawing::FillStyle_NONE));
599
0
            }
600
0
        }
601
602
0
        if(SfxItemState::SET == GetItemSet().GetItemState(nInner, false, &pItem))
603
0
        {
604
            // The set InfoItem is always required
605
0
            m_pBBSet->Put(*pItem);
606
0
        }
607
0
    }
608
609
0
    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
610
611
0
    VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxBorderBackgroundDlg(
612
0
        GetFrameWeld(),
613
0
        *m_pBBSet,
614
0
        mbEnableDrawingLayerFillStyles));
615
616
0
    pDlg->StartExecuteAsync([pDlg, this](sal_Int32 nResult) {
617
0
        if (nResult == RET_OK && pDlg->GetOutputItemSet())
618
0
        {
619
0
            SfxItemIter aIter(*pDlg->GetOutputItemSet());
620
621
0
            for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
622
0
            {
623
0
                if(!IsInvalidItem(pItem))
624
0
                {
625
0
                    m_pBBSet->Put(*pItem);
626
0
                }
627
0
            }
628
629
0
            {
630
0
                drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
631
632
0
                if (mbEnableDrawingLayerFillStyles)
633
0
                {
634
                    // create FillAttributes directly from DrawingLayer FillStyle entries
635
0
                    aFillAttributes =
636
0
                        std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(*m_pBBSet);
637
0
                }
638
0
                else
639
0
                {
640
0
                    const sal_uInt16 nWhich = GetWhich(SID_ATTR_BRUSH);
641
642
0
                    if (m_pBBSet->GetItemState(nWhich) == SfxItemState::SET)
643
0
                    {
644
                        // create FillAttributes from SvxBrushItem
645
0
                        const SvxBrushItem& rItem
646
0
                            = static_cast<const SvxBrushItem&>(m_pBBSet->Get(nWhich));
647
0
                        SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*m_pBBSet->GetPool());
648
649
0
                        setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
650
0
                        aFillAttributes =
651
0
                            std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
652
0
                    }
653
0
                }
654
655
0
                if (SID_ATTR_PAGE_HEADERSET == m_nId)
656
0
                {
657
                    //m_aBspWin.SetHdColor(rItem.GetColor());
658
0
                    m_aBspWin.setHeaderFillAttributes(aFillAttributes);
659
0
                }
660
0
                else
661
0
                {
662
                    //m_aBspWin.SetFtColor(rItem.GetColor());
663
0
                    m_aBspWin.setFooterFillAttributes(aFillAttributes);
664
0
                }
665
0
            }
666
0
        }
667
0
        pDlg->disposeOnce();
668
0
    });
669
670
0
    UpdateExample();
671
0
}
672
673
void SvxHFPage::UpdateExample()
674
0
{
675
0
    if ( m_nId == SID_ATTR_PAGE_HEADERSET )
676
0
    {
677
0
        m_aBspWin.SetHeader( m_xTurnOnBox->get_active() );
678
0
        m_aBspWin.SetHdHeight( GetCoreValue( *m_xHeightEdit, MapUnit::MapTwip ) );
679
0
        m_aBspWin.SetHdDist( GetCoreValue( *m_xDistEdit, MapUnit::MapTwip ) );
680
0
        m_aBspWin.SetHdLeft( GetCoreValue( *m_xLMEdit, MapUnit::MapTwip ) );
681
0
        m_aBspWin.SetHdRight( GetCoreValue( *m_xRMEdit, MapUnit::MapTwip ) );
682
0
    }
683
0
    else
684
0
    {
685
0
        m_aBspWin.SetFooter( m_xTurnOnBox->get_active() );
686
0
        m_aBspWin.SetFtHeight( GetCoreValue( *m_xHeightEdit, MapUnit::MapTwip ) );
687
0
        m_aBspWin.SetFtDist( GetCoreValue( *m_xDistEdit, MapUnit::MapTwip ) );
688
0
        m_aBspWin.SetFtLeft( GetCoreValue( *m_xLMEdit, MapUnit::MapTwip ) );
689
0
        m_aBspWin.SetFtRight( GetCoreValue( *m_xRMEdit, MapUnit::MapTwip ) );
690
0
    }
691
0
    m_aBspWin.Invalidate();
692
0
}
693
694
void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet )
695
0
{
696
0
    sal_uInt16 nWhich(GetWhich(SID_ATTR_PAGE_HEADERSET));
697
698
0
    if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
699
0
    {
700
0
        const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false));
701
0
        const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
702
0
        const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON));
703
704
0
        if(rOn.GetValue())
705
0
        {
706
0
            drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes;
707
708
0
            if(mbEnableDrawingLayerFillStyles)
709
0
            {
710
                // create FillAttributes directly from DrawingLayer FillStyle entries
711
0
                aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet);
712
0
            }
713
0
            else
714
0
            {
715
0
                nWhich = GetWhich(SID_ATTR_BRUSH);
716
717
0
                if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
718
0
                {
719
                    // create FillAttributes from SvxBrushItem
720
0
                    const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
721
0
                    SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*rTmpSet.GetPool());
722
723
0
                    setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
724
0
                    aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
725
0
                }
726
0
            }
727
728
0
            m_aBspWin.setHeaderFillAttributes(aHeaderFillAttributes);
729
0
        }
730
0
    }
731
732
0
    nWhich = GetWhich(SID_ATTR_PAGE_FOOTERSET);
733
734
0
    if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
735
0
    {
736
0
        const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false));
737
0
        const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
738
0
        const SfxBoolItem& rOn = rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON));
739
740
0
        if(rOn.GetValue())
741
0
        {
742
0
            drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes;
743
744
0
            if(mbEnableDrawingLayerFillStyles)
745
0
            {
746
                // create FillAttributes directly from DrawingLayer FillStyle entries
747
0
                aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet);
748
0
            }
749
0
            else
750
0
            {
751
0
                nWhich = GetWhich(SID_ATTR_BRUSH);
752
753
0
                if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
754
0
                {
755
                    // create FillAttributes from SvxBrushItem
756
0
                    const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
757
0
                    SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*rTmpSet.GetPool());
758
759
0
                    setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
760
0
                    aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
761
0
                }
762
0
            }
763
764
0
            m_aBspWin.setFooterFillAttributes(aFooterFillAttributes);
765
0
        }
766
0
    }
767
768
0
    drawinglayer::attribute::SdrAllFillAttributesHelperPtr aPageFillAttributes;
769
770
0
    if(mbEnableDrawingLayerFillStyles)
771
0
    {
772
        // create FillAttributes directly from DrawingLayer FillStyle entries
773
0
        aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rSet);
774
0
    }
775
0
    else
776
0
    {
777
0
        nWhich = GetWhich(SID_ATTR_BRUSH);
778
779
0
        if(rSet.GetItemState(nWhich) >= SfxItemState::DEFAULT)
780
0
        {
781
            // create FillAttributes from SvxBrushItem
782
0
            const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rSet.Get(nWhich));
783
0
            SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aTempSet(*rSet.GetPool());
784
785
0
            setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
786
0
            aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
787
0
        }
788
0
    }
789
790
0
    m_aBspWin.setPageFillAttributes(aPageFillAttributes);
791
0
}
792
793
void SvxHFPage::ActivatePage( const SfxItemSet& rSet )
794
0
{
795
0
    const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE );
796
797
0
    if ( pItem )
798
0
    {
799
        // Set left and right margins
800
0
        const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(*pItem);
801
802
0
        m_aBspWin.SetLeft(rLRSpace.ResolveLeft({}));
803
0
        m_aBspWin.SetRight(rLRSpace.ResolveRight({}));
804
0
    }
805
0
    else
806
0
    {
807
0
        m_aBspWin.SetLeft( 0 );
808
0
        m_aBspWin.SetRight( 0 );
809
0
    }
810
811
0
    pItem = GetItem( rSet, SID_ATTR_ULSPACE );
812
813
0
    if ( pItem )
814
0
    {
815
        // Set top and bottom margins
816
0
        const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(*pItem);
817
818
0
        m_aBspWin.SetTop( rULSpace.GetUpper() );
819
0
        m_aBspWin.SetBottom( rULSpace.GetLower() );
820
0
    }
821
0
    else
822
0
    {
823
0
        m_aBspWin.SetTop( 0 );
824
0
        m_aBspWin.SetBottom( 0 );
825
0
    }
826
827
0
    SvxPageUsage nUsage = SvxPageUsage::All;
828
0
    pItem = GetItem( rSet, SID_ATTR_PAGE );
829
830
0
    if ( pItem )
831
0
        nUsage = static_cast<const SvxPageItem*>(pItem)->GetPageUsage();
832
833
0
    m_aBspWin.SetUsage( nUsage );
834
835
0
    if ( SvxPageUsage::Right == nUsage || SvxPageUsage::Left == nUsage )
836
0
        m_xCntSharedBox->set_sensitive(false);
837
0
    else
838
0
    {
839
0
        m_xCntSharedBox->set_sensitive(true);
840
0
        m_xCntSharedFirstBox->set_sensitive(true);
841
0
    }
842
0
    pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
843
844
0
    if ( pItem )
845
0
    {
846
        // Orientation and Size from the PageItem
847
0
        const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(*pItem);
848
        // if the size is already swapped (Landscape)
849
0
        m_aBspWin.SetSize( rSize.GetSize() );
850
0
    }
851
852
    // For Writer, either header OR footer can indicate that first H/F will have different contents.
853
    // Prioritize the non-activated tab's setting (in case the value was already changed there).
854
0
    std::optional<bool> oNonActivatedFirstShared; // only used by Writer
855
0
    bool bActivatedFirstShared = true; // default value
856
0
    const sal_uInt16 nSidAttrPageSharedFirst = GetWhich(SID_ATTR_PAGE_SHARED_FIRST);
857
858
    // Evaluate Header attribute
859
0
    const SvxSetItem* pSetItem = nullptr;
860
861
0
    if ( SfxItemState::SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
862
0
                                            false,
863
0
                                            reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
864
0
    {
865
0
        const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
866
0
        const SfxBoolItem& rHeaderOn =
867
0
            rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
868
869
0
        if ( rHeaderOn.GetValue() )
870
0
        {
871
0
            const SvxSizeItem& rSize =
872
0
                rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
873
0
            const SvxULSpaceItem& rUL = rHeaderSet.Get( GetWhich(SID_ATTR_ULSPACE ) );
874
0
            const SvxLRSpaceItem& rLR = rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
875
0
            tools::Long nDist = rUL.GetLower();
876
877
0
            m_aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist );
878
0
            m_aBspWin.SetHdDist( nDist );
879
0
            m_aBspWin.SetHdLeft(rLR.ResolveLeft({}));
880
0
            m_aBspWin.SetHdRight(rLR.ResolveRight({}));
881
0
            m_aBspWin.SetHeader( true );
882
0
            const SfxBoolItem* pSharedFirst = nullptr;
883
0
            if (rHeaderSet.HasItem(nSidAttrPageSharedFirst))
884
0
                 pSharedFirst
885
0
                    = static_cast<const SfxBoolItem*>(&rHeaderSet.Get(nSidAttrPageSharedFirst));
886
0
            if (pSharedFirst)
887
0
            {
888
0
                if (SID_ATTR_PAGE_HEADERSET == m_nId || m_bIsCalc)
889
0
                    bActivatedFirstShared = pSharedFirst->GetValue();
890
0
                else
891
0
                    oNonActivatedFirstShared = pSharedFirst->GetValue();
892
0
            }
893
0
        }
894
0
        else
895
0
            pSetItem = nullptr;
896
0
    }
897
898
0
    if ( !pSetItem )
899
0
    {
900
0
        m_aBspWin.SetHeader( false );
901
902
0
        if ( SID_ATTR_PAGE_HEADERSET == m_nId )
903
0
        {
904
0
            m_xCntSharedBox->set_sensitive(false);
905
0
            m_xCntSharedFirstBox->set_sensitive(false);
906
0
        }
907
0
    }
908
0
    pSetItem = nullptr;
909
910
0
    if ( SfxItemState::SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
911
0
                                            false,
912
0
                                            reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
913
0
    {
914
0
        const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
915
0
        const SfxBoolItem& rFooterOn =
916
0
            rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
917
918
0
        if ( rFooterOn.GetValue() )
919
0
        {
920
0
            const SvxSizeItem& rSize =
921
0
                rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
922
0
            const SvxULSpaceItem& rUL = rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
923
0
            const SvxLRSpaceItem& rLR = rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
924
0
            tools::Long nDist = rUL.GetUpper();
925
926
0
            m_aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist );
927
0
            m_aBspWin.SetFtDist( nDist );
928
0
            m_aBspWin.SetFtLeft(rLR.ResolveLeft({}));
929
0
            m_aBspWin.SetFtRight(rLR.ResolveRight({}));
930
0
            m_aBspWin.SetFooter( true );
931
0
            const SfxBoolItem* pSharedFirst = nullptr;
932
0
            if (rFooterSet.HasItem(nSidAttrPageSharedFirst))
933
0
                 pSharedFirst
934
0
                    = static_cast<const SfxBoolItem*>(&rFooterSet.Get(nSidAttrPageSharedFirst));
935
0
            if (pSharedFirst)
936
0
            {
937
0
                if (SID_ATTR_PAGE_FOOTERSET == m_nId || m_bIsCalc)
938
0
                    bActivatedFirstShared = pSharedFirst->GetValue();
939
0
                else
940
0
                    oNonActivatedFirstShared = pSharedFirst->GetValue();
941
0
            }
942
0
        }
943
0
        else
944
0
            pSetItem = nullptr;
945
0
    }
946
947
0
    if ( !pSetItem )
948
0
    {
949
0
        m_aBspWin.SetFooter( false );
950
951
0
        if ( SID_ATTR_PAGE_FOOTERSET == m_nId )
952
0
        {
953
0
            m_xCntSharedBox->set_sensitive(false);
954
0
            m_xCntSharedFirstBox->set_sensitive(false);
955
0
        }
956
0
    }
957
958
    // Priority: non-active tab's FirstBox - then this tab's First - otherwise default is shared
959
0
    m_xCntSharedFirstBox->set_active(
960
0
        oNonActivatedFirstShared.has_value() ? *oNonActivatedFirstShared : bActivatedFirstShared);
961
962
0
    pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
963
964
0
    if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
965
0
    {
966
0
        m_aBspWin.SetTable( true );
967
0
        m_aBspWin.SetHorz( pBoolItem->GetValue() );
968
0
    }
969
970
0
    pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
971
972
0
    if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
973
0
    {
974
0
        m_aBspWin.SetTable( true );
975
0
        m_aBspWin.SetVert( pBoolItem->GetValue() );
976
0
    }
977
0
    ResetBackground_Impl( rSet );
978
0
    RangeHdl();
979
0
}
980
981
DeactivateRC SvxHFPage::DeactivatePage( SfxItemSet* _pSet )
982
0
{
983
0
    if ( _pSet )
984
0
        FillItemSet( _pSet );
985
0
    return DeactivateRC::LeavePage;
986
0
}
987
988
IMPL_LINK_NOARG(SvxHFPage, ValueChangeHdl, weld::MetricSpinButton&, void)
989
0
{
990
0
    UpdateExample();
991
0
    RangeHdl();
992
0
}
993
994
void SvxHFPage::RangeHdl()
995
0
{
996
0
    tools::Long nHHeight = m_aBspWin.GetHdHeight();
997
0
    tools::Long nHDist   = m_aBspWin.GetHdDist();
998
999
0
    tools::Long nFHeight = m_aBspWin.GetFtHeight();
1000
0
    tools::Long nFDist   = m_aBspWin.GetFtDist();
1001
1002
0
    tools::Long nHeight = std::max(tools::Long(MINBODY),
1003
0
        static_cast<tools::Long>(m_xHeightEdit->denormalize(m_xHeightEdit->get_value(FieldUnit::TWIP))));
1004
0
    tools::Long nDist   = m_xTurnOnBox->get_active() ?
1005
0
        static_cast<tools::Long>(m_xDistEdit->denormalize(m_xDistEdit->get_value(FieldUnit::TWIP))) : 0;
1006
1007
0
    tools::Long nMin;
1008
0
    tools::Long nMax;
1009
1010
0
    if ( m_nId == SID_ATTR_PAGE_HEADERSET )
1011
0
    {
1012
0
        nHHeight = nHeight;
1013
0
        nHDist   = nDist;
1014
0
    }
1015
0
    else
1016
0
    {
1017
0
        nFHeight = nHeight;
1018
0
        nFDist   = nDist;
1019
0
    }
1020
1021
    // Current values of the side edges
1022
0
    tools::Long nBT = m_aBspWin.GetTop();
1023
0
    tools::Long nBB = m_aBspWin.GetBottom();
1024
0
    tools::Long nBL = m_aBspWin.GetLeft();
1025
0
    tools::Long nBR = m_aBspWin.GetRight();
1026
1027
0
    tools::Long nH  = m_aBspWin.GetSize().Height();
1028
0
    tools::Long nW  = m_aBspWin.GetSize().Width();
1029
1030
    // Borders
1031
0
    if ( m_nId == SID_ATTR_PAGE_HEADERSET )
1032
0
    {
1033
        // Header
1034
0
        nMin = ( nH - nBB - nBT ) / 5; // 20%
1035
0
        nMax = std::max( nH - nMin - nHDist - nFDist - nFHeight - nBB - nBT,
1036
0
                    nMin );
1037
0
        m_xHeightEdit->set_max(m_xHeightEdit->normalize(nMax), FieldUnit::TWIP);
1038
0
        nMin = ( nH - nBB - nBT ) / 5; // 20%
1039
0
        nDist = std::max( nH - nMin - nHHeight - nFDist - nFHeight - nBB - nBT,
1040
0
                     tools::Long(0) );
1041
0
        m_xDistEdit->set_max(m_xDistEdit->normalize(nDist), FieldUnit::TWIP);
1042
0
    }
1043
0
    else
1044
0
    {
1045
        // Footer
1046
0
        nMin = ( nH - nBT - nBB ) / 5; // 20%
1047
0
        nMax = std::max( nH - nMin - nFDist - nHDist - nHHeight - nBT - nBB,
1048
0
                    nMin );
1049
0
        m_xHeightEdit->set_max(m_xHeightEdit->normalize(nMax), FieldUnit::TWIP);
1050
0
        nMin = ( nH - nBT - nBB ) / 5; // 20%
1051
0
        nDist = std::max( nH - nMin - nFHeight - nHDist - nHHeight - nBT - nBB,
1052
0
                     tools::Long(0) );
1053
0
        m_xDistEdit->set_max(m_xDistEdit->normalize(nDist), FieldUnit::TWIP);
1054
0
    }
1055
1056
    // Limit Indentation
1057
0
    nMax = nW - nBL - nBR -
1058
0
           static_cast<tools::Long>(m_xRMEdit->denormalize(m_xRMEdit->get_value(FieldUnit::TWIP))) - MINBODY;
1059
0
    m_xLMEdit->set_max(m_xLMEdit->normalize(nMax), FieldUnit::TWIP);
1060
1061
0
    nMax = nW - nBL - nBR -
1062
0
           static_cast<tools::Long>(m_xLMEdit->denormalize(m_xLMEdit->get_value(FieldUnit::TWIP))) - MINBODY;
1063
0
    m_xRMEdit->set_max(m_xLMEdit->normalize(nMax), FieldUnit::TWIP);
1064
0
}
1065
1066
void SvxHFPage::EnableDynamicSpacing()
1067
0
{
1068
0
    m_xDynSpacingCB->show();
1069
0
}
1070
1071
void SvxHFPage::PageCreated(const SfxAllItemSet &rSet)
1072
0
{
1073
0
    const SfxBoolItem* pSupportDrawingLayerFillStyleItem = rSet.GetItem<SfxBoolItem>(SID_DRAWINGLAYER_FILLSTYLES, false);
1074
1075
0
    if (pSupportDrawingLayerFillStyleItem)
1076
0
    {
1077
0
        const bool bNew(pSupportDrawingLayerFillStyleItem->GetValue());
1078
1079
0
        mbEnableDrawingLayerFillStyles = bNew;
1080
0
    }
1081
0
}
1082
1083
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */