1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 #include <strings.hxx>
31 #include <FixedLine.hxx>
32 #include <FormattedField.hxx>
33 #include <FixedText.hxx>
34 #include <ImageControl.hxx>
39 using namespace reportdesign
;
40 using namespace com::sun::star
;
43 OReportModel::OReportModel(::reportdesign::OReportDefinition
* _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);
67 void OReportModel::detachController()
69 if (!m_pReportDefinition
)
71 m_pController
= nullptr;
72 m_xUndoEnv
->EndListening( *this );
74 m_xUndoEnv
->Clear(OXUndoEnvironment::Accessor());
75 m_pReportDefinition
= nullptr;
78 rtl::Reference
<SdrPage
> OReportModel::AllocPage(bool /*bMasterPage*/)
80 OSL_FAIL("Who called me!");
85 void OReportModel::SetChanged( bool bChanged
)
87 SdrModel::SetChanged( bChanged
);
88 SetModified( bChanged
);
92 void OReportModel::SetModified(bool _bModified
)
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());
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
);
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
)
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
;
152 if ( aServiceSpecifier
== SERVICE_FORMATTEDFIELD
)
154 uno::Reference
<report::XFormattedField
> xProp
= new OFormattedField(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
);
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
));
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
));
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
));
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
));
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
));
188 throw uno::Exception(u
"no shape"_ustr
, nullptr);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */