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 <unotools/resmgr.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <vcl/svapp.hxx>
27 #include <UndoActions.hxx>
28 #include <UndoEnv.hxx>
29 #include <ReportUndoFactory.hxx>
30 #include <ReportDefinition.hxx>
32 #include <svx/tbcontrl.hxx>
33 #include <rptui_slotid.hrc>
35 #include <strings.hxx>
36 #include <FixedLine.hxx>
37 #include <FormattedField.hxx>
38 #include <FixedText.hxx>
39 #include <ImageControl.hxx>
44 using namespace reportdesign
;
45 using namespace com::sun::star
;
48 OReportModel::OReportModel(::reportdesign::OReportDefinition
* _pReportDefinition
)
52 ,m_pController(nullptr)
53 ,m_pReportDefinition(_pReportDefinition
)
55 m_xUndoEnv
= new OXUndoEnvironment(*this);
56 SetSdrUndoFactory(new OReportUndoFactory
);
60 OReportModel::~OReportModel()
65 void OReportModel::detachController()
67 m_pReportDefinition
= nullptr;
68 m_pController
= nullptr;
69 m_xUndoEnv
->EndListening( *this );
71 m_xUndoEnv
->Clear(OXUndoEnvironment::Accessor());
74 SdrPage
* OReportModel::AllocPage(bool /*bMasterPage*/)
76 OSL_FAIL("Who called me!");
81 void OReportModel::SetChanged( bool bChanged
)
83 SdrModel::SetChanged( bChanged
);
84 SetModified( bChanged
);
88 void OReportModel::SetModified(bool _bModified
)
91 m_pController
->setModified(_bModified
);
94 SdrPage
* OReportModel::RemovePage(sal_uInt16 nPgNum
)
96 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(SdrModel::RemovePage(nPgNum
));
100 OReportPage
* OReportModel::createNewPage(const uno::Reference
< report::XSection
>& _xSection
)
102 SolarMutexGuard aSolarGuard
;
103 OReportPage
* pPage
= new OReportPage( *this ,_xSection
);
105 m_xUndoEnv
->AddSection(_xSection
);
109 OReportPage
* OReportModel::getPage(const uno::Reference
< report::XSection
>& _xSection
)
111 OReportPage
* pPage
= nullptr;
112 sal_uInt16 nCount
= GetPageCount();
113 for (sal_uInt16 i
= 0; i
< nCount
&& !pPage
; ++i
)
115 OReportPage
* pRptPage
= dynamic_cast<OReportPage
*>( GetPage(i
) );
116 if ( pRptPage
&& pRptPage
->getSection() == _xSection
)
122 SvxNumType
OReportModel::GetPageNumType() const
124 uno::Reference
< report::XReportDefinition
> xReportDefinition( getReportDefinition() );
125 if ( xReportDefinition
.is() )
126 return static_cast<SvxNumType
>(getStyleProperty
<sal_Int16
>(xReportDefinition
,PROPERTY_NUMBERINGTYPE
));
127 return SVX_NUM_ARABIC
;
131 uno::Reference
< report::XReportDefinition
> OReportModel::getReportDefinition() const
133 uno::Reference
< report::XReportDefinition
> xReportDefinition
= m_pReportDefinition
;
134 OSL_ENSURE( xReportDefinition
.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
135 return xReportDefinition
;
138 uno::Reference
< uno::XInterface
> OReportModel::createUnoModel()
140 return uno::Reference
< uno::XInterface
>(getReportDefinition(),uno::UNO_QUERY
);
143 uno::Reference
< uno::XInterface
> OReportModel::createShape(const OUString
& aServiceSpecifier
,uno::Reference
< drawing::XShape
>& _rShape
,sal_Int32 nOrientation
)
145 uno::Reference
< uno::XInterface
> xRet
;
148 if ( aServiceSpecifier
== SERVICE_FORMATTEDFIELD
)
150 uno::Reference
<report::XFormattedField
> xProp
= new OFormattedField(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
);
153 throw uno::Exception("no shape", nullptr);
154 xProp
->setPropertyValue( PROPERTY_FORMATSSUPPLIER
, uno::makeAny(uno::Reference
< util::XNumberFormatsSupplier
>(*m_pReportDefinition
,uno::UNO_QUERY
)) );
156 else if ( aServiceSpecifier
== SERVICE_FIXEDTEXT
)
158 xRet
= static_cast<cppu::OWeakObject
*>(new OFixedText(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
160 throw uno::Exception("no shape", nullptr);
162 else if ( aServiceSpecifier
== SERVICE_FIXEDLINE
)
164 xRet
= static_cast<cppu::OWeakObject
*>(new OFixedLine(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
,nOrientation
));
166 throw uno::Exception("no shape", nullptr);
168 else if ( aServiceSpecifier
== SERVICE_IMAGECONTROL
)
170 xRet
= static_cast<cppu::OWeakObject
*>(new OImageControl(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
172 throw uno::Exception("no shape", nullptr);
174 else if ( aServiceSpecifier
== SERVICE_REPORTDEFINITION
)
176 xRet
= static_cast<cppu::OWeakObject
*>(new OReportDefinition(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
178 throw uno::Exception("no shape", nullptr);
180 else if ( _rShape
.is() )
182 xRet
= static_cast<cppu::OWeakObject
*>(new OShape(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
,aServiceSpecifier
));
184 throw uno::Exception("no shape", nullptr);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */