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