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