LibreOffice Module svx (master) 1
constructhelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <svl/itemset.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>
34
35//using namespace ::com::sun::star;
36
38 const SdrModel& rModel)
39{
41 XLineEndListRef pLineEndList(rModel.GetLineEndList());
42
43 if (pLineEndList.is())
44 {
45 OUString aArrowName(SvxResId(pResId));
46 tools::Long nCount = pLineEndList->Count();
48 for (nIndex = 0; nIndex < nCount; nIndex++)
49 {
50 const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
51 if (pEntry->GetName() == aArrowName)
52 {
53 aRetval = pEntry->GetLineEnd();
54 break;
55 }
56 }
57 }
58
59 return aRetval;
60}
61
62void ConstructHelper::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId,
63 tools::Long nWidth)
64{
65 SdrModel& rModel(rObj.getSdrModelFromSdrObject());
66
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;
72
73 // set attributes of line start and ends
74
75 // arrowhead
76 ::basegfx::B2DPolyPolygon aArrow(GetLineEndPoly(RID_SVXSTR_ARROW, rModel));
77 if (!aArrow.count())
78 {
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);
85 }
86
87 // Circles
88 ::basegfx::B2DPolyPolygon aCircle(GetLineEndPoly(RID_SVXSTR_CIRCLE, rModel));
89 if (!aCircle.count())
90 {
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);
95 }
96
97 // Square
98 ::basegfx::B2DPolyPolygon aSquare(GetLineEndPoly(RID_SVXSTR_SQUARE, rModel));
99 if (!aSquare.count())
100 {
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);
108 }
109
110 SfxItemSet aSet(rModel.GetItemPool());
111
112 // determine line width and calculate with it the line end width
113 if (aSet.GetItemState(XATTR_LINEWIDTH) != SfxItemState::DONTCARE)
114 {
115 tools::Long nValue = aSet.Get(XATTR_LINEWIDTH).GetValue();
116 if (nValue > 0)
117 nWidth = nValue * 3;
118 }
119
120 switch (nSlotId)
121 {
122 case SID_LINE_ARROWS:
123 case SID_DRAW_MEASURELINE:
124 {
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));
130 }
131 break;
132
133 case SID_LINE_ARROW_START:
134 case SID_LINE_ARROW_CIRCLE:
135 case SID_LINE_ARROW_SQUARE:
136 {
137 // connector with arrow start
138 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
139 rAttr.Put(XLineStartWidthItem(nWidth));
140 }
141 break;
142
143 case SID_LINE_ARROW_END:
144 case SID_LINE_CIRCLE_ARROW:
145 case SID_LINE_SQUARE_ARROW:
146 {
147 // connector with arrow end
148 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
149 rAttr.Put(XLineEndWidthItem(nWidth));
150 }
151 break;
152 }
153
154 // and again, for the still missing ends
155 switch (nSlotId)
156 {
157 case SID_LINE_ARROW_CIRCLE:
158 {
159 // circle end
160 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
161 rAttr.Put(XLineEndWidthItem(nWidth));
162 }
163 break;
164
165 case SID_LINE_CIRCLE_ARROW:
166 {
167 // circle start
168 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
169 rAttr.Put(XLineStartWidthItem(nWidth));
170 }
171 break;
172
173 case SID_LINE_ARROW_SQUARE:
174 {
175 // square end
176 rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
177 rAttr.Put(XLineEndWidthItem(nWidth));
178 }
179 break;
180
181 case SID_LINE_SQUARE_ARROW:
182 {
183 // square start
184 rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
185 rAttr.Put(XLineStartWidthItem(nWidth));
186 }
187 break;
188 }
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::basegfx::B2DPolyPolygon GetLineEndPoly(TranslateId pResId, const SdrModel &rModel)
static void SetLineEnds(SfxItemSet &rAttr, const SdrObject &rObj, sal_uInt16 nSlotId, tools::Long nWidth)
XLineEndListRef GetLineEndList() const
Definition: svdmodel.hxx:533
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:318
Abstract DrawObject.
Definition: svdobj.hxx:260
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:289
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const basegfx::B2DPolyPolygon & GetLineEnd() const
Definition: xtable.hxx:65
const OUString & GetName() const
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
sal_uInt32 count() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
sal_Int32 nIndex
long Long
constexpr TypedWhichId< XLineWidthItem > XATTR_LINEWIDTH(XATTR_LINE_FIRST+2)