xref: /trunk/main/cui/source/tabpages/page.cxx (revision 72febba8)
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_cui.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <sfx2/app.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <tools/resary.hxx>
31 #include <vcl/graph.hxx>
32 #include <sfx2/viewsh.hxx>
33 #include <svl/itemiter.hxx>
34 #include <svl/languageoptions.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <unotools/configitem.hxx>
37 #include "svx/htmlmode.hxx"
38 
39 #define _SVX_PAGE_CXX
40 
41 #include <cuires.hrc>
42 #include "page.hrc"
43 #include "helpid.hrc"
44 #include "page.hxx"
45 #include <svx/pageitem.hxx>
46 #include <editeng/brshitem.hxx>
47 #include <editeng/boxitem.hxx>
48 #include <editeng/shaditem.hxx>
49 #include <editeng/pbinitem.hxx>
50 #include <editeng/lrspitem.hxx>
51 #include <editeng/ulspitem.hxx>
52 #include <editeng/sizeitem.hxx>
53 #include <editeng/frmdiritem.hxx>
54 #include "svx/dlgutil.hxx"
55 #include <dialmgr.hxx>
56 #include <editeng/paperinf.hxx>
57 #include <dialmgr.hxx>
58 #include <sfx2/module.hxx>
59 #include <svl/stritem.hxx>
60 #include <svx/dialogs.hrc>  // for RID_SVXPAGE_PAGE
61 #include <editeng/eerdll.hxx>
62 #include <editeng/editrids.hrc> // for RID_SVXSTR_PAPERBIN...,
63 #include <svx/svxids.hrc>
64 
65 // #i4219#
66 #include <svtools/optionsdrawinglayer.hxx>
67 #include <svl/slstitm.hxx> //CHINA001
68 #include <svl/aeitem.hxx> //CHINA001
69 #include <sfx2/request.hxx> //CHINA001
70 // configuration helper =======================================================
71 
72 /** Helper to get a configuration setting.
73     @descr  This is a HACK to get a configuration item directly. Normally the
74     OfaHtmlOptions class from 'offmgr' project would do the job, but we cannot
75     use it here. On the other hand, the OfaHtmlOptions cannot be moved to
76     'svtools', because it uses 'svx' itself...
77     The correct way would be to move OfaHtmlOptions to 'svtools' anyway, and to
78     remove the dependency from 'svx' (a call to the static function
79     SvxTextEncodingBox::GetBestMimeEncoding(), which contains low level
80     operations that can be moved to lower projects, i.e. 'rtl'). Then this
81     class can be removed, and the OfaHtmlOptions can be used instead. */
82 class SvxHtmlExportModeConfigItem_Impl : public utl::ConfigItem
83 {
84 public:
85     explicit                    SvxHtmlExportModeConfigItem_Impl();
86 
87     /** Returns the HTML export mode, as read from the configuration. */
88     inline sal_Int32            GetExportMode() const { return mnExpMode; }
89 
90     /** Returns true, if the current HTML export mode is set to HTML 3.2. */
91     inline bool                 IsExportModeHTML32() const { return mnExpMode == 0; } // 0 == HTML_CFG_HTML32, see offmgr/htmlcfg.hxx
92 
93     virtual void    Commit();
94 	virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames);
95 
96 private:
97     sal_Int32                   mnExpMode;
98 };
99 
100 SvxHtmlExportModeConfigItem_Impl::SvxHtmlExportModeConfigItem_Impl() :
101     utl::ConfigItem( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/HTML/Export" ) ) ),
102     mnExpMode( 3 )  // default to 3 == HTML_CFG_NS40, see offmgr/htmlcfg.hxx
103 {
104     using com::sun::star::uno::Sequence;
105     using com::sun::star::uno::Any;
106 
107     Sequence< rtl::OUString > aPropNames( 1 );
108     aPropNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Browser" ) );
109     Sequence< Any > aPropValues( GetProperties( aPropNames ) );
110     if( aPropValues.getLength() == 1 )
111         aPropValues[ 0 ] >>= mnExpMode;
112 }
113 
114 void SvxHtmlExportModeConfigItem_Impl::Commit()
115 {
116 }
117 
118 void SvxHtmlExportModeConfigItem_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
119 {
120 }
121 
122 // static ----------------------------------------------------------------
123 
124 static const long MINBODY 		= 284;	// 0,5cm in twips aufgerundet
125 //static const long PRINT_OFFSET 	= 17;	// 0,03cm in twips abgerundet
126 static const long PRINT_OFFSET 	= 0;	// why was this ever set to 17 ? it led to wrong right and bottom margins.
127 
128 static sal_uInt16 pRanges[] =
129 {
130 	SID_ATTR_BORDER_OUTER,
131 	SID_ATTR_BORDER_SHADOW,
132 	SID_ATTR_LRSPACE,
133 	SID_ATTR_PAGE_SHARED,
134 	SID_SWREGISTER_COLLECTION,
135 	SID_SWREGISTER_MODE,
136 	0
137 };
138 
139 // ------- Mapping Seitenlayout ------------------------------------------
140 
141 sal_uInt16 aArr[] =
142 {
143 	SVX_PAGE_ALL,
144 	SVX_PAGE_MIRROR,
145 	SVX_PAGE_RIGHT,
146 	SVX_PAGE_LEFT
147 };
148 
149 // -----------------------------------------------------------------------
150 
151 sal_uInt16 PageUsageToPos_Impl( sal_uInt16 nUsage )
152 {
153 	const sal_uInt16 nCount = sizeof(aArr) / sizeof(sal_uInt16);
154 
155 	for ( sal_uInt16 i = 0; i < nCount; ++i )
156 		if ( aArr[i] == ( nUsage & 0x000f ) )
157 			return i;
158 	return SVX_PAGE_ALL;
159 }
160 
161 // -----------------------------------------------------------------------
162 
163 sal_uInt16 PosToPageUsage_Impl( sal_uInt16 nPos )
164 {
165 	const sal_uInt16 nCount = sizeof(aArr) / sizeof(sal_uInt16);
166 
167 	if ( nPos >= nCount )
168 		return 0;
169 	return aArr[nPos];
170 }
171 
172 // -----------------------------------------------------------------------
173 
174 Size GetMinBorderSpace_Impl( const SvxShadowItem& rShadow, const SvxBoxItem& rBox )
175 {
176 	Size aSz;
177 	aSz.Height() = rShadow.CalcShadowSpace( SHADOW_BOTTOM ) + rBox.CalcLineSpace( BOX_LINE_BOTTOM );
178 	aSz.Height() += rShadow.CalcShadowSpace( SHADOW_TOP ) + rBox.CalcLineSpace( BOX_LINE_TOP );
179 	aSz.Width() = rShadow.CalcShadowSpace( SHADOW_LEFT ) + rBox.CalcLineSpace( BOX_LINE_LEFT );
180 	aSz.Width() += rShadow.CalcShadowSpace( SHADOW_RIGHT ) + rBox.CalcLineSpace( BOX_LINE_RIGHT );
181 	return aSz;
182 }
183 
184 // -----------------------------------------------------------------------
185 
186 long ConvertLong_Impl( const long nIn, SfxMapUnit eUnit )
187 {
188 	return OutputDevice::LogicToLogic( nIn, (MapUnit)eUnit, MAP_TWIP );
189 }
190 
191 sal_Bool IsEqualSize_Impl( const SvxSizeItem* pSize, const Size& rSize )
192 {
193 	if ( pSize )
194 	{
195 		Size aSize = pSize->GetSize();
196 		long nDiffW = Abs( rSize.Width () - aSize.Width () );
197 		long nDiffH = Abs( rSize.Height() - aSize.Height() );
198 		return ( nDiffW < 10 && nDiffH < 10 );
199 	}
200 	else
201 		return sal_False;
202 }
203 
204 // -----------------------------------------------------------------------
205 
206 #define MARGIN_LEFT		( (MarginPosition)0x0001 )
207 #define MARGIN_RIGHT	( (MarginPosition)0x0002 )
208 #define MARGIN_TOP		( (MarginPosition)0x0004 )
209 #define MARGIN_BOTTOM	( (MarginPosition)0x0008 )
210 
211 struct SvxPage_Impl
212 {
213 	MarginPosition	m_nPos;
214     Printer*        mpDefPrinter;
215     bool            mbDelPrinter;
216 
217     SvxPage_Impl() :
218         m_nPos( 0 ),
219         mpDefPrinter( 0 ),
220         mbDelPrinter( false ) {}
221 
222     ~SvxPage_Impl() { if ( mbDelPrinter ) delete mpDefPrinter; }
223 };
224 
225 // class SvxPageDescPage --------------------------------------------------
226 
227 // gibt den Bereich der Which-Werte zur"uck
228 
229 sal_uInt16* SvxPageDescPage::GetRanges()
230 {
231 	return pRanges;
232 }
233 
234 // -----------------------------------------------------------------------
235 
236 SfxTabPage* SvxPageDescPage::Create( Window* pParent, const SfxItemSet& rSet )
237 {
238 	return new SvxPageDescPage( pParent, rSet );
239 }
240 
241 // -----------------------------------------------------------------------
242 
243 SvxPageDescPage::SvxPageDescPage( Window* pParent, const SfxItemSet& rAttr ) :
244 
245 	SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_PAGE ), rAttr ),
246 
247     aPaperSizeFl        ( this, CUI_RES( FL_PAPER_SIZE ) ),
248     aPaperFormatText    ( this, CUI_RES( FT_PAPER_FORMAT ) ),
249     aPaperSizeBox       ( this, CUI_RES( LB_PAPER_SIZE ) ),
250     aPaperWidthText     ( this, CUI_RES( FT_PAPER_WIDTH ) ),
251     aPaperWidthEdit     ( this, CUI_RES( ED_PAPER_WIDTH ) ),
252     aPaperHeightText    ( this, CUI_RES( FT_PAPER_HEIGHT ) ),
253     aPaperHeightEdit    ( this, CUI_RES( ED_PAPER_HEIGHT ) ),
254     aOrientationFT      ( this, CUI_RES( FT_ORIENTATION ) ),
255 	aPortraitBtn        ( this, CUI_RES( RB_PORTRAIT ) ),
256     aLandscapeBtn       ( this, CUI_RES( RB_LANDSCAPE ) ),
257 	aBspWin             ( this, CUI_RES( WN_BSP ) ),
258     aTextFlowLbl        ( this, CUI_RES( FT_TEXT_FLOW ) ),
259     aTextFlowBox        ( this, CUI_RES( LB_TEXT_FLOW ) ),
260 	aPaperTrayLbl       ( this, CUI_RES( FT_PAPER_TRAY ) ),
261     aPaperTrayBox       ( this, CUI_RES( LB_PAPER_TRAY ) ),
262 	aMarginFl           ( this, CUI_RES( FL_MARGIN ) ),
263     aLeftMarginLbl      ( this, CUI_RES( FT_LEFT_MARGIN ) ),
264 	aLeftMarginEdit		( this, CUI_RES( ED_LEFT_MARGIN ) ),
265 	aRightMarginLbl		( this, CUI_RES( FT_RIGHT_MARGIN ) ),
266 	aRightMarginEdit	( this, CUI_RES( ED_RIGHT_MARGIN ) ),
267 	aTopMarginLbl		( this, CUI_RES( FT_TOP_MARGIN ) ),
268 	aTopMarginEdit		( this, CUI_RES( ED_TOP_MARGIN ) ),
269 	aBottomMarginLbl	( this, CUI_RES( FT_BOTTOM_MARGIN ) ),
270 	aBottomMarginEdit	( this, CUI_RES( ED_BOTTOM_MARGIN ) ),
271     aBottomSeparatorFl  ( this, CUI_RES( FL_BOTTOM_SEP ) ),
272     aLayoutFL           ( this, CUI_RES( FL_LAYOUT ) ),
273 	aPageText			( this, CUI_RES( FT_PAGELAYOUT ) ),
274     aLayoutBox          ( this, CUI_RES( LB_LAYOUT ) ),
275 	aNumberFormatText	( this, CUI_RES( FT_NUMBER_FORMAT ) ),
276 	aNumberFormatBox	( this, CUI_RES( LB_NUMBER_FORMAT ) ),
277     aTblAlignFT         ( this, CUI_RES( FT_TBL_ALIGN ) ),
278     aHorzBox            ( this, CUI_RES( CB_HORZ ) ),
279 	aVertBox			( this, CUI_RES( CB_VERT ) ),
280 	aAdaptBox			( this, CUI_RES( CB_ADAPT ) ),
281 	aRegisterCB         ( this, CUI_RES( CB_REGISTER ) ),
282 	aRegisterFT         ( this, CUI_RES( FT_REGISTER ) ),
283 	aRegisterLB       	( this, CUI_RES( LB_REGISTER ) ),
284 
285 	aInsideText			( 		CUI_RES( STR_INSIDE ) ),
286 	aOutsideText		( 		CUI_RES( STR_OUTSIDE ) ),
287 	aPrintRangeQueryText(		CUI_RES( STR_QUERY_PRINTRANGE ) ),
288 
289 	bLandscape			( sal_False ),
290 	eMode				( SVX_PAGE_MODE_STANDARD ),
291 	ePaperStart			( PAPER_A3 ),
292 	ePaperEnd 			( PAPER_ENV_DL ),
293 	pImpl				( new SvxPage_Impl )
294 
295 {
296 	bBorderModified = sal_False;
297 	FreeResource();
298     aBspWin.EnableRTL( sal_False );
299 
300 	// diese Page braucht ExchangeSupport
301 	SetExchangeSupport();
302 
303     SvtLanguageOptions aLangOptions;
304     sal_Bool bCJK = aLangOptions.IsAsianTypographyEnabled();
305     sal_Bool bCTL = aLangOptions.IsCTLFontEnabled();
306     sal_Bool bWeb = sal_False;
307     const SfxPoolItem* pItem;
308 
309     SfxObjectShell* pShell;
310     if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
311 		( 0 != (pShell = SfxObjectShell::Current()) &&
312 					0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
313         bWeb = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
314 
315     // #109989# get the HTML export setting from configuration.
316     // !! This is a hack, see comments in SvxHtmlExportModeConfigItem_Impl class above.
317     bool bHTML32 = SvxHtmlExportModeConfigItem_Impl().IsExportModeHTML32();
318 
319     //  fill text flow listbox with valid entries
320     aTextFlowBox.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_HORI ), FRMDIR_HORI_LEFT_TOP );
321     if( bCTL )
322         aTextFlowBox.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_HORI ), FRMDIR_HORI_RIGHT_TOP );
323     // #109989# do not show vertical directions in Writer/Web
324     if( !bWeb )
325     {
326         if( bCJK )
327         {
328             aTextFlowBox.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_VERT ), FRMDIR_VERT_TOP_RIGHT );
329 //            aTextFlowBox.InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_VERT ), FRMDIR_VERT_TOP_LEFT );
330         }
331     }
332 
333     // #109989# show the text direction box in Writer/Web too, but only, if HTML export mode is not HTML3.2.
334     if( !(bWeb && bHTML32) && (bCJK || bCTL) &&
335         SFX_ITEM_UNKNOWN < rAttr.GetItemState(GetWhich( SID_ATTR_FRAMEDIRECTION )))
336     {
337         aTextFlowLbl.Show();
338         aTextFlowBox.Show();
339         aTextFlowBox.SetSelectHdl(LINK(this, SvxPageDescPage, FrameDirectionModify_Impl ));
340 
341         aBspWin.EnableFrameDirection(sal_True);
342     }
343     Init_Impl();
344 
345 	FieldUnit eFUnit = GetModuleFieldUnit( rAttr );
346 	SetFieldUnit( aLeftMarginEdit, eFUnit );
347 	SetFieldUnit( aRightMarginEdit, eFUnit );
348 	SetFieldUnit( aTopMarginEdit, eFUnit );
349 	SetFieldUnit( aBottomMarginEdit, eFUnit );
350 	SetFieldUnit( aPaperWidthEdit, eFUnit );
351 	SetFieldUnit( aPaperHeightEdit, eFUnit );
352 
353     if ( SfxViewShell::Current() && SfxViewShell::Current()->GetPrinter() )
354         pImpl->mpDefPrinter = (Printer*)SfxViewShell::Current()->GetPrinter();
355 	else
356 	{
357         pImpl->mpDefPrinter = new Printer;
358         pImpl->mbDelPrinter = true;
359 	}
360 
361     MapMode aOldMode = pImpl->mpDefPrinter->GetMapMode();
362     pImpl->mpDefPrinter->SetMapMode( MAP_TWIP );
363 
364 	// First- und Last-Werte f"ur die R"ander setzen
365     Size aPaperSize = pImpl->mpDefPrinter->GetPaperSize();
366     Size aPrintSize = pImpl->mpDefPrinter->GetOutputSize();
367 	/*
368 	 * einen Punkt ( 0,0 ) in logische Koordinaten zu konvertieren,
369 	 * sieht aus wie Unsinn; ist aber sinnvoll, wenn der Ursprung des
370 	 * Koordinatensystems verschoben ist.
371 	 */
372     Point aPrintOffset = pImpl->mpDefPrinter->GetPageOffset() -
373                          pImpl->mpDefPrinter->PixelToLogic( Point() );
374     pImpl->mpDefPrinter->SetMapMode( aOldMode );
375 
376     long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
377 	aLeftMarginEdit.SetFirst( aLeftMarginEdit.Normalize( aPrintOffset.X() ), FUNIT_TWIP );
378 	nFirstLeftMargin = static_cast<long>(aLeftMarginEdit.GetFirst());
379 	aRightMarginEdit.SetFirst( aRightMarginEdit.Normalize(
380 		aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset ), FUNIT_TWIP);
381 	nFirstRightMargin = static_cast<long>(aRightMarginEdit.GetFirst());
382 	aTopMarginEdit.SetFirst( aTopMarginEdit.Normalize( aPrintOffset.Y() ), FUNIT_TWIP );
383 	nFirstTopMargin = static_cast<long>(aTopMarginEdit.GetFirst());
384 	aBottomMarginEdit.SetFirst( aBottomMarginEdit.Normalize(
385 		aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset ), FUNIT_TWIP );
386 	nFirstBottomMargin = static_cast<long>(aBottomMarginEdit.GetFirst());
387 	aLeftMarginEdit.SetLast( aLeftMarginEdit.Normalize(
388 		aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
389 	nLastLeftMargin = static_cast<long>(aLeftMarginEdit.GetLast());
390 	aRightMarginEdit.SetLast( aRightMarginEdit.Normalize(
391 		aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
392 	nLastRightMargin = static_cast<long>(aRightMarginEdit.GetLast());
393 	aTopMarginEdit.SetLast( aTopMarginEdit.Normalize(
394 		aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
395 	nLastTopMargin = static_cast<long>(aTopMarginEdit.GetLast());
396 	aBottomMarginEdit.SetLast( aBottomMarginEdit.Normalize(
397 		aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
398 	nLastBottomMargin = static_cast<long>(aBottomMarginEdit.GetLast());
399 
400 	// #i4219# get DrawingLayer options
401     const SvtOptionsDrawinglayer aDrawinglayerOpt;
402 
403 	// #i4219# take Maximum now from configuration (1/100th cm)
404 	// was: 11900 -> 119 cm ;new value 3 meters -> 300 cm -> 30000
405 	aPaperWidthEdit.SetMax(aPaperWidthEdit.Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
406 	aPaperWidthEdit.SetLast(aPaperWidthEdit.Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
407 	aPaperHeightEdit.SetMax(aPaperHeightEdit.Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
408 	aPaperHeightEdit.SetLast(aPaperHeightEdit.Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
409 
410 	// #i4219# also for margins (1/100th cm). Was: 9999, keeping.
411 	aLeftMarginEdit.SetMax(aDrawinglayerOpt.GetMaximumPaperLeftMargin());
412 	aLeftMarginEdit.SetLast(aDrawinglayerOpt.GetMaximumPaperLeftMargin());
413 	aRightMarginEdit.SetMax(aDrawinglayerOpt.GetMaximumPaperRightMargin());
414 	aRightMarginEdit.SetLast(aDrawinglayerOpt.GetMaximumPaperRightMargin());
415 	aTopMarginEdit.SetMax(aDrawinglayerOpt.GetMaximumPaperTopMargin());
416 	aTopMarginEdit.SetLast(aDrawinglayerOpt.GetMaximumPaperTopMargin());
417 	aBottomMarginEdit.SetMax(aDrawinglayerOpt.GetMaximumPaperBottomMargin());
418 	aBottomMarginEdit.SetLast(aDrawinglayerOpt.GetMaximumPaperBottomMargin());
419 
420 	aPortraitBtn.SetAccessibleRelationMemberOf(&aOrientationFT);
421 	aLandscapeBtn.SetAccessibleRelationMemberOf(&aOrientationFT);
422 }
423 
424 // -----------------------------------------------------------------------
425 
426 SvxPageDescPage::~SvxPageDescPage()
427 {
428 	delete pImpl;
429 }
430 
431 // -----------------------------------------------------------------------
432 
433 void SvxPageDescPage::Init_Impl()
434 {
435 	aLeftText = aLeftMarginLbl.GetText();
436 	aRightText = aRightMarginLbl.GetText();
437 
438 		// Handler einstellen
439 	aLayoutBox.SetSelectHdl( LINK( this, SvxPageDescPage, LayoutHdl_Impl ) );
440     aPaperSizeBox.SetDropDownLineCount(10);
441 
442 	aPaperTrayBox.SetGetFocusHdl(
443 		LINK( this, SvxPageDescPage, PaperBinHdl_Impl ) );
444 	aPaperSizeBox.SetSelectHdl(
445 		LINK( this, SvxPageDescPage, PaperSizeSelect_Impl ) );
446 	aPaperWidthEdit.SetModifyHdl(
447 		LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
448 	aPaperHeightEdit.SetModifyHdl(
449 		LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
450 	aLandscapeBtn.SetClickHdl(
451 		LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
452 	aPortraitBtn.SetClickHdl(
453 		LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
454 
455 	Link aLink = LINK( this, SvxPageDescPage, BorderModify_Impl );
456 	aLeftMarginEdit.SetModifyHdl( aLink );
457 	aRightMarginEdit.SetModifyHdl( aLink );
458 	aTopMarginEdit.SetModifyHdl( aLink );
459 	aBottomMarginEdit.SetModifyHdl( aLink );
460 
461 	aLink = LINK( this, SvxPageDescPage, RangeHdl_Impl );
462 	aPaperWidthEdit.SetLoseFocusHdl( aLink );
463 	aPaperHeightEdit.SetLoseFocusHdl( aLink );
464 	aLeftMarginEdit.SetLoseFocusHdl( aLink );
465 	aRightMarginEdit.SetLoseFocusHdl( aLink );
466 	aTopMarginEdit.SetLoseFocusHdl( aLink );
467 	aBottomMarginEdit.SetLoseFocusHdl( aLink );
468 
469 	aHorzBox.SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
470 	aVertBox.SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
471 
472 }
473 
474 // -----------------------------------------------------------------------
475 
476 void SvxPageDescPage::Reset( const SfxItemSet& rSet )
477 {
478 	SfxItemPool* pPool = rSet.GetPool();
479 	DBG_ASSERT( pPool, "Wo ist der Pool" );
480 	SfxMapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_LRSPACE ) );
481 
482 	// R"ander (Links/Rechts) einstellen
483 	const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE );
484 
485 	if ( pItem )
486 	{
487 		const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)*pItem;
488 		SetMetricValue( aLeftMarginEdit, rLRSpace.GetLeft(), eUnit );
489 		aBspWin.SetLeft(
490 			(sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetLeft(), eUnit ) );
491 		SetMetricValue( aRightMarginEdit, rLRSpace.GetRight(), eUnit );
492 		aBspWin.SetRight(
493 			(sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetRight(), eUnit ) );
494 	}
495 
496 	// R"ander (Oben/Unten) einstellen
497 	pItem = GetItem( rSet, SID_ATTR_ULSPACE );
498 
499 	if ( pItem )
500 	{
501 		const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)*pItem;
502 		SetMetricValue( aTopMarginEdit, rULSpace.GetUpper(), eUnit );
503 		aBspWin.SetTop(
504 			(sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetUpper(), eUnit ) );
505 		SetMetricValue( aBottomMarginEdit, rULSpace.GetLower(), eUnit );
506 		aBspWin.SetBottom(
507 			(sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetLower(), eUnit ) );
508 	}
509 
510     // allgemeine Seitendaten
511 	SvxNumType eNumType = SVX_ARABIC;
512     bLandscape = ( pImpl->mpDefPrinter->GetOrientation() == ORIENTATION_LANDSCAPE );
513 	sal_uInt16 nUse = (sal_uInt16)SVX_PAGE_ALL;
514 	pItem = GetItem( rSet, SID_ATTR_PAGE );
515 
516 	if ( pItem )
517 	{
518 		const SvxPageItem& rItem = (const SvxPageItem&)*pItem;
519 		eNumType = rItem.GetNumType();
520 		nUse = rItem.GetPageUsage();
521 		bLandscape = rItem.IsLandscape();
522 	}
523 
524 	// Ausrichtung
525 	aLayoutBox.SelectEntryPos( ::PageUsageToPos_Impl( nUse ) );
526 	aBspWin.SetUsage( nUse );
527 	LayoutHdl_Impl( 0 );
528 
529 	// Numerierungsart der Seitenvorlage einstellen
530 	aNumberFormatBox.SelectEntryPos( sal::static_int_cast< sal_uInt16 >(eNumType) );
531 
532 	// Aktueller Papierschacht
533 	aPaperTrayBox.Clear();
534 	sal_uInt8 nPaperBin = PAPERBIN_PRINTER_SETTINGS;
535 	pItem = GetItem( rSet, SID_ATTR_PAGE_PAPERBIN );
536 
537 	if ( pItem )
538 	{
539 		nPaperBin = ( (const SvxPaperBinItem*)pItem )->GetValue();
540 
541         if ( nPaperBin >= pImpl->mpDefPrinter->GetPaperBinCount() )
542 			nPaperBin = PAPERBIN_PRINTER_SETTINGS;
543 	}
544 
545 	String aBinName;
546 
547 	if ( PAPERBIN_PRINTER_SETTINGS	== nPaperBin )
548 		aBinName = EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS );
549 	else
550         aBinName = pImpl->mpDefPrinter->GetPaperBinName( (sal_uInt16)nPaperBin );
551 
552 	sal_uInt16 nEntryPos = aPaperTrayBox.InsertEntry( aBinName );
553 	aPaperTrayBox.SetEntryData( nEntryPos, (void*)(sal_uLong)nPaperBin );
554 	aPaperTrayBox.SelectEntry( aBinName );
555 
556 	// Size rausholen
557     Size aPaperSize = SvxPaperInfo::GetPaperSize( pImpl->mpDefPrinter );
558 	pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
559 
560 	if ( pItem )
561 		aPaperSize = ( (const SvxSizeItem*)pItem )->GetSize();
562 
563 	FASTBOOL bOrientationSupport =
564         pImpl->mpDefPrinter->HasSupport( SUPPORT_SET_ORIENTATION );
565 #ifdef OS2
566 	// unter OS/2 wird bei HasSupport() immer sal_True returned
567 	// aber nur als Dummy, deshalb FALSE
568 	bOrientationSupport = sal_False;
569 #endif
570 
571 	if ( !bOrientationSupport &&
572 		 aPaperSize.Width() > aPaperSize.Height() )
573 		bLandscape = sal_True;
574 
575 	aLandscapeBtn.Check( bLandscape );
576 	aPortraitBtn.Check( !bLandscape );
577 
578 	aBspWin.SetSize( Size( ConvertLong_Impl( aPaperSize.Width(), eUnit ),
579 						   ConvertLong_Impl( aPaperSize.Height(), eUnit ) ) );
580 
581 	aPaperSize = OutputDevice::LogicToLogic(aPaperSize, (MapUnit)eUnit, MAP_100TH_MM);
582 	if ( bLandscape )
583 		Swap( aPaperSize );
584 
585 	// Actual Paper Format
586 	Paper ePaper = SvxPaperInfo::GetSvxPaper( aPaperSize, MAP_100TH_MM, sal_True );
587 
588 	if ( PAPER_USER != ePaper )
589 		aPaperSize = SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM );
590 
591 	if ( bLandscape )
592 		Swap( aPaperSize );
593 
594 	// Werte in die Edits eintragen
595 	SetMetricValue( aPaperHeightEdit, aPaperSize.Height(), SFX_MAPUNIT_100TH_MM );
596 	SetMetricValue( aPaperWidthEdit, aPaperSize.Width(), SFX_MAPUNIT_100TH_MM );
597 	aPaperSizeBox.Clear();
598 
599 	sal_uInt16 nActPos = LISTBOX_ENTRY_NOTFOUND;
600 	sal_uInt16 nAryId = RID_SVXSTRARY_PAPERSIZE_STD;
601 
602 	if ( ePaperStart != PAPER_A3 )
603 		nAryId = RID_SVXSTRARY_PAPERSIZE_DRAW;
604 	ResStringArray aPaperAry( CUI_RES( nAryId ) );
605 	sal_uInt32 nCnt = aPaperAry.Count();
606 
607     sal_uInt16 nUserPos = LISTBOX_ENTRY_NOTFOUND;
608 	for ( sal_uInt32 i = 0; i < nCnt; ++i )
609 	{
610 		String aStr = aPaperAry.GetString(i);
611 		Paper eSize = (Paper)aPaperAry.GetValue(i);
612 		sal_uInt16 nPos = aPaperSizeBox.InsertEntry( aStr );
613 		aPaperSizeBox.SetEntryData( nPos, (void*)(sal_uLong)eSize );
614 
615 		if ( eSize == ePaper )
616 			nActPos = nPos;
617         if( eSize == PAPER_USER )
618             nUserPos = nPos;
619 	}
620 	// preselect current paper format - #115915#: ePaper might not be in aPaperSizeBox so use PAPER_USER instead
621     aPaperSizeBox.SelectEntryPos( nActPos != LISTBOX_ENTRY_NOTFOUND ? nActPos : nUserPos );
622 
623     // Applikationsspezifisch
624 
625 	switch ( eMode )
626 	{
627 		case SVX_PAGE_MODE_CENTER:
628 		{
629             aTblAlignFT.Show();
630             aHorzBox.Show();
631 			aVertBox.Show();
632             DisableVerticalPageDir();
633 
634 			// Horizontale Ausrichtung
635 			pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
636 			aHorzBox.Check( pItem ? ( (const SfxBoolItem*)pItem )->GetValue()
637 								  : sal_False );
638 
639 			// Vertikale Ausrichtung
640 			pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
641 			aVertBox.Check( pItem ? ( (const SfxBoolItem*)pItem )->GetValue()
642 								  : sal_False );
643 
644 			// Beispiel-Fenster auf Tabelle setzen
645 			aBspWin.SetTable( sal_True );
646 			aBspWin.SetHorz( aHorzBox.IsChecked() );
647 			aBspWin.SetVert( aVertBox.IsChecked() );
648 
649 			break;
650 		}
651 
652 		case SVX_PAGE_MODE_PRESENTATION:
653 		{
654             DisableVerticalPageDir();
655 			aAdaptBox.Show();
656 			pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
657 			aAdaptBox.Check( pItem ?
658 				( (const SfxBoolItem*)pItem )->GetValue() : sal_False );
659 
660 			//!!! hidden, weil von StarDraw nicht implementiert
661 			aLayoutBox.Hide();
662 			aPageText.Hide();
663 
664 			break;
665 		}
666         default: ;//prevent warning
667 	}
668 
669 
670 	// im Beispiel Hintergrund und Umrandung anzeigen
671 	ResetBackground_Impl( rSet );
672 //!	UpdateExample_Impl();
673 	RangeHdl_Impl( 0 );
674 
675 	// Header Footer anzeigen
676 	InitHeadFoot_Impl( rSet );
677 
678 	// R"ander auf Hoch/Quer updaten, dann Beispiel updaten
679 	bBorderModified = sal_False;
680 	SwapFirstValues_Impl( sal_False );
681 	UpdateExample_Impl();
682 
683 	// Alte Werte sichern
684 	aLeftMarginEdit.SaveValue();
685 	aRightMarginEdit.SaveValue();
686 	aTopMarginEdit.SaveValue();
687 	aBottomMarginEdit.SaveValue();
688 	aLayoutBox.SaveValue();
689 	aNumberFormatBox.SaveValue();
690 	aPaperSizeBox.SaveValue();
691 	aPaperWidthEdit.SaveValue();
692 	aPaperHeightEdit.SaveValue();
693 	aPortraitBtn.SaveValue();
694 	aLandscapeBtn.SaveValue();
695 	aPaperTrayBox.SaveValue();
696 	aVertBox.SaveValue();
697 	aHorzBox.SaveValue();
698     aAdaptBox.SaveValue();
699 
700 	CheckMarginEdits( true );
701 
702 	// Registerhaltigkeit
703 	if(SFX_ITEM_SET == rSet.GetItemState(SID_SWREGISTER_MODE))
704 	{
705 		aRegisterCB.Check(((const SfxBoolItem&)rSet.Get(
706 								SID_SWREGISTER_MODE)).GetValue());
707 		aRegisterCB.SaveValue();
708 		RegisterModify(&aRegisterCB);
709 	}
710 	if(SFX_ITEM_SET == rSet.GetItemState(SID_SWREGISTER_COLLECTION))
711 	{
712 		aRegisterLB.SelectEntry(
713 				((const SfxStringItem&)rSet.Get(SID_SWREGISTER_COLLECTION)).GetValue());
714 		aRegisterLB.SaveValue();
715 	}
716 
717 	SfxItemState eState = rSet.GetItemState( GetWhich( SID_ATTR_FRAMEDIRECTION ),
718 												sal_True, &pItem );
719 	if( SFX_ITEM_UNKNOWN != eState )
720 	{
721         sal_uInt32 nVal  = SFX_ITEM_SET == eState
722 								? ((SvxFrameDirectionItem*)pItem)->GetValue()
723                                 : 0;
724         aTextFlowBox.SelectEntryValue( static_cast< SvxFrameDirection >( nVal ) );
725 		aTextFlowBox.SaveValue();
726         aBspWin.SetFrameDirection(nVal);
727 	}
728 }
729 
730 // -----------------------------------------------------------------------
731 
732 void SvxPageDescPage::FillUserData()
733 {
734 	if ( SVX_PAGE_MODE_PRESENTATION == eMode )
735 		SetUserData( UniString::CreateFromInt32( (sal_Int32)aAdaptBox.IsChecked() ) );
736 }
737 
738 // -----------------------------------------------------------------------
739 
740 sal_Bool SvxPageDescPage::FillItemSet( SfxItemSet& rSet )
741 {
742 	sal_Bool bModified = sal_False;
743 	const SfxItemSet& rOldSet = GetItemSet();
744 	SfxItemPool* pPool = rOldSet.GetPool();
745 	DBG_ASSERT( pPool, "Wo ist der Pool" );
746 	sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
747 	SfxMapUnit eUnit = pPool->GetMetric( nWhich );
748 	const SfxPoolItem* pOld = 0;
749 
750 	// alten linken und rechten Rand kopieren
751 	SvxLRSpaceItem aMargin( (const SvxLRSpaceItem&)rOldSet.Get( nWhich ) );
752 
753 	// alten  oberen und unteren Rand kopieren
754 	nWhich = GetWhich( SID_ATTR_ULSPACE );
755 	SvxULSpaceItem aTopMargin( (const SvxULSpaceItem&)rOldSet.Get( nWhich ) );
756 
757 	if ( aLeftMarginEdit.GetText() != aLeftMarginEdit.GetSavedValue() )
758 	{
759 		aMargin.SetLeft( (sal_uInt16)GetCoreValue( aLeftMarginEdit, eUnit ) );
760 		bModified |= sal_True;
761 	}
762 
763 	if ( aRightMarginEdit.GetText() != aRightMarginEdit.GetSavedValue() )
764 	{
765 		aMargin.SetRight( (sal_uInt16)GetCoreValue( aRightMarginEdit, eUnit ) );
766 		bModified |= sal_True;
767 	}
768 
769 	// Linken und rechten Rand setzen
770 	if ( bModified )
771 	{
772 		pOld = GetOldItem( rSet, SID_ATTR_LRSPACE );
773 
774 		if ( !pOld || !( *(const SvxLRSpaceItem*)pOld == aMargin ) )
775 			rSet.Put( aMargin );
776 		else
777 			bModified = sal_False;
778 	}
779 
780 	sal_Bool bMod = sal_False;
781 
782 	if ( aTopMarginEdit.GetText() != aTopMarginEdit.GetSavedValue() )
783 	{
784 		aTopMargin.SetUpper( (sal_uInt16)GetCoreValue( aTopMarginEdit, eUnit ) );
785 		bMod |= sal_True;
786 	}
787 
788 	if ( aBottomMarginEdit.GetText() != aBottomMarginEdit.GetSavedValue() )
789 	{
790 		aTopMargin.SetLower( (sal_uInt16)GetCoreValue( aBottomMarginEdit, eUnit ) );
791 		bMod |= sal_True;
792 	}
793 
794 	// unteren oberen Rand setzen
795 	//
796 	if ( bMod )
797 	{
798 		pOld = GetOldItem( rSet, SID_ATTR_ULSPACE );
799 
800 		if ( !pOld || !( *(const SvxULSpaceItem*)pOld == aTopMargin ) )
801 		{
802 			bModified |= sal_True;
803 			rSet.Put( aTopMargin );
804 		}
805 	}
806 
807 	// Druckerschacht
808 	nWhich = GetWhich( SID_ATTR_PAGE_PAPERBIN );
809 	sal_uInt16 nPos = aPaperTrayBox.GetSelectEntryPos();
810 	sal_uInt16 nBin = (sal_uInt16)(sal_uLong)aPaperTrayBox.GetEntryData( nPos );
811 	pOld = GetOldItem( rSet, SID_ATTR_PAGE_PAPERBIN );
812 
813 	if ( !pOld || ( (const SvxPaperBinItem*)pOld )->GetValue() != nBin )
814 	{
815 		rSet.Put( SvxPaperBinItem( nWhich, (sal_uInt8)nBin ) );
816 		bModified |= sal_True;
817 	}
818 
819 	nPos = aPaperSizeBox.GetSelectEntryPos();
820 	Paper ePaper = (Paper)(sal_uLong)aPaperSizeBox.GetEntryData( nPos );
821 	const sal_uInt16 nOld = aPaperSizeBox.GetSavedValue();
822 	sal_Bool bChecked = aLandscapeBtn.IsChecked();
823 
824 	if ( PAPER_USER == ePaper )
825 	{
826 		if ( nOld != nPos						||
827 			 aPaperWidthEdit.IsValueModified()  ||
828 			 aPaperHeightEdit.IsValueModified() ||
829 			 bChecked != aLandscapeBtn.GetSavedValue() )
830 		{
831 			Size aSize( GetCoreValue( aPaperWidthEdit, eUnit ),
832 						GetCoreValue( aPaperHeightEdit, eUnit ) );
833 			pOld = GetOldItem( rSet, SID_ATTR_PAGE_SIZE );
834 
835 			if ( !pOld || ( (const SvxSizeItem*)pOld )->GetSize() != aSize )
836 			{
837 				rSet.Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
838 				bModified |= sal_True;
839 			}
840 		}
841 	}
842 	else
843 	{
844 		if ( nOld != nPos || bChecked != aLandscapeBtn.GetSavedValue() )
845 		{
846 			Size aSize( SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)eUnit ) );
847 
848 			if ( bChecked )
849 				Swap( aSize );
850 
851 			pOld = GetOldItem( rSet, SID_ATTR_PAGE_SIZE );
852 
853 			if ( !pOld || ( (const SvxSizeItem*)pOld )->GetSize() != aSize )
854 			{
855 				rSet.Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
856 				bModified |= sal_True;
857 			}
858 		}
859 	}
860 
861 	// sonstiges Zeug der Page
862 	nWhich = GetWhich( SID_ATTR_PAGE );
863 	SvxPageItem aPage( (const SvxPageItem&)rOldSet.Get( nWhich ) );
864 	bMod = 	aLayoutBox.GetSelectEntryPos()  != aLayoutBox.GetSavedValue();
865 
866 	if ( bMod )
867 		aPage.SetPageUsage(
868 			::PosToPageUsage_Impl( aLayoutBox.GetSelectEntryPos() ) );
869 
870 	if ( bChecked != aLandscapeBtn.GetSavedValue() )
871 	{
872 		aPage.SetLandscape(bChecked);
873 		bMod |= sal_True;
874 	}
875 
876 	// Einstellen der Numerierungsart der Seite
877 	nPos = aNumberFormatBox.GetSelectEntryPos();
878 
879 	if ( nPos != aNumberFormatBox.GetSavedValue() )
880 	{
881 		aPage.SetNumType( (SvxNumType)nPos );
882 		bMod |= sal_True;
883 	}
884 
885 	if ( bMod )
886 	{
887 		pOld = GetOldItem( rSet, SID_ATTR_PAGE );
888 
889 		if ( !pOld || !( *(const SvxPageItem*)pOld == aPage ) )
890 		{
891 			rSet.Put( aPage );
892 			bModified |= sal_True;
893 		}
894 	}
895 	else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich ) )
896 		rSet.ClearItem( nWhich );
897 	else
898 		rSet.Put( rOldSet.Get( nWhich ) );
899 
900 	// Modispezifische Controls auswerten
901 
902 	switch ( eMode )
903 	{
904 		case SVX_PAGE_MODE_CENTER:
905 		{
906 			if ( aHorzBox.IsChecked() != aHorzBox.GetSavedValue() )
907 			{
908 				SfxBoolItem aHorz( GetWhich( SID_ATTR_PAGE_EXT1 ),
909 								   aHorzBox.IsChecked() );
910 				rSet.Put( aHorz );
911 				bModified |= sal_True;
912 			}
913 
914 			if ( aVertBox.IsChecked() != aVertBox.GetSavedValue() )
915 			{
916 				SfxBoolItem aVert( GetWhich( SID_ATTR_PAGE_EXT2 ),
917 								   aVertBox.IsChecked() );
918 				rSet.Put( aVert );
919 				bModified |= sal_True;
920 			}
921 			break;
922 		}
923 
924 		case SVX_PAGE_MODE_PRESENTATION:
925 		{
926 			// immer putten, damit Draw das auswerten kann
927 			rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_PAGE_EXT1 ),
928 					  aAdaptBox.IsChecked() ) );
929 			bModified |= sal_True;
930 			break;
931 		}
932         default: ;//prevent warning
933 
934 	}
935 
936 	if(aRegisterCB.IsVisible() &&
937 		(aRegisterCB.IsChecked() || aRegisterCB.GetSavedValue() != aRegisterCB.IsChecked()))
938 	{
939 		const SfxBoolItem& rRegItem = (const SfxBoolItem&)rOldSet.Get(SID_SWREGISTER_MODE);
940 		SfxBoolItem* pRegItem = (SfxBoolItem*)rRegItem.Clone();
941 		sal_Bool bCheck = aRegisterCB.IsChecked();
942 		pRegItem->SetValue(bCheck);
943 		rSet.Put(*pRegItem);
944 		bModified |= sal_True;
945 		if(bCheck)
946 		{
947 			bModified |= sal_True;
948 			rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION,
949 							aRegisterLB.GetSelectEntry()));
950 		}
951 		delete pRegItem;
952 	}
953 
954     SvxFrameDirection eDirection = aTextFlowBox.GetSelectEntryValue();
955     if( aTextFlowBox.IsVisible() && (eDirection != aTextFlowBox.GetSavedValue()) )
956 	{
957         rSet.Put( SvxFrameDirectionItem( eDirection, GetWhich( SID_ATTR_FRAMEDIRECTION ) ) );
958 		bModified = sal_True;
959 	}
960 
961 	return bModified;
962 }
963 
964 // -----------------------------------------------------------------------
965 
966 IMPL_LINK( SvxPageDescPage, LayoutHdl_Impl, ListBox *, EMPTYARG )
967 {
968 	// innen au\sen umschalten
969 	const sal_uInt16 nPos = PosToPageUsage_Impl( aLayoutBox.GetSelectEntryPos() );
970 
971 	if ( nPos == SVX_PAGE_MIRROR )
972 	{
973 		if ( aLeftMarginLbl.GetText() != aInsideText )
974 			aLeftMarginLbl.SetText( aInsideText );
975 
976 		if ( aRightMarginLbl.GetText() != aOutsideText )
977 			aRightMarginLbl.SetText( aOutsideText );
978 	}
979 	else
980 	{
981 		if ( aLeftMarginLbl.GetText() != aLeftText )
982 			aLeftMarginLbl.SetText( aLeftText );
983 
984 		if ( aRightMarginLbl.GetText() != aRightText )
985 			aRightMarginLbl.SetText( aRightText );
986 	}
987     UpdateExample_Impl( true );
988 	return 0;
989 }
990 
991 // -----------------------------------------------------------------------
992 
993 IMPL_LINK( SvxPageDescPage, PaperBinHdl_Impl, ListBox *, EMPTYARG )
994 {
995 	if ( aPaperTrayBox.GetEntryCount() > 1 )
996 		// schon gef"ullt
997 		return 0;
998 
999 	// Schacht-Box initialisieren
1000 	String aOldName = aPaperTrayBox.GetSelectEntry();
1001 	aPaperTrayBox.SetUpdateMode( sal_False );
1002 	aPaperTrayBox.Clear();
1003 	sal_uInt16 nEntryPos = aPaperTrayBox.InsertEntry(
1004 		EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS ) );
1005 	aPaperTrayBox.SetEntryData( nEntryPos,
1006 		(void*)(sal_uLong)PAPERBIN_PRINTER_SETTINGS );
1007 	String aPaperBin( EditResId( RID_SVXSTR_PAPERBIN ) );
1008     sal_uInt16 nBinCount = pImpl->mpDefPrinter->GetPaperBinCount();
1009 
1010 	for ( sal_uInt16 i = 0; i < nBinCount; ++i )
1011 	{
1012         String aName = pImpl->mpDefPrinter->GetPaperBinName(i);
1013 
1014 		if ( !aName.Len() )
1015 		{
1016 			aName = aPaperBin;
1017 			aName.Append( sal_Unicode(' ') );
1018 			aName.Append( UniString::CreateFromInt32( i+1 ) );
1019 		}
1020 		nEntryPos = aPaperTrayBox.InsertEntry( aName );
1021 		aPaperTrayBox.SetEntryData( nEntryPos, (void*)(sal_uLong)i );
1022 	}
1023 	aPaperTrayBox.SelectEntry( aOldName );
1024 	aPaperTrayBox.SetUpdateMode( sal_True );
1025 
1026     return 0;
1027 }
1028 
1029 // -----------------------------------------------------------------------
1030 
1031 IMPL_LINK( SvxPageDescPage, PaperSizeSelect_Impl, ListBox *, pBox )
1032 {
1033 	const sal_uInt16 nPos = pBox->GetSelectEntryPos();
1034 	Paper ePaper = (Paper)(sal_uLong)aPaperSizeBox.GetEntryData( nPos );
1035 
1036 	if ( ePaper != PAPER_USER )
1037 	{
1038 		Size aSize( SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM ) );
1039 
1040 		if ( aLandscapeBtn.IsChecked() )
1041 			Swap( aSize );
1042 
1043 		if ( aSize.Height() < aPaperHeightEdit.GetMin( FUNIT_100TH_MM ) )
1044 			aPaperHeightEdit.SetMin(
1045 				aPaperHeightEdit.Normalize( aSize.Height() ), FUNIT_100TH_MM );
1046 		if ( aSize.Width() < aPaperWidthEdit.GetMin( FUNIT_100TH_MM ) )
1047 			aPaperWidthEdit.SetMin(
1048 				aPaperWidthEdit.Normalize( aSize.Width() ), FUNIT_100TH_MM );
1049 		SetMetricValue( aPaperHeightEdit, aSize.Height(), SFX_MAPUNIT_100TH_MM );
1050 		SetMetricValue( aPaperWidthEdit, aSize.Width(), SFX_MAPUNIT_100TH_MM );
1051 
1052 		// R"ander ggf. neu berechnen
1053 		CalcMargin_Impl();
1054 
1055 		RangeHdl_Impl( 0 );
1056 		UpdateExample_Impl( true );
1057 
1058 		if ( eMode == SVX_PAGE_MODE_PRESENTATION )
1059 		{
1060 			// Draw: bei Papierformat soll der Rand 1cm betragen
1061 			long nTmp = 0;
1062 			sal_Bool bScreen = ( PAPER_SCREEN == ePaper );
1063 
1064 			if ( !bScreen )
1065 				// bei Bildschirm keinen Rand
1066 				nTmp = 1; // entspr. 1cm
1067 
1068 			// Abfragen, ob fuer Raender 0 gesetzt ist:
1069 			if ( bScreen || aRightMarginEdit.GetValue() == 0 )
1070 			{
1071 				SetMetricValue( aRightMarginEdit, nTmp, SFX_MAPUNIT_CM );
1072 				if ( !bScreen &&
1073 					 aRightMarginEdit.GetFirst() > aRightMarginEdit.GetValue() )
1074 					aRightMarginEdit.SetValue( aRightMarginEdit.GetFirst() );
1075 			}
1076 			if ( bScreen || aLeftMarginEdit.GetValue() == 0 )
1077 			{
1078 				SetMetricValue( aLeftMarginEdit, nTmp, SFX_MAPUNIT_CM );
1079 				if ( !bScreen &&
1080 					 aLeftMarginEdit.GetFirst() > aLeftMarginEdit.GetValue() )
1081 					aLeftMarginEdit.SetValue( aLeftMarginEdit.GetFirst() );
1082 			}
1083 			if ( bScreen || aBottomMarginEdit.GetValue() == 0 )
1084 			{
1085 				SetMetricValue( aBottomMarginEdit, nTmp, SFX_MAPUNIT_CM );
1086 				if ( !bScreen &&
1087 					 aBottomMarginEdit.GetFirst() > aBottomMarginEdit.GetValue() )
1088 					aBottomMarginEdit.SetValue( aBottomMarginEdit.GetFirst() );
1089 			}
1090 			if ( bScreen || aTopMarginEdit.GetValue() == 0 )
1091 			{
1092 				SetMetricValue( aTopMarginEdit, nTmp, SFX_MAPUNIT_CM );
1093 				if ( !bScreen &&
1094 					 aTopMarginEdit.GetFirst() > aTopMarginEdit.GetValue() )
1095 					aTopMarginEdit.SetValue( aTopMarginEdit.GetFirst() );
1096 			}
1097 			UpdateExample_Impl( true );
1098 		}
1099 	}
1100 	return 0;
1101 }
1102 
1103 // -----------------------------------------------------------------------
1104 
1105 IMPL_LINK( SvxPageDescPage, PaperSizeModify_Impl, Edit *, EMPTYARG )
1106 {
1107 	sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
1108 	SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
1109 	Size aSize( GetCoreValue( aPaperWidthEdit, eUnit ),
1110 				GetCoreValue( aPaperHeightEdit, eUnit ) );
1111 	Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, (MapUnit)eUnit, sal_True );
1112 	sal_uInt16 nEntryCount = aPaperSizeBox.GetEntryCount();
1113 
1114 	for ( sal_uInt16 i = 0; i < nEntryCount; ++i )
1115 	{
1116 		Paper eTmp = (Paper)(sal_uLong)aPaperSizeBox.GetEntryData(i);
1117 
1118 		if ( eTmp == ePaper )
1119 		{
1120 			aPaperSizeBox.SelectEntryPos(i);
1121 			break;
1122 		}
1123 	}
1124 	UpdateExample_Impl( true );
1125 	return 0;
1126 }
1127 
1128 // -----------------------------------------------------------------------
1129 
1130 IMPL_LINK( SvxPageDescPage, SwapOrientation_Impl, RadioButton *, pBtn )
1131 {
1132 	if (
1133         (!bLandscape && pBtn == &aLandscapeBtn) ||
1134 		(bLandscape  && pBtn == &aPortraitBtn)
1135        )
1136 	{
1137 		bLandscape = aLandscapeBtn.IsChecked();
1138 
1139 		const long lWidth = GetCoreValue( aPaperWidthEdit, SFX_MAPUNIT_100TH_MM );
1140 		const long lHeight = GetCoreValue( aPaperHeightEdit, SFX_MAPUNIT_100TH_MM );
1141 
1142         // swap with and height
1143 		SetMetricValue( aPaperWidthEdit, lHeight, SFX_MAPUNIT_100TH_MM );
1144 		SetMetricValue( aPaperHeightEdit, lWidth, SFX_MAPUNIT_100TH_MM );
1145 
1146         // recalculate margins if necessary
1147 		CalcMargin_Impl();
1148 
1149 		PaperSizeSelect_Impl( &aPaperSizeBox );
1150 		RangeHdl_Impl( 0 );
1151 		SwapFirstValues_Impl( bBorderModified );
1152         UpdateExample_Impl( true );
1153 	}
1154 	return 0;
1155 }
1156 
1157 // -----------------------------------------------------------------------
1158 
1159 void SvxPageDescPage::SwapFirstValues_Impl( FASTBOOL bSet )
1160 {
1161     MapMode aOldMode = pImpl->mpDefPrinter->GetMapMode();
1162 	Orientation	eOri = ORIENTATION_PORTRAIT;
1163 
1164 	if ( bLandscape )
1165 		eOri = ORIENTATION_LANDSCAPE;
1166     Orientation eOldOri = pImpl->mpDefPrinter->GetOrientation();
1167     pImpl->mpDefPrinter->SetOrientation( eOri );
1168     pImpl->mpDefPrinter->SetMapMode( MAP_TWIP );
1169 
1170 	// First- und Last-Werte f"ur die R"ander setzen
1171     Size aPaperSize = pImpl->mpDefPrinter->GetPaperSize();
1172     Size aPrintSize = pImpl->mpDefPrinter->GetOutputSize();
1173 	/*
1174 	 * einen Punkt ( 0,0 ) in logische Koordinaten zu konvertieren,
1175 	 * sieht aus wie Unsinn; ist aber sinnvoll, wenn der Ursprung des
1176 	 * Koordinatensystems verschoben ist.
1177 	 */
1178     Point aPrintOffset = pImpl->mpDefPrinter->GetPageOffset() -
1179                          pImpl->mpDefPrinter->PixelToLogic( Point() );
1180     pImpl->mpDefPrinter->SetMapMode( aOldMode );
1181     pImpl->mpDefPrinter->SetOrientation( eOldOri );
1182 
1183     sal_Int64 nSetL = aLeftMarginEdit.Denormalize(
1184 					aLeftMarginEdit.GetValue( FUNIT_TWIP ) );
1185 	sal_Int64 nSetR = aRightMarginEdit.Denormalize(
1186 					aRightMarginEdit.GetValue( FUNIT_TWIP ) );
1187 	sal_Int64 nSetT = aTopMarginEdit.Denormalize(
1188 					aTopMarginEdit.GetValue( FUNIT_TWIP ) );
1189 	sal_Int64 nSetB = aBottomMarginEdit.Denormalize(
1190 					aBottomMarginEdit.GetValue( FUNIT_TWIP ) );
1191 
1192 	long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
1193 	long nNewL = aPrintOffset.X();
1194 	long nNewR =
1195 		aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset;
1196 	long nNewT = aPrintOffset.Y();
1197 	long nNewB =
1198 		aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset;
1199 
1200 	aLeftMarginEdit.SetFirst( aLeftMarginEdit.Normalize( nNewL ), FUNIT_TWIP );
1201 	nFirstLeftMargin = static_cast<long>(aLeftMarginEdit.GetFirst());
1202 	aRightMarginEdit.SetFirst( aRightMarginEdit.Normalize( nNewR ), FUNIT_TWIP );
1203 	nFirstRightMargin = static_cast<long>(aRightMarginEdit.GetFirst());
1204 	aTopMarginEdit.SetFirst( aTopMarginEdit.Normalize( nNewT ), FUNIT_TWIP );
1205 	nFirstTopMargin = static_cast<long>(aTopMarginEdit.GetFirst());
1206 	aBottomMarginEdit.SetFirst(	aBottomMarginEdit.Normalize( nNewB ), FUNIT_TWIP );
1207 	nFirstBottomMargin = static_cast<long>(aBottomMarginEdit.GetFirst());
1208 
1209 	if ( bSet )
1210 	{
1211 		// ggf. auch die Werte umsetzen,
1212 		if ( nSetL < nNewL )
1213 			aLeftMarginEdit.SetValue( aLeftMarginEdit.Normalize( nNewL ),
1214 									  FUNIT_TWIP );
1215 		if ( nSetR < nNewR )
1216 			aRightMarginEdit.SetValue( aRightMarginEdit.Normalize( nNewR ),
1217 									   FUNIT_TWIP );
1218 		if ( nSetT < nNewT )
1219 			aTopMarginEdit.SetValue( aTopMarginEdit.Normalize( nNewT ),
1220 									 FUNIT_TWIP );
1221 		if ( nSetB < nNewB )
1222 			aBottomMarginEdit.SetValue( aBottomMarginEdit.Normalize( nNewB ),
1223 										FUNIT_TWIP );
1224 	}
1225 }
1226 
1227 // -----------------------------------------------------------------------
1228 
1229 IMPL_LINK_INLINE_START( SvxPageDescPage, BorderModify_Impl, MetricField *, EMPTYARG )
1230 {
1231 	if ( !bBorderModified )
1232 		bBorderModified = sal_True;
1233 	UpdateExample_Impl();
1234 	return 0;
1235 }
1236 IMPL_LINK_INLINE_END( SvxPageDescPage, BorderModify_Impl, MetricField *, EMPTYARG )
1237 
1238 // -----------------------------------------------------------------------
1239 
1240 void SvxPageDescPage::UpdateExample_Impl( bool bResetbackground )
1241 {
1242 	// Size
1243 	Size aSize(	GetCoreValue( aPaperWidthEdit, SFX_MAPUNIT_TWIP ),
1244 				GetCoreValue( aPaperHeightEdit, SFX_MAPUNIT_TWIP ) );
1245 
1246 	aBspWin.SetSize( aSize );
1247 
1248 	// R"ander
1249 	aBspWin.SetTop( GetCoreValue( aTopMarginEdit, SFX_MAPUNIT_TWIP ) );
1250 	aBspWin.SetBottom( GetCoreValue( aBottomMarginEdit, SFX_MAPUNIT_TWIP ) );
1251 	aBspWin.SetLeft( GetCoreValue( aLeftMarginEdit, SFX_MAPUNIT_TWIP ) );
1252 	aBspWin.SetRight( GetCoreValue( aRightMarginEdit, SFX_MAPUNIT_TWIP ) );
1253 
1254 	// Layout
1255 	aBspWin.SetUsage( PosToPageUsage_Impl( aLayoutBox.GetSelectEntryPos() ) );
1256     if ( bResetbackground )
1257         aBspWin.ResetBackground();
1258 	aBspWin.Invalidate();
1259 }
1260 
1261 // -----------------------------------------------------------------------
1262 
1263 void SvxPageDescPage::ResetBackground_Impl( const SfxItemSet& rSet )
1264 {
1265 	sal_uInt16 nWhich = GetWhich( SID_ATTR_PAGE_HEADERSET );
1266 
1267 	if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
1268 	{
1269 		const SvxSetItem& rSetItem =
1270 			(const SvxSetItem&)rSet.Get( nWhich, sal_False );
1271 		const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1272 		const SfxBoolItem& rOn =
1273 			(const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1274 
1275 		if ( rOn.GetValue() )
1276 		{
1277 			nWhich = GetWhich( SID_ATTR_BRUSH );
1278 
1279 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1280 			{
1281 				const SvxBrushItem& rItem =
1282 					(const SvxBrushItem&)rTmpSet.Get( nWhich );
1283 				aBspWin.SetHdColor( rItem.GetColor() );
1284 			}
1285 			nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1286 
1287 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1288 			{
1289 				const SvxBoxItem& rItem =
1290 					(const SvxBoxItem&)rTmpSet.Get( nWhich );
1291 				aBspWin.SetHdBorder( rItem );
1292 			}
1293 		}
1294 	}
1295 
1296 	nWhich = GetWhich( SID_ATTR_PAGE_FOOTERSET );
1297 
1298 	if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
1299 	{
1300 		const SvxSetItem& rSetItem =
1301 			(const SvxSetItem&)rSet.Get( nWhich, sal_False );
1302 		const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1303 		const SfxBoolItem& rOn =
1304 			(const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1305 
1306 		if ( rOn.GetValue() )
1307 		{
1308 			nWhich = GetWhich( SID_ATTR_BRUSH );
1309 
1310 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1311 			{
1312 				const SvxBrushItem& rItem =
1313 					(const SvxBrushItem&)rTmpSet.Get( nWhich );
1314 				aBspWin.SetFtColor( rItem.GetColor() );
1315 			}
1316 			nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1317 
1318 			if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1319 			{
1320 				const SvxBoxItem& rItem =
1321 					(const SvxBoxItem&)rTmpSet.Get( nWhich );
1322 				aBspWin.SetFtBorder( rItem );
1323 			}
1324 		}
1325 	}
1326 
1327 	const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_BRUSH );
1328 
1329 	if ( pItem )
1330 	{
1331 		aBspWin.SetColor( ( (const SvxBrushItem*)pItem )->GetColor() );
1332 		const Graphic* pGrf = ( (const SvxBrushItem*)pItem )->GetGraphic();
1333 
1334 		if ( pGrf )
1335 		{
1336 			Bitmap aBitmap = pGrf->GetBitmap();
1337 			aBspWin.SetBitmap( &aBitmap );
1338 		}
1339 		else
1340 			aBspWin.SetBitmap( NULL );
1341 	}
1342 
1343 	pItem = GetItem( rSet, SID_ATTR_BORDER_OUTER );
1344 
1345 	if ( pItem )
1346 		aBspWin.SetBorder( (SvxBoxItem&)*pItem );
1347 }
1348 
1349 // -----------------------------------------------------------------------
1350 
1351 void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
1352 {
1353 	bLandscape = aLandscapeBtn.IsChecked();
1354 	const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
1355 
1356 	if ( pItem )
1357 		aBspWin.SetSize( ( (const SvxSizeItem*)pItem )->GetSize() );
1358 
1359 	const SvxSetItem* pSetItem = 0;
1360 
1361 	// Kopfzeilen-Attribute auswerten
1362 
1363 	if ( SFX_ITEM_SET ==
1364 		 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
1365 							sal_False, (const SfxPoolItem**)&pSetItem ) )
1366 	{
1367 		const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
1368 		const SfxBoolItem& rHeaderOn =
1369 			(const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1370 
1371 		if ( rHeaderOn.GetValue() )
1372 		{
1373 			const SvxSizeItem& rSize = (const SvxSizeItem&)
1374 				rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
1375 			const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
1376 				rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
1377 			long nDist = rUL.GetLower();
1378 			aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist );
1379 			aBspWin.SetHdDist( nDist );
1380 			const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
1381 				rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
1382 			aBspWin.SetHdLeft( rLR.GetLeft() );
1383 			aBspWin.SetHdRight( rLR.GetRight() );
1384 			aBspWin.SetHeader( sal_True );
1385 		}
1386 		else
1387 			aBspWin.SetHeader( sal_False );
1388 
1389 		// im Beispiel Hintergrund und Umrandung anzeigen
1390 		sal_uInt16 nWhich = GetWhich( SID_ATTR_BRUSH );
1391 
1392 		if ( rHeaderSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1393 		{
1394 			const SvxBrushItem& rItem =
1395 				(const SvxBrushItem&)rHeaderSet.Get( nWhich );
1396 			aBspWin.SetHdColor( rItem.GetColor() );
1397 		}
1398 		nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1399 
1400 		if ( rHeaderSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1401 		{
1402 			const SvxBoxItem& rItem =
1403 				(const SvxBoxItem&)rHeaderSet.Get( nWhich );
1404 			aBspWin.SetHdBorder( rItem );
1405 		}
1406 	}
1407 
1408 	// Fusszeilen-Attribute auswerten
1409 
1410 	if ( SFX_ITEM_SET ==
1411 		 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
1412 							sal_False, (const SfxPoolItem**)&pSetItem ) )
1413 	{
1414 		const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
1415 		const SfxBoolItem& rFooterOn =
1416 			(const SfxBoolItem&)rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1417 
1418 		if ( rFooterOn.GetValue() )
1419 		{
1420 			const SvxSizeItem& rSize = (const SvxSizeItem&)
1421 				rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
1422 			const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
1423 				rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
1424 			long nDist = rUL.GetUpper();
1425 			aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist );
1426 			aBspWin.SetFtDist( nDist );
1427 			const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
1428 				rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
1429 			aBspWin.SetFtLeft( rLR.GetLeft() );
1430 			aBspWin.SetFtRight( rLR.GetRight() );
1431 			aBspWin.SetFooter( sal_True );
1432 		}
1433 		else
1434 			aBspWin.SetFooter( sal_False );
1435 
1436 		// im Beispiel Hintergrund und Umrandung anzeigen
1437 		sal_uInt16 nWhich = GetWhich( SID_ATTR_BRUSH );
1438 
1439 		if ( rFooterSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1440 		{
1441 			const SvxBrushItem& rItem =
1442 				(const SvxBrushItem&)rFooterSet.Get( nWhich );
1443 			aBspWin.SetFtColor( rItem.GetColor() );
1444 		}
1445 		nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1446 
1447 		if ( rFooterSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1448 		{
1449 			const SvxBoxItem& rItem =
1450 				(const SvxBoxItem&)rFooterSet.Get( nWhich );
1451 			aBspWin.SetFtBorder( rItem );
1452 		}
1453 	}
1454 }
1455 
1456 // -----------------------------------------------------------------------
1457 
1458 void SvxPageDescPage::ActivatePage( const SfxItemSet& rSet )
1459 {
1460 	InitHeadFoot_Impl( rSet );
1461 	UpdateExample_Impl();
1462 	ResetBackground_Impl( rSet );
1463 	RangeHdl_Impl( 0 );
1464 }
1465 
1466 // -----------------------------------------------------------------------
1467 
1468 int SvxPageDescPage::DeactivatePage( SfxItemSet* _pSet )
1469 {
1470 	// Abfrage, ob die Seitenr"ander ausserhalb des Druckbereichs liegen
1471 	// Wenn nicht, dann den Anwender fragen, ob sie "ubernommen werden sollen.
1472 	// Wenn nicht, dann auf der TabPage bleiben.
1473 	sal_uInt16 nPos = aPaperSizeBox.GetSelectEntryPos();
1474 	Paper ePaper = (Paper)(sal_uLong)aPaperSizeBox.GetEntryData( nPos );
1475 
1476 	if ( ePaper != PAPER_SCREEN && IsMarginOutOfRange() )
1477 	{
1478 		if ( QueryBox( this, WB_YES_NO | WB_DEF_NO, aPrintRangeQueryText ).Execute() == RET_NO )
1479 		{
1480 			MetricField* pField = NULL;
1481 			if ( IsPrinterRangeOverflow( aLeftMarginEdit, nFirstLeftMargin, nLastLeftMargin, MARGIN_LEFT ) )
1482 				pField = &aLeftMarginEdit;
1483 			if (	IsPrinterRangeOverflow( aRightMarginEdit, nFirstRightMargin, nLastRightMargin, MARGIN_RIGHT )
1484 				 && !pField )
1485 				pField = &aRightMarginEdit;
1486 			if (	IsPrinterRangeOverflow( aTopMarginEdit, nFirstTopMargin, nLastTopMargin, MARGIN_TOP )
1487 				 && !pField )
1488 				pField = &aTopMarginEdit;
1489 			if (	IsPrinterRangeOverflow( aBottomMarginEdit, nFirstBottomMargin, nLastBottomMargin, MARGIN_BOTTOM )
1490 				 && !pField )
1491 				pField = &aBottomMarginEdit;
1492 			if ( pField )
1493 				pField->GrabFocus();
1494 			UpdateExample_Impl();
1495 			return KEEP_PAGE;
1496 		}
1497 		else
1498 			CheckMarginEdits( false );
1499 	}
1500 
1501     if ( _pSet )
1502 	{
1503         FillItemSet( *_pSet );
1504 
1505 		// ggf. hoch/quer putten
1506 		sal_uInt16 nWh = GetWhich( SID_ATTR_PAGE_SIZE );
1507 		SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWh );
1508 		Size aSize( GetCoreValue( aPaperWidthEdit, eUnit ),
1509 					GetCoreValue( aPaperHeightEdit, eUnit ) );
1510 
1511         // putten, wenn aktuelle Gr"o/se unterschiedlich zum Wert in _pSet
1512         const SvxSizeItem* pSize = (const SvxSizeItem*)GetItem( *_pSet, SID_ATTR_PAGE_SIZE );
1513 		if ( aSize.Width() && ( !pSize || !IsEqualSize_Impl( pSize, aSize ) ) )
1514             _pSet->Put( SvxSizeItem( nWh, aSize ) );
1515 	}
1516 
1517 	return LEAVE_PAGE;
1518 }
1519 
1520 // -----------------------------------------------------------------------
1521 
1522 IMPL_LINK( SvxPageDescPage, RangeHdl_Impl, Edit *, EMPTYARG )
1523 {
1524 	// Aktuelle Header-Breite/H"ohe aus dem Bsp
1525 	long nHHeight = aBspWin.GetHdHeight();
1526 	long nHDist = aBspWin.GetHdDist();
1527 
1528 	// Aktuelle Footer-Breite/H"ohe aus dem Bsp
1529 	long nFHeight = aBspWin.GetFtHeight();
1530 	long nFDist = aBspWin.GetFtDist();
1531 
1532 	// Aktuelle Header/Footer-R"ander aus dem Bsp
1533 	long nHFLeft = Max( aBspWin.GetHdLeft(), aBspWin.GetFtLeft() );
1534 	long nHFRight = Max( aBspWin.GetHdRight(), aBspWin.GetFtRight() );
1535 
1536 	// Aktuelle Werte der Seitenr"ander
1537 	long nBT = static_cast<long>(aTopMarginEdit.Denormalize(aTopMarginEdit.GetValue(FUNIT_TWIP)));
1538 	long nBB = static_cast<long>(aBottomMarginEdit.Denormalize(aBottomMarginEdit.GetValue(FUNIT_TWIP)));
1539 	long nBL = static_cast<long>(aLeftMarginEdit.Denormalize(aLeftMarginEdit.GetValue(FUNIT_TWIP)));
1540 	long nBR = static_cast<long>(aRightMarginEdit.Denormalize(aRightMarginEdit.GetValue(FUNIT_TWIP)));
1541 
1542 	// Breite Umrandung der Seite berechnen
1543     const SfxItemSet* _pSet = &GetItemSet();
1544 	Size aBorder;
1545 
1546     if ( _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_SHADOW) ) >=
1547 			SFX_ITEM_AVAILABLE &&
1548          _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_OUTER)  ) >=
1549 			SFX_ITEM_AVAILABLE )
1550 	{
1551 		aBorder = ( GetMinBorderSpace_Impl(
1552             (const SvxShadowItem&)_pSet->Get(GetWhich(SID_ATTR_BORDER_SHADOW)),
1553             (const SvxBoxItem&)_pSet->Get(GetWhich(SID_ATTR_BORDER_OUTER))));
1554 	}
1555 
1556 	long nH  = static_cast<long>(aPaperHeightEdit.Denormalize(aPaperHeightEdit.GetValue(FUNIT_TWIP)));
1557 	long nW  = static_cast<long>(aPaperWidthEdit.Denormalize(aPaperWidthEdit.GetValue(FUNIT_TWIP)));
1558 
1559 	// Grenzen Papier
1560 	// Maximum liegt bei 54cm
1561 	//
1562 	long nMin = nHHeight + nHDist + nFDist + nFHeight + nBT + nBB +
1563 				MINBODY + aBorder.Height();
1564 	aPaperHeightEdit.SetMin(aPaperHeightEdit.Normalize(nMin), FUNIT_TWIP);
1565 
1566 	nMin = MINBODY + nBL + nBR + aBorder.Width();
1567 	aPaperWidthEdit.SetMin(aPaperWidthEdit.Normalize(nMin), FUNIT_TWIP);
1568 
1569 	// Falls sich die Papiergr"o\se ge"adert hat
1570 	nH = static_cast<long>(aPaperHeightEdit.Denormalize(aPaperHeightEdit.GetValue(FUNIT_TWIP)));
1571 	nW = static_cast<long>(aPaperWidthEdit.Denormalize(aPaperWidthEdit.GetValue(FUNIT_TWIP)));
1572 
1573 	// Top
1574 	long nMax =	nH - nBB - aBorder.Height() - MINBODY -
1575 				nFDist - nFHeight -	nHDist - nHHeight;
1576 
1577 	aTopMarginEdit.SetMax(aTopMarginEdit.Normalize(nMax), FUNIT_TWIP);
1578 
1579 	// Bottom
1580 	nMax = nH - nBT - aBorder.Height() - MINBODY -
1581 		   nFDist - nFHeight - nHDist - nHHeight;
1582 
1583 	aBottomMarginEdit.SetMax(aTopMarginEdit.Normalize(nMax), FUNIT_TWIP);
1584 
1585 	// Left
1586 	nMax = nW - nBR - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1587 	aLeftMarginEdit.SetMax(aLeftMarginEdit.Normalize(nMax), FUNIT_TWIP);
1588 
1589 	// Right
1590 	nMax = nW - nBL - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1591 	aRightMarginEdit.SetMax(aRightMarginEdit.Normalize(nMax), FUNIT_TWIP);
1592 	return 0;
1593 }
1594 
1595 // -----------------------------------------------------------------------
1596 
1597 void SvxPageDescPage::CalcMargin_Impl()
1598 {
1599 	// Aktuelle Werte der Seitenr"ander
1600 	long nBT = GetCoreValue( aTopMarginEdit, SFX_MAPUNIT_TWIP );
1601 	long nBB = GetCoreValue( aBottomMarginEdit, SFX_MAPUNIT_TWIP );
1602 
1603 	long nBL = GetCoreValue( aLeftMarginEdit, SFX_MAPUNIT_TWIP );
1604 	long nBR = GetCoreValue( aRightMarginEdit, SFX_MAPUNIT_TWIP );
1605 
1606 	long nH  = GetCoreValue( aPaperHeightEdit, SFX_MAPUNIT_TWIP );
1607 	long nW  = GetCoreValue( aPaperWidthEdit, SFX_MAPUNIT_TWIP );
1608 
1609 	long nWidth = nBL + nBR + MINBODY;
1610 	long nHeight = nBT + nBB + MINBODY;
1611 
1612 	if ( nWidth > nW || nHeight > nH )
1613 	{
1614 		if ( nWidth > nW )
1615 		{
1616 			long nTmp = nBL <= nBR ? nBR : nBL;
1617 			nTmp -= nWidth - nW;
1618 
1619 			if ( nBL <= nBR )
1620 				SetMetricValue( aRightMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1621 			else
1622 				SetMetricValue( aLeftMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1623 		}
1624 
1625 		if ( nHeight > nH )
1626 		{
1627 			long nTmp = nBT <= nBB ? nBB : nBT;
1628 			nTmp -= nHeight - nH;
1629 
1630 			if ( nBT <= nBB )
1631 				SetMetricValue( aBottomMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1632 			else
1633 				SetMetricValue( aTopMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1634 		}
1635 	}
1636 }
1637 
1638 // -----------------------------------------------------------------------
1639 
1640 IMPL_LINK_INLINE_START( SvxPageDescPage, CenterHdl_Impl, CheckBox *, EMPTYARG )
1641 {
1642     aBspWin.SetHorz( aHorzBox.IsChecked() );
1643     aBspWin.SetVert( aVertBox.IsChecked() );
1644     UpdateExample_Impl();
1645 	return 0;
1646 }
1647 IMPL_LINK_INLINE_END( SvxPageDescPage, CenterHdl_Impl, CheckBox *, EMPTYARG )
1648 
1649 // -----------------------------------------------------------------------
1650 
1651 void SvxPageDescPage::SetCollectionList(const List* pList)
1652 {
1653 	sStandardRegister = *(String*)pList->GetObject(0);
1654 	for( sal_uInt16 i = 1; i < pList->Count(); i++   )
1655 	{
1656 		aRegisterLB.InsertEntry(*(String*)pList->GetObject(i));
1657 	}
1658 
1659 	aRegisterCB  .Show();
1660 	aRegisterFT  .Show();
1661 	aRegisterLB.Show();
1662 	aRegisterCB.SetClickHdl(LINK(this, SvxPageDescPage, RegisterModify));
1663 }
1664 
1665 // -----------------------------------------------------------------------
1666 
1667 IMPL_LINK( SvxPageDescPage, RegisterModify, CheckBox*, pBox )
1668 {
1669 	sal_Bool bEnable = sal_False;
1670 	if(pBox->IsChecked())
1671 	{
1672 		bEnable = sal_True;
1673 		if(USHRT_MAX == aRegisterLB.GetSelectEntryPos())
1674 			aRegisterLB.SelectEntry(sStandardRegister);
1675 	}
1676 	aRegisterFT.Enable( bEnable );
1677 	aRegisterLB.Enable( bEnable );
1678 	return 0;
1679 }
1680 
1681 // ----------------------------------------------------------------------------
1682 
1683 void SvxPageDescPage::DisableVerticalPageDir()
1684 {
1685     aTextFlowBox.RemoveEntryValue( FRMDIR_VERT_TOP_RIGHT );
1686     aTextFlowBox.RemoveEntryValue( FRMDIR_VERT_TOP_LEFT );
1687     if( aTextFlowBox.GetEntryCount() < 2 )
1688     {
1689         aTextFlowLbl.Hide();
1690         aTextFlowBox.Hide();
1691         aBspWin.EnableFrameDirection( sal_False );
1692     }
1693 }
1694 
1695 IMPL_LINK( SvxPageDescPage, FrameDirectionModify_Impl, ListBox*,  EMPTYARG)
1696 {
1697     aBspWin.SetFrameDirection( (sal_uInt32) aTextFlowBox.GetSelectEntryValue() );
1698     aBspWin.Invalidate();
1699     return 0;
1700 }
1701 
1702 bool SvxPageDescPage::IsPrinterRangeOverflow(
1703 	MetricField& rField, long nFirstMargin, long nLastMargin, MarginPosition nPos )
1704 {
1705 	bool bRet = false;
1706 	bool bCheck = ( ( pImpl->m_nPos & nPos ) == 0 );
1707 	long nValue = static_cast<long>(rField.GetValue());
1708 	if ( bCheck &&
1709 		 (  nValue < nFirstMargin || nValue > nLastMargin ) &&
1710 		 rField.GetText() != rField.GetSavedValue() )
1711 	{
1712 		rField.SetValue( nValue < nFirstMargin ? nFirstMargin : nLastMargin );
1713  		bRet = true;
1714 	}
1715 
1716 	return bRet;
1717 }
1718 
1719 /** Check if a value of a margin edit is outside the printer paper margins
1720 	and save this information.
1721 */
1722 void SvxPageDescPage::CheckMarginEdits( bool _bClear )
1723 {
1724 	if ( _bClear )
1725 		pImpl->m_nPos = 0;
1726 
1727 	sal_Int64 nValue = aLeftMarginEdit.GetValue();
1728 	if (  nValue < nFirstLeftMargin || nValue > nLastLeftMargin )
1729 		pImpl->m_nPos |= MARGIN_LEFT;
1730 	nValue = aRightMarginEdit.GetValue();
1731 	if (  nValue < nFirstRightMargin || nValue > nLastRightMargin )
1732 		pImpl->m_nPos |= MARGIN_RIGHT;
1733 	nValue = aTopMarginEdit.GetValue();
1734 	if (  nValue < nFirstTopMargin || nValue > nLastTopMargin )
1735 		pImpl->m_nPos |= MARGIN_TOP;
1736 	nValue = aBottomMarginEdit.GetValue();
1737 	if (  nValue < nFirstBottomMargin || nValue > nLastBottomMargin )
1738 		pImpl->m_nPos |= MARGIN_BOTTOM;
1739 }
1740 
1741 bool SvxPageDescPage::IsMarginOutOfRange()
1742 {
1743 	bool bRet = ( ( ( !( pImpl->m_nPos & MARGIN_LEFT ) &&
1744 					  ( aLeftMarginEdit.GetText() != aLeftMarginEdit.GetSavedValue() ) ) &&
1745 					( aLeftMarginEdit.GetValue() < nFirstLeftMargin ||
1746 					  aLeftMarginEdit.GetValue() > nLastLeftMargin ) ) ||
1747 				  ( ( !( pImpl->m_nPos & MARGIN_RIGHT ) &&
1748 					  ( aRightMarginEdit.GetText() != aRightMarginEdit.GetSavedValue() ) ) &&
1749 					( aRightMarginEdit.GetValue() < nFirstRightMargin ||
1750 					  aRightMarginEdit.GetValue() > nLastRightMargin ) ) ||
1751 				  ( ( !( pImpl->m_nPos & MARGIN_TOP ) &&
1752 					  ( aTopMarginEdit.GetText() != aTopMarginEdit.GetSavedValue() ) ) &&
1753 					( aTopMarginEdit.GetValue() < nFirstTopMargin ||
1754 					  aTopMarginEdit.GetValue() > nLastTopMargin ) ) ||
1755 				  ( ( !( pImpl->m_nPos & MARGIN_BOTTOM ) &&
1756 					  ( aBottomMarginEdit.GetText() != aBottomMarginEdit.GetSavedValue() ) ) &&
1757 					( aBottomMarginEdit.GetValue() < nFirstBottomMargin ||
1758 					  aBottomMarginEdit.GetValue() > nLastBottomMargin ) ) );
1759 	return bRet;
1760 }
1761 
1762 void SvxPageDescPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
1763 {
1764 	SFX_ITEMSET_ARG (&aSet,pModeItem,SfxAllEnumItem,SID_ENUM_PAGE_MODE,sal_False);
1765 	SFX_ITEMSET_ARG (&aSet,pPaperStartItem,SfxAllEnumItem,SID_PAPER_START,sal_False);
1766 	SFX_ITEMSET_ARG (&aSet,pPaperEndItem,SfxAllEnumItem,SID_PAPER_END,sal_False);
1767 	SFX_ITEMSET_ARG (&aSet,pCollectListItem,SfxStringListItem,SID_COLLECT_LIST,sal_False);
1768 	if (pModeItem)
1769 		SetMode((SvxModeType)pModeItem->GetEnumValue());
1770 	if (pPaperStartItem && pPaperEndItem)
1771 		SetPaperFormatRanges( (Paper)pPaperStartItem->GetEnumValue(), (Paper)pPaperEndItem->GetEnumValue() );
1772 	if (pCollectListItem)
1773 		SetCollectionList(pCollectListItem->GetList());
1774 }
1775