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 <tools/debug.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 "corestrings.hrc"
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
;
46 TYPEINIT1(OReportModel
,SdrModel
);
50 OReportModel::OReportModel(::reportdesign::OReportDefinition
* _pReportDefinition
) :
51 SdrModel(SvtPathOptions().GetPalettePath(),NULL
,_pReportDefinition
, false, false)
53 ,m_pReportDefinition(_pReportDefinition
)
55 m_pUndoEnv
= new OXUndoEnvironment(*this);
56 m_pUndoEnv
->acquire();
57 SetSdrUndoFactory(new OReportUndoFactory
);
61 OReportModel::~OReportModel()
64 m_pUndoEnv
->release();
67 void OReportModel::detachController()
69 m_pReportDefinition
= NULL
;
71 m_pUndoEnv
->EndListening( *this );
73 m_pUndoEnv
->Clear(OXUndoEnvironment::Accessor());
76 SdrPage
* OReportModel::AllocPage(bool /*bMasterPage*/)
78 OSL_FAIL("Who called me!");
84 void OReportModel::SetChanged( bool bChanged
)
86 SdrModel::SetChanged( bChanged
);
87 SetModified( bChanged
);
93 void OReportModel::SetModified(bool _bModified
)
96 m_pController
->setModified(_bModified
);
99 SdrPage
* OReportModel::RemovePage(sal_uInt16 nPgNum
)
101 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(SdrModel::RemovePage(nPgNum
));
105 OReportPage
* OReportModel::createNewPage(const uno::Reference
< report::XSection
>& _xSection
)
107 SolarMutexGuard aSolarGuard
;
108 OReportPage
* pPage
= new OReportPage( *this ,_xSection
);
110 m_pUndoEnv
->AddSection(_xSection
);
114 OReportPage
* OReportModel::getPage(const uno::Reference
< report::XSection
>& _xSection
)
116 OReportPage
* pPage
= NULL
;
117 sal_uInt16 nCount
= GetPageCount();
118 for (sal_uInt16 i
= 0; i
< nCount
&& !pPage
; ++i
)
120 OReportPage
* pRptPage
= PTR_CAST( OReportPage
, GetPage(i
) );
121 if ( pRptPage
&& pRptPage
->getSection() == _xSection
)
127 SvxNumType
OReportModel::GetPageNumType() const
129 uno::Reference
< report::XReportDefinition
> xReportDefinition( getReportDefinition() );
130 if ( xReportDefinition
.is() )
131 return (SvxNumType
)getStyleProperty
<sal_Int16
>(xReportDefinition
,PROPERTY_NUMBERINGTYPE
);
136 uno::Reference
< report::XReportDefinition
> OReportModel::getReportDefinition() const
138 uno::Reference
< report::XReportDefinition
> xReportDefinition
= m_pReportDefinition
;
139 OSL_ENSURE( xReportDefinition
.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
140 return xReportDefinition
;
143 uno::Reference
< uno::XInterface
> OReportModel::createUnoModel()
145 return uno::Reference
< uno::XInterface
>(getReportDefinition(),uno::UNO_QUERY
);
148 uno::Reference
< uno::XInterface
> OReportModel::createShape(const OUString
& aServiceSpecifier
,uno::Reference
< drawing::XShape
>& _rShape
,sal_Int32 nOrientation
)
150 uno::Reference
< uno::XInterface
> xRet
;
153 if ( aServiceSpecifier
== SERVICE_FORMATTEDFIELD
)
155 uno::Reference
<report::XFormattedField
> xProp
= new OFormattedField(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
);
158 throw uno::Exception();
159 xProp
->setPropertyValue( PROPERTY_FORMATSSUPPLIER
, uno::makeAny(uno::Reference
< util::XNumberFormatsSupplier
>(*m_pReportDefinition
,uno::UNO_QUERY
)) );
161 else if ( aServiceSpecifier
== SERVICE_FIXEDTEXT
)
163 xRet
= static_cast<cppu::OWeakObject
*>(new OFixedText(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
165 throw uno::Exception();
167 else if ( aServiceSpecifier
== SERVICE_FIXEDLINE
)
169 xRet
= static_cast<cppu::OWeakObject
*>(new OFixedLine(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
,nOrientation
));
171 throw uno::Exception();
173 else if ( aServiceSpecifier
== SERVICE_IMAGECONTROL
)
175 xRet
= static_cast<cppu::OWeakObject
*>(new OImageControl(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
177 throw uno::Exception();
179 else if ( aServiceSpecifier
== SERVICE_REPORTDEFINITION
)
181 xRet
= static_cast<cppu::OWeakObject
*>(new OReportDefinition(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
));
183 throw uno::Exception();
185 else if ( _rShape
.is() )
187 xRet
= static_cast<cppu::OWeakObject
*>(new OShape(m_pReportDefinition
->getContext(),m_pReportDefinition
,_rShape
,aServiceSpecifier
));
189 throw uno::Exception();
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */