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