Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / drawinglayer / DrawViewWrapper.cxx
blob2141c4f76bce2be826fb8286808eb3fa08006a14
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 <DrawViewWrapper.hxx>
21 #include <chartview/DrawModelWrapper.hxx>
22 #include <ConfigurationAccess.hxx>
24 #include <unotools/lingucfg.hxx>
25 #include <editeng/langitem.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/itempool.hxx>
28 #include <svx/obj3d.hxx>
29 #include <svx/svdpagv.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <svx/svdetc.hxx>
32 #include <svx/svdoutl.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/unoshape.hxx>
35 #include <tools/globname.hxx>
36 #include <editeng/fhgtitem.hxx>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <sfx2/objsh.hxx>
42 #include <svx/helperhittest3d.hxx>
44 using namespace ::com::sun::star;
46 namespace chart
49 namespace
51 short lcl_getHitTolerance( OutputDevice const * pOutDev )
53 const short HITPIX=2; //hit-tolerance in pixel
54 short nHitTolerance = 50;
55 if(pOutDev)
56 nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
57 return nHitTolerance;
60 // this code is copied from sfx2/source/doc/objembed.cxx
61 SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
63 SfxObjectShell* pResult = nullptr;
65 try
67 uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
68 if ( xChildModel.is() )
70 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
71 if ( xParentTunnel.is() )
73 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
74 pResult = reinterpret_cast< SfxObjectShell * >(
75 xParentTunnel->getSomething( aSfxIdent.GetByteSequence() ) );
79 catch( const uno::Exception& )
81 // TODO: error handling
84 return pResult;
87 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
88 // get the reference device (e.g. printer) from the parent document
89 OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
91 SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
92 if ( pParent )
93 return pParent->GetDocumentRefDev();
94 return nullptr;
99 DrawViewWrapper::DrawViewWrapper(
100 SdrModel& rSdrModel,
101 OutputDevice* pOut)
102 : E3dView(rSdrModel, pOut)
103 ,m_pMarkHandleProvider(nullptr)
104 ,m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rSdrModel))
105 ,m_bRestoreMapMode( false )
107 SetBufferedOutputAllowed(true);
108 SetBufferedOverlayAllowed(true);
109 SetPagePaintingAllowed(true);
111 // #i12587# support for shapes in chart
112 SdrOutliner* pOutliner = getOutliner();
113 SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : nullptr );
114 if ( pOutlinerPool )
116 SvtLinguConfig aLinguConfig;
117 SvtLinguOptions aLinguOptions;
118 aLinguConfig.GetOptions( aLinguOptions );
119 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
120 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
121 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
123 // set font height without changing SdrEngineDefaults
124 pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
127 // #i121463# Use big handles by default
128 SetMarkHdlSizePixel(9);
130 ReInit();
133 void DrawViewWrapper::ReInit()
135 OutputDevice* pOutDev = GetFirstOutputDevice();
136 Size aOutputSize(100,100);
137 if(pOutDev)
138 aOutputSize = pOutDev->GetOutputSize();
140 mbPageVisible = false;
141 mbPageBorderVisible = false;
142 mbBordVisible = false;
143 mbGridVisible = false;
144 mbHlplVisible = false;
146 SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
148 //a correct work area is at least necessary for correct values in the position and size dialog
149 tools::Rectangle aRect(Point(0,0), aOutputSize);
150 SetWorkArea(aRect);
152 ShowSdrPage(GetModel()->GetPage(0));
155 DrawViewWrapper::~DrawViewWrapper()
157 maComeBackIdle.Stop();//@todo this should be done in destructor of base class
158 UnmarkAllObj();//necessary to avoid a paint call during the destructor hierarchy
161 SdrPageView* DrawViewWrapper::GetPageView() const
163 SdrPageView* pSdrPageView = GetSdrPageView();
164 return pSdrPageView;
167 void DrawViewWrapper::SetMarkHandles(SfxViewShell* pOtherShell)
169 if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( maHdlList ) )
170 return;
171 else
172 SdrView::SetMarkHandles(pOtherShell);
175 SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
177 SdrPageView* pSdrPageView = GetPageView();
178 SdrObject* pRet = SdrView::PickObj(rPnt, lcl_getHitTolerance( GetFirstOutputDevice() ), pSdrPageView,
179 SdrSearchOptions::DEEP | SdrSearchOptions::TESTMARKABLE);
181 if( pRet )
183 // ignore some special shapes
184 OUString aShapeName = pRet->GetName();
186 // return right away if it is a field button
187 if (aShapeName.startsWith("FieldButton"))
188 return pRet;
190 if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") )
192 pRet->SetMarkProtect( true );
193 return getHitObject( rPnt );
196 //3d objects need a special treatment
197 //because the simple PickObj method is not accurate in this case for performance reasons
198 E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
199 if( pE3d )
201 E3dScene* pScene(pE3d->getRootE3dSceneFromE3dObject());
203 if(nullptr != pScene)
205 // prepare result vector and call helper
206 std::vector< const E3dCompoundObject* > aHitList;
207 const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
208 getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
210 if(!aHitList.empty())
212 // choose the frontmost hit 3D object of the scene
213 pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
218 return pRet;
221 void DrawViewWrapper::MarkObject( SdrObject* pObj )
223 bool bFrameDragSingles = true;//true == green == surrounding handles
224 if(pObj)
225 pObj->SetMarkProtect(false);
226 if( m_pMarkHandleProvider )
227 bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
229 SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles
230 SdrView::MarkObj( pObj, GetPageView() );
231 showMarkHandles();
234 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
236 m_pMarkHandleProvider = pMarkHandleProvider;
239 void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
241 svtools::ColorConfig aColorConfig;
242 Color aFillColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
243 SetApplicationBackgroundColor(aFillColor);
244 E3dView::CompleteRedraw( pOut, rReg );
247 SdrObject* DrawViewWrapper::getSelectedObject() const
249 SdrObject* pObj(nullptr);
250 const SdrMarkList& rMarkList = GetMarkedObjectList();
251 if(rMarkList.GetMarkCount() == 1)
253 SdrMark* pMark = rMarkList.GetMark(0);
254 pObj = pMark->GetMarkedSdrObj();
256 return pObj;
259 SdrObject* DrawViewWrapper::getTextEditObject() const
261 SdrObject* pObj = getSelectedObject();
262 SdrObject* pTextObj = nullptr;
263 if( pObj && pObj->HasTextEdit())
264 pTextObj = pObj;
265 return pTextObj;
268 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
270 OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
271 SdrOutliner * pOutliner( getOutliner());
272 if( pParentRefDev && pOutliner )
274 pOutliner->SetRefDevice( pParentRefDev );
278 SdrOutliner* DrawViewWrapper::getOutliner() const
280 return m_apOutliner.get();
283 SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
285 SfxItemSet aFullSet(
286 GetModel()->GetItemPool(),
287 svl::Items<
288 SDRATTR_ECKENRADIUS, SDRATTR_ECKENRADIUS,
289 SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE,
290 SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT,
291 SID_ATTR_METRIC, SID_ATTR_METRIC>{});
292 SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
293 aFullSet.Put( aGeoSet );
294 aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
295 return aFullSet;
298 SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const
300 if(rName.isEmpty())
301 return nullptr;
302 SdrPageView* pSdrPageView = GetPageView();
303 if( pSdrPageView )
305 return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
307 return nullptr;
310 bool DrawViewWrapper::IsObjectHit( SdrObject const * pObj, const Point& rPnt )
312 if(pObj)
314 tools::Rectangle aRect(pObj->GetCurrentBoundRect());
315 return aRect.IsInside(rPnt);
317 return false;
320 void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
322 //prevent wrong reselection of objects
323 SdrModel* pSdrModel( GetModel() );
324 if( pSdrModel && pSdrModel->isLocked() )
325 return;
327 const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr );
329 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
330 SdrPageView* pSdrPageView = GetPageView();
331 if( pSdrHint && pSdrPageView )
333 if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
334 return;
337 E3dView::Notify(rBC, rHint);
339 if( pSdrHint != nullptr )
341 SdrHintKind eKind = pSdrHint->GetKind();
342 if( eKind == SdrHintKind::BeginEdit )
344 // #i79965# remember map mode
345 OSL_ASSERT( ! m_bRestoreMapMode );
346 OutputDevice* pOutDev = GetFirstOutputDevice();
347 if( pOutDev )
349 m_aMapModeToRestore = pOutDev->GetMapMode();
350 m_bRestoreMapMode = true;
353 else if( eKind == SdrHintKind::EndEdit )
355 // #i79965# scroll back view when ending text edit
356 OSL_ASSERT( m_bRestoreMapMode );
357 if( m_bRestoreMapMode )
359 OutputDevice* pOutDev = GetFirstOutputDevice();
360 if( pOutDev )
362 pOutDev->SetMapMode( m_aMapModeToRestore );
363 m_bRestoreMapMode = false;
370 SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
371 drawing::XShape >& xShape )
373 SdrObject* pRet = nullptr;
374 uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
375 if(xTypeProvider.is())
377 SvxShape* pSvxShape = comphelper::getUnoTunnelImplementation<SvxShape>(xShape);
378 if(pSvxShape)
379 pRet = pSvxShape->GetSdrObject();
381 return pRet;
384 } //namespace chart
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */