cui/source/tabpages/transfrm.cxx | 31 ++--------- include/svx/transfrmhelper.hxx | 50 ++++++++++++++++++ svx/source/sidebar/possize/PosSizePropertyPanel.cxx | 55 ++++++++++++++++---- svx/source/sidebar/possize/PosSizePropertyPanel.hxx | 5 + 4 files changed, 106 insertions(+), 35 deletions(-)
New commits: commit 1386c348f81738a9966d1217db89d1f603466317 Author: Katarina Behrens <[email protected]> Date: Fri Nov 28 11:20:04 2014 +0100 fdo#82616: set limits on spinboxes according to size of workarea Do it the same way as position'n'size dialog does, for that matter move shared code into a separate header/class. This fixes regression from .ui migration that omitted spinbox limits Change-Id: I884904719b2608dd80aecc5d7ffb3923de71774d Reviewed-on: https://gerrit.libreoffice.org/13174 Tested-by: LibreOffice gerrit bot <[email protected]> Reviewed-by: Katarina Behrens <[email protected]> diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx index e1193c1..310a1a1 100644 --- a/cui/source/tabpages/transfrm.cxx +++ b/cui/source/tabpages/transfrm.cxx @@ -24,6 +24,7 @@ #include <svx/svdotext.hxx> #include <svx/sderitm.hxx> #include <svx/dialogs.hrc> +#include <svx/transfrmhelper.hxx> #include <cuires.hrc> #include <editeng/sizeitem.hxx> @@ -78,24 +79,6 @@ static const sal_uInt16 pSlantRanges[] = 0 }; -static void lcl_ConvertRect(basegfx::B2DRange& rRange, const sal_uInt16 nDigits, const MapUnit ePoolUnit, const FieldUnit eDlgUnit) -{ - const basegfx::B2DPoint aTopLeft( - (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinX()), nDigits, ePoolUnit, eDlgUnit), - (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinY()), nDigits, ePoolUnit, eDlgUnit)); - const basegfx::B2DPoint aBottomRight( - (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxX()), nDigits, ePoolUnit, eDlgUnit), - (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxY()), nDigits, ePoolUnit, eDlgUnit)); - - rRange = basegfx::B2DRange(aTopLeft, aBottomRight); -} - -static void lcl_ScaleRect(basegfx::B2DRange& rRange, const Fraction aUIScale) -{ - const double fFactor(1.0 / double(aUIScale)); - rRange = basegfx::B2DRange(rRange.getMinimum() * fFactor, rRange.getMaximum() * fFactor); -} - /************************************************************************* |* |* constructor of the tab dialog: adds the pages to the dialog @@ -255,11 +238,11 @@ void SvxAngleTabPage::Construct() // take scale into account const Fraction aUIScale(pView->GetModel()->GetUIScale()); - lcl_ScaleRect(maRange, aUIScale); + TransfrmHelper::ScaleRect(maRange, aUIScale); // take UI units into account sal_uInt16 nDigits(m_pMtrPosX->GetDecimalDigits()); - lcl_ConvertRect(maRange, nDigits, (MapUnit)ePoolUnit, eDlgUnit); + TransfrmHelper::ConvertRect(maRange, nDigits, (MapUnit)ePoolUnit, eDlgUnit); if(!pView->IsRotateAllowed()) { @@ -759,13 +742,13 @@ void SvxPositionSizeTabPage::Construct() // take scale into account const Fraction aUIScale(mpView->GetModel()->GetUIScale()); - lcl_ScaleRect( maWorkRange, aUIScale ); - lcl_ScaleRect( maRange, aUIScale ); + TransfrmHelper::ScaleRect( maWorkRange, aUIScale ); + TransfrmHelper::ScaleRect( maRange, aUIScale ); // take UI units into account const sal_uInt16 nDigits(m_pMtrPosX->GetDecimalDigits()); - lcl_ConvertRect( maWorkRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); - lcl_ConvertRect( maRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); + TransfrmHelper::ConvertRect( maWorkRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); + TransfrmHelper::ConvertRect( maRange, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); SetMinMaxPosition(); } diff --git a/include/svx/transfrmhelper.hxx b/include/svx/transfrmhelper.hxx new file mode 100644 index 0000000..71affa7 --- /dev/null +++ b/include/svx/transfrmhelper.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SVX_TRANSFRMHELPER_HXX +#define INCLUDED_SVX_TRANSFRMHELPER_HXX + +#include <basegfx/range/b2drange.hxx> +#include <tools/fldunit.hxx> +#include <tools/mapunit.hxx> + +class SVX_DLLPUBLIC TransfrmHelper +{ +public: + static void ConvertRect(basegfx::B2DRange& rRange, const sal_uInt16 nDigits, const MapUnit ePoolUnit, const FieldUnit eDlgUnit) + { + const basegfx::B2DPoint aTopLeft( + (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinX()), nDigits, ePoolUnit, eDlgUnit), + (double)MetricField::ConvertValue(basegfx::fround(rRange.getMinY()), nDigits, ePoolUnit, eDlgUnit)); + const basegfx::B2DPoint aBottomRight( + (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxX()), nDigits, ePoolUnit, eDlgUnit), + (double)MetricField::ConvertValue(basegfx::fround(rRange.getMaxY()), nDigits, ePoolUnit, eDlgUnit)); + + rRange = basegfx::B2DRange(aTopLeft, aBottomRight); + } + + static void ScaleRect(basegfx::B2DRange& rRange, const Fraction aUIScale) + { + const double fFactor(1.0 / double(aUIScale)); + rRange = basegfx::B2DRange(rRange.getMinimum() * fFactor, rRange.getMaximum() * fFactor); + } +}; + +#endif +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx index 6956bf6..44c5288 100644 --- a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx +++ b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx @@ -37,6 +37,7 @@ #include <vcl/toolbox.hxx> #include <svl/aeitem.hxx> #include <svx/svdview.hxx> +#include <svx/transfrmhelper.hxx> using namespace css; using namespace css::uno; @@ -949,10 +950,6 @@ void PosSizePropertyPanel::executePosX() lX = -lX; long lY = GetCoreValue( *mpMtrPosY, mePoolUnit ); - Rectangle aRect; - maRect = mpView->GetAllMarkedRect(); - aRect = mpView->GetAllMarkedRect(); - Fraction aUIScale = mpView->GetModel()->GetUIScale(); lX += maAnchorPos.X(); lX = Fraction( lX ) * aUIScale; @@ -976,10 +973,6 @@ void PosSizePropertyPanel::executePosY() long lX = GetCoreValue( *mpMtrPosX, mePoolUnit ); long lY = GetCoreValue( *mpMtrPosY, mePoolUnit ); - Rectangle aRect; - maRect = mpView->GetAllMarkedRect(); - aRect = mpView->GetAllMarkedRect(); - Fraction aUIScale = mpView->GetModel()->GetUIScale(); lX += maAnchorPos.X(); lX = Fraction( lX ) * aUIScale; @@ -1018,6 +1011,7 @@ void PosSizePropertyPanel::MetricState( SfxItemState eState, const SfxPoolItem* SetFieldUnit( *mpMtrPosY, meDlgUnit, true ); if(bPosYBlank) mpMtrPosY->SetText(OUString()); + SetPosXYMinMax(); if (mpMtrWidth->GetText().isEmpty()) bWidthBlank = true; @@ -1153,8 +1147,49 @@ void PosSizePropertyPanel::DisableControls() } } - - +void PosSizePropertyPanel::SetPosXYMinMax() +{ + Rectangle aTmpRect(mpView->GetAllMarkedRect()); + mpView->GetSdrPageView()->LogicToPagePos(aTmpRect); + maRect = basegfx::B2DRange(aTmpRect.Left(), aTmpRect.Top(), aTmpRect.Right(), aTmpRect.Bottom()); + + Rectangle aTmpRect2(mpView->GetWorkArea()); + mpView->GetSdrPageView()->LogicToPagePos(aTmpRect2); + maWorkArea = basegfx::B2DRange(aTmpRect2.Left(), aTmpRect2.Top(), aTmpRect2.Right(), aTmpRect2.Bottom()); + + const Fraction aUIScale(mpView->GetModel()->GetUIScale()); + TransfrmHelper::ScaleRect( maWorkArea, aUIScale ); + TransfrmHelper::ScaleRect( maRect, aUIScale ); + + const sal_uInt16 nDigits(mpMtrPosX->GetDecimalDigits()); + TransfrmHelper::ConvertRect( maWorkArea, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); + TransfrmHelper::ConvertRect( maRect, nDigits, (MapUnit) mePoolUnit, meDlgUnit ); + + double fLeft(maWorkArea.getMinX()); + double fTop(maWorkArea.getMinY()); + double fRight(maWorkArea.getMaxX()); + double fBottom(maWorkArea.getMaxY()); + + // seems that sidebar defaults to top left reference point + // and there's no way to set it to something else + fRight -= maRect.getWidth(); + fBottom -= maRect.getHeight(); + + const double fMaxLong((double)(MetricField::ConvertValue( LONG_MAX, 0, MAP_100TH_MM, meDlgUnit ) - 1L)); + fLeft = basegfx::clamp(fLeft, -fMaxLong, fMaxLong); + fRight = basegfx::clamp(fRight, -fMaxLong, fMaxLong); + fTop = basegfx::clamp(fTop, - fMaxLong, fMaxLong); + fBottom = basegfx::clamp(fBottom, -fMaxLong, fMaxLong); + + mpMtrPosX->SetMin(basegfx::fround64(fLeft)); + mpMtrPosX->SetFirst(basegfx::fround64(fLeft)); + mpMtrPosX->SetMax(basegfx::fround64(fRight)); + mpMtrPosX->SetLast(basegfx::fround64(fRight)); + mpMtrPosY->SetMin(basegfx::fround64(fTop)); + mpMtrPosY->SetFirst(basegfx::fround64(fTop)); + mpMtrPosY->SetMax(basegfx::fround64(fBottom)); + mpMtrPosY->SetLast(basegfx::fround64(fBottom)); +} void PosSizePropertyPanel::UpdateUIScale() { diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.hxx b/svx/source/sidebar/possize/PosSizePropertyPanel.hxx index e9880c4..a0b39cd 100644 --- a/svx/source/sidebar/possize/PosSizePropertyPanel.hxx +++ b/svx/source/sidebar/possize/PosSizePropertyPanel.hxx @@ -30,6 +30,7 @@ #include <tools/fldunit.hxx> #include <tools/fract.hxx> #include <com/sun/star/ui/XSidebar.hpp> +#include <basegfx/range/b2drange.hxx> class DialControl; class SdrView; @@ -95,7 +96,8 @@ private: ToolBox* mpFlipTbx; // Internal variables - Rectangle maRect; + basegfx::B2DRange maRect; + basegfx::B2DRange maWorkArea; const SdrView* mpView; sal_uInt32 mlOldWidth; sal_uInt32 mlOldHeight; @@ -163,6 +165,7 @@ private: void MetricState( SfxItemState eState, const SfxPoolItem* pState ); FieldUnit GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState ); void DisableControls(); + void SetPosXYMinMax(); /** Check if the UI scale has changed and handle such a change. UI scale is an SD only feature. The UI scale is represented by items _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
