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 <tools/shl.hxx>
21 #include <svl/itemiter.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/module.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <vcl/graph.hxx>
28 #include <sfx2/sfxsids.hrc>
29 #include <svx/svxids.hrc>
30 #include <svx/dialogs.hrc>
32 #include <svl/intitem.hxx>
34 #include <svx/hdft.hxx>
35 #include <svx/pageitem.hxx>
37 #include "svx/dlgutil.hxx"
38 #include <svx/dialmgr.hxx>
39 #include <sfx2/htmlmode.hxx>
41 #include <editeng/brushitem.hxx>
42 #include <editeng/lrspitem.hxx>
43 #include <editeng/ulspitem.hxx>
44 #include <editeng/shaditem.hxx>
45 #include <editeng/sizeitem.hxx>
46 #include <editeng/boxitem.hxx>
48 #include <svx/svxdlg.hxx>
49 // static ----------------------------------------------------------------
51 // Word 97 incompatibility (#i19922#)
52 static const long MINBODY
= 56; // 1mm in twips rounded
54 // default distance to Header or footer
55 static const long DEF_DIST_WRITER
= 500; // 5mm (Writer)
56 static const long DEF_DIST_CALC
= 250; // 2.5mm (Calc)
58 static sal_uInt16 pRanges
[] =
60 SID_ATTR_BRUSH
, SID_ATTR_BRUSH
,
61 SID_ATTR_BORDER_OUTER
, SID_ATTR_BORDER_OUTER
,
62 SID_ATTR_BORDER_INNER
, SID_ATTR_BORDER_INNER
,
63 SID_ATTR_BORDER_SHADOW
, SID_ATTR_BORDER_SHADOW
,
64 SID_ATTR_LRSPACE
, SID_ATTR_LRSPACE
,
65 SID_ATTR_ULSPACE
, SID_ATTR_ULSPACE
,
66 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
67 SID_ATTR_PAGE_HEADERSET
, SID_ATTR_PAGE_HEADERSET
,
68 SID_ATTR_PAGE_FOOTERSET
, SID_ATTR_PAGE_FOOTERSET
,
69 SID_ATTR_PAGE_ON
, SID_ATTR_PAGE_ON
,
70 SID_ATTR_PAGE_DYNAMIC
, SID_ATTR_PAGE_DYNAMIC
,
71 SID_ATTR_PAGE_SHARED
, SID_ATTR_PAGE_SHARED
,
72 SID_ATTR_PAGE_SHARED_FIRST
, SID_ATTR_PAGE_SHARED_FIRST
,
73 SID_ATTR_HDFT_DYNAMIC_SPACING
, SID_ATTR_HDFT_DYNAMIC_SPACING
,
79 bool ShowBorderBackgroundDlg( Window
* pParent
, SfxItemSet
* pBBSet
,
80 bool bEnableBackgroundSelector
)
83 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
86 SfxAbstractTabDialog
* pDlg
= pFact
->CreateSvxBorderBackgroundDlg( pParent
, *pBBSet
, bEnableBackgroundSelector
);
87 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
88 if ( pDlg
->Execute() == RET_OK
&& pDlg
->GetOutputItemSet() )
90 SfxItemIter
aIter( *pDlg
->GetOutputItemSet() );
91 const SfxPoolItem
* pItem
= aIter
.FirstItem();
95 if ( !IsInvalidItem( pItem
) )
96 pBBSet
->Put( *pItem
);
97 pItem
= aIter
.NextItem();
107 // returns the Which values to the range
110 sal_uInt16
* SvxHeaderPage::GetRanges()
115 //------------------------------------------------------------------------
117 SfxTabPage
* SvxHeaderPage::Create( Window
* pParent
, const SfxItemSet
& rSet
)
119 return new SvxHeaderPage( pParent
, rSet
);
122 //------------------------------------------------------------------------
124 sal_uInt16
* SvxFooterPage::GetRanges()
129 // -----------------------------------------------------------------------
131 SfxTabPage
* SvxFooterPage::Create( Window
* pParent
, const SfxItemSet
& rSet
)
133 return new SvxFooterPage( pParent
, rSet
);
136 // -----------------------------------------------------------------------
138 SvxHeaderPage::SvxHeaderPage( Window
* pParent
, const SfxItemSet
& rAttr
) :
140 SvxHFPage( pParent
, rAttr
, SID_ATTR_PAGE_HEADERSET
)
145 // -----------------------------------------------------------------------
147 SvxFooterPage::SvxFooterPage( Window
* pParent
, const SfxItemSet
& rAttr
) :
149 SvxHFPage( pParent
, rAttr
, SID_ATTR_PAGE_FOOTERSET
)
154 // -----------------------------------------------------------------------
156 SvxHFPage::SvxHFPage( Window
* pParent
, const SfxItemSet
& rSet
, sal_uInt16 nSetId
) :
158 SfxTabPage( pParent
, "HFFormatPage", "svx/ui/headfootformatpage.ui", rSet
),
161 bDisableQueryBox ( sal_False
),
162 bEnableBackgroundSelector ( sal_True
)
165 get(m_pCntSharedBox
,"checkSameLR");
166 get(m_pCntSharedFirstBox
,"checkSameFP");
167 get(m_pLMEdit
,"spinMargLeft");
168 get(m_pLMLbl
,"labelLeftMarg");
169 get(m_pRMEdit
,"spinMargRight");
170 get(m_pRMLbl
,"labelRightMarg");
171 get(m_pDistEdit
,"spinSpacing");
172 get(m_pDistFT
,"labelSpacing");
173 get(m_pDynSpacingCB
,"checkDynSpacing");
174 get(m_pHeightFT
,"labelHeight");
175 get(m_pHeightEdit
,"spinHeight");
176 get(m_pHeightDynBtn
,"checkAutofit");
177 get(m_pBspWin
,"drawingareaPageHF");
178 get(m_pBackgroundBtn
,"buttonMore");
180 //swap header <-> footer in UI
181 if(nId
== SID_ATTR_PAGE_FOOTERSET
)
183 get(m_pPageLbl
,"labelFooterFormat");
184 get(m_pTurnOnBox
, "checkFooterOn");
188 get(m_pPageLbl
,"labelHeaderFormat");
189 get(m_pTurnOnBox
, "checkHeaderOn");
191 m_pTurnOnBox
->Show();
195 m_pBspWin
->EnableRTL( sal_False
);
197 // This Page needs ExchangeSupport
198 SetExchangeSupport();
202 FieldUnit eFUnit
= GetModuleFieldUnit( rSet
);
203 SetFieldUnit( *m_pDistEdit
, eFUnit
);
204 SetFieldUnit( *m_pHeightEdit
, eFUnit
);
205 SetFieldUnit( *m_pLMEdit
, eFUnit
);
206 SetFieldUnit( *m_pRMEdit
, eFUnit
);
209 // -----------------------------------------------------------------------
211 SvxHFPage::~SvxHFPage()
216 // -----------------------------------------------------------------------
218 sal_Bool
SvxHFPage::FillItemSet( SfxItemSet
& rSet
)
220 const sal_uInt16 nWSize
= GetWhich( SID_ATTR_PAGE_SIZE
);
221 const sal_uInt16 nWLRSpace
= GetWhich( SID_ATTR_LRSPACE
);
222 const sal_uInt16 nWULSpace
= GetWhich( SID_ATTR_ULSPACE
);
223 const sal_uInt16 nWOn
= GetWhich( SID_ATTR_PAGE_ON
);
224 const sal_uInt16 nWDynamic
= GetWhich( SID_ATTR_PAGE_DYNAMIC
);
225 const sal_uInt16 nWDynSpacing
= GetWhich( SID_ATTR_HDFT_DYNAMIC_SPACING
);
226 const sal_uInt16 nWShared
= GetWhich( SID_ATTR_PAGE_SHARED
);
227 const sal_uInt16 nWSharedFirst
= GetWhich( SID_ATTR_PAGE_SHARED_FIRST
);
228 const sal_uInt16 nWBrush
= GetWhich( SID_ATTR_BRUSH
);
229 const sal_uInt16 nWBox
= GetWhich( SID_ATTR_BORDER_OUTER
);
230 const sal_uInt16 nWBoxInfo
= GetWhich( SID_ATTR_BORDER_INNER
);
231 const sal_uInt16 nWShadow
= GetWhich( SID_ATTR_BORDER_SHADOW
);
232 const sal_uInt16 aWhichTab
[] = { nWSize
, nWSize
,
233 nWLRSpace
, nWLRSpace
,
234 nWULSpace
, nWULSpace
,
236 nWDynamic
, nWDynamic
,
238 nWSharedFirst
, nWSharedFirst
,
240 nWBoxInfo
, nWBoxInfo
,
243 nWDynSpacing
, nWDynSpacing
,
245 const SfxItemSet
& rOldSet
= GetItemSet();
246 SfxItemPool
* pPool
= rOldSet
.GetPool();
247 DBG_ASSERT( pPool
, "no pool :-(" );
248 SfxMapUnit eUnit
= pPool
->GetMetric( nWSize
);
249 SfxItemSet
aSet ( *pPool
, aWhichTab
);
251 //--------------------------------------------------------------------
253 aSet
.Put( SfxBoolItem( nWOn
, m_pTurnOnBox
->IsChecked() ) );
254 aSet
.Put( SfxBoolItem( nWDynamic
, m_pHeightDynBtn
->IsChecked() ) );
255 aSet
.Put( SfxBoolItem( nWShared
, m_pCntSharedBox
->IsChecked() ) );
256 if(m_pCntSharedFirstBox
->IsVisible())
257 aSet
.Put( SfxBoolItem( nWSharedFirst
, m_pCntSharedFirstBox
->IsChecked() ) );
258 if(m_pDynSpacingCB
->IsVisible() && SFX_WHICH_MAX
> nWDynSpacing
)
260 SfxBoolItem
* pBoolItem
= (SfxBoolItem
*)pPool
->GetDefaultItem(nWDynSpacing
).Clone();
261 pBoolItem
->SetValue(m_pDynSpacingCB
->IsChecked());
262 aSet
.Put(*pBoolItem
);
267 SvxSizeItem
aSizeItem( (const SvxSizeItem
&)rOldSet
.Get( nWSize
) );
268 Size
aSize( aSizeItem
.GetSize() );
269 long nDist
= GetCoreValue( *m_pDistEdit
, eUnit
);
270 long nH
= GetCoreValue( *m_pHeightEdit
, eUnit
);
272 nH
+= nDist
; // add distance
274 aSizeItem
.SetSize( aSize
);
275 aSet
.Put( aSizeItem
);
278 SvxLRSpaceItem
aLR( nWLRSpace
);
279 aLR
.SetLeft( (sal_uInt16
)GetCoreValue( *m_pLMEdit
, eUnit
) );
280 aLR
.SetRight( (sal_uInt16
)GetCoreValue( *m_pRMEdit
, eUnit
) );
283 SvxULSpaceItem
aUL( nWULSpace
);
284 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
285 aUL
.SetLower( (sal_uInt16
)nDist
);
287 aUL
.SetUpper( (sal_uInt16
)nDist
);
290 // Background and border?
295 const SfxPoolItem
* pItem
;
298 GetItemSet().GetItemState( GetWhich( nId
), sal_False
, &pItem
) )
300 const SfxItemSet
* _pSet
;
301 _pSet
= &( (SvxSetItem
*)pItem
)->GetItemSet();
303 if ( _pSet
->GetItemState( nWBrush
) == SFX_ITEM_SET
)
304 aSet
.Put( (const SvxBrushItem
&)_pSet
->Get( nWBrush
) );
305 if ( _pSet
->GetItemState( nWBoxInfo
) == SFX_ITEM_SET
)
306 aSet
.Put( (const SvxBoxInfoItem
&)_pSet
->Get( nWBoxInfo
) );
307 if ( _pSet
->GetItemState( nWBox
) == SFX_ITEM_SET
)
308 aSet
.Put( (const SvxBoxItem
&)_pSet
->Get( nWBox
) );
309 if ( _pSet
->GetItemState( nWShadow
) == SFX_ITEM_SET
)
310 aSet
.Put( (const SvxShadowItem
&)_pSet
->Get( nWShadow
) );
315 SvxSetItem
aSetItem( GetWhich( nId
), aSet
);
316 rSet
.Put( aSetItem
);
321 // -----------------------------------------------------------------------
322 void SvxHFPage::Reset( const SfxItemSet
& rSet
)
324 ActivatePage( rSet
);
325 ResetBackground_Impl( rSet
);
327 SfxItemPool
* pPool
= GetItemSet().GetPool();
328 DBG_ASSERT( pPool
, "Where is the pool" );
329 SfxMapUnit eUnit
= pPool
->GetMetric( GetWhich( SID_ATTR_PAGE_SIZE
) );
331 //hide "same content on first page when this is calc
332 bool bIsCalc
= false;
333 const SfxPoolItem
* pExt1
= GetItem(rSet
, SID_ATTR_PAGE_EXT1
);
334 const SfxPoolItem
* pExt2
= GetItem(rSet
, SID_ATTR_PAGE_EXT2
);
335 if (pExt1
&& pExt1
->ISA(SfxBoolItem
) && pExt2
&& pExt2
->ISA(SfxBoolItem
))
337 m_pCntSharedFirstBox
->Show(!bIsCalc
);
339 // Evaluate header-/footer- attributes
340 const SvxSetItem
* pSetItem
= 0;
342 if ( SFX_ITEM_SET
== rSet
.GetItemState( GetWhich(nId
), sal_False
,
343 (const SfxPoolItem
**)&pSetItem
) )
345 const SfxItemSet
& rHeaderSet
= pSetItem
->GetItemSet();
346 const SfxBoolItem
& rHeaderOn
=
347 (const SfxBoolItem
&)rHeaderSet
.Get(GetWhich(SID_ATTR_PAGE_ON
));
349 m_pTurnOnBox
->Check(rHeaderOn
.GetValue());
351 if ( rHeaderOn
.GetValue() )
353 const SfxBoolItem
& rDynamic
=
354 (const SfxBoolItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC
) );
355 const SfxBoolItem
& rShared
=
356 (const SfxBoolItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SHARED
) );
357 const SfxBoolItem
* pSharedFirst
= 0;
358 if (rHeaderSet
.HasItem(GetWhich(SID_ATTR_PAGE_SHARED_FIRST
)))
359 pSharedFirst
= (const SfxBoolItem
*)&rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SHARED_FIRST
) );
360 const SvxSizeItem
& rSize
=
361 (const SvxSizeItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
362 const SvxULSpaceItem
& rUL
=
363 (const SvxULSpaceItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_ULSPACE
) );
364 const SvxLRSpaceItem
& rLR
=
365 (const SvxLRSpaceItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
366 if(m_pDynSpacingCB
->IsVisible())
368 const SfxBoolItem
& rDynSpacing
=
369 (const SfxBoolItem
&)rHeaderSet
.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING
));
370 m_pDynSpacingCB
->Check(rDynSpacing
.GetValue());
374 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
376 SetMetricValue( *m_pDistEdit
, rUL
.GetLower(), eUnit
);
377 SetMetricValue( *m_pHeightEdit
, rSize
.GetSize().Height() - rUL
.GetLower(), eUnit
);
381 SetMetricValue( *m_pDistEdit
, rUL
.GetUpper(), eUnit
);
382 SetMetricValue( *m_pHeightEdit
, rSize
.GetSize().Height() - rUL
.GetUpper(), eUnit
);
385 m_pHeightDynBtn
->Check(rDynamic
.GetValue());
386 SetMetricValue( *m_pLMEdit
, rLR
.GetLeft(), eUnit
);
387 SetMetricValue( *m_pRMEdit
, rLR
.GetRight(), eUnit
);
388 m_pCntSharedBox
->Check(rShared
.GetValue());
390 m_pCntSharedFirstBox
->Check(pSharedFirst
->GetValue());
392 m_pCntSharedFirstBox
->Hide();
399 // defaults for distance and height
400 long nDefaultDist
= bIsCalc
? DEF_DIST_CALC
: DEF_DIST_WRITER
;
401 SetMetricValue( *m_pDistEdit
, nDefaultDist
, SFX_MAPUNIT_100TH_MM
);
402 SetMetricValue( *m_pHeightEdit
, 500, SFX_MAPUNIT_100TH_MM
);
407 m_pTurnOnBox
->Check( sal_False
);
408 m_pHeightDynBtn
->Check( sal_True
);
409 m_pCntSharedBox
->Check( sal_True
);
410 m_pCntSharedFirstBox
->Check( sal_True
);
415 m_pTurnOnBox
->SaveValue();
416 m_pDistEdit
->SaveValue();
417 m_pHeightEdit
->SaveValue();
418 m_pHeightDynBtn
->SaveValue();
419 m_pLMEdit
->SaveValue();
420 m_pRMEdit
->SaveValue();
421 m_pCntSharedBox
->SaveValue();
424 const SfxPoolItem
* pItem
= 0;
425 SfxObjectShell
* pShell
;
426 if(SFX_ITEM_SET
== rSet
.GetItemState(SID_HTML_MODE
, sal_False
, &pItem
) ||
427 ( 0 != (pShell
= SfxObjectShell::Current()) &&
428 0 != (pItem
= pShell
->GetItem(SID_HTML_MODE
))))
430 sal_uInt16 nHtmlMode
= 0;
431 nHtmlMode
= ((SfxUInt16Item
*)pItem
)->GetValue();
432 if(nHtmlMode
& HTMLMODE_ON
)
434 m_pCntSharedBox
->Hide();
435 m_pBackgroundBtn
->Hide();
441 void SvxHFPage::InitHandler()
443 m_pTurnOnBox
->SetClickHdl(LINK(this, SvxHFPage
, TurnOnHdl
));
444 m_pDistEdit
->SetModifyHdl(LINK(this, SvxHFPage
, DistModify
));
445 m_pDistEdit
->SetLoseFocusHdl(LINK(this, SvxHFPage
, RangeHdl
));
447 m_pHeightEdit
->SetModifyHdl(LINK(this, SvxHFPage
, HeightModify
));
448 m_pHeightEdit
->SetLoseFocusHdl(LINK(this,SvxHFPage
,RangeHdl
));
450 m_pLMEdit
->SetModifyHdl(LINK(this, SvxHFPage
, BorderModify
));
451 m_pLMEdit
->SetLoseFocusHdl(LINK(this, SvxHFPage
, RangeHdl
));
452 m_pRMEdit
->SetModifyHdl(LINK(this, SvxHFPage
, BorderModify
));
453 m_pRMEdit
->SetLoseFocusHdl(LINK(this, SvxHFPage
, RangeHdl
));
454 m_pBackgroundBtn
->SetClickHdl(LINK(this,SvxHFPage
, BackgroundHdl
));
457 IMPL_LINK( SvxHFPage
, TurnOnHdl
, CheckBox
*, pBox
)
459 if ( m_pTurnOnBox
->IsChecked() )
462 m_pDistEdit
->Enable();
463 m_pDynSpacingCB
->Enable();
464 m_pHeightFT
->Enable();
465 m_pHeightEdit
->Enable();
466 m_pHeightDynBtn
->Enable();
472 sal_uInt16 nUsage
= m_pBspWin
->GetUsage();
474 if( nUsage
== SVX_PAGE_RIGHT
|| nUsage
== SVX_PAGE_LEFT
)
475 m_pCntSharedBox
->Disable();
478 m_pCntSharedBox
->Enable();
479 m_pCntSharedFirstBox
->Enable();
481 m_pBackgroundBtn
->Enable();
487 if ( !bDisableQueryBox
&& pBox
&& m_pTurnOnBox
->GetSavedValue() == sal_True
)
488 bDelete
= ( QueryBox( this, SVX_RES( RID_SVXQBX_DELETE_HEADFOOT
) ).Execute() == RET_YES
);
492 m_pDistFT
->Disable();
493 m_pDistEdit
->Disable();
494 m_pDynSpacingCB
->Enable(sal_False
);
495 m_pHeightFT
->Disable();
496 m_pHeightEdit
->Disable();
497 m_pHeightDynBtn
->Disable();
500 m_pLMEdit
->Disable();
502 m_pRMEdit
->Disable();
504 m_pCntSharedBox
->Disable();
505 m_pBackgroundBtn
->Disable();
506 m_pCntSharedFirstBox
->Disable();
509 m_pTurnOnBox
->Check();
515 IMPL_LINK_NOARG_INLINE_START(SvxHFPage
, DistModify
)
520 IMPL_LINK_NOARG_INLINE_END(SvxHFPage
, DistModify
)
522 IMPL_LINK_NOARG_INLINE_START(SvxHFPage
, HeightModify
)
528 IMPL_LINK_NOARG_INLINE_END(SvxHFPage
, HeightModify
)
530 IMPL_LINK_NOARG_INLINE_START(SvxHFPage
, BorderModify
)
535 IMPL_LINK_NOARG_INLINE_END(SvxHFPage
, BorderModify
)
537 IMPL_LINK_NOARG(SvxHFPage
, BackgroundHdl
)
541 // Use only the necessary items for border and background
542 sal_uInt16 nBrush
= GetWhich( SID_ATTR_BRUSH
);
543 sal_uInt16 nOuter
= GetWhich( SID_ATTR_BORDER_OUTER
);
544 sal_uInt16 nInner
= GetWhich( SID_ATTR_BORDER_INNER
, sal_False
);
545 sal_uInt16 nShadow
= GetWhich( SID_ATTR_BORDER_SHADOW
);
547 // Create an empty set
548 pBBSet
= new SfxItemSet( *GetItemSet().GetPool(), nBrush
, nBrush
,
549 nOuter
, nOuter
, nInner
, nInner
,
550 nShadow
, nShadow
, 0 );
551 const SfxPoolItem
* pItem
;
554 GetItemSet().GetItemState( GetWhich( nId
), sal_False
, &pItem
) )
555 // if there is one that is already set, then use this
556 pBBSet
->Put( ( (SvxSetItem
*)pItem
)->GetItemSet() );
559 GetItemSet().GetItemState( nInner
, sal_False
, &pItem
) )
560 // The set InfoItem is always required
561 pBBSet
->Put( *pItem
);
564 if ( svx::ShowBorderBackgroundDlg( this, pBBSet
, bEnableBackgroundSelector
) )
566 //----------------------------------------------------------------
568 sal_uInt16 nWhich
= GetWhich( SID_ATTR_BRUSH
);
570 if ( pBBSet
->GetItemState( nWhich
) == SFX_ITEM_SET
)
572 const SvxBrushItem
& rItem
= (const SvxBrushItem
&)pBBSet
->Get( nWhich
);
573 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
574 m_pBspWin
->SetHdColor( rItem
.GetColor() );
576 m_pBspWin
->SetFtColor( rItem
.GetColor() );
579 //----------------------------------------------------------------
581 nWhich
= GetWhich( SID_ATTR_BORDER_OUTER
);
583 if ( pBBSet
->GetItemState( nWhich
) == SFX_ITEM_SET
)
585 const SvxBoxItem
& rItem
= (const SvxBoxItem
&)pBBSet
->Get( nWhich
);
587 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
588 m_pBspWin
->SetHdBorder( rItem
);
590 m_pBspWin
->SetFtBorder( rItem
);
599 void SvxHFPage::UpdateExample()
601 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
603 m_pBspWin
->SetHeader( m_pTurnOnBox
->IsChecked() );
604 m_pBspWin
->SetHdHeight( GetCoreValue( *m_pHeightEdit
, SFX_MAPUNIT_TWIP
) );
605 m_pBspWin
->SetHdDist( GetCoreValue( *m_pDistEdit
, SFX_MAPUNIT_TWIP
) );
606 m_pBspWin
->SetHdLeft( GetCoreValue( *m_pLMEdit
, SFX_MAPUNIT_TWIP
) );
607 m_pBspWin
->SetHdRight( GetCoreValue( *m_pRMEdit
, SFX_MAPUNIT_TWIP
) );
611 m_pBspWin
->SetFooter( m_pTurnOnBox
->IsChecked() );
612 m_pBspWin
->SetFtHeight( GetCoreValue( *m_pHeightEdit
, SFX_MAPUNIT_TWIP
) );
613 m_pBspWin
->SetFtDist( GetCoreValue( *m_pDistEdit
, SFX_MAPUNIT_TWIP
) );
614 m_pBspWin
->SetFtLeft( GetCoreValue( *m_pLMEdit
, SFX_MAPUNIT_TWIP
) );
615 m_pBspWin
->SetFtRight( GetCoreValue( *m_pRMEdit
, SFX_MAPUNIT_TWIP
) );
617 m_pBspWin
->Invalidate();
620 void SvxHFPage::ResetBackground_Impl( const SfxItemSet
& rSet
)
622 sal_uInt16 nWhich
= GetWhich( SID_ATTR_PAGE_HEADERSET
);
624 if ( rSet
.GetItemState( nWhich
, sal_False
) == SFX_ITEM_SET
)
626 const SvxSetItem
& rSetItem
=
627 (const SvxSetItem
&)rSet
.Get( nWhich
, sal_False
);
628 const SfxItemSet
& rTmpSet
= rSetItem
.GetItemSet();
629 const SfxBoolItem
& rOn
=
630 (const SfxBoolItem
&)rTmpSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
632 if ( rOn
.GetValue() )
634 nWhich
= GetWhich( SID_ATTR_BRUSH
);
636 if ( rTmpSet
.GetItemState( nWhich
) == SFX_ITEM_SET
)
638 const SvxBrushItem
& rItem
= (const SvxBrushItem
&)rTmpSet
.Get( nWhich
);
639 m_pBspWin
->SetHdColor( rItem
.GetColor() );
641 nWhich
= GetWhich( SID_ATTR_BORDER_OUTER
);
643 if ( rTmpSet
.GetItemState( nWhich
) == SFX_ITEM_SET
)
645 const SvxBoxItem
& rItem
=
646 (const SvxBoxItem
&)rTmpSet
.Get( nWhich
);
647 m_pBspWin
->SetHdBorder( rItem
);
652 nWhich
= GetWhich( SID_ATTR_PAGE_FOOTERSET
);
654 if ( rSet
.GetItemState( nWhich
, sal_False
) == SFX_ITEM_SET
)
656 const SvxSetItem
& rSetItem
=
657 (const SvxSetItem
&)rSet
.Get( nWhich
, sal_False
);
658 const SfxItemSet
& rTmpSet
= rSetItem
.GetItemSet();
659 const SfxBoolItem
& rOn
=
660 (const SfxBoolItem
&)rTmpSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
662 if ( rOn
.GetValue() )
664 nWhich
= GetWhich( SID_ATTR_BRUSH
);
666 if ( rTmpSet
.GetItemState( nWhich
) == SFX_ITEM_SET
)
668 const SvxBrushItem
& rItem
= (const SvxBrushItem
&)rTmpSet
.Get( nWhich
);
669 m_pBspWin
->SetFtColor( rItem
.GetColor() );
671 nWhich
= GetWhich( SID_ATTR_BORDER_OUTER
);
673 if ( rTmpSet
.GetItemState( nWhich
) == SFX_ITEM_SET
)
675 const SvxBoxItem
& rItem
=
676 (const SvxBoxItem
&)rTmpSet
.Get( nWhich
);
677 m_pBspWin
->SetFtBorder( rItem
);
681 nWhich
= GetWhich( SID_ATTR_BRUSH
);
683 if ( rSet
.GetItemState( nWhich
) >= SFX_ITEM_AVAILABLE
)
685 const SvxBrushItem
& rItem
= (const SvxBrushItem
&)rSet
.Get( nWhich
);
686 m_pBspWin
->SetColor( rItem
.GetColor() );
687 const Graphic
* pGrf
= rItem
.GetGraphic();
691 Bitmap aBitmap
= pGrf
->GetBitmap();
692 m_pBspWin
->SetBitmap( &aBitmap
);
695 m_pBspWin
->SetBitmap( NULL
);
697 nWhich
= GetWhich( SID_ATTR_BORDER_OUTER
);
699 if ( rSet
.GetItemState( nWhich
) >= SFX_ITEM_AVAILABLE
)
701 const SvxBoxItem
& rItem
= (const SvxBoxItem
&)rSet
.Get( nWhich
);
702 m_pBspWin
->SetBorder( rItem
);
706 void SvxHFPage::ActivatePage( const SfxItemSet
& rSet
)
708 const SfxPoolItem
* pItem
= GetItem( rSet
, SID_ATTR_LRSPACE
);
712 // Set left and right margins
713 const SvxLRSpaceItem
& rLRSpace
= (const SvxLRSpaceItem
&)*pItem
;
715 m_pBspWin
->SetLeft( rLRSpace
.GetLeft() );
716 m_pBspWin
->SetRight( rLRSpace
.GetRight() );
720 m_pBspWin
->SetLeft( 0 );
721 m_pBspWin
->SetRight( 0 );
724 pItem
= GetItem( rSet
, SID_ATTR_ULSPACE
);
728 // Set top and bottom margins
729 const SvxULSpaceItem
& rULSpace
= (const SvxULSpaceItem
&)*pItem
;
731 m_pBspWin
->SetTop( rULSpace
.GetUpper() );
732 m_pBspWin
->SetBottom( rULSpace
.GetLower() );
736 m_pBspWin
->SetTop( 0 );
737 m_pBspWin
->SetBottom( 0 );
740 sal_uInt16 nUsage
= SVX_PAGE_ALL
;
741 pItem
= GetItem( rSet
, SID_ATTR_PAGE
);
744 nUsage
= ( (const SvxPageItem
*)pItem
)->GetPageUsage();
746 m_pBspWin
->SetUsage( nUsage
);
748 if ( SVX_PAGE_RIGHT
== nUsage
|| SVX_PAGE_LEFT
== nUsage
)
749 m_pCntSharedBox
->Disable();
752 m_pCntSharedBox
->Enable();
753 m_pCntSharedFirstBox
->Enable();
755 pItem
= GetItem( rSet
, SID_ATTR_PAGE_SIZE
);
759 // Orientation and Size from the PageItem
760 const SvxSizeItem
& rSize
= (const SvxSizeItem
&)*pItem
;
761 // if the size is already swapped (Landscape)
762 m_pBspWin
->SetSize( rSize
.GetSize() );
765 // Evaluate Header attribute
766 const SvxSetItem
* pSetItem
= 0;
768 if ( SFX_ITEM_SET
== rSet
.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET
),
770 (const SfxPoolItem
**)&pSetItem
) )
772 const SfxItemSet
& rHeaderSet
= pSetItem
->GetItemSet();
773 const SfxBoolItem
& rHeaderOn
=
774 (const SfxBoolItem
&)rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
776 if ( rHeaderOn
.GetValue() )
778 const SvxSizeItem
& rSize
= (const SvxSizeItem
&)
779 rHeaderSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
780 const SvxULSpaceItem
& rUL
= (const SvxULSpaceItem
&)
781 rHeaderSet
.Get( GetWhich(SID_ATTR_ULSPACE
) );
782 const SvxLRSpaceItem
& rLR
= (const SvxLRSpaceItem
&)
783 rHeaderSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
784 long nDist
= rUL
.GetLower();
786 m_pBspWin
->SetHdHeight( rSize
.GetSize().Height() - nDist
);
787 m_pBspWin
->SetHdDist( nDist
);
788 m_pBspWin
->SetHdLeft( rLR
.GetLeft() );
789 m_pBspWin
->SetHdRight( rLR
.GetRight() );
790 m_pBspWin
->SetHeader( sal_True
);
798 m_pBspWin
->SetHeader( sal_False
);
800 if ( SID_ATTR_PAGE_HEADERSET
== nId
)
802 m_pCntSharedBox
->Disable();
803 m_pCntSharedFirstBox
->Disable();
808 if ( SFX_ITEM_SET
== rSet
.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET
),
810 (const SfxPoolItem
**)&pSetItem
) )
812 const SfxItemSet
& rFooterSet
= pSetItem
->GetItemSet();
813 const SfxBoolItem
& rFooterOn
=
814 (const SfxBoolItem
&)rFooterSet
.Get( GetWhich( SID_ATTR_PAGE_ON
) );
816 if ( rFooterOn
.GetValue() )
818 const SvxSizeItem
& rSize
= (const SvxSizeItem
&)
819 rFooterSet
.Get( GetWhich( SID_ATTR_PAGE_SIZE
) );
820 const SvxULSpaceItem
& rUL
= (const SvxULSpaceItem
&)
821 rFooterSet
.Get( GetWhich( SID_ATTR_ULSPACE
) );
822 const SvxLRSpaceItem
& rLR
= (const SvxLRSpaceItem
&)
823 rFooterSet
.Get( GetWhich( SID_ATTR_LRSPACE
) );
824 long nDist
= rUL
.GetUpper();
826 m_pBspWin
->SetFtHeight( rSize
.GetSize().Height() - nDist
);
827 m_pBspWin
->SetFtDist( nDist
);
828 m_pBspWin
->SetFtLeft( rLR
.GetLeft() );
829 m_pBspWin
->SetFtRight( rLR
.GetRight() );
830 m_pBspWin
->SetFooter( sal_True
);
838 m_pBspWin
->SetFooter( sal_False
);
840 if ( SID_ATTR_PAGE_FOOTERSET
== nId
)
842 m_pCntSharedBox
->Disable();
843 m_pCntSharedFirstBox
->Disable();
847 pItem
= GetItem( rSet
, SID_ATTR_PAGE_EXT1
);
849 if ( pItem
&& pItem
->ISA(SfxBoolItem
) )
851 m_pBspWin
->SetTable( sal_True
);
852 m_pBspWin
->SetHorz( ( (SfxBoolItem
*)pItem
)->GetValue() );
855 pItem
= GetItem( rSet
, SID_ATTR_PAGE_EXT2
);
857 if ( pItem
&& pItem
->ISA(SfxBoolItem
) )
859 m_pBspWin
->SetTable( sal_True
);
860 m_pBspWin
->SetVert( ( (SfxBoolItem
*)pItem
)->GetValue() );
862 ResetBackground_Impl( rSet
);
866 int SvxHFPage::DeactivatePage( SfxItemSet
* _pSet
)
869 FillItemSet( *_pSet
);
873 IMPL_LINK_NOARG(SvxHFPage
, RangeHdl
)
875 long nHHeight
= m_pBspWin
->GetHdHeight();
876 long nHDist
= m_pBspWin
->GetHdDist();
878 long nFHeight
= m_pBspWin
->GetFtHeight();
879 long nFDist
= m_pBspWin
->GetFtDist();
881 long nHeight
= std::max( (long)MINBODY
,
882 static_cast<long>(m_pHeightEdit
->Denormalize( m_pHeightEdit
->GetValue( FUNIT_TWIP
) ) ) );
883 long nDist
= m_pTurnOnBox
->IsChecked() ?
884 static_cast<long>(m_pDistEdit
->Denormalize( m_pDistEdit
->GetValue( FUNIT_TWIP
) )) : 0;
889 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
900 // Current values of the side edges
901 long nBT
= m_pBspWin
->GetTop();
902 long nBB
= m_pBspWin
->GetBottom();
903 long nBL
= m_pBspWin
->GetLeft();
904 long nBR
= m_pBspWin
->GetRight();
906 long nH
= m_pBspWin
->GetSize().Height();
907 long nW
= m_pBspWin
->GetSize().Width();
910 if ( nId
== SID_ATTR_PAGE_HEADERSET
)
913 nMin
= ( nH
- nBB
- nBT
) / 5; // 20%
914 nMax
= std::max( nH
- nMin
- nHDist
- nFDist
- nFHeight
- nBB
- nBT
,
916 m_pHeightEdit
->SetMax( m_pHeightEdit
->Normalize( nMax
), FUNIT_TWIP
);
917 nMin
= ( nH
- nBB
- nBT
) / 5; // 20%
918 nDist
= std::max( nH
- nMin
- nHHeight
- nFDist
- nFHeight
- nBB
- nBT
,
920 m_pDistEdit
->SetMax( m_pDistEdit
->Normalize( nDist
), FUNIT_TWIP
);
925 nMin
= ( nH
- nBT
- nBB
) / 5; // 20%
926 nMax
= std::max( nH
- nMin
- nFDist
- nHDist
- nHHeight
- nBT
- nBB
,
928 m_pHeightEdit
->SetMax( m_pHeightEdit
->Normalize( nMax
), FUNIT_TWIP
);
929 nMin
= ( nH
- nBT
- nBB
) / 5; // 20%
930 nDist
= std::max( nH
- nMin
- nFHeight
- nHDist
- nHHeight
- nBT
- nBB
,
932 m_pDistEdit
->SetMax( m_pDistEdit
->Normalize( nDist
), FUNIT_TWIP
);
936 nMax
= nW
- nBL
- nBR
-
937 static_cast<long>(m_pRMEdit
->Denormalize( m_pRMEdit
->GetValue( FUNIT_TWIP
) )) - MINBODY
;
938 m_pLMEdit
->SetMax( m_pLMEdit
->Normalize( nMax
), FUNIT_TWIP
);
940 nMax
= nW
- nBL
- nBR
-
941 static_cast<long>(m_pLMEdit
->Denormalize( m_pLMEdit
->GetValue( FUNIT_TWIP
) )) - MINBODY
;
942 m_pRMEdit
->SetMax( m_pLMEdit
->Normalize( nMax
), FUNIT_TWIP
);
946 static void lcl_Move(Window
& rWin
, sal_Int32 nDiff
)
948 Point
aPos(rWin
.GetPosPixel());
950 rWin
.SetPosPixel(aPos
);
952 void SvxHFPage::EnableDynamicSpacing()
954 m_pDynSpacingCB
->Show();
955 //move all following controls
956 Window
* aMoveWindows
[] =
964 sal_Int32 nOffset
= m_pTurnOnBox
->GetPosPixel().Y() - m_pCntSharedBox
->GetPosPixel().Y();
966 while(aMoveWindows
[nIdx
])
967 lcl_Move(*aMoveWindows
[nIdx
++], nOffset
);
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */