LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdouno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 125 242 51.7 %
Date: 2012-08-25 Functions: 23 39 59.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 125 408 30.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svx/sdr/contact/viewcontactofunocontrol.hxx>
      30                 :            : #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
      31                 :            : #include <com/sun/star/container/XChild.hpp>
      32                 :            : #include <com/sun/star/awt/XWindow.hpp>
      33                 :            : #include <com/sun/star/awt/PosSize.hpp>
      34                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      35                 :            : #include <com/sun/star/io/XPersistObject.hpp>
      36                 :            : #include <com/sun/star/io/XOutputStream.hpp>
      37                 :            : #include <com/sun/star/io/XInputStream.hpp>
      38                 :            : #include <com/sun/star/io/XActiveDataSink.hpp>
      39                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      40                 :            : #include <com/sun/star/io/XObjectOutputStream.hpp>
      41                 :            : #include <com/sun/star/io/XObjectInputStream.hpp>
      42                 :            : #include <com/sun/star/util/XCloneable.hpp>
      43                 :            : #include <comphelper/processfactory.hxx>
      44                 :            : #include <comphelper/types.hxx>
      45                 :            : #include <vcl/pdfextoutdevdata.hxx>
      46                 :            : #include <svx/svdouno.hxx>
      47                 :            : #include <svx/svdpagv.hxx>
      48                 :            : #include <svx/svdmodel.hxx>
      49                 :            : #include "svx/svdglob.hxx"  // string cache
      50                 :            : #include "svx/svdstr.hrc"   // the object's name
      51                 :            : #include <svx/svdetc.hxx>
      52                 :            : #include <svx/svdview.hxx>
      53                 :            : #include <svx/svdorect.hxx>
      54                 :            : #include "svx/svdviter.hxx"
      55                 :            : #include <rtl/ref.hxx>
      56                 :            : #include <set>
      57                 :            : #include <memory>
      58                 :            : #include <svx/sdrpagewindow.hxx>
      59                 :            : #include <svx/sdrpaintwindow.hxx>
      60                 :            : #include <tools/diagnose_ex.h>
      61                 :            : #include <svx/svdograf.hxx>
      62                 :            : 
      63                 :            : using namespace ::com::sun::star;
      64                 :            : using namespace ::sdr::contact;
      65                 :            : 
      66                 :            : //************************************************************
      67                 :            : //   Defines
      68                 :            : //************************************************************
      69                 :            : 
      70                 :            : //************************************************************
      71                 :            : //   Helper class SdrControlEventListenerImpl
      72                 :            : //************************************************************
      73                 :            : #include <com/sun/star/lang/XEventListener.hpp>
      74                 :            : 
      75                 :            : #include <cppuhelper/implbase1.hxx>
      76                 :            : 
      77                 :            : // =============================================================================
      78         [ -  + ]:       1052 : class SdrControlEventListenerImpl : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
      79                 :            : {
      80                 :            : protected:
      81                 :            :     SdrUnoObj*                  pObj;
      82                 :            : 
      83                 :            : public:
      84                 :        534 :     SdrControlEventListenerImpl(SdrUnoObj* _pObj)
      85                 :        534 :     :   pObj(_pObj)
      86                 :        534 :     {}
      87                 :            : 
      88                 :            :     // XEventListener
      89                 :            :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
      90                 :            : 
      91                 :            :     void StopListening(const uno::Reference< lang::XComponent >& xComp);
      92                 :            :     void StartListening(const uno::Reference< lang::XComponent >& xComp);
      93                 :            : };
      94                 :            : 
      95                 :            : // XEventListener
      96                 :        526 : void SAL_CALL SdrControlEventListenerImpl::disposing( const ::com::sun::star::lang::EventObject& /*Source*/)
      97                 :            :     throw(::com::sun::star::uno::RuntimeException)
      98                 :            : {
      99         [ +  - ]:        526 :     if (pObj)
     100                 :            :     {
     101                 :        526 :         pObj->xUnoControlModel = NULL;
     102                 :            :     }
     103                 :        526 : }
     104                 :            : 
     105                 :          0 : void SdrControlEventListenerImpl::StopListening(const uno::Reference< lang::XComponent >& xComp)
     106                 :            : {
     107         [ #  # ]:          0 :     if (xComp.is())
     108         [ #  # ]:          0 :         xComp->removeEventListener(this);
     109                 :          0 : }
     110                 :            : 
     111                 :        533 : void SdrControlEventListenerImpl::StartListening(const uno::Reference< lang::XComponent >& xComp)
     112                 :            : {
     113         [ +  - ]:        533 :     if (xComp.is())
     114         [ +  - ]:        533 :         xComp->addEventListener(this);
     115                 :        533 : }
     116                 :            : 
     117                 :            : // =============================================================================
     118                 :       1060 : struct SAL_DLLPRIVATE SdrUnoObjDataHolder
     119                 :            : {
     120                 :            :     mutable ::rtl::Reference< SdrControlEventListenerImpl >
     121                 :            :                                     pEventListener;
     122                 :            : };
     123                 :            : 
     124                 :            : // =============================================================================
     125                 :            : namespace
     126                 :            : {
     127                 :        920 :     void lcl_ensureControlVisibility( SdrView* _pView, const SdrUnoObj* _pObject, bool _bVisible )
     128                 :            :     {
     129                 :            :         OSL_PRECOND( _pObject, "lcl_ensureControlVisibility: no object -> no survival!" );
     130                 :            : 
     131         [ +  - ]:        920 :         SdrPageView* pPageView = _pView ? _pView->GetSdrPageView() : NULL;
     132                 :            :         DBG_ASSERT( pPageView, "lcl_ensureControlVisibility: no view found!" );
     133         [ -  + ]:        920 :         if ( !pPageView )
     134                 :        920 :             return;
     135                 :            : 
     136                 :        920 :         ViewContact& rUnoControlContact( _pObject->GetViewContact() );
     137                 :            : 
     138         [ +  + ]:       1840 :         for ( sal_uInt32 i = 0; i < pPageView->PageWindowCount(); ++i )
     139                 :            :         {
     140                 :        920 :             const SdrPageWindow* pPageWindow = pPageView->GetPageWindow( i );
     141                 :            :             DBG_ASSERT( pPageWindow, "lcl_ensureControlVisibility: invalid PageViewWindow!" );
     142         [ -  + ]:        920 :             if ( !pPageWindow )
     143                 :          0 :                 continue;
     144                 :            : 
     145         [ +  + ]:        920 :             if ( !pPageWindow->HasObjectContact() )
     146                 :         46 :                 continue;
     147                 :            : 
     148                 :        874 :             ObjectContact& rPageViewContact( pPageWindow->GetObjectContact() );
     149                 :        874 :             const ViewObjectContact& rViewObjectContact( rUnoControlContact.GetViewObjectContact( rPageViewContact ) );
     150         [ -  + ]:        874 :             const ViewObjectContactOfUnoControl* pUnoControlContact = dynamic_cast< const ViewObjectContactOfUnoControl* >( &rViewObjectContact );
     151                 :            :             DBG_ASSERT( pUnoControlContact, "lcl_ensureControlVisibility: wrong ViewObjectContact type!" );
     152         [ -  + ]:        874 :             if ( !pUnoControlContact )
     153                 :          0 :                 continue;
     154                 :            : 
     155                 :        874 :             pUnoControlContact->ensureControlVisibility( _bVisible );
     156                 :            :         }
     157                 :            :     }
     158                 :            : }
     159                 :            : 
     160                 :            : //************************************************************
     161                 :            : //   SdrUnoObj
     162                 :            : //************************************************************
     163                 :            : 
     164 [ +  + ][ +  + ]:      91132 : TYPEINIT1(SdrUnoObj, SdrRectObj);
     165                 :            : 
     166                 :        534 : SdrUnoObj::SdrUnoObj(const String& rModelName, sal_Bool _bOwnUnoControlModel)
     167         [ +  - ]:        534 : :   m_pImpl( new SdrUnoObjDataHolder ),
     168 [ +  - ][ +  - ]:       1068 :     bOwnUnoControlModel( _bOwnUnoControlModel )
                 [ +  - ]
     169                 :            : {
     170                 :        534 :     bIsUnoObj = sal_True;
     171                 :            : 
     172 [ +  - ][ +  - ]:        534 :     m_pImpl->pEventListener = new SdrControlEventListenerImpl(this);
     173                 :            : 
     174                 :            :     // only an owner may create independently
     175         [ -  + ]:        534 :     if (rModelName.Len())
     176         [ #  # ]:          0 :         CreateUnoControlModel(rModelName);
     177                 :        534 : }
     178                 :            : 
     179                 :          0 : SdrUnoObj::SdrUnoObj(const String& rModelName,
     180                 :            :                      const uno::Reference< lang::XMultiServiceFactory >& rxSFac,
     181                 :            :                      sal_Bool _bOwnUnoControlModel)
     182         [ #  # ]:          0 : :   m_pImpl( new SdrUnoObjDataHolder ),
     183 [ #  # ][ #  # ]:          0 :     bOwnUnoControlModel( _bOwnUnoControlModel )
                 [ #  # ]
     184                 :            : {
     185                 :          0 :     bIsUnoObj = sal_True;
     186                 :            : 
     187 [ #  # ][ #  # ]:          0 :     m_pImpl->pEventListener = new SdrControlEventListenerImpl(this);
     188                 :            : 
     189                 :            :     // only an owner may create independently
     190         [ #  # ]:          0 :     if (rModelName.Len())
     191         [ #  # ]:          0 :         CreateUnoControlModel(rModelName,rxSFac);
     192                 :          0 : }
     193                 :            : 
     194 [ +  - ][ +  - ]:        526 : SdrUnoObj::~SdrUnoObj()
     195                 :            : {
     196                 :            :     try
     197                 :            :     {
     198                 :            :         // clean up the control model
     199         [ +  - ]:        526 :         uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
     200         [ +  + ]:        526 :         if (xComp.is())
     201                 :            :         {
     202                 :            :             // is the control model owned by its environment?
     203         [ +  - ]:        435 :             uno::Reference< container::XChild > xContent(xUnoControlModel, uno::UNO_QUERY);
     204 [ +  - ][ +  - ]:        435 :             if (xContent.is() && !xContent->getParent().is())
         [ +  - ][ +  - ]
                 [ +  - ]
           [ +  -  #  # ]
     205 [ +  - ][ +  - ]:        435 :                 xComp->dispose();
     206                 :            :             else
     207         [ #  # ]:        435 :                 m_pImpl->pEventListener->StopListening(xComp);
     208         [ #  # ]:        526 :         }
     209                 :            :     }
     210         [ #  # ]:          0 :     catch( const uno::Exception& )
     211                 :            :     {
     212                 :            :         OSL_FAIL( "SdrUnoObj::~SdrUnoObj: caught an exception!" );
     213                 :            :     }
     214 [ +  - ][ +  - ]:        526 :     delete m_pImpl;
     215         [ -  + ]:        526 : }
     216                 :            : 
     217                 :        533 : void SdrUnoObj::SetModel(SdrModel* pNewModel)
     218                 :            : {
     219                 :        533 :     SdrRectObj::SetModel(pNewModel);
     220                 :        533 : }
     221                 :            : 
     222                 :       1018 : void SdrUnoObj::SetPage(SdrPage* pNewPage)
     223                 :            : {
     224                 :       1018 :     SdrRectObj::SetPage(pNewPage);
     225                 :       1018 : }
     226                 :            : 
     227                 :          0 : void SdrUnoObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
     228                 :            : {
     229                 :          0 :     rInfo.bRotateFreeAllowed        =   sal_False;
     230                 :          0 :     rInfo.bRotate90Allowed          =   sal_False;
     231                 :          0 :     rInfo.bMirrorFreeAllowed        =   sal_False;
     232                 :          0 :     rInfo.bMirror45Allowed          =   sal_False;
     233                 :          0 :     rInfo.bMirror90Allowed          =   sal_False;
     234                 :          0 :     rInfo.bTransparenceAllowed = sal_False;
     235                 :          0 :     rInfo.bGradientAllowed = sal_False;
     236                 :          0 :     rInfo.bShearAllowed             =   sal_False;
     237                 :          0 :     rInfo.bEdgeRadiusAllowed        =   sal_False;
     238                 :          0 :     rInfo.bNoOrthoDesired           =   sal_False;
     239                 :          0 :     rInfo.bCanConvToPath            =   sal_False;
     240                 :          0 :     rInfo.bCanConvToPoly            =   sal_False;
     241                 :          0 :     rInfo.bCanConvToPathLineToArea  =   sal_False;
     242                 :          0 :     rInfo.bCanConvToPolyLineToArea  =   sal_False;
     243                 :          0 :     rInfo.bCanConvToContour = sal_False;
     244                 :          0 : }
     245                 :            : 
     246                 :          0 : sal_uInt16 SdrUnoObj::GetObjIdentifier() const
     247                 :            : {
     248                 :          0 :     return sal_uInt16(OBJ_UNO);
     249                 :            : }
     250                 :            : 
     251                 :        920 : void SdrUnoObj::SetContextWritingMode( const sal_Int16 _nContextWritingMode )
     252                 :            : {
     253                 :            :     try
     254                 :            :     {
     255 [ +  - ][ +  - ]:        920 :         uno::Reference< beans::XPropertySet > xModelProperties( GetUnoControlModel(), uno::UNO_QUERY_THROW );
     256         [ +  - ]:        920 :         xModelProperties->setPropertyValue(
     257                 :            :             ::rtl::OUString(  "ContextWritingMode"  ),
     258                 :            :             uno::makeAny( _nContextWritingMode )
     259 [ +  - ][ +  - ]:        920 :         );
                 [ #  # ]
     260                 :            :     }
     261                 :          0 :     catch( const uno::Exception& )
     262                 :            :     {
     263                 :            :         DBG_UNHANDLED_EXCEPTION();
     264                 :            :     }
     265                 :        920 : }
     266                 :            : 
     267                 :            : // ----------------------------------------------------------------------------
     268                 :            : namespace
     269                 :            : {
     270                 :            :     /** helper class to restore graphics at <awt::XView> object after <SdrUnoObj::Paint>
     271                 :            :         Restoration of graphics necessary to assure that paint on a window  */
     272                 :            :     class RestoreXViewGraphics
     273                 :            :     {
     274                 :            :         private:
     275                 :            :             uno::Reference< awt::XView >        m_rXView;
     276                 :            :             uno::Reference< awt::XGraphics >    m_rXGraphics;
     277                 :            : 
     278                 :            :         public:
     279                 :            :             RestoreXViewGraphics( const uno::Reference< awt::XView >& _rXView )
     280                 :            :             {
     281                 :            :                 m_rXView = _rXView;
     282                 :            :                 m_rXGraphics = m_rXView->getGraphics();
     283                 :            :             }
     284                 :            :             ~RestoreXViewGraphics()
     285                 :            :             {
     286                 :            :                 m_rXView->setGraphics( m_rXGraphics );
     287                 :            :             }
     288                 :            :     };
     289                 :            : }
     290                 :            : 
     291                 :        656 : void SdrUnoObj::TakeObjNameSingul(XubString& rName) const
     292                 :            : {
     293 [ +  - ][ +  - ]:        656 :     rName = ImpGetResStr(STR_ObjNameSingulUno);
                 [ +  - ]
     294                 :            : 
     295 [ +  - ][ +  - ]:        656 :     String aName( GetName() );
     296         [ -  + ]:        656 :     if(aName.Len())
     297                 :            :     {
     298         [ #  # ]:          0 :         rName += sal_Unicode(' ');
     299         [ #  # ]:          0 :         rName += sal_Unicode('\'');
     300         [ #  # ]:          0 :         rName += aName;
     301         [ #  # ]:          0 :         rName += sal_Unicode('\'');
     302         [ +  - ]:        656 :     }
     303                 :        656 : }
     304                 :            : 
     305                 :          2 : void SdrUnoObj::TakeObjNamePlural(XubString& rName) const
     306                 :            : {
     307         [ +  - ]:          2 :     rName = ImpGetResStr(STR_ObjNamePluralUno);
     308                 :          2 : }
     309                 :            : 
     310                 :          0 : SdrUnoObj* SdrUnoObj::Clone() const
     311                 :            : {
     312                 :          0 :     return CloneHelper< SdrUnoObj >();
     313                 :            : }
     314                 :            : 
     315                 :          0 : SdrUnoObj& SdrUnoObj::operator= (const SdrUnoObj& rObj)
     316                 :            : {
     317         [ #  # ]:          0 :     if( this == &rObj )
     318                 :          0 :         return *this;
     319         [ #  # ]:          0 :     SdrRectObj::operator= (rObj);
     320                 :            : 
     321                 :            :     // release the reference to the current control model
     322 [ #  # ][ #  # ]:          0 :     SetUnoControlModel( NULL );
     323                 :            : 
     324         [ #  # ]:          0 :     aUnoControlModelTypeName = rObj.aUnoControlModelTypeName;
     325         [ #  # ]:          0 :     aUnoControlTypeName = rObj.aUnoControlTypeName;
     326                 :            : 
     327                 :            :     // copy the uno control model
     328 [ #  # ][ #  # ]:          0 :     const uno::Reference< awt::XControlModel > xSourceControlModel( rObj.GetUnoControlModel(), uno::UNO_QUERY );
     329         [ #  # ]:          0 :     if ( xSourceControlModel.is() )
     330                 :            :     {
     331                 :            :         try
     332                 :            :         {
     333         [ #  # ]:          0 :             uno::Reference< util::XCloneable > xClone( xSourceControlModel, uno::UNO_QUERY_THROW );
     334 [ #  # ][ #  # ]:          0 :             xUnoControlModel.set( xClone->createClone(), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     335                 :            :         }
     336         [ #  # ]:          0 :         catch( const uno::Exception& )
     337                 :            :         {
     338                 :            :             DBG_UNHANDLED_EXCEPTION();
     339                 :            :         }
     340                 :            :     }
     341                 :            : 
     342                 :            :     // get service name of the control from the control model
     343         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY);
     344         [ #  # ]:          0 :     if (xSet.is())
     345                 :            :     {
     346 [ #  # ][ #  # ]:          0 :         uno::Any aValue( xSet->getPropertyValue( rtl::OUString("DefaultControl")) );
     347                 :          0 :         ::rtl::OUString aStr;
     348                 :            : 
     349         [ #  # ]:          0 :         if( aValue >>= aStr )
     350 [ #  # ][ #  # ]:          0 :             aUnoControlTypeName = String(aStr);
                 [ #  # ]
     351                 :            :     }
     352                 :            : 
     353         [ #  # ]:          0 :     uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
     354         [ #  # ]:          0 :     if (xComp.is())
     355         [ #  # ]:          0 :         m_pImpl->pEventListener->StartListening(xComp);
     356                 :          0 :     return *this;
     357                 :            : }
     358                 :            : 
     359                 :          0 : void SdrUnoObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
     360                 :            : {
     361                 :          0 :     SdrRectObj::NbcResize(rRef,xFact,yFact);
     362                 :            : 
     363 [ #  # ][ #  # ]:          0 :     if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0)
     364                 :            :     {
     365                 :            :         // small correctures
     366 [ #  # ][ #  # ]:          0 :         if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000)
     367                 :            :         {
     368                 :          0 :             aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom());
     369                 :            :         }
     370                 :            : 
     371                 :          0 :         aGeo.nDrehWink  = 0;
     372                 :          0 :         aGeo.nShearWink = 0;
     373                 :          0 :         aGeo.nSin       = 0.0;
     374                 :          0 :         aGeo.nCos       = 1.0;
     375                 :          0 :         aGeo.nTan       = 0.0;
     376                 :          0 :         SetRectsDirty();
     377                 :            :     }
     378                 :          0 : }
     379                 :            : 
     380                 :            : // -----------------------------------------------------------------------------
     381                 :            : 
     382                 :          6 : bool SdrUnoObj::hasSpecialDrag() const
     383                 :            : {
     384                 :            :     // no special drag; we have no rounding rect and
     385                 :            :     // do want frame handles
     386                 :          6 :     return false;
     387                 :            : }
     388                 :            : 
     389                 :          0 : bool SdrUnoObj::supportsFullDrag() const
     390                 :            : {
     391                 :            :     // overloaded to have the possibility to enable/disable in debug and
     392                 :            :     // to ckeck some things out. Current solution is working, so default is
     393                 :            :     // enabled
     394                 :            :     static bool bDoSupportFullDrag(true);
     395                 :            : 
     396                 :          0 :     return bDoSupportFullDrag;
     397                 :            : }
     398                 :            : 
     399                 :          0 : SdrObject* SdrUnoObj::getFullDragClone() const
     400                 :            : {
     401                 :          0 :     SdrObject* pRetval = 0;
     402                 :            :     static bool bHandleSpecial(false);
     403                 :            : 
     404         [ #  # ]:          0 :     if(bHandleSpecial)
     405                 :            :     {
     406                 :            :         // special handling for SdrUnoObj (FormControl). Create a SdrGrafObj
     407                 :            :         // for drag containing the graphical representation. This does not work too
     408                 :            :         // well, so the default is to simply clone
     409 [ #  # ][ #  # ]:          0 :         pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
                 [ #  # ]
     410                 :            :     }
     411                 :            :     else
     412                 :            :     {
     413                 :            :         // call parent (simply clone)
     414                 :          0 :         pRetval = SdrRectObj::getFullDragClone();
     415                 :            :     }
     416                 :            : 
     417                 :          0 :     return pRetval;
     418                 :            : }
     419                 :            : 
     420                 :            : // -----------------------------------------------------------------------------
     421                 :       1949 : void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer )
     422                 :            : {
     423 [ +  - ][ +  + ]:       1949 :     if ( GetLayer() == _nLayer )
     424                 :            :     {   // redundant call -> not interested in doing anything here
     425         [ +  - ]:        470 :         SdrRectObj::NbcSetLayer( _nLayer );
     426                 :       1949 :         return;
     427                 :            :     }
     428                 :            : 
     429                 :            :     // we need some special handling here in case we're moved from an invisible layer
     430                 :            :     // to a visible one, or vice versa
     431                 :            :     // (relative to a layer. Remember that the visibility of a layer is a view attribute
     432                 :            :     // - the same layer can be visible in one view, and invisible in another view, at the
     433                 :            :     // same time)
     434                 :            : 
     435                 :            :     // collect all views in which our old layer is visible
     436         [ +  - ]:       1479 :     ::std::set< SdrView* > aPreviouslyVisible;
     437                 :            : 
     438                 :            :     {
     439         [ +  - ]:       1479 :         SdrViewIter aIter( this );
     440 [ +  - ][ +  - ]:       1929 :         for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
                 [ +  + ]
     441         [ +  - ]:        450 :             aPreviouslyVisible.insert( pView );
     442                 :            :     }
     443                 :            : 
     444         [ +  - ]:       1479 :     SdrRectObj::NbcSetLayer( _nLayer );
     445                 :            : 
     446                 :            :     // collect all views in which our new layer is visible
     447         [ +  - ]:       1479 :     ::std::set< SdrView* > aNewlyVisible;
     448                 :            : 
     449                 :            :     {
     450         [ +  - ]:       1479 :         SdrViewIter aIter( this );
     451 [ +  - ][ +  - ]:       1949 :         for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
                 [ +  + ]
     452                 :            :         {
     453         [ +  - ]:        470 :             ::std::set< SdrView* >::const_iterator aPrevPos = aPreviouslyVisible.find( pView );
     454 [ +  - ][ -  + ]:        470 :             if ( aPreviouslyVisible.end() != aPrevPos )
     455                 :            :             {   // in pView, we were visible _before_ the layer change, and are
     456                 :            :                 // visible _after_ the layer change, too
     457                 :            :                 // -> we're not interested in this view at all
     458         [ #  # ]:          0 :                 aPreviouslyVisible.erase( aPrevPos );
     459                 :            :             }
     460                 :            :             else
     461                 :            :             {
     462                 :            :                 // in pView, we were visible _before_ the layer change, and are
     463                 :            :                 // _not_ visible after the layer change
     464                 :            :                 // => remember this view, as our visibility there changed
     465         [ +  - ]:        470 :                 aNewlyVisible.insert( pView );
     466                 :            :             }
     467                 :            :         }
     468                 :            :     }
     469                 :            : 
     470                 :            :     // now aPreviouslyVisible contains all views where we became invisible
     471         [ +  - ]:       1479 :     ::std::set< SdrView* >::const_iterator aLoopViews;
     472   [ +  -  +  - ]:       3858 :     for (   aLoopViews = aPreviouslyVisible.begin();
                 [ +  + ]
     473                 :       1929 :             aLoopViews != aPreviouslyVisible.end();
     474                 :            :             ++aLoopViews
     475                 :            :         )
     476                 :            :     {
     477 [ +  - ][ +  - ]:        450 :         lcl_ensureControlVisibility( *aLoopViews, this, false );
     478                 :            :     }
     479                 :            : 
     480                 :            :     // and aNewlyVisible all views where we became visible
     481   [ +  -  +  - ]:       3898 :     for (   aLoopViews = aNewlyVisible.begin();
                 [ +  + ]
     482                 :       1949 :             aLoopViews != aNewlyVisible.end();
     483                 :            :             ++aLoopViews
     484                 :            :         )
     485                 :            :     {
     486 [ +  - ][ +  - ]:        470 :         lcl_ensureControlVisibility( *aLoopViews, this, true );
     487                 :       1949 :     }
     488                 :            : }
     489                 :            : 
     490                 :          0 : void SdrUnoObj::CreateUnoControlModel(const String& rModelName)
     491                 :            : {
     492                 :            :     DBG_ASSERT(!xUnoControlModel.is(), "model already exists");
     493                 :            : 
     494         [ #  # ]:          0 :     aUnoControlModelTypeName = rModelName;
     495                 :            : 
     496                 :          0 :     uno::Reference< awt::XControlModel >   xModel;
     497         [ #  # ]:          0 :     uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
     498 [ #  # ][ #  # ]:          0 :     if (aUnoControlModelTypeName.Len() && xFactory.is() )
                 [ #  # ]
     499                 :            :     {
     500         [ #  # ]:          0 :         xModel = uno::Reference< awt::XControlModel >(xFactory->createInstance(
     501 [ #  # ][ #  # ]:          0 :             aUnoControlModelTypeName), uno::UNO_QUERY);
         [ #  # ][ #  # ]
     502                 :            : 
     503         [ #  # ]:          0 :         if (xModel.is())
     504         [ #  # ]:          0 :             SetChanged();
     505                 :            :     }
     506                 :            : 
     507         [ #  # ]:          0 :     SetUnoControlModel(xModel);
     508                 :          0 : }
     509                 :            : 
     510                 :          0 : void SdrUnoObj::CreateUnoControlModel(const String& rModelName,
     511                 :            :                                       const uno::Reference< lang::XMultiServiceFactory >& rxSFac)
     512                 :            : {
     513                 :            :     DBG_ASSERT(!xUnoControlModel.is(), "model already exists");
     514                 :            : 
     515         [ #  # ]:          0 :     aUnoControlModelTypeName = rModelName;
     516                 :            : 
     517                 :          0 :     uno::Reference< awt::XControlModel >   xModel;
     518 [ #  # ][ #  # ]:          0 :     if (aUnoControlModelTypeName.Len() && rxSFac.is() )
                 [ #  # ]
     519                 :            :     {
     520         [ #  # ]:          0 :         xModel = uno::Reference< awt::XControlModel >(rxSFac->createInstance(
     521 [ #  # ][ #  # ]:          0 :             aUnoControlModelTypeName), uno::UNO_QUERY);
         [ #  # ][ #  # ]
     522                 :            : 
     523         [ #  # ]:          0 :         if (xModel.is())
     524         [ #  # ]:          0 :             SetChanged();
     525                 :            :     }
     526                 :            : 
     527         [ #  # ]:          0 :     SetUnoControlModel(xModel);
     528                 :          0 : }
     529                 :            : 
     530                 :        533 : void SdrUnoObj::SetUnoControlModel( const uno::Reference< awt::XControlModel >& xModel)
     531                 :            : {
     532         [ -  + ]:        533 :     if (xUnoControlModel.is())
     533                 :            :     {
     534         [ #  # ]:          0 :         uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
     535         [ #  # ]:          0 :         if (xComp.is())
     536         [ #  # ]:          0 :             m_pImpl->pEventListener->StopListening(xComp);
     537                 :            :     }
     538                 :            : 
     539         [ +  - ]:        533 :     xUnoControlModel = xModel;
     540                 :            : 
     541                 :            :     // control model has to contain service name of the control
     542         [ +  - ]:        533 :     if (xUnoControlModel.is())
     543                 :            :     {
     544         [ +  - ]:        533 :         uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY);
     545         [ +  - ]:        533 :         if (xSet.is())
     546                 :            :         {
     547 [ +  - ][ +  - ]:        533 :             uno::Any aValue( xSet->getPropertyValue(String("DefaultControl", osl_getThreadTextEncoding())) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     548                 :        533 :             ::rtl::OUString aStr;
     549         [ +  - ]:        533 :             if( aValue >>= aStr )
     550 [ +  - ][ +  - ]:        533 :                 aUnoControlTypeName = String(aStr);
                 [ +  - ]
     551                 :            :         }
     552                 :            : 
     553         [ +  - ]:        533 :         uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY);
     554         [ +  - ]:        533 :         if (xComp.is())
     555         [ +  - ]:        533 :             m_pImpl->pEventListener->StartListening(xComp);
     556                 :            :     }
     557                 :            : 
     558                 :            :     // invalidate all ViewObject contacts
     559                 :        533 :     ViewContactOfUnoControl* pVC = NULL;
     560 [ +  - ][ +  - ]:        533 :     if ( impl_getViewContact( pVC ) )
     561                 :            :     {
     562                 :            :         // flushViewObjectContacts() removes all existing VOCs for the local DrawHierarchy. This
     563                 :            :         // is always allowed since they will be re-created on demand (and with the changed model)
     564 [ +  - ][ +  - ]:        533 :         GetViewContact().flushViewObjectContacts(true);
     565                 :            :     }
     566                 :        533 : }
     567                 :            : 
     568                 :            : //------------------------------------------------------------------------
     569                 :        194 : uno::Reference< awt::XControl > SdrUnoObj::GetUnoControl(const SdrView& _rView, const OutputDevice& _rOut) const
     570                 :            : {
     571                 :        194 :     uno::Reference< awt::XControl > xControl;
     572                 :            : 
     573                 :        194 :     SdrPageView* pPageView = _rView.GetSdrPageView();
     574                 :            :     OSL_ENSURE( GetPage() == pPageView->GetPage(), "SdrUnoObj::GetUnoControl: This object is not displayed in that particular view!" );
     575 [ -  + ][ +  - ]:        194 :     if ( GetPage() != pPageView->GetPage() )
     576         [ #  # ]:          0 :         return NULL;
     577                 :            : 
     578 [ +  - ][ +  - ]:        194 :     SdrPageWindow* pPageWindow = pPageView ? pPageView->FindPageWindow( _rOut ) : NULL;
     579                 :            :     OSL_ENSURE( pPageWindow, "SdrUnoObj::GetUnoControl: did not find my SdrPageWindow!" );
     580         [ -  + ]:        194 :     if ( !pPageWindow )
     581         [ #  # ]:          0 :         return NULL;
     582                 :            : 
     583 [ +  - ][ +  - ]:        194 :     ViewObjectContact& rViewObjectContact( GetViewContact().GetViewObjectContact( pPageWindow->GetObjectContact() ) );
                 [ +  - ]
     584         [ -  + ]:        194 :     ViewObjectContactOfUnoControl* pUnoContact = dynamic_cast< ViewObjectContactOfUnoControl* >( &rViewObjectContact );
     585                 :            :     OSL_ENSURE( pUnoContact, "SdrUnoObj::GetUnoControl: wrong contact type!" );
     586         [ +  - ]:        194 :     if ( pUnoContact )
     587 [ +  - ][ +  - ]:        194 :         xControl = pUnoContact->getControl();
     588                 :            : 
     589                 :        194 :     return xControl;
     590                 :            : }
     591                 :            : 
     592                 :            : //------------------------------------------------------------------------
     593                 :          0 : uno::Reference< awt::XControl > SdrUnoObj::GetTemporaryControlForWindow(
     594                 :            :     const Window& _rWindow, uno::Reference< awt::XControlContainer >& _inout_ControlContainer ) const
     595                 :            : {
     596                 :          0 :     uno::Reference< awt::XControl > xControl;
     597                 :            : 
     598                 :          0 :     ViewContactOfUnoControl* pVC = NULL;
     599 [ #  # ][ #  # ]:          0 :     if ( impl_getViewContact( pVC ) )
     600 [ #  # ][ #  # ]:          0 :         xControl = pVC->getTemporaryControlForWindow( _rWindow, _inout_ControlContainer );
     601                 :            : 
     602                 :          0 :     return xControl;
     603                 :            : }
     604                 :            : 
     605                 :            : //------------------------------------------------------------------------
     606                 :        533 : bool SdrUnoObj::impl_getViewContact( ViewContactOfUnoControl*& _out_rpContact ) const
     607                 :            : {
     608                 :        533 :     ViewContact& rViewContact( GetViewContact() );
     609         [ -  + ]:        533 :     _out_rpContact = dynamic_cast< ViewContactOfUnoControl* >( &rViewContact );
     610                 :            :     DBG_ASSERT( _out_rpContact, "SdrUnoObj::impl_getViewContact: could not find my ViewContact!" );
     611                 :        533 :     return ( _out_rpContact != NULL );
     612                 :            : }
     613                 :            : 
     614                 :            : //------------------------------------------------------------------------
     615                 :        533 : ::sdr::contact::ViewContact* SdrUnoObj::CreateObjectSpecificViewContact()
     616                 :            : {
     617         [ +  - ]:        533 :   return new ::sdr::contact::ViewContactOfUnoControl( *this );
     618                 :            : }
     619                 :            : 
     620                 :            : 
     621                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10