tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / app / client.cxx
blob5c44bc077e8329982d20c73c39172680a943a1e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/embed/XEmbeddedObject.hpp>
22 #include <toolkit/helper/vclunohelper.hxx>
23 #include <comphelper/diagnose_ex.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <svx/svditer.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdpage.hxx>
29 #include <svx/svdoole2.hxx>
31 #include <client.hxx>
32 #include <tabvwsh.hxx>
33 #include <docsh.hxx>
34 #include <gridwin.hxx>
36 using namespace com::sun::star;
38 ScClient::ScClient( ScTabViewShell* pViewShell, vcl::Window* pDraw, SdrModel* pSdrModel, const SdrOle2Obj* pObj ) :
39 SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
40 pModel( pSdrModel )
42 SetObject( pObj->GetObjRef() );
45 ScClient::~ScClient()
49 SdrOle2Obj* ScClient::GetDrawObj()
51 uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
52 SdrOle2Obj* pOle2Obj = nullptr;
53 OUString aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
55 sal_uInt16 nPages = pModel->GetPageCount();
56 for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
58 SdrPage* pPage = pModel->GetPage(nPNr);
59 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
60 SdrObject* pObject = aIter.Next();
61 while (pObject && !pOle2Obj)
63 if ( pObject->GetObjIdentifier() == SdrObjKind::OLE2 )
65 // name from InfoObject is PersistName
66 if ( static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == aName )
67 pOle2Obj = static_cast<SdrOle2Obj*>(pObject);
69 pObject = aIter.Next();
72 return pOle2Obj;
75 void ScClient::RequestNewObjectArea( tools::Rectangle& aLogicRect )
77 SfxViewShell* pSfxViewSh = GetViewShell();
78 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
79 if (!pViewSh)
81 OSL_FAIL("Wrong ViewShell");
82 return;
85 tools::Rectangle aOldRect = GetObjArea();
86 SdrOle2Obj* pDrawObj = GetDrawObj();
87 if ( pDrawObj )
89 if ( pDrawObj->IsResizeProtect() )
90 aLogicRect.SetSize( aOldRect.GetSize() );
92 if ( pDrawObj->IsMoveProtect() )
93 aLogicRect.SetPos( aOldRect.TopLeft() );
96 sal_uInt16 nTab = pViewSh->GetViewData().GetTabNo();
97 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
98 if ( !(pPage && aLogicRect != aOldRect) )
99 return;
101 Point aPos;
102 Size aSize = pPage->GetSize();
103 if ( aSize.Width() < 0 )
105 aPos.setX( aSize.Width() + 1 ); // negative
106 aSize.setWidth( -aSize.Width() ); // positive
108 tools::Rectangle aPageRect( aPos, aSize );
110 if (aLogicRect.Right() > aPageRect.Right())
112 tools::Long nDiff = aLogicRect.Right() - aPageRect.Right();
113 aLogicRect.AdjustLeft( -nDiff );
114 aLogicRect.AdjustRight( -nDiff );
116 if (aLogicRect.Bottom() > aPageRect.Bottom())
118 tools::Long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
119 aLogicRect.AdjustTop( -nDiff );
120 aLogicRect.AdjustBottom( -nDiff );
123 if (aLogicRect.Left() < aPageRect.Left())
125 tools::Long nDiff = aLogicRect.Left() - aPageRect.Left();
126 aLogicRect.AdjustRight( -nDiff );
127 aLogicRect.AdjustLeft( -nDiff );
129 if (aLogicRect.Top() < aPageRect.Top())
131 tools::Long nDiff = aLogicRect.Top() - aPageRect.Top();
132 aLogicRect.AdjustBottom( -nDiff );
133 aLogicRect.AdjustTop( -nDiff );
137 void ScClient::ObjectAreaChanged()
139 SfxViewShell* pSfxViewSh = GetViewShell();
140 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
141 if (!pViewSh)
143 OSL_FAIL("Wrong ViewShell");
144 return;
147 // Take over position and size into document
148 SdrOle2Obj* pDrawObj = GetDrawObj();
149 if (!pDrawObj)
150 return;
152 tools::Rectangle aNewRectangle(GetScaledObjArea());
154 // #i118524# if sheared/rotated, center to non-rotated LogicRect
155 pDrawObj->setSuppressSetVisAreaSize(true);
157 if(pDrawObj->GetGeoStat().m_nRotationAngle || pDrawObj->GetGeoStat().m_nShearAngle)
159 pDrawObj->SetLogicRect( aNewRectangle );
161 const tools::Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
162 const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
164 aNewRectangle.Move(aDelta.X(), aDelta.Y());
167 pDrawObj->SetLogicRect( aNewRectangle );
168 pDrawObj->setSuppressSetVisAreaSize(false);
170 // set document modified (SdrModel::SetChanged is not used)
171 pViewSh->GetViewData().GetDocShell()->SetDrawModified();
172 pViewSh->ScrollToObject(pDrawObj);
175 void ScClient::ViewChanged()
177 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
179 // the iconified object seems not to need such a scaling handling
180 // since the replacement image and the size a completely controlled by the container
181 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
183 return;
186 uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
187 if (!xObj.is())
188 return;
190 // TODO/LEAN: working with Visual Area can switch object to running state
191 awt::Size aSz;
192 try {
193 aSz = xObj->getVisualAreaSize( GetAspect() );
194 } catch (const uno::Exception&) {
195 TOOLS_WARN_EXCEPTION("sc", "The visual area size must be available!");
196 return; // leave it unchanged on failure
199 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
200 Size aVisSize = OutputDevice::LogicToLogic(Size(aSz.Width, aSz.Height), MapMode(aMapUnit), MapMode(MapUnit::Map100thMM));
202 // Take over position and size into document
203 SdrOle2Obj* pDrawObj = GetDrawObj();
204 if (!pDrawObj)
205 return;
207 if (!IsObjectInPlaceActive())
209 pDrawObj->ActionChanged();
210 return;
213 tools::Rectangle aLogicRect = pDrawObj->GetLogicRect();
214 Fraction aFractX = GetScaleWidth() * aVisSize.Width();
215 Fraction aFractY = GetScaleHeight() * aVisSize.Height();
216 aVisSize = Size( static_cast<tools::Long>(aFractX), static_cast<tools::Long>(aFractY) ); // Scaled for Draw model
218 // pClientData->SetObjArea before pDrawObj->SetLogicRect, so that we don't
219 // calculate wrong scalings:
220 //Rectangle aObjArea = aLogicRect;
221 //aObjArea.SetSize( aVisSize ); // Document size from the server
222 //SetObjArea( aObjArea );
224 SfxViewShell* pSfxViewSh = GetViewShell();
225 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
226 if ( pViewSh )
228 vcl::Window* pWin = pViewSh->GetActiveWin();
229 if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
231 aLogicRect.SetSize( aVisSize );
232 pDrawObj->SetLogicRect( aLogicRect );
234 // set document modified (SdrModel::SetChanged is not used)
235 pViewSh->GetViewData().GetDocShell()->SetDrawModified();
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */