tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / view / main / DrawModelWrapper.cxx
blob8c418ec2374d1daa320da8a0aab25efd0548b0ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <editeng/unolingu.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/virdev.hxx>
34 #include <libxml/xmlwriter.h>
35 #include <osl/diagnose.h>
37 namespace com::sun::star::linguistic2 { class XHyphenator; }
38 namespace com::sun::star::linguistic2 { class XSpellChecker1; }
40 using namespace ::com::sun::star;
43 namespace chart
46 DrawModelWrapper::DrawModelWrapper()
47 : SdrModel()
49 m_xChartItemPool = ChartItemPool::CreateChartItemPool();
51 SetDefaultFontHeight(423); // 12pt
53 SfxItemPool* pMasterPool = &GetItemPool();
54 pMasterPool->SetDefaultMetric(MapUnit::Map100thMM);
55 pMasterPool->SetUserDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) );
56 pMasterPool->SetUserDefaultItem(makeSvx3DPercentDiagonalItem (5));
58 // append chart pool to end of pool chain
59 pMasterPool->GetLastPoolInChain()->SetSecondaryPool(m_xChartItemPool.get());
60 SetTextDefaults();
62 //this factory needs to be created before first use of 3D scenes once upon an office runtime
63 //@todo in future this should be done by drawing engine itself on demand
64 static bool b3dFactoryInitialized = false;
65 if(!b3dFactoryInitialized)
67 E3dObjFactory aObjFactory;
68 b3dFactoryInitialized = true;
71 //Hyphenation and spellchecking
72 SdrOutliner& rOutliner = GetDrawOutliner();
73 try
75 uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
76 if( xHyphenator.is() )
77 rOutliner.SetHyphenator( xHyphenator );
79 uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
80 if ( xSpellChecker.is() )
81 rOutliner.SetSpeller( xSpellChecker );
83 catch(...)
85 OSL_FAIL("Can't get Hyphenator or SpellChecker for chart");
88 //ref device for font rendering
89 OutputDevice* pDefaultDevice = rOutliner.GetRefDevice();
90 if( !pDefaultDevice )
91 pDefaultDevice = Application::GetDefaultDevice();
92 m_pRefDevice.disposeAndClear();
93 m_pRefDevice = VclPtr<VirtualDevice>::Create(*pDefaultDevice);
94 MapMode aMapMode = m_pRefDevice->GetMapMode();
95 aMapMode.SetMapUnit(MapUnit::Map100thMM);
96 m_pRefDevice->SetMapMode(aMapMode);
97 SetRefDevice(m_pRefDevice.get());
98 rOutliner.SetRefDevice(m_pRefDevice.get());
101 DrawModelWrapper::~DrawModelWrapper()
103 // normally call from ~SdrModel, but do it here explicitly before we clear m_xChartItemPool
104 implDtorClearModel();
106 //remove m_pChartItemPool from pool chain
107 if (m_xChartItemPool)
109 SfxItemPool* pPool = &GetItemPool();
110 for (;;)
112 SfxItemPool* pSecondary = pPool->GetSecondaryPool();
113 if(pSecondary == m_xChartItemPool.get())
115 pPool->SetSecondaryPool (nullptr);
116 break;
118 pPool = pSecondary;
120 m_xChartItemPool.clear();
122 m_pRefDevice.disposeAndClear();
125 uno::Reference< frame::XModel > DrawModelWrapper::createUnoModel()
127 return new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer
130 const uno::Reference< frame::XModel > & DrawModelWrapper::getUnoModel()
132 return SdrModel::getUnoModel();
135 SdrModel& DrawModelWrapper::getSdrModel()
137 return *this;
140 uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory()
142 uno::Reference< lang::XMultiServiceFactory > xShapeFactory( getUnoModel(), uno::UNO_QUERY );
143 return xShapeFactory;
146 const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getMainDrawPage()
148 if (m_xMainDrawPage.is())
149 return m_xMainDrawPage;
151 // Create draw page.
152 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSuplier(getUnoModel(), uno::UNO_QUERY);
153 if (!xDrawPagesSuplier.is())
154 return m_xMainDrawPage;
156 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSuplier->getDrawPages();
157 if (xDrawPages->getCount() > 1)
159 // Take the first page in case of multiple pages.
160 uno::Any aPage = xDrawPages->getByIndex(0);
161 uno::Reference<drawing::XDrawPage> xTmp;
162 aPage >>= xTmp;
163 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get());
164 assert(m_xMainDrawPage);
167 if (!m_xMainDrawPage.is())
169 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex(0).get());
170 assert(m_xMainDrawPage);
173 //ensure that additional shapes are in front of the chart objects so create the chart root before
174 // let us disable this call for now
175 // TODO:moggi
176 // ShapeFactory::getOrCreateShapeFactory(getShapeFactory())->getOrCreateChartRootShape( m_xMainDrawPage );
177 return m_xMainDrawPage;
180 const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getHiddenDrawPage()
182 if( !m_xHiddenDrawPage.is() )
184 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( getUnoModel(), uno::UNO_QUERY );
185 if( xDrawPagesSuplier.is() )
187 uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
188 if( xDrawPages->getCount()>1 )
190 uno::Any aPage = xDrawPages->getByIndex( 1 ) ;
191 uno::Reference<drawing::XDrawPage> xTmp;
192 aPage >>= xTmp;
193 m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get());
194 assert(m_xHiddenDrawPage);
197 if(!m_xHiddenDrawPage.is())
199 if( xDrawPages->getCount()==0 )
201 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 0 ).get());
202 assert(m_xMainDrawPage);
204 m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 1 ).get());
205 assert(m_xHiddenDrawPage);
209 return m_xHiddenDrawPage;
211 void DrawModelWrapper::clearMainDrawPage()
213 //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY );
214 rtl::Reference<SvxShapeGroupAnyD> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) );
215 if( xChartRoot.is() )
217 sal_Int32 nSubCount = xChartRoot->getCount();
218 uno::Reference< drawing::XShape > xShape;
219 for( sal_Int32 nS = nSubCount; nS--; )
221 if( xChartRoot->getByIndex( nS ) >>= xShape )
222 xChartRoot->remove( xShape );
227 rtl::Reference<SvxShapeGroupAnyD> DrawModelWrapper::getChartRootShape( const rtl::Reference<SvxDrawPage>& xDrawPage )
229 return ShapeFactory::getChartRootShape( xDrawPage );
232 void DrawModelWrapper::lockControllers()
234 uno::Reference< frame::XModel > xDrawModel( getUnoModel() );
235 if( xDrawModel.is())
236 xDrawModel->lockControllers();
238 void DrawModelWrapper::unlockControllers()
240 uno::Reference< frame::XModel > xDrawModel( getUnoModel() );
241 if( xDrawModel.is())
242 xDrawModel->unlockControllers();
245 OutputDevice* DrawModelWrapper::getReferenceDevice() const
247 return SdrModel::GetRefDevice();
250 SfxItemPool& DrawModelWrapper::GetItemPool()
252 return SdrModel::GetItemPool();
254 XColorListRef DrawModelWrapper::GetColorList() const
256 return SdrModel::GetColorList();
258 XDashListRef DrawModelWrapper::GetDashList() const
260 return SdrModel::GetDashList();
262 XLineEndListRef DrawModelWrapper::GetLineEndList() const
264 return SdrModel::GetLineEndList();
266 XGradientListRef DrawModelWrapper::GetGradientList() const
268 return SdrModel::GetGradientList();
270 XHatchListRef DrawModelWrapper::GetHatchList() const
272 return SdrModel::GetHatchList();
274 XBitmapListRef DrawModelWrapper::GetBitmapList() const
276 return SdrModel::GetBitmapList();
279 XPatternListRef DrawModelWrapper::GetPatternList() const
281 return SdrModel::GetPatternList();
284 SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rName )
286 if( rName.isEmpty() )
287 return nullptr;
288 return getNamedSdrObject( rName, GetPage(0) );
291 SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rObjectCID, SdrObjList const * pSearchList )
293 if(!pSearchList || rObjectCID.isEmpty())
294 return nullptr;
295 for (const rtl::Reference<SdrObject>& pObj : *pSearchList)
297 if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) )
298 return pObj.get();
299 SdrObject* pNamedObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() );
300 if(pNamedObj)
301 return pNamedObj;
303 return nullptr;
306 bool DrawModelWrapper::removeShape( const rtl::Reference<SvxShape>& xShape )
308 uno::Reference<drawing::XShapes> xShapes( xShape->getParent(), uno::UNO_QUERY );
309 if( xShapes.is() )
311 xShapes->remove(xShape);
312 return true;
314 return false;
317 void DrawModelWrapper::dumpAsXml(xmlTextWriterPtr pWriter) const
319 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DrawModelWrapper"));
320 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
322 SdrModel::dumpAsXml(pWriter);
324 (void)xmlTextWriterEndElement(pWriter);
327 } //namespace chart
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */