1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "DrawViewWrapper.hxx"
30 #include "chartview/DrawModelWrapper.hxx"
31 #include "ConfigurationAccess.hxx"
34 #include <unotools/lingucfg.hxx>
35 #include <editeng/langitem.hxx>
36 // header for class SdrPage
37 #include <svx/svdpage.hxx>
38 //header for class SdrPageView
39 #include <svx/svdpagv.hxx>
40 // header for class SdrModel
41 #include <svx/svdmodel.hxx>
42 // header for class E3dScene
43 #include <svx/scene3d.hxx>
44 #include <svx/svdetc.hxx>
45 #include <svx/svdoutl.hxx>
47 // header for class SvxForbiddenCharactersTable
48 #include <editeng/forbiddencharacterstable.hxx>
50 #include <svx/svxids.hrc>
52 // header for class SvxShape
53 #include <svx/unoshape.hxx>
54 #include <editeng/fhgtitem.hxx>
56 #include <com/sun/star/container/XChild.hpp>
57 #include <com/sun/star/lang/XUnoTunnel.hpp>
59 #include <sfx2/objsh.hxx>
60 #include <svx/helperhittest3d.hxx>
62 using namespace ::com::sun::star
;
64 //.............................................................................
67 //.............................................................................
71 short lcl_getHitTolerance( OutputDevice
* pOutDev
)
73 const short HITPIX
=2; //hit-tolerance in pixel
74 short nHitTolerance
= 50;
76 nHitTolerance
= static_cast<short>(pOutDev
->PixelToLogic(Size(HITPIX
,0)).Width());
80 // this code is copied from sfx2/source/doc/objembed.cxx
81 SfxObjectShell
* lcl_GetParentObjectShell( const uno::Reference
< frame::XModel
> & xModel
)
83 SfxObjectShell
* pResult
= NULL
;
87 uno::Reference
< container::XChild
> xChildModel( xModel
, uno::UNO_QUERY
);
88 if ( xChildModel
.is() )
90 uno::Reference
< lang::XUnoTunnel
> xParentTunnel( xChildModel
->getParent(), uno::UNO_QUERY
);
91 if ( xParentTunnel
.is() )
93 SvGlobalName
aSfxIdent( SFX_GLOBAL_CLASSID
);
94 pResult
= reinterpret_cast< SfxObjectShell
* >(
95 xParentTunnel
->getSomething( uno::Sequence
< sal_Int8
>( aSfxIdent
.GetByteSequence() ) ) );
99 catch( const uno::Exception
& )
101 // TODO: error handling
107 // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
108 // get the reference device (e.g. printer) fromthe parent document
109 OutputDevice
* lcl_GetParentRefDevice( const uno::Reference
< frame::XModel
> & xModel
)
111 SfxObjectShell
* pParent
= lcl_GetParentObjectShell( xModel
);
113 return pParent
->GetDocumentRefDev();
119 DrawViewWrapper::DrawViewWrapper( SdrModel
* pSdrModel
, OutputDevice
* pOut
, bool bPaintPageForEditMode
)
120 : E3dView(pSdrModel
, pOut
)
121 , m_pMarkHandleProvider(NULL
)
122 , m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT
, pSdrModel
) )
123 , m_bRestoreMapMode( false )
125 SetBufferedOutputAllowed(true);
126 SetBufferedOverlayAllowed(true);
128 SetPagePaintingAllowed(bPaintPageForEditMode
);
130 // #i12587# support for shapes in chart
131 SdrOutliner
* pOutliner
= getOutliner();
132 SfxItemPool
* pOutlinerPool
= ( pOutliner
? pOutliner
->GetEditTextObjectPool() : NULL
);
135 SvtLinguConfig aLinguConfig
;
136 SvtLinguOptions aLinguOptions
;
137 if ( aLinguConfig
.GetOptions( aLinguOptions
) )
139 pOutlinerPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
140 pOutlinerPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
141 pOutlinerPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions
.nDefaultLanguage_CTL
, EE_CHAR_LANGUAGE_CTL
) );
144 // set font height without changing SdrEngineDefaults
145 pOutlinerPool
->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT
) ); // 12pt
151 void DrawViewWrapper::ReInit()
153 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
154 Size
aOutputSize(100,100);
156 aOutputSize
= pOutDev
->GetOutputSize();
158 bPageVisible
= false;
159 bPageBorderVisible
= false;
160 bBordVisible
= false;
161 bGridVisible
= false;
162 bHlplVisible
= false;
164 this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
166 //a correct work area is at least necessary for correct values in the position and size dialog
167 Rectangle
aRect(Point(0,0), aOutputSize
);
168 this->SetWorkArea(aRect
);
170 this->ShowSdrPage(this->GetModel()->GetPage(0));
173 DrawViewWrapper::~DrawViewWrapper()
175 aComeBackTimer
.Stop();//@todo this should be done in destructor of base class
176 UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
179 SdrPageView
* DrawViewWrapper::GetPageView() const
181 SdrPageView
* pSdrPageView
= this->GetSdrPageView();
185 void DrawViewWrapper::SetMarkHandles()
187 if( m_pMarkHandleProvider
&& m_pMarkHandleProvider
->getMarkHandles( aHdl
) )
190 SdrView::SetMarkHandles();
193 SdrObject
* DrawViewWrapper::getHitObject( const Point
& rPnt
) const
195 SdrObject
* pRet
= NULL
;
196 sal_uLong nOptions
= SDRSEARCH_DEEP
| SDRSEARCH_TESTMARKABLE
;
198 SdrPageView
* pSdrPageView
= this->GetPageView();
199 this->SdrView::PickObj(rPnt
, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet
, pSdrPageView
, nOptions
);
203 //ignore some special shapes
204 rtl::OUString aShapeName
= pRet
->GetName();
205 if( aShapeName
.match(C2U("PlotAreaIncludingAxes")) || aShapeName
.match(C2U("PlotAreaExcludingAxes")) )
207 pRet
->SetMarkProtect( true );
208 return getHitObject( rPnt
);
211 //3d objects need a special treatment
212 //because the simple PickObj method is not accurate in this case for performance reasons
213 E3dObject
* pE3d
= dynamic_cast< E3dObject
* >(pRet
);
216 E3dScene
* pScene
= pE3d
->GetScene();
219 // prepare result vector and call helper
220 ::std::vector
< const E3dCompoundObject
* > aHitList
;
221 const basegfx::B2DPoint
aHitPoint(rPnt
.X(), rPnt
.Y());
222 getAllHit3DObjectsSortedFrontToBack(aHitPoint
, *pScene
, aHitList
);
224 if(!aHitList
.empty())
226 // choose the frontmost hit 3D object of the scene
227 pRet
= const_cast< E3dCompoundObject
* >(aHitList
[0]);
235 void DrawViewWrapper::MarkObject( SdrObject
* pObj
)
237 bool bFrameDragSingles
= true;//true == green == surrounding handles
239 pObj
->SetMarkProtect(false);
240 if( m_pMarkHandleProvider
)
241 bFrameDragSingles
= m_pMarkHandleProvider
->getFrameDragSingles();
243 this->SetFrameDragSingles(bFrameDragSingles
);//decide whether each single object should get handles
244 this->SdrView::MarkObj( pObj
, this->GetPageView() );
245 this->showMarkHandles();
249 void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider
* pMarkHandleProvider
)
251 m_pMarkHandleProvider
= pMarkHandleProvider
;
254 void DrawViewWrapper::CompleteRedraw(OutputDevice
* pOut
, const Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* /* pRedirector */)
256 svtools::ColorConfig aColorConfig
;
257 Color aFillColor
= Color( aColorConfig
.GetColorValue( svtools::DOCCOLOR
).nColor
);
258 this->SetApplicationBackgroundColor(aFillColor
);
259 this->E3dView::CompleteRedraw( pOut
, rReg
);
262 SdrObject
* DrawViewWrapper::getSelectedObject() const
264 SdrObject
* pObj(NULL
);
265 const SdrMarkList
& rMarkList
= this->GetMarkedObjectList();
266 if(rMarkList
.GetMarkCount() == 1)
268 SdrMark
* pMark
= rMarkList
.GetMark(0);
269 pObj
= pMark
->GetMarkedSdrObj();
274 SdrObject
* DrawViewWrapper::getTextEditObject() const
276 SdrObject
* pObj
= this->getSelectedObject();
277 SdrObject
* pTextObj
= NULL
;
278 if( pObj
&& pObj
->HasTextEdit())
279 pTextObj
= (SdrTextObj
*)pObj
;
283 void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference
< frame::XModel
> & xChartModel
)
285 OutputDevice
* pParentRefDev( lcl_GetParentRefDevice( xChartModel
));
286 SdrOutliner
* pOutliner( getOutliner());
287 if( pParentRefDev
&& pOutliner
)
289 pOutliner
->SetRefDevice( pParentRefDev
);
293 SdrOutliner
* DrawViewWrapper::getOutliner() const
295 return m_apOutliner
.get();
298 SfxItemSet
DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
300 SfxItemSet
aFullSet( GetModel()->GetItemPool(),
301 SID_ATTR_TRANSFORM_POS_X
,SID_ATTR_TRANSFORM_ANGLE
,
302 SID_ATTR_TRANSFORM_PROTECT_POS
,SID_ATTR_TRANSFORM_AUTOHEIGHT
,
303 SDRATTR_ECKENRADIUS
,SDRATTR_ECKENRADIUS
,
304 SID_ATTR_METRIC
,SID_ATTR_METRIC
,
306 SfxItemSet
aGeoSet( E3dView::GetGeoAttrFromMarked() );
307 aFullSet
.Put( aGeoSet
);
308 aFullSet
.Put( SfxUInt16Item(SID_ATTR_METRIC
,static_cast< sal_uInt16
>( ConfigurationAccess::getFieldUnit())));
312 SdrObject
* DrawViewWrapper::getNamedSdrObject( const rtl::OUString
& rName
) const
316 SdrPageView
* pSdrPageView
= this->GetPageView();
319 return DrawModelWrapper::getNamedSdrObject( rName
, pSdrPageView
->GetObjList() );
324 bool DrawViewWrapper::IsObjectHit( SdrObject
* pObj
, const Point
& rPnt
) const
328 Rectangle
aRect(pObj
->GetCurrentBoundRect());
329 return aRect
.IsInside(rPnt
);
334 void DrawViewWrapper::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
336 //prevent wrong reselection of objects
337 SdrModel
* pSdrModel( this->GetModel() );
338 if( pSdrModel
&& pSdrModel
->isLocked() )
341 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
343 //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
344 SdrPageView
* pSdrPageView
= this->GetPageView();
345 if( pSdrHint
&& pSdrPageView
)
347 if( pSdrPageView
->GetPage() != pSdrHint
->GetPage() )
351 E3dView::Notify(rBC
, rHint
);
355 SdrHintKind eKind
= pSdrHint
->GetKind();
356 if( eKind
== HINT_BEGEDIT
)
358 // #i79965# remember map mode
359 OSL_ASSERT( ! m_bRestoreMapMode
);
360 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
363 m_aMapModeToRestore
= pOutDev
->GetMapMode();
364 m_bRestoreMapMode
= true;
367 else if( eKind
== HINT_ENDEDIT
)
369 // #i79965# scroll back view when ending text edit
370 OSL_ASSERT( m_bRestoreMapMode
);
371 if( m_bRestoreMapMode
)
373 OutputDevice
* pOutDev
= this->GetFirstOutputDevice();
376 pOutDev
->SetMapMode( m_aMapModeToRestore
);
377 m_bRestoreMapMode
= false;
384 SdrObject
* DrawViewWrapper::getSdrObject( const uno::Reference
<
385 drawing::XShape
>& xShape
)
388 uno::Reference
< lang::XUnoTunnel
> xUnoTunnel( xShape
, uno::UNO_QUERY
);
389 uno::Reference
< lang::XTypeProvider
> xTypeProvider( xShape
, uno::UNO_QUERY
);
390 if(xUnoTunnel
.is()&&xTypeProvider
.is())
392 SvxShape
* pSvxShape
= reinterpret_cast<SvxShape
*>(xUnoTunnel
->getSomething( SvxShape::getUnoTunnelId() ));
394 pRet
= pSvxShape
->GetSdrObject();
399 //.............................................................................
401 //.............................................................................
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */