LibreOffice Module sw (master) 1
swcli.cxx
Go to the documentation of this file.
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>
25#include <view.hxx>
26#include <edtwin.hxx>
27#include <swcli.hxx>
28#include <svtools/embedhlp.hxx>
29#include <osl/diagnose.h>
30
32
33#include <ndole.hxx>
34
35using namespace com::sun::star;
36
38 : SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() )
39 , m_IsInDoVerb(false)
40 , m_IsOldCheckForOLEInCaption(pView->GetWrtShell().IsCheckForOLEInCaption())
41{
42 SetObject( xObj.GetObject() );
43}
44
46{
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 SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
56
57 rSh.StartAllAction();
58
59 // the aLogRect will get the preliminary size now
60 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 if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
65 {
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 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
71 MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
72
73 Size aNewObjSize( tools::Long( aLogRect.GetWidth() / GetScaleWidth() ),
74 tools::Long( aLogRect.GetHeight() / GetScaleHeight() ) );
75
76 // convert to logical coordinates of the embedded object
77 Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
78 GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
79 }
80
81 rSh.EndAllAction();
82
83 SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, GetObject() )),
84 aPrt( rSh.GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, GetObject() ));
85 aLogRect.SetPos( aPrt.Pos() + aFrame.Pos() );
86 aLogRect.SetSize( aPrt.SSize() );
87}
88
90{
91 SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
92 SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, GetObject() ));
93 if ( !aFrame.Overlaps( rSh.VisArea() ) )
94 rSh.MakeVisible( aFrame );
95}
96
98{
99 if (m_IsInDoVerb)
100 return;
101
102 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
103 {
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 return;
109 }
110
111 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 awt::Size aSz;
120 try
121 {
122 aSz = GetObject()->getVisualAreaSize( GetAspect() );
123 }
124 catch (const embed::NoVisualAreaSizeException&)
125 {
126 // Nothing will be done
127 }
128 catch (const uno::Exception&)
129 {
130 OSL_FAIL( "Something goes wrong on requesting object size!" );
131 }
132
133 Size aVisSize( aSz.Width, aSz.Height );
134
135 // As long as from the object comes no reasonable size
136 // nothing can be scaled.
137 if( !aVisSize.Width() || !aVisSize.Height() )
138 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 const MapMode aMyMap ( MapUnit::MapTwip );
144 const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
145 aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
146
147 aVisSize.setWidth( tools::Long(aVisSize.Width() * GetScaleWidth()) );
148 aVisSize.setHeight( tools::Long(aVisSize.Height() * GetScaleHeight()) );
149
150 SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
151 rSh.LockView( true ); // Prevent scrolling in the EndAction
152 rSh.StartAllAction();
153 rSh.RequestObjectResize( aRect, GetObject() );
154 rSh.EndAllAction();
155 rSh.LockView( false );
156}
157
159{
160 const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
161 SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
162 if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
163 {
164 SwWrtShell & rWrtSh = pView->GetWrtShell();
166 rWrtSh.AlignFormulaToBaseline( xObj );
167 }
168}
169
171{
172 auto pView = dynamic_cast<SwView*>(GetViewShell());
173 if (!pView)
174 {
175 return false;
176 }
177
178 SwWrtShell& rWrtSh = pView->GetWrtShell();
179 if (rWrtSh.IsTableMode())
180 {
181 return false;
182 }
183
184 SwOLENode* pOLENode = rWrtSh.GetCursor()->GetPointNode().GetOLENode();
185 if (!pOLENode)
186 {
187 return false;
188 }
189
190 return pOLENode->GetOLEObj().IsProtected();
191}
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
const Fraction & GetScaleHeight() const
void SetObject(const css::uno::Reference< css::embed::XEmbeddedObject > &rObject)
vcl::Window * GetEditWin() const
tools::Rectangle GetScaledObjArea() const
const Fraction & GetScaleWidth() const
SfxViewShell * GetViewShell() const
sal_Int64 GetAspect() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
static sal_uInt16 IsMath(const SvGlobalName &rName)
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
bool IsTableMode() const
Definition: crsrsh.hxx:668
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:190
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void EndAllAction()
Definition: edws.cxx:97
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
void AlignFormulaToBaseline(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj)
for starmath formulas anchored 'as char' it aligns it baseline to baseline changing the previous vert...
Definition: fefly1.cxx:2097
const SwRect & GetAnyCurRect(CurRectType eType, const Point *pPt=nullptr, const css::uno::Reference< css::embed::XEmbeddedObject > &=css::uno::Reference< css::embed::XEmbeddedObject >()) const
Definition: fews.cxx:90
Size RequestObjectResize(const SwRect &rRect, const css::uno::Reference< css::embed::XEmbeddedObject > &)
OLE.
Definition: fefly1.cxx:1318
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:165
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:116
bool IsProtected() const
Definition: ndole.cxx:984
bool IsProtected() const override
Definition: swcli.cxx:170
SwOleClient(SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef &)
Definition: swcli.cxx:37
virtual void RequestNewObjectArea(tools::Rectangle &) override
Definition: swcli.cxx:45
bool m_IsInDoVerb
Definition: swcli.hxx:32
virtual void ViewChanged() override
Definition: swcli.cxx:97
virtual void ObjectAreaChanged() override
Definition: swcli.cxx:89
virtual void FormatChanged() override
Definition: swcli.cxx:158
SwNode & GetPointNode() const
Definition: pam.hxx:275
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Pos(const Point &rNew)
Definition: swrect.hxx:171
void SSize(const Size &rNew)
Definition: swrect.hxx:180
bool Overlaps(const SwRect &rRect) const
Definition: swrect.hxx:374
const SwRect & VisArea() const
Definition: viewsh.cxx:642
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
void LockView(bool b)
Definition: viewsh.hxx:491
void MakeVisible(const SwRect &)
Definition: viewsh.cxx:649
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
constexpr tools::Long GetWidth() const
void SetSize(const Size &)
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
constexpr tools::Long GetHeight() const
Size LogicToLogic(const Size &rSzSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
@ FlyEmbeddedPrt
Rect of PrtArea of FlyFrame.
@ FlyEmbedded
Rect of current FlyFrame.
MapUnit GetMapUnit()
long Long