xref: /aoo41x/main/svx/source/dialog/hdft.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <tools/shl.hxx>
33 #include <svl/itemiter.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <sfx2/module.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <vcl/graph.hxx>
39 
40 #include <sfx2/sfxsids.hrc>
41 #include <svx/svxids.hrc>
42 #include <svx/dialogs.hrc>
43 #include "hdft.hrc"
44 #include <svl/intitem.hxx>
45 
46 #define _SVX_HDFT_CXX
47 
48 #include <svx/hdft.hxx>
49 #include <svx/pageitem.hxx>
50 //CHINA001 #include "bbdlg.hxx"
51 #include "svx/dlgutil.hxx"
52 #include <svx/dialmgr.hxx>
53 #include "svx/htmlmode.hxx"
54 
55 #include <editeng/brshitem.hxx>
56 #include <editeng/lrspitem.hxx>
57 #include <editeng/ulspitem.hxx>
58 #include <editeng/shaditem.hxx>
59 #include <editeng/sizeitem.hxx>
60 #include <editeng/boxitem.hxx>
61 
62 #include <svx/svxdlg.hxx> //CHINA001
63 #include <svx/dialogs.hrc> //CHINA001
64 // static ----------------------------------------------------------------
65 
66 // --> OD 2004-06-18 #i19922#
67 //static const long MINBODY = 284;            // 0,5cm in twips aufgerundet
68 static const long MINBODY = 56;  // 1mm in twips rounded
69 
70 // default distance to Header or footer
71 static const long DEF_DIST_WRITER = 500;	// 5mm (Writer)
72 static const long DEF_DIST_CALC = 250;		// 2,5mm (Calc)
73 
74 static sal_uInt16 pRanges[] =
75 {
76 	SID_ATTR_BRUSH,			 SID_ATTR_BRUSH,
77 	SID_ATTR_BORDER_OUTER,	 SID_ATTR_BORDER_OUTER,
78 	SID_ATTR_BORDER_INNER,	 SID_ATTR_BORDER_INNER,
79 	SID_ATTR_BORDER_SHADOW,	 SID_ATTR_BORDER_SHADOW,
80 	SID_ATTR_LRSPACE,		 SID_ATTR_LRSPACE,
81 	SID_ATTR_ULSPACE,		 SID_ATTR_ULSPACE,
82 	SID_ATTR_PAGE_SIZE,		 SID_ATTR_PAGE_SIZE,
83 	SID_ATTR_PAGE_HEADERSET, SID_ATTR_PAGE_HEADERSET,
84 	SID_ATTR_PAGE_FOOTERSET, SID_ATTR_PAGE_FOOTERSET,
85 	SID_ATTR_PAGE_ON,		 SID_ATTR_PAGE_ON,
86 	SID_ATTR_PAGE_DYNAMIC,	 SID_ATTR_PAGE_DYNAMIC,
87 	SID_ATTR_PAGE_SHARED,	 SID_ATTR_PAGE_SHARED,
88     SID_ATTR_HDFT_DYNAMIC_SPACING, SID_ATTR_HDFT_DYNAMIC_SPACING,
89 	0
90 };
91 
92 /*--------------------------------------------------------------------
93 	Beschreibung:
94  --------------------------------------------------------------------*/
95 
96 // gibt den Bereich der Which-Werte zurueck
97 
98 
99 sal_uInt16* SvxHeaderPage::GetRanges()
100 {
101 	return pRanges;
102 }
103 
104 //------------------------------------------------------------------------
105 
106 SfxTabPage* SvxHeaderPage::Create( Window* pParent, const SfxItemSet& rSet )
107 {
108 	return new SvxHeaderPage( pParent, rSet );
109 }
110 
111 //------------------------------------------------------------------------
112 
113 sal_uInt16* SvxFooterPage::GetRanges()
114 {
115 	return pRanges;
116 }
117 
118 // -----------------------------------------------------------------------
119 
120 SfxTabPage* SvxFooterPage::Create( Window* pParent, const SfxItemSet& rSet )
121 {
122 	return new SvxFooterPage( pParent, rSet );
123 }
124 
125 // -----------------------------------------------------------------------
126 
127 SvxHeaderPage::SvxHeaderPage( Window* pParent, const SfxItemSet& rAttr ) :
128 
129 	SvxHFPage( pParent, RID_SVXPAGE_HEADER, rAttr, SID_ATTR_PAGE_HEADERSET )
130 
131 {
132 }
133 
134 // -----------------------------------------------------------------------
135 
136 SvxFooterPage::SvxFooterPage( Window* pParent, const SfxItemSet& rAttr ) :
137 
138 	SvxHFPage( pParent, RID_SVXPAGE_FOOTER, rAttr, SID_ATTR_PAGE_FOOTERSET )
139 
140 {
141 }
142 
143 // -----------------------------------------------------------------------
144 
145 SvxHFPage::SvxHFPage( Window* pParent, sal_uInt16 nResId, const SfxItemSet& rAttr, sal_uInt16 nSetId ) :
146 
147 	SfxTabPage( pParent, SVX_RES( nResId ), rAttr ),
148 
149     aFrm            ( this, SVX_RES( FL_FRAME ) ),
150 	aTurnOnBox		( this, SVX_RES( CB_TURNON ) ),
151     aCntSharedBox   ( this, SVX_RES( CB_SHARED ) ),
152     aLMLbl          ( this, SVX_RES( FT_LMARGIN ) ),
153     aLMEdit         ( this, SVX_RES( ED_LMARGIN ) ),
154     aRMLbl          ( this, SVX_RES( FT_RMARGIN ) ),
155     aRMEdit         ( this, SVX_RES( ED_RMARGIN ) ),
156     aDistFT         ( this, SVX_RES( FT_DIST ) ),
157 	aDistEdit		( this, SVX_RES( ED_DIST ) ),
158     aDynSpacingCB   ( this, SVX_RES( CB_DYNSPACING ) ),
159     aHeightFT       ( this, SVX_RES( FT_HEIGHT ) ),
160 	aHeightEdit		( this, SVX_RES( ED_HEIGHT ) ),
161 	aHeightDynBtn	( this, SVX_RES( CB_HEIGHT_DYN ) ),
162 	aBspWin			( this, SVX_RES( WN_BSP ) ),
163 	aBackgroundBtn	( this, SVX_RES( BTN_EXTRAS ) ),
164 
165     nId                         ( nSetId ),
166     pBBSet                      ( NULL ),
167     bDisableQueryBox            ( sal_False ),
168 	bEnableBackgroundSelector	( sal_True )
169 
170 {
171 	InitHandler();
172     aBspWin.EnableRTL( sal_False );
173 
174 	// diese Page braucht ExchangeSupport
175 	SetExchangeSupport();
176 
177 	FreeResource();
178 
179 	// Metrik einstellen
180 	FieldUnit eFUnit = GetModuleFieldUnit( rAttr );
181 	SetFieldUnit( aDistEdit, eFUnit );
182 	SetFieldUnit( aHeightEdit, eFUnit );
183 	SetFieldUnit( aLMEdit, eFUnit );
184 	SetFieldUnit( aRMEdit, eFUnit );
185 
186 	aTurnOnBox.SetAccessibleRelationMemberOf( &aFrm );
187 	aCntSharedBox.SetAccessibleRelationMemberOf( &aFrm );
188 	aLMLbl.SetAccessibleRelationMemberOf( &aFrm );
189 	aLMEdit.SetAccessibleRelationMemberOf( &aFrm );
190 	aRMLbl.SetAccessibleRelationMemberOf( &aFrm );
191 	aRMEdit.SetAccessibleRelationMemberOf( &aFrm );
192 	aDistFT.SetAccessibleRelationMemberOf( &aFrm );
193 	aDistEdit.SetAccessibleRelationMemberOf( &aFrm );
194 	aDynSpacingCB.SetAccessibleRelationMemberOf( &aFrm );
195 	aHeightFT.SetAccessibleRelationMemberOf( &aFrm );
196 	aHeightEdit.SetAccessibleRelationMemberOf( &aFrm );
197 	aHeightDynBtn.SetAccessibleRelationMemberOf( &aFrm );
198 	aBackgroundBtn.SetAccessibleRelationMemberOf(&aFrm);
199 }
200 
201 // -----------------------------------------------------------------------
202 
203 SvxHFPage::~SvxHFPage()
204 {
205 	delete pBBSet;
206 }
207 
208 // -----------------------------------------------------------------------
209 
210 sal_Bool SvxHFPage::FillItemSet( SfxItemSet& rSet )
211 {
212 	const sal_uInt16		nWSize		= GetWhich( SID_ATTR_PAGE_SIZE );
213 	const sal_uInt16		nWLRSpace	= GetWhich( SID_ATTR_LRSPACE );
214 	const sal_uInt16		nWULSpace	= GetWhich( SID_ATTR_ULSPACE );
215 	const sal_uInt16		nWOn		= GetWhich( SID_ATTR_PAGE_ON );
216 	const sal_uInt16		nWDynamic	= GetWhich( SID_ATTR_PAGE_DYNAMIC );
217     const sal_uInt16        nWDynSpacing = GetWhich( SID_ATTR_HDFT_DYNAMIC_SPACING );
218 	const sal_uInt16		nWShared	= GetWhich( SID_ATTR_PAGE_SHARED );
219 	const sal_uInt16		nWBrush		= GetWhich( SID_ATTR_BRUSH );
220 	const sal_uInt16		nWBox		= GetWhich( SID_ATTR_BORDER_OUTER );
221 	const sal_uInt16		nWBoxInfo	= GetWhich( SID_ATTR_BORDER_INNER );
222 	const sal_uInt16		nWShadow	= GetWhich( SID_ATTR_BORDER_SHADOW );
223 	const sal_uInt16		aWhichTab[] = { nWSize,		nWSize,
224 										nWLRSpace,	nWLRSpace,
225 										nWULSpace,	nWULSpace,
226 										nWOn,		nWOn,
227 										nWDynamic,	nWDynamic,
228 										nWShared,	nWShared,
229 										nWBrush,	nWBrush,
230 										nWBoxInfo,	nWBoxInfo,
231 										nWBox,		nWBox,
232 										nWShadow,	nWShadow,
233                                         nWDynSpacing, nWDynSpacing,
234 										0 };
235 	const SfxItemSet&	rOldSet		= GetItemSet();
236 	SfxItemPool*		pPool		= rOldSet.GetPool();
237 	DBG_ASSERT( pPool, "no pool :-(" );
238 	SfxMapUnit			eUnit		= pPool->GetMetric( nWSize );
239 	SfxItemSet			aSet		( *pPool, aWhichTab );
240 
241 	//--------------------------------------------------------------------
242 
243 	aSet.Put( SfxBoolItem( nWOn,	  aTurnOnBox.IsChecked() ) );
244 	aSet.Put( SfxBoolItem( nWDynamic, aHeightDynBtn.IsChecked() ) );
245 	aSet.Put( SfxBoolItem( nWShared,  aCntSharedBox.IsChecked() ) );
246     if(aDynSpacingCB.IsVisible() && SFX_WHICH_MAX > nWDynSpacing)
247     {
248         SfxBoolItem* pBoolItem = (SfxBoolItem*)pPool->GetDefaultItem(nWDynSpacing).Clone();
249         pBoolItem->SetValue(aDynSpacingCB.IsChecked());
250         aSet.Put(*pBoolItem);
251         delete pBoolItem;
252     }
253 
254 	// Groesse
255 	SvxSizeItem aSizeItem( (const SvxSizeItem&)rOldSet.Get( nWSize ) );
256 	Size		aSize( aSizeItem.GetSize() );
257 	long		nDist = GetCoreValue( aDistEdit, eUnit );
258 	long		nH	  = GetCoreValue( aHeightEdit, eUnit );
259 
260 	// fixe Hoehe?
261 //	if ( !aHeightDynBtn.IsChecked() )
262 		nH += nDist; // dann Abstand dazu addieren
263 	aSize.Height() = nH;
264 	aSizeItem.SetSize( aSize );
265 	aSet.Put( aSizeItem );
266 
267 	// Raender
268 	SvxLRSpaceItem aLR( nWLRSpace );
269 	aLR.SetLeft( (sal_uInt16)GetCoreValue( aLMEdit, eUnit ) );
270 	aLR.SetRight( (sal_uInt16)GetCoreValue( aRMEdit, eUnit ) );
271 	aSet.Put( aLR );
272 
273 	SvxULSpaceItem aUL( nWULSpace );
274 	if ( nId == SID_ATTR_PAGE_HEADERSET )
275 		aUL.SetLower( (sal_uInt16)nDist );
276 	else
277 		aUL.SetUpper( (sal_uInt16)nDist );
278 	aSet.Put( aUL );
279 
280 	// Hintergrund und Umrandung?
281 	if ( pBBSet )
282 		aSet.Put( *pBBSet );
283 	else
284 	{
285         const SfxItemSet* _pSet;
286 		const SfxPoolItem* pItem;
287 
288 		if ( SFX_ITEM_SET ==
289 			 GetItemSet().GetItemState( GetWhich( nId ), sal_False, &pItem ) )
290 		{
291             _pSet = &( (SvxSetItem*)pItem )->GetItemSet();
292 
293             if ( _pSet->GetItemState( nWBrush ) == SFX_ITEM_SET )
294                 aSet.Put( (const SvxBrushItem&)_pSet->Get( nWBrush ) );
295             if ( _pSet->GetItemState( nWBoxInfo ) == SFX_ITEM_SET )
296                 aSet.Put( (const SvxBoxInfoItem&)_pSet->Get( nWBoxInfo ) );
297             if ( _pSet->GetItemState( nWBox ) == SFX_ITEM_SET )
298                 aSet.Put( (const SvxBoxItem&)_pSet->Get( nWBox ) );
299             if ( _pSet->GetItemState( nWShadow ) == SFX_ITEM_SET )
300                 aSet.Put( (const SvxShadowItem&)_pSet->Get( nWShadow ) );
301 		}
302 	}
303 
304 	// Das SetItem wegschreiben
305 	SvxSetItem aSetItem( GetWhich( nId ), aSet );
306 	rSet.Put( aSetItem );
307 
308 	return sal_True;
309 }
310 
311 // -----------------------------------------------------------------------
312 void SvxHFPage::Reset( const SfxItemSet& rSet )
313 {
314 	ActivatePage( rSet );
315 	ResetBackground_Impl( rSet );
316 
317 	SfxItemPool* pPool = GetItemSet().GetPool();
318 	DBG_ASSERT( pPool, "Wo ist der Pool" );
319 	SfxMapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_PAGE_SIZE ) );
320 
321 	// Kopf-/Fusszeilen-Attribute auswerten
322 	//
323 	const SvxSetItem* pSetItem = 0;
324 
325 	if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich(nId), sal_False,
326 											(const SfxPoolItem**)&pSetItem ) )
327 	{
328 		const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
329 		const SfxBoolItem& rHeaderOn =
330 			(const SfxBoolItem&)rHeaderSet.Get(GetWhich(SID_ATTR_PAGE_ON));
331 
332 		aTurnOnBox.Check(rHeaderOn.GetValue());
333 
334 		if ( rHeaderOn.GetValue() )
335 		{
336 			const SfxBoolItem& rDynamic =
337 				(const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_DYNAMIC ) );
338 			const SfxBoolItem& rShared =
339 				(const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SHARED ) );
340 			const SvxSizeItem& rSize =
341 				(const SvxSizeItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
342 			const SvxULSpaceItem& rUL =
343 				(const SvxULSpaceItem&)rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
344 			const SvxLRSpaceItem& rLR =
345 				(const SvxLRSpaceItem&)rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
346             if(aDynSpacingCB.IsVisible())
347             {
348                 const SfxBoolItem& rDynSpacing =
349                     (const SfxBoolItem&)rHeaderSet.Get(GetWhich(SID_ATTR_HDFT_DYNAMIC_SPACING));
350                 aDynSpacingCB.Check(rDynSpacing.GetValue());
351             }
352 
353 
354             if ( nId == SID_ATTR_PAGE_HEADERSET )
355 			{	// Kopfzeile
356 				SetMetricValue( aDistEdit, rUL.GetLower(), eUnit );
357 				SetMetricValue( aHeightEdit, rSize.GetSize().Height() - rUL.GetLower(), eUnit );
358 			}
359 			else
360 			{	// Fusszeile
361 				SetMetricValue( aDistEdit, rUL.GetUpper(), eUnit );
362 				SetMetricValue( aHeightEdit, rSize.GetSize().Height() - rUL.GetUpper(), eUnit );
363 			}
364 
365 			aHeightDynBtn.Check(rDynamic.GetValue());
366 			SetMetricValue( aLMEdit, rLR.GetLeft(), eUnit );
367 			SetMetricValue( aRMEdit, rLR.GetRight(), eUnit );
368 			aCntSharedBox.Check(rShared.GetValue());
369 		}
370 		else
371 			pSetItem = 0;
372 	}
373 	else
374 	{
375 		// defaults for distance and height
376 		long nDefaultDist = DEF_DIST_WRITER;
377 		const SfxPoolItem* pExt1 = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
378 		const SfxPoolItem* pExt2 = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
379 
380 		if ( pExt1 && pExt1->ISA(SfxBoolItem) && pExt2 && pExt2->ISA(SfxBoolItem) )
381 			nDefaultDist = DEF_DIST_CALC;
382 
383 		SetMetricValue( aDistEdit, nDefaultDist, SFX_MAPUNIT_100TH_MM );
384 		SetMetricValue( aHeightEdit, 500, SFX_MAPUNIT_100TH_MM );
385 	}
386 
387 	if ( !pSetItem )
388 	{
389 		aTurnOnBox.Check( sal_False );
390 		aHeightDynBtn.Check( sal_True );
391 		aCntSharedBox.Check( sal_True );
392 	}
393 
394 	TurnOnHdl(0);
395 
396 	aTurnOnBox.SaveValue();
397 	aDistEdit.SaveValue();
398 	aHeightEdit.SaveValue();
399 	aHeightDynBtn.SaveValue();
400 	aLMEdit.SaveValue();
401 	aRMEdit.SaveValue();
402 	aCntSharedBox.SaveValue();
403 	RangeHdl( 0 );
404 
405 	sal_uInt16 nHtmlMode = 0;
406 	const SfxPoolItem* pItem = 0;
407 	SfxObjectShell* pShell;
408 	if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
409 		( 0 != (pShell = SfxObjectShell::Current()) &&
410 					0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
411 	{
412 		nHtmlMode = ((SfxUInt16Item*)pItem)->GetValue();
413 		if(nHtmlMode && HTMLMODE_ON)
414 		{
415 			aCntSharedBox.Hide();
416 			aBackgroundBtn.Hide();
417 		}
418 	}
419 
420 }
421 
422 /*--------------------------------------------------------------------
423 	Beschreibung:	Handler initialisieren
424  --------------------------------------------------------------------*/
425 
426 void SvxHFPage::InitHandler()
427 {
428 	aTurnOnBox.SetClickHdl(LINK(this, 	SvxHFPage, TurnOnHdl));
429 	aDistEdit.SetModifyHdl(LINK(this, 	SvxHFPage, DistModify));
430 	aDistEdit.SetLoseFocusHdl(LINK(this, SvxHFPage, RangeHdl));
431 
432 	aHeightEdit.SetModifyHdl(LINK(this, 	SvxHFPage, HeightModify));
433 	aHeightEdit.SetLoseFocusHdl(LINK(this,SvxHFPage,RangeHdl));
434 
435 	aLMEdit.SetModifyHdl(LINK(this, 		SvxHFPage, BorderModify));
436 	aLMEdit.SetLoseFocusHdl(LINK(this,	SvxHFPage, RangeHdl));
437 	aRMEdit.SetModifyHdl(LINK(this, 		SvxHFPage, BorderModify));
438 	aRMEdit.SetLoseFocusHdl(LINK(this,	SvxHFPage, RangeHdl));
439 	aBackgroundBtn.SetClickHdl(LINK(this,SvxHFPage, BackgroundHdl));
440 }
441 
442 /*--------------------------------------------------------------------
443 	Beschreibung:	Ein/aus
444  --------------------------------------------------------------------*/
445 
446 IMPL_LINK( SvxHFPage, TurnOnHdl, CheckBox *, pBox )
447 {
448 	if ( aTurnOnBox.IsChecked() )
449 	{
450 		aDistFT.Enable();
451 		aDistEdit.Enable();
452         aDynSpacingCB.Enable();
453 		aHeightFT.Enable();
454 		aHeightEdit.Enable();
455 		aHeightDynBtn.Enable();
456 		aLMLbl.Enable();
457 		aLMEdit.Enable();
458 		aRMLbl.Enable();
459 		aRMEdit.Enable();
460 
461 		sal_uInt16 nUsage = aBspWin.GetUsage();
462 
463 		if( nUsage == SVX_PAGE_RIGHT || nUsage == SVX_PAGE_LEFT )
464 			aCntSharedBox.Disable();
465 		else
466 			aCntSharedBox.Enable();
467 		aBackgroundBtn.Enable();
468 	}
469 	else
470 	{
471 		sal_Bool bDelete = sal_True;
472 
473 		if ( !bDisableQueryBox && pBox && aTurnOnBox.GetSavedValue() == sal_True )
474 			bDelete = ( QueryBox( this, SVX_RES( RID_SVXQBX_DELETE_HEADFOOT ) ).Execute() == RET_YES );
475 
476 		if ( bDelete )
477 		{
478 			aDistFT.Disable();
479 			aDistEdit.Disable();
480             aDynSpacingCB.Enable(sal_False);
481             aHeightFT.Disable();
482 			aHeightEdit.Disable();
483 			aHeightDynBtn.Disable();
484 
485 			aLMLbl.Disable();
486 			aLMEdit.Disable();
487 			aRMLbl.Disable();
488 			aRMEdit.Disable();
489 
490 			aCntSharedBox.Disable();
491 			aBackgroundBtn.Disable();
492 		}
493 		else
494 			aTurnOnBox.Check();
495 	}
496 	UpdateExample();
497 	return 0;
498 }
499 
500 /*--------------------------------------------------------------------
501 	Beschreibung:	Abstand im Bsp Modifizieren
502  --------------------------------------------------------------------*/
503 
504 IMPL_LINK_INLINE_START( SvxHFPage, DistModify, MetricField *, EMPTYARG )
505 {
506 	UpdateExample();
507 	return 0;
508 }
509 IMPL_LINK_INLINE_END( SvxHFPage, DistModify, MetricField *, EMPTYARG )
510 
511 IMPL_LINK_INLINE_START( SvxHFPage, HeightModify, MetricField *, EMPTYARG )
512 {
513 	UpdateExample();
514 
515 	return 0;
516 }
517 IMPL_LINK_INLINE_END( SvxHFPage, HeightModify, MetricField *, EMPTYARG )
518 
519 /*--------------------------------------------------------------------
520 	Beschreibung: Raender einstellen
521  --------------------------------------------------------------------*/
522 
523 IMPL_LINK_INLINE_START( SvxHFPage, BorderModify, MetricField *, EMPTYARG )
524 {
525 	UpdateExample();
526 	return 0;
527 }
528 IMPL_LINK_INLINE_END( SvxHFPage, BorderModify, MetricField *, EMPTYARG )
529 
530 /*--------------------------------------------------------------------
531 	Beschreibung:	Hintergrund
532  --------------------------------------------------------------------*/
533 
534 IMPL_LINK( SvxHFPage, BackgroundHdl, Button *, EMPTYARG )
535 {
536 	if ( !pBBSet )
537 	{
538 		// nur die n"otigen Items f"uer Umrandung und Hintergrund benutzen
539 		sal_uInt16 nBrush = GetWhich( SID_ATTR_BRUSH );
540 		sal_uInt16 nOuter = GetWhich( SID_ATTR_BORDER_OUTER );
541 		sal_uInt16 nInner = GetWhich( SID_ATTR_BORDER_INNER, sal_False );
542 		sal_uInt16 nShadow = GetWhich( SID_ATTR_BORDER_SHADOW );
543 
544 		// einen leeren Set erzeugenc
545 		pBBSet = new SfxItemSet( *GetItemSet().GetPool(), nBrush, nBrush,
546 								 nOuter, nOuter, nInner, nInner,
547 								 nShadow, nShadow, 0 );
548 		const SfxPoolItem* pItem;
549 
550 		if ( SFX_ITEM_SET ==
551 			 GetItemSet().GetItemState( GetWhich( nId ), sal_False, &pItem ) )
552 			// wenn es schon einen gesetzen Set gibt, dann diesen benutzen
553 			pBBSet->Put( ( (SvxSetItem*)pItem)->GetItemSet() );
554 
555 		if ( SFX_ITEM_SET ==
556 			 GetItemSet().GetItemState( nInner, sal_False, &pItem ) )
557 			// das gesetze InfoItem wird immer ben"otigt
558 			pBBSet->Put( *pItem );
559 	}
560 
561 	//CHINA001 SvxBorderBackgroundDlg* pDlg =
562 //CHINA001 		new SvxBorderBackgroundDlg( this, *pBBSet, bEnableBackgroundSelector );
563 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
564 	if(pFact)
565 	{
566 		SfxAbstractTabDialog* pDlg = pFact->CreateSvxBorderBackgroundDlg( this, *pBBSet, bEnableBackgroundSelector );
567 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
568 		if ( pDlg->Execute() == RET_OK && pDlg->GetOutputItemSet() )
569 		{
570 			SfxItemIter aIter( *pDlg->GetOutputItemSet() );
571 			const SfxPoolItem* pItem = aIter.FirstItem();
572 
573 			while ( pItem )
574 			{
575 				if ( !IsInvalidItem( pItem ) )
576 					pBBSet->Put( *pItem );
577 				pItem = aIter.NextItem();
578 			}
579 
580 			//----------------------------------------------------------------
581 
582 			sal_uInt16 nWhich = GetWhich( SID_ATTR_BRUSH );
583 
584 			if ( pBBSet->GetItemState( nWhich ) == SFX_ITEM_SET )
585 			{
586 				const SvxBrushItem& rItem = (const SvxBrushItem&)pBBSet->Get( nWhich );
587 				if ( nId == SID_ATTR_PAGE_HEADERSET )
588 					aBspWin.SetHdColor( rItem.GetColor() );
589 				else
590 					aBspWin.SetFtColor( rItem.GetColor() );
591 			}
592 
593 			//----------------------------------------------------------------
594 
595 			nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
596 
597 			if ( pBBSet->GetItemState( nWhich ) == SFX_ITEM_SET )
598 			{
599 				const SvxBoxItem& rItem = (const SvxBoxItem&)pBBSet->Get( nWhich );
600 
601 				if ( nId == SID_ATTR_PAGE_HEADERSET )
602 					aBspWin.SetHdBorder( rItem );
603 				else
604 					aBspWin.SetFtBorder( rItem );
605 			}
606 
607 			UpdateExample();
608 		}
609 	delete pDlg;
610 	}
611 	return 0;
612 }
613 
614 /*--------------------------------------------------------------------
615 	Beschreibung:	Bsp
616  --------------------------------------------------------------------*/
617 
618 void SvxHFPage::UpdateExample()
619 {
620 	if ( nId == SID_ATTR_PAGE_HEADERSET )
621 	{
622 		aBspWin.SetHeader( aTurnOnBox.IsChecked() );
623 		aBspWin.SetHdHeight( GetCoreValue( aHeightEdit, SFX_MAPUNIT_TWIP ) );
624 		aBspWin.SetHdDist( GetCoreValue( aDistEdit, SFX_MAPUNIT_TWIP ) );
625 		aBspWin.SetHdLeft( GetCoreValue( aLMEdit, SFX_MAPUNIT_TWIP ) );
626 		aBspWin.SetHdRight( GetCoreValue( aRMEdit, SFX_MAPUNIT_TWIP ) );
627 	}
628 	else
629 	{
630 		aBspWin.SetFooter( aTurnOnBox.IsChecked() );
631 		aBspWin.SetFtHeight( GetCoreValue( aHeightEdit, SFX_MAPUNIT_TWIP ) );
632 		aBspWin.SetFtDist( GetCoreValue( aDistEdit, SFX_MAPUNIT_TWIP ) );
633 		aBspWin.SetFtLeft( GetCoreValue( aLMEdit, SFX_MAPUNIT_TWIP ) );
634 		aBspWin.SetFtRight( GetCoreValue( aRMEdit, SFX_MAPUNIT_TWIP ) );
635 	}
636 	aBspWin.Invalidate();
637 }
638 
639 /*--------------------------------------------------------------------
640 	Beschreibung: Hintergrund im Beispiel setzen
641  --------------------------------------------------------------------*/
642 
643 void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet )
644 {
645 	sal_uInt16 nWhich = GetWhich( SID_ATTR_PAGE_HEADERSET );
646 
647 	if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
648 	{
649 		const SvxSetItem& rSetItem =
650 			(const SvxSetItem&)rSet.Get( nWhich, sal_False );
651 		const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
652 		const SfxBoolItem& rOn =
653 			(const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
654 
655 		if ( rOn.GetValue() )
656 		{
657 			nWhich = GetWhich( SID_ATTR_BRUSH );
658 
659 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
660 			{
661 				const SvxBrushItem& rItem = (const SvxBrushItem&)rTmpSet.Get( nWhich );
662 				aBspWin.SetHdColor( rItem.GetColor() );
663 			}
664 			nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
665 
666 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
667 			{
668 				const SvxBoxItem& rItem =
669 					(const SvxBoxItem&)rTmpSet.Get( nWhich );
670 				aBspWin.SetHdBorder( rItem );
671 			}
672 		}
673 	}
674 
675 	nWhich = GetWhich( SID_ATTR_PAGE_FOOTERSET );
676 
677 	if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
678 	{
679 		const SvxSetItem& rSetItem =
680 			(const SvxSetItem&)rSet.Get( nWhich, sal_False );
681 		const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
682 		const SfxBoolItem& rOn =
683 			(const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
684 
685 		if ( rOn.GetValue() )
686 		{
687 			nWhich = GetWhich( SID_ATTR_BRUSH );
688 
689 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
690 			{
691 				const SvxBrushItem& rItem = (const SvxBrushItem&)rTmpSet.Get( nWhich );
692 				aBspWin.SetFtColor( rItem.GetColor() );
693 			}
694 			nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
695 
696 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
697 			{
698 				const SvxBoxItem& rItem =
699 					(const SvxBoxItem&)rTmpSet.Get( nWhich );
700 				aBspWin.SetFtBorder( rItem );
701 			}
702 		}
703 	}
704 	nWhich = GetWhich( SID_ATTR_BRUSH );
705 
706 	if ( rSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
707 	{
708 		const SvxBrushItem& rItem = (const SvxBrushItem&)rSet.Get( nWhich );
709 		aBspWin.SetColor( rItem.GetColor() );
710 		const Graphic* pGrf = rItem.GetGraphic();
711 
712 		if ( pGrf )
713 		{
714 			Bitmap aBitmap = pGrf->GetBitmap();
715 			aBspWin.SetBitmap( &aBitmap );
716 		}
717 		else
718 			aBspWin.SetBitmap( NULL );
719 	}
720 	nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
721 
722 	if ( rSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
723 	{
724 		const SvxBoxItem& rItem = (const SvxBoxItem&)rSet.Get( nWhich );
725 		aBspWin.SetBorder( rItem );
726 	}
727 }
728 
729 /*--------------------------------------------------------------------
730 	Beschreibung:
731  --------------------------------------------------------------------*/
732 
733 void SvxHFPage::ActivatePage( const SfxItemSet& rSet )
734 {
735 	const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE );
736 
737 	if ( pItem )
738 	{
739 		// linken und rechten Rand einstellen
740 		const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)*pItem;
741 
742 		aBspWin.SetLeft( rLRSpace.GetLeft() );
743 		aBspWin.SetRight( rLRSpace.GetRight() );
744 	}
745 	else
746 	{
747 		aBspWin.SetLeft( 0 );
748 		aBspWin.SetRight( 0 );
749 	}
750 
751 	pItem = GetItem( rSet, SID_ATTR_ULSPACE );
752 
753 	if ( pItem )
754 	{
755 		// oberen und unteren Rand einstellen
756 		const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)*pItem;
757 
758 		aBspWin.SetTop( rULSpace.GetUpper() );
759 		aBspWin.SetBottom( rULSpace.GetLower() );
760 	}
761 	else
762 	{
763 		aBspWin.SetTop( 0 );
764 		aBspWin.SetBottom( 0 );
765 	}
766 
767 	sal_uInt16 nUsage = SVX_PAGE_ALL;
768 	pItem = GetItem( rSet, SID_ATTR_PAGE );
769 
770 	if ( pItem )
771 		nUsage = ( (const SvxPageItem*)pItem )->GetPageUsage();
772 
773 	aBspWin.SetUsage( nUsage );
774 
775 	if ( SVX_PAGE_RIGHT == nUsage || SVX_PAGE_LEFT == nUsage )
776 		aCntSharedBox.Disable();
777 	else
778 		aCntSharedBox.Enable();
779 	pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
780 
781 	if ( pItem )
782 	{
783 		// Orientation und Size aus dem PageItem
784 		const SvxSizeItem& rSize = (const SvxSizeItem&)*pItem;
785 		// die Groesse ist ggf. schon geswappt (Querformat)
786 		aBspWin.SetSize( rSize.GetSize() );
787 	}
788 
789 	// Kopfzeilen-Attribute auswerten
790 	const SvxSetItem* pSetItem = 0;
791 
792 	if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
793 											sal_False,
794 											(const SfxPoolItem**)&pSetItem ) )
795 	{
796 		const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
797 		const SfxBoolItem& rHeaderOn =
798 			(const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
799 
800 		if ( rHeaderOn.GetValue() )
801 		{
802 			const SvxSizeItem& rSize = (const SvxSizeItem&)
803 				rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
804 			const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
805 				rHeaderSet.Get( GetWhich(SID_ATTR_ULSPACE ) );
806 			const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
807 				rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
808 			long nDist = rUL.GetLower();
809 
810 			aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist );
811 			aBspWin.SetHdDist( nDist );
812 			aBspWin.SetHdLeft( rLR.GetLeft() );
813 			aBspWin.SetHdRight( rLR.GetRight() );
814 			aBspWin.SetHeader( sal_True );
815 		}
816 		else
817 			pSetItem = 0;
818 	}
819 
820 	if ( !pSetItem )
821 	{
822 		aBspWin.SetHeader( sal_False );
823 
824 		if ( SID_ATTR_PAGE_HEADERSET == nId )
825 			aCntSharedBox.Disable();
826 	}
827 	pSetItem = 0;
828 
829 	if ( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
830 											sal_False,
831 											(const SfxPoolItem**)&pSetItem ) )
832 	{
833 		const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
834 		const SfxBoolItem& rFooterOn =
835 			(const SfxBoolItem&)rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
836 
837 		if ( rFooterOn.GetValue() )
838 		{
839 			const SvxSizeItem& rSize = (const SvxSizeItem&)
840 				rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
841 			const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
842 				rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
843 			const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
844 				rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
845 			long nDist = rUL.GetUpper();
846 
847 			aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist );
848 			aBspWin.SetFtDist( nDist );
849 			aBspWin.SetFtLeft( rLR.GetLeft() );
850 			aBspWin.SetFtRight( rLR.GetRight() );
851 			aBspWin.SetFooter( sal_True );
852 		}
853 		else
854 			pSetItem = 0;
855 	}
856 
857 	if ( !pSetItem )
858 	{
859 		aBspWin.SetFooter( sal_False );
860 
861 		if ( SID_ATTR_PAGE_FOOTERSET == nId )
862 			aCntSharedBox.Disable();
863 	}
864 
865 	pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
866 
867 	if ( pItem && pItem->ISA(SfxBoolItem) )
868 	{
869 		aBspWin.SetTable( sal_True );
870 		aBspWin.SetHorz( ( (SfxBoolItem*)pItem )->GetValue() );
871 	}
872 
873 	pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
874 
875 	if ( pItem && pItem->ISA(SfxBoolItem) )
876 	{
877 		aBspWin.SetTable( sal_True );
878 		aBspWin.SetVert( ( (SfxBoolItem*)pItem )->GetValue() );
879 	}
880 	ResetBackground_Impl( rSet );
881 	RangeHdl( 0 );
882 }
883 
884 /*--------------------------------------------------------------------
885 	Beschreibung:
886  --------------------------------------------------------------------*/
887 
888 int SvxHFPage::DeactivatePage( SfxItemSet* _pSet )
889 {
890     if ( _pSet )
891         FillItemSet( *_pSet );
892 	return LEAVE_PAGE;
893 }
894 
895 /*--------------------------------------------------------------------
896 	Beschreibung:	Berech
897  --------------------------------------------------------------------*/
898 
899 IMPL_LINK( SvxHFPage, RangeHdl, Edit *, EMPTYARG )
900 {
901 	long nHHeight = aBspWin.GetHdHeight();
902 	long nHDist   = aBspWin.GetHdDist();
903 
904 	long nFHeight = aBspWin.GetFtHeight();
905 	long nFDist   = aBspWin.GetFtDist();
906 
907 	long nHeight = Max( (long)MINBODY,
908 		static_cast<long>(aHeightEdit.Denormalize( aHeightEdit.GetValue( FUNIT_TWIP ) ) ) );
909 	long nDist   = aTurnOnBox.IsChecked() ?
910 		static_cast<long>(aDistEdit.Denormalize( aDistEdit.GetValue( FUNIT_TWIP ) )) : 0;
911 
912 	long nMin;
913 	long nMax;
914 
915 	if ( nId == SID_ATTR_PAGE_HEADERSET )
916 	{
917 		nHHeight = nHeight;
918 		nHDist   = nDist;
919 	}
920 	else
921 	{
922 		nFHeight = nHeight;
923 		nFDist 	 = nDist;
924 	}
925 
926 	// Aktuelle Werte der Seitenraender
927 	long nBT = aBspWin.GetTop();
928 	long nBB = aBspWin.GetBottom();
929 	long nBL = aBspWin.GetLeft();
930 	long nBR = aBspWin.GetRight();
931 
932 	long nH  = aBspWin.GetSize().Height();
933 	long nW  = aBspWin.GetSize().Width();
934 
935 	// Grenzen
936 	if ( nId == SID_ATTR_PAGE_HEADERSET )
937 	{
938 		// Header
939 		nMin = ( nH - nBB - nBT ) / 5; // 20%
940 		nMax = Max( nH - nMin - nHDist - nFDist - nFHeight - nBB - nBT,
941 					nMin );
942 		aHeightEdit.SetMax( aHeightEdit.Normalize( nMax ), FUNIT_TWIP );
943 		nMin = ( nH - nBB - nBT ) / 5; // 20%
944 		nDist = Max( nH - nMin - nHHeight - nFDist - nFHeight - nBB - nBT,
945 					 long(0) );
946 		aDistEdit.SetMax( aDistEdit.Normalize( nDist ), FUNIT_TWIP );
947 	}
948 	else
949 	{
950 		// Footer
951 		nMin = ( nH - nBT - nBB ) / 5; // 20%
952 		nMax = Max( nH - nMin - nFDist - nHDist - nHHeight - nBT - nBB,
953 					nMin );
954 		aHeightEdit.SetMax( aHeightEdit.Normalize( nMax ), FUNIT_TWIP );
955         nMin = ( nH - nBT - nBB ) / 5; // 20%
956 		nDist = Max( nH - nMin - nFHeight - nHDist - nHHeight - nBT - nBB,
957 					 long(0) );
958 		aDistEdit.SetMax( aDistEdit.Normalize( nDist ), FUNIT_TWIP );
959 	}
960 
961 	// Einzuege beschraenken
962 	nMax = nW - nBL - nBR -
963 		   static_cast<long>(aRMEdit.Denormalize( aRMEdit.GetValue( FUNIT_TWIP ) )) - MINBODY;
964 	aLMEdit.SetMax( aLMEdit.Normalize( nMax ), FUNIT_TWIP );
965 
966 	nMax = nW - nBL - nBR -
967 		   static_cast<long>(aLMEdit.Denormalize( aLMEdit.GetValue( FUNIT_TWIP ) )) - MINBODY;
968 	aRMEdit.SetMax( aLMEdit.Normalize( nMax ), FUNIT_TWIP );
969 	return 0;
970 }
971 /* -----------------------------26.08.2002 12:49------------------------------
972 
973  ---------------------------------------------------------------------------*/
974 void lcl_Move(Window& rWin, sal_Int32 nDiff)
975 {
976 	Point aPos(rWin.GetPosPixel());
977 	aPos.Y() -= nDiff;
978 	rWin.SetPosPixel(aPos);
979 }
980 void SvxHFPage::EnableDynamicSpacing()
981 {
982     aDynSpacingCB.Show();
983     //move all following controls
984     Window* aMoveWindows[] =
985     {
986         &aHeightFT,
987         &aHeightEdit,
988         &aHeightDynBtn,
989         &aBackgroundBtn,
990         0
991     };
992     sal_Int32 nOffset = aTurnOnBox.GetPosPixel().Y() - aCntSharedBox.GetPosPixel().Y();
993     sal_Int32 nIdx = 0;
994     while(aMoveWindows[nIdx])
995         lcl_Move(*aMoveWindows[nIdx++], nOffset);
996 }
997 
998