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