update dev300-m58
[ooovba.git] / svx / source / cui / transfrm.cxx
blob538e8eb5234c28068b11b4e183d0c099801ba3de
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: transfrm.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
41 #include <tools/shl.hxx>
42 #include <sfx2/app.hxx>
43 #include <svx/svdview.hxx>
44 #include <svx/svdobj.hxx>
45 #include <svx/svdpagv.hxx>
46 #include <svx/svdotext.hxx>
47 #include <svx/sderitm.hxx>
49 #include <svx/svxids.hrc>
50 #include <svx/dialogs.hrc>
51 #include "transfrm.hrc"
52 #include <svx/sizeitem.hxx>
54 #include "transfrm.hxx"
55 #include <svx/dialmgr.hxx>
56 #include "dlgutil.hxx"
57 #include <svx/svxenum.hxx>
58 #include "anchorid.hxx"
59 #include <sfx2/module.hxx>
60 #include <svtools/rectitem.hxx>
61 #include <svtools/aeitem.hxx>
62 #include <swpossizetabpage.hxx>
64 // Toleranz fuer WorkingArea
65 #define DIFF 1000
67 // static ----------------------------------------------------------------
69 static USHORT pPosSizeRanges[] =
71 SID_ATTR_TRANSFORM_POS_X,
72 SID_ATTR_TRANSFORM_POS_Y,
73 SID_ATTR_TRANSFORM_PROTECT_POS,
74 SID_ATTR_TRANSFORM_PROTECT_POS,
75 SID_ATTR_TRANSFORM_INTERN,
76 SID_ATTR_TRANSFORM_INTERN,
77 SID_ATTR_TRANSFORM_ANCHOR,
78 SID_ATTR_TRANSFORM_VERT_ORIENT,
79 SID_ATTR_TRANSFORM_WIDTH,
80 SID_ATTR_TRANSFORM_SIZE_POINT,
81 SID_ATTR_TRANSFORM_PROTECT_POS,
82 SID_ATTR_TRANSFORM_INTERN,
83 SID_ATTR_TRANSFORM_AUTOWIDTH,
84 SID_ATTR_TRANSFORM_AUTOHEIGHT,
88 static USHORT pAngleRanges[] =
90 SID_ATTR_TRANSFORM_ROT_X,
91 SID_ATTR_TRANSFORM_ANGLE,
92 SID_ATTR_TRANSFORM_INTERN,
93 SID_ATTR_TRANSFORM_INTERN,
97 static USHORT pSlantRanges[] =
99 SDRATTR_ECKENRADIUS,
100 SDRATTR_ECKENRADIUS,
101 SID_ATTR_TRANSFORM_SHEAR,
102 SID_ATTR_TRANSFORM_SHEAR_VERTICAL,
103 SID_ATTR_TRANSFORM_INTERN,
104 SID_ATTR_TRANSFORM_INTERN,
108 void lcl_ConvertRect(basegfx::B2DRange& rRange, const sal_uInt16 nDigits, const MapUnit ePoolUnit, const FieldUnit eDlgUnit)
110 const basegfx::B2DPoint aTopLeft(
111 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinX()), nDigits, ePoolUnit, eDlgUnit),
112 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinY()), nDigits, ePoolUnit, eDlgUnit));
113 const basegfx::B2DPoint aBottomRight(
114 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxX()), nDigits, ePoolUnit, eDlgUnit),
115 (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxY()), nDigits, ePoolUnit, eDlgUnit));
117 rRange = basegfx::B2DRange(aTopLeft, aBottomRight);
120 void lcl_ScaleRect(basegfx::B2DRange& rRange, const Fraction aUIScale)
122 const double fFactor(1.0 / double(aUIScale));
123 rRange = basegfx::B2DRange(rRange.getMinimum() * fFactor, rRange.getMaximum() * fFactor);
126 /*************************************************************************
128 |* Konstruktor des Tab-Dialogs: Fuegt die Seiten zum Dialog hinzu
130 \************************************************************************/
132 SvxTransformTabDialog::SvxTransformTabDialog( Window* pParent, const SfxItemSet* pAttr,
133 const SdrView* pSdrView, USHORT nAnchorTypes ) :
134 SfxTabDialog( pParent, SVX_RES( RID_SVXDLG_TRANSFORM ), pAttr ),
135 pView ( pSdrView ),
136 nAnchorCtrls(nAnchorTypes)
138 DBG_ASSERT(pView, "no valid view (!)");
139 FreeResource();
141 //different positioning page in Writer
142 if(nAnchorCtrls & 0x00ff)
144 AddTabPage(RID_SVXPAGE_SWPOSSIZE, SvxSwPosSizeTabPage::Create, SvxSwPosSizeTabPage::GetRanges);
145 RemoveTabPage(RID_SVXPAGE_POSITION_SIZE);
147 else
149 AddTabPage(RID_SVXPAGE_POSITION_SIZE, SvxPositionSizeTabPage::Create, SvxPositionSizeTabPage::GetRanges);
150 RemoveTabPage(RID_SVXPAGE_SWPOSSIZE);
153 AddTabPage(RID_SVXPAGE_ANGLE, SvxAngleTabPage::Create, SvxAngleTabPage::GetRanges);
154 AddTabPage(RID_SVXPAGE_SLANT, SvxSlantTabPage::Create, SvxSlantTabPage::GetRanges);
157 // -----------------------------------------------------------------------
159 SvxTransformTabDialog::~SvxTransformTabDialog()
163 // -----------------------------------------------------------------------
165 void SvxTransformTabDialog::PageCreated(USHORT nId, SfxTabPage &rPage)
167 switch(nId)
169 case RID_SVXPAGE_POSITION_SIZE:
171 SvxPositionSizeTabPage& rSvxPos = static_cast<SvxPositionSizeTabPage&>(rPage);
172 rSvxPos.SetView(pView);
173 rSvxPos.Construct();
175 if(nAnchorCtrls & SVX_OBJ_NORESIZE)
177 rSvxPos.DisableResize();
180 if(nAnchorCtrls & SVX_OBJ_NOPROTECT)
182 rSvxPos.DisableProtect();
183 rSvxPos.UpdateControlStates();
186 break;
188 case RID_SVXPAGE_SWPOSSIZE :
190 SvxSwPosSizeTabPage& rSwPos = static_cast<SvxSwPosSizeTabPage&>(rPage);
192 rSwPos.EnableAnchorTypes(nAnchorCtrls);
193 rSwPos.SetValidateFramePosLink(aValidateLink);
194 rSwPos.SetView(pView);
196 break;
199 case RID_SVXPAGE_ANGLE:
201 SvxAngleTabPage& rSvxAng = static_cast<SvxAngleTabPage&>(rPage);
203 rSvxAng.SetView( pView );
204 rSvxAng.Construct();
206 break;
209 case RID_SVXPAGE_SLANT:
211 SvxSlantTabPage& rSvxSlnt = static_cast<SvxSlantTabPage&>(rPage);
213 rSvxSlnt.SetView( pView );
214 rSvxSlnt.Construct();
216 break;
221 // -----------------------------------------------------------------------
223 void SvxTransformTabDialog::SetValidateFramePosLink(const Link& rLink)
225 aValidateLink = rLink;
228 /*************************************************************************
230 |* Dialog zum Aendern der Position des Drehwinkels und des Drehwinkels
231 |* der Grafikobjekte
233 \************************************************************************/
235 SvxAngleTabPage::SvxAngleTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
236 SvxTabPage ( pParent, SVX_RES( RID_SVXPAGE_ANGLE ), rInAttrs ),
237 aFlPosition ( this, SVX_RES( FL_POSITION ) ),
238 aFtPosX ( this, SVX_RES( FT_POS_X ) ),
239 aMtrPosX ( this, SVX_RES( MTR_FLD_POS_X ) ),
240 aFtPosY ( this, SVX_RES( FT_POS_Y ) ),
241 aMtrPosY ( this, SVX_RES( MTR_FLD_POS_Y ) ),
242 aFtPosPresets ( this, SVX_RES(FT_POSPRESETS) ),
243 aCtlRect ( this, SVX_RES( CTL_RECT ) ),
245 aFlAngle ( this, SVX_RES( FL_ANGLE ) ),
246 aFtAngle ( this, SVX_RES( FT_ANGLE ) ),
247 aMtrAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
248 aFtAnglePresets ( this, SVX_RES(FT_ANGLEPRESETS) ),
249 aCtlAngle ( this, SVX_RES( CTL_ANGLE ),
250 RP_RB, 200, 80, CS_ANGLE ),
251 rOutAttrs ( rInAttrs )
253 FreeResource();
255 // calculate PoolUnit
256 SfxItemPool* pPool = rOutAttrs.GetPool();
257 DBG_ASSERT( pPool, "no pool (!)" );
258 ePoolUnit = pPool->GetMetric(SID_ATTR_TRANSFORM_POS_X);
260 aMtrAngle.SetModifyHdl(LINK( this, SvxAngleTabPage, ModifiedHdl));
263 // -----------------------------------------------------------------------
265 void SvxAngleTabPage::Construct()
267 DBG_ASSERT(pView, "No valid view (!)");
268 eDlgUnit = GetModuleFieldUnit(&GetItemSet());
269 SetFieldUnit(aMtrPosX, eDlgUnit, TRUE);
270 SetFieldUnit(aMtrPosY, eDlgUnit, TRUE);
272 if(FUNIT_MILE == eDlgUnit || FUNIT_KM == eDlgUnit)
274 aMtrPosX.SetDecimalDigits( 3 );
275 aMtrPosY.SetDecimalDigits( 3 );
278 { // #i75273#
279 Rectangle aTempRect(pView->GetAllMarkedRect());
280 pView->GetSdrPageView()->LogicToPagePos(aTempRect);
281 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
284 // Take anchor into account (Writer)
285 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
287 if(rMarkList.GetMarkCount())
289 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
290 maAnchor = basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y());
292 if(!maAnchor.equalZero()) // -> Writer
294 maRange = basegfx::B2DRange(maRange.getMinimum() - maAnchor, maRange.getMaximum() - maAnchor);
298 // take scale into account
299 const Fraction aUIScale(pView->GetModel()->GetUIScale());
300 lcl_ScaleRect(maRange, aUIScale);
302 // take UI units into account
303 sal_uInt16 nDigits(aMtrPosX.GetDecimalDigits());
304 lcl_ConvertRect(maRange, nDigits, (MapUnit)ePoolUnit, eDlgUnit);
306 if(!pView->IsRotateAllowed())
308 aFlPosition.Disable();
309 aFtPosX.Disable();
310 aMtrPosX.Disable();
311 aFtPosY.Disable();
312 aMtrPosY.Disable();
313 aFtPosPresets.Disable();
314 aCtlRect.Disable();
315 aFlAngle.Disable();
316 aFtAngle.Disable();
317 aMtrAngle.Disable();
318 aFtAnglePresets.Disable();
319 aCtlAngle.Disable();
323 // -----------------------------------------------------------------------
325 BOOL SvxAngleTabPage::FillItemSet(SfxItemSet& rSet)
327 BOOL bModified = FALSE;
329 if(aMtrAngle.IsValueModified() || aMtrPosX.IsValueModified() || aMtrPosY.IsValueModified())
331 const double fUIScale(double(pView->GetModel()->GetUIScale()));
332 const double fTmpX((GetCoreValue(aMtrPosX, ePoolUnit) + maAnchor.getX()) * fUIScale);
333 const double fTmpY((GetCoreValue(aMtrPosY, ePoolUnit) + maAnchor.getY()) * fUIScale);
335 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ANGLE), static_cast<sal_Int32>(aMtrAngle.GetValue())));
336 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ROT_X), basegfx::fround(fTmpX)));
337 rSet.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_ROT_Y), basegfx::fround(fTmpY)));
339 bModified |= TRUE;
342 return bModified;
345 // -----------------------------------------------------------------------
347 void SvxAngleTabPage::Reset(const SfxItemSet& rAttrs)
349 const double fUIScale(double(pView->GetModel()->GetUIScale()));
351 const SfxPoolItem* pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_ROT_X );
352 if(pItem)
354 const double fTmp(((double)((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getX()) / fUIScale);
355 SetMetricValue(aMtrPosX, basegfx::fround(fTmp), ePoolUnit);
357 else
359 aMtrPosX.SetText( String() );
362 pItem = GetItem(rAttrs, SID_ATTR_TRANSFORM_ROT_Y);
363 if(pItem)
365 const double fTmp(((double)((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getY()) / fUIScale);
366 SetMetricValue(aMtrPosY, basegfx::fround(fTmp), ePoolUnit);
368 else
370 aMtrPosX.SetText( String() );
373 pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_ANGLE );
374 if(pItem)
376 aMtrAngle.SetValue(((const SfxInt32Item*)pItem)->GetValue());
378 else
380 aMtrAngle.SetText( String() );
383 aMtrAngle.SaveValue();
384 ModifiedHdl(this);
387 // -----------------------------------------------------------------------
389 SfxTabPage* SvxAngleTabPage::Create( Window* pWindow, const SfxItemSet& rSet)
391 return(new SvxAngleTabPage(pWindow, rSet));
394 //------------------------------------------------------------------------
396 USHORT* SvxAngleTabPage::GetRanges()
398 return(pAngleRanges);
401 // -----------------------------------------------------------------------
403 void SvxAngleTabPage::ActivatePage(const SfxItemSet& /*rSet*/)
407 // -----------------------------------------------------------------------
409 int SvxAngleTabPage::DeactivatePage( SfxItemSet* _pSet )
411 if(_pSet)
413 FillItemSet(*_pSet);
416 return LEAVE_PAGE;
419 //------------------------------------------------------------------------
421 void SvxAngleTabPage::PointChanged(Window* pWindow, RECT_POINT eRP)
423 if(pWindow == &aCtlRect)
425 switch(eRP)
427 case RP_LT:
429 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
430 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
431 break;
433 case RP_MT:
435 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
436 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
437 break;
439 case RP_RT:
441 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
442 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMinY()), FUNIT_NONE );
443 break;
445 case RP_LM:
447 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
448 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
449 break;
451 case RP_MM:
453 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
454 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
455 break;
457 case RP_RM:
459 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
460 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getCenter().getY()), FUNIT_NONE );
461 break;
463 case RP_LB:
465 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMinX()), FUNIT_NONE );
466 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
467 break;
469 case RP_MB:
471 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getCenter().getX()), FUNIT_NONE );
472 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
473 break;
475 case RP_RB:
477 aMtrPosX.SetUserValue( basegfx::fround64(maRange.getMaxX()), FUNIT_NONE );
478 aMtrPosY.SetUserValue( basegfx::fround64(maRange.getMaxY()), FUNIT_NONE );
479 break;
483 else if(pWindow == &aCtlAngle)
485 switch( eRP )
487 case RP_LT: aMtrAngle.SetUserValue( 13500, FUNIT_NONE ); break;
488 case RP_MT: aMtrAngle.SetUserValue( 9000, FUNIT_NONE ); break;
489 case RP_RT: aMtrAngle.SetUserValue( 4500, FUNIT_NONE ); break;
490 case RP_LM: aMtrAngle.SetUserValue( 18000, FUNIT_NONE ); break;
491 case RP_RM: aMtrAngle.SetUserValue( 0, FUNIT_NONE ); break;
492 case RP_LB: aMtrAngle.SetUserValue( 22500, FUNIT_NONE ); break;
493 case RP_MB: aMtrAngle.SetUserValue( 27000, FUNIT_NONE ); break;
494 case RP_RB: aMtrAngle.SetUserValue( 31500, FUNIT_NONE ); break;
495 case RP_MM: break;
500 //------------------------------------------------------------------------
502 IMPL_LINK( SvxAngleTabPage, ModifiedHdl, void *, EMPTYARG )
504 switch(aMtrAngle.GetValue())
506 case 13500: aCtlAngle.SetActualRP( RP_LT ); break;
507 case 9000: aCtlAngle.SetActualRP( RP_MT ); break;
508 case 4500: aCtlAngle.SetActualRP( RP_RT ); break;
509 case 18000: aCtlAngle.SetActualRP( RP_LM ); break;
510 case 0: aCtlAngle.SetActualRP( RP_RM ); break;
511 case 22500: aCtlAngle.SetActualRP( RP_LB ); break;
512 case 27000: aCtlAngle.SetActualRP( RP_MB ); break;
513 case 31500: aCtlAngle.SetActualRP( RP_RB ); break;
514 default: aCtlAngle.SetActualRP( RP_MM ); break;
517 return( 0L );
520 /*************************************************************************
522 |* Dialog zum Aendern des Eckenradius und zum Schraegstellen
524 \************************************************************************/
526 SvxSlantTabPage::SvxSlantTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
527 SvxTabPage ( pParent, SVX_RES( RID_SVXPAGE_SLANT ), rInAttrs ),
529 aFlRadius ( this, SVX_RES( FL_RADIUS ) ),
530 aFtRadius ( this, SVX_RES( FT_RADIUS ) ),
531 aMtrRadius ( this, SVX_RES( MTR_FLD_RADIUS ) ),
532 aFlAngle ( this, SVX_RES( FL_SLANT ) ),
533 aFtAngle ( this, SVX_RES( FT_ANGLE ) ),
534 aMtrAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
535 rOutAttrs ( rInAttrs )
537 FreeResource();
539 // this page needs ExchangeSupport
540 SetExchangeSupport();
542 // evaluate PoolUnit
543 SfxItemPool* pPool = rOutAttrs.GetPool();
544 DBG_ASSERT( pPool, "no pool (!)" );
545 ePoolUnit = pPool->GetMetric( SID_ATTR_TRANSFORM_POS_X );
548 // -----------------------------------------------------------------------
550 void SvxSlantTabPage::Construct()
552 // get the range
553 DBG_ASSERT(pView, "no valid view (!)");
554 eDlgUnit = GetModuleFieldUnit(&GetItemSet());
555 SetFieldUnit(aMtrRadius, eDlgUnit, TRUE);
557 { // #i75273#
558 Rectangle aTempRect(pView->GetAllMarkedRect());
559 pView->GetSdrPageView()->LogicToPagePos(aTempRect);
560 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
564 // -----------------------------------------------------------------------
566 BOOL SvxSlantTabPage::FillItemSet(SfxItemSet& rAttrs)
568 BOOL bModified = FALSE;
569 INT32 nValue = 0L;
570 String aStr = aMtrRadius.GetText();
572 if( aStr != aMtrRadius.GetSavedValue() )
574 Fraction aUIScale = pView->GetModel()->GetUIScale();
575 long nTmp = GetCoreValue( aMtrRadius, ePoolUnit );
576 nTmp = Fraction( nTmp ) * aUIScale;
578 rAttrs.Put( SdrEckenradiusItem( nTmp ) );
579 bModified = TRUE;
582 aStr = aMtrAngle.GetText();
584 if( aStr != aMtrAngle.GetSavedValue() )
586 nValue = static_cast<INT32>(aMtrAngle.GetValue());
587 rAttrs.Put( SfxInt32Item( SID_ATTR_TRANSFORM_SHEAR, nValue ) );
588 bModified = TRUE;
591 if( bModified )
593 // Referenzpunkt setzen
594 // #75897#
595 Rectangle aObjectRect(pView->GetAllMarkedRect());
596 pView->GetSdrPageView()->LogicToPagePos(aObjectRect);
597 Point aPt = aObjectRect.Center();
599 rAttrs.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_X, aPt.X()));
600 rAttrs.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_Y, aPt.Y()));
601 rAttrs.Put( SfxBoolItem( SID_ATTR_TRANSFORM_SHEAR_VERTICAL, FALSE ) );
604 return( bModified );
607 // -----------------------------------------------------------------------
609 void SvxSlantTabPage::Reset(const SfxItemSet& rAttrs)
611 // if the view has selected objects, items with SFX_ITEM_DEFAULT need to be disabled
612 const SfxPoolItem* pItem;
614 // Eckenradius
615 if(!pView->IsEdgeRadiusAllowed())
617 aFlRadius.Disable();
618 aFtRadius.Disable();
619 aMtrRadius.Disable();
620 aMtrRadius.SetText( String() );
622 else
624 pItem = GetItem( rAttrs, SDRATTR_ECKENRADIUS );
626 if( pItem )
628 const double fUIScale(double(pView->GetModel()->GetUIScale()));
629 const double fTmp((double)((const SdrEckenradiusItem*)pItem)->GetValue() / fUIScale);
630 SetMetricValue(aMtrRadius, basegfx::fround(fTmp), ePoolUnit);
632 else
634 aMtrRadius.SetText( String() );
638 aMtrRadius.SaveValue();
640 // Schraegstellen: Winkel
641 if( !pView->IsShearAllowed() )
643 aFlAngle.Disable();
644 aFtAngle.Disable();
645 aMtrAngle.Disable();
646 aMtrAngle.SetText( String() );
648 else
650 pItem = GetItem( rAttrs, SID_ATTR_TRANSFORM_SHEAR );
652 if( pItem )
654 aMtrAngle.SetValue( ( (const SfxInt32Item*)pItem )->GetValue() );
656 else
658 aMtrAngle.SetText( String() );
662 aMtrAngle.SaveValue();
665 // -----------------------------------------------------------------------
667 SfxTabPage* SvxSlantTabPage::Create( Window* pWindow, const SfxItemSet& rOutAttrs )
669 return( new SvxSlantTabPage( pWindow, rOutAttrs ) );
672 //------------------------------------------------------------------------
674 USHORT* SvxSlantTabPage::GetRanges()
676 return( pSlantRanges );
679 // -----------------------------------------------------------------------
681 void SvxSlantTabPage::ActivatePage( const SfxItemSet& rSet )
683 SfxRectangleItem* pRectItem = NULL;
685 if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_TRANSFORM_INTERN ) , FALSE, (const SfxPoolItem**) &pRectItem ) )
687 const Rectangle aTempRect(pRectItem->GetValue());
688 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
692 // -----------------------------------------------------------------------
694 int SvxSlantTabPage::DeactivatePage( SfxItemSet* _pSet )
696 if(_pSet)
698 FillItemSet(*_pSet);
701 return LEAVE_PAGE;
704 //------------------------------------------------------------------------
706 void SvxSlantTabPage::PointChanged( Window* , RECT_POINT )
710 /*************************************************************************
712 |* Dialog for changing position and size of graphic objects
714 \************************************************************************/
716 SvxPositionSizeTabPage::SvxPositionSizeTabPage( Window* pParent, const SfxItemSet& rInAttrs ) :
717 SvxTabPage ( pParent, SVX_RES( RID_SVXPAGE_POSITION_SIZE ), rInAttrs ),
718 maFlPosition ( this, SVX_RES( FL_POSITION ) ),
719 maFtPosX ( this, SVX_RES( FT_POS_X ) ),
720 maMtrPosX ( this, SVX_RES( MTR_FLD_POS_X ) ),
721 maFtPosY ( this, SVX_RES( FT_POS_Y ) ),
722 maMtrPosY ( this, SVX_RES( MTR_FLD_POS_Y ) ),
723 maFtPosReference ( this, SVX_RES( FT_POSREFERENCE ) ),
724 maCtlPos ( this, SVX_RES( CTL_POSRECT ), RP_LT ),
726 maFlSize ( this, SVX_RES( FL_SIZE ) ),
727 maFtWidth ( this, SVX_RES( FT_WIDTH ) ),
728 maMtrWidth ( this, SVX_RES( MTR_FLD_WIDTH ) ),
729 maFtHeight ( this, SVX_RES( FT_HEIGHT ) ),
730 maMtrHeight ( this, SVX_RES( MTR_FLD_HEIGHT ) ),
731 maCbxScale ( this, SVX_RES( CBX_SCALE ) ),
732 maFtSizeReference ( this, SVX_RES( FT_SIZEREFERENCE) ),
733 maCtlSize ( this, SVX_RES( CTL_SIZERECT ), RP_LT ),
735 maFlProtect ( this, SVX_RES( FL_PROTECT) ),
736 maTsbPosProtect ( this, SVX_RES( TSB_POSPROTECT ) ),
737 maTsbSizeProtect ( this, SVX_RES( TSB_SIZEPROTECT ) ),
740 maFlAdjust ( this, SVX_RES( FL_ADJUST ) ),
741 maTsbAutoGrowWidth ( this, SVX_RES( TSB_AUTOGROW_WIDTH ) ),
742 maTsbAutoGrowHeight ( this, SVX_RES( TSB_AUTOGROW_HEIGHT ) ),
744 maFlDivider (this, SVX_RES( FL_DIVIDER ) ),
746 mrOutAttrs ( rInAttrs ),
747 mnProtectSizeState( STATE_NOCHECK ),
748 mbPageDisabled ( FALSE ),
749 mbProtectDisabled( false ),
750 mbSizeDisabled( false ),
751 mbAdjustDisabled( true )
753 FreeResource();
755 // this pege needs ExchangeSupport
756 SetExchangeSupport();
758 // evaluate PoolUnit
759 SfxItemPool* pPool = mrOutAttrs.GetPool();
760 DBG_ASSERT( pPool, "no pool (!)" );
761 mePoolUnit = pPool->GetMetric( SID_ATTR_TRANSFORM_POS_X );
763 meRP = RP_LT; // s.o.
765 maMtrWidth.SetModifyHdl( LINK( this, SvxPositionSizeTabPage, ChangeWidthHdl ) );
766 maMtrHeight.SetModifyHdl( LINK( this, SvxPositionSizeTabPage, ChangeHeightHdl ) );
767 maCbxScale.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickAutoHdl ) );
769 maTsbAutoGrowWidth.Disable();
770 maTsbAutoGrowHeight.Disable();
771 maFlAdjust.Disable();
773 // #i2379# disable controls when protected
774 maTsbPosProtect.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ChangePosProtectHdl ) );
775 maTsbSizeProtect.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ChangeSizeProtectHdl ) );
779 // -----------------------------------------------------------------------
781 void SvxPositionSizeTabPage::Construct()
783 // get range and work area
784 DBG_ASSERT( mpView, "no valid view (!)" );
785 meDlgUnit = GetModuleFieldUnit( &GetItemSet() );
786 SetFieldUnit( maMtrPosX, meDlgUnit, TRUE );
787 SetFieldUnit( maMtrPosY, meDlgUnit, TRUE );
788 SetFieldUnit( maMtrWidth, meDlgUnit, TRUE );
789 SetFieldUnit( maMtrHeight, meDlgUnit, TRUE );
791 if(FUNIT_MILE == meDlgUnit || FUNIT_KM == meDlgUnit)
793 maMtrPosX.SetDecimalDigits( 3 );
794 maMtrPosY.SetDecimalDigits( 3 );
795 maMtrWidth.SetDecimalDigits( 3 );
796 maMtrHeight.SetDecimalDigits( 3 );
799 { // #i75273#
800 Rectangle aTempRect(mpView->GetAllMarkedRect());
801 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
802 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
805 { // #i75273#
806 Rectangle aTempRect(mpView->GetWorkArea());
807 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
808 maWorkRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
811 // take anchor into account (Writer)
812 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
814 if(rMarkList.GetMarkCount())
816 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
817 maAnchor = basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y());
819 if(!maAnchor.equalZero()) // -> Writer
821 for(sal_uInt16 i(1); i < rMarkList.GetMarkCount(); i++)
823 pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
825 if(maAnchor != basegfx::B2DPoint(pObj->GetAnchorPos().X(), pObj->GetAnchorPos().Y()))
827 // diferent anchor positions
828 maMtrPosX.SetText( String() );
829 maMtrPosY.SetText( String() );
830 mbPageDisabled = TRUE;
831 return;
835 // translate ranges about anchor
836 maRange = basegfx::B2DRange(maRange.getMinimum() - maAnchor, maRange.getMaximum() - maAnchor);
837 maWorkRange = basegfx::B2DRange(maWorkRange.getMinimum() - maAnchor, maWorkRange.getMaximum() - maAnchor);
841 // this should happen via SID_ATTR_TRANSFORM_AUTOSIZE
842 if(1 == rMarkList.GetMarkCount())
844 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
845 const SdrObjKind eKind((SdrObjKind)pObj->GetObjIdentifier());
847 if((pObj->GetObjInventor() == SdrInventor) && (OBJ_TEXT == eKind || OBJ_TITLETEXT == eKind || OBJ_OUTLINETEXT == eKind) && ((SdrTextObj*)pObj)->HasText())
849 mbAdjustDisabled = false;
850 maFlAdjust.Enable();
851 maTsbAutoGrowWidth.Enable();
852 maTsbAutoGrowHeight.Enable();
853 maTsbAutoGrowWidth.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickSizeProtectHdl ) );
854 maTsbAutoGrowHeight.SetClickHdl( LINK( this, SvxPositionSizeTabPage, ClickSizeProtectHdl ) );
856 // is used as flag to evaluate if its selectable
857 maTsbAutoGrowWidth.EnableTriState( FALSE );
858 maTsbAutoGrowHeight.EnableTriState( FALSE );
862 // take scale into account
863 const Fraction aUIScale(mpView->GetModel()->GetUIScale());
864 lcl_ScaleRect( maWorkRange, aUIScale );
865 lcl_ScaleRect( maRange, aUIScale );
867 // take UI units into account
868 const sal_uInt16 nDigits(maMtrPosX.GetDecimalDigits());
869 lcl_ConvertRect( maWorkRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit );
870 lcl_ConvertRect( maRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit );
872 SetMinMaxPosition();
875 // -----------------------------------------------------------------------
877 BOOL SvxPositionSizeTabPage::FillItemSet( SfxItemSet& rOutAttrs )
879 BOOL bModified(FALSE);
881 if ( maMtrWidth.HasFocus() )
883 ChangeWidthHdl( this );
886 if ( maMtrHeight.HasFocus() )
888 ChangeHeightHdl( this );
891 if( !mbPageDisabled )
893 if ( maMtrPosX.IsValueModified() || maMtrPosY.IsValueModified() )
895 const double fUIScale(double(mpView->GetModel()->GetUIScale()));
896 double fX((GetCoreValue( maMtrPosX, mePoolUnit ) + maAnchor.getX()) * fUIScale);
897 double fY((GetCoreValue( maMtrPosY, mePoolUnit ) + maAnchor.getY()) * fUIScale);
899 { // #i75273#
900 Rectangle aTempRect(mpView->GetAllMarkedRect());
901 mpView->GetSdrPageView()->LogicToPagePos(aTempRect);
902 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
905 // #101581# GetTopLeftPosition(...) needs coordinates after UI scaling, in real PagePositions
906 GetTopLeftPosition(fX, fY, maRange);
908 rOutAttrs.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_POS_X), basegfx::fround(fX)));
909 rOutAttrs.Put(SfxInt32Item(GetWhich(SID_ATTR_TRANSFORM_POS_Y), basegfx::fround(fY)));
911 bModified |= TRUE;
914 if ( maTsbPosProtect.GetState() != maTsbPosProtect.GetSavedValue() )
916 if( maTsbPosProtect.GetState() == STATE_DONTKNOW )
918 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_PROTECT_POS );
920 else
922 rOutAttrs.Put(
923 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_PROTECT_POS ),
924 maTsbPosProtect.GetState() == STATE_CHECK ? TRUE : FALSE ) );
927 bModified |= TRUE;
931 if ( maMtrWidth.IsValueModified() || maMtrHeight.IsValueModified() )
933 Fraction aUIScale = mpView->GetModel()->GetUIScale();
935 // get Width
936 double nWidth = static_cast<double>(maMtrWidth.GetValue( meDlgUnit ));
937 nWidth = MetricField::ConvertDoubleValue( nWidth, maMtrWidth.GetBaseValue(), maMtrWidth.GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
938 long lWidth = long(nWidth * (double)aUIScale);
939 lWidth = OutputDevice::LogicToLogic( lWidth, MAP_100TH_MM, (MapUnit)mePoolUnit );
940 lWidth = static_cast<long>(maMtrWidth.Denormalize( lWidth ));
942 // get Height
943 double nHeight = static_cast<double>(maMtrHeight.GetValue( meDlgUnit ));
944 nHeight = MetricField::ConvertDoubleValue( nHeight, maMtrHeight.GetBaseValue(), maMtrHeight.GetDecimalDigits(), meDlgUnit, FUNIT_100TH_MM );
945 long lHeight = long(nHeight * (double)aUIScale);
946 lHeight = OutputDevice::LogicToLogic( lHeight, MAP_100TH_MM, (MapUnit)mePoolUnit );
947 lHeight = static_cast<long>(maMtrWidth.Denormalize( lHeight ));
949 // put Width & Height to itemset
950 rOutAttrs.Put( SfxUInt32Item( GetWhich( SID_ATTR_TRANSFORM_WIDTH ),
951 (UINT32) lWidth ) );
952 rOutAttrs.Put( SfxUInt32Item( GetWhich( SID_ATTR_TRANSFORM_HEIGHT ),
953 (UINT32) lHeight ) );
954 rOutAttrs.Put( SfxAllEnumItem( GetWhich( SID_ATTR_TRANSFORM_SIZE_POINT ), sal::static_int_cast< USHORT >( meRP ) ) );
955 bModified |= TRUE;
958 if ( maTsbSizeProtect.GetState() != maTsbSizeProtect.GetSavedValue() )
960 if ( maTsbSizeProtect.GetState() == STATE_DONTKNOW )
961 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_PROTECT_SIZE );
962 else
963 rOutAttrs.Put(
964 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_PROTECT_SIZE ),
965 maTsbSizeProtect.GetState() == STATE_CHECK ? TRUE : FALSE ) );
966 bModified |= TRUE;
969 if ( maTsbAutoGrowWidth.GetState() != maTsbAutoGrowWidth.GetSavedValue() )
971 if ( !maTsbAutoGrowWidth.IsTriStateEnabled() )
973 if( maTsbAutoGrowWidth.GetState() == STATE_DONTKNOW )
974 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_AUTOWIDTH );
975 else
976 rOutAttrs.Put(
977 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_AUTOWIDTH ),
978 maTsbAutoGrowWidth.GetState() == STATE_CHECK ? TRUE : FALSE ) );
980 bModified |= TRUE;
983 if ( maTsbAutoGrowHeight.GetState() != maTsbAutoGrowHeight.GetSavedValue() )
985 if ( !maTsbAutoGrowHeight.IsTriStateEnabled() )
987 if( maTsbAutoGrowHeight.GetState() == STATE_DONTKNOW )
988 rOutAttrs.InvalidateItem( SID_ATTR_TRANSFORM_AUTOHEIGHT );
989 else
990 rOutAttrs.Put(
991 SfxBoolItem( GetWhich( SID_ATTR_TRANSFORM_AUTOHEIGHT ),
992 maTsbAutoGrowHeight.GetState() == STATE_CHECK ? TRUE : FALSE ) );
994 bModified |= TRUE;
998 return bModified;
1001 // -----------------------------------------------------------------------
1003 void SvxPositionSizeTabPage::Reset( const SfxItemSet& )
1005 const SfxPoolItem* pItem;
1006 const double fUIScale(double(mpView->GetModel()->GetUIScale()));
1008 if ( !mbPageDisabled )
1010 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_POS_X );
1011 if ( pItem )
1013 const double fTmp((((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getX()) / fUIScale);
1014 SetMetricValue(maMtrPosX, basegfx::fround(fTmp), mePoolUnit);
1017 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_POS_Y );
1018 if ( pItem )
1020 const double fTmp((((const SfxInt32Item*)pItem)->GetValue() - maAnchor.getY()) / fUIScale);
1021 SetMetricValue(maMtrPosY, basegfx::fround(fTmp), mePoolUnit);
1024 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_PROTECT_POS );
1025 if ( pItem )
1027 sal_Bool bProtected = ( ( const SfxBoolItem* )pItem )->GetValue();
1028 maTsbPosProtect.SetState( bProtected ? STATE_CHECK : STATE_NOCHECK );
1029 maTsbPosProtect.EnableTriState( FALSE );
1031 else
1033 maTsbPosProtect.SetState( STATE_DONTKNOW );
1036 maTsbPosProtect.SaveValue();
1037 maCtlPos.Reset();
1039 // #i2379# Disable controls for protected objects
1040 ChangePosProtectHdl( this );
1043 { // #i75273# set width
1044 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_WIDTH );
1045 mfOldWidth = std::max( pItem ? (double)((const SfxUInt32Item*)pItem)->GetValue() : 0.0, 1.0 );
1046 double fTmpWidth((OutputDevice::LogicToLogic(static_cast<sal_Int32>(mfOldWidth), (MapUnit)mePoolUnit, MAP_100TH_MM)) / fUIScale);
1048 if(maMtrWidth.GetDecimalDigits())
1049 fTmpWidth *= pow(10.0, maMtrWidth.GetDecimalDigits());
1051 fTmpWidth = MetricField::ConvertDoubleValue(fTmpWidth, maMtrWidth.GetBaseValue(), maMtrWidth.GetDecimalDigits(), FUNIT_100TH_MM, meDlgUnit);
1052 maMtrWidth.SetValue(static_cast<sal_Int64>(fTmpWidth), meDlgUnit);
1055 { // #i75273# set height
1056 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_HEIGHT );
1057 mfOldHeight = std::max( pItem ? (double)((const SfxUInt32Item*)pItem)->GetValue() : 0.0, 1.0 );
1058 double fTmpHeight((OutputDevice::LogicToLogic(static_cast<sal_Int32>(mfOldHeight), (MapUnit)mePoolUnit, MAP_100TH_MM)) / fUIScale);
1060 if(maMtrHeight.GetDecimalDigits())
1061 fTmpHeight *= pow(10.0, maMtrHeight.GetDecimalDigits());
1063 fTmpHeight = MetricField::ConvertDoubleValue(fTmpHeight, maMtrHeight.GetBaseValue(), maMtrHeight.GetDecimalDigits(), FUNIT_100TH_MM, meDlgUnit);
1064 maMtrHeight.SetValue(static_cast<sal_Int64>(fTmpHeight), meDlgUnit);
1067 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_PROTECT_SIZE );
1068 if ( pItem )
1070 maTsbSizeProtect.SetState( ( (const SfxBoolItem*)pItem )->GetValue()
1071 ? STATE_CHECK : STATE_NOCHECK );
1072 maTsbSizeProtect.EnableTriState( FALSE );
1074 else
1075 maTsbSizeProtect.SetState( STATE_DONTKNOW );
1077 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_AUTOWIDTH );
1078 if ( pItem )
1080 maTsbAutoGrowWidth.SetState( ( ( const SfxBoolItem* )pItem )->GetValue()
1081 ? STATE_CHECK : STATE_NOCHECK );
1083 else
1084 maTsbAutoGrowWidth.SetState( STATE_DONTKNOW );
1086 pItem = GetItem( mrOutAttrs, SID_ATTR_TRANSFORM_AUTOHEIGHT );
1087 if ( pItem )
1089 maTsbAutoGrowHeight.SetState( ( ( const SfxBoolItem* )pItem )->GetValue()
1090 ? STATE_CHECK : STATE_NOCHECK );
1092 else
1093 maTsbAutoGrowHeight.SetState( STATE_DONTKNOW );
1095 // Ist Abgleich gesetzt?
1096 String aStr = GetUserData();
1097 maCbxScale.Check( (BOOL)aStr.ToInt32() );
1099 maTsbSizeProtect.SaveValue();
1100 maTsbAutoGrowWidth.SaveValue();
1101 maTsbAutoGrowHeight.SaveValue();
1102 ClickSizeProtectHdl( NULL );
1104 // #i2379# Disable controls for protected objects
1105 ChangeSizeProtectHdl( this );
1108 // -----------------------------------------------------------------------
1110 SfxTabPage* SvxPositionSizeTabPage::Create( Window* pWindow, const SfxItemSet& rOutAttrs )
1112 return( new SvxPositionSizeTabPage( pWindow, rOutAttrs ) );
1115 //------------------------------------------------------------------------
1117 USHORT* SvxPositionSizeTabPage::GetRanges()
1119 return( pPosSizeRanges );
1122 // -----------------------------------------------------------------------
1124 void SvxPositionSizeTabPage::ActivatePage( const SfxItemSet& rSet )
1126 SfxRectangleItem* pRectItem = NULL;
1128 if( SFX_ITEM_SET == rSet.GetItemState( GetWhich( SID_ATTR_TRANSFORM_INTERN ) , FALSE, (const SfxPoolItem**) &pRectItem ) )
1130 { // #i75273#
1131 const Rectangle aTempRect(pRectItem->GetValue());
1132 maRange = basegfx::B2DRange(aTempRect.Left(), aTempRect.Top(), aTempRect.Right(), aTempRect.Bottom());
1135 SetMinMaxPosition();
1139 // -----------------------------------------------------------------------
1141 int SvxPositionSizeTabPage::DeactivatePage( SfxItemSet* _pSet )
1143 if( _pSet )
1145 double fX((double)maMtrPosX.GetValue());
1146 double fY((double)maMtrPosY.GetValue());
1148 GetTopLeftPosition(fX, fY, maRange);
1149 const Rectangle aOutRectangle(
1150 basegfx::fround(fX), basegfx::fround(fY),
1151 basegfx::fround(fX + maRange.getWidth()), basegfx::fround(fY + maRange.getHeight()));
1152 _pSet->Put(SfxRectangleItem(SID_ATTR_TRANSFORM_INTERN, aOutRectangle));
1154 FillItemSet(*_pSet);
1157 return LEAVE_PAGE;
1160 //------------------------------------------------------------------------
1162 IMPL_LINK( SvxPositionSizeTabPage, ChangePosProtectHdl, void *, EMPTYARG )
1164 // #106572# Remember user's last choice
1165 maTsbSizeProtect.SetState( maTsbPosProtect.GetState() == STATE_CHECK ? STATE_CHECK : mnProtectSizeState );
1166 UpdateControlStates();
1167 return( 0L );
1170 //------------------------------------------------------------------------
1172 void SvxPositionSizeTabPage::UpdateControlStates()
1174 const bool bPosProtect = maTsbPosProtect.GetState() == STATE_CHECK;
1175 const bool bSizeProtect = maTsbSizeProtect.GetState() == STATE_CHECK;
1176 const bool bHeightChecked = !maTsbAutoGrowHeight.IsTriStateEnabled() && (maTsbAutoGrowHeight.GetState() == STATE_CHECK);
1177 const bool bWidthChecked = !maTsbAutoGrowWidth.IsTriStateEnabled() && (maTsbAutoGrowWidth.GetState() == STATE_CHECK);
1179 maFlPosition.Enable( !bPosProtect && !mbPageDisabled );
1180 maFtPosX.Enable( !bPosProtect && !mbPageDisabled );
1181 maMtrPosX.Enable( !bPosProtect && !mbPageDisabled );
1182 maFtPosY.Enable( !bPosProtect && !mbPageDisabled );
1183 maMtrPosY.Enable( !bPosProtect && !mbPageDisabled );
1184 maFtPosReference.Enable( !bPosProtect && !mbPageDisabled );
1185 maCtlPos.Enable( !bPosProtect );
1186 maTsbPosProtect.Enable( !mbProtectDisabled && !mbPageDisabled );
1188 maFlSize.Enable( !mbSizeDisabled && !bSizeProtect );
1189 maCtlSize.Enable( !mbSizeDisabled && !bSizeProtect && (!bHeightChecked || !bWidthChecked) );
1190 maFtWidth.Enable( !mbSizeDisabled && !bSizeProtect && !bWidthChecked );
1191 maMtrWidth.Enable( !mbSizeDisabled && !bSizeProtect && !bWidthChecked );
1192 maFtHeight.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked );
1193 maMtrHeight.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked );
1194 maCbxScale.Enable( !mbSizeDisabled && !bSizeProtect && !bHeightChecked && !bWidthChecked );
1195 maFtSizeReference.Enable( !mbSizeDisabled && !bSizeProtect );
1196 maFlProtect.Enable( !mbProtectDisabled );
1197 maTsbSizeProtect.Enable( !mbProtectDisabled && !bPosProtect );
1199 maFlAdjust.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1200 maTsbAutoGrowWidth.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1201 maTsbAutoGrowHeight.Enable( !mbSizeDisabled && !bSizeProtect && !mbAdjustDisabled );
1203 maCtlSize.Invalidate();
1204 maCtlPos.Invalidate();
1208 //------------------------------------------------------------------------
1210 IMPL_LINK( SvxPositionSizeTabPage, ChangeSizeProtectHdl, void *, EMPTYARG )
1212 if( maTsbSizeProtect.IsEnabled() )
1214 // #106572# Remember user's last choice
1216 // Note: this works only as long as the dialog is open. When
1217 // the user closes the dialog, there is no way to remember
1218 // whether size was enabled or disabled befor pos protect was
1219 // clicked. Thus, if pos protect is selected, the dialog is
1220 // closed and reopened again, unchecking pos protect will
1221 // always uncheck size protect, too. That's life.
1222 mnProtectSizeState = maTsbSizeProtect.GetState();
1225 UpdateControlStates();
1227 return( 0L );
1230 //------------------------------------------------------------------------
1232 IMPL_LINK_INLINE_START( SvxPositionSizeTabPage, ChangePosXHdl, void *, EMPTYARG )
1234 return( 0L );
1236 IMPL_LINK_INLINE_END( SvxPositionSizeTabPage, ChangePosXHdl, void *, EMPTYARG )
1238 //------------------------------------------------------------------------
1240 IMPL_LINK_INLINE_START( SvxPositionSizeTabPage, ChangePosYHdl, void *, EMPTYARG )
1242 return( 0L );
1244 IMPL_LINK_INLINE_END( SvxPositionSizeTabPage, ChangePosYHdl, void *, EMPTYARG )
1246 //------------------------------------------------------------------------
1248 void SvxPositionSizeTabPage::SetMinMaxPosition()
1250 // position
1251 double fLeft(maWorkRange.getMinX());
1252 double fTop(maWorkRange.getMinY());
1253 double fRight(maWorkRange.getMaxX());
1254 double fBottom(maWorkRange.getMaxY());
1256 switch ( maCtlPos.GetActualRP() )
1258 case RP_LT:
1260 fRight -= maRange.getWidth();
1261 fBottom -= maRange.getHeight();
1262 break;
1264 case RP_MT:
1266 fLeft += maRange.getWidth() / 2.0;
1267 fRight -= maRange.getWidth() / 2.0;
1268 fBottom -= maRange.getHeight();
1269 break;
1271 case RP_RT:
1273 fLeft += maRange.getWidth();
1274 fBottom -= maRange.getHeight();
1275 break;
1277 case RP_LM:
1279 fRight -= maRange.getWidth();
1280 fTop += maRange.getHeight() / 2.0;
1281 fBottom -= maRange.getHeight() / 2.0;
1282 break;
1284 case RP_MM:
1286 fLeft += maRange.getWidth() / 2.0;
1287 fRight -= maRange.getWidth() / 2.0;
1288 fTop += maRange.getHeight() / 2.0;
1289 fBottom -= maRange.getHeight() / 2.0;
1290 break;
1292 case RP_RM:
1294 fLeft += maRange.getWidth();
1295 fTop += maRange.getHeight() / 2.0;
1296 fBottom -= maRange.getHeight() / 2.0;
1297 break;
1299 case RP_LB:
1301 fRight -= maRange.getWidth();
1302 fTop += maRange.getHeight();
1303 break;
1305 case RP_MB:
1307 fLeft += maRange.getWidth() / 2.0;
1308 fRight -= maRange.getWidth() / 2.0;
1309 fTop += maRange.getHeight();
1310 break;
1312 case RP_RB:
1314 fLeft += maRange.getWidth();
1315 fTop += maRange.getHeight();
1316 break;
1320 const double fMaxLong((double)(MetricField::ConvertValue( LONG_MAX, 0, MAP_100TH_MM, meDlgUnit ) - 1L));
1321 fLeft = (fLeft > fMaxLong) ? fMaxLong : (fLeft < -fMaxLong) ? -fMaxLong : fLeft;
1322 fRight = (fRight > fMaxLong) ? fMaxLong : (fRight < -fMaxLong) ? -fMaxLong : fRight;
1323 fTop = (fTop > fMaxLong) ? fMaxLong : (fTop < -fMaxLong) ? -fMaxLong : fTop;
1324 fBottom = (fBottom > fMaxLong) ? fMaxLong : (fBottom < -fMaxLong) ? -fMaxLong : fBottom;
1326 // #i75273# normalizing when setting the min/max values was wrong, removed
1327 maMtrPosX.SetMin(basegfx::fround64(fLeft));
1328 maMtrPosX.SetFirst(basegfx::fround64(fLeft));
1329 maMtrPosX.SetMax(basegfx::fround64(fRight));
1330 maMtrPosX.SetLast(basegfx::fround64(fRight));
1331 maMtrPosY.SetMin(basegfx::fround64(fTop));
1332 maMtrPosY.SetFirst(basegfx::fround64(fTop));
1333 maMtrPosY.SetMax(basegfx::fround64(fBottom));
1334 maMtrPosY.SetLast(basegfx::fround64(fBottom));
1336 // size
1337 fLeft = maWorkRange.getMinX();
1338 fTop = maWorkRange.getMinY();
1339 fRight = maWorkRange.getMaxX();
1340 fBottom = maWorkRange.getMaxY();
1341 double fNewX(0);
1342 double fNewY(0);
1344 switch ( maCtlSize.GetActualRP() )
1346 case RP_LT:
1348 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1349 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1350 break;
1352 case RP_MT:
1354 fNewX = std::min( maRange.getCenter().getX() - fLeft, fRight - maRange.getCenter().getX() ) * 2.0;
1355 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1356 break;
1358 case RP_RT:
1360 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1361 fNewY = maWorkRange.getHeight() - ( maRange.getMinY() - fTop );
1362 break;
1364 case RP_LM:
1366 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1367 fNewY = std::min( maRange.getCenter().getY() - fTop, fBottom - maRange.getCenter().getY() ) * 2.0;
1368 break;
1370 case RP_MM:
1372 const double f1(maRange.getCenter().getX() - fLeft);
1373 const double f2(fRight - maRange.getCenter().getX());
1374 const double f3(std::min(f1, f2));
1375 const double f4(maRange.getCenter().getY() - fTop);
1376 const double f5(fBottom - maRange.getCenter().getY());
1377 const double f6(std::min(f4, f5));
1379 fNewX = f3 * 2.0;
1380 fNewY = f6 * 3.0;
1382 break;
1384 case RP_RM:
1386 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1387 fNewY = std::min( maRange.getCenter().getY() - fTop, fBottom - maRange.getCenter().getY() ) * 2.0;
1388 break;
1390 case RP_LB:
1392 fNewX = maWorkRange.getWidth() - ( maRange.getMinX() - fLeft );
1393 fNewY = maWorkRange.getHeight() - ( fBottom - maRange.getMaxY() );
1394 break;
1396 case RP_MB:
1398 fNewX = std::min( maRange.getCenter().getX() - fLeft, fRight - maRange.getCenter().getX() ) * 2.0;
1399 fNewY = maWorkRange.getHeight() - ( maRange.getMaxY() - fBottom );
1400 break;
1402 case RP_RB:
1404 fNewX = maWorkRange.getWidth() - ( fRight - maRange.getMaxX() );
1405 fNewY = maWorkRange.getHeight() - ( fBottom - maRange.getMaxY() );
1406 break;
1410 // #i75273# normalizing when setting the min/max values was wrong, removed
1411 maMtrWidth.SetMax(basegfx::fround64(fNewX));
1412 maMtrWidth.SetLast(basegfx::fround64(fNewX));
1413 maMtrHeight.SetMax(basegfx::fround64(fNewY));
1414 maMtrHeight.SetLast(basegfx::fround64(fNewY));
1417 //------------------------------------------------------------------------
1419 void SvxPositionSizeTabPage::GetTopLeftPosition(double& rfX, double& rfY, const basegfx::B2DRange& rRange)
1421 switch (maCtlPos.GetActualRP())
1423 case RP_LT:
1425 break;
1427 case RP_MT:
1429 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1430 break;
1432 case RP_RT:
1434 rfX -= rRange.getWidth();
1435 break;
1437 case RP_LM:
1439 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1440 break;
1442 case RP_MM:
1444 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1445 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1446 break;
1448 case RP_RM:
1450 rfX -= rRange.getWidth();
1451 rfY -= rRange.getCenter().getY() - rRange.getMinY();
1452 break;
1454 case RP_LB:
1456 rfY -= rRange.getHeight();
1457 break;
1459 case RP_MB:
1461 rfX -= rRange.getCenter().getX() - rRange.getMinX();
1462 rfY -= rRange.getHeight();
1463 break;
1465 case RP_RB:
1467 rfX -= rRange.getWidth();
1468 rfY -= rRange.getHeight();
1469 break;
1474 //------------------------------------------------------------------------
1476 void SvxPositionSizeTabPage::PointChanged( Window* pWindow, RECT_POINT eRP )
1478 if( pWindow == &maCtlPos )
1480 SetMinMaxPosition();
1481 switch( eRP )
1483 case RP_LT:
1485 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1486 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1487 break;
1489 case RP_MT:
1491 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1492 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1493 break;
1495 case RP_RT:
1497 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1498 maMtrPosY.SetValue( basegfx::fround64(maRange.getMinY()) );
1499 break;
1501 case RP_LM:
1503 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1504 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1505 break;
1507 case RP_MM:
1509 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1510 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1511 break;
1513 case RP_RM:
1515 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1516 maMtrPosY.SetValue( basegfx::fround64(maRange.getCenter().getY()) );
1517 break;
1519 case RP_LB:
1521 maMtrPosX.SetValue( basegfx::fround64(maRange.getMinX()) );
1522 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1523 break;
1525 case RP_MB:
1527 maMtrPosX.SetValue( basegfx::fround64(maRange.getCenter().getX()) );
1528 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1529 break;
1531 case RP_RB:
1533 maMtrPosX.SetValue( basegfx::fround64(maRange.getMaxX()) );
1534 maMtrPosY.SetValue( basegfx::fround64(maRange.getMaxY()) );
1535 break;
1539 else
1541 meRP = eRP;
1543 Rectangle aTmpRect( GetRect() );
1544 SetMinMaxPosition();
1548 //------------------------------------------------------------------------
1550 void SvxPositionSizeTabPage::DisableResize()
1552 mbSizeDisabled = true;
1555 //------------------------------------------------------------------------
1557 void SvxPositionSizeTabPage::DisableProtect()
1559 mbProtectDisabled = true;
1562 //------------------------------------------------------------------------
1564 Rectangle SvxPositionSizeTabPage::GetRect()
1566 double fLeft(maRange.getMinX());
1567 double fTop(maRange.getMinY());
1568 double fRight(fLeft + (double)maMtrWidth.GetValue());
1569 double fBottom(fTop + (double)maMtrHeight.GetValue());
1571 switch ( maCtlSize.GetActualRP() )
1573 case RP_LT:
1575 break;
1577 case RP_MT:
1579 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() ) / 2.0;
1580 break;
1582 case RP_RT:
1584 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() );
1585 break;
1587 case RP_LM:
1589 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() ) / 2.0;
1590 break;
1592 case RP_MM:
1594 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() ) / 2.0;
1595 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() ) / 2.0;
1596 break;
1598 case RP_RM:
1600 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() );
1601 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() ) / 2.0;
1602 break;
1604 case RP_LB:
1606 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() );
1607 break;
1609 case RP_MB:
1611 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() ) / 2.0;
1612 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() );
1613 break;
1615 case RP_RB:
1617 fLeft = maRange.getMinX() - ( fRight - maRange.getMaxX() );
1618 fTop = maRange.getMinY() - ( fBottom - maRange.getMaxY() );
1619 break;
1623 return Rectangle(basegfx::fround(fLeft), basegfx::fround(fTop), basegfx::fround(fRight), basegfx::fround(fBottom));
1626 //------------------------------------------------------------------------
1628 IMPL_LINK( SvxPositionSizeTabPage, ChangeWidthHdl, void *, EMPTYARG )
1630 if( maCbxScale.IsChecked() && maCbxScale.IsEnabled() )
1632 sal_Int64 nHeight(basegfx::fround64((mfOldHeight * (double)maMtrWidth.GetValue()) / mfOldWidth));
1634 if(nHeight <= maMtrHeight.GetMax(FUNIT_NONE))
1636 maMtrHeight.SetUserValue(nHeight, FUNIT_NONE);
1638 else
1640 nHeight = maMtrHeight.GetMax(FUNIT_NONE);
1641 maMtrHeight.SetUserValue(nHeight);
1643 const sal_Int64 nWidth(basegfx::fround64((mfOldWidth * (double)nHeight) / mfOldHeight));
1644 maMtrWidth.SetUserValue(nWidth, FUNIT_NONE);
1648 return( 0L );
1651 //------------------------------------------------------------------------
1653 IMPL_LINK( SvxPositionSizeTabPage, ChangeHeightHdl, void *, EMPTYARG )
1655 if( maCbxScale.IsChecked() && maCbxScale.IsEnabled() )
1657 sal_Int64 nWidth(basegfx::fround64((mfOldWidth * (double)maMtrHeight.GetValue()) / mfOldHeight));
1659 if(nWidth <= maMtrWidth.GetMax(FUNIT_NONE))
1661 maMtrWidth.SetUserValue(nWidth, FUNIT_NONE);
1663 else
1665 nWidth = maMtrWidth.GetMax(FUNIT_NONE);
1666 maMtrWidth.SetUserValue(nWidth);
1668 const sal_Int64 nHeight(basegfx::fround64((mfOldHeight * (double)nWidth) / mfOldWidth));
1669 maMtrHeight.SetUserValue(nHeight, FUNIT_NONE);
1673 return( 0L );
1676 //------------------------------------------------------------------------
1678 IMPL_LINK( SvxPositionSizeTabPage, ClickSizeProtectHdl, void *, EMPTYARG )
1680 UpdateControlStates();
1681 return( 0L );
1684 //------------------------------------------------------------------------
1686 IMPL_LINK( SvxPositionSizeTabPage, ClickAutoHdl, void *, EMPTYARG )
1688 if( maCbxScale.IsChecked() )
1690 mfOldWidth = std::max( (double)GetCoreValue( maMtrWidth, mePoolUnit ), 1.0 );
1691 mfOldHeight = std::max( (double)GetCoreValue( maMtrHeight, mePoolUnit ), 1.0 );
1694 return( 0L );
1697 //------------------------------------------------------------------------
1699 void SvxPositionSizeTabPage::FillUserData()
1701 // Abgleich wird in der Ini-Datei festgehalten
1702 UniString aStr = UniString::CreateFromInt32( (sal_Int32) maCbxScale.IsChecked() );
1703 SetUserData( aStr );
1706 // eof