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