bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / core / sdr / RptModel.cxx
blob5c50ad72144be526aa02d0dd18d5c17b93d93468
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 <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"
34 #include "RptDef.hxx"
35 #include "corestrings.hrc"
36 #include "FixedLine.hxx"
37 #include "FormattedField.hxx"
38 #include "FixedText.hxx"
39 #include "ImageControl.hxx"
40 #include "Shape.hxx"
42 namespace rptui
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)
52 ,m_pController(NULL)
53 ,m_pReportDefinition(_pReportDefinition)
55 m_pUndoEnv = new OXUndoEnvironment(*this);
56 m_pUndoEnv->acquire();
57 SetSdrUndoFactory(new OReportUndoFactory);
61 OReportModel::~OReportModel()
63 detachController();
64 m_pUndoEnv->release();
67 void OReportModel::detachController()
69 m_pReportDefinition = NULL;
70 m_pController = NULL;
71 m_pUndoEnv->EndListening( *this );
72 ClearUndoBuffer();
73 m_pUndoEnv->Clear(OXUndoEnvironment::Accessor());
76 SdrPage* OReportModel::AllocPage(bool /*bMasterPage*/)
78 OSL_FAIL("Who called me!");
79 return NULL;
84 void OReportModel::SetChanged( bool bChanged )
86 SdrModel::SetChanged( bChanged );
87 SetModified( bChanged );
93 void OReportModel::SetModified(bool _bModified)
95 if ( m_pController )
96 m_pController->setModified(_bModified);
99 SdrPage* OReportModel::RemovePage(sal_uInt16 nPgNum)
101 OReportPage* pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum));
102 return pPage;
105 OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
107 SolarMutexGuard aSolarGuard;
108 OReportPage* pPage = new OReportPage( *this ,_xSection);
109 InsertPage(pPage);
110 m_pUndoEnv->AddSection(_xSection);
111 return pPage;
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 )
122 pPage = pRptPage;
124 return pPage;
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);
132 return SVX_ARABIC;
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;
151 if ( _rShape.is() )
153 if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
155 uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
156 xRet = xProp;
157 if ( _rShape.is() )
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));
164 if ( _rShape.is() )
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));
170 if ( _rShape.is() )
171 throw uno::Exception();
173 else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
175 xRet = static_cast<cppu::OWeakObject*>(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
176 if ( _rShape.is() )
177 throw uno::Exception();
179 else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
181 xRet = static_cast<cppu::OWeakObject*>(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
182 if ( _rShape.is() )
183 throw uno::Exception();
185 else if ( _rShape.is() )
187 xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
188 if ( _rShape.is() )
189 throw uno::Exception();
192 return xRet;
195 } //rptui
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */