/src/libreoffice/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
Line | Count | Source |
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 | | |
23 | | #include <unotools/lingucfg.hxx> |
24 | | #include <unotools/syslocale.hxx> |
25 | | #include <unotools/localedatawrapper.hxx> |
26 | | #include <editeng/eeitem.hxx> |
27 | | #include <editeng/langitem.hxx> |
28 | | #include <svl/intitem.hxx> |
29 | | #include <svl/itempool.hxx> |
30 | | #include <svx/obj3d.hxx> |
31 | | #include <svx/svdpagv.hxx> |
32 | | #include <svx/svdmodel.hxx> |
33 | | #include <svx/svdetc.hxx> |
34 | | #include <svx/svdoutl.hxx> |
35 | | #include <svx/svxids.hrc> |
36 | | #include <editeng/fhgtitem.hxx> |
37 | | #include <osl/diagnose.h> |
38 | | |
39 | | #include <com/sun/star/drawing/XShape.hpp> |
40 | | |
41 | | #include <sfx2/objsh.hxx> |
42 | | #include <sfx2/viewsh.hxx> |
43 | | #include <svx/helperhittest3d.hxx> |
44 | | #include <officecfg/Office/Calc.hxx> |
45 | | |
46 | | using namespace ::com::sun::star; |
47 | | |
48 | | namespace chart |
49 | | { |
50 | | |
51 | | namespace |
52 | | { |
53 | | short lcl_getHitTolerance( OutputDevice const * pOutDev ) |
54 | 0 | { |
55 | 0 | const short HITPIX=2; //hit-tolerance in pixel |
56 | 0 | short nHitTolerance = 50; |
57 | 0 | if(pOutDev) |
58 | 0 | nHitTolerance = static_cast<short>(pOutDev->PixelToLogic(Size(HITPIX,0)).Width()); |
59 | 0 | return nHitTolerance; |
60 | 0 | } |
61 | | |
62 | | // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to |
63 | | // get the reference device (e.g. printer) from the parent document |
64 | | OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel ) |
65 | 0 | { |
66 | 0 | SfxObjectShell* pParent = SfxObjectShell::GetParentShell(xModel); |
67 | 0 | if ( pParent ) |
68 | 0 | return pParent->GetDocumentRefDev(); |
69 | 0 | return nullptr; |
70 | 0 | } |
71 | | |
72 | | } |
73 | | |
74 | | DrawViewWrapper::DrawViewWrapper( |
75 | | SdrModel& rSdrModel, |
76 | | OutputDevice* pOut) |
77 | 0 | : E3dView(rSdrModel, pOut) |
78 | 0 | ,m_pMarkHandleProvider(nullptr) |
79 | 0 | ,m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rSdrModel)) |
80 | 0 | ,m_bRestoreMapMode( false ) |
81 | 0 | { |
82 | 0 | SetBufferedOutputAllowed(true); |
83 | 0 | SetBufferedOverlayAllowed(true); |
84 | | |
85 | | // #i12587# support for shapes in chart |
86 | 0 | SdrOutliner* pOutliner = getOutliner(); |
87 | 0 | SfxItemPool* pOutlinerPool = ( pOutliner ? pOutliner->GetEditEnginePool() : nullptr ); |
88 | 0 | if ( pOutlinerPool ) |
89 | 0 | { |
90 | 0 | SvtLinguConfig aLinguConfig; |
91 | 0 | SvtLinguOptions aLinguOptions; |
92 | 0 | aLinguConfig.GetOptions( aLinguOptions ); |
93 | 0 | pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage, EE_CHAR_LANGUAGE ) ); |
94 | 0 | pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) ); |
95 | 0 | pOutlinerPool->SetUserDefaultItem( SvxLanguageItem( aLinguOptions.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) ); |
96 | | |
97 | | // set font height without changing SdrEngineDefaults |
98 | 0 | pOutlinerPool->SetUserDefaultItem( SvxFontHeightItem( 423, 100, EE_CHAR_FONTHEIGHT ) ); // 12pt |
99 | 0 | } |
100 | | |
101 | | // #i121463# Use big handles by default |
102 | 0 | SetMarkHdlSizePixel(9); |
103 | |
|
104 | 0 | ReInit(); |
105 | 0 | } |
106 | | |
107 | | void DrawViewWrapper::ReInit() |
108 | 0 | { |
109 | 0 | OutputDevice* pOutDev = GetFirstOutputDevice(); |
110 | 0 | Size aOutputSize(100,100); |
111 | 0 | if(pOutDev) |
112 | 0 | aOutputSize = pOutDev->GetOutputSize(); |
113 | |
|
114 | 0 | mbPageVisible = false; |
115 | 0 | mbPageBorderVisible = false; |
116 | 0 | mbBordVisible = false; |
117 | 0 | mbGridVisible = false; |
118 | 0 | mbHlplVisible = false; |
119 | |
|
120 | 0 | SetNoDragXorPolys(true);//for interactive 3D resize-dragging: paint only a single rectangle (not a simulated 3D object) |
121 | | |
122 | | //a correct work area is at least necessary for correct values in the position and size dialog |
123 | 0 | tools::Rectangle aRect(Point(0,0), aOutputSize); |
124 | 0 | SetWorkArea(aRect); |
125 | |
|
126 | 0 | ShowSdrPage(GetModel().GetPage(0)); |
127 | 0 | } |
128 | | |
129 | | DrawViewWrapper::~DrawViewWrapper() |
130 | 0 | { |
131 | 0 | maComeBackIdle.Stop();//@todo this should be done in destructor of base class |
132 | 0 | UnmarkAllObj();//necessary to avoid a paint call during the destructor hierarchy |
133 | 0 | } |
134 | | |
135 | | SdrPageView* DrawViewWrapper::GetPageView() const |
136 | 0 | { |
137 | 0 | SdrPageView* pSdrPageView = GetSdrPageView(); |
138 | 0 | return pSdrPageView; |
139 | 0 | }; |
140 | | |
141 | | void DrawViewWrapper::SetMarkHandles(SfxViewShell* pOtherShell) |
142 | 0 | { |
143 | 0 | if( m_pMarkHandleProvider && m_pMarkHandleProvider->getMarkHandles( maHdlList ) ) |
144 | 0 | return; |
145 | 0 | else |
146 | 0 | SdrView::SetMarkHandles(pOtherShell); |
147 | 0 | } |
148 | | |
149 | | SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const |
150 | 0 | { |
151 | 0 | SdrPageView* pSdrPageView = GetPageView(); |
152 | 0 | SdrObject* pRet = SdrView::PickObj(rPnt, lcl_getHitTolerance( GetFirstOutputDevice() ), pSdrPageView, |
153 | 0 | SdrSearchOptions::DEEP | SdrSearchOptions::TESTMARKABLE); |
154 | |
|
155 | 0 | if( pRet ) |
156 | 0 | { |
157 | | // ignore some special shapes |
158 | 0 | OUString aShapeName = pRet->GetName(); |
159 | | |
160 | | // return right away if it is a field button |
161 | 0 | if (aShapeName.startsWith("FieldButton")) |
162 | 0 | return pRet; |
163 | | |
164 | 0 | if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") ) |
165 | 0 | { |
166 | 0 | pRet->SetMarkProtect( true ); |
167 | 0 | return getHitObject( rPnt ); |
168 | 0 | } |
169 | | |
170 | | //3d objects need a special treatment |
171 | | //because the simple PickObj method is not accurate in this case for performance reasons |
172 | 0 | E3dObject* pE3d = DynCastE3dObject(pRet); |
173 | 0 | if( pE3d ) |
174 | 0 | { |
175 | 0 | E3dScene* pScene(pE3d->getRootE3dSceneFromE3dObject()); |
176 | |
|
177 | 0 | if(nullptr != pScene) |
178 | 0 | { |
179 | | // prepare result vector and call helper |
180 | 0 | std::vector< const E3dCompoundObject* > aHitList; |
181 | 0 | const basegfx::B2DPoint aHitPoint(rPnt.X(), rPnt.Y()); |
182 | 0 | getAllHit3DObjectsSortedFrontToBack(aHitPoint, *pScene, aHitList); |
183 | |
|
184 | 0 | if(!aHitList.empty()) |
185 | 0 | { |
186 | | // choose the frontmost hit 3D object of the scene |
187 | 0 | pRet = const_cast< E3dCompoundObject* >(aHitList[0]); |
188 | 0 | } |
189 | 0 | } |
190 | 0 | } |
191 | 0 | } |
192 | 0 | return pRet; |
193 | 0 | } |
194 | | |
195 | | void DrawViewWrapper::MarkObject( SdrObject* pObj ) |
196 | 0 | { |
197 | 0 | bool bFrameDragSingles = true;//true == green == surrounding handles |
198 | 0 | if(pObj) |
199 | 0 | pObj->SetMarkProtect(false); |
200 | 0 | if( m_pMarkHandleProvider ) |
201 | 0 | bFrameDragSingles = m_pMarkHandleProvider->getFrameDragSingles(); |
202 | |
|
203 | 0 | SetFrameDragSingles(bFrameDragSingles);//decide whether each single object should get handles |
204 | 0 | SdrView::MarkObj( pObj, GetPageView() ); |
205 | 0 | showMarkHandles(); |
206 | 0 | } |
207 | | |
208 | | void DrawViewWrapper::setMarkHandleProvider( MarkHandleProvider* pMarkHandleProvider ) |
209 | 0 | { |
210 | 0 | m_pMarkHandleProvider = pMarkHandleProvider; |
211 | 0 | } |
212 | | |
213 | | void DrawViewWrapper::CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* /* pRedirector */) |
214 | 0 | { |
215 | 0 | Color aFillColor; |
216 | 0 | if (const SfxViewShell* pViewShell = SfxViewShell::Current()) |
217 | 0 | aFillColor = pViewShell->GetColorConfigColor(svtools::DOCCOLOR); |
218 | 0 | else |
219 | 0 | { |
220 | 0 | svtools::ColorConfig aColorConfig; |
221 | 0 | aFillColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor; |
222 | 0 | } |
223 | 0 | SetApplicationBackgroundColor(aFillColor); |
224 | |
|
225 | 0 | SdrOutliner& rOutliner = GetModel().GetDrawOutliner(); |
226 | 0 | Color aOldBackColor = rOutliner.GetBackgroundColor(); |
227 | 0 | rOutliner.SetBackgroundColor(aFillColor); |
228 | |
|
229 | 0 | E3dView::CompleteRedraw( pOut, rReg ); |
230 | |
|
231 | 0 | rOutliner.SetBackgroundColor(aOldBackColor); |
232 | 0 | } |
233 | | |
234 | | SdrObject* DrawViewWrapper::getSelectedObject() const |
235 | 0 | { |
236 | 0 | SdrObject* pObj(nullptr); |
237 | 0 | const SdrMarkList& rMarkList = GetMarkedObjectList(); |
238 | 0 | if(rMarkList.GetMarkCount() == 1) |
239 | 0 | { |
240 | 0 | SdrMark* pMark = rMarkList.GetMark(0); |
241 | 0 | pObj = pMark->GetMarkedSdrObj(); |
242 | 0 | } |
243 | 0 | return pObj; |
244 | 0 | } |
245 | | |
246 | | SdrObject* DrawViewWrapper::getTextEditObject() const |
247 | 0 | { |
248 | 0 | SdrObject* pObj = getSelectedObject(); |
249 | 0 | SdrObject* pTextObj = nullptr; |
250 | 0 | if( pObj && pObj->HasTextEdit()) |
251 | 0 | pTextObj = pObj; |
252 | 0 | return pTextObj; |
253 | 0 | } |
254 | | |
255 | | void DrawViewWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel ) |
256 | 0 | { |
257 | 0 | OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel )); |
258 | 0 | SdrOutliner * pOutliner( getOutliner()); |
259 | 0 | if( pParentRefDev && pOutliner ) |
260 | 0 | { |
261 | 0 | pOutliner->SetRefDevice( pParentRefDev ); |
262 | 0 | } |
263 | 0 | } |
264 | | |
265 | | SdrOutliner* DrawViewWrapper::getOutliner() const |
266 | 0 | { |
267 | 0 | return m_apOutliner.get(); |
268 | 0 | } |
269 | | |
270 | | SfxItemSet DrawViewWrapper::getPositionAndSizeItemSetFromMarkedObject() const |
271 | 0 | { |
272 | 0 | SvtSysLocale aSysLocale; |
273 | 0 | MeasurementSystem eSys = aSysLocale.GetLocaleData().getMeasurementSystemEnum(); |
274 | 0 | sal_uInt16 nAttrMetric; |
275 | 0 | if( eSys == MeasurementSystem::Metric ) |
276 | 0 | nAttrMetric = officecfg::Office::Calc::Layout::Other::MeasureUnit::Metric::get(); |
277 | 0 | else |
278 | 0 | nAttrMetric = officecfg::Office::Calc::Layout::Other::MeasureUnit::NonMetric::get(); |
279 | |
|
280 | 0 | SfxItemSet aFullSet( |
281 | 0 | GetModel().GetItemPool(), |
282 | 0 | svl::Items< |
283 | 0 | SDRATTR_CORNER_RADIUS, SDRATTR_CORNER_RADIUS, |
284 | 0 | SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE, |
285 | 0 | SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT, |
286 | 0 | SID_ATTR_METRIC, SID_ATTR_METRIC>); |
287 | 0 | SfxItemSet aGeoSet( E3dView::GetGeoAttrFromMarked() ); |
288 | 0 | aFullSet.Put( aGeoSet ); |
289 | 0 | aFullSet.Put( SfxUInt16Item(SID_ATTR_METRIC, nAttrMetric) ); |
290 | 0 | return aFullSet; |
291 | 0 | } |
292 | | |
293 | | SdrObject* DrawViewWrapper::getNamedSdrObject( const OUString& rName ) const |
294 | 0 | { |
295 | 0 | if(rName.isEmpty()) |
296 | 0 | return nullptr; |
297 | 0 | SdrPageView* pSdrPageView = GetPageView(); |
298 | 0 | if( pSdrPageView ) |
299 | 0 | { |
300 | 0 | return DrawModelWrapper::getNamedSdrObject( rName, pSdrPageView->GetObjList() ); |
301 | 0 | } |
302 | 0 | return nullptr; |
303 | 0 | } |
304 | | |
305 | | bool DrawViewWrapper::IsObjectHit( SdrObject const * pObj, const Point& rPnt ) |
306 | 0 | { |
307 | 0 | if(pObj) |
308 | 0 | { |
309 | 0 | tools::Rectangle aRect(pObj->GetCurrentBoundRect()); |
310 | 0 | return aRect.Contains(rPnt); |
311 | 0 | } |
312 | 0 | return false; |
313 | 0 | } |
314 | | |
315 | | void DrawViewWrapper::Notify(SfxBroadcaster& rBC, const SfxHint& rHint) |
316 | 0 | { |
317 | | //prevent wrong reselection of objects |
318 | 0 | SdrModel& rSdrModel = GetModel(); |
319 | 0 | if (rSdrModel.isLocked()) |
320 | 0 | return; |
321 | | |
322 | 0 | const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr ); |
323 | | |
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 | 0 | SdrPageView* pSdrPageView = GetPageView(); |
326 | 0 | if( pSdrHint && pSdrPageView ) |
327 | 0 | { |
328 | 0 | if( pSdrPageView->GetPage() != pSdrHint->GetPage() ) |
329 | 0 | return; |
330 | 0 | } |
331 | | |
332 | 0 | E3dView::Notify(rBC, rHint); |
333 | |
|
334 | 0 | if( pSdrHint == nullptr ) |
335 | 0 | return; |
336 | | |
337 | 0 | SdrHintKind eKind = pSdrHint->GetKind(); |
338 | 0 | if( eKind == SdrHintKind::BeginEdit ) |
339 | 0 | { |
340 | | // #i79965# remember map mode |
341 | 0 | OSL_ASSERT( ! m_bRestoreMapMode ); |
342 | 0 | OutputDevice* pOutDev = GetFirstOutputDevice(); |
343 | 0 | if( pOutDev ) |
344 | 0 | { |
345 | 0 | m_aMapModeToRestore = pOutDev->GetMapMode(); |
346 | 0 | m_bRestoreMapMode = true; |
347 | 0 | } |
348 | 0 | } |
349 | 0 | else if( eKind == SdrHintKind::EndEdit ) |
350 | 0 | { |
351 | | // #i79965# scroll back view when ending text edit |
352 | 0 | OSL_ASSERT( m_bRestoreMapMode ); |
353 | 0 | if( m_bRestoreMapMode ) |
354 | 0 | { |
355 | 0 | OutputDevice* pOutDev = GetFirstOutputDevice(); |
356 | 0 | if( pOutDev ) |
357 | 0 | { |
358 | 0 | pOutDev->SetMapMode( m_aMapModeToRestore ); |
359 | 0 | m_bRestoreMapMode = false; |
360 | 0 | } |
361 | 0 | } |
362 | 0 | } |
363 | 0 | } |
364 | | |
365 | | SdrObject* DrawViewWrapper::getSdrObject( const uno::Reference< |
366 | | drawing::XShape >& xShape ) |
367 | 0 | { |
368 | 0 | SdrObject* pRet = nullptr; |
369 | 0 | uno::Reference< lang::XTypeProvider > xTypeProvider( xShape, uno::UNO_QUERY ); |
370 | 0 | if(xTypeProvider.is()) |
371 | 0 | { |
372 | 0 | pRet = SdrObject::getSdrObjectFromXShape(xShape); |
373 | 0 | } |
374 | 0 | return pRet; |
375 | 0 | } |
376 | | |
377 | | } //namespace chart |
378 | | |
379 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |