include/svx/constructhelper.hxx | 37 ++++++ sc/source/ui/drawfunc/fuconrec.cxx | 163 ----------------------------- svx/Library_svxcore.mk | 3 svx/source/svdraw/constructhelper.cxx | 190 ++++++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+), 162 deletions(-)
New commits: commit 32fd602d3918be032d79322f76021c6ebc27ccba Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Fri Jun 30 23:41:15 2023 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Jul 3 21:33:44 2023 +0200 tdf#155630 Move sc's SetLineEnds into svx SetLineEnds is duped in sc,sd and sw. Swing SetLineEnds into svx where we'll share it. Note: a) We also move it's helper function getPolygon b) sc, sd and sw use different values for the magic nWidth value so parameterise Change-Id: I6011b41d9db7b7fab364038227e1866fb9d64b02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153826 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/include/svx/constructhelper.hxx b/include/svx/constructhelper.hxx new file mode 100644 index 000000000000..449a7ba7d1d0 --- /dev/null +++ b/include/svx/constructhelper.hxx @@ -0,0 +1,37 @@ +/* -*- 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 . + */ + +#pragma once + +#include <svx/svxdllapi.h> +#include <tools/long.hxx> + +class SdrObject; +class SfxItemSet; + +class SVXCORE_DLLPUBLIC ConstructHelper +{ +public: + // set line starts and ends for newly created objects + static void SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId, + tools::Long nWidth); +}; + +////////////////////////////////////////////////////////////////////////////// +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/drawfunc/fuconrec.cxx b/sc/source/ui/drawfunc/fuconrec.cxx index d73915ca450e..0f06de3d82db 100644 --- a/sc/source/ui/drawfunc/fuconrec.cxx +++ b/sc/source/ui/drawfunc/fuconrec.cxx @@ -22,6 +22,7 @@ #include <drawview.hxx> #include <editeng/outlobj.hxx> +#include <svx/constructhelper.hxx> // Create default drawing objects via keyboard #include <svx/svdopath.hxx> #include <svx/svdocapt.hxx> @@ -50,38 +51,6 @@ FuConstRectangle::~FuConstRectangle() { } -/** - * set line starts and ends for the object to be created - */ - -namespace { - -::basegfx::B2DPolyPolygon getPolygon(TranslateId pResId, const SdrModel& rModel) -{ - ::basegfx::B2DPolyPolygon aRetval; - XLineEndListRef pLineEndList(rModel.GetLineEndList()); - - if( pLineEndList.is() ) - { - OUString aArrowName( SvxResId(pResId) ); - tools::Long nCount = pLineEndList->Count(); - tools::Long nIndex; - for( nIndex = 0; nIndex < nCount; nIndex++ ) - { - const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex); - if( pEntry->GetName() == aArrowName ) - { - aRetval = pEntry->GetLineEnd(); - break; - } - } - } - - return aRetval; -} - -} - bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt) { // remember button state for creation of own MouseEvents @@ -206,135 +175,7 @@ void FuConstRectangle::Activate() void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId) { - SdrModel& rModel(rObj.getSdrModelFromSdrObject()); - - if ( !(nSlotId == SID_LINE_ARROW_START || - nSlotId == SID_LINE_ARROW_END || - nSlotId == SID_LINE_ARROWS || - nSlotId == SID_LINE_ARROW_CIRCLE || - nSlotId == SID_LINE_CIRCLE_ARROW || - nSlotId == SID_LINE_ARROW_SQUARE || - nSlotId == SID_LINE_SQUARE_ARROW || - nSlotId == SID_DRAW_MEASURELINE) ) - return; - - - // set attributes of line start and ends - - // arrowhead - ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) ); - if( !aArrow.count() ) - { - ::basegfx::B2DPolygon aNewArrow; - aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0)); - aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0)); - aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0)); - aNewArrow.setClosed(true); - aArrow.append(aNewArrow); - } - - // Circles - ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) ); - if( !aCircle.count() ) - { - ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0); - aNewCircle.setClosed(true); - aCircle.append(aNewCircle); - } - - // Square - ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) ); - if( !aSquare.count() ) - { - ::basegfx::B2DPolygon aNewSquare; - aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0)); - aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0)); - aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0)); - aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0)); - aNewSquare.setClosed(true); - aSquare.append(aNewSquare); - } - - SfxItemSet aSet( rModel.GetItemPool() ); - tools::Long nWidth = 200; // (1/100th mm) - - // determine line width and calculate with it the line end width - if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE ) - { - tools::Long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue(); - if( nValue > 0 ) - nWidth = nValue * 3; - } - - switch (nSlotId) - { - case SID_LINE_ARROWS: - case SID_DRAW_MEASURELINE: - { - // connector with arrow ends - rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); - rAttr.Put(XLineStartWidthItem(nWidth)); - rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); - rAttr.Put(XLineEndWidthItem(nWidth)); - } - break; - - case SID_LINE_ARROW_START: - case SID_LINE_ARROW_CIRCLE: - case SID_LINE_ARROW_SQUARE: - { - // connector with arrow start - rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); - rAttr.Put(XLineStartWidthItem(nWidth)); - } - break; - - case SID_LINE_ARROW_END: - case SID_LINE_CIRCLE_ARROW: - case SID_LINE_SQUARE_ARROW: - { - // connector with arrow end - rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); - rAttr.Put(XLineEndWidthItem(nWidth)); - } - break; - } - - // and again, for the still missing ends - switch (nSlotId) - { - case SID_LINE_ARROW_CIRCLE: - { - // circle end - rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle)); - rAttr.Put(XLineEndWidthItem(nWidth)); - } - break; - - case SID_LINE_CIRCLE_ARROW: - { - // circle start - rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle)); - rAttr.Put(XLineStartWidthItem(nWidth)); - } - break; - - case SID_LINE_ARROW_SQUARE: - { - // square end - rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare)); - rAttr.Put(XLineEndWidthItem(nWidth)); - } - break; - - case SID_LINE_SQUARE_ARROW: - { - // square start - rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare)); - rAttr.Put(XLineStartWidthItem(nWidth)); - } - break; - } + ConstructHelper::SetLineEnds(rAttr, rObj, nSlotId, 200); } void FuConstRectangle::Deactivate() diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index ed2298e526c4..bdff68a6a4b1 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -329,8 +329,9 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/sdr/properties/connectorproperties \ svx/source/sdr/properties/e3dcompoundproperties \ svx/source/sdr/properties/oleproperties \ - svx/source/svdraw/clonelist \ svx/source/svdraw/charthelper \ + svx/source/svdraw/constructhelper \ + svx/source/svdraw/clonelist \ svx/source/svdraw/gradtrns \ svx/source/svdraw/polypolygoneditor \ svx/source/svdraw/presetooxhandleadjustmentrelations \ diff --git a/svx/source/svdraw/constructhelper.cxx b/svx/source/svdraw/constructhelper.cxx new file mode 100644 index 000000000000..f09d11787809 --- /dev/null +++ b/svx/source/svdraw/constructhelper.cxx @@ -0,0 +1,190 @@ +/* -*- 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 . + */ + +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <svl/itemset.hxx> +#include <svx/constructhelper.hxx> +#include <svx/dialmgr.hxx> +#include <svx/strings.hrc> +#include <svx/svdmodel.hxx> +#include <svx/svdobj.hxx> +#include <svx/svxids.hrc> +#include <svx/xdef.hxx> +#include <svx/xlnedit.hxx> +#include <svx/xlnedwit.hxx> +#include <svx/xlnstwit.hxx> +#include <svx/xlnstit.hxx> +#include <svx/xlnwtit.hxx> + +//using namespace ::com::sun::star; + +static ::basegfx::B2DPolyPolygon lcl_getPolygon(TranslateId pResId, const SdrModel& rModel) +{ + ::basegfx::B2DPolyPolygon aRetval; + XLineEndListRef pLineEndList(rModel.GetLineEndList()); + + if (pLineEndList.is()) + { + OUString aArrowName(SvxResId(pResId)); + tools::Long nCount = pLineEndList->Count(); + tools::Long nIndex; + for (nIndex = 0; nIndex < nCount; nIndex++) + { + const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex); + if (pEntry->GetName() == aArrowName) + { + aRetval = pEntry->GetLineEnd(); + break; + } + } + } + + return aRetval; +} + +void ConstructHelper::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId, + tools::Long nWidth) +{ + SdrModel& rModel(rObj.getSdrModelFromSdrObject()); + + if (!(nSlotId == SID_LINE_ARROW_START || nSlotId == SID_LINE_ARROW_END + || nSlotId == SID_LINE_ARROWS || nSlotId == SID_LINE_ARROW_CIRCLE + || nSlotId == SID_LINE_CIRCLE_ARROW || nSlotId == SID_LINE_ARROW_SQUARE + || nSlotId == SID_LINE_SQUARE_ARROW || nSlotId == SID_DRAW_MEASURELINE)) + return; + + // set attributes of line start and ends + + // arrowhead + ::basegfx::B2DPolyPolygon aArrow(lcl_getPolygon(RID_SVXSTR_ARROW, rModel)); + if (!aArrow.count()) + { + ::basegfx::B2DPolygon aNewArrow; + aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0)); + aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0)); + aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0)); + aNewArrow.setClosed(true); + aArrow.append(aNewArrow); + } + + // Circles + ::basegfx::B2DPolyPolygon aCircle(lcl_getPolygon(RID_SVXSTR_CIRCLE, rModel)); + if (!aCircle.count()) + { + ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse( + ::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0); + aNewCircle.setClosed(true); + aCircle.append(aNewCircle); + } + + // Square + ::basegfx::B2DPolyPolygon aSquare(lcl_getPolygon(RID_SVXSTR_SQUARE, rModel)); + if (!aSquare.count()) + { + ::basegfx::B2DPolygon aNewSquare; + aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0)); + aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0)); + aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0)); + aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0)); + aNewSquare.setClosed(true); + aSquare.append(aNewSquare); + } + + SfxItemSet aSet(rModel.GetItemPool()); + + // determine line width and calculate with it the line end width + if (aSet.GetItemState(XATTR_LINEWIDTH) != SfxItemState::DONTCARE) + { + tools::Long nValue = aSet.Get(XATTR_LINEWIDTH).GetValue(); + if (nValue > 0) + nWidth = nValue * 3; + } + + switch (nSlotId) + { + case SID_LINE_ARROWS: + case SID_DRAW_MEASURELINE: + { + // connector with arrow ends + rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); + rAttr.Put(XLineStartWidthItem(nWidth)); + rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); + rAttr.Put(XLineEndWidthItem(nWidth)); + } + break; + + case SID_LINE_ARROW_START: + case SID_LINE_ARROW_CIRCLE: + case SID_LINE_ARROW_SQUARE: + { + // connector with arrow start + rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); + rAttr.Put(XLineStartWidthItem(nWidth)); + } + break; + + case SID_LINE_ARROW_END: + case SID_LINE_CIRCLE_ARROW: + case SID_LINE_SQUARE_ARROW: + { + // connector with arrow end + rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow)); + rAttr.Put(XLineEndWidthItem(nWidth)); + } + break; + } + + // and again, for the still missing ends + switch (nSlotId) + { + case SID_LINE_ARROW_CIRCLE: + { + // circle end + rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle)); + rAttr.Put(XLineEndWidthItem(nWidth)); + } + break; + + case SID_LINE_CIRCLE_ARROW: + { + // circle start + rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle)); + rAttr.Put(XLineStartWidthItem(nWidth)); + } + break; + + case SID_LINE_ARROW_SQUARE: + { + // square end + rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare)); + rAttr.Put(XLineEndWidthItem(nWidth)); + } + break; + + case SID_LINE_SQUARE_ARROW: + { + // square start + rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare)); + rAttr.Put(XLineStartWidthItem(nWidth)); + } + break; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */