bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / form / navigatortreemodel.cxx
blobc8d5326cae1d8ca5516785549ef7951b6677a538
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/dialmgr.hxx>
21 #include <svx/fmshell.hxx>
22 #include <svx/fmmodel.hxx>
23 #include <svx/fmpage.hxx>
24 #include <svx/svditer.hxx>
25 #include <svx/svdogrp.hxx>
27 #include <fmprop.hxx>
29 #include <fmundo.hxx>
30 #include <fmexpl.hxx>
31 #include <svx/strings.hrc>
32 #include <fmshimp.hxx>
33 #include <fmobj.hxx>
34 #include <o3tl/safeint.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <com/sun/star/container/XContainer.hpp>
38 #include <comphelper/types.hxx>
41 namespace svxform
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::form;
49 using namespace ::com::sun::star::awt;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::script;
52 using namespace ::com::sun::star::sdb;
54 OFormComponentObserver::OFormComponentObserver(NavigatorTreeModel* _pModel)
55 :m_pNavModel(_pModel)
56 ,m_nLocks(0)
57 ,m_bCanUndo(true)
61 // XPropertyChangeListener
63 void SAL_CALL OFormComponentObserver::disposing(const EventObject& Source)
65 Remove( Source.Source );
69 void SAL_CALL OFormComponentObserver::propertyChange(const PropertyChangeEvent& evt)
71 if( !m_pNavModel ) return;
72 if( evt.PropertyName != FM_PROP_NAME ) return;
74 Reference< XFormComponent > xFormComponent(evt.Source, UNO_QUERY);
75 Reference< XForm > xForm(evt.Source, UNO_QUERY);
77 FmEntryData* pEntryData( nullptr );
78 if( xForm.is() )
79 pEntryData = m_pNavModel->FindData( xForm, m_pNavModel->GetRootList() );
80 else if( xFormComponent.is() )
81 pEntryData = m_pNavModel->FindData( xFormComponent, m_pNavModel->GetRootList() );
83 if( pEntryData )
85 OUString aNewName = ::comphelper::getString(evt.NewValue);
86 pEntryData->SetText( aNewName );
87 FmNavNameChangedHint aNameChangedHint( pEntryData, aNewName );
88 m_pNavModel->Broadcast( aNameChangedHint );
92 // XContainerListener
94 void SAL_CALL OFormComponentObserver::elementInserted(const ContainerEvent& evt)
96 if (IsLocked() || !m_pNavModel)
97 return;
99 // insert no Undoaction
100 m_bCanUndo = false;
102 Reference< XInterface > xTemp;
103 evt.Element >>= xTemp;
104 Insert(xTemp, ::comphelper::getINT32(evt.Accessor));
106 m_bCanUndo = true;
110 void OFormComponentObserver::Insert(const Reference< XInterface > & xIface, sal_Int32 nIndex)
112 Reference< XForm > xForm(xIface, UNO_QUERY);
113 if (xForm.is())
115 m_pNavModel->InsertForm(xForm, sal_uInt32(nIndex));
116 Reference< XIndexContainer > xContainer(xForm, UNO_QUERY);
117 Reference< XInterface > xTemp;
118 for (sal_Int32 i = 0; i < xContainer->getCount(); i++)
120 xContainer->getByIndex(i) >>= xTemp;
121 Insert(xTemp, i);
124 else
126 Reference< XFormComponent > xFormComp(xIface, UNO_QUERY);
127 if (xFormComp.is())
128 m_pNavModel->InsertFormComponent(xFormComp, sal_uInt32(nIndex));
133 void SAL_CALL OFormComponentObserver::elementReplaced(const ContainerEvent& evt)
135 if (IsLocked() || !m_pNavModel)
136 return;
138 m_bCanUndo = false;
140 // delete EntryData
141 Reference< XFormComponent > xReplaced;
142 evt.ReplacedElement >>= xReplaced;
143 FmEntryData* pEntryData = m_pNavModel->FindData(xReplaced, m_pNavModel->GetRootList());
144 if (pEntryData)
146 if (dynamic_cast<const FmControlData*>( pEntryData) != nullptr)
148 Reference< XFormComponent > xComp;
149 evt.Element >>= xComp;
150 DBG_ASSERT(xComp.is(), "OFormComponentObserver::elementReplaced : invalid argument !");
151 // FmControlData should be coupled with XFormComponent
152 m_pNavModel->ReplaceFormComponent(xReplaced, xComp);
154 else if (dynamic_cast<const FmFormData*>( pEntryData) != nullptr)
156 OSL_FAIL("replacing forms not implemented yet !");
160 m_bCanUndo = true;
164 void OFormComponentObserver::Remove( const css::uno::Reference< css::uno::XInterface >& _rxElement )
166 if (IsLocked() || !m_pNavModel)
167 return;
169 m_bCanUndo = false;
172 // delete EntryData
173 FmEntryData* pEntryData = m_pNavModel->FindData( _rxElement, m_pNavModel->GetRootList() );
174 if (pEntryData)
175 m_pNavModel->Remove(pEntryData);
177 m_bCanUndo = true;
181 void SAL_CALL OFormComponentObserver::elementRemoved(const ContainerEvent& evt)
183 Reference< XInterface > xElement;
184 evt.Element >>= xElement;
185 Remove( xElement );
188 NavigatorTreeModel::NavigatorTreeModel()
189 :m_pFormShell(nullptr)
190 ,m_pFormPage(nullptr)
191 ,m_pFormModel(nullptr)
193 m_pPropChangeList = new OFormComponentObserver(this);
194 m_pRootList.reset( new FmEntryDataList() );
197 NavigatorTreeModel::~NavigatorTreeModel()
200 // unregister Listener
201 if( m_pFormShell)
203 FmFormModel* pFormModel = m_pFormShell->GetFormModel();
204 if( pFormModel && IsListening(*pFormModel))
205 EndListening( *pFormModel );
207 if (IsListening(*m_pFormShell))
208 EndListening(*m_pFormShell);
211 Clear();
212 m_pRootList.reset();
213 m_pPropChangeList->ReleaseModel();
217 void NavigatorTreeModel::SetModified()
219 if( !m_pFormShell ) return;
220 SfxObjectShell* pObjShell = m_pFormShell->GetFormModel()->GetObjectShell();
221 if( !pObjShell ) return;
222 pObjShell->SetModified();
226 void NavigatorTreeModel::Clear()
228 Reference< css::form::XForms > xForms( GetForms());
229 if(xForms.is())
230 xForms->removeContainerListener(m_pPropChangeList);
233 // delete RootList
234 GetRootList()->clear();
237 // notify UI
238 FmNavClearedHint aClearedHint;
239 Broadcast( aClearedHint );
243 Reference< css::form::XForms > NavigatorTreeModel::GetForms() const
245 if( !m_pFormShell || !m_pFormShell->GetCurPage())
246 return nullptr;
247 else
248 return m_pFormShell->GetCurPage()->GetForms();
252 void NavigatorTreeModel::Insert(FmEntryData* pEntry, sal_uInt32 nRelPos, bool bAlterModel)
254 if (IsListening(*m_pFormModel))
255 EndListening(*m_pFormModel);
257 m_pPropChangeList->Lock();
258 FmFormData* pFolder = static_cast<FmFormData*>( pEntry->GetParent() );
259 Reference< XChild > xElement( pEntry->GetChildIFace() );
260 if (bAlterModel)
262 OUString aStr;
263 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
264 aStr = SvxResId(RID_STR_FORM);
265 else
266 aStr = SvxResId(RID_STR_CONTROL);
268 Reference< XIndexContainer > xContainer;
269 if (pFolder)
270 xContainer.set(pFolder->GetFormIface(), UNO_QUERY);
271 else
272 xContainer = GetForms();
274 bool bUndo = m_pFormModel->IsUndoEnabled();
276 if( bUndo )
278 OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_INSERT));
279 aUndoStr = aUndoStr.replaceFirst("#", aStr);
280 m_pFormModel->BegUndo(aUndoStr);
283 if (nRelPos >= o3tl::make_unsigned(xContainer->getCount()))
284 nRelPos = static_cast<sal_uInt32>(xContainer->getCount());
286 // UndoAction
287 if ( bUndo && m_pPropChangeList->CanUndo())
289 m_pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*m_pFormModel,
290 FmUndoContainerAction::Inserted,
291 xContainer,
292 xElement,
293 nRelPos));
296 // Element has to be of the expected type by the container
297 if (xContainer->getElementType() ==
298 cppu::UnoType<XForm>::get())
301 Reference< XForm > xElementAsForm(xElement, UNO_QUERY);
302 xContainer->insertByIndex(nRelPos, makeAny(xElementAsForm));
304 else if (xContainer->getElementType() ==
305 cppu::UnoType<XFormComponent>::get())
308 Reference< XFormComponent > xElementAsComponent(xElement, UNO_QUERY);
309 xContainer->insertByIndex(nRelPos, makeAny(xElementAsComponent));
311 else
313 OSL_FAIL("NavigatorTreeModel::Insert : the parent container needs an elementtype I don't know !");
316 if( bUndo )
317 m_pFormModel->EndUndo();
320 // register as PropertyChangeListener
321 Reference< XPropertySet > xSet(xElement, UNO_QUERY);
322 if( xSet.is() )
323 xSet->addPropertyChangeListener( FM_PROP_NAME, m_pPropChangeList );
326 // Remove data from model
327 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
329 Reference< XContainer > xContainer(xElement, UNO_QUERY);
330 if (xContainer.is())
331 xContainer->addContainerListener(m_pPropChangeList);
334 if (pFolder)
335 pFolder->GetChildList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
336 else
337 GetRootList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
340 // notify UI
341 FmNavInsertedHint aInsertedHint( pEntry, nRelPos );
342 Broadcast( aInsertedHint );
344 m_pPropChangeList->UnLock();
345 if (IsListening(*m_pFormModel))
346 StartListening(*m_pFormModel);
350 void NavigatorTreeModel::Remove(FmEntryData* pEntry, bool bAlterModel)
353 // get form and parent
354 if (!pEntry || !m_pFormModel)
355 return;
357 if (IsListening(*m_pFormModel))
358 EndListening(*m_pFormModel);
360 const bool bUndo = m_pFormModel->IsUndoEnabled();
362 m_pPropChangeList->Lock();
363 FmFormData* pFolder = static_cast<FmFormData*>( pEntry->GetParent() );
364 Reference< XChild > xElement ( pEntry->GetChildIFace() );
365 if (bAlterModel)
367 OUString aStr;
368 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
369 aStr = SvxResId(RID_STR_FORM);
370 else
371 aStr = SvxResId(RID_STR_CONTROL);
373 if( bUndo )
375 OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_REMOVE));
376 aUndoStr = aUndoStr.replaceFirst("#", aStr);
377 m_pFormModel->BegUndo(aUndoStr);
381 // now real deletion of data form model
382 if (auto pFormData = dynamic_cast<FmFormData*>( pEntry))
383 RemoveForm(pFormData);
384 else
385 RemoveFormComponent(static_cast<FmControlData*>(pEntry));
388 if (bAlterModel)
390 Reference< XIndexContainer > xContainer(xElement->getParent(), UNO_QUERY);
391 // remove from Container
392 sal_Int32 nContainerIndex = getElementPos(xContainer, xElement);
393 // UndoAction
394 if (nContainerIndex >= 0)
396 if ( bUndo && m_pPropChangeList->CanUndo())
398 m_pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*m_pFormModel,
399 FmUndoContainerAction::Removed,
400 xContainer,
401 xElement, nContainerIndex ));
403 else if( !m_pPropChangeList->CanUndo() )
405 FmUndoContainerAction::DisposeElement( xElement );
408 xContainer->removeByIndex(nContainerIndex );
411 if( bUndo )
412 m_pFormModel->EndUndo();
415 // remove from parent
416 if (pFolder)
417 pFolder->GetChildList()->removeNoDelete( pEntry );
418 else
420 GetRootList()->removeNoDelete( pEntry );
422 // If root has no more form, reset CurForm at shell
423 if ( !GetRootList()->size() )
424 m_pFormShell->GetImpl()->forgetCurrentForm_Lock();
428 // notify UI
429 FmNavRemovedHint aRemovedHint( pEntry );
430 Broadcast( aRemovedHint );
432 // delete entry
433 delete pEntry;
435 m_pPropChangeList->UnLock();
436 StartListening(*m_pFormModel);
440 void NavigatorTreeModel::RemoveForm(FmFormData const * pFormData)
443 // get form and parent
444 if (!pFormData || !m_pFormModel)
445 return;
447 FmEntryDataList* pChildList = pFormData->GetChildList();
448 for ( size_t i = pChildList->size(); i > 0; )
450 FmEntryData* pEntryData = pChildList->at( --i );
453 // Child is form -> recursive call
454 if( auto pChildFormData = dynamic_cast<FmFormData*>( pEntryData) )
455 RemoveForm(pChildFormData);
456 else if( auto pChildControlData = dynamic_cast<FmControlData*>( pEntryData) )
457 RemoveFormComponent(pChildControlData);
461 // unregister as PropertyChangeListener
462 Reference< XPropertySet > xSet( pFormData->GetPropertySet() );
463 if ( xSet.is() )
464 xSet->removePropertyChangeListener( FM_PROP_NAME, m_pPropChangeList );
468 void NavigatorTreeModel::RemoveFormComponent(FmControlData const * pControlData)
471 // get control and parent
472 if (!pControlData)
473 return;
476 // unregister as PropertyChangeListener
477 Reference< XPropertySet > xSet( pControlData->GetPropertySet() );
478 if (xSet.is())
479 xSet->removePropertyChangeListener( FM_PROP_NAME, m_pPropChangeList);
483 void NavigatorTreeModel::FillBranch( FmFormData* pFormData )
486 // insert forms from root
487 if( pFormData == nullptr )
489 Reference< XIndexContainer > xForms = GetForms();
490 if (!xForms.is())
491 return;
493 Reference< XForm > xSubForm;
494 for (sal_Int32 i=0; i<xForms->getCount(); ++i)
496 DBG_ASSERT( xForms->getByIndex(i).getValueType() == cppu::UnoType<XForm>::get(),
497 "NavigatorTreeModel::FillBranch : the root container should supply only elements of type XForm");
499 xForms->getByIndex(i) >>= xSubForm;
500 FmFormData* pSubFormData = new FmFormData(xSubForm, pFormData);
501 Insert( pSubFormData );
503 // new branch, if SubForm contains Subforms itself
504 FillBranch( pSubFormData );
509 // insert components
510 else
512 Reference< XIndexContainer > xComponents( GetFormComponents(pFormData));
513 if( !xComponents.is() ) return;
515 FmControlData* pNewControlData;
516 FmFormData* pSubFormData;
518 Reference< XFormComponent > xCurrentComponent;
519 for (sal_Int32 j=0; j<xComponents->getCount(); ++j)
521 xComponents->getByIndex(j) >>= xCurrentComponent;
522 Reference< XForm > xSubForm(xCurrentComponent, UNO_QUERY);
524 if (xSubForm.is())
525 { // actual component is a form
526 pSubFormData = new FmFormData(xSubForm, pFormData);
527 Insert(pSubFormData);
530 // new branch, if SubForm contains Subforms itself
531 FillBranch(pSubFormData);
533 else
535 pNewControlData = new FmControlData(xCurrentComponent, pFormData);
536 Insert(pNewControlData);
543 void NavigatorTreeModel::InsertForm(const Reference< XForm > & xForm, sal_uInt32 nRelPos)
545 FmFormData* pFormData = static_cast<FmFormData*>(FindData( xForm, GetRootList() ));
546 if (pFormData)
547 return;
550 // set ParentData
551 Reference< XInterface > xIFace( xForm->getParent());
552 Reference< XForm > xParentForm(xIFace, UNO_QUERY);
553 FmFormData* pParentData = nullptr;
554 if (xParentForm.is())
555 pParentData = static_cast<FmFormData*>(FindData( xParentForm, GetRootList() ));
557 pFormData = new FmFormData(xForm, pParentData);
558 Insert( pFormData, nRelPos );
562 void NavigatorTreeModel::InsertFormComponent(const Reference< XFormComponent > & xComp, sal_uInt32 nRelPos)
565 // set ParentData
566 Reference< XInterface > xIFace( xComp->getParent());
567 Reference< XForm > xForm(xIFace, UNO_QUERY);
568 if (!xForm.is())
569 return;
571 FmFormData* pParentData = static_cast<FmFormData*>(FindData( xForm, GetRootList() ));
572 if( !pParentData )
574 pParentData = new FmFormData(xForm, nullptr);
575 Insert( pParentData );
578 if (!FindData(xComp, pParentData->GetChildList(),false))
581 // set new EntryData
582 FmEntryData* pNewEntryData = new FmControlData(xComp, pParentData);
585 // insert new EntryData
586 Insert( pNewEntryData, nRelPos );
590 void NavigatorTreeModel::ReplaceFormComponent(
591 const Reference< XFormComponent > & xOld,
592 const Reference< XFormComponent > & xNew
595 FmEntryData* pData = FindData(xOld, GetRootList());
596 assert(dynamic_cast<const FmControlData*>( pData)); //NavigatorTreeModel::ReplaceFormComponent : invalid argument
597 auto pControlData = dynamic_cast<FmControlData*>( pData);
598 if (!pControlData)
599 return;
600 pControlData->ModelReplaced(xNew);
602 FmNavModelReplacedHint aReplacedHint( pData );
603 Broadcast( aReplacedHint );
606 FmEntryData* NavigatorTreeModel::FindData(const Reference< XInterface > & xElement, FmEntryDataList* pDataList, bool bRecurs)
608 // normalize
609 Reference< XInterface > xIFace( xElement, UNO_QUERY );
611 for ( size_t i = 0; i < pDataList->size(); i++ )
613 FmEntryData* pEntryData = pDataList->at( i );
614 if ( pEntryData->GetElement().get() == xIFace.get() )
615 return pEntryData;
616 else if (bRecurs)
618 pEntryData = FindData( xElement, pEntryData->GetChildList() );
619 if (pEntryData)
620 return pEntryData;
623 return nullptr;
627 FmEntryData* NavigatorTreeModel::FindData( const OUString& rText, FmFormData const * pParentData, bool bRecurs )
629 FmEntryDataList* pDataList;
630 if( !pParentData )
631 pDataList = GetRootList();
632 else
633 pDataList = pParentData->GetChildList();
635 OUString aEntryText;
636 FmEntryData* pEntryData;
637 FmEntryData* pChildData;
639 for( size_t i = 0; i < pDataList->size(); i++ )
641 pEntryData = pDataList->at( i );
642 aEntryText = pEntryData->GetText();
644 if (rText == aEntryText)
645 return pEntryData;
647 if (FmFormData* pFormData = bRecurs ? dynamic_cast<FmFormData*>(pEntryData) : nullptr)
649 pChildData = FindData(rText, pFormData, true);
650 if( pChildData )
651 return pChildData;
655 return nullptr;
658 void NavigatorTreeModel::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
660 if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
662 const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint);
663 switch( pSdrHint->GetKind() )
665 case SdrHintKind::ObjectInserted:
666 InsertSdrObj(pSdrHint->GetObject());
667 break;
668 case SdrHintKind::ObjectRemoved:
669 RemoveSdrObj(pSdrHint->GetObject());
670 break;
671 default:
672 break;
675 // is shell gone?
676 else if (rHint.GetId() == SfxHintId::Dying)
678 UpdateContent(nullptr);
680 // changed mark of controls?
681 else if (const FmNavViewMarksChanged* pvmcHint = dynamic_cast<const FmNavViewMarksChanged*>(&rHint))
683 BroadcastMarkedObjects(pvmcHint->GetAffectedView()->GetMarkedObjectList());
687 void NavigatorTreeModel::InsertSdrObj( const SdrObject* pObj )
689 const FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
690 if ( pFormObject )
694 Reference< XFormComponent > xFormComponent( pFormObject->GetUnoControlModel(), UNO_QUERY_THROW );
695 Reference< XIndexAccess > xContainer( xFormComponent->getParent(), UNO_QUERY_THROW );
697 sal_Int32 nPos = getElementPos( xContainer, xFormComponent );
698 InsertFormComponent( xFormComponent, nPos );
700 catch( const Exception& )
702 DBG_UNHANDLED_EXCEPTION("svx");
705 else if ( pObj->IsGroupObject() )
707 SdrObjListIter aIter( pObj->GetSubList() );
708 while ( aIter.IsMore() )
709 InsertSdrObj( aIter.Next() );
714 void NavigatorTreeModel::RemoveSdrObj( const SdrObject* pObj )
716 const FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
717 if ( pFormObject )
721 Reference< XFormComponent > xFormComponent( pFormObject->GetUnoControlModel(), UNO_QUERY_THROW );
722 FmEntryData* pEntryData = FindData( xFormComponent, GetRootList() );
723 if ( pEntryData )
724 Remove( pEntryData );
726 catch( const Exception& )
728 DBG_UNHANDLED_EXCEPTION("svx");
731 else if ( pObj->IsGroupObject() )
733 SdrObjListIter aIter( pObj->GetSubList() );
734 while ( aIter.IsMore() )
735 RemoveSdrObj( aIter.Next() );
739 bool NavigatorTreeModel::InsertFormComponent(FmNavRequestSelectHint& rHint, SdrObject* pObject)
741 if ( auto pObjGroup = dynamic_cast<const SdrObjGroup*>( pObject) )
742 { // descend recursively
743 const SdrObjList *pChildren = pObjGroup->GetSubList();
744 for ( size_t i=0; i<pChildren->GetObjCount(); ++i )
746 SdrObject* pCurrent = pChildren->GetObj(i);
747 if (!InsertFormComponent(rHint, pCurrent))
748 return false;
751 else
753 FmFormObj* pFormObject = FmFormObj::GetFormObject( pObject );
754 if ( !pFormObject )
755 return false;
759 Reference< XFormComponent > xFormViewControl( pFormObject->GetUnoControlModel(), UNO_QUERY_THROW );
760 FmEntryData* pControlData = FindData( xFormViewControl, GetRootList() );
761 if ( !pControlData )
762 return false;
764 rHint.AddItem( pControlData );
765 return true;
767 catch( const Exception& )
769 DBG_UNHANDLED_EXCEPTION("svx");
770 return false;
774 return true;
777 void NavigatorTreeModel::BroadcastMarkedObjects(const SdrMarkList& mlMarked)
779 // search all objects, which can be handled, out of marked objects
780 FmNavRequestSelectHint rshRequestSelection;
781 bool bIsMixedSelection = false;
783 for (size_t i=0; (i<mlMarked.GetMarkCount()) && !bIsMixedSelection; ++i)
785 SdrObject* pobjCurrent = mlMarked.GetMark(i)->GetMarkedSdrObj();
786 bIsMixedSelection |= !InsertFormComponent(rshRequestSelection, pobjCurrent);
787 // if Not-Form-Control, InsertFormComponent returns sal_False !
790 rshRequestSelection.SetMixedSelection(bIsMixedSelection);
791 if (bIsMixedSelection)
792 rshRequestSelection.ClearItems();
794 Broadcast(rshRequestSelection);
795 // an empty list causes NavigatorTree to remove his selection
799 void NavigatorTreeModel::UpdateContent( const Reference< css::form::XForms > & xForms )
802 // refill model form root upward
803 Clear();
804 if (!xForms.is())
805 return;
807 xForms->addContainerListener(m_pPropChangeList);
809 FillBranch(nullptr);
811 // select same control in tree as in view
812 // (or all of them), if there is one ...
813 if(!m_pFormShell) return; // no shell
815 FmFormView* pFormView = m_pFormShell->GetFormView();
816 DBG_ASSERT(pFormView != nullptr, "NavigatorTreeModel::UpdateContent : no FormView");
817 BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
821 void NavigatorTreeModel::UpdateContent( FmFormShell* pShell )
824 // If shell is unchanged, do nothing
825 FmFormPage* pNewPage = pShell ? pShell->GetCurPage() : nullptr;
826 if ((pShell == m_pFormShell) && (m_pFormPage == pNewPage))
827 return;
830 // unregister as Listener
831 if( m_pFormShell )
833 if (m_pFormModel)
834 EndListening( *m_pFormModel );
835 m_pFormModel = nullptr;
836 EndListening( *m_pFormShell );
837 Clear();
841 // entire update
842 m_pFormShell = pShell;
843 if (m_pFormShell)
845 m_pFormPage = pNewPage;
846 UpdateContent(m_pFormPage->GetForms());
847 } else
848 m_pFormPage = nullptr;
851 // register as Listener again
852 if( m_pFormShell )
854 StartListening( *m_pFormShell );
855 m_pFormModel = m_pFormShell->GetFormModel();
856 if( m_pFormModel )
857 StartListening( *m_pFormModel );
862 Reference< XIndexContainer > NavigatorTreeModel::GetFormComponents( FmFormData const * pFormData )
865 // get components from form
866 if (pFormData)
867 return Reference< XIndexContainer > (pFormData->GetFormIface(), UNO_QUERY);
869 return Reference< XIndexContainer > ();
873 bool NavigatorTreeModel::Rename( FmEntryData* pEntryData, const OUString& rNewText )
876 // If name already exist, error message
877 pEntryData->SetText( rNewText );
880 // get PropertySet
881 Reference< XFormComponent > xFormComponent;
883 if( auto pFormData = dynamic_cast<FmFormData*>( pEntryData))
885 xFormComponent = pFormData->GetFormIface();
888 if( auto pControlData = dynamic_cast<FmControlData*>( pEntryData) )
890 xFormComponent = pControlData->GetFormComponent();
893 if( !xFormComponent.is() ) return false;
894 Reference< XPropertySet > xSet(xFormComponent, UNO_QUERY);
895 if( !xSet.is() ) return false;
898 // set name
899 xSet->setPropertyValue( FM_PROP_NAME, makeAny(rNewText) );
901 return true;
907 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */