1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <o3tl/unit_conversion.hxx>
23 #include <svl/itemiter.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <svx/svxids.hrc>
27 #include <svl/intitem.hxx>
28 #include <svtools/unitconv.hxx>
30 #include <svx/hdft.hxx>
31 #include <svx/pageitem.hxx>
33 #include <svx/dlgutil.hxx>
34 #include <sfx2/htmlmode.hxx>
35 #include <osl/diagnose.h>
37 #include <editeng/brushitem.hxx>
38 #include <editeng/lrspitem.hxx>
39 #include <editeng/ulspitem.hxx>
40 #include <editeng/sizeitem.hxx>
41 #include <editeng/boxitem.hxx>
43 #include <svx/svxdlg.hxx>
46 #include <svx/xdef.hxx>
47 #include <svx/xfillit0.hxx>
48 #include <svx/unobrushitemhelper.hxx>
50 using namespace com::sun::star
;
52 // Word 97 incompatibility (#i19922#)
53 // #i19922# - tdf#126051 see cui/source/tabpages/page.cxx and sw/source/uibase/sidebar/PageMarginControl.hxx
54 constexpr tools::Long MINBODY
= o3tl::toTwips(1, o3tl::Length::mm
); // 1mm in twips rounded
56 // default distance to Header or footer
57 const tools::Long DEF_DIST_WRITER
= 500; // 5mm (Writer)
58 const tools::Long DEF_DIST_CALC
= 250; // 2.5mm (Calc)
60 const WhichRangesContainer
SvxHFPage::pRanges(svl::Items
<
61 // Support DrawingLayer FillStyles (no real call to below GetRanges()
62 // detected, still do the complete transition)
63 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
65 SID_ATTR_BRUSH
, SID_ATTR_BRUSH
,
66 SID_ATTR_BORDER_INNER
, SID_ATTR_BORDER_INNER
,
67 SID_ATTR_BORDER_OUTER
, SID_ATTR_BORDER_OUTER
,
68 SID_ATTR_BORDER_SHADOW
, SID_ATTR_BORDER_SHADOW
,
69 SID_ATTR_LRSPACE
, SID_ATTR_LRSPACE
,
70 SID_ATTR_ULSPACE
, SID_ATTR_ULSPACE
,
71 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
72 SID_ATTR_PAGE_HEADERSET
, SID_ATTR_PAGE_HEADERSET
,
73 SID_ATTR_PAGE_FOOTERSET
, SID_ATTR_PAGE_FOOTERSET
,
74 SID_ATTR_PAGE_ON
, SID_ATTR_PAGE_ON
,
75 SID_ATTR_PAGE_DYNAMIC
, SID_ATTR_PAGE_DYNAMIC
,
76 SID_ATTR_PAGE_SHARED
, SID_ATTR_PAGE_SHARED
,
77 SID_ATTR_HDFT_DYNAMIC_SPACING
, SID_ATTR_HDFT_DYNAMIC_SPACING
,
78 SID_ATTR_PAGE_SHARED_FIRST
, SID_ATTR_PAGE_SHARED_FIRST
83 bool ShowBorderBackgroundDlg(weld::Window
* pParent
, SfxItemSet
* pBBSet
)
86 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
87 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSvxBorderBackgroundDlg(pParent
, *pBBSet
, true /*bEnableDrawingLayerFillStyles*/));
88 if ( pDlg
->Execute() == RET_OK
&& pDlg
->GetOutputItemSet() )
90 SfxItemIter
aIter( *pDlg
->GetOutputItemSet() );
92 for (const SfxPoolItem
* pItem
= aIter
.GetCurItem(); pItem
; pItem
= aIter
.NextItem())
94 if ( !IsInvalidItem( pItem
) )
95 pBBSet
->Put( *pItem
);
103 std::unique_ptr
<SfxTabPage
> SvxHeaderPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
105 return std::make_unique
<SvxHeaderPage
>( pPage
, pController
, *rSet
);
108 std::unique_ptr
<SfxTabPage
> SvxFooterPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rSet
)
110 return std::make_unique
<SvxFooterPage
>( pPage
, pController
, *rSet
);
113 SvxHeaderPage::SvxHeaderPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rAttr
)
114 : SvxHFPage( pPage
, pController
, rAttr
, SID_ATTR_PAGE_HEADERSET
)
118 SvxFooterPage::SvxFooterPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rAttr
)
119 : SvxHFPage( pPage
, pController
, rAttr
, SID_ATTR_PAGE_FOOTERSET
)
123 SvxHFPage::SvxHFPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
, sal_uInt16 nSetId
)
124 : SfxTabPage(pPage
, pController
, "svx/ui/headfootformatpage.ui", "HFFormatPage", &rSet
)
126 , mbDisableQueryBox(false)
127 , mbEnableDrawingLayerFillStyles(false)
128 , m_xCntSharedBox(m_xBuilder
->weld_check_button("checkSameLR"))
129 , m_xCntSharedFirstBox(m_xBuilder
->weld_check_button("checkSameFP"))
130 , m_xLMLbl(m_xBuilder
->weld_label("labelLeftMarg"))
131 , m_xLMEdit(m_xBuilder
->weld_metric_spin_button("spinMargLeft", FieldUnit::CM
))
132 , m_xRMLbl(m_xBuilder
->weld_label("labelRightMarg"))
133 , m_xRMEdit(m_xBuilder
->weld_metric_spin_button("spinMargRight", FieldUnit::CM
))
134 , m_xDistFT(m_xBuilder
->weld_label("labelSpacing"))
135 , m_xDistEdit(m_xBuilder
->weld_metric_spin_button("spinSpacing", FieldUnit::CM
))
136 , m_xDynSpacingCB(m_xBuilder
->weld_check_button("checkDynSpacing"))
137 , m_xHeightFT(m_xBuilder
->weld_label("labelHeight"))
138 , m_xHeightEdit(m_xBuilder
->weld_metric_spin_button("spinHeight", FieldUnit::CM
))
139 , m_xHeightDynBtn(m_xBuilder
->weld_check_button("checkAutofit"))
140 , m_xBackgroundBtn(m_xBuilder
->weld_button("buttonMore"))
141 , m_xBspWin(new weld::CustomWeld(*m_xBuilder
, "drawingareaPageHF", m_aBspWin
))
143 //swap header <-> footer in UI
144 if (nId
== SID_ATTR_PAGE_FOOTERSET
)
146 m_xContainer
->set_help_id("svx/ui/headfootformatpage/FFormatPage");
147 m_xPageLbl
= m_xBuilder
->weld_label("labelFooterFormat");
148 m_xTurnOnBox
= m_xBuilder
->weld_check_button("checkFooterOn");
150 /* Set custom HIDs for the Footer help page (shared/01/05040400.xhp)
151 otherwise it would display the same extended help
152 on both the Header and Footer tabs */
153 m_xCntSharedBox
->set_help_id( "SVX_HID_FOOTER_CHECKSAMELR" );
154 m_xCntSharedFirstBox
->set_help_id( "SVX_HID_FOOTER_CHECKSAMEFP" );
155 m_xLMEdit
->set_help_id( "SVX_HID_FOOTER_SPINMARGLEFT" );
156 m_xRMEdit
->set_help_id( "SVX_HID_FOOTER_SPINMARGRIGHT" );
157 m_xDistEdit
->set_help_id( "SVX_HID_FOOTER_SPINSPACING" );
158 m_xDynSpacingCB
->set_help_id( "SVX_HID_FOOTER_CHECKDYNSPACING" );
159 m_xHeightEdit
->set_help_id( "SVX_HID_FOOTER_SPINHEIGHT" );
160 m_xHeightDynBtn
->set_help_id( "SVX_HID_FOOTER_CHECKAUTOFIT" );
161 m_xBackgroundBtn
->set_help_id( "SVX_HID_FOOTER_BUTTONMORE" );
165 m_xContainer
->set_help_id("svx/ui/headfootformatpage/HFormatPage");
166 m_xPageLbl
= m_xBuilder
->weld_label("labelHeaderFormat");
167 m_xTurnOnBox
= m_xBuilder
->weld_check_button("checkHeaderOn");
169 m_xTurnOnBox
->show();
173 m_aBspWin
.EnableRTL(false);
175 // This Page needs ExchangeSupport
176 SetExchangeSupport();
179 FieldUnit eFUnit
= GetModuleFieldUnit( rSet
);
180 SetFieldUnit( *m_xDistEdit
, eFUnit
);
181 SetFieldUnit( *m_xHeightEdit
, eFUnit
);
182 SetFieldUnit( *m_xLMEdit
, eFUnit
);
183 SetFieldUnit( *m_xRMEdit
, eFUnit
);
186 SvxHFPage::~SvxHFPage()
190 bool SvxHFPage::FillItemSet( SfxItemSet
* rSet
)
192 const sal_uInt16 nWSize
= GetWhich(SID_ATTR_PAGE_SIZE
);
193 const sal_uInt16 nWLRSpace
= GetWhich(SID_ATTR_LRSPACE
);
194 const sal_uInt16 nWULSpace
= GetWhich(SID_ATTR_ULSPACE
);
195 const sal_uInt16 nWOn
= GetWhich(SID_ATTR_PAGE_ON
);
196 const sal_uInt16 nWDynamic
= GetWhich(SID_ATTR_PAGE_DYNAMIC
);
197 const sal_uInt16 nWDynSpacing
= GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING
);
198 const sal_uInt16 nWShared
= GetWhich(SID_ATTR_PAGE_SHARED
);
199 const sal_uInt16 nWSharedFirst
= GetWhich( SID_ATTR_PAGE_SHARED_FIRST
);
200 const sal_uInt16 nWBrush
= GetWhich(SID_ATTR_BRUSH
);
201 const sal_uInt16 nWBox
= GetWhich(SID_ATTR_BORDER_OUTER
);
202 const sal_uInt16 nWBoxInfo
= GetWhich(SID_ATTR_BORDER_INNER
);
203 const sal_uInt16 nWShadow
= GetWhich(SID_ATTR_BORDER_SHADOW
);
205 const SfxItemSet
& rOldSet
= GetItemSet();
206 SfxItemPool
* pPool
= rOldSet
.GetPool();
207 DBG_ASSERT(pPool
,"no pool :-(");
208 MapUnit eUnit
= pPool
->GetMetric(nWSize
);
209 // take over DrawingLayer FillStyles
210 SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
> aSet(*pPool
);
212 aSet
.MergeRange(nWSize
, nWSize
);
213 aSet
.MergeRange(nWLRSpace
, nWLRSpace
);
214 aSet
.MergeRange(nWULSpace
, nWULSpace
);
215 aSet
.MergeRange(nWOn
, nWOn
);
216 aSet
.MergeRange(nWDynamic
, nWDynamic
);
217 aSet
.MergeRange(nWShared
, nWShared
);
218 aSet
.MergeRange(nWSharedFirst
, nWSharedFirst
);
219 aSet
.MergeRange(nWBrush
, nWBrush
);
220 aSet
.MergeRange(nWBoxInfo
, nWBoxInfo
);
221 aSet
.MergeRange(nWBox
, nWBox
);
222 aSet
.MergeRange(nWShadow
, nWShadow
);
223 aSet
.MergeRange(nWDynSpacing
, nWDynSpacing
);
225 if(mbEnableDrawingLayerFillStyles
)
227 // When using the XATTR_FILLSTYLE DrawingLayer FillStyle definition
228 // extra action has to be done here since the pool default is drawing::FillStyle_SOLID
229 // instead of drawing::FillStyle_NONE (to have the default blue fill color at start).
230 aSet
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
233 aSet
.Put( SfxBoolItem( nWOn
, m_xTurnOnBox
->get_active() ) );
234 aSet
.Put( SfxBoolItem( nWDynamic
, m_xHeightDynBtn
->get_active() ) );
235 aSet
.Put( SfxBoolItem( nWShared
, m_xCntSharedBox
->get_active() ) );
236 if(m_xCntSharedFirstBox
->get_visible())
237 aSet
.Put(SfxBoolItem(nWSharedFirst
, m_xCntSharedFirstBox
->get_active()));
238 if (m_xDynSpacingCB
->get_visible() && SfxItemPool::IsWhich(nWDynSpacing
))
240 std::unique_ptr
<SfxBoolItem
> pBoolItem(static_cast<SfxBoolItem
*>(pPool
->GetDefaultItem(nWDynSpacing
).Clone()));
241 pBoolItem
->SetValue(m_xDynSpacingCB
->get_active());
242 aSet
.Put(std::move(pBoolItem
));
246 SvxSizeItem
aSizeItem( static_cast<const SvxSizeItem
&>(rOldSet
.Get( nWSize
)) );
247 Size
aSize( aSizeItem
.GetSize() );
248 tools::Long nDist
= GetCoreValue( *m_xDistEdit
, eUnit
);
249 tools::Long nH
= GetCoreValue( *m_xHeightEdit
, eUnit
);
251 nH
+= nDist
; // add distance
252 aSize
.setHeight( nH
);
253 aSizeItem
.SetSize( aSize
);
254 aSet
.Put( aSizeItem
);
257 SvxLRSpaceItem
aLR( nWLRSpace
);
258 aLR
.SetLeft( static_cast<sal_uInt16
>(GetCoreValue( *m_xLMEdit
, eUnit
)) );
259 aLR
.SetRight( static_cast<sal_uInt16
>(GetCoreValue( *m_xRMEdit
, eUnit
)) );
262 SvxULSpaceItem
aUL( nWULSpace
);
263 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
264 aUL
.SetLower( static_cast<sal_uInt16
>(nDist
) );
266 aUL
.SetUpper( static_cast<sal_uInt16
>(nDist
) );
269 // Background and border?
276 const SfxPoolItem
* pItem
;
278 if(SfxItemState::SET
== GetItemSet().GetItemState(GetWhich(nId
), false, &pItem
))
280 const SfxItemSet
* _pSet
= &(static_cast< const SvxSetItem
* >(pItem
)->GetItemSet());
282 if(_pSet
->GetItemState(nWBrush
) == SfxItemState::SET
)
284 aSet
.Put(_pSet
->Get(nWBrush
));
287 if(_pSet
->GetItemState(nWBoxInfo
) == SfxItemState::SET
)
289 aSet
.Put(_pSet
->Get(nWBoxInfo
));
292 if(_pSet
->GetItemState(nWBox
) == SfxItemState::SET
)
294 aSet
.Put(_pSet
->Get(nWBox
));
297 if(_pSet
->GetItemState(nWShadow
) == SfxItemState::SET
)
299 aSet
.Put(_pSet
->Get(nWShadow
));
302 // take care of [XATTR_XATTR_FILL_FIRST .. XATTR_FILL_LAST]
303 for(sal_uInt16
nFillStyleId(XATTR_FILL_FIRST
); nFillStyleId
<= XATTR_FILL_LAST
; nFillStyleId
++)
305 if(_pSet
->GetItemState(nFillStyleId
) == SfxItemState::SET
)
307 aSet
.Put(_pSet
->Get(nFillStyleId
));
314 SvxSetItem
aSetItem( TypedWhichId
<SvxSetItem
>(GetWhich( nId
)), aSet
);
315 rSet
->Put( aSetItem
);
321 void SvxHFPage::Reset( const SfxItemSet
* rSet
)
323 ActivatePage( *rSet
);
324 ResetBackground_Impl( *rSet
);
326 SfxItemPool
* pPool
= GetItemSet().GetPool();
327 DBG_ASSERT( pPool
, "Where is the pool" );
328 MapUnit eUnit
= pPool
->GetMetric( GetWhich( SID_ATTR_PAGE_SIZE
) );
330 // Evaluate header-/footer- attributes
331 const SvxSetItem
* pSetItem
= nullptr;
333 if ( SfxItemState::SET
== rSet
->GetItemState( GetWhich(nId
), false,
334 reinterpret_cast<const SfxPoolItem
**>(&pSetItem
) ) )
336 const SfxItemSet
& rHeaderSet
= pSetItem
->GetItemSet();
337 const SfxBoolItem
& rHeaderOn
=
338 rHeaderSet
.Get(GetWhich(SID_ATTR_PAGE_ON
));
340 m_xTurnOnBox
->set_active(rHeaderOn
.GetValue());
342 if ( rHeaderOn
.GetValue() )
344 const SfxBoolItem
& rDynamic
=
345 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC
) );
346 const SfxBoolItem
& rShared
=
347 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SHARED
) );
348 const SfxBoolItem
* pSharedFirst
= nullptr;
349 if (rHeaderSet
.HasItem(GetWhich(SID_ATTR_PAGE_SHARED_FIRST
)))
350 pSharedFirst
= static_cast<const SfxBoolItem
*>(&rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SHARED_FIRST
) ));
351 const SvxSizeItem
& rSize
=
352 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
353 const SvxULSpaceItem
& rUL
= rHeaderSet
.Get( GetWhich( SID_ATTR_ULSPACE
) );
354 const SvxLRSpaceItem
& rLR
= rHeaderSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
355 if (m_xDynSpacingCB
->get_visible())
357 const SfxBoolItem
& rDynSpacing
=
358 static_cast<const SfxBoolItem
&>(rHeaderSet
.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING
)));
359 m_xDynSpacingCB
->set_active(rDynSpacing
.GetValue());
363 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
365 SetMetricValue( *m_xDistEdit
, rUL
.GetLower(), eUnit
);
366 SetMetricValue( *m_xHeightEdit
, rSize
.GetSize().Height() - rUL
.GetLower(), eUnit
);
370 SetMetricValue( *m_xDistEdit
, rUL
.GetUpper(), eUnit
);
371 SetMetricValue( *m_xHeightEdit
, rSize
.GetSize().Height() - rUL
.GetUpper(), eUnit
);
374 m_xHeightDynBtn
->set_active(rDynamic
.GetValue());
375 SetMetricValue( *m_xLMEdit
, rLR
.GetLeft(), eUnit
);
376 SetMetricValue( *m_xRMEdit
, rLR
.GetRight(), eUnit
);
377 m_xCntSharedBox
->set_active(rShared
.GetValue());
379 m_xCntSharedFirstBox
->set_active(pSharedFirst
->GetValue());
386 bool bIsCalc
= false;
387 const SfxPoolItem
* pExt1
= GetItem(*rSet
, SID_ATTR_PAGE_EXT1
);
388 const SfxPoolItem
* pExt2
= GetItem(*rSet
, SID_ATTR_PAGE_EXT2
);
389 if (dynamic_cast<const SfxBoolItem
*>(pExt1
) && dynamic_cast<const SfxBoolItem
*>(pExt2
) )
392 // defaults for distance and height
393 tools::Long nDefaultDist
= bIsCalc
? DEF_DIST_CALC
: DEF_DIST_WRITER
;
394 SetMetricValue( *m_xDistEdit
, nDefaultDist
, MapUnit::Map100thMM
);
395 SetMetricValue( *m_xHeightEdit
, 500, MapUnit::Map100thMM
);
400 m_xTurnOnBox
->set_active(false);
401 m_xHeightDynBtn
->set_active(true);
402 m_xCntSharedBox
->set_active(true);
403 m_xCntSharedFirstBox
->set_active(true);
408 m_xTurnOnBox
->save_state();
409 m_xDistEdit
->save_value();
410 m_xHeightEdit
->save_value();
411 m_xHeightDynBtn
->save_state();
412 m_xLMEdit
->save_value();
413 m_xRMEdit
->save_value();
414 m_xCntSharedBox
->save_state();
417 SfxObjectShell
* pShell
;
418 const SfxUInt16Item
* pItem
= rSet
->GetItemIfSet(SID_HTML_MODE
, false);
420 ( nullptr != (pShell
= SfxObjectShell::Current()) &&
421 nullptr != (pItem
= pShell
->GetItem(SID_HTML_MODE
))))
423 sal_uInt16 nHtmlMode
= pItem
->GetValue();
424 if (nHtmlMode
& HTMLMODE_ON
)
426 m_xCntSharedBox
->hide();
427 m_xBackgroundBtn
->hide();
433 void SvxHFPage::InitHandler()
435 m_xTurnOnBox
->connect_toggled(LINK(this, SvxHFPage
, TurnOnHdl
));
436 m_xDistEdit
->connect_value_changed(LINK(this, SvxHFPage
, ValueChangeHdl
));
437 m_xHeightEdit
->connect_value_changed(LINK(this,SvxHFPage
,ValueChangeHdl
));
439 m_xLMEdit
->connect_value_changed(LINK(this, SvxHFPage
, ValueChangeHdl
));
440 m_xRMEdit
->connect_value_changed(LINK(this, SvxHFPage
, ValueChangeHdl
));
441 m_xBackgroundBtn
->connect_clicked(LINK(this,SvxHFPage
, BackgroundHdl
));
444 void SvxHFPage::TurnOn(const weld::Toggleable
* pBox
)
446 if (m_xTurnOnBox
->get_active())
448 m_xDistFT
->set_sensitive(true);
449 m_xDistEdit
->set_sensitive(true);
450 m_xDynSpacingCB
->set_sensitive(true);
451 m_xHeightFT
->set_sensitive(true);
452 m_xHeightEdit
->set_sensitive(true);
453 m_xHeightDynBtn
->set_sensitive(true);
454 m_xLMLbl
->set_sensitive(true);
455 m_xLMEdit
->set_sensitive(true);
456 m_xRMLbl
->set_sensitive(true);
457 m_xRMEdit
->set_sensitive(true);
459 SvxPageUsage nUsage
= m_aBspWin
.GetUsage();
461 if( nUsage
== SvxPageUsage::Right
|| nUsage
== SvxPageUsage::Left
)
462 m_xCntSharedBox
->set_sensitive(false);
465 m_xCntSharedBox
->set_sensitive(true);
466 m_xCntSharedFirstBox
->set_sensitive(true);
468 m_xBackgroundBtn
->set_sensitive(true);
474 if (!mbDisableQueryBox
&& pBox
&& m_xTurnOnBox
->get_saved_state() == TRISTATE_TRUE
)
477 if (nId
== SID_ATTR_PAGE_HEADERSET
)
479 DeleteHeaderDialog
aDlg(GetFrameWeld());
480 nResult
= aDlg
.run();
484 DeleteFooterDialog
aDlg(GetFrameWeld());
485 nResult
= aDlg
.run();
487 bDelete
= nResult
== RET_YES
;
492 m_xDistFT
->set_sensitive(false);
493 m_xDistEdit
->set_sensitive(false);
494 m_xDynSpacingCB
->set_sensitive(false);
495 m_xHeightFT
->set_sensitive(false);
496 m_xHeightEdit
->set_sensitive(false);
497 m_xHeightDynBtn
->set_sensitive(false);
499 m_xLMLbl
->set_sensitive(false);
500 m_xLMEdit
->set_sensitive(false);
501 m_xRMLbl
->set_sensitive(false);
502 m_xRMEdit
->set_sensitive(false);
504 m_xCntSharedBox
->set_sensitive(false);
505 m_xBackgroundBtn
->set_sensitive(false);
506 m_xCntSharedFirstBox
->set_sensitive(false);
509 m_xTurnOnBox
->set_active(true);
514 IMPL_LINK(SvxHFPage
, TurnOnHdl
, weld::Toggleable
&, rBox
, void)
519 IMPL_LINK_NOARG(SvxHFPage
, BackgroundHdl
, weld::Button
&, void)
523 // Use only the necessary items for border and background
524 const sal_uInt16
nOuter(GetWhich(SID_ATTR_BORDER_OUTER
));
525 const sal_uInt16
nInner(GetWhich(SID_ATTR_BORDER_INNER
, false));
526 const sal_uInt16
nShadow(GetWhich(SID_ATTR_BORDER_SHADOW
));
528 if(mbEnableDrawingLayerFillStyles
)
530 pBBSet
.reset(new SfxItemSetFixed
531 <XATTR_FILL_FIRST
, XATTR_FILL_LAST
, // DrawingLayer FillStyle definitions
532 SID_COLOR_TABLE
, SID_PATTERN_LIST
> // XPropertyLists for Color, Gradient, Hatch and Graphic fills
533 (*GetItemSet().GetPool()));
535 pBBSet
->MergeRange(nOuter
, nOuter
);
536 pBBSet
->MergeRange(nInner
, nInner
);
537 pBBSet
->MergeRange(nShadow
, nShadow
);
539 // copy items for XPropertyList entries from the DrawModel so that
540 // the Area TabPage can access them
541 static const sal_uInt16 nCopyFlags
[] = {
550 for(sal_uInt16
a(0); nCopyFlags
[a
]; a
++)
552 const SfxPoolItem
* pItem
= GetItemSet().GetItem(nCopyFlags
[a
]);
560 OSL_ENSURE(false, "XPropertyList missing (!)");
566 const sal_uInt16
nBrush(GetWhich(SID_ATTR_BRUSH
));
568 pBBSet
.reset( new SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
>
569 (*GetItemSet().GetPool()) );
571 pBBSet
->MergeRange(nBrush
, nBrush
);
572 pBBSet
->MergeRange(nOuter
, nOuter
);
573 pBBSet
->MergeRange(nInner
, nInner
);
574 pBBSet
->MergeRange(nShadow
, nShadow
);
577 const SfxPoolItem
* pItem
;
579 if(SfxItemState::SET
== GetItemSet().GetItemState(GetWhich(nId
), false, &pItem
))
581 // If a SfxItemSet from the SetItem for SID_ATTR_PAGE_HEADERSET or
582 // SID_ATTR_PAGE_FOOTERSET exists, use its content
583 pBBSet
->Put(static_cast<const SvxSetItem
*>(pItem
)->GetItemSet());
587 if(mbEnableDrawingLayerFillStyles
)
589 // The style for header/footer is not yet created, need to reset
590 // XFillStyleItem to drawing::FillStyle_NONE which is the same as in the style
591 // initialization. This needs to be done since the pool default for
592 // XFillStyleItem is drawing::FillStyle_SOLID
593 pBBSet
->Put(XFillStyleItem(drawing::FillStyle_NONE
));
597 if(SfxItemState::SET
== GetItemSet().GetItemState(nInner
, false, &pItem
))
599 // The set InfoItem is always required
604 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
606 VclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSvxBorderBackgroundDlg(
609 mbEnableDrawingLayerFillStyles
));
611 pDlg
->StartExecuteAsync([pDlg
, this](sal_Int32 nResult
) {
612 if (nResult
== RET_OK
&& pDlg
->GetOutputItemSet())
614 SfxItemIter
aIter(*pDlg
->GetOutputItemSet());
616 for (const SfxPoolItem
* pItem
= aIter
.GetCurItem(); pItem
; pItem
= aIter
.NextItem())
618 if(!IsInvalidItem(pItem
))
625 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes
;
627 if (mbEnableDrawingLayerFillStyles
)
629 // create FillAttributes directly from DrawingLayer FillStyle entries
631 std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(*pBBSet
);
635 const sal_uInt16 nWhich
= GetWhich(SID_ATTR_BRUSH
);
637 if (pBBSet
->GetItemState(nWhich
) == SfxItemState::SET
)
639 // create FillAttributes from SvxBrushItem
640 const SvxBrushItem
& rItem
641 = static_cast<const SvxBrushItem
&>(pBBSet
->Get(nWhich
));
642 SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
> aTempSet(*pBBSet
->GetPool());
644 setSvxBrushItemAsFillAttributesToTargetSet(rItem
, aTempSet
);
646 std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(aTempSet
);
650 if (SID_ATTR_PAGE_HEADERSET
== nId
)
652 //m_aBspWin.SetHdColor(rItem.GetColor());
653 m_aBspWin
.setHeaderFillAttributes(aFillAttributes
);
657 //m_aBspWin.SetFtColor(rItem.GetColor());
658 m_aBspWin
.setFooterFillAttributes(aFillAttributes
);
668 void SvxHFPage::UpdateExample()
670 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
672 m_aBspWin
.SetHeader( m_xTurnOnBox
->get_active() );
673 m_aBspWin
.SetHdHeight( GetCoreValue( *m_xHeightEdit
, MapUnit::MapTwip
) );
674 m_aBspWin
.SetHdDist( GetCoreValue( *m_xDistEdit
, MapUnit::MapTwip
) );
675 m_aBspWin
.SetHdLeft( GetCoreValue( *m_xLMEdit
, MapUnit::MapTwip
) );
676 m_aBspWin
.SetHdRight( GetCoreValue( *m_xRMEdit
, MapUnit::MapTwip
) );
680 m_aBspWin
.SetFooter( m_xTurnOnBox
->get_active() );
681 m_aBspWin
.SetFtHeight( GetCoreValue( *m_xHeightEdit
, MapUnit::MapTwip
) );
682 m_aBspWin
.SetFtDist( GetCoreValue( *m_xDistEdit
, MapUnit::MapTwip
) );
683 m_aBspWin
.SetFtLeft( GetCoreValue( *m_xLMEdit
, MapUnit::MapTwip
) );
684 m_aBspWin
.SetFtRight( GetCoreValue( *m_xRMEdit
, MapUnit::MapTwip
) );
686 m_aBspWin
.Invalidate();
689 void SvxHFPage::ResetBackground_Impl( const SfxItemSet
& rSet
)
691 sal_uInt16
nWhich(GetWhich(SID_ATTR_PAGE_HEADERSET
));
693 if (SfxItemState::SET
== rSet
.GetItemState(nWhich
, false))
695 const SvxSetItem
& rSetItem
= static_cast< const SvxSetItem
& >(rSet
.Get(nWhich
, false));
696 const SfxItemSet
& rTmpSet
= rSetItem
.GetItemSet();
697 const SfxBoolItem
& rOn
= rTmpSet
.Get(GetWhich(SID_ATTR_PAGE_ON
));
701 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes
;
703 if(mbEnableDrawingLayerFillStyles
)
705 // create FillAttributes directly from DrawingLayer FillStyle entries
706 aHeaderFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(rTmpSet
);
710 nWhich
= GetWhich(SID_ATTR_BRUSH
);
712 if(SfxItemState::SET
== rTmpSet
.GetItemState(nWhich
))
714 // create FillAttributes from SvxBrushItem
715 const SvxBrushItem
& rItem
= static_cast< const SvxBrushItem
& >(rTmpSet
.Get(nWhich
));
716 SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
> aTempSet(*rTmpSet
.GetPool());
718 setSvxBrushItemAsFillAttributesToTargetSet(rItem
, aTempSet
);
719 aHeaderFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(aTempSet
);
723 m_aBspWin
.setHeaderFillAttributes(aHeaderFillAttributes
);
727 nWhich
= GetWhich(SID_ATTR_PAGE_FOOTERSET
);
729 if (SfxItemState::SET
== rSet
.GetItemState(nWhich
, false))
731 const SvxSetItem
& rSetItem
= static_cast< const SvxSetItem
& >(rSet
.Get(nWhich
, false));
732 const SfxItemSet
& rTmpSet
= rSetItem
.GetItemSet();
733 const SfxBoolItem
& rOn
= rTmpSet
.Get(GetWhich(SID_ATTR_PAGE_ON
));
737 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes
;
739 if(mbEnableDrawingLayerFillStyles
)
741 // create FillAttributes directly from DrawingLayer FillStyle entries
742 aFooterFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(rTmpSet
);
746 nWhich
= GetWhich(SID_ATTR_BRUSH
);
748 if(SfxItemState::SET
== rTmpSet
.GetItemState(nWhich
))
750 // create FillAttributes from SvxBrushItem
751 const SvxBrushItem
& rItem
= static_cast< const SvxBrushItem
& >(rTmpSet
.Get(nWhich
));
752 SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
> aTempSet(*rTmpSet
.GetPool());
754 setSvxBrushItemAsFillAttributesToTargetSet(rItem
, aTempSet
);
755 aFooterFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(aTempSet
);
759 m_aBspWin
.setFooterFillAttributes(aFooterFillAttributes
);
763 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aPageFillAttributes
;
765 if(mbEnableDrawingLayerFillStyles
)
767 // create FillAttributes directly from DrawingLayer FillStyle entries
768 aPageFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(rSet
);
772 nWhich
= GetWhich(SID_ATTR_BRUSH
);
774 if(rSet
.GetItemState(nWhich
) >= SfxItemState::DEFAULT
)
776 // create FillAttributes from SvxBrushItem
777 const SvxBrushItem
& rItem
= static_cast< const SvxBrushItem
& >(rSet
.Get(nWhich
));
778 SfxItemSetFixed
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
> aTempSet(*rSet
.GetPool());
780 setSvxBrushItemAsFillAttributesToTargetSet(rItem
, aTempSet
);
781 aPageFillAttributes
= std::make_shared
<drawinglayer::attribute::SdrAllFillAttributesHelper
>(aTempSet
);
785 m_aBspWin
.setPageFillAttributes(aPageFillAttributes
);
788 void SvxHFPage::ActivatePage( const SfxItemSet
& rSet
)
790 const SfxPoolItem
* pItem
= GetItem( rSet
, SID_ATTR_LRSPACE
);
794 // Set left and right margins
795 const SvxLRSpaceItem
& rLRSpace
= static_cast<const SvxLRSpaceItem
&>(*pItem
);
797 m_aBspWin
.SetLeft( rLRSpace
.GetLeft() );
798 m_aBspWin
.SetRight( rLRSpace
.GetRight() );
802 m_aBspWin
.SetLeft( 0 );
803 m_aBspWin
.SetRight( 0 );
806 pItem
= GetItem( rSet
, SID_ATTR_ULSPACE
);
810 // Set top and bottom margins
811 const SvxULSpaceItem
& rULSpace
= static_cast<const SvxULSpaceItem
&>(*pItem
);
813 m_aBspWin
.SetTop( rULSpace
.GetUpper() );
814 m_aBspWin
.SetBottom( rULSpace
.GetLower() );
818 m_aBspWin
.SetTop( 0 );
819 m_aBspWin
.SetBottom( 0 );
822 SvxPageUsage nUsage
= SvxPageUsage::All
;
823 pItem
= GetItem( rSet
, SID_ATTR_PAGE
);
826 nUsage
= static_cast<const SvxPageItem
*>(pItem
)->GetPageUsage();
828 m_aBspWin
.SetUsage( nUsage
);
830 if ( SvxPageUsage::Right
== nUsage
|| SvxPageUsage::Left
== nUsage
)
831 m_xCntSharedBox
->set_sensitive(false);
834 m_xCntSharedBox
->set_sensitive(true);
835 m_xCntSharedFirstBox
->set_sensitive(true);
837 pItem
= GetItem( rSet
, SID_ATTR_PAGE_SIZE
);
841 // Orientation and Size from the PageItem
842 const SvxSizeItem
& rSize
= static_cast<const SvxSizeItem
&>(*pItem
);
843 // if the size is already swapped (Landscape)
844 m_aBspWin
.SetSize( rSize
.GetSize() );
847 // Evaluate Header attribute
848 const SvxSetItem
* pSetItem
= nullptr;
850 if ( SfxItemState::SET
== rSet
.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET
),
852 reinterpret_cast<const SfxPoolItem
**>(&pSetItem
) ) )
854 const SfxItemSet
& rHeaderSet
= pSetItem
->GetItemSet();
855 const SfxBoolItem
& rHeaderOn
=
856 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
858 if ( rHeaderOn
.GetValue() )
860 const SvxSizeItem
& rSize
=
861 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
862 const SvxULSpaceItem
& rUL
= rHeaderSet
.Get( GetWhich(SID_ATTR_ULSPACE
) );
863 const SvxLRSpaceItem
& rLR
= rHeaderSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
864 tools::Long nDist
= rUL
.GetLower();
866 m_aBspWin
.SetHdHeight( rSize
.GetSize().Height() - nDist
);
867 m_aBspWin
.SetHdDist( nDist
);
868 m_aBspWin
.SetHdLeft( rLR
.GetLeft() );
869 m_aBspWin
.SetHdRight( rLR
.GetRight() );
870 m_aBspWin
.SetHeader( true );
878 m_aBspWin
.SetHeader( false );
880 if ( SID_ATTR_PAGE_HEADERSET
== nId
)
882 m_xCntSharedBox
->set_sensitive(false);
883 m_xCntSharedFirstBox
->set_sensitive(false);
888 if ( SfxItemState::SET
== rSet
.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET
),
890 reinterpret_cast<const SfxPoolItem
**>(&pSetItem
) ) )
892 const SfxItemSet
& rFooterSet
= pSetItem
->GetItemSet();
893 const SfxBoolItem
& rFooterOn
=
894 rFooterSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
896 if ( rFooterOn
.GetValue() )
898 const SvxSizeItem
& rSize
=
899 rFooterSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
900 const SvxULSpaceItem
& rUL
= rFooterSet
.Get( GetWhich( SID_ATTR_ULSPACE
) );
901 const SvxLRSpaceItem
& rLR
= rFooterSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
902 tools::Long nDist
= rUL
.GetUpper();
904 m_aBspWin
.SetFtHeight( rSize
.GetSize().Height() - nDist
);
905 m_aBspWin
.SetFtDist( nDist
);
906 m_aBspWin
.SetFtLeft( rLR
.GetLeft() );
907 m_aBspWin
.SetFtRight( rLR
.GetRight() );
908 m_aBspWin
.SetFooter( true );
916 m_aBspWin
.SetFooter( false );
918 if ( SID_ATTR_PAGE_FOOTERSET
== nId
)
920 m_xCntSharedBox
->set_sensitive(false);
921 m_xCntSharedFirstBox
->set_sensitive(false);
925 pItem
= GetItem( rSet
, SID_ATTR_PAGE_EXT1
);
927 if ( auto pBoolItem
= dynamic_cast<const SfxBoolItem
*>( pItem
) )
929 m_aBspWin
.SetTable( true );
930 m_aBspWin
.SetHorz( pBoolItem
->GetValue() );
933 pItem
= GetItem( rSet
, SID_ATTR_PAGE_EXT2
);
935 if ( auto pBoolItem
= dynamic_cast<const SfxBoolItem
*>( pItem
) )
937 m_aBspWin
.SetTable( true );
938 m_aBspWin
.SetVert( pBoolItem
->GetValue() );
940 ResetBackground_Impl( rSet
);
944 DeactivateRC
SvxHFPage::DeactivatePage( SfxItemSet
* _pSet
)
947 FillItemSet( _pSet
);
948 return DeactivateRC::LeavePage
;
951 IMPL_LINK_NOARG(SvxHFPage
, ValueChangeHdl
, weld::MetricSpinButton
&, void)
957 void SvxHFPage::RangeHdl()
959 tools::Long nHHeight
= m_aBspWin
.GetHdHeight();
960 tools::Long nHDist
= m_aBspWin
.GetHdDist();
962 tools::Long nFHeight
= m_aBspWin
.GetFtHeight();
963 tools::Long nFDist
= m_aBspWin
.GetFtDist();
965 tools::Long nHeight
= std::max(tools::Long(MINBODY
),
966 static_cast<tools::Long
>(m_xHeightEdit
->denormalize(m_xHeightEdit
->get_value(FieldUnit::TWIP
))));
967 tools::Long nDist
= m_xTurnOnBox
->get_active() ?
968 static_cast<tools::Long
>(m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
))) : 0;
973 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
984 // Current values of the side edges
985 tools::Long nBT
= m_aBspWin
.GetTop();
986 tools::Long nBB
= m_aBspWin
.GetBottom();
987 tools::Long nBL
= m_aBspWin
.GetLeft();
988 tools::Long nBR
= m_aBspWin
.GetRight();
990 tools::Long nH
= m_aBspWin
.GetSize().Height();
991 tools::Long nW
= m_aBspWin
.GetSize().Width();
994 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
997 nMin
= ( nH
- nBB
- nBT
) / 5; // 20%
998 nMax
= std::max( nH
- nMin
- nHDist
- nFDist
- nFHeight
- nBB
- nBT
,
1000 m_xHeightEdit
->set_max(m_xHeightEdit
->normalize(nMax
), FieldUnit::TWIP
);
1001 nMin
= ( nH
- nBB
- nBT
) / 5; // 20%
1002 nDist
= std::max( nH
- nMin
- nHHeight
- nFDist
- nFHeight
- nBB
- nBT
,
1004 m_xDistEdit
->set_max(m_xDistEdit
->normalize(nDist
), FieldUnit::TWIP
);
1009 nMin
= ( nH
- nBT
- nBB
) / 5; // 20%
1010 nMax
= std::max( nH
- nMin
- nFDist
- nHDist
- nHHeight
- nBT
- nBB
,
1012 m_xHeightEdit
->set_max(m_xHeightEdit
->normalize(nMax
), FieldUnit::TWIP
);
1013 nMin
= ( nH
- nBT
- nBB
) / 5; // 20%
1014 nDist
= std::max( nH
- nMin
- nFHeight
- nHDist
- nHHeight
- nBT
- nBB
,
1016 m_xDistEdit
->set_max(m_xDistEdit
->normalize(nDist
), FieldUnit::TWIP
);
1019 // Limit Indentation
1020 nMax
= nW
- nBL
- nBR
-
1021 static_cast<tools::Long
>(m_xRMEdit
->denormalize(m_xRMEdit
->get_value(FieldUnit::TWIP
))) - MINBODY
;
1022 m_xLMEdit
->set_max(m_xLMEdit
->normalize(nMax
), FieldUnit::TWIP
);
1024 nMax
= nW
- nBL
- nBR
-
1025 static_cast<tools::Long
>(m_xLMEdit
->denormalize(m_xLMEdit
->get_value(FieldUnit::TWIP
))) - MINBODY
;
1026 m_xRMEdit
->set_max(m_xLMEdit
->normalize(nMax
), FieldUnit::TWIP
);
1029 void SvxHFPage::EnableDynamicSpacing()
1031 m_xDynSpacingCB
->show();
1034 void SvxHFPage::PageCreated(const SfxAllItemSet
&rSet
)
1036 const SfxBoolItem
* pSupportDrawingLayerFillStyleItem
= rSet
.GetItem
<SfxBoolItem
>(SID_DRAWINGLAYER_FILLSTYLES
, false);
1038 if (pSupportDrawingLayerFillStyleItem
)
1040 const bool bNew(pSupportDrawingLayerFillStyleItem
->GetValue());
1042 mbEnableDrawingLayerFillStyles
= bNew
;
1046 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */