Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/func/futransf.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 <futransf.hxx>
21
22
#include <svx/svxids.hrc>
23
#include <sfx2/request.hxx>
24
25
#include <strings.hrc>
26
#include <ViewShell.hxx>
27
#include <View.hxx>
28
#include <sdresid.hxx>
29
#include <drawdoc.hxx>
30
#include <svx/svxdlg.hxx>
31
#include <comphelper/lok.hxx>
32
33
#include <memory>
34
35
using namespace sd;
36
37
FuTransform::FuTransform(ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView,
38
                         SdDrawDocument& rDoc, SfxRequest& rReq)
39
0
    : FuPoor(rViewSh, pWin, pView, rDoc, rReq)
40
0
{
41
0
}
42
43
rtl::Reference<FuPoor> FuTransform::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq )
44
0
{
45
0
    rtl::Reference<FuPoor> xFunc( new FuTransform( rViewSh, pWin, pView, rDoc, rReq ) );
46
0
    xFunc->DoExecute(rReq);
47
0
    return xFunc;
48
0
}
49
50
namespace {
51
52
void setUndo(::sd::View* pView, const SfxItemSet* pArgs, bool addPageMargin)
53
0
{
54
    // Undo
55
0
    const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
56
0
    OUString aString = rMarkList.GetMarkDescription() +
57
0
        " " + SdResId(STR_TRANSFORM);
58
0
    pView->BegUndo(aString);
59
0
    pView->SetGeoAttrToMarked(*pArgs, addPageMargin);
60
0
    pView->SetAttributes(*pArgs);
61
0
    pView->EndUndo();
62
0
}
63
64
}
65
66
void FuTransform::DoExecute( SfxRequest& rReq )
67
0
{
68
0
    const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
69
0
    if (rMarkList.GetMarkCount() == 0)
70
0
        return;
71
72
0
    const SfxItemSet* pArgs = rReq.GetArgs();
73
74
0
    if (pArgs)
75
0
    {
76
        // If this comes from LOK, that means the shape is moved by mouse
77
        // only then pArgs is pre-set.
78
0
        setUndo(mpView, pArgs, comphelper::LibreOfficeKit::isActive());
79
0
        return;
80
0
    }
81
82
    // --------- itemset for size and position --------
83
0
    SfxItemSet aSet( mpView->GetGeoAttrFromMarked() );
84
0
    VclPtr<SfxAbstractTabDialog> pDlg;
85
86
0
    bool bWelded = false;
87
0
    SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
88
0
    if( rMarkList.GetMarkCount() == 1 &&
89
0
        pObj->GetObjInventor() == SdrInventor::Default &&
90
0
        pObj->GetObjIdentifier() == SdrObjKind::Caption )
91
0
    {
92
        // --------- itemset for caption --------
93
0
        SfxItemSet aNewAttr( mrDoc.GetPool() );
94
0
        mpView->GetAttributes( aNewAttr );
95
96
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
97
0
        pDlg.reset(pFact->CreateCaptionDialog(mrViewShell.GetFrameWeld(), mpView));
98
99
0
        const WhichRangesContainer aRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
100
0
        SfxItemSet aCombSet( *aNewAttr.GetPool(), aRange );
101
0
        aCombSet.Put( aNewAttr );
102
0
        aCombSet.Put( aSet );
103
0
        pDlg->SetInputSet( &aCombSet );
104
0
    }
105
0
    else
106
0
    {
107
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
108
0
        pDlg.reset(pFact->CreateSvxTransformTabDialog(mrViewShell.GetFrameWeld(), &aSet, mpView));
109
0
        bWelded = true;
110
0
    }
111
112
0
    assert(pDlg && "there must be a dialog at this point");
113
114
0
    auto xRequest = std::make_shared<SfxRequest>(rReq);
115
0
    rReq.Ignore(); // the 'old' request is not relevant any more
116
117
0
    pDlg->StartExecuteAsync([bWelded, pDlg, xRequest=std::move(xRequest), this](sal_Int32 nResult){
118
0
        if (nResult == RET_OK)
119
0
        {
120
0
            xRequest->Done(*(pDlg->GetOutputItemSet()));
121
            // Page margin is already calculated at this point.
122
0
            setUndo(mpView, xRequest->GetArgs(), false);
123
0
        }
124
125
        // deferred until the dialog ends
126
0
        mrViewShell.Invalidate(SID_RULER_OBJECT);
127
0
        mrViewShell.Cancel();
128
0
        if (bWelded)
129
0
            pDlg->disposeOnce();
130
0
    });
131
0
}
132
133
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */