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 #include "precompiled_reportdesign.hxx" 24 #include "RptPage.hxx" 25 #include "RptModel.hxx" 26 #include "Section.hxx" 27 #include "RptObject.hxx" 28 #include <svx/unoapi.hxx> 29 #include <svx/unoshape.hxx> 30 #include "ReportDrawPage.hxx" 31 32 namespace rptui 33 { 34 using namespace ::com::sun::star; 35 TYPEINIT1( OReportPage, SdrPage ); 36 37 //---------------------------------------------------------------------------- 38 DBG_NAME( rpt_OReportPage ) 39 OReportPage::OReportPage( OReportModel& _rModel 40 ,const uno::Reference< report::XSection >& _xSection 41 ,FASTBOOL bMasterPage ) 42 :SdrPage( _rModel, bMasterPage ) 43 ,rModel(_rModel) 44 ,m_xSection(_xSection) 45 ,m_bSpecialInsertMode(false) 46 { 47 DBG_CTOR( rpt_OReportPage,NULL); 48 } 49 50 //---------------------------------------------------------------------------- 51 52 OReportPage::OReportPage( const OReportPage& rPage ) 53 :SdrPage( rPage ) 54 ,rModel(rPage.rModel) 55 ,m_xSection(rPage.m_xSection) 56 ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode) 57 ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList) 58 { 59 DBG_CTOR( rpt_OReportPage,NULL); 60 } 61 62 //---------------------------------------------------------------------------- 63 64 OReportPage::~OReportPage() 65 { 66 DBG_DTOR( rpt_OReportPage,NULL); 67 } 68 69 //---------------------------------------------------------------------------- 70 71 SdrPage* OReportPage::Clone() const 72 { 73 DBG_CHKTHIS( rpt_OReportPage,NULL); 74 return new OReportPage( *this ); 75 } 76 77 //---------------------------------------------------------------------------- 78 sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject) 79 { 80 DBG_CHKTHIS( rpt_OReportPage,NULL); 81 sal_uLong nCount = GetObjCount(); 82 sal_uLong i = 0; 83 for (; i < nCount; ++i) 84 { 85 OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i)); 86 OSL_ENSURE(pObj,"Invalid object found!"); 87 if ( pObj && pObj->getReportComponent() == _xObject ) 88 { 89 break; 90 } 91 } // for (; i < nCount; ++i) 92 return i; 93 } 94 //---------------------------------------------------------------------------- 95 void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject) 96 { 97 DBG_CHKTHIS( rpt_OReportPage,NULL); 98 sal_uLong nPos = getIndexOf(_xObject); 99 if ( nPos < GetObjCount() ) 100 { 101 OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos)); 102 OSL_ENSURE(pBase,"Why is this not a OObjectBase?"); 103 if ( pBase ) 104 pBase->EndListening(); 105 /*delete */RemoveObject(nPos); 106 } 107 } 108 // ----------------------------------------------------------------------------- 109 SdrObject* OReportPage::RemoveObject(sal_uLong nObjNum) 110 { 111 SdrObject* pObj = SdrPage::RemoveObject(nObjNum); 112 if (getSpecialMode()) 113 { 114 return pObj; 115 } 116 117 // this code is evil, but what else shall I do 118 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection); 119 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY); 120 pSection->notifyElementRemoved(xShape); 121 if (pObj->ISA(OUnoObject)) 122 { 123 OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj); 124 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY); 125 if ( xChild.is() ) 126 xChild->setParent(NULL); 127 } 128 return pObj; 129 } 130 //---------------------------------------------------------------------------- 131 //namespace 132 //{ 133 // ::rtl::OUString lcl_getControlName(const uno::Reference< lang::XServiceInfo >& _xServiceInfo) 134 // { 135 // if ( _xServiceInfo->supportsService( SERVICE_FIXEDTEXT )) 136 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText")); 137 // if ( _xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD )) 138 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FormattedField")); 139 // if ( _xServiceInfo->supportsService( SERVICE_IMAGECONTROL)) 140 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.DatabaseImageControl")); 141 // 142 // return ::rtl::OUString(); 143 // } 144 //} 145 //---------------------------------------------------------------------------- 146 void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject) 147 { 148 DBG_CHKTHIS( rpt_OReportPage,NULL); 149 OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!"); 150 if ( !_xObject.is() ) // || !m_pView ) 151 return; 152 sal_uLong nPos = getIndexOf(_xObject); 153 if ( nPos < GetObjCount() ) 154 return; // Object already in list 155 156 SvxShape* pShape = SvxShape::getImplementation( _xObject ); 157 OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL; 158 OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" ); 159 if ( pObject ) 160 pObject->StartListening(); 161 } 162 // ----------------------------------------------------------------------------- 163 uno::Reference< report::XSection > OReportPage::getSection() const 164 { 165 return m_xSection; 166 } 167 // ----------------------------------------------------------------------------- 168 uno::Reference< uno::XInterface > OReportPage::createUnoPage() 169 { 170 return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) ); 171 } 172 // ----------------------------------------------------------------------------- 173 void OReportPage::removeTempObject(SdrObject *_pToRemoveObj) 174 { 175 if (_pToRemoveObj) 176 { 177 for (sal_uLong i=0;i<GetObjCount();i++) 178 { 179 SdrObject *aObj = GetObj(i); 180 if (aObj && aObj == _pToRemoveObj) 181 { 182 SdrObject* pObject = RemoveObject(i); 183 (void)pObject; 184 break; 185 // delete pObject; 186 } 187 } 188 } 189 } 190 191 void OReportPage::resetSpecialMode() 192 { 193 const sal_Bool bChanged = rModel.IsChanged(); 194 ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin(); 195 ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end(); 196 197 for (; aIter != aEnd; ++aIter) 198 { 199 removeTempObject(*aIter); 200 } 201 m_aTemporaryObjectList.clear(); 202 rModel.SetChanged(bChanged); 203 204 m_bSpecialInsertMode = false; 205 } 206 // ----------------------------------------------------------------------------- 207 void OReportPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason) 208 { 209 SdrPage::NbcInsertObject(pObj, nPos, pReason); 210 211 OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj ); 212 if (getSpecialMode()) 213 { 214 m_aTemporaryObjectList.push_back(pObj); 215 return; 216 } 217 218 if ( pUnoObj ) 219 { 220 pUnoObj->CreateMediator(); 221 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY); 222 if ( xChild.is() && !xChild->getParent().is() ) 223 xChild->setParent(m_xSection); 224 } 225 226 // this code is evil, but what else shall I do 227 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection); 228 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY); 229 pSection->notifyElementAdded(xShape); 230 231 //// check if we are a shape 232 //uno::Reference<beans::XPropertySet> xProp(xShape,uno::UNO_QUERY); 233 //if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID"))) ) 234 //{ 235 // // use MimeConfigurationHelper::GetStringClassIDRepresentation(MimeConfigurationHelper::GetSequenceClassID(SO3_SCH_OLE_EMBED_CLASSID_8)) 236 // xProp->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID")),uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("12dcae26-281f-416f-a234-c3086127382e")))); 237 //} 238 239 // now that the shape is inserted into its structures, we can allow the OObjectBase 240 // to release the reference to it 241 OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj ); 242 OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" ); 243 if ( pObjectBase ) 244 pObjectBase->releaseUnoShape(); 245 } 246 //============================================================================ 247 } // rptui 248 //============================================================================ 249