LibreOffice Module reportdesign (master) 1
RptModel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <RptModel.hxx>
21#include <RptPage.hxx>
23#include <vcl/svapp.hxx>
24
25#include <UndoEnv.hxx>
26#include <ReportUndoFactory.hxx>
27#include <ReportDefinition.hxx>
28
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>
36
37namespace rptui
38{
39using namespace reportdesign;
40using namespace com::sun::star;
41
42
44: SdrModel(
45 nullptr,
46 _pReportDefinition)
47 ,m_pController(nullptr)
48 ,m_pReportDefinition(_pReportDefinition)
49{
50 m_xUndoEnv = new OXUndoEnvironment(*this);
52}
53
54
56{
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())
63
65}
66
68{
70 return;
71 m_pController = nullptr;
72 m_xUndoEnv->EndListening( *this );
75 m_pReportDefinition = nullptr;
76}
77
79{
80 OSL_FAIL("Who called me!");
81 return nullptr;
82}
83
84
85void OReportModel::SetChanged( bool bChanged )
86{
87 SdrModel::SetChanged( bChanged );
88 SetModified( bChanged );
89}
90
91
92void OReportModel::SetModified(bool _bModified)
93{
94 if ( m_pController )
95 m_pController->setModified(_bModified);
96}
97
99{
100 rtl::Reference<OReportPage> pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum).get());
101 return pPage;
102}
103
104OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
105{
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();
111}
112
113OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
114{
115 OReportPage* pPage = nullptr;
116 sal_uInt16 nCount = GetPageCount();
117 for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
118 {
119 OReportPage* pRptPage = dynamic_cast<OReportPage*>( GetPage(i) );
120 if ( pRptPage && pRptPage->getSection() == _xSection )
121 pPage = pRptPage;
122 }
123 return pPage;
124}
125
127{
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;
132}
133
134
135uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
136{
137 uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
138 OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
139 return xReportDefinition;
140}
141
142uno::Reference< uno::XInterface > OReportModel::createUnoModel()
143{
144 return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
145}
146
147uno::Reference< uno::XInterface > OReportModel::createShape(const OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
148{
149 uno::Reference< uno::XInterface > xRet;
150 if ( _rShape.is() )
151 {
152 if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
153 {
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("no shape", nullptr);
158 xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::Any(uno::Reference< util::XNumberFormatsSupplier >(m_pReportDefinition)) );
159 }
160 else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
161 {
163 if ( _rShape.is() )
164 throw uno::Exception("no shape", nullptr);
165 }
166 else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
167 {
168 xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
169 if ( _rShape.is() )
170 throw uno::Exception("no shape", nullptr);
171 }
172 else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
173 {
175 if ( _rShape.is() )
176 throw uno::Exception("no shape", nullptr);
177 }
178 else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
179 {
181 if ( _rShape.is() )
182 throw uno::Exception("no shape", nullptr);
183 }
184 else if ( _rShape.is() )
185 {
186 xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
187 if ( _rShape.is() )
188 throw uno::Exception("no shape", nullptr);
189 }
190 }
191 return xRet;
192}
193
194} //rptui
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum)
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
virtual void SetChanged(bool bFlg=true)
void ClearUndoBuffer()
void SetSdrUndoFactory(SdrUndoFactory *pUndoFactory)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
virtual void SAL_CALL setModified(sal_Bool bModified) override
implementation of a
Definition: FixedLine.hxx:45
implementation of a
Definition: FixedText.hxx:46
implementation of a
css::uno::Reference< css::uno::XComponentContext > getContext()
implementation of a
Definition: Shape.hxx:45
virtual SvxNumType GetPageNumType() const override
Definition: RptModel.cxx:126
rtl::Reference< OXUndoEnvironment > m_xUndoEnv
Definition: RptModel.hxx:45
OReportPage * createNewPage(const css::uno::Reference< css::report::XSection > &_xSection)
Definition: RptModel.cxx:104
virtual void SetChanged(bool bFlg=true) override
Definition: RptModel.cxx:85
::dbaui::DBSubComponentController * m_pController
Definition: RptModel.hxx:46
virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override
Definition: RptModel.cxx:142
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum) override
Definition: RptModel.cxx:98
css::uno::Reference< css::report::XReportDefinition > getReportDefinition() const
returns the XReportDefinition which the OReportModel belongs to
Definition: RptModel.cxx:135
void SetModified(bool _bModified)
Definition: RptModel.cxx:92
OReportPage * getPage(const css::uno::Reference< css::report::XSection > &_xSection)
returns the page which belongs to a section
Definition: RptModel.cxx:113
virtual ~OReportModel() override
Definition: RptModel.cxx:55
OReportModel(const OReportModel &)=delete
css::uno::Reference< css::uno::XInterface > createShape(const OUString &aServiceSpecifier, css::uno::Reference< css::drawing::XShape > &_rShape, sal_Int32 nOrientation=-1)
Definition: RptModel.cxx:147
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
Definition: RptModel.cxx:78
void detachController()
Definition: RptModel.cxx:67
::reportdesign::OReportDefinition * m_pReportDefinition
Definition: RptModel.hxx:47
friend class OReportPage
Definition: RptModel.hxx:42
const css::uno::Reference< css::report::XSection > & getSection() const
Definition: RptPage.hxx:82
int nCount
int i
constexpr OUStringLiteral SERVICE_FIXEDLINE
Definition: strings.hxx:29
constexpr OUStringLiteral PROPERTY_NUMBERINGTYPE
Definition: strings.hxx:207
constexpr OUStringLiteral SERVICE_IMAGECONTROL
Definition: strings.hxx:24
constexpr OUStringLiteral SERVICE_FIXEDTEXT
Definition: strings.hxx:22
constexpr OUStringLiteral SERVICE_FORMATTEDFIELD
Definition: strings.hxx:23
constexpr OUStringLiteral SERVICE_REPORTDEFINITION
Definition: strings.hxx:27
constexpr OUStringLiteral PROPERTY_FORMATSSUPPLIER
Definition: strings.hxx:95
SvxNumType
SVX_NUM_ARABIC