merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / drawinglayer / DrawViewWrapper.cxx
blob48c96a715c5fc1927578d6cf957476e2e6c70620
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "DrawViewWrapper.hxx"
31 #include "chartview/DrawModelWrapper.hxx"
32 #include "ConfigurationAccess.hxx"
33 #include "macros.hxx"
35 #include <unotools/lingucfg.hxx>
36 #include <editeng/langitem.hxx>
37 // header for class SdrPage
38 #include <svx/svdpage.hxx>
39 //header for class SdrPageView
40 #include <svx/svdpagv.hxx>
41 // header for class SdrModel
42 #include <svx/svdmodel.hxx>
43 // header for class E3dScene
44 #include <svx/scene3d.hxx>
45 #include <svx/svdetc.hxx>
46 #include <svx/svdoutl.hxx>
48 // header for class SvxForbiddenCharactersTable
49 #include <editeng/forbiddencharacterstable.hxx>
51 #ifndef _SVX_SVXIDS_HRC
52 #include <svx/svxids.hrc>
53 #endif
55 // header for class SvxShape
56 #include <svx/unoshape.hxx>
57 #include <editeng/fhgtitem.hxx>
59 #include <com/sun/star/container/XChild.hpp>
60 #include <com/sun/star/lang/XUnoTunnel.hpp>
62 #include <sfx2/objsh.hxx>
63 #include <svx/helperhittest3d.hxx>
65 using namespace ::com::sun::star;
67 //.............................................................................
68 namespace chart
70 //.............................................................................
72 namespace
74 short lcl_getHitTolerance( OutputDevice* pOutDev )
76 const short HITPIX=2; //hit-tolerance in pixel
77 short nHitTolerance = 50;
78 if(pOutDev)
79 nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
80 return nHitTolerance;
83 // this code is copied from sfx2/source/doc/objembed.cxx
84 SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
86 SfxObjectShell* pResult = NULL;
88 try
90 uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
91 if ( xChildModel.is() )
93 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
94 if ( xParentTunnel.is() )
96 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
97 pResult = reinterpret_cast< SfxObjectShell * >(
98 xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
102 catch( uno::Exception& )
104 // TODO: error handling
107 return pResult;
110 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
111 // get the reference device (e.g. printer) fromthe parent document
112 OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
114 SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
115 if ( pParent )
116 return pParent->GetDocumentRefDev();
117 return NULL;
123 void lcl_initOutliner( SdrOutliner* pTargetOutliner, SdrOutliner* pSourceOutliner )
125 //just an unsuccessful try to initialize the text edit outliner correctly
126 //if( bInit )
128 pTargetOutliner->EraseVirtualDevice();
129 pTargetOutliner->SetUpdateMode(FALSE);
130 pTargetOutliner->SetEditTextObjectPool( pSourceOutliner->GetEditTextObjectPool() );
131 pTargetOutliner->SetDefTab( pSourceOutliner->GetDefTab() );
134 pTargetOutliner->SetRefDevice( pSourceOutliner->GetRefDevice() );
135 pTargetOutliner->SetForbiddenCharsTable( pSourceOutliner->GetForbiddenCharsTable() );
136 pTargetOutliner->SetAsianCompressionMode( pSourceOutliner->GetAsianCompressionMode() );
137 pTargetOutliner->SetKernAsianPunctuation( pSourceOutliner->IsKernAsianPunctuation() );
138 pTargetOutliner->SetStyleSheetPool( pSourceOutliner->GetStyleSheetPool() );
139 pTargetOutliner->SetRefMapMode( pSourceOutliner->GetRefMapMode() );
140 pTargetOutliner->SetDefaultLanguage( pSourceOutliner->GetDefaultLanguage() );
141 pTargetOutliner->SetHyphenator( pSourceOutliner->GetHyphenator() );
143 USHORT nX, nY;
144 pSourceOutliner->GetGlobalCharStretching( nX, nY );
145 pTargetOutliner->SetGlobalCharStretching( nX, nY );
147 *//*
148 if ( !GetRefDevice() )
150 MapMode aMapMode(eObjUnit, Point(0,0), aObjUnit, aObjUnit);
151 pTargetOutliner->SetRefMapMode(aMapMode);
153 *//*
157 DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut, bool bPaintPageForEditMode)
158 : E3dView(pSdrModel, pOut)
159 , m_pMarkHandleProvider(NULL)
160 , m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, pSdrModel ) )
161 , m_bRestoreMapMode( false )
163 // #114898#
164 SetBufferedOutputAllowed(true);
165 SetBufferedOverlayAllowed(true);
167 SetPagePaintingAllowed(bPaintPageForEditMode);
169 // #i12587# support for shapes in chart
170 SdrOutliner* pOutliner = getOutliner();
171 SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : NULL );
172 if ( pOutlinerPool )
174 SvtLinguConfig aLinguConfig;
175 SvtLinguOptions aLinguOptions;
176 if ( aLinguConfig.GetOptions( aLinguOptions ) )
178 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
179 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
180 pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
183 // set font height without changing SdrEngineDefaults
184 pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
187 ReInit();
190 void DrawViewWrapper::ReInit()
192 OutputDevice* pOutDev = this->GetFirstOutputDevice();
193 Size aOutputSize(100,100);
194 if(pOutDev)
195 aOutputSize = pOutDev->GetOutputSize();
197 bPageVisible = false;
198 bPageBorderVisible = false;
199 bBordVisible = false;
200 bGridVisible = false;
201 bHlplVisible = false;
203 this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
204 //this->SetResizeAtCenter(true);//for interactive resize-dragging: keep the object center fix
206 //a correct work area is at least necessary for correct values in the position and size dialog
207 Rectangle aRect(Point(0,0), aOutputSize);
208 this->SetWorkArea(aRect);
210 this->ShowSdrPage(this->GetModel()->GetPage(0));
213 DrawViewWrapper::~DrawViewWrapper()
215 aComeBackTimer.Stop();//@todo this should be done in destructor of base class
216 UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
219 SdrPageView* DrawViewWrapper::GetPageView() const
221 SdrPageView* pSdrPageView = this->GetSdrPageView();
222 return pSdrPageView;
225 //virtual
226 void DrawViewWrapper::SetMarkHandles()
228 if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( aHdl ) )
229 return;
230 else
231 SdrView::SetMarkHandles();
234 SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
236 SdrObject* pRet = NULL;
237 //ULONG nOptions =SDRSEARCH_DEEP|SDRSEARCH_PASS2BOUND|SDRSEARCH_PASS3NEAREST;
238 ULONG nOptions = SDRSEARCH_DEEP | SDRSEARCH_TESTMARKABLE;
240 SdrPageView* pSdrPageView = this->GetPageView();
241 this->SdrView::PickObj(rPnt, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet, pSdrPageView, nOptions);
243 if( pRet )
245 //ignore some special shapes
246 rtl::OUString aShapeName = pRet->GetName();
247 if( aShapeName.match(C2U("PlotAreaIncludingAxes")) || aShapeName.match(C2U("PlotAreaExcludingAxes")) )
249 pRet->SetMarkProtect( true );
250 return getHitObject( rPnt );
253 //3d objects need a special treatment
254 //because the simple PickObj method is not accurate in this case for performance reasons
255 E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
256 if( pE3d )
258 E3dScene* pScene = pE3d->GetScene();
259 if( pScene )
261 // prepare result vector and call helper
262 ::std::vector< const E3dCompoundObject* > aHitList;
263 const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
264 getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
266 if(aHitList.size())
268 // choose the frontmost hit 3D object of the scene
269 pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
274 return pRet;
277 void DrawViewWrapper::MarkObject( SdrObject* pObj )
279 bool bFrameDragSingles = true;//true == green == surrounding handles
280 if(pObj)
281 pObj->SetMarkProtect(false);
282 if( m_pMarkHandleProvider )
283 bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
285 this->SetFrameDragSingles(bFrameDragSingles);//decide wether each single object should get handles
286 this->SdrView::MarkObj( pObj, this->GetPageView() );
287 this->showMarkHandles();
291 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
293 m_pMarkHandleProvider = pMarkHandleProvider;
296 void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
298 svtools::ColorConfig aColorConfig;
299 Color aFillColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
300 this->SetApplicationBackgroundColor(aFillColor);
301 this->E3dView::CompleteRedraw( pOut, rReg );
304 SdrObject* DrawViewWrapper::getSelectedObject() const
306 SdrObject* pObj(NULL);
307 const SdrMarkList& rMarkList = this->GetMarkedObjectList();
308 if(rMarkList.GetMarkCount() == 1)
310 SdrMark* pMark = rMarkList.GetMark(0);
311 pObj = pMark->GetMarkedSdrObj();
313 return pObj;
316 SdrObject* DrawViewWrapper::getTextEditObject() const
318 SdrObject* pObj = this->getSelectedObject();
319 SdrObject* pTextObj = NULL;
320 if( pObj && pObj->HasTextEdit())
321 pTextObj = (SdrTextObj*)pObj;
322 return pTextObj;
325 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
327 OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
328 SdrOutliner * pOutliner( getOutliner());
329 if( pParentRefDev && pOutliner )
331 pOutliner->SetRefDevice( pParentRefDev );
335 SdrOutliner* DrawViewWrapper::getOutliner() const
337 // lcl_initOutliner( m_apOutliner.get(), &GetModel()->GetDrawOutliner() );
338 return m_apOutliner.get();
341 SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
343 SfxItemSet aFullSet( GetModel()->GetItemPool(),
344 SID_ATTR_TRANSFORM_POS_X,SID_ATTR_TRANSFORM_ANGLE,
345 SID_ATTR_TRANSFORM_PROTECT_POS,SID_ATTR_TRANSFORM_AUTOHEIGHT,
346 SDRATTR_ECKENRADIUS,SDRATTR_ECKENRADIUS,
347 SID_ATTR_METRIC,SID_ATTR_METRIC,
349 SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
350 aFullSet.Put( aGeoSet );
351 aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
352 return aFullSet;
355 SdrObject* DrawViewWrapper::getNamedSdrObject( const rtl::OUString& rName ) const
357 if(rName.getLength()==0)
358 return 0;
359 SdrPageView* pSdrPageView = this->GetPageView();
360 if( pSdrPageView )
362 return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
364 return 0;
367 bool DrawViewWrapper::IsObjectHit( SdrObject* pObj, const Point& rPnt ) const
369 if(pObj)
371 Rectangle aRect(pObj->GetCurrentBoundRect());
372 return aRect.IsInside(rPnt);
374 return false;
377 void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
379 //prevent wrong reselection of objects
380 SdrModel* pSdrModel( this->GetModel() );
381 if( pSdrModel && pSdrModel->isLocked() )
382 return;
384 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
386 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
387 SdrPageView* pSdrPageView = this->GetPageView();
388 if( pSdrHint && pSdrPageView )
390 if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
391 return;
394 E3dView::Notify(rBC, rHint);
396 if( pSdrHint != 0 )
398 SdrHintKind eKind = pSdrHint->GetKind();
399 if( eKind == HINT_BEGEDIT )
401 // #i79965# remember map mode
402 OSL_ASSERT( ! m_bRestoreMapMode );
403 OutputDevice* pOutDev = this->GetFirstOutputDevice();
404 if( pOutDev )
406 m_aMapModeToRestore = pOutDev->GetMapMode();
407 m_bRestoreMapMode = true;
410 else if( eKind == HINT_ENDEDIT )
412 // #i79965# scroll back view when ending text edit
413 OSL_ASSERT( m_bRestoreMapMode );
414 if( m_bRestoreMapMode )
416 OutputDevice* pOutDev = this->GetFirstOutputDevice();
417 if( pOutDev )
419 pOutDev->SetMapMode( m_aMapModeToRestore );
420 m_bRestoreMapMode = false;
427 //static
428 SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
429 drawing::XShape >& xShape )
431 SdrObject* pRet = 0;
432 uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
433 uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
434 if(xUnoTunnel.is()&&xTypeProvider.is())
436 SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
437 if(pSvxShape)
438 pRet = pSvxShape->GetSdrObject();
440 return pRet;
443 //.............................................................................
444 } //namespace chart
445 //.............................................................................