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

Generated by: LCOV version 1.11