Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / svdraw / constructhelper.cxx
blobd7c7f20a5cc845383707bc33739dbd88acd94b88
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 <basegfx/polygon/b2dpolygontools.hxx>
21 #include <svl/itemset.hxx>
22 #include <svx/constructhelper.hxx>
23 #include <svx/dialmgr.hxx>
24 #include <svx/strings.hrc>
25 #include <svx/svdmodel.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/xdef.hxx>
29 #include <svx/xlnedit.hxx>
30 #include <svx/xlnedwit.hxx>
31 #include <svx/xlnstwit.hxx>
32 #include <svx/xlnstit.hxx>
33 #include <svx/xlnwtit.hxx>
35 //using namespace ::com::sun::star;
37 ::basegfx::B2DPolyPolygon ConstructHelper::GetLineEndPoly(TranslateId pResId,
38 const SdrModel& rModel)
40 ::basegfx::B2DPolyPolygon aRetval;
41 XLineEndListRef pLineEndList(rModel.GetLineEndList());
43 if (pLineEndList.is())
45 OUString aArrowName(SvxResId(pResId));
46 tools::Long nCount = pLineEndList->Count();
47 tools::Long nIndex;
48 for (nIndex = 0; nIndex < nCount; nIndex++)
50 const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
51 if (pEntry->GetName() == aArrowName)
53 aRetval = pEntry->GetLineEnd();
54 break;
59 return aRetval;
62 void ConstructHelper::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId,
63 tools::Long nWidth)
65 SdrModel& rModel(rObj.getSdrModelFromSdrObject());
67 if (!(nSlotId == SID_LINE_ARROW_START || nSlotId == SID_LINE_ARROW_END
68 || nSlotId == SID_LINE_ARROWS || nSlotId == SID_LINE_ARROW_CIRCLE
69 || nSlotId == SID_LINE_CIRCLE_ARROW || nSlotId == SID_LINE_ARROW_SQUARE
70 || nSlotId == SID_LINE_SQUARE_ARROW || nSlotId == SID_DRAW_MEASURELINE))
71 return;
73 // set attributes of line start and ends
75 // arrowhead
76 ::basegfx::B2DPolyPolygon aArrow(GetLineEndPoly(RID_SVXSTR_ARROW, rModel));
77 if (!aArrow.count())
79 ::basegfx::B2DPolygon aNewArrow;
80 aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
81 aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
82 aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
83 aNewArrow.setClosed(true);
84 aArrow.append(aNewArrow);
87 // Circles
88 ::basegfx::B2DPolyPolygon aCircle(GetLineEndPoly(RID_SVXSTR_CIRCLE, rModel));
89 if (!aCircle.count())
91 ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(
92 ::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
93 aNewCircle.setClosed(true);
94 aCircle.append(aNewCircle);
97 // Square
98 ::basegfx::B2DPolyPolygon aSquare(GetLineEndPoly(RID_SVXSTR_SQUARE, rModel));
99 if (!aSquare.count())
101 ::basegfx::B2DPolygon aNewSquare;
102 aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
103 aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
104 aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
105 aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
106 aNewSquare.setClosed(true);
107 aSquare.append(aNewSquare);
110 SfxItemSet aSet(rModel.GetItemPool());
112 // determine line width and calculate with it the line end width
113 if (aSet.GetItemState(XATTR_LINEWIDTH) != SfxItemState::DONTCARE)
115 tools::Long nValue = aSet.Get(XATTR_LINEWIDTH).GetValue();
116 if (nValue > 0)
117 nWidth = nValue * 3;
120 switch (nSlotId)
122 case SID_LINE_ARROWS:
123 case SID_DRAW_MEASURELINE:
125 // connector with arrow ends
126 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
127 rAttr.Put(XLineStartWidthItem(nWidth));
128 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
129 rAttr.Put(XLineEndWidthItem(nWidth));
131 break;
133 case SID_LINE_ARROW_START:
134 case SID_LINE_ARROW_CIRCLE:
135 case SID_LINE_ARROW_SQUARE:
137 // connector with arrow start
138 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
139 rAttr.Put(XLineStartWidthItem(nWidth));
141 break;
143 case SID_LINE_ARROW_END:
144 case SID_LINE_CIRCLE_ARROW:
145 case SID_LINE_SQUARE_ARROW:
147 // connector with arrow end
148 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
149 rAttr.Put(XLineEndWidthItem(nWidth));
151 break;
154 // and again, for the still missing ends
155 switch (nSlotId)
157 case SID_LINE_ARROW_CIRCLE:
159 // circle end
160 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
161 rAttr.Put(XLineEndWidthItem(nWidth));
163 break;
165 case SID_LINE_CIRCLE_ARROW:
167 // circle start
168 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
169 rAttr.Put(XLineStartWidthItem(nWidth));
171 break;
173 case SID_LINE_ARROW_SQUARE:
175 // square end
176 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
177 rAttr.Put(XLineEndWidthItem(nWidth));
179 break;
181 case SID_LINE_SQUARE_ARROW:
183 // square start
184 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
185 rAttr.Put(XLineStartWidthItem(nWidth));
187 break;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */