Bump version to 6.4-15
[LibreOffice.git] / svx / source / form / navigatortreemodel.cxx
blobc58c79f1e3a3f3c16acf56ed384d610dcb8f487d
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/fmglob.hxx>
25 #include <svx/svditer.hxx>
26 #include <svx/svdogrp.hxx>
27 #include <svx/svdpagv.hxx>
29 #include <fmprop.hxx>
31 #include <fmundo.hxx>
32 #include <fmexpl.hxx>
33 #include <svx/strings.hrc>
34 #include <fmshimp.hxx>
35 #include <fmobj.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <com/sun/star/container/XContainer.hpp>
39 #include <comphelper/types.hxx>
42 namespace svxform
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::form;
50 using namespace ::com::sun::star::awt;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::script;
53 using namespace ::com::sun::star::sdb;
55 OFormComponentObserver::OFormComponentObserver(NavigatorTreeModel* _pModel)
56 :m_pNavModel(_pModel)
57 ,m_nLocks(0)
58 ,m_bCanUndo(true)
62 // XPropertyChangeListener
64 void SAL_CALL OFormComponentObserver::disposing(const EventObject& Source)
66 Remove( Source.Source );
70 void SAL_CALL OFormComponentObserver::propertyChange(const PropertyChangeEvent& evt)
72 if( !m_pNavModel ) return;
73 if( evt.PropertyName != FM_PROP_NAME ) return;
75 Reference< XFormComponent > xFormComponent(evt.Source, UNO_QUERY);
76 Reference< XForm > xForm(evt.Source, UNO_QUERY);
78 FmEntryData* pEntryData( nullptr );
79 if( xForm.is() )
80 pEntryData = m_pNavModel->FindData( xForm, m_pNavModel->GetRootList() );
81 else if( xFormComponent.is() )
82 pEntryData = m_pNavModel->FindData( xFormComponent, m_pNavModel->GetRootList() );
84 if( pEntryData )
86 OUString aNewName = ::comphelper::getString(evt.NewValue);
87 pEntryData->SetText( aNewName );
88 FmNavNameChangedHint aNameChangedHint( pEntryData, aNewName );
89 m_pNavModel->Broadcast( aNameChangedHint );
93 // XContainerListener
95 void SAL_CALL OFormComponentObserver::elementInserted(const ContainerEvent& evt)
97 if (IsLocked() || !m_pNavModel)
98 return;
100 // insert no Undoaction
101 m_bCanUndo = false;
103 Reference< XInterface > xTemp;
104 evt.Element >>= xTemp;
105 Insert(xTemp, ::comphelper::getINT32(evt.Accessor));
107 m_bCanUndo = true;
111 void OFormComponentObserver::Insert(const Reference< XInterface > & xIface, sal_Int32 nIndex)
113 Reference< XForm > xForm(xIface, UNO_QUERY);
114 if (xForm.is())
116 m_pNavModel->InsertForm(xForm, sal_uInt32(nIndex));
117 Reference< XIndexContainer > xContainer(xForm, UNO_QUERY);
118 Reference< XInterface > xTemp;
119 for (sal_Int32 i = 0; i < xContainer->getCount(); i++)
121 xContainer->getByIndex(i) >>= xTemp;
122 Insert(xTemp, i);
125 else
127 Reference< XFormComponent > xFormComp(xIface, UNO_QUERY);
128 if (xFormComp.is())
129 m_pNavModel->InsertFormComponent(xFormComp, sal_uInt32(nIndex));
134 void SAL_CALL OFormComponentObserver::elementReplaced(const ContainerEvent& evt)
136 if (IsLocked() || !m_pNavModel)
137 return;
139 m_bCanUndo = false;
141 // delete EntryData
142 Reference< XFormComponent > xReplaced;
143 evt.ReplacedElement >>= xReplaced;
144 FmEntryData* pEntryData = m_pNavModel->FindData(xReplaced, m_pNavModel->GetRootList());
145 if (pEntryData)
147 if (dynamic_cast<const FmControlData*>( pEntryData) != nullptr)
149 Reference< XFormComponent > xComp;
150 evt.Element >>= xComp;
151 DBG_ASSERT(xComp.is(), "OFormComponentObserver::elementReplaced : invalid argument !");
152 // FmControlData should be coupled with XFormComponent
153 m_pNavModel->ReplaceFormComponent(xReplaced, xComp);
155 else if (dynamic_cast<const FmFormData*>( pEntryData) != nullptr)
157 OSL_FAIL("replacing forms not implemented yet !");
161 m_bCanUndo = true;
165 void OFormComponentObserver::Remove( const css::uno::Reference< css::uno::XInterface >& _rxElement )
167 if (IsLocked() || !m_pNavModel)
168 return;
170 m_bCanUndo = false;
173 // delete EntryData
174 FmEntryData* pEntryData = m_pNavModel->FindData( _rxElement, m_pNavModel->GetRootList() );
175 if (pEntryData)
176 m_pNavModel->Remove(pEntryData);
178 m_bCanUndo = true;
182 void SAL_CALL OFormComponentObserver::elementRemoved(const ContainerEvent& evt)
184 Reference< XInterface > xElement;
185 evt.Element >>= xElement;
186 Remove( xElement );
189 NavigatorTreeModel::NavigatorTreeModel()
190 :m_pFormShell(nullptr)
191 ,m_pFormPage(nullptr)
192 ,m_pFormModel(nullptr)
194 m_pPropChangeList = new OFormComponentObserver(this);
195 m_pRootList.reset( new FmEntryDataList() );
198 NavigatorTreeModel::~NavigatorTreeModel()
201 // unregister Listener
202 if( m_pFormShell)
204 FmFormModel* pFormModel = m_pFormShell->GetFormModel();
205 if( pFormModel && IsListening(*pFormModel))
206 EndListening( *pFormModel );
208 if (IsListening(*m_pFormShell))
209 EndListening(*m_pFormShell);
212 Clear();
213 m_pRootList.reset();
214 m_pPropChangeList->ReleaseModel();
218 void NavigatorTreeModel::SetModified()
220 if( !m_pFormShell ) return;
221 SfxObjectShell* pObjShell = m_pFormShell->GetFormModel()->GetObjectShell();
222 if( !pObjShell ) return;
223 pObjShell->SetModified();
227 void NavigatorTreeModel::Clear()
229 Reference< css::form::XForms > xForms( GetForms());
230 if(xForms.is())
231 xForms->removeContainerListener(m_pPropChangeList.get());
234 // delete RootList
235 GetRootList()->clear();
238 // notify UI
239 FmNavClearedHint aClearedHint;
240 Broadcast( aClearedHint );
244 Reference< css::form::XForms > NavigatorTreeModel::GetForms() const
246 if( !m_pFormShell || !m_pFormShell->GetCurPage())
247 return nullptr;
248 else
249 return m_pFormShell->GetCurPage()->GetForms();
253 void NavigatorTreeModel::Insert(FmEntryData* pEntry, sal_uInt32 nRelPos, bool bAlterModel)
255 if (IsListening(*m_pFormModel))
256 EndListening(*m_pFormModel);
258 m_pPropChangeList->Lock();
259 FmFormData* pFolder = static_cast<FmFormData*>( pEntry->GetParent() );
260 Reference< XChild > xElement( pEntry->GetChildIFace() );
261 if (bAlterModel)
263 OUString aStr;
264 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
265 aStr = SvxResId(RID_STR_FORM);
266 else
267 aStr = SvxResId(RID_STR_CONTROL);
269 Reference< XIndexContainer > xContainer;
270 if (pFolder)
271 xContainer.set(pFolder->GetFormIface(), UNO_QUERY);
272 else
273 xContainer = GetForms();
275 bool bUndo = m_pFormModel->IsUndoEnabled();
277 if( bUndo )
279 OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_INSERT));
280 aUndoStr = aUndoStr.replaceFirst("#", aStr);
281 m_pFormModel->BegUndo(aUndoStr);
284 if (nRelPos >= static_cast<sal_uInt32>(xContainer->getCount()))
285 nRelPos = static_cast<sal_uInt32>(xContainer->getCount());
287 // UndoAction
288 if ( bUndo && m_pPropChangeList->CanUndo())
290 m_pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*m_pFormModel,
291 FmUndoContainerAction::Inserted,
292 xContainer,
293 xElement,
294 nRelPos));
297 // Element has to be of the expected type by the container
298 if (xContainer->getElementType() ==
299 cppu::UnoType<XForm>::get())
302 Reference< XForm > xElementAsForm(xElement, UNO_QUERY);
303 xContainer->insertByIndex(nRelPos, makeAny(xElementAsForm));
305 else if (xContainer->getElementType() ==
306 cppu::UnoType<XFormComponent>::get())
309 Reference< XFormComponent > xElementAsComponent(xElement, UNO_QUERY);
310 xContainer->insertByIndex(nRelPos, makeAny(xElementAsComponent));
312 else
314 OSL_FAIL("NavigatorTreeModel::Insert : the parent container needs an elementtype I don't know !");
317 if( bUndo )
318 m_pFormModel->EndUndo();
321 // register as PropertyChangeListener
322 Reference< XPropertySet > xSet(xElement, UNO_QUERY);
323 if( xSet.is() )
324 xSet->addPropertyChangeListener( FM_PROP_NAME, m_pPropChangeList.get() );
327 // Remove data from model
328 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
330 Reference< XContainer > xContainer(xElement, UNO_QUERY);
331 if (xContainer.is())
332 xContainer->addContainerListener(m_pPropChangeList.get());
335 if (pFolder)
336 pFolder->GetChildList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
337 else
338 GetRootList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
341 // notify UI
342 FmNavInsertedHint aInsertedHint( pEntry, nRelPos );
343 Broadcast( aInsertedHint );
345 m_pPropChangeList->UnLock();
346 if (IsListening(*m_pFormModel))
347 StartListening(*m_pFormModel);
351 void NavigatorTreeModel::Remove(FmEntryData* pEntry, bool bAlterModel)
354 // get form and parent
355 if (!pEntry || !m_pFormModel)
356 return;
358 if (IsListening(*m_pFormModel))
359 EndListening(*m_pFormModel);
361 const bool bUndo = m_pFormModel->IsUndoEnabled();
363 m_pPropChangeList->Lock();
364 FmFormData* pFolder = static_cast<FmFormData*>( pEntry->GetParent() );
365 Reference< XChild > xElement ( pEntry->GetChildIFace() );
366 if (bAlterModel)
368 OUString aStr;
369 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
370 aStr = SvxResId(RID_STR_FORM);
371 else
372 aStr = SvxResId(RID_STR_CONTROL);
374 if( bUndo )
376 OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_REMOVE));
377 aUndoStr = aUndoStr.replaceFirst("#", aStr);
378 m_pFormModel->BegUndo(aUndoStr);
382 // now real deletion of data form model
383 if (dynamic_cast<const FmFormData*>( pEntry) != nullptr)
384 RemoveForm(static_cast<FmFormData*>(pEntry));
385 else
386 RemoveFormComponent(static_cast<FmControlData*>(pEntry));
389 if (bAlterModel)
391 Reference< XIndexContainer > xContainer(xElement->getParent(), UNO_QUERY);
392 // remove from Container
393 sal_Int32 nContainerIndex = getElementPos(xContainer.get(), xElement);
394 // UndoAction
395 if (nContainerIndex >= 0)
397 if ( bUndo && m_pPropChangeList->CanUndo())
399 m_pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*m_pFormModel,
400 FmUndoContainerAction::Removed,
401 xContainer,
402 xElement, nContainerIndex ));
404 else if( !m_pPropChangeList->CanUndo() )
406 FmUndoContainerAction::DisposeElement( xElement );
409 xContainer->removeByIndex(nContainerIndex );
412 if( bUndo )
413 m_pFormModel->EndUndo();
416 // remove from parent
417 if (pFolder)
418 pFolder->GetChildList()->removeNoDelete( pEntry );
419 else
421 GetRootList()->removeNoDelete( pEntry );
423 // If root has no more form, reset CurForm at shell
424 if ( !GetRootList()->size() )
425 m_pFormShell->GetImpl()->forgetCurrentForm_Lock();
429 // notify UI
430 FmNavRemovedHint aRemovedHint( pEntry );
431 Broadcast( aRemovedHint );
433 // delete entry
434 delete pEntry;
436 m_pPropChangeList->UnLock();
437 StartListening(*m_pFormModel);
441 void NavigatorTreeModel::RemoveForm(FmFormData const * pFormData)
444 // get form and parent
445 if (!pFormData || !m_pFormModel)
446 return;
448 FmEntryDataList* pChildList = pFormData->GetChildList();
449 for ( size_t i = pChildList->size(); i > 0; )
451 FmEntryData* pEntryData = pChildList->at( --i );
454 // Child is form -> recursive call
455 if( dynamic_cast<const FmFormData*>( pEntryData) != nullptr )
456 RemoveForm( static_cast<FmFormData*>(pEntryData));
457 else if( dynamic_cast<const FmControlData*>( pEntryData) != nullptr )
458 RemoveFormComponent(static_cast<FmControlData*>(pEntryData));
462 // unregister as PropertyChangeListener
463 Reference< XPropertySet > xSet( pFormData->GetPropertySet() );
464 if ( xSet.is() )
465 xSet->removePropertyChangeListener( FM_PROP_NAME, m_pPropChangeList.get() );
469 void NavigatorTreeModel::RemoveFormComponent(FmControlData const * pControlData)
472 // get control and parent
473 if (!pControlData)
474 return;
477 // unregister as PropertyChangeListener
478 Reference< XPropertySet > xSet( pControlData->GetPropertySet() );
479 if (xSet.is())
480 xSet->removePropertyChangeListener( FM_PROP_NAME, m_pPropChangeList.get());
484 void NavigatorTreeModel::FillBranch( FmFormData* pFormData )
487 // insert forms from root
488 if( pFormData == nullptr )
490 Reference< XIndexContainer > xForms = GetForms();
491 if (!xForms.is())
492 return;
494 Reference< XForm > xSubForm;
495 for (sal_Int32 i=0; i<xForms->getCount(); ++i)
497 DBG_ASSERT( xForms->getByIndex(i).getValueType() == cppu::UnoType<XForm>::get(),
498 "NavigatorTreeModel::FillBranch : the root container should supply only elements of type XForm");
500 xForms->getByIndex(i) >>= xSubForm;
501 FmFormData* pSubFormData = new FmFormData(xSubForm, pFormData);
502 Insert( pSubFormData );
504 // new branch, if SubForm contains Subforms itself
505 FillBranch( pSubFormData );
510 // insert components
511 else
513 Reference< XIndexContainer > xComponents( GetFormComponents(pFormData));
514 if( !xComponents.is() ) return;
516 FmControlData* pNewControlData;
517 FmFormData* pSubFormData;
519 Reference< XFormComponent > xCurrentComponent;
520 for (sal_Int32 j=0; j<xComponents->getCount(); ++j)
522 xComponents->getByIndex(j) >>= xCurrentComponent;
523 Reference< XForm > xSubForm(xCurrentComponent, UNO_QUERY);
525 if (xSubForm.is())
526 { // actual component is a form
527 pSubFormData = new FmFormData(xSubForm, pFormData);
528 Insert(pSubFormData);
531 // new branch, if SubForm contains Subforms itself
532 FillBranch(pSubFormData);
534 else
536 pNewControlData = new FmControlData(xCurrentComponent, pFormData);
537 Insert(pNewControlData);
544 void NavigatorTreeModel::InsertForm(const Reference< XForm > & xForm, sal_uInt32 nRelPos)
546 FmFormData* pFormData = static_cast<FmFormData*>(FindData( xForm, GetRootList() ));
547 if (pFormData)
548 return;
551 // set ParentData
552 Reference< XInterface > xIFace( xForm->getParent());
553 Reference< XForm > xParentForm(xIFace, UNO_QUERY);
554 FmFormData* pParentData = nullptr;
555 if (xParentForm.is())
556 pParentData = static_cast<FmFormData*>(FindData( xParentForm, GetRootList() ));
558 pFormData = new FmFormData(xForm, pParentData);
559 Insert( pFormData, nRelPos );
563 void NavigatorTreeModel::InsertFormComponent(const Reference< XFormComponent > & xComp, sal_uInt32 nRelPos)
566 // set ParentData
567 Reference< XInterface > xIFace( xComp->getParent());
568 Reference< XForm > xForm(xIFace, UNO_QUERY);
569 if (!xForm.is())
570 return;
572 FmFormData* pParentData = static_cast<FmFormData*>(FindData( xForm, GetRootList() ));
573 if( !pParentData )
575 pParentData = new FmFormData(xForm, nullptr);
576 Insert( pParentData );
579 if (!FindData(xComp, pParentData->GetChildList(),false))
582 // set new EntryData
583 FmEntryData* pNewEntryData = new FmControlData(xComp, pParentData);
586 // insert new EntryData
587 Insert( pNewEntryData, nRelPos );
591 void NavigatorTreeModel::ReplaceFormComponent(
592 const Reference< XFormComponent > & xOld,
593 const Reference< XFormComponent > & xNew
596 FmEntryData* pData = FindData(xOld, GetRootList());
597 assert(dynamic_cast<const FmControlData*>( pData)); //NavigatorTreeModel::ReplaceFormComponent : invalid argument
598 if (!dynamic_cast<const FmControlData*>( pData))
599 return;
600 static_cast<FmControlData*>(pData)->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 ( dynamic_cast<const SdrObjGroup*>( pObject) != nullptr )
742 { // descend recursively
743 const SdrObjList *pChildren = static_cast<SdrObjGroup*>(pObject)->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())
806 xForms->addContainerListener(m_pPropChangeList.get());
808 FillBranch(nullptr);
810 // select same control in tree as in view
811 // (or all of them), if there is one ...
812 if(!m_pFormShell) return; // no shell
814 FmFormView* pFormView = m_pFormShell->GetFormView();
815 DBG_ASSERT(pFormView != nullptr, "NavigatorTreeModel::UpdateContent : no FormView");
816 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( dynamic_cast<const FmFormData*>( pEntryData) != nullptr )
885 FmFormData* pFormData = static_cast<FmFormData*>(pEntryData);
886 xFormComponent = pFormData->GetFormIface();
889 if( dynamic_cast<const FmControlData*>( pEntryData) != nullptr )
891 FmControlData* pControlData = static_cast<FmControlData*>(pEntryData);
892 xFormComponent = pControlData->GetFormComponent();
895 if( !xFormComponent.is() ) return false;
896 Reference< XPropertySet > xSet(xFormComponent, UNO_QUERY);
897 if( !xSet.is() ) return false;
900 // set name
901 xSet->setPropertyValue( FM_PROP_NAME, makeAny(rNewText) );
903 return true;
909 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */