bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / dialog / hdft.cxx
blob606c7970ce18efc28b2927c6ff1ac7c5ba58569b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <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,
77 namespace svx {
79 bool ShowBorderBackgroundDlg( Window* pParent, SfxItemSet* pBBSet,
80 bool bEnableBackgroundSelector )
82 bool bRes = false;
83 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
84 if(pFact)
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();
93 while ( pItem )
95 if ( !IsInvalidItem( pItem ) )
96 pBBSet->Put( *pItem );
97 pItem = aIter.NextItem();
99 bRes = true;
101 delete pDlg;
103 return bRes;
107 // returns the Which values to the range
110 sal_uInt16* SvxHeaderPage::GetRanges()
112 return pRanges;
115 //------------------------------------------------------------------------
117 SfxTabPage* SvxHeaderPage::Create( Window* pParent, const SfxItemSet& rSet )
119 return new SvxHeaderPage( pParent, rSet );
122 //------------------------------------------------------------------------
124 sal_uInt16* SvxFooterPage::GetRanges()
126 return pRanges;
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 ),
159 nId ( nSetId ),
160 pBBSet ( NULL ),
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");
186 else //Header
188 get(m_pPageLbl,"labelHeaderFormat");
189 get(m_pTurnOnBox, "checkHeaderOn");
191 m_pTurnOnBox->Show();
192 m_pPageLbl->Show();
194 InitHandler();
195 m_pBspWin->EnableRTL( sal_False );
197 // This Page needs ExchangeSupport
198 SetExchangeSupport();
201 // Set metrics
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()
213 delete pBBSet;
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,
235 nWOn, nWOn,
236 nWDynamic, nWDynamic,
237 nWShared, nWShared,
238 nWSharedFirst, nWSharedFirst,
239 nWBrush, nWBrush,
240 nWBoxInfo, nWBoxInfo,
241 nWBox, nWBox,
242 nWShadow, nWShadow,
243 nWDynSpacing, nWDynSpacing,
244 0 };
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);
263 delete pBoolItem;
266 // Size
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
273 aSize.Height() = nH;
274 aSizeItem.SetSize( aSize );
275 aSet.Put( aSizeItem );
277 // Margins
278 SvxLRSpaceItem aLR( nWLRSpace );
279 aLR.SetLeft( (sal_uInt16)GetCoreValue( *m_pLMEdit, eUnit ) );
280 aLR.SetRight( (sal_uInt16)GetCoreValue( *m_pRMEdit, eUnit ) );
281 aSet.Put( aLR );
283 SvxULSpaceItem aUL( nWULSpace );
284 if ( nId == SID_ATTR_PAGE_HEADERSET )
285 aUL.SetLower( (sal_uInt16)nDist );
286 else
287 aUL.SetUpper( (sal_uInt16)nDist );
288 aSet.Put( aUL );
290 // Background and border?
291 if ( pBBSet )
292 aSet.Put( *pBBSet );
293 else
295 const SfxPoolItem* pItem;
297 if ( SFX_ITEM_SET ==
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 ) );
314 // Flush the SetItem
315 SvxSetItem aSetItem( GetWhich( nId ), aSet );
316 rSet.Put( aSetItem );
318 return sal_True;
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))
336 bIsCalc = true;
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 )
375 { // Header
376 SetMetricValue( *m_pDistEdit, rUL.GetLower(), eUnit );
377 SetMetricValue( *m_pHeightEdit, rSize.GetSize().Height() - rUL.GetLower(), eUnit );
379 else
380 { // Footer
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());
389 if (pSharedFirst)
390 m_pCntSharedFirstBox->Check(pSharedFirst->GetValue());
391 else
392 m_pCntSharedFirstBox->Hide();
394 else
395 pSetItem = 0;
397 else
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 );
405 if ( !pSetItem )
407 m_pTurnOnBox->Check( sal_False );
408 m_pHeightDynBtn->Check( sal_True );
409 m_pCntSharedBox->Check( sal_True );
410 m_pCntSharedFirstBox->Check( sal_True );
413 TurnOnHdl(0);
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();
422 RangeHdl( 0 );
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() )
461 m_pDistFT->Enable();
462 m_pDistEdit->Enable();
463 m_pDynSpacingCB->Enable();
464 m_pHeightFT->Enable();
465 m_pHeightEdit->Enable();
466 m_pHeightDynBtn->Enable();
467 m_pLMLbl->Enable();
468 m_pLMEdit->Enable();
469 m_pRMLbl->Enable();
470 m_pRMEdit->Enable();
472 sal_uInt16 nUsage = m_pBspWin->GetUsage();
474 if( nUsage == SVX_PAGE_RIGHT || nUsage == SVX_PAGE_LEFT )
475 m_pCntSharedBox->Disable();
476 else
478 m_pCntSharedBox->Enable();
479 m_pCntSharedFirstBox->Enable();
481 m_pBackgroundBtn->Enable();
483 else
485 bool bDelete = true;
487 if ( !bDisableQueryBox && pBox && m_pTurnOnBox->GetSavedValue() == sal_True )
488 bDelete = ( QueryBox( this, SVX_RES( RID_SVXQBX_DELETE_HEADFOOT ) ).Execute() == RET_YES );
490 if ( bDelete )
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();
499 m_pLMLbl->Disable();
500 m_pLMEdit->Disable();
501 m_pRMLbl->Disable();
502 m_pRMEdit->Disable();
504 m_pCntSharedBox->Disable();
505 m_pBackgroundBtn->Disable();
506 m_pCntSharedFirstBox->Disable();
508 else
509 m_pTurnOnBox->Check();
511 UpdateExample();
512 return 0;
515 IMPL_LINK_NOARG_INLINE_START(SvxHFPage, DistModify)
517 UpdateExample();
518 return 0;
520 IMPL_LINK_NOARG_INLINE_END(SvxHFPage, DistModify)
522 IMPL_LINK_NOARG_INLINE_START(SvxHFPage, HeightModify)
524 UpdateExample();
526 return 0;
528 IMPL_LINK_NOARG_INLINE_END(SvxHFPage, HeightModify)
530 IMPL_LINK_NOARG_INLINE_START(SvxHFPage, BorderModify)
532 UpdateExample();
533 return 0;
535 IMPL_LINK_NOARG_INLINE_END(SvxHFPage, BorderModify)
537 IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl)
539 if ( !pBBSet )
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;
553 if ( SFX_ITEM_SET ==
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() );
558 if ( SFX_ITEM_SET ==
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() );
575 else
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 );
589 else
590 m_pBspWin->SetFtBorder( rItem );
593 UpdateExample();
596 return 0;
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 ) );
609 else
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();
689 if ( pGrf )
691 Bitmap aBitmap = pGrf->GetBitmap();
692 m_pBspWin->SetBitmap( &aBitmap );
694 else
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 );
710 if ( pItem )
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() );
718 else
720 m_pBspWin->SetLeft( 0 );
721 m_pBspWin->SetRight( 0 );
724 pItem = GetItem( rSet, SID_ATTR_ULSPACE );
726 if ( pItem )
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() );
734 else
736 m_pBspWin->SetTop( 0 );
737 m_pBspWin->SetBottom( 0 );
740 sal_uInt16 nUsage = SVX_PAGE_ALL;
741 pItem = GetItem( rSet, SID_ATTR_PAGE );
743 if ( pItem )
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();
750 else
752 m_pCntSharedBox->Enable();
753 m_pCntSharedFirstBox->Enable();
755 pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
757 if ( pItem )
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 ),
769 sal_False,
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 );
792 else
793 pSetItem = 0;
796 if ( !pSetItem )
798 m_pBspWin->SetHeader( sal_False );
800 if ( SID_ATTR_PAGE_HEADERSET == nId )
802 m_pCntSharedBox->Disable();
803 m_pCntSharedFirstBox->Disable();
806 pSetItem = 0;
808 if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
809 sal_False,
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 );
832 else
833 pSetItem = 0;
836 if ( !pSetItem )
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 );
863 RangeHdl( 0 );
866 int SvxHFPage::DeactivatePage( SfxItemSet* _pSet )
868 if ( _pSet )
869 FillItemSet( *_pSet );
870 return LEAVE_PAGE;
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;
886 long nMin;
887 long nMax;
889 if ( nId == SID_ATTR_PAGE_HEADERSET )
891 nHHeight = nHeight;
892 nHDist = nDist;
894 else
896 nFHeight = nHeight;
897 nFDist = nDist;
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();
909 // Borders
910 if ( nId == SID_ATTR_PAGE_HEADERSET )
912 // Header
913 nMin = ( nH - nBB - nBT ) / 5; // 20%
914 nMax = std::max( nH - nMin - nHDist - nFDist - nFHeight - nBB - nBT,
915 nMin );
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,
919 long(0) );
920 m_pDistEdit->SetMax( m_pDistEdit->Normalize( nDist ), FUNIT_TWIP );
922 else
924 // Footer
925 nMin = ( nH - nBT - nBB ) / 5; // 20%
926 nMax = std::max( nH - nMin - nFDist - nHDist - nHHeight - nBT - nBB,
927 nMin );
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,
931 long(0) );
932 m_pDistEdit->SetMax( m_pDistEdit->Normalize( nDist ), FUNIT_TWIP );
935 // Limit Indentation
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 );
943 return 0;
946 static void lcl_Move(Window& rWin, sal_Int32 nDiff)
948 Point aPos(rWin.GetPosPixel());
949 aPos.Y() -= nDiff;
950 rWin.SetPosPixel(aPos);
952 void SvxHFPage::EnableDynamicSpacing()
954 m_pDynSpacingCB->Show();
955 //move all following controls
956 Window* aMoveWindows[] =
958 m_pHeightFT,
959 m_pHeightEdit,
960 m_pHeightDynBtn,
961 m_pBackgroundBtn,
964 sal_Int32 nOffset = m_pTurnOnBox->GetPosPixel().Y() - m_pCntSharedBox->GetPosPixel().Y();
965 sal_Int32 nIdx = 0;
966 while(aMoveWindows[nIdx])
967 lcl_Move(*aMoveWindows[nIdx++], nOffset);
970 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */