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