Update ooo320-m1
[ooovba.git] / svx / source / dialog / hdft.cxx
blob9ba5238dea4661c186bd1f663f45e8b8372218c5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hdft.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
36 #include <svtools/itemiter.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/module.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <vcl/graph.hxx>
43 #include <svx/dialogs.hrc>
44 #include "hdft.hrc"
57 #define _SVX_HDFT_CXX
59 #include <svx/hdft.hxx>
60 #include <svx/pageitem.hxx>
61 //CHINA001 #include "bbdlg.hxx"
62 #include "dlgutil.hxx"
63 #include <svx/dialmgr.hxx>
64 #include "htmlmode.hxx"
66 #include <svx/brshitem.hxx>
67 #include <svx/lrspitem.hxx>
68 #include <svx/ulspitem.hxx>
69 #include <svx/shaditem.hxx>
70 #include <svx/sizeitem.hxx>
71 #include <svx/boxitem.hxx>
73 #include <svx/svxdlg.hxx> //CHINA001
74 #include <svx/dialogs.hrc> //CHINA001
75 // static ----------------------------------------------------------------
77 // --> OD 2004-06-18 #i19922#
78 //static const long MINBODY = 284; // 0,5cm in twips aufgerundet
79 static const long MINBODY = 56; // 1mm in twips rounded
81 // default distance to Header or footer
82 static const long DEF_DIST_WRITER = 500; // 5mm (Writer)
83 static const long DEF_DIST_CALC = 250; // 2,5mm (Calc)
85 static USHORT pRanges[] =
87 SID_ATTR_BRUSH, SID_ATTR_BRUSH,
88 SID_ATTR_BORDER_OUTER, SID_ATTR_BORDER_OUTER,
89 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
90 SID_ATTR_BORDER_SHADOW, SID_ATTR_BORDER_SHADOW,
91 SID_ATTR_LRSPACE, SID_ATTR_LRSPACE,
92 SID_ATTR_ULSPACE, SID_ATTR_ULSPACE,
93 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
94 SID_ATTR_PAGE_HEADERSET, SID_ATTR_PAGE_HEADERSET,
95 SID_ATTR_PAGE_FOOTERSET, SID_ATTR_PAGE_FOOTERSET,
96 SID_ATTR_PAGE_ON, SID_ATTR_PAGE_ON,
97 SID_ATTR_PAGE_DYNAMIC, SID_ATTR_PAGE_DYNAMIC,
98 SID_ATTR_PAGE_SHARED, SID_ATTR_PAGE_SHARED,
99 SID_ATTR_HDFT_DYNAMIC_SPACING, SID_ATTR_HDFT_DYNAMIC_SPACING,
103 /*--------------------------------------------------------------------
104 Beschreibung:
105 --------------------------------------------------------------------*/
107 // gibt den Bereich der Which-Werte zurueck
110 USHORT* SvxHeaderPage::GetRanges()
112 return pRanges;
115 //------------------------------------------------------------------------
117 SfxTabPage* SvxHeaderPage::Create( Window* pParent, const SfxItemSet& rSet )
119 return new SvxHeaderPage( pParent, rSet );
122 //------------------------------------------------------------------------
124 USHORT* 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, RID_SVXPAGE_HEADER, rAttr, SID_ATTR_PAGE_HEADERSET )
145 // -----------------------------------------------------------------------
147 SvxFooterPage::SvxFooterPage( Window* pParent, const SfxItemSet& rAttr ) :
149 SvxHFPage( pParent, RID_SVXPAGE_FOOTER, rAttr, SID_ATTR_PAGE_FOOTERSET )
154 // -----------------------------------------------------------------------
156 SvxHFPage::SvxHFPage( Window* pParent, USHORT nResId, const SfxItemSet& rAttr, USHORT nSetId ) :
158 SfxTabPage( pParent, SVX_RES( nResId ), rAttr ),
160 aTurnOnBox ( this, SVX_RES( CB_TURNON ) ),
161 aCntSharedBox ( this, SVX_RES( CB_SHARED ) ),
162 aLMLbl ( this, SVX_RES( FT_LMARGIN ) ),
163 aLMEdit ( this, SVX_RES( ED_LMARGIN ) ),
164 aRMLbl ( this, SVX_RES( FT_RMARGIN ) ),
165 aRMEdit ( this, SVX_RES( ED_RMARGIN ) ),
166 aDistFT ( this, SVX_RES( FT_DIST ) ),
167 aDistEdit ( this, SVX_RES( ED_DIST ) ),
168 aDynSpacingCB ( this, SVX_RES( CB_DYNSPACING ) ),
169 aHeightFT ( this, SVX_RES( FT_HEIGHT ) ),
170 aHeightEdit ( this, SVX_RES( ED_HEIGHT ) ),
171 aHeightDynBtn ( this, SVX_RES( CB_HEIGHT_DYN ) ),
172 aFrm ( this, SVX_RES( FL_FRAME ) ),
173 aBspWin ( this, SVX_RES( WN_BSP ) ),
174 aBackgroundBtn ( this, SVX_RES( BTN_EXTRAS ) ),
176 nId ( nSetId ),
177 pBBSet ( NULL ),
178 bDisableQueryBox ( FALSE ),
179 bEnableBackgroundSelector ( TRUE )
182 InitHandler();
183 aBspWin.EnableRTL( FALSE );
185 // diese Page braucht ExchangeSupport
186 SetExchangeSupport();
188 FreeResource();
190 // Metrik einstellen
191 FieldUnit eFUnit = GetModuleFieldUnit( &rAttr );
192 SetFieldUnit( aDistEdit, eFUnit );
193 SetFieldUnit( aHeightEdit, eFUnit );
194 SetFieldUnit( aLMEdit, eFUnit );
195 SetFieldUnit( aRMEdit, eFUnit );
198 // -----------------------------------------------------------------------
200 SvxHFPage::~SvxHFPage()
202 delete pBBSet;
205 // -----------------------------------------------------------------------
207 BOOL SvxHFPage::FillItemSet( SfxItemSet& rSet )
209 const USHORT nWSize = GetWhich( SID_ATTR_PAGE_SIZE );
210 const USHORT nWLRSpace = GetWhich( SID_ATTR_LRSPACE );
211 const USHORT nWULSpace = GetWhich( SID_ATTR_ULSPACE );
212 const USHORT nWOn = GetWhich( SID_ATTR_PAGE_ON );
213 const USHORT nWDynamic = GetWhich( SID_ATTR_PAGE_DYNAMIC );
214 const USHORT nWDynSpacing = GetWhich( SID_ATTR_HDFT_DYNAMIC_SPACING );
215 const USHORT nWShared = GetWhich( SID_ATTR_PAGE_SHARED );
216 const USHORT nWBrush = GetWhich( SID_ATTR_BRUSH );
217 const USHORT nWBox = GetWhich( SID_ATTR_BORDER_OUTER );
218 const USHORT nWBoxInfo = GetWhich( SID_ATTR_BORDER_INNER );
219 const USHORT nWShadow = GetWhich( SID_ATTR_BORDER_SHADOW );
220 const USHORT aWhichTab[] = { nWSize, nWSize,
221 nWLRSpace, nWLRSpace,
222 nWULSpace, nWULSpace,
223 nWOn, nWOn,
224 nWDynamic, nWDynamic,
225 nWShared, nWShared,
226 nWBrush, nWBrush,
227 nWBoxInfo, nWBoxInfo,
228 nWBox, nWBox,
229 nWShadow, nWShadow,
230 nWDynSpacing, nWDynSpacing,
231 0 };
232 const SfxItemSet& rOldSet = GetItemSet();
233 SfxItemPool* pPool = rOldSet.GetPool();
234 DBG_ASSERT( pPool, "no pool :-(" );
235 SfxMapUnit eUnit = pPool->GetMetric( nWSize );
236 SfxItemSet aSet ( *pPool, aWhichTab );
238 //--------------------------------------------------------------------
240 aSet.Put( SfxBoolItem( nWOn, aTurnOnBox.IsChecked() ) );
241 aSet.Put( SfxBoolItem( nWDynamic, aHeightDynBtn.IsChecked() ) );
242 aSet.Put( SfxBoolItem( nWShared, aCntSharedBox.IsChecked() ) );
243 if(aDynSpacingCB.IsVisible() && SFX_WHICH_MAX > nWDynSpacing)
245 SfxBoolItem* pBoolItem = (SfxBoolItem*)pPool->GetDefaultItem(nWDynSpacing).Clone();
246 pBoolItem->SetValue(aDynSpacingCB.IsChecked());
247 aSet.Put(*pBoolItem);
248 delete pBoolItem;
251 // Groesse
252 SvxSizeItem aSizeItem( (const SvxSizeItem&)rOldSet.Get( nWSize ) );
253 Size aSize( aSizeItem.GetSize() );
254 long nDist = GetCoreValue( aDistEdit, eUnit );
255 long nH = GetCoreValue( aHeightEdit, eUnit );
257 // fixe Hoehe?
258 // if ( !aHeightDynBtn.IsChecked() )
259 nH += nDist; // dann Abstand dazu addieren
260 aSize.Height() = nH;
261 aSizeItem.SetSize( aSize );
262 aSet.Put( aSizeItem );
264 // Raender
265 SvxLRSpaceItem aLR( nWLRSpace );
266 aLR.SetLeft( (USHORT)GetCoreValue( aLMEdit, eUnit ) );
267 aLR.SetRight( (USHORT)GetCoreValue( aRMEdit, eUnit ) );
268 aSet.Put( aLR );
270 SvxULSpaceItem aUL( nWULSpace );
271 if ( nId == SID_ATTR_PAGE_HEADERSET )
272 aUL.SetLower( (USHORT)nDist );
273 else
274 aUL.SetUpper( (USHORT)nDist );
275 aSet.Put( aUL );
277 // Hintergrund und Umrandung?
278 if ( pBBSet )
279 aSet.Put( *pBBSet );
280 else
282 const SfxItemSet* _pSet;
283 const SfxPoolItem* pItem;
285 if ( SFX_ITEM_SET ==
286 GetItemSet().GetItemState( GetWhich( nId ), FALSE, &pItem ) )
288 _pSet = &( (SvxSetItem*)pItem )->GetItemSet();
290 if ( _pSet->GetItemState( nWBrush ) == SFX_ITEM_SET )
291 aSet.Put( (const SvxBrushItem&)_pSet->Get( nWBrush ) );
292 if ( _pSet->GetItemState( nWBoxInfo ) == SFX_ITEM_SET )
293 aSet.Put( (const SvxBoxInfoItem&)_pSet->Get( nWBoxInfo ) );
294 if ( _pSet->GetItemState( nWBox ) == SFX_ITEM_SET )
295 aSet.Put( (const SvxBoxItem&)_pSet->Get( nWBox ) );
296 if ( _pSet->GetItemState( nWShadow ) == SFX_ITEM_SET )
297 aSet.Put( (const SvxShadowItem&)_pSet->Get( nWShadow ) );
301 // Das SetItem wegschreiben
302 SvxSetItem aSetItem( GetWhich( nId ), aSet );
303 rSet.Put( aSetItem );
305 return TRUE;
308 // -----------------------------------------------------------------------
309 void SvxHFPage::Reset( const SfxItemSet& rSet )
311 ActivatePage( rSet );
312 ResetBackground_Impl( rSet );
314 SfxItemPool* pPool = GetItemSet().GetPool();
315 DBG_ASSERT( pPool, "Wo ist der Pool" );
316 SfxMapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_PAGE_SIZE ) );
318 // Kopf-/Fusszeilen-Attribute auswerten
320 const SvxSetItem* pSetItem = 0;
322 if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich(nId), FALSE,
323 (const SfxPoolItem**)&pSetItem ) )
325 const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
326 const SfxBoolItem& rHeaderOn =
327 (const SfxBoolItem&)rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ON));
329 aTurnOnBox.Check(rHeaderOn.GetValue());
331 if ( rHeaderOn.GetValue() )
333 const SfxBoolItem& rDynamic =
334 (const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC ) );
335 const SfxBoolItem& rShared =
336 (const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED ) );
337 const SvxSizeItem& rSize =
338 (const SvxSizeItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
339 const SvxULSpaceItem& rUL =
340 (const SvxULSpaceItem&)rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
341 const SvxLRSpaceItem& rLR =
342 (const SvxLRSpaceItem&)rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
343 if(aDynSpacingCB.IsVisible())
345 const SfxBoolItem& rDynSpacing =
346 (const SfxBoolItem&)rHeaderSet.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING));
347 aDynSpacingCB.Check(rDynSpacing.GetValue());
351 if ( nId == SID_ATTR_PAGE_HEADERSET )
352 { // Kopfzeile
353 SetMetricValue( aDistEdit, rUL.GetLower(), eUnit );
354 SetMetricValue( aHeightEdit, rSize.GetSize().Height() - rUL.GetLower(), eUnit );
356 else
357 { // Fusszeile
358 SetMetricValue( aDistEdit, rUL.GetUpper(), eUnit );
359 SetMetricValue( aHeightEdit, rSize.GetSize().Height() - rUL.GetUpper(), eUnit );
362 aHeightDynBtn.Check(rDynamic.GetValue());
363 SetMetricValue( aLMEdit, rLR.GetLeft(), eUnit );
364 SetMetricValue( aRMEdit, rLR.GetRight(), eUnit );
365 aCntSharedBox.Check(rShared.GetValue());
367 else
368 pSetItem = 0;
370 else
372 // defaults for distance and height
373 long nDefaultDist = DEF_DIST_WRITER;
374 const SfxPoolItem* pExt1 = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
375 const SfxPoolItem* pExt2 = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
377 if ( pExt1 && pExt1->ISA(SfxBoolItem) && pExt2 && pExt2->ISA(SfxBoolItem) )
378 nDefaultDist = DEF_DIST_CALC;
380 SetMetricValue( aDistEdit, nDefaultDist, SFX_MAPUNIT_100TH_MM );
381 SetMetricValue( aHeightEdit, 500, SFX_MAPUNIT_100TH_MM );
384 if ( !pSetItem )
386 aTurnOnBox.Check( FALSE );
387 aHeightDynBtn.Check( TRUE );
388 aCntSharedBox.Check( TRUE );
391 TurnOnHdl(0);
393 aTurnOnBox.SaveValue();
394 aDistEdit.SaveValue();
395 aHeightEdit.SaveValue();
396 aHeightDynBtn.SaveValue();
397 aLMEdit.SaveValue();
398 aRMEdit.SaveValue();
399 aCntSharedBox.SaveValue();
400 RangeHdl( 0 );
402 USHORT nHtmlMode = 0;
403 const SfxPoolItem* pItem = 0;
404 SfxObjectShell* pShell;
405 if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, FALSE, &pItem) ||
406 ( 0 != (pShell = SfxObjectShell::Current()) &&
407 0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
409 nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
410 if(nHtmlMode && HTMLMODE_ON)
412 aCntSharedBox.Hide();
413 aBackgroundBtn.Hide();
419 /*--------------------------------------------------------------------
420 Beschreibung: Handler initialisieren
421 --------------------------------------------------------------------*/
423 void SvxHFPage::InitHandler()
425 aTurnOnBox.SetClickHdl(LINK(this, SvxHFPage, TurnOnHdl));
426 aDistEdit.SetModifyHdl(LINK(this, SvxHFPage, DistModify));
427 aDistEdit.SetLoseFocusHdl(LINK(this, SvxHFPage, RangeHdl));
429 aHeightEdit.SetModifyHdl(LINK(this, SvxHFPage, HeightModify));
430 aHeightEdit.SetLoseFocusHdl(LINK(this,SvxHFPage,RangeHdl));
432 aLMEdit.SetModifyHdl(LINK(this, SvxHFPage, BorderModify));
433 aLMEdit.SetLoseFocusHdl(LINK(this, SvxHFPage, RangeHdl));
434 aRMEdit.SetModifyHdl(LINK(this, SvxHFPage, BorderModify));
435 aRMEdit.SetLoseFocusHdl(LINK(this, SvxHFPage, RangeHdl));
436 aBackgroundBtn.SetClickHdl(LINK(this,SvxHFPage, BackgroundHdl));
439 /*--------------------------------------------------------------------
440 Beschreibung: Ein/aus
441 --------------------------------------------------------------------*/
443 IMPL_LINK( SvxHFPage, TurnOnHdl, CheckBox *, pBox )
445 if ( aTurnOnBox.IsChecked() )
447 aDistFT.Enable();
448 aDistEdit.Enable();
449 aDynSpacingCB.Enable();
450 aHeightFT.Enable();
451 aHeightEdit.Enable();
452 aHeightDynBtn.Enable();
453 aLMLbl.Enable();
454 aLMEdit.Enable();
455 aRMLbl.Enable();
456 aRMEdit.Enable();
458 USHORT nUsage = aBspWin.GetUsage();
460 if( nUsage == SVX_PAGE_RIGHT || nUsage == SVX_PAGE_LEFT )
461 aCntSharedBox.Disable();
462 else
463 aCntSharedBox.Enable();
464 aBackgroundBtn.Enable();
466 else
468 BOOL bDelete = TRUE;
470 if ( !bDisableQueryBox && pBox && aTurnOnBox.GetSavedValue() == TRUE )
471 bDelete = ( QueryBox( this, SVX_RES( RID_SVXQBX_DELETE_HEADFOOT ) ).Execute() == RET_YES );
473 if ( bDelete )
475 aDistFT.Disable();
476 aDistEdit.Disable();
477 aDynSpacingCB.Enable(FALSE);
478 aHeightFT.Disable();
479 aHeightEdit.Disable();
480 aHeightDynBtn.Disable();
482 aLMLbl.Disable();
483 aLMEdit.Disable();
484 aRMLbl.Disable();
485 aRMEdit.Disable();
487 aCntSharedBox.Disable();
488 aBackgroundBtn.Disable();
490 else
491 aTurnOnBox.Check();
493 UpdateExample();
494 return 0;
497 /*--------------------------------------------------------------------
498 Beschreibung: Abstand im Bsp Modifizieren
499 --------------------------------------------------------------------*/
501 IMPL_LINK_INLINE_START( SvxHFPage, DistModify, MetricField *, EMPTYARG )
503 UpdateExample();
504 return 0;
506 IMPL_LINK_INLINE_END( SvxHFPage, DistModify, MetricField *, EMPTYARG )
508 IMPL_LINK_INLINE_START( SvxHFPage, HeightModify, MetricField *, EMPTYARG )
510 UpdateExample();
512 return 0;
514 IMPL_LINK_INLINE_END( SvxHFPage, HeightModify, MetricField *, EMPTYARG )
516 /*--------------------------------------------------------------------
517 Beschreibung: Raender einstellen
518 --------------------------------------------------------------------*/
520 IMPL_LINK_INLINE_START( SvxHFPage, BorderModify, MetricField *, EMPTYARG )
522 UpdateExample();
523 return 0;
525 IMPL_LINK_INLINE_END( SvxHFPage, BorderModify, MetricField *, EMPTYARG )
527 /*--------------------------------------------------------------------
528 Beschreibung: Hintergrund
529 --------------------------------------------------------------------*/
531 IMPL_LINK( SvxHFPage, BackgroundHdl, Button *, EMPTYARG )
533 if ( !pBBSet )
535 // nur die n"otigen Items f"uer Umrandung und Hintergrund benutzen
536 USHORT nBrush = GetWhich( SID_ATTR_BRUSH );
537 USHORT nOuter = GetWhich( SID_ATTR_BORDER_OUTER );
538 USHORT nInner = GetWhich( SID_ATTR_BORDER_INNER, sal_False );
539 USHORT nShadow = GetWhich( SID_ATTR_BORDER_SHADOW );
541 // einen leeren Set erzeugenc
542 pBBSet = new SfxItemSet( *GetItemSet().GetPool(), nBrush, nBrush,
543 nOuter, nOuter, nInner, nInner,
544 nShadow, nShadow, 0 );
545 const SfxPoolItem* pItem;
547 if ( SFX_ITEM_SET ==
548 GetItemSet().GetItemState( GetWhich( nId ), FALSE, &pItem ) )
549 // wenn es schon einen gesetzen Set gibt, dann diesen benutzen
550 pBBSet->Put( ( (SvxSetItem*)pItem)->GetItemSet() );
552 if ( SFX_ITEM_SET ==
553 GetItemSet().GetItemState( nInner, FALSE, &pItem ) )
554 // das gesetze InfoItem wird immer ben"otigt
555 pBBSet->Put( *pItem );
558 //CHINA001 SvxBorderBackgroundDlg* pDlg =
559 //CHINA001 new SvxBorderBackgroundDlg( this, *pBBSet, bEnableBackgroundSelector );
560 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
561 if(pFact)
563 SfxAbstractTabDialog* pDlg = pFact->CreateSvxBorderBackgroundDlg( this, *pBBSet, RID_SVXDLG_BBDLG,bEnableBackgroundSelector );
564 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
565 if ( pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet() )
567 SfxItemIter aIter( *pDlg->GetOutputItemSet() );
568 const SfxPoolItem* pItem = aIter.FirstItem();
570 while ( pItem )
572 if ( !IsInvalidItem( pItem ) )
573 pBBSet->Put( *pItem );
574 pItem = aIter.NextItem();
577 //----------------------------------------------------------------
579 USHORT nWhich = GetWhich( SID_ATTR_BRUSH );
581 if ( pBBSet->GetItemState( nWhich ) == SFX_ITEM_SET )
583 const SvxBrushItem& rItem = (const SvxBrushItem&)pBBSet->Get( nWhich );
584 if ( nId == SID_ATTR_PAGE_HEADERSET )
585 aBspWin.SetHdColor( rItem.GetColor() );
586 else
587 aBspWin.SetFtColor( rItem.GetColor() );
590 //----------------------------------------------------------------
592 nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
594 if ( pBBSet->GetItemState( nWhich ) == SFX_ITEM_SET )
596 const SvxBoxItem& rItem = (const SvxBoxItem&)pBBSet->Get( nWhich );
598 if ( nId == SID_ATTR_PAGE_HEADERSET )
599 aBspWin.SetHdBorder( rItem );
600 else
601 aBspWin.SetFtBorder( rItem );
604 UpdateExample();
606 delete pDlg;
608 return 0;
611 /*--------------------------------------------------------------------
612 Beschreibung: Bsp
613 --------------------------------------------------------------------*/
615 void SvxHFPage::UpdateExample()
617 if ( nId == SID_ATTR_PAGE_HEADERSET )
619 aBspWin.SetHeader( aTurnOnBox.IsChecked() );
620 aBspWin.SetHdHeight( GetCoreValue( aHeightEdit, SFX_MAPUNIT_TWIP ) );
621 aBspWin.SetHdDist( GetCoreValue( aDistEdit, SFX_MAPUNIT_TWIP ) );
622 aBspWin.SetHdLeft( GetCoreValue( aLMEdit, SFX_MAPUNIT_TWIP ) );
623 aBspWin.SetHdRight( GetCoreValue( aRMEdit, SFX_MAPUNIT_TWIP ) );
625 else
627 aBspWin.SetFooter( aTurnOnBox.IsChecked() );
628 aBspWin.SetFtHeight( GetCoreValue( aHeightEdit, SFX_MAPUNIT_TWIP ) );
629 aBspWin.SetFtDist( GetCoreValue( aDistEdit, SFX_MAPUNIT_TWIP ) );
630 aBspWin.SetFtLeft( GetCoreValue( aLMEdit, SFX_MAPUNIT_TWIP ) );
631 aBspWin.SetFtRight( GetCoreValue( aRMEdit, SFX_MAPUNIT_TWIP ) );
633 aBspWin.Invalidate();
636 /*--------------------------------------------------------------------
637 Beschreibung: Hintergrund im Beispiel setzen
638 --------------------------------------------------------------------*/
640 void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet )
642 USHORT nWhich = GetWhich( SID_ATTR_PAGE_HEADERSET );
644 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
646 const SvxSetItem& rSetItem =
647 (const SvxSetItem&)rSet.Get( nWhich, FALSE );
648 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
649 const SfxBoolItem& rOn =
650 (const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
652 if ( rOn.GetValue() )
654 nWhich = GetWhich( SID_ATTR_BRUSH );
656 if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
658 const SvxBrushItem& rItem = (const SvxBrushItem&)rTmpSet.Get( nWhich );
659 aBspWin.SetHdColor( rItem.GetColor() );
661 nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
663 if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
665 const SvxBoxItem& rItem =
666 (const SvxBoxItem&)rTmpSet.Get( nWhich );
667 aBspWin.SetHdBorder( rItem );
672 nWhich = GetWhich( SID_ATTR_PAGE_FOOTERSET );
674 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
676 const SvxSetItem& rSetItem =
677 (const SvxSetItem&)rSet.Get( nWhich, FALSE );
678 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
679 const SfxBoolItem& rOn =
680 (const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
682 if ( rOn.GetValue() )
684 nWhich = GetWhich( SID_ATTR_BRUSH );
686 if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
688 const SvxBrushItem& rItem = (const SvxBrushItem&)rTmpSet.Get( nWhich );
689 aBspWin.SetFtColor( rItem.GetColor() );
691 nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
693 if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
695 const SvxBoxItem& rItem =
696 (const SvxBoxItem&)rTmpSet.Get( nWhich );
697 aBspWin.SetFtBorder( rItem );
701 nWhich = GetWhich( SID_ATTR_BRUSH );
703 if ( rSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
705 const SvxBrushItem& rItem = (const SvxBrushItem&)rSet.Get( nWhich );
706 aBspWin.SetColor( rItem.GetColor() );
707 const Graphic* pGrf = rItem.GetGraphic();
709 if ( pGrf )
711 Bitmap aBitmap = pGrf->GetBitmap();
712 aBspWin.SetBitmap( &aBitmap );
714 else
715 aBspWin.SetBitmap( NULL );
717 nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
719 if ( rSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
721 const SvxBoxItem& rItem = (const SvxBoxItem&)rSet.Get( nWhich );
722 aBspWin.SetBorder( rItem );
726 /*--------------------------------------------------------------------
727 Beschreibung:
728 --------------------------------------------------------------------*/
730 void SvxHFPage::ActivatePage( const SfxItemSet& rSet )
732 const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE );
734 if ( pItem )
736 // linken und rechten Rand einstellen
737 const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)*pItem;
739 aBspWin.SetLeft( rLRSpace.GetLeft() );
740 aBspWin.SetRight( rLRSpace.GetRight() );
742 else
744 aBspWin.SetLeft( 0 );
745 aBspWin.SetRight( 0 );
748 pItem = GetItem( rSet, SID_ATTR_ULSPACE );
750 if ( pItem )
752 // oberen und unteren Rand einstellen
753 const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)*pItem;
755 aBspWin.SetTop( rULSpace.GetUpper() );
756 aBspWin.SetBottom( rULSpace.GetLower() );
758 else
760 aBspWin.SetTop( 0 );
761 aBspWin.SetBottom( 0 );
764 USHORT nUsage = SVX_PAGE_ALL;
765 pItem = GetItem( rSet, SID_ATTR_PAGE );
767 if ( pItem )
768 nUsage = ( (const SvxPageItem*)pItem )->GetPageUsage();
770 aBspWin.SetUsage( nUsage );
772 if ( SVX_PAGE_RIGHT == nUsage || SVX_PAGE_LEFT == nUsage )
773 aCntSharedBox.Disable();
774 else
775 aCntSharedBox.Enable();
776 pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
778 if ( pItem )
780 // Orientation und Size aus dem PageItem
781 const SvxSizeItem& rSize = (const SvxSizeItem&)*pItem;
782 // die Groesse ist ggf. schon geswappt (Querformat)
783 aBspWin.SetSize( rSize.GetSize() );
786 // Kopfzeilen-Attribute auswerten
787 const SvxSetItem* pSetItem = 0;
789 if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
790 FALSE,
791 (const SfxPoolItem**)&pSetItem ) )
793 const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
794 const SfxBoolItem& rHeaderOn =
795 (const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
797 if ( rHeaderOn.GetValue() )
799 const SvxSizeItem& rSize = (const SvxSizeItem&)
800 rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
801 const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
802 rHeaderSet.Get( GetWhich(SID_ATTR_ULSPACE ) );
803 const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
804 rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
805 long nDist = rUL.GetLower();
807 aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist );
808 aBspWin.SetHdDist( nDist );
809 aBspWin.SetHdLeft( rLR.GetLeft() );
810 aBspWin.SetHdRight( rLR.GetRight() );
811 aBspWin.SetHeader( TRUE );
813 else
814 pSetItem = 0;
817 if ( !pSetItem )
819 aBspWin.SetHeader( FALSE );
821 if ( SID_ATTR_PAGE_HEADERSET == nId )
822 aCntSharedBox.Disable();
824 pSetItem = 0;
826 if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
827 FALSE,
828 (const SfxPoolItem**)&pSetItem ) )
830 const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
831 const SfxBoolItem& rFooterOn =
832 (const SfxBoolItem&)rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
834 if ( rFooterOn.GetValue() )
836 const SvxSizeItem& rSize = (const SvxSizeItem&)
837 rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
838 const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
839 rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
840 const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
841 rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
842 long nDist = rUL.GetUpper();
844 aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist );
845 aBspWin.SetFtDist( nDist );
846 aBspWin.SetFtLeft( rLR.GetLeft() );
847 aBspWin.SetFtRight( rLR.GetRight() );
848 aBspWin.SetFooter( TRUE );
850 else
851 pSetItem = 0;
854 if ( !pSetItem )
856 aBspWin.SetFooter( FALSE );
858 if ( SID_ATTR_PAGE_FOOTERSET == nId )
859 aCntSharedBox.Disable();
862 pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
864 if ( pItem && pItem->ISA(SfxBoolItem) )
866 aBspWin.SetTable( TRUE );
867 aBspWin.SetHorz( ( (SfxBoolItem*)pItem )->GetValue() );
870 pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
872 if ( pItem && pItem->ISA(SfxBoolItem) )
874 aBspWin.SetTable( TRUE );
875 aBspWin.SetVert( ( (SfxBoolItem*)pItem )->GetValue() );
877 ResetBackground_Impl( rSet );
878 RangeHdl( 0 );
881 /*--------------------------------------------------------------------
882 Beschreibung:
883 --------------------------------------------------------------------*/
885 int SvxHFPage::DeactivatePage( SfxItemSet* _pSet )
887 if ( _pSet )
888 FillItemSet( *_pSet );
889 return LEAVE_PAGE;
892 /*--------------------------------------------------------------------
893 Beschreibung: Berech
894 --------------------------------------------------------------------*/
896 IMPL_LINK( SvxHFPage, RangeHdl, Edit *, EMPTYARG )
898 long nHHeight = aBspWin.GetHdHeight();
899 long nHDist = aBspWin.GetHdDist();
901 long nFHeight = aBspWin.GetFtHeight();
902 long nFDist = aBspWin.GetFtDist();
904 long nHeight = Max( (long)MINBODY,
905 static_cast<long>(aHeightEdit.Denormalize( aHeightEdit.GetValue( FUNIT_TWIP ) ) ) );
906 long nDist = aTurnOnBox.IsChecked() ?
907 static_cast<long>(aDistEdit.Denormalize( aDistEdit.GetValue( FUNIT_TWIP ) )) : 0;
909 long nMin;
910 long nMax;
912 if ( nId == SID_ATTR_PAGE_HEADERSET )
914 nHHeight = nHeight;
915 nHDist = nDist;
917 else
919 nFHeight = nHeight;
920 nFDist = nDist;
923 // Aktuelle Werte der Seitenraender
924 long nBT = aBspWin.GetTop();
925 long nBB = aBspWin.GetBottom();
926 long nBL = aBspWin.GetLeft();
927 long nBR = aBspWin.GetRight();
929 long nH = aBspWin.GetSize().Height();
930 long nW = aBspWin.GetSize().Width();
932 // Grenzen
933 if ( nId == SID_ATTR_PAGE_HEADERSET )
935 // Header
936 nMin = ( nH - nBB - nBT ) / 5; // 20%
937 nMax = Max( nH - nMin - nHDist - nFDist - nFHeight - nBB - nBT,
938 nMin );
939 aHeightEdit.SetMax( aHeightEdit.Normalize( nMax ), FUNIT_TWIP );
940 nMin = ( nH - nBB - nBT ) / 5; // 20%
941 nDist = Max( nH - nMin - nHHeight - nFDist - nFHeight - nBB - nBT,
942 long(0) );
943 aDistEdit.SetMax( aDistEdit.Normalize( nDist ), FUNIT_TWIP );
945 else
947 // Footer
948 nMin = ( nH - nBT - nBB ) / 5; // 20%
949 nMax = Max( nH - nMin - nFDist - nHDist - nHHeight - nBT - nBB,
950 nMin );
951 aHeightEdit.SetMax( aHeightEdit.Normalize( nMax ), FUNIT_TWIP );
952 nMin = ( nH - nBT - nBB ) / 5; // 20%
953 nDist = Max( nH - nMin - nFHeight - nHDist - nHHeight - nBT - nBB,
954 long(0) );
955 aDistEdit.SetMax( aDistEdit.Normalize( nDist ), FUNIT_TWIP );
958 // Einzuege beschraenken
959 nMax = nW - nBL - nBR -
960 static_cast<long>(aRMEdit.Denormalize( aRMEdit.GetValue( FUNIT_TWIP ) )) - MINBODY;
961 aLMEdit.SetMax( aLMEdit.Normalize( nMax ), FUNIT_TWIP );
963 nMax = nW - nBL - nBR -
964 static_cast<long>(aLMEdit.Denormalize( aLMEdit.GetValue( FUNIT_TWIP ) )) - MINBODY;
965 aRMEdit.SetMax( aLMEdit.Normalize( nMax ), FUNIT_TWIP );
966 return 0;
968 /* -----------------------------26.08.2002 12:49------------------------------
970 ---------------------------------------------------------------------------*/
971 void lcl_Move(Window& rWin, sal_Int32 nDiff)
973 Point aPos(rWin.GetPosPixel());
974 aPos.Y() -= nDiff;
975 rWin.SetPosPixel(aPos);
977 void SvxHFPage::EnableDynamicSpacing()
979 aDynSpacingCB.Show();
980 //move all following controls
981 Window* aMoveWindows[] =
983 &aHeightFT,
984 &aHeightEdit,
985 &aHeightDynBtn,
986 &aBackgroundBtn,
989 sal_Int32 nOffset = aTurnOnBox.GetPosPixel().Y() - aCntSharedBox.GetPosPixel().Y();
990 sal_Int32 nIdx = 0;
991 while(aMoveWindows[nIdx])
992 lcl_Move(*aMoveWindows[nIdx++], nOffset);