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