Update ooo320-m1
[ooovba.git] / reportdesign / source / core / sdr / RptModel.cxx
blobf1c04c795243ae1e427c85891b7269c2c758ff90
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RptModel.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include "RptModel.hxx"
33 #include "RptPage.hxx"
34 #include <dbaccess/singledoccontroller.hxx>
35 #include <tools/debug.hxx>
36 #include <svtools/pathoptions.hxx>
38 #include "UndoActions.hxx"
39 #include "UndoEnv.hxx"
40 #include "ReportUndoFactory.hxx"
41 #include "ReportDefinition.hxx"
42 #define ITEMID_COLOR 1
43 #define ITEMID_BRUSH 2
44 #define ITEMID_FONT 3
45 #define ITEMID_FONTHEIGHT 4
47 #include <svx/tbcontrl.hxx>
48 #include "rptui_slotid.hrc"
49 #include "RptDef.hxx"
50 #include "corestrings.hrc"
51 #include "FixedLine.hxx"
52 #include "FormattedField.hxx"
53 #include "FixedText.hxx"
54 #include "ImageControl.hxx"
55 #include "Shape.hxx"
57 namespace rptui
59 using namespace reportdesign;
60 using namespace com::sun::star;
61 DBG_NAME( rpt_OReportModel )
62 TYPEINIT1(OReportModel,SdrModel);
64 //----------------------------------------------------------------------------
66 OReportModel::OReportModel(::reportdesign::OReportDefinition* _pReportDefinition) :
67 SdrModel(SvtPathOptions().GetPalettePath(),NULL,_pReportDefinition)
68 ,m_pController(NULL)
69 ,m_pReportDefinition(_pReportDefinition)
71 DBG_CTOR( rpt_OReportModel,0);
72 SetAllowShapePropertyChangeListener(true);
73 m_pUndoEnv = new OXUndoEnvironment(*this);
74 m_pUndoEnv->acquire();
75 SetSdrUndoFactory(new OReportUndoFactory);
77 // SvxFontNameToolBoxControl::RegisterControl(SID_ATTR_CHAR_FONT);
78 //SvxFontHeightToolBoxControl::RegisterControl(SID_ATTR_CHAR_FONTHEIGHT);
79 //SvxFontColorToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR);
80 //SvxFontColorExtToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR2);
81 //SvxFontColorExtToolBoxControl::RegisterControl(SID_ATTR_CHAR_COLOR_BACKGROUND);
82 //SvxColorToolBoxControl::RegisterControl(SID_BACKGROUND_COLOR);
85 //----------------------------------------------------------------------------
86 OReportModel::~OReportModel()
88 DBG_DTOR( rpt_OReportModel,0);
89 detachController();
90 m_pUndoEnv->release();
92 // -----------------------------------------------------------------------------
93 void OReportModel::detachController()
95 m_pReportDefinition = NULL;
96 m_pController = NULL;
97 m_pUndoEnv->EndListening( *this );
98 ClearUndoBuffer();
99 m_pUndoEnv->Clear(OXUndoEnvironment::Accessor());
101 //----------------------------------------------------------------------------
102 SdrPage* OReportModel::AllocPage(FASTBOOL /*bMasterPage*/)
104 DBG_CHKTHIS( rpt_OReportModel, 0);
105 OSL_ENSURE(0,"Who called me!");
106 return NULL;
109 //----------------------------------------------------------------------------
111 void OReportModel::SetChanged( sal_Bool bChanged )
113 SdrModel::SetChanged( bChanged );
114 SetModified( bChanged );
117 //----------------------------------------------------------------------------
119 Window* OReportModel::GetCurDocViewWin()
121 return 0;
124 //----------------------------------------------------------------------------
125 OXUndoEnvironment& OReportModel::GetUndoEnv()
127 return *m_pUndoEnv;
129 //----------------------------------------------------------------------------
130 void OReportModel::SetModified(sal_Bool _bModified)
132 if ( m_pController )
133 m_pController->setModified(_bModified);
135 // -----------------------------------------------------------------------------
136 SdrPage* OReportModel::RemovePage(USHORT nPgNum)
138 OReportPage* pPage = dynamic_cast<OReportPage*>(SdrModel::RemovePage(nPgNum));
139 //if ( pPage )
141 // m_pUndoEnv->RemoveSection(pPage);
143 return pPage;
145 // -----------------------------------------------------------------------------
146 OReportPage* OReportModel::createNewPage(const uno::Reference< report::XSection >& _xSection)
148 OReportPage* pPage = new OReportPage( *this ,_xSection);
149 InsertPage(pPage);
150 m_pUndoEnv->AddSection(_xSection);
151 return pPage;
153 // -----------------------------------------------------------------------------
154 OReportPage* OReportModel::getPage(const uno::Reference< report::XSection >& _xSection)
156 OReportPage* pPage = NULL;
157 USHORT nCount = GetPageCount();
158 for (USHORT i = 0; i < nCount && !pPage ; ++i)
160 OReportPage* pRptPage = PTR_CAST( OReportPage, GetPage(i) );
161 if ( pRptPage && pRptPage->getSection() == _xSection )
162 pPage = pRptPage;
164 return pPage;
166 // -----------------------------------------------------------------------------
167 SvxNumType OReportModel::GetPageNumType() const
169 uno::Reference< report::XReportDefinition > xReportDefinition( getReportDefinition() );
170 if ( xReportDefinition.is() )
171 return (SvxNumType)getStyleProperty<sal_Int16>(xReportDefinition,reportdesign::PROPERTY_NUMBERINGTYPE);
172 return SVX_ARABIC;
175 // -----------------------------------------------------------------------------
176 uno::Reference< report::XReportDefinition > OReportModel::getReportDefinition() const
178 uno::Reference< report::XReportDefinition > xReportDefinition = m_pReportDefinition;
179 OSL_ENSURE( xReportDefinition.is(), "OReportModel::getReportDefinition: invalid model at our controller!" );
180 return xReportDefinition;
182 // -----------------------------------------------------------------------------
183 uno::Reference< uno::XInterface > OReportModel::createUnoModel()
185 return uno::Reference< uno::XInterface >(getReportDefinition(),uno::UNO_QUERY);
187 // -----------------------------------------------------------------------------
188 uno::Reference< uno::XInterface > OReportModel::createShape(const ::rtl::OUString& aServiceSpecifier,uno::Reference< drawing::XShape >& _rShape,sal_Int32 nOrientation)
190 uno::Reference< uno::XInterface > xRet;
191 if ( _rShape.is() )
193 if ( aServiceSpecifier == SERVICE_FORMATTEDFIELD )
195 uno::Reference<report::XFormattedField> xProp = new OFormattedField(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape);
196 xRet = xProp;
197 if ( _rShape.is() )
198 throw uno::Exception();
199 xProp->setPropertyValue( PROPERTY_FORMATSSUPPLIER, uno::makeAny(uno::Reference< util::XNumberFormatsSupplier >(*m_pReportDefinition,uno::UNO_QUERY)) );
201 else if ( aServiceSpecifier == SERVICE_FIXEDTEXT)
203 xRet = static_cast<cppu::OWeakObject*>(new OFixedText(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
204 if ( _rShape.is() )
205 throw uno::Exception();
207 else if ( aServiceSpecifier == SERVICE_FIXEDLINE)
209 xRet = static_cast<cppu::OWeakObject*>(new OFixedLine(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,nOrientation));
210 if ( _rShape.is() )
211 throw uno::Exception();
213 else if ( aServiceSpecifier == SERVICE_IMAGECONTROL )
215 xRet = static_cast<cppu::OWeakObject*>(new OImageControl(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
216 if ( _rShape.is() )
217 throw uno::Exception();
219 else if ( aServiceSpecifier == SERVICE_REPORTDEFINITION )
221 xRet = static_cast<cppu::OWeakObject*>(new OReportDefinition(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape));
222 if ( _rShape.is() )
223 throw uno::Exception();
225 else if ( _rShape.is() )
227 xRet = static_cast<cppu::OWeakObject*>(new OShape(m_pReportDefinition->getContext(),m_pReportDefinition,_rShape,aServiceSpecifier));
228 if ( _rShape.is() )
229 throw uno::Exception();
232 return xRet;
234 //==================================================================
235 } //rptui
236 //==================================================================