bump product version to 4.1.6.2
[LibreOffice.git] / cui / source / tabpages / transfrm.cxx
blob9cd709f4722444953b72c24853ef024f87d9dee8
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 <tools/shl.hxx>
21 #include <sfx2/app.hxx>
22 #include <svx/svdview.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/svdpagv.hxx>
25 #include <svx/svdotext.hxx>
26 #include <svx/sderitm.hxx>
27 #include <svx/dialogs.hrc>
28 #include <cuires.hrc>
29 #include "transfrm.hrc"
30 #include <editeng/sizeitem.hxx>
32 #include "transfrm.hxx"
33 #include <dialmgr.hxx>
34 #include "svx/dlgutil.hxx"
35 #include <editeng/svxenum.hxx>
36 #include "svx/anchorid.hxx"
37 #include <sfx2/module.hxx>
38 #include <svl/rectitem.hxx>
39 #include <svl/aeitem.hxx>
40 #include <swpossizetabpage.hxx>
42 // static ----------------------------------------------------------------
44 static sal_uInt16 pPosSizeRanges[] =
46 SID_ATTR_TRANSFORM_POS_X,
47 SID_ATTR_TRANSFORM_POS_Y,
48 SID_ATTR_TRANSFORM_PROTECT_POS,
49 SID_ATTR_TRANSFORM_PROTECT_POS,
50 SID_ATTR_TRANSFORM_INTERN,
51 SID_ATTR_TRANSFORM_INTERN,
52 SID_ATTR_TRANSFORM_ANCHOR,
53 SID_ATTR_TRANSFORM_VERT_ORIENT,
54 SID_ATTR_TRANSFORM_WIDTH,
55 SID_ATTR_TRANSFORM_SIZE_POINT,
56 SID_ATTR_TRANSFORM_PROTECT_POS,
57 SID_ATTR_TRANSFORM_INTERN,
58 SID_ATTR_TRANSFORM_AUTOWIDTH,
59 SID_ATTR_TRANSFORM_AUTOHEIGHT,
63 static sal_uInt16 pAngleRanges[] =
65 SID_ATTR_TRANSFORM_ROT_X,
66 SID_ATTR_TRANSFORM_ANGLE,
67 SID_ATTR_TRANSFORM_INTERN,
68 SID_ATTR_TRANSFORM_INTERN,
72 static sal_uInt16 pSlantRanges[] =
74 SDRATTR_ECKENRADIUS,
75 SDRATTR_ECKENRADIUS,
76 SID_ATTR_TRANSFORM_SHEAR,
77 SID_ATTR_TRANSFORM_SHEAR_VERTICAL,
78 SID_ATTR_TRANSFORM_INTERN,
79 SID_ATTR_TRANSFORM_INTERN,
83 static void lcl_ConvertRect(basegfx::B2DRange& rRange, const sal_uInt16 nDigits, const MapUnit ePoolUnit, const FieldUnit eDlgUnit)
85 const basegfx::B2DPoint aTopLeft(
86 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinX()), nDigits, ePoolUnit, eDlgUnit),
87 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinY()), nDigits, ePoolUnit, eDlgUnit));
88 const basegfx::B2DPoint aBottomRight(
89 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxX()), nDigits, ePoolUnit, eDlgUnit),
90 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxY()), nDigits, ePoolUnit, eDlgUnit));
92 rRange = basegfx::B2DRange(aTopLeft, aBottomRight);
95 static void lcl_ScaleRect(basegfx::B2DRange& rRange, const Fraction aUIScale)
97 const double fFactor(1.0 / double(aUIScale));
98 rRange = basegfx::B2DRange(rRange.getMinimum() * fFactor, rRange.getMaximum() * fFactor);
101 /*************************************************************************
103 |* constructor of the tab dialog: adds the pages to the dialog
105 \************************************************************************/
107 SvxTransformTabDialog::SvxTransformTabDialog( Window* pParent, const SfxItemSet* pAttr,
108 const SdrView* pSdrView, sal_uInt16 nAnchorTypes ) :
109 SfxTabDialog( pParent, CUI_RES( RID_SVXDLG_TRANSFORM ), pAttr ),
110 pView ( pSdrView ),
111 nAnchorCtrls(nAnchorTypes)
113 DBG_ASSERT(pView, "no valid view (!)");
114 FreeResource();
116 //different positioning page in Writer
117 if(nAnchorCtrls & 0x00ff)
119 AddTabPage(RID_SVXPAGE_SWPOSSIZE, SvxSwPosSizeTabPage::Create, SvxSwPosSizeTabPage::GetRanges);
120 RemoveTabPage(RID_SVXPAGE_POSITION_SIZE);
122 else
124 AddTabPage(RID_SVXPAGE_POSITION_SIZE, SvxPositionSizeTabPage::Create, SvxPositionSizeTabPage::GetRanges);
125 RemoveTabPage(RID_SVXPAGE_SWPOSSIZE);
128 AddTabPage(RID_SVXPAGE_ANGLE, SvxAngleTabPage::Create, SvxAngleTabPage::GetRanges);
129 AddTabPage(RID_SVXPAGE_SLANT, SvxSlantTabPage::Create, SvxSlantTabPage::GetRanges);
132 // -----------------------------------------------------------------------
134 SvxTransformTabDialog::~SvxTransformTabDialog()
138 // -----------------------------------------------------------------------
140 void SvxTransformTabDialog::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
142 switch(nId)
144 case RID_SVXPAGE_POSITION_SIZE:
146 SvxPositionSizeTabPage& rSvxPos = static_cast<SvxPositionSizeTabPage&>(rPage);
147 rSvxPos.SetView(pView);
148 rSvxPos.Construct();
150 if(nAnchorCtrls & SVX_OBJ_NORESIZE)
152 rSvxPos.DisableResize();
155 if(nAnchorCtrls & SVX_OBJ_NOPROTECT)
157 rSvxPos.DisableProtect();
158 rSvxPos.UpdateControlStates();
161 break;
163 case RID_SVXPAGE_SWPOSSIZE :
165 SvxSwPosSizeTabPage& rSwPos = static_cast<SvxSwPosSizeTabPage&>(rPage);
167 rSwPos.EnableAnchorTypes(nAnchorCtrls);
168 rSwPos.SetValidateFramePosLink(aValidateLink);
169 rSwPos.SetView(pView);
171 break;
174 case RID_SVXPAGE_ANGLE:
176 SvxAngleTabPage& rSvxAng = static_cast<SvxAngleTabPage&>(rPage);
178 rSvxAng.SetView( pView );
179 rSvxAng.Construct();
181 break;
184 case RID_SVXPAGE_SLANT:
186 SvxSlantTabPage& rSvxSlnt = static_cast<SvxSlantTabPage&>(rPage);
188 rSvxSlnt.SetView( pView );
189 rSvxSlnt.Construct();
191 break;
196 // -----------------------------------------------------------------------
198 void SvxTransformTabDialog::SetValidateFramePosLink(const Link& rLink)
200 aValidateLink = rLink;
203 /*************************************************************************
205 |* dialog for changing the positions of the rotation
206 |* angle and the rotation angle of the graphic objects
208 \************************************************************************/
210 SvxAngleTabPage::SvxAngleTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
211 SvxTabPage ( pParent, CUI_RES( RID_SVXPAGE_ANGLE ), rInAttrs ),
212 aFlPosition ( this, CUI_RES( FL_POSITION ) ),
213 aFtPosX ( this, CUI_RES( FT_POS_X ) ),
214 aMtrPosX ( this, CUI_RES( MTR_FLD_POS_X ) ),
215 aFtPosY ( this, CUI_RES( FT_POS_Y ) ),
216 aMtrPosY ( this, CUI_RES( MTR_FLD_POS_Y ) ),
217 aFtPosPresets ( this, CUI_RES(FT_POSPRESETS) ),
218 aCtlRect ( this, CUI_RES( CTL_RECT ) ),
220 aFlAngle ( this, CUI_RES( FL_ANGLE ) ),
221 aFtAngle ( this, CUI_RES( FT_ANGLE ) ),
222 maNfAngle ( this, CUI_RES( NF_ANGLE ) ),
223 aFtAnglePresets ( this, CUI_RES(FT_ANGLEPRESETS) ),
224 aCtlAngle ( this, CUI_RES( CTL_ANGLE ) ),
225 rOutAttrs ( rInAttrs )
227 FreeResource();
229 // calculate PoolUnit
230 SfxItemPool* pPool = rOutAttrs.GetPool();
231 DBG_ASSERT( pPool, "no pool (!)" );
232 ePoolUnit = pPool->GetMetric(SID_ATTR_TRANSFORM_POS_X);
234 aCtlRect.SetAccessibleRelationLabeledBy(&aFtPosPresets);
235 aCtlRect.SetAccessibleRelationMemberOf(&aFlPosition);
236 aCtlAngle.SetAccessibleRelationLabeledBy(&aFtAnglePresets);
237 aCtlAngle.SetAccessibleRelationMemberOf(&aFlAngle);
238 aCtlAngle.SetLinkedField( &maNfAngle, 2 );
241 // -----------------------------------------------------------------------
243 void SvxAngleTabPage::Construct()
245 DBG_ASSERT(pView, "No valid view (!)");
246 eDlgUnit = GetModuleFieldUnit(GetItemSet());
247 SetFieldUnit(aMtrPosX, eDlgUnit, sal_True);
248 SetFieldUnit(aMtrPosY, eDlgUnit, sal_True);
250 if(FUNIT_MILE == eDlgUnit || FUNIT_KM == eDlgUnit)
252 aMtrPosX.SetDecimalDigits( 3 );
253 aMtrPosY.SetDecimalDigits( 3 );
256 { // #i75273#
257 Rectangle aTempRect(pView->GetAllMarkedRect());
258 pView->GetSdrPageView()->LogicToPagePos(aTempRect);
259 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
262 // Take anchor into account (Writer)
263 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
265 if(rMarkList.GetMarkCount())
267 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
268 maAnchor = basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y());
270 if(!maAnchor.equalZero()) // -> Writer
272 maRange = basegfx::B2DRange(maRange.getMinimum() - maAnchor, maRange.getMaximum() - maAnchor);
276 // take scale into account
277 const Fraction aUIScale(pView->GetModel()->GetUIScale());
278 lcl_ScaleRect(maRange, aUIScale);
280 // take UI units into account
281 sal_uInt16 nDigits(aMtrPosX.GetDecimalDigits());
282 lcl_ConvertRect(maRange, nDigits, (MapUnit)ePoolUnit, eDlgUnit);
284 if(!pView->IsRotateAllowed())
286 aFlPosition.Disable();
287 aFtPosX.Disable();
288 aMtrPosX.Disable();
289 aFtPosY.Disable();
290 aMtrPosY.Disable();
291 aFtPosPresets.Disable();
292 aCtlRect.Disable();
293 aFlAngle.Disable();
294 aFtAngle.Disable();
295 maNfAngle.Disable();
296 aFtAnglePresets.Disable();
297 aCtlAngle.Disable();
301 sal_Bool SvxAngleTabPage::FillItemSet(SfxItemSet& rSet)
303 sal_Bool bModified = sal_False;
305 if(aCtlAngle.IsValueModified() || aMtrPosX.IsValueModified() || aMtrPosY.IsValueModified())
307 const double fUIScale(double(pView->GetModel()->GetUIScale()));
308 const double fTmpX((GetCoreValue(aMtrPosX, ePoolUnit) + maAnchor.getX()) * fUIScale);
309 const double fTmpY((GetCoreValue(aMtrPosY, ePoolUnit) + maAnchor.getY()) * fUIScale);
311 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ANGLE), aCtlAngle.GetRotation()));
312 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ROT_X), basegfx::fround(fTmpX)));
313 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ROT_Y), basegfx::fround(fTmpY)));
315 bModified = sal_True;
318 return bModified;
321 // -----------------------------------------------------------------------
323 void SvxAngleTabPage::Reset(const SfxItemSet& rAttrs)
325 const double fUIScale(double(pView->GetModel()->GetUIScale()));
327 const SfxPoolItem* pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_ROT_X );
328 if(pItem)
330 const double fTmp(((double)((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getX()) / fUIScale);
331 SetMetricValue(aMtrPosX, basegfx::fround(fTmp), ePoolUnit);
333 else
335 aMtrPosX.SetText( String() );
338 pItem = GetItem(rAttrs, SID_ATTR_TRANSFORM_ROT_Y);
339 if(pItem)
341 const double fTmp(((double)((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getY()) / fUIScale);
342 SetMetricValue(aMtrPosY, basegfx::fround(fTmp), ePoolUnit);
344 else
346 aMtrPosY.SetText( String() );
349 pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_ANGLE );
350 if(pItem)
352 aCtlAngle.SetRotation(((const SfxInt32Item*)pItem)->GetValue());
354 else
356 aCtlAngle.SetRotation(0);
358 aCtlAngle.SaveValue();
361 // -----------------------------------------------------------------------
363 SfxTabPage* SvxAngleTabPage::Create( Window* pWindow, const SfxItemSet& rSet)
365 return(new SvxAngleTabPage(pWindow, rSet));
368 //------------------------------------------------------------------------
370 sal_uInt16* SvxAngleTabPage::GetRanges()
372 return(pAngleRanges);
375 // -----------------------------------------------------------------------
377 void SvxAngleTabPage::ActivatePage(const SfxItemSet& /*rSet*/)
381 // -----------------------------------------------------------------------
383 int SvxAngleTabPage::DeactivatePage( SfxItemSet* _pSet )
385 if(_pSet)
387 FillItemSet(*_pSet);
390 return LEAVE_PAGE;
393 //------------------------------------------------------------------------
395 void SvxAngleTabPage::PointChanged(Window* pWindow, RECT_POINT eRP)
397 if(pWindow == &aCtlRect)
399 switch(eRP)
401 case RP_LT:
403 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
404 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
405 break;
407 case RP_MT:
409 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
410 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
411 break;
413 case RP_RT:
415 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
416 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
417 break;
419 case RP_LM:
421 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
422 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
423 break;
425 case RP_MM:
427 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
428 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
429 break;
431 case RP_RM:
433 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
434 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
435 break;
437 case RP_LB:
439 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
440 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
441 break;
443 case RP_MB:
445 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
446 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
447 break;
449 case RP_RB:
451 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
452 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
453 break;
459 /*************************************************************************
461 |* dialog for changing slant and corner radius
463 \************************************************************************/
465 SvxSlantTabPage::SvxSlantTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
466 SvxTabPage ( pParent, CUI_RES( RID_SVXPAGE_SLANT ), rInAttrs ),
468 aFlRadius ( this, CUI_RES( FL_RADIUS ) ),
469 aFtRadius ( this, CUI_RES( FT_RADIUS ) ),
470 aMtrRadius ( this, CUI_RES( MTR_FLD_RADIUS ) ),
471 aFlAngle ( this, CUI_RES( FL_SLANT ) ),
472 aFtAngle ( this, CUI_RES( FT_ANGLE ) ),
473 aMtrAngle ( this, CUI_RES( MTR_FLD_ANGLE ) ),
474 rOutAttrs ( rInAttrs )
476 FreeResource();
478 // this page needs ExchangeSupport
479 SetExchangeSupport();
481 // evaluate PoolUnit
482 SfxItemPool* pPool = rOutAttrs.GetPool();
483 DBG_ASSERT( pPool, "no pool (!)" );
484 ePoolUnit = pPool->GetMetric( SID_ATTR_TRANSFORM_POS_X );
487 // -----------------------------------------------------------------------
489 void SvxSlantTabPage::Construct()
491 // get the range
492 DBG_ASSERT(pView, "no valid view (!)");
493 eDlgUnit = GetModuleFieldUnit(GetItemSet());
494 SetFieldUnit(aMtrRadius, eDlgUnit, sal_True);
496 { // #i75273#
497 Rectangle aTempRect(pView->GetAllMarkedRect());
498 pView->GetSdrPageView()->LogicToPagePos(aTempRect);
499 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
503 // -----------------------------------------------------------------------
505 sal_Bool SvxSlantTabPage::FillItemSet(SfxItemSet& rAttrs)
507 sal_Bool bModified = sal_False;
508 String aStr = aMtrRadius.GetText();
510 if( aStr != aMtrRadius.GetSavedValue() )
512 Fraction aUIScale = pView->GetModel()->GetUIScale();
513 long nTmp = GetCoreValue( aMtrRadius, ePoolUnit );
514 nTmp = Fraction( nTmp ) * aUIScale;
516 rAttrs.Put( SdrEckenradiusItem( nTmp ) );
517 bModified = sal_True;
520 aStr = aMtrAngle.GetText();
522 if( aStr != aMtrAngle.GetSavedValue() )
524 sal_Int32 nValue = static_cast<sal_Int32>(aMtrAngle.GetValue());
525 rAttrs.Put( SfxInt32Item( SID_ATTR_TRANSFORM_SHEAR, nValue ) );
526 bModified = sal_True;
529 if( bModified )
531 // set reference points
532 // #75897#
533 Rectangle aObjectRect(pView->GetAllMarkedRect());
534 pView->GetSdrPageView()->LogicToPagePos(aObjectRect);
535 Point aPt = aObjectRect.Center();
537 rAttrs.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_X, aPt.X()));
538 rAttrs.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_Y, aPt.Y()));
539 rAttrs.Put( SfxBoolItem( SID_ATTR_TRANSFORM_SHEAR_VERTICAL, sal_False ) );
542 return( bModified );
545 // -----------------------------------------------------------------------
547 void SvxSlantTabPage::Reset(const SfxItemSet& rAttrs)
549 // if the view has selected objects, items with SFX_ITEM_DEFAULT need to be disabled
550 const SfxPoolItem* pItem;
552 // corner radius
553 if(!pView->IsEdgeRadiusAllowed())
555 aFlRadius.Disable();
556 aFtRadius.Disable();
557 aMtrRadius.Disable();
558 aMtrRadius.SetText( String() );
560 else
562 pItem = GetItem( rAttrs, SDRATTR_ECKENRADIUS );
564 if( pItem )
566 const double fUIScale(double(pView->GetModel()->GetUIScale()));
567 const double fTmp((double)((const SdrEckenradiusItem*)pItem)->GetValue() / fUIScale);
568 SetMetricValue(aMtrRadius, basegfx::fround(fTmp), ePoolUnit);
570 else
572 aMtrRadius.SetText( String() );
576 aMtrRadius.SaveValue();
578 // slant: angle
579 if( !pView->IsShearAllowed() )
581 aFlAngle.Disable();
582 aFtAngle.Disable();
583 aMtrAngle.Disable();
584 aMtrAngle.SetText( String() );
586 else
588 pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_SHEAR );
590 if( pItem )
592 aMtrAngle.SetValue( ( (const SfxInt32Item*)pItem )->GetValue() );
594 else
596 aMtrAngle.SetText( String() );
600 aMtrAngle.SaveValue();
603 // -----------------------------------------------------------------------
605 SfxTabPage* SvxSlantTabPage::Create( Window* pWindow, const SfxItemSet& rOutAttrs )
607 return( new SvxSlantTabPage( pWindow, rOutAttrs ) );
610 //------------------------------------------------------------------------
612 sal_uInt16* SvxSlantTabPage::GetRanges()
614 return( pSlantRanges );
617 // -----------------------------------------------------------------------
619 void SvxSlantTabPage::ActivatePage( const SfxItemSet& rSet )
621 SfxRectangleItem* pRectItem = NULL;
623 if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_TRANSFORM_INTERN ) , sal_False, (const SfxPoolItem**) &pRectItem ) )
625 const Rectangle aTempRect(pRectItem->GetValue());
626 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
630 // -----------------------------------------------------------------------
632 int SvxSlantTabPage::DeactivatePage( SfxItemSet* _pSet )
634 if(_pSet)
636 FillItemSet(*_pSet);
639 return LEAVE_PAGE;
642 //------------------------------------------------------------------------
644 void SvxSlantTabPage::PointChanged( Window* , RECT_POINT )
648 /*************************************************************************
650 |* Dialog for changing position and size of graphic objects
652 \************************************************************************/
654 SvxPositionSizeTabPage::SvxPositionSizeTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
655 SvxTabPage ( pParent, CUI_RES( RID_SVXPAGE_POSITION_SIZE ), rInAttrs ),
656 maFlPosition ( this, CUI_RES( FL_POSITION ) ),
657 maFtPosX ( this, CUI_RES( FT_POS_X ) ),
658 maMtrPosX ( this, CUI_RES( MTR_FLD_POS_X ) ),
659 maFtPosY ( this, CUI_RES( FT_POS_Y ) ),
660 maMtrPosY ( this, CUI_RES( MTR_FLD_POS_Y ) ),
661 maFtPosReference ( this, CUI_RES( FT_POSREFERENCE ) ),
662 maCtlPos ( this, CUI_RES( CTL_POSRECT ), RP_LT ),
664 maFlSize ( this, CUI_RES( FL_SIZE ) ),
665 maFtWidth ( this, CUI_RES( FT_WIDTH ) ),
666 maMtrWidth ( this, CUI_RES( MTR_FLD_WIDTH ) ),
667 maFtHeight ( this, CUI_RES( FT_HEIGHT ) ),
668 maMtrHeight ( this, CUI_RES( MTR_FLD_HEIGHT ) ),
669 maCbxScale ( this, CUI_RES( CBX_SCALE ) ),
670 maFtSizeReference ( this, CUI_RES( FT_SIZEREFERENCE) ),
671 maCtlSize ( this, CUI_RES( CTL_SIZERECT ), RP_LT ),
673 maFlProtect ( this, CUI_RES( FL_PROTECT) ),
674 maTsbPosProtect ( this, CUI_RES( TSB_POSPROTECT ) ),
675 maTsbSizeProtect ( this, CUI_RES( TSB_SIZEPROTECT ) ),
678 maFlAdjust ( this, CUI_RES( FL_ADJUST ) ),
679 maTsbAutoGrowWidth ( this, CUI_RES( TSB_AUTOGROW_WIDTH ) ),
680 maTsbAutoGrowHeight ( this, CUI_RES( TSB_AUTOGROW_HEIGHT ) ),
682 maFlDivider (this, CUI_RES( FL_DIVIDER ) ),
684 mrOutAttrs ( rInAttrs ),
685 mnProtectSizeState( STATE_NOCHECK ),
686 mbPageDisabled ( sal_False ),
687 mbProtectDisabled( false ),
688 mbSizeDisabled( false ),
689 mbAdjustDisabled( true )
691 FreeResource();
693 // this pege needs ExchangeSupport
694 SetExchangeSupport();
696 // evaluate PoolUnit
697 SfxItemPool* pPool = mrOutAttrs.GetPool();
698 DBG_ASSERT( pPool, "no pool (!)" );
699 mePoolUnit = pPool->GetMetric( SID_ATTR_TRANSFORM_POS_X );
701 meRP = RP_LT; // see above
703 maMtrWidth.SetModifyHdl( LINK( this, SvxPositionSizeTabPage, ChangeWidthHdl ) );
704 maMtrHeight.SetModifyHdl( LINK( this, SvxPositionSizeTabPage, ChangeHeightHdl ) );
705 maCbxScale.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickAutoHdl ) );
707 maTsbAutoGrowWidth.Disable();
708 maTsbAutoGrowHeight.Disable();
709 maFlAdjust.Disable();
711 // #i2379# disable controls when protected
712 maTsbPosProtect.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ChangePosProtectHdl ) );
713 maTsbSizeProtect.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ChangeSizeProtectHdl ) );
715 maCtlPos.SetAccessibleRelationMemberOf( &maFlPosition );
716 maCtlSize.SetAccessibleRelationMemberOf( &maFlSize );
717 maCtlPos.SetAccessibleRelationLabeledBy( &maFtPosReference );
718 maCtlSize.SetAccessibleRelationLabeledBy( &maFtSizeReference );
721 // -----------------------------------------------------------------------
723 void SvxPositionSizeTabPage::Construct()
725 // get range and work area
726 DBG_ASSERT( mpView, "no valid view (!)" );
727 meDlgUnit = GetModuleFieldUnit( GetItemSet() );
728 SetFieldUnit( maMtrPosX, meDlgUnit, sal_True );
729 SetFieldUnit( maMtrPosY, meDlgUnit, sal_True );
730 SetFieldUnit( maMtrWidth, meDlgUnit, sal_True );
731 SetFieldUnit( maMtrHeight, meDlgUnit, sal_True );
733 if(FUNIT_MILE == meDlgUnit || FUNIT_KM == meDlgUnit)
735 maMtrPosX.SetDecimalDigits( 3 );
736 maMtrPosY.SetDecimalDigits( 3 );
737 maMtrWidth.SetDecimalDigits( 3 );
738 maMtrHeight.SetDecimalDigits( 3 );
741 { // #i75273#
742 Rectangle aTempRect(mpView->GetAllMarkedRect());
743 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
744 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
747 { // #i75273#
748 Rectangle aTempRect(mpView->GetWorkArea());
749 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
750 maWorkRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
753 // take anchor into account (Writer)
754 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
756 if(rMarkList.GetMarkCount())
758 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
759 maAnchor = basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y());
761 if(!maAnchor.equalZero()) // -> Writer
763 for(sal_uInt16 i(1); i < rMarkList.GetMarkCount(); i++)
765 pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
767 if(maAnchor != basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y()))
769 // diferent anchor positions
770 maMtrPosX.SetText( String() );
771 maMtrPosY.SetText( String() );
772 mbPageDisabled = sal_True;
773 return;
777 // translate ranges about anchor
778 maRange = basegfx::B2DRange(maRange.getMinimum() - maAnchor, maRange.getMaximum() - maAnchor);
779 maWorkRange = basegfx::B2DRange(maWorkRange.getMinimum() - maAnchor, maWorkRange.getMaximum() - maAnchor);
783 // this should happen via SID_ATTR_TRANSFORM_AUTOSIZE
784 if(1 == rMarkList.GetMarkCount())
786 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
787 const SdrObjKind eKind((SdrObjKind)pObj->GetObjIdentifier());
789 if((pObj->GetObjInventor() == SdrInventor) && (OBJ_TEXT == eKind || OBJ_TITLETEXT == eKind || OBJ_OUTLINETEXT == eKind) && ((SdrTextObj*)pObj)->HasText())
791 mbAdjustDisabled = false;
792 maFlAdjust.Enable();
793 maTsbAutoGrowWidth.Enable();
794 maTsbAutoGrowHeight.Enable();
795 maTsbAutoGrowWidth.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickSizeProtectHdl ) );
796 maTsbAutoGrowHeight.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickSizeProtectHdl ) );
798 // is used as flag to evaluate if its selectable
799 maTsbAutoGrowWidth.EnableTriState( sal_False );
800 maTsbAutoGrowHeight.EnableTriState( sal_False );
804 // take scale into account
805 const Fraction aUIScale(mpView->GetModel()->GetUIScale());
806 lcl_ScaleRect( maWorkRange, aUIScale );
807 lcl_ScaleRect( maRange, aUIScale );
809 // take UI units into account
810 const sal_uInt16 nDigits(maMtrPosX.GetDecimalDigits());
811 lcl_ConvertRect( maWorkRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit );
812 lcl_ConvertRect( maRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit );
814 SetMinMaxPosition();
817 // -----------------------------------------------------------------------
819 sal_Bool SvxPositionSizeTabPage::FillItemSet( SfxItemSet& rOutAttrs )
821 sal_Bool bModified(sal_False);
823 if ( maMtrWidth.HasFocus() )
825 ChangeWidthHdl( this );
828 if ( maMtrHeight.HasFocus() )
830 ChangeHeightHdl( this );
833 if( !mbPageDisabled )
835 if ( maMtrPosX.IsValueModified() || maMtrPosY.IsValueModified() )
837 const double fUIScale(double(mpView->GetModel()->GetUIScale()));
838 double fX((GetCoreValue( maMtrPosX, mePoolUnit ) + maAnchor.getX()) * fUIScale);
839 double fY((GetCoreValue( maMtrPosY, mePoolUnit ) + maAnchor.getY()) * fUIScale);
841 { // #i75273#
842 Rectangle aTempRect(mpView->GetAllMarkedRect());
843 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
844 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
847 // #101581# GetTopLeftPosition(...) needs coordinates after UI scaling, in real PagePositions
848 GetTopLeftPosition(fX, fY, maRange);
850 rOutAttrs.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_POS_X), basegfx::fround(fX)));
851 rOutAttrs.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_POS_Y), basegfx::fround(fY)));
853 bModified |= sal_True;
856 if ( maTsbPosProtect.GetState() != maTsbPosProtect.GetSavedValue() )
858 if( maTsbPosProtect.GetState() == STATE_DONTKNOW )
860 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_PROTECT_POS );
862 else
864 rOutAttrs.Put(
865 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_PROTECT_POS ),
866 maTsbPosProtect.GetState() == STATE_CHECK ? sal_True : sal_False ) );
869 bModified |= sal_True;
873 if ( maMtrWidth.IsValueModified() || maMtrHeight.IsValueModified() )
875 Fraction aUIScale = mpView->GetModel()->GetUIScale();
877 // get Width
878 double nWidth = static_cast<double>(maMtrWidth.GetValue( meDlgUnit ));
879 nWidth = MetricField::ConvertDoubleValue( nWidth, maMtrWidth.GetBaseValue(), maMtrWidth.GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
880 long lWidth = long(nWidth * (double)aUIScale);
881 lWidth = OutputDevice::LogicToLogic( lWidth, MAP_100TH_MM, (MapUnit)mePoolUnit );
882 lWidth = static_cast<long>(maMtrWidth.Denormalize( lWidth ));
884 // get Height
885 double nHeight = static_cast<double>(maMtrHeight.GetValue( meDlgUnit ));
886 nHeight = MetricField::ConvertDoubleValue( nHeight, maMtrHeight.GetBaseValue(), maMtrHeight.GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
887 long lHeight = long(nHeight * (double)aUIScale);
888 lHeight = OutputDevice::LogicToLogic( lHeight, MAP_100TH_MM, (MapUnit)mePoolUnit );
889 lHeight = static_cast<long>(maMtrHeight.Denormalize( lHeight ));
891 // put Width & Height to itemset
892 rOutAttrs.Put( SfxUInt32Item( GetWhich( SID_ATTR_TRANSFORM_WIDTH ),
893 (sal_uInt32) lWidth ) );
894 rOutAttrs.Put( SfxUInt32Item( GetWhich( SID_ATTR_TRANSFORM_HEIGHT ),
895 (sal_uInt32) lHeight ) );
896 rOutAttrs.Put( SfxAllEnumItem( GetWhich( SID_ATTR_TRANSFORM_SIZE_POINT ), sal::static_int_cast< sal_uInt16 >( meRP ) ) );
897 bModified |= sal_True;
900 if ( maTsbSizeProtect.GetState() != maTsbSizeProtect.GetSavedValue() )
902 if ( maTsbSizeProtect.GetState() == STATE_DONTKNOW )
903 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_PROTECT_SIZE );
904 else
905 rOutAttrs.Put(
906 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_PROTECT_SIZE ),
907 maTsbSizeProtect.GetState() == STATE_CHECK ? sal_True : sal_False ) );
908 bModified |= sal_True;
911 if ( maTsbAutoGrowWidth.GetState() != maTsbAutoGrowWidth.GetSavedValue() )
913 if ( !maTsbAutoGrowWidth.IsTriStateEnabled() )
915 if( maTsbAutoGrowWidth.GetState() == STATE_DONTKNOW )
916 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_AUTOWIDTH );
917 else
918 rOutAttrs.Put(
919 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_AUTOWIDTH ),
920 maTsbAutoGrowWidth.GetState() == STATE_CHECK ? sal_True : sal_False ) );
922 bModified |= sal_True;
925 if ( maTsbAutoGrowHeight.GetState() != maTsbAutoGrowHeight.GetSavedValue() )
927 if ( !maTsbAutoGrowHeight.IsTriStateEnabled() )
929 if( maTsbAutoGrowHeight.GetState() == STATE_DONTKNOW )
930 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_AUTOHEIGHT );
931 else
932 rOutAttrs.Put(
933 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_AUTOHEIGHT ),
934 maTsbAutoGrowHeight.GetState() == STATE_CHECK ? sal_True : sal_False ) );
936 bModified |= sal_True;
940 return bModified;
943 // -----------------------------------------------------------------------
945 void SvxPositionSizeTabPage::Reset( const SfxItemSet& )
947 const SfxPoolItem* pItem;
948 const double fUIScale(double(mpView->GetModel()->GetUIScale()));
950 if ( !mbPageDisabled )
952 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_POS_X );
953 if ( pItem )
955 const double fTmp((((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getX()) / fUIScale);
956 SetMetricValue(maMtrPosX, basegfx::fround(fTmp), mePoolUnit);
959 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_POS_Y );
960 if ( pItem )
962 const double fTmp((((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getY()) / fUIScale);
963 SetMetricValue(maMtrPosY, basegfx::fround(fTmp), mePoolUnit);
966 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_PROTECT_POS );
967 if ( pItem )
969 sal_Bool bProtected = ( ( const SfxBoolItem* )pItem )->GetValue();
970 maTsbPosProtect.SetState( bProtected ? STATE_CHECK : STATE_NOCHECK );
971 maTsbPosProtect.EnableTriState( sal_False );
973 else
975 maTsbPosProtect.SetState( STATE_DONTKNOW );
978 maTsbPosProtect.SaveValue();
979 maCtlPos.Reset();
981 // #i2379# Disable controls for protected objects
982 ChangePosProtectHdl( this );
985 { // #i75273# set width
986 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_WIDTH );
987 mfOldWidth = std::max( pItem ? (double)((const SfxUInt32Item*)pItem)->GetValue() : 0.0, 1.0 );
988 double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32>(mfOldWidth), (MapUnit)mePoolUnit, MAP_100TH_MM)) / fUIScale);
990 if(maMtrWidth.GetDecimalDigits())
991 fTmpWidth *= pow(10.0, maMtrWidth.GetDecimalDigits());
993 fTmpWidth = MetricField::ConvertDoubleValue(fTmpWidth, maMtrWidth.GetBaseValue(), maMtrWidth.GetDecimalDigits(), FUNIT_100TH_MM, meDlgUnit);
994 maMtrWidth.SetValue(static_cast<sal_Int64>(fTmpWidth), meDlgUnit);
997 { // #i75273# set height
998 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_HEIGHT );
999 mfOldHeight = std::max( pItem ? (double)((const SfxUInt32Item*)pItem)->GetValue() : 0.0, 1.0 );
1000 double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(mfOldHeight), (MapUnit)mePoolUnit, MAP_100TH_MM)) / fUIScale);
1002 if(maMtrHeight.GetDecimalDigits())
1003 fTmpHeight *= pow(10.0, maMtrHeight.GetDecimalDigits());
1005 fTmpHeight = MetricField::ConvertDoubleValue(fTmpHeight, maMtrHeight.GetBaseValue(), maMtrHeight.GetDecimalDigits(), FUNIT_100TH_MM, meDlgUnit);
1006 maMtrHeight.SetValue(static_cast<sal_Int64>(fTmpHeight), meDlgUnit);
1009 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_PROTECT_SIZE );
1010 if ( pItem )
1012 maTsbSizeProtect.SetState( ( (const SfxBoolItem*)pItem )->GetValue()
1013 ? STATE_CHECK : STATE_NOCHECK );
1014 maTsbSizeProtect.EnableTriState( sal_False );
1016 else
1017 maTsbSizeProtect.SetState( STATE_DONTKNOW );
1019 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_AUTOWIDTH );
1020 if ( pItem )
1022 maTsbAutoGrowWidth.SetState( ( ( const SfxBoolItem* )pItem )->GetValue()
1023 ? STATE_CHECK : STATE_NOCHECK );
1025 else
1026 maTsbAutoGrowWidth.SetState( STATE_DONTKNOW );
1028 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_AUTOHEIGHT );
1029 if ( pItem )
1031 maTsbAutoGrowHeight.SetState( ( ( const SfxBoolItem* )pItem )->GetValue()
1032 ? STATE_CHECK : STATE_NOCHECK );
1034 else
1035 maTsbAutoGrowHeight.SetState( STATE_DONTKNOW );
1037 // Is matching set?
1038 String aStr = GetUserData();
1039 maCbxScale.Check( (sal_Bool)aStr.ToInt32() );
1041 maTsbSizeProtect.SaveValue();
1042 maTsbAutoGrowWidth.SaveValue();
1043 maTsbAutoGrowHeight.SaveValue();
1044 ClickSizeProtectHdl( NULL );
1046 // #i2379# Disable controls for protected objects
1047 ChangeSizeProtectHdl( this );
1050 // -----------------------------------------------------------------------
1052 SfxTabPage* SvxPositionSizeTabPage::Create( Window* pWindow, const SfxItemSet& rOutAttrs )
1054 return( new SvxPositionSizeTabPage( pWindow, rOutAttrs ) );
1057 //------------------------------------------------------------------------
1059 sal_uInt16* SvxPositionSizeTabPage::GetRanges()
1061 return( pPosSizeRanges );
1064 // -----------------------------------------------------------------------
1066 void SvxPositionSizeTabPage::ActivatePage( const SfxItemSet& rSet )
1068 SfxRectangleItem* pRectItem = NULL;
1070 if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_TRANSFORM_INTERN ) , sal_False, (const SfxPoolItem**) &pRectItem ) )
1072 { // #i75273#
1073 const Rectangle aTempRect(pRectItem->GetValue());
1074 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
1077 SetMinMaxPosition();
1081 // -----------------------------------------------------------------------
1083 int SvxPositionSizeTabPage::DeactivatePage( SfxItemSet* _pSet )
1085 if( _pSet )
1087 double fX((double)maMtrPosX.GetValue());
1088 double fY((double)maMtrPosY.GetValue());
1090 GetTopLeftPosition(fX, fY, maRange);
1091 const Rectangle aOutRectangle(
1092 basegfx::fround(fX), basegfx::fround(fY),
1093 basegfx::fround(fX + maRange.getWidth()), basegfx::fround(fY + maRange.getHeight()));
1094 _pSet->Put(SfxRectangleItem(SID_ATTR_TRANSFORM_INTERN, aOutRectangle));
1096 FillItemSet(*_pSet);
1099 return LEAVE_PAGE;
1102 //------------------------------------------------------------------------
1104 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ChangePosProtectHdl)
1106 // #106572# Remember user's last choice
1107 maTsbSizeProtect.SetState( maTsbPosProtect.GetState() == STATE_CHECK ? STATE_CHECK : mnProtectSizeState );
1108 UpdateControlStates();
1109 return( 0L );
1112 //------------------------------------------------------------------------
1114 void SvxPositionSizeTabPage::UpdateControlStates()
1116 const bool bPosProtect = maTsbPosProtect.GetState() == STATE_CHECK;
1117 const bool bSizeProtect = maTsbSizeProtect.GetState() == STATE_CHECK;
1118 const bool bHeightChecked = !maTsbAutoGrowHeight.IsTriStateEnabled() && (maTsbAutoGrowHeight.GetState() == STATE_CHECK);
1119 const bool bWidthChecked = !maTsbAutoGrowWidth.IsTriStateEnabled() && (maTsbAutoGrowWidth.GetState() == STATE_CHECK);
1121 maFlPosition.Enable( !bPosProtect && !mbPageDisabled );
1122 maFtPosX.Enable( !bPosProtect && !mbPageDisabled );
1123 maMtrPosX.Enable( !bPosProtect && !mbPageDisabled );
1124 maFtPosY.Enable( !bPosProtect && !mbPageDisabled );
1125 maMtrPosY.Enable( !bPosProtect && !mbPageDisabled );
1126 maFtPosReference.Enable( !bPosProtect && !mbPageDisabled );
1127 maCtlPos.Enable( !bPosProtect );
1128 maTsbPosProtect.Enable( !mbProtectDisabled && !mbPageDisabled );
1130 maFlSize.Enable( !mbSizeDisabled && !bSizeProtect );
1131 maCtlSize.Enable( !mbSizeDisabled && !bSizeProtect && (!bHeightChecked || !bWidthChecked) );
1132 maFtWidth.Enable( !mbSizeDisabled && !bSizeProtect && !bWidthChecked );
1133 maMtrWidth.Enable( !mbSizeDisabled && !bSizeProtect && !bWidthChecked );
1134 maFtHeight.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked );
1135 maMtrHeight.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked );
1136 maCbxScale.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked && !bWidthChecked );
1137 maFtSizeReference.Enable( !mbSizeDisabled && !bSizeProtect );
1138 maFlProtect.Enable( !mbProtectDisabled );
1139 maTsbSizeProtect.Enable( !mbProtectDisabled && !bPosProtect );
1141 maFlAdjust.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1142 maTsbAutoGrowWidth.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1143 maTsbAutoGrowHeight.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1145 maCtlSize.Invalidate();
1146 maCtlPos.Invalidate();
1150 //------------------------------------------------------------------------
1152 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ChangeSizeProtectHdl)
1154 if( maTsbSizeProtect.IsEnabled() )
1156 // #106572# Remember user's last choice
1158 // Note: this works only as long as the dialog is open. When
1159 // the user closes the dialog, there is no way to remember
1160 // whether size was enabled or disabled befor pos protect was
1161 // clicked. Thus, if pos protect is selected, the dialog is
1162 // closed and reopened again, unchecking pos protect will
1163 // always uncheck size protect, too. That's life.
1164 mnProtectSizeState = maTsbSizeProtect.GetState();
1167 UpdateControlStates();
1169 return( 0L );
1172 //------------------------------------------------------------------------
1174 void SvxPositionSizeTabPage::SetMinMaxPosition()
1176 // position
1177 double fLeft(maWorkRange.getMinX());
1178 double fTop(maWorkRange.getMinY());
1179 double fRight(maWorkRange.getMaxX());
1180 double fBottom(maWorkRange.getMaxY());
1182 switch ( maCtlPos.GetActualRP() )
1184 case RP_LT:
1186 fRight -= maRange.getWidth();
1187 fBottom -= maRange.getHeight();
1188 break;
1190 case RP_MT:
1192 fLeft += maRange.getWidth() / 2.0;
1193 fRight -= maRange.getWidth() / 2.0;
1194 fBottom -= maRange.getHeight();
1195 break;
1197 case RP_RT:
1199 fLeft += maRange.getWidth();
1200 fBottom -= maRange.getHeight();
1201 break;
1203 case RP_LM:
1205 fRight -= maRange.getWidth();
1206 fTop += maRange.getHeight() / 2.0;
1207 fBottom -= maRange.getHeight() / 2.0;
1208 break;
1210 case RP_MM:
1212 fLeft += maRange.getWidth() / 2.0;
1213 fRight -= maRange.getWidth() / 2.0;
1214 fTop += maRange.getHeight() / 2.0;
1215 fBottom -= maRange.getHeight() / 2.0;
1216 break;
1218 case RP_RM:
1220 fLeft += maRange.getWidth();
1221 fTop += maRange.getHeight() / 2.0;
1222 fBottom -= maRange.getHeight() / 2.0;
1223 break;
1225 case RP_LB:
1227 fRight -= maRange.getWidth();
1228 fTop += maRange.getHeight();
1229 break;
1231 case RP_MB:
1233 fLeft += maRange.getWidth() / 2.0;
1234 fRight -= maRange.getWidth() / 2.0;
1235 fTop += maRange.getHeight();
1236 break;
1238 case RP_RB:
1240 fLeft += maRange.getWidth();
1241 fTop += maRange.getHeight();
1242 break;
1246 const double fMaxLong((double)(MetricField::ConvertValue( LONG_MAX, 0, MAP_100TH_MM, meDlgUnit ) - 1L));
1247 fLeft = (fLeft > fMaxLong) ? fMaxLong : (fLeft < -fMaxLong) ? -fMaxLong : fLeft;
1248 fRight = (fRight > fMaxLong) ? fMaxLong : (fRight < -fMaxLong) ? -fMaxLong : fRight;
1249 fTop = (fTop > fMaxLong) ? fMaxLong : (fTop < -fMaxLong) ? -fMaxLong : fTop;
1250 fBottom = (fBottom > fMaxLong) ? fMaxLong : (fBottom < -fMaxLong) ? -fMaxLong : fBottom;
1252 // #i75273# normalizing when setting the min/max values was wrong, removed
1253 maMtrPosX.SetMin(basegfx::fround64(fLeft));
1254 maMtrPosX.SetFirst(basegfx::fround64(fLeft));
1255 maMtrPosX.SetMax(basegfx::fround64(fRight));
1256 maMtrPosX.SetLast(basegfx::fround64(fRight));
1257 maMtrPosY.SetMin(basegfx::fround64(fTop));
1258 maMtrPosY.SetFirst(basegfx::fround64(fTop));
1259 maMtrPosY.SetMax(basegfx::fround64(fBottom));
1260 maMtrPosY.SetLast(basegfx::fround64(fBottom));
1262 // size
1263 fLeft = maWorkRange.getMinX();
1264 fTop = maWorkRange.getMinY();
1265 fRight = maWorkRange.getMaxX();
1266 fBottom = maWorkRange.getMaxY();
1267 double fNewX(0);
1268 double fNewY(0);
1270 switch ( maCtlSize.GetActualRP() )
1272 case RP_LT:
1274 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1275 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1276 break;
1278 case RP_MT:
1280 fNewX = std::min( maRange.getCenter().getX() - fLeft, fRight - maRange.getCenter().getX() ) * 2.0;
1281 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1282 break;
1284 case RP_RT:
1286 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1287 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1288 break;
1290 case RP_LM:
1292 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1293 fNewY = std::min( maRange.getCenter().getY() - fTop, fBottom - maRange.getCenter().getY() ) * 2.0;
1294 break;
1296 case RP_MM:
1298 const double f1(maRange.getCenter().getX() - fLeft);
1299 const double f2(fRight - maRange.getCenter().getX());
1300 const double f3(std::min(f1, f2));
1301 const double f4(maRange.getCenter().getY() - fTop);
1302 const double f5(fBottom - maRange.getCenter().getY());
1303 const double f6(std::min(f4, f5));
1305 fNewX = f3 * 2.0;
1306 fNewY = f6 * 3.0;
1308 break;
1310 case RP_RM:
1312 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1313 fNewY = std::min( maRange.getCenter().getY() - fTop, fBottom - maRange.getCenter().getY() ) * 2.0;
1314 break;
1316 case RP_LB:
1318 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1319 fNewY = maWorkRange.getHeight() - ( fBottom - maRange.getMaxY() );
1320 break;
1322 case RP_MB:
1324 fNewX = std::min( maRange.getCenter().getX() - fLeft, fRight - maRange.getCenter().getX() ) * 2.0;
1325 fNewY = maWorkRange.getHeight() - ( maRange.getMaxY() - fBottom );
1326 break;
1328 case RP_RB:
1330 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1331 fNewY = maWorkRange.getHeight() - ( fBottom - maRange.getMaxY() );
1332 break;
1336 // #i75273# normalizing when setting the min/max values was wrong, removed
1337 maMtrWidth.SetMax(basegfx::fround64(fNewX));
1338 maMtrWidth.SetLast(basegfx::fround64(fNewX));
1339 maMtrHeight.SetMax(basegfx::fround64(fNewY));
1340 maMtrHeight.SetLast(basegfx::fround64(fNewY));
1343 //------------------------------------------------------------------------
1345 void SvxPositionSizeTabPage::GetTopLeftPosition(double& rfX, double& rfY, const basegfx::B2DRange& rRange)
1347 switch (maCtlPos.GetActualRP())
1349 case RP_LT:
1351 break;
1353 case RP_MT:
1355 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1356 break;
1358 case RP_RT:
1360 rfX -= rRange.getWidth();
1361 break;
1363 case RP_LM:
1365 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1366 break;
1368 case RP_MM:
1370 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1371 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1372 break;
1374 case RP_RM:
1376 rfX -= rRange.getWidth();
1377 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1378 break;
1380 case RP_LB:
1382 rfY -= rRange.getHeight();
1383 break;
1385 case RP_MB:
1387 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1388 rfY -= rRange.getHeight();
1389 break;
1391 case RP_RB:
1393 rfX -= rRange.getWidth();
1394 rfY -= rRange.getHeight();
1395 break;
1400 //------------------------------------------------------------------------
1402 void SvxPositionSizeTabPage::PointChanged( Window* pWindow, RECT_POINT eRP )
1404 if( pWindow == &maCtlPos )
1406 SetMinMaxPosition();
1407 switch( eRP )
1409 case RP_LT:
1411 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1412 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1413 break;
1415 case RP_MT:
1417 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1418 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1419 break;
1421 case RP_RT:
1423 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1424 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1425 break;
1427 case RP_LM:
1429 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1430 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1431 break;
1433 case RP_MM:
1435 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1436 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1437 break;
1439 case RP_RM:
1441 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1442 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1443 break;
1445 case RP_LB:
1447 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1448 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1449 break;
1451 case RP_MB:
1453 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1454 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1455 break;
1457 case RP_RB:
1459 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1460 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1461 break;
1465 else
1467 meRP = eRP;
1468 SetMinMaxPosition();
1472 //------------------------------------------------------------------------
1474 void SvxPositionSizeTabPage::DisableResize()
1476 mbSizeDisabled = true;
1479 //------------------------------------------------------------------------
1481 void SvxPositionSizeTabPage::DisableProtect()
1483 mbProtectDisabled = true;
1486 //------------------------------------------------------------------------
1488 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ChangeWidthHdl)
1490 if( maCbxScale.IsChecked() && maCbxScale.IsEnabled() )
1492 sal_Int64 nHeight(basegfx::fround64((mfOldHeight * (double)maMtrWidth.GetValue()) / mfOldWidth));
1494 if(nHeight <= maMtrHeight.GetMax(FUNIT_NONE))
1496 maMtrHeight.SetUserValue(nHeight, FUNIT_NONE);
1498 else
1500 nHeight = maMtrHeight.GetMax(FUNIT_NONE);
1501 maMtrHeight.SetUserValue(nHeight);
1503 const sal_Int64 nWidth(basegfx::fround64((mfOldWidth * (double)nHeight) / mfOldHeight));
1504 maMtrWidth.SetUserValue(nWidth, FUNIT_NONE);
1508 return( 0L );
1511 //------------------------------------------------------------------------
1513 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ChangeHeightHdl)
1515 if( maCbxScale.IsChecked() && maCbxScale.IsEnabled() )
1517 sal_Int64 nWidth(basegfx::fround64((mfOldWidth * (double)maMtrHeight.GetValue()) / mfOldHeight));
1519 if(nWidth <= maMtrWidth.GetMax(FUNIT_NONE))
1521 maMtrWidth.SetUserValue(nWidth, FUNIT_NONE);
1523 else
1525 nWidth = maMtrWidth.GetMax(FUNIT_NONE);
1526 maMtrWidth.SetUserValue(nWidth);
1528 const sal_Int64 nHeight(basegfx::fround64((mfOldHeight * (double)nWidth) / mfOldWidth));
1529 maMtrHeight.SetUserValue(nHeight, FUNIT_NONE);
1533 return( 0L );
1536 //------------------------------------------------------------------------
1538 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ClickSizeProtectHdl)
1540 UpdateControlStates();
1541 return( 0L );
1544 //------------------------------------------------------------------------
1546 IMPL_LINK_NOARG(SvxPositionSizeTabPage, ClickAutoHdl)
1548 if( maCbxScale.IsChecked() )
1550 mfOldWidth = std::max( (double)GetCoreValue( maMtrWidth, mePoolUnit ), 1.0 );
1551 mfOldHeight = std::max( (double)GetCoreValue( maMtrHeight, mePoolUnit ), 1.0 );
1554 return( 0L );
1557 //------------------------------------------------------------------------
1559 void SvxPositionSizeTabPage::FillUserData()
1561 // matching is saved in the Ini-file
1562 OUString aStr = OUString::valueOf( (sal_Int32) maCbxScale.IsChecked() );
1563 SetUserData( aStr );
1566 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */