fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / form / navigatortree.cxx
blob828054700dc4b5a58d5a39f913adc364ffa8ccfd
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.hrc"
29 #include "fmexpl.hxx"
30 #include "svx/fmresids.hrc"
31 #include "fmshimp.hxx"
32 #include "fmservs.hxx"
33 #include "fmundo.hxx"
34 #include "fmpgeimp.hxx"
35 #include "fmitems.hxx"
36 #include "fmobj.hxx"
37 #include "fmprop.hrc"
38 #include <vcl/wrkwin.hxx>
39 #include <sfx2/viewsh.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/property.hxx>
44 #include <com/sun/star/form/FormComponentType.hpp>
45 #include <com/sun/star/sdb/CommandType.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <com/sun/star/script/XEventAttacherManager.hpp>
48 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
49 #include <com/sun/star/datatransfer/XTransferable.hpp>
50 #include <svx/sdrpaintwindow.hxx>
52 #include <svx/svxdlg.hxx>
53 #include <svx/dialogs.hrc>
54 #include "svtools/treelistentry.hxx"
55 #include <rtl/logfile.hxx>
56 //............................................................................
57 namespace svxform
59 //............................................................................
61 #define DROP_ACTION_TIMER_INITIAL_TICKS 10
62 // solange dauert es, bis das Scrollen anspringt
63 #define DROP_ACTION_TIMER_SCROLL_TICKS 3
64 // in diesen Intervallen wird jeweils eine Zeile gescrollt
65 #define DROP_ACTION_TIMER_TICK_BASE 10
66 // das ist die Basis, mit der beide Angaben multipliziert werden (in ms)
68 #define EXPLORER_SYNC_DELAY 200
69 // dieser Betrag an Millisekunden wird gewartet, ehe der Explorer nach einem Select oder Deselect die ::com::sun::star::sdbcx::View synchronisiert
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::form;
75 using namespace ::com::sun::star::awt;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::script;
78 using namespace ::com::sun::star::datatransfer;
79 using namespace ::com::sun::star::datatransfer::clipboard;
80 using namespace ::com::sun::star::sdb;
82 //========================================================================
83 // helper
84 //========================================================================
86 typedef ::std::map< Reference< XInterface >, SdrObject*, ::comphelper::OInterfaceCompare< XInterface > >
87 MapModelToShape;
88 typedef MapModelToShape::value_type ModelShapePair;
90 //------------------------------------------------------------------------
91 void collectShapeModelMapping( SdrPage* _pPage, MapModelToShape& _rMapping )
93 OSL_ENSURE( _pPage, "collectShapeModelMapping: invalid arg!" );
95 _rMapping.clear();
97 SdrObjListIter aIter( *_pPage );
98 while ( aIter.IsMore() )
100 SdrObject* pSdrObject = aIter.Next();
101 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
102 if ( !pFormObject )
103 continue;
105 Reference< XInterface > xNormalizedModel( pFormObject->GetUnoControlModel(), UNO_QUERY );
106 // note that this is normalized (i.e. queried for XInterface explicitly)
108 #ifdef DBG_UTIL
109 ::std::pair< MapModelToShape::iterator, bool > aPos =
110 #endif
111 _rMapping.insert( ModelShapePair( xNormalizedModel, pSdrObject ) );
112 DBG_ASSERT( aPos.second, "collectShapeModelMapping: model was already existent!" );
113 // if this asserts, this would mean we have 2 shapes pointing to the same model
117 //========================================================================
118 // class NavigatorTree
119 //========================================================================
121 //------------------------------------------------------------------------
122 NavigatorTree::NavigatorTree( const Reference< XMultiServiceFactory >& _xORB,
123 Window* pParent )
124 :SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HSCROLL ) // #100258# OJ WB_HSCROLL added
125 ,m_aControlExchange(this)
126 ,m_xORB(_xORB)
127 ,m_pNavModel( NULL )
128 ,m_pRootEntry(NULL)
129 ,m_pEditEntry(NULL)
130 ,nEditEvent(0)
131 ,m_sdiState(SDI_DIRTY)
132 ,m_aTimerTriggered(-1,-1)
133 ,m_aDropActionType( DA_SCROLLUP )
134 ,m_nSelectLock(0)
135 ,m_nFormsSelected(0)
136 ,m_nControlsSelected(0)
137 ,m_nHiddenControls(0)
138 ,m_aTimerCounter( DROP_ACTION_TIMER_INITIAL_TICKS )
139 ,m_bDragDataDirty(sal_False)
140 ,m_bPrevSelectionMixed(sal_False)
141 ,m_bMarkingObjects(sal_False)
142 ,m_bRootSelected(sal_False)
143 ,m_bInitialUpdate(sal_True)
144 ,m_bKeyboardCut( sal_False )
146 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::NavigatorTree" );
147 SetHelpId( HID_FORM_NAVIGATOR );
149 m_aNavigatorImages = ImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
151 SetNodeBitmaps(
152 m_aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
153 m_aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
156 SetDragDropMode(0xFFFF);
157 EnableInplaceEditing( sal_True );
158 SetSelectionMode(MULTIPLE_SELECTION);
160 m_pNavModel = new NavigatorTreeModel( m_aNavigatorImages );
161 Clear();
163 StartListening( *m_pNavModel );
165 m_aDropActionTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnDropActionTimer));
167 m_aSynchronizeTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnSynchronizeTimer));
168 SetSelectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
169 SetDeselectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
172 //------------------------------------------------------------------------
173 NavigatorTree::~NavigatorTree()
175 if( nEditEvent )
176 Application::RemoveUserEvent( nEditEvent );
178 if (m_aSynchronizeTimer.IsActive())
179 m_aSynchronizeTimer.Stop();
181 DBG_ASSERT(GetNavModel() != NULL, "NavigatorTree::~NavigatorTree : unerwartet : kein ExplorerModel");
182 EndListening( *m_pNavModel );
183 Clear();
184 delete m_pNavModel;
187 //------------------------------------------------------------------------
188 void NavigatorTree::Clear()
190 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Clear" );
191 m_pNavModel->Clear();
194 //------------------------------------------------------------------------
195 void NavigatorTree::UpdateContent( FmFormShell* pFormShell )
197 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::UpdateContent" );
198 if (m_bInitialUpdate)
200 GrabFocus();
201 m_bInitialUpdate = sal_False;
204 FmFormShell* pOldShell = GetNavModel()->GetFormShell();
205 FmFormPage* pOldPage = GetNavModel()->GetFormPage();
206 FmFormPage* pNewPage = pFormShell ? pFormShell->GetCurPage() : NULL;
208 if ((pOldShell != pFormShell) || (pOldPage != pNewPage))
210 // neue Shell, waehrend ich gerade editiere ?
211 if (IsEditingActive())
212 CancelTextEditing();
214 m_bDragDataDirty = sal_True; // sicherheitshalber, auch wenn ich gar nicht dragge
216 GetNavModel()->UpdateContent( pFormShell );
218 // wenn es eine Form gibt, die Root expandieren
219 if (m_pRootEntry && !IsExpanded(m_pRootEntry))
220 Expand(m_pRootEntry);
221 // wenn es GENAU eine Form gibt, auch diese expandieren
222 if (m_pRootEntry)
224 SvTreeListEntry* pFirst = FirstChild(m_pRootEntry);
225 if (pFirst && !NextSibling(pFirst))
226 Expand(pFirst);
230 //------------------------------------------------------------------------------
231 sal_Bool NavigatorTree::implAllowExchange( sal_Int8 _nAction, sal_Bool* _pHasNonHidden )
233 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implAllowExchange" );
234 SvTreeListEntry* pCurEntry = GetCurEntry();
235 if (!pCurEntry)
236 return sal_False;
238 // die Informationen fuer das AcceptDrop und ExecuteDrop
239 CollectSelectionData(SDI_ALL);
240 if (m_arrCurrentSelection.empty())
241 // nothing to do
242 return sal_False;
244 // testen, ob es sich vielleicht ausschliesslich um hidden controls handelt (dann koennte ich pCtrlExch noch ein
245 // zusaetzliches Format geben)
246 sal_Bool bHasNonHidden = sal_False;
247 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
248 it != m_arrCurrentSelection.end(); ++it )
250 FmEntryData* pCurrent = static_cast< FmEntryData* >( (*it)->GetUserData() );
251 if ( IsHiddenControl( pCurrent ) )
252 continue;
253 bHasNonHidden = sal_True;
254 break;
257 if ( bHasNonHidden && ( 0 == ( _nAction & DND_ACTION_MOVE ) ) )
258 // non-hidden controls need to be moved
259 return sal_False;
261 if ( _pHasNonHidden )
262 *_pHasNonHidden = bHasNonHidden;
264 return sal_True;
267 //------------------------------------------------------------------------------
268 sal_Bool NavigatorTree::implPrepareExchange( sal_Int8 _nAction )
270 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implPrepareExchange" );
272 EndSelection();
274 sal_Bool bHasNonHidden = sal_False;
275 if ( !implAllowExchange( _nAction, &bHasNonHidden ) )
276 return sal_False;
278 m_aControlExchange.prepareDrag();
279 m_aControlExchange->setFocusEntry( GetCurEntry() );
281 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
282 it != m_arrCurrentSelection.end(); ++it )
283 m_aControlExchange->addSelectedEntry(*it);
285 m_aControlExchange->setFormsRoot( GetNavModel()->GetFormPage()->GetForms() );
286 m_aControlExchange->buildPathFormat( this, m_pRootEntry );
288 if (!bHasNonHidden)
290 // eine entsprechende Sequenz aufbauen
291 Sequence< Reference< XInterface > > seqIFaces(m_arrCurrentSelection.size());
292 Reference< XInterface >* pArray = seqIFaces.getArray();
293 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
294 it != m_arrCurrentSelection.end(); ++it, ++pArray )
295 *pArray = static_cast< FmEntryData* >( (*it)->GetUserData() )->GetElement();
297 // und das neue Format
298 m_aControlExchange->addHiddenControlsFormat(seqIFaces);
301 m_bDragDataDirty = sal_False;
302 return sal_True;
305 //------------------------------------------------------------------------------
306 void NavigatorTree::StartDrag( sal_Int8 /*nAction*/, const ::Point& /*rPosPixel*/ )
308 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::StartDrag" );
309 EndSelection();
311 if ( !implPrepareExchange( DND_ACTION_COPYMOVE ) )
312 // nothing to do or something went wrong
313 return;
315 // jetzt haben wir alle in der aktuelle Situation moeglichen Formate eingesammelt, es kann also losgehen ...
316 m_aControlExchange.startDrag( DND_ACTION_COPYMOVE );
319 //------------------------------------------------------------------------------
320 void NavigatorTree::Command( const CommandEvent& rEvt )
322 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Command" );
323 sal_Bool bHandled = sal_False;
324 switch( rEvt.GetCommand() )
326 case COMMAND_CONTEXTMENU:
328 // die Stelle, an der geklickt wurde
329 ::Point ptWhere;
330 if (rEvt.IsMouseEvent())
332 ptWhere = rEvt.GetMousePosPixel();
333 SvTreeListEntry* ptClickedOn = GetEntry(ptWhere);
334 if (ptClickedOn == NULL)
335 break;
336 if ( !IsSelected(ptClickedOn) )
338 SelectAll(sal_False);
339 Select(ptClickedOn, sal_True);
340 SetCurEntry(ptClickedOn);
343 else
345 if (m_arrCurrentSelection.empty()) // kann nur bei Kontextmenue ueber Tastatur passieren
346 break;
348 SvTreeListEntry* pCurrent = GetCurEntry();
349 if (!pCurrent)
350 break;
351 ptWhere = GetEntryPosition(pCurrent);
354 // meine Selektionsdaten auf den aktuellen Stand
355 CollectSelectionData(SDI_ALL);
357 // wenn mindestens ein Nicht-Root-Eintrag selektiert ist und die Root auch, dann nehme ich letztere aus der Selektion
358 // fix wieder raus
359 if ( (m_arrCurrentSelection.size() > 1) && m_bRootSelected )
361 Select( m_pRootEntry, sal_False );
362 SetCursor( *m_arrCurrentSelection.begin(), sal_True);
364 sal_Bool bSingleSelection = (m_arrCurrentSelection.size() == 1);
367 DBG_ASSERT( (m_arrCurrentSelection.size() > 0) || m_bRootSelected, "keine Eintraege selektiert" );
368 // solte nicht passieren, da ich oben bei der IsSelected-Abfrage auf jeden Fall einen selektiert haette,
369 // wenn das vorher nicht der Fall gewesen waere
372 // das Menue zusammenbasteln
373 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
374 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
375 if( pFormShell && pFormModel )
377 PopupMenu aContextMenu(SVX_RES(RID_FMEXPLORER_POPUPMENU));
378 PopupMenu* pSubMenuNew = aContextMenu.GetPopupMenu( SID_FM_NEW );
380 // das 'Neu'-Untermenue gibt es nur, wenn genau die Root oder genau ein Formular selektiert sind
381 aContextMenu.EnableItem( SID_FM_NEW, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
383 // 'Neu'\'Formular' unter genau den selben Bedingungen
384 pSubMenuNew->EnableItem( SID_FM_NEW_FORM, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
385 pSubMenuNew->SetItemImage(SID_FM_NEW_FORM, m_aNavigatorImages.GetImage(RID_SVXIMG_FORM));
386 pSubMenuNew->SetItemImage(SID_FM_NEW_HIDDEN, m_aNavigatorImages.GetImage(RID_SVXIMG_HIDDEN));
388 // 'Neu'\'verstecktes...', wenn genau ein Formular selektiert ist
389 pSubMenuNew->EnableItem( SID_FM_NEW_HIDDEN, bSingleSelection && m_nFormsSelected );
391 // 'Delete': everything which is not root can be removed
392 aContextMenu.EnableItem( SID_FM_DELETE, !m_bRootSelected );
394 // 'Cut', 'Copy' and 'Paste'
395 aContextMenu.EnableItem( SID_CUT, !m_bRootSelected && implAllowExchange( DND_ACTION_MOVE ) );
396 aContextMenu.EnableItem( SID_COPY, !m_bRootSelected && implAllowExchange( DND_ACTION_COPY ) );
397 aContextMenu.EnableItem( SID_PASTE, implAcceptPaste( ) );
399 // der TabDialog, wenn es genau ein Formular ist ...
400 aContextMenu.EnableItem( SID_FM_TAB_DIALOG, bSingleSelection && m_nFormsSelected );
402 // in XML forms, we don't allow for the properties of a form
403 // #i36484#
404 if ( pFormShell->GetImpl()->isEnhancedForm() && !m_nControlsSelected )
405 aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
407 // if the property browser is already open, we don't allow for the properties, too
408 if( pFormShell->GetImpl()->IsPropBrwOpen() )
409 aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
410 // and finally, if there's a mixed selection of forms and controls, disable the entry, too
411 else
412 aContextMenu.EnableItem( SID_FM_SHOW_PROPERTY_BROWSER,
413 (m_nControlsSelected && !m_nFormsSelected) || (!m_nControlsSelected && m_nFormsSelected) );
415 // Umbenennen gdw wenn ein Element und nicht die Root
416 aContextMenu.EnableItem( SID_FM_RENAME_OBJECT, bSingleSelection && !m_bRootSelected );
418 // der Reandonly-Eintrag ist nur auf der Root erlaubt
419 aContextMenu.EnableItem( SID_FM_OPEN_READONLY, m_bRootSelected );
420 // the same for automatic control focus
421 aContextMenu.EnableItem( SID_FM_AUTOCONTROLFOCUS, m_bRootSelected );
423 // die ConvertTo-Slots sind enabled, wenn genau ein Control selektiert ist, der
424 // dem Control entsprechende Slot ist disabled
425 if (!m_bRootSelected && !m_nFormsSelected && (m_nControlsSelected == 1))
427 aContextMenu.SetPopupMenu( SID_FM_CHANGECONTROLTYPE, FmXFormShell::GetConversionMenu() );
428 #if OSL_DEBUG_LEVEL > 0
429 FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
430 OSL_ENSURE( pFormShell->GetImpl()->isSolelySelected( pCurrent->GetFormComponent() ),
431 "NavigatorTree::Command: inconsistency between the navigator selection, and the selection as the shell knows it!" );
432 #endif
434 pFormShell->GetImpl()->checkControlConversionSlotsForCurrentSelection( *aContextMenu.GetPopupMenu( SID_FM_CHANGECONTROLTYPE ) );
436 else
437 aContextMenu.EnableItem( SID_FM_CHANGECONTROLTYPE, sal_False );
439 // jetzt alles, was disabled wurde, wech
440 aContextMenu.RemoveDisabledEntries(sal_True, sal_True);
441 //////////////////////////////////////////////////////////
442 // OpenReadOnly setzen
444 aContextMenu.CheckItem( SID_FM_OPEN_READONLY, pFormModel->GetOpenInDesignMode() );
445 aContextMenu.CheckItem( SID_FM_AUTOCONTROLFOCUS, pFormModel->GetAutoControlFocus() );
447 sal_uInt16 nSlotId = aContextMenu.Execute( this, ptWhere );
448 switch( nSlotId )
450 case SID_FM_NEW_FORM:
452 OUString aStr(SVX_RESSTR(RID_STR_FORM));
453 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
455 pFormModel->BegUndo(aUndoStr);
456 // der Slot war nur verfuegbar, wenn es genau einen selektierten Eintrag gibt und dieser die Root
457 // oder ein Formular ist
458 NewForm( *m_arrCurrentSelection.begin() );
459 pFormModel->EndUndo();
461 } break;
462 case SID_FM_NEW_HIDDEN:
464 OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
465 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
467 pFormModel->BegUndo(aUndoStr);
468 // dieser Slot war guletig bei (genau) einem selektierten Formular
469 OUString fControlName = FM_COMPONENT_HIDDEN;
470 NewControl( fControlName, *m_arrCurrentSelection.begin() );
471 pFormModel->EndUndo();
473 } break;
475 case SID_CUT:
476 doCut();
477 break;
479 case SID_COPY:
480 doCopy();
481 break;
483 case SID_PASTE:
484 doPaste();
485 break;
487 case SID_FM_DELETE:
489 DeleteSelection();
491 break;
492 case SID_FM_TAB_DIALOG:
494 // dieser Slot galt bei genau einem selektierten Formular
495 SvTreeListEntry* pSelectedForm = *m_arrCurrentSelection.begin();
496 DBG_ASSERT( IsFormEntry(pSelectedForm), "NavigatorTree::Command: Dieser Eintrag muss ein FormEntry sein." );
498 FmFormData* pFormData = (FmFormData*)pSelectedForm->GetUserData();
499 Reference< XForm > xForm( pFormData->GetFormIface());
501 Reference< XTabControllerModel > xTabController(xForm, UNO_QUERY);
502 if( !xTabController.is() )
503 break;
504 GetNavModel()->GetFormShell()->GetImpl()->ExecuteTabOrderDialog( xTabController );
506 break;
508 case SID_FM_SHOW_PROPERTY_BROWSER:
510 ShowSelectionProperties(sal_True);
512 break;
513 case SID_FM_RENAME_OBJECT:
515 // das war bei genau einem Nicht-Root-Eintrag erlaubt
516 EditEntry( *m_arrCurrentSelection.begin() );
518 break;
519 case SID_FM_OPEN_READONLY:
521 pFormModel->SetOpenInDesignMode( !pFormModel->GetOpenInDesignMode() );
522 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
524 break;
525 case SID_FM_AUTOCONTROLFOCUS:
527 pFormModel->SetAutoControlFocus( !pFormModel->GetAutoControlFocus() );
528 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
530 break;
531 default:
532 if (pFormShell->GetImpl()->isControlConversionSlot(nSlotId))
534 FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
535 if ( pFormShell->GetImpl()->executeControlConversionSlot( pCurrent->GetFormComponent(), nSlotId ) )
536 ShowSelectionProperties();
540 bHandled = sal_True;
541 } break;
544 if (!bHandled)
545 SvTreeListBox::Command( rEvt );
548 //------------------------------------------------------------------------
549 SvTreeListEntry* NavigatorTree::FindEntry( FmEntryData* pEntryData )
551 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::FindEntry" );
552 if( !pEntryData ) return NULL;
553 SvTreeListEntry* pCurEntry = First();
554 FmEntryData* pCurEntryData;
555 while( pCurEntry )
557 pCurEntryData = (FmEntryData*)pCurEntry->GetUserData();
558 if( pCurEntryData && pCurEntryData->IsEqualWithoutChildren(pEntryData) )
559 return pCurEntry;
561 pCurEntry = Next( pCurEntry );
564 return NULL;
567 //------------------------------------------------------------------------
568 void NavigatorTree::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
570 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Notify" );
571 if( rHint.ISA(FmNavRemovedHint) )
573 FmNavRemovedHint* pRemovedHint = (FmNavRemovedHint*)&rHint;
574 FmEntryData* pEntryData = pRemovedHint->GetEntryData();
575 Remove( pEntryData );
578 else if( rHint.ISA(FmNavInsertedHint) )
580 FmNavInsertedHint* pInsertedHint = (FmNavInsertedHint*)&rHint;
581 FmEntryData* pEntryData = pInsertedHint->GetEntryData();
582 sal_uInt32 nRelPos = pInsertedHint->GetRelPos();
583 Insert( pEntryData, nRelPos );
586 else if( rHint.ISA(FmNavModelReplacedHint) )
588 FmEntryData* pData = ((FmNavModelReplacedHint*)&rHint)->GetEntryData();
589 SvTreeListEntry* pEntry = FindEntry( pData );
590 if (pEntry)
591 { // das Image neu setzen
592 SetCollapsedEntryBmp( pEntry, pData->GetNormalImage() );
593 SetExpandedEntryBmp( pEntry, pData->GetNormalImage() );
597 else if( rHint.ISA(FmNavNameChangedHint) )
599 FmNavNameChangedHint* pNameChangedHint = (FmNavNameChangedHint*)&rHint;
600 SvTreeListEntry* pEntry = FindEntry( pNameChangedHint->GetEntryData() );
601 SetEntryText( pEntry, pNameChangedHint->GetNewName() );
604 else if( rHint.ISA(FmNavClearedHint) )
606 SvTreeListBox::Clear();
608 //////////////////////////////////////////////////////////////////////
609 // Default-Eintrag "Formulare"
610 Image aRootImage( m_aNavigatorImages.GetImage( RID_SVXIMG_FORMS ) );
611 m_pRootEntry = InsertEntry( SVX_RES(RID_STR_FORMS), aRootImage, aRootImage,
612 NULL, sal_False, 0, NULL );
614 else if (!m_bMarkingObjects && rHint.ISA(FmNavRequestSelectHint))
615 { // wenn m_bMarkingObjects sal_True ist, markiere ich gerade selber Objekte, und da der ganze Mechanismus dahinter synchron ist,
616 // ist das genau der Hint, der durch mein Markieren ausgeloest wird, also kann ich ihn ignorieren
617 FmNavRequestSelectHint* pershHint = (FmNavRequestSelectHint*)&rHint;
618 FmEntryDataArray& arredToSelect = pershHint->GetItems();
619 SynchronizeSelection(arredToSelect);
621 if (pershHint->IsMixedSelection())
622 // in diesem Fall habe ich alles deselektiert, obwohl die View u.U. eine gemischte Markierung hatte
623 // ich muss also im naechsten Select den Navigator an die View anpassen
624 m_bPrevSelectionMixed = sal_True;
628 //------------------------------------------------------------------------
629 SvTreeListEntry* NavigatorTree::Insert( FmEntryData* pEntryData, sal_uIntPtr nRelPos )
631 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Insert" );
632 //////////////////////////////////////////////////////////////////////
633 // Aktuellen Eintrag einfuegen
634 SvTreeListEntry* pParentEntry = FindEntry( pEntryData->GetParent() );
635 SvTreeListEntry* pNewEntry;
637 if( !pParentEntry )
638 pNewEntry = InsertEntry( pEntryData->GetText(),
639 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
640 m_pRootEntry, sal_False, nRelPos, pEntryData );
642 else
643 pNewEntry = InsertEntry( pEntryData->GetText(),
644 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
645 pParentEntry, sal_False, nRelPos, pEntryData );
647 //////////////////////////////////////////////////////////////////////
648 // Wenn Root-Eintrag Root expandieren
649 if( !pParentEntry )
650 Expand( m_pRootEntry );
652 //////////////////////////////////////////////////////////////////////
653 // Children einfuegen
654 FmEntryDataList* pChildList = pEntryData->GetChildList();
655 size_t nChildCount = pChildList->size();
656 FmEntryData* pChildData;
657 for( size_t i = 0; i < nChildCount; i++ )
659 pChildData = pChildList->at( i );
660 Insert( pChildData, LIST_APPEND );
663 return pNewEntry;
666 //------------------------------------------------------------------------
667 void NavigatorTree::Remove( FmEntryData* pEntryData )
669 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Remove" );
670 if( !pEntryData )
671 return;
673 // der Entry zu den Daten
674 SvTreeListEntry* pEntry = FindEntry( pEntryData );
675 if (!pEntry)
676 return;
678 // Eintrag aus TreeListBox entfernen
679 // ich darf das Select, das ich ausloese, nicht behandeln :
680 // Select aendert die MarkList der View, wenn das gerade auch jemand anders macht und dabei ein Remove
681 // triggert, haben wir mit ziemlicher Sicherheit ein Problem - Paradebeispiel war das Gruppieren von Controls mit
682 // offenem Navigator ...)
683 LockSelectionHandling();
685 // ein kleines Problem : ich merke mir meine selektierten Daten, wenn mir jetzt jemand einen selektierten Eintrag
686 // unter dem Hintern wegschiesst, werde ich inkonsistent ... was schlecht waere
687 Select(pEntry, sal_False);
689 // beim eigentlichen Entfernen kann die Selection geaendert werden, da ich aber das SelectionHandling abgeschaltet
690 // habe, muss ich mich hinterher darum kuemmern
691 sal_uIntPtr nExpectedSelectionCount = GetSelectionCount();
693 if( pEntry )
694 GetModel()->Remove( pEntry );
696 if (nExpectedSelectionCount != GetSelectionCount())
697 SynchronizeSelection();
699 // und standardmaessig behandle ich das Select natuerlich
700 UnlockSelectionHandling();
703 //------------------------------------------------------------------------
704 sal_Bool NavigatorTree::IsFormEntry( SvTreeListEntry* pEntry )
706 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::IsFormEntry" );
707 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
708 return !pEntryData || pEntryData->ISA(FmFormData);
711 //------------------------------------------------------------------------
712 sal_Bool NavigatorTree::IsFormComponentEntry( SvTreeListEntry* pEntry )
714 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::IsFormComponentEntry" );
715 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
716 return pEntryData && pEntryData->ISA(FmControlData);
719 //------------------------------------------------------------------------
720 sal_Bool NavigatorTree::implAcceptPaste( )
722 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implAcceptPaste" );
723 SvTreeListEntry* pFirstSelected = FirstSelected();
724 if ( !pFirstSelected || NextSelected( pFirstSelected ) )
725 // no selected entry, or at least two selected entries
726 return sal_False;
728 // get the clipboard
729 TransferableDataHelper aClipboardContent( TransferableDataHelper::CreateFromSystemClipboard( this ) );
731 sal_Int8 nAction = m_aControlExchange.isClipboardOwner() && doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY;
732 return ( nAction == implAcceptDataTransfer( aClipboardContent.GetDataFlavorExVector(), nAction, pFirstSelected, sal_False ) );
735 //------------------------------------------------------------------------
736 sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, const ::Point& _rDropPos, sal_Bool _bDnD )
738 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implAcceptDataTransfer" );
739 return implAcceptDataTransfer( _rFlavors, _nAction, GetEntry( _rDropPos ), _bDnD );
742 //------------------------------------------------------------------------
743 sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, sal_Bool _bDnD )
745 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implAcceptDataTransfer" );
746 // no target -> no drop
747 if (!_pTargetEntry)
748 return DND_ACTION_NONE;
750 // format check
751 sal_Bool bHasDefControlFormat = OControlExchange::hasFieldExchangeFormat( _rFlavors );
752 sal_Bool bHasControlPathFormat = OControlExchange::hasControlPathFormat( _rFlavors );
753 sal_Bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( _rFlavors );
754 if (!bHasDefControlFormat && !bHasControlPathFormat && !bHasHiddenControlsFormat)
755 return DND_ACTION_NONE;
757 sal_Bool bSelfSource = _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner();
759 if ( bHasHiddenControlsFormat )
760 { // bHasHiddenControlsFormat means that only hidden controls are part of the data
762 // hidden controls can be copied to a form only
763 if ( !_pTargetEntry || ( _pTargetEntry == m_pRootEntry ) || !IsFormEntry( _pTargetEntry ) )
764 return DND_ACTION_NONE;
766 return bSelfSource ? ( DND_ACTION_COPYMOVE & _nAction ) : DND_ACTION_COPY;
769 if ( !bSelfSource )
771 // DnD or CnP crossing navigator boundaries
772 // The main problem here is that the current API does not allow us to sneak into the content which
773 // is to be inserted. So we have to allow it for the moment, but maybe reject later on (in the real drop).
775 // TODO: this smart behaviour later on ... at the moment, we disallow data transfer crossing navigator
776 // boundaries.
778 return DND_ACTION_NONE;
781 DBG_ASSERT( _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner(),
782 "NavigatorTree::implAcceptDataTransfer: here only with source=dest!" );
783 // somebody changed the logic of this method ...
785 // from here on, I can work with m_aControlExchange instead of _rData!
787 sal_Bool bForeignCollection = m_aControlExchange->getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
788 if ( bForeignCollection )
790 // crossing shell/page boundaries, we can exchange hidden controls only
791 // But if we survived the checks above, we do not have hidden controls.
792 // -> no data transfer
793 DBG_ASSERT( !bHasHiddenControlsFormat, "NavigatorTree::implAcceptDataTransfer: still hidden controls format!" );
794 // somebody changed the logic of this method ...
796 return DND_ACTION_COPY;
799 if (DND_ACTION_MOVE != _nAction) // 'normal' controls within a shell are moved only (never copied)
800 return DND_ACTION_NONE;
802 if ( m_bDragDataDirty || !bHasDefControlFormat )
804 if (!bHasControlPathFormat)
805 // ich befinde mich zwar in der Shell/Page, aus der die Controls stammen, habe aber kein Format, das den stattgefundenen
806 // Shell-Wechsel ueberlebt hat (SVX_FM_CONTROLS_AS_PATH)
807 return DND_ACTION_NONE;
809 // da die Shell waehrend des Draggens umgeschaltet wude, muss ich die Liste des ExchangeObjektes wieder neu aufbauen
810 // (dort stehen SvLBoxEntries drin, und die sind bei der Umschaltung floeten gegangen)
811 m_aControlExchange->buildListFromPath(this, m_pRootEntry);
812 m_bDragDataDirty = sal_False;
815 // die Liste der gedroppten Eintraege aus dem DragServer
816 const ListBoxEntrySet& aDropped = m_aControlExchange->selected();
817 DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implAcceptDataTransfer: keine Eintraege !");
819 sal_Bool bDropTargetIsComponent = IsFormComponentEntry( _pTargetEntry );
820 //SvTreeListEntry* pDropTargetParent = GetParent( _pTargetEntry );
822 // conditions to disallow the drop
823 // 0) the root entry is part of the list (can't DnD the root!)
824 // 1) one of the draged entries is to be dropped onto it's own parent
825 // 2) - " - is to be dropped onto itself
826 // 3) - " - is a Form and to be dropped onto one of it's descendants
827 // 4) one of the entries is a control and to be dropped onto the root
828 // 5) a control or form will be dropped onto a control which is _not_ a sibling (dropping onto a sibling
829 // means moving the control)
831 // collect the ancestors of the drop targte (speeds up 3)
832 SvLBoxEntrySortedArray arrDropAnchestors;
833 SvTreeListEntry* pLoop = _pTargetEntry;
834 while (pLoop)
836 arrDropAnchestors.insert(pLoop);
837 pLoop = GetParent(pLoop);
840 for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
841 dropped != aDropped.end();
842 ++dropped
845 SvTreeListEntry* pCurrent = *dropped;
846 SvTreeListEntry* pCurrentParent = GetParent(pCurrent);
848 // test for 0)
849 if (pCurrent == m_pRootEntry)
850 return DND_ACTION_NONE;
852 // test for 1)
853 if ( _pTargetEntry == pCurrentParent )
854 return DND_ACTION_NONE;
856 // test for 2)
857 if (pCurrent == _pTargetEntry)
858 return DND_ACTION_NONE;
860 // test for 5)
861 // if ( bDropTargetIsComponent && (pDropTargetParent != pCurrentParent) )
862 if ( bDropTargetIsComponent ) // TODO : die obige Zeile wieder rein, dann muss aber ExecuteDrop das Vertauschen auch beherrschen
863 return DND_ACTION_NONE;
865 // test for 3)
866 if ( IsFormEntry(pCurrent) )
868 if ( arrDropAnchestors.find(pCurrent) != arrDropAnchestors.end() )
869 return DND_ACTION_NONE;
870 } else if ( IsFormComponentEntry(pCurrent) )
872 // test for 4)
873 if (_pTargetEntry == m_pRootEntry)
874 return DND_ACTION_NONE;
878 return DND_ACTION_MOVE;
881 //------------------------------------------------------------------------
882 sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& rEvt )
884 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::AcceptDrop" );
885 ::Point aDropPos = rEvt.maPosPixel;
887 // kuemmern wir uns erst mal um moeglich DropActions (Scrollen und Aufklappen)
888 if (rEvt.mbLeaving)
890 if (m_aDropActionTimer.IsActive())
891 m_aDropActionTimer.Stop();
892 } else
894 sal_Bool bNeedTrigger = sal_False;
895 // auf dem ersten Eintrag ?
896 if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
898 m_aDropActionType = DA_SCROLLUP;
899 bNeedTrigger = sal_True;
900 } else
901 // auf dem letzten (bzw. in dem Bereich, den ein Eintrag einnehmen wuerde, wenn er unten genau buendig
902 // abschliessen wuerde) ?
903 if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
905 m_aDropActionType = DA_SCROLLDOWN;
906 bNeedTrigger = sal_True;
907 } else
908 { // auf einem Entry mit Children, der nicht aufgeklappt ist ?
909 SvTreeListEntry* pDropppedOn = GetEntry(aDropPos);
910 if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
912 // -> aufklappen
913 m_aDropActionType = DA_EXPANDNODE;
914 bNeedTrigger = sal_True;
918 if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
920 // neu anfangen zu zaehlen
921 m_aTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
922 // die Pos merken, da ich auch AcceptDrops bekomme, wenn sich die Maus gar nicht bewegt hat
923 m_aTimerTriggered = aDropPos;
924 // und den Timer los
925 if (!m_aDropActionTimer.IsActive()) // gibt es den Timer schon ?
927 m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
928 m_aDropActionTimer.Start();
930 } else if (!bNeedTrigger)
931 m_aDropActionTimer.Stop();
934 return implAcceptDataTransfer( GetDataFlavorExVector(), rEvt.mnAction, aDropPos, sal_True );
937 //------------------------------------------------------------------------
938 sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const ::Point& _rDropPos, sal_Bool _bDnD )
940 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implExecuteDataTransfer" );
941 return implExecuteDataTransfer( _rData, _nAction, GetEntry( _rDropPos ), _bDnD );
944 //------------------------------------------------------------------------
945 sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, sal_Bool _bDnD )
947 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::implExecuteDataTransfer" );
948 const DataFlavorExVector& rDataFlavors = _rData.GetDataFlavorExVector();
950 if ( DND_ACTION_NONE == implAcceptDataTransfer( rDataFlavors, _nAction, _pTargetEntry, _bDnD ) )
951 // under some platforms, it may happen that ExecuteDrop is called though AcceptDrop returned DND_ACTION_NONE
952 return DND_ACTION_NONE;
954 // ware schlecht, wenn nach dem Droppen noch gescrollt wird ...
955 if (m_aDropActionTimer.IsActive())
956 m_aDropActionTimer.Stop();
958 if (!_pTargetEntry)
959 // no target -> no drop
960 return DND_ACTION_NONE;
962 // format checks
963 #ifdef DBG_UTIL
964 sal_Bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( rDataFlavors );
965 sal_Bool bForeignCollection = _rData.getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
966 DBG_ASSERT(!bForeignCollection || bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: invalid format (AcceptDrop shouldn't have let this pass) !");
967 DBG_ASSERT(bForeignCollection || !m_bDragDataDirty, "NavigatorTree::implExecuteDataTransfer: invalid state (shell changed since last exchange resync) !");
968 // das sollte in AcceptDrop erledigt worden sein : dort wird in _rData die Liste der Controls aufgebaut und m_bDragDataDirty
969 // zurueckgesetzt
970 #endif
972 if ( DND_ACTION_COPY == _nAction )
973 { // bHasHiddenControlsFormat means that only hidden controls are part of the data
974 DBG_ASSERT( bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: copy allowed for hidden controls only!" );
975 DBG_ASSERT( _pTargetEntry && ( _pTargetEntry != m_pRootEntry ) && IsFormEntry( _pTargetEntry ),
976 "NavigatorTree::implExecuteDataTransfer: should not be here!" );
977 // implAcceptDataTransfer should have caught both cases
979 DBG_ASSERT(bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: only copying of hidden controls is supported !");
980 // das sollte das AcceptDrop abgefangen haben
982 // da ich gleich die Zielobjekte alle selektieren will (und nur die)
983 SelectAll(sal_False);
985 Sequence< Reference< XInterface > > aControls = _rData.hiddenControls();
986 sal_Int32 nCount = aControls.getLength();
987 const Reference< XInterface >* pControls = aControls.getConstArray();
989 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
990 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
992 // innerhalb eines Undo ...
993 if (pFormModel)
995 OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
996 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
997 pFormModel->BegUndo(aUndoStr);
1000 // die Conrtols kopieren
1001 for (sal_Int32 i=0; i<nCount; ++i)
1003 // neues Control anlegen
1004 OUString fControlName = FM_COMPONENT_HIDDEN;
1005 FmControlData* pNewControlData = NewControl( fControlName, _pTargetEntry, sal_False);
1006 Reference< XPropertySet > xNewPropSet( pNewControlData->GetPropertySet() );
1008 // und die Properties des alten in das neue kopieren
1009 Reference< XPropertySet > xCurrent(pControls[i], UNO_QUERY);
1010 #if (OSL_DEBUG_LEVEL > 1)
1011 // nur mal eben sehen, ob das Ding tatsaechlich ein hidden control ist
1012 sal_Int16 nClassId = ::comphelper::getINT16(xCurrent->getPropertyValue(FM_PROP_CLASSID));
1013 OSL_ENSURE(nClassId == FormComponentType::HIDDENCONTROL, "NavigatorTree::implExecuteDataTransfer: invalid control in drop list !");
1014 // wenn das SVX_FM_HIDDEN_CONTROLS-Format vorhanden ist, dann sollten wirklich nur hidden controls in der Sequenz
1015 // stecken
1016 #endif // (OSL_DEBUG_LEVEL > 1)
1017 Reference< XPropertySetInfo > xPropInfo( xCurrent->getPropertySetInfo());
1018 Sequence< Property> seqAllCurrentProps = xPropInfo->getProperties();
1019 Property* pAllCurrentProps = seqAllCurrentProps.getArray();
1020 for (sal_Int32 j=0; j<seqAllCurrentProps.getLength(); ++j)
1022 OUString sCurrentProp = pAllCurrentProps[j].Name;
1023 if (((pAllCurrentProps[j].Attributes & PropertyAttribute::READONLY) == 0) && (sCurrentProp != FM_PROP_NAME))
1024 { // (read-only attribs werden natuerlich nicht gesetzt, dito der Name, den hat das NewControl schon eindeutig
1025 // festgelegt)
1026 xNewPropSet->setPropertyValue(sCurrentProp, xCurrent->getPropertyValue(sCurrentProp));
1030 SvTreeListEntry* pToSelect = FindEntry(pNewControlData);
1031 Select(pToSelect, sal_True);
1032 if (i == 0)
1033 SetCurEntry(pToSelect);
1036 if (pFormModel)
1037 pFormModel->EndUndo();
1039 return _nAction;
1042 if ( !OControlExchange::hasFieldExchangeFormat( _rData.GetDataFlavorExVector() ) )
1044 // can't do anything without the internal format here ... usually happens when doing DnD or CnP
1045 // over navigator boundaries
1046 return DND_ACTION_NONE;
1049 // some data for the target
1050 sal_Bool bDropTargetIsForm = IsFormEntry(_pTargetEntry);
1051 FmFormData* pTargetData = bDropTargetIsForm ? (FmFormData*)_pTargetEntry->GetUserData() : NULL;
1053 DBG_ASSERT( DND_ACTION_COPY != _nAction, "NavigatorTree::implExecuteDataTransfer: somebody changed the logics!" );
1055 // die Liste der gedraggten Eintraege
1056 ListBoxEntrySet aDropped = _rData.selected();
1057 DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implExecuteDataTransfer: no entries!");
1059 // die Shell und das Model
1060 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1061 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
1062 if (!pFormModel)
1063 return DND_ACTION_NONE;
1065 // fuer's Undo
1066 const bool bUndo = pFormModel->IsUndoEnabled();
1068 if( bUndo )
1070 OUString strUndoDescription(SVX_RESSTR(RID_STR_UNDO_CONTAINER_REPLACE));
1071 pFormModel->BegUndo(strUndoDescription);
1074 // ich nehme vor dem Einfuegen eines Eintrages seine Selection raus, damit die Markierung dabei nicht flackert
1075 // -> das Handeln des Select locken
1076 LockSelectionHandling();
1078 // jetzt durch alle gedroppten Eintraege ...
1079 for ( ListBoxEntrySet::const_iterator dropped = aDropped.begin();
1080 dropped != aDropped.end();
1081 ++dropped
1084 // ein paar Daten zum aktuellen Element
1085 SvTreeListEntry* pCurrent = *dropped;
1086 DBG_ASSERT(pCurrent != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
1087 DBG_ASSERT(GetParent(pCurrent) != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
1088 // die Root darf nicht gedraggt werden
1090 FmEntryData* pCurrentUserData = (FmEntryData*)pCurrent->GetUserData();
1092 Reference< XChild > xCurrentChild(pCurrentUserData->GetChildIFace(), UNO_QUERY);
1093 Reference< XIndexContainer > xContainer(xCurrentChild->getParent(), UNO_QUERY);
1095 FmFormData* pCurrentParentUserData = (FmFormData*)pCurrentUserData->GetParent();
1096 DBG_ASSERT(pCurrentParentUserData == NULL || pCurrentParentUserData->ISA(FmFormData), "NavigatorTree::implExecuteDataTransfer: ungueltiges Parent");
1098 // beim Vater austragen
1099 if (pCurrentParentUserData)
1100 pCurrentParentUserData->GetChildList()->remove( pCurrentUserData );
1101 else
1102 GetNavModel()->GetRootList()->remove( pCurrentUserData );
1104 // aus dem Container entfernen
1105 sal_Int32 nIndex = getElementPos(Reference< XIndexAccess > (xContainer, UNO_QUERY), xCurrentChild);
1106 GetNavModel()->m_pPropChangeList->Lock();
1107 // die Undo-Action fuer das Rausnehmen
1108 if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1110 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Removed,
1111 xContainer, xCurrentChild, nIndex));
1113 else if( !GetNavModel()->m_pPropChangeList->CanUndo() )
1115 FmUndoContainerAction::DisposeElement( xCurrentChild );
1118 // Events mitkopieren
1119 Reference< XEventAttacherManager > xManager(xContainer, UNO_QUERY);
1120 Sequence< ScriptEventDescriptor > aEvts;
1122 if (xManager.is() && nIndex >= 0)
1123 aEvts = xManager->getScriptEvents(nIndex);
1124 xContainer->removeByIndex(nIndex);
1126 // die Selection raus
1127 Select(pCurrent, sal_False);
1128 // und weg
1129 Remove(pCurrentUserData);
1131 // die Stelle innerhalb des DropParents, an der ich die gedroppten Eintraege einfuegen muss
1132 if (pTargetData)
1133 xContainer = Reference< XIndexContainer > (pTargetData->GetElement(), UNO_QUERY);
1134 else
1135 xContainer = Reference< XIndexContainer > (GetNavModel()->GetForms(), UNO_QUERY);
1137 // immer ganz hinten einfuegen
1138 nIndex = xContainer->getCount();
1140 // UndoAction fuer das Einfuegen
1141 if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1142 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Inserted,
1143 xContainer, xCurrentChild, nIndex));
1145 // einfuegen im neuen Container
1146 if (pTargetData)
1148 // es wird in eine Form eingefuegt, dann brauche ich eine FormComponent
1149 xContainer->insertByIndex( nIndex,
1150 makeAny( Reference< XFormComponent >( xCurrentChild, UNO_QUERY ) ) );
1152 else
1154 xContainer->insertByIndex( nIndex,
1155 makeAny( Reference< XForm >( xCurrentChild, UNO_QUERY ) ) );
1158 if (aEvts.getLength())
1160 xManager = Reference< XEventAttacherManager > (xContainer, UNO_QUERY);
1161 if (xManager.is())
1162 xManager->registerScriptEvents(nIndex, aEvts);
1165 GetNavModel()->m_pPropChangeList->UnLock();
1167 // zuerst dem Eintrag das neue Parent
1168 pCurrentUserData->SetParent(pTargetData);
1170 // dann dem Parent das neue Child
1171 if (pTargetData)
1172 pTargetData->GetChildList()->insert( pCurrentUserData, nIndex );
1173 else
1174 GetNavModel()->GetRootList()->insert( pCurrentUserData, nIndex );
1176 // dann bei mir selber bekanntgeben und neu selektieren
1177 SvTreeListEntry* pNew = Insert( pCurrentUserData, nIndex );
1178 if ( ( aDropped.begin() == dropped ) && pNew )
1180 SvTreeListEntry* pParent = GetParent( pNew );
1181 if ( pParent )
1182 Expand( pParent );
1186 UnlockSelectionHandling();
1188 if( bUndo )
1189 pFormModel->EndUndo();
1191 // During the move, the markings of the underlying view did not change (because the view is not affected by the logical
1192 // hierarchy of the form/control models. But my selection changed - which means I have to adjust it according to the
1193 // view marks, again.
1194 SynchronizeSelection();
1196 // in addition, with the move of controls such things as "the current form" may have changed - force the shell
1197 // to update itself accordingly
1198 if( pFormShell && pFormShell->GetImpl() && pFormShell->GetFormView() )
1199 pFormShell->GetImpl()->DetermineSelection( pFormShell->GetFormView()->GetMarkedObjectList() );
1201 if ( m_aControlExchange.isClipboardOwner() && ( DND_ACTION_MOVE == _nAction ) )
1202 m_aControlExchange->clear();
1204 return _nAction;
1207 //------------------------------------------------------------------------
1208 sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
1210 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::ExecuteDrop" );
1211 sal_Int8 nResult( DND_ACTION_NONE );
1213 if ( m_aControlExchange.isDragSource() )
1214 nResult = implExecuteDataTransfer( *m_aControlExchange, rEvt.mnAction, rEvt.maPosPixel, sal_True );
1215 else
1217 OControlTransferData aDroppedData( rEvt.maDropEvent.Transferable );
1218 nResult = implExecuteDataTransfer( aDroppedData, rEvt.mnAction, rEvt.maPosPixel, sal_True );
1221 return nResult;
1224 //------------------------------------------------------------------------
1225 void NavigatorTree::doPaste()
1227 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::doPaste" );
1230 if ( m_aControlExchange.isClipboardOwner() )
1232 implExecuteDataTransfer( *m_aControlExchange, doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY, FirstSelected(), sal_False );
1234 else
1236 // the clipboard content
1237 Reference< XClipboard > xClipboard( GetClipboard() );
1238 Reference< XTransferable > xTransferable;
1239 if ( xClipboard.is() )
1240 xTransferable = xClipboard->getContents();
1242 OControlTransferData aClipboardContent( xTransferable );
1243 implExecuteDataTransfer( aClipboardContent, DND_ACTION_COPY, FirstSelected(), sal_False );
1246 catch( const Exception& )
1248 OSL_FAIL( "NavigatorTree::doPaste: caught an exception!" );
1252 //------------------------------------------------------------------------
1253 void NavigatorTree::doCopy()
1255 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::doCopy" );
1256 if ( implPrepareExchange( DND_ACTION_COPY ) )
1258 m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1259 m_aControlExchange.copyToClipboard( );
1263 //------------------------------------------------------------------------
1264 void NavigatorTree::ModelHasRemoved( SvTreeListEntry* _pEntry )
1266 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::ModelHasRemoved" );
1267 SvTreeListEntry* pTypedEntry = static_cast< SvTreeListEntry* >( _pEntry );
1268 if ( doingKeyboardCut() )
1269 m_aCutEntries.erase( pTypedEntry );
1271 if ( m_aControlExchange.isDataExchangeActive() )
1273 if ( 0 == m_aControlExchange->onEntryRemoved( pTypedEntry ) )
1275 // last of the entries which we put into the clipboard has been deleted from the tree.
1276 // Give up the clipboard ownership.
1277 m_aControlExchange.clear();
1282 //------------------------------------------------------------------------
1283 void NavigatorTree::doCut()
1285 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::doCut" );
1286 if ( implPrepareExchange( DND_ACTION_MOVE ) )
1288 m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1289 m_aControlExchange.copyToClipboard( );
1290 m_bKeyboardCut = sal_True;
1292 // mark all the entries we just "cut" into the clipboard as "nearly moved"
1293 for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1294 it != m_arrCurrentSelection.end(); ++it )
1296 SvTreeListEntry* pEntry = *it;
1297 if ( pEntry )
1299 m_aCutEntries.insert( pEntry );
1300 pEntry->SetFlags( pEntry->GetFlags() | SV_ENTRYFLAG_SEMITRANSPARENT );
1301 InvalidateEntry( pEntry );
1307 //------------------------------------------------------------------------
1308 void NavigatorTree::KeyInput(const ::KeyEvent& rKEvt)
1310 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::KeyInput" );
1311 const KeyCode& rCode = rKEvt.GetKeyCode();
1313 // delete?
1314 if (rKEvt.GetKeyCode().GetCode() == KEY_DELETE && !rKEvt.GetKeyCode().GetModifier())
1316 DeleteSelection();
1317 return;
1320 // copy'n'paste?
1321 switch ( rCode.GetFunction() )
1323 case KEYFUNC_CUT:
1324 doCut();
1325 break;
1327 case KEYFUNC_PASTE:
1328 if ( implAcceptPaste() )
1329 doPaste();
1330 break;
1332 case KEYFUNC_COPY:
1333 doCopy();
1334 break;
1336 default:
1337 break;
1340 SvTreeListBox::KeyInput(rKEvt);
1343 //------------------------------------------------------------------------
1344 sal_Bool NavigatorTree::EditingEntry( SvTreeListEntry* pEntry, Selection& rSelection )
1346 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::EditingEntry" );
1347 if (!SvTreeListBox::EditingEntry( pEntry, rSelection ))
1348 return sal_False;
1350 return (pEntry && (pEntry->GetUserData() != NULL));
1351 // die Wurzel, die ich nicht umbenennen darf, hat als UserData NULL
1354 //------------------------------------------------------------------------
1355 void NavigatorTree::NewForm( SvTreeListEntry* pParentEntry )
1357 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::NewForm" );
1358 //////////////////////////////////////////////////////////////////////
1359 // ParentFormData holen
1360 if( !IsFormEntry(pParentEntry) )
1361 return;
1363 FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();
1365 //////////////////////////////////////////////////////////////////////
1366 // Neue Form erzeugen
1367 Reference< XForm > xNewForm(m_xORB->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
1368 if (!xNewForm.is())
1369 return;
1371 FmFormData* pNewFormData = new FmFormData( xNewForm, m_aNavigatorImages, pParentFormData );
1373 //////////////////////////////////////////////////////////////////////
1374 // Namen setzen
1375 OUString aName = GenerateName(pNewFormData);
1376 pNewFormData->SetText(aName);
1378 Reference< XPropertySet > xPropertySet(xNewForm, UNO_QUERY);
1379 if (!xPropertySet.is())
1380 return;
1383 xPropertySet->setPropertyValue( FM_PROP_NAME, makeAny(aName) );
1384 // a form should always have the command type table as default
1385 xPropertySet->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE)));
1387 catch ( const Exception& )
1389 OSL_FAIL("NavigatorTree::NewForm : could not set esssential properties !");
1393 //////////////////////////////////////////////////////////////////////
1394 // Form einfuegen
1395 GetNavModel()->Insert( pNewFormData, LIST_APPEND, sal_True );
1397 //////////////////////////////////////////////////////////////////////
1398 // Neue Form als aktive Form setzen
1399 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1400 if( pFormShell )
1402 InterfaceBag aSelection;
1403 aSelection.insert( Reference< XInterface >( xNewForm, UNO_QUERY ) );
1404 pFormShell->GetImpl()->setCurrentSelection( aSelection );
1406 pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_PROPERTIES,sal_True,sal_True);
1408 GetNavModel()->SetModified();
1410 //////////////////////////////////////////////////////////////////////
1411 // In EditMode schalten
1412 SvTreeListEntry* pNewEntry = FindEntry( pNewFormData );
1413 EditEntry( pNewEntry );
1416 //------------------------------------------------------------------------
1417 FmControlData* NavigatorTree::NewControl( const OUString& rServiceName, SvTreeListEntry* pParentEntry, sal_Bool bEditName )
1419 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::NewControl" );
1420 //////////////////////////////////////////////////////////////////////
1421 // ParentForm holen
1422 if (!GetNavModel()->GetFormShell())
1423 return NULL;
1424 if (!IsFormEntry(pParentEntry))
1425 return NULL;
1427 FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();;
1428 Reference< XForm > xParentForm( pParentFormData->GetFormIface());
1430 //////////////////////////////////////////////////////////////////////
1431 // Neue Component erzeugen
1432 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
1433 Reference<XFormComponent> xNewComponent( xContext->getServiceManager()->createInstanceWithContext(rServiceName, xContext), UNO_QUERY);
1434 if (!xNewComponent.is())
1435 return NULL;
1437 FmControlData* pNewFormControlData = new FmControlData( xNewComponent, m_aNavigatorImages, pParentFormData );
1439 //////////////////////////////////////////////////////////////////////
1440 // Namen setzen
1441 FmFormView* pFormView = GetNavModel()->GetFormShell()->GetFormView();
1442 SdrPageView* pPageView = pFormView->GetSdrPageView();
1443 FmFormPage* pPage = (FmFormPage*)pPageView->GetPage();
1445 OUString sName = pPage->GetImpl().setUniqueName( xNewComponent, xParentForm );
1447 pNewFormControlData->SetText( sName );
1449 //////////////////////////////////////////////////////////////////////
1450 // FormComponent einfuegen
1451 GetNavModel()->Insert( pNewFormControlData, LIST_APPEND, sal_True );
1452 GetNavModel()->SetModified();
1454 if (bEditName)
1456 //////////////////////////////////////////////////////////////////////
1457 // In EditMode schalten
1458 SvTreeListEntry* pNewEntry = FindEntry( pNewFormControlData );
1459 Select( pNewEntry, sal_True );
1460 EditEntry( pNewEntry );
1463 return pNewFormControlData;
1466 //------------------------------------------------------------------------
1467 OUString NavigatorTree::GenerateName( FmEntryData* pEntryData )
1469 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::GenerateName" );
1470 const sal_uInt16 nMaxCount = 99;
1471 OUString aNewName;
1473 //////////////////////////////////////////////////////////////////////
1474 // BasisNamen erzeugen
1475 OUString aBaseName;
1476 if( pEntryData->ISA(FmFormData) )
1477 aBaseName = SVX_RESSTR( RID_STR_STDFORMNAME );
1478 else if( pEntryData->ISA(FmControlData) )
1479 aBaseName = SVX_RESSTR( RID_STR_CONTROL );
1481 //////////////////////////////////////////////////////////////////////
1482 // Neuen Namen erstellen
1483 FmFormData* pFormParentData = (FmFormData*)pEntryData->GetParent();
1485 for( sal_Int32 i=0; i<nMaxCount; i++ )
1487 aNewName = aBaseName;
1488 if( i>0 )
1490 aNewName += OUString(" ");
1491 aNewName += OUString::valueOf(i).getStr();
1494 if( GetNavModel()->FindData(aNewName, pFormParentData,sal_False) == NULL )
1495 break;
1498 return aNewName;
1501 //------------------------------------------------------------------------
1502 sal_Bool NavigatorTree::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText )
1504 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::EditedEntry" );
1505 if (EditingCanceled())
1506 return sal_True;
1508 GrabFocus();
1509 FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
1510 sal_Bool bRes = GetNavModel()->Rename( pEntryData, rNewText);
1511 if( !bRes )
1513 m_pEditEntry = pEntry;
1514 nEditEvent = Application::PostUserEvent( LINK(this, NavigatorTree, OnEdit) );
1515 } else
1516 SetCursor(pEntry, sal_True);
1518 return bRes;
1521 //------------------------------------------------------------------------
1522 IMPL_LINK_NOARG(NavigatorTree, OnEdit)
1524 nEditEvent = 0;
1525 EditEntry( m_pEditEntry );
1526 m_pEditEntry = NULL;
1528 return 0L;
1531 //------------------------------------------------------------------------
1532 IMPL_LINK_NOARG(NavigatorTree, OnDropActionTimer)
1534 if (--m_aTimerCounter > 0)
1535 return 0L;
1537 switch ( m_aDropActionType )
1539 case DA_EXPANDNODE:
1541 SvTreeListEntry* pToExpand = GetEntry(m_aTimerTriggered);
1542 if (pToExpand && (GetChildCount(pToExpand) > 0) && !IsExpanded(pToExpand))
1543 // tja, eigentlich muesste ich noch testen, ob die Node nicht schon expandiert ist, aber ich
1544 // habe dazu weder in den Basisklassen noch im Model eine Methode gefunden ...
1545 // aber ich denke, die BK sollte es auch so vertragen
1546 Expand(pToExpand);
1548 // nach dem Expand habe ich im Gegensatz zum Scrollen natuerlich nix mehr zu tun
1549 m_aDropActionTimer.Stop();
1551 break;
1553 case DA_SCROLLUP :
1554 ScrollOutputArea( 1 );
1555 m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1556 break;
1558 case DA_SCROLLDOWN :
1559 ScrollOutputArea( -1 );
1560 m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1561 break;
1565 return 0L;
1568 //------------------------------------------------------------------------
1569 IMPL_LINK(NavigatorTree, OnEntrySelDesel, NavigatorTree*, /*pThis*/)
1571 m_sdiState = SDI_DIRTY;
1573 if (IsSelectionHandlingLocked())
1574 return 0L;
1576 if (m_aSynchronizeTimer.IsActive())
1577 m_aSynchronizeTimer.Stop();
1579 m_aSynchronizeTimer.SetTimeout(EXPLORER_SYNC_DELAY);
1580 m_aSynchronizeTimer.Start();
1582 return 0L;
1585 //------------------------------------------------------------------------
1586 IMPL_LINK_NOARG(NavigatorTree, OnSynchronizeTimer)
1588 SynchronizeMarkList();
1589 return 0L;
1593 //------------------------------------------------------------------------
1594 IMPL_LINK_NOARG(NavigatorTree, OnClipboardAction)
1596 if ( !m_aControlExchange.isClipboardOwner() )
1598 if ( doingKeyboardCut() )
1600 for ( ListBoxEntrySet::const_iterator i = m_aCutEntries.begin();
1601 i != m_aCutEntries.end();
1605 SvTreeListEntry* pEntry = *i;
1606 if ( !pEntry )
1607 continue;
1609 pEntry->SetFlags( pEntry->GetFlags() & ~SV_ENTRYFLAG_SEMITRANSPARENT );
1610 InvalidateEntry( pEntry );
1612 ListBoxEntrySet aEmpty;
1613 m_aCutEntries.swap( aEmpty );
1615 m_bKeyboardCut = sal_False;
1618 return 0L;
1621 //------------------------------------------------------------------------
1622 void NavigatorTree::ShowSelectionProperties(sal_Bool bForce)
1624 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::ShowSelectionProperties" );
1625 // zuerst brauche ich die FormShell
1626 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1627 if (!pFormShell)
1628 // keine Shell -> ich koennte kein curObject setzen -> raus
1629 return;
1631 CollectSelectionData(SDI_ALL);
1632 SAL_WARN_IF(static_cast<size_t>(m_nFormsSelected + m_nControlsSelected
1633 + (m_bRootSelected ? 1 : 0)) != m_arrCurrentSelection.size(),
1634 "svx.form",
1635 "NavigatorTree::ShowSelectionProperties : selection meta data invalid !");
1638 InterfaceBag aSelection;
1639 sal_Bool bSetSelectionAsMarkList = sal_False;
1641 if (m_bRootSelected)
1642 ; // no properties for the root, neither for single nor for multi selection
1643 else if ( m_nFormsSelected + m_nControlsSelected == 0 ) // none of the two should be less 0
1644 ; // no selection -> no properties
1645 else if ( m_nFormsSelected * m_nControlsSelected != 0 )
1646 ; // mixed selection -> no properties
1647 else
1648 { // either only forms, or only controls are selected
1649 if (m_arrCurrentSelection.size() == 1)
1651 if (m_nFormsSelected > 0)
1652 { // es ist genau eine Form selektiert
1653 FmFormData* pFormData = (FmFormData*)(*m_arrCurrentSelection.begin())->GetUserData();
1654 aSelection.insert( Reference< XInterface >( pFormData->GetFormIface(), UNO_QUERY ) );
1656 else
1657 { // es ist genau ein Control selektiert (egal ob hidden oder normal)
1658 FmEntryData* pEntryData = (FmEntryData*)(*m_arrCurrentSelection.begin())->GetUserData();
1660 aSelection.insert( Reference< XInterface >( pEntryData->GetElement(), UNO_QUERY ) );
1663 else
1664 { // wir haben eine MultiSelection, also muessen wir ein MultiSet dafuer aufbauen
1665 if (m_nFormsSelected > 0)
1666 { // ... nur Forms
1667 // erstmal die PropertySet-Interfaces der Forms einsammeln
1668 SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1669 for ( sal_Int32 i = 0; i < m_nFormsSelected; ++i )
1671 FmFormData* pFormData = (FmFormData*)(*it)->GetUserData();
1672 aSelection.insert( pFormData->GetPropertySet().get() );
1673 ++it;
1676 else
1677 { // ... nur Controls
1678 if (m_nHiddenControls == m_nControlsSelected)
1679 { // ein MultiSet fuer die Properties der hidden controls
1680 SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1681 for ( sal_Int32 i = 0; i < m_nHiddenControls; ++i )
1683 FmEntryData* pEntryData = (FmEntryData*)(*it)->GetUserData();
1684 aSelection.insert( pEntryData->GetPropertySet().get() );
1685 ++it;
1688 else if (m_nHiddenControls == 0)
1689 { // nur normale Controls
1690 bSetSelectionAsMarkList = sal_True;
1697 // und dann meine Form und mein SelObject
1698 if ( bSetSelectionAsMarkList )
1699 pFormShell->GetImpl()->setCurrentSelectionFromMark( pFormShell->GetFormView()->GetMarkedObjectList() );
1700 else
1701 pFormShell->GetImpl()->setCurrentSelection( aSelection );
1703 if ( pFormShell->GetImpl()->IsPropBrwOpen() || bForce )
1705 // und jetzt kann ich das Ganze dem PropertyBrowser uebergeben
1706 pFormShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON );
1710 //------------------------------------------------------------------------
1711 void NavigatorTree::DeleteSelection()
1713 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::DeleteSelection" );
1714 // die Root darf ich natuerlich nicht mitloeschen
1715 sal_Bool bRootSelected = IsSelected(m_pRootEntry);
1716 sal_uIntPtr nSelectedEntries = GetSelectionCount();
1717 if (bRootSelected && (nSelectedEntries > 1)) // die Root plus andere Elemente ?
1718 Select(m_pRootEntry, sal_False); // ja -> die Root raus
1720 if ((nSelectedEntries == 0) || bRootSelected) // immer noch die Root ?
1721 return; // -> sie ist das einzige selektierte -> raus
1723 DBG_ASSERT(!m_bPrevSelectionMixed, "NavigatorTree::DeleteSelection() : loeschen nicht erlaubt wenn Markierung und Selektion nciht konsistent");
1725 // ich brauche unten das FormModel ...
1726 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1727 if (!pFormShell)
1728 return;
1729 FmFormModel* pFormModel = pFormShell->GetFormModel();
1730 if (!pFormModel)
1731 return;
1733 // jetzt muss ich noch die DeleteList etwas absichern : wenn man ein Formular und ein abhaengiges
1734 // Element loescht - und zwar in dieser Reihenfolge - dann ist der SvLBoxEntryPtr des abhaengigen Elementes
1735 // natuerlich schon ungueltig, wenn es geloescht werden soll ... diesen GPF, den es dann mit Sicherheit gibt,
1736 // gilt es zu verhindern, also die 'normalisierte' Liste
1737 CollectSelectionData( SDI_NORMALIZED );
1739 // see below for why we need this mapping from models to shapes
1740 FmFormView* pFormView = pFormShell->GetFormView();
1741 SdrPageView* pPageView = pFormView ? pFormView->GetSdrPageView() : NULL;
1742 SdrPage* pPage = pPageView ? pPageView->GetPage() : NULL;
1743 DBG_ASSERT( pPage, "NavigatorTree::DeleteSelection: invalid form page!" );
1745 MapModelToShape aModelShapes;
1746 if ( pPage )
1747 collectShapeModelMapping( pPage, aModelShapes );
1749 // problem: we have to use ExplorerModel::Remove, since only this one properly deletes Form objects.
1750 // But, the controls themself must be deleted via DeleteMarked (else, the Writer has some problems
1751 // somewhere). In case I'd first delete the structure, then the controls, the UNDO would not work
1752 // (since UNDO then would mean to first restore the controls, then the structure, means their parent
1753 // form). The other way round, the EntryDatas would be invalid, if I'd first delete the controls and
1754 // then go on to the strucure. This means I have to delete the forms *after* the normal controls, so
1755 // that during UNDO, they're restored in the proper order.
1756 pFormShell->GetImpl()->EnableTrackProperties(sal_False);
1757 for (SvLBoxEntrySortedArray::reverse_iterator it = m_arrCurrentSelection.rbegin();
1758 it != m_arrCurrentSelection.rend(); )
1760 FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
1762 // eine Form ?
1763 sal_Bool bIsForm = pCurrent->ISA(FmFormData);
1765 // da ich das Loeschen im folgenden der View ueberlasse und dabei auf deren MarkList aufbaue, im Normalfall aber bei
1766 // einem makierten Formular nur die direkt, nicht die indirekt abhaengigen Controls markiert werden, muss ich das hier
1767 // noch nachholen
1768 if (bIsForm)
1769 MarkViewObj((FmFormData*)pCurrent, sal_True, sal_True); // das zweite sal_True heisst "deep"
1771 // ein hidden control ?
1772 sal_Bool bIsHidden = IsHiddenControl(pCurrent);
1774 // Forms und hidden Controls muss ich behalten, alles andere nicht
1775 if (!bIsForm && !bIsHidden)
1777 // well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
1778 // be deleted automatically. This is because for every model (except forms and hidden control models)
1779 // there exist a shape, which is marked _if_and_only_if_ the model is selected in our tree.
1780 if ( aModelShapes.find( pCurrent->GetElement() ) != aModelShapes.end() )
1782 // if there's a shape for the current entry, then either it is marked or it is in a
1783 // hidden layer (#i28502#), or something like this.
1784 // In the first case, it will be deleted below, in the second case, we currently don't
1785 // delete it, as there's no real (working!) API for this, neither in UNO nor in non-UNO.
1786 m_arrCurrentSelection.erase( --(it.base()) );
1788 else
1789 ++it;
1790 // In case there is no shape for the current entry, we keep the entry in m_arrCurrentSelection,
1791 // since then we can definitely remove it.
1792 // #103597#
1794 else
1795 ++it;
1797 pFormShell->GetImpl()->EnableTrackProperties(sal_True);
1799 // let the view delete the marked controls
1800 pFormShell->GetFormView()->DeleteMarked();
1802 // start UNDO at this point. Unfortunately, this results in 2 UNDO actions, since DeleteMarked is
1803 // creating an own one. However, if we'd move it before DeleteMarked, Writer does not really like
1804 // this ... :(
1805 // #i31038#
1807 // ---------------
1808 // initialize UNDO
1809 String aUndoStr;
1810 if ( m_arrCurrentSelection.size() == 1 )
1812 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE);
1813 if (m_nFormsSelected)
1814 aUndoStr.SearchAndReplaceAscii( "#", SVX_RESSTR( RID_STR_FORM ) );
1815 else
1816 // it must be a control (else the root would be selected, but it cannot be deleted)
1817 aUndoStr.SearchAndReplaceAscii( "#", SVX_RESSTR( RID_STR_CONTROL ) );
1819 else
1821 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE_MULTIPLE);
1822 aUndoStr.SearchAndReplaceAscii( "#", OUString::number( m_arrCurrentSelection.size() ) );
1824 pFormModel->BegUndo(aUndoStr);
1827 // remove remaining structure
1828 for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1829 it != m_arrCurrentSelection.end(); ++it)
1831 FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
1833 // if the entry still has children, we skipped deletion of one of those children.
1834 // This may for instance be because the shape is in a hidden layer, where we're unable
1835 // to remove it
1836 if ( pCurrent->GetChildList()->size() )
1837 continue;
1839 // noch ein kleines Problem, bevor ich das ganz loesche : wenn es eine Form ist und die Shell diese als CurrentObject
1840 // kennt, dann muss ich ihr das natuerlich ausreden
1841 if (pCurrent->ISA(FmFormData))
1843 Reference< XForm > xCurrentForm( static_cast< FmFormData* >( pCurrent )->GetFormIface() );
1844 if ( pFormShell->GetImpl()->getCurrentForm() == xCurrentForm ) // die Shell kennt die zu loeschende Form ?
1845 pFormShell->GetImpl()->forgetCurrentForm(); // -> wegnehmen ...
1847 GetNavModel()->Remove(pCurrent, sal_True);
1849 pFormModel->EndUndo();
1852 //------------------------------------------------------------------------
1853 void NavigatorTree::CollectSelectionData(SELDATA_ITEMS sdiHow)
1855 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::CollectSelectionData" );
1856 DBG_ASSERT(sdiHow != SDI_DIRTY, "NavigatorTree::CollectSelectionData : ever thought about your parameter ? DIRTY ?");
1857 if (sdiHow == m_sdiState)
1858 return;
1860 m_arrCurrentSelection.clear();
1861 m_nFormsSelected = m_nControlsSelected = m_nHiddenControls = 0;
1862 m_bRootSelected = sal_False;
1864 SvTreeListEntry* pSelectionLoop = FirstSelected();
1865 while (pSelectionLoop)
1867 // erst mal die Zaehlung der verschiedenen Elemente
1868 if (pSelectionLoop == m_pRootEntry)
1869 m_bRootSelected = sal_True;
1870 else
1872 if (IsFormEntry(pSelectionLoop))
1873 ++m_nFormsSelected;
1874 else
1876 ++m_nControlsSelected;
1877 if (IsHiddenControl((FmEntryData*)(pSelectionLoop->GetUserData())))
1878 ++m_nHiddenControls;
1882 if (sdiHow == SDI_NORMALIZED)
1884 // alles, was schon einen selektierten Vorfahr hat, nicht mitnehmen
1885 if (pSelectionLoop == m_pRootEntry)
1886 m_arrCurrentSelection.insert(pSelectionLoop);
1887 else
1889 SvTreeListEntry* pParentLoop = GetParent(pSelectionLoop);
1890 while (pParentLoop)
1892 // eigentlich muesste ich testen, ob das Parent in der m_arrCurrentSelection steht ...
1893 // Aber wenn es selektiert ist, dann steht es in m_arrCurrentSelection, oder wenigstens einer seiner Vorfahren,
1894 // wenn der auch schon selektiert war. In beiden Faellen reicht also die Abfrage IsSelected
1895 if (IsSelected(pParentLoop))
1896 break;
1897 else
1899 if (m_pRootEntry == pParentLoop)
1901 // bis (exclusive) zur Root gab es kein selektiertes Parent -> der Eintrag gehoert in die normalisierte Liste
1902 m_arrCurrentSelection.insert(pSelectionLoop);
1903 break;
1905 else
1906 pParentLoop = GetParent(pParentLoop);
1911 else if (sdiHow == SDI_NORMALIZED_FORMARK)
1913 SvTreeListEntry* pParent = GetParent(pSelectionLoop);
1914 if (!pParent || !IsSelected(pParent) || IsFormEntry(pSelectionLoop))
1915 m_arrCurrentSelection.insert(pSelectionLoop);
1917 else
1918 m_arrCurrentSelection.insert(pSelectionLoop);
1921 pSelectionLoop = NextSelected(pSelectionLoop);
1924 m_sdiState = sdiHow;
1927 //------------------------------------------------------------------------
1928 void NavigatorTree::SynchronizeSelection(FmEntryDataArray& arredToSelect)
1930 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::SynchronizeSelection" );
1931 LockSelectionHandling();
1932 if (arredToSelect.empty())
1934 SelectAll(sal_False);
1936 else
1938 // erst mal gleiche ich meine aktuelle Selektion mit der geforderten SelectList ab
1939 SvTreeListEntry* pSelection = FirstSelected();
1940 while (pSelection)
1942 FmEntryData* pCurrent = (FmEntryData*)pSelection->GetUserData();
1943 if (pCurrent != NULL)
1945 FmEntryDataArray::iterator it = arredToSelect.find(pCurrent);
1946 if ( it != arredToSelect.end() )
1947 { // der Entry ist schon selektiert, steht aber auch in der SelectList -> er kann aus letzterer
1948 // raus
1949 arredToSelect.erase(it);
1950 } else
1951 { // der Entry ist selektiert, aber steht nicht in der SelectList -> Selektion rausnehmen
1952 Select(pSelection, sal_False);
1953 // und sichtbar machen (kann ja sein, dass das die einzige Modifikation ist, die ich hier in dem
1954 // ganzen Handler mache, dann sollte das zu sehen sein)
1955 MakeVisible(pSelection);
1958 else
1959 Select(pSelection, sal_False);
1961 pSelection = NextSelected(pSelection);
1964 // jetzt habe ich in der SelectList genau die Eintraege, die noch selektiert werden muessen
1965 // zwei Moeglichkeiten : 1) ich gehe durch die SelectList, besorge mir zu jedem Eintrag meinen SvTreeListEntry
1966 // und selektiere diesen (waere irgendwie intuitiver ;)) 2) ich gehe durch alle meine SvLBoxEntries und selektiere
1967 // genau die, die ich in der SelectList finde
1968 // 1) braucht O(k*n) (k=Laenge der SelectList, n=Anzahl meiner Entries), plus den Fakt, dass FindEntry nicht den
1969 // Pointer auf die UserDaten vergleicht, sondern ein aufwendigeres IsEqualWithoutChildren durchfuehrt
1970 // 2) braucht O(n*log k), dupliziert aber etwas Code (naemlich den aus FindEntry)
1971 // da das hier eine relativ oft aufgerufenen Stelle sein koennte (bei jeder Aenderung in der Markierung in der View !),
1972 // nehme ich doch lieber letzteres
1973 SvTreeListEntry* pLoop = First();
1974 while( pLoop )
1976 FmEntryData* pCurEntryData = (FmEntryData*)pLoop->GetUserData();
1977 FmEntryDataArray::iterator it = arredToSelect.find(pCurEntryData);
1978 if ( it != arredToSelect.end() )
1980 Select(pLoop, sal_True);
1981 MakeVisible(pLoop);
1982 SetCursor(pLoop, sal_True);
1985 pLoop = Next( pLoop );
1988 UnlockSelectionHandling();
1991 //------------------------------------------------------------------------
1992 void NavigatorTree::SynchronizeSelection()
1994 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::SynchronizeSelection" );
1995 // Shell und View
1996 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1997 if(!pFormShell) return;
1999 FmFormView* pFormView = pFormShell->GetFormView();
2000 if (!pFormView) return;
2002 GetNavModel()->BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
2005 //------------------------------------------------------------------------
2006 void NavigatorTree::SynchronizeMarkList()
2008 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::SynchronizeMarkList" );
2009 // die Shell werde ich brauchen ...
2010 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2011 if (!pFormShell) return;
2013 CollectSelectionData(SDI_NORMALIZED_FORMARK);
2015 // Die View soll jetzt kein Notify bei einer Aenderung der MarkList rauslassen
2016 pFormShell->GetImpl()->EnableTrackProperties(sal_False);
2018 UnmarkAllViewObj();
2020 for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
2021 it != m_arrCurrentSelection.end(); ++it)
2023 SvTreeListEntry* pSelectionLoop = *it;
2024 // Bei Formselektion alle Controls dieser Form markieren
2025 if (IsFormEntry(pSelectionLoop) && (pSelectionLoop != m_pRootEntry))
2026 MarkViewObj((FmFormData*)pSelectionLoop->GetUserData(), sal_True, sal_False);
2028 // Bei Controlselektion Control-SdrObjects markieren
2029 else if (IsFormComponentEntry(pSelectionLoop))
2031 FmControlData* pControlData = (FmControlData*)pSelectionLoop->GetUserData();
2032 if (pControlData)
2034 /////////////////////////////////////////////////////////////////
2035 // Beim HiddenControl kann kein Object selektiert werden
2036 Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
2037 if (!xFormComponent.is())
2038 continue;
2039 Reference< XPropertySet > xSet(xFormComponent, UNO_QUERY);
2040 if (!xSet.is())
2041 continue;
2043 sal_uInt16 nClassId = ::comphelper::getINT16(xSet->getPropertyValue(FM_PROP_CLASSID));
2044 if (nClassId != FormComponentType::HIDDENCONTROL)
2045 MarkViewObj(pControlData, sal_True, sal_True);
2050 // wenn der PropertyBrowser offen ist, muss ich den entsprechend meiner Selektion anpassen
2051 // (NICHT entsprechend der MarkList der View : wenn ich ein Formular selektiert habe, sind in der
2052 // View alle zugehoerigen Controls markiert, trotzdem moechte ich natuerlich die Formular-Eigenschaften
2053 // sehen)
2054 ShowSelectionProperties(sal_False);
2056 // Flag an View wieder zuruecksetzen
2057 pFormShell->GetImpl()->EnableTrackProperties(sal_True);
2059 // wenn jetzt genau eine Form selektiert ist, sollte die Shell das als CurrentForm mitbekommen
2060 // (wenn SelectionHandling nicht locked ist, kuemmert sich die View eigentlich in MarkListHasChanged drum,
2061 // aber der Mechanismus greift zum Beispiel nicht, wenn die Form leer ist)
2062 if ((m_arrCurrentSelection.size() == 1) && (m_nFormsSelected == 1))
2064 FmFormData* pSingleSelectionData = PTR_CAST( FmFormData, static_cast< FmEntryData* >( FirstSelected()->GetUserData() ) );
2065 DBG_ASSERT( pSingleSelectionData, "NavigatorTree::SynchronizeMarkList: invalid selected form!" );
2066 if ( pSingleSelectionData )
2068 InterfaceBag aSelection;
2069 aSelection.insert( Reference< XInterface >( pSingleSelectionData->GetFormIface(), UNO_QUERY ) );
2070 pFormShell->GetImpl()->setCurrentSelection( aSelection );
2075 //------------------------------------------------------------------------
2076 sal_Bool NavigatorTree::IsHiddenControl(FmEntryData* pEntryData)
2078 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::IsHiddenControl" );
2079 if (pEntryData == NULL) return sal_False;
2081 Reference< XPropertySet > xProperties( pEntryData->GetPropertySet() );
2082 if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
2084 Any aClassID = xProperties->getPropertyValue( FM_PROP_CLASSID );
2085 return (::comphelper::getINT16(aClassID) == FormComponentType::HIDDENCONTROL);
2087 return sal_False;
2090 //------------------------------------------------------------------------
2091 sal_Bool NavigatorTree::Select( SvTreeListEntry* pEntry, sal_Bool bSelect )
2093 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::Select" );
2094 if (bSelect == IsSelected(pEntry)) // das passiert manchmal, ich glaube, die Basisklasse geht zu sehr auf Nummer sicher ;)
2095 return sal_True;
2097 return SvTreeListBox::Select(pEntry, bSelect );
2100 //------------------------------------------------------------------------
2101 void NavigatorTree::UnmarkAllViewObj()
2103 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::UnmarkAllViewObj" );
2104 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2105 if( !pFormShell )
2106 return;
2107 FmFormView* pFormView = pFormShell->GetFormView();
2108 pFormView->UnMarkAll();
2110 //------------------------------------------------------------------------
2111 void NavigatorTree::MarkViewObj(FmFormData* pFormData, sal_Bool bMark, sal_Bool bDeep )
2113 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::MarkViewObjects" );
2114 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2115 if( !pFormShell )
2116 return;
2118 // first collect all sdrobjects
2119 ::std::set< Reference< XFormComponent > > aObjects;
2120 CollectObjects(pFormData,bDeep,aObjects);
2122 //////////////////////////////////////////////////////////////////////
2123 // In der Page das entsprechende SdrObj finden und selektieren
2124 FmFormView* pFormView = pFormShell->GetFormView();
2125 SdrPageView* pPageView = pFormView->GetSdrPageView();
2126 SdrPage* pPage = pPageView->GetPage();
2127 //FmFormPage* pFormPage = dynamic_cast< FmFormPage* >( pPage );
2129 SdrObjListIter aIter( *pPage );
2130 while ( aIter.IsMore() )
2132 SdrObject* pSdrObject = aIter.Next();
2133 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
2134 if ( !pFormObject )
2135 continue;
2137 Reference< XFormComponent > xControlModel( pFormObject->GetUnoControlModel(),UNO_QUERY );
2138 if ( xControlModel.is() && aObjects.find(xControlModel) != aObjects.end() && bMark != pFormView->IsObjMarked( pSdrObject ) )
2140 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
2141 pFormView->MarkObj( pSdrObject, pPageView, !bMark, sal_False );
2143 } // while ( aIter.IsMore() )
2144 if ( bMark )
2146 // make the mark visible
2147 ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
2148 for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2150 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
2151 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
2152 if ( ( OUTDEV_WINDOW == rOutDev.GetOutDevType() ) && !aMarkRect.IsEmpty() )
2154 pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
2156 } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2159 //------------------------------------------------------------------------
2160 void NavigatorTree::CollectObjects(FmFormData* pFormData, sal_Bool bDeep, ::std::set< Reference< XFormComponent > >& _rObjects)
2162 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::MarkViewObjects" );
2163 FmEntryDataList* pChildList = pFormData->GetChildList();
2164 FmEntryData* pEntryData;
2165 FmControlData* pControlData;
2166 for( size_t i = 0; i < pChildList->size(); ++i )
2168 pEntryData = pChildList->at( i );
2169 if( pEntryData->ISA(FmControlData) )
2171 pControlData = (FmControlData*)pEntryData;
2172 _rObjects.insert(pControlData->GetFormComponent());
2173 } // if( pEntryData->ISA(FmControlData) )
2174 else if (bDeep && (pEntryData->ISA(FmFormData)))
2175 CollectObjects((FmFormData*)pEntryData,bDeep,_rObjects);
2176 } // for( sal_uInt32 i=0; i<pChildList->Count(); i++ )
2178 //------------------------------------------------------------------------
2179 void NavigatorTree::MarkViewObj( FmControlData* pControlData, sal_Bool bMarkHandles, sal_Bool bMark)
2181 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "NavigatorTree::MarkViewObj" );
2182 if( !pControlData )
2183 return;
2184 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
2185 if( !pFormShell )
2186 return;
2188 //////////////////////////////////////////////////////////////////////
2189 // In der Page das entsprechende SdrObj finden und selektieren
2190 FmFormView* pFormView = pFormShell->GetFormView();
2191 Reference< XFormComponent > xFormComponent( pControlData->GetFormComponent());
2192 SdrPageView* pPageView = pFormView->GetSdrPageView();
2193 SdrPage* pPage = pPageView->GetPage();
2195 bool bPaint = false;
2196 SdrObjListIter aIter( *pPage );
2197 while ( aIter.IsMore() )
2199 SdrObject* pSdrObject = aIter.Next();
2200 FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
2201 if ( !pFormObject )
2202 continue;
2204 Reference< XInterface > xControlModel( pFormObject->GetUnoControlModel() );
2205 if ( xControlModel != xFormComponent )
2206 continue;
2208 // mark the object
2209 if ( bMark != pFormView->IsObjMarked( pSdrObject ) )
2210 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
2211 pFormView->MarkObj( pSdrObject, pPageView, !bMark, sal_False );
2213 if ( !bMarkHandles || !bMark )
2214 continue;
2216 bPaint = true;
2218 } // while ( aIter.IsMore() )
2219 if ( bPaint )
2221 // make the mark visible
2222 ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
2223 for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2225 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
2226 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
2227 if ( OUTDEV_WINDOW == rOutDev.GetOutDevType() )
2229 pFormView->MakeVisible( aMarkRect, (Window&)rOutDev );
2231 } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2235 //............................................................................
2236 } // namespace svxform
2237 //............................................................................
2240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */