/src/libreoffice/chart2/source/view/main/DrawModelWrapper.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 <chartview/DrawModelWrapper.hxx> |
21 | | #include <ShapeFactory.hxx> |
22 | | #include "ChartItemPool.hxx" |
23 | | #include <ObjectIdentifier.hxx> |
24 | | #include <svx/unomodel.hxx> |
25 | | #include <svl/itempool.hxx> |
26 | | #include <svx/objfac3d.hxx> |
27 | | #include <svx/svdpage.hxx> |
28 | | #include <svx/svx3ditems.hxx> |
29 | | #include <svx/xtable.hxx> |
30 | | #include <svx/svdoutl.hxx> |
31 | | #include <tools/mapunit.hxx> |
32 | | #include <editeng/unolingu.hxx> |
33 | | #include <vcl/svapp.hxx> |
34 | | #include <vcl/virdev.hxx> |
35 | | #include <libxml/xmlwriter.h> |
36 | | #include <osl/diagnose.h> |
37 | | |
38 | | namespace com::sun::star::linguistic2 { class XHyphenator; } |
39 | | namespace com::sun::star::linguistic2 { class XSpellChecker1; } |
40 | | |
41 | | using namespace ::com::sun::star; |
42 | | |
43 | | |
44 | | namespace chart |
45 | | { |
46 | | |
47 | | DrawModelWrapper::DrawModelWrapper() |
48 | 0 | : SdrModel() |
49 | 0 | { |
50 | 0 | m_xChartItemPool = ChartItemPool::CreateChartItemPool(); |
51 | |
|
52 | 0 | SetDefaultFontHeight(423); // 12pt |
53 | |
|
54 | 0 | SfxItemPool* pMasterPool = &GetItemPool(); |
55 | 0 | pMasterPool->SetDefaultMetric(MapUnit::Map100thMM); |
56 | 0 | pMasterPool->SetUserDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) ); |
57 | 0 | pMasterPool->SetUserDefaultItem(makeSvx3DPercentDiagonalItem (5)); |
58 | | |
59 | | // append chart pool to end of pool chain |
60 | 0 | pMasterPool->GetLastPoolInChain()->SetSecondaryPool(m_xChartItemPool.get()); |
61 | 0 | SetTextDefaults(); |
62 | | |
63 | | //this factory needs to be created before first use of 3D scenes once upon an office runtime |
64 | | //@todo in future this should be done by drawing engine itself on demand |
65 | 0 | static bool b3dFactoryInitialized = false; |
66 | 0 | if(!b3dFactoryInitialized) |
67 | 0 | { |
68 | 0 | E3dObjFactory aObjFactory; |
69 | 0 | b3dFactoryInitialized = true; |
70 | 0 | } |
71 | | |
72 | | //Hyphenation and spellchecking |
73 | 0 | SdrOutliner& rOutliner = GetDrawOutliner(); |
74 | 0 | try |
75 | 0 | { |
76 | 0 | uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() ); |
77 | 0 | if( xHyphenator.is() ) |
78 | 0 | rOutliner.SetHyphenator( xHyphenator ); |
79 | |
|
80 | 0 | uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() ); |
81 | 0 | if ( xSpellChecker.is() ) |
82 | 0 | rOutliner.SetSpeller( xSpellChecker ); |
83 | 0 | } |
84 | 0 | catch(...) |
85 | 0 | { |
86 | 0 | OSL_FAIL("Can't get Hyphenator or SpellChecker for chart"); |
87 | 0 | } |
88 | | |
89 | | //ref device for font rendering |
90 | 0 | OutputDevice* pDefaultDevice = rOutliner.GetRefDevice(); |
91 | 0 | if( !pDefaultDevice ) |
92 | 0 | pDefaultDevice = Application::GetDefaultDevice(); |
93 | 0 | m_pRefDevice.disposeAndClear(); |
94 | 0 | m_pRefDevice = VclPtr<VirtualDevice>::Create(*pDefaultDevice); |
95 | 0 | MapMode aMapMode = m_pRefDevice->GetMapMode(); |
96 | 0 | aMapMode.SetMapUnit(MapUnit::Map100thMM); |
97 | 0 | m_pRefDevice->SetMapMode(aMapMode); |
98 | 0 | SetRefDevice(m_pRefDevice.get()); |
99 | 0 | rOutliner.SetRefDevice(m_pRefDevice.get()); |
100 | 0 | } |
101 | | |
102 | | DrawModelWrapper::~DrawModelWrapper() |
103 | 0 | { |
104 | | // normally call from ~SdrModel, but do it here explicitly before we clear m_xChartItemPool |
105 | 0 | implDtorClearModel(); |
106 | | |
107 | | //remove m_pChartItemPool from pool chain |
108 | 0 | if (m_xChartItemPool) |
109 | 0 | { |
110 | 0 | SfxItemPool* pPool = &GetItemPool(); |
111 | 0 | for (;;) |
112 | 0 | { |
113 | 0 | SfxItemPool* pSecondary = pPool->GetSecondaryPool(); |
114 | 0 | if(pSecondary == m_xChartItemPool.get()) |
115 | 0 | { |
116 | 0 | pPool->SetSecondaryPool (nullptr); |
117 | 0 | break; |
118 | 0 | } |
119 | 0 | pPool = pSecondary; |
120 | 0 | } |
121 | 0 | m_xChartItemPool.clear(); |
122 | 0 | } |
123 | 0 | m_pRefDevice.disposeAndClear(); |
124 | 0 | } |
125 | | |
126 | | uno::Reference< frame::XModel > DrawModelWrapper::createUnoModel() |
127 | 0 | { |
128 | 0 | return new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer |
129 | 0 | } |
130 | | |
131 | | const uno::Reference< frame::XModel > & DrawModelWrapper::getUnoModel() |
132 | 0 | { |
133 | 0 | return SdrModel::getUnoModel(); |
134 | 0 | } |
135 | | |
136 | | SdrModel& DrawModelWrapper::getSdrModel() |
137 | 0 | { |
138 | 0 | return *this; |
139 | 0 | } |
140 | | |
141 | | uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory() |
142 | 0 | { |
143 | 0 | uno::Reference< lang::XMultiServiceFactory > xShapeFactory( getUnoModel(), uno::UNO_QUERY ); |
144 | 0 | return xShapeFactory; |
145 | 0 | } |
146 | | |
147 | | const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getMainDrawPage() |
148 | 0 | { |
149 | 0 | if (m_xMainDrawPage.is()) |
150 | 0 | return m_xMainDrawPage; |
151 | | |
152 | | // Create draw page. |
153 | 0 | uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSuplier(getUnoModel(), uno::UNO_QUERY); |
154 | 0 | if (!xDrawPagesSuplier.is()) |
155 | 0 | return m_xMainDrawPage; |
156 | | |
157 | 0 | uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSuplier->getDrawPages(); |
158 | 0 | if (xDrawPages->getCount() > 1) |
159 | 0 | { |
160 | | // Take the first page in case of multiple pages. |
161 | 0 | uno::Any aPage = xDrawPages->getByIndex(0); |
162 | 0 | uno::Reference<drawing::XDrawPage> xTmp; |
163 | 0 | aPage >>= xTmp; |
164 | 0 | m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get()); |
165 | 0 | assert(m_xMainDrawPage); |
166 | 0 | } |
167 | |
|
168 | 0 | if (!m_xMainDrawPage.is()) |
169 | 0 | { |
170 | 0 | m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex(0).get()); |
171 | 0 | assert(m_xMainDrawPage); |
172 | 0 | } |
173 | | |
174 | | //ensure that additional shapes are in front of the chart objects so create the chart root before |
175 | | // let us disable this call for now |
176 | | // TODO:moggi |
177 | | // ShapeFactory::getOrCreateShapeFactory(getShapeFactory())->getOrCreateChartRootShape( m_xMainDrawPage ); |
178 | 0 | return m_xMainDrawPage; |
179 | 0 | } |
180 | | |
181 | | const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getHiddenDrawPage() |
182 | 0 | { |
183 | 0 | if( !m_xHiddenDrawPage.is() ) |
184 | 0 | { |
185 | 0 | uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( getUnoModel(), uno::UNO_QUERY ); |
186 | 0 | if( xDrawPagesSuplier.is() ) |
187 | 0 | { |
188 | 0 | uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () ); |
189 | 0 | if( xDrawPages->getCount()>1 ) |
190 | 0 | { |
191 | 0 | uno::Any aPage = xDrawPages->getByIndex( 1 ) ; |
192 | 0 | uno::Reference<drawing::XDrawPage> xTmp; |
193 | 0 | aPage >>= xTmp; |
194 | 0 | m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get()); |
195 | 0 | assert(m_xHiddenDrawPage); |
196 | 0 | } |
197 | |
|
198 | 0 | if(!m_xHiddenDrawPage.is()) |
199 | 0 | { |
200 | 0 | if( xDrawPages->getCount()==0 ) |
201 | 0 | { |
202 | 0 | m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 0 ).get()); |
203 | 0 | assert(m_xMainDrawPage); |
204 | 0 | } |
205 | 0 | m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 1 ).get()); |
206 | 0 | assert(m_xHiddenDrawPage); |
207 | 0 | } |
208 | 0 | } |
209 | 0 | } |
210 | 0 | return m_xHiddenDrawPage; |
211 | 0 | } |
212 | | void DrawModelWrapper::clearMainDrawPage() |
213 | 0 | { |
214 | | //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY ); |
215 | 0 | rtl::Reference<SvxShapeGroupAnyD> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) ); |
216 | 0 | if( xChartRoot.is() ) |
217 | 0 | { |
218 | 0 | sal_Int32 nSubCount = xChartRoot->getCount(); |
219 | 0 | uno::Reference< drawing::XShape > xShape; |
220 | 0 | for( sal_Int32 nS = nSubCount; nS--; ) |
221 | 0 | { |
222 | 0 | if( xChartRoot->getByIndex( nS ) >>= xShape ) |
223 | 0 | xChartRoot->remove( xShape ); |
224 | 0 | } |
225 | 0 | } |
226 | 0 | } |
227 | | |
228 | | rtl::Reference<SvxShapeGroupAnyD> DrawModelWrapper::getChartRootShape( const rtl::Reference<SvxDrawPage>& xDrawPage ) |
229 | 0 | { |
230 | 0 | return ShapeFactory::getChartRootShape( xDrawPage ); |
231 | 0 | } |
232 | | |
233 | | void DrawModelWrapper::lockControllers() |
234 | 0 | { |
235 | 0 | uno::Reference< frame::XModel > xDrawModel( getUnoModel() ); |
236 | 0 | if( xDrawModel.is()) |
237 | 0 | xDrawModel->lockControllers(); |
238 | 0 | } |
239 | | void DrawModelWrapper::unlockControllers() |
240 | 0 | { |
241 | 0 | uno::Reference< frame::XModel > xDrawModel( getUnoModel() ); |
242 | 0 | if( xDrawModel.is()) |
243 | 0 | xDrawModel->unlockControllers(); |
244 | 0 | } |
245 | | |
246 | | OutputDevice* DrawModelWrapper::getReferenceDevice() const |
247 | 0 | { |
248 | 0 | return SdrModel::GetRefDevice(); |
249 | 0 | } |
250 | | |
251 | | SfxItemPool& DrawModelWrapper::GetItemPool() |
252 | 0 | { |
253 | 0 | return SdrModel::GetItemPool(); |
254 | 0 | } |
255 | | XColorListRef DrawModelWrapper::GetColorList() const |
256 | 0 | { |
257 | 0 | return SdrModel::GetColorList(); |
258 | 0 | } |
259 | | XDashListRef DrawModelWrapper::GetDashList() const |
260 | 0 | { |
261 | 0 | return SdrModel::GetDashList(); |
262 | 0 | } |
263 | | XLineEndListRef DrawModelWrapper::GetLineEndList() const |
264 | 0 | { |
265 | 0 | return SdrModel::GetLineEndList(); |
266 | 0 | } |
267 | | XGradientListRef DrawModelWrapper::GetGradientList() const |
268 | 0 | { |
269 | 0 | return SdrModel::GetGradientList(); |
270 | 0 | } |
271 | | XHatchListRef DrawModelWrapper::GetHatchList() const |
272 | 0 | { |
273 | 0 | return SdrModel::GetHatchList(); |
274 | 0 | } |
275 | | XBitmapListRef DrawModelWrapper::GetBitmapList() const |
276 | 0 | { |
277 | 0 | return SdrModel::GetBitmapList(); |
278 | 0 | } |
279 | | |
280 | | XPatternListRef DrawModelWrapper::GetPatternList() const |
281 | 0 | { |
282 | 0 | return SdrModel::GetPatternList(); |
283 | 0 | } |
284 | | |
285 | | SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rName ) |
286 | 0 | { |
287 | 0 | if( rName.isEmpty() ) |
288 | 0 | return nullptr; |
289 | 0 | return getNamedSdrObject( rName, GetPage(0) ); |
290 | 0 | } |
291 | | |
292 | | SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rObjectCID, SdrObjList const * pSearchList ) |
293 | 0 | { |
294 | 0 | if(!pSearchList || rObjectCID.isEmpty()) |
295 | 0 | return nullptr; |
296 | 0 | for (const rtl::Reference<SdrObject>& pObj : *pSearchList) |
297 | 0 | { |
298 | 0 | if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) ) |
299 | 0 | return pObj.get(); |
300 | 0 | SdrObject* pNamedObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() ); |
301 | 0 | if(pNamedObj) |
302 | 0 | return pNamedObj; |
303 | 0 | } |
304 | 0 | return nullptr; |
305 | 0 | } |
306 | | |
307 | | bool DrawModelWrapper::removeShape( const rtl::Reference<SvxShape>& xShape ) |
308 | 0 | { |
309 | 0 | uno::Reference<drawing::XShapes> xShapes( xShape->getParent(), uno::UNO_QUERY ); |
310 | 0 | if( xShapes.is() ) |
311 | 0 | { |
312 | 0 | xShapes->remove(xShape); |
313 | 0 | return true; |
314 | 0 | } |
315 | 0 | return false; |
316 | 0 | } |
317 | | |
318 | | void DrawModelWrapper::dumpAsXml(xmlTextWriterPtr pWriter) const |
319 | 0 | { |
320 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DrawModelWrapper")); |
321 | 0 | (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); |
322 | |
|
323 | 0 | SdrModel::dumpAsXml(pWriter); |
324 | |
|
325 | 0 | (void)xmlTextWriterEndElement(pWriter); |
326 | 0 | } |
327 | | |
328 | | } //namespace chart |
329 | | |
330 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |