1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9e0e4191SAndrew Rist * distributed with this work for additional information
6*9e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist * KIND, either express or implied. See the License for the
17*9e0e4191SAndrew Rist * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9e0e4191SAndrew Rist *************************************************************/
21*9e0e4191SAndrew Rist
22*9e0e4191SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include "RptModel.hxx"
26cdf0e10cSrcweir #include "RptPage.hxx"
27cdf0e10cSrcweir #include <dbaccess/dbsubcomponentcontroller.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "UndoActions.hxx"
32cdf0e10cSrcweir #include "UndoEnv.hxx"
33cdf0e10cSrcweir #include "ReportUndoFactory.hxx"
34cdf0e10cSrcweir #include "ReportDefinition.hxx"
35cdf0e10cSrcweir #define ITEMID_COLOR 1
36cdf0e10cSrcweir #define ITEMID_BRUSH 2
37cdf0e10cSrcweir #define ITEMID_FONT 3
38cdf0e10cSrcweir #define ITEMID_FONTHEIGHT 4
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <svx/tbcontrl.hxx>
41cdf0e10cSrcweir #include "rptui_slotid.hrc"
42cdf0e10cSrcweir #include "RptDef.hxx"
43cdf0e10cSrcweir #include "corestrings.hrc"
44cdf0e10cSrcweir #include "FixedLine.hxx"
45cdf0e10cSrcweir #include "FormattedField.hxx"
46cdf0e10cSrcweir #include "FixedText.hxx"
47cdf0e10cSrcweir #include "ImageControl.hxx"
48cdf0e10cSrcweir #include "Shape.hxx"
49cdf0e10cSrcweir
50cdf0e10cSrcweir namespace rptui
51cdf0e10cSrcweir {
52cdf0e10cSrcweir using namespace reportdesign;
53cdf0e10cSrcweir using namespace com::sun::star;
54cdf0e10cSrcweir DBG_NAME( rpt_OReportModel )
55cdf0e10cSrcweir TYPEINIT1(OReportModel,SdrModel);
56cdf0e10cSrcweir
57cdf0e10cSrcweir //----------------------------------------------------------------------------
58cdf0e10cSrcweir
OReportModel(::reportdesign::OReportDefinition * _pReportDefinition)59cdf0e10cSrcweir OReportModel::OReportModel(::reportdesign::OReportDefinition* _pReportDefinition) :
60cdf0e10cSrcweir SdrModel(SvtPathOptions().GetPalettePath(),NULL,_pReportDefinition)
61cdf0e10cSrcweir ,m_pController(NULL)
62cdf0e10cSrcweir ,m_pReportDefinition(_pReportDefinition)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir DBG_CTOR( rpt_OReportModel,0);
65cdf0e10cSrcweir SetAllowShapePropertyChangeListener(true);
66cdf0e10cSrcweir m_pUndoEnv = new OXUndoEnvironment(*this);
67cdf0e10cSrcweir m_pUndoEnv->acquire();
68cdf0e10cSrcweir SetSdrUndoFactory(new OReportUndoFactory);
69cdf0e10cSrcweir
70cdf0e10cSrcweir // SvxFontNameToolBoxControl::RegisterControl(SID_ATTR_CHAR_FONT);
71cdf0e10cSrcweir //SvxFontHeightToolBoxControl::RegisterControl(SID_ATTR_CHAR_FONTHEIGHT);
72cdf0e10cSrcweir //SvxFontColorToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR);
73cdf0e10cSrcweir //SvxFontColorExtToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR2);
74cdf0e10cSrcweir //SvxFontColorExtToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR_BACKGROUND);
75cdf0e10cSrcweir //SvxColorToolBoxControl::RegisterControl(SID_BACKGROUND_COLOR);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir //----------------------------------------------------------------------------
~OReportModel()79cdf0e10cSrcweir OReportModel::~OReportModel()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir DBG_DTOR( rpt_OReportModel,0);
82cdf0e10cSrcweir detachController();
83cdf0e10cSrcweir m_pUndoEnv->release();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir // -----------------------------------------------------------------------------
detachController()86cdf0e10cSrcweir void OReportModel::detachController()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir m_pReportDefinition = NULL;
89cdf0e10cSrcweir m_pController = NULL;
90cdf0e10cSrcweir m_pUndoEnv->EndListening( *this );
91cdf0e10cSrcweir ClearUndoBuffer();
92cdf0e10cSrcweir m_pUndoEnv->Clear(OXUndoEnvironment::Accessor());
93cdf0e10cSrcweir }
94cdf0e10cSrcweir //----------------------------------------------------------------------------
AllocPage(FASTBOOL)95cdf0e10cSrcweir SdrPage* OReportModel::AllocPage(FASTBOOL /*bMasterPage*/)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir DBG_CHKTHIS( rpt_OReportModel, 0);
98cdf0e10cSrcweir OSL_ENSURE(0,"Who called me!");
99cdf0e10cSrcweir return NULL;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir //----------------------------------------------------------------------------
103cdf0e10cSrcweir
SetChanged(sal_Bool bChanged)104cdf0e10cSrcweir void OReportModel::SetChanged( sal_Bool bChanged )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir SdrModel::SetChanged( bChanged );
107cdf0e10cSrcweir SetModified( bChanged );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir //----------------------------------------------------------------------------
111cdf0e10cSrcweir
GetCurDocViewWin()112cdf0e10cSrcweir Window* OReportModel::GetCurDocViewWin()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir return 0;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir //----------------------------------------------------------------------------
GetUndoEnv()118cdf0e10cSrcweir OXUndoEnvironment& OReportModel::GetUndoEnv()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir return *m_pUndoEnv;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir //----------------------------------------------------------------------------
SetModified(sal_Bool _bModified)123cdf0e10cSrcweir void OReportModel::SetModified(sal_Bool _bModified)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if ( m_pController )
126cdf0e10cSrcweir m_pController->setModified(_bModified);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir // -----------------------------------------------------------------------------
RemovePage(sal_uInt16 nPgNum)129cdf0e10cSrcweir SdrPage* OReportModel::RemovePage(sal_uInt16 nPgNum)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir OReportPage* pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum));
132cdf0e10cSrcweir //if ( pPage )
133cdf0e10cSrcweir //{
134cdf0e10cSrcweir // m_pUndoEnv->RemoveSection(pPage);
135cdf0e10cSrcweir //}
136cdf0e10cSrcweir return pPage;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir // -----------------------------------------------------------------------------
createNewPage(const uno::Reference<report::XSection> & _xSection)139cdf0e10cSrcweir OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir OReportPage* pPage = new OReportPage( *this ,_xSection);
142cdf0e10cSrcweir InsertPage(pPage);
143cdf0e10cSrcweir m_pUndoEnv->AddSection(_xSection);
144cdf0e10cSrcweir return pPage;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPage(const uno::Reference<report::XSection> & _xSection)147cdf0e10cSrcweir OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir OReportPage* pPage = NULL;
150cdf0e10cSrcweir sal_uInt16 nCount = GetPageCount();
151cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nCount && !pPage ; ++i)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir OReportPage* pRptPage = PTR_CAST( OReportPage, GetPage(i) );
154cdf0e10cSrcweir if ( pRptPage && pRptPage->getSection() == _xSection )
155cdf0e10cSrcweir pPage = pRptPage;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir return pPage;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetPageNumType() const160cdf0e10cSrcweir SvxNumType OReportModel::GetPageNumType() const
161cdf0e10cSrcweir {
162cdf0e10cSrcweir uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
163cdf0e10cSrcweir if ( xReportDefinition.is() )
164cdf0e10cSrcweir return (SvxNumType)getStyleProperty<sal_Int16>(xReportDefinition,reportdesign::PROPERTY_NUMBERINGTYPE);
165cdf0e10cSrcweir return SVX_ARABIC;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir // -----------------------------------------------------------------------------
getReportDefinition() const169cdf0e10cSrcweir uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
172cdf0e10cSrcweir OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
173cdf0e10cSrcweir return xReportDefinition;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir // -----------------------------------------------------------------------------
createUnoModel()176cdf0e10cSrcweir uno::Reference< uno::XInterface > OReportModel::createUnoModel()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -----------------------------------------------------------------------------
createShape(const::rtl::OUString & aServiceSpecifier,uno::Reference<drawing::XShape> & _rShape,sal_Int32 nOrientation)181cdf0e10cSrcweir uno::Reference< uno::XInterface > OReportModel::createShape(const ::rtl::OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir uno::Reference< uno::XInterface > xRet;
184cdf0e10cSrcweir if ( _rShape.is() )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
189cdf0e10cSrcweir xRet = xProp;
190cdf0e10cSrcweir if ( _rShape.is() )
191cdf0e10cSrcweir throw uno::Exception();
192cdf0e10cSrcweir xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::makeAny(uno::Reference< util::XNumberFormatsSupplier >(*m_pReportDefinition,uno::UNO_QUERY)) );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir xRet = static_cast<cppu::OWeakObject*>(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
197cdf0e10cSrcweir if ( _rShape.is() )
198cdf0e10cSrcweir throw uno::Exception();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
203cdf0e10cSrcweir if ( _rShape.is() )
204cdf0e10cSrcweir throw uno::Exception();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir xRet = static_cast<cppu::OWeakObject*>(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
209cdf0e10cSrcweir if ( _rShape.is() )
210cdf0e10cSrcweir throw uno::Exception();
211cdf0e10cSrcweir }
212cdf0e10cSrcweir else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir xRet = static_cast<cppu::OWeakObject*>(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
215cdf0e10cSrcweir if ( _rShape.is() )
216cdf0e10cSrcweir throw uno::Exception();
217cdf0e10cSrcweir }
218cdf0e10cSrcweir else if ( _rShape.is() )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
221cdf0e10cSrcweir if ( _rShape.is() )
222cdf0e10cSrcweir throw uno::Exception();
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir return xRet;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir //==================================================================
228cdf0e10cSrcweir } //rptui
229cdf0e10cSrcweir //==================================================================
230