nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / controller / drawinglayer / DrawViewWrapper.cxx
blob9d448b4119fefb8cb9b53d710a2df7738bda8108
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 <editeng/fhgtitem.hxx>
37 #include <com/sun/star/frame/XModel.hpp>
39 #include <sfx2/objsh.hxx>
40 #include <svx/helperhittest3d.hxx>
42 using namespace ::com::sun::star;
44 namespace chart
47 namespace
49 short lcl_getHitTolerance( OutputDevice const * pOutDev )
51 const short HITPIX=2; //hit-tolerance in pixel
52 short nHitTolerance = 50;
53 if(pOutDev)
54 nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
55 return nHitTolerance;
58 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
59 // get the reference device (e.g. printer) from the parent document
60 OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
62 SfxObjectShell* pParent = SfxObjectShell::GetParentShell(xModel);
63 if ( pParent )
64 return pParent->GetDocumentRefDev();
65 return nullptr;
70 DrawViewWrapper::DrawViewWrapper(
71 SdrModel& rSdrModel,
72 OutputDevice* pOut)
73 : E3dView(rSdrModel, pOut)
74 ,m_pMarkHandleProvider(nullptr)
75 ,m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rSdrModel))
76 ,m_bRestoreMapMode( false )
78 SetBufferedOutputAllowed(true);
79 SetBufferedOverlayAllowed(true);
80 SetPagePaintingAllowed(true);
82 // #i12587# support for shapes in chart
83 SdrOutliner* pOutliner = getOutliner();
84 SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : nullptr );
85 if ( pOutlinerPool )
87 SvtLinguConfig aLinguConfig;
88 SvtLinguOptions aLinguOptions;
89 aLinguConfig.GetOptions( aLinguOptions );
90 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
91 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
92 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
94 // set font height without changing SdrEngineDefaults
95 pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
98 // #i121463# Use big handles by default
99 SetMarkHdlSizePixel(9);
101 ReInit();
104 void DrawViewWrapper::ReInit()
106 OutputDevice* pOutDev = GetFirstOutputDevice();
107 Size aOutputSize(100,100);
108 if(pOutDev)
109 aOutputSize = pOutDev->GetOutputSize();
111 mbPageVisible = false;
112 mbPageBorderVisible = false;
113 mbBordVisible = false;
114 mbGridVisible = false;
115 mbHlplVisible = false;
117 SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
119 //a correct work area is at least necessary for correct values in the position and size dialog
120 tools::Rectangle aRect(Point(0,0), aOutputSize);
121 SetWorkArea(aRect);
123 ShowSdrPage(GetModel()->GetPage(0));
126 DrawViewWrapper::~DrawViewWrapper()
128 maComeBackIdle.Stop();//@todo this should be done in destructor of base class
129 UnmarkAllObj();//necessary to avoid a paint call during the destructor hierarchy
132 SdrPageView* DrawViewWrapper::GetPageView() const
134 SdrPageView* pSdrPageView = GetSdrPageView();
135 return pSdrPageView;
138 void DrawViewWrapper::SetMarkHandles(SfxViewShell* pOtherShell)
140 if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( maHdlList ) )
141 return;
142 else
143 SdrView::SetMarkHandles(pOtherShell);
146 SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
148 SdrPageView* pSdrPageView = GetPageView();
149 SdrObject* pRet = SdrView::PickObj(rPnt, lcl_getHitTolerance( GetFirstOutputDevice() ), pSdrPageView,
150 SdrSearchOptions::DEEP | SdrSearchOptions::TESTMARKABLE);
152 if( pRet )
154 // ignore some special shapes
155 OUString aShapeName = pRet->GetName();
157 // return right away if it is a field button
158 if (aShapeName.startsWith("FieldButton"))
159 return pRet;
161 if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") )
163 pRet->SetMarkProtect( true );
164 return getHitObject( rPnt );
167 //3d objects need a special treatment
168 //because the simple PickObj method is not accurate in this case for performance reasons
169 E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
170 if( pE3d )
172 E3dScene* pScene(pE3d->getRootE3dSceneFromE3dObject());
174 if(nullptr != pScene)
176 // prepare result vector and call helper
177 std::vector< const E3dCompoundObject* > aHitList;
178 const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
179 getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
181 if(!aHitList.empty())
183 // choose the frontmost hit 3D object of the scene
184 pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
189 return pRet;
192 void DrawViewWrapper::MarkObject( SdrObject* pObj )
194 bool bFrameDragSingles = true;//true == green == surrounding handles
195 if(pObj)
196 pObj->SetMarkProtect(false);
197 if( m_pMarkHandleProvider )
198 bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
200 SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles
201 SdrView::MarkObj( pObj, GetPageView() );
202 showMarkHandles();
205 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
207 m_pMarkHandleProvider = pMarkHandleProvider;
210 void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
212 svtools::ColorConfig aColorConfig;
213 Color aFillColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
214 SetApplicationBackgroundColor(aFillColor);
215 E3dView::CompleteRedraw( pOut, rReg );
218 SdrObject* DrawViewWrapper::getSelectedObject() const
220 SdrObject* pObj(nullptr);
221 const SdrMarkList& rMarkList = GetMarkedObjectList();
222 if(rMarkList.GetMarkCount() == 1)
224 SdrMark* pMark = rMarkList.GetMark(0);
225 pObj = pMark->GetMarkedSdrObj();
227 return pObj;
230 SdrObject* DrawViewWrapper::getTextEditObject() const
232 SdrObject* pObj = getSelectedObject();
233 SdrObject* pTextObj = nullptr;
234 if( pObj && pObj->HasTextEdit())
235 pTextObj = pObj;
236 return pTextObj;
239 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
241 OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
242 SdrOutliner * pOutliner( getOutliner());
243 if( pParentRefDev && pOutliner )
245 pOutliner->SetRefDevice( pParentRefDev );
249 SdrOutliner* DrawViewWrapper::getOutliner() const
251 return m_apOutliner.get();
254 SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
256 SfxItemSet aFullSet(
257 GetModel()->GetItemPool(),
258 svl::Items<
259 SDRATTR_ECKENRADIUS, SDRATTR_ECKENRADIUS,
260 SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE,
261 SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT,
262 SID_ATTR_METRIC, SID_ATTR_METRIC>{});
263 SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
264 aFullSet.Put( aGeoSet );
265 aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
266 return aFullSet;
269 SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const
271 if(rName.isEmpty())
272 return nullptr;
273 SdrPageView* pSdrPageView = GetPageView();
274 if( pSdrPageView )
276 return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
278 return nullptr;
281 bool DrawViewWrapper::IsObjectHit( SdrObject const * pObj, const Point& rPnt )
283 if(pObj)
285 tools::Rectangle aRect(pObj->GetCurrentBoundRect());
286 return aRect.IsInside(rPnt);
288 return false;
291 void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
293 //prevent wrong reselection of objects
294 SdrModel* pSdrModel( GetModel() );
295 if( pSdrModel && pSdrModel->isLocked() )
296 return;
298 const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr );
300 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
301 SdrPageView* pSdrPageView = GetPageView();
302 if( pSdrHint && pSdrPageView )
304 if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
305 return;
308 E3dView::Notify(rBC, rHint);
310 if( pSdrHint == nullptr )
311 return;
313 SdrHintKind eKind = pSdrHint->GetKind();
314 if( eKind == SdrHintKind::BeginEdit )
316 // #i79965# remember map mode
317 OSL_ASSERT( ! m_bRestoreMapMode );
318 OutputDevice* pOutDev = GetFirstOutputDevice();
319 if( pOutDev )
321 m_aMapModeToRestore = pOutDev->GetMapMode();
322 m_bRestoreMapMode = true;
325 else if( eKind == SdrHintKind::EndEdit )
327 // #i79965# scroll back view when ending text edit
328 OSL_ASSERT( m_bRestoreMapMode );
329 if( m_bRestoreMapMode )
331 OutputDevice* pOutDev = GetFirstOutputDevice();
332 if( pOutDev )
334 pOutDev->SetMapMode( m_aMapModeToRestore );
335 m_bRestoreMapMode = false;
341 SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
342 drawing::XShape >& xShape )
344 SdrObject* pRet = nullptr;
345 uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
346 if(xTypeProvider.is())
348 SvxShape* pSvxShape = comphelper::getUnoTunnelImplementation<SvxShape>(xShape);
349 if(pSvxShape)
350 pRet = pSvxShape->GetSdrObject();
352 return pRet;
355 } //namespace chart
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */