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