bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / page.cxx
blob7a60414d310fccac686a0de11a6ffb9e3389118b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/app.hxx>
21 #include <sfx2/objsh.hxx>
22 #include <sfx2/printer.hxx>
23 #include <tools/resary.hxx>
24 #include <vcl/graph.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <svl/itemiter.hxx>
27 #include <svl/languageoptions.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <unotools/configitem.hxx>
30 #include <sfx2/htmlmode.hxx>
31 #include <sal/macros.h>
33 #include <cuires.hrc>
34 #include "helpid.hrc"
35 #include "page.hxx"
36 #include <svx/pageitem.hxx>
37 #include <editeng/brushitem.hxx>
38 #include <editeng/boxitem.hxx>
39 #include <editeng/shaditem.hxx>
40 #include <editeng/pbinitem.hxx>
41 #include <editeng/lrspitem.hxx>
42 #include <editeng/ulspitem.hxx>
43 #include <editeng/sizeitem.hxx>
44 #include <editeng/frmdiritem.hxx>
45 #include "svx/dlgutil.hxx"
46 #include <editeng/paperinf.hxx>
47 #include <dialmgr.hxx>
48 #include <sfx2/module.hxx>
49 #include <svl/stritem.hxx>
50 #include <svx/dialogs.hrc>
51 #include <editeng/eerdll.hxx>
52 #include <editeng/editrids.hrc>
53 #include <svx/svxids.hrc>
54 #include <svtools/optionsdrawinglayer.hxx>
55 #include <svl/slstitm.hxx>
56 #include <svl/aeitem.hxx>
57 #include <sfx2/request.hxx>
59 //UUUU
60 #include <svx/xdef.hxx>
61 #include <svx/unobrushitemhelper.hxx>
63 #include <numpages.hxx>
64 #include <boost/scoped_ptr.hpp>
66 // static ----------------------------------------------------------------
68 static const long MINBODY = 284; // 0,5 cm rounded up in twips
69 //static const long PRINT_OFFSET = 17; // 0,03 cm rounded down in twips
70 static const long PRINT_OFFSET = 0; // why was this ever set to 17 ? it led to wrong right and bottom margins.
72 const sal_uInt16 SvxPageDescPage::pRanges[] =
74 SID_ATTR_BORDER_OUTER,
75 SID_ATTR_BORDER_SHADOW,
76 SID_ATTR_LRSPACE,
77 SID_ATTR_PAGE_SHARED,
78 SID_SWREGISTER_COLLECTION,
79 SID_SWREGISTER_MODE,
82 // ------- Mapping page layout ------------------------------------------
84 const sal_uInt16 aArr[] =
86 SVX_PAGE_ALL,
87 SVX_PAGE_MIRROR,
88 SVX_PAGE_RIGHT,
89 SVX_PAGE_LEFT
94 sal_uInt16 PageUsageToPos_Impl( sal_uInt16 nUsage )
96 for ( sal_uInt16 i = 0; i < SAL_N_ELEMENTS(aArr); ++i )
97 if ( aArr[i] == ( nUsage & 0x000f ) )
98 return i;
99 return SVX_PAGE_ALL;
104 sal_uInt16 PosToPageUsage_Impl( sal_uInt16 nPos )
106 if ( nPos >= SAL_N_ELEMENTS(aArr) )
107 return 0;
108 return aArr[nPos];
113 Size GetMinBorderSpace_Impl( const SvxShadowItem& rShadow, const SvxBoxItem& rBox )
115 Size aSz;
116 aSz.Height() = rShadow.CalcShadowSpace( SvxShadowItemSide::BOTTOM ) + rBox.CalcLineSpace( SvxBoxItemLine::BOTTOM );
117 aSz.Height() += rShadow.CalcShadowSpace( SvxShadowItemSide::TOP ) + rBox.CalcLineSpace( SvxBoxItemLine::TOP );
118 aSz.Width() = rShadow.CalcShadowSpace( SvxShadowItemSide::LEFT ) + rBox.CalcLineSpace( SvxBoxItemLine::LEFT );
119 aSz.Width() += rShadow.CalcShadowSpace( SvxShadowItemSide::RIGHT ) + rBox.CalcLineSpace( SvxBoxItemLine::RIGHT );
120 return aSz;
125 long ConvertLong_Impl( const long nIn, SfxMapUnit eUnit )
127 return OutputDevice::LogicToLogic( nIn, (MapUnit)eUnit, MAP_TWIP );
130 bool IsEqualSize_Impl( const SvxSizeItem* pSize, const Size& rSize )
132 if ( pSize )
134 Size aSize = pSize->GetSize();
135 long nDiffW = std::abs( rSize.Width () - aSize.Width () );
136 long nDiffH = std::abs( rSize.Height() - aSize.Height() );
137 return ( nDiffW < 10 && nDiffH < 10 );
139 else
140 return false;
145 #define MARGIN_LEFT ( (MarginPosition)0x0001 )
146 #define MARGIN_RIGHT ( (MarginPosition)0x0002 )
147 #define MARGIN_TOP ( (MarginPosition)0x0004 )
148 #define MARGIN_BOTTOM ( (MarginPosition)0x0008 )
150 //UUUU
151 //struct SvxPage_Impl
153 // MarginPosition m_nPos;
154 // Printer* mpDefPrinter;
155 // bool mbDelPrinter;
157 // SvxPage_Impl() :
158 // m_nPos( 0 ),
159 // mpDefPrinter( 0 ),
160 // mbDelPrinter( false ) {}
162 // ~SvxPage_Impl() { if ( mbDelPrinter ) delete mpDefPrinter; }
163 //};
165 // class SvxPageDescPage --------------------------------------------------
167 VclPtr<SfxTabPage> SvxPageDescPage::Create( vcl::Window* pParent, const SfxItemSet* rSet )
169 return VclPtr<SvxPageDescPage>::Create( pParent, *rSet );
172 SvxPageDescPage::SvxPageDescPage( vcl::Window* pParent, const SfxItemSet& rAttr ) :
174 SfxTabPage( pParent, "PageFormatPage", "cui/ui/pageformatpage.ui", &rAttr ),
176 bLandscape ( false ),
177 eMode ( SVX_PAGE_MODE_STANDARD ),
178 ePaperStart ( PAPER_A3 ),
179 ePaperEnd ( PAPER_ENV_DL ),
181 //UUUU
182 // pImpl ( new SvxPage_Impl ),
184 //UUUU
185 m_nPos( 0 ),
186 mpDefPrinter( 0 ),
187 mbDelPrinter( false ),
189 //UUUU
190 mbEnableDrawingLayerFillStyles(false)
192 get(m_pPaperSizeBox,"comboPageFormat");
193 get(m_pPaperWidthEdit,"spinWidth");
194 get(m_pPaperHeightEdit,"spinHeight");
196 get(m_pOrientationFT,"labelOrientation");
197 get(m_pPortraitBtn,"radiobuttonPortrait");
198 get(m_pLandscapeBtn,"radiobuttonLandscape");
200 get(m_pBspWin,"drawingareaPageDirection");
201 get(m_pTextFlowLbl,"labelTextFlow");
202 get(m_pTextFlowBox,"comboTextFlowBox");
203 get(m_pPaperTrayBox,"comboPaperTray");
205 get(m_pLeftMarginLbl,"labelLeftMargin");
206 get(m_pLeftMarginEdit,"spinMargLeft");
207 get(m_pRightMarginLbl,"labelRightMargin");
208 get(m_pRightMarginEdit,"spinMargRight");
210 get(m_pTopMarginEdit,"spinMargTop");
212 get(m_pBottomMarginEdit,"spinMargBot");
214 get(m_pPageText,"labelPageLayout");
215 get(m_pLayoutBox,"comboPageLayout");
216 get(m_pNumberFormatBox,"comboLayoutFormat");
218 get(m_pRegisterCB,"checkRegisterTrue");
219 get(m_pRegisterFT,"labelRegisterStyle");
220 get(m_pRegisterLB,"comboRegisterStyle");
222 get(m_pTblAlignFT,"labelTblAlign");
223 get(m_pHorzBox,"checkbuttonHorz");
224 get(m_pVertBox,"checkbuttonVert");
226 get(m_pAdaptBox,"checkAdaptBox");
227 // Strings stored in UI
228 get(m_pInsideLbl,"labelInner");
229 get(m_pOutsideLbl,"labelOuter");
230 get(m_pPrintRangeQueryText,"labelMsg");
232 bBorderModified = false;
233 m_pBspWin->EnableRTL( false );
235 // this page needs ExchangeSupport
236 SetExchangeSupport();
238 SvtLanguageOptions aLangOptions;
239 bool bCJK = aLangOptions.IsAsianTypographyEnabled();
240 bool bCTL = aLangOptions.IsCTLFontEnabled();
241 bool bWeb = false;
242 const SfxPoolItem* pItem;
244 SfxObjectShell* pShell;
245 if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
246 ( 0 != (pShell = SfxObjectShell::Current()) &&
247 0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
248 bWeb = 0 != (static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON);
250 // fill text flow listbox with valid entries
252 m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_HORI ), FRMDIR_HORI_LEFT_TOP );
255 if( bCTL )
256 m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_HORI ), FRMDIR_HORI_RIGHT_TOP );
259 // #109989# do not show vertical directions in Writer/Web
260 if( !bWeb )
262 if( bCJK )
264 m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_VERT ), FRMDIR_VERT_TOP_RIGHT );
265 // m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_VERT ), FRMDIR_VERT_TOP_LEFT );
269 // #109989# show the text direction box in Writer/Web too
270 if( (bCJK || bCTL) &&
271 SfxItemState::UNKNOWN < rAttr.GetItemState(GetWhich( SID_ATTR_FRAMEDIRECTION )))
273 m_pTextFlowLbl->Show();
274 m_pTextFlowBox->Show();
275 m_pTextFlowBox->SetSelectHdl(LINK(this, SvxPageDescPage, FrameDirectionModify_Impl ));
277 m_pBspWin->EnableFrameDirection(true);
279 Init_Impl();
281 FieldUnit eFUnit = GetModuleFieldUnit( rAttr );
282 SetFieldUnit( *m_pLeftMarginEdit, eFUnit );
283 SetFieldUnit( *m_pRightMarginEdit, eFUnit );
284 SetFieldUnit( *m_pTopMarginEdit, eFUnit );
285 SetFieldUnit( *m_pBottomMarginEdit, eFUnit );
286 SetFieldUnit( *m_pPaperWidthEdit, eFUnit );
287 SetFieldUnit( *m_pPaperHeightEdit, eFUnit );
289 if ( SfxViewShell::Current() && SfxViewShell::Current()->GetPrinter() )
291 mpDefPrinter = SfxViewShell::Current()->GetPrinter();
293 else
295 mpDefPrinter = VclPtr<Printer>::Create();
296 mbDelPrinter = true;
299 MapMode aOldMode = mpDefPrinter->GetMapMode();
300 mpDefPrinter->SetMapMode( MAP_TWIP );
302 // set first- and last-values for the margins
303 Size aPaperSize = mpDefPrinter->GetPaperSize();
304 Size aPrintSize = mpDefPrinter->GetOutputSize();
306 * To convert a point ( 0,0 ) into logic coordinates
307 * looks like nonsense; but it makes sense when the
308 * coordinate system's origin has been moved.
310 Point aPrintOffset = mpDefPrinter->GetPageOffset() - mpDefPrinter->PixelToLogic( Point() );
311 mpDefPrinter->SetMapMode( aOldMode );
313 long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
314 m_pLeftMarginEdit->SetFirst( m_pLeftMarginEdit->Normalize( aPrintOffset.X() ), FUNIT_TWIP );
315 nFirstLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetFirst());
317 m_pRightMarginEdit->SetFirst( m_pRightMarginEdit->Normalize( aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset ), FUNIT_TWIP);
318 nFirstRightMargin = static_cast<long>(m_pRightMarginEdit->GetFirst());
320 m_pTopMarginEdit->SetFirst( m_pTopMarginEdit->Normalize( aPrintOffset.Y() ), FUNIT_TWIP );
321 nFirstTopMargin = static_cast<long>(m_pTopMarginEdit->GetFirst());
323 m_pBottomMarginEdit->SetFirst( m_pBottomMarginEdit->Normalize( aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset ), FUNIT_TWIP );
324 nFirstBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetFirst());
326 m_pLeftMarginEdit->SetLast( m_pLeftMarginEdit->Normalize( aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
327 nLastLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetLast());
329 m_pRightMarginEdit->SetLast( m_pRightMarginEdit->Normalize( aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
330 nLastRightMargin = static_cast<long>(m_pRightMarginEdit->GetLast());
332 m_pTopMarginEdit->SetLast( m_pTopMarginEdit->Normalize( aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
333 nLastTopMargin = static_cast<long>(m_pTopMarginEdit->GetLast());
335 m_pBottomMarginEdit->SetLast( m_pBottomMarginEdit->Normalize( aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
336 nLastBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetLast());
338 // #i4219# get DrawingLayer options
339 const SvtOptionsDrawinglayer aDrawinglayerOpt;
341 // #i4219# take Maximum now from configuration (1/100th cm)
342 // was: 11900 -> 119 cm ;new value 3 meters -> 300 cm -> 30000
343 m_pPaperWidthEdit->SetMax(m_pPaperWidthEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
344 m_pPaperWidthEdit->SetLast(m_pPaperWidthEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
345 m_pPaperHeightEdit->SetMax(m_pPaperHeightEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
346 m_pPaperHeightEdit->SetLast(m_pPaperHeightEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
348 // #i4219# also for margins (1/100th cm). Was: 9999, keeping.
349 m_pLeftMarginEdit->SetMax(m_pLeftMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperLeftMargin()), FUNIT_MM);
350 m_pLeftMarginEdit->SetLast(m_pLeftMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperLeftMargin()), FUNIT_MM);
351 m_pRightMarginEdit->SetMax(m_pRightMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperRightMargin()), FUNIT_MM);
352 m_pRightMarginEdit->SetLast(m_pRightMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperRightMargin()), FUNIT_MM);
353 m_pTopMarginEdit->SetMax(m_pTopMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperTopMargin()), FUNIT_MM);
354 m_pTopMarginEdit->SetLast(m_pTopMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperTopMargin()), FUNIT_MM);
355 m_pBottomMarginEdit->SetMax(m_pBottomMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperBottomMargin()), FUNIT_MM);
356 m_pBottomMarginEdit->SetLast(m_pBottomMarginEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperBottomMargin()), FUNIT_MM);
358 m_pPortraitBtn->SetAccessibleRelationMemberOf(m_pOrientationFT);
359 m_pLandscapeBtn->SetAccessibleRelationMemberOf(m_pOrientationFT);
361 // Get the i18n framework numberings and add them to the listbox.
362 SvxNumOptionsTabPage::GetI18nNumbering( *m_pNumberFormatBox, ::std::numeric_limits<sal_uInt16>::max());
367 SvxPageDescPage::~SvxPageDescPage()
369 disposeOnce();
372 void SvxPageDescPage::dispose()
374 if(mbDelPrinter)
376 mpDefPrinter.disposeAndClear();
377 mbDelPrinter = false;
379 m_pPaperSizeBox.clear();
380 m_pPaperWidthEdit.clear();
381 m_pPaperHeightEdit.clear();
382 m_pOrientationFT.clear();
383 m_pPortraitBtn.clear();
384 m_pLandscapeBtn.clear();
385 m_pBspWin.clear();
386 m_pTextFlowLbl.clear();
387 m_pTextFlowBox.clear();
388 m_pPaperTrayBox.clear();
389 m_pLeftMarginLbl.clear();
390 m_pLeftMarginEdit.clear();
391 m_pRightMarginLbl.clear();
392 m_pRightMarginEdit.clear();
393 m_pTopMarginEdit.clear();
394 m_pBottomMarginEdit.clear();
395 m_pPageText.clear();
396 m_pLayoutBox.clear();
397 m_pNumberFormatBox.clear();
398 m_pTblAlignFT.clear();
399 m_pHorzBox.clear();
400 m_pVertBox.clear();
401 m_pAdaptBox.clear();
402 m_pRegisterCB.clear();
403 m_pRegisterFT.clear();
404 m_pRegisterLB.clear();
405 m_pInsideLbl.clear();
406 m_pOutsideLbl.clear();
407 m_pPrintRangeQueryText.clear();
408 SfxTabPage::dispose();
413 void SvxPageDescPage::Init_Impl()
415 // adjust the handler
416 m_pLayoutBox->SetSelectHdl( LINK( this, SvxPageDescPage, LayoutHdl_Impl ) );
417 m_pPaperSizeBox->SetDropDownLineCount(10);
419 m_pPaperTrayBox->SetGetFocusHdl( LINK( this, SvxPageDescPage, PaperBinHdl_Impl ) );
420 m_pPaperSizeBox->SetSelectHdl( LINK( this, SvxPageDescPage, PaperSizeSelect_Impl ) );
421 m_pPaperWidthEdit->SetModifyHdl( LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
422 m_pPaperHeightEdit->SetModifyHdl( LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
423 m_pLandscapeBtn->SetClickHdl( LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
424 m_pPortraitBtn->SetClickHdl( LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
426 Link<> aLink = LINK( this, SvxPageDescPage, BorderModify_Impl );
427 m_pLeftMarginEdit->SetModifyHdl( aLink );
428 m_pRightMarginEdit->SetModifyHdl( aLink );
429 m_pTopMarginEdit->SetModifyHdl( aLink );
430 m_pBottomMarginEdit->SetModifyHdl( aLink );
432 aLink = LINK( this, SvxPageDescPage, RangeHdl_Impl );
433 m_pPaperWidthEdit->SetLoseFocusHdl( aLink );
434 m_pPaperHeightEdit->SetLoseFocusHdl( aLink );
435 m_pLeftMarginEdit->SetLoseFocusHdl( aLink );
436 m_pRightMarginEdit->SetLoseFocusHdl( aLink );
437 m_pTopMarginEdit->SetLoseFocusHdl( aLink );
438 m_pBottomMarginEdit->SetLoseFocusHdl( aLink );
440 m_pHorzBox->SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
441 m_pVertBox->SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
447 void SvxPageDescPage::Reset( const SfxItemSet* rSet )
449 SfxItemPool* pPool = rSet->GetPool();
450 DBG_ASSERT( pPool, "Wo ist der Pool" );
451 SfxMapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_LRSPACE ) );
453 // adjust margins (right/left)
454 const SfxPoolItem* pItem = GetItem( *rSet, SID_ATTR_LRSPACE );
456 if ( pItem )
458 const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(*pItem);
459 SetMetricValue( *m_pLeftMarginEdit, rLRSpace.GetLeft(), eUnit );
460 m_pBspWin->SetLeft(
461 (sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetLeft(), eUnit ) );
462 SetMetricValue( *m_pRightMarginEdit, rLRSpace.GetRight(), eUnit );
463 m_pBspWin->SetRight(
464 (sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetRight(), eUnit ) );
467 // adjust margins (top/bottom)
468 pItem = GetItem( *rSet, SID_ATTR_ULSPACE );
470 if ( pItem )
472 const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(*pItem);
473 SetMetricValue( *m_pTopMarginEdit, rULSpace.GetUpper(), eUnit );
474 m_pBspWin->SetTop(
475 (sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetUpper(), eUnit ) );
476 SetMetricValue( *m_pBottomMarginEdit, rULSpace.GetLower(), eUnit );
477 m_pBspWin->SetBottom(
478 (sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetLower(), eUnit ) );
481 // general page data
482 SvxNumType eNumType = SVX_ARABIC;
483 bLandscape = ( mpDefPrinter->GetOrientation() == ORIENTATION_LANDSCAPE );
484 sal_uInt16 nUse = (sal_uInt16)SVX_PAGE_ALL;
485 pItem = GetItem( *rSet, SID_ATTR_PAGE );
487 if ( pItem )
489 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(*pItem);
490 eNumType = rItem.GetNumType();
491 nUse = rItem.GetPageUsage();
492 bLandscape = rItem.IsLandscape();
495 // alignment
496 m_pLayoutBox->SelectEntryPos( ::PageUsageToPos_Impl( nUse ) );
497 m_pBspWin->SetUsage( nUse );
498 LayoutHdl_Impl( 0 );
500 //adjust numeration type of the page style
501 //Get the Position of the saved NumType
502 for(int i=0; i<m_pNumberFormatBox->GetEntryCount(); i++)
503 if(eNumType == (sal_uInt16)reinterpret_cast<sal_uLong>(m_pNumberFormatBox->GetEntryData(i)))
505 m_pNumberFormatBox->SelectEntryPos( i );
506 break;
509 m_pPaperTrayBox->Clear();
510 sal_uInt8 nPaperBin = PAPERBIN_PRINTER_SETTINGS;
511 pItem = GetItem( *rSet, SID_ATTR_PAGE_PAPERBIN );
513 if ( pItem )
515 nPaperBin = static_cast<const SvxPaperBinItem*>(pItem)->GetValue();
517 if ( nPaperBin >= mpDefPrinter->GetPaperBinCount() )
518 nPaperBin = PAPERBIN_PRINTER_SETTINGS;
521 OUString aBinName;
523 if ( PAPERBIN_PRINTER_SETTINGS == nPaperBin )
524 aBinName = EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS );
525 else
526 aBinName = mpDefPrinter->GetPaperBinName( (sal_uInt16)nPaperBin );
528 sal_uInt16 nEntryPos = m_pPaperTrayBox->InsertEntry( aBinName );
529 m_pPaperTrayBox->SetEntryData( nEntryPos, reinterpret_cast<void*>((sal_uLong)nPaperBin) );
530 m_pPaperTrayBox->SelectEntry( aBinName );
532 Size aPaperSize = SvxPaperInfo::GetPaperSize( mpDefPrinter );
533 pItem = GetItem( *rSet, SID_ATTR_PAGE_SIZE );
535 if ( pItem )
536 aPaperSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
538 bool bOrientationSupport =
539 mpDefPrinter->HasSupport( SUPPORT_SET_ORIENTATION );
541 if ( !bOrientationSupport &&
542 aPaperSize.Width() > aPaperSize.Height() )
543 bLandscape = true;
545 m_pLandscapeBtn->Check( bLandscape );
546 m_pPortraitBtn->Check( !bLandscape );
548 m_pBspWin->SetSize( Size( ConvertLong_Impl( aPaperSize.Width(), eUnit ),
549 ConvertLong_Impl( aPaperSize.Height(), eUnit ) ) );
551 aPaperSize = OutputDevice::LogicToLogic(aPaperSize, (MapUnit)eUnit, MAP_100TH_MM);
552 if ( bLandscape )
553 Swap( aPaperSize );
555 // Actual Paper Format
556 Paper ePaper = SvxPaperInfo::GetSvxPaper( aPaperSize, MAP_100TH_MM, true );
558 if ( PAPER_USER != ePaper )
559 aPaperSize = SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM );
561 if ( bLandscape )
562 Swap( aPaperSize );
564 // write values into the edits
565 SetMetricValue( *m_pPaperHeightEdit, aPaperSize.Height(), SFX_MAPUNIT_100TH_MM );
566 SetMetricValue( *m_pPaperWidthEdit, aPaperSize.Width(), SFX_MAPUNIT_100TH_MM );
567 m_pPaperSizeBox->Clear();
569 sal_Int32 nActPos = LISTBOX_ENTRY_NOTFOUND;
570 sal_uInt16 nAryId = RID_SVXSTRARY_PAPERSIZE_STD;
572 if ( ePaperStart != PAPER_A3 )
573 nAryId = RID_SVXSTRARY_PAPERSIZE_DRAW;
574 ResStringArray aPaperAry( CUI_RES( nAryId ) );
575 sal_uInt32 nCnt = aPaperAry.Count();
577 sal_Int32 nUserPos = LISTBOX_ENTRY_NOTFOUND;
578 for ( sal_uInt32 i = 0; i < nCnt; ++i )
580 OUString aStr = aPaperAry.GetString(i);
581 Paper eSize = (Paper)aPaperAry.GetValue(i);
582 sal_Int32 nPos = m_pPaperSizeBox->InsertEntry( aStr );
583 m_pPaperSizeBox->SetEntryData( nPos, reinterpret_cast<void*>((sal_uLong)eSize) );
585 if ( eSize == ePaper )
586 nActPos = nPos;
587 if( eSize == PAPER_USER )
588 nUserPos = nPos;
590 // preselect current paper format - #115915#: ePaper might not be in aPaperSizeBox so use PAPER_USER instead
591 m_pPaperSizeBox->SelectEntryPos( nActPos != LISTBOX_ENTRY_NOTFOUND ? nActPos : nUserPos );
593 // application specific
595 switch ( eMode )
597 case SVX_PAGE_MODE_CENTER:
599 m_pTblAlignFT->Show();
600 m_pHorzBox->Show();
601 m_pVertBox->Show();
602 DisableVerticalPageDir();
604 // horizontal alignment
605 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT1 );
606 m_pHorzBox->Check( pItem && static_cast<const SfxBoolItem*>(pItem)->GetValue() );
608 // vertical alignment
609 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT2 );
610 m_pVertBox->Check( pItem && static_cast<const SfxBoolItem*>(pItem)->GetValue() );
612 // set example window on the table
613 m_pBspWin->SetTable( true );
614 m_pBspWin->SetHorz( m_pHorzBox->IsChecked() );
615 m_pBspWin->SetVert( m_pVertBox->IsChecked() );
617 break;
620 case SVX_PAGE_MODE_PRESENTATION:
622 DisableVerticalPageDir();
623 m_pAdaptBox->Show();
624 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT1 );
625 m_pAdaptBox->Check( pItem &&
626 static_cast<const SfxBoolItem*>(pItem)->GetValue() );
628 //!!! hidden, because not implemented by StarDraw
629 m_pLayoutBox->Hide();
630 m_pPageText->Hide();
632 break;
634 default: ;//prevent warning
638 // display background and border in the example
639 ResetBackground_Impl( *rSet );
640 //! UpdateExample_Impl();
641 RangeHdl_Impl( 0 );
643 InitHeadFoot_Impl( *rSet );
645 bBorderModified = false;
646 SwapFirstValues_Impl( false );
647 UpdateExample_Impl();
649 m_pLeftMarginEdit->SaveValue();
650 m_pRightMarginEdit->SaveValue();
651 m_pTopMarginEdit->SaveValue();
652 m_pBottomMarginEdit->SaveValue();
653 m_pLayoutBox->SaveValue();
654 m_pNumberFormatBox->SaveValue();
655 m_pPaperSizeBox->SaveValue();
656 m_pPaperWidthEdit->SaveValue();
657 m_pPaperHeightEdit->SaveValue();
658 m_pPortraitBtn->SaveValue();
659 m_pLandscapeBtn->SaveValue();
660 m_pPaperTrayBox->SaveValue();
661 m_pVertBox->SaveValue();
662 m_pHorzBox->SaveValue();
663 m_pAdaptBox->SaveValue();
665 CheckMarginEdits( true );
668 if(SfxItemState::SET == rSet->GetItemState(SID_SWREGISTER_MODE))
670 m_pRegisterCB->Check(static_cast<const SfxBoolItem&>(rSet->Get(
671 SID_SWREGISTER_MODE)).GetValue());
672 m_pRegisterCB->SaveValue();
673 RegisterModify(m_pRegisterCB);
675 if(SfxItemState::SET == rSet->GetItemState(SID_SWREGISTER_COLLECTION))
677 m_pRegisterLB->SelectEntry(
678 static_cast<const SfxStringItem&>(rSet->Get(SID_SWREGISTER_COLLECTION)).GetValue());
679 m_pRegisterLB->SaveValue();
682 SfxItemState eState = rSet->GetItemState( GetWhich( SID_ATTR_FRAMEDIRECTION ),
683 true, &pItem );
684 if( SfxItemState::UNKNOWN != eState )
686 sal_uInt32 nVal = SfxItemState::SET == eState
687 ? static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue()
688 : 0;
689 m_pTextFlowBox->SelectEntryValue( static_cast< SvxFrameDirection >( nVal ) );
691 m_pTextFlowBox->SaveValue();
692 m_pBspWin->SetFrameDirection(nVal);
698 void SvxPageDescPage::FillUserData()
700 if ( SVX_PAGE_MODE_PRESENTATION == eMode )
701 SetUserData( m_pAdaptBox->IsChecked() ? OUString("1") : OUString("0") ) ;
707 bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet )
709 bool bModified = false;
710 const SfxItemSet& rOldSet = GetItemSet();
711 SfxItemPool* pPool = rOldSet.GetPool();
712 DBG_ASSERT( pPool, "Wo ist der Pool" );
713 sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
714 SfxMapUnit eUnit = pPool->GetMetric( nWhich );
715 const SfxPoolItem* pOld = 0;
717 // copy old left and right margins
718 SvxLRSpaceItem aMargin( static_cast<const SvxLRSpaceItem&>(rOldSet.Get( nWhich )) );
720 // copy old top and bottom margins
721 nWhich = GetWhich( SID_ATTR_ULSPACE );
722 SvxULSpaceItem aTopMargin( static_cast<const SvxULSpaceItem&>(rOldSet.Get( nWhich )) );
724 if ( m_pLeftMarginEdit->IsValueChangedFromSaved() )
726 aMargin.SetLeft( (sal_uInt16)GetCoreValue( *m_pLeftMarginEdit, eUnit ) );
727 bModified = true;
730 if ( m_pRightMarginEdit->IsValueChangedFromSaved() )
732 aMargin.SetRight( (sal_uInt16)GetCoreValue( *m_pRightMarginEdit, eUnit ) );
733 bModified = true;
736 // set left and right margins
737 if ( bModified )
739 pOld = GetOldItem( *rSet, SID_ATTR_LRSPACE );
741 if ( !pOld || !( *static_cast<const SvxLRSpaceItem*>(pOld) == aMargin ) )
742 rSet->Put( aMargin );
743 else
744 bModified = false;
747 bool bMod = false;
749 if ( m_pTopMarginEdit->IsValueChangedFromSaved() )
751 aTopMargin.SetUpper( (sal_uInt16)GetCoreValue( *m_pTopMarginEdit, eUnit ) );
752 bMod = true;
755 if ( m_pBottomMarginEdit->IsValueChangedFromSaved() )
757 aTopMargin.SetLower( (sal_uInt16)GetCoreValue( *m_pBottomMarginEdit, eUnit ) );
758 bMod = true;
761 // set top and bottom margins
763 if ( bMod )
765 pOld = GetOldItem( *rSet, SID_ATTR_ULSPACE );
767 if ( !pOld || !( *static_cast<const SvxULSpaceItem*>(pOld) == aTopMargin ) )
769 bModified = true;
770 rSet->Put( aTopMargin );
774 // paper tray
775 nWhich = GetWhich( SID_ATTR_PAGE_PAPERBIN );
776 sal_Int32 nPos = m_pPaperTrayBox->GetSelectEntryPos();
777 sal_uInt16 nBin = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pPaperTrayBox->GetEntryData( nPos ));
778 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_PAPERBIN );
780 if ( !pOld || static_cast<const SvxPaperBinItem*>(pOld)->GetValue() != nBin )
782 rSet->Put( SvxPaperBinItem( nWhich, (sal_uInt8)nBin ) );
783 bModified = true;
786 nPos = m_pPaperSizeBox->GetSelectEntryPos();
787 Paper ePaper = (Paper)reinterpret_cast<sal_uLong>(m_pPaperSizeBox->GetEntryData( nPos ));
788 const sal_Int32 nOld = m_pPaperSizeBox->GetSavedValue();
789 bool bChecked = m_pLandscapeBtn->IsChecked();
791 if ( PAPER_USER == ePaper )
793 if ( nOld != nPos ||
794 m_pPaperWidthEdit->IsValueModified() ||
795 m_pPaperHeightEdit->IsValueModified() ||
796 m_pLandscapeBtn->IsValueChangedFromSaved() )
798 Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
799 GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
800 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_SIZE );
802 if ( !pOld || static_cast<const SvxSizeItem*>(pOld)->GetSize() != aSize )
804 rSet->Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
805 bModified = true;
809 else
811 if ( nOld != nPos || m_pLandscapeBtn->IsValueChangedFromSaved() )
813 Size aSize( SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)eUnit ) );
815 if ( bChecked )
816 Swap( aSize );
818 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_SIZE );
820 if ( !pOld || static_cast<const SvxSizeItem*>(pOld)->GetSize() != aSize )
822 rSet->Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
823 bModified = true;
828 nWhich = GetWhich( SID_ATTR_PAGE );
829 SvxPageItem aPage( static_cast<const SvxPageItem&>(rOldSet.Get( nWhich )) );
830 bMod = m_pLayoutBox->IsValueChangedFromSaved();
832 if ( bMod )
833 aPage.SetPageUsage(
834 ::PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() ) );
836 if ( m_pLandscapeBtn->IsValueChangedFromSaved() )
838 aPage.SetLandscape(bChecked);
839 bMod = true;
842 //Get the NumType value
843 nPos = m_pNumberFormatBox->GetSelectEntryPos();
844 sal_uInt16 nEntryData = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pNumberFormatBox->GetEntryData(nPos));
845 if ( m_pNumberFormatBox->IsValueChangedFromSaved() )
847 aPage.SetNumType( (SvxNumType)nEntryData );
848 bMod = true;
851 if ( bMod )
853 pOld = GetOldItem( *rSet, SID_ATTR_PAGE );
855 if ( !pOld || !( *static_cast<const SvxPageItem*>(pOld) == aPage ) )
857 rSet->Put( aPage );
858 bModified = true;
861 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich ) )
862 rSet->ClearItem( nWhich );
863 else
864 rSet->Put( rOldSet.Get( nWhich ) );
866 // evaluate mode specific controls
868 switch ( eMode )
870 case SVX_PAGE_MODE_CENTER:
872 if ( m_pHorzBox->IsValueChangedFromSaved() )
874 SfxBoolItem aHorz( GetWhich( SID_ATTR_PAGE_EXT1 ),
875 m_pHorzBox->IsChecked() );
876 rSet->Put( aHorz );
877 bModified = true;
880 if ( m_pVertBox->IsValueChangedFromSaved() )
882 SfxBoolItem aVert( GetWhich( SID_ATTR_PAGE_EXT2 ),
883 m_pVertBox->IsChecked() );
884 rSet->Put( aVert );
885 bModified = true;
887 break;
890 case SVX_PAGE_MODE_PRESENTATION:
892 // always put so that draw can evaluate this
893 rSet->Put( SfxBoolItem( GetWhich( SID_ATTR_PAGE_EXT1 ),
894 m_pAdaptBox->IsChecked() ) );
895 bModified = true;
896 break;
898 default: ;//prevent warning
902 if(m_pRegisterCB->IsVisible() &&
903 (m_pRegisterCB->IsChecked() || m_pRegisterCB->IsValueChangedFromSaved()))
905 const SfxBoolItem& rRegItem = static_cast<const SfxBoolItem&>(rOldSet.Get(SID_SWREGISTER_MODE));
906 boost::scoped_ptr<SfxBoolItem> pRegItem(static_cast<SfxBoolItem*>(rRegItem.Clone()));
907 bool bCheck = m_pRegisterCB->IsChecked();
908 pRegItem->SetValue(bCheck);
909 rSet->Put(*pRegItem);
910 bModified = true;
911 if(bCheck)
913 bModified = true;
914 rSet->Put(SfxStringItem(SID_SWREGISTER_COLLECTION,
915 m_pRegisterLB->GetSelectEntry()));
919 SvxFrameDirection eDirection = m_pTextFlowBox->GetSelectEntryValue();
920 if( m_pTextFlowBox->IsVisible() && m_pTextFlowBox->IsValueChangedFromSaved() )
922 rSet->Put( SvxFrameDirectionItem( eDirection, GetWhich( SID_ATTR_FRAMEDIRECTION ) ) );
923 bModified = true;
926 return bModified;
931 IMPL_LINK_NOARG(SvxPageDescPage, LayoutHdl_Impl)
933 // switch inside outside
934 const sal_uInt16 nPos = PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() );
936 if ( nPos == SVX_PAGE_MIRROR )
938 m_pLeftMarginLbl->Hide();
939 m_pRightMarginLbl->Hide();
940 m_pInsideLbl->Show();
941 m_pOutsideLbl->Show();
943 else
945 m_pLeftMarginLbl->Show();
946 m_pRightMarginLbl->Show();
947 m_pInsideLbl->Hide();
948 m_pOutsideLbl->Hide();
950 UpdateExample_Impl( true );
951 return 0;
956 IMPL_LINK_NOARG(SvxPageDescPage, PaperBinHdl_Impl)
958 if ( m_pPaperTrayBox->GetEntryCount() > 1 )
959 // already filled
960 return 0;
962 OUString aOldName = m_pPaperTrayBox->GetSelectEntry();
963 m_pPaperTrayBox->SetUpdateMode( false );
964 m_pPaperTrayBox->Clear();
965 sal_Int32 nEntryPos = m_pPaperTrayBox->InsertEntry(
966 EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS ) );
967 m_pPaperTrayBox->SetEntryData( nEntryPos,
968 reinterpret_cast<void*>((sal_uLong)PAPERBIN_PRINTER_SETTINGS) );
969 OUString aPaperBin( EditResId( RID_SVXSTR_PAPERBIN ) );
970 sal_uInt16 nBinCount = mpDefPrinter->GetPaperBinCount();
972 for ( sal_uInt16 i = 0; i < nBinCount; ++i )
974 OUString aName = mpDefPrinter->GetPaperBinName(i);
976 if ( aName.isEmpty() )
978 aName = aPaperBin;
979 aName += " ";
980 aName += OUString::number( i+1 );
982 nEntryPos = m_pPaperTrayBox->InsertEntry( aName );
983 m_pPaperTrayBox->SetEntryData( nEntryPos, reinterpret_cast<void*>((sal_uLong)i) );
985 m_pPaperTrayBox->SelectEntry( aOldName );
986 m_pPaperTrayBox->SetUpdateMode( true );
988 return 0;
993 IMPL_LINK( SvxPageDescPage, PaperSizeSelect_Impl, ListBox *, pBox )
995 const sal_Int32 nPos = pBox->GetSelectEntryPos();
996 Paper ePaper = (Paper)reinterpret_cast<sal_uLong>(m_pPaperSizeBox->GetEntryData( nPos ));
998 if ( ePaper != PAPER_USER )
1000 Size aSize( SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM ) );
1002 if ( m_pLandscapeBtn->IsChecked() )
1003 Swap( aSize );
1005 if ( aSize.Height() < m_pPaperHeightEdit->GetMin( FUNIT_100TH_MM ) )
1006 m_pPaperHeightEdit->SetMin(
1007 m_pPaperHeightEdit->Normalize( aSize.Height() ), FUNIT_100TH_MM );
1008 if ( aSize.Width() < m_pPaperWidthEdit->GetMin( FUNIT_100TH_MM ) )
1009 m_pPaperWidthEdit->SetMin(
1010 m_pPaperWidthEdit->Normalize( aSize.Width() ), FUNIT_100TH_MM );
1011 SetMetricValue( *m_pPaperHeightEdit, aSize.Height(), SFX_MAPUNIT_100TH_MM );
1012 SetMetricValue( *m_pPaperWidthEdit, aSize.Width(), SFX_MAPUNIT_100TH_MM );
1014 CalcMargin_Impl();
1016 RangeHdl_Impl( 0 );
1017 UpdateExample_Impl( true );
1019 if ( eMode == SVX_PAGE_MODE_PRESENTATION )
1021 // Draw: if paper format the margin shall be 1 cm
1022 long nTmp = 0;
1023 bool bScreen = (( PAPER_SCREEN_4_3 == ePaper )||( PAPER_SCREEN_16_9 == ePaper)||( PAPER_SCREEN_16_10 == ePaper));
1025 if ( !bScreen )
1026 // no margin if screen
1027 nTmp = 1; // accordingly 1 cm
1029 if ( bScreen || m_pRightMarginEdit->GetValue() == 0 )
1031 SetMetricValue( *m_pRightMarginEdit, nTmp, SFX_MAPUNIT_CM );
1032 if ( !bScreen &&
1033 m_pRightMarginEdit->GetFirst() > m_pRightMarginEdit->GetValue() )
1034 m_pRightMarginEdit->SetValue( m_pRightMarginEdit->GetFirst() );
1036 if ( bScreen || m_pLeftMarginEdit->GetValue() == 0 )
1038 SetMetricValue( *m_pLeftMarginEdit, nTmp, SFX_MAPUNIT_CM );
1039 if ( !bScreen &&
1040 m_pLeftMarginEdit->GetFirst() > m_pLeftMarginEdit->GetValue() )
1041 m_pLeftMarginEdit->SetValue( m_pLeftMarginEdit->GetFirst() );
1043 if ( bScreen || m_pBottomMarginEdit->GetValue() == 0 )
1045 SetMetricValue( *m_pBottomMarginEdit, nTmp, SFX_MAPUNIT_CM );
1046 if ( !bScreen &&
1047 m_pBottomMarginEdit->GetFirst() > m_pBottomMarginEdit->GetValue() )
1048 m_pBottomMarginEdit->SetValue( m_pBottomMarginEdit->GetFirst() );
1050 if ( bScreen || m_pTopMarginEdit->GetValue() == 0 )
1052 SetMetricValue( *m_pTopMarginEdit, nTmp, SFX_MAPUNIT_CM );
1053 if ( !bScreen &&
1054 m_pTopMarginEdit->GetFirst() > m_pTopMarginEdit->GetValue() )
1055 m_pTopMarginEdit->SetValue( m_pTopMarginEdit->GetFirst() );
1057 UpdateExample_Impl( true );
1060 return 0;
1065 IMPL_LINK_NOARG(SvxPageDescPage, PaperSizeModify_Impl)
1067 sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
1068 SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
1069 Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
1070 GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
1071 Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, (MapUnit)eUnit, true );
1072 sal_Int32 nEntryCount = m_pPaperSizeBox->GetEntryCount();
1074 for ( sal_Int32 i = 0; i < nEntryCount; ++i )
1076 Paper eTmp = (Paper)reinterpret_cast<sal_uLong>(m_pPaperSizeBox->GetEntryData(i));
1078 if ( eTmp == ePaper )
1080 m_pPaperSizeBox->SelectEntryPos(i);
1081 break;
1084 UpdateExample_Impl( true );
1085 return 0;
1090 IMPL_LINK( SvxPageDescPage, SwapOrientation_Impl, RadioButton *, pBtn )
1092 if (
1093 (!bLandscape && pBtn == m_pLandscapeBtn) ||
1094 (bLandscape && pBtn == m_pPortraitBtn)
1097 bLandscape = m_pLandscapeBtn->IsChecked();
1099 const long lWidth = GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_100TH_MM );
1100 const long lHeight = GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_100TH_MM );
1102 // swap width and height
1103 SetMetricValue( *m_pPaperWidthEdit, lHeight, SFX_MAPUNIT_100TH_MM );
1104 SetMetricValue( *m_pPaperHeightEdit, lWidth, SFX_MAPUNIT_100TH_MM );
1106 // recalculate margins if necessary
1107 CalcMargin_Impl();
1109 PaperSizeSelect_Impl( m_pPaperSizeBox );
1110 RangeHdl_Impl( 0 );
1111 SwapFirstValues_Impl( bBorderModified );
1112 UpdateExample_Impl( true );
1114 return 0;
1119 void SvxPageDescPage::SwapFirstValues_Impl( bool bSet )
1121 MapMode aOldMode = mpDefPrinter->GetMapMode();
1122 Orientation eOri = ORIENTATION_PORTRAIT;
1124 if ( bLandscape )
1125 eOri = ORIENTATION_LANDSCAPE;
1126 Orientation eOldOri = mpDefPrinter->GetOrientation();
1127 mpDefPrinter->SetOrientation( eOri );
1128 mpDefPrinter->SetMapMode( MAP_TWIP );
1130 // set first- and last-values for margins
1131 Size aPaperSize = mpDefPrinter->GetPaperSize();
1132 Size aPrintSize = mpDefPrinter->GetOutputSize();
1134 * To convert a point ( 0,0 ) into logic coordinates
1135 * looks like nonsense; but it makes sense if the
1136 * coordinate system's origin has been moved.
1138 Point aPrintOffset = mpDefPrinter->GetPageOffset() - mpDefPrinter->PixelToLogic( Point() );
1139 mpDefPrinter->SetMapMode( aOldMode );
1140 mpDefPrinter->SetOrientation( eOldOri );
1142 sal_Int64 nSetL = m_pLeftMarginEdit->Denormalize(
1143 m_pLeftMarginEdit->GetValue( FUNIT_TWIP ) );
1144 sal_Int64 nSetR = m_pRightMarginEdit->Denormalize(
1145 m_pRightMarginEdit->GetValue( FUNIT_TWIP ) );
1146 sal_Int64 nSetT = m_pTopMarginEdit->Denormalize(
1147 m_pTopMarginEdit->GetValue( FUNIT_TWIP ) );
1148 sal_Int64 nSetB = m_pBottomMarginEdit->Denormalize(
1149 m_pBottomMarginEdit->GetValue( FUNIT_TWIP ) );
1151 long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
1152 long nNewL = aPrintOffset.X();
1153 long nNewR =
1154 aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset;
1155 long nNewT = aPrintOffset.Y();
1156 long nNewB =
1157 aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset;
1159 m_pLeftMarginEdit->SetFirst( m_pLeftMarginEdit->Normalize( nNewL ), FUNIT_TWIP );
1160 nFirstLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetFirst());
1161 m_pRightMarginEdit->SetFirst( m_pRightMarginEdit->Normalize( nNewR ), FUNIT_TWIP );
1162 nFirstRightMargin = static_cast<long>(m_pRightMarginEdit->GetFirst());
1163 m_pTopMarginEdit->SetFirst( m_pTopMarginEdit->Normalize( nNewT ), FUNIT_TWIP );
1164 nFirstTopMargin = static_cast<long>(m_pTopMarginEdit->GetFirst());
1165 m_pBottomMarginEdit->SetFirst( m_pBottomMarginEdit->Normalize( nNewB ), FUNIT_TWIP );
1166 nFirstBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetFirst());
1168 if ( bSet )
1170 if ( nSetL < nNewL )
1171 m_pLeftMarginEdit->SetValue( m_pLeftMarginEdit->Normalize( nNewL ),
1172 FUNIT_TWIP );
1173 if ( nSetR < nNewR )
1174 m_pRightMarginEdit->SetValue( m_pRightMarginEdit->Normalize( nNewR ),
1175 FUNIT_TWIP );
1176 if ( nSetT < nNewT )
1177 m_pTopMarginEdit->SetValue( m_pTopMarginEdit->Normalize( nNewT ),
1178 FUNIT_TWIP );
1179 if ( nSetB < nNewB )
1180 m_pBottomMarginEdit->SetValue( m_pBottomMarginEdit->Normalize( nNewB ),
1181 FUNIT_TWIP );
1187 IMPL_LINK_NOARG(SvxPageDescPage, BorderModify_Impl)
1189 if ( !bBorderModified )
1190 bBorderModified = true;
1191 UpdateExample_Impl();
1192 return 0;
1195 void SvxPageDescPage::UpdateExample_Impl( bool bResetbackground )
1197 // Size
1198 Size aSize( GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_TWIP ),
1199 GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_TWIP ) );
1201 m_pBspWin->SetSize( aSize );
1203 // Margins
1204 m_pBspWin->SetTop( GetCoreValue( *m_pTopMarginEdit, SFX_MAPUNIT_TWIP ) );
1205 m_pBspWin->SetBottom( GetCoreValue( *m_pBottomMarginEdit, SFX_MAPUNIT_TWIP ) );
1206 m_pBspWin->SetLeft( GetCoreValue( *m_pLeftMarginEdit, SFX_MAPUNIT_TWIP ) );
1207 m_pBspWin->SetRight( GetCoreValue( *m_pRightMarginEdit, SFX_MAPUNIT_TWIP ) );
1209 // Layout
1210 m_pBspWin->SetUsage( PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() ) );
1211 if ( bResetbackground )
1212 m_pBspWin->ResetBackground();
1213 m_pBspWin->Invalidate();
1218 void SvxPageDescPage::ResetBackground_Impl(const SfxItemSet& rSet)
1220 sal_uInt16 nWhich(GetWhich(SID_ATTR_PAGE_HEADERSET));
1222 if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
1224 const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false));
1225 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1226 const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)));
1228 if(rOn.GetValue())
1230 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes;
1232 if(mbEnableDrawingLayerFillStyles)
1234 //UUUU create FillAttributes directly from DrawingLayer FillStyle entries
1235 aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(rTmpSet));
1237 else
1239 nWhich = GetWhich(SID_ATTR_BRUSH);
1241 if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
1243 //UUUU create FillAttributes from SvxBrushItem
1244 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
1245 SfxItemSet aTempSet(*rTmpSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
1247 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1248 aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
1252 m_pBspWin->setHeaderFillAttributes(aHeaderFillAttributes);
1253 nWhich = GetWhich(SID_ATTR_BORDER_OUTER);
1255 if(rTmpSet.GetItemState(nWhich) == SfxItemState::SET)
1257 const SvxBoxItem& rItem =
1258 static_cast<const SvxBoxItem&>(rTmpSet.Get( nWhich ));
1259 m_pBspWin->SetHdBorder( rItem );
1264 nWhich = GetWhich(SID_ATTR_PAGE_FOOTERSET);
1266 if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
1268 const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich,false));
1269 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1270 const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ON)));
1272 if(rOn.GetValue())
1274 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes;
1276 if(mbEnableDrawingLayerFillStyles)
1278 //UUUU create FillAttributes directly from DrawingLayer FillStyle entries
1279 aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(rTmpSet));
1281 else
1283 nWhich = GetWhich(SID_ATTR_BRUSH);
1285 if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
1287 //UUUU create FillAttributes from SvxBrushItem
1288 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
1289 SfxItemSet aTempSet(*rTmpSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
1291 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1292 aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
1296 m_pBspWin->setFooterFillAttributes(aFooterFillAttributes);
1297 nWhich = GetWhich(SID_ATTR_BORDER_OUTER);
1299 if(rTmpSet.GetItemState(nWhich) == SfxItemState::SET)
1301 const SvxBoxItem& rItem = static_cast< const SvxBoxItem& >(rTmpSet.Get(nWhich));
1302 m_pBspWin->SetFtBorder(rItem);
1307 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aPageFillAttributes;
1308 const SfxPoolItem* pItem = 0;
1310 if(mbEnableDrawingLayerFillStyles)
1312 //UUUU create FillAttributes directly from DrawingLayer FillStyle entries
1313 aPageFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(rSet));
1315 else
1317 pItem = GetItem(rSet, SID_ATTR_BRUSH);
1319 if(pItem)
1321 //UUUU create FillAttributes from SvxBrushItem
1322 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem);
1323 SfxItemSet aTempSet(*rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
1325 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1326 aPageFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
1330 m_pBspWin->setPageFillAttributes(aPageFillAttributes);
1331 pItem = GetItem(rSet, SID_ATTR_BORDER_OUTER);
1333 if(pItem)
1335 m_pBspWin->SetBorder(static_cast< const SvxBoxItem& >(*pItem));
1339 void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
1341 bLandscape = m_pLandscapeBtn->IsChecked();
1342 const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
1344 if ( pItem )
1345 m_pBspWin->SetSize( static_cast<const SvxSizeItem*>(pItem)->GetSize() );
1347 const SvxSetItem* pSetItem = 0;
1349 // evaluate header attributes
1351 if ( SfxItemState::SET ==
1352 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
1353 false, reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
1355 const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
1356 const SfxBoolItem& rHeaderOn =
1357 static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ));
1359 if ( rHeaderOn.GetValue() )
1361 const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(
1362 rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ));
1363 const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(
1364 rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) ));
1365 long nDist = rUL.GetLower();
1366 m_pBspWin->SetHdHeight( rSize.GetSize().Height() - nDist );
1367 m_pBspWin->SetHdDist( nDist );
1368 const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(
1369 rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) ));
1370 m_pBspWin->SetHdLeft( rLR.GetLeft() );
1371 m_pBspWin->SetHdRight( rLR.GetRight() );
1372 m_pBspWin->SetHeader( true );
1374 else
1375 m_pBspWin->SetHeader( false );
1377 // show background and border in the example
1378 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes;
1380 if(mbEnableDrawingLayerFillStyles)
1382 //UUUU create FillAttributes directly from DrawingLayer FillStyle entries
1383 aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(rHeaderSet));
1385 else
1387 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BRUSH));
1389 if(rHeaderSet.GetItemState(nWhich) >= SfxItemState::DEFAULT)
1391 //UUUU aBspWin.SetHdColor(rItem.GetColor());
1392 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rHeaderSet.Get(nWhich));
1393 SfxItemSet aTempSet(*rHeaderSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
1395 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1396 aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
1400 m_pBspWin->setHeaderFillAttributes(aHeaderFillAttributes);
1401 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BORDER_OUTER));
1403 if ( rHeaderSet.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
1405 const SvxBoxItem& rItem =
1406 static_cast<const SvxBoxItem&>(rHeaderSet.Get( nWhich ));
1407 m_pBspWin->SetHdBorder( rItem );
1411 // evaluate footer attributes
1413 if ( SfxItemState::SET ==
1414 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
1415 false, reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
1417 const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
1418 const SfxBoolItem& rFooterOn =
1419 static_cast<const SfxBoolItem&>(rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) ));
1421 if ( rFooterOn.GetValue() )
1423 const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(
1424 rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) ));
1425 const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(
1426 rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) ));
1427 long nDist = rUL.GetUpper();
1428 m_pBspWin->SetFtHeight( rSize.GetSize().Height() - nDist );
1429 m_pBspWin->SetFtDist( nDist );
1430 const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(
1431 rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) ));
1432 m_pBspWin->SetFtLeft( rLR.GetLeft() );
1433 m_pBspWin->SetFtRight( rLR.GetRight() );
1434 m_pBspWin->SetFooter( true );
1436 else
1437 m_pBspWin->SetFooter( false );
1439 // show background and border in the example
1440 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes;
1442 if(mbEnableDrawingLayerFillStyles)
1444 //UUUU create FillAttributes directly from DrawingLayer FillStyle entries
1445 aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(rFooterSet));
1447 else
1449 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BRUSH));
1451 if(rFooterSet.GetItemState(nWhich) >= SfxItemState::DEFAULT)
1453 //UUUU aBspWin.SetFtColor(rItem.GetColor());
1454 const SvxBrushItem& rItem = static_cast<const SvxBrushItem&>(rFooterSet.Get(nWhich));
1455 SfxItemSet aTempSet(*rFooterSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
1457 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1458 aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
1462 m_pBspWin->setFooterFillAttributes(aFooterFillAttributes);
1463 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BORDER_OUTER));
1465 if ( rFooterSet.GetItemState( nWhich ) >= SfxItemState::DEFAULT )
1467 const SvxBoxItem& rItem =
1468 static_cast<const SvxBoxItem&>(rFooterSet.Get( nWhich ));
1469 m_pBspWin->SetFtBorder( rItem );
1476 void SvxPageDescPage::ActivatePage( const SfxItemSet& rSet )
1478 InitHeadFoot_Impl( rSet );
1479 UpdateExample_Impl();
1480 ResetBackground_Impl( rSet );
1481 RangeHdl_Impl( 0 );
1486 SfxTabPage::sfxpg SvxPageDescPage::DeactivatePage( SfxItemSet* _pSet )
1488 // Inquiry whether the page margins are beyond the printing area.
1489 // If not, ask user whether they shall be taken.
1490 // If not, stay on the TabPage.
1491 sal_Int32 nPos = m_pPaperSizeBox->GetSelectEntryPos();
1492 Paper ePaper = (Paper)reinterpret_cast<sal_uLong>(m_pPaperSizeBox->GetEntryData( nPos ));
1494 if ( ePaper != PAPER_SCREEN_4_3 && ePaper != PAPER_SCREEN_16_9 && ePaper != PAPER_SCREEN_16_10 && IsMarginOutOfRange() )
1496 if ( ScopedVclPtr<QueryBox>::Create( this, WB_YES_NO | WB_DEF_NO, m_pPrintRangeQueryText->GetText() )->Execute() == RET_NO )
1498 MetricField* pField = NULL;
1499 if ( IsPrinterRangeOverflow( *m_pLeftMarginEdit, nFirstLeftMargin, nLastLeftMargin, MARGIN_LEFT ) )
1500 pField = m_pLeftMarginEdit;
1501 if ( IsPrinterRangeOverflow( *m_pRightMarginEdit, nFirstRightMargin, nLastRightMargin, MARGIN_RIGHT )
1502 && !pField )
1503 pField = m_pRightMarginEdit;
1504 if ( IsPrinterRangeOverflow( *m_pTopMarginEdit, nFirstTopMargin, nLastTopMargin, MARGIN_TOP )
1505 && !pField )
1506 pField = m_pTopMarginEdit;
1507 if ( IsPrinterRangeOverflow( *m_pBottomMarginEdit, nFirstBottomMargin, nLastBottomMargin, MARGIN_BOTTOM )
1508 && !pField )
1509 pField = m_pBottomMarginEdit;
1510 if ( pField )
1511 pField->GrabFocus();
1512 UpdateExample_Impl();
1513 return KEEP_PAGE;
1515 else
1516 CheckMarginEdits( false );
1519 if ( _pSet )
1521 FillItemSet( _pSet );
1523 // put portray/landscape if applicable
1524 sal_uInt16 nWh = GetWhich( SID_ATTR_PAGE_SIZE );
1525 SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWh );
1526 Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
1527 GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
1529 // put, if current size is different to the value in _pSet
1530 const SvxSizeItem* pSize = static_cast<const SvxSizeItem*>(GetItem( *_pSet, SID_ATTR_PAGE_SIZE ));
1531 if ( aSize.Width() && ( !pSize || !IsEqualSize_Impl( pSize, aSize ) ) )
1532 _pSet->Put( SvxSizeItem( nWh, aSize ) );
1535 return LEAVE_PAGE;
1540 IMPL_LINK_NOARG(SvxPageDescPage, RangeHdl_Impl)
1542 // example window
1543 long nHHeight = m_pBspWin->GetHdHeight();
1544 long nHDist = m_pBspWin->GetHdDist();
1546 long nFHeight = m_pBspWin->GetFtHeight();
1547 long nFDist = m_pBspWin->GetFtDist();
1549 long nHFLeft = std::max( m_pBspWin->GetHdLeft(), m_pBspWin->GetFtLeft() );
1550 long nHFRight = std::max( m_pBspWin->GetHdRight(), m_pBspWin->GetFtRight() );
1552 // current values for page margins
1553 long nBT = static_cast<long>(m_pTopMarginEdit->Denormalize(m_pTopMarginEdit->GetValue(FUNIT_TWIP)));
1554 long nBB = static_cast<long>(m_pBottomMarginEdit->Denormalize(m_pBottomMarginEdit->GetValue(FUNIT_TWIP)));
1555 long nBL = static_cast<long>(m_pLeftMarginEdit->Denormalize(m_pLeftMarginEdit->GetValue(FUNIT_TWIP)));
1556 long nBR = static_cast<long>(m_pRightMarginEdit->Denormalize(m_pRightMarginEdit->GetValue(FUNIT_TWIP)));
1558 // calculate width of page border
1559 const SfxItemSet* _pSet = &GetItemSet();
1560 Size aBorder;
1562 if ( _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_SHADOW) ) >=
1563 SfxItemState::DEFAULT &&
1564 _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_OUTER) ) >=
1565 SfxItemState::DEFAULT )
1567 aBorder = GetMinBorderSpace_Impl(
1568 static_cast<const SvxShadowItem&>(_pSet->Get(GetWhich(SID_ATTR_BORDER_SHADOW))),
1569 static_cast<const SvxBoxItem&>(_pSet->Get(GetWhich(SID_ATTR_BORDER_OUTER))));
1572 // limits paper
1573 // maximum is 54 cm
1575 long nMin = nHHeight + nHDist + nFDist + nFHeight + nBT + nBB +
1576 MINBODY + aBorder.Height();
1577 m_pPaperHeightEdit->SetMin(m_pPaperHeightEdit->Normalize(nMin), FUNIT_TWIP);
1579 nMin = MINBODY + nBL + nBR + aBorder.Width();
1580 m_pPaperWidthEdit->SetMin(m_pPaperWidthEdit->Normalize(nMin), FUNIT_TWIP);
1582 long nH = static_cast<long>(m_pPaperHeightEdit->Denormalize(m_pPaperHeightEdit->GetValue(FUNIT_TWIP)));
1583 long nW = static_cast<long>(m_pPaperWidthEdit->Denormalize(m_pPaperWidthEdit->GetValue(FUNIT_TWIP)));
1585 // Top
1586 long nMax = nH - nBB - aBorder.Height() - MINBODY -
1587 nFDist - nFHeight - nHDist - nHHeight;
1589 m_pTopMarginEdit->SetMax(m_pTopMarginEdit->Normalize(nMax), FUNIT_TWIP);
1591 // Bottom
1592 nMax = nH - nBT - aBorder.Height() - MINBODY -
1593 nFDist - nFHeight - nHDist - nHHeight;
1595 m_pBottomMarginEdit->SetMax(m_pTopMarginEdit->Normalize(nMax), FUNIT_TWIP);
1597 // Left
1598 nMax = nW - nBR - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1599 m_pLeftMarginEdit->SetMax(m_pLeftMarginEdit->Normalize(nMax), FUNIT_TWIP);
1601 // Right
1602 nMax = nW - nBL - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1603 m_pRightMarginEdit->SetMax(m_pRightMarginEdit->Normalize(nMax), FUNIT_TWIP);
1604 return 0;
1609 void SvxPageDescPage::CalcMargin_Impl()
1611 // current values for page margins
1612 long nBT = GetCoreValue( *m_pTopMarginEdit, SFX_MAPUNIT_TWIP );
1613 long nBB = GetCoreValue( *m_pBottomMarginEdit, SFX_MAPUNIT_TWIP );
1615 long nBL = GetCoreValue( *m_pLeftMarginEdit, SFX_MAPUNIT_TWIP );
1616 long nBR = GetCoreValue( *m_pRightMarginEdit, SFX_MAPUNIT_TWIP );
1618 long nH = GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_TWIP );
1619 long nW = GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_TWIP );
1621 long nWidth = nBL + nBR + MINBODY;
1622 long nHeight = nBT + nBB + MINBODY;
1624 if ( nWidth > nW || nHeight > nH )
1626 if ( nWidth > nW )
1628 long nTmp = nBL <= nBR ? nBR : nBL;
1629 nTmp -= nWidth - nW;
1631 if ( nBL <= nBR )
1632 SetMetricValue( *m_pRightMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1633 else
1634 SetMetricValue( *m_pLeftMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1637 if ( nHeight > nH )
1639 long nTmp = nBT <= nBB ? nBB : nBT;
1640 nTmp -= nHeight - nH;
1642 if ( nBT <= nBB )
1643 SetMetricValue( *m_pBottomMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1644 else
1645 SetMetricValue( *m_pTopMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1652 IMPL_LINK_NOARG(SvxPageDescPage, CenterHdl_Impl)
1654 m_pBspWin->SetHorz( m_pHorzBox->IsChecked() );
1655 m_pBspWin->SetVert( m_pVertBox->IsChecked() );
1656 UpdateExample_Impl();
1657 return 0;
1660 void SvxPageDescPage::SetCollectionList(const std::vector<OUString> &aList)
1662 OSL_ENSURE(!aList.empty(), "Empty string list");
1664 sStandardRegister = aList[0];
1665 for( size_t i = 1; i < aList.size(); i++ )
1666 m_pRegisterLB->InsertEntry(aList[i]);
1668 m_pRegisterCB->Show();
1669 m_pRegisterFT->Show();
1670 m_pRegisterLB->Show();
1671 m_pRegisterCB->SetClickHdl(LINK(this, SvxPageDescPage, RegisterModify));
1676 IMPL_LINK( SvxPageDescPage, RegisterModify, CheckBox*, pBox )
1678 bool bEnable = false;
1679 if(pBox->IsChecked())
1681 bEnable = true;
1682 if(USHRT_MAX == m_pRegisterLB->GetSelectEntryPos())
1683 m_pRegisterLB->SelectEntry(sStandardRegister);
1685 m_pRegisterFT->Enable( bEnable );
1686 m_pRegisterLB->Enable( bEnable );
1687 return 0;
1692 void SvxPageDescPage::DisableVerticalPageDir()
1694 m_pTextFlowBox->RemoveEntryValue( FRMDIR_VERT_TOP_RIGHT );
1695 m_pTextFlowBox->RemoveEntryValue( FRMDIR_VERT_TOP_LEFT );
1696 if( m_pTextFlowBox->GetEntryCount() < 2 )
1698 m_pTextFlowLbl->Hide();
1699 m_pTextFlowBox->Hide();
1700 m_pBspWin->EnableFrameDirection( false );
1704 IMPL_LINK( SvxPageDescPage, FrameDirectionModify_Impl, ListBox*,)
1706 m_pBspWin->SetFrameDirection( (sal_uInt32) m_pTextFlowBox->GetSelectEntryValue() );
1707 m_pBspWin->Invalidate();
1708 return 0;
1711 bool SvxPageDescPage::IsPrinterRangeOverflow(
1712 MetricField& rField, long nFirstMargin, long nLastMargin, MarginPosition nPos )
1714 bool bRet = false;
1715 bool bCheck = ( ( m_nPos & nPos ) == 0 );
1716 long nValue = static_cast<long>(rField.GetValue());
1717 if ( bCheck &&
1718 ( nValue < nFirstMargin || nValue > nLastMargin ) &&
1719 rField.IsValueChangedFromSaved() )
1721 rField.SetValue( nValue < nFirstMargin ? nFirstMargin : nLastMargin );
1722 bRet = true;
1725 return bRet;
1728 /** Check if a value of a margin edit is outside the printer paper margins
1729 and save this information.
1731 void SvxPageDescPage::CheckMarginEdits( bool _bClear )
1733 if ( _bClear )
1734 m_nPos = 0;
1736 sal_Int64 nValue = m_pLeftMarginEdit->GetValue();
1737 if ( nValue < nFirstLeftMargin || nValue > nLastLeftMargin )
1738 m_nPos |= MARGIN_LEFT;
1739 nValue = m_pRightMarginEdit->GetValue();
1740 if ( nValue < nFirstRightMargin || nValue > nLastRightMargin )
1741 m_nPos |= MARGIN_RIGHT;
1742 nValue = m_pTopMarginEdit->GetValue();
1743 if ( nValue < nFirstTopMargin || nValue > nLastTopMargin )
1744 m_nPos |= MARGIN_TOP;
1745 nValue = m_pBottomMarginEdit->GetValue();
1746 if ( nValue < nFirstBottomMargin || nValue > nLastBottomMargin )
1747 m_nPos |= MARGIN_BOTTOM;
1750 bool SvxPageDescPage::IsMarginOutOfRange()
1752 bool bRet = ( ( ( !( m_nPos & MARGIN_LEFT ) &&
1753 m_pLeftMarginEdit->IsValueChangedFromSaved() ) &&
1754 ( m_pLeftMarginEdit->GetValue() < nFirstLeftMargin ||
1755 m_pLeftMarginEdit->GetValue() > nLastLeftMargin ) ) ||
1756 ( ( !( m_nPos & MARGIN_RIGHT ) &&
1757 m_pRightMarginEdit->IsValueChangedFromSaved() ) &&
1758 ( m_pRightMarginEdit->GetValue() < nFirstRightMargin ||
1759 m_pRightMarginEdit->GetValue() > nLastRightMargin ) ) ||
1760 ( ( !( m_nPos & MARGIN_TOP ) &&
1761 m_pTopMarginEdit->IsValueChangedFromSaved() ) &&
1762 ( m_pTopMarginEdit->GetValue() < nFirstTopMargin ||
1763 m_pTopMarginEdit->GetValue() > nLastTopMargin ) ) ||
1764 ( ( !( m_nPos & MARGIN_BOTTOM ) &&
1765 m_pBottomMarginEdit->IsValueChangedFromSaved() ) &&
1766 ( m_pBottomMarginEdit->GetValue() < nFirstBottomMargin ||
1767 m_pBottomMarginEdit->GetValue() > nLastBottomMargin ) ) );
1768 return bRet;
1771 void SvxPageDescPage::PageCreated(const SfxAllItemSet& aSet)
1773 SFX_ITEMSET_ARG (&aSet,pModeItem,SfxAllEnumItem,SID_ENUM_PAGE_MODE,false);
1774 SFX_ITEMSET_ARG (&aSet,pPaperStartItem,SfxAllEnumItem,SID_PAPER_START,false);
1775 SFX_ITEMSET_ARG (&aSet,pPaperEndItem,SfxAllEnumItem,SID_PAPER_END,false);
1776 SFX_ITEMSET_ARG (&aSet,pCollectListItem,SfxStringListItem,SID_COLLECT_LIST,false);
1778 //UUUU
1779 SFX_ITEMSET_ARG (&aSet, pSupportDrawingLayerFillStyleItem, SfxBoolItem, SID_DRAWINGLAYER_FILLSTYLES, false);
1781 if (pModeItem)
1783 SetMode((SvxModeType)pModeItem->GetEnumValue());
1786 if(pPaperStartItem && pPaperEndItem)
1788 SetPaperFormatRanges((Paper)pPaperStartItem->GetEnumValue(),(Paper)pPaperEndItem->GetEnumValue());
1791 if(pCollectListItem)
1793 SetCollectionList(pCollectListItem->GetList());
1796 if(pSupportDrawingLayerFillStyleItem)
1798 const bool bNew(pSupportDrawingLayerFillStyleItem->GetValue());
1800 EnableDrawingLayerFillStyles(bNew);
1804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */