Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / form / navigatortree.cxx
blobf1254f1cf1cd1f2fe3eb275fa12e572a1320d3f5
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/svdpagv.hxx>
25 #include "svx/svditer.hxx"
27 #include "fmhelp.hrc"
28 #include "fmexpl.hxx"
29 #include "svx/fmresids.hrc"
30 #include "fmshimp.hxx"
31 #include "fmservs.hxx"
32 #include "fmundo.hxx"
33 #include "fmpgeimp.hxx"
34 #include "fmitems.hxx"
35 #include "fmobj.hxx"
36 #include "fmprop.hrc"
37 #include <vcl/wrkwin.hxx>
38 #include <sfx2/viewsh.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <comphelper/property.hxx>
43 #include <com/sun/star/form/FormComponentType.hpp>
44 #include <com/sun/star/sdb/CommandType.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/script/XEventAttacherManager.hpp>
47 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
48 #include <com/sun/star/datatransfer/XTransferable.hpp>
49 #include <svx/sdrpaintwindow.hxx>
51 #include <svx/svxdlg.hxx>
52 #include <svx/dialogs.hrc>
53 #include "svtools/treelistentry.hxx"
55 namespace svxform
59 #define DROP_ACTION_TIMER_INITIAL_TICKS 10
60 // solange dauert es, bis das Scrollen anspringt
61 #define DROP_ACTION_TIMER_SCROLL_TICKS 3
62 // in diesen Intervallen wird jeweils eine Zeile gescrollt
63 #define DROP_ACTION_TIMER_TICK_BASE 10
64 // das ist die Basis, mit der beide Angaben multipliziert werden (in ms)
66 #define EXPLORER_SYNC_DELAY 200
67 // dieser Betrag an Millisekunden wird gewartet, ehe der Explorer nach einem Select oder Deselect die ::com::sun::star::sdbcx::View synchronisiert
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::form;
73 using namespace ::com::sun::star::awt;
74 using namespace ::com::sun::star::container;
75 using namespace ::com::sun::star::script;
76 using namespace ::com::sun::star::datatransfer;
77 using namespace ::com::sun::star::datatransfer::clipboard;
78 using namespace ::com::sun::star::sdb;
81 // helper
84 typedef ::std::map< Reference< XInterface >, SdrObject*, ::comphelper::OInterfaceCompare< XInterface > >
85 MapModelToShape;
86 typedef MapModelToShape::value_type ModelShapePair;
89 void collectShapeModelMapping( SdrPage* _pPage, MapModelToShape& _rMapping )
91 OSL_ENSURE( _pPage, "collectShapeModelMapping: invalid arg!" );
93 _rMapping.clear();
95 SdrObjListIter aIter( *_pPage );
96 while ( aIter.IsMore() )
98 SdrObject* pSdrObject = aIter.Next();
99 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
100 if ( !pFormObject )
101 continue;
103 Reference< XInterface > xNormalizedModel( pFormObject->GetUnoControlModel(), UNO_QUERY );
104 // note that this is normalized (i.e. queried for XInterface explicitly)
106 #ifdef DBG_UTIL
107 ::std::pair< MapModelToShape::iterator, bool > aPos =
108 #endif
109 _rMapping.insert( ModelShapePair( xNormalizedModel, pSdrObject ) );
110 DBG_ASSERT( aPos.second, "collectShapeModelMapping: model was already existent!" );
111 // if this asserts, this would mean we have 2 shapes pointing to the same model
116 // class NavigatorTree
120 NavigatorTree::NavigatorTree( Window* pParent )
121 :SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HSCROLL ) // #100258# OJ WB_HSCROLL added
122 ,m_aControlExchange(this)
123 ,m_pNavModel( NULL )
124 ,m_pRootEntry(NULL)
125 ,m_pEditEntry(NULL)
126 ,nEditEvent(0)
127 ,m_sdiState(SDI_DIRTY)
128 ,m_aTimerTriggered(-1,-1)
129 ,m_aDropActionType( DA_SCROLLUP )
130 ,m_nSelectLock(0)
131 ,m_nFormsSelected(0)
132 ,m_nControlsSelected(0)
133 ,m_nHiddenControls(0)
134 ,m_aTimerCounter( DROP_ACTION_TIMER_INITIAL_TICKS )
135 ,m_bDragDataDirty(false)
136 ,m_bPrevSelectionMixed(false)
137 ,m_bMarkingObjects(false)
138 ,m_bRootSelected(false)
139 ,m_bInitialUpdate(true)
140 ,m_bKeyboardCut( false )
142 SetHelpId( HID_FORM_NAVIGATOR );
144 m_aNavigatorImages = ImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
146 SetNodeBitmaps(
147 m_aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
148 m_aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
151 SetDragDropMode(0xFFFF);
152 EnableInplaceEditing( true );
153 SetSelectionMode(MULTIPLE_SELECTION);
155 m_pNavModel = new NavigatorTreeModel( m_aNavigatorImages );
156 Clear();
158 StartListening( *m_pNavModel );
160 m_aDropActionTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnDropActionTimer));
162 m_aSynchronizeTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnSynchronizeTimer));
163 SetSelectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
164 SetDeselectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
168 NavigatorTree::~NavigatorTree()
170 if( nEditEvent )
171 Application::RemoveUserEvent( nEditEvent );
173 if (m_aSynchronizeTimer.IsActive())
174 m_aSynchronizeTimer.Stop();
176 DBG_ASSERT(GetNavModel() != NULL, "NavigatorTree::~NavigatorTree : unerwartet : kein ExplorerModel");
177 EndListening( *m_pNavModel );
178 Clear();
179 delete m_pNavModel;
183 void NavigatorTree::Clear()
185 m_pNavModel->Clear();
189 void NavigatorTree::UpdateContent( FmFormShell* pFormShell )
191 if (m_bInitialUpdate)
193 GrabFocus();
194 m_bInitialUpdate = false;
197 FmFormShell* pOldShell = GetNavModel()->GetFormShell();
198 FmFormPage* pOldPage = GetNavModel()->GetFormPage();
199 FmFormPage* pNewPage = pFormShell ? pFormShell->GetCurPage() : NULL;
201 if ((pOldShell != pFormShell) || (pOldPage != pNewPage))
203 // neue Shell, waehrend ich gerade editiere ?
204 if (IsEditingActive())
205 CancelTextEditing();
207 m_bDragDataDirty = true; // sicherheitshalber, auch wenn ich gar nicht dragge
209 GetNavModel()->UpdateContent( pFormShell );
211 // wenn es eine Form gibt, die Root expandieren
212 if (m_pRootEntry && !IsExpanded(m_pRootEntry))
213 Expand(m_pRootEntry);
214 // wenn es GENAU eine Form gibt, auch diese expandieren
215 if (m_pRootEntry)
217 SvTreeListEntry* pFirst = FirstChild(m_pRootEntry);
218 if (pFirst && !NextSibling(pFirst))
219 Expand(pFirst);
224 bool NavigatorTree::implAllowExchange( sal_Int8 _nAction, bool* _pHasNonHidden )
226 SvTreeListEntry* pCurEntry = GetCurEntry();
227 if (!pCurEntry)
228 return false;
230 // die Informationen fuer das AcceptDrop und ExecuteDrop
231 CollectSelectionData(SDI_ALL);
232 if (m_arrCurrentSelection.empty())
233 // nothing to do
234 return false;
236 // testen, ob es sich vielleicht ausschliesslich um hidden controls handelt (dann koennte ich pCtrlExch noch ein
237 // zusaetzliches Format geben)
238 bool bHasNonHidden = false;
239 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
240 it != m_arrCurrentSelection.end(); ++it )
242 FmEntryData* pCurrent = static_cast< FmEntryData* >( (*it)->GetUserData() );
243 if ( IsHiddenControl( pCurrent ) )
244 continue;
245 bHasNonHidden = true;
246 break;
249 if ( bHasNonHidden && ( 0 == ( _nAction & DND_ACTION_MOVE ) ) )
250 // non-hidden controls need to be moved
251 return false;
253 if ( _pHasNonHidden )
254 *_pHasNonHidden = bHasNonHidden;
256 return true;
260 bool NavigatorTree::implPrepareExchange( sal_Int8 _nAction )
262 EndSelection();
264 bool bHasNonHidden = false;
265 if ( !implAllowExchange( _nAction, &bHasNonHidden ) )
266 return false;
268 m_aControlExchange.prepareDrag();
269 m_aControlExchange->setFocusEntry( GetCurEntry() );
271 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
272 it != m_arrCurrentSelection.end(); ++it )
273 m_aControlExchange->addSelectedEntry(*it);
275 m_aControlExchange->setFormsRoot( GetNavModel()->GetFormPage()->GetForms() );
276 m_aControlExchange->buildPathFormat( this, m_pRootEntry );
278 if (!bHasNonHidden)
280 // eine entsprechende Sequenz aufbauen
281 Sequence< Reference< XInterface > > seqIFaces(m_arrCurrentSelection.size());
282 Reference< XInterface >* pArray = seqIFaces.getArray();
283 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
284 it != m_arrCurrentSelection.end(); ++it, ++pArray )
285 *pArray = static_cast< FmEntryData* >( (*it)->GetUserData() )->GetElement();
287 // und das neue Format
288 m_aControlExchange->addHiddenControlsFormat(seqIFaces);
291 m_bDragDataDirty = false;
292 return true;
296 void NavigatorTree::StartDrag( sal_Int8 /*nAction*/, const ::Point& /*rPosPixel*/ )
298 EndSelection();
300 if ( !implPrepareExchange( DND_ACTION_COPYMOVE ) )
301 // nothing to do or something went wrong
302 return;
304 // jetzt haben wir alle in der aktuelle Situation moeglichen Formate eingesammelt, es kann also losgehen ...
305 m_aControlExchange.startDrag( DND_ACTION_COPYMOVE );
309 void NavigatorTree::Command( const CommandEvent& rEvt )
311 bool bHandled = false;
312 switch( rEvt.GetCommand() )
314 case COMMAND_CONTEXTMENU:
316 // die Stelle, an der geklickt wurde
317 ::Point ptWhere;
318 if (rEvt.IsMouseEvent())
320 ptWhere = rEvt.GetMousePosPixel();
321 SvTreeListEntry* ptClickedOn = GetEntry(ptWhere);
322 if (ptClickedOn == NULL)
323 break;
324 if ( !IsSelected(ptClickedOn) )
326 SelectAll(false);
327 Select(ptClickedOn, true);
328 SetCurEntry(ptClickedOn);
331 else
333 if (m_arrCurrentSelection.empty()) // kann nur bei Kontextmenue ueber Tastatur passieren
334 break;
336 SvTreeListEntry* pCurrent = GetCurEntry();
337 if (!pCurrent)
338 break;
339 ptWhere = GetEntryPosition(pCurrent);
342 // meine Selektionsdaten auf den aktuellen Stand
343 CollectSelectionData(SDI_ALL);
345 // wenn mindestens ein Nicht-Root-Eintrag selektiert ist und die Root auch, dann nehme ich letztere aus der Selektion
346 // fix wieder raus
347 if ( (m_arrCurrentSelection.size() > 1) && m_bRootSelected )
349 Select( m_pRootEntry, false );
350 SetCursor( *m_arrCurrentSelection.begin(), true);
352 bool bSingleSelection = (m_arrCurrentSelection.size() == 1);
355 DBG_ASSERT( (m_arrCurrentSelection.size() > 0) || m_bRootSelected, "keine Eintraege selektiert" );
356 // solte nicht passieren, da ich oben bei der IsSelected-Abfrage auf jeden Fall einen selektiert haette,
357 // wenn das vorher nicht der Fall gewesen waere
360 // das Menue zusammenbasteln
361 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
362 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
363 if( pFormShell && pFormModel )
365 PopupMenu aContextMenu(SVX_RES(RID_FMEXPLORER_POPUPMENU));
366 PopupMenu* pSubMenuNew = aContextMenu.GetPopupMenu( SID_FM_NEW );
368 // das 'Neu'-Untermenue gibt es nur, wenn genau die Root oder genau ein Formular selektiert sind
369 aContextMenu.EnableItem( SID_FM_NEW, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
371 // 'Neu'\'Formular' unter genau den selben Bedingungen
372 pSubMenuNew->EnableItem( SID_FM_NEW_FORM, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
373 pSubMenuNew->SetItemImage(SID_FM_NEW_FORM, m_aNavigatorImages.GetImage(RID_SVXIMG_FORM));
374 pSubMenuNew->SetItemImage(SID_FM_NEW_HIDDEN, m_aNavigatorImages.GetImage(RID_SVXIMG_HIDDEN));
376 // 'Neu'\'verstecktes...', wenn genau ein Formular selektiert ist
377 pSubMenuNew->EnableItem( SID_FM_NEW_HIDDEN, bSingleSelection && m_nFormsSelected );
379 // 'Delete': everything which is not root can be removed
380 aContextMenu.EnableItem( SID_FM_DELETE, !m_bRootSelected );
382 // 'Cut', 'Copy' and 'Paste'
383 aContextMenu.EnableItem( SID_CUT, !m_bRootSelected && implAllowExchange( DND_ACTION_MOVE ) );
384 aContextMenu.EnableItem( SID_COPY, !m_bRootSelected && implAllowExchange( DND_ACTION_COPY ) );
385 aContextMenu.EnableItem( SID_PASTE, implAcceptPaste( ) );
387 // der TabDialog, wenn es genau ein Formular ist ...
388 aContextMenu.EnableItem( SID_FM_TAB_DIALOG, bSingleSelection && m_nFormsSelected );
390 // in XML forms, we don't allow for the properties of a form
391 // #i36484#
392 if ( pFormShell->GetImpl()->isEnhancedForm() && !m_nControlsSelected )
393 aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
395 // if the property browser is already open, we don't allow for the properties, too
396 if( pFormShell->GetImpl()->IsPropBrwOpen() )
397 aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
398 // and finally, if there's a mixed selection of forms and controls, disable the entry, too
399 else
400 aContextMenu.EnableItem( SID_FM_SHOW_PROPERTY_BROWSER,
401 (m_nControlsSelected && !m_nFormsSelected) || (!m_nControlsSelected && m_nFormsSelected) );
403 // Umbenennen gdw wenn ein Element und nicht die Root
404 aContextMenu.EnableItem( SID_FM_RENAME_OBJECT, bSingleSelection && !m_bRootSelected );
406 // der Reandonly-Eintrag ist nur auf der Root erlaubt
407 aContextMenu.EnableItem( SID_FM_OPEN_READONLY, m_bRootSelected );
408 // the same for automatic control focus
409 aContextMenu.EnableItem( SID_FM_AUTOCONTROLFOCUS, m_bRootSelected );
411 // die ConvertTo-Slots sind enabled, wenn genau ein Control selektiert ist, der
412 // dem Control entsprechende Slot ist disabled
413 if (!m_bRootSelected && !m_nFormsSelected && (m_nControlsSelected == 1))
415 aContextMenu.SetPopupMenu( SID_FM_CHANGECONTROLTYPE, FmXFormShell::GetConversionMenu() );
416 #if OSL_DEBUG_LEVEL > 0
417 FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
418 OSL_ENSURE( pFormShell->GetImpl()->isSolelySelected( pCurrent->GetFormComponent() ),
419 "NavigatorTree::Command: inconsistency between the navigator selection, and the selection as the shell knows it!" );
420 #endif
422 pFormShell->GetImpl()->checkControlConversionSlotsForCurrentSelection( *aContextMenu.GetPopupMenu( SID_FM_CHANGECONTROLTYPE ) );
424 else
425 aContextMenu.EnableItem( SID_FM_CHANGECONTROLTYPE, false );
427 // jetzt alles, was disabled wurde, wech
428 aContextMenu.RemoveDisabledEntries(true, true);
430 // OpenReadOnly setzen
432 aContextMenu.CheckItem( SID_FM_OPEN_READONLY, pFormModel->GetOpenInDesignMode() );
433 aContextMenu.CheckItem( SID_FM_AUTOCONTROLFOCUS, pFormModel->GetAutoControlFocus() );
435 sal_uInt16 nSlotId = aContextMenu.Execute( this, ptWhere );
436 switch( nSlotId )
438 case SID_FM_NEW_FORM:
440 OUString aStr(SVX_RESSTR(RID_STR_FORM));
441 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
443 pFormModel->BegUndo(aUndoStr);
444 // der Slot war nur verfuegbar, wenn es genau einen selektierten Eintrag gibt und dieser die Root
445 // oder ein Formular ist
446 NewForm( *m_arrCurrentSelection.begin() );
447 pFormModel->EndUndo();
449 } break;
450 case SID_FM_NEW_HIDDEN:
452 OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
453 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
455 pFormModel->BegUndo(aUndoStr);
456 // dieser Slot war guletig bei (genau) einem selektierten Formular
457 OUString fControlName = FM_COMPONENT_HIDDEN;
458 NewControl( fControlName, *m_arrCurrentSelection.begin() );
459 pFormModel->EndUndo();
461 } break;
463 case SID_CUT:
464 doCut();
465 break;
467 case SID_COPY:
468 doCopy();
469 break;
471 case SID_PASTE:
472 doPaste();
473 break;
475 case SID_FM_DELETE:
477 DeleteSelection();
479 break;
480 case SID_FM_TAB_DIALOG:
482 // dieser Slot galt bei genau einem selektierten Formular
483 SvTreeListEntry* pSelectedForm = *m_arrCurrentSelection.begin();
484 DBG_ASSERT( IsFormEntry(pSelectedForm), "NavigatorTree::Command: Dieser Eintrag muss ein FormEntry sein." );
486 FmFormData* pFormData = (FmFormData*)pSelectedForm->GetUserData();
487 Reference< XForm > xForm( pFormData->GetFormIface());
489 Reference< XTabControllerModel > xTabController(xForm, UNO_QUERY);
490 if( !xTabController.is() )
491 break;
492 GetNavModel()->GetFormShell()->GetImpl()->ExecuteTabOrderDialog( xTabController );
494 break;
496 case SID_FM_SHOW_PROPERTY_BROWSER:
498 ShowSelectionProperties(true);
500 break;
501 case SID_FM_RENAME_OBJECT:
503 // das war bei genau einem Nicht-Root-Eintrag erlaubt
504 EditEntry( *m_arrCurrentSelection.begin() );
506 break;
507 case SID_FM_OPEN_READONLY:
509 pFormModel->SetOpenInDesignMode( !pFormModel->GetOpenInDesignMode() );
510 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
512 break;
513 case SID_FM_AUTOCONTROLFOCUS:
515 pFormModel->SetAutoControlFocus( !pFormModel->GetAutoControlFocus() );
516 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
518 break;
519 default:
520 if (pFormShell->GetImpl()->isControlConversionSlot(nSlotId))
522 FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
523 if ( pFormShell->GetImpl()->executeControlConversionSlot( pCurrent->GetFormComponent(), nSlotId ) )
524 ShowSelectionProperties();
528 bHandled = true;
529 } break;
532 if (!bHandled)
533 SvTreeListBox::Command( rEvt );
537 SvTreeListEntry* NavigatorTree::FindEntry( FmEntryData* pEntryData )
539 if( !pEntryData ) return NULL;
540 SvTreeListEntry* pCurEntry = First();
541 FmEntryData* pCurEntryData;
542 while( pCurEntry )
544 pCurEntryData = (FmEntryData*)pCurEntry->GetUserData();
545 if( pCurEntryData && pCurEntryData->IsEqualWithoutChildren(pEntryData) )
546 return pCurEntry;
548 pCurEntry = Next( pCurEntry );
551 return NULL;
555 void NavigatorTree::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
557 if( rHint.ISA(FmNavRemovedHint) )
559 FmNavRemovedHint* pRemovedHint = (FmNavRemovedHint*)&rHint;
560 FmEntryData* pEntryData = pRemovedHint->GetEntryData();
561 Remove( pEntryData );
564 else if( rHint.ISA(FmNavInsertedHint) )
566 FmNavInsertedHint* pInsertedHint = (FmNavInsertedHint*)&rHint;
567 FmEntryData* pEntryData = pInsertedHint->GetEntryData();
568 sal_uInt32 nRelPos = pInsertedHint->GetRelPos();
569 Insert( pEntryData, nRelPos );
572 else if( rHint.ISA(FmNavModelReplacedHint) )
574 FmEntryData* pData = ((FmNavModelReplacedHint*)&rHint)->GetEntryData();
575 SvTreeListEntry* pEntry = FindEntry( pData );
576 if (pEntry)
577 { // das Image neu setzen
578 SetCollapsedEntryBmp( pEntry, pData->GetNormalImage() );
579 SetExpandedEntryBmp( pEntry, pData->GetNormalImage() );
583 else if( rHint.ISA(FmNavNameChangedHint) )
585 FmNavNameChangedHint* pNameChangedHint = (FmNavNameChangedHint*)&rHint;
586 SvTreeListEntry* pEntry = FindEntry( pNameChangedHint->GetEntryData() );
587 SetEntryText( pEntry, pNameChangedHint->GetNewName() );
590 else if( rHint.ISA(FmNavClearedHint) )
592 SvTreeListBox::Clear();
595 // Default-Eintrag "Formulare"
596 Image aRootImage( m_aNavigatorImages.GetImage( RID_SVXIMG_FORMS ) );
597 m_pRootEntry = InsertEntry( SVX_RESSTR(RID_STR_FORMS), aRootImage, aRootImage,
598 NULL, false, 0, NULL );
600 else if (!m_bMarkingObjects && rHint.ISA(FmNavRequestSelectHint))
601 { // wenn m_bMarkingObjects sal_True ist, markiere ich gerade selber Objekte, und da der ganze Mechanismus dahinter synchron ist,
602 // ist das genau der Hint, der durch mein Markieren ausgeloest wird, also kann ich ihn ignorieren
603 FmNavRequestSelectHint* pershHint = (FmNavRequestSelectHint*)&rHint;
604 FmEntryDataArray& arredToSelect = pershHint->GetItems();
605 SynchronizeSelection(arredToSelect);
607 if (pershHint->IsMixedSelection())
608 // in diesem Fall habe ich alles deselektiert, obwohl die View u.U. eine gemischte Markierung hatte
609 // ich muss also im naechsten Select den Navigator an die View anpassen
610 m_bPrevSelectionMixed = true;
615 SvTreeListEntry* NavigatorTree::Insert( FmEntryData* pEntryData, sal_uIntPtr nRelPos )
618 // Aktuellen Eintrag einfuegen
619 SvTreeListEntry* pParentEntry = FindEntry( pEntryData->GetParent() );
620 SvTreeListEntry* pNewEntry;
622 if( !pParentEntry )
623 pNewEntry = InsertEntry( pEntryData->GetText(),
624 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
625 m_pRootEntry, false, nRelPos, pEntryData );
627 else
628 pNewEntry = InsertEntry( pEntryData->GetText(),
629 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
630 pParentEntry, false, nRelPos, pEntryData );
633 // Wenn Root-Eintrag Root expandieren
634 if( !pParentEntry )
635 Expand( m_pRootEntry );
638 // Children einfuegen
639 FmEntryDataList* pChildList = pEntryData->GetChildList();
640 size_t nChildCount = pChildList->size();
641 FmEntryData* pChildData;
642 for( size_t i = 0; i < nChildCount; i++ )
644 pChildData = pChildList->at( i );
645 Insert( pChildData, TREELIST_APPEND );
648 return pNewEntry;
652 void NavigatorTree::Remove( FmEntryData* pEntryData )
654 if( !pEntryData )
655 return;
657 // der Entry zu den Daten
658 SvTreeListEntry* pEntry = FindEntry( pEntryData );
659 if (!pEntry)
660 return;
662 // Eintrag aus TreeListBox entfernen
663 // ich darf das Select, das ich ausloese, nicht behandeln :
664 // Select aendert die MarkList der View, wenn das gerade auch jemand anders macht und dabei ein Remove
665 // triggert, haben wir mit ziemlicher Sicherheit ein Problem - Paradebeispiel war das Gruppieren von Controls mit
666 // offenem Navigator ...)
667 LockSelectionHandling();
669 // ein kleines Problem : ich merke mir meine selektierten Daten, wenn mir jetzt jemand einen selektierten Eintrag
670 // unter dem Hintern wegschiesst, werde ich inkonsistent ... was schlecht waere
671 Select(pEntry, false);
673 // beim eigentlichen Entfernen kann die Selection geaendert werden, da ich aber das SelectionHandling abgeschaltet
674 // habe, muss ich mich hinterher darum kuemmern
675 sal_uIntPtr nExpectedSelectionCount = GetSelectionCount();
677 if( pEntry )
678 GetModel()->Remove( pEntry );
680 if (nExpectedSelectionCount != GetSelectionCount())
681 SynchronizeSelection();
683 // und standardmaessig behandle ich das Select natuerlich
684 UnlockSelectionHandling();
688 bool NavigatorTree::IsFormEntry( SvTreeListEntry* pEntry )
690 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
691 return !pEntryData || pEntryData->ISA(FmFormData);
695 bool NavigatorTree::IsFormComponentEntry( SvTreeListEntry* pEntry )
697 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
698 return pEntryData && pEntryData->ISA(FmControlData);
702 bool NavigatorTree::implAcceptPaste( )
704 SvTreeListEntry* pFirstSelected = FirstSelected();
705 if ( !pFirstSelected || NextSelected( pFirstSelected ) )
706 // no selected entry, or at least two selected entries
707 return false;
709 // get the clipboard
710 TransferableDataHelper aClipboardContent( TransferableDataHelper::CreateFromSystemClipboard( this ) );
712 sal_Int8 nAction = m_aControlExchange.isClipboardOwner() && doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY;
713 return ( nAction == implAcceptDataTransfer( aClipboardContent.GetDataFlavorExVector(), nAction, pFirstSelected, false ) );
717 sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
719 return implAcceptDataTransfer( _rFlavors, _nAction, GetEntry( _rDropPos ), _bDnD );
723 sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
725 // no target -> no drop
726 if (!_pTargetEntry)
727 return DND_ACTION_NONE;
729 // format check
730 bool bHasDefControlFormat = OControlExchange::hasFieldExchangeFormat( _rFlavors );
731 bool bHasControlPathFormat = OControlExchange::hasControlPathFormat( _rFlavors );
732 bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( _rFlavors );
733 if (!bHasDefControlFormat && !bHasControlPathFormat && !bHasHiddenControlsFormat)
734 return DND_ACTION_NONE;
736 bool bSelfSource = _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner();
738 if ( bHasHiddenControlsFormat )
739 { // bHasHiddenControlsFormat means that only hidden controls are part of the data
741 // hidden controls can be copied to a form only
742 if ( !_pTargetEntry || ( _pTargetEntry == m_pRootEntry ) || !IsFormEntry( _pTargetEntry ) )
743 return DND_ACTION_NONE;
745 return bSelfSource ? ( DND_ACTION_COPYMOVE & _nAction ) : DND_ACTION_COPY;
748 if ( !bSelfSource )
750 // DnD or CnP crossing navigator boundaries
751 // The main problem here is that the current API does not allow us to sneak into the content which
752 // is to be inserted. So we have to allow it for the moment, but maybe reject later on (in the real drop).
754 // TODO: this smart behaviour later on ... at the moment, we disallow data transfer crossing navigator
755 // boundaries.
757 return DND_ACTION_NONE;
760 DBG_ASSERT( _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner(),
761 "NavigatorTree::implAcceptDataTransfer: here only with source=dest!" );
762 // somebody changed the logic of this method ...
764 // from here on, I can work with m_aControlExchange instead of _rData!
766 bool bForeignCollection = m_aControlExchange->getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
767 if ( bForeignCollection )
769 // crossing shell/page boundaries, we can exchange hidden controls only
770 // But if we survived the checks above, we do not have hidden controls.
771 // -> no data transfer
772 DBG_ASSERT( !bHasHiddenControlsFormat, "NavigatorTree::implAcceptDataTransfer: still hidden controls format!" );
773 // somebody changed the logic of this method ...
775 return DND_ACTION_COPY;
778 if (DND_ACTION_MOVE != _nAction) // 'normal' controls within a shell are moved only (never copied)
779 return DND_ACTION_NONE;
781 if ( m_bDragDataDirty || !bHasDefControlFormat )
783 if (!bHasControlPathFormat)
784 // ich befinde mich zwar in der Shell/Page, aus der die Controls stammen, habe aber kein Format, das den stattgefundenen
785 // Shell-Wechsel ueberlebt hat (SVX_FM_CONTROLS_AS_PATH)
786 return DND_ACTION_NONE;
788 // da die Shell waehrend des Draggens umgeschaltet wude, muss ich die Liste des ExchangeObjektes wieder neu aufbauen
789 // (dort stehen SvLBoxEntries drin, und die sind bei der Umschaltung floeten gegangen)
790 m_aControlExchange->buildListFromPath(this, m_pRootEntry);
791 m_bDragDataDirty = false;
794 // die Liste der gedroppten Eintraege aus dem DragServer
795 const ListBoxEntrySet& aDropped = m_aControlExchange->selected();
796 DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implAcceptDataTransfer: keine Eintraege !");
798 bool bDropTargetIsComponent = IsFormComponentEntry( _pTargetEntry );
799 //SvTreeListEntry* pDropTargetParent = GetParent( _pTargetEntry );
801 // conditions to disallow the drop
802 // 0) the root entry is part of the list (can't DnD the root!)
803 // 1) one of the draged entries is to be dropped onto it's own parent
804 // 2) - " - is to be dropped onto itself
805 // 3) - " - is a Form and to be dropped onto one of it's descendants
806 // 4) one of the entries is a control and to be dropped onto the root
807 // 5) a control or form will be dropped onto a control which is _not_ a sibling (dropping onto a sibling
808 // means moving the control)
810 // collect the ancestors of the drop targte (speeds up 3)
811 SvLBoxEntrySortedArray arrDropAnchestors;
812 SvTreeListEntry* pLoop = _pTargetEntry;
813 while (pLoop)
815 arrDropAnchestors.insert(pLoop);
816 pLoop = GetParent(pLoop);
819 for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
820 dropped != aDropped.end();
821 ++dropped
824 SvTreeListEntry* pCurrent = *dropped;
825 SvTreeListEntry* pCurrentParent = GetParent(pCurrent);
827 // test for 0)
828 if (pCurrent == m_pRootEntry)
829 return DND_ACTION_NONE;
831 // test for 1)
832 if ( _pTargetEntry == pCurrentParent )
833 return DND_ACTION_NONE;
835 // test for 2)
836 if (pCurrent == _pTargetEntry)
837 return DND_ACTION_NONE;
839 // test for 5)
840 // if ( bDropTargetIsComponent && (pDropTargetParent != pCurrentParent) )
841 if ( bDropTargetIsComponent ) // TODO : die obige Zeile wieder rein, dann muss aber ExecuteDrop das Vertauschen auch beherrschen
842 return DND_ACTION_NONE;
844 // test for 3)
845 if ( IsFormEntry(pCurrent) )
847 if ( arrDropAnchestors.find(pCurrent) != arrDropAnchestors.end() )
848 return DND_ACTION_NONE;
849 } else if ( IsFormComponentEntry(pCurrent) )
851 // test for 4)
852 if (_pTargetEntry == m_pRootEntry)
853 return DND_ACTION_NONE;
857 return DND_ACTION_MOVE;
861 sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& rEvt )
863 ::Point aDropPos = rEvt.maPosPixel;
865 // kuemmern wir uns erst mal um moeglich DropActions (Scrollen und Aufklappen)
866 if (rEvt.mbLeaving)
868 if (m_aDropActionTimer.IsActive())
869 m_aDropActionTimer.Stop();
870 } else
872 bool bNeedTrigger = false;
873 // auf dem ersten Eintrag ?
874 if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
876 m_aDropActionType = DA_SCROLLUP;
877 bNeedTrigger = true;
878 } else
879 // auf dem letzten (bzw. in dem Bereich, den ein Eintrag einnehmen wuerde, wenn er unten genau buendig
880 // abschliessen wuerde) ?
881 if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
883 m_aDropActionType = DA_SCROLLDOWN;
884 bNeedTrigger = true;
885 } else
886 { // auf einem Entry mit Children, der nicht aufgeklappt ist ?
887 SvTreeListEntry* pDropppedOn = GetEntry(aDropPos);
888 if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
890 // -> aufklappen
891 m_aDropActionType = DA_EXPANDNODE;
892 bNeedTrigger = true;
896 if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
898 // neu anfangen zu zaehlen
899 m_aTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
900 // die Pos merken, da ich auch AcceptDrops bekomme, wenn sich die Maus gar nicht bewegt hat
901 m_aTimerTriggered = aDropPos;
902 // und den Timer los
903 if (!m_aDropActionTimer.IsActive()) // gibt es den Timer schon ?
905 m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
906 m_aDropActionTimer.Start();
908 } else if (!bNeedTrigger)
909 m_aDropActionTimer.Stop();
912 return implAcceptDataTransfer( GetDataFlavorExVector(), rEvt.mnAction, aDropPos, true );
916 sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
918 return implExecuteDataTransfer( _rData, _nAction, GetEntry( _rDropPos ), _bDnD );
922 sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
924 const DataFlavorExVector& rDataFlavors = _rData.GetDataFlavorExVector();
926 if ( DND_ACTION_NONE == implAcceptDataTransfer( rDataFlavors, _nAction, _pTargetEntry, _bDnD ) )
927 // under some platforms, it may happen that ExecuteDrop is called though AcceptDrop returned DND_ACTION_NONE
928 return DND_ACTION_NONE;
930 // ware schlecht, wenn nach dem Droppen noch gescrollt wird ...
931 if (m_aDropActionTimer.IsActive())
932 m_aDropActionTimer.Stop();
934 if (!_pTargetEntry)
935 // no target -> no drop
936 return DND_ACTION_NONE;
938 // format checks
939 #ifdef DBG_UTIL
940 bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( rDataFlavors );
941 bool bForeignCollection = _rData.getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
942 DBG_ASSERT(!bForeignCollection || bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: invalid format (AcceptDrop shouldn't have let this pass) !");
943 DBG_ASSERT(bForeignCollection || !m_bDragDataDirty, "NavigatorTree::implExecuteDataTransfer: invalid state (shell changed since last exchange resync) !");
944 // das sollte in AcceptDrop erledigt worden sein : dort wird in _rData die Liste der Controls aufgebaut und m_bDragDataDirty
945 // zurueckgesetzt
946 #endif
948 if ( DND_ACTION_COPY == _nAction )
949 { // bHasHiddenControlsFormat means that only hidden controls are part of the data
950 DBG_ASSERT( bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: copy allowed for hidden controls only!" );
951 DBG_ASSERT( _pTargetEntry && ( _pTargetEntry != m_pRootEntry ) && IsFormEntry( _pTargetEntry ),
952 "NavigatorTree::implExecuteDataTransfer: should not be here!" );
953 // implAcceptDataTransfer should have caught both cases
955 DBG_ASSERT(bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: only copying of hidden controls is supported !");
956 // das sollte das AcceptDrop abgefangen haben
958 // da ich gleich die Zielobjekte alle selektieren will (und nur die)
959 SelectAll(false);
961 Sequence< Reference< XInterface > > aControls = _rData.hiddenControls();
962 sal_Int32 nCount = aControls.getLength();
963 const Reference< XInterface >* pControls = aControls.getConstArray();
965 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
966 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
968 // innerhalb eines Undo ...
969 if (pFormModel)
971 OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
972 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
973 pFormModel->BegUndo(aUndoStr);
976 // die Conrtols kopieren
977 for (sal_Int32 i=0; i<nCount; ++i)
979 // neues Control anlegen
980 OUString fControlName = FM_COMPONENT_HIDDEN;
981 FmControlData* pNewControlData = NewControl( fControlName, _pTargetEntry, false);
982 Reference< XPropertySet > xNewPropSet( pNewControlData->GetPropertySet() );
984 // und die Properties des alten in das neue kopieren
985 Reference< XPropertySet > xCurrent(pControls[i], UNO_QUERY);
986 #if (OSL_DEBUG_LEVEL > 1)
987 // nur mal eben sehen, ob das Ding tatsaechlich ein hidden control ist
988 sal_Int16 nClassId = ::comphelper::getINT16(xCurrent->getPropertyValue(FM_PROP_CLASSID));
989 OSL_ENSURE(nClassId == FormComponentType::HIDDENCONTROL, "NavigatorTree::implExecuteDataTransfer: invalid control in drop list !");
990 // wenn das SVX_FM_HIDDEN_CONTROLS-Format vorhanden ist, dann sollten wirklich nur hidden controls in der Sequenz
991 // stecken
992 #endif // (OSL_DEBUG_LEVEL > 1)
993 Reference< XPropertySetInfo > xPropInfo( xCurrent->getPropertySetInfo());
994 Sequence< Property> seqAllCurrentProps = xPropInfo->getProperties();
995 Property* pAllCurrentProps = seqAllCurrentProps.getArray();
996 for (sal_Int32 j=0; j<seqAllCurrentProps.getLength(); ++j)
998 OUString sCurrentProp = pAllCurrentProps[j].Name;
999 if (((pAllCurrentProps[j].Attributes & PropertyAttribute::READONLY) == 0) && (sCurrentProp != FM_PROP_NAME))
1000 { // (read-only attribs werden natuerlich nicht gesetzt, dito der Name, den hat das NewControl schon eindeutig
1001 // festgelegt)
1002 xNewPropSet->setPropertyValue(sCurrentProp, xCurrent->getPropertyValue(sCurrentProp));
1006 SvTreeListEntry* pToSelect = FindEntry(pNewControlData);
1007 Select(pToSelect, true);
1008 if (i == 0)
1009 SetCurEntry(pToSelect);
1012 if (pFormModel)
1013 pFormModel->EndUndo();
1015 return _nAction;
1018 if ( !OControlExchange::hasFieldExchangeFormat( _rData.GetDataFlavorExVector() ) )
1020 // can't do anything without the internal format here ... usually happens when doing DnD or CnP
1021 // over navigator boundaries
1022 return DND_ACTION_NONE;
1025 // some data for the target
1026 bool bDropTargetIsForm = IsFormEntry(_pTargetEntry);
1027 FmFormData* pTargetData = bDropTargetIsForm ? (FmFormData*)_pTargetEntry->GetUserData() : NULL;
1029 DBG_ASSERT( DND_ACTION_COPY != _nAction, "NavigatorTree::implExecuteDataTransfer: somebody changed the logics!" );
1031 // die Liste der gedraggten Eintraege
1032 ListBoxEntrySet aDropped = _rData.selected();
1033 DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implExecuteDataTransfer: no entries!");
1035 // die Shell und das Model
1036 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1037 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
1038 if (!pFormModel)
1039 return DND_ACTION_NONE;
1041 // fuer's Undo
1042 const bool bUndo = pFormModel->IsUndoEnabled();
1044 if( bUndo )
1046 OUString strUndoDescription(SVX_RESSTR(RID_STR_UNDO_CONTAINER_REPLACE));
1047 pFormModel->BegUndo(strUndoDescription);
1050 // ich nehme vor dem Einfuegen eines Eintrages seine Selection raus, damit die Markierung dabei nicht flackert
1051 // -> das Handeln des Select locken
1052 LockSelectionHandling();
1054 // jetzt durch alle gedroppten Eintraege ...
1055 for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
1056 dropped != aDropped.end();
1057 ++dropped
1060 // ein paar Daten zum aktuellen Element
1061 SvTreeListEntry* pCurrent = *dropped;
1062 DBG_ASSERT(pCurrent != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
1063 DBG_ASSERT(GetParent(pCurrent) != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
1064 // die Root darf nicht gedraggt werden
1066 FmEntryData* pCurrentUserData = (FmEntryData*)pCurrent->GetUserData();
1068 Reference< XChild > xCurrentChild(pCurrentUserData->GetChildIFace(), UNO_QUERY);
1069 Reference< XIndexContainer > xContainer(xCurrentChild->getParent(), UNO_QUERY);
1071 FmFormData* pCurrentParentUserData = (FmFormData*)pCurrentUserData->GetParent();
1072 DBG_ASSERT(pCurrentParentUserData == NULL || pCurrentParentUserData->ISA(FmFormData), "NavigatorTree::implExecuteDataTransfer: ungueltiges Parent");
1074 // beim Vater austragen
1075 if (pCurrentParentUserData)
1076 pCurrentParentUserData->GetChildList()->remove( pCurrentUserData );
1077 else
1078 GetNavModel()->GetRootList()->remove( pCurrentUserData );
1080 // aus dem Container entfernen
1081 sal_Int32 nIndex = getElementPos(xContainer, xCurrentChild);
1082 GetNavModel()->m_pPropChangeList->Lock();
1083 // die Undo-Action fuer das Rausnehmen
1084 if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1086 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Removed,
1087 xContainer, xCurrentChild, nIndex));
1089 else if( !GetNavModel()->m_pPropChangeList->CanUndo() )
1091 FmUndoContainerAction::DisposeElement( xCurrentChild );
1094 // Events mitkopieren
1095 Reference< XEventAttacherManager > xManager(xContainer, UNO_QUERY);
1096 Sequence< ScriptEventDescriptor > aEvts;
1098 if (xManager.is() && nIndex >= 0)
1099 aEvts = xManager->getScriptEvents(nIndex);
1100 xContainer->removeByIndex(nIndex);
1102 // die Selection raus
1103 Select(pCurrent, false);
1104 // und weg
1105 Remove(pCurrentUserData);
1107 // die Stelle innerhalb des DropParents, an der ich die gedroppten Eintraege einfuegen muss
1108 if (pTargetData)
1109 xContainer = Reference< XIndexContainer > (pTargetData->GetElement(), UNO_QUERY);
1110 else
1111 xContainer = Reference< XIndexContainer > (GetNavModel()->GetForms(), UNO_QUERY);
1113 // immer ganz hinten einfuegen
1114 nIndex = xContainer->getCount();
1116 // UndoAction fuer das Einfuegen
1117 if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1118 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Inserted,
1119 xContainer, xCurrentChild, nIndex));
1121 // einfuegen im neuen Container
1122 if (pTargetData)
1124 // es wird in eine Form eingefuegt, dann brauche ich eine FormComponent
1125 xContainer->insertByIndex( nIndex,
1126 makeAny( Reference< XFormComponent >( xCurrentChild, UNO_QUERY ) ) );
1128 else
1130 xContainer->insertByIndex( nIndex,
1131 makeAny( Reference< XForm >( xCurrentChild, UNO_QUERY ) ) );
1134 if (aEvts.getLength())
1136 xManager = Reference< XEventAttacherManager > (xContainer, UNO_QUERY);
1137 if (xManager.is())
1138 xManager->registerScriptEvents(nIndex, aEvts);
1141 GetNavModel()->m_pPropChangeList->UnLock();
1143 // zuerst dem Eintrag das neue Parent
1144 pCurrentUserData->SetParent(pTargetData);
1146 // dann dem Parent das neue Child
1147 if (pTargetData)
1148 pTargetData->GetChildList()->insert( pCurrentUserData, nIndex );
1149 else
1150 GetNavModel()->GetRootList()->insert( pCurrentUserData, nIndex );
1152 // dann bei mir selber bekanntgeben und neu selektieren
1153 SvTreeListEntry* pNew = Insert( pCurrentUserData, nIndex );
1154 if ( ( aDropped.begin() == dropped ) && pNew )
1156 SvTreeListEntry* pParent = GetParent( pNew );
1157 if ( pParent )
1158 Expand( pParent );
1162 UnlockSelectionHandling();
1164 if( bUndo )
1165 pFormModel->EndUndo();
1167 // During the move, the markings of the underlying view did not change (because the view is not affected by the logical
1168 // hierarchy of the form/control models. But my selection changed - which means I have to adjust it according to the
1169 // view marks, again.
1170 SynchronizeSelection();
1172 // in addition, with the move of controls such things as "the current form" may have changed - force the shell
1173 // to update itself accordingly
1174 if( pFormShell && pFormShell->GetImpl() && pFormShell->GetFormView() )
1175 pFormShell->GetImpl()->DetermineSelection( pFormShell->GetFormView()->GetMarkedObjectList() );
1177 if ( m_aControlExchange.isClipboardOwner() && ( DND_ACTION_MOVE == _nAction ) )
1178 m_aControlExchange->clear();
1180 return _nAction;
1184 sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
1186 sal_Int8 nResult( DND_ACTION_NONE );
1188 if ( m_aControlExchange.isDragSource() )
1189 nResult = implExecuteDataTransfer( *m_aControlExchange, rEvt.mnAction, rEvt.maPosPixel, true );
1190 else
1192 OControlTransferData aDroppedData( rEvt.maDropEvent.Transferable );
1193 nResult = implExecuteDataTransfer( aDroppedData, rEvt.mnAction, rEvt.maPosPixel, true );
1196 return nResult;
1200 void NavigatorTree::doPaste()
1204 if ( m_aControlExchange.isClipboardOwner() )
1206 implExecuteDataTransfer( *m_aControlExchange, doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY, FirstSelected(), false );
1208 else
1210 // the clipboard content
1211 Reference< XClipboard > xClipboard( GetClipboard() );
1212 Reference< XTransferable > xTransferable;
1213 if ( xClipboard.is() )
1214 xTransferable = xClipboard->getContents();
1216 OControlTransferData aClipboardContent( xTransferable );
1217 implExecuteDataTransfer( aClipboardContent, DND_ACTION_COPY, FirstSelected(), false );
1220 catch( const Exception& )
1222 OSL_FAIL( "NavigatorTree::doPaste: caught an exception!" );
1227 void NavigatorTree::doCopy()
1229 if ( implPrepareExchange( DND_ACTION_COPY ) )
1231 m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1232 m_aControlExchange.copyToClipboard( );
1237 void NavigatorTree::ModelHasRemoved( SvTreeListEntry* _pEntry )
1239 SvTreeListEntry* pTypedEntry = static_cast< SvTreeListEntry* >( _pEntry );
1240 if ( doingKeyboardCut() )
1241 m_aCutEntries.erase( pTypedEntry );
1243 if ( m_aControlExchange.isDataExchangeActive() )
1245 if ( 0 == m_aControlExchange->onEntryRemoved( pTypedEntry ) )
1247 // last of the entries which we put into the clipboard has been deleted from the tree.
1248 // Give up the clipboard ownership.
1249 m_aControlExchange.clear();
1255 void NavigatorTree::doCut()
1257 if ( implPrepareExchange( DND_ACTION_MOVE ) )
1259 m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1260 m_aControlExchange.copyToClipboard( );
1261 m_bKeyboardCut = true;
1263 // mark all the entries we just "cut" into the clipboard as "nearly moved"
1264 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1265 it != m_arrCurrentSelection.end(); ++it )
1267 SvTreeListEntry* pEntry = *it;
1268 if ( pEntry )
1270 m_aCutEntries.insert( pEntry );
1271 pEntry->SetFlags( pEntry->GetFlags() | SV_ENTRYFLAG_SEMITRANSPARENT );
1272 InvalidateEntry( pEntry );
1279 void NavigatorTree::KeyInput(const ::KeyEvent& rKEvt)
1281 const KeyCode& rCode = rKEvt.GetKeyCode();
1283 // delete?
1284 if (rKEvt.GetKeyCode().GetCode() == KEY_DELETE && !rKEvt.GetKeyCode().GetModifier())
1286 DeleteSelection();
1287 return;
1290 // copy'n'paste?
1291 switch ( rCode.GetFunction() )
1293 case KEYFUNC_CUT:
1294 doCut();
1295 break;
1297 case KEYFUNC_PASTE:
1298 if ( implAcceptPaste() )
1299 doPaste();
1300 break;
1302 case KEYFUNC_COPY:
1303 doCopy();
1304 break;
1306 default:
1307 break;
1310 SvTreeListBox::KeyInput(rKEvt);
1314 bool NavigatorTree::EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection )
1316 if (!SvTreeListBox::EditingEntry( pEntry, rSelection ))
1317 return false;
1319 return (pEntry && (pEntry->GetUserData() != NULL));
1320 // die Wurzel, die ich nicht umbenennen darf, hat als UserData NULL
1324 void NavigatorTree::NewForm( SvTreeListEntry* pParentEntry )
1327 // ParentFormData holen
1328 if( !IsFormEntry(pParentEntry) )
1329 return;
1331 FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();
1334 // Neue Form erzeugen
1335 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
1336 Reference< XForm > xNewForm(xContext->getServiceManager()->createInstanceWithContext(FM_SUN_COMPONENT_FORM, xContext), UNO_QUERY);
1337 if (!xNewForm.is())
1338 return;
1340 FmFormData* pNewFormData = new FmFormData( xNewForm, m_aNavigatorImages, pParentFormData );
1343 // Namen setzen
1344 OUString aName = GenerateName(pNewFormData);
1345 pNewFormData->SetText(aName);
1347 Reference< XPropertySet > xPropertySet(xNewForm, UNO_QUERY);
1348 if (!xPropertySet.is())
1349 return;
1352 xPropertySet->setPropertyValue( FM_PROP_NAME, makeAny(aName) );
1353 // a form should always have the command type table as default
1354 xPropertySet->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE)));
1356 catch ( const Exception& )
1358 OSL_FAIL("NavigatorTree::NewForm : could not set esssential properties !");
1363 // Form einfuegen
1364 GetNavModel()->Insert( pNewFormData, TREELIST_APPEND, true );
1367 // Neue Form als aktive Form setzen
1368 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1369 if( pFormShell )
1371 InterfaceBag aSelection;
1372 aSelection.insert( xNewForm );
1373 pFormShell->GetImpl()->setCurrentSelection( aSelection );
1375 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_PROPERTIES, true, true);
1377 GetNavModel()->SetModified();
1380 // In EditMode schalten
1381 SvTreeListEntry* pNewEntry = FindEntry( pNewFormData );
1382 EditEntry( pNewEntry );
1386 FmControlData* NavigatorTree::NewControl( const OUString& rServiceName, SvTreeListEntry* pParentEntry, bool bEditName )
1389 // ParentForm holen
1390 if (!GetNavModel()->GetFormShell())
1391 return NULL;
1392 if (!IsFormEntry(pParentEntry))
1393 return NULL;
1395 FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();;
1396 Reference< XForm > xParentForm( pParentFormData->GetFormIface());
1399 // Neue Component erzeugen
1400 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
1401 Reference<XFormComponent> xNewComponent( xContext->getServiceManager()->createInstanceWithContext(rServiceName, xContext), UNO_QUERY);
1402 if (!xNewComponent.is())
1403 return NULL;
1405 FmControlData* pNewFormControlData = new FmControlData( xNewComponent, m_aNavigatorImages, pParentFormData );
1408 // Namen setzen
1409 FmFormView* pFormView = GetNavModel()->GetFormShell()->GetFormView();
1410 SdrPageView* pPageView = pFormView->GetSdrPageView();
1411 FmFormPage* pPage = (FmFormPage*)pPageView->GetPage();
1413 OUString sName = pPage->GetImpl().setUniqueName( xNewComponent, xParentForm );
1415 pNewFormControlData->SetText( sName );
1418 // FormComponent einfuegen
1419 GetNavModel()->Insert( pNewFormControlData, TREELIST_APPEND, true );
1420 GetNavModel()->SetModified();
1422 if (bEditName)
1425 // In EditMode schalten
1426 SvTreeListEntry* pNewEntry = FindEntry( pNewFormControlData );
1427 Select( pNewEntry, true );
1428 EditEntry( pNewEntry );
1431 return pNewFormControlData;
1435 OUString NavigatorTree::GenerateName( FmEntryData* pEntryData )
1437 const sal_uInt16 nMaxCount = 99;
1438 OUString aNewName;
1441 // BasisNamen erzeugen
1442 OUString aBaseName;
1443 if( pEntryData->ISA(FmFormData) )
1444 aBaseName = SVX_RESSTR( RID_STR_STDFORMNAME );
1445 else if( pEntryData->ISA(FmControlData) )
1446 aBaseName = SVX_RESSTR( RID_STR_CONTROL );
1449 // Neuen Namen erstellen
1450 FmFormData* pFormParentData = (FmFormData*)pEntryData->GetParent();
1452 for( sal_Int32 i=0; i<nMaxCount; i++ )
1454 aNewName = aBaseName;
1455 if( i>0 )
1457 aNewName += " ";
1458 aNewName += OUString::number(i).getStr();
1461 if( GetNavModel()->FindData(aNewName, pFormParentData,false) == NULL )
1462 break;
1465 return aNewName;
1469 bool NavigatorTree::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText )
1471 if (EditingCanceled())
1472 return true;
1474 GrabFocus();
1475 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
1476 bool bRes = GetNavModel()->Rename( pEntryData, rNewText);
1477 if( !bRes )
1479 m_pEditEntry = pEntry;
1480 nEditEvent = Application::PostUserEvent( LINK(this, NavigatorTree, OnEdit) );
1481 } else
1482 SetCursor(pEntry, true);
1484 return bRes;
1488 IMPL_LINK_NOARG(NavigatorTree, OnEdit)
1490 nEditEvent = 0;
1491 EditEntry( m_pEditEntry );
1492 m_pEditEntry = NULL;
1494 return 0L;
1498 IMPL_LINK_NOARG(NavigatorTree, OnDropActionTimer)
1500 if (--m_aTimerCounter > 0)
1501 return 0L;
1503 switch ( m_aDropActionType )
1505 case DA_EXPANDNODE:
1507 SvTreeListEntry* pToExpand = GetEntry(m_aTimerTriggered);
1508 if (pToExpand && (GetChildCount(pToExpand) > 0) && !IsExpanded(pToExpand))
1509 // tja, eigentlich muesste ich noch testen, ob die Node nicht schon expandiert ist, aber ich
1510 // habe dazu weder in den Basisklassen noch im Model eine Methode gefunden ...
1511 // aber ich denke, die BK sollte es auch so vertragen
1512 Expand(pToExpand);
1514 // nach dem Expand habe ich im Gegensatz zum Scrollen natuerlich nix mehr zu tun
1515 m_aDropActionTimer.Stop();
1517 break;
1519 case DA_SCROLLUP :
1520 ScrollOutputArea( 1 );
1521 m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1522 break;
1524 case DA_SCROLLDOWN :
1525 ScrollOutputArea( -1 );
1526 m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1527 break;
1531 return 0L;
1535 IMPL_LINK(NavigatorTree, OnEntrySelDesel, NavigatorTree*, /*pThis*/)
1537 m_sdiState = SDI_DIRTY;
1539 if (IsSelectionHandlingLocked())
1540 return 0L;
1542 if (m_aSynchronizeTimer.IsActive())
1543 m_aSynchronizeTimer.Stop();
1545 m_aSynchronizeTimer.SetTimeout(EXPLORER_SYNC_DELAY);
1546 m_aSynchronizeTimer.Start();
1548 return 0L;
1552 IMPL_LINK_NOARG(NavigatorTree, OnSynchronizeTimer)
1554 SynchronizeMarkList();
1555 return 0L;
1560 IMPL_LINK_NOARG(NavigatorTree, OnClipboardAction)
1562 if ( !m_aControlExchange.isClipboardOwner() )
1564 if ( doingKeyboardCut() )
1566 for ( ListBoxEntrySet::const_iterator i = m_aCutEntries.begin();
1567 i != m_aCutEntries.end();
1571 SvTreeListEntry* pEntry = *i;
1572 if ( !pEntry )
1573 continue;
1575 pEntry->SetFlags( pEntry->GetFlags() & ~SV_ENTRYFLAG_SEMITRANSPARENT );
1576 InvalidateEntry( pEntry );
1578 ListBoxEntrySet aEmpty;
1579 m_aCutEntries.swap( aEmpty );
1581 m_bKeyboardCut = false;
1584 return 0L;
1588 void NavigatorTree::ShowSelectionProperties(bool bForce)
1590 // zuerst brauche ich die FormShell
1591 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1592 if (!pFormShell)
1593 // keine Shell -> ich koennte kein curObject setzen -> raus
1594 return;
1596 CollectSelectionData(SDI_ALL);
1597 SAL_WARN_IF(static_cast<size_t>(m_nFormsSelected + m_nControlsSelected
1598 + (m_bRootSelected ? 1 : 0)) != m_arrCurrentSelection.size(),
1599 "svx.form",
1600 "NavigatorTree::ShowSelectionProperties : selection meta data invalid !");
1603 InterfaceBag aSelection;
1604 bool bSetSelectionAsMarkList = false;
1606 if (m_bRootSelected)
1607 ; // no properties for the root, neither for single nor for multi selection
1608 else if ( m_nFormsSelected + m_nControlsSelected == 0 ) // none of the two should be less 0
1609 ; // no selection -> no properties
1610 else if ( m_nFormsSelected * m_nControlsSelected != 0 )
1611 ; // mixed selection -> no properties
1612 else
1613 { // either only forms, or only controls are selected
1614 if (m_arrCurrentSelection.size() == 1)
1616 if (m_nFormsSelected > 0)
1617 { // es ist genau eine Form selektiert
1618 FmFormData* pFormData = (FmFormData*)(*m_arrCurrentSelection.begin())->GetUserData();
1619 aSelection.insert( Reference< XInterface >( pFormData->GetFormIface(), UNO_QUERY ) );
1621 else
1622 { // es ist genau ein Control selektiert (egal ob hidden oder normal)
1623 FmEntryData* pEntryData = (FmEntryData*)(*m_arrCurrentSelection.begin())->GetUserData();
1625 aSelection.insert( Reference< XInterface >( pEntryData->GetElement(), UNO_QUERY ) );
1628 else
1629 { // wir haben eine MultiSelection, also muessen wir ein MultiSet dafuer aufbauen
1630 if (m_nFormsSelected > 0)
1631 { // ... nur Forms
1632 // erstmal die PropertySet-Interfaces der Forms einsammeln
1633 SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1634 for ( sal_Int32 i = 0; i < m_nFormsSelected; ++i )
1636 FmFormData* pFormData = (FmFormData*)(*it)->GetUserData();
1637 aSelection.insert( pFormData->GetPropertySet().get() );
1638 ++it;
1641 else
1642 { // ... nur Controls
1643 if (m_nHiddenControls == m_nControlsSelected)
1644 { // ein MultiSet fuer die Properties der hidden controls
1645 SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1646 for ( sal_Int32 i = 0; i < m_nHiddenControls; ++i )
1648 FmEntryData* pEntryData = (FmEntryData*)(*it)->GetUserData();
1649 aSelection.insert( pEntryData->GetPropertySet().get() );
1650 ++it;
1653 else if (m_nHiddenControls == 0)
1654 { // nur normale Controls
1655 bSetSelectionAsMarkList = true;
1662 // und dann meine Form und mein SelObject
1663 if ( bSetSelectionAsMarkList )
1664 pFormShell->GetImpl()->setCurrentSelectionFromMark( pFormShell->GetFormView()->GetMarkedObjectList() );
1665 else
1666 pFormShell->GetImpl()->setCurrentSelection( aSelection );
1668 if ( pFormShell->GetImpl()->IsPropBrwOpen() || bForce )
1670 // und jetzt kann ich das Ganze dem PropertyBrowser uebergeben
1671 pFormShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON );
1676 void NavigatorTree::DeleteSelection()
1678 // die Root darf ich natuerlich nicht mitloeschen
1679 bool bRootSelected = IsSelected(m_pRootEntry);
1680 sal_uIntPtr nSelectedEntries = GetSelectionCount();
1681 if (bRootSelected && (nSelectedEntries > 1)) // die Root plus andere Elemente ?
1682 Select(m_pRootEntry, false); // ja -> die Root raus
1684 if ((nSelectedEntries == 0) || bRootSelected) // immer noch die Root ?
1685 return; // -> sie ist das einzige selektierte -> raus
1687 DBG_ASSERT(!m_bPrevSelectionMixed, "NavigatorTree::DeleteSelection() : loeschen nicht erlaubt wenn Markierung und Selektion nciht konsistent");
1689 // ich brauche unten das FormModel ...
1690 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1691 if (!pFormShell)
1692 return;
1693 FmFormModel* pFormModel = pFormShell->GetFormModel();
1694 if (!pFormModel)
1695 return;
1697 // jetzt muss ich noch die DeleteList etwas absichern : wenn man ein Formular und ein abhaengiges
1698 // Element loescht - und zwar in dieser Reihenfolge - dann ist der SvLBoxEntryPtr des abhaengigen Elementes
1699 // natuerlich schon ungueltig, wenn es geloescht werden soll ... diesen GPF, den es dann mit Sicherheit gibt,
1700 // gilt es zu verhindern, also die 'normalisierte' Liste
1701 CollectSelectionData( SDI_NORMALIZED );
1703 // see below for why we need this mapping from models to shapes
1704 FmFormView* pFormView = pFormShell->GetFormView();
1705 SdrPageView* pPageView = pFormView ? pFormView->GetSdrPageView() : NULL;
1706 SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
1707 DBG_ASSERT( pPage, "NavigatorTree::DeleteSelection: invalid form page!" );
1709 MapModelToShape aModelShapes;
1710 if ( pPage )
1711 collectShapeModelMapping( pPage, aModelShapes );
1713 // problem: we have to use ExplorerModel::Remove, since only this one properly deletes Form objects.
1714 // But, the controls themself must be deleted via DeleteMarked (else, the Writer has some problems
1715 // somewhere). In case I'd first delete the structure, then the controls, the UNDO would not work
1716 // (since UNDO then would mean to first restore the controls, then the structure, means their parent
1717 // form). The other way round, the EntryDatas would be invalid, if I'd first delete the controls and
1718 // then go on to the strucure. This means I have to delete the forms *after* the normal controls, so
1719 // that during UNDO, they're restored in the proper order.
1720 pFormShell->GetImpl()->EnableTrackProperties(false);
1721 for (SvLBoxEntrySortedArray::reverse_iterator it = m_arrCurrentSelection.rbegin();
1722 it != m_arrCurrentSelection.rend(); )
1724 FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
1726 // eine Form ?
1727 bool bIsForm = pCurrent->ISA(FmFormData);
1729 // da ich das Loeschen im folgenden der View ueberlasse und dabei auf deren MarkList aufbaue, im Normalfall aber bei
1730 // einem makierten Formular nur die direkt, nicht die indirekt abhaengigen Controls markiert werden, muss ich das hier
1731 // noch nachholen
1732 if (bIsForm)
1733 MarkViewObj((FmFormData*)pCurrent, true, true); // das zweite sal_True heisst "deep"
1735 // ein hidden control ?
1736 bool bIsHidden = IsHiddenControl(pCurrent);
1738 // Forms und hidden Controls muss ich behalten, alles andere nicht
1739 if (!bIsForm && !bIsHidden)
1741 // well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
1742 // be deleted automatically. This is because for every model (except forms and hidden control models)
1743 // there exist a shape, which is marked _if_and_only_if_ the model is selected in our tree.
1744 if ( aModelShapes.find( pCurrent->GetElement() ) != aModelShapes.end() )
1746 // if there's a shape for the current entry, then either it is marked or it is in a
1747 // hidden layer (#i28502#), or something like this.
1748 // In the first case, it will be deleted below, in the second case, we currently don't
1749 // delete it, as there's no real (working!) API for this, neither in UNO nor in non-UNO.
1750 m_arrCurrentSelection.erase( --(it.base()) );
1752 else
1753 ++it;
1754 // In case there is no shape for the current entry, we keep the entry in m_arrCurrentSelection,
1755 // since then we can definitely remove it.
1756 // #103597#
1758 else
1759 ++it;
1761 pFormShell->GetImpl()->EnableTrackProperties(true);
1763 // let the view delete the marked controls
1764 pFormShell->GetFormView()->DeleteMarked();
1766 // start UNDO at this point. Unfortunately, this results in 2 UNDO actions, since DeleteMarked is
1767 // creating an own one. However, if we'd move it before DeleteMarked, Writer does not really like
1768 // this ... :(
1769 // #i31038#
1772 // initialize UNDO
1773 OUString aUndoStr;
1774 if ( m_arrCurrentSelection.size() == 1 )
1776 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE);
1777 if (m_nFormsSelected)
1778 aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_FORM ) );
1779 else
1780 // it must be a control (else the root would be selected, but it cannot be deleted)
1781 aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_CONTROL ) );
1783 else
1785 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE_MULTIPLE);
1786 aUndoStr = aUndoStr.replaceFirst( "#", OUString::number( m_arrCurrentSelection.size() ) );
1788 pFormModel->BegUndo(aUndoStr);
1791 // remove remaining structure
1792 for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1793 it != m_arrCurrentSelection.end(); ++it)
1795 FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
1797 // if the entry still has children, we skipped deletion of one of those children.
1798 // This may for instance be because the shape is in a hidden layer, where we're unable
1799 // to remove it
1800 if ( pCurrent->GetChildList()->size() )
1801 continue;
1803 // noch ein kleines Problem, bevor ich das ganz loesche : wenn es eine Form ist und die Shell diese als CurrentObject
1804 // kennt, dann muss ich ihr das natuerlich ausreden
1805 if (pCurrent->ISA(FmFormData))
1807 Reference< XForm > xCurrentForm( static_cast< FmFormData* >( pCurrent )->GetFormIface() );
1808 if ( pFormShell->GetImpl()->getCurrentForm() == xCurrentForm ) // die Shell kennt die zu loeschende Form ?
1809 pFormShell->GetImpl()->forgetCurrentForm(); // -> wegnehmen ...
1811 GetNavModel()->Remove(pCurrent, true);
1813 pFormModel->EndUndo();
1817 void NavigatorTree::CollectSelectionData(SELDATA_ITEMS sdiHow)
1819 DBG_ASSERT(sdiHow != SDI_DIRTY, "NavigatorTree::CollectSelectionData : ever thought about your parameter ? DIRTY ?");
1820 if (sdiHow == m_sdiState)
1821 return;
1823 m_arrCurrentSelection.clear();
1824 m_nFormsSelected = m_nControlsSelected = m_nHiddenControls = 0;
1825 m_bRootSelected = false;
1827 SvTreeListEntry* pSelectionLoop = FirstSelected();
1828 while (pSelectionLoop)
1830 // erst mal die Zaehlung der verschiedenen Elemente
1831 if (pSelectionLoop == m_pRootEntry)
1832 m_bRootSelected = true;
1833 else
1835 if (IsFormEntry(pSelectionLoop))
1836 ++m_nFormsSelected;
1837 else
1839 ++m_nControlsSelected;
1840 if (IsHiddenControl((FmEntryData*)(pSelectionLoop->GetUserData())))
1841 ++m_nHiddenControls;
1845 if (sdiHow == SDI_NORMALIZED)
1847 // alles, was schon einen selektierten Vorfahr hat, nicht mitnehmen
1848 if (pSelectionLoop == m_pRootEntry)
1849 m_arrCurrentSelection.insert(pSelectionLoop);
1850 else
1852 SvTreeListEntry* pParentLoop = GetParent(pSelectionLoop);
1853 while (pParentLoop)
1855 // eigentlich muesste ich testen, ob das Parent in der m_arrCurrentSelection steht ...
1856 // Aber wenn es selektiert ist, dann steht es in m_arrCurrentSelection, oder wenigstens einer seiner Vorfahren,
1857 // wenn der auch schon selektiert war. In beiden Faellen reicht also die Abfrage IsSelected
1858 if (IsSelected(pParentLoop))
1859 break;
1860 else
1862 if (m_pRootEntry == pParentLoop)
1864 // bis (exclusive) zur Root gab es kein selektiertes Parent -> der Eintrag gehoert in die normalisierte Liste
1865 m_arrCurrentSelection.insert(pSelectionLoop);
1866 break;
1868 else
1869 pParentLoop = GetParent(pParentLoop);
1874 else if (sdiHow == SDI_NORMALIZED_FORMARK)
1876 SvTreeListEntry* pParent = GetParent(pSelectionLoop);
1877 if (!pParent || !IsSelected(pParent) || IsFormEntry(pSelectionLoop))
1878 m_arrCurrentSelection.insert(pSelectionLoop);
1880 else
1881 m_arrCurrentSelection.insert(pSelectionLoop);
1884 pSelectionLoop = NextSelected(pSelectionLoop);
1887 m_sdiState = sdiHow;
1891 void NavigatorTree::SynchronizeSelection(FmEntryDataArray& arredToSelect)
1893 LockSelectionHandling();
1894 if (arredToSelect.empty())
1896 SelectAll(false);
1898 else
1900 // erst mal gleiche ich meine aktuelle Selektion mit der geforderten SelectList ab
1901 SvTreeListEntry* pSelection = FirstSelected();
1902 while (pSelection)
1904 FmEntryData* pCurrent = (FmEntryData*)pSelection->GetUserData();
1905 if (pCurrent != NULL)
1907 FmEntryDataArray::iterator it = arredToSelect.find(pCurrent);
1908 if ( it != arredToSelect.end() )
1909 { // der Entry ist schon selektiert, steht aber auch in der SelectList -> er kann aus letzterer
1910 // raus
1911 arredToSelect.erase(it);
1912 } else
1913 { // der Entry ist selektiert, aber steht nicht in der SelectList -> Selektion rausnehmen
1914 Select(pSelection, false);
1915 // und sichtbar machen (kann ja sein, dass das die einzige Modifikation ist, die ich hier in dem
1916 // ganzen Handler mache, dann sollte das zu sehen sein)
1917 MakeVisible(pSelection);
1920 else
1921 Select(pSelection, false);
1923 pSelection = NextSelected(pSelection);
1926 // jetzt habe ich in der SelectList genau die Eintraege, die noch selektiert werden muessen
1927 // zwei Moeglichkeiten : 1) ich gehe durch die SelectList, besorge mir zu jedem Eintrag meinen SvTreeListEntry
1928 // und selektiere diesen (waere irgendwie intuitiver ;)) 2) ich gehe durch alle meine SvLBoxEntries und selektiere
1929 // genau die, die ich in der SelectList finde
1930 // 1) braucht O(k*n) (k=Laenge der SelectList, n=Anzahl meiner Entries), plus den Fakt, dass FindEntry nicht den
1931 // Pointer auf die UserDaten vergleicht, sondern ein aufwendigeres IsEqualWithoutChildren durchfuehrt
1932 // 2) braucht O(n*log k), dupliziert aber etwas Code (naemlich den aus FindEntry)
1933 // da das hier eine relativ oft aufgerufenen Stelle sein koennte (bei jeder Aenderung in der Markierung in der View !),
1934 // nehme ich doch lieber letzteres
1935 SvTreeListEntry* pLoop = First();
1936 while( pLoop )
1938 FmEntryData* pCurEntryData = (FmEntryData*)pLoop->GetUserData();
1939 FmEntryDataArray::iterator it = arredToSelect.find(pCurEntryData);
1940 if ( it != arredToSelect.end() )
1942 Select(pLoop, true);
1943 MakeVisible(pLoop);
1944 SetCursor(pLoop, true);
1947 pLoop = Next( pLoop );
1950 UnlockSelectionHandling();
1954 void NavigatorTree::SynchronizeSelection()
1956 // Shell und View
1957 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1958 if(!pFormShell) return;
1960 FmFormView* pFormView = pFormShell->GetFormView();
1961 if (!pFormView) return;
1963 GetNavModel()->BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
1967 void NavigatorTree::SynchronizeMarkList()
1969 // die Shell werde ich brauchen ...
1970 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1971 if (!pFormShell) return;
1973 CollectSelectionData(SDI_NORMALIZED_FORMARK);
1975 // Die View soll jetzt kein Notify bei einer Aenderung der MarkList rauslassen
1976 pFormShell->GetImpl()->EnableTrackProperties(false);
1978 UnmarkAllViewObj();
1980 for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1981 it != m_arrCurrentSelection.end(); ++it)
1983 SvTreeListEntry* pSelectionLoop = *it;
1984 // Bei Formselektion alle Controls dieser Form markieren
1985 if (IsFormEntry(pSelectionLoop) && (pSelectionLoop != m_pRootEntry))
1986 MarkViewObj((FmFormData*)pSelectionLoop->GetUserData(), true, false);
1988 // Bei Controlselektion Control-SdrObjects markieren
1989 else if (IsFormComponentEntry(pSelectionLoop))
1991 FmControlData* pControlData = (FmControlData*)pSelectionLoop->GetUserData();
1992 if (pControlData)
1995 // Beim HiddenControl kann kein Object selektiert werden
1996 Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
1997 if (!xFormComponent.is())
1998 continue;
1999 Reference< XPropertySet > xSet(xFormComponent, UNO_QUERY);
2000 if (!xSet.is())
2001 continue;
2003 sal_uInt16 nClassId = ::comphelper::getINT16(xSet->getPropertyValue(FM_PROP_CLASSID));
2004 if (nClassId != FormComponentType::HIDDENCONTROL)
2005 MarkViewObj(pControlData, true, true);
2010 // wenn der PropertyBrowser offen ist, muss ich den entsprechend meiner Selektion anpassen
2011 // (NICHT entsprechend der MarkList der View : wenn ich ein Formular selektiert habe, sind in der
2012 // View alle zugehoerigen Controls markiert, trotzdem moechte ich natuerlich die Formular-Eigenschaften
2013 // sehen)
2014 ShowSelectionProperties(false);
2016 // Flag an View wieder zuruecksetzen
2017 pFormShell->GetImpl()->EnableTrackProperties(true);
2019 // wenn jetzt genau eine Form selektiert ist, sollte die Shell das als CurrentForm mitbekommen
2020 // (wenn SelectionHandling nicht locked ist, kuemmert sich die View eigentlich in MarkListHasChanged drum,
2021 // aber der Mechanismus greift zum Beispiel nicht, wenn die Form leer ist)
2022 if ((m_arrCurrentSelection.size() == 1) && (m_nFormsSelected == 1))
2024 FmFormData* pSingleSelectionData = PTR_CAST( FmFormData, static_cast< FmEntryData* >( FirstSelected()->GetUserData() ) );
2025 DBG_ASSERT( pSingleSelectionData, "NavigatorTree::SynchronizeMarkList: invalid selected form!" );
2026 if ( pSingleSelectionData )
2028 InterfaceBag aSelection;
2029 aSelection.insert( Reference< XInterface >( pSingleSelectionData->GetFormIface(), UNO_QUERY ) );
2030 pFormShell->GetImpl()->setCurrentSelection( aSelection );
2036 bool NavigatorTree::IsHiddenControl(FmEntryData* pEntryData)
2038 if (pEntryData == NULL) return false;
2040 Reference< XPropertySet > xProperties( pEntryData->GetPropertySet() );
2041 if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
2043 Any aClassID = xProperties->getPropertyValue( FM_PROP_CLASSID );
2044 return (::comphelper::getINT16(aClassID) == FormComponentType::HIDDENCONTROL);
2046 return false;
2050 bool NavigatorTree::Select( SvTreeListEntry* pEntry, bool bSelect )
2052 if (bSelect == IsSelected(pEntry)) // das passiert manchmal, ich glaube, die Basisklasse geht zu sehr auf Nummer sicher ;)
2053 return true;
2055 return SvTreeListBox::Select(pEntry, bSelect );
2059 void NavigatorTree::UnmarkAllViewObj()
2061 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2062 if( !pFormShell )
2063 return;
2064 FmFormView* pFormView = pFormShell->GetFormView();
2065 pFormView->UnMarkAll();
2068 void NavigatorTree::MarkViewObj(FmFormData* pFormData, bool bMark, bool bDeep )
2070 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2071 if( !pFormShell )
2072 return;
2074 // first collect all sdrobjects
2075 ::std::set< Reference< XFormComponent > > aObjects;
2076 CollectObjects(pFormData,bDeep,aObjects);
2079 // In der Page das entsprechende SdrObj finden und selektieren
2080 FmFormView* pFormView = pFormShell->GetFormView();
2081 SdrPageView* pPageView = pFormView->GetSdrPageView();
2082 SdrPage* pPage = pPageView->GetPage();
2083 //FmFormPage* pFormPage = dynamic_cast< FmFormPage* >( pPage );
2085 SdrObjListIter aIter( *pPage );
2086 while ( aIter.IsMore() )
2088 SdrObject* pSdrObject = aIter.Next();
2089 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
2090 if ( !pFormObject )
2091 continue;
2093 Reference< XFormComponent > xControlModel( pFormObject->GetUnoControlModel(),UNO_QUERY );
2094 if ( xControlModel.is() && aObjects.find(xControlModel) != aObjects.end() && bMark != pFormView->IsObjMarked( pSdrObject ) )
2096 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
2097 pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
2099 } // while ( aIter.IsMore() )
2100 if ( bMark )
2102 // make the mark visible
2103 ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
2104 for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2106 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
2107 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
2108 if ( ( OUTDEV_WINDOW == rOutDev.GetOutDevType() ) && !aMarkRect.IsEmpty() )
2110 pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
2112 } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2116 void NavigatorTree::CollectObjects(FmFormData* pFormData, bool bDeep, ::std::set< Reference< XFormComponent > >& _rObjects)
2118 FmEntryDataList* pChildList = pFormData->GetChildList();
2119 FmEntryData* pEntryData;
2120 FmControlData* pControlData;
2121 for( size_t i = 0; i < pChildList->size(); ++i )
2123 pEntryData = pChildList->at( i );
2124 if( pEntryData->ISA(FmControlData) )
2126 pControlData = (FmControlData*)pEntryData;
2127 _rObjects.insert(pControlData->GetFormComponent());
2128 } // if( pEntryData->ISA(FmControlData) )
2129 else if (bDeep && (pEntryData->ISA(FmFormData)))
2130 CollectObjects((FmFormData*)pEntryData,bDeep,_rObjects);
2131 } // for( sal_uInt32 i=0; i<pChildList->Count(); i++ )
2134 void NavigatorTree::MarkViewObj( FmControlData* pControlData, bool bMarkHandles, bool bMark)
2136 if( !pControlData )
2137 return;
2138 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2139 if( !pFormShell )
2140 return;
2143 // In der Page das entsprechende SdrObj finden und selektieren
2144 FmFormView* pFormView = pFormShell->GetFormView();
2145 Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
2146 SdrPageView* pPageView = pFormView->GetSdrPageView();
2147 SdrPage* pPage = pPageView->GetPage();
2149 bool bPaint = false;
2150 SdrObjListIter aIter( *pPage );
2151 while ( aIter.IsMore() )
2153 SdrObject* pSdrObject = aIter.Next();
2154 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
2155 if ( !pFormObject )
2156 continue;
2158 Reference< XInterface > xControlModel( pFormObject->GetUnoControlModel() );
2159 if ( xControlModel != xFormComponent )
2160 continue;
2162 // mark the object
2163 if ( bMark != pFormView->IsObjMarked( pSdrObject ) )
2164 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
2165 pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
2167 if ( !bMarkHandles || !bMark )
2168 continue;
2170 bPaint = true;
2172 } // while ( aIter.IsMore() )
2173 if ( bPaint )
2175 // make the mark visible
2176 ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
2177 for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2179 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
2180 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
2181 if ( OUTDEV_WINDOW == rOutDev.GetOutDevType() )
2183 pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
2185 } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2190 } // namespace svxform
2194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */