Line data Source code
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"
22 : #include <dbaccess/dbsubcomponentcontroller.hxx>
23 : #include <tools/debug.hxx>
24 : #include <unotools/pathoptions.hxx>
25 : #include <vcl/svapp.hxx>
26 :
27 : #include "UndoActions.hxx"
28 : #include "UndoEnv.hxx"
29 : #include "ReportUndoFactory.hxx"
30 : #include "ReportDefinition.hxx"
31 :
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"
41 :
42 : namespace rptui
43 : {
44 : using namespace reportdesign;
45 : using namespace com::sun::star;
46 0 : TYPEINIT1(OReportModel,SdrModel);
47 :
48 :
49 :
50 0 : OReportModel::OReportModel(::reportdesign::OReportDefinition* _pReportDefinition) :
51 0 : SdrModel(SvtPathOptions().GetPalettePath(),NULL,_pReportDefinition, false, false)
52 : ,m_pController(NULL)
53 0 : ,m_pReportDefinition(_pReportDefinition)
54 : {
55 0 : m_pUndoEnv = new OXUndoEnvironment(*this);
56 0 : m_pUndoEnv->acquire();
57 0 : SetSdrUndoFactory(new OReportUndoFactory);
58 0 : }
59 :
60 :
61 0 : OReportModel::~OReportModel()
62 : {
63 0 : detachController();
64 0 : m_pUndoEnv->release();
65 0 : }
66 :
67 0 : void OReportModel::detachController()
68 : {
69 0 : m_pReportDefinition = NULL;
70 0 : m_pController = NULL;
71 0 : m_pUndoEnv->EndListening( *this );
72 0 : ClearUndoBuffer();
73 0 : m_pUndoEnv->Clear(OXUndoEnvironment::Accessor());
74 0 : }
75 :
76 0 : SdrPage* OReportModel::AllocPage(bool /*bMasterPage*/)
77 : {
78 : OSL_FAIL("Who called me!");
79 0 : return NULL;
80 : }
81 :
82 :
83 :
84 0 : void OReportModel::SetChanged( bool bChanged )
85 : {
86 0 : SdrModel::SetChanged( bChanged );
87 0 : SetModified( bChanged );
88 0 : }
89 :
90 :
91 :
92 :
93 0 : void OReportModel::SetModified(bool _bModified)
94 : {
95 0 : if ( m_pController )
96 0 : m_pController->setModified(_bModified);
97 0 : }
98 :
99 0 : SdrPage* OReportModel::RemovePage(sal_uInt16 nPgNum)
100 : {
101 0 : OReportPage* pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum));
102 0 : return pPage;
103 : }
104 :
105 0 : OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
106 : {
107 0 : SolarMutexGuard aSolarGuard;
108 0 : OReportPage* pPage = new OReportPage( *this ,_xSection);
109 0 : InsertPage(pPage);
110 0 : m_pUndoEnv->AddSection(_xSection);
111 0 : return pPage;
112 : }
113 :
114 0 : OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
115 : {
116 0 : OReportPage* pPage = NULL;
117 0 : sal_uInt16 nCount = GetPageCount();
118 0 : for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
119 : {
120 0 : OReportPage* pRptPage = PTR_CAST( OReportPage, GetPage(i) );
121 0 : if ( pRptPage && pRptPage->getSection() == _xSection )
122 0 : pPage = pRptPage;
123 : }
124 0 : return pPage;
125 : }
126 :
127 0 : SvxNumType OReportModel::GetPageNumType() const
128 : {
129 0 : uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
130 0 : if ( xReportDefinition.is() )
131 0 : return (SvxNumType)getStyleProperty<sal_Int16>(xReportDefinition,PROPERTY_NUMBERINGTYPE);
132 0 : return SVX_ARABIC;
133 : }
134 :
135 :
136 0 : uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
137 : {
138 0 : uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
139 : OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
140 0 : return xReportDefinition;
141 : }
142 :
143 0 : uno::Reference< uno::XInterface > OReportModel::createUnoModel()
144 : {
145 0 : return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
146 : }
147 :
148 0 : uno::Reference< uno::XInterface > OReportModel::createShape(const OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
149 : {
150 0 : uno::Reference< uno::XInterface > xRet;
151 0 : if ( _rShape.is() )
152 : {
153 0 : if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
154 : {
155 0 : uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
156 0 : xRet = xProp;
157 0 : if ( _rShape.is() )
158 0 : throw uno::Exception();
159 0 : xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::makeAny(uno::Reference< util::XNumberFormatsSupplier >(*m_pReportDefinition,uno::UNO_QUERY)) );
160 : }
161 0 : else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
162 : {
163 0 : xRet = static_cast<cppu::OWeakObject*>(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
164 0 : if ( _rShape.is() )
165 0 : throw uno::Exception();
166 : }
167 0 : else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
168 : {
169 0 : xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
170 0 : if ( _rShape.is() )
171 0 : throw uno::Exception();
172 : }
173 0 : else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
174 : {
175 0 : xRet = static_cast<cppu::OWeakObject*>(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
176 0 : if ( _rShape.is() )
177 0 : throw uno::Exception();
178 : }
179 0 : else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
180 : {
181 0 : xRet = static_cast<cppu::OWeakObject*>(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
182 0 : if ( _rShape.is() )
183 0 : throw uno::Exception();
184 : }
185 0 : else if ( _rShape.is() )
186 : {
187 0 : xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
188 0 : if ( _rShape.is() )
189 0 : throw uno::Exception();
190 : }
191 : }
192 0 : return xRet;
193 : }
194 :
195 6 : } //rptui
196 :
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|