Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/uiview/swcli.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 <com/sun/star/embed/NoVisualAreaSizeException.hpp>
21
#include <com/sun/star/embed/XEmbeddedObject.hpp>
22
#include <wrtsh.hxx>
23
#include <doc.hxx>
24
#include <IDocumentSettingAccess.hxx>
25
#include <view.hxx>
26
#include <edtwin.hxx>
27
#include <swcli.hxx>
28
#include <svtools/embedhlp.hxx>
29
#include <osl/diagnose.h>
30
31
#include <toolkit/helper/vclunohelper.hxx>
32
33
#include <ndole.hxx>
34
35
using namespace com::sun::star;
36
37
SwOleClient::SwOleClient(SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj)
38
0
    : SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() )
39
0
    , m_IsInDoVerb(false)
40
0
    , m_IsOldCheckForOLEInCaption(pView->GetWrtShell().IsCheckForOLEInCaption())
41
0
{
42
0
    SetObject( xObj.GetObject() );
43
0
}
44
45
void SwOleClient::RequestNewObjectArea( tools::Rectangle& aLogRect )
46
0
{
47
    // The server wants to change the client size.
48
    // We put the desired size in the core. The attributes of the frame
49
    // are set to the desired value. This value will be passed on to the
50
    // InPlaceClient.
51
    // The core accepts or formats the adjusted values not necessarily.
52
    // If the Ole-Frame is formatted, then the CalcAndSetScale() of the WrtShell
53
    // will be called. There the scaling of the SwOleClient is set if necessary.
54
55
0
    SwWrtShell &rSh  = static_cast<SwView*>(GetViewShell())->GetWrtShell();
56
57
0
    rSh.StartAllAction();
58
59
    // the aLogRect will get the preliminary size now
60
0
    aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
61
62
    // the EndAllAction() call will trigger CalcAndSetScale() call,
63
    // so the embedded object must get the correct size before
64
0
    if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
65
0
    {
66
        // size has changed, so first change visual area of the object before we resize its view
67
        // without this the object always would be scaled - now it has the choice
68
69
        // TODO/LEAN: getMapUnit can switch object to running state
70
0
        MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
71
0
        MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
72
73
0
        Size aNewObjSize( tools::Long( aLogRect.GetWidth() / GetScaleWidth() ),
74
0
                          tools::Long( aLogRect.GetHeight() / GetScaleHeight() ) );
75
76
        // convert to logical coordinates of the embedded object
77
0
        Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
78
0
        GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
79
0
    }
80
81
0
    rSh.EndAllAction();
82
83
0
    SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded,     nullptr, GetObject() )),
84
0
           aPrt( rSh.GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, GetObject() ));
85
0
    aLogRect.SetPos( aPrt.Pos() + aFrame.Pos() );
86
0
    aLogRect.SetSize( aPrt.SSize() );
87
0
}
88
89
void SwOleClient::ObjectAreaChanged()
90
0
{
91
0
    SwWrtShell &rSh  = static_cast<SwView*>(GetViewShell())->GetWrtShell();
92
0
    SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded,     nullptr, GetObject() ));
93
0
    if ( !aFrame.Overlaps( rSh.VisArea() ) )
94
0
        rSh.MakeVisible( aFrame );
95
0
}
96
97
void SwOleClient::ViewChanged()
98
0
{
99
0
    if (m_IsInDoVerb)
100
0
        return;
101
102
0
    if ( GetAspect() == embed::Aspects::MSOLE_ICON )
103
0
    {
104
        // the iconified object seems not to need such a scaling handling
105
        // since the replacement image and the size a completely controlled by the container
106
        // TODO/LATER: when the icon exchange is implemented the scaling handling
107
        //             might be required again here
108
0
        return;
109
0
    }
110
111
0
    SwWrtShell &rSh  = static_cast<SwView*>(GetViewShell())->GetWrtShell();
112
113
    // Adjust the size of the object in the core. The Scaling must
114
    // be considered. Repercussions on the object are considered by
115
    // CalcAndSetScale() of the WrtShell if the size / position of
116
    // the frame in the core changes.
117
118
    // TODO/LEAN: getMapUnit can switch object to running state
119
0
    awt::Size aSz;
120
0
    try
121
0
    {
122
0
        aSz = GetObject()->getVisualAreaSize( GetAspect() );
123
0
    }
124
0
    catch (const embed::NoVisualAreaSizeException&)
125
0
    {
126
        // Nothing will be done
127
0
    }
128
0
    catch (const uno::Exception&)
129
0
    {
130
0
        OSL_FAIL( "Something goes wrong on requesting object size!" );
131
0
    }
132
133
0
    Size aVisSize( aSz.Width, aSz.Height );
134
135
    // As long as from the object comes no reasonable size
136
    // nothing can be scaled.
137
0
    if( !aVisSize.Width() || !aVisSize.Height() )
138
0
        return;
139
140
    // first convert to TWIPS before scaling, because scaling factors are calculated for
141
    // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
142
    // coordinates
143
0
    const MapMode aMyMap ( MapUnit::MapTwip );
144
0
    const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
145
0
    aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
146
147
0
    aVisSize.setWidth( tools::Long(aVisSize.Width() * GetScaleWidth()) );
148
0
    aVisSize.setHeight( tools::Long(aVisSize.Height() * GetScaleHeight()) );
149
150
0
    SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
151
0
    rSh.LockView( true );   // Prevent scrolling in the EndAction
152
0
    rSh.StartAllAction();
153
0
    rSh.RequestObjectResize( aRect, GetObject() );
154
0
    rSh.EndAllAction();
155
0
    rSh.LockView( false );
156
0
}
157
158
void SwOleClient::FormatChanged()
159
0
{
160
0
    const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
161
0
    SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
162
0
    if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
163
0
    {
164
0
        SwWrtShell & rWrtSh = pView->GetWrtShell();
165
0
        if (rWrtSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ))
166
0
            rWrtSh.AlignFormulaToBaseline( xObj );
167
0
    }
168
0
}
169
170
bool SwOleClient::IsProtected() const
171
0
{
172
0
    auto pView = dynamic_cast<SwView*>(GetViewShell());
173
0
    if (!pView)
174
0
    {
175
0
        return false;
176
0
    }
177
178
0
    SwWrtShell& rWrtSh = pView->GetWrtShell();
179
0
    if (rWrtSh.IsTableMode())
180
0
    {
181
0
        return false;
182
0
    }
183
184
0
    SwOLENode* pOLENode = rWrtSh.GetCursor()->GetPointNode().GetOLENode();
185
0
    if (!pOLENode)
186
0
    {
187
0
        return false;
188
0
    }
189
190
0
    return pOLENode->GetOLEObj().IsProtected();
191
0
}
192
193
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */