Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/svdraw/constructhelper.cxx
Line
Count
Source
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
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/sxekitm.hxx>
28
#include <svx/svxids.hrc>
29
#include <svx/xdef.hxx>
30
#include <svx/xlnedit.hxx>
31
#include <svx/xlnedwit.hxx>
32
#include <svx/xlnstwit.hxx>
33
#include <svx/xlnstit.hxx>
34
#include <svx/xlnwtit.hxx>
35
36
//using namespace ::com::sun::star;
37
38
::basegfx::B2DPolyPolygon ConstructHelper::GetLineEndPoly(TranslateId pResId,
39
                                                          const SdrModel& rModel)
40
0
{
41
0
    ::basegfx::B2DPolyPolygon aRetval;
42
0
    XLineEndListRef pLineEndList(rModel.GetLineEndList());
43
44
0
    if (pLineEndList.is())
45
0
    {
46
0
        OUString aArrowName(SvxResId(pResId));
47
0
        tools::Long nCount = pLineEndList->Count();
48
0
        tools::Long nIndex;
49
0
        for (nIndex = 0; nIndex < nCount; nIndex++)
50
0
        {
51
0
            const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
52
0
            if (pEntry->GetName() == aArrowName)
53
0
            {
54
0
                aRetval = pEntry->GetLineEnd();
55
0
                break;
56
0
            }
57
0
        }
58
0
    }
59
60
0
    return aRetval;
61
0
}
62
63
void ConstructHelper::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId,
64
                                  tools::Long nWidth)
65
0
{
66
0
    SdrModel& rModel(rObj.getSdrModelFromSdrObject());
67
68
0
    if (!(nSlotId == SID_LINE_ARROW_START || nSlotId == SID_LINE_ARROW_END
69
0
          || nSlotId == SID_LINE_ARROWS || nSlotId == SID_LINE_ARROW_CIRCLE
70
0
          || nSlotId == SID_LINE_CIRCLE_ARROW || nSlotId == SID_LINE_ARROW_SQUARE
71
0
          || nSlotId == SID_LINE_SQUARE_ARROW || nSlotId == SID_DRAW_MEASURELINE
72
0
          || nSlotId == SID_CONNECTOR_LINE || nSlotId == SID_CONNECTOR_LINE_ARROW_START
73
0
          || nSlotId == SID_CONNECTOR_LINE_ARROW_END || nSlotId == SID_CONNECTOR_LINE_ARROWS
74
0
          || nSlotId == SID_CONNECTOR_LINE_CIRCLE_START || nSlotId == SID_CONNECTOR_LINE_CIRCLE_END
75
0
          || nSlotId == SID_CONNECTOR_LINE_CIRCLES || nSlotId == SID_CONNECTOR_LINES
76
0
          || nSlotId == SID_CONNECTOR_LINES_ARROW_START || nSlotId == SID_CONNECTOR_LINES_ARROW_END
77
0
          || nSlotId == SID_CONNECTOR_LINES_ARROWS || nSlotId == SID_CONNECTOR_LINES_CIRCLE_START
78
0
          || nSlotId == SID_CONNECTOR_LINES_CIRCLE_END || nSlotId == SID_CONNECTOR_LINES_CIRCLES
79
0
          || nSlotId == SID_CONNECTOR_ARROW_START || nSlotId == SID_CONNECTOR_ARROW_END
80
0
          || nSlotId == SID_CONNECTOR_ARROWS || nSlotId == SID_CONNECTOR_CIRCLE_START
81
0
          || nSlotId == SID_CONNECTOR_CIRCLE_END || nSlotId == SID_CONNECTOR_CIRCLES
82
0
          || nSlotId == SID_CONNECTOR_CURVE || nSlotId == SID_CONNECTOR_CURVE_ARROW_START
83
0
          || nSlotId == SID_CONNECTOR_CURVE_ARROW_END || nSlotId == SID_CONNECTOR_CURVE_ARROWS
84
0
          || nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START
85
0
          || nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END || nSlotId == SID_CONNECTOR_CURVE_CIRCLES))
86
0
        return;
87
88
    // set attributes of line start and ends
89
90
    // arrowhead
91
0
    ::basegfx::B2DPolyPolygon aArrow(GetLineEndPoly(RID_SVXSTR_ARROW, rModel));
92
0
    if (!aArrow.count())
93
0
    {
94
0
        ::basegfx::B2DPolygon aNewArrow;
95
0
        aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
96
0
        aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
97
0
        aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
98
0
        aNewArrow.setClosed(true);
99
0
        aArrow.append(aNewArrow);
100
0
    }
101
102
    // Circles
103
0
    ::basegfx::B2DPolyPolygon aCircle(GetLineEndPoly(RID_SVXSTR_CIRCLE, rModel));
104
0
    if (!aCircle.count())
105
0
    {
106
0
        ::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(
107
0
            ::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
108
0
        aNewCircle.setClosed(true);
109
0
        aCircle.append(aNewCircle);
110
0
    }
111
112
    // Square
113
0
    ::basegfx::B2DPolyPolygon aSquare(GetLineEndPoly(RID_SVXSTR_SQUARE, rModel));
114
0
    if (!aSquare.count())
115
0
    {
116
0
        ::basegfx::B2DPolygon aNewSquare;
117
0
        aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
118
0
        aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
119
0
        aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
120
0
        aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
121
0
        aNewSquare.setClosed(true);
122
0
        aSquare.append(aNewSquare);
123
0
    }
124
125
0
    SfxItemSet aSet(rModel.GetItemPool());
126
127
    // determine line width and calculate with it the line end width
128
0
    if (aSet.GetItemState(XATTR_LINEWIDTH) != SfxItemState::INVALID)
129
0
    {
130
0
        tools::Long nValue = aSet.Get(XATTR_LINEWIDTH).GetValue();
131
0
        if (nValue > 0)
132
0
            nWidth = nValue * 3;
133
0
    }
134
135
0
    switch (nSlotId)
136
0
    {
137
0
        case SID_CONNECTOR_ARROWS:
138
0
        case SID_CONNECTOR_LINE_ARROWS:
139
0
        case SID_CONNECTOR_LINES_ARROWS:
140
0
        case SID_CONNECTOR_CURVE_ARROWS:
141
0
        case SID_LINE_ARROWS:
142
0
        case SID_DRAW_MEASURELINE:
143
0
        {
144
            // connector with arrow ends
145
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
146
0
            rAttr.Put(XLineStartWidthItem(nWidth));
147
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
148
0
            rAttr.Put(XLineEndWidthItem(nWidth));
149
0
        }
150
0
        break;
151
152
0
        case SID_CONNECTOR_ARROW_START:
153
0
        case SID_CONNECTOR_LINE_ARROW_START:
154
0
        case SID_CONNECTOR_LINES_ARROW_START:
155
0
        case SID_CONNECTOR_CURVE_ARROW_START:
156
0
        case SID_LINE_ARROW_START:
157
0
        case SID_LINE_ARROW_CIRCLE:
158
0
        case SID_LINE_ARROW_SQUARE:
159
0
        {
160
            // connector with arrow start
161
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
162
0
            rAttr.Put(XLineStartWidthItem(nWidth));
163
0
        }
164
0
        break;
165
166
0
        case SID_CONNECTOR_ARROW_END:
167
0
        case SID_CONNECTOR_LINE_ARROW_END:
168
0
        case SID_CONNECTOR_LINES_ARROW_END:
169
0
        case SID_CONNECTOR_CURVE_ARROW_END:
170
0
        case SID_LINE_ARROW_END:
171
0
        case SID_LINE_CIRCLE_ARROW:
172
0
        case SID_LINE_SQUARE_ARROW:
173
0
        {
174
            // connector with arrow end
175
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), std::move(aArrow)));
176
0
            rAttr.Put(XLineEndWidthItem(nWidth));
177
0
        }
178
0
        break;
179
180
0
        case SID_CONNECTOR_CIRCLES:
181
0
        case SID_CONNECTOR_LINE_CIRCLES:
182
0
        case SID_CONNECTOR_LINES_CIRCLES:
183
0
        case SID_CONNECTOR_CURVE_CIRCLES:
184
0
        {
185
            // connector with circle ends
186
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
187
0
            rAttr.Put(XLineStartWidthItem(nWidth));
188
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
189
0
            rAttr.Put(XLineEndWidthItem(nWidth));
190
0
        }
191
0
        break;
192
193
0
        case SID_CONNECTOR_CIRCLE_START:
194
0
        case SID_CONNECTOR_LINE_CIRCLE_START:
195
0
        case SID_CONNECTOR_LINES_CIRCLE_START:
196
0
        case SID_CONNECTOR_CURVE_CIRCLE_START:
197
0
        {
198
            // connector with circle start
199
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
200
0
            rAttr.Put(XLineStartWidthItem(nWidth));
201
0
        }
202
0
        break;
203
204
0
        case SID_CONNECTOR_CIRCLE_END:
205
0
        case SID_CONNECTOR_LINE_CIRCLE_END:
206
0
        case SID_CONNECTOR_LINES_CIRCLE_END:
207
0
        case SID_CONNECTOR_CURVE_CIRCLE_END:
208
0
        {
209
            // connector with circle ends
210
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
211
0
            rAttr.Put(XLineEndWidthItem(nWidth));
212
0
        }
213
0
        break;
214
0
    }
215
216
    // and again, for the still missing ends
217
0
    switch (nSlotId)
218
0
    {
219
0
        case SID_LINE_ARROW_CIRCLE:
220
0
        {
221
            // circle end
222
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
223
0
            rAttr.Put(XLineEndWidthItem(nWidth));
224
0
        }
225
0
        break;
226
227
0
        case SID_LINE_CIRCLE_ARROW:
228
0
        {
229
            // circle start
230
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), std::move(aCircle)));
231
0
            rAttr.Put(XLineStartWidthItem(nWidth));
232
0
        }
233
0
        break;
234
235
0
        case SID_LINE_ARROW_SQUARE:
236
0
        {
237
            // square end
238
0
            rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
239
0
            rAttr.Put(XLineEndWidthItem(nWidth));
240
0
        }
241
0
        break;
242
243
0
        case SID_LINE_SQUARE_ARROW:
244
0
        {
245
            // square start
246
0
            rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), std::move(aSquare)));
247
0
            rAttr.Put(XLineStartWidthItem(nWidth));
248
0
        }
249
0
        break;
250
0
    }
251
0
    SetAttributes(rAttr, nSlotId);
252
0
}
253
254
/**
255
 * set attribute for the object to be created
256
 */
257
void ConstructHelper::SetAttributes(SfxItemSet& rAttr, sal_uInt16 nSlotId)
258
0
{
259
0
    if (nSlotId == SID_CONNECTOR_LINE || nSlotId == SID_CONNECTOR_LINE_ARROW_START
260
0
        || nSlotId == SID_CONNECTOR_LINE_ARROW_END || nSlotId == SID_CONNECTOR_LINE_ARROWS
261
0
        || nSlotId == SID_CONNECTOR_LINE_CIRCLE_START || nSlotId == SID_CONNECTOR_LINE_CIRCLE_END
262
0
        || nSlotId == SID_CONNECTOR_LINE_CIRCLES)
263
0
    {
264
        // direct connector
265
0
        rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::OneLine));
266
0
    }
267
0
    else if (nSlotId == SID_CONNECTOR_LINES || nSlotId == SID_CONNECTOR_LINES_ARROW_START
268
0
             || nSlotId == SID_CONNECTOR_LINES_ARROW_END || nSlotId == SID_CONNECTOR_LINES_ARROWS
269
0
             || nSlotId == SID_CONNECTOR_LINES_CIRCLE_START
270
0
             || nSlotId == SID_CONNECTOR_LINES_CIRCLE_END || nSlotId == SID_CONNECTOR_LINES_CIRCLES)
271
0
    {
272
        // line connector
273
0
        rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::ThreeLines));
274
0
    }
275
0
    else if (nSlotId == SID_CONNECTOR_CURVE || nSlotId == SID_CONNECTOR_CURVE_ARROW_START
276
0
             || nSlotId == SID_CONNECTOR_CURVE_ARROW_END || nSlotId == SID_CONNECTOR_CURVE_ARROWS
277
0
             || nSlotId == SID_CONNECTOR_CURVE_CIRCLE_START
278
0
             || nSlotId == SID_CONNECTOR_CURVE_CIRCLE_END || nSlotId == SID_CONNECTOR_CURVE_CIRCLES)
279
0
    {
280
        // curve connector
281
0
        rAttr.Put(SdrEdgeKindItem(SdrEdgeKind::Bezier));
282
0
    }
283
0
}
284
285
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */