LCOV - code coverage report
Current view: top level - reportdesign/source/core/sdr - RptPage.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 95 1.1 %
Date: 2015-06-13 12:38:46 Functions: 2 21 9.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include "RptPage.hxx"
      20             : #include "RptModel.hxx"
      21             : #include "Section.hxx"
      22             : #include "RptObject.hxx"
      23             : #include <svx/unoapi.hxx>
      24             : #include <svx/unoshape.hxx>
      25             : #include "ReportDrawPage.hxx"
      26             : 
      27             : namespace rptui
      28             : {
      29             : using namespace ::com::sun::star;
      30           0 : TYPEINIT1( OReportPage, SdrPage );
      31             : 
      32             : 
      33           0 : OReportPage::OReportPage( OReportModel& _rModel
      34             :                          ,const uno::Reference< report::XSection >& _xSection
      35             :                          ,bool bMasterPage )
      36             :     :SdrPage( _rModel, bMasterPage )
      37             :     ,rModel(_rModel)
      38             :     ,m_xSection(_xSection)
      39           0 :      ,m_bSpecialInsertMode(false)
      40             : {
      41           0 : }
      42             : 
      43             : 
      44             : 
      45           0 : OReportPage::OReportPage( const OReportPage& rPage )
      46             :     :SdrPage( rPage )
      47             :     ,rModel(rPage.rModel)
      48             :      ,m_xSection(rPage.m_xSection)
      49             :      ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
      50           0 :      ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
      51             : {
      52           0 : }
      53             : 
      54             : 
      55             : 
      56           0 : OReportPage::~OReportPage()
      57             : {
      58           0 : }
      59             : 
      60             : 
      61             : 
      62           0 : SdrPage* OReportPage::Clone() const
      63             : {
      64           0 :     return Clone(0);
      65             : }
      66             : 
      67           0 : SdrPage* OReportPage::Clone( SdrModel* const pNewModel ) const
      68             : {
      69           0 :     OReportPage *const pNewPage = new OReportPage( *this );
      70           0 :     OReportModel* pReportModel = 0;
      71           0 :     if ( pNewModel )
      72             :     {
      73           0 :         pReportModel = dynamic_cast<OReportModel*>( pNewModel );
      74             :         assert( pReportModel );
      75             :     }
      76           0 :     pNewPage->lateInit( *this, pReportModel );
      77           0 :     return pNewPage;
      78             : }
      79             : 
      80             : 
      81           0 : sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
      82             : {
      83           0 :     const size_t nCount = GetObjCount();
      84           0 :     size_t i = 0;
      85           0 :     for (; i < nCount; ++i)
      86             :     {
      87           0 :         OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
      88             :         OSL_ENSURE(pObj,"Invalid object found!");
      89           0 :         if ( pObj && pObj->getReportComponent() == _xObject )
      90             :         {
      91           0 :             break;
      92             :         }
      93             :     }
      94           0 :     return static_cast<sal_uLong>(i);
      95             : }
      96             : 
      97           0 : void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
      98             : {
      99           0 :     sal_uLong nPos = getIndexOf(_xObject);
     100           0 :     if ( nPos < GetObjCount() )
     101             :     {
     102           0 :         OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
     103             :         OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
     104           0 :         if ( pBase )
     105           0 :             pBase->EndListening();
     106           0 :         RemoveObject(nPos);
     107             :     }
     108           0 : }
     109             : 
     110           0 : SdrObject* OReportPage::RemoveObject(size_t nObjNum)
     111             : {
     112           0 :     SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
     113           0 :     if (getSpecialMode())
     114             :     {
     115           0 :         return pObj;
     116             :     }
     117             : 
     118             :     // this code is evil, but what else shall I do
     119           0 :     reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
     120           0 :     uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
     121           0 :     pSection->notifyElementRemoved(xShape);
     122           0 :     if (pObj->ISA(OUnoObject))
     123             :     {
     124           0 :         OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
     125           0 :         uno::Reference< container::XChild> xChild(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
     126           0 :         if ( xChild.is() )
     127           0 :             xChild->setParent(NULL);
     128             :     }
     129           0 :     return pObj;
     130             : }
     131             : 
     132           0 : void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
     133             : {
     134             :     OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
     135           0 :     if ( !_xObject.is() )
     136           0 :         return;
     137           0 :     sal_uLong nPos = getIndexOf(_xObject);
     138           0 :     if ( nPos < GetObjCount() )
     139           0 :         return; // Object already in list
     140             : 
     141           0 :     SvxShape* pShape = SvxShape::getImplementation( _xObject );
     142           0 :     OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL;
     143             :     OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
     144           0 :     if ( pObject )
     145           0 :         pObject->StartListening();
     146             : }
     147             : 
     148             : 
     149           0 : uno::Reference< uno::XInterface > OReportPage::createUnoPage()
     150             : {
     151           0 :     return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
     152             : }
     153             : 
     154           0 : void OReportPage::removeTempObject(SdrObject *_pToRemoveObj)
     155             : {
     156           0 :     if (_pToRemoveObj)
     157             :     {
     158           0 :         for (size_t i=0; i<GetObjCount(); ++i)
     159             :         {
     160           0 :             SdrObject *aObj = GetObj(i);
     161           0 :             if (aObj && aObj == _pToRemoveObj)
     162             :             {
     163           0 :                 SdrObject* pObject = RemoveObject(i);
     164             :                 (void)pObject;
     165           0 :                 break;
     166             :             }
     167             :         }
     168             :     }
     169           0 : }
     170             : 
     171           0 : void OReportPage::resetSpecialMode()
     172             : {
     173           0 :     const bool bChanged = rModel.IsChanged();
     174           0 :     ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin();
     175           0 :     ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end();
     176             : 
     177           0 :     for (; aIter != aEnd; ++aIter)
     178             :     {
     179           0 :          removeTempObject(*aIter);
     180             :     }
     181           0 :     m_aTemporaryObjectList.clear();
     182           0 :     rModel.SetChanged(bChanged);
     183             : 
     184           0 :     m_bSpecialInsertMode = false;
     185           0 : }
     186             : 
     187           0 : void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos, const SdrInsertReason* pReason)
     188             : {
     189           0 :     SdrPage::NbcInsertObject(pObj, nPos, pReason);
     190             : 
     191           0 :     OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
     192           0 :     if (getSpecialMode())
     193             :     {
     194           0 :         m_aTemporaryObjectList.push_back(pObj);
     195           0 :         return;
     196             :     }
     197             : 
     198           0 :     if ( pUnoObj )
     199             :     {
     200           0 :         pUnoObj->CreateMediator();
     201           0 :         uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
     202           0 :         if ( xChild.is() && !xChild->getParent().is() )
     203           0 :             xChild->setParent(m_xSection);
     204             :     }
     205             : 
     206             :     // this code is evil, but what else shall I do
     207           0 :     reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
     208           0 :     uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
     209           0 :     pSection->notifyElementAdded(xShape);
     210             : 
     211             :     // now that the shape is inserted into its structures, we can allow the OObjectBase
     212             :     // to release the reference to it
     213           0 :     OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
     214             :     OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
     215           0 :     if ( pObjectBase )
     216           0 :         pObjectBase->releaseUnoShape();
     217             : }
     218             : 
     219           3 : } // rptui
     220             : 
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11