cid#1607171 Data race condition
[LibreOffice.git] / reportdesign / source / core / sdr / RptModel.cxx
blobec72a62afcd00fd7c50d9c05a7c7106109d8fe21
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 <RptModel.hxx>
21 #include <RptPage.hxx>
22 #include <dbaccess/dbsubcomponentcontroller.hxx>
23 #include <vcl/svapp.hxx>
25 #include <UndoEnv.hxx>
26 #include <ReportUndoFactory.hxx>
27 #include <ReportDefinition.hxx>
29 #include <RptDef.hxx>
30 #include <strings.hxx>
31 #include <FixedLine.hxx>
32 #include <FormattedField.hxx>
33 #include <FixedText.hxx>
34 #include <ImageControl.hxx>
35 #include <Shape.hxx>
37 namespace rptui
39 using namespace reportdesign;
40 using namespace com::sun::star;
43 OReportModel::OReportModel(::reportdesign::OReportDefinition* _pReportDefinition)
44 : SdrModel(
45 nullptr,
46 _pReportDefinition)
47 ,m_pController(nullptr)
48 ,m_pReportDefinition(_pReportDefinition)
50 m_xUndoEnv = new OXUndoEnvironment(*this);
51 SetSdrUndoFactory(new OReportUndoFactory);
55 OReportModel::~OReportModel()
57 // There are some nasty interactions which mean that we have to delete
58 // the pages before we destroy the model - otherwise we will trigger
59 // callbacks which will attempt to recreate SvxShape objects and
60 // fail because the model is being torn down.
61 while (GetPageCount())
62 RemovePage(GetPageCount()-1);
64 detachController();
67 void OReportModel::detachController()
69 if (!m_pReportDefinition)
70 return;
71 m_pController = nullptr;
72 m_xUndoEnv->EndListening( *this );
73 ClearUndoBuffer();
74 m_xUndoEnv->Clear(OXUndoEnvironment::Accessor());
75 m_pReportDefinition = nullptr;
78 rtl::Reference<SdrPage> OReportModel::AllocPage(bool /*bMasterPage*/)
80 OSL_FAIL("Who called me!");
81 return nullptr;
85 void OReportModel::SetChanged( bool bChanged )
87 SdrModel::SetChanged( bChanged );
88 SetModified( bChanged );
92 void OReportModel::SetModified(bool _bModified)
94 if ( m_pController )
95 m_pController->setModified(_bModified);
98 rtl::Reference<SdrPage> OReportModel::RemovePage(sal_uInt16 nPgNum)
100 rtl::Reference<OReportPage> pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum).get());
101 return pPage;
104 OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
106 SolarMutexGuard aSolarGuard;
107 rtl::Reference<OReportPage> pPage = new OReportPage( *this ,_xSection);
108 InsertPage(pPage.get());
109 m_xUndoEnv->AddSection(_xSection);
110 return pPage.get();
113 OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
115 OReportPage* pPage = nullptr;
116 sal_uInt16 nCount = GetPageCount();
117 for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
119 OReportPage* pRptPage = dynamic_cast<OReportPage*>( GetPage(i) );
120 if ( pRptPage && pRptPage->getSection() == _xSection )
121 pPage = pRptPage;
123 return pPage;
126 SvxNumType OReportModel::GetPageNumType() const
128 uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
129 if ( xReportDefinition.is() )
130 return static_cast<SvxNumType>(getStyleProperty<sal_Int16>(xReportDefinition,PROPERTY_NUMBERINGTYPE));
131 return SVX_NUM_ARABIC;
135 uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
137 uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
138 OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
139 return xReportDefinition;
142 uno::Reference< frame::XModel > OReportModel::createUnoModel()
144 return getReportDefinition();
147 uno::Reference< uno::XInterface > OReportModel::createShape(const OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
149 uno::Reference< uno::XInterface > xRet;
150 if ( _rShape.is() )
152 if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
154 uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
155 xRet = xProp;
156 if ( _rShape.is() )
157 throw uno::Exception(u"no shape"_ustr, nullptr);
158 xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::Any(uno::Reference< util::XNumberFormatsSupplier >(m_pReportDefinition)) );
160 else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
162 xRet = getXWeak(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
163 if ( _rShape.is() )
164 throw uno::Exception(u"no shape"_ustr, nullptr);
166 else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
168 xRet = getXWeak(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
169 if ( _rShape.is() )
170 throw uno::Exception(u"no shape"_ustr, nullptr);
172 else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
174 xRet = getXWeak(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
175 if ( _rShape.is() )
176 throw uno::Exception(u"no shape"_ustr, nullptr);
178 else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
180 xRet = getXWeak(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
181 if ( _rShape.is() )
182 throw uno::Exception(u"no shape"_ustr, nullptr);
184 else if ( _rShape.is() )
186 xRet = getXWeak(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
187 if ( _rShape.is() )
188 throw uno::Exception(u"no shape"_ustr, nullptr);
191 return xRet;
194 } //rptui
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */