LCOV - code coverage report
Current view: top level - svx/source/form - navigatortree.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 951 0.1 %
Date: 2014-11-03 Functions: 2 57 3.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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"
      26             : 
      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>
      50             : 
      51             : #include <svx/svxdlg.hxx>
      52             : #include <svx/dialogs.hrc>
      53             : #include "svtools/treelistentry.hxx"
      54             : 
      55             : namespace svxform
      56             : {
      57             : 
      58             : 
      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)
      65             : 
      66             :     #define EXPLORER_SYNC_DELAY                 200
      67             :         // dieser Betrag an Millisekunden wird gewartet, ehe der Explorer nach einem Select oder Deselect die View synchronisiert
      68             : 
      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;
      79             : 
      80             : 
      81             :     // helper
      82             : 
      83             : 
      84             :     typedef ::std::map< Reference< XInterface >, SdrObject*, ::comphelper::OInterfaceCompare< XInterface > >
      85             :             MapModelToShape;
      86             :     typedef MapModelToShape::value_type ModelShapePair;
      87             : 
      88             : 
      89           0 :     void    collectShapeModelMapping( SdrPage* _pPage, MapModelToShape& _rMapping )
      90             :     {
      91             :         OSL_ENSURE( _pPage, "collectShapeModelMapping: invalid arg!" );
      92             : 
      93           0 :         _rMapping.clear();
      94             : 
      95           0 :         SdrObjListIter aIter( *_pPage );
      96           0 :         while ( aIter.IsMore() )
      97             :         {
      98           0 :             SdrObject* pSdrObject = aIter.Next();
      99           0 :             FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
     100           0 :             if ( !pFormObject )
     101           0 :                 continue;
     102             : 
     103           0 :             Reference< XInterface > xNormalizedModel( pFormObject->GetUnoControlModel(), UNO_QUERY );
     104             :                 // note that this is normalized (i.e. queried for XInterface explicitly)
     105             : 
     106             : #ifdef DBG_UTIL
     107             :             ::std::pair< MapModelToShape::iterator, bool > aPos =
     108             : #endif
     109           0 :             _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
     112           0 :         }
     113           0 :     }
     114             : 
     115           0 :     NavigatorTree::NavigatorTree( vcl::Window* pParent )
     116             :         :SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HSCROLL ) // #100258# OJ WB_HSCROLL added
     117             :         ,m_aControlExchange(this)
     118             :         ,m_pNavModel( NULL )
     119             :         ,m_pRootEntry(NULL)
     120             :         ,m_pEditEntry(NULL)
     121             :         ,nEditEvent(0)
     122             :         ,m_sdiState(SDI_DIRTY)
     123             :         ,m_aTimerTriggered(-1,-1)
     124             :         ,m_aDropActionType( DA_SCROLLUP )
     125             :         ,m_nSelectLock(0)
     126             :         ,m_nFormsSelected(0)
     127             :         ,m_nControlsSelected(0)
     128             :         ,m_nHiddenControls(0)
     129             :         ,m_aTimerCounter( DROP_ACTION_TIMER_INITIAL_TICKS )
     130             :         ,m_bDragDataDirty(false)
     131             :         ,m_bPrevSelectionMixed(false)
     132             :         ,m_bMarkingObjects(false)
     133             :         ,m_bRootSelected(false)
     134             :         ,m_bInitialUpdate(true)
     135           0 :         ,m_bKeyboardCut( false )
     136             :     {
     137           0 :         SetHelpId( HID_FORM_NAVIGATOR );
     138             : 
     139           0 :         m_aNavigatorImages = ImageList( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
     140             : 
     141             :         SetNodeBitmaps(
     142             :             m_aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
     143             :             m_aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
     144           0 :         );
     145             : 
     146           0 :         SetDragDropMode(0xFFFF);
     147           0 :         EnableInplaceEditing( true );
     148           0 :         SetSelectionMode(MULTIPLE_SELECTION);
     149             : 
     150           0 :         m_pNavModel = new NavigatorTreeModel( m_aNavigatorImages );
     151           0 :         Clear();
     152             : 
     153           0 :         StartListening( *m_pNavModel );
     154             : 
     155           0 :         m_aDropActionTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnDropActionTimer));
     156             : 
     157           0 :         m_aSynchronizeTimer.SetTimeoutHdl(LINK(this, NavigatorTree, OnSynchronizeTimer));
     158           0 :         SetSelectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
     159           0 :         SetDeselectHdl(LINK(this, NavigatorTree, OnEntrySelDesel));
     160           0 :     }
     161             : 
     162             : 
     163           0 :     NavigatorTree::~NavigatorTree()
     164             :     {
     165           0 :         if( nEditEvent )
     166           0 :             Application::RemoveUserEvent( nEditEvent );
     167             : 
     168           0 :         if (m_aSynchronizeTimer.IsActive())
     169           0 :             m_aSynchronizeTimer.Stop();
     170             : 
     171             :         DBG_ASSERT(GetNavModel() != NULL, "NavigatorTree::~NavigatorTree : unerwartet : kein ExplorerModel");
     172           0 :         EndListening( *m_pNavModel );
     173           0 :         Clear();
     174           0 :         delete m_pNavModel;
     175           0 :     }
     176             : 
     177             : 
     178           0 :     void NavigatorTree::Clear()
     179             :     {
     180           0 :         m_pNavModel->Clear();
     181           0 :     }
     182             : 
     183             : 
     184           0 :     void NavigatorTree::UpdateContent( FmFormShell* pFormShell )
     185             :     {
     186           0 :         if (m_bInitialUpdate)
     187             :         {
     188           0 :             GrabFocus();
     189           0 :             m_bInitialUpdate = false;
     190             :         }
     191             : 
     192           0 :         FmFormShell* pOldShell = GetNavModel()->GetFormShell();
     193           0 :         FmFormPage* pOldPage = GetNavModel()->GetFormPage();
     194           0 :         FmFormPage* pNewPage = pFormShell ? pFormShell->GetCurPage() : NULL;
     195             : 
     196           0 :         if ((pOldShell != pFormShell) || (pOldPage != pNewPage))
     197             :         {
     198             :             // neue Shell, waehrend ich gerade editiere ?
     199           0 :             if (IsEditingActive())
     200           0 :                 CancelTextEditing();
     201             : 
     202           0 :             m_bDragDataDirty = true;    // sicherheitshalber, auch wenn ich gar nicht dragge
     203             :         }
     204           0 :         GetNavModel()->UpdateContent( pFormShell );
     205             : 
     206             :         // wenn es eine Form gibt, die Root expandieren
     207           0 :         if (m_pRootEntry && !IsExpanded(m_pRootEntry))
     208           0 :             Expand(m_pRootEntry);
     209             :         // wenn es GENAU eine Form gibt, auch diese expandieren
     210           0 :         if (m_pRootEntry)
     211             :         {
     212           0 :             SvTreeListEntry* pFirst = FirstChild(m_pRootEntry);
     213           0 :             if (pFirst && !NextSibling(pFirst))
     214           0 :                 Expand(pFirst);
     215             :         }
     216           0 :     }
     217             : 
     218             : 
     219           0 :     bool NavigatorTree::implAllowExchange( sal_Int8 _nAction, bool* _pHasNonHidden )
     220             :     {
     221           0 :         SvTreeListEntry* pCurEntry = GetCurEntry();
     222           0 :         if (!pCurEntry)
     223           0 :             return false;
     224             : 
     225             :         // die Informationen fuer das AcceptDrop und ExecuteDrop
     226           0 :         CollectSelectionData(SDI_ALL);
     227           0 :         if (m_arrCurrentSelection.empty())
     228             :             // nothing to do
     229           0 :             return false;
     230             : 
     231             :         // testen, ob es sich vielleicht ausschliesslich um hidden controls handelt (dann koennte ich pCtrlExch noch ein
     232             :         // zusaetzliches Format geben)
     233           0 :         bool bHasNonHidden = false;
     234           0 :         for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
     235           0 :               it != m_arrCurrentSelection.end(); ++it )
     236             :         {
     237           0 :             FmEntryData* pCurrent = static_cast< FmEntryData* >( (*it)->GetUserData() );
     238           0 :             if ( IsHiddenControl( pCurrent ) )
     239           0 :                 continue;
     240           0 :             bHasNonHidden = true;
     241           0 :             break;
     242             :         }
     243             : 
     244           0 :         if ( bHasNonHidden && ( 0 == ( _nAction & DND_ACTION_MOVE ) ) )
     245             :             // non-hidden controls need to be moved
     246           0 :             return false;
     247             : 
     248           0 :         if ( _pHasNonHidden )
     249           0 :             *_pHasNonHidden = bHasNonHidden;
     250             : 
     251           0 :         return true;
     252             :     }
     253             : 
     254             : 
     255           0 :     bool NavigatorTree::implPrepareExchange( sal_Int8 _nAction )
     256             :     {
     257           0 :         EndSelection();
     258             : 
     259           0 :         bool bHasNonHidden = false;
     260           0 :         if ( !implAllowExchange( _nAction, &bHasNonHidden ) )
     261           0 :             return false;
     262             : 
     263           0 :         m_aControlExchange.prepareDrag();
     264           0 :         m_aControlExchange->setFocusEntry( GetCurEntry() );
     265             : 
     266           0 :         for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
     267           0 :               it != m_arrCurrentSelection.end(); ++it )
     268           0 :             m_aControlExchange->addSelectedEntry(*it);
     269             : 
     270           0 :         m_aControlExchange->setFormsRoot( GetNavModel()->GetFormPage()->GetForms() );
     271           0 :         m_aControlExchange->buildPathFormat( this, m_pRootEntry );
     272             : 
     273           0 :         if (!bHasNonHidden)
     274             :         {
     275             :             // eine entsprechende Sequenz aufbauen
     276           0 :             Sequence< Reference< XInterface > > seqIFaces(m_arrCurrentSelection.size());
     277           0 :             Reference< XInterface >* pArray = seqIFaces.getArray();
     278           0 :             for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
     279           0 :                   it != m_arrCurrentSelection.end(); ++it, ++pArray )
     280           0 :                 *pArray = static_cast< FmEntryData* >( (*it)->GetUserData() )->GetElement();
     281             : 
     282             :             // und das neue Format
     283           0 :             m_aControlExchange->addHiddenControlsFormat(seqIFaces);
     284             :         }
     285             : 
     286           0 :         m_bDragDataDirty = false;
     287           0 :         return true;
     288             :     }
     289             : 
     290             : 
     291           0 :     void NavigatorTree::StartDrag( sal_Int8 /*nAction*/, const ::Point& /*rPosPixel*/ )
     292             :     {
     293           0 :         EndSelection();
     294             : 
     295           0 :         if ( !implPrepareExchange( DND_ACTION_COPYMOVE ) )
     296             :             // nothing to do or something went wrong
     297           0 :             return;
     298             : 
     299             :         // jetzt haben wir alle in der aktuelle Situation moeglichen Formate eingesammelt, es kann also losgehen ...
     300           0 :         m_aControlExchange.startDrag( DND_ACTION_COPYMOVE );
     301             :     }
     302             : 
     303             : 
     304           0 :     void NavigatorTree::Command( const CommandEvent& rEvt )
     305             :     {
     306           0 :         bool bHandled = false;
     307           0 :         switch( rEvt.GetCommand() )
     308             :         {
     309             :             case COMMAND_CONTEXTMENU:
     310             :             {
     311             :                 // die Stelle, an der geklickt wurde
     312           0 :                 ::Point ptWhere;
     313           0 :                 if (rEvt.IsMouseEvent())
     314             :                 {
     315           0 :                     ptWhere = rEvt.GetMousePosPixel();
     316           0 :                     SvTreeListEntry* ptClickedOn = GetEntry(ptWhere);
     317           0 :                     if (ptClickedOn == NULL)
     318           0 :                         break;
     319           0 :                     if ( !IsSelected(ptClickedOn) )
     320             :                     {
     321           0 :                         SelectAll(false);
     322           0 :                         Select(ptClickedOn, true);
     323           0 :                         SetCurEntry(ptClickedOn);
     324             :                     }
     325             :                 }
     326             :                 else
     327             :                 {
     328           0 :                     if (m_arrCurrentSelection.empty()) // kann nur bei Kontextmenue ueber Tastatur passieren
     329           0 :                         break;
     330             : 
     331           0 :                     SvTreeListEntry* pCurrent = GetCurEntry();
     332           0 :                     if (!pCurrent)
     333           0 :                         break;
     334           0 :                     ptWhere = GetEntryPosition(pCurrent);
     335             :                 }
     336             : 
     337             :                 // meine Selektionsdaten auf den aktuellen Stand
     338           0 :                 CollectSelectionData(SDI_ALL);
     339             : 
     340             :                 // wenn mindestens ein Nicht-Root-Eintrag selektiert ist und die Root auch, dann nehme ich letztere aus der Selektion
     341             :                 // fix wieder raus
     342           0 :                 if ( (m_arrCurrentSelection.size() > 1) && m_bRootSelected )
     343             :                 {
     344           0 :                     Select( m_pRootEntry, false );
     345           0 :                     SetCursor( *m_arrCurrentSelection.begin(), true);
     346             :                 }
     347           0 :                 bool bSingleSelection = (m_arrCurrentSelection.size() == 1);
     348             : 
     349             : 
     350             :                 DBG_ASSERT( (m_arrCurrentSelection.size() > 0) || m_bRootSelected, "keine Eintraege selektiert" );
     351             :                     // solte nicht passieren, da ich oben bei der IsSelected-Abfrage auf jeden Fall einen selektiert haette,
     352             :                     // wenn das vorher nicht der Fall gewesen waere
     353             : 
     354             : 
     355             :                 // das Menue zusammenbasteln
     356           0 :                 FmFormShell* pFormShell = GetNavModel()->GetFormShell();
     357           0 :                 FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
     358           0 :                 if( pFormShell && pFormModel )
     359             :                 {
     360           0 :                     PopupMenu aContextMenu(SVX_RES(RID_FMEXPLORER_POPUPMENU));
     361           0 :                     PopupMenu* pSubMenuNew = aContextMenu.GetPopupMenu( SID_FM_NEW );
     362             : 
     363             :                     // das 'Neu'-Untermenue gibt es nur, wenn genau die Root oder genau ein Formular selektiert sind
     364           0 :                     aContextMenu.EnableItem( SID_FM_NEW, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
     365             : 
     366             :                     // 'Neu'\'Formular' unter genau den selben Bedingungen
     367           0 :                     pSubMenuNew->EnableItem( SID_FM_NEW_FORM, bSingleSelection && (m_nFormsSelected || m_bRootSelected) );
     368           0 :                     pSubMenuNew->SetItemImage(SID_FM_NEW_FORM, m_aNavigatorImages.GetImage(RID_SVXIMG_FORM));
     369           0 :                     pSubMenuNew->SetItemImage(SID_FM_NEW_HIDDEN, m_aNavigatorImages.GetImage(RID_SVXIMG_HIDDEN));
     370             : 
     371             :                     // 'Neu'\'verstecktes...', wenn genau ein Formular selektiert ist
     372           0 :                     pSubMenuNew->EnableItem( SID_FM_NEW_HIDDEN, bSingleSelection && m_nFormsSelected );
     373             : 
     374             :                     // 'Delete': everything which is not root can be removed
     375           0 :                     aContextMenu.EnableItem( SID_FM_DELETE, !m_bRootSelected );
     376             : 
     377             :                     // 'Cut', 'Copy' and 'Paste'
     378           0 :                     aContextMenu.EnableItem( SID_CUT, !m_bRootSelected && implAllowExchange( DND_ACTION_MOVE ) );
     379           0 :                     aContextMenu.EnableItem( SID_COPY, !m_bRootSelected && implAllowExchange( DND_ACTION_COPY ) );
     380           0 :                     aContextMenu.EnableItem( SID_PASTE, implAcceptPaste( ) );
     381             : 
     382             :                     // der TabDialog, wenn es genau ein Formular ist ...
     383           0 :                     aContextMenu.EnableItem( SID_FM_TAB_DIALOG, bSingleSelection && m_nFormsSelected );
     384             : 
     385             :                     // in XML forms, we don't allow for the properties of a form
     386             :                     // #i36484#
     387           0 :                     if ( pFormShell->GetImpl()->isEnhancedForm() && !m_nControlsSelected )
     388           0 :                         aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
     389             : 
     390             :                     // if the property browser is already open, we don't allow for the properties, too
     391           0 :                     if( pFormShell->GetImpl()->IsPropBrwOpen() )
     392           0 :                         aContextMenu.RemoveItem( aContextMenu.GetItemPos( SID_FM_SHOW_PROPERTY_BROWSER ) );
     393             :                     // and finally, if there's a mixed selection of forms and controls, disable the entry, too
     394             :                     else
     395             :                         aContextMenu.EnableItem( SID_FM_SHOW_PROPERTY_BROWSER,
     396           0 :                             (m_nControlsSelected && !m_nFormsSelected) || (!m_nControlsSelected && m_nFormsSelected) );
     397             : 
     398             :                     // Umbenennen gdw wenn ein Element und nicht die Root
     399           0 :                     aContextMenu.EnableItem( SID_FM_RENAME_OBJECT, bSingleSelection && !m_bRootSelected );
     400             : 
     401             :                     // der Reandonly-Eintrag ist nur auf der Root erlaubt
     402           0 :                     aContextMenu.EnableItem( SID_FM_OPEN_READONLY, m_bRootSelected );
     403             :                     // the same for automatic control focus
     404           0 :                     aContextMenu.EnableItem( SID_FM_AUTOCONTROLFOCUS, m_bRootSelected );
     405             : 
     406             :                     // die ConvertTo-Slots sind enabled, wenn genau ein Control selektiert ist, der
     407             :                     // dem Control entsprechende Slot ist disabled
     408           0 :                     if (!m_bRootSelected && !m_nFormsSelected && (m_nControlsSelected == 1))
     409             :                     {
     410           0 :                         aContextMenu.SetPopupMenu( SID_FM_CHANGECONTROLTYPE, FmXFormShell::GetConversionMenu() );
     411             : #if OSL_DEBUG_LEVEL > 0
     412             :                         FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
     413             :                         OSL_ENSURE( pFormShell->GetImpl()->isSolelySelected( pCurrent->GetFormComponent() ),
     414             :                             "NavigatorTree::Command: inconsistency between the navigator selection, and the selection as the shell knows it!" );
     415             : #endif
     416             : 
     417           0 :                         pFormShell->GetImpl()->checkControlConversionSlotsForCurrentSelection( *aContextMenu.GetPopupMenu( SID_FM_CHANGECONTROLTYPE ) );
     418             :                     }
     419             :                     else
     420           0 :                         aContextMenu.EnableItem( SID_FM_CHANGECONTROLTYPE, false );
     421             : 
     422             :                     // jetzt alles, was disabled wurde, wech
     423           0 :                     aContextMenu.RemoveDisabledEntries(true, true);
     424             : 
     425             :                     // OpenReadOnly setzen
     426             : 
     427           0 :                     aContextMenu.CheckItem( SID_FM_OPEN_READONLY, pFormModel->GetOpenInDesignMode() );
     428           0 :                     aContextMenu.CheckItem( SID_FM_AUTOCONTROLFOCUS, pFormModel->GetAutoControlFocus() );
     429             : 
     430           0 :                     sal_uInt16 nSlotId = aContextMenu.Execute( this, ptWhere );
     431           0 :                     switch( nSlotId )
     432             :                     {
     433             :                         case SID_FM_NEW_FORM:
     434             :                         {
     435           0 :                             OUString aStr(SVX_RESSTR(RID_STR_FORM));
     436           0 :                             OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
     437             : 
     438           0 :                             pFormModel->BegUndo(aUndoStr);
     439             :                             // der Slot war nur verfuegbar, wenn es genau einen selektierten Eintrag gibt und dieser die Root
     440             :                             // oder ein Formular ist
     441           0 :                             NewForm( *m_arrCurrentSelection.begin() );
     442           0 :                             pFormModel->EndUndo();
     443             : 
     444           0 :                         }   break;
     445             :                         case SID_FM_NEW_HIDDEN:
     446             :                         {
     447           0 :                             OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
     448           0 :                             OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
     449             : 
     450           0 :                             pFormModel->BegUndo(aUndoStr);
     451             :                             // dieser Slot war guletig bei (genau) einem selektierten Formular
     452           0 :                             OUString fControlName = FM_COMPONENT_HIDDEN;
     453           0 :                             NewControl( fControlName, *m_arrCurrentSelection.begin() );
     454           0 :                             pFormModel->EndUndo();
     455             : 
     456           0 :                         }   break;
     457             : 
     458             :                         case SID_CUT:
     459           0 :                             doCut();
     460           0 :                             break;
     461             : 
     462             :                         case SID_COPY:
     463           0 :                             doCopy();
     464           0 :                             break;
     465             : 
     466             :                         case SID_PASTE:
     467           0 :                             doPaste();
     468           0 :                             break;
     469             : 
     470             :                         case SID_FM_DELETE:
     471             :                         {
     472           0 :                             DeleteSelection();
     473             :                         }
     474           0 :                         break;
     475             :                         case SID_FM_TAB_DIALOG:
     476             :                         {
     477             :                             // dieser Slot galt bei genau einem selektierten Formular
     478           0 :                             SvTreeListEntry* pSelectedForm = *m_arrCurrentSelection.begin();
     479             :                             DBG_ASSERT( IsFormEntry(pSelectedForm), "NavigatorTree::Command: Dieser Eintrag muss ein FormEntry sein." );
     480             : 
     481           0 :                             FmFormData* pFormData = (FmFormData*)pSelectedForm->GetUserData();
     482           0 :                             Reference< XForm >  xForm(  pFormData->GetFormIface());
     483             : 
     484           0 :                             Reference< XTabControllerModel >  xTabController(xForm, UNO_QUERY);
     485           0 :                             if( !xTabController.is() )
     486           0 :                                 break;
     487           0 :                             GetNavModel()->GetFormShell()->GetImpl()->ExecuteTabOrderDialog( xTabController );
     488             :                         }
     489           0 :                         break;
     490             : 
     491             :                         case SID_FM_SHOW_PROPERTY_BROWSER:
     492             :                         {
     493           0 :                             ShowSelectionProperties(true);
     494             :                         }
     495           0 :                         break;
     496             :                         case SID_FM_RENAME_OBJECT:
     497             :                         {
     498             :                             // das war bei genau einem Nicht-Root-Eintrag erlaubt
     499           0 :                             EditEntry( *m_arrCurrentSelection.begin() );
     500             :                         }
     501           0 :                         break;
     502             :                         case SID_FM_OPEN_READONLY:
     503             :                         {
     504           0 :                             pFormModel->SetOpenInDesignMode( !pFormModel->GetOpenInDesignMode() );
     505           0 :                             pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_OPEN_READONLY);
     506             :                         }
     507           0 :                         break;
     508             :                         case SID_FM_AUTOCONTROLFOCUS:
     509             :                         {
     510           0 :                             pFormModel->SetAutoControlFocus( !pFormModel->GetAutoControlFocus() );
     511           0 :                             pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
     512             :                         }
     513           0 :                         break;
     514             :                         default:
     515           0 :                             if (FmXFormShell::isControlConversionSlot(nSlotId))
     516             :                             {
     517           0 :                                 FmControlData* pCurrent = (FmControlData*)(*m_arrCurrentSelection.begin())->GetUserData();
     518           0 :                                 if ( pFormShell->GetImpl()->executeControlConversionSlot( pCurrent->GetFormComponent(), nSlotId ) )
     519           0 :                                     ShowSelectionProperties();
     520             :                             }
     521           0 :                     }
     522             :                 }
     523           0 :                 bHandled = true;
     524           0 :             } break;
     525             :         }
     526             : 
     527           0 :         if (!bHandled)
     528           0 :             SvTreeListBox::Command( rEvt );
     529           0 :     }
     530             : 
     531             : 
     532           0 :     SvTreeListEntry* NavigatorTree::FindEntry( FmEntryData* pEntryData )
     533             :     {
     534           0 :         if( !pEntryData ) return NULL;
     535           0 :         SvTreeListEntry* pCurEntry = First();
     536             :         FmEntryData* pCurEntryData;
     537           0 :         while( pCurEntry )
     538             :         {
     539           0 :             pCurEntryData = (FmEntryData*)pCurEntry->GetUserData();
     540           0 :             if( pCurEntryData && pCurEntryData->IsEqualWithoutChildren(pEntryData) )
     541           0 :                 return pCurEntry;
     542             : 
     543           0 :             pCurEntry = Next( pCurEntry );
     544             :         }
     545             : 
     546           0 :         return NULL;
     547             :     }
     548             : 
     549             : 
     550           0 :     void NavigatorTree::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     551             :     {
     552           0 :         if( dynamic_cast<const FmNavRemovedHint*>(&rHint) )
     553             :         {
     554           0 :             const FmNavRemovedHint* pRemovedHint = static_cast<const FmNavRemovedHint*>(&rHint);
     555           0 :             FmEntryData* pEntryData = pRemovedHint->GetEntryData();
     556           0 :             Remove( pEntryData );
     557             :         }
     558             : 
     559           0 :         else if( dynamic_cast<const FmNavInsertedHint*>(&rHint) )
     560             :         {
     561           0 :             const FmNavInsertedHint* pInsertedHint = static_cast<const FmNavInsertedHint*>(&rHint);
     562           0 :             FmEntryData* pEntryData = pInsertedHint->GetEntryData();
     563           0 :             sal_uInt32 nRelPos = pInsertedHint->GetRelPos();
     564           0 :             Insert( pEntryData, nRelPos );
     565             :         }
     566             : 
     567           0 :         else if( dynamic_cast<const FmNavModelReplacedHint*>(&rHint) )
     568             :         {
     569           0 :             FmEntryData* pData = static_cast<const FmNavModelReplacedHint*>(&rHint)->GetEntryData();
     570           0 :             SvTreeListEntry* pEntry = FindEntry( pData );
     571           0 :             if (pEntry)
     572             :             {   // das Image neu setzen
     573           0 :                 SetCollapsedEntryBmp( pEntry, pData->GetNormalImage() );
     574           0 :                 SetExpandedEntryBmp( pEntry, pData->GetNormalImage() );
     575           0 :             }
     576             :         }
     577             : 
     578           0 :         else if( dynamic_cast<const FmNavNameChangedHint*>(&rHint) )
     579             :         {
     580           0 :             const FmNavNameChangedHint* pNameChangedHint = static_cast<const FmNavNameChangedHint*>(&rHint);
     581           0 :             SvTreeListEntry* pEntry = FindEntry( pNameChangedHint->GetEntryData() );
     582           0 :             SetEntryText( pEntry, pNameChangedHint->GetNewName() );
     583             :         }
     584             : 
     585           0 :         else if( dynamic_cast<const FmNavClearedHint*>(&rHint) )
     586             :         {
     587           0 :             SvTreeListBox::Clear();
     588             : 
     589             : 
     590             :             // Default-Eintrag "Formulare"
     591           0 :             Image aRootImage( m_aNavigatorImages.GetImage( RID_SVXIMG_FORMS ) );
     592           0 :             m_pRootEntry = InsertEntry( SVX_RESSTR(RID_STR_FORMS), aRootImage, aRootImage,
     593           0 :                 NULL, false, 0, NULL );
     594             :         }
     595           0 :         else if (!m_bMarkingObjects && dynamic_cast<const FmNavRequestSelectHint*>(&rHint))
     596             :         {   // wenn m_bMarkingObjects sal_True ist, markiere ich gerade selber Objekte, und da der ganze Mechanismus dahinter synchron ist,
     597             :             // ist das genau der Hint, der durch mein Markieren ausgeloest wird, also kann ich ihn ignorieren
     598           0 :             FmNavRequestSelectHint* pershHint = const_cast<FmNavRequestSelectHint*>(static_cast<const FmNavRequestSelectHint*>(&rHint));
     599           0 :             FmEntryDataArray& arredToSelect = pershHint->GetItems();
     600           0 :             SynchronizeSelection(arredToSelect);
     601             : 
     602           0 :             if (pershHint->IsMixedSelection())
     603             :                 // in diesem Fall habe ich alles deselektiert, obwohl die View u.U. eine gemischte Markierung hatte
     604             :                 // ich muss also im naechsten Select den Navigator an die View anpassen
     605           0 :                 m_bPrevSelectionMixed = true;
     606             :         }
     607           0 :     }
     608             : 
     609             : 
     610           0 :     SvTreeListEntry* NavigatorTree::Insert( FmEntryData* pEntryData, sal_uIntPtr nRelPos )
     611             :     {
     612             : 
     613             :         // Aktuellen Eintrag einfuegen
     614           0 :         SvTreeListEntry* pParentEntry = FindEntry( pEntryData->GetParent() );
     615             :         SvTreeListEntry* pNewEntry;
     616             : 
     617           0 :         if( !pParentEntry )
     618             :             pNewEntry = InsertEntry( pEntryData->GetText(),
     619           0 :                 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
     620           0 :                 m_pRootEntry, false, nRelPos, pEntryData );
     621             : 
     622             :         else
     623             :             pNewEntry = InsertEntry( pEntryData->GetText(),
     624           0 :                 pEntryData->GetNormalImage(), pEntryData->GetNormalImage(),
     625           0 :                 pParentEntry, false, nRelPos, pEntryData );
     626             : 
     627             : 
     628             :         // Wenn Root-Eintrag Root expandieren
     629           0 :         if( !pParentEntry )
     630           0 :             Expand( m_pRootEntry );
     631             : 
     632             : 
     633             :         // Children einfuegen
     634           0 :         FmEntryDataList* pChildList = pEntryData->GetChildList();
     635           0 :         size_t nChildCount = pChildList->size();
     636             :         FmEntryData* pChildData;
     637           0 :         for( size_t i = 0; i < nChildCount; i++ )
     638             :         {
     639           0 :             pChildData = pChildList->at( i );
     640           0 :             Insert( pChildData, TREELIST_APPEND );
     641             :         }
     642             : 
     643           0 :         return pNewEntry;
     644             :     }
     645             : 
     646             : 
     647           0 :     void NavigatorTree::Remove( FmEntryData* pEntryData )
     648             :     {
     649           0 :         if( !pEntryData )
     650           0 :             return;
     651             : 
     652             :         // der Entry zu den Daten
     653           0 :         SvTreeListEntry* pEntry = FindEntry( pEntryData );
     654           0 :         if (!pEntry)
     655           0 :             return;
     656             : 
     657             :         // Eintrag aus TreeListBox entfernen
     658             :         // ich darf das Select, das ich ausloese, nicht behandeln :
     659             :         // Select aendert die MarkList der View, wenn das gerade auch jemand anders macht und dabei ein Remove
     660             :         // triggert, haben wir mit ziemlicher Sicherheit ein Problem - Paradebeispiel war das Gruppieren von Controls mit
     661             :         // offenem Navigator ...)
     662           0 :         LockSelectionHandling();
     663             : 
     664             :         // ein kleines Problem : ich merke mir meine selektierten Daten, wenn mir jetzt jemand einen selektierten Eintrag
     665             :         // unter dem Hintern wegschiesst, werde ich inkonsistent ... was schlecht waere
     666           0 :         Select(pEntry, false);
     667             : 
     668             :         // beim eigentlichen Entfernen kann die Selection geaendert werden, da ich aber das SelectionHandling abgeschaltet
     669             :         // habe, muss ich mich hinterher darum kuemmern
     670           0 :         sal_uIntPtr nExpectedSelectionCount = GetSelectionCount();
     671             : 
     672           0 :         if( pEntry )
     673           0 :             GetModel()->Remove( pEntry );
     674             : 
     675           0 :         if (nExpectedSelectionCount != GetSelectionCount())
     676           0 :             SynchronizeSelection();
     677             : 
     678             :         // und standardmaessig behandle ich das Select natuerlich
     679           0 :         UnlockSelectionHandling();
     680             :     }
     681             : 
     682             : 
     683           0 :     bool NavigatorTree::IsFormEntry( SvTreeListEntry* pEntry )
     684             :     {
     685           0 :         FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
     686           0 :         return !pEntryData || pEntryData->ISA(FmFormData);
     687             :     }
     688             : 
     689             : 
     690           0 :     bool NavigatorTree::IsFormComponentEntry( SvTreeListEntry* pEntry )
     691             :     {
     692           0 :         FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
     693           0 :         return pEntryData && pEntryData->ISA(FmControlData);
     694             :     }
     695             : 
     696             : 
     697           0 :     bool NavigatorTree::implAcceptPaste( )
     698             :     {
     699           0 :         SvTreeListEntry* pFirstSelected = FirstSelected();
     700           0 :         if ( !pFirstSelected || NextSelected( pFirstSelected ) )
     701             :             // no selected entry, or at least two selected entries
     702           0 :             return false;
     703             : 
     704             :         // get the clipboard
     705           0 :         TransferableDataHelper aClipboardContent( TransferableDataHelper::CreateFromSystemClipboard( this ) );
     706             : 
     707           0 :         sal_Int8 nAction = m_aControlExchange.isClipboardOwner() && doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY;
     708           0 :         return ( nAction == implAcceptDataTransfer( aClipboardContent.GetDataFlavorExVector(), nAction, pFirstSelected, false ) );
     709             :     }
     710             : 
     711             : 
     712           0 :     sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
     713             :     {
     714           0 :         return implAcceptDataTransfer( _rFlavors, _nAction, GetEntry( _rDropPos ), _bDnD );
     715             :     }
     716             : 
     717             : 
     718           0 :     sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
     719             :     {
     720             :         // no target -> no drop
     721           0 :         if (!_pTargetEntry)
     722           0 :             return DND_ACTION_NONE;
     723             : 
     724             :         // format check
     725           0 :         bool bHasDefControlFormat = OControlExchange::hasFieldExchangeFormat( _rFlavors );
     726           0 :         bool bHasControlPathFormat = OControlExchange::hasControlPathFormat( _rFlavors );
     727           0 :         bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( _rFlavors );
     728           0 :         if (!bHasDefControlFormat && !bHasControlPathFormat && !bHasHiddenControlsFormat)
     729           0 :             return DND_ACTION_NONE;
     730             : 
     731           0 :         bool bSelfSource = _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner();
     732             : 
     733           0 :         if ( bHasHiddenControlsFormat )
     734             :         {   // bHasHiddenControlsFormat means that only hidden controls are part of the data
     735             : 
     736             :             // hidden controls can be copied to a form only
     737           0 :             if ( !_pTargetEntry || ( _pTargetEntry == m_pRootEntry ) || !IsFormEntry( _pTargetEntry ) )
     738           0 :                 return DND_ACTION_NONE;
     739             : 
     740           0 :             return bSelfSource ? ( DND_ACTION_COPYMOVE & _nAction ) : DND_ACTION_COPY;
     741             :         }
     742             : 
     743           0 :         if  ( !bSelfSource )
     744             :         {
     745             :             // DnD or CnP crossing navigator boundaries
     746             :             // The main problem here is that the current API does not allow us to sneak into the content which
     747             :             // is to be inserted. So we have to allow it for the moment, but maybe reject later on (in the real drop).
     748             : 
     749             :             // TODO: this smart behaviour later on ... at the moment, we disallow data transfer crossing navigator
     750             :             // boundaries.
     751             : 
     752           0 :             return DND_ACTION_NONE;
     753             :         }
     754             : 
     755             :         DBG_ASSERT( _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner(),
     756             :             "NavigatorTree::implAcceptDataTransfer: here only with source=dest!" );
     757             :             // somebody changed the logic of this method ...
     758             : 
     759             :         // from here on, I can work with m_aControlExchange instead of _rData!
     760             : 
     761           0 :         bool bForeignCollection = m_aControlExchange->getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
     762           0 :         if ( bForeignCollection )
     763             :         {
     764             :             // crossing shell/page boundaries, we can exchange hidden controls only
     765             :             // But if we survived the checks above, we do not have hidden controls.
     766             :             // -> no data transfer
     767             :             DBG_ASSERT( !bHasHiddenControlsFormat, "NavigatorTree::implAcceptDataTransfer: still hidden controls format!" );
     768             :                 // somebody changed the logic of this method ...
     769             : 
     770           0 :             return DND_ACTION_COPY;
     771             :         }
     772             : 
     773           0 :         if (DND_ACTION_MOVE != _nAction) // 'normal' controls within a shell are moved only (never copied)
     774           0 :             return DND_ACTION_NONE;
     775             : 
     776           0 :         if ( m_bDragDataDirty || !bHasDefControlFormat )
     777             :         {
     778           0 :             if (!bHasControlPathFormat)
     779             :                 // ich befinde mich zwar in der Shell/Page, aus der die Controls stammen, habe aber kein Format, das den stattgefundenen
     780             :                 // Shell-Wechsel ueberlebt hat (SVX_FM_CONTROLS_AS_PATH)
     781           0 :                 return DND_ACTION_NONE;
     782             : 
     783             :             // da die Shell waehrend des Draggens umgeschaltet wude, muss ich die Liste des ExchangeObjektes wieder neu aufbauen
     784             :             // (dort stehen SvLBoxEntries drin, und die sind bei der Umschaltung floeten gegangen)
     785           0 :             m_aControlExchange->buildListFromPath(this, m_pRootEntry);
     786           0 :             m_bDragDataDirty = false;
     787             :         }
     788             : 
     789             :         // die Liste der gedroppten Eintraege aus dem DragServer
     790           0 :         const ListBoxEntrySet& aDropped = m_aControlExchange->selected();
     791             :         DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implAcceptDataTransfer: keine Eintraege !");
     792             : 
     793           0 :         bool bDropTargetIsComponent = IsFormComponentEntry( _pTargetEntry );
     794             :         //SvTreeListEntry* pDropTargetParent = GetParent( _pTargetEntry );
     795             : 
     796             :         // conditions to disallow the drop
     797             :         // 0) the root entry is part of the list (can't DnD the root!)
     798             :         // 1) one of the draged entries is to be dropped onto it's own parent
     799             :         // 2) -               "       - is to be dropped onto itself
     800             :         // 3) -               "       - is a Form and to be dropped onto one of it's descendants
     801             :         // 4) one of the entries is a control and to be dropped onto the root
     802             :         // 5) a control or form will be dropped onto a control which is _not_ a sibling (dropping onto a sibling
     803             :         //      means moving the control)
     804             : 
     805             :         // collect the ancestors of the drop targte (speeds up 3)
     806           0 :         SvLBoxEntrySortedArray arrDropAnchestors;
     807           0 :         SvTreeListEntry* pLoop = _pTargetEntry;
     808           0 :         while (pLoop)
     809             :         {
     810           0 :             arrDropAnchestors.insert(pLoop);
     811           0 :             pLoop = GetParent(pLoop);
     812             :         }
     813             : 
     814           0 :         for (   ListBoxEntrySet::const_iterator dropped = aDropped.begin();
     815           0 :                 dropped != aDropped.end();
     816             :                 ++dropped
     817             :             )
     818             :         {
     819           0 :             SvTreeListEntry* pCurrent = *dropped;
     820           0 :             SvTreeListEntry* pCurrentParent = GetParent(pCurrent);
     821             : 
     822             :             // test for 0)
     823           0 :             if (pCurrent == m_pRootEntry)
     824           0 :                 return DND_ACTION_NONE;
     825             : 
     826             :             // test for 1)
     827           0 :             if ( _pTargetEntry == pCurrentParent )
     828           0 :                 return DND_ACTION_NONE;
     829             : 
     830             :             // test for 2)
     831           0 :             if (pCurrent == _pTargetEntry)
     832           0 :                 return DND_ACTION_NONE;
     833             : 
     834             :             // test for 5)
     835             :     //      if ( bDropTargetIsComponent && (pDropTargetParent != pCurrentParent) )
     836           0 :             if ( bDropTargetIsComponent )   // TODO : die obige Zeile wieder rein, dann muss aber ExecuteDrop das Vertauschen auch beherrschen
     837           0 :                 return DND_ACTION_NONE;
     838             : 
     839             :             // test for 3)
     840           0 :             if ( IsFormEntry(pCurrent) )
     841             :             {
     842           0 :                 if ( arrDropAnchestors.find(pCurrent) != arrDropAnchestors.end() )
     843           0 :                     return DND_ACTION_NONE;
     844           0 :             } else if ( IsFormComponentEntry(pCurrent) )
     845             :             {
     846             :                 // test for 4)
     847           0 :                 if (_pTargetEntry == m_pRootEntry)
     848           0 :                     return DND_ACTION_NONE;
     849             :             }
     850             :         }
     851             : 
     852           0 :         return DND_ACTION_MOVE;
     853             :     }
     854             : 
     855             : 
     856           0 :     sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& rEvt )
     857             :     {
     858           0 :         ::Point aDropPos = rEvt.maPosPixel;
     859             : 
     860             :         // kuemmern wir uns erst mal um moeglich DropActions (Scrollen und Aufklappen)
     861           0 :         if (rEvt.mbLeaving)
     862             :         {
     863           0 :             if (m_aDropActionTimer.IsActive())
     864           0 :                 m_aDropActionTimer.Stop();
     865             :         } else
     866             :         {
     867           0 :             bool bNeedTrigger = false;
     868             :             // auf dem ersten Eintrag ?
     869           0 :             if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
     870             :             {
     871           0 :                 m_aDropActionType = DA_SCROLLUP;
     872           0 :                 bNeedTrigger = true;
     873             :             } else
     874             :                 // auf dem letzten (bzw. in dem Bereich, den ein Eintrag einnehmen wuerde, wenn er unten genau buendig
     875             :                 // abschliessen wuerde) ?
     876           0 :                 if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
     877             :                 {
     878           0 :                     m_aDropActionType = DA_SCROLLDOWN;
     879           0 :                     bNeedTrigger = true;
     880             :                 } else
     881             :                 {   // auf einem Entry mit Children, der nicht aufgeklappt ist ?
     882           0 :                     SvTreeListEntry* pDropppedOn = GetEntry(aDropPos);
     883           0 :                     if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
     884             :                     {
     885             :                         // -> aufklappen
     886           0 :                         m_aDropActionType = DA_EXPANDNODE;
     887           0 :                         bNeedTrigger = true;
     888             :                     }
     889             :                 }
     890             : 
     891           0 :             if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
     892             :             {
     893             :                 // neu anfangen zu zaehlen
     894           0 :                 m_aTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
     895             :                 // die Pos merken, da ich auch AcceptDrops bekomme, wenn sich die Maus gar nicht bewegt hat
     896           0 :                 m_aTimerTriggered = aDropPos;
     897             :                 // und den Timer los
     898           0 :                 if (!m_aDropActionTimer.IsActive()) // gibt es den Timer schon ?
     899             :                 {
     900           0 :                     m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
     901           0 :                     m_aDropActionTimer.Start();
     902             :                 }
     903           0 :             } else if (!bNeedTrigger)
     904           0 :                 m_aDropActionTimer.Stop();
     905             :         }
     906             : 
     907           0 :         return implAcceptDataTransfer( GetDataFlavorExVector(), rEvt.mnAction, aDropPos, true );
     908             :     }
     909             : 
     910             : 
     911           0 :     sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
     912             :     {
     913           0 :         return implExecuteDataTransfer( _rData, _nAction, GetEntry( _rDropPos ), _bDnD );
     914             :     }
     915             : 
     916             : 
     917           0 :     sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, SvTreeListEntry* _pTargetEntry, bool _bDnD )
     918             :     {
     919           0 :         const DataFlavorExVector& rDataFlavors = _rData.GetDataFlavorExVector();
     920             : 
     921           0 :         if ( DND_ACTION_NONE == implAcceptDataTransfer( rDataFlavors, _nAction, _pTargetEntry, _bDnD ) )
     922             :             // under some platforms, it may happen that ExecuteDrop is called though AcceptDrop returned DND_ACTION_NONE
     923           0 :             return DND_ACTION_NONE;
     924             : 
     925             :         // ware schlecht, wenn nach dem Droppen noch gescrollt wird ...
     926           0 :         if (m_aDropActionTimer.IsActive())
     927           0 :             m_aDropActionTimer.Stop();
     928             : 
     929           0 :         if (!_pTargetEntry)
     930             :             // no target -> no drop
     931           0 :             return DND_ACTION_NONE;
     932             : 
     933             :         // format checks
     934             : #ifdef DBG_UTIL
     935             :         bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( rDataFlavors );
     936             :         bool bForeignCollection = _rData.getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
     937             :         DBG_ASSERT(!bForeignCollection || bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: invalid format (AcceptDrop shouldn't have let this pass) !");
     938             :         DBG_ASSERT(bForeignCollection || !m_bDragDataDirty, "NavigatorTree::implExecuteDataTransfer: invalid state (shell changed since last exchange resync) !");
     939             :             // das sollte in AcceptDrop erledigt worden sein : dort wird in _rData die Liste der Controls aufgebaut und m_bDragDataDirty
     940             :             // zurueckgesetzt
     941             : #endif
     942             : 
     943           0 :         if ( DND_ACTION_COPY == _nAction )
     944             :         {   // bHasHiddenControlsFormat means that only hidden controls are part of the data
     945             :             DBG_ASSERT( bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: copy allowed for hidden controls only!" );
     946             :             DBG_ASSERT( _pTargetEntry && ( _pTargetEntry != m_pRootEntry ) && IsFormEntry( _pTargetEntry ),
     947             :                 "NavigatorTree::implExecuteDataTransfer: should not be here!" );
     948             :                 // implAcceptDataTransfer should have caught both cases
     949             : 
     950             :             DBG_ASSERT(bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: only copying of hidden controls is supported !");
     951             :                 // das sollte das AcceptDrop abgefangen haben
     952             : 
     953             :             // da ich gleich die Zielobjekte alle selektieren will (und nur die)
     954           0 :             SelectAll(false);
     955             : 
     956           0 :             Sequence< Reference< XInterface > > aControls = _rData.hiddenControls();
     957           0 :             sal_Int32 nCount = aControls.getLength();
     958           0 :             const Reference< XInterface >* pControls = aControls.getConstArray();
     959             : 
     960           0 :             FmFormShell* pFormShell = GetNavModel()->GetFormShell();
     961           0 :             FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
     962             : 
     963             :             // innerhalb eines Undo ...
     964           0 :             if (pFormModel)
     965             :             {
     966           0 :                 OUString aStr(SVX_RESSTR(RID_STR_CONTROL));
     967           0 :                 OUString aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_INSERT).replaceAll(OUString('#'), aStr);
     968           0 :                 pFormModel->BegUndo(aUndoStr);
     969             :             }
     970             : 
     971             :             // die Conrtols kopieren
     972           0 :             for (sal_Int32 i=0; i<nCount; ++i)
     973             :             {
     974             :                 // neues Control anlegen
     975           0 :                 OUString fControlName = FM_COMPONENT_HIDDEN;
     976           0 :                 FmControlData* pNewControlData = NewControl( fControlName, _pTargetEntry, false);
     977           0 :                 Reference< XPropertySet >  xNewPropSet( pNewControlData->GetPropertySet() );
     978             : 
     979             :                 // und die Properties des alten in das neue kopieren
     980           0 :                 Reference< XPropertySet >  xCurrent(pControls[i], UNO_QUERY);
     981             : #if (OSL_DEBUG_LEVEL > 1)
     982             :                 // nur mal eben sehen, ob das Ding tatsaechlich ein hidden control ist
     983             :                 sal_Int16 nClassId = ::comphelper::getINT16(xCurrent->getPropertyValue(FM_PROP_CLASSID));
     984             :                 OSL_ENSURE(nClassId == FormComponentType::HIDDENCONTROL, "NavigatorTree::implExecuteDataTransfer: invalid control in drop list !");
     985             :                     // wenn das SVX_FM_HIDDEN_CONTROLS-Format vorhanden ist, dann sollten wirklich nur hidden controls in der Sequenz
     986             :                     // stecken
     987             : #endif // (OSL_DEBUG_LEVEL > 1)
     988           0 :                 Reference< XPropertySetInfo >  xPropInfo( xCurrent->getPropertySetInfo());
     989           0 :                 Sequence< Property> seqAllCurrentProps = xPropInfo->getProperties();
     990           0 :                 Property* pAllCurrentProps = seqAllCurrentProps.getArray();
     991           0 :                 for (sal_Int32 j=0; j<seqAllCurrentProps.getLength(); ++j)
     992             :                 {
     993           0 :                     OUString sCurrentProp = pAllCurrentProps[j].Name;
     994           0 :                     if (((pAllCurrentProps[j].Attributes & PropertyAttribute::READONLY) == 0) && (sCurrentProp != FM_PROP_NAME))
     995             :                     {   // (read-only attribs werden natuerlich nicht gesetzt, dito der Name, den hat das NewControl schon eindeutig
     996             :                         // festgelegt)
     997           0 :                         xNewPropSet->setPropertyValue(sCurrentProp, xCurrent->getPropertyValue(sCurrentProp));
     998             :                     }
     999           0 :                 }
    1000             : 
    1001           0 :                 SvTreeListEntry* pToSelect = FindEntry(pNewControlData);
    1002           0 :                 Select(pToSelect, true);
    1003           0 :                 if (i == 0)
    1004           0 :                     SetCurEntry(pToSelect);
    1005           0 :             }
    1006             : 
    1007           0 :             if (pFormModel)
    1008           0 :                 pFormModel->EndUndo();
    1009             : 
    1010           0 :             return _nAction;
    1011             :         }
    1012             : 
    1013           0 :         if ( !OControlExchange::hasFieldExchangeFormat( _rData.GetDataFlavorExVector() ) )
    1014             :         {
    1015             :             // can't do anything without the internal format here ... usually happens when doing DnD or CnP
    1016             :             // over navigator boundaries
    1017           0 :             return DND_ACTION_NONE;
    1018             :         }
    1019             : 
    1020             :         // some data for the target
    1021           0 :         bool bDropTargetIsForm = IsFormEntry(_pTargetEntry);
    1022           0 :         FmFormData* pTargetData = bDropTargetIsForm ? (FmFormData*)_pTargetEntry->GetUserData() : NULL;
    1023             : 
    1024             :         DBG_ASSERT( DND_ACTION_COPY != _nAction, "NavigatorTree::implExecuteDataTransfer: somebody changed the logics!" );
    1025             : 
    1026             :         // die Liste der gedraggten Eintraege
    1027           0 :         ListBoxEntrySet aDropped = _rData.selected();
    1028             :         DBG_ASSERT(aDropped.size() >= 1, "NavigatorTree::implExecuteDataTransfer: no entries!");
    1029             : 
    1030             :         // die Shell und das Model
    1031           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1032           0 :         FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : NULL;
    1033           0 :         if (!pFormModel)
    1034           0 :             return DND_ACTION_NONE;
    1035             : 
    1036             :         // fuer's Undo
    1037           0 :         const bool bUndo = pFormModel->IsUndoEnabled();
    1038             : 
    1039           0 :         if( bUndo )
    1040             :         {
    1041           0 :             OUString strUndoDescription(SVX_RESSTR(RID_STR_UNDO_CONTAINER_REPLACE));
    1042           0 :             pFormModel->BegUndo(strUndoDescription);
    1043             :         }
    1044             : 
    1045             :         // ich nehme vor dem Einfuegen eines Eintrages seine Selection raus, damit die Markierung dabei nicht flackert
    1046             :         // -> das Handeln des Select locken
    1047           0 :         LockSelectionHandling();
    1048             : 
    1049             :         // jetzt durch alle gedroppten Eintraege ...
    1050           0 :         for (   ListBoxEntrySet::const_iterator dropped = aDropped.begin();
    1051           0 :                 dropped != aDropped.end();
    1052             :                 ++dropped
    1053             :             )
    1054             :         {
    1055             :             // ein paar Daten zum aktuellen Element
    1056           0 :             SvTreeListEntry* pCurrent = *dropped;
    1057             :             DBG_ASSERT(pCurrent != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
    1058             :             DBG_ASSERT(GetParent(pCurrent) != NULL, "NavigatorTree::implExecuteDataTransfer: ungueltiger Eintrag");
    1059             :                 // die Root darf nicht gedraggt werden
    1060             : 
    1061           0 :             FmEntryData* pCurrentUserData = (FmEntryData*)pCurrent->GetUserData();
    1062             : 
    1063           0 :             Reference< XChild >  xCurrentChild(pCurrentUserData->GetChildIFace(), UNO_QUERY);
    1064           0 :             Reference< XIndexContainer >  xContainer(xCurrentChild->getParent(), UNO_QUERY);
    1065             : 
    1066           0 :             FmFormData* pCurrentParentUserData = static_cast<FmFormData*>(pCurrentUserData->GetParent());
    1067             :             DBG_ASSERT(pCurrentParentUserData == NULL || pCurrentParentUserData->ISA(FmFormData), "NavigatorTree::implExecuteDataTransfer: ungueltiges Parent");
    1068             : 
    1069             :             // beim Vater austragen
    1070           0 :             if (pCurrentParentUserData)
    1071           0 :                 pCurrentParentUserData->GetChildList()->remove( pCurrentUserData );
    1072             :             else
    1073           0 :                 GetNavModel()->GetRootList()->remove( pCurrentUserData );
    1074             : 
    1075             :             // aus dem Container entfernen
    1076           0 :             sal_Int32 nIndex = getElementPos(xContainer, xCurrentChild);
    1077           0 :             GetNavModel()->m_pPropChangeList->Lock();
    1078             :             // die Undo-Action fuer das Rausnehmen
    1079           0 :             if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
    1080             :             {
    1081             :                 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Removed,
    1082           0 :                                                             xContainer, xCurrentChild, nIndex));
    1083             :             }
    1084           0 :             else if( !GetNavModel()->m_pPropChangeList->CanUndo() )
    1085             :             {
    1086           0 :                 FmUndoContainerAction::DisposeElement( xCurrentChild );
    1087             :             }
    1088             : 
    1089             :             // Events mitkopieren
    1090           0 :             Reference< XEventAttacherManager >  xManager(xContainer, UNO_QUERY);
    1091           0 :             Sequence< ScriptEventDescriptor > aEvts;
    1092             : 
    1093           0 :             if (xManager.is() && nIndex >= 0)
    1094           0 :                 aEvts = xManager->getScriptEvents(nIndex);
    1095           0 :             xContainer->removeByIndex(nIndex);
    1096             : 
    1097             :             // die Selection raus
    1098           0 :             Select(pCurrent, false);
    1099             :             // und weg
    1100           0 :             Remove(pCurrentUserData);
    1101             : 
    1102             :             // die Stelle innerhalb des DropParents, an der ich die gedroppten Eintraege einfuegen muss
    1103           0 :             if (pTargetData)
    1104           0 :                 xContainer = Reference< XIndexContainer > (pTargetData->GetElement(), UNO_QUERY);
    1105             :             else
    1106           0 :                 xContainer = Reference< XIndexContainer > (GetNavModel()->GetForms(), UNO_QUERY);
    1107             : 
    1108             :             // immer ganz hinten einfuegen
    1109           0 :             nIndex = xContainer->getCount();
    1110             : 
    1111             :             // UndoAction fuer das Einfuegen
    1112           0 :             if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
    1113             :                 pFormModel->AddUndo(new FmUndoContainerAction(*pFormModel, FmUndoContainerAction::Inserted,
    1114           0 :                                                          xContainer, xCurrentChild, nIndex));
    1115             : 
    1116             :             // einfuegen im neuen Container
    1117           0 :             if (pTargetData)
    1118             :             {
    1119             :                  // es wird in eine Form eingefuegt, dann brauche ich eine FormComponent
    1120           0 :                 xContainer->insertByIndex( nIndex,
    1121           0 :                     makeAny( Reference< XFormComponent >( xCurrentChild, UNO_QUERY ) ) );
    1122             :             }
    1123             :             else
    1124             :             {
    1125           0 :                 xContainer->insertByIndex( nIndex,
    1126           0 :                     makeAny( Reference< XForm >( xCurrentChild, UNO_QUERY ) ) );
    1127             :             }
    1128             : 
    1129           0 :             if (aEvts.getLength())
    1130             :             {
    1131           0 :                 xManager = Reference< XEventAttacherManager > (xContainer, UNO_QUERY);
    1132           0 :                 if (xManager.is())
    1133           0 :                     xManager->registerScriptEvents(nIndex, aEvts);
    1134             :             }
    1135             : 
    1136           0 :             GetNavModel()->m_pPropChangeList->UnLock();
    1137             : 
    1138             :             // zuerst dem Eintrag das neue Parent
    1139           0 :             pCurrentUserData->SetParent(pTargetData);
    1140             : 
    1141             :             // dann dem Parent das neue Child
    1142           0 :             if (pTargetData)
    1143           0 :                 pTargetData->GetChildList()->insert( pCurrentUserData, nIndex );
    1144             :             else
    1145           0 :                 GetNavModel()->GetRootList()->insert( pCurrentUserData, nIndex );
    1146             : 
    1147             :             // dann bei mir selber bekanntgeben und neu selektieren
    1148           0 :             SvTreeListEntry* pNew = Insert( pCurrentUserData, nIndex );
    1149           0 :             if ( ( aDropped.begin() == dropped ) && pNew )
    1150             :             {
    1151           0 :                 SvTreeListEntry* pParent = GetParent( pNew );
    1152           0 :                 if ( pParent )
    1153           0 :                     Expand( pParent );
    1154             :             }
    1155           0 :         }
    1156             : 
    1157           0 :         UnlockSelectionHandling();
    1158             : 
    1159           0 :         if( bUndo )
    1160           0 :             pFormModel->EndUndo();
    1161             : 
    1162             :         // During the move, the markings of the underlying view did not change (because the view is not affected by the logical
    1163             :         // hierarchy of the form/control models. But my selection changed - which means I have to adjust it according to the
    1164             :         // view marks, again.
    1165           0 :         SynchronizeSelection();
    1166             : 
    1167             :         // in addition, with the move of controls such things as "the current form" may have changed - force the shell
    1168             :         // to update itself accordingly
    1169           0 :         if( pFormShell && pFormShell->GetImpl() && pFormShell->GetFormView() )
    1170           0 :             pFormShell->GetImpl()->DetermineSelection( pFormShell->GetFormView()->GetMarkedObjectList() );
    1171             : 
    1172           0 :         if ( m_aControlExchange.isClipboardOwner() && ( DND_ACTION_MOVE == _nAction ) )
    1173           0 :             m_aControlExchange->clear();
    1174             : 
    1175           0 :         return _nAction;
    1176             :     }
    1177             : 
    1178             : 
    1179           0 :     sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
    1180             :     {
    1181           0 :         sal_Int8 nResult( DND_ACTION_NONE );
    1182             : 
    1183           0 :         if ( m_aControlExchange.isDragSource() )
    1184           0 :             nResult = implExecuteDataTransfer( *m_aControlExchange, rEvt.mnAction, rEvt.maPosPixel, true );
    1185             :         else
    1186             :         {
    1187           0 :             OControlTransferData aDroppedData( rEvt.maDropEvent.Transferable );
    1188           0 :             nResult = implExecuteDataTransfer( aDroppedData, rEvt.mnAction, rEvt.maPosPixel, true );
    1189             :         }
    1190             : 
    1191           0 :         return nResult;
    1192             :     }
    1193             : 
    1194             : 
    1195           0 :     void NavigatorTree::doPaste()
    1196             :     {
    1197             :            try
    1198             :         {
    1199           0 :             if ( m_aControlExchange.isClipboardOwner() )
    1200             :             {
    1201           0 :                 implExecuteDataTransfer( *m_aControlExchange, doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY, FirstSelected(), false );
    1202             :             }
    1203             :             else
    1204             :             {
    1205             :                 // the clipboard content
    1206           0 :                 Reference< XClipboard > xClipboard( GetClipboard() );
    1207           0 :                 Reference< XTransferable > xTransferable;
    1208           0 :                 if ( xClipboard.is() )
    1209           0 :                     xTransferable = xClipboard->getContents();
    1210             : 
    1211           0 :                 OControlTransferData aClipboardContent( xTransferable );
    1212           0 :                 implExecuteDataTransfer( aClipboardContent, DND_ACTION_COPY, FirstSelected(), false );
    1213             :             }
    1214             :         }
    1215           0 :         catch( const Exception& )
    1216             :         {
    1217             :             OSL_FAIL( "NavigatorTree::doPaste: caught an exception!" );
    1218             :         }
    1219           0 :     }
    1220             : 
    1221             : 
    1222           0 :     void NavigatorTree::doCopy()
    1223             :     {
    1224           0 :         if ( implPrepareExchange( DND_ACTION_COPY ) )
    1225             :         {
    1226           0 :             m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
    1227           0 :             m_aControlExchange.copyToClipboard( );
    1228             :         }
    1229           0 :     }
    1230             : 
    1231             : 
    1232           0 :     void NavigatorTree::ModelHasRemoved( SvTreeListEntry* _pEntry )
    1233             :     {
    1234           0 :         SvTreeListEntry* pTypedEntry = static_cast< SvTreeListEntry* >( _pEntry );
    1235           0 :         if ( doingKeyboardCut() )
    1236           0 :             m_aCutEntries.erase( pTypedEntry );
    1237             : 
    1238           0 :         if ( m_aControlExchange.isDataExchangeActive() )
    1239             :         {
    1240           0 :             if ( 0 == m_aControlExchange->onEntryRemoved( pTypedEntry ) )
    1241             :             {
    1242             :                 // last of the entries which we put into the clipboard has been deleted from the tree.
    1243             :                 // Give up the clipboard ownership.
    1244           0 :                 m_aControlExchange.clear();
    1245             :             }
    1246             :         }
    1247           0 :     }
    1248             : 
    1249             : 
    1250           0 :     void NavigatorTree::doCut()
    1251             :     {
    1252           0 :         if ( implPrepareExchange( DND_ACTION_MOVE ) )
    1253             :         {
    1254           0 :             m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
    1255           0 :             m_aControlExchange.copyToClipboard( );
    1256           0 :             m_bKeyboardCut = true;
    1257             : 
    1258             :             // mark all the entries we just "cut" into the clipboard as "nearly moved"
    1259           0 :             for ( SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
    1260           0 :                   it != m_arrCurrentSelection.end(); ++it )
    1261             :             {
    1262           0 :                 SvTreeListEntry* pEntry = *it;
    1263           0 :                 if ( pEntry )
    1264             :                 {
    1265           0 :                     m_aCutEntries.insert( pEntry );
    1266           0 :                     pEntry->SetFlags( pEntry->GetFlags() | SV_ENTRYFLAG_SEMITRANSPARENT );
    1267           0 :                     InvalidateEntry( pEntry );
    1268             :                 }
    1269             :             }
    1270             :         }
    1271           0 :     }
    1272             : 
    1273             : 
    1274           0 :     void NavigatorTree::KeyInput(const ::KeyEvent& rKEvt)
    1275             :     {
    1276           0 :         const vcl::KeyCode& rCode = rKEvt.GetKeyCode();
    1277             : 
    1278             :         // delete?
    1279           0 :         if (rKEvt.GetKeyCode().GetCode() == KEY_DELETE && !rKEvt.GetKeyCode().GetModifier())
    1280             :         {
    1281           0 :             DeleteSelection();
    1282           0 :             return;
    1283             :         }
    1284             : 
    1285             :         // copy'n'paste?
    1286           0 :         switch ( rCode.GetFunction() )
    1287             :         {
    1288             :             case KeyFuncType::CUT:
    1289           0 :                 doCut();
    1290           0 :                 break;
    1291             : 
    1292             :             case KeyFuncType::PASTE:
    1293           0 :                 if ( implAcceptPaste() )
    1294           0 :                     doPaste();
    1295           0 :                 break;
    1296             : 
    1297             :             case KeyFuncType::COPY:
    1298           0 :                 doCopy();
    1299           0 :                 break;
    1300             : 
    1301             :             default:
    1302           0 :                 break;
    1303             :         }
    1304             : 
    1305           0 :         SvTreeListBox::KeyInput(rKEvt);
    1306             :     }
    1307             : 
    1308             : 
    1309           0 :     bool NavigatorTree::EditingEntry( SvTreeListEntry* pEntry, ::Selection& rSelection )
    1310             :     {
    1311           0 :         if (!SvTreeListBox::EditingEntry( pEntry, rSelection ))
    1312           0 :             return false;
    1313             : 
    1314           0 :         return (pEntry && (pEntry->GetUserData() != NULL));
    1315             :             // die Wurzel, die ich nicht umbenennen darf, hat als UserData NULL
    1316             :     }
    1317             : 
    1318             : 
    1319           0 :     void NavigatorTree::NewForm( SvTreeListEntry* pParentEntry )
    1320             :     {
    1321             : 
    1322             :         // ParentFormData holen
    1323           0 :         if( !IsFormEntry(pParentEntry) )
    1324           0 :             return;
    1325             : 
    1326           0 :         FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();
    1327             : 
    1328             : 
    1329             :         // Neue Form erzeugen
    1330           0 :         Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
    1331           0 :         Reference< XForm >  xNewForm(xContext->getServiceManager()->createInstanceWithContext(FM_SUN_COMPONENT_FORM, xContext), UNO_QUERY);
    1332           0 :         if (!xNewForm.is())
    1333           0 :             return;
    1334             : 
    1335           0 :         FmFormData* pNewFormData = new FmFormData( xNewForm, m_aNavigatorImages, pParentFormData );
    1336             : 
    1337             : 
    1338             :         // Namen setzen
    1339           0 :         OUString aName = GenerateName(pNewFormData);
    1340           0 :         pNewFormData->SetText(aName);
    1341             : 
    1342           0 :         Reference< XPropertySet >  xPropertySet(xNewForm, UNO_QUERY);
    1343           0 :         if (!xPropertySet.is())
    1344           0 :             return;
    1345             :         try
    1346             :         {
    1347           0 :             xPropertySet->setPropertyValue( FM_PROP_NAME, makeAny(aName) );
    1348             :             // a form should always have the command type table as default
    1349           0 :             xPropertySet->setPropertyValue( FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE)));
    1350             :         }
    1351           0 :         catch ( const Exception& )
    1352             :         {
    1353             :             OSL_FAIL("NavigatorTree::NewForm : could not set esssential properties !");
    1354             :         }
    1355             : 
    1356             : 
    1357             : 
    1358             :         // Form einfuegen
    1359           0 :         GetNavModel()->Insert( pNewFormData, TREELIST_APPEND, true );
    1360             : 
    1361             : 
    1362             :         // Neue Form als aktive Form setzen
    1363           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1364           0 :         if( pFormShell )
    1365             :         {
    1366           0 :             InterfaceBag aSelection;
    1367           0 :             aSelection.insert( Reference<XInterface>( xNewForm, UNO_QUERY ) );
    1368           0 :             pFormShell->GetImpl()->setCurrentSelection( aSelection );
    1369             : 
    1370           0 :             pFormShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_PROPERTIES, true, true);
    1371             :         }
    1372           0 :         GetNavModel()->SetModified();
    1373             : 
    1374             : 
    1375             :         // In EditMode schalten
    1376           0 :         SvTreeListEntry* pNewEntry = FindEntry( pNewFormData );
    1377           0 :         EditEntry( pNewEntry );
    1378             :     }
    1379             : 
    1380             : 
    1381           0 :     FmControlData* NavigatorTree::NewControl( const OUString& rServiceName, SvTreeListEntry* pParentEntry, bool bEditName )
    1382             :     {
    1383             : 
    1384             :         // ParentForm holen
    1385           0 :         if (!GetNavModel()->GetFormShell())
    1386           0 :             return NULL;
    1387           0 :         if (!IsFormEntry(pParentEntry))
    1388           0 :             return NULL;
    1389             : 
    1390           0 :         FmFormData* pParentFormData = (FmFormData*)pParentEntry->GetUserData();;
    1391           0 :         Reference< XForm >  xParentForm( pParentFormData->GetFormIface());
    1392             : 
    1393             : 
    1394             :         // Neue Component erzeugen
    1395           0 :         Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
    1396           0 :         Reference<XFormComponent> xNewComponent( xContext->getServiceManager()->createInstanceWithContext(rServiceName, xContext), UNO_QUERY);
    1397           0 :         if (!xNewComponent.is())
    1398           0 :             return NULL;
    1399             : 
    1400           0 :         FmControlData* pNewFormControlData = new FmControlData( xNewComponent, m_aNavigatorImages, pParentFormData );
    1401             : 
    1402             : 
    1403             :         // Namen setzen
    1404           0 :         FmFormView*     pFormView       = GetNavModel()->GetFormShell()->GetFormView();
    1405           0 :         SdrPageView*    pPageView       = pFormView->GetSdrPageView();
    1406           0 :         FmFormPage*     pPage           = static_cast<FmFormPage*>(pPageView->GetPage());
    1407             : 
    1408           0 :         OUString sName = pPage->GetImpl().setUniqueName( xNewComponent, xParentForm );
    1409             : 
    1410           0 :         pNewFormControlData->SetText( sName );
    1411             : 
    1412             : 
    1413             :         // FormComponent einfuegen
    1414           0 :         GetNavModel()->Insert( pNewFormControlData, TREELIST_APPEND, true );
    1415           0 :         GetNavModel()->SetModified();
    1416             : 
    1417           0 :         if (bEditName)
    1418             :         {
    1419             : 
    1420             :             // In EditMode schalten
    1421           0 :             SvTreeListEntry* pNewEntry = FindEntry( pNewFormControlData );
    1422           0 :             Select( pNewEntry, true );
    1423           0 :             EditEntry( pNewEntry );
    1424             :         }
    1425             : 
    1426           0 :         return pNewFormControlData;
    1427             :     }
    1428             : 
    1429             : 
    1430           0 :     OUString NavigatorTree::GenerateName( FmEntryData* pEntryData )
    1431             :     {
    1432           0 :         const sal_uInt16 nMaxCount = 99;
    1433           0 :         OUString aNewName;
    1434             : 
    1435             : 
    1436             :         // BasisNamen erzeugen
    1437           0 :         OUString aBaseName;
    1438           0 :         if( pEntryData->ISA(FmFormData) )
    1439           0 :             aBaseName = SVX_RESSTR( RID_STR_STDFORMNAME );
    1440           0 :         else if( pEntryData->ISA(FmControlData) )
    1441           0 :             aBaseName = SVX_RESSTR( RID_STR_CONTROL );
    1442             : 
    1443             : 
    1444             :         // Neuen Namen erstellen
    1445           0 :         FmFormData* pFormParentData = static_cast<FmFormData*>(pEntryData->GetParent());
    1446             : 
    1447           0 :         for( sal_Int32 i=0; i<nMaxCount; i++ )
    1448             :         {
    1449           0 :             aNewName = aBaseName;
    1450           0 :             if( i>0 )
    1451             :             {
    1452           0 :                 aNewName += " ";
    1453           0 :                 aNewName += OUString::number(i).getStr();
    1454             :             }
    1455             : 
    1456           0 :             if( GetNavModel()->FindData(aNewName, pFormParentData,false) == NULL )
    1457           0 :                 break;
    1458             :         }
    1459             : 
    1460           0 :         return aNewName;
    1461             :     }
    1462             : 
    1463             : 
    1464           0 :     bool NavigatorTree::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText )
    1465             :     {
    1466           0 :         if (EditingCanceled())
    1467           0 :             return true;
    1468             : 
    1469           0 :         GrabFocus();
    1470           0 :         FmEntryData* pEntryData = (FmEntryData*)pEntry->GetUserData();
    1471           0 :         bool bRes = GetNavModel()->Rename( pEntryData, rNewText);
    1472           0 :         if( !bRes )
    1473             :         {
    1474           0 :             m_pEditEntry = pEntry;
    1475           0 :             nEditEvent = Application::PostUserEvent( LINK(this, NavigatorTree, OnEdit) );
    1476             :         } else
    1477           0 :             SetCursor(pEntry, true);
    1478             : 
    1479           0 :         return bRes;
    1480             :     }
    1481             : 
    1482             : 
    1483           0 :     IMPL_LINK_NOARG(NavigatorTree, OnEdit)
    1484             :     {
    1485           0 :         nEditEvent = 0;
    1486           0 :         EditEntry( m_pEditEntry );
    1487           0 :         m_pEditEntry = NULL;
    1488             : 
    1489           0 :         return 0L;
    1490             :     }
    1491             : 
    1492             : 
    1493           0 :     IMPL_LINK_NOARG(NavigatorTree, OnDropActionTimer)
    1494             :     {
    1495           0 :         if (--m_aTimerCounter > 0)
    1496           0 :             return 0L;
    1497             : 
    1498           0 :         switch ( m_aDropActionType )
    1499             :         {
    1500             :         case DA_EXPANDNODE:
    1501             :         {
    1502           0 :             SvTreeListEntry* pToExpand = GetEntry(m_aTimerTriggered);
    1503           0 :             if (pToExpand && (GetChildCount(pToExpand) > 0) &&  !IsExpanded(pToExpand))
    1504             :                 // tja, eigentlich muesste ich noch testen, ob die Node nicht schon expandiert ist, aber ich
    1505             :                 // habe dazu weder in den Basisklassen noch im Model eine Methode gefunden ...
    1506             :                 // aber ich denke, die BK sollte es auch so vertragen
    1507           0 :                 Expand(pToExpand);
    1508             : 
    1509             :             // nach dem Expand habe ich im Gegensatz zum Scrollen natuerlich nix mehr zu tun
    1510           0 :             m_aDropActionTimer.Stop();
    1511             :         }
    1512           0 :         break;
    1513             : 
    1514             :         case DA_SCROLLUP :
    1515           0 :             ScrollOutputArea( 1 );
    1516           0 :             m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
    1517           0 :             break;
    1518             : 
    1519             :         case DA_SCROLLDOWN :
    1520           0 :             ScrollOutputArea( -1 );
    1521           0 :             m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
    1522           0 :             break;
    1523             : 
    1524             :         }
    1525             : 
    1526           0 :         return 0L;
    1527             :     }
    1528             : 
    1529             : 
    1530           0 :     IMPL_LINK(NavigatorTree, OnEntrySelDesel, NavigatorTree*, /*pThis*/)
    1531             :     {
    1532           0 :         m_sdiState = SDI_DIRTY;
    1533             : 
    1534           0 :         if (IsSelectionHandlingLocked())
    1535           0 :             return 0L;
    1536             : 
    1537           0 :         if (m_aSynchronizeTimer.IsActive())
    1538           0 :             m_aSynchronizeTimer.Stop();
    1539             : 
    1540           0 :         m_aSynchronizeTimer.SetTimeout(EXPLORER_SYNC_DELAY);
    1541           0 :         m_aSynchronizeTimer.Start();
    1542             : 
    1543           0 :         return 0L;
    1544             :     }
    1545             : 
    1546             : 
    1547           0 :     IMPL_LINK_NOARG(NavigatorTree, OnSynchronizeTimer)
    1548             :     {
    1549           0 :         SynchronizeMarkList();
    1550           0 :         return 0L;
    1551             :     }
    1552             : 
    1553             : 
    1554             : 
    1555           0 :     IMPL_LINK_NOARG(NavigatorTree, OnClipboardAction)
    1556             :     {
    1557           0 :         if ( !m_aControlExchange.isClipboardOwner() )
    1558             :         {
    1559           0 :             if ( doingKeyboardCut() )
    1560             :             {
    1561           0 :                 for (   ListBoxEntrySet::const_iterator i = m_aCutEntries.begin();
    1562           0 :                         i != m_aCutEntries.end();
    1563             :                         ++i
    1564             :                     )
    1565             :                 {
    1566           0 :                     SvTreeListEntry* pEntry = *i;
    1567           0 :                     if ( !pEntry )
    1568           0 :                         continue;
    1569             : 
    1570           0 :                     pEntry->SetFlags( pEntry->GetFlags() & ~SV_ENTRYFLAG_SEMITRANSPARENT );
    1571           0 :                     InvalidateEntry( pEntry );
    1572             :                 }
    1573           0 :                 ListBoxEntrySet aEmpty;
    1574           0 :                 m_aCutEntries.swap( aEmpty );
    1575             : 
    1576           0 :                 m_bKeyboardCut = false;
    1577             :             }
    1578             :         }
    1579           0 :         return 0L;
    1580             :     }
    1581             : 
    1582             : 
    1583           0 :     void NavigatorTree::ShowSelectionProperties(bool bForce)
    1584             :     {
    1585             :         // zuerst brauche ich die FormShell
    1586           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1587           0 :         if (!pFormShell)
    1588             :             // keine Shell -> ich koennte kein curObject setzen -> raus
    1589           0 :             return;
    1590             : 
    1591           0 :         CollectSelectionData(SDI_ALL);
    1592             :         SAL_WARN_IF(static_cast<size_t>(m_nFormsSelected + m_nControlsSelected
    1593             :                 + (m_bRootSelected ? 1 : 0)) != m_arrCurrentSelection.size(),
    1594             :             "svx.form",
    1595             :             "NavigatorTree::ShowSelectionProperties : selection meta data invalid !");
    1596             : 
    1597             : 
    1598           0 :         InterfaceBag aSelection;
    1599           0 :         bool bSetSelectionAsMarkList = false;
    1600             : 
    1601           0 :         if (m_bRootSelected)
    1602             :             ;                                   // no properties for the root, neither for single nor for multi selection
    1603           0 :         else if ( m_nFormsSelected + m_nControlsSelected == 0 )   // none of the two should be less 0
    1604             :             ;                                   // no selection -> no properties
    1605           0 :         else if ( m_nFormsSelected * m_nControlsSelected != 0 )
    1606             :             ;                                   // mixed selection -> no properties
    1607             :         else
    1608             :         {   // either only forms, or only controls are selected
    1609           0 :             if (m_arrCurrentSelection.size() == 1)
    1610             :             {
    1611           0 :                 if (m_nFormsSelected > 0)
    1612             :                 {   // es ist genau eine Form selektiert
    1613           0 :                     FmFormData* pFormData = (FmFormData*)(*m_arrCurrentSelection.begin())->GetUserData();
    1614           0 :                     aSelection.insert( Reference< XInterface >( pFormData->GetFormIface(), UNO_QUERY ) );
    1615             :                 }
    1616             :                 else
    1617             :                 {   // es ist genau ein Control selektiert (egal ob hidden oder normal)
    1618           0 :                     FmEntryData* pEntryData = (FmEntryData*)(*m_arrCurrentSelection.begin())->GetUserData();
    1619             : 
    1620           0 :                     aSelection.insert( Reference< XInterface >( pEntryData->GetElement(), UNO_QUERY ) );
    1621             :                 }
    1622             :             }
    1623             :             else
    1624             :             {   // wir haben eine MultiSelection, also muessen wir ein MultiSet dafuer aufbauen
    1625           0 :                 if (m_nFormsSelected > 0)
    1626             :                 {   // ... nur Forms
    1627             :                     // erstmal die PropertySet-Interfaces der Forms einsammeln
    1628           0 :                    SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
    1629           0 :                     for ( sal_Int32 i = 0; i < m_nFormsSelected; ++i )
    1630             :                     {
    1631           0 :                         FmFormData* pFormData = (FmFormData*)(*it)->GetUserData();
    1632           0 :                         aSelection.insert( pFormData->GetPropertySet().get() );
    1633           0 :                         ++it;
    1634             :                     }
    1635             :                 }
    1636             :                 else
    1637             :                 {   // ... nur Controls
    1638           0 :                     if (m_nHiddenControls == m_nControlsSelected)
    1639             :                     {   // ein MultiSet fuer die Properties der hidden controls
    1640           0 :                         SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
    1641           0 :                         for ( sal_Int32 i = 0; i < m_nHiddenControls; ++i )
    1642             :                         {
    1643           0 :                             FmEntryData* pEntryData = (FmEntryData*)(*it)->GetUserData();
    1644           0 :                             aSelection.insert( pEntryData->GetPropertySet().get() );
    1645           0 :                             ++it;
    1646             :                         }
    1647             :                     }
    1648           0 :                     else if (m_nHiddenControls == 0)
    1649             :                     {   // nur normale Controls
    1650           0 :                         bSetSelectionAsMarkList = true;
    1651             :                     }
    1652             :                 }
    1653             :             }
    1654             : 
    1655             :         }
    1656             : 
    1657             :         // und dann meine Form und mein SelObject
    1658           0 :         if ( bSetSelectionAsMarkList )
    1659           0 :             pFormShell->GetImpl()->setCurrentSelectionFromMark( pFormShell->GetFormView()->GetMarkedObjectList() );
    1660             :         else
    1661           0 :             pFormShell->GetImpl()->setCurrentSelection( aSelection );
    1662             : 
    1663           0 :         if ( pFormShell->GetImpl()->IsPropBrwOpen() || bForce )
    1664             :         {
    1665             :             // und jetzt kann ich das Ganze dem PropertyBrowser uebergeben
    1666           0 :             pFormShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SfxCallMode::ASYNCHRON );
    1667           0 :         }
    1668             :     }
    1669             : 
    1670             : 
    1671           0 :     void NavigatorTree::DeleteSelection()
    1672             :     {
    1673             :         // die Root darf ich natuerlich nicht mitloeschen
    1674           0 :         bool bRootSelected = IsSelected(m_pRootEntry);
    1675           0 :         sal_uIntPtr nSelectedEntries = GetSelectionCount();
    1676           0 :         if (bRootSelected && (nSelectedEntries > 1))     // die Root plus andere Elemente ?
    1677           0 :             Select(m_pRootEntry, false);                // ja -> die Root raus
    1678             : 
    1679           0 :         if ((nSelectedEntries == 0) || bRootSelected)    // immer noch die Root ?
    1680           0 :             return;                                     // -> sie ist das einzige selektierte -> raus
    1681             : 
    1682             :         DBG_ASSERT(!m_bPrevSelectionMixed, "NavigatorTree::DeleteSelection() : loeschen nicht erlaubt wenn Markierung und Selektion nciht konsistent");
    1683             : 
    1684             :         // ich brauche unten das FormModel ...
    1685           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1686           0 :         if (!pFormShell)
    1687           0 :             return;
    1688           0 :         FmFormModel* pFormModel = pFormShell->GetFormModel();
    1689           0 :         if (!pFormModel)
    1690           0 :             return;
    1691             : 
    1692             :         // jetzt muss ich noch die DeleteList etwas absichern : wenn man ein Formular und ein abhaengiges
    1693             :         // Element loescht - und zwar in dieser Reihenfolge - dann ist der SvLBoxEntryPtr des abhaengigen Elementes
    1694             :         // natuerlich schon ungueltig, wenn es geloescht werden soll ... diesen GPF, den es dann mit Sicherheit gibt,
    1695             :         // gilt es zu verhindern, also die 'normalisierte' Liste
    1696           0 :         CollectSelectionData( SDI_NORMALIZED );
    1697             : 
    1698             :         // see below for why we need this mapping from models to shapes
    1699           0 :         FmFormView*     pFormView       = pFormShell->GetFormView();
    1700           0 :         SdrPageView*    pPageView       = pFormView ? pFormView->GetSdrPageView() : NULL;
    1701           0 :         SdrPage*        pPage           = pPageView ? pPageView->GetPage() : NULL;
    1702             :         DBG_ASSERT( pPage, "NavigatorTree::DeleteSelection: invalid form page!" );
    1703             : 
    1704           0 :         MapModelToShape aModelShapes;
    1705           0 :         if ( pPage )
    1706           0 :             collectShapeModelMapping( pPage, aModelShapes );
    1707             : 
    1708             :         // problem: we have to use ExplorerModel::Remove, since only this one properly deletes Form objects.
    1709             :         // But, the controls themself must be deleted via DeleteMarked (else, the Writer has some problems
    1710             :         // somewhere). In case I'd first delete the structure, then the controls, the UNDO would not work
    1711             :         // (since UNDO then would mean to first restore the controls, then the structure, means their parent
    1712             :         // form). The other way round, the EntryDatas would be invalid, if I'd first delete the controls and
    1713             :         // then go on to the strucure. This means I have to delete the forms *after* the normal controls, so
    1714             :         // that during UNDO, they're restored in the proper order.
    1715           0 :         pFormShell->GetImpl()->EnableTrackProperties(false);
    1716           0 :         for (SvLBoxEntrySortedArray::reverse_iterator it = m_arrCurrentSelection.rbegin();
    1717           0 :              it != m_arrCurrentSelection.rend(); )
    1718             :         {
    1719           0 :             FmEntryData* pCurrent = static_cast<FmEntryData*>((*it)->GetUserData());
    1720             : 
    1721             :             // eine Form ?
    1722           0 :             bool bIsForm = pCurrent->ISA(FmFormData);
    1723             : 
    1724             :             // da ich das Loeschen im folgenden der View ueberlasse und dabei auf deren MarkList aufbaue, im Normalfall aber bei
    1725             :             // einem makierten Formular nur die direkt, nicht die indirekt abhaengigen Controls markiert werden, muss ich das hier
    1726             :             // noch nachholen
    1727           0 :             if (bIsForm)
    1728           0 :                 MarkViewObj(static_cast<FmFormData*>(pCurrent), true, true);     // das zweite sal_True heisst "deep"
    1729             : 
    1730             :             // ein hidden control ?
    1731           0 :             bool bIsHidden = IsHiddenControl(pCurrent);
    1732             : 
    1733             :             // Forms und hidden Controls muss ich behalten, alles andere nicht
    1734           0 :             if (!bIsForm && !bIsHidden)
    1735             :             {
    1736             :                 // well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
    1737             :                 // be deleted automatically. This is because for every model (except forms and hidden control models)
    1738             :                 // there exist a shape, which is marked _if_and_only_if_ the model is selected in our tree.
    1739           0 :                 if ( aModelShapes.find( pCurrent->GetElement() ) != aModelShapes.end() )
    1740             :                 {
    1741             :                     // if there's a shape for the current entry, then either it is marked or it is in a
    1742             :                     // hidden layer (#i28502#), or something like this.
    1743             :                     // In the first case, it will be deleted below, in the second case, we currently don't
    1744             :                     // delete it, as there's no real (working!) API for this, neither in UNO nor in non-UNO.
    1745           0 :                     m_arrCurrentSelection.erase( --(it.base()) );
    1746             :                 }
    1747             :                 else
    1748           0 :                    ++it;
    1749             :                 // In case there is no shape for the current entry, we keep the entry in m_arrCurrentSelection,
    1750             :                 // since then we can definitely remove it.
    1751             :                 // #103597#
    1752             :             }
    1753             :             else
    1754           0 :                 ++it;
    1755             :         }
    1756           0 :         pFormShell->GetImpl()->EnableTrackProperties(true);
    1757             : 
    1758             :         // let the view delete the marked controls
    1759           0 :         pFormShell->GetFormView()->DeleteMarked();
    1760             : 
    1761             :         // start UNDO at this point. Unfortunately, this results in 2 UNDO actions, since DeleteMarked is
    1762             :         // creating an own one. However, if we'd move it before DeleteMarked, Writer does not really like
    1763             :         // this ... :(
    1764             :         // #i31038#
    1765             :         {
    1766             : 
    1767             :             // initialize UNDO
    1768           0 :             OUString aUndoStr;
    1769           0 :             if ( m_arrCurrentSelection.size() == 1 )
    1770             :             {
    1771           0 :                 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE);
    1772           0 :                 if (m_nFormsSelected)
    1773           0 :                     aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_FORM ) );
    1774             :                 else
    1775             :                     // it must be a control (else the root would be selected, but it cannot be deleted)
    1776           0 :                     aUndoStr = aUndoStr.replaceFirst( "#", SVX_RESSTR( RID_STR_CONTROL ) );
    1777             :             }
    1778             :             else
    1779             :             {
    1780           0 :                 aUndoStr = SVX_RESSTR(RID_STR_UNDO_CONTAINER_REMOVE_MULTIPLE);
    1781           0 :                 aUndoStr = aUndoStr.replaceFirst( "#", OUString::number( m_arrCurrentSelection.size() ) );
    1782             :             }
    1783           0 :             pFormModel->BegUndo(aUndoStr);
    1784             :         }
    1785             : 
    1786             :         // remove remaining structure
    1787           0 :         for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
    1788           0 :              it != m_arrCurrentSelection.end(); ++it)
    1789             :         {
    1790           0 :             FmEntryData* pCurrent = (FmEntryData*)((*it)->GetUserData());
    1791             : 
    1792             :             // if the entry still has children, we skipped deletion of one of those children.
    1793             :             // This may for instance be because the shape is in a hidden layer, where we're unable
    1794             :             // to remove it
    1795           0 :             if ( pCurrent->GetChildList()->size() )
    1796           0 :                 continue;
    1797             : 
    1798             :             // noch ein kleines Problem, bevor ich das ganz loesche : wenn es eine Form ist und die Shell diese als CurrentObject
    1799             :             // kennt, dann muss ich ihr das natuerlich ausreden
    1800           0 :             if (pCurrent->ISA(FmFormData))
    1801             :             {
    1802           0 :                 Reference< XForm >  xCurrentForm( static_cast< FmFormData* >( pCurrent )->GetFormIface() );
    1803           0 :                 if ( pFormShell->GetImpl()->getCurrentForm() == xCurrentForm )  // die Shell kennt die zu loeschende Form ?
    1804           0 :                     pFormShell->GetImpl()->forgetCurrentForm();                 // -> wegnehmen ...
    1805             :             }
    1806           0 :             GetNavModel()->Remove(pCurrent, true);
    1807             :         }
    1808           0 :         pFormModel->EndUndo();
    1809             :     }
    1810             : 
    1811             : 
    1812           0 :     void NavigatorTree::CollectSelectionData(SELDATA_ITEMS sdiHow)
    1813             :     {
    1814             :         DBG_ASSERT(sdiHow != SDI_DIRTY, "NavigatorTree::CollectSelectionData : ever thought about your parameter ? DIRTY ?");
    1815           0 :         if (sdiHow == m_sdiState)
    1816           0 :             return;
    1817             : 
    1818           0 :         m_arrCurrentSelection.clear();
    1819           0 :         m_nFormsSelected = m_nControlsSelected = m_nHiddenControls = 0;
    1820           0 :         m_bRootSelected = false;
    1821             : 
    1822           0 :         SvTreeListEntry* pSelectionLoop = FirstSelected();
    1823           0 :         while (pSelectionLoop)
    1824             :         {
    1825             :             // erst mal die Zaehlung der verschiedenen Elemente
    1826           0 :             if (pSelectionLoop == m_pRootEntry)
    1827           0 :                 m_bRootSelected = true;
    1828             :             else
    1829             :             {
    1830           0 :                 if (IsFormEntry(pSelectionLoop))
    1831           0 :                     ++m_nFormsSelected;
    1832             :                 else
    1833             :                 {
    1834           0 :                     ++m_nControlsSelected;
    1835           0 :                     if (IsHiddenControl((FmEntryData*)(pSelectionLoop->GetUserData())))
    1836           0 :                         ++m_nHiddenControls;
    1837             :                 }
    1838             :             }
    1839             : 
    1840           0 :             if (sdiHow == SDI_NORMALIZED)
    1841             :             {
    1842             :                 // alles, was schon einen selektierten Vorfahr hat, nicht mitnehmen
    1843           0 :                 if (pSelectionLoop == m_pRootEntry)
    1844           0 :                     m_arrCurrentSelection.insert(pSelectionLoop);
    1845             :                 else
    1846             :                 {
    1847           0 :                     SvTreeListEntry* pParentLoop = GetParent(pSelectionLoop);
    1848           0 :                     while (pParentLoop)
    1849             :                     {
    1850             :                         // eigentlich muesste ich testen, ob das Parent in der m_arrCurrentSelection steht ...
    1851             :                         // Aber wenn es selektiert ist, dann steht es in m_arrCurrentSelection, oder wenigstens einer seiner Vorfahren,
    1852             :                         // wenn der auch schon selektiert war. In beiden Faellen reicht also die Abfrage IsSelected
    1853           0 :                         if (IsSelected(pParentLoop))
    1854           0 :                             break;
    1855             :                         else
    1856             :                         {
    1857           0 :                             if (m_pRootEntry == pParentLoop)
    1858             :                             {
    1859             :                                 // bis (exclusive) zur Root gab es kein selektiertes Parent -> der Eintrag gehoert in die normalisierte Liste
    1860           0 :                                 m_arrCurrentSelection.insert(pSelectionLoop);
    1861           0 :                                 break;
    1862             :                             }
    1863             :                             else
    1864           0 :                                 pParentLoop = GetParent(pParentLoop);
    1865             :                         }
    1866             :                     }
    1867             :                 }
    1868             :             }
    1869           0 :             else if (sdiHow == SDI_NORMALIZED_FORMARK)
    1870             :             {
    1871           0 :                 SvTreeListEntry* pParent = GetParent(pSelectionLoop);
    1872           0 :                 if (!pParent || !IsSelected(pParent) || IsFormEntry(pSelectionLoop))
    1873           0 :                     m_arrCurrentSelection.insert(pSelectionLoop);
    1874             :             }
    1875             :             else
    1876           0 :                 m_arrCurrentSelection.insert(pSelectionLoop);
    1877             : 
    1878             : 
    1879           0 :             pSelectionLoop = NextSelected(pSelectionLoop);
    1880             :         }
    1881             : 
    1882           0 :         m_sdiState = sdiHow;
    1883             :     }
    1884             : 
    1885             : 
    1886           0 :     void NavigatorTree::SynchronizeSelection(FmEntryDataArray& arredToSelect)
    1887             :     {
    1888           0 :         LockSelectionHandling();
    1889           0 :         if (arredToSelect.empty())
    1890             :         {
    1891           0 :             SelectAll(false);
    1892             :         }
    1893             :         else
    1894             :         {
    1895             :             // erst mal gleiche ich meine aktuelle Selektion mit der geforderten SelectList ab
    1896           0 :             SvTreeListEntry* pSelection = FirstSelected();
    1897           0 :             while (pSelection)
    1898             :             {
    1899           0 :                 FmEntryData* pCurrent = (FmEntryData*)pSelection->GetUserData();
    1900           0 :                 if (pCurrent != NULL)
    1901             :                 {
    1902           0 :                     FmEntryDataArray::iterator it = arredToSelect.find(pCurrent);
    1903           0 :                     if ( it != arredToSelect.end() )
    1904             :                     {   // der Entry ist schon selektiert, steht aber auch in der SelectList -> er kann aus letzterer
    1905             :                         // raus
    1906           0 :                         arredToSelect.erase(it);
    1907             :                     } else
    1908             :                     {   // der Entry ist selektiert, aber steht nicht in der SelectList -> Selektion rausnehmen
    1909           0 :                         Select(pSelection, false);
    1910             :                         // und sichtbar machen (kann ja sein, dass das die einzige Modifikation ist, die ich hier in dem
    1911             :                         // ganzen Handler mache, dann sollte das zu sehen sein)
    1912           0 :                         MakeVisible(pSelection);
    1913             :                     }
    1914             :                 }
    1915             :                 else
    1916           0 :                     Select(pSelection, false);
    1917             : 
    1918           0 :                 pSelection = NextSelected(pSelection);
    1919             :             }
    1920             : 
    1921             :             // jetzt habe ich in der SelectList genau die Eintraege, die noch selektiert werden muessen
    1922             :             // zwei Moeglichkeiten : 1) ich gehe durch die SelectList, besorge mir zu jedem Eintrag meinen SvTreeListEntry
    1923             :             // und selektiere diesen (waere irgendwie intuitiver ;)) 2) ich gehe durch alle meine SvLBoxEntries und selektiere
    1924             :             // genau die, die ich in der SelectList finde
    1925             :             // 1) braucht O(k*n) (k=Laenge der SelectList, n=Anzahl meiner Entries), plus den Fakt, dass FindEntry nicht den
    1926             :             // Pointer auf die UserDaten vergleicht, sondern ein aufwendigeres IsEqualWithoutChildren durchfuehrt
    1927             :             // 2) braucht O(n*log k), dupliziert aber etwas Code (naemlich den aus FindEntry)
    1928             :             // da das hier eine relativ oft aufgerufenen Stelle sein koennte (bei jeder Aenderung in der Markierung in der View !),
    1929             :             // nehme ich doch lieber letzteres
    1930           0 :             SvTreeListEntry* pLoop = First();
    1931           0 :             while( pLoop )
    1932             :             {
    1933           0 :                 FmEntryData* pCurEntryData = (FmEntryData*)pLoop->GetUserData();
    1934           0 :                 FmEntryDataArray::iterator it = arredToSelect.find(pCurEntryData);
    1935           0 :                 if ( it != arredToSelect.end() )
    1936             :                 {
    1937           0 :                     Select(pLoop, true);
    1938           0 :                     MakeVisible(pLoop);
    1939           0 :                     SetCursor(pLoop, true);
    1940             :                 }
    1941             : 
    1942           0 :                 pLoop = Next( pLoop );
    1943             :             }
    1944             :         }
    1945           0 :         UnlockSelectionHandling();
    1946           0 :     }
    1947             : 
    1948             : 
    1949           0 :     void NavigatorTree::SynchronizeSelection()
    1950             :     {
    1951             :         // Shell und View
    1952           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1953           0 :         if(!pFormShell) return;
    1954             : 
    1955           0 :         FmFormView* pFormView = pFormShell->GetFormView();
    1956           0 :         if (!pFormView) return;
    1957             : 
    1958           0 :         GetNavModel()->BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
    1959             :     }
    1960             : 
    1961             : 
    1962           0 :     void NavigatorTree::SynchronizeMarkList()
    1963             :     {
    1964             :         // die Shell werde ich brauchen ...
    1965           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    1966           0 :         if (!pFormShell) return;
    1967             : 
    1968           0 :         CollectSelectionData(SDI_NORMALIZED_FORMARK);
    1969             : 
    1970             :         // Die View soll jetzt kein Notify bei einer Aenderung der MarkList rauslassen
    1971           0 :         pFormShell->GetImpl()->EnableTrackProperties(false);
    1972             : 
    1973           0 :         UnmarkAllViewObj();
    1974             : 
    1975           0 :         for (SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
    1976           0 :              it != m_arrCurrentSelection.end(); ++it)
    1977             :         {
    1978           0 :             SvTreeListEntry* pSelectionLoop = *it;
    1979             :             // Bei Formselektion alle Controls dieser Form markieren
    1980           0 :             if (IsFormEntry(pSelectionLoop) && (pSelectionLoop != m_pRootEntry))
    1981           0 :                 MarkViewObj((FmFormData*)pSelectionLoop->GetUserData(), true, false);
    1982             : 
    1983             :             // Bei Controlselektion Control-SdrObjects markieren
    1984           0 :             else if (IsFormComponentEntry(pSelectionLoop))
    1985             :             {
    1986           0 :                 FmControlData* pControlData = (FmControlData*)pSelectionLoop->GetUserData();
    1987           0 :                 if (pControlData)
    1988             :                 {
    1989             : 
    1990             :                     // Beim HiddenControl kann kein Object selektiert werden
    1991           0 :                     Reference< XFormComponent >  xFormComponent( pControlData->GetFormComponent());
    1992           0 :                     if (!xFormComponent.is())
    1993           0 :                         continue;
    1994           0 :                     Reference< XPropertySet >  xSet(xFormComponent, UNO_QUERY);
    1995           0 :                     if (!xSet.is())
    1996           0 :                         continue;
    1997             : 
    1998           0 :                     sal_uInt16 nClassId = ::comphelper::getINT16(xSet->getPropertyValue(FM_PROP_CLASSID));
    1999           0 :                     if (nClassId != FormComponentType::HIDDENCONTROL)
    2000           0 :                         MarkViewObj(pControlData, true, true);
    2001             :                 }
    2002             :             }
    2003             :         }
    2004             : 
    2005             :         // wenn der PropertyBrowser offen ist, muss ich den entsprechend meiner Selektion anpassen
    2006             :         // (NICHT entsprechend der MarkList der View : wenn ich ein Formular selektiert habe, sind in der
    2007             :         // View alle zugehoerigen Controls markiert, trotzdem moechte ich natuerlich die Formular-Eigenschaften
    2008             :         // sehen)
    2009           0 :         ShowSelectionProperties(false);
    2010             : 
    2011             :         // Flag an View wieder zuruecksetzen
    2012           0 :         pFormShell->GetImpl()->EnableTrackProperties(true);
    2013             : 
    2014             :         // wenn jetzt genau eine Form selektiert ist, sollte die Shell das als CurrentForm mitbekommen
    2015             :         // (wenn SelectionHandling nicht locked ist, kuemmert sich die View eigentlich in MarkListHasChanged drum,
    2016             :         // aber der Mechanismus greift zum Beispiel nicht, wenn die Form leer ist)
    2017           0 :         if ((m_arrCurrentSelection.size() == 1) && (m_nFormsSelected == 1))
    2018             :         {
    2019           0 :             FmFormData* pSingleSelectionData = PTR_CAST( FmFormData, static_cast< FmEntryData* >( FirstSelected()->GetUserData() ) );
    2020             :             DBG_ASSERT( pSingleSelectionData, "NavigatorTree::SynchronizeMarkList: invalid selected form!" );
    2021           0 :             if ( pSingleSelectionData )
    2022             :             {
    2023           0 :                 InterfaceBag aSelection;
    2024           0 :                 aSelection.insert( Reference< XInterface >( pSingleSelectionData->GetFormIface(), UNO_QUERY ) );
    2025           0 :                 pFormShell->GetImpl()->setCurrentSelection( aSelection );
    2026             :             }
    2027             :         }
    2028             :     }
    2029             : 
    2030             : 
    2031           0 :     bool NavigatorTree::IsHiddenControl(FmEntryData* pEntryData)
    2032             :     {
    2033           0 :         if (pEntryData == NULL) return false;
    2034             : 
    2035           0 :         Reference< XPropertySet > xProperties( pEntryData->GetPropertySet() );
    2036           0 :         if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
    2037             :         {
    2038           0 :             Any aClassID = xProperties->getPropertyValue( FM_PROP_CLASSID );
    2039           0 :             return (::comphelper::getINT16(aClassID) == FormComponentType::HIDDENCONTROL);
    2040             :         }
    2041           0 :         return false;
    2042             :     }
    2043             : 
    2044             : 
    2045           0 :     bool NavigatorTree::Select( SvTreeListEntry* pEntry, bool bSelect )
    2046             :     {
    2047           0 :         if (bSelect == IsSelected(pEntry))  // das passiert manchmal, ich glaube, die Basisklasse geht zu sehr auf Nummer sicher ;)
    2048           0 :             return true;
    2049             : 
    2050           0 :         return SvTreeListBox::Select(pEntry, bSelect );
    2051             :     }
    2052             : 
    2053             : 
    2054           0 :     void NavigatorTree::UnmarkAllViewObj()
    2055             :     {
    2056           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    2057           0 :         if( !pFormShell )
    2058           0 :             return;
    2059           0 :         FmFormView* pFormView = pFormShell->GetFormView();
    2060           0 :         pFormView->UnMarkAll();
    2061             :     }
    2062             : 
    2063           0 :     void NavigatorTree::MarkViewObj(FmFormData* pFormData, bool bMark, bool bDeep )
    2064             :     {
    2065           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    2066           0 :         if( !pFormShell )
    2067           0 :             return;
    2068             : 
    2069             :         // first collect all sdrobjects
    2070           0 :         ::std::set< Reference< XFormComponent > > aObjects;
    2071           0 :         CollectObjects(pFormData,bDeep,aObjects);
    2072             : 
    2073             : 
    2074             :         // In der Page das entsprechende SdrObj finden und selektieren
    2075           0 :         FmFormView*     pFormView       = pFormShell->GetFormView();
    2076           0 :         SdrPageView*    pPageView       = pFormView->GetSdrPageView();
    2077           0 :         SdrPage*        pPage           = pPageView->GetPage();
    2078             :         //FmFormPage*     pFormPage       = dynamic_cast< FmFormPage* >( pPage );
    2079             : 
    2080           0 :         SdrObjListIter aIter( *pPage );
    2081           0 :         while ( aIter.IsMore() )
    2082             :         {
    2083           0 :             SdrObject* pSdrObject = aIter.Next();
    2084           0 :             FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
    2085           0 :             if ( !pFormObject )
    2086           0 :                 continue;
    2087             : 
    2088           0 :             Reference< XFormComponent > xControlModel( pFormObject->GetUnoControlModel(),UNO_QUERY );
    2089           0 :             if ( xControlModel.is() && aObjects.find(xControlModel) != aObjects.end() && bMark != pFormView->IsObjMarked( pSdrObject ) )
    2090             :             {
    2091             :                 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
    2092           0 :                 pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
    2093             :             }
    2094           0 :         } // while ( aIter.IsMore() )
    2095           0 :         if ( bMark )
    2096             :         {
    2097             :             // make the mark visible
    2098           0 :             ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
    2099           0 :             for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
    2100             :             {
    2101           0 :                 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
    2102           0 :                 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
    2103           0 :                 if ( ( OUTDEV_WINDOW == rOutDev.GetOutDevType() ) && !aMarkRect.IsEmpty() )
    2104             :                 {
    2105           0 :                     pFormView->MakeVisible( aMarkRect, static_cast<vcl::Window&>(rOutDev) );
    2106             :                 }
    2107             :             } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
    2108           0 :         }
    2109             :     }
    2110             : 
    2111           0 :     void NavigatorTree::CollectObjects(FmFormData* pFormData, bool bDeep, ::std::set< Reference< XFormComponent > >& _rObjects)
    2112             :     {
    2113           0 :         FmEntryDataList* pChildList = pFormData->GetChildList();
    2114             :         FmEntryData* pEntryData;
    2115             :         FmControlData* pControlData;
    2116           0 :         for( size_t i = 0; i < pChildList->size(); ++i )
    2117             :         {
    2118           0 :             pEntryData = pChildList->at( i );
    2119           0 :             if( pEntryData->ISA(FmControlData) )
    2120             :             {
    2121           0 :                 pControlData = static_cast<FmControlData*>(pEntryData);
    2122           0 :                 _rObjects.insert(pControlData->GetFormComponent());
    2123             :             } // if( pEntryData->ISA(FmControlData) )
    2124           0 :             else if (bDeep && (pEntryData->ISA(FmFormData)))
    2125           0 :                 CollectObjects(static_cast<FmFormData*>(pEntryData), bDeep, _rObjects);
    2126             :         } // for( sal_uInt32 i=0; i<pChildList->Count(); i++ )
    2127           0 :     }
    2128             : 
    2129           0 :     void NavigatorTree::MarkViewObj( FmControlData* pControlData, bool bMarkHandles, bool bMark)
    2130             :     {
    2131           0 :         if( !pControlData )
    2132           0 :             return;
    2133           0 :         FmFormShell* pFormShell = GetNavModel()->GetFormShell();
    2134           0 :         if( !pFormShell )
    2135           0 :             return;
    2136             : 
    2137             : 
    2138             :         // In der Page das entsprechende SdrObj finden und selektieren
    2139           0 :         FmFormView*     pFormView       = pFormShell->GetFormView();
    2140           0 :         Reference< XFormComponent >  xFormComponent( pControlData->GetFormComponent());
    2141           0 :         SdrPageView*    pPageView       = pFormView->GetSdrPageView();
    2142           0 :         SdrPage*        pPage           = pPageView->GetPage();
    2143             : 
    2144           0 :         bool bPaint = false;
    2145           0 :         SdrObjListIter aIter( *pPage );
    2146           0 :         while ( aIter.IsMore() )
    2147             :         {
    2148           0 :             SdrObject* pSdrObject = aIter.Next();
    2149           0 :             FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
    2150           0 :             if ( !pFormObject )
    2151           0 :                 continue;
    2152             : 
    2153           0 :             Reference< XInterface > xControlModel( pFormObject->GetUnoControlModel() );
    2154           0 :             if ( xControlModel != xFormComponent )
    2155           0 :                 continue;
    2156             : 
    2157             :             // mark the object
    2158           0 :             if ( bMark != pFormView->IsObjMarked( pSdrObject ) )
    2159             :                 // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
    2160           0 :                 pFormView->MarkObj( pSdrObject, pPageView, !bMark, false );
    2161             : 
    2162           0 :             if ( !bMarkHandles || !bMark )
    2163           0 :                 continue;
    2164             : 
    2165           0 :             bPaint = true;
    2166             : 
    2167           0 :         } // while ( aIter.IsMore() )
    2168           0 :         if ( bPaint )
    2169             :         {
    2170             :             // make the mark visible
    2171           0 :             ::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
    2172           0 :             for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
    2173             :             {
    2174           0 :                 SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
    2175           0 :                 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
    2176           0 :                 if ( OUTDEV_WINDOW == rOutDev.GetOutDevType() )
    2177             :                 {
    2178           0 :                     pFormView->MakeVisible( aMarkRect, static_cast<vcl::Window&>(rOutDev) );
    2179             :                 }
    2180             :             } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
    2181           0 :         }
    2182             :     }
    2183             : 
    2184             : 
    2185         651 : }   // namespace svxform
    2186             : 
    2187             : 
    2188             : 
    2189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10