LibreOffice Module chart2 (master) 1
DrawModelWrapper.cxx
Go to the documentation of this file.
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
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>
36
37namespace com::sun::star::linguistic2 { class XHyphenator; }
38namespace com::sun::star::linguistic2 { class XSpellChecker1; }
39
40using namespace ::com::sun::star;
41
42
43namespace chart
44{
45
47: SdrModel()
48{
50
51 SetDefaultFontHeight(423); // 12pt
52
53 SfxItemPool* pMasterPool = &GetItemPool();
54 pMasterPool->SetDefaultMetric(MapUnit::Map100thMM);
57
58 // append chart pool to end of pool chain
60 pMasterPool->FreezeIdRanges();
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 static bool b3dFactoryInitialized = false;
66 if(!b3dFactoryInitialized)
67 {
68 E3dObjFactory aObjFactory;
69 b3dFactoryInitialized = true;
70 }
71
72 //Hyphenation and spellchecking
73 SdrOutliner& rOutliner = GetDrawOutliner();
74 try
75 {
77 if( xHyphenator.is() )
78 rOutliner.SetHyphenator( xHyphenator );
79
81 if ( xSpellChecker.is() )
82 rOutliner.SetSpeller( xSpellChecker );
83 }
84 catch(...)
85 {
86 OSL_FAIL("Can't get Hyphenator or SpellChecker for chart");
87 }
88
89 //ref device for font rendering
90 OutputDevice* pDefaultDevice = rOutliner.GetRefDevice();
91 if( !pDefaultDevice )
92 pDefaultDevice = Application::GetDefaultDevice();
95 MapMode aMapMode = m_pRefDevice->GetMapMode();
96 aMapMode.SetMapUnit(MapUnit::Map100thMM);
97 m_pRefDevice->SetMapMode(aMapMode);
99 rOutliner.SetRefDevice(m_pRefDevice.get());
100}
101
103{
104 //remove m_pChartItemPool from pool chain
106 {
107 SfxItemPool* pPool = &GetItemPool();
108 for (;;)
109 {
110 SfxItemPool* pSecondary = pPool->GetSecondaryPool();
111 if(pSecondary == m_xChartItemPool.get())
112 {
113 pPool->SetSecondaryPool (nullptr);
114 break;
115 }
116 pPool = pSecondary;
117 }
118 m_xChartItemPool.clear();
119 }
121}
122
124{
125 uno::Reference< lang::XComponent > xComponent = new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer
126 return uno::Reference< uno::XInterface >::query( xComponent );
127}
128
130{
133}
134
136{
137 return *this;
138}
139
141{
142 uno::Reference< lang::XMultiServiceFactory > xShapeFactory( getUnoModel(), uno::UNO_QUERY );
143 return xShapeFactory;
144}
145
147{
148 if (m_xMainDrawPage.is())
149 return m_xMainDrawPage;
150
151 // Create draw page.
152 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSuplier(getUnoModel(), uno::UNO_QUERY);
153 if (!xDrawPagesSuplier.is())
154 return m_xMainDrawPage;
155
156 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSuplier->getDrawPages();
157 if (xDrawPages->getCount() > 1)
158 {
159 // Take the first page in case of multiple pages.
160 uno::Any aPage = xDrawPages->getByIndex(0);
162 aPage >>= xTmp;
163 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get());
164 assert(m_xMainDrawPage);
165 }
166
167 if (!m_xMainDrawPage.is())
168 {
169 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex(0).get());
170 assert(m_xMainDrawPage);
171 }
172
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;
178}
179
181{
182 if( !m_xHiddenDrawPage.is() )
183 {
184 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( getUnoModel(), uno::UNO_QUERY );
185 if( xDrawPagesSuplier.is() )
186 {
187 uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
188 if( xDrawPages->getCount()>1 )
189 {
190 uno::Any aPage = xDrawPages->getByIndex( 1 ) ;
192 aPage >>= xTmp;
193 m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get());
194 assert(m_xHiddenDrawPage);
195 }
196
197 if(!m_xHiddenDrawPage.is())
198 {
199 if( xDrawPages->getCount()==0 )
200 {
201 m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 0 ).get());
202 assert(m_xMainDrawPage);
203 }
204 m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 1 ).get());
205 assert(m_xHiddenDrawPage);
206 }
207 }
208 }
209 return m_xHiddenDrawPage;
210}
212{
213 //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY );
215 if( xChartRoot.is() )
216 {
217 sal_Int32 nSubCount = xChartRoot->getCount();
219 for( sal_Int32 nS = nSubCount; nS--; )
220 {
221 if( xChartRoot->getByIndex( nS ) >>= xShape )
222 xChartRoot->remove( xShape );
223 }
224 }
225}
226
228{
229 return ShapeFactory::getChartRootShape( xDrawPage );
230}
231
233{
235 if( xDrawModel.is())
236 xDrawModel->lockControllers();
237}
239{
241 if( xDrawModel.is())
242 xDrawModel->unlockControllers();
243}
244
246{
247 return SdrModel::GetRefDevice();
248}
249
251{
252 return SdrModel::GetItemPool();
253}
255{
256 return SdrModel::GetColorList();
257}
259{
260 return SdrModel::GetDashList();
261}
263{
265}
267{
269}
271{
272 return SdrModel::GetHatchList();
273}
275{
277}
278
280{
282}
283
285{
286 if( rName.isEmpty() )
287 return nullptr;
288 return getNamedSdrObject( rName, GetPage(0) );
289}
290
291SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rObjectCID, SdrObjList const * pSearchList )
292{
293 if(!pSearchList || rObjectCID.isEmpty())
294 return nullptr;
295 const size_t nCount = pSearchList->GetObjCount();
296 for( size_t nN=0; nN<nCount; ++nN )
297 {
298 SdrObject* pObj = pSearchList->GetObj(nN);
299 if(!pObj)
300 continue;
301 if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) )
302 return pObj;
303 pObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() );
304 if(pObj)
305 return pObj;
306 }
307 return nullptr;
308}
309
311{
312 uno::Reference<drawing::XShapes> xShapes( xShape->getParent(), uno::UNO_QUERY );
313 if( xShapes.is() )
314 {
315 xShapes->remove(xShape);
316 return true;
317 }
318 return false;
319}
320
322{
323 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DrawModelWrapper"));
324 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
325
326 SdrModel::dumpAsXml(pWriter);
327
328 (void)xmlTextWriterEndElement(pWriter);
329}
330
331} //namespace chart
332
333/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
static css::uno::Reference< css::linguistic2::XHyphenator > GetHyphenator()
void SetMapUnit(MapUnit eUnit)
XBitmapListRef GetBitmapList() const
XDashListRef GetDashList() const
XGradientListRef GetGradientList() const
void SetRefDevice(OutputDevice *pDev)
XPatternListRef GetPatternList() const
SdrOutliner & GetDrawOutliner(const SdrTextObj *pObj=nullptr) const
XLineEndListRef GetLineEndList() const
void SetTextDefaults() const
const SfxItemPool & GetItemPool() const
XColorListRef GetColorList() const
XHatchListRef GetHatchList() const
void SetDefaultFontHeight(sal_Int32 nVal)
OutputDevice * GetRefDevice() const
css::uno::Reference< css::uno::XInterface > const & getUnoModel()
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
virtual SdrObjList * GetSubList() const
virtual const OUString & GetName() const
SfxItemPool * GetSecondaryPool() const
void FreezeIdRanges()
void SetPoolDefaultItem(const SfxPoolItem &)
SfxItemPool * GetLastPoolInChain()
void SetDefaultMetric(MapUnit eNewMetric)
void SetSecondaryPool(SfxItemPool *pPool)
void disposeAndClear()
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
static rtl::Reference< SfxItemPool > CreateChartItemPool()
creates a pure chart item pool
XDashListRef GetDashList() const
css::uno::Reference< css::lang::XMultiServiceFactory > getShapeFactory()
static rtl::Reference< SvxShapeGroupAnyD > getChartRootShape(const rtl::Reference< SvxDrawPage > &xPage)
XColorListRef GetColorList() const
static bool removeShape(const rtl::Reference< SvxShape > &xShape)
SAL_DLLPRIVATE css::uno::Reference< css::frame::XModel > getUnoModel()
SAL_DLLPRIVATE void lockControllers()
SdrObject * getNamedSdrObject(const OUString &rName)
XGradientListRef GetGradientList() const
SAL_DLLPRIVATE void unlockControllers()
void dumpAsXml(xmlTextWriterPtr pWriter) const override
rtl::Reference< SfxItemPool > m_xChartItemPool
rtl::Reference< SvxDrawPage > m_xHiddenDrawPage
XPatternListRef GetPatternList() const
XBitmapListRef GetBitmapList() const
XLineEndListRef GetLineEndList() const
const rtl::Reference< SvxDrawPage > & getMainDrawPage()
XHatchListRef GetHatchList() const
SAL_DLLPRIVATE void clearMainDrawPage()
const rtl::Reference< SvxDrawPage > & getHiddenDrawPage()
rtl::Reference< SvxDrawPage > m_xMainDrawPage
VclPtr< OutputDevice > m_pRefDevice
SAL_DLLPRIVATE DrawModelWrapper()
virtual SAL_DLLPRIVATE ~DrawModelWrapper() override
OutputDevice * getReferenceDevice() const
virtual SAL_DLLPRIVATE css::uno::Reference< css::uno::XInterface > createUnoModel() override
static bool areIdenticalObjects(std::u16string_view rCID1, std::u16string_view rCID2)
static rtl::Reference< SvxShapeGroupAnyD > getChartRootShape(const rtl::Reference< SvxDrawPage > &xPage)
int nCount
constexpr TypedWhichId< SfxBoolItem > EE_PARA_HYPHENATE(EE_PARA_START+6)
struct _xmlTextWriter * xmlTextWriterPtr
SfxUInt16Item makeSvx3DPercentDiagonalItem(sal_uInt16 nVal)