Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "DrawViewWrapper.hxx"
21 : : #include "chartview/DrawModelWrapper.hxx"
22 : : #include "ConfigurationAccess.hxx"
23 : : #include "macros.hxx"
24 : :
25 : : #include <unotools/lingucfg.hxx>
26 : : #include <editeng/langitem.hxx>
27 : : // header for class SdrPage
28 : : #include <svx/svdpage.hxx>
29 : : //header for class SdrPageView
30 : : #include <svx/svdpagv.hxx>
31 : : // header for class SdrModel
32 : : #include <svx/svdmodel.hxx>
33 : : // header for class E3dScene
34 : : #include <svx/scene3d.hxx>
35 : : #include <svx/svdetc.hxx>
36 : : #include <svx/svdoutl.hxx>
37 : :
38 : : // header for class SvxForbiddenCharactersTable
39 : : #include <editeng/forbiddencharacterstable.hxx>
40 : :
41 : : #include <svx/svxids.hrc>
42 : :
43 : : // header for class SvxShape
44 : : #include <svx/unoshape.hxx>
45 : : #include <editeng/fhgtitem.hxx>
46 : :
47 : : #include <com/sun/star/container/XChild.hpp>
48 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
49 : :
50 : : #include <sfx2/objsh.hxx>
51 : : #include <svx/helperhittest3d.hxx>
52 : :
53 : : using namespace ::com::sun::star;
54 : :
55 : : //.............................................................................
56 : : namespace chart
57 : : {
58 : : //.............................................................................
59 : :
60 : : namespace
61 : : {
62 : 0 : short lcl_getHitTolerance( OutputDevice* pOutDev )
63 : : {
64 : 0 : const short HITPIX=2; //hit-tolerance in pixel
65 : 0 : short nHitTolerance = 50;
66 [ # # ]: 0 : if(pOutDev)
67 [ # # ]: 0 : nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width());
68 : 0 : return nHitTolerance;
69 : : }
70 : :
71 : : // this code is copied from sfx2/source/doc/objembed.cxx
72 : 34 : SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
73 : : {
74 : 34 : SfxObjectShell* pResult = NULL;
75 : :
76 : : try
77 : : {
78 [ + - ]: 34 : uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
79 [ + - ]: 34 : if ( xChildModel.is() )
80 : : {
81 [ + - ][ + - ]: 34 : uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
[ + - ]
82 [ + + ]: 34 : if ( xParentTunnel.is() )
83 : : {
84 [ + - ]: 2 : SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
85 : : pResult = reinterpret_cast< SfxObjectShell * >(
86 [ + - ][ + - ]: 2 : xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
[ + - ][ + - ]
[ + - ]
87 : 34 : }
88 [ # # ]: 34 : }
89 : : }
90 : 0 : catch( const uno::Exception& )
91 : : {
92 : : // TODO: error handling
93 : : }
94 : :
95 : 34 : return pResult;
96 : : }
97 : :
98 : : // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
99 : : // get the reference device (e.g. printer) fromthe parent document
100 : 34 : OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
101 : : {
102 : 34 : SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
103 [ + + ]: 34 : if ( pParent )
104 : 2 : return pParent->GetDocumentRefDev();
105 : 34 : return NULL;
106 : : }
107 : :
108 : : }
109 : :
110 : 34 : DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut, bool bPaintPageForEditMode)
111 : : : E3dView(pSdrModel, pOut)
112 : : , m_pMarkHandleProvider(NULL)
113 : : , m_apOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, pSdrModel ) )
114 [ + - ][ + - ]: 34 : , m_bRestoreMapMode( false )
115 : : {
116 [ + - ]: 34 : SetBufferedOutputAllowed(true);
117 [ + - ]: 34 : SetBufferedOverlayAllowed(true);
118 : :
119 [ + - ]: 34 : SetPagePaintingAllowed(bPaintPageForEditMode);
120 : :
121 : : // #i12587# support for shapes in chart
122 : 34 : SdrOutliner* pOutliner = getOutliner();
123 [ + - ][ + - ]: 34 : SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditTextObjectPool() : NULL );
124 [ + - ]: 34 : if ( pOutlinerPool )
125 : : {
126 [ + - ]: 34 : SvtLinguConfig aLinguConfig;
127 [ + - ]: 34 : SvtLinguOptions aLinguOptions;
128 [ + - ][ + - ]: 34 : if ( aLinguConfig.GetOptions( aLinguOptions ) )
129 : : {
130 [ + - ][ + - ]: 34 : pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
[ + - ]
131 [ + - ][ + - ]: 34 : pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
[ + - ]
132 [ + - ][ + - ]: 34 : pOutlinerPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
[ + - ]
133 : : }
134 : :
135 : : // set font height without changing SdrEngineDefaults
136 [ + - ][ + - ]: 34 : pOutlinerPool->SetPoolDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt
[ + - ][ + - ]
[ + - ]
137 : : }
138 : :
139 [ + - ]: 34 : ReInit();
140 : 34 : }
141 : :
142 : 783 : void DrawViewWrapper::ReInit()
143 : : {
144 [ + - ]: 783 : OutputDevice* pOutDev = this->GetFirstOutputDevice();
145 : 783 : Size aOutputSize(100,100);
146 [ + - ]: 783 : if(pOutDev)
147 [ + - ]: 783 : aOutputSize = pOutDev->GetOutputSize();
148 : :
149 : 783 : bPageVisible = false;
150 : 783 : bPageBorderVisible = false;
151 : 783 : bBordVisible = false;
152 : 783 : bGridVisible = false;
153 : 783 : bHlplVisible = false;
154 : :
155 [ + - ]: 783 : this->SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object)
156 : :
157 : : //a correct work area is at least necessary for correct values in the position and size dialog
158 [ + - ]: 783 : Rectangle aRect(Point(0,0), aOutputSize);
159 : 783 : this->SetWorkArea(aRect);
160 : :
161 [ + - ][ + - ]: 783 : this->ShowSdrPage(this->GetModel()->GetPage(0));
162 : 783 : }
163 : :
164 [ + - ][ + - ]: 34 : DrawViewWrapper::~DrawViewWrapper()
165 : : {
166 [ + - ]: 34 : aComeBackTimer.Stop();//@todo this should be done in destructor of base class
167 [ + - ]: 34 : UnmarkAllObj();//necessary to aavoid a paint call during the destructor hierarchy
168 [ - + ]: 68 : }
169 : :
170 : 1498 : SdrPageView* DrawViewWrapper::GetPageView() const
171 : : {
172 : 1498 : SdrPageView* pSdrPageView = this->GetSdrPageView();
173 : 1498 : return pSdrPageView;
174 : : };
175 : :
176 : 1532 : void DrawViewWrapper::SetMarkHandles()
177 : : {
178 [ + + ][ - + ]: 1532 : if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( aHdl ) )
[ - + ]
179 : 1532 : return;
180 : : else
181 : 1532 : SdrView::SetMarkHandles();
182 : : }
183 : :
184 : 0 : SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const
185 : : {
186 : 0 : SdrObject* pRet = NULL;
187 : 0 : sal_uLong nOptions = SDRSEARCH_DEEP | SDRSEARCH_TESTMARKABLE;
188 : :
189 : 0 : SdrPageView* pSdrPageView = this->GetPageView();
190 [ # # ][ # # ]: 0 : this->SdrView::PickObj(rPnt, lcl_getHitTolerance( this->GetFirstOutputDevice() ), pRet, pSdrPageView, nOptions);
[ # # ]
191 : :
192 [ # # ]: 0 : if( pRet )
193 : : {
194 : : //ignore some special shapes
195 [ # # ]: 0 : rtl::OUString aShapeName = pRet->GetName();
196 [ # # ][ # # ]: 0 : if( aShapeName.match(C2U("PlotAreaIncludingAxes")) || aShapeName.match(C2U("PlotAreaExcludingAxes")) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
197 : : {
198 [ # # ]: 0 : pRet->SetMarkProtect( true );
199 [ # # ]: 0 : return getHitObject( rPnt );
200 : : }
201 : :
202 : : //3d objects need a special treatment
203 : : //because the simple PickObj method is not accurate in this case for performance reasons
204 [ # # ]: 0 : E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet);
205 [ # # ]: 0 : if( pE3d )
206 : : {
207 [ # # ]: 0 : E3dScene* pScene = pE3d->GetScene();
208 [ # # ]: 0 : if( pScene )
209 : : {
210 : : // prepare result vector and call helper
211 [ # # ]: 0 : ::std::vector< const E3dCompoundObject* > aHitList;
212 : 0 : const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y());
213 [ # # ]: 0 : getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList);
214 : :
215 [ # # ]: 0 : if(!aHitList.empty())
216 : : {
217 : : // choose the frontmost hit 3D object of the scene
218 [ # # ]: 0 : pRet = const_cast< E3dCompoundObject* >(aHitList[0]);
219 : 0 : }
220 : : }
221 [ # # ]: 0 : }
222 : : }
223 : 0 : return pRet;
224 : : }
225 : :
226 : 749 : void DrawViewWrapper::MarkObject( SdrObject* pObj )
227 : : {
228 : 749 : bool bFrameDragSingles = true;//true == green == surrounding handles
229 [ + - ]: 749 : if(pObj)
230 : 749 : pObj->SetMarkProtect(false);
231 [ + - ]: 749 : if( m_pMarkHandleProvider )
232 : 749 : bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles();
233 : :
234 : 749 : this->SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles
235 : 749 : this->SdrView::MarkObj( pObj, this->GetPageView() );
236 : 749 : this->showMarkHandles();
237 : 749 : }
238 : :
239 : :
240 : 1498 : void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider )
241 : : {
242 : 1498 : m_pMarkHandleProvider = pMarkHandleProvider;
243 : 1498 : }
244 : :
245 : 908 : void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */)
246 : : {
247 [ + - ]: 908 : svtools::ColorConfig aColorConfig;
248 [ + - ]: 908 : Color aFillColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
249 [ + - ]: 908 : this->SetApplicationBackgroundColor(aFillColor);
250 [ + - ][ + - ]: 908 : this->E3dView::CompleteRedraw( pOut, rReg );
251 : 908 : }
252 : :
253 : 0 : SdrObject* DrawViewWrapper::getSelectedObject() const
254 : : {
255 : 0 : SdrObject* pObj(NULL);
256 : 0 : const SdrMarkList& rMarkList = this->GetMarkedObjectList();
257 [ # # ]: 0 : if(rMarkList.GetMarkCount() == 1)
258 : : {
259 : 0 : SdrMark* pMark = rMarkList.GetMark(0);
260 : 0 : pObj = pMark->GetMarkedSdrObj();
261 : : }
262 : 0 : return pObj;
263 : : }
264 : :
265 : 0 : SdrObject* DrawViewWrapper::getTextEditObject() const
266 : : {
267 : 0 : SdrObject* pObj = this->getSelectedObject();
268 : 0 : SdrObject* pTextObj = NULL;
269 [ # # ][ # # ]: 0 : if( pObj && pObj->HasTextEdit())
[ # # ]
270 : 0 : pTextObj = (SdrTextObj*)pObj;
271 : 0 : return pTextObj;
272 : : }
273 : :
274 : 34 : void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
275 : : {
276 : 34 : OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
277 : 34 : SdrOutliner * pOutliner( getOutliner());
278 [ + - ][ + + ]: 34 : if( pParentRefDev && pOutliner )
279 : : {
280 : 2 : pOutliner->SetRefDevice( pParentRefDev );
281 : : }
282 : 34 : }
283 : :
284 : 68 : SdrOutliner* DrawViewWrapper::getOutliner() const
285 : : {
286 : 68 : return m_apOutliner.get();
287 : : }
288 : :
289 : 0 : SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const
290 : : {
291 : 0 : SfxItemSet aFullSet( GetModel()->GetItemPool(),
292 : : SID_ATTR_TRANSFORM_POS_X,SID_ATTR_TRANSFORM_ANGLE,
293 : : SID_ATTR_TRANSFORM_PROTECT_POS,SID_ATTR_TRANSFORM_AUTOHEIGHT,
294 : : SDRATTR_ECKENRADIUS,SDRATTR_ECKENRADIUS,
295 : : SID_ATTR_METRIC,SID_ATTR_METRIC,
296 [ # # ]: 0 : 0);
297 [ # # ]: 0 : SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() );
298 [ # # ]: 0 : aFullSet.Put( aGeoSet );
299 [ # # ][ # # ]: 0 : aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC,static_cast< sal_uInt16 >( ConfigurationAccess::getFieldUnit())));
[ # # ][ # # ]
300 [ # # ]: 0 : return aFullSet;
301 : : }
302 : :
303 : 749 : SdrObject* DrawViewWrapper::getNamedSdrObject( const rtl::OUString& rName ) const
304 : : {
305 [ - + ]: 749 : if(rName.isEmpty())
306 : 0 : return 0;
307 : 749 : SdrPageView* pSdrPageView = this->GetPageView();
308 [ + - ]: 749 : if( pSdrPageView )
309 : : {
310 [ + - ]: 749 : return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() );
311 : : }
312 : 749 : return 0;
313 : : }
314 : :
315 : 0 : bool DrawViewWrapper::IsObjectHit( SdrObject* pObj, const Point& rPnt ) const
316 : : {
317 [ # # ]: 0 : if(pObj)
318 : : {
319 [ # # ]: 0 : Rectangle aRect(pObj->GetCurrentBoundRect());
320 [ # # ]: 0 : return aRect.IsInside(rPnt);
321 : : }
322 : 0 : return false;
323 : : }
324 : :
325 : 75771 : void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
326 : : {
327 : : //prevent wrong reselection of objects
328 : 75771 : SdrModel* pSdrModel( this->GetModel() );
329 [ + - ][ + - ]: 75771 : if( pSdrModel && pSdrModel->isLocked() )
[ + - ]
330 : 75771 : return;
331 : :
332 [ # # ]: 0 : const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
333 : :
334 : : //#i76053# do nothing when only changes on the hidden draw page were made ( e.g. when the symbols for the dialogs are created )
335 : 0 : SdrPageView* pSdrPageView = this->GetPageView();
336 [ # # ][ # # ]: 0 : if( pSdrHint && pSdrPageView )
337 : : {
338 [ # # ]: 0 : if( pSdrPageView->GetPage() != pSdrHint->GetPage() )
339 : 0 : return;
340 : : }
341 : :
342 : 0 : E3dView::Notify(rBC, rHint);
343 : :
344 [ # # ]: 0 : if( pSdrHint != 0 )
345 : : {
346 : 0 : SdrHintKind eKind = pSdrHint->GetKind();
347 [ # # ]: 0 : if( eKind == HINT_BEGEDIT )
348 : : {
349 : : // #i79965# remember map mode
350 : : OSL_ASSERT( ! m_bRestoreMapMode );
351 : 0 : OutputDevice* pOutDev = this->GetFirstOutputDevice();
352 [ # # ]: 0 : if( pOutDev )
353 : : {
354 : 0 : m_aMapModeToRestore = pOutDev->GetMapMode();
355 : 0 : m_bRestoreMapMode = true;
356 : : }
357 : : }
358 [ # # ]: 0 : else if( eKind == HINT_ENDEDIT )
359 : : {
360 : : // #i79965# scroll back view when ending text edit
361 : : OSL_ASSERT( m_bRestoreMapMode );
362 [ # # ]: 0 : if( m_bRestoreMapMode )
363 : : {
364 : 0 : OutputDevice* pOutDev = this->GetFirstOutputDevice();
365 [ # # ]: 0 : if( pOutDev )
366 : : {
367 : 0 : pOutDev->SetMapMode( m_aMapModeToRestore );
368 : 75771 : m_bRestoreMapMode = false;
369 : : }
370 : : }
371 : : }
372 : : }
373 : : }
374 : :
375 : 0 : SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference<
376 : : drawing::XShape >& xShape )
377 : : {
378 : 0 : SdrObject* pRet = 0;
379 [ # # ]: 0 : uno::Reference< lang::XUnoTunnel > xUnoTunnel( xShape, uno::UNO_QUERY );
380 [ # # ]: 0 : uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY );
381 [ # # ][ # # ]: 0 : if(xUnoTunnel.is()&&xTypeProvider.is())
[ # # ]
382 : : {
383 [ # # ][ # # ]: 0 : SvxShape* pSvxShape = reinterpret_cast<SvxShape*>(xUnoTunnel->getSomething( SvxShape::getUnoTunnelId() ));
384 [ # # ]: 0 : if(pSvxShape)
385 [ # # ]: 0 : pRet = pSvxShape->GetSdrObject();
386 : : }
387 : 0 : return pRet;
388 : : }
389 : :
390 : : //.............................................................................
391 : : } //namespace chart
392 : : //.............................................................................
393 : :
394 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|