1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
25 #include <unotools/lingucfg.hxx>
26 #include <editeng/langitem.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdpagv.hxx>
29 #include <svx/svdmodel.hxx>
30 #include <svx/scene3d.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/container/XChild.hpp>
38 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <sfx2/objsh.hxx>
41 #include <svx/helperhittest3d.hxx>
43 using namespace ::com::sun::star
;
50 short lcl_getHitTolerance( OutputDevice
* pOutDev
)
52 const short HITPIX
=2; //hit-tolerance in pixel
53 short nHitTolerance
= 50;
55 nHitTolerance
= static_cast<short>(pOutDev
->PixelToLogic(Size(HITPIX
,0)).Width());
59 // this code is copied from sfx2/source/doc/objembed.cxx
60 SfxObjectShell
* lcl_GetParentObjectShell( const uno::Reference
< frame::XModel
> & xModel
)
62 SfxObjectShell
* pResult
= NULL
;
66 uno::Reference
< container::XChild
> xChildModel( xModel
, uno::UNO_QUERY
);
67 if ( xChildModel
.is() )
69 uno::Reference
< lang::XUnoTunnel
> xParentTunnel( xChildModel
->getParent(), uno::UNO_QUERY
);
70 if ( xParentTunnel
.is() )
72 SvGlobalName
aSfxIdent( SFX_GLOBAL_CLASSID
);
73 pResult
= reinterpret_cast< SfxObjectShell
* >(
74 xParentTunnel
->getSomething( uno::Sequence
< sal_Int8
>( aSfxIdent
.GetByteSequence() ) ) );
78 catch( const uno::Exception
& )
80 // TODO: error handling
86 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
87 // get the reference device (e.g. printer) fromthe parent document
88 OutputDevice
* lcl_GetParentRefDevice( const uno::Reference
< frame::XModel
> & xModel
)
90 SfxObjectShell
* pParent
= lcl_GetParentObjectShell( xModel
);
92 return pParent
->GetDocumentRefDev();
98 DrawViewWrapper::DrawViewWrapper( SdrModel
* pSdrModel
, OutputDevice
* pOut
, bool bPaintPageForEditMode
)
99 : E3dView(pSdrModel
, pOut
)
100 , m_pMarkHandleProvider(NULL
)
101 , m_apOutliner(SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT
, *pSdrModel
))
102 , m_bRestoreMapMode( false )
104 SetBufferedOutputAllowed(true);
105 SetBufferedOverlayAllowed(true);
107 SetPagePaintingAllowed(bPaintPageForEditMode
);
109 // #i12587# support for shapes in chart
110 SdrOutliner
* pOutliner
= getOutliner();
111 SfxItemPool
* pOutlinerPool
= ( pOutliner
? pOutliner
->GetEditTextObjectPool() : NULL
);
114 SvtLinguConfig aLinguConfig
;
115 SvtLinguOptions aLinguOptions
;
116 if ( aLinguConfig
.GetOptions( aLinguOptions
) )
118 pOutlinerPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
119 pOutlinerPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
120 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);
133 void DrawViewWrapper::ReInit()
135 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
136 Size
aOutputSize(100,100);
138 aOutputSize
= pOutDev
->GetOutputSize();
140 bPageVisible
= false;
141 bPageBorderVisible
= false;
142 bBordVisible
= false;
143 bGridVisible
= false;
144 bHlplVisible
= false;
146 this->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 Rectangle
aRect(Point(0,0), aOutputSize
);
150 this->SetWorkArea(aRect
);
152 this->ShowSdrPage(this->GetModel()->GetPage(0));
155 DrawViewWrapper::~DrawViewWrapper()
157 aComeBackIdle
.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
= this->GetSdrPageView();
167 void DrawViewWrapper::SetMarkHandles()
169 if( m_pMarkHandleProvider
&& m_pMarkHandleProvider
->getMarkHandles( maHdlList
) )
172 SdrView::SetMarkHandles();
175 SdrObject
* DrawViewWrapper::getHitObject( const Point
& rPnt
) const
177 SdrObject
* pRet
= NULL
;
178 SdrSearchOptions nOptions
= SdrSearchOptions::DEEP
| SdrSearchOptions::TESTMARKABLE
;
180 SdrPageView
* pSdrPageView
= this->GetPageView();
181 this->SdrView::PickObj(rPnt
, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet
, pSdrPageView
, nOptions
);
185 //ignore some special shapes
186 OUString aShapeName
= pRet
->GetName();
187 if( aShapeName
.match("PlotAreaIncludingAxes") || aShapeName
.match("PlotAreaExcludingAxes") )
189 pRet
->SetMarkProtect( true );
190 return getHitObject( rPnt
);
193 //3d objects need a special treatment
194 //because the simple PickObj method is not accurate in this case for performance reasons
195 E3dObject
* pE3d
= dynamic_cast< E3dObject
* >(pRet
);
198 E3dScene
* pScene
= pE3d
->GetScene();
201 // prepare result vector and call helper
202 ::std::vector
< const E3dCompoundObject
* > aHitList
;
203 const basegfx::B2DPoint
aHitPoint(rPnt
.X(), rPnt
.Y());
204 getAllHit3DObjectsSortedFrontToBack(aHitPoint
, *pScene
, aHitList
);
206 if(!aHitList
.empty())
208 // choose the frontmost hit 3D object of the scene
209 pRet
= const_cast< E3dCompoundObject
* >(aHitList
[0]);
217 void DrawViewWrapper::MarkObject( SdrObject
* pObj
)
219 bool bFrameDragSingles
= true;//true == green == surrounding handles
221 pObj
->SetMarkProtect(false);
222 if( m_pMarkHandleProvider
)
223 bFrameDragSingles
= m_pMarkHandleProvider
->getFrameDragSingles();
225 this->SetFrameDragSingles(bFrameDragSingles
);//decide whether each single object should get handles
226 this->SdrView::MarkObj( pObj
, this->GetPageView() );
227 this->showMarkHandles();
230 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider
* pMarkHandleProvider
)
232 m_pMarkHandleProvider
= pMarkHandleProvider
;
235 void DrawViewWrapper::CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* /* pRedirector */)
237 svtools::ColorConfig aColorConfig
;
238 Color aFillColor
= Color( aColorConfig
.GetColorValue( svtools::DOCCOLOR
).nColor
);
239 this->SetApplicationBackgroundColor(aFillColor
);
240 this->E3dView::CompleteRedraw( pOut
, rReg
);
243 SdrObject
* DrawViewWrapper::getSelectedObject() const
245 SdrObject
* pObj(NULL
);
246 const SdrMarkList
& rMarkList
= this->GetMarkedObjectList();
247 if(rMarkList
.GetMarkCount() == 1)
249 SdrMark
* pMark
= rMarkList
.GetMark(0);
250 pObj
= pMark
->GetMarkedSdrObj();
255 SdrObject
* DrawViewWrapper::getTextEditObject() const
257 SdrObject
* pObj
= this->getSelectedObject();
258 SdrObject
* pTextObj
= NULL
;
259 if( pObj
&& pObj
->HasTextEdit())
260 pTextObj
= static_cast<SdrTextObj
*>(pObj
);
264 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference
< frame::XModel
> & xChartModel
)
266 OutputDevice
* pParentRefDev( lcl_GetParentRefDevice( xChartModel
));
267 SdrOutliner
* pOutliner( getOutliner());
268 if( pParentRefDev
&& pOutliner
)
270 pOutliner
->SetRefDevice( pParentRefDev
);
274 SdrOutliner
* DrawViewWrapper::getOutliner() const
276 return m_apOutliner
.get();
279 SfxItemSet
DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
281 SfxItemSet
aFullSet( GetModel()->GetItemPool(),
282 SID_ATTR_TRANSFORM_POS_X
, SID_ATTR_TRANSFORM_ANGLE
,
283 SID_ATTR_TRANSFORM_PROTECT_POS
, SID_ATTR_TRANSFORM_AUTOHEIGHT
,
284 SDRATTR_ECKENRADIUS
, SDRATTR_ECKENRADIUS
,
285 SID_ATTR_METRIC
, SID_ATTR_METRIC
,
287 SfxItemSet
aGeoSet( E3dView::GetGeoAttrFromMarked() );
288 aFullSet
.Put( aGeoSet
);
289 aFullSet
.Put( SfxUInt16Item(SID_ATTR_METRIC
,static_cast< sal_uInt16
>( ConfigurationAccess::getFieldUnit())));
293 SdrObject
* DrawViewWrapper::getNamedSdrObject( const OUString
& rName
) const
297 SdrPageView
* pSdrPageView
= this->GetPageView();
300 return DrawModelWrapper::getNamedSdrObject( rName
, pSdrPageView
->GetObjList() );
305 bool DrawViewWrapper::IsObjectHit( SdrObject
* pObj
, const Point
& rPnt
)
309 Rectangle
aRect(pObj
->GetCurrentBoundRect());
310 return aRect
.IsInside(rPnt
);
315 void DrawViewWrapper::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
317 //prevent wrong reselection of objects
318 SdrModel
* pSdrModel( this->GetModel() );
319 if( pSdrModel
&& pSdrModel
->isLocked() )
322 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
324 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
325 SdrPageView
* pSdrPageView
= this->GetPageView();
326 if( pSdrHint
&& pSdrPageView
)
328 if( pSdrPageView
->GetPage() != pSdrHint
->GetPage() )
332 E3dView::Notify(rBC
, rHint
);
336 SdrHintKind eKind
= pSdrHint
->GetKind();
337 if( eKind
== HINT_BEGEDIT
)
339 // #i79965# remember map mode
340 OSL_ASSERT( ! m_bRestoreMapMode
);
341 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
344 m_aMapModeToRestore
= pOutDev
->GetMapMode();
345 m_bRestoreMapMode
= true;
348 else if( eKind
== HINT_ENDEDIT
)
350 // #i79965# scroll back view when ending text edit
351 OSL_ASSERT( m_bRestoreMapMode
);
352 if( m_bRestoreMapMode
)
354 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
357 pOutDev
->SetMapMode( m_aMapModeToRestore
);
358 m_bRestoreMapMode
= false;
365 SdrObject
* DrawViewWrapper::getSdrObject( const uno::Reference
<
366 drawing::XShape
>& xShape
)
369 uno::Reference
< lang::XUnoTunnel
> xUnoTunnel( xShape
, uno::UNO_QUERY
);
370 uno::Reference
< lang::XTypeProvider
> xTypeProvider( xShape
, uno::UNO_QUERY
);
371 if(xUnoTunnel
.is()&&xTypeProvider
.is())
373 SvxShape
* pSvxShape
= reinterpret_cast<SvxShape
*>(xUnoTunnel
->getSomething( SvxShape::getUnoTunnelId() ));
375 pRet
= pSvxShape
->GetSdrObject();
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */