1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DrawViewWrapper.cxx,v $
10 * $Revision: 1.20.6.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "DrawViewWrapper.hxx"
34 #include "chartview/DrawModelWrapper.hxx"
35 #include "ConfigurationAccess.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 <svx/forbiddencharacterstable.hxx>
51 #ifndef _SVX_SVXIDS_HRC
52 #include <svx/svxids.hrc>
55 // header for class SvxShape
56 #include <svx/unoshape.hxx>
58 #include <com/sun/star/container/XChild.hpp>
59 #include <com/sun/star/lang/XUnoTunnel.hpp>
61 #include <sfx2/objsh.hxx>
62 #include <svx/helperhittest3d.hxx>
64 using namespace ::com::sun::star
;
66 //.............................................................................
69 //.............................................................................
73 short lcl_getHitTolerance( OutputDevice
* pOutDev
)
75 const short HITPIX
=2; //hit-tolerance in pixel
76 short nHitTolerance
= 50;
78 nHitTolerance
= static_cast<short>(pOutDev
->PixelToLogic(Size(HITPIX
,0)).Width());
82 // this code is copied from sfx2/source/doc/objembed.cxx
83 SfxObjectShell
* lcl_GetParentObjectShell( const uno::Reference
< frame::XModel
> & xModel
)
85 SfxObjectShell
* pResult
= NULL
;
89 uno::Reference
< container::XChild
> xChildModel( xModel
, uno::UNO_QUERY
);
90 if ( xChildModel
.is() )
92 uno::Reference
< lang::XUnoTunnel
> xParentTunnel( xChildModel
->getParent(), uno::UNO_QUERY
);
93 if ( xParentTunnel
.is() )
95 SvGlobalName
aSfxIdent( SFX_GLOBAL_CLASSID
);
96 pResult
= reinterpret_cast< SfxObjectShell
* >(
97 xParentTunnel
->getSomething( uno::Sequence
< sal_Int8
>( aSfxIdent
.GetByteSequence() ) ) );
101 catch( uno::Exception
& )
103 // TODO: error handling
109 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
110 // get the reference device (e.g. printer) fromthe parent document
111 OutputDevice
* lcl_GetParentRefDevice( const uno::Reference
< frame::XModel
> & xModel
)
113 SfxObjectShell
* pParent
= lcl_GetParentObjectShell( xModel
);
115 return pParent
->GetDocumentRefDev();
122 void lcl_initOutliner( SdrOutliner* pTargetOutliner, SdrOutliner* pSourceOutliner )
124 //just an unsuccessful try to initialize the text edit outliner correctly
127 pTargetOutliner->EraseVirtualDevice();
128 pTargetOutliner->SetUpdateMode(FALSE);
129 pTargetOutliner->SetEditTextObjectPool( pSourceOutliner->GetEditTextObjectPool() );
130 pTargetOutliner->SetDefTab( pSourceOutliner->GetDefTab() );
133 pTargetOutliner->SetRefDevice( pSourceOutliner->GetRefDevice() );
134 pTargetOutliner->SetForbiddenCharsTable( pSourceOutliner->GetForbiddenCharsTable() );
135 pTargetOutliner->SetAsianCompressionMode( pSourceOutliner->GetAsianCompressionMode() );
136 pTargetOutliner->SetKernAsianPunctuation( pSourceOutliner->IsKernAsianPunctuation() );
137 pTargetOutliner->SetStyleSheetPool( pSourceOutliner->GetStyleSheetPool() );
138 pTargetOutliner->SetRefMapMode( pSourceOutliner->GetRefMapMode() );
139 pTargetOutliner->SetDefaultLanguage( pSourceOutliner->GetDefaultLanguage() );
140 pTargetOutliner->SetHyphenator( pSourceOutliner->GetHyphenator() );
143 pSourceOutliner->GetGlobalCharStretching( nX, nY );
144 pTargetOutliner->SetGlobalCharStretching( nX, nY );
147 if ( !GetRefDevice() )
149 MapMode aMapMode(eObjUnit, Point(0,0), aObjUnit, aObjUnit);
150 pTargetOutliner->SetRefMapMode(aMapMode);
156 DrawViewWrapper::DrawViewWrapper( SdrModel
* pSdrModel
, OutputDevice
* pOut
, bool bPaintPageForEditMode
)
157 : E3dView(pSdrModel
, pOut
)
158 , m_pMarkHandleProvider(NULL
)
159 , m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT
, pSdrModel
) )
160 , m_bRestoreMapMode( false )
163 SetBufferedOutputAllowed(true);
164 SetBufferedOverlayAllowed(true);
166 SetPagePaintingAllowed(bPaintPageForEditMode
);
171 void DrawViewWrapper::ReInit()
173 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
174 Size
aOutputSize(100,100);
176 aOutputSize
= pOutDev
->GetOutputSize();
178 bPageVisible
= false;
179 bPageBorderVisible
= false;
180 bBordVisible
= false;
181 bGridVisible
= false;
182 bHlplVisible
= false;
184 this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
185 //this->SetResizeAtCenter(true);//for interactive resize-dragging: keep the object center fix
187 //a correct work area is at least necessary for correct values in the position and size dialog
188 Rectangle
aRect(Point(0,0), aOutputSize
);
189 this->SetWorkArea(aRect
);
191 this->ShowSdrPage(this->GetModel()->GetPage(0));
194 DrawViewWrapper::~DrawViewWrapper()
196 aComeBackTimer
.Stop();//@todo this should be done in destructor of base class
197 UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
200 SdrPageView
* DrawViewWrapper::GetPageView() const
202 SdrPageView
* pSdrPageView
= this->GetSdrPageView();
207 void DrawViewWrapper::SetMarkHandles()
209 if( m_pMarkHandleProvider
&& m_pMarkHandleProvider
->getMarkHandles( aHdl
) )
212 SdrView::SetMarkHandles();
215 SdrObject
* DrawViewWrapper::getHitObject( const Point
& rPnt
) const
217 SdrObject
* pRet
= NULL
;
218 //ULONG nOptions =SDRSEARCH_DEEP|SDRSEARCH_PASS2BOUND|SDRSEARCH_PASS3NEAREST;
219 ULONG nOptions
= SDRSEARCH_DEEP
| SDRSEARCH_TESTMARKABLE
;
221 SdrPageView
* pSdrPageView
= this->GetPageView();
222 this->SdrView::PickObj(rPnt
, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet
, pSdrPageView
, nOptions
);
226 //3d objects need a special treatment
227 //because the simple PickObj method is not accurate in this case for performance reasons
228 E3dObject
* pE3d
= dynamic_cast< E3dObject
* >(pRet
);
231 E3dScene
* pScene
= pE3d
->GetScene();
234 // prepare result vector and call helper
235 ::std::vector
< const E3dCompoundObject
* > aHitList
;
236 const basegfx::B2DPoint
aHitPoint(rPnt
.X(), rPnt
.Y());
237 getAllHit3DObjectsSortedFrontToBack(aHitPoint
, *pScene
, aHitList
);
241 // choose the frontmost hit 3D object of the scene
242 pRet
= const_cast< E3dCompoundObject
* >(aHitList
[0]);
250 void DrawViewWrapper::MarkObject( SdrObject
* pObj
)
252 bool bFrameDragSingles
= true;//true == green == surrounding handles
254 pObj
->SetMarkProtect(false);
255 if( m_pMarkHandleProvider
)
256 bFrameDragSingles
= m_pMarkHandleProvider
->getFrameDragSingles();
258 this->SetFrameDragSingles(bFrameDragSingles
);//decide wether each single object should get handles
259 this->SdrView::MarkObj( pObj
, this->GetPageView() );
260 this->showMarkHandles();
264 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider
* pMarkHandleProvider
)
266 m_pMarkHandleProvider
= pMarkHandleProvider
;
269 void DrawViewWrapper::CompleteRedraw(OutputDevice
* pOut
, const Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* /* pRedirector */)
271 svtools::ColorConfig aColorConfig
;
272 Color aFillColor
= Color( aColorConfig
.GetColorValue( svtools::DOCCOLOR
).nColor
);
273 this->SetApplicationBackgroundColor(aFillColor
);
274 this->E3dView::CompleteRedraw( pOut
, rReg
);
277 SdrObject
* DrawViewWrapper::getSelectedObject() const
279 SdrObject
* pObj(NULL
);
280 const SdrMarkList
& rMarkList
= this->GetMarkedObjectList();
281 if(rMarkList
.GetMarkCount() == 1)
283 SdrMark
* pMark
= rMarkList
.GetMark(0);
284 pObj
= pMark
->GetMarkedSdrObj();
289 SdrObject
* DrawViewWrapper::getTextEditObject() const
291 SdrObject
* pObj
= this->getSelectedObject();
292 SdrObject
* pTextObj
= NULL
;
293 if( pObj
&& pObj
->HasTextEdit())
294 pTextObj
= (SdrTextObj
*)pObj
;
298 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference
< frame::XModel
> & xChartModel
)
300 OutputDevice
* pParentRefDev( lcl_GetParentRefDevice( xChartModel
));
301 SdrOutliner
* pOutliner( getOutliner());
302 if( pParentRefDev
&& pOutliner
)
304 pOutliner
->SetRefDevice( pParentRefDev
);
308 SdrOutliner
* DrawViewWrapper::getOutliner() const
310 // lcl_initOutliner( m_apOutliner.get(), &GetModel()->GetDrawOutliner() );
311 return m_apOutliner
.get();
314 SfxItemSet
DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
316 SfxItemSet
aFullSet( GetModel()->GetItemPool(),
317 SID_ATTR_TRANSFORM_POS_X
,SID_ATTR_TRANSFORM_ANGLE
,
318 SID_ATTR_TRANSFORM_PROTECT_POS
,SID_ATTR_TRANSFORM_AUTOHEIGHT
,
319 SDRATTR_ECKENRADIUS
,SDRATTR_ECKENRADIUS
,
320 SID_ATTR_METRIC
,SID_ATTR_METRIC
,
322 SfxItemSet
aGeoSet( E3dView::GetGeoAttrFromMarked() );
323 aFullSet
.Put( aGeoSet
);
324 aFullSet
.Put( SfxUInt16Item(SID_ATTR_METRIC
,static_cast< sal_uInt16
>( ConfigurationAccess::getFieldUnit())));
328 SdrObject
* DrawViewWrapper::getNamedSdrObject( const rtl::OUString
& rName
) const
330 if(rName
.getLength()==0)
332 SdrPageView
* pSdrPageView
= this->GetPageView();
335 return DrawModelWrapper::getNamedSdrObject( rName
, pSdrPageView
->GetObjList() );
340 bool DrawViewWrapper::IsObjectHit( SdrObject
* pObj
, const Point
& rPnt
) const
344 Rectangle
aRect(pObj
->GetCurrentBoundRect());
345 return aRect
.IsInside(rPnt
);
350 void DrawViewWrapper::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
352 //prevent wrong reselection of objects
353 SdrModel
* pSdrModel( this->GetModel() );
354 if( pSdrModel
&& pSdrModel
->isLocked() )
357 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
359 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
360 SdrPageView
* pSdrPageView
= this->GetPageView();
361 if( pSdrHint
&& pSdrPageView
)
363 if( pSdrPageView
->GetPage() != pSdrHint
->GetPage() )
367 E3dView::Notify(rBC
, rHint
);
371 SdrHintKind eKind
= pSdrHint
->GetKind();
372 if( eKind
== HINT_BEGEDIT
)
374 // #i79965# remember map mode
375 OSL_ASSERT( ! m_bRestoreMapMode
);
376 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
379 m_aMapModeToRestore
= pOutDev
->GetMapMode();
380 m_bRestoreMapMode
= true;
383 else if( eKind
== HINT_ENDEDIT
)
385 // #i79965# scroll back view when ending text edit
386 OSL_ASSERT( m_bRestoreMapMode
);
387 if( m_bRestoreMapMode
)
389 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
392 pOutDev
->SetMapMode( m_aMapModeToRestore
);
393 m_bRestoreMapMode
= false;
401 SdrObject
* DrawViewWrapper::getSdrObject( const uno::Reference
<
402 drawing::XShape
>& xShape
)
405 uno::Reference
< lang::XUnoTunnel
> xUnoTunnel( xShape
, uno::UNO_QUERY
);
406 uno::Reference
< lang::XTypeProvider
> xTypeProvider( xShape
, uno::UNO_QUERY
);
407 if(xUnoTunnel
.is()&&xTypeProvider
.is())
409 SvxShape
* pSvxShape
= reinterpret_cast<SvxShape
*>(xUnoTunnel
->getSomething( SvxShape::getUnoTunnelId() ));
411 pRet
= pSvxShape
->GetSdrObject();
416 //.............................................................................
418 //.............................................................................