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