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 0 : OXUndoEnvironment& OReportModel::GetUndoEnv()
93 : {
94 0 : return *m_pUndoEnv;
95 : }
96 :
97 0 : void OReportModel::SetModified(sal_Bool _bModified)
98 : {
99 0 : if ( m_pController )
100 0 : m_pController->setModified(_bModified);
101 0 : }
102 :
103 0 : SdrPage* OReportModel::RemovePage(sal_uInt16 nPgNum)
104 : {
105 0 : OReportPage* pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum));
106 0 : return pPage;
107 : }
108 :
109 0 : OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
110 : {
111 0 : SolarMutexGuard aSolarGuard;
112 0 : OReportPage* pPage = new OReportPage( *this ,_xSection);
113 0 : InsertPage(pPage);
114 0 : m_pUndoEnv->AddSection(_xSection);
115 0 : return pPage;
116 : }
117 :
118 0 : OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
119 : {
120 0 : OReportPage* pPage = NULL;
121 0 : sal_uInt16 nCount = GetPageCount();
122 0 : for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
123 : {
124 0 : OReportPage* pRptPage = PTR_CAST( OReportPage, GetPage(i) );
125 0 : if ( pRptPage && pRptPage->getSection() == _xSection )
126 0 : pPage = pRptPage;
127 : }
128 0 : return pPage;
129 : }
130 :
131 0 : SvxNumType OReportModel::GetPageNumType() const
132 : {
133 0 : uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
134 0 : if ( xReportDefinition.is() )
135 0 : return (SvxNumType)getStyleProperty<sal_Int16>(xReportDefinition,PROPERTY_NUMBERINGTYPE);
136 0 : return SVX_ARABIC;
137 : }
138 :
139 :
140 0 : uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
141 : {
142 0 : uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
143 : OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
144 0 : return xReportDefinition;
145 : }
146 :
147 0 : uno::Reference< uno::XInterface > OReportModel::createUnoModel()
148 : {
149 0 : return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
150 : }
151 :
152 0 : uno::Reference< uno::XInterface > OReportModel::createShape(const OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
153 : {
154 0 : uno::Reference< uno::XInterface > xRet;
155 0 : if ( _rShape.is() )
156 : {
157 0 : if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
158 : {
159 0 : uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
160 0 : xRet = xProp;
161 0 : if ( _rShape.is() )
162 0 : throw uno::Exception();
163 0 : xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::makeAny(uno::Reference< util::XNumberFormatsSupplier >(*m_pReportDefinition,uno::UNO_QUERY)) );
164 : }
165 0 : else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
166 : {
167 0 : xRet = static_cast<cppu::OWeakObject*>(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
168 0 : if ( _rShape.is() )
169 0 : throw uno::Exception();
170 : }
171 0 : else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
172 : {
173 0 : xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
174 0 : if ( _rShape.is() )
175 0 : throw uno::Exception();
176 : }
177 0 : else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
178 : {
179 0 : xRet = static_cast<cppu::OWeakObject*>(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
180 0 : if ( _rShape.is() )
181 0 : throw uno::Exception();
182 : }
183 0 : else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
184 : {
185 0 : xRet = static_cast<cppu::OWeakObject*>(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
186 0 : if ( _rShape.is() )
187 0 : throw uno::Exception();
188 : }
189 0 : else if ( _rShape.is() )
190 : {
191 0 : xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
192 0 : if ( _rShape.is() )
193 0 : throw uno::Exception();
194 : }
195 : }
196 0 : return xRet;
197 : }
198 :
199 : } //rptui
200 :
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|