Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sw/source/uibase/shells/drawdlg.cxx
Line
Count
Source (jump to first uncovered line)
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 <sfx2/request.hxx>
21
#include <sfx2/dispatch.hxx>
22
#include <sfx2/viewfrm.hxx>
23
#include <svx/svdview.hxx>
24
25
#include <view.hxx>
26
#include <wrtsh.hxx>
27
#include <cmdid.h>
28
29
#include <drawsh.hxx>
30
#include <svx/svxdlg.hxx>
31
#include <svx/dialogs.hrc>
32
#include <memory>
33
#include <svl/stritem.hxx>
34
#include <svx/xlnclit.hxx>
35
#include <svx/xflclit.hxx>
36
#include <svx/chrtitem.hxx>
37
#include <svx/xlnwtit.hxx>
38
#include <svx/xflgrit.hxx>
39
#include <svx/xflftrit.hxx>
40
#include <svx/xfltrit.hxx>
41
#include <comphelper/lok.hxx>
42
#include <textboxhelper.hxx>
43
44
void SwDrawShell::ExecDrawDlg(SfxRequest& rReq)
45
0
{
46
0
    SwWrtShell*     pSh     = &GetShell();
47
0
    SdrView*        pView   = pSh->GetDrawView();
48
0
    SdrModel& rModel = pView->GetModel();
49
0
    bool            bChanged = rModel.IsChanged();
50
0
    rModel.SetChanged(false);
51
52
0
    SfxItemSet aNewAttr(rModel.GetItemPool());
53
0
    pView->GetAttributes( aNewAttr );
54
55
0
    GetView().NoRotate();
56
57
0
    switch (rReq.GetSlot())
58
0
    {
59
0
        case FN_DRAWTEXT_ATTR_DLG:
60
0
        {
61
0
            SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
62
0
            VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(rReq.GetFrameWeld(), &aNewAttr, pView));
63
0
            auto xRequest = std::make_shared<SfxRequest>(rReq);
64
0
            rReq.Ignore(); // the 'old' request is not relevant any more
65
0
            pDlg->StartExecuteAsync(
66
0
                [pDlg, xRequest=std::move(xRequest), pView, pSh] (sal_Int32 nResult)->void
67
0
                {
68
0
                    if (nResult == RET_OK)
69
0
                    {
70
0
                        if (pView->GetMarkedObjectList().GetMarkCount() != 0)
71
0
                        {
72
0
                            pSh->StartAction();
73
0
                            pView->SetAttributes(*pDlg->GetOutputItemSet());
74
0
                            auto vMarkedObjs = pView->GetMarkedObjects();
75
0
                            for (auto pObj : vMarkedObjs)
76
0
                            {
77
                                // If the shape has textframe, set its params as well.
78
0
                                if (SwTextBoxHelper::hasTextFrame(pObj))
79
0
                                    SwTextBoxHelper::updateTextBoxMargin(pObj);
80
0
                            }
81
0
                            xRequest->Done(*(pDlg->GetOutputItemSet()));
82
0
                            pSh->EndAction();
83
0
                        }
84
0
                    }
85
0
                    pDlg->disposeOnce();
86
0
                }
87
0
            );
88
0
        }
89
0
        break;
90
91
0
        case SID_MEASURE_DLG:
92
0
        {
93
0
            bool bHasMarked = pView->GetMarkedObjectList().GetMarkCount() != 0;
94
95
0
            SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
96
0
            ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog(rReq.GetFrameWeld(),
97
0
                                                 aNewAttr, pView, RID_SVXPAGE_MEASURE));
98
0
            if (pDlg->Execute() == RET_OK)
99
0
            {
100
0
                pSh->StartAction();
101
0
                if (bHasMarked)
102
0
                    pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
103
0
                else
104
0
                    pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
105
0
                pSh->EndAction();
106
0
            }
107
0
        }
108
0
        break;
109
110
0
        case SID_ATTRIBUTES_AREA:
111
0
        {
112
0
            bool bHasMarked = pView->GetMarkedObjectList().GetMarkCount() != 0;
113
114
0
            SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
115
0
            VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(rReq.GetFrameWeld(),
116
0
                                                                            &aNewAttr,
117
0
                                                                            &rModel,
118
0
                                                                            true,
119
0
                                                                            false));
120
121
0
            pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
122
0
                                        sal_Int32 nResult){
123
0
                rModel.SetChanged(false);
124
125
0
                if (nResult == RET_OK)
126
0
                {
127
0
                    pSh->StartAction();
128
0
                    if (bHasMarked)
129
0
                        pView->SetAttributes(*pDlg->GetOutputItemSet());
130
0
                    else
131
0
                        pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
132
0
                    pSh->EndAction();
133
134
0
                    static sal_uInt16 aInval[] =
135
0
                    {
136
0
                        SID_ATTR_FILL_STYLE,
137
0
                        SID_ATTR_FILL_COLOR,
138
0
                        SID_ATTR_FILL_TRANSPARENCE,
139
0
                        SID_ATTR_FILL_FLOATTRANSPARENCE,
140
0
                        0
141
0
                    };
142
0
                    SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
143
0
                    rBnd.Invalidate(aInval);
144
0
                    rBnd.Update(SID_ATTR_FILL_STYLE);
145
0
                    rBnd.Update(SID_ATTR_FILL_COLOR);
146
0
                    rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
147
0
                    rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
148
0
                }
149
150
0
                if (rModel.IsChanged())
151
0
                    GetShell().SetModified();
152
0
                else if (bChanged)
153
0
                    rModel.SetChanged();
154
155
0
                pDlg->disposeOnce();
156
0
            });
157
0
        }
158
0
        break;
159
160
0
        case SID_ATTRIBUTES_LINE:
161
0
        {
162
0
            bool bHasMarked = pView->GetMarkedObjectList().GetMarkCount() != 0;
163
164
0
            const SdrObject* pObj = nullptr;
165
0
            const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
166
0
            if( rMarkList.GetMarkCount() == 1 )
167
0
                pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
168
169
0
            SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
170
0
            VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxLineTabDialog(rReq.GetFrameWeld(),
171
0
                    &aNewAttr,
172
0
                &rModel,
173
0
                pObj,
174
0
                bHasMarked));
175
176
0
            pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
177
0
                                        sal_Int32 nResult){
178
0
                rModel.SetChanged(false);
179
180
0
                if (nResult == RET_OK)
181
0
                {
182
0
                    pSh->StartAction();
183
0
                    if(bHasMarked)
184
0
                        pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
185
0
                    else
186
0
                        pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
187
0
                    pSh->EndAction();
188
189
0
                    static sal_uInt16 aInval[] =
190
0
                    {
191
0
                        SID_ATTR_LINE_STYLE,                // ( SID_SVX_START + 169 )
192
0
                        SID_ATTR_LINE_DASH,                 // ( SID_SVX_START + 170 )
193
0
                        SID_ATTR_LINE_WIDTH,                // ( SID_SVX_START + 171 )
194
0
                        SID_ATTR_LINE_COLOR,                // ( SID_SVX_START + 172 )
195
0
                        SID_ATTR_LINE_START,                // ( SID_SVX_START + 173 )
196
0
                        SID_ATTR_LINE_END,                  // ( SID_SVX_START + 174 )
197
0
                        SID_ATTR_LINE_TRANSPARENCE,         // (SID_SVX_START+1107)
198
0
                        SID_ATTR_LINE_JOINT,                // (SID_SVX_START+1110)
199
0
                        SID_ATTR_LINE_CAP,                  // (SID_SVX_START+1111)
200
0
                        0
201
0
                    };
202
203
0
                    GetView().GetViewFrame().GetBindings().Invalidate(aInval);
204
0
                }
205
206
0
                if (rModel.IsChanged())
207
0
                    GetShell().SetModified();
208
0
                else if (bChanged)
209
0
                    rModel.SetChanged();
210
211
0
                pDlg->disposeOnce();
212
0
            });
213
0
        }
214
0
        break;
215
216
0
        default:
217
0
            break;
218
0
    }
219
220
0
    if (rModel.IsChanged())
221
0
        GetShell().SetModified();
222
0
    else if (bChanged)
223
0
        rModel.SetChanged();
224
0
}
225
226
namespace
227
{
228
    void lcl_convertStringArguments(const std::unique_ptr<SfxItemSet>& pArgs)
229
0
    {
230
0
        if (const SvxDoubleItem* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_LINE_WIDTH_ARG, false))
231
0
        {
232
0
            double fValue = pWidthItem->GetValue();
233
            // FIXME: different units...
234
0
            int nPow = 100;
235
0
            int nValue = fValue * nPow;
236
237
0
            XLineWidthItem aItem(nValue);
238
0
            pArgs->Put(aItem);
239
0
        }
240
0
        if (const SfxStringItem* pJSON = pArgs->GetItemIfSet(SID_FILL_GRADIENT_JSON, false))
241
0
        {
242
0
            basegfx::BGradient aGradient = basegfx::BGradient::fromJSON(pJSON->GetValue());
243
0
            XFillGradientItem aItem(aGradient);
244
0
            pArgs->Put(aItem);
245
0
        }
246
0
    }
247
}
248
249
void SwDrawShell::ExecDrawAttrArgs(SfxRequest const & rReq)
250
0
{
251
0
    SwWrtShell* pSh   = &GetShell();
252
0
    SdrView*    pView = pSh->GetDrawView();
253
0
    const SfxItemSet* pArgs = rReq.GetArgs();
254
0
    bool        bChanged = pView->GetModel().IsChanged();
255
0
    pView->GetModel().SetChanged(false);
256
257
0
    GetView().NoRotate();
258
259
0
    if (pArgs)
260
0
    {
261
0
        if(pView->GetMarkedObjectList().GetMarkCount() != 0)
262
0
        {
263
0
            std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
264
0
            lcl_convertStringArguments(pNewArgs);
265
0
            pView->SetAttrToMarked(*pNewArgs, false);
266
0
        }
267
0
        else
268
0
            pView->SetDefaultAttr(*rReq.GetArgs(), false);
269
0
    }
270
0
    else
271
0
    {
272
0
        SfxDispatcher* pDis = pSh->GetView().GetViewFrame().GetDispatcher();
273
0
        switch (rReq.GetSlot())
274
0
        {
275
0
            case SID_ATTR_FILL_STYLE:
276
0
            case SID_ATTR_FILL_COLOR:
277
0
            case SID_ATTR_FILL_GRADIENT:
278
0
            case SID_ATTR_FILL_HATCH:
279
0
            case SID_ATTR_FILL_BITMAP:
280
0
            case SID_ATTR_FILL_TRANSPARENCE:
281
0
            case SID_ATTR_FILL_FLOATTRANSPARENCE:
282
0
                pDis->Execute(SID_ATTRIBUTES_AREA);
283
0
                break;
284
0
            case SID_ATTR_LINE_STYLE:
285
0
            case SID_ATTR_LINE_DASH:
286
0
            case SID_ATTR_LINE_WIDTH:
287
0
            case SID_ATTR_LINE_COLOR:
288
0
            case SID_ATTR_LINE_TRANSPARENCE:
289
0
            case SID_ATTR_LINE_JOINT:
290
0
            case SID_ATTR_LINE_CAP:
291
0
                pDis->Execute(SID_ATTRIBUTES_LINE);
292
0
                break;
293
0
        }
294
0
    }
295
0
    if (pView->GetModel().IsChanged())
296
0
        GetShell().SetModified();
297
0
    else
298
0
        if (bChanged)
299
0
            pView->GetModel().SetChanged();
300
0
}
301
302
static void lcl_unifyFillTransparencyItems(const SfxItemSet& rSet)
303
0
{
304
    // Transparent fill options are None, Solid, Linear, Axial, Radial, Elliptical, Square, Rectangular.
305
    // But this is represented across two items namely XFillTransparenceItem (for None and Solid)
306
    // and XFillFloatTransparenceItem (for the rest). To simplify the representation in LOKit case let's
307
    // use XFillFloatTransparenceItem to carry the information of XFillTransparenceItem when gradients
308
    // are disabled. When gradient transparency is disabled, all fields of XFillFloatTransparenceItem are invalid
309
    // and not used. So convert XFillTransparenceItem's constant transparency percentage as an intensity
310
    // and assign this to the XFillFloatTransparenceItem's start-intensity and end-intensity fields.
311
    // Now the LOK clients need only listen to statechange messages of XFillFloatTransparenceItem
312
    // to get fill-transparency settings instead of listening to two separate items.
313
314
0
    XFillFloatTransparenceItem* pFillFloatTranspItem =
315
0
        const_cast<XFillFloatTransparenceItem*>
316
0
        (rSet.GetItem<XFillFloatTransparenceItem>(XATTR_FILLFLOATTRANSPARENCE));
317
0
    if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
318
0
        return;
319
320
0
    const XFillTransparenceItem* pFillTranspItem =
321
0
        rSet.GetItem<XFillTransparenceItem>(XATTR_FILLTRANSPARENCE);
322
323
0
    if (!pFillTranspItem)
324
0
        return;
325
326
0
    basegfx::BGradient aTmpGradient = pFillFloatTranspItem->GetGradientValue();
327
0
    sal_uInt16 nTranspPercent = pFillTranspItem->GetValue();
328
    // Encode transparency percentage as intensity
329
0
    sal_uInt16 nIntensity = 100 - std::min<sal_uInt16>
330
0
        (std::max<sal_uInt16>(nTranspPercent, 0), 100);
331
0
    aTmpGradient.SetStartIntens(nIntensity);
332
0
    aTmpGradient.SetEndIntens(nIntensity);
333
0
    pFillFloatTranspItem->SetGradientValue(aTmpGradient);
334
0
}
335
336
void SwDrawShell::GetDrawAttrState(SfxItemSet& rSet)
337
0
{
338
0
    SdrView* pSdrView = GetShell().GetDrawView();
339
340
0
    if (pSdrView->GetMarkedObjectList().GetMarkCount() != 0)
341
0
    {
342
0
        bool bDisable = Disable( rSet );
343
344
0
        if( !bDisable )
345
0
        {
346
0
            SfxItemSet aSet(rSet);
347
0
            aSet.MergeRange(SDRATTR_TEXTCOLUMNS_NUMBER, SDRATTR_TEXTCOLUMNS_SPACING);
348
0
            pSdrView->GetAttributes(aSet);
349
0
            if (const SfxPoolItem* pItem = nullptr;
350
0
                aSet.GetItemState(SDRATTR_TEXTCOLUMNS_NUMBER, false, &pItem)
351
0
                    >= SfxItemState::DEFAULT
352
0
                && pItem)
353
0
            {
354
0
                aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_NUMBER));
355
0
            }
356
0
            if (const SfxPoolItem* pItem = nullptr;
357
0
                aSet.GetItemState(SDRATTR_TEXTCOLUMNS_SPACING, false, &pItem)
358
0
                    >= SfxItemState::DEFAULT
359
0
                && pItem)
360
0
            {
361
0
                aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_SPACING));
362
0
            }
363
0
            rSet.Put(aSet, false);
364
0
            if (comphelper::LibreOfficeKit::isActive())
365
0
                lcl_unifyFillTransparencyItems(rSet);
366
0
        }
367
0
    }
368
0
    else
369
0
        rSet.Put(pSdrView->GetDefaultAttr());
370
0
}
371
372
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */