Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/app.hxx>
21 : #include <sfx2/objsh.hxx>
22 : #include <tools/resary.hxx>
23 : #include <vcl/graph.hxx>
24 : #include <sfx2/viewsh.hxx>
25 : #include <svl/itemiter.hxx>
26 : #include <svl/languageoptions.hxx>
27 : #include <vcl/msgbox.hxx>
28 : #include <unotools/configitem.hxx>
29 : #include <sfx2/htmlmode.hxx>
30 : #include <sal/macros.h>
31 :
32 : #include <cuires.hrc>
33 : #include "helpid.hrc"
34 : #include "page.hxx"
35 : #include <svx/pageitem.hxx>
36 : #include <editeng/brushitem.hxx>
37 : #include <editeng/boxitem.hxx>
38 : #include <editeng/shaditem.hxx>
39 : #include <editeng/pbinitem.hxx>
40 : #include <editeng/lrspitem.hxx>
41 : #include <editeng/ulspitem.hxx>
42 : #include <editeng/sizeitem.hxx>
43 : #include <editeng/frmdiritem.hxx>
44 : #include "svx/dlgutil.hxx"
45 : #include <editeng/paperinf.hxx>
46 : #include <dialmgr.hxx>
47 : #include <sfx2/module.hxx>
48 : #include <svl/stritem.hxx>
49 : #include <svx/dialogs.hrc>
50 : #include <editeng/eerdll.hxx>
51 : #include <editeng/editrids.hrc>
52 : #include <svx/svxids.hrc>
53 :
54 : // #i4219#
55 : #include <svtools/optionsdrawinglayer.hxx>
56 : #include <svl/slstitm.hxx>
57 : #include <svl/aeitem.hxx>
58 : #include <sfx2/request.hxx>
59 :
60 : #include <numpages.hxx>
61 :
62 : // static ----------------------------------------------------------------
63 :
64 : static const long MINBODY = 284; // 0,5 cm rounded up in twips
65 : //static const long PRINT_OFFSET = 17; // 0,03 cm rounded down in twips
66 : static const long PRINT_OFFSET = 0; // why was this ever set to 17 ? it led to wrong right and bottom margins.
67 :
68 : static sal_uInt16 pRanges[] =
69 : {
70 : SID_ATTR_BORDER_OUTER,
71 : SID_ATTR_BORDER_SHADOW,
72 : SID_ATTR_LRSPACE,
73 : SID_ATTR_PAGE_SHARED,
74 : SID_SWREGISTER_COLLECTION,
75 : SID_SWREGISTER_MODE,
76 : 0
77 : };
78 : // ------- Mapping page layout ------------------------------------------
79 :
80 : sal_uInt16 aArr[] =
81 : {
82 : SVX_PAGE_ALL,
83 : SVX_PAGE_MIRROR,
84 : SVX_PAGE_RIGHT,
85 : SVX_PAGE_LEFT
86 : };
87 :
88 :
89 :
90 0 : sal_uInt16 PageUsageToPos_Impl( sal_uInt16 nUsage )
91 : {
92 0 : for ( sal_uInt16 i = 0; i < SAL_N_ELEMENTS(aArr); ++i )
93 0 : if ( aArr[i] == ( nUsage & 0x000f ) )
94 0 : return i;
95 0 : return SVX_PAGE_ALL;
96 : }
97 :
98 :
99 :
100 0 : sal_uInt16 PosToPageUsage_Impl( sal_uInt16 nPos )
101 : {
102 0 : if ( nPos >= SAL_N_ELEMENTS(aArr) )
103 0 : return 0;
104 0 : return aArr[nPos];
105 : }
106 :
107 :
108 :
109 0 : Size GetMinBorderSpace_Impl( const SvxShadowItem& rShadow, const SvxBoxItem& rBox )
110 : {
111 0 : Size aSz;
112 0 : aSz.Height() = rShadow.CalcShadowSpace( SHADOW_BOTTOM ) + rBox.CalcLineSpace( BOX_LINE_BOTTOM );
113 0 : aSz.Height() += rShadow.CalcShadowSpace( SHADOW_TOP ) + rBox.CalcLineSpace( BOX_LINE_TOP );
114 0 : aSz.Width() = rShadow.CalcShadowSpace( SHADOW_LEFT ) + rBox.CalcLineSpace( BOX_LINE_LEFT );
115 0 : aSz.Width() += rShadow.CalcShadowSpace( SHADOW_RIGHT ) + rBox.CalcLineSpace( BOX_LINE_RIGHT );
116 0 : return aSz;
117 : }
118 :
119 :
120 :
121 0 : long ConvertLong_Impl( const long nIn, SfxMapUnit eUnit )
122 : {
123 0 : return OutputDevice::LogicToLogic( nIn, (MapUnit)eUnit, MAP_TWIP );
124 : }
125 :
126 0 : sal_Bool IsEqualSize_Impl( const SvxSizeItem* pSize, const Size& rSize )
127 : {
128 0 : if ( pSize )
129 : {
130 0 : Size aSize = pSize->GetSize();
131 0 : long nDiffW = std::abs( rSize.Width () - aSize.Width () );
132 0 : long nDiffH = std::abs( rSize.Height() - aSize.Height() );
133 0 : return ( nDiffW < 10 && nDiffH < 10 );
134 : }
135 : else
136 0 : return sal_False;
137 : }
138 :
139 :
140 :
141 : #define MARGIN_LEFT ( (MarginPosition)0x0001 )
142 : #define MARGIN_RIGHT ( (MarginPosition)0x0002 )
143 : #define MARGIN_TOP ( (MarginPosition)0x0004 )
144 : #define MARGIN_BOTTOM ( (MarginPosition)0x0008 )
145 :
146 : struct SvxPage_Impl
147 : {
148 : MarginPosition m_nPos;
149 : Printer* mpDefPrinter;
150 : bool mbDelPrinter;
151 :
152 0 : SvxPage_Impl() :
153 : m_nPos( 0 ),
154 : mpDefPrinter( 0 ),
155 0 : mbDelPrinter( false ) {}
156 :
157 0 : ~SvxPage_Impl() { if ( mbDelPrinter ) delete mpDefPrinter; }
158 : };
159 :
160 : // class SvxPageDescPage --------------------------------------------------
161 :
162 : // returns the range of the Which values
163 0 : sal_uInt16* SvxPageDescPage::GetRanges()
164 : {
165 0 : return pRanges;
166 : }
167 :
168 :
169 :
170 0 : SfxTabPage* SvxPageDescPage::Create( Window* pParent, const SfxItemSet& rSet )
171 : {
172 0 : return new SvxPageDescPage( pParent, rSet );
173 : }
174 :
175 :
176 :
177 0 : SvxPageDescPage::SvxPageDescPage( Window* pParent, const SfxItemSet& rAttr ) :
178 :
179 : SfxTabPage( pParent, "PageFormatPage", "cui/ui/pageformatpage.ui", rAttr ),
180 :
181 : bLandscape ( sal_False ),
182 : eMode ( SVX_PAGE_MODE_STANDARD ),
183 : ePaperStart ( PAPER_A3 ),
184 : ePaperEnd ( PAPER_ENV_DL ),
185 0 : pImpl ( new SvxPage_Impl )
186 :
187 : {
188 0 : get(m_pPaperSizeBox,"comboPageFormat");
189 0 : get(m_pPaperWidthEdit,"spinWidth");
190 0 : get(m_pPaperHeightEdit,"spinHeight");
191 :
192 0 : get(m_pOrientationFT,"labelOrientation");
193 0 : get(m_pPortraitBtn,"radiobuttonPortrait");
194 0 : get(m_pLandscapeBtn,"radiobuttonLandscape");
195 :
196 0 : get(m_pBspWin,"drawingareaPageDirection");
197 0 : get(m_pTextFlowLbl,"labelTextFlow");
198 0 : get(m_pTextFlowBox,"comboTextFlowBox");
199 0 : get(m_pPaperTrayBox,"comboPaperTray");
200 :
201 0 : get(m_pLeftMarginLbl,"labelLeftMargin");
202 0 : get(m_pLeftMarginEdit,"spinMargLeft");
203 0 : get(m_pRightMarginLbl,"labelRightMargin");
204 0 : get(m_pRightMarginEdit,"spinMargRight");
205 :
206 0 : get(m_pTopMarginEdit,"spinMargTop");
207 :
208 0 : get(m_pBottomMarginEdit,"spinMargBot");
209 :
210 0 : get(m_pPageText,"labelPageLayout");
211 0 : get(m_pLayoutBox,"comboPageLayout");
212 0 : get(m_pNumberFormatBox,"comboLayoutFormat");
213 :
214 0 : get(m_pRegisterCB,"checkRegisterTrue");
215 0 : get(m_pRegisterFT,"labelRegisterStyle");
216 0 : get(m_pRegisterLB,"comboRegisterStyle");
217 :
218 0 : get(m_pTblAlignFT,"labelTblAlign");
219 0 : get(m_pHorzBox,"checkbuttonHorz");
220 0 : get(m_pVertBox,"checkbuttonVert");
221 :
222 0 : get(m_pAdaptBox,"checkAdaptBox");
223 : // Strings stored in UI
224 0 : get(m_pInsideLbl,"labelInner");
225 0 : get(m_pOutsideLbl,"labelOuter");
226 0 : get(m_pPrintRangeQueryText,"labelMsg");
227 :
228 0 : bBorderModified = false;
229 0 : m_pBspWin->EnableRTL( false );
230 :
231 : // this page needs ExchangeSupport
232 0 : SetExchangeSupport();
233 :
234 0 : SvtLanguageOptions aLangOptions;
235 0 : sal_Bool bCJK = aLangOptions.IsAsianTypographyEnabled();
236 0 : sal_Bool bCTL = aLangOptions.IsCTLFontEnabled();
237 0 : sal_Bool bWeb = sal_False;
238 : const SfxPoolItem* pItem;
239 :
240 : SfxObjectShell* pShell;
241 0 : if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
242 0 : ( 0 != (pShell = SfxObjectShell::Current()) &&
243 0 : 0 != (pItem = pShell->GetItem(SID_HTML_MODE))))
244 0 : bWeb = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
245 :
246 : // fill text flow listbox with valid entries
247 :
248 0 : m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_HORI ), FRMDIR_HORI_LEFT_TOP );
249 :
250 :
251 0 : if( bCTL )
252 0 : m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_HORI ), FRMDIR_HORI_RIGHT_TOP );
253 :
254 :
255 : // #109989# do not show vertical directions in Writer/Web
256 0 : if( !bWeb )
257 : {
258 0 : if( bCJK )
259 : {
260 0 : m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_RTL_VERT ), FRMDIR_VERT_TOP_RIGHT );
261 : // m_pTextFlowBox->InsertEntryValue( CUI_RESSTR( RID_SVXSTR_PAGEDIR_LTR_VERT ), FRMDIR_VERT_TOP_LEFT );
262 : }
263 : }
264 :
265 : // #109989# show the text direction box in Writer/Web too
266 0 : if( (bCJK || bCTL) &&
267 0 : SFX_ITEM_UNKNOWN < rAttr.GetItemState(GetWhich( SID_ATTR_FRAMEDIRECTION )))
268 : {
269 0 : m_pTextFlowLbl->Show();
270 0 : m_pTextFlowBox->Show();
271 0 : m_pTextFlowBox->SetSelectHdl(LINK(this, SvxPageDescPage, FrameDirectionModify_Impl ));
272 :
273 0 : m_pBspWin->EnableFrameDirection(true);
274 : }
275 0 : Init_Impl();
276 :
277 0 : FieldUnit eFUnit = GetModuleFieldUnit( rAttr );
278 0 : SetFieldUnit( *m_pLeftMarginEdit, eFUnit );
279 0 : SetFieldUnit( *m_pRightMarginEdit, eFUnit );
280 0 : SetFieldUnit( *m_pTopMarginEdit, eFUnit );
281 0 : SetFieldUnit( *m_pBottomMarginEdit, eFUnit );
282 0 : SetFieldUnit( *m_pPaperWidthEdit, eFUnit );
283 0 : SetFieldUnit( *m_pPaperHeightEdit, eFUnit );
284 :
285 0 : if ( SfxViewShell::Current() && SfxViewShell::Current()->GetPrinter() )
286 0 : pImpl->mpDefPrinter = (Printer*)SfxViewShell::Current()->GetPrinter();
287 : else
288 : {
289 0 : pImpl->mpDefPrinter = new Printer;
290 0 : pImpl->mbDelPrinter = true;
291 : }
292 :
293 0 : MapMode aOldMode = pImpl->mpDefPrinter->GetMapMode();
294 0 : pImpl->mpDefPrinter->SetMapMode( MAP_TWIP );
295 :
296 : // set first- and last-values for the margins
297 0 : Size aPaperSize = pImpl->mpDefPrinter->GetPaperSize();
298 0 : Size aPrintSize = pImpl->mpDefPrinter->GetOutputSize();
299 : /*
300 : * To convert a point ( 0,0 ) into logic coordinates
301 : * looks like nonsense; but it makes sense when the
302 : * coordinate system's origin has been moved.
303 : */
304 0 : Point aPrintOffset = pImpl->mpDefPrinter->GetPageOffset() -
305 0 : pImpl->mpDefPrinter->PixelToLogic( Point() );
306 0 : pImpl->mpDefPrinter->SetMapMode( aOldMode );
307 :
308 0 : long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
309 0 : m_pLeftMarginEdit->SetFirst( m_pLeftMarginEdit->Normalize( aPrintOffset.X() ), FUNIT_TWIP );
310 0 : nFirstLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetFirst());
311 :
312 0 : m_pRightMarginEdit->SetFirst( m_pRightMarginEdit->Normalize( aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset ), FUNIT_TWIP);
313 0 : nFirstRightMargin = static_cast<long>(m_pRightMarginEdit->GetFirst());
314 :
315 0 : m_pTopMarginEdit->SetFirst( m_pTopMarginEdit->Normalize( aPrintOffset.Y() ), FUNIT_TWIP );
316 0 : nFirstTopMargin = static_cast<long>(m_pTopMarginEdit->GetFirst());
317 :
318 0 : m_pBottomMarginEdit->SetFirst( m_pBottomMarginEdit->Normalize( aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset ), FUNIT_TWIP );
319 0 : nFirstBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetFirst());
320 :
321 0 : m_pLeftMarginEdit->SetLast( m_pLeftMarginEdit->Normalize( aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
322 0 : nLastLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetLast());
323 :
324 0 : m_pRightMarginEdit->SetLast( m_pRightMarginEdit->Normalize( aPrintOffset.X() + aPrintSize.Width() ), FUNIT_TWIP );
325 0 : nLastRightMargin = static_cast<long>(m_pRightMarginEdit->GetLast());
326 :
327 0 : m_pTopMarginEdit->SetLast( m_pTopMarginEdit->Normalize( aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
328 0 : nLastTopMargin = static_cast<long>(m_pTopMarginEdit->GetLast());
329 :
330 0 : m_pBottomMarginEdit->SetLast( m_pBottomMarginEdit->Normalize( aPrintOffset.Y() + aPrintSize.Height() ), FUNIT_TWIP );
331 0 : nLastBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetLast());
332 :
333 : // #i4219# get DrawingLayer options
334 0 : const SvtOptionsDrawinglayer aDrawinglayerOpt;
335 :
336 : // #i4219# take Maximum now from configuration (1/100th cm)
337 : // was: 11900 -> 119 cm ;new value 3 meters -> 300 cm -> 30000
338 0 : m_pPaperWidthEdit->SetMax(m_pPaperWidthEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
339 0 : m_pPaperWidthEdit->SetLast(m_pPaperWidthEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FUNIT_CM);
340 0 : m_pPaperHeightEdit->SetMax(m_pPaperHeightEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
341 0 : m_pPaperHeightEdit->SetLast(m_pPaperHeightEdit->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FUNIT_CM);
342 :
343 : // #i4219# also for margins (1/100th cm). Was: 9999, keeping.
344 0 : m_pLeftMarginEdit->SetMax(aDrawinglayerOpt.GetMaximumPaperLeftMargin());
345 0 : m_pLeftMarginEdit->SetLast(aDrawinglayerOpt.GetMaximumPaperLeftMargin());
346 0 : m_pRightMarginEdit->SetMax(aDrawinglayerOpt.GetMaximumPaperRightMargin());
347 0 : m_pRightMarginEdit->SetLast(aDrawinglayerOpt.GetMaximumPaperRightMargin());
348 0 : m_pTopMarginEdit->SetMax(aDrawinglayerOpt.GetMaximumPaperTopMargin());
349 0 : m_pTopMarginEdit->SetLast(aDrawinglayerOpt.GetMaximumPaperTopMargin());
350 0 : m_pBottomMarginEdit->SetMax(aDrawinglayerOpt.GetMaximumPaperBottomMargin());
351 0 : m_pBottomMarginEdit->SetLast(aDrawinglayerOpt.GetMaximumPaperBottomMargin());
352 :
353 0 : m_pPortraitBtn->SetAccessibleRelationMemberOf(m_pOrientationFT);
354 0 : m_pLandscapeBtn->SetAccessibleRelationMemberOf(m_pOrientationFT);
355 :
356 : // Get the i18n framework numberings and add them to the listbox.
357 0 : SvxNumOptionsTabPage::GetI18nNumbering( *m_pNumberFormatBox, ::std::numeric_limits<sal_uInt16>::max());
358 0 : }
359 :
360 :
361 :
362 0 : SvxPageDescPage::~SvxPageDescPage()
363 : {
364 0 : delete pImpl;
365 0 : }
366 :
367 :
368 :
369 0 : void SvxPageDescPage::Init_Impl()
370 : {
371 : // adjust the handler
372 0 : m_pLayoutBox->SetSelectHdl( LINK( this, SvxPageDescPage, LayoutHdl_Impl ) );
373 0 : m_pPaperSizeBox->SetDropDownLineCount(10);
374 :
375 0 : m_pPaperTrayBox->SetGetFocusHdl( LINK( this, SvxPageDescPage, PaperBinHdl_Impl ) );
376 0 : m_pPaperSizeBox->SetSelectHdl( LINK( this, SvxPageDescPage, PaperSizeSelect_Impl ) );
377 0 : m_pPaperWidthEdit->SetModifyHdl( LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
378 0 : m_pPaperHeightEdit->SetModifyHdl( LINK( this, SvxPageDescPage, PaperSizeModify_Impl ) );
379 0 : m_pLandscapeBtn->SetClickHdl( LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
380 0 : m_pPortraitBtn->SetClickHdl( LINK( this, SvxPageDescPage, SwapOrientation_Impl ) );
381 :
382 0 : Link aLink = LINK( this, SvxPageDescPage, BorderModify_Impl );
383 0 : m_pLeftMarginEdit->SetModifyHdl( aLink );
384 0 : m_pRightMarginEdit->SetModifyHdl( aLink );
385 0 : m_pTopMarginEdit->SetModifyHdl( aLink );
386 0 : m_pBottomMarginEdit->SetModifyHdl( aLink );
387 :
388 0 : aLink = LINK( this, SvxPageDescPage, RangeHdl_Impl );
389 0 : m_pPaperWidthEdit->SetLoseFocusHdl( aLink );
390 0 : m_pPaperHeightEdit->SetLoseFocusHdl( aLink );
391 0 : m_pLeftMarginEdit->SetLoseFocusHdl( aLink );
392 0 : m_pRightMarginEdit->SetLoseFocusHdl( aLink );
393 0 : m_pTopMarginEdit->SetLoseFocusHdl( aLink );
394 0 : m_pBottomMarginEdit->SetLoseFocusHdl( aLink );
395 :
396 0 : m_pHorzBox->SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
397 0 : m_pVertBox->SetClickHdl( LINK( this, SvxPageDescPage, CenterHdl_Impl ) );
398 :
399 0 : }
400 :
401 :
402 :
403 0 : void SvxPageDescPage::Reset( const SfxItemSet& rSet )
404 : {
405 0 : SfxItemPool* pPool = rSet.GetPool();
406 : DBG_ASSERT( pPool, "Wo ist der Pool" );
407 0 : SfxMapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_LRSPACE ) );
408 :
409 : // adjust margins (right/left)
410 0 : const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_LRSPACE );
411 :
412 0 : if ( pItem )
413 : {
414 0 : const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)*pItem;
415 0 : SetMetricValue( *m_pLeftMarginEdit, rLRSpace.GetLeft(), eUnit );
416 : m_pBspWin->SetLeft(
417 0 : (sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetLeft(), eUnit ) );
418 0 : SetMetricValue( *m_pRightMarginEdit, rLRSpace.GetRight(), eUnit );
419 : m_pBspWin->SetRight(
420 0 : (sal_uInt16)ConvertLong_Impl( (long)rLRSpace.GetRight(), eUnit ) );
421 : }
422 :
423 : // adjust margins (top/bottom)
424 0 : pItem = GetItem( rSet, SID_ATTR_ULSPACE );
425 :
426 0 : if ( pItem )
427 : {
428 0 : const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)*pItem;
429 0 : SetMetricValue( *m_pTopMarginEdit, rULSpace.GetUpper(), eUnit );
430 : m_pBspWin->SetTop(
431 0 : (sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetUpper(), eUnit ) );
432 0 : SetMetricValue( *m_pBottomMarginEdit, rULSpace.GetLower(), eUnit );
433 : m_pBspWin->SetBottom(
434 0 : (sal_uInt16)ConvertLong_Impl( (long)rULSpace.GetLower(), eUnit ) );
435 : }
436 :
437 : // general page data
438 0 : SvxNumType eNumType = SVX_ARABIC;
439 0 : bLandscape = ( pImpl->mpDefPrinter->GetOrientation() == ORIENTATION_LANDSCAPE );
440 0 : sal_uInt16 nUse = (sal_uInt16)SVX_PAGE_ALL;
441 0 : pItem = GetItem( rSet, SID_ATTR_PAGE );
442 :
443 0 : if ( pItem )
444 : {
445 0 : const SvxPageItem& rItem = (const SvxPageItem&)*pItem;
446 0 : eNumType = rItem.GetNumType();
447 0 : nUse = rItem.GetPageUsage();
448 0 : bLandscape = rItem.IsLandscape();
449 : }
450 :
451 : // alignment
452 0 : m_pLayoutBox->SelectEntryPos( ::PageUsageToPos_Impl( nUse ) );
453 0 : m_pBspWin->SetUsage( nUse );
454 0 : LayoutHdl_Impl( 0 );
455 :
456 : //adjust numeration type of the page style
457 : //Get the Position of the saved NumType
458 0 : for(int i=0; i<m_pNumberFormatBox->GetEntryCount(); i++)
459 0 : if(eNumType == (sal_uInt16)(sal_uLong)m_pNumberFormatBox->GetEntryData(i)){
460 0 : m_pNumberFormatBox->SelectEntryPos( i );
461 0 : break;
462 : }
463 :
464 0 : m_pPaperTrayBox->Clear();
465 0 : sal_uInt8 nPaperBin = PAPERBIN_PRINTER_SETTINGS;
466 0 : pItem = GetItem( rSet, SID_ATTR_PAGE_PAPERBIN );
467 :
468 0 : if ( pItem )
469 : {
470 0 : nPaperBin = ( (const SvxPaperBinItem*)pItem )->GetValue();
471 :
472 0 : if ( nPaperBin >= pImpl->mpDefPrinter->GetPaperBinCount() )
473 0 : nPaperBin = PAPERBIN_PRINTER_SETTINGS;
474 : }
475 :
476 0 : OUString aBinName;
477 :
478 0 : if ( PAPERBIN_PRINTER_SETTINGS == nPaperBin )
479 0 : aBinName = EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS );
480 : else
481 0 : aBinName = pImpl->mpDefPrinter->GetPaperBinName( (sal_uInt16)nPaperBin );
482 :
483 0 : sal_uInt16 nEntryPos = m_pPaperTrayBox->InsertEntry( aBinName );
484 0 : m_pPaperTrayBox->SetEntryData( nEntryPos, (void*)(sal_uLong)nPaperBin );
485 0 : m_pPaperTrayBox->SelectEntry( aBinName );
486 :
487 0 : Size aPaperSize = SvxPaperInfo::GetPaperSize( pImpl->mpDefPrinter );
488 0 : pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
489 :
490 0 : if ( pItem )
491 0 : aPaperSize = ( (const SvxSizeItem*)pItem )->GetSize();
492 :
493 : bool bOrientationSupport =
494 0 : pImpl->mpDefPrinter->HasSupport( SUPPORT_SET_ORIENTATION );
495 :
496 0 : if ( !bOrientationSupport &&
497 0 : aPaperSize.Width() > aPaperSize.Height() )
498 0 : bLandscape = sal_True;
499 :
500 0 : m_pLandscapeBtn->Check( bLandscape );
501 0 : m_pPortraitBtn->Check( !bLandscape );
502 :
503 0 : m_pBspWin->SetSize( Size( ConvertLong_Impl( aPaperSize.Width(), eUnit ),
504 0 : ConvertLong_Impl( aPaperSize.Height(), eUnit ) ) );
505 :
506 0 : aPaperSize = OutputDevice::LogicToLogic(aPaperSize, (MapUnit)eUnit, MAP_100TH_MM);
507 0 : if ( bLandscape )
508 0 : Swap( aPaperSize );
509 :
510 : // Actual Paper Format
511 0 : Paper ePaper = SvxPaperInfo::GetSvxPaper( aPaperSize, MAP_100TH_MM, true );
512 :
513 0 : if ( PAPER_USER != ePaper )
514 0 : aPaperSize = SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM );
515 :
516 0 : if ( bLandscape )
517 0 : Swap( aPaperSize );
518 :
519 : // write values into the edits
520 0 : SetMetricValue( *m_pPaperHeightEdit, aPaperSize.Height(), SFX_MAPUNIT_100TH_MM );
521 0 : SetMetricValue( *m_pPaperWidthEdit, aPaperSize.Width(), SFX_MAPUNIT_100TH_MM );
522 0 : m_pPaperSizeBox->Clear();
523 :
524 0 : sal_Int32 nActPos = LISTBOX_ENTRY_NOTFOUND;
525 0 : sal_uInt16 nAryId = RID_SVXSTRARY_PAPERSIZE_STD;
526 :
527 0 : if ( ePaperStart != PAPER_A3 )
528 0 : nAryId = RID_SVXSTRARY_PAPERSIZE_DRAW;
529 0 : ResStringArray aPaperAry( CUI_RES( nAryId ) );
530 0 : sal_uInt32 nCnt = aPaperAry.Count();
531 :
532 0 : sal_Int32 nUserPos = LISTBOX_ENTRY_NOTFOUND;
533 0 : for ( sal_uInt32 i = 0; i < nCnt; ++i )
534 : {
535 0 : OUString aStr = aPaperAry.GetString(i);
536 0 : Paper eSize = (Paper)aPaperAry.GetValue(i);
537 0 : sal_Int32 nPos = m_pPaperSizeBox->InsertEntry( aStr );
538 0 : m_pPaperSizeBox->SetEntryData( nPos, (void*)(sal_uLong)eSize );
539 :
540 0 : if ( eSize == ePaper )
541 0 : nActPos = nPos;
542 0 : if( eSize == PAPER_USER )
543 0 : nUserPos = nPos;
544 0 : }
545 : // preselect current paper format - #115915#: ePaper might not be in aPaperSizeBox so use PAPER_USER instead
546 0 : m_pPaperSizeBox->SelectEntryPos( nActPos != LISTBOX_ENTRY_NOTFOUND ? nActPos : nUserPos );
547 :
548 : // application specific
549 :
550 0 : switch ( eMode )
551 : {
552 : case SVX_PAGE_MODE_CENTER:
553 : {
554 0 : m_pTblAlignFT->Show();
555 0 : m_pHorzBox->Show();
556 0 : m_pVertBox->Show();
557 0 : DisableVerticalPageDir();
558 :
559 : // horizontal alignment
560 0 : pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
561 0 : m_pHorzBox->Check( pItem ? ( (const SfxBoolItem*)pItem )->GetValue()
562 0 : : sal_False );
563 :
564 : // vertical alignment
565 0 : pItem = GetItem( rSet, SID_ATTR_PAGE_EXT2 );
566 0 : m_pVertBox->Check( pItem ? ( (const SfxBoolItem*)pItem )->GetValue()
567 0 : : sal_False );
568 :
569 : // set example window on the table
570 0 : m_pBspWin->SetTable( true );
571 0 : m_pBspWin->SetHorz( m_pHorzBox->IsChecked() );
572 0 : m_pBspWin->SetVert( m_pVertBox->IsChecked() );
573 :
574 0 : break;
575 : }
576 :
577 : case SVX_PAGE_MODE_PRESENTATION:
578 : {
579 0 : DisableVerticalPageDir();
580 0 : m_pAdaptBox->Show();
581 0 : pItem = GetItem( rSet, SID_ATTR_PAGE_EXT1 );
582 : m_pAdaptBox->Check( pItem ?
583 0 : ( (const SfxBoolItem*)pItem )->GetValue() : sal_False );
584 :
585 : //!!! hidden, because not implemented by StarDraw
586 0 : m_pLayoutBox->Hide();
587 0 : m_pPageText->Hide();
588 :
589 0 : break;
590 : }
591 : default: ;//prevent warning
592 : }
593 :
594 :
595 : // display background and border in the example
596 0 : ResetBackground_Impl( rSet );
597 : //! UpdateExample_Impl();
598 0 : RangeHdl_Impl( 0 );
599 :
600 0 : InitHeadFoot_Impl( rSet );
601 :
602 0 : bBorderModified = false;
603 0 : SwapFirstValues_Impl( false );
604 0 : UpdateExample_Impl();
605 :
606 0 : m_pLeftMarginEdit->SaveValue();
607 0 : m_pRightMarginEdit->SaveValue();
608 0 : m_pTopMarginEdit->SaveValue();
609 0 : m_pBottomMarginEdit->SaveValue();
610 0 : m_pLayoutBox->SaveValue();
611 0 : m_pNumberFormatBox->SaveValue();
612 0 : m_pPaperSizeBox->SaveValue();
613 0 : m_pPaperWidthEdit->SaveValue();
614 0 : m_pPaperHeightEdit->SaveValue();
615 0 : m_pPortraitBtn->SaveValue();
616 0 : m_pLandscapeBtn->SaveValue();
617 0 : m_pPaperTrayBox->SaveValue();
618 0 : m_pVertBox->SaveValue();
619 0 : m_pHorzBox->SaveValue();
620 0 : m_pAdaptBox->SaveValue();
621 :
622 0 : CheckMarginEdits( true );
623 :
624 :
625 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_SWREGISTER_MODE))
626 : {
627 : m_pRegisterCB->Check(((const SfxBoolItem&)rSet.Get(
628 0 : SID_SWREGISTER_MODE)).GetValue());
629 0 : m_pRegisterCB->SaveValue();
630 0 : RegisterModify(m_pRegisterCB);
631 : }
632 0 : if(SFX_ITEM_SET == rSet.GetItemState(SID_SWREGISTER_COLLECTION))
633 : {
634 : m_pRegisterLB->SelectEntry(
635 0 : ((const SfxStringItem&)rSet.Get(SID_SWREGISTER_COLLECTION)).GetValue());
636 0 : m_pRegisterLB->SaveValue();
637 : }
638 :
639 0 : SfxItemState eState = rSet.GetItemState( GetWhich( SID_ATTR_FRAMEDIRECTION ),
640 0 : true, &pItem );
641 0 : if( SFX_ITEM_UNKNOWN != eState )
642 : {
643 : sal_uInt32 nVal = SFX_ITEM_SET == eState
644 0 : ? ((SvxFrameDirectionItem*)pItem)->GetValue()
645 0 : : 0;
646 0 : m_pTextFlowBox->SelectEntryValue( static_cast< SvxFrameDirection >( nVal ) );
647 :
648 0 : m_pTextFlowBox->SaveValue();
649 0 : m_pBspWin->SetFrameDirection(nVal);
650 0 : }
651 0 : }
652 :
653 :
654 :
655 0 : void SvxPageDescPage::FillUserData()
656 : {
657 0 : if ( SVX_PAGE_MODE_PRESENTATION == eMode )
658 0 : SetUserData( m_pAdaptBox->IsChecked() ? OUString("1") : OUString("0") ) ;
659 :
660 0 : }
661 :
662 :
663 :
664 0 : bool SvxPageDescPage::FillItemSet( SfxItemSet& rSet )
665 : {
666 0 : sal_Bool bModified = sal_False;
667 0 : const SfxItemSet& rOldSet = GetItemSet();
668 0 : SfxItemPool* pPool = rOldSet.GetPool();
669 : DBG_ASSERT( pPool, "Wo ist der Pool" );
670 0 : sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
671 0 : SfxMapUnit eUnit = pPool->GetMetric( nWhich );
672 0 : const SfxPoolItem* pOld = 0;
673 :
674 : // copy old left and right margins
675 0 : SvxLRSpaceItem aMargin( (const SvxLRSpaceItem&)rOldSet.Get( nWhich ) );
676 :
677 : // copy old top and bottom margins
678 0 : nWhich = GetWhich( SID_ATTR_ULSPACE );
679 0 : SvxULSpaceItem aTopMargin( (const SvxULSpaceItem&)rOldSet.Get( nWhich ) );
680 :
681 0 : if ( m_pLeftMarginEdit->GetText() != m_pLeftMarginEdit->GetSavedValue() )
682 : {
683 0 : aMargin.SetLeft( (sal_uInt16)GetCoreValue( *m_pLeftMarginEdit, eUnit ) );
684 0 : bModified |= sal_True;
685 : }
686 :
687 0 : if ( m_pRightMarginEdit->GetText() != m_pRightMarginEdit->GetSavedValue() )
688 : {
689 0 : aMargin.SetRight( (sal_uInt16)GetCoreValue( *m_pRightMarginEdit, eUnit ) );
690 0 : bModified |= sal_True;
691 : }
692 :
693 : // set left and right margins
694 0 : if ( bModified )
695 : {
696 0 : pOld = GetOldItem( rSet, SID_ATTR_LRSPACE );
697 :
698 0 : if ( !pOld || !( *(const SvxLRSpaceItem*)pOld == aMargin ) )
699 0 : rSet.Put( aMargin );
700 : else
701 0 : bModified = sal_False;
702 : }
703 :
704 0 : sal_Bool bMod = sal_False;
705 :
706 0 : if ( m_pTopMarginEdit->GetText() != m_pTopMarginEdit->GetSavedValue() )
707 : {
708 0 : aTopMargin.SetUpper( (sal_uInt16)GetCoreValue( *m_pTopMarginEdit, eUnit ) );
709 0 : bMod |= sal_True;
710 : }
711 :
712 0 : if ( m_pBottomMarginEdit->GetText() != m_pBottomMarginEdit->GetSavedValue() )
713 : {
714 0 : aTopMargin.SetLower( (sal_uInt16)GetCoreValue( *m_pBottomMarginEdit, eUnit ) );
715 0 : bMod |= sal_True;
716 : }
717 :
718 : // set top and bottom margins
719 :
720 0 : if ( bMod )
721 : {
722 0 : pOld = GetOldItem( rSet, SID_ATTR_ULSPACE );
723 :
724 0 : if ( !pOld || !( *(const SvxULSpaceItem*)pOld == aTopMargin ) )
725 : {
726 0 : bModified |= sal_True;
727 0 : rSet.Put( aTopMargin );
728 : }
729 : }
730 :
731 : // paper tray
732 0 : nWhich = GetWhich( SID_ATTR_PAGE_PAPERBIN );
733 0 : sal_Int32 nPos = m_pPaperTrayBox->GetSelectEntryPos();
734 0 : sal_uInt16 nBin = (sal_uInt16)(sal_uLong)m_pPaperTrayBox->GetEntryData( nPos );
735 0 : pOld = GetOldItem( rSet, SID_ATTR_PAGE_PAPERBIN );
736 :
737 0 : if ( !pOld || ( (const SvxPaperBinItem*)pOld )->GetValue() != nBin )
738 : {
739 0 : rSet.Put( SvxPaperBinItem( nWhich, (sal_uInt8)nBin ) );
740 0 : bModified |= sal_True;
741 : }
742 :
743 0 : nPos = m_pPaperSizeBox->GetSelectEntryPos();
744 0 : Paper ePaper = (Paper)(sal_uLong)m_pPaperSizeBox->GetEntryData( nPos );
745 0 : const sal_Int32 nOld = m_pPaperSizeBox->GetSavedValue();
746 0 : bool bChecked = m_pLandscapeBtn->IsChecked();
747 :
748 0 : if ( PAPER_USER == ePaper )
749 : {
750 0 : if ( nOld != nPos ||
751 0 : m_pPaperWidthEdit->IsValueModified() ||
752 0 : m_pPaperHeightEdit->IsValueModified() ||
753 0 : bChecked != m_pLandscapeBtn->GetSavedValue() )
754 : {
755 : Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
756 0 : GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
757 0 : pOld = GetOldItem( rSet, SID_ATTR_PAGE_SIZE );
758 :
759 0 : if ( !pOld || ( (const SvxSizeItem*)pOld )->GetSize() != aSize )
760 : {
761 0 : rSet.Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
762 0 : bModified |= sal_True;
763 : }
764 : }
765 : }
766 : else
767 : {
768 0 : if ( nOld != nPos || bChecked != m_pLandscapeBtn->GetSavedValue() )
769 : {
770 0 : Size aSize( SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)eUnit ) );
771 :
772 0 : if ( bChecked )
773 0 : Swap( aSize );
774 :
775 0 : pOld = GetOldItem( rSet, SID_ATTR_PAGE_SIZE );
776 :
777 0 : if ( !pOld || ( (const SvxSizeItem*)pOld )->GetSize() != aSize )
778 : {
779 0 : rSet.Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZE), aSize ) );
780 0 : bModified |= sal_True;
781 : }
782 : }
783 : }
784 :
785 0 : nWhich = GetWhich( SID_ATTR_PAGE );
786 0 : SvxPageItem aPage( (const SvxPageItem&)rOldSet.Get( nWhich ) );
787 0 : bMod = m_pLayoutBox->GetSelectEntryPos() != m_pLayoutBox->GetSavedValue();
788 :
789 0 : if ( bMod )
790 : aPage.SetPageUsage(
791 0 : ::PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() ) );
792 :
793 0 : if ( bChecked != m_pLandscapeBtn->GetSavedValue() )
794 : {
795 0 : aPage.SetLandscape(bChecked);
796 0 : bMod |= sal_True;
797 : }
798 :
799 : //Get the NumType value
800 0 : nPos = m_pNumberFormatBox->GetSelectEntryPos();
801 0 : sal_uInt16 nEntryData = (sal_uInt16)(sal_uLong)m_pNumberFormatBox->GetEntryData(nPos);
802 0 : if ( nPos != m_pNumberFormatBox->GetSavedValue() )
803 : {
804 0 : aPage.SetNumType( (SvxNumType)nEntryData );
805 0 : bMod |= sal_True;
806 : }
807 :
808 0 : if ( bMod )
809 : {
810 0 : pOld = GetOldItem( rSet, SID_ATTR_PAGE );
811 :
812 0 : if ( !pOld || !( *(const SvxPageItem*)pOld == aPage ) )
813 : {
814 0 : rSet.Put( aPage );
815 0 : bModified |= sal_True;
816 : }
817 : }
818 0 : else if ( SFX_ITEM_DEFAULT == rOldSet.GetItemState( nWhich ) )
819 0 : rSet.ClearItem( nWhich );
820 : else
821 0 : rSet.Put( rOldSet.Get( nWhich ) );
822 :
823 : // evaluate mode specific controls
824 :
825 0 : switch ( eMode )
826 : {
827 : case SVX_PAGE_MODE_CENTER:
828 : {
829 0 : if ( TriState(m_pHorzBox->IsChecked()) != m_pHorzBox->GetSavedValue() )
830 : {
831 0 : SfxBoolItem aHorz( GetWhich( SID_ATTR_PAGE_EXT1 ),
832 0 : m_pHorzBox->IsChecked() );
833 0 : rSet.Put( aHorz );
834 0 : bModified |= sal_True;
835 : }
836 :
837 0 : if ( TriState(m_pVertBox->IsChecked()) != m_pVertBox->GetSavedValue() )
838 : {
839 0 : SfxBoolItem aVert( GetWhich( SID_ATTR_PAGE_EXT2 ),
840 0 : m_pVertBox->IsChecked() );
841 0 : rSet.Put( aVert );
842 0 : bModified |= sal_True;
843 : }
844 0 : break;
845 : }
846 :
847 : case SVX_PAGE_MODE_PRESENTATION:
848 : {
849 : // always put so that draw can evaluate this
850 0 : rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_PAGE_EXT1 ),
851 0 : m_pAdaptBox->IsChecked() ) );
852 0 : bModified |= sal_True;
853 0 : break;
854 : }
855 : default: ;//prevent warning
856 :
857 : }
858 :
859 0 : if(m_pRegisterCB->IsVisible() &&
860 0 : (m_pRegisterCB->IsChecked() || m_pRegisterCB->GetSavedValue() != TriState(m_pRegisterCB->IsChecked())))
861 : {
862 0 : const SfxBoolItem& rRegItem = (const SfxBoolItem&)rOldSet.Get(SID_SWREGISTER_MODE);
863 0 : SfxBoolItem* pRegItem = (SfxBoolItem*)rRegItem.Clone();
864 0 : sal_Bool bCheck = m_pRegisterCB->IsChecked();
865 0 : pRegItem->SetValue(bCheck);
866 0 : rSet.Put(*pRegItem);
867 0 : bModified |= sal_True;
868 0 : if(bCheck)
869 : {
870 0 : bModified |= sal_True;
871 : rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION,
872 0 : m_pRegisterLB->GetSelectEntry()));
873 : }
874 0 : delete pRegItem;
875 : }
876 :
877 0 : SvxFrameDirection eDirection = m_pTextFlowBox->GetSelectEntryValue();
878 0 : if( m_pTextFlowBox->IsVisible() && (eDirection != m_pTextFlowBox->GetSavedValue()) )
879 : {
880 0 : rSet.Put( SvxFrameDirectionItem( eDirection, GetWhich( SID_ATTR_FRAMEDIRECTION ) ) );
881 0 : bModified = sal_True;
882 : }
883 :
884 0 : return bModified;
885 : }
886 :
887 :
888 :
889 0 : IMPL_LINK_NOARG(SvxPageDescPage, LayoutHdl_Impl)
890 : {
891 : // switch inside outside
892 0 : const sal_uInt16 nPos = PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() );
893 :
894 0 : if ( nPos == SVX_PAGE_MIRROR )
895 : {
896 0 : m_pLeftMarginLbl->Hide();
897 0 : m_pRightMarginLbl->Hide();
898 0 : m_pInsideLbl->Show();
899 0 : m_pOutsideLbl->Show();
900 : }
901 : else
902 : {
903 0 : m_pLeftMarginLbl->Show();
904 0 : m_pRightMarginLbl->Show();
905 0 : m_pInsideLbl->Hide();
906 0 : m_pOutsideLbl->Hide();
907 : }
908 0 : UpdateExample_Impl( true );
909 0 : return 0;
910 : }
911 :
912 :
913 :
914 0 : IMPL_LINK_NOARG(SvxPageDescPage, PaperBinHdl_Impl)
915 : {
916 0 : if ( m_pPaperTrayBox->GetEntryCount() > 1 )
917 : // already filled
918 0 : return 0;
919 :
920 0 : OUString aOldName = m_pPaperTrayBox->GetSelectEntry();
921 0 : m_pPaperTrayBox->SetUpdateMode( false );
922 0 : m_pPaperTrayBox->Clear();
923 : sal_Int32 nEntryPos = m_pPaperTrayBox->InsertEntry(
924 0 : EE_RESSTR( RID_SVXSTR_PAPERBIN_SETTINGS ) );
925 : m_pPaperTrayBox->SetEntryData( nEntryPos,
926 0 : (void*)(sal_uLong)PAPERBIN_PRINTER_SETTINGS );
927 0 : OUString aPaperBin( EditResId( RID_SVXSTR_PAPERBIN ) );
928 0 : sal_uInt16 nBinCount = pImpl->mpDefPrinter->GetPaperBinCount();
929 :
930 0 : for ( sal_uInt16 i = 0; i < nBinCount; ++i )
931 : {
932 0 : OUString aName = pImpl->mpDefPrinter->GetPaperBinName(i);
933 :
934 0 : if ( aName.isEmpty() )
935 : {
936 0 : aName = aPaperBin;
937 0 : aName += " ";
938 0 : aName += OUString::number( i+1 );
939 : }
940 0 : nEntryPos = m_pPaperTrayBox->InsertEntry( aName );
941 0 : m_pPaperTrayBox->SetEntryData( nEntryPos, (void*)(sal_uLong)i );
942 0 : }
943 0 : m_pPaperTrayBox->SelectEntry( aOldName );
944 0 : m_pPaperTrayBox->SetUpdateMode( true );
945 :
946 0 : return 0;
947 : }
948 :
949 :
950 :
951 0 : IMPL_LINK( SvxPageDescPage, PaperSizeSelect_Impl, ListBox *, pBox )
952 : {
953 0 : const sal_Int32 nPos = pBox->GetSelectEntryPos();
954 0 : Paper ePaper = (Paper)(sal_uLong)m_pPaperSizeBox->GetEntryData( nPos );
955 :
956 0 : if ( ePaper != PAPER_USER )
957 : {
958 0 : Size aSize( SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM ) );
959 :
960 0 : if ( m_pLandscapeBtn->IsChecked() )
961 0 : Swap( aSize );
962 :
963 0 : if ( aSize.Height() < m_pPaperHeightEdit->GetMin( FUNIT_100TH_MM ) )
964 : m_pPaperHeightEdit->SetMin(
965 0 : m_pPaperHeightEdit->Normalize( aSize.Height() ), FUNIT_100TH_MM );
966 0 : if ( aSize.Width() < m_pPaperWidthEdit->GetMin( FUNIT_100TH_MM ) )
967 : m_pPaperWidthEdit->SetMin(
968 0 : m_pPaperWidthEdit->Normalize( aSize.Width() ), FUNIT_100TH_MM );
969 0 : SetMetricValue( *m_pPaperHeightEdit, aSize.Height(), SFX_MAPUNIT_100TH_MM );
970 0 : SetMetricValue( *m_pPaperWidthEdit, aSize.Width(), SFX_MAPUNIT_100TH_MM );
971 :
972 0 : CalcMargin_Impl();
973 :
974 0 : RangeHdl_Impl( 0 );
975 0 : UpdateExample_Impl( true );
976 :
977 0 : if ( eMode == SVX_PAGE_MODE_PRESENTATION )
978 : {
979 : // Draw: if paper format the margin shall be 1 cm
980 0 : long nTmp = 0;
981 0 : sal_Bool bScreen = (( PAPER_SCREEN_4_3 == ePaper )||( PAPER_SCREEN_16_9 == ePaper)||( PAPER_SCREEN_16_10 == ePaper));
982 :
983 0 : if ( !bScreen )
984 : // no margin if screen
985 0 : nTmp = 1; // accordingly 1 cm
986 :
987 0 : if ( bScreen || m_pRightMarginEdit->GetValue() == 0 )
988 : {
989 0 : SetMetricValue( *m_pRightMarginEdit, nTmp, SFX_MAPUNIT_CM );
990 0 : if ( !bScreen &&
991 0 : m_pRightMarginEdit->GetFirst() > m_pRightMarginEdit->GetValue() )
992 0 : m_pRightMarginEdit->SetValue( m_pRightMarginEdit->GetFirst() );
993 : }
994 0 : if ( bScreen || m_pLeftMarginEdit->GetValue() == 0 )
995 : {
996 0 : SetMetricValue( *m_pLeftMarginEdit, nTmp, SFX_MAPUNIT_CM );
997 0 : if ( !bScreen &&
998 0 : m_pLeftMarginEdit->GetFirst() > m_pLeftMarginEdit->GetValue() )
999 0 : m_pLeftMarginEdit->SetValue( m_pLeftMarginEdit->GetFirst() );
1000 : }
1001 0 : if ( bScreen || m_pBottomMarginEdit->GetValue() == 0 )
1002 : {
1003 0 : SetMetricValue( *m_pBottomMarginEdit, nTmp, SFX_MAPUNIT_CM );
1004 0 : if ( !bScreen &&
1005 0 : m_pBottomMarginEdit->GetFirst() > m_pBottomMarginEdit->GetValue() )
1006 0 : m_pBottomMarginEdit->SetValue( m_pBottomMarginEdit->GetFirst() );
1007 : }
1008 0 : if ( bScreen || m_pTopMarginEdit->GetValue() == 0 )
1009 : {
1010 0 : SetMetricValue( *m_pTopMarginEdit, nTmp, SFX_MAPUNIT_CM );
1011 0 : if ( !bScreen &&
1012 0 : m_pTopMarginEdit->GetFirst() > m_pTopMarginEdit->GetValue() )
1013 0 : m_pTopMarginEdit->SetValue( m_pTopMarginEdit->GetFirst() );
1014 : }
1015 0 : UpdateExample_Impl( true );
1016 : }
1017 : }
1018 0 : return 0;
1019 : }
1020 :
1021 :
1022 :
1023 0 : IMPL_LINK_NOARG(SvxPageDescPage, PaperSizeModify_Impl)
1024 : {
1025 0 : sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE );
1026 0 : SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
1027 : Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
1028 0 : GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
1029 0 : Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, (MapUnit)eUnit, true );
1030 0 : sal_Int32 nEntryCount = m_pPaperSizeBox->GetEntryCount();
1031 :
1032 0 : for ( sal_Int32 i = 0; i < nEntryCount; ++i )
1033 : {
1034 0 : Paper eTmp = (Paper)(sal_uLong)m_pPaperSizeBox->GetEntryData(i);
1035 :
1036 0 : if ( eTmp == ePaper )
1037 : {
1038 0 : m_pPaperSizeBox->SelectEntryPos(i);
1039 0 : break;
1040 : }
1041 : }
1042 0 : UpdateExample_Impl( true );
1043 0 : return 0;
1044 : }
1045 :
1046 :
1047 :
1048 0 : IMPL_LINK( SvxPageDescPage, SwapOrientation_Impl, RadioButton *, pBtn )
1049 : {
1050 0 : if (
1051 0 : (!bLandscape && pBtn == m_pLandscapeBtn) ||
1052 0 : (bLandscape && pBtn == m_pPortraitBtn)
1053 : )
1054 : {
1055 0 : bLandscape = m_pLandscapeBtn->IsChecked();
1056 :
1057 0 : const long lWidth = GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_100TH_MM );
1058 0 : const long lHeight = GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_100TH_MM );
1059 :
1060 : // swap with and height
1061 0 : SetMetricValue( *m_pPaperWidthEdit, lHeight, SFX_MAPUNIT_100TH_MM );
1062 0 : SetMetricValue( *m_pPaperHeightEdit, lWidth, SFX_MAPUNIT_100TH_MM );
1063 :
1064 : // recalculate margins if necessary
1065 0 : CalcMargin_Impl();
1066 :
1067 0 : PaperSizeSelect_Impl( m_pPaperSizeBox );
1068 0 : RangeHdl_Impl( 0 );
1069 0 : SwapFirstValues_Impl( bBorderModified );
1070 0 : UpdateExample_Impl( true );
1071 : }
1072 0 : return 0;
1073 : }
1074 :
1075 :
1076 :
1077 0 : void SvxPageDescPage::SwapFirstValues_Impl( bool bSet )
1078 : {
1079 0 : MapMode aOldMode = pImpl->mpDefPrinter->GetMapMode();
1080 0 : Orientation eOri = ORIENTATION_PORTRAIT;
1081 :
1082 0 : if ( bLandscape )
1083 0 : eOri = ORIENTATION_LANDSCAPE;
1084 0 : Orientation eOldOri = pImpl->mpDefPrinter->GetOrientation();
1085 0 : pImpl->mpDefPrinter->SetOrientation( eOri );
1086 0 : pImpl->mpDefPrinter->SetMapMode( MAP_TWIP );
1087 :
1088 : // set first- and last-values for margins
1089 0 : Size aPaperSize = pImpl->mpDefPrinter->GetPaperSize();
1090 0 : Size aPrintSize = pImpl->mpDefPrinter->GetOutputSize();
1091 : /*
1092 : * To convert a point ( 0,0 ) into logic coordinates
1093 : * looks like nonsense; but it makes sense if the
1094 : * coordinate system's origin has been moved.
1095 : */
1096 0 : Point aPrintOffset = pImpl->mpDefPrinter->GetPageOffset() -
1097 0 : pImpl->mpDefPrinter->PixelToLogic( Point() );
1098 0 : pImpl->mpDefPrinter->SetMapMode( aOldMode );
1099 0 : pImpl->mpDefPrinter->SetOrientation( eOldOri );
1100 :
1101 : sal_Int64 nSetL = m_pLeftMarginEdit->Denormalize(
1102 0 : m_pLeftMarginEdit->GetValue( FUNIT_TWIP ) );
1103 : sal_Int64 nSetR = m_pRightMarginEdit->Denormalize(
1104 0 : m_pRightMarginEdit->GetValue( FUNIT_TWIP ) );
1105 : sal_Int64 nSetT = m_pTopMarginEdit->Denormalize(
1106 0 : m_pTopMarginEdit->GetValue( FUNIT_TWIP ) );
1107 : sal_Int64 nSetB = m_pBottomMarginEdit->Denormalize(
1108 0 : m_pBottomMarginEdit->GetValue( FUNIT_TWIP ) );
1109 :
1110 0 : long nOffset = !aPrintOffset.X() && !aPrintOffset.Y() ? 0 : PRINT_OFFSET;
1111 0 : long nNewL = aPrintOffset.X();
1112 : long nNewR =
1113 0 : aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X() + nOffset;
1114 0 : long nNewT = aPrintOffset.Y();
1115 : long nNewB =
1116 0 : aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y() + nOffset;
1117 :
1118 0 : m_pLeftMarginEdit->SetFirst( m_pLeftMarginEdit->Normalize( nNewL ), FUNIT_TWIP );
1119 0 : nFirstLeftMargin = static_cast<long>(m_pLeftMarginEdit->GetFirst());
1120 0 : m_pRightMarginEdit->SetFirst( m_pRightMarginEdit->Normalize( nNewR ), FUNIT_TWIP );
1121 0 : nFirstRightMargin = static_cast<long>(m_pRightMarginEdit->GetFirst());
1122 0 : m_pTopMarginEdit->SetFirst( m_pTopMarginEdit->Normalize( nNewT ), FUNIT_TWIP );
1123 0 : nFirstTopMargin = static_cast<long>(m_pTopMarginEdit->GetFirst());
1124 0 : m_pBottomMarginEdit->SetFirst( m_pBottomMarginEdit->Normalize( nNewB ), FUNIT_TWIP );
1125 0 : nFirstBottomMargin = static_cast<long>(m_pBottomMarginEdit->GetFirst());
1126 :
1127 0 : if ( bSet )
1128 : {
1129 0 : if ( nSetL < nNewL )
1130 : m_pLeftMarginEdit->SetValue( m_pLeftMarginEdit->Normalize( nNewL ),
1131 0 : FUNIT_TWIP );
1132 0 : if ( nSetR < nNewR )
1133 : m_pRightMarginEdit->SetValue( m_pRightMarginEdit->Normalize( nNewR ),
1134 0 : FUNIT_TWIP );
1135 0 : if ( nSetT < nNewT )
1136 : m_pTopMarginEdit->SetValue( m_pTopMarginEdit->Normalize( nNewT ),
1137 0 : FUNIT_TWIP );
1138 0 : if ( nSetB < nNewB )
1139 : m_pBottomMarginEdit->SetValue( m_pBottomMarginEdit->Normalize( nNewB ),
1140 0 : FUNIT_TWIP );
1141 0 : }
1142 0 : }
1143 :
1144 :
1145 :
1146 0 : IMPL_LINK_NOARG_INLINE_START(SvxPageDescPage, BorderModify_Impl)
1147 : {
1148 0 : if ( !bBorderModified )
1149 0 : bBorderModified = true;
1150 0 : UpdateExample_Impl();
1151 0 : return 0;
1152 : }
1153 0 : IMPL_LINK_NOARG_INLINE_END(SvxPageDescPage, BorderModify_Impl)
1154 :
1155 :
1156 :
1157 0 : void SvxPageDescPage::UpdateExample_Impl( bool bResetbackground )
1158 : {
1159 : // Size
1160 : Size aSize( GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_TWIP ),
1161 0 : GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_TWIP ) );
1162 :
1163 0 : m_pBspWin->SetSize( aSize );
1164 :
1165 : // Margins
1166 0 : m_pBspWin->SetTop( GetCoreValue( *m_pTopMarginEdit, SFX_MAPUNIT_TWIP ) );
1167 0 : m_pBspWin->SetBottom( GetCoreValue( *m_pBottomMarginEdit, SFX_MAPUNIT_TWIP ) );
1168 0 : m_pBspWin->SetLeft( GetCoreValue( *m_pLeftMarginEdit, SFX_MAPUNIT_TWIP ) );
1169 0 : m_pBspWin->SetRight( GetCoreValue( *m_pRightMarginEdit, SFX_MAPUNIT_TWIP ) );
1170 :
1171 : // Layout
1172 0 : m_pBspWin->SetUsage( PosToPageUsage_Impl( m_pLayoutBox->GetSelectEntryPos() ) );
1173 0 : if ( bResetbackground )
1174 0 : m_pBspWin->ResetBackground();
1175 0 : m_pBspWin->Invalidate();
1176 0 : }
1177 :
1178 :
1179 :
1180 0 : void SvxPageDescPage::ResetBackground_Impl( const SfxItemSet& rSet )
1181 : {
1182 0 : sal_uInt16 nWhich = GetWhich( SID_ATTR_PAGE_HEADERSET );
1183 :
1184 0 : if ( rSet.GetItemState( nWhich, false ) == SFX_ITEM_SET )
1185 : {
1186 : const SvxSetItem& rSetItem =
1187 0 : (const SvxSetItem&)rSet.Get( nWhich, false );
1188 0 : const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1189 : const SfxBoolItem& rOn =
1190 0 : (const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1191 :
1192 0 : if ( rOn.GetValue() )
1193 : {
1194 0 : nWhich = GetWhich( SID_ATTR_BRUSH );
1195 :
1196 0 : if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1197 : {
1198 : const SvxBrushItem& rItem =
1199 0 : (const SvxBrushItem&)rTmpSet.Get( nWhich );
1200 0 : m_pBspWin->SetHdColor( rItem.GetColor() );
1201 : }
1202 0 : nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1203 :
1204 0 : if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1205 : {
1206 : const SvxBoxItem& rItem =
1207 0 : (const SvxBoxItem&)rTmpSet.Get( nWhich );
1208 0 : m_pBspWin->SetHdBorder( rItem );
1209 : }
1210 : }
1211 : }
1212 :
1213 0 : nWhich = GetWhich( SID_ATTR_PAGE_FOOTERSET );
1214 :
1215 0 : if ( rSet.GetItemState( nWhich, false ) == SFX_ITEM_SET )
1216 : {
1217 : const SvxSetItem& rSetItem =
1218 0 : (const SvxSetItem&)rSet.Get( nWhich, false );
1219 0 : const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1220 : const SfxBoolItem& rOn =
1221 0 : (const SfxBoolItem&)rTmpSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1222 :
1223 0 : if ( rOn.GetValue() )
1224 : {
1225 0 : nWhich = GetWhich( SID_ATTR_BRUSH );
1226 :
1227 0 : if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1228 : {
1229 : const SvxBrushItem& rItem =
1230 0 : (const SvxBrushItem&)rTmpSet.Get( nWhich );
1231 0 : m_pBspWin->SetFtColor( rItem.GetColor() );
1232 : }
1233 0 : nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1234 :
1235 0 : if ( rTmpSet.GetItemState( nWhich ) == SFX_ITEM_SET )
1236 : {
1237 : const SvxBoxItem& rItem =
1238 0 : (const SvxBoxItem&)rTmpSet.Get( nWhich );
1239 0 : m_pBspWin->SetFtBorder( rItem );
1240 : }
1241 : }
1242 : }
1243 :
1244 0 : const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_BRUSH );
1245 :
1246 0 : if ( pItem )
1247 : {
1248 0 : m_pBspWin->SetColor( ( (const SvxBrushItem*)pItem )->GetColor() );
1249 0 : const Graphic* pGrf = ( (const SvxBrushItem*)pItem )->GetGraphic();
1250 :
1251 0 : if ( pGrf )
1252 : {
1253 0 : Bitmap aBitmap = pGrf->GetBitmap();
1254 0 : m_pBspWin->SetBitmap( &aBitmap );
1255 : }
1256 : else
1257 0 : m_pBspWin->SetBitmap( NULL );
1258 : }
1259 :
1260 0 : pItem = GetItem( rSet, SID_ATTR_BORDER_OUTER );
1261 :
1262 0 : if ( pItem )
1263 0 : m_pBspWin->SetBorder( (SvxBoxItem&)*pItem );
1264 0 : }
1265 :
1266 :
1267 :
1268 0 : void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
1269 : {
1270 0 : bLandscape = m_pLandscapeBtn->IsChecked();
1271 0 : const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
1272 :
1273 0 : if ( pItem )
1274 0 : m_pBspWin->SetSize( ( (const SvxSizeItem*)pItem )->GetSize() );
1275 :
1276 0 : const SvxSetItem* pSetItem = 0;
1277 :
1278 : // evaluate header attributes
1279 :
1280 0 : if ( SFX_ITEM_SET ==
1281 0 : rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSET ),
1282 0 : false, (const SfxPoolItem**)&pSetItem ) )
1283 : {
1284 0 : const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
1285 : const SfxBoolItem& rHeaderOn =
1286 0 : (const SfxBoolItem&)rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1287 :
1288 0 : if ( rHeaderOn.GetValue() )
1289 : {
1290 : const SvxSizeItem& rSize = (const SvxSizeItem&)
1291 0 : rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
1292 : const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
1293 0 : rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
1294 0 : long nDist = rUL.GetLower();
1295 0 : m_pBspWin->SetHdHeight( rSize.GetSize().Height() - nDist );
1296 0 : m_pBspWin->SetHdDist( nDist );
1297 : const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
1298 0 : rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
1299 0 : m_pBspWin->SetHdLeft( rLR.GetLeft() );
1300 0 : m_pBspWin->SetHdRight( rLR.GetRight() );
1301 0 : m_pBspWin->SetHeader( true );
1302 : }
1303 : else
1304 0 : m_pBspWin->SetHeader( false );
1305 :
1306 : // show background and border in the example
1307 0 : sal_uInt16 nWhich = GetWhich( SID_ATTR_BRUSH );
1308 :
1309 0 : if ( rHeaderSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1310 : {
1311 : const SvxBrushItem& rItem =
1312 0 : (const SvxBrushItem&)rHeaderSet.Get( nWhich );
1313 0 : m_pBspWin->SetHdColor( rItem.GetColor() );
1314 : }
1315 0 : nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1316 :
1317 0 : if ( rHeaderSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1318 : {
1319 : const SvxBoxItem& rItem =
1320 0 : (const SvxBoxItem&)rHeaderSet.Get( nWhich );
1321 0 : m_pBspWin->SetHdBorder( rItem );
1322 : }
1323 : }
1324 :
1325 : // evaluate footer attributes
1326 :
1327 0 : if ( SFX_ITEM_SET ==
1328 0 : rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSET ),
1329 0 : false, (const SfxPoolItem**)&pSetItem ) )
1330 : {
1331 0 : const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
1332 : const SfxBoolItem& rFooterOn =
1333 0 : (const SfxBoolItem&)rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ON ) );
1334 :
1335 0 : if ( rFooterOn.GetValue() )
1336 : {
1337 : const SvxSizeItem& rSize = (const SvxSizeItem&)
1338 0 : rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZE ) );
1339 : const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)
1340 0 : rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE ) );
1341 0 : long nDist = rUL.GetUpper();
1342 0 : m_pBspWin->SetFtHeight( rSize.GetSize().Height() - nDist );
1343 0 : m_pBspWin->SetFtDist( nDist );
1344 : const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)
1345 0 : rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE ) );
1346 0 : m_pBspWin->SetFtLeft( rLR.GetLeft() );
1347 0 : m_pBspWin->SetFtRight( rLR.GetRight() );
1348 0 : m_pBspWin->SetFooter( true );
1349 : }
1350 : else
1351 0 : m_pBspWin->SetFooter( false );
1352 :
1353 : // show background and border in the example
1354 0 : sal_uInt16 nWhich = GetWhich( SID_ATTR_BRUSH );
1355 :
1356 0 : if ( rFooterSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1357 : {
1358 : const SvxBrushItem& rItem =
1359 0 : (const SvxBrushItem&)rFooterSet.Get( nWhich );
1360 0 : m_pBspWin->SetFtColor( rItem.GetColor() );
1361 : }
1362 0 : nWhich = GetWhich( SID_ATTR_BORDER_OUTER );
1363 :
1364 0 : if ( rFooterSet.GetItemState( nWhich ) >= SFX_ITEM_AVAILABLE )
1365 : {
1366 : const SvxBoxItem& rItem =
1367 0 : (const SvxBoxItem&)rFooterSet.Get( nWhich );
1368 0 : m_pBspWin->SetFtBorder( rItem );
1369 : }
1370 : }
1371 0 : }
1372 :
1373 :
1374 :
1375 0 : void SvxPageDescPage::ActivatePage( const SfxItemSet& rSet )
1376 : {
1377 0 : InitHeadFoot_Impl( rSet );
1378 0 : ResetBackground_Impl( rSet );
1379 0 : RangeHdl_Impl( 0 );
1380 0 : }
1381 :
1382 :
1383 :
1384 0 : int SvxPageDescPage::DeactivatePage( SfxItemSet* _pSet )
1385 : {
1386 : // Inquiry whether the page margins are beyond the printing area.
1387 : // If not, ask user whether they shall be taken.
1388 : // If not, stay on the TabPage.
1389 0 : sal_Int32 nPos = m_pPaperSizeBox->GetSelectEntryPos();
1390 0 : Paper ePaper = (Paper)(sal_uLong)m_pPaperSizeBox->GetEntryData( nPos );
1391 :
1392 0 : if ( ePaper != PAPER_SCREEN_4_3 && ePaper != PAPER_SCREEN_16_9 && ePaper != PAPER_SCREEN_16_10 && IsMarginOutOfRange() )
1393 : {
1394 0 : if ( QueryBox( this, WB_YES_NO | WB_DEF_NO, m_pPrintRangeQueryText->GetText() ).Execute() == RET_NO )
1395 : {
1396 0 : MetricField* pField = NULL;
1397 0 : if ( IsPrinterRangeOverflow( *m_pLeftMarginEdit, nFirstLeftMargin, nLastLeftMargin, MARGIN_LEFT ) )
1398 0 : pField = m_pLeftMarginEdit;
1399 0 : if ( IsPrinterRangeOverflow( *m_pRightMarginEdit, nFirstRightMargin, nLastRightMargin, MARGIN_RIGHT )
1400 0 : && !pField )
1401 0 : pField = m_pRightMarginEdit;
1402 0 : if ( IsPrinterRangeOverflow( *m_pTopMarginEdit, nFirstTopMargin, nLastTopMargin, MARGIN_TOP )
1403 0 : && !pField )
1404 0 : pField = m_pTopMarginEdit;
1405 0 : if ( IsPrinterRangeOverflow( *m_pBottomMarginEdit, nFirstBottomMargin, nLastBottomMargin, MARGIN_BOTTOM )
1406 0 : && !pField )
1407 0 : pField = m_pBottomMarginEdit;
1408 0 : if ( pField )
1409 0 : pField->GrabFocus();
1410 0 : UpdateExample_Impl();
1411 0 : return KEEP_PAGE;
1412 : }
1413 : else
1414 0 : CheckMarginEdits( false );
1415 : }
1416 :
1417 0 : if ( _pSet )
1418 : {
1419 0 : FillItemSet( *_pSet );
1420 :
1421 : // put portray/landscape if applicable
1422 0 : sal_uInt16 nWh = GetWhich( SID_ATTR_PAGE_SIZE );
1423 0 : SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWh );
1424 : Size aSize( GetCoreValue( *m_pPaperWidthEdit, eUnit ),
1425 0 : GetCoreValue( *m_pPaperHeightEdit, eUnit ) );
1426 :
1427 : // put, if current size is different to the value in _pSet
1428 0 : const SvxSizeItem* pSize = (const SvxSizeItem*)GetItem( *_pSet, SID_ATTR_PAGE_SIZE );
1429 0 : if ( aSize.Width() && ( !pSize || !IsEqualSize_Impl( pSize, aSize ) ) )
1430 0 : _pSet->Put( SvxSizeItem( nWh, aSize ) );
1431 : }
1432 :
1433 0 : return LEAVE_PAGE;
1434 : }
1435 :
1436 :
1437 :
1438 0 : IMPL_LINK_NOARG(SvxPageDescPage, RangeHdl_Impl)
1439 : {
1440 : // example window
1441 0 : long nHHeight = m_pBspWin->GetHdHeight();
1442 0 : long nHDist = m_pBspWin->GetHdDist();
1443 :
1444 0 : long nFHeight = m_pBspWin->GetFtHeight();
1445 0 : long nFDist = m_pBspWin->GetFtDist();
1446 :
1447 0 : long nHFLeft = std::max( m_pBspWin->GetHdLeft(), m_pBspWin->GetFtLeft() );
1448 0 : long nHFRight = std::max( m_pBspWin->GetHdRight(), m_pBspWin->GetFtRight() );
1449 :
1450 : // current values for page margins
1451 0 : long nBT = static_cast<long>(m_pTopMarginEdit->Denormalize(m_pTopMarginEdit->GetValue(FUNIT_TWIP)));
1452 0 : long nBB = static_cast<long>(m_pBottomMarginEdit->Denormalize(m_pBottomMarginEdit->GetValue(FUNIT_TWIP)));
1453 0 : long nBL = static_cast<long>(m_pLeftMarginEdit->Denormalize(m_pLeftMarginEdit->GetValue(FUNIT_TWIP)));
1454 0 : long nBR = static_cast<long>(m_pRightMarginEdit->Denormalize(m_pRightMarginEdit->GetValue(FUNIT_TWIP)));
1455 :
1456 : // calculate width of page border
1457 0 : const SfxItemSet* _pSet = &GetItemSet();
1458 0 : Size aBorder;
1459 :
1460 0 : if ( _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_SHADOW) ) >=
1461 0 : SFX_ITEM_AVAILABLE &&
1462 0 : _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_OUTER) ) >=
1463 : SFX_ITEM_AVAILABLE )
1464 : {
1465 : aBorder = ( GetMinBorderSpace_Impl(
1466 0 : (const SvxShadowItem&)_pSet->Get(GetWhich(SID_ATTR_BORDER_SHADOW)),
1467 0 : (const SvxBoxItem&)_pSet->Get(GetWhich(SID_ATTR_BORDER_OUTER))));
1468 : }
1469 :
1470 0 : long nH = static_cast<long>(m_pPaperHeightEdit->Denormalize(m_pPaperHeightEdit->GetValue(FUNIT_TWIP)));
1471 0 : long nW = static_cast<long>(m_pPaperWidthEdit->Denormalize(m_pPaperWidthEdit->GetValue(FUNIT_TWIP)));
1472 :
1473 : // limits paper
1474 : // maximum is 54 cm
1475 :
1476 0 : long nMin = nHHeight + nHDist + nFDist + nFHeight + nBT + nBB +
1477 0 : MINBODY + aBorder.Height();
1478 0 : m_pPaperHeightEdit->SetMin(m_pPaperHeightEdit->Normalize(nMin), FUNIT_TWIP);
1479 :
1480 0 : nMin = MINBODY + nBL + nBR + aBorder.Width();
1481 0 : m_pPaperWidthEdit->SetMin(m_pPaperWidthEdit->Normalize(nMin), FUNIT_TWIP);
1482 :
1483 : // if the paper size has been changed
1484 0 : nH = static_cast<long>(m_pPaperHeightEdit->Denormalize(m_pPaperHeightEdit->GetValue(FUNIT_TWIP)));
1485 0 : nW = static_cast<long>(m_pPaperWidthEdit->Denormalize(m_pPaperWidthEdit->GetValue(FUNIT_TWIP)));
1486 :
1487 : // Top
1488 0 : long nMax = nH - nBB - aBorder.Height() - MINBODY -
1489 0 : nFDist - nFHeight - nHDist - nHHeight;
1490 :
1491 0 : m_pTopMarginEdit->SetMax(m_pTopMarginEdit->Normalize(nMax), FUNIT_TWIP);
1492 :
1493 : // Bottom
1494 0 : nMax = nH - nBT - aBorder.Height() - MINBODY -
1495 0 : nFDist - nFHeight - nHDist - nHHeight;
1496 :
1497 0 : m_pBottomMarginEdit->SetMax(m_pTopMarginEdit->Normalize(nMax), FUNIT_TWIP);
1498 :
1499 : // Left
1500 0 : nMax = nW - nBR - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1501 0 : m_pLeftMarginEdit->SetMax(m_pLeftMarginEdit->Normalize(nMax), FUNIT_TWIP);
1502 :
1503 : // Right
1504 0 : nMax = nW - nBL - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1505 0 : m_pRightMarginEdit->SetMax(m_pRightMarginEdit->Normalize(nMax), FUNIT_TWIP);
1506 0 : return 0;
1507 : }
1508 :
1509 :
1510 :
1511 0 : void SvxPageDescPage::CalcMargin_Impl()
1512 : {
1513 : // current values for page margins
1514 0 : long nBT = GetCoreValue( *m_pTopMarginEdit, SFX_MAPUNIT_TWIP );
1515 0 : long nBB = GetCoreValue( *m_pBottomMarginEdit, SFX_MAPUNIT_TWIP );
1516 :
1517 0 : long nBL = GetCoreValue( *m_pLeftMarginEdit, SFX_MAPUNIT_TWIP );
1518 0 : long nBR = GetCoreValue( *m_pRightMarginEdit, SFX_MAPUNIT_TWIP );
1519 :
1520 0 : long nH = GetCoreValue( *m_pPaperHeightEdit, SFX_MAPUNIT_TWIP );
1521 0 : long nW = GetCoreValue( *m_pPaperWidthEdit, SFX_MAPUNIT_TWIP );
1522 :
1523 0 : long nWidth = nBL + nBR + MINBODY;
1524 0 : long nHeight = nBT + nBB + MINBODY;
1525 :
1526 0 : if ( nWidth > nW || nHeight > nH )
1527 : {
1528 0 : if ( nWidth > nW )
1529 : {
1530 0 : long nTmp = nBL <= nBR ? nBR : nBL;
1531 0 : nTmp -= nWidth - nW;
1532 :
1533 0 : if ( nBL <= nBR )
1534 0 : SetMetricValue( *m_pRightMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1535 : else
1536 0 : SetMetricValue( *m_pLeftMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1537 : }
1538 :
1539 0 : if ( nHeight > nH )
1540 : {
1541 0 : long nTmp = nBT <= nBB ? nBB : nBT;
1542 0 : nTmp -= nHeight - nH;
1543 :
1544 0 : if ( nBT <= nBB )
1545 0 : SetMetricValue( *m_pBottomMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1546 : else
1547 0 : SetMetricValue( *m_pTopMarginEdit, nTmp, SFX_MAPUNIT_TWIP );
1548 : }
1549 : }
1550 0 : }
1551 :
1552 :
1553 :
1554 0 : IMPL_LINK_NOARG_INLINE_START(SvxPageDescPage, CenterHdl_Impl)
1555 : {
1556 0 : m_pBspWin->SetHorz( m_pHorzBox->IsChecked() );
1557 0 : m_pBspWin->SetVert( m_pVertBox->IsChecked() );
1558 0 : UpdateExample_Impl();
1559 0 : return 0;
1560 : }
1561 0 : IMPL_LINK_NOARG_INLINE_END(SvxPageDescPage, CenterHdl_Impl)
1562 :
1563 :
1564 :
1565 0 : void SvxPageDescPage::SetCollectionList(const std::vector<OUString> &aList)
1566 : {
1567 : OSL_ENSURE(!aList.empty(), "Empty string list");
1568 :
1569 0 : sStandardRegister = aList[0];
1570 0 : for( size_t i = 1; i < aList.size(); i++ )
1571 0 : m_pRegisterLB->InsertEntry(aList[i]);
1572 :
1573 0 : m_pRegisterCB->Show();
1574 0 : m_pRegisterFT->Show();
1575 0 : m_pRegisterLB->Show();
1576 0 : m_pRegisterCB->SetClickHdl(LINK(this, SvxPageDescPage, RegisterModify));
1577 0 : }
1578 :
1579 :
1580 :
1581 0 : IMPL_LINK( SvxPageDescPage, RegisterModify, CheckBox*, pBox )
1582 : {
1583 0 : sal_Bool bEnable = sal_False;
1584 0 : if(pBox->IsChecked())
1585 : {
1586 0 : bEnable = sal_True;
1587 0 : if(USHRT_MAX == m_pRegisterLB->GetSelectEntryPos())
1588 0 : m_pRegisterLB->SelectEntry(sStandardRegister);
1589 : }
1590 0 : m_pRegisterFT->Enable( bEnable );
1591 0 : m_pRegisterLB->Enable( bEnable );
1592 0 : return 0;
1593 : }
1594 :
1595 :
1596 :
1597 0 : void SvxPageDescPage::DisableVerticalPageDir()
1598 : {
1599 0 : m_pTextFlowBox->RemoveEntryValue( FRMDIR_VERT_TOP_RIGHT );
1600 0 : m_pTextFlowBox->RemoveEntryValue( FRMDIR_VERT_TOP_LEFT );
1601 0 : if( m_pTextFlowBox->GetEntryCount() < 2 )
1602 : {
1603 0 : m_pTextFlowLbl->Hide();
1604 0 : m_pTextFlowBox->Hide();
1605 0 : m_pBspWin->EnableFrameDirection( false );
1606 : }
1607 0 : }
1608 :
1609 0 : IMPL_LINK( SvxPageDescPage, FrameDirectionModify_Impl, ListBox*, EMPTYARG)
1610 : {
1611 0 : m_pBspWin->SetFrameDirection( (sal_uInt32) m_pTextFlowBox->GetSelectEntryValue() );
1612 0 : m_pBspWin->Invalidate();
1613 0 : return 0;
1614 : }
1615 :
1616 0 : bool SvxPageDescPage::IsPrinterRangeOverflow(
1617 : MetricField& rField, long nFirstMargin, long nLastMargin, MarginPosition nPos )
1618 : {
1619 0 : bool bRet = false;
1620 0 : bool bCheck = ( ( pImpl->m_nPos & nPos ) == 0 );
1621 0 : long nValue = static_cast<long>(rField.GetValue());
1622 0 : if ( bCheck &&
1623 0 : ( nValue < nFirstMargin || nValue > nLastMargin ) &&
1624 0 : rField.GetText() != rField.GetSavedValue() )
1625 : {
1626 0 : rField.SetValue( nValue < nFirstMargin ? nFirstMargin : nLastMargin );
1627 0 : bRet = true;
1628 : }
1629 :
1630 0 : return bRet;
1631 : }
1632 :
1633 : /** Check if a value of a margin edit is outside the printer paper margins
1634 : and save this information.
1635 : */
1636 0 : void SvxPageDescPage::CheckMarginEdits( bool _bClear )
1637 : {
1638 0 : if ( _bClear )
1639 0 : pImpl->m_nPos = 0;
1640 :
1641 0 : sal_Int64 nValue = m_pLeftMarginEdit->GetValue();
1642 0 : if ( nValue < nFirstLeftMargin || nValue > nLastLeftMargin )
1643 0 : pImpl->m_nPos |= MARGIN_LEFT;
1644 0 : nValue = m_pRightMarginEdit->GetValue();
1645 0 : if ( nValue < nFirstRightMargin || nValue > nLastRightMargin )
1646 0 : pImpl->m_nPos |= MARGIN_RIGHT;
1647 0 : nValue = m_pTopMarginEdit->GetValue();
1648 0 : if ( nValue < nFirstTopMargin || nValue > nLastTopMargin )
1649 0 : pImpl->m_nPos |= MARGIN_TOP;
1650 0 : nValue = m_pBottomMarginEdit->GetValue();
1651 0 : if ( nValue < nFirstBottomMargin || nValue > nLastBottomMargin )
1652 0 : pImpl->m_nPos |= MARGIN_BOTTOM;
1653 0 : }
1654 :
1655 0 : bool SvxPageDescPage::IsMarginOutOfRange()
1656 : {
1657 0 : bool bRet = ( ( ( !( pImpl->m_nPos & MARGIN_LEFT ) &&
1658 0 : ( m_pLeftMarginEdit->GetText() != m_pLeftMarginEdit->GetSavedValue() ) ) &&
1659 0 : ( m_pLeftMarginEdit->GetValue() < nFirstLeftMargin ||
1660 0 : m_pLeftMarginEdit->GetValue() > nLastLeftMargin ) ) ||
1661 0 : ( ( !( pImpl->m_nPos & MARGIN_RIGHT ) &&
1662 0 : ( m_pRightMarginEdit->GetText() != m_pRightMarginEdit->GetSavedValue() ) ) &&
1663 0 : ( m_pRightMarginEdit->GetValue() < nFirstRightMargin ||
1664 0 : m_pRightMarginEdit->GetValue() > nLastRightMargin ) ) ||
1665 0 : ( ( !( pImpl->m_nPos & MARGIN_TOP ) &&
1666 0 : ( m_pTopMarginEdit->GetText() != m_pTopMarginEdit->GetSavedValue() ) ) &&
1667 0 : ( m_pTopMarginEdit->GetValue() < nFirstTopMargin ||
1668 0 : m_pTopMarginEdit->GetValue() > nLastTopMargin ) ) ||
1669 0 : ( ( !( pImpl->m_nPos & MARGIN_BOTTOM ) &&
1670 0 : ( m_pBottomMarginEdit->GetText() != m_pBottomMarginEdit->GetSavedValue() ) ) &&
1671 0 : ( m_pBottomMarginEdit->GetValue() < nFirstBottomMargin ||
1672 0 : m_pBottomMarginEdit->GetValue() > nLastBottomMargin ) ) );
1673 0 : return bRet;
1674 : }
1675 :
1676 0 : void SvxPageDescPage::PageCreated (SfxAllItemSet aSet)
1677 : {
1678 0 : SFX_ITEMSET_ARG (&aSet,pModeItem,SfxAllEnumItem,SID_ENUM_PAGE_MODE,false);
1679 0 : SFX_ITEMSET_ARG (&aSet,pPaperStartItem,SfxAllEnumItem,SID_PAPER_START,false);
1680 0 : SFX_ITEMSET_ARG (&aSet,pPaperEndItem,SfxAllEnumItem,SID_PAPER_END,false);
1681 0 : SFX_ITEMSET_ARG (&aSet,pCollectListItem,SfxStringListItem,SID_COLLECT_LIST,false);
1682 0 : if (pModeItem)
1683 0 : SetMode((SvxModeType)pModeItem->GetEnumValue());
1684 0 : if (pPaperStartItem && pPaperEndItem)
1685 0 : SetPaperFormatRanges( (Paper)pPaperStartItem->GetEnumValue(), (Paper)pPaperEndItem->GetEnumValue() );
1686 0 : if (pCollectListItem)
1687 0 : SetCollectionList(pCollectListItem->GetList());
1688 0 : }
1689 :
1690 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|