LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/form - fmobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 302 36.4 %
Date: 2013-07-09 Functions: 21 32 65.6 %
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             : 
      20             : #include "fmobj.hxx"
      21             : #include "fmprop.hrc"
      22             : #include "fmvwimp.hxx"
      23             : #include "fmpgeimp.hxx"
      24             : #include "svx/fmresids.hrc"
      25             : #include "svx/fmview.hxx"
      26             : #include "svx/fmglob.hxx"
      27             : #include "svx/fmpage.hxx"
      28             : #include "editeng/editeng.hxx"
      29             : #include "svx/svdovirt.hxx"
      30             : #include "svx/fmmodel.hxx"
      31             : #include "svx/dialmgr.hxx"
      32             : 
      33             : #include <com/sun/star/awt/XDevice.hpp>
      34             : #include <com/sun/star/awt/XControlContainer.hpp>
      35             : #include <com/sun/star/form/Forms.hpp>
      36             : #include <com/sun/star/io/XPersistObject.hpp>
      37             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      38             : #include <com/sun/star/util/XCloneable.hpp>
      39             : #include "svx/fmtools.hxx"
      40             : 
      41             : #include <tools/shl.hxx>
      42             : #include <comphelper/property.hxx>
      43             : #include <comphelper/processfactory.hxx>
      44             : #include <toolkit/awt/vclxdevice.hxx>
      45             : #include <vcl/svapp.hxx>
      46             : #include <tools/diagnose_ex.h>
      47             : 
      48             : using namespace ::com::sun::star::io;
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::awt;
      51             : using namespace ::com::sun::star::lang;
      52             : using namespace ::com::sun::star::util;
      53             : using namespace ::com::sun::star::form;
      54             : using namespace ::com::sun::star::beans;
      55             : using namespace ::com::sun::star::script;
      56             : using namespace ::com::sun::star::container;
      57             : using namespace ::svxform;
      58             : 
      59       73294 : TYPEINIT1(FmFormObj, SdrUnoObj);
      60             : DBG_NAME(FmFormObj);
      61             : //------------------------------------------------------------------
      62           0 : FmFormObj::FmFormObj(const OUString& rModelName)
      63             :           :SdrUnoObj                ( rModelName    )
      64             :           ,m_nPos                   ( -1            )
      65           0 :           ,m_pLastKnownRefDevice    ( NULL          )
      66             : {
      67             :     DBG_CTOR(FmFormObj, NULL);
      68             : 
      69             :     // normally, this is done in SetUnoControlModel, but if the call happened in the base class ctor,
      70             :     // then our incarnation of it was not called (since we were not constructed at this time).
      71           0 :     impl_checkRefDevice_nothrow( true );
      72           0 : }
      73             : 
      74             : //------------------------------------------------------------------
      75         301 : FmFormObj::FmFormObj()
      76             :           :SdrUnoObj                ( String()  )
      77             :           ,m_nPos                   ( -1        )
      78         301 :           ,m_pLastKnownRefDevice    ( NULL      )
      79             : {
      80             :     DBG_CTOR(FmFormObj, NULL);
      81         301 : }
      82             : 
      83             : //------------------------------------------------------------------
      84         894 : FmFormObj::~FmFormObj()
      85             : {
      86             :     DBG_DTOR(FmFormObj, NULL);
      87             : 
      88         298 :     if (m_xEnvironmentHistory.is())
      89           0 :         m_xEnvironmentHistory->dispose();
      90             : 
      91         298 :     m_xEnvironmentHistory = NULL;
      92         298 :     m_aEventsHistory.realloc(0);
      93         596 : }
      94             : 
      95             : //------------------------------------------------------------------
      96           5 : void FmFormObj::SetObjEnv(const Reference< XIndexContainer > & xForm, const sal_Int32 nIdx,
      97             :                           const Sequence< ScriptEventDescriptor >& rEvts)
      98             : {
      99           5 :     m_xParent = xForm;
     100           5 :     aEvts     = rEvts;
     101           5 :     m_nPos    = nIdx;
     102           5 : }
     103             : 
     104             : //------------------------------------------------------------------
     105         476 : void FmFormObj::ClearObjEnv()
     106             : {
     107         476 :     m_xParent.clear();
     108         476 :     aEvts.realloc( 0 );
     109         476 :     m_nPos = -1;
     110         476 : }
     111             : 
     112             : //------------------------------------------------------------------
     113         607 : void FmFormObj::impl_checkRefDevice_nothrow( bool _force )
     114             : {
     115         607 :     const FmFormModel* pFormModel = PTR_CAST( FmFormModel, GetModel() );
     116         607 :     if ( !pFormModel || !pFormModel->ControlsUseRefDevice() )
     117         722 :         return;
     118             : 
     119         253 :     OutputDevice* pCurrentRefDevice = pFormModel ? pFormModel->GetRefDevice() : NULL;
     120         253 :     if ( ( m_pLastKnownRefDevice == pCurrentRefDevice ) && !_force )
     121           6 :         return;
     122             : 
     123         247 :     Reference< XControlModel > xControlModel( GetUnoControlModel() );
     124         247 :     if ( !xControlModel.is() )
     125           3 :         return;
     126             : 
     127         244 :     m_pLastKnownRefDevice = pCurrentRefDevice;
     128         244 :     if ( m_pLastKnownRefDevice == NULL )
     129           5 :         return;
     130             : 
     131             :     try
     132             :     {
     133         239 :         Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY_THROW );
     134         478 :         Reference< XPropertySetInfo > xPropertyInfo( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
     135             : 
     136         239 :         static const OUString sRefDevicePropName( "ReferenceDevice" );
     137         239 :         if ( xPropertyInfo->hasPropertyByName( sRefDevicePropName ) )
     138             :         {
     139         142 :             VCLXDevice* pUnoRefDevice = new VCLXDevice;
     140         142 :             pUnoRefDevice->SetOutputDevice( m_pLastKnownRefDevice );
     141         142 :             Reference< XDevice > xRefDevice( pUnoRefDevice );
     142         142 :             xModelProps->setPropertyValue( sRefDevicePropName, makeAny( xRefDevice ) );
     143         239 :         }
     144             :     }
     145           0 :     catch( const Exception& )
     146             :     {
     147             :         DBG_UNHANDLED_EXCEPTION();
     148         239 :     }
     149             : }
     150             : 
     151             : //------------------------------------------------------------------
     152         242 : void FmFormObj::impl_isolateControlModel_nothrow()
     153             : {
     154             :     try
     155             :     {
     156         242 :         Reference< XChild > xControlModel( GetUnoControlModel(), UNO_QUERY );
     157         242 :         if ( xControlModel.is() )
     158             :         {
     159         225 :             Reference< XIndexContainer> xParent( xControlModel->getParent(), UNO_QUERY );
     160         225 :             if ( xParent.is() )
     161             :             {
     162         215 :                 sal_Int32 nPos = getElementPos( xParent.get(), xControlModel );
     163         215 :                 xParent->removeByIndex( nPos );
     164         225 :             }
     165         242 :         }
     166             :     }
     167           0 :     catch( const Exception& )
     168             :     {
     169             :         DBG_UNHANDLED_EXCEPTION();
     170             :     }
     171         242 : }
     172             : 
     173             : //------------------------------------------------------------------
     174         546 : void FmFormObj::SetPage(SdrPage* _pNewPage)
     175             : {
     176         546 :     if ( GetPage() == _pNewPage )
     177             :     {
     178           2 :         SdrUnoObj::SetPage(_pNewPage);
     179         246 :         return;
     180             :     }
     181             : 
     182         544 :     FmFormPage* pOldFormPage = PTR_CAST( FmFormPage, GetPage() );
     183         544 :     if ( pOldFormPage )
     184         242 :         pOldFormPage->GetImpl().formObjectRemoved( *this );
     185             : 
     186         544 :     FmFormPage* pNewFormPage = PTR_CAST( FmFormPage, _pNewPage );
     187         544 :     if ( !pNewFormPage )
     188             :     {   // Maybe it makes sense to create an environment history here : if somebody set's our page to NULL, and we have a valid page before,
     189             :         // me may want to remember our place within the old page. For this we could create a new m_xEnvironmentHistory to store it.
     190             :         // So the next SetPage with a valid new page would restore that environment within the new page.
     191             :         // But for the original Bug (#57300#) we don't need that, so I omit it here. Maybe this will be implemented later.
     192         242 :         impl_isolateControlModel_nothrow();
     193         242 :         SdrUnoObj::SetPage(_pNewPage);
     194         242 :         return;
     195             :     }
     196             : 
     197         302 :     Reference< css::form::XForms >      xNewPageForms = pNewFormPage->GetForms( true );
     198         604 :     Reference< XIndexContainer >        xNewParent;
     199         604 :     Sequence< ScriptEventDescriptor>    aNewEvents;
     200             : 
     201             :     // calc the new parent for my model (within the new page's forms hierarchy)
     202             :     // do we have a history ? (from :Clone)
     203         302 :     if ( m_xEnvironmentHistory.is() )
     204             :     {
     205             :         // the element in m_xEnvironmentHistory which is equivalent to my new parent (which (perhaps) has to be created within _pNewPage->GetForms)
     206             :         // is the right-most element in the tree.
     207           0 :         Reference< XIndexContainer > xRightMostLeaf( m_xEnvironmentHistory, UNO_QUERY_THROW );
     208             :         try
     209             :         {
     210           0 :             while ( xRightMostLeaf->getCount() )
     211             :             {
     212             :                 xRightMostLeaf.set(
     213           0 :                     xRightMostLeaf->getByIndex( xRightMostLeaf->getCount() - 1 ),
     214             :                     UNO_QUERY_THROW
     215           0 :                 );
     216             :             }
     217             : 
     218           0 :             xNewParent.set( ensureModelEnv( xRightMostLeaf, xNewPageForms ), UNO_QUERY_THROW );
     219             : 
     220             :             // we successfully cloned the environment in m_xEnvironmentHistory, so we can use m_aEventsHistory
     221             :             // (which describes the events of our model at the moment m_xEnvironmentHistory was created)
     222           0 :             aNewEvents = m_aEventsHistory;
     223             :         }
     224           0 :         catch( const Exception& )
     225             :         {
     226             :             DBG_UNHANDLED_EXCEPTION();
     227           0 :         }
     228             :     }
     229             : 
     230         302 :     if ( !xNewParent.is() )
     231             :     {
     232             :         // are we a valid part of our current page forms ?
     233         302 :         Reference< XIndexContainer > xOldForms;
     234         302 :         if ( pOldFormPage )
     235           0 :             xOldForms.set( pOldFormPage->GetForms(), UNO_QUERY_THROW );
     236             : 
     237         302 :         if ( xOldForms.is() )
     238             :         {
     239             :             // search (upward from our model) for xOldForms
     240           0 :             Reference< XChild > xSearch( GetUnoControlModel(), UNO_QUERY );
     241           0 :             while (xSearch.is())
     242             :             {
     243           0 :                 if ( xSearch == xOldForms )
     244           0 :                     break;
     245           0 :                 xSearch = Reference< XChild >( xSearch->getParent(), UNO_QUERY );
     246             :             }
     247           0 :             if ( xSearch.is() ) // implies xSearch == xOldForms, which means we're a valid part of our current page forms hierarchy
     248             :             {
     249           0 :                 Reference< XChild >  xMeAsChild( GetUnoControlModel(), UNO_QUERY );
     250           0 :                 xNewParent.set( ensureModelEnv( xMeAsChild->getParent(), xNewPageForms ), UNO_QUERY );
     251             : 
     252           0 :                 if ( xNewParent.is() )
     253             :                 {
     254             :                     try
     255             :                     {
     256             :                         // transfer the events from our (model's) parent to the new (model's) parent, too
     257           0 :                         Reference< XEventAttacherManager >  xEventManager(xMeAsChild->getParent(), UNO_QUERY);
     258           0 :                         Reference< XIndexAccess >  xManagerAsIndex(xEventManager, UNO_QUERY);
     259           0 :                         if (xManagerAsIndex.is())
     260             :                         {
     261           0 :                             sal_Int32 nPos = getElementPos(xManagerAsIndex, xMeAsChild);
     262           0 :                             if (nPos >= 0)
     263           0 :                                 aNewEvents = xEventManager->getScriptEvents(nPos);
     264             :                         }
     265             :                         else
     266           0 :                             aNewEvents = aEvts;
     267             :                     }
     268           0 :                     catch( const Exception& )
     269             :                     {
     270             :                         DBG_UNHANDLED_EXCEPTION();
     271             :                     }
     272           0 :                 }
     273           0 :             }
     274         302 :         }
     275             :     }
     276             : 
     277             :     // now set the page
     278         302 :     SdrUnoObj::SetPage(_pNewPage);
     279             : 
     280             :     // place my model within the new parent container
     281         302 :     if (xNewParent.is())
     282             :     {
     283           0 :         Reference< XFormComponent >  xMeAsFormComp(GetUnoControlModel(), UNO_QUERY);
     284           0 :         if (xMeAsFormComp.is())
     285             :         {
     286             :             // check if I have another parent (and remove me, if necessary)
     287           0 :             Reference< XIndexContainer >  xOldParent(xMeAsFormComp->getParent(), UNO_QUERY);
     288           0 :             if (xOldParent.is())
     289             :             {
     290           0 :                 sal_Int32 nPos = getElementPos(xOldParent, xMeAsFormComp);
     291           0 :                 if (nPos > -1)
     292           0 :                     xOldParent->removeByIndex(nPos);
     293             :             }
     294             :             // and insert into the new container
     295           0 :             xNewParent->insertByIndex(xNewParent->getCount(), makeAny(xMeAsFormComp));
     296             : 
     297             :             // transfer the events
     298           0 :             if (aNewEvents.getLength())
     299             :             {
     300             :                 try
     301             :                 {
     302           0 :                     Reference< XEventAttacherManager >  xEventManager(xNewParent, UNO_QUERY);
     303           0 :                     Reference< XIndexAccess >  xManagerAsIndex(xEventManager, UNO_QUERY);
     304           0 :                     if (xManagerAsIndex.is())
     305             :                     {
     306           0 :                         sal_Int32 nPos = getElementPos(xManagerAsIndex, xMeAsFormComp);
     307             :                         DBG_ASSERT(nPos >= 0, "FmFormObj::SetPage : inserted but not present ?");
     308           0 :                         xEventManager->registerScriptEvents(nPos, aNewEvents);
     309           0 :                     }
     310             :                 }
     311           0 :                 catch( const Exception& )
     312             :                 {
     313             :                     DBG_UNHANDLED_EXCEPTION();
     314             :                 }
     315             : 
     316           0 :             }
     317           0 :         }
     318             :     }
     319             : 
     320             :     // delete my history
     321         302 :     if (m_xEnvironmentHistory.is())
     322           0 :         m_xEnvironmentHistory->dispose();
     323             : 
     324         302 :     m_xEnvironmentHistory = NULL;
     325         302 :     m_aEventsHistory.realloc(0);
     326             : 
     327         302 :     if ( pNewFormPage )
     328         604 :         pNewFormPage->GetImpl().formObjectInserted( *this );
     329             : }
     330             : 
     331             : //------------------------------------------------------------------
     332        4566 : sal_uInt32 FmFormObj::GetObjInventor()   const
     333             : {
     334        4566 :     return FmFormInventor;
     335             : }
     336             : 
     337             : //------------------------------------------------------------------
     338         160 : sal_uInt16 FmFormObj::GetObjIdentifier() const
     339             : {
     340         160 :     return OBJ_UNO;
     341             : }
     342             : 
     343             : //------------------------------------------------------------------
     344           0 : void FmFormObj::clonedFrom(const FmFormObj* _pSource)
     345             : {
     346             :     DBG_ASSERT(_pSource != NULL, "FmFormObj::clonedFrom : invalid source !");
     347           0 :     if (m_xEnvironmentHistory.is())
     348           0 :        m_xEnvironmentHistory->dispose();
     349             : 
     350           0 :     m_xEnvironmentHistory = NULL;
     351           0 :     m_aEventsHistory.realloc(0);
     352             : 
     353           0 :     Reference< XChild >  xSourceAsChild(_pSource->GetUnoControlModel(), UNO_QUERY);
     354           0 :     if (!xSourceAsChild.is())
     355           0 :         return;
     356             : 
     357           0 :     Reference< XInterface >  xSourceContainer = xSourceAsChild->getParent();
     358             : 
     359           0 :     m_xEnvironmentHistory = css::form::Forms::create( comphelper::getProcessComponentContext() );
     360             : 
     361           0 :     ensureModelEnv(xSourceContainer, m_xEnvironmentHistory);
     362           0 :     m_aEventsHistory = aEvts;
     363             :         // if we we're clone there was a call to operator=, so aEvts are excatly the events we need here ...
     364             : }
     365             : 
     366             : //------------------------------------------------------------------
     367           0 : FmFormObj* FmFormObj::Clone() const
     368             : {
     369           0 :     FmFormObj* pFormObject = CloneHelper< FmFormObj >();
     370             :     DBG_ASSERT(pFormObject != NULL, "FmFormObj::Clone : invalid clone !");
     371           0 :     if (pFormObject)
     372           0 :         pFormObject->clonedFrom(this);
     373             : 
     374           0 :     return pFormObject;
     375             : }
     376             : 
     377             : //------------------------------------------------------------------
     378           7 : void FmFormObj::NbcReformatText()
     379             : {
     380           7 :     impl_checkRefDevice_nothrow( false );
     381           7 :     SdrUnoObj::NbcReformatText();
     382           7 : }
     383             : 
     384             : //------------------------------------------------------------------
     385           0 : FmFormObj& FmFormObj::operator= (const FmFormObj& rObj)
     386             : {
     387           0 :     if( this == &rObj )
     388           0 :         return *this;
     389           0 :     SdrUnoObj::operator= (rObj);
     390             : 
     391             :     // liegt das UnoControlModel in einer Eventumgebung,
     392             :     // dann koennen noch Events zugeordnet sein
     393           0 :     Reference< XFormComponent >  xContent(rObj.xUnoControlModel, UNO_QUERY);
     394           0 :     if (xContent.is())
     395             :     {
     396           0 :         Reference< XEventAttacherManager >  xManager(xContent->getParent(), UNO_QUERY);
     397           0 :         Reference< XIndexAccess >  xManagerAsIndex(xManager, UNO_QUERY);
     398           0 :         if (xManagerAsIndex.is())
     399             :         {
     400           0 :             sal_Int32 nPos = getElementPos( xManagerAsIndex, xContent );
     401           0 :             if ( nPos >= 0 )
     402           0 :                 aEvts = xManager->getScriptEvents( nPos );
     403           0 :         }
     404             :     }
     405             :     else
     406           0 :         aEvts = rObj.aEvts;
     407           0 :     return *this;
     408             : }
     409             : 
     410             : //------------------------------------------------------------------
     411             : namespace
     412             : {
     413           0 :     OUString lcl_getFormComponentAccessPath(const Reference< XInterface >& _xElement, Reference< XInterface >& _rTopLevelElement)
     414             :     {
     415           0 :         Reference< ::com::sun::star::form::XFormComponent> xChild(_xElement, UNO_QUERY);
     416           0 :         Reference< ::com::sun::star::container::XIndexAccess> xParent;
     417           0 :         if (xChild.is())
     418           0 :             xParent = Reference< ::com::sun::star::container::XIndexAccess>(xChild->getParent(), UNO_QUERY);
     419             : 
     420             :         // while the current content is a form
     421           0 :         String sReturn;
     422           0 :         String sCurrentIndex;
     423           0 :         while (xChild.is())
     424             :         {
     425             :             // get the content's relative pos within it's parent container
     426           0 :             sal_Int32 nPos = getElementPos(xParent, xChild);
     427             : 
     428             :             // prepend this current relaive pos
     429           0 :             sCurrentIndex = OUString::number(nPos);
     430           0 :             if (sReturn.Len() != 0)
     431             :             {
     432           0 :                 sCurrentIndex += '\\';
     433           0 :                 sCurrentIndex += sReturn;
     434             :             }
     435             : 
     436           0 :             sReturn = sCurrentIndex;
     437             : 
     438             :             // travel up
     439           0 :             if (::comphelper::query_interface((Reference< XInterface >)xParent,xChild))
     440           0 :                 xParent = Reference< ::com::sun::star::container::XIndexAccess>(xChild->getParent(), UNO_QUERY);
     441             :         }
     442             : 
     443           0 :         _rTopLevelElement = xParent;
     444           0 :         return sReturn;
     445             :     }
     446             : }
     447             : 
     448             : //------------------------------------------------------------------
     449           0 : Reference< XInterface >  FmFormObj::ensureModelEnv(const Reference< XInterface > & _rSourceContainer, const Reference<css::form::XForms>& _rTopLevelDestContainer)
     450             : {
     451           0 :     Reference< XInterface >  xTopLevelSouce;
     452           0 :     OUString sAccessPath = lcl_getFormComponentAccessPath(_rSourceContainer, xTopLevelSouce);
     453           0 :     if (!xTopLevelSouce.is())
     454             :         // something went wrong, maybe _rSourceContainer isn't part of a valid forms hierarchy
     455           0 :         return Reference< XInterface > ();
     456             : 
     457           0 :     Reference< XIndexContainer >  xDestContainer(_rTopLevelDestContainer, UNO_QUERY_THROW);
     458           0 :     Reference< XIndexContainer >  xSourceContainer(xTopLevelSouce, UNO_QUERY);
     459             :     DBG_ASSERT(xSourceContainer.is(), "FmFormObj::ensureModelEnv : the top level source is invalid !");
     460             : 
     461           0 :     sal_Int32 nTokIndex = 0;
     462           0 :     do
     463             :     {
     464           0 :         OUString aToken = sAccessPath.getToken( 0, '\\', nTokIndex );
     465           0 :         sal_uInt16 nIndex = (sal_uInt16)aToken.toInt32();
     466             : 
     467             :         // get the DSS of the source form (we have to find an aquivalent for)
     468             :         DBG_ASSERT(nIndex<xSourceContainer->getCount(), "FmFormObj::ensureModelEnv : invalid access path !");
     469           0 :         Reference< XPropertySet >  xSourceForm;
     470           0 :         xSourceContainer->getByIndex(nIndex) >>= xSourceForm;
     471             :         DBG_ASSERT(xSourceForm.is(), "FmFormObj::ensureModelEnv : invalid source form !");
     472             : 
     473           0 :         Any aSrcCursorSource, aSrcCursorSourceType, aSrcDataSource;
     474             :         DBG_ASSERT(::comphelper::hasProperty(FM_PROP_COMMAND, xSourceForm) && ::comphelper::hasProperty(FM_PROP_COMMANDTYPE, xSourceForm)
     475             :             && ::comphelper::hasProperty(FM_PROP_DATASOURCE, xSourceForm), "FmFormObj::ensureModelEnv : invalid access path or invalid form (missing props) !");
     476             :             // the parent access path should refer to a row set
     477             :         try
     478             :         {
     479           0 :             aSrcCursorSource        = xSourceForm->getPropertyValue(FM_PROP_COMMAND);
     480           0 :             aSrcCursorSourceType    = xSourceForm->getPropertyValue(FM_PROP_COMMANDTYPE);
     481           0 :             aSrcDataSource          = xSourceForm->getPropertyValue(FM_PROP_DATASOURCE);
     482             :         }
     483           0 :         catch(Exception&)
     484             :         {
     485             :             OSL_FAIL("FmFormObj::ensureModelEnv : could not retrieve a source DSS !");
     486             :         }
     487             : 
     488             : 
     489             :         // calc the number of (source) form siblings with the same DSS
     490           0 :         Reference< XPropertySet >  xCurrentSourceForm, xCurrentDestForm;
     491           0 :         sal_Int16 nCurrentSourceIndex = 0, nCurrentDestIndex = 0;
     492           0 :         while (nCurrentSourceIndex <= nIndex)
     493             :         {
     494           0 :             sal_Bool bEqualDSS = sal_False;
     495           0 :             while (!bEqualDSS)  // (we don't have to check nCurrentSourceIndex here : it's bound by nIndex)
     496             :             {
     497           0 :                 xSourceContainer->getByIndex(nCurrentSourceIndex) >>= xCurrentSourceForm;
     498             :                 DBG_ASSERT(xCurrentSourceForm.is(), "FmFormObj::ensureModelEnv : invalid form ancestor (2) !");
     499           0 :                 bEqualDSS = sal_False;
     500           0 :                 if (::comphelper::hasProperty(FM_PROP_DATASOURCE, xCurrentSourceForm))
     501             :                 {   // it is a form
     502             :                     try
     503             :                     {
     504           0 :                         if  (   ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_COMMAND), aSrcCursorSource)
     505           0 :                             &&  ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_COMMANDTYPE), aSrcCursorSourceType)
     506           0 :                             &&  ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_DATASOURCE), aSrcDataSource)
     507             :                             )
     508             :                         {
     509           0 :                             bEqualDSS = sal_True;
     510             :                         }
     511             :                     }
     512           0 :                     catch(Exception&)
     513             :                     {
     514             :                         OSL_FAIL("FmFormObj::ensureModelEnv : exception while getting a sibling's DSS !");
     515             :                     }
     516             : 
     517             :                 }
     518           0 :                 ++nCurrentSourceIndex;
     519             :             }
     520             : 
     521             :             DBG_ASSERT(bEqualDSS, "FmFormObj::ensureModelEnv : found no source form !");
     522             :             // ??? at least the nIndex-th one should have been found ???
     523             : 
     524             :             // now search the next one with the given DSS (within the destination container)
     525           0 :             bEqualDSS = sal_False;
     526           0 :             while (!bEqualDSS && (nCurrentDestIndex < xDestContainer->getCount()))
     527             :             {
     528           0 :                 xDestContainer->getByIndex(nCurrentDestIndex) >>= xCurrentDestForm;
     529             :                 DBG_ASSERT(xCurrentDestForm.is(), "FmFormObj::ensureModelEnv : invalid destination form !");
     530           0 :                 bEqualDSS = sal_False;
     531           0 :                 if (::comphelper::hasProperty(FM_PROP_DATASOURCE, xCurrentDestForm))
     532             :                 {   // it is a form
     533             :                     try
     534             :                     {
     535           0 :                         if  (   ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_COMMAND), aSrcCursorSource)
     536           0 :                             &&  ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_COMMANDTYPE), aSrcCursorSourceType)
     537           0 :                             &&  ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_DATASOURCE), aSrcDataSource)
     538             :                             )
     539             :                         {
     540           0 :                             bEqualDSS = sal_True;
     541             :                         }
     542             :                     }
     543           0 :                     catch(Exception&)
     544             :                     {
     545             :                         OSL_FAIL("FmFormObj::ensureModelEnv : exception while getting a destination DSS !");
     546             :                     }
     547             : 
     548             :                 }
     549           0 :                 ++nCurrentDestIndex;
     550             :             }
     551             : 
     552           0 :             if (!bEqualDSS)
     553             :             {   // There is at least one more source form with the given DSS than destination forms are.
     554             :                 // correct this ...
     555             :                 try
     556             :                 {
     557             :                     // create and insert (into the destination) a copy of the form
     558             :                     xCurrentDestForm.set(
     559           0 :                         ::comphelper::getProcessServiceFactory()->createInstance("com.sun.star.form.component.DataForm"),
     560           0 :                         UNO_QUERY_THROW );
     561           0 :                     ::comphelper::copyProperties( xCurrentSourceForm, xCurrentDestForm );
     562             : 
     563             :                     DBG_ASSERT(nCurrentDestIndex == xDestContainer->getCount(), "FmFormObj::ensureModelEnv : something went wrong with the numbers !");
     564           0 :                     xDestContainer->insertByIndex(nCurrentDestIndex, makeAny(xCurrentDestForm));
     565             : 
     566           0 :                     ++nCurrentDestIndex;
     567             :                         // like nCurrentSourceIndex, nCurrentDestIndex now points 'behind' the form it actally means
     568             :                 }
     569           0 :                 catch(Exception&)
     570             :                 {
     571             :                     OSL_FAIL("FmFormObj::ensureModelEnv : something went seriously wrong while creating a new form !");
     572             :                     // no more options anymore ...
     573           0 :                     return Reference< XInterface > ();
     574             :                 }
     575             : 
     576             :             }
     577             :         }
     578             : 
     579             :         // now xCurrentDestForm is a form equivalent to xSourceForm (which means they have the same DSS and the same number
     580             :         // of left siblings with the same DSS, which counts for all their ancestors, too)
     581             : 
     582             :         // go down
     583           0 :         xDestContainer = Reference< XIndexContainer > (xCurrentDestForm, UNO_QUERY);
     584           0 :         xSourceContainer = Reference< XIndexContainer > (xSourceForm, UNO_QUERY);
     585           0 :         DBG_ASSERT(xDestContainer.is() && xSourceContainer.is(), "FmFormObj::ensureModelEnv : invalid container !");
     586             :     }
     587           0 :     while ( nTokIndex >= 0 );
     588             : 
     589           0 :     return xDestContainer;
     590             : }
     591             : 
     592             : //------------------------------------------------------------------
     593         300 : void FmFormObj::SetModel( SdrModel* _pNewModel )
     594             : {
     595         300 :     SdrUnoObj::SetModel( _pNewModel );
     596         300 :     impl_checkRefDevice_nothrow();
     597         300 : }
     598             : 
     599             : //------------------------------------------------------------------
     600           1 : FmFormObj* FmFormObj::GetFormObject( SdrObject* _pSdrObject )
     601             : {
     602           1 :     FmFormObj* pFormObject = dynamic_cast< FmFormObj* >( _pSdrObject );
     603           1 :     if ( !pFormObject )
     604             :     {
     605           1 :         SdrVirtObj* pVirtualObject = dynamic_cast< SdrVirtObj* >( _pSdrObject );
     606           1 :         if ( pVirtualObject )
     607           0 :             pFormObject = dynamic_cast< FmFormObj* >( &pVirtualObject->ReferencedObj() );
     608             :     }
     609           1 :     return pFormObject;
     610             : }
     611             : 
     612             : //------------------------------------------------------------------
     613           0 : const FmFormObj* FmFormObj::GetFormObject( const SdrObject* _pSdrObject )
     614             : {
     615           0 :     const FmFormObj* pFormObject = dynamic_cast< const FmFormObj* >( _pSdrObject );
     616           0 :     if ( !pFormObject )
     617             :     {
     618           0 :         const SdrVirtObj* pVirtualObject = dynamic_cast< const SdrVirtObj* >( _pSdrObject );
     619           0 :         if ( pVirtualObject )
     620           0 :             pFormObject = dynamic_cast< const FmFormObj* >( &pVirtualObject->GetReferencedObj() );
     621             :     }
     622           0 :     return pFormObject;
     623             : }
     624             : 
     625             : //------------------------------------------------------------------
     626         300 : void FmFormObj::SetUnoControlModel( const Reference< com::sun::star::awt::XControlModel >& _rxModel )
     627             : {
     628         300 :     SdrUnoObj::SetUnoControlModel( _rxModel );
     629             : 
     630         300 :     FmFormPage* pFormPage = PTR_CAST( FmFormPage, GetPage() );
     631         300 :     if ( pFormPage )
     632          29 :         pFormPage->GetImpl().formModelAssigned( *this );
     633             : 
     634         300 :     impl_checkRefDevice_nothrow( true );
     635         300 : }
     636             : 
     637             : //------------------------------------------------------------------
     638           0 : bool FmFormObj::EndCreate( SdrDragStat& rStat, SdrCreateCmd eCmd )
     639             : {
     640           0 :     bool bResult = SdrUnoObj::EndCreate(rStat, eCmd);
     641           0 :     if ( bResult && SDRCREATE_FORCEEND == eCmd && rStat.GetView() )
     642             :     {
     643           0 :         if ( pPage )
     644             :         {
     645           0 :             FmFormPage& rPage = dynamic_cast< FmFormPage& >( *pPage );
     646             : 
     647             :             try
     648             :             {
     649           0 :                 Reference< XFormComponent >  xContent( xUnoControlModel, UNO_QUERY_THROW );
     650           0 :                 Reference< XForm > xParentForm( xContent->getParent(), UNO_QUERY );
     651             : 
     652           0 :                 Reference< XIndexContainer > xFormToInsertInto;
     653             : 
     654           0 :                 if ( !xParentForm.is() )
     655             :                 {   // model is not yet part of a form component hierachy
     656           0 :                     xParentForm.set( rPage.GetImpl().findPlaceInFormComponentHierarchy( xContent ), UNO_SET_THROW );
     657           0 :                     xFormToInsertInto.set( xParentForm, UNO_QUERY_THROW );
     658             :                 }
     659             : 
     660           0 :                 rPage.GetImpl().setUniqueName( xContent, xParentForm );
     661             : 
     662           0 :                 if ( xFormToInsertInto.is() )
     663           0 :                     xFormToInsertInto->insertByIndex( xFormToInsertInto->getCount(), makeAny( xContent ) );
     664             :             }
     665           0 :             catch( const Exception& )
     666             :             {
     667             :                 DBG_UNHANDLED_EXCEPTION();
     668             :             }
     669             :         }
     670             : 
     671           0 :         FmFormView* pView( dynamic_cast< FmFormView* >( rStat.GetView() ) );
     672           0 :         FmXFormView* pViewImpl = pView ? pView->GetImpl() : NULL;
     673             :         OSL_ENSURE( pViewImpl, "FmFormObj::EndCreate: no view!?" );
     674           0 :         if ( pViewImpl )
     675           0 :             pViewImpl->onCreatedFormObject( *this );
     676             :     }
     677           0 :     return bResult;
     678             : }
     679             : 
     680             : //------------------------------------------------------------------------------
     681           0 : void FmFormObj::BrkCreate( SdrDragStat& rStat )
     682             : {
     683           0 :     SdrUnoObj::BrkCreate( rStat );
     684           0 :     impl_isolateControlModel_nothrow();
     685           0 : }
     686             : 
     687             : // -----------------------------------------------------------------------------
     688             : // #i70852# overload Layer interface to force to FormColtrol layer
     689             : 
     690       21655 : SdrLayerID FmFormObj::GetLayer() const
     691             : {
     692             :     // #i72535#
     693             :     // i70852 was too radical, in SW obects (and thus, FormControls, too)
     694             :     // get moved to invisible layers to hide them (e.g. in hidden sections).
     695             :     // This means that form controls ARE allowed to be on other layers than
     696             :     // the form control layer ATM and that being member of form control layer
     697             :     // is no criteria to find all FormControls of a document.
     698             :     // To fix, use parent functionality
     699       21655 :     return SdrUnoObj::GetLayer();
     700             : }
     701             : 
     702        1038 : void FmFormObj::NbcSetLayer(SdrLayerID nLayer)
     703             : {
     704             :     // #i72535#
     705             :     // See above. To fix, use parent functionality
     706        1038 :     return SdrUnoObj::NbcSetLayer(nLayer);
     707         258 : }
     708             : 
     709             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10