Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/main/ChartController_Position.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 <ChartController.hxx>
21
22
#include <DrawViewWrapper.hxx>
23
#include <PositionAndSizeHelper.hxx>
24
#include <ChartModel.hxx>
25
#include <ChartView.hxx>
26
#include "UndoGuard.hxx"
27
#include <ObjectNameProvider.hxx>
28
#include <DiagramHelper.hxx>
29
#include <CommonConverters.hxx>
30
#include <svx/ActionDescriptionProvider.hxx>
31
32
#include <svx/svxids.hrc>
33
#include <svx/rectenum.hxx>
34
#include <svl/intitem.hxx>
35
#include <svx/svxdlg.hxx>
36
#include <comphelper/diagnose_ex.hxx>
37
#include <vcl/svapp.hxx>
38
#include <memory>
39
40
namespace chart
41
{
42
using namespace ::com::sun::star;
43
44
static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
45
0
{
46
0
    tools::Long nPosX(0);
47
0
    tools::Long nPosY(0);
48
0
    tools::Long nSizX(0);
49
0
    tools::Long nSizY(0);
50
51
0
    RectPoint eRP = RectPoint::LT;
52
53
    //read position
54
0
    if (const SfxInt32Item* pPosXItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_X))
55
0
        nPosX = pPosXItem->GetValue();
56
0
    if (const SfxInt32Item* pPosYItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y))
57
0
        nPosY = pPosYItem->GetValue();
58
    //read size
59
0
    if (const SfxUInt32Item* pWidthItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH))
60
0
        nSizX = pWidthItem->GetValue();
61
0
    if (const SfxUInt32Item* pHeightItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT))
62
0
        nSizY = pHeightItem->GetValue();
63
0
    if (const SfxUInt16Item* pSizeItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_SIZE_POINT))
64
0
        eRP=static_cast<RectPoint>(pSizeItem->GetValue());
65
66
0
    switch( eRP )
67
0
    {
68
0
        case RectPoint::LT:
69
0
            break;
70
0
        case RectPoint::MT:
71
0
            nPosX += ( rOriginalSize.Width - nSizX ) / 2;
72
0
            break;
73
0
        case RectPoint::RT:
74
0
            nPosX += rOriginalSize.Width - nSizX;
75
0
            break;
76
0
        case RectPoint::LM:
77
0
            nPosY += ( rOriginalSize.Height - nSizY ) / 2;
78
0
            break;
79
0
        case RectPoint::MM:
80
0
            nPosX += ( rOriginalSize.Width  - nSizX ) / 2;
81
0
            nPosY += ( rOriginalSize.Height - nSizY ) / 2;
82
0
            break;
83
0
        case RectPoint::RM:
84
0
            nPosX += rOriginalSize.Width - nSizX;
85
0
            nPosY += ( rOriginalSize.Height - nSizY ) / 2;
86
0
            break;
87
0
        case RectPoint::LB:
88
0
            nPosY += rOriginalSize.Height - nSizY;
89
0
            break;
90
0
        case RectPoint::MB:
91
0
            nPosX += ( rOriginalSize.Width - nSizX ) / 2;
92
0
            nPosY += rOriginalSize.Height - nSizY;
93
0
            break;
94
0
        case RectPoint::RB:
95
0
            nPosX += rOriginalSize.Width - nSizX;
96
0
            nPosY += rOriginalSize.Height - nSizY;
97
0
            break;
98
0
        default:
99
0
            break;
100
0
    }
101
102
0
    rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
103
0
}
104
105
void ChartController::executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs)
106
0
{
107
0
    const OUString aCID( m_aSelection.getSelectedCID() );
108
109
0
    if( aCID.isEmpty() )
110
0
        return;
111
112
0
    ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
113
114
0
    UndoGuard aUndoGuard(
115
0
        ActionDescriptionProvider::createDescription(
116
0
            ActionDescriptionProvider::ActionType::PosSize,
117
0
            ObjectNameProvider::getName( eObjectType)),
118
0
        m_xUndoManager );
119
120
0
    try
121
0
    {
122
0
        SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
123
0
        const SfxItemSet* pOutItemSet = nullptr;
124
0
        if (!pArgs)
125
0
        {
126
            //prepare and open dialog
127
0
            SdrView* pSdrView = m_pDrawViewWrapper.get();
128
0
            bool bResizePossible = m_aSelection.isResizeableObjectSelected();
129
130
0
            SolarMutexGuard aGuard;
131
0
            SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
132
0
            ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
133
0
               GetChartFrame(), &aItemSet, pSdrView, bResizePossible));
134
135
0
            if( pDlg->Execute() == RET_OK )
136
0
            {
137
0
                pOutItemSet = pDlg->GetOutputItemSet();
138
0
                if (pOutItemSet)
139
0
                    aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
140
0
            }
141
0
        }
142
0
        else
143
0
        {
144
0
            const SfxItemPool* pPool = aItemSet.GetPool();
145
0
            if (!pPool)
146
0
                return;
147
148
0
            for (const auto& aProp: *pArgs)
149
0
            {
150
0
                sal_Int32 nValue = 0;
151
0
                aProp.Value >>= nValue;
152
0
                if (aProp.Name == "TransformPosX") {
153
0
                    aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_X, nValue));
154
0
                }
155
0
                else if (aProp.Name == "TransformPosY") {
156
0
                    aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_Y, nValue));
157
0
                }
158
0
                else if (aProp.Name == "TransformWidth") {
159
0
                    aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_WIDTH, static_cast<sal_uInt32>(nValue)));
160
0
                }
161
0
                else if (aProp.Name == "TransformHeight") {
162
0
                    aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_HEIGHT, static_cast<sal_uInt32>(nValue)));
163
0
                }
164
0
            }
165
0
        }
166
167
0
        if(pOutItemSet || pArgs)
168
0
        {
169
0
            awt::Rectangle aOldObjectRect;
170
0
            if( m_xChartView )
171
0
                aOldObjectRect = m_xChartView->getRectangleOfObject(aCID);
172
173
0
            awt::Rectangle aNewObjectRect;
174
0
            lcl_getPositionAndSizeFromItemSet( aItemSet, aNewObjectRect, ToSize(aOldObjectRect) );
175
0
            awt::Size aPageSize( getChartModel()->getPageSize() );
176
0
            awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
177
178
0
            bool bChanged = false;
179
0
            if ( eObjectType == OBJECTTYPE_LEGEND )
180
0
            {
181
0
                bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), false , true);
182
0
            }
183
184
0
            bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getChartModel()
185
0
                        , aNewObjectRect, aOldObjectRect, aPageRect );
186
0
            if( bMoved || bChanged )
187
0
                aUndoGuard.commit();
188
0
        }
189
0
    }
190
0
    catch(const uno::Exception&)
191
0
    {
192
0
        TOOLS_WARN_EXCEPTION("chart2", "" );
193
0
    }
194
0
}
195
196
} //namespace chart
197
198
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */