Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/form/navigatortree.cxx
Line
Count
Source
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 <memory>
21
#include <svx/dialmgr.hxx>
22
#include <svx/fmshell.hxx>
23
#include <svx/fmmodel.hxx>
24
#include <svx/fmpage.hxx>
25
#include <svx/svdpagv.hxx>
26
#include <svx/svditer.hxx>
27
28
#include <helpids.h>
29
#include <fmexpl.hxx>
30
#include <fmshimp.hxx>
31
#include <fmservs.hxx>
32
#include <fmundo.hxx>
33
#include <fmpgeimp.hxx>
34
#include <fmobj.hxx>
35
#include <fmprop.hxx>
36
#include <sal/log.hxx>
37
#include <vcl/svapp.hxx>
38
#include <sfx2/viewsh.hxx>
39
#include <sfx2/dispatch.hxx>
40
#include <sfx2/viewfrm.hxx>
41
#include <comphelper/processfactory.hxx>
42
#include <comphelper/property.hxx>
43
#include <comphelper/types.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 <com/sun/star/uno/XComponentContext.hpp>
51
#include <svx/sdrpaintwindow.hxx>
52
53
#include <svx/strings.hrc>
54
#include <comphelper/diagnose_ex.hxx>
55
#include <svx/svxids.hrc>
56
#include <bitmaps.hlst>
57
#include <vcl/commandevent.hxx>
58
#include <vcl/weld/Builder.hxx>
59
#include <vcl/weld/Menu.hxx>
60
#include <vcl/weld/weldutils.hxx>
61
62
namespace svxform
63
{
64
0
    #define EXPLORER_SYNC_DELAY                 200
65
        // Time (in ms) until explorer synchronizes the view after select or deselect
66
67
    using namespace ::com::sun::star::uno;
68
    using namespace ::com::sun::star::lang;
69
    using namespace ::com::sun::star::beans;
70
    using namespace ::com::sun::star::form;
71
    using namespace ::com::sun::star::awt;
72
    using namespace ::com::sun::star::container;
73
    using namespace ::com::sun::star::script;
74
    using namespace ::com::sun::star::datatransfer;
75
    using namespace ::com::sun::star::datatransfer::clipboard;
76
    using namespace ::com::sun::star::sdb;
77
78
79
    // helper
80
81
82
    typedef ::std::map< Reference< XInterface >, SdrObject* > MapModelToShape;
83
84
85
    static void    collectShapeModelMapping( SdrPage const * _pPage, MapModelToShape& _rMapping )
86
0
    {
87
0
        OSL_ENSURE( _pPage, "collectShapeModelMapping: invalid arg!" );
88
89
0
        _rMapping.clear();
90
91
0
        SdrObjListIter aIter( _pPage );
92
0
        while ( aIter.IsMore() )
93
0
        {
94
0
            SdrObject* pSdrObject = aIter.Next();
95
0
            FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
96
0
            if ( !pFormObject )
97
0
                continue;
98
99
0
            Reference< XInterface > xNormalizedModel( pFormObject->GetUnoControlModel(), UNO_QUERY );
100
                // note that this is normalized (i.e. queried for XInterface explicitly)
101
102
0
            ::std::pair< MapModelToShape::iterator, bool > aPos =
103
0
                  _rMapping.emplace( xNormalizedModel, pSdrObject );
104
0
            DBG_ASSERT( aPos.second, "collectShapeModelMapping: model was already existent!" );
105
                // if this asserts, this would mean we have 2 shapes pointing to the same model
106
0
        }
107
0
    }
108
109
    NavigatorTreeDropTarget::NavigatorTreeDropTarget(NavigatorTree& rTreeView)
110
0
        : DropTargetHelper(rTreeView.get_widget().get_drop_target())
111
0
        , m_rTreeView(rTreeView)
112
0
    {
113
0
    }
114
115
    sal_Int8 NavigatorTreeDropTarget::AcceptDrop(const AcceptDropEvent& rEvt)
116
0
    {
117
0
        sal_Int8 nAccept = m_rTreeView.AcceptDrop(rEvt);
118
119
0
        if (nAccept != DND_ACTION_NONE)
120
0
        {
121
            // to enable the autoscroll when we're close to the edges
122
0
            weld::TreeView& rWidget = m_rTreeView.get_widget();
123
0
            rWidget.get_dest_row_at_pos(rEvt.maPosPixel, true);
124
0
        }
125
126
0
        return nAccept;
127
0
    }
128
129
    sal_Int8 NavigatorTreeDropTarget::ExecuteDrop(const ExecuteDropEvent& rEvt)
130
0
    {
131
0
        return m_rTreeView.ExecuteDrop(rEvt);
132
0
    }
133
134
    NavigatorTree::NavigatorTree(std::unique_ptr<weld::TreeView> xTreeView)
135
0
        :m_xTreeView(std::move(xTreeView))
136
0
        ,m_aDropTargetHelper(*this)
137
0
        ,m_aSynchronizeTimer("svx NavigatorTree m_aSynchronizeTimer")
138
0
        ,nEditEvent(nullptr)
139
0
        ,m_sdiState(SDI_DIRTY)
140
0
        ,m_nSelectLock(0)
141
0
        ,m_nFormsSelected(0)
142
0
        ,m_nControlsSelected(0)
143
0
        ,m_nHiddenControls(0)
144
0
        ,m_bDragDataDirty(false)
145
0
        ,m_bPrevSelectionMixed(false)
146
0
        ,m_bRootSelected(false)
147
0
        ,m_bInitialUpdate(true)
148
0
        ,m_bKeyboardCut( false )
149
0
        ,m_bEditing( false )
150
0
    {
151
0
        m_xTreeView->set_help_id(HID_FORM_NAVIGATOR);
152
0
        m_xTreeView->set_size_request(200, 200);
153
154
0
        m_xTreeView->set_selection_mode(SelectionMode::Multiple);
155
0
        m_xTreeView->set_column_editables({ true });
156
157
0
        m_pNavModel.reset(new NavigatorTreeModel());
158
0
        Clear();
159
160
0
        StartListening( *m_pNavModel );
161
162
0
        m_aSynchronizeTimer.SetInvokeHandler(LINK(this, NavigatorTree, OnSynchronizeTimer));
163
0
        m_xTreeView->connect_selection_changed(LINK(this, NavigatorTree, OnEntrySelDesel));
164
0
        m_xTreeView->connect_key_press(LINK(this, NavigatorTree, KeyInputHdl));
165
0
        m_xTreeView->connect_command(LINK(this, NavigatorTree, PopupMenuHdl));
166
0
        m_xTreeView->connect_editing(LINK(this, NavigatorTree, EditingEntryHdl),
167
0
                                     LINK(this, NavigatorTree, EditedEntryHdl));
168
0
        m_xTreeView->connect_drag_begin(LINK(this, NavigatorTree, DragBeginHdl));
169
0
    }
170
171
    NavigatorTree::~NavigatorTree()
172
0
    {
173
0
        if( nEditEvent )
174
0
            Application::RemoveUserEvent( nEditEvent );
175
176
0
        if (m_aSynchronizeTimer.IsActive())
177
0
            m_aSynchronizeTimer.Stop();
178
179
0
        DBG_ASSERT(GetNavModel() != nullptr, "NavigatorTree::~NavigatorTree : unexpected : no ExplorerModel");
180
0
        EndListening( *m_pNavModel );
181
0
        Clear();
182
0
        m_pNavModel.reset();
183
0
    }
184
185
    void NavigatorTree::Clear()
186
0
    {
187
0
        m_pNavModel->Clear();
188
0
    }
189
190
    void NavigatorTree::UpdateContent( FmFormShell* pFormShell )
191
0
    {
192
0
        if (m_bInitialUpdate)
193
0
        {
194
0
            GrabFocus();
195
0
            m_bInitialUpdate = false;
196
0
        }
197
198
0
        FmFormShell* pOldShell = GetNavModel()->GetFormShell();
199
0
        FmFormPage* pOldPage = GetNavModel()->GetFormPage();
200
0
        FmFormPage* pNewPage = pFormShell ? pFormShell->GetCurPage() : nullptr;
201
202
0
        if ((pOldShell != pFormShell) || (pOldPage != pNewPage))
203
0
        {
204
            // new shell during editing
205
0
            if (IsEditingActive())
206
0
            {
207
0
                m_xTreeView->end_editing();
208
0
                m_bEditing = false;
209
0
            }
210
211
0
            m_bDragDataDirty = true;    // as a precaution, although I don't drag
212
0
        }
213
0
        GetNavModel()->UpdateContent( pFormShell );
214
215
        // if there is a form, expand root
216
0
        if (m_xRootEntry && !m_xTreeView->get_row_expanded(*m_xRootEntry))
217
0
            m_xTreeView->expand_row(*m_xRootEntry);
218
        // if there is EXACTLY ONE form, expand it too
219
0
        if (m_xRootEntry)
220
0
        {
221
0
            std::unique_ptr<weld::TreeIter> xFirst(m_xTreeView->make_iterator(m_xRootEntry.get()));
222
0
            bool bFirst = m_xTreeView->iter_children(*xFirst);
223
0
            if (bFirst)
224
0
            {
225
0
                std::unique_ptr<weld::TreeIter> xSibling(m_xTreeView->make_iterator(xFirst.get()));
226
0
                if (!m_xTreeView->iter_next_sibling(*xSibling))
227
0
                    m_xTreeView->expand_row(*xFirst);
228
0
            }
229
0
        }
230
0
    }
231
232
    bool NavigatorTree::implAllowExchange( sal_Int8 _nAction, bool* _pHasNonHidden )
233
0
    {
234
0
        if (!m_xTreeView->get_cursor())
235
0
            return false;
236
237
        // Information for AcceptDrop and Execute Drop
238
0
        CollectSelectionData(SDI_ALL);
239
0
        if (m_arrCurrentSelection.empty())
240
            // nothing to do
241
0
            return false;
242
243
        // check whether there are only hidden controls
244
        // I may add a format to pCtrlExch
245
0
        bool bHasNonHidden = std::any_of(m_arrCurrentSelection.begin(), m_arrCurrentSelection.end(),
246
0
            [this](const auto& rEntry) {
247
0
                FmEntryData* pCurrent = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rEntry));
248
0
                return !IsHiddenControl( pCurrent );
249
0
            });
250
251
0
        if ( bHasNonHidden && ( 0 == ( _nAction & DND_ACTION_MOVE ) ) )
252
            // non-hidden controls need to be moved
253
0
            return false;
254
255
0
        if ( _pHasNonHidden )
256
0
            *_pHasNonHidden = bHasNonHidden;
257
258
0
        return true;
259
0
    }
260
261
    bool NavigatorTree::implPrepareExchange( sal_Int8 _nAction )
262
0
    {
263
0
        bool bHasNonHidden = false;
264
0
        if ( !implAllowExchange( _nAction, &bHasNonHidden ) )
265
0
            return false;
266
267
0
        m_aControlExchange.prepareDrag();
268
0
        m_aControlExchange->setFocusEntry(bool(m_xTreeView->get_cursor()));
269
270
0
        for (const auto& rpEntry : m_arrCurrentSelection)
271
0
            m_aControlExchange->addSelectedEntry(m_xTreeView->make_iterator(rpEntry.get()));
272
273
0
        m_aControlExchange->setFormsRoot( GetNavModel()->GetFormPage()->GetForms() );
274
0
        m_aControlExchange->buildPathFormat(m_xTreeView.get(), m_xRootEntry.get());
275
276
0
        if (!bHasNonHidden)
277
0
        {
278
            // create a sequence
279
0
            Sequence< Reference< XInterface > > seqIFaces(m_arrCurrentSelection.size());
280
0
            Reference< XInterface >* pArray = seqIFaces.getArray();
281
0
            for (const auto& rpEntry : m_arrCurrentSelection)
282
0
            {
283
0
                *pArray = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rpEntry))->GetElement();
284
0
                ++pArray;
285
0
            }
286
            // and the new format
287
0
            m_aControlExchange->addHiddenControlsFormat(seqIFaces);
288
0
        }
289
290
0
        m_bDragDataDirty = false;
291
0
        return true;
292
0
    }
293
294
    IMPL_LINK(NavigatorTree, DragBeginHdl, bool&, rUnsetDragIcon, bool)
295
0
    {
296
0
        rUnsetDragIcon = false;
297
298
0
        bool bSuccess = implPrepareExchange(DND_ACTION_COPYMOVE);
299
0
        if (bSuccess)
300
0
        {
301
0
            OControlExchange& rExchange = *m_aControlExchange;
302
0
            rtl::Reference<TransferDataContainer> xHelper(&rExchange);
303
0
            m_xTreeView->enable_drag_source(xHelper, DND_ACTION_COPYMOVE);
304
0
            rExchange.setDragging(true);
305
0
        }
306
0
        return !bSuccess;
307
0
    }
308
309
    IMPL_LINK(NavigatorTree, PopupMenuHdl, const CommandEvent&, rEvt, bool)
310
0
    {
311
0
        bool bHandled = false;
312
0
        switch( rEvt.GetCommand() )
313
0
        {
314
0
            case CommandEventId::ContextMenu:
315
0
            {
316
                // Position of click
317
0
                ::Point ptWhere;
318
0
                if (rEvt.IsMouseEvent())
319
0
                {
320
0
                    ptWhere = rEvt.GetMousePosPixel();
321
0
                    std::unique_ptr<weld::TreeIter> xClickedOn
322
0
                        = m_xTreeView->get_dest_row_at_pos(ptWhere, false);
323
0
                    if (!xClickedOn)
324
0
                        break;
325
0
                    if (!m_xTreeView->is_selected(*xClickedOn))
326
0
                    {
327
0
                        m_xTreeView->unselect_all();
328
0
                        m_xTreeView->select(*xClickedOn);
329
0
                        m_xTreeView->set_cursor(*xClickedOn);
330
0
                    }
331
0
                }
332
0
                else
333
0
                {
334
0
                    if (m_arrCurrentSelection.empty()) // only happens with context menu via keyboard
335
0
                        break;
336
337
0
                    std::unique_ptr<weld::TreeIter> xCurrent = m_xTreeView->get_cursor();
338
0
                    if (!xCurrent)
339
0
                        break;
340
0
                    ptWhere = m_xTreeView->get_row_area(*xCurrent).Center();
341
0
                }
342
343
                // update my selection data
344
0
                CollectSelectionData(SDI_ALL);
345
346
                // if there is at least one no-root-entry and the root selected, I deselect root
347
0
                if ( (m_arrCurrentSelection.size() > 1) && m_bRootSelected )
348
0
                {
349
0
                    const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
350
0
                    m_xTreeView->set_cursor(*rIter);
351
0
                    m_xTreeView->unselect(*m_xRootEntry);
352
0
                }
353
0
                bool bSingleSelection = (m_arrCurrentSelection.size() == 1);
354
355
356
0
                DBG_ASSERT( (!m_arrCurrentSelection.empty()) || m_bRootSelected, "no entries selected" );
357
                    // shouldn't happen, because I would have selected one during call to IsSelected,
358
                    // if there was none before
359
360
361
                // create menu
362
0
                FmFormShell* pFormShell = GetNavModel()->GetFormShell();
363
0
                FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : nullptr;
364
0
                if( pFormShell && pFormModel )
365
0
                {
366
0
                    std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xTreeView.get(), u"svx/ui/formnavimenu.ui"_ustr));
367
0
                    std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu(u"menu"_ustr));
368
0
                    std::unique_ptr<weld::Menu> xSubMenuNew(xBuilder->weld_menu(u"submenu"_ustr));
369
370
                    // menu 'New' only exists, if only the root or only one form is selected
371
0
                    bool bShowNew = bSingleSelection && (m_nFormsSelected || m_bRootSelected);
372
0
                    if (!bShowNew)
373
0
                        xContextMenu->remove(u"new"_ustr);
374
375
                    // 'New'\'Form' under the same terms
376
0
                    bool bShowForm = bSingleSelection && (m_nFormsSelected || m_bRootSelected);
377
0
                    if (bShowForm)
378
0
                        xSubMenuNew->append(u"form"_ustr, SvxResId(RID_STR_FORM), RID_SVXBMP_FORM);
379
380
                    // 'New'\'hidden...', if exactly one form is selected
381
0
                    bool bShowHidden = bSingleSelection && m_nFormsSelected;
382
0
                    if (bShowHidden)
383
0
                        xSubMenuNew->append(u"hidden"_ustr, SvxResId(RID_STR_HIDDEN), RID_SVXBMP_HIDDEN);
384
385
                    // 'Delete': everything which is not root can be removed
386
0
                    if (m_bRootSelected)
387
0
                        xContextMenu->remove(u"delete"_ustr);
388
389
                    // 'Cut', 'Copy' and 'Paste'
390
0
                    bool bShowCut = !m_bRootSelected && implAllowExchange(DND_ACTION_MOVE);
391
0
                    if (!bShowCut)
392
0
                        xContextMenu->remove(u"cut"_ustr);
393
0
                    bool bShowCopy = !m_bRootSelected && implAllowExchange(DND_ACTION_COPY);
394
0
                    if (!bShowCopy)
395
0
                        xContextMenu->remove(u"copy"_ustr);
396
0
                    if (!implAcceptPaste())
397
0
                        xContextMenu->remove(u"paste"_ustr);
398
399
                    // TabDialog, if exactly one form
400
0
                    bool bShowTabOrder = bSingleSelection && m_nFormsSelected;
401
0
                    if (!bShowTabOrder)
402
0
                        xContextMenu->remove(u"taborder"_ustr);
403
404
0
                    bool bShowProps = true;
405
                    // in XML forms, we don't allow for the properties of a form
406
                    // #i36484#
407
0
                    if (pFormShell->GetImpl()->isEnhancedForm_Lock() && !m_nControlsSelected)
408
0
                        bShowProps = false;
409
                    // if the property browser is already open, we don't allow for the properties, too
410
0
                    if (pFormShell->GetImpl()->IsPropBrwOpen_Lock())
411
0
                        bShowProps = false;
412
413
                    // and finally, if there's a mixed selection of forms and controls, disable the entry, too
414
0
                    if (bShowProps && !pFormShell->GetImpl()->IsPropBrwOpen_Lock())
415
0
                        bShowProps =
416
0
                            (m_nControlsSelected && !m_nFormsSelected) || (!m_nControlsSelected && m_nFormsSelected);
417
418
0
                    if (!bShowProps)
419
0
                        xContextMenu->remove(u"props"_ustr);
420
421
                    // rename, if one element and no root
422
0
                    bool bShowRename = bSingleSelection && !m_bRootSelected;
423
0
                    if (!bShowRename)
424
0
                        xContextMenu->remove(u"rename"_ustr);
425
426
0
                    if (!m_bRootSelected)
427
0
                    {
428
                        // Readonly-entry is only for root
429
0
                        xContextMenu->remove(u"designmode"_ustr);
430
                        // the same for automatic control focus
431
0
                        xContextMenu->remove(u"controlfocus"_ustr);
432
0
                    }
433
434
0
                    std::unique_ptr<weld::Menu> xConversionMenu(xBuilder->weld_menu(u"changemenu"_ustr));
435
                    // ConvertTo-Slots are enabled, if one control is selected
436
                    // the corresponding slot is disabled
437
0
                    if (!m_bRootSelected && !m_nFormsSelected && (m_nControlsSelected == 1))
438
0
                    {
439
0
                        FmXFormShell::GetConversionMenu_Lock(*xConversionMenu);
440
#if OSL_DEBUG_LEVEL > 0
441
                        const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
442
                        FmControlData* pCurrent = weld::fromId<FmControlData*>(m_xTreeView->get_id(*rIter));
443
                        OSL_ENSURE( pFormShell->GetImpl()->isSolelySelected_Lock( pCurrent->GetFormComponent() ),
444
                            "NavigatorTree::Command: inconsistency between the navigator selection, and the selection as the shell knows it!" );
445
#endif
446
447
0
                        pFormShell->GetImpl()->checkControlConversionSlotsForCurrentSelection_Lock(*xConversionMenu);
448
0
                    }
449
0
                    else
450
0
                        xContextMenu->remove(u"change"_ustr);
451
452
0
                    if (m_bRootSelected)
453
0
                    {
454
                        // set OpenReadOnly
455
0
                        xContextMenu->set_active(u"designmode"_ustr, pFormModel->GetOpenInDesignMode());
456
0
                        xContextMenu->set_active(u"controlfocus"_ustr, pFormModel->GetAutoControlFocus());
457
0
                    }
458
459
0
                    OUString sIdent = xContextMenu->popup_at_rect(m_xTreeView.get(), tools::Rectangle(ptWhere, ::Size(1, 1)));
460
0
                    if (sIdent == "form")
461
0
                    {
462
0
                        OUString aStr(SvxResId(RID_STR_FORM));
463
0
                        OUString aUndoStr = SvxResId(RID_STR_UNDO_CONTAINER_INSERT).replaceAll("#", aStr);
464
465
0
                        pFormModel->BegUndo(aUndoStr);
466
                        // slot was only available, if there is only one selected entry,
467
                        // which is a root or a form
468
0
                        const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
469
0
                        NewForm(*rIter);
470
0
                        pFormModel->EndUndo();
471
0
                    }
472
0
                    else if (sIdent == "hidden")
473
0
                    {
474
0
                        OUString aStr(SvxResId(RID_STR_CONTROL));
475
0
                        OUString aUndoStr = SvxResId(RID_STR_UNDO_CONTAINER_INSERT).replaceAll("#", aStr);
476
477
0
                        pFormModel->BegUndo(aUndoStr);
478
                        // slot was valid for (exactly) one selected form
479
0
                        const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
480
0
                        NewControl(FM_COMPONENT_HIDDEN, *rIter, true);
481
0
                        pFormModel->EndUndo();
482
0
                    }
483
0
                    else if (sIdent == "cut")
484
0
                        doCut();
485
0
                    else if (sIdent == "copy")
486
0
                        doCopy();
487
0
                    else if (sIdent == "paste")
488
0
                        doPaste();
489
0
                    else if (sIdent == "delete")
490
0
                        DeleteSelection();
491
0
                    else if (sIdent == "taborder")
492
0
                    {
493
                        // this slot was effective for exactly one selected form
494
0
                        const std::unique_ptr<weld::TreeIter>& rSelectedForm = *m_arrCurrentSelection.begin();
495
0
                        DBG_ASSERT( IsFormEntry(*rSelectedForm), "NavigatorTree::Command: This entry must be a FormEntry." );
496
497
0
                        FmFormData* pFormData = weld::fromId<FmFormData*>(m_xTreeView->get_id(*rSelectedForm));
498
0
                        const Reference< XForm >&  xForm(  pFormData->GetFormIface());
499
500
0
                        Reference< XTabControllerModel >  xTabController(xForm, UNO_QUERY);
501
0
                        if( !xTabController.is() )
502
0
                            break;
503
0
                        GetNavModel()->GetFormShell()->GetImpl()->ExecuteTabOrderDialog_Lock(xTabController);
504
0
                    }
505
0
                    else if (sIdent == "props")
506
0
                        ShowSelectionProperties(true);
507
0
                    else if (sIdent == "rename")
508
0
                    {
509
                        // only allowed for one no-root-entry
510
0
                        const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
511
0
                        m_xTreeView->start_editing(*rIter);
512
0
                        m_bEditing = true;
513
0
                    }
514
0
                    else if (sIdent == "designmode")
515
0
                    {
516
0
                        pFormModel->SetOpenInDesignMode( !pFormModel->GetOpenInDesignMode() );
517
0
                        pFormShell->GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_OPEN_READONLY);
518
0
                    }
519
0
                    else if (sIdent == "controlfocus")
520
0
                    {
521
0
                        pFormModel->SetAutoControlFocus( !pFormModel->GetAutoControlFocus() );
522
0
                        pFormShell->GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_AUTOCONTROLFOCUS);
523
0
                    }
524
0
                    else if (FmXFormShell::isControlConversionSlot(sIdent))
525
0
                    {
526
0
                        const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
527
0
                        FmControlData* pCurrent = weld::fromId<FmControlData*>(m_xTreeView->get_id(*rIter));
528
0
                        if (pFormShell->GetImpl()->executeControlConversionSlot_Lock(pCurrent->GetFormComponent(), sIdent))
529
0
                            ShowSelectionProperties();
530
0
                    }
531
0
                }
532
0
                bHandled = true;
533
0
            }
534
0
            break;
535
0
            default: break;
536
0
        }
537
538
0
        return bHandled;
539
0
    }
540
541
    std::unique_ptr<weld::TreeIter> NavigatorTree::FindEntry(FmEntryData* pEntryData)
542
0
    {
543
0
        std::unique_ptr<weld::TreeIter> xRet;
544
0
        if(!pEntryData)
545
0
            return xRet;
546
547
0
        m_xTreeView->all_foreach([this, pEntryData, &xRet](weld::TreeIter& rEntry){
548
0
            FmEntryData* pCurEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rEntry));
549
0
            if (pCurEntryData && pCurEntryData->IsEqualWithoutChildren(pEntryData))
550
0
            {
551
0
                xRet = m_xTreeView->make_iterator(&rEntry);
552
0
                return true;
553
0
            }
554
0
            return false;
555
0
        });
556
557
0
        return xRet;
558
0
    }
559
560
    void NavigatorTree::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
561
0
    {
562
0
        if( rHint.GetId() == SfxHintId::FmNavRemoved )
563
0
        {
564
0
            auto pRemovedHint = static_cast<const FmNavRemovedHint*>(&rHint);
565
0
            FmEntryData* pEntryData = pRemovedHint->GetEntryData();
566
0
            Remove( pEntryData );
567
0
        }
568
0
        else if( rHint.GetId() == SfxHintId::FmNavInserted )
569
0
        {
570
0
            auto pInsertedHint = static_cast<const FmNavInsertedHint*>(&rHint);
571
0
            FmEntryData* pEntryData = pInsertedHint->GetEntryData();
572
0
            sal_uInt32 nRelPos = pInsertedHint->GetRelPos();
573
0
            Insert( pEntryData, nRelPos );
574
0
        }
575
0
        else if( rHint.GetId() == SfxHintId::FmNavModelReplaced )
576
0
        {
577
0
            auto pReplacedHint = static_cast<const FmNavModelReplacedHint*>(&rHint);
578
0
            FmEntryData* pData = pReplacedHint->GetEntryData();
579
0
            std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pData);
580
0
            if (xEntry)
581
0
            {
582
                // reset image
583
0
                m_xTreeView->set_image(*xEntry, pData->GetNormalImage());
584
0
            }
585
0
        }
586
0
        else if( rHint.GetId() == SfxHintId::FmNavNameChanged )
587
0
        {
588
0
            auto pNameChangedHint = static_cast<const FmNavNameChangedHint*>(&rHint);
589
0
            std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pNameChangedHint->GetEntryData());
590
0
            if (xEntry)
591
0
                m_xTreeView->set_text(*xEntry, pNameChangedHint->GetNewName());
592
0
        }
593
0
        else if( rHint.GetId() == SfxHintId::FmNavCleared )
594
0
        {
595
0
            m_aCutEntries.clear();
596
0
            if (m_aControlExchange.isDataExchangeActive())
597
0
                m_aControlExchange.clear();
598
0
            m_xTreeView->clear();
599
600
            // default-entry "Forms"
601
0
            OUString sText(SvxResId(RID_STR_FORMS));
602
0
            m_xRootEntry = m_xTreeView->make_iterator();
603
0
            m_xTreeView->insert(nullptr, -1, &sText, nullptr, nullptr, nullptr,
604
0
                                false, m_xRootEntry.get());
605
0
            m_xTreeView->set_image(*m_xRootEntry, RID_SVXBMP_FORMS);
606
0
            m_xTreeView->set_sensitive(*m_xRootEntry, true);
607
0
        }
608
0
        else if (rHint.GetId() == SfxHintId::FmNavRequestSelect)
609
0
        {
610
0
            auto pSelectHint = static_cast<const FmNavRequestSelectHint*>(&rHint);
611
0
            FmEntryDataArray& arredToSelect = const_cast<FmNavRequestSelectHint*>(pSelectHint)->GetItems();
612
0
            SynchronizeSelection(arredToSelect);
613
614
0
            if (pSelectHint->IsMixedSelection())
615
                // in this case I deselect all, although the view had a mixed selection
616
                // during next selection, I must adapt the navigator to the view
617
0
                m_bPrevSelectionMixed = true;
618
0
        }
619
0
    }
620
621
    std::unique_ptr<weld::TreeIter> NavigatorTree::Insert(const FmEntryData* pEntryData, int nRelPos)
622
0
    {
623
        // insert current entry
624
0
        std::unique_ptr<weld::TreeIter> xParentEntry = FindEntry( pEntryData->GetParent() );
625
0
        std::unique_ptr<weld::TreeIter> xNewEntry(m_xTreeView->make_iterator());
626
0
        OUString sId(weld::toId(pEntryData));
627
628
0
        if(!xParentEntry)
629
0
        {
630
0
            m_xTreeView->insert(m_xRootEntry.get(), nRelPos, &pEntryData->GetText(), &sId,
631
0
                                nullptr, nullptr, false, xNewEntry.get());
632
0
        }
633
0
        else
634
0
        {
635
0
            m_xTreeView->insert(xParentEntry.get(), nRelPos, &pEntryData->GetText(), &sId,
636
0
                                nullptr, nullptr, false, xNewEntry.get());
637
0
        }
638
639
0
        m_xTreeView->set_image(*xNewEntry, pEntryData->GetNormalImage());
640
0
        m_xTreeView->set_sensitive(*xNewEntry, true);
641
642
        // If root-entry, expand root
643
0
        if (!xParentEntry)
644
0
            m_xTreeView->expand_row(*m_xRootEntry);
645
646
        // insert children
647
0
        FmEntryDataList* pChildList = pEntryData->GetChildList();
648
0
        size_t nChildCount = pChildList->size();
649
0
        for( size_t i = 0; i < nChildCount; i++ )
650
0
        {
651
0
            FmEntryData* pChildData = pChildList->at( i );
652
0
            Insert(pChildData, -1);
653
0
        }
654
655
0
        return xNewEntry;
656
0
    }
657
658
    void NavigatorTree::Remove( FmEntryData* pEntryData )
659
0
    {
660
0
        if( !pEntryData )
661
0
            return;
662
663
        // entry for the data
664
0
        std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pEntryData);
665
0
        if (!xEntry)
666
0
            return;
667
668
        // delete entry from TreeListBox
669
        // I'm not allowed, to treat the selection, which I trigger:
670
        // select changes the MarkList of the view, if somebody else does this at the same time
671
        // and removes a selection, we get a problem
672
        // e.g. Group controls with open navigator
673
0
        LockSelectionHandling();
674
675
        // little problem: I remember the selected data, but if somebody deletes one of these entries,
676
        // I get inconsistent... this would be bad
677
0
        m_xTreeView->unselect(*xEntry);
678
679
        // selection can be modified during deletion,
680
        // but because I disabled SelectionHandling, I have to do it later
681
0
        auto nExpectedSelectionCount = m_xTreeView->count_selected_rows();
682
683
0
        ModelHasRemoved(xEntry.get());
684
0
        m_xTreeView->remove(*xEntry);
685
686
0
        if (nExpectedSelectionCount != m_xTreeView->count_selected_rows())
687
0
            SynchronizeSelection();
688
689
        // by default I treat the selection of course
690
0
        UnlockSelectionHandling();
691
0
    }
692
693
    bool NavigatorTree::IsFormEntry(const weld::TreeIter& rEntry)
694
0
    {
695
0
        FmEntryData* pEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rEntry));
696
0
        return !pEntryData || dynamic_cast<const FmFormData*>( pEntryData) !=  nullptr;
697
0
    }
698
699
    bool NavigatorTree::IsFormComponentEntry(const weld::TreeIter& rEntry)
700
0
    {
701
0
        FmEntryData* pEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rEntry));
702
0
        return dynamic_cast<const FmControlData*>( pEntryData) != nullptr;
703
0
    }
704
705
    bool NavigatorTree::implAcceptPaste( )
706
0
    {
707
0
        auto nSelectedEntries = m_xTreeView->count_selected_rows();
708
0
        if (nSelectedEntries != 1)
709
            // no selected entry, or at least two selected entries
710
0
            return false;
711
712
        // get the clipboard
713
0
        TransferableDataHelper aClipboardContent(TransferableDataHelper::CreateFromClipboard(m_xTreeView->get_clipboard()));
714
715
0
        sal_Int8 nAction = m_aControlExchange.isClipboardOwner() && doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY;
716
0
        std::unique_ptr<weld::TreeIter> xSelected = m_xTreeView->get_selected();
717
0
        return nAction == implAcceptDataTransfer(aClipboardContent.GetDataFlavorExVector(), nAction, xSelected.get(), false);
718
0
    }
719
720
    sal_Int8 NavigatorTree::implAcceptDataTransfer( const DataFlavorExVector& _rFlavors, sal_Int8 _nAction, const weld::TreeIter* _pTargetEntry, bool _bDnD )
721
0
    {
722
        // no target -> no drop
723
0
        if (!_pTargetEntry)
724
0
            return DND_ACTION_NONE;
725
726
        // format check
727
0
        bool bHasDefControlFormat = OControlExchange::hasFieldExchangeFormat( _rFlavors );
728
0
        bool bHasControlPathFormat = OControlExchange::hasControlPathFormat( _rFlavors );
729
0
        bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( _rFlavors );
730
0
        if (!bHasDefControlFormat && !bHasControlPathFormat && !bHasHiddenControlsFormat)
731
0
            return DND_ACTION_NONE;
732
733
0
        bool bSelfSource = _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner();
734
735
0
        if ( bHasHiddenControlsFormat )
736
0
        {   // bHasHiddenControlsFormat means that only hidden controls are part of the data
737
738
            // hidden controls can be copied to a form only
739
0
            if (_pTargetEntry->equal(*m_xRootEntry) || !IsFormEntry(*_pTargetEntry))
740
0
                return DND_ACTION_NONE;
741
742
0
            return bSelfSource ? ( DND_ACTION_COPYMOVE & _nAction ) : DND_ACTION_COPY;
743
0
        }
744
745
0
        if  ( !bSelfSource )
746
0
        {
747
            // DnD or CnP crossing navigator boundaries
748
            // The main problem here is that the current API does not allow us to sneak into the content which
749
            // is to be inserted. So we have to allow it for the moment, but maybe reject later on (in the real drop).
750
751
            // TODO: this smart behaviour later on ... at the moment, we disallow data transfer crossing navigator
752
            // boundaries.
753
754
0
            return DND_ACTION_NONE;
755
0
        }
756
757
0
        DBG_ASSERT( _bDnD ? m_aControlExchange.isDragSource() : m_aControlExchange.isClipboardOwner(),
758
0
            "NavigatorTree::implAcceptDataTransfer: here only with source=dest!" );
759
            // somebody changed the logic of this method ...
760
761
        // from here on, I can work with m_aControlExchange instead of _rData!
762
763
0
        bool bForeignCollection = m_aControlExchange->getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
764
0
        if ( bForeignCollection )
765
0
        {
766
            // crossing shell/page boundaries, we can exchange hidden controls only
767
            // But if we survived the checks above, we do not have hidden controls.
768
            // -> no data transfer
769
0
            DBG_ASSERT( !bHasHiddenControlsFormat, "NavigatorTree::implAcceptDataTransfer: still hidden controls format!" );
770
                // somebody changed the logic of this method ...
771
772
0
            return DND_ACTION_COPY;
773
0
        }
774
775
0
        if (DND_ACTION_MOVE != _nAction) // 'normal' controls within a shell are moved only (never copied)
776
0
            return DND_ACTION_NONE;
777
778
0
        if ( m_bDragDataDirty || !bHasDefControlFormat )
779
0
        {
780
0
            if (!bHasControlPathFormat)
781
                // I am in the shell/page, which has the controls, but I have no format,
782
                // which survived the shell change (SVX_FM_CONTROLS_AS_PATH)
783
0
                return DND_ACTION_NONE;
784
785
            // I must recreate the list of the ExchangeObjects, because the shell was changed during dragging
786
            // (there are SvLBoxEntries in it, and we lost them during change)
787
0
            m_aControlExchange->buildListFromPath(m_xTreeView.get(), m_xRootEntry.get());
788
0
            m_bDragDataDirty = false;
789
0
        }
790
791
        // List of dropped entries from DragServer
792
0
        const ListBoxEntrySet& rDropped = m_aControlExchange->selected();
793
0
        DBG_ASSERT(!rDropped.empty(), "NavigatorTree::implAcceptDataTransfer: no entries !");
794
795
0
        bool bDropTargetIsComponent = IsFormComponentEntry( *_pTargetEntry );
796
797
        // conditions to disallow the drop
798
        // 0) the root entry is part of the list (can't DnD the root!)
799
        // 1) one of the dragged entries is to be dropped onto its own parent
800
        // 2) -               "       - is to be dropped onto itself
801
        // 3) -               "       - is a Form and to be dropped onto one of its descendants
802
        // 4) one of the entries is a control and to be dropped onto the root
803
        // 5) a control or form will be dropped onto a control which is _not_ a sibling (dropping onto a sibling
804
        //      means moving the control)
805
806
        // collect the ancestors of the drop target (speeds up 3)
807
0
        SvLBoxEntrySortedArray arrDropAncestors;
808
0
        std::unique_ptr<weld::TreeIter> xLoop(m_xTreeView->make_iterator(_pTargetEntry));
809
0
        do
810
0
        {
811
0
            arrDropAncestors.emplace(m_xTreeView->make_iterator(xLoop.get()));
812
0
        }
813
0
        while (m_xTreeView->iter_parent(*xLoop));
814
815
0
        for (const auto& rCurrent : rDropped)
816
0
        {
817
            // test for 0)
818
0
            if (rCurrent->equal(*m_xRootEntry))
819
0
                return DND_ACTION_NONE;
820
821
0
            std::unique_ptr<weld::TreeIter> xCurrentParent(m_xTreeView->make_iterator(rCurrent.get()));
822
0
            m_xTreeView->iter_parent(*xCurrentParent);
823
824
            // test for 1)
825
0
            if (_pTargetEntry->equal(*xCurrentParent))
826
0
                return DND_ACTION_NONE;
827
828
            // test for 2)
829
0
            if (rCurrent->equal(*_pTargetEntry))
830
0
                return DND_ACTION_NONE;
831
832
            // test for 5)
833
0
            if (bDropTargetIsComponent)
834
0
                return DND_ACTION_NONE;
835
836
            // test for 3)
837
0
            if (IsFormEntry(*rCurrent))
838
0
            {
839
0
                auto aIter = std::find_if(arrDropAncestors.begin(), arrDropAncestors.end(),
840
0
                                          [&rCurrent](const auto& rElem) {
841
0
                                            return rElem->equal(*rCurrent);
842
0
                                          });
843
844
0
                if ( aIter != arrDropAncestors.end() )
845
0
                    return DND_ACTION_NONE;
846
0
            }
847
0
            else if (IsFormComponentEntry(*rCurrent))
848
0
            {
849
                // test for 4)
850
0
                if (_pTargetEntry->equal(*m_xRootEntry))
851
0
                    return DND_ACTION_NONE;
852
0
            }
853
0
        }
854
0
        return DND_ACTION_MOVE;
855
0
    }
856
857
    sal_Int8 NavigatorTree::AcceptDrop( const AcceptDropEvent& rEvt )
858
0
    {
859
0
        ::Point aDropPos = rEvt.maPosPixel;
860
        // get_dest_row_at_pos with false cause we must drop exactly "on" a form to paste a control into it
861
0
        std::unique_ptr<weld::TreeIter> xDropTarget
862
0
            = m_xTreeView->get_dest_row_at_pos(aDropPos, false);
863
0
        return implAcceptDataTransfer(m_aDropTargetHelper.GetDataFlavorExVector(), rEvt.mnAction, xDropTarget.get(), true);
864
0
    }
865
866
    sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const ::Point& _rDropPos, bool _bDnD )
867
0
    {
868
        // get_dest_row_at_pos with false cause we must drop exactly "on" a form to paste a control into it
869
0
        std::unique_ptr<weld::TreeIter> xDrop = m_xTreeView->get_dest_row_at_pos(_rDropPos, false);
870
0
        return implExecuteDataTransfer( _rData, _nAction, xDrop.get(), _bDnD );
871
0
    }
872
873
    sal_Int8 NavigatorTree::implExecuteDataTransfer( const OControlTransferData& _rData, sal_Int8 _nAction, const weld::TreeIter* _pTargetEntry, bool _bDnD )
874
0
    {
875
0
        const DataFlavorExVector& rDataFlavors = _rData.GetDataFlavorExVector();
876
877
0
        if ( DND_ACTION_NONE == implAcceptDataTransfer( rDataFlavors, _nAction, _pTargetEntry, _bDnD ) )
878
            // under some platforms, it may happen that ExecuteDrop is called though AcceptDrop returned DND_ACTION_NONE
879
0
            return DND_ACTION_NONE;
880
881
0
        if (!_pTargetEntry)
882
            // no target -> no drop
883
0
            return DND_ACTION_NONE;
884
885
        // format checks
886
#ifdef DBG_UTIL
887
        bool bHasHiddenControlsFormat = OControlExchange::hasHiddenControlModelsFormat( rDataFlavors );
888
        bool bForeignCollection = _rData.getFormsRoot().get() != GetNavModel()->GetFormPage()->GetForms().get();
889
        DBG_ASSERT(!bForeignCollection || bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: invalid format (AcceptDrop shouldn't have let this pass) !");
890
        DBG_ASSERT(bForeignCollection || !m_bDragDataDirty, "NavigatorTree::implExecuteDataTransfer: invalid state (shell changed since last exchange resync) !");
891
            // this should be done in AcceptDrop: the list of controls is created in _rData
892
            // and m_bDragDataDirty is reset
893
#endif
894
895
0
        if ( DND_ACTION_COPY == _nAction )
896
0
        {   // bHasHiddenControlsFormat means that only hidden controls are part of the data
897
#ifdef DBG_UTIL
898
            DBG_ASSERT( bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: copy allowed for hidden controls only!" );
899
#endif
900
0
            DBG_ASSERT( _pTargetEntry && !_pTargetEntry->equal(*m_xRootEntry) && IsFormEntry( *_pTargetEntry ),
901
0
                "NavigatorTree::implExecuteDataTransfer: should not be here!" );
902
                // implAcceptDataTransfer should have caught both cases
903
904
#ifdef DBG_UTIL
905
            DBG_ASSERT(bHasHiddenControlsFormat, "NavigatorTree::implExecuteDataTransfer: only copying of hidden controls is supported !");
906
                // should be caught by AcceptDrop
907
#endif
908
909
            // because i want to select all targets (and only them)
910
0
            m_xTreeView->unselect_all();
911
912
0
            const Sequence< Reference< XInterface > >& aControls = _rData.hiddenControls();
913
0
            sal_Int32 nCount = aControls.getLength();
914
0
            const Reference< XInterface >* pControls = aControls.getConstArray();
915
916
0
            FmFormShell* pFormShell = GetNavModel()->GetFormShell();
917
0
            FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : nullptr;
918
919
            // within undo
920
0
            if (pFormModel)
921
0
            {
922
0
                OUString aStr(SvxResId(RID_STR_CONTROL));
923
0
                OUString aUndoStr = SvxResId(RID_STR_UNDO_CONTAINER_INSERT).replaceAll("#", aStr);
924
0
                pFormModel->BegUndo(aUndoStr);
925
0
            }
926
927
            // copy controls
928
0
            for (sal_Int32 i=0; i<nCount; ++i)
929
0
            {
930
                // create new control
931
0
                FmControlData* pNewControlData = NewControl( FM_COMPONENT_HIDDEN, *_pTargetEntry, false);
932
0
                Reference< XPropertySet >  xNewPropSet( pNewControlData->GetPropertySet() );
933
934
                // copy properties form old control to new one
935
0
                Reference< XPropertySet >  xCurrent(pControls[i], UNO_QUERY);
936
#if (OSL_DEBUG_LEVEL > 0)
937
                // check whether it is a hidden control
938
                sal_Int16 nClassId = ::comphelper::getINT16(xCurrent->getPropertyValue(FM_PROP_CLASSID));
939
                OSL_ENSURE(nClassId == FormComponentType::HIDDENCONTROL, "NavigatorTree::implExecuteDataTransfer: invalid control in drop list !");
940
                    // if SVX_FM_HIDDEN_CONTROLS-format exists, the sequence
941
                    // should only contain hidden controls
942
#endif // (OSL_DEBUG_LEVEL > 0)
943
0
                Reference< XPropertySetInfo >  xPropInfo( xCurrent->getPropertySetInfo());
944
0
                const Sequence< Property> seqAllCurrentProps = xPropInfo->getProperties();
945
0
                for (Property const & currentProp : seqAllCurrentProps)
946
0
                {
947
0
                    if (((currentProp.Attributes & PropertyAttribute::READONLY) == 0) && (currentProp.Name != FM_PROP_NAME))
948
0
                    {   // (read-only attribs aren't set, ditto name,
949
                        // NewControl defined it uniquely
950
0
                        xNewPropSet->setPropertyValue(currentProp.Name, xCurrent->getPropertyValue(currentProp.Name));
951
0
                    }
952
0
                }
953
954
0
                std::unique_ptr<weld::TreeIter> xToSelect = FindEntry(pNewControlData);
955
0
                m_xTreeView->select(*xToSelect);
956
0
                if (i == 0)
957
0
                    m_xTreeView->set_cursor(*xToSelect);
958
0
            }
959
960
0
            if (pFormModel)
961
0
                pFormModel->EndUndo();
962
963
0
            return _nAction;
964
0
        }
965
966
0
        if ( !OControlExchange::hasFieldExchangeFormat( _rData.GetDataFlavorExVector() ) )
967
0
        {
968
            // can't do anything without the internal format here ... usually happens when doing DnD or CnP
969
            // over navigator boundaries
970
0
            return DND_ACTION_NONE;
971
0
        }
972
973
        // some data for the target
974
0
        bool bDropTargetIsForm = IsFormEntry(*_pTargetEntry);
975
0
        FmFormData* pTargetData = bDropTargetIsForm ? weld::fromId<FmFormData*>(m_xTreeView->get_id(*_pTargetEntry)) : nullptr;
976
977
0
        DBG_ASSERT( DND_ACTION_COPY != _nAction, "NavigatorTree::implExecuteDataTransfer: somebody changed the logics!" );
978
979
        // list of dragged entries
980
0
        const ListBoxEntrySet& rDropped = _rData.selected();
981
0
        DBG_ASSERT(!rDropped.empty(), "NavigatorTree::implExecuteDataTransfer: no entries!");
982
983
        // make a copy because rDropped is updated on deleting an entry which we do in the processing loop
984
0
        ListBoxEntrySet aDropped;
985
0
        for (const auto& rEntry : rDropped)
986
0
            aDropped.emplace(m_xTreeView->make_iterator(rEntry.get()));
987
988
        // shell and model
989
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
990
0
        FmFormModel* pFormModel = pFormShell ? pFormShell->GetFormModel() : nullptr;
991
0
        if (!pFormModel)
992
0
            return DND_ACTION_NONE;
993
994
        // for Undo
995
0
        const bool bUndo = pFormModel->IsUndoEnabled();
996
997
0
        if( bUndo )
998
0
        {
999
0
            OUString strUndoDescription(SvxResId(RID_STR_UNDO_CONTAINER_REPLACE));
1000
0
            pFormModel->BegUndo(strUndoDescription);
1001
0
        }
1002
1003
        // remove selection before adding an entry, so the mark doesn't flicker
1004
        // -> lock action of selection
1005
0
        LockSelectionHandling();
1006
1007
        // go through all dropped entries
1008
0
        for (   ListBoxEntrySet::const_iterator dropped = aDropped.begin();
1009
0
                dropped != aDropped.end();
1010
0
                ++dropped
1011
0
            )
1012
0
        {
1013
0
            bool bFirstEntry = aDropped.begin() == dropped;
1014
1015
            // some data of the current element
1016
0
            const auto& rCurrent = *dropped;
1017
0
            DBG_ASSERT(rCurrent, "NavigatorTree::implExecuteDataTransfer: invalid entry");
1018
0
            DBG_ASSERT(m_xTreeView->get_iter_depth(*rCurrent) != 0, "NavigatorTree::implExecuteDataTransfer: invalid entry");
1019
                // don't drag root
1020
1021
0
            FmEntryData* pCurrentUserData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rCurrent));
1022
1023
0
            Reference< XChild >  xCurrentChild = pCurrentUserData->GetChildIFace();
1024
0
            Reference< XIndexContainer >  xContainer(xCurrentChild->getParent(), UNO_QUERY);
1025
1026
0
            FmFormData* pCurrentParentUserData = static_cast<FmFormData*>(pCurrentUserData->GetParent());
1027
0
            DBG_ASSERT(pCurrentParentUserData == nullptr || dynamic_cast<const FmFormData*>(pCurrentUserData->GetParent()) !=  nullptr, "NavigatorTree::implExecuteDataTransfer: invalid parent");
1028
1029
            // remove from parent
1030
0
            if (pCurrentParentUserData)
1031
0
                pCurrentParentUserData->GetChildList()->removeNoDelete( pCurrentUserData );
1032
0
            else
1033
0
                GetNavModel()->GetRootList()->removeNoDelete( pCurrentUserData );
1034
1035
            // remove from container
1036
0
            sal_Int32 nIndex = getElementPos(xContainer, xCurrentChild);
1037
0
            GetNavModel()->m_pPropChangeList->Lock();
1038
            // UndoAction for removal
1039
0
            if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1040
0
            {
1041
0
                pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*pFormModel, FmUndoContainerAction::Removed,
1042
0
                                                            xContainer, xCurrentChild, nIndex));
1043
0
            }
1044
0
            else if( !GetNavModel()->m_pPropChangeList->CanUndo() )
1045
0
            {
1046
0
                FmUndoContainerAction::DisposeElement( xCurrentChild );
1047
0
            }
1048
1049
            // copy events
1050
0
            Reference< XEventAttacherManager >  xManager(xContainer, UNO_QUERY);
1051
0
            Sequence< ScriptEventDescriptor > aEvts;
1052
1053
0
            if (xManager.is() && nIndex >= 0)
1054
0
                aEvts = xManager->getScriptEvents(nIndex);
1055
0
            xContainer->removeByIndex(nIndex);
1056
1057
            // remove selection
1058
0
            m_xTreeView->unselect(*rCurrent);
1059
            // and delete it
1060
0
            Remove(pCurrentUserData);
1061
1062
            // position in DropParents, where to insert dropped entries
1063
0
            if (pTargetData)
1064
0
                xContainer.set(pTargetData->GetElement(), UNO_QUERY);
1065
0
            else
1066
0
                xContainer = GetNavModel()->GetForms();
1067
1068
            // always insert at the end
1069
0
            nIndex = xContainer->getCount();
1070
1071
            // UndoAction for insertion
1072
0
            if ( bUndo && GetNavModel()->m_pPropChangeList->CanUndo())
1073
0
                pFormModel->AddUndo(std::make_unique<FmUndoContainerAction>(*pFormModel, FmUndoContainerAction::Inserted,
1074
0
                                                         xContainer, xCurrentChild, nIndex));
1075
1076
            // insert in new container
1077
0
            if (pTargetData)
1078
0
            {
1079
                 // insert in a form needs a FormComponent
1080
0
                xContainer->insertByIndex( nIndex,
1081
0
                    Any( Reference< XFormComponent >( xCurrentChild, UNO_QUERY ) ) );
1082
0
            }
1083
0
            else
1084
0
            {
1085
0
                xContainer->insertByIndex( nIndex,
1086
0
                    Any( Reference< XForm >( xCurrentChild, UNO_QUERY ) ) );
1087
0
            }
1088
1089
0
            if (aEvts.hasElements())
1090
0
            {
1091
0
                xManager.set(xContainer, UNO_QUERY);
1092
0
                if (xManager.is())
1093
0
                    xManager->registerScriptEvents(nIndex, aEvts);
1094
0
            }
1095
1096
0
            GetNavModel()->m_pPropChangeList->UnLock();
1097
1098
            // give an entry the new parent
1099
0
            pCurrentUserData->SetParent(pTargetData);
1100
1101
            // give parent the new child
1102
0
            if (pTargetData)
1103
0
                pTargetData->GetChildList()->insert( std::unique_ptr<FmEntryData>(pCurrentUserData), nIndex );
1104
0
            else
1105
0
                GetNavModel()->GetRootList()->insert( std::unique_ptr<FmEntryData>(pCurrentUserData), nIndex );
1106
1107
            // announce to myself and reselect
1108
0
            std::unique_ptr<weld::TreeIter> xNew = Insert( pCurrentUserData, nIndex );
1109
0
            if (bFirstEntry && xNew)
1110
0
            {
1111
0
                if (m_xTreeView->iter_parent(*xNew))
1112
0
                    m_xTreeView->expand_row(*xNew);
1113
0
            }
1114
0
        }
1115
1116
0
        UnlockSelectionHandling();
1117
1118
0
        if( bUndo )
1119
0
            pFormModel->EndUndo();
1120
1121
        // During the move, the markings of the underlying view did not change (because the view is not affected by the logical
1122
        // hierarchy of the form/control models. But my selection changed - which means I have to adjust it according to the
1123
        // view marks, again.
1124
0
        SynchronizeSelection();
1125
1126
        // in addition, with the move of controls such things as "the current form" may have changed - force the shell
1127
        // to update itself accordingly
1128
0
        if( pFormShell && pFormShell->GetImpl() && pFormShell->GetFormView() )
1129
0
            pFormShell->GetImpl()->DetermineSelection_Lock( pFormShell->GetFormView()->GetMarkedObjectList() );
1130
1131
0
        if ( m_aControlExchange.isClipboardOwner() && ( DND_ACTION_MOVE == _nAction ) )
1132
0
            m_aControlExchange->clear();
1133
1134
0
        return _nAction;
1135
0
    }
1136
1137
    sal_Int8 NavigatorTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
1138
0
    {
1139
0
        sal_Int8 nResult( DND_ACTION_NONE );
1140
0
        if ( m_aControlExchange.isDragSource() )
1141
0
            nResult = implExecuteDataTransfer( *m_aControlExchange, rEvt.mnAction, rEvt.maPosPixel, true );
1142
0
        else
1143
0
        {
1144
0
            OControlTransferData aDroppedData( rEvt.maDropEvent.Transferable );
1145
0
            nResult = implExecuteDataTransfer( aDroppedData, rEvt.mnAction, rEvt.maPosPixel, true );
1146
0
        }
1147
0
        return nResult;
1148
0
    }
1149
1150
    void NavigatorTree::doPaste()
1151
0
    {
1152
0
        std::unique_ptr<weld::TreeIter> xSelected = m_xTreeView->get_selected();
1153
0
        try
1154
0
        {
1155
0
            if ( m_aControlExchange.isClipboardOwner() )
1156
0
            {
1157
0
                implExecuteDataTransfer( *m_aControlExchange, doingKeyboardCut( ) ? DND_ACTION_MOVE : DND_ACTION_COPY, xSelected.get(), false );
1158
0
            }
1159
0
            else
1160
0
            {
1161
                // the clipboard content
1162
0
                Reference< XClipboard > xClipboard(m_xTreeView->get_clipboard());
1163
0
                Reference< XTransferable > xTransferable;
1164
0
                if ( xClipboard.is() )
1165
0
                    xTransferable = xClipboard->getContents();
1166
1167
0
                OControlTransferData aClipboardContent( xTransferable );
1168
0
                implExecuteDataTransfer( aClipboardContent, DND_ACTION_COPY, xSelected.get(), false );
1169
0
            }
1170
0
        }
1171
0
        catch( const Exception& )
1172
0
        {
1173
0
            TOOLS_WARN_EXCEPTION( "svx", "NavigatorTree::doPaste" );
1174
0
        }
1175
0
    }
1176
1177
    void NavigatorTree::doCopy()
1178
0
    {
1179
0
        if ( implPrepareExchange( DND_ACTION_COPY ) )
1180
0
        {
1181
0
            m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1182
0
            m_aControlExchange.copyToClipboard(*m_xTreeView);
1183
0
        }
1184
0
    }
1185
1186
    void NavigatorTree::ModelHasRemoved(const weld::TreeIter* pTypedEntry)
1187
0
    {
1188
0
        if (doingKeyboardCut())
1189
0
        {
1190
0
            auto aIter = std::find_if(m_aCutEntries.begin(), m_aCutEntries.end(),
1191
0
                                      [pTypedEntry](const auto& rElem) {
1192
0
                                        return rElem->equal(*pTypedEntry);
1193
0
                                      });
1194
0
            if (aIter != m_aCutEntries.end())
1195
0
                m_aCutEntries.erase(aIter);
1196
0
        }
1197
1198
0
        if (m_aControlExchange.isDataExchangeActive())
1199
0
        {
1200
0
            if (0 == m_aControlExchange->onEntryRemoved(pTypedEntry))
1201
0
            {
1202
                // last of the entries which we put into the clipboard has been deleted from the tree.
1203
                // Give up the clipboard ownership.
1204
0
                m_aControlExchange.clear();
1205
0
            }
1206
0
        }
1207
0
    }
1208
1209
    void NavigatorTree::doCut()
1210
0
    {
1211
0
        if ( !implPrepareExchange( DND_ACTION_MOVE ) )
1212
0
            return;
1213
1214
0
        m_aControlExchange.setClipboardListener( LINK( this, NavigatorTree, OnClipboardAction ) );
1215
0
        m_aControlExchange.copyToClipboard(*m_xTreeView);
1216
0
        m_bKeyboardCut = true;
1217
1218
        // mark all the entries we just "cut" into the clipboard as "nearly moved"
1219
0
        for (const auto& rEntry : m_arrCurrentSelection )
1220
0
        {
1221
0
            if (!rEntry)
1222
0
                continue;
1223
0
            m_aCutEntries.emplace(m_xTreeView->make_iterator(rEntry.get()));
1224
0
            m_xTreeView->set_sensitive(*rEntry, false);
1225
0
        }
1226
0
    }
1227
1228
    IMPL_LINK(NavigatorTree, KeyInputHdl, const ::KeyEvent&, rKEvt, bool)
1229
0
    {
1230
0
        const vcl::KeyCode& rCode = rKEvt.GetKeyCode();
1231
1232
        // delete?
1233
0
        if (rCode.GetCode() == KEY_DELETE && !rCode.GetModifier())
1234
0
        {
1235
0
            DeleteSelection();
1236
0
            return true;
1237
0
        }
1238
1239
        // copy'n'paste?
1240
0
        switch ( rCode.GetFunction() )
1241
0
        {
1242
0
            case KeyFuncType::CUT:
1243
0
                doCut();
1244
0
                break;
1245
1246
0
            case KeyFuncType::PASTE:
1247
0
                if ( implAcceptPaste() )
1248
0
                    doPaste();
1249
0
                break;
1250
1251
0
            case KeyFuncType::COPY:
1252
0
                doCopy();
1253
0
                break;
1254
1255
0
            default:
1256
0
                break;
1257
0
        }
1258
1259
0
        return false;
1260
0
    }
1261
1262
    IMPL_LINK(NavigatorTree, EditingEntryHdl, const weld::TreeIter&, rIter, bool)
1263
0
    {
1264
        // root, which isn't allowed to be renamed, has UserData=NULL
1265
0
        m_bEditing = !m_xTreeView->get_id(rIter).isEmpty();
1266
0
        return m_bEditing;
1267
0
    }
1268
1269
    void NavigatorTree::NewForm(const weld::TreeIter& rParentEntry)
1270
0
    {
1271
        // get ParentFormData
1272
0
        if (!IsFormEntry(rParentEntry))
1273
0
            return;
1274
1275
0
        FmFormData* pParentFormData = weld::fromId<FmFormData*>(m_xTreeView->get_id(rParentEntry));
1276
1277
1278
        // create new form
1279
0
        const Reference<XComponentContext>& xContext = comphelper::getProcessComponentContext();
1280
0
        Reference< XForm >  xNewForm(xContext->getServiceManager()->createInstanceWithContext(FM_SUN_COMPONENT_FORM, xContext), UNO_QUERY);
1281
0
        if (!xNewForm.is())
1282
0
            return;
1283
1284
0
        Reference< XPropertySet >  xPropertySet(xNewForm, UNO_QUERY);
1285
0
        if (!xPropertySet.is())
1286
0
            return;
1287
1288
0
        FmFormData* pNewFormData = new FmFormData(xNewForm, pParentFormData);
1289
1290
1291
        // set name
1292
0
        OUString aName = GenerateName(*pNewFormData);
1293
0
        pNewFormData->SetText(aName);
1294
1295
0
        try
1296
0
        {
1297
0
            xPropertySet->setPropertyValue( FM_PROP_NAME, Any(aName) );
1298
            // a form should always have the command type table as default
1299
0
            xPropertySet->setPropertyValue( FM_PROP_COMMANDTYPE, Any(sal_Int32(CommandType::TABLE)));
1300
0
        }
1301
0
        catch ( const Exception& )
1302
0
        {
1303
0
            OSL_FAIL("NavigatorTree::NewForm : could not set essential properties!");
1304
0
        }
1305
1306
1307
        // insert form
1308
0
        GetNavModel()->Insert(pNewFormData, SAL_MAX_UINT32, true);
1309
1310
1311
        // set new form as active
1312
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1313
0
        if( pFormShell )
1314
0
        {
1315
0
            InterfaceBag aSelection;
1316
0
            aSelection.insert( Reference<XInterface>( xNewForm, UNO_QUERY ) );
1317
0
            pFormShell->GetImpl()->setCurrentSelection_Lock(std::move(aSelection));
1318
1319
0
            pFormShell->GetViewShell()->GetViewFrame().GetBindings().Invalidate(SID_FM_PROPERTIES, true, true);
1320
0
        }
1321
0
        GetNavModel()->SetModified();
1322
1323
        // switch to EditMode
1324
0
        std::unique_ptr<weld::TreeIter> xNewEntry = FindEntry(pNewFormData);
1325
0
        m_xTreeView->start_editing(*xNewEntry);
1326
0
        m_bEditing = true;
1327
0
    }
1328
1329
    FmControlData* NavigatorTree::NewControl(const OUString& rServiceName, const weld::TreeIter& rParentEntry, bool bEditName)
1330
0
    {
1331
        // get ParentForm
1332
0
        if (!GetNavModel()->GetFormShell())
1333
0
            return nullptr;
1334
0
        if (!IsFormEntry(rParentEntry))
1335
0
            return nullptr;
1336
1337
0
        FmFormData* pParentFormData = weld::fromId<FmFormData*>(m_xTreeView->get_id(rParentEntry));
1338
0
        Reference<XForm>  xParentForm(pParentFormData->GetFormIface());
1339
1340
        // create new component
1341
0
        const Reference<XComponentContext>& xContext = comphelper::getProcessComponentContext();
1342
0
        Reference<XFormComponent> xNewComponent( xContext->getServiceManager()->createInstanceWithContext(rServiceName, xContext), UNO_QUERY);
1343
0
        if (!xNewComponent.is())
1344
0
            return nullptr;
1345
1346
0
        FmControlData* pNewFormControlData = new FmControlData(xNewComponent, pParentFormData);
1347
1348
        // set name
1349
0
        OUString sName = FmFormPageImpl::setUniqueName( xNewComponent, xParentForm );
1350
1351
0
        pNewFormControlData->SetText( sName );
1352
1353
        // insert FormComponent
1354
0
        GetNavModel()->Insert(pNewFormControlData, SAL_MAX_UINT32, true);
1355
0
        GetNavModel()->SetModified();
1356
1357
0
        if (bEditName)
1358
0
        {
1359
            // switch to EditMode
1360
0
            std::unique_ptr<weld::TreeIter> xNewEntry = FindEntry( pNewFormControlData );
1361
0
            m_xTreeView->select(*xNewEntry);
1362
1363
0
            m_xTreeView->start_editing(*xNewEntry);
1364
0
            m_bEditing = true;
1365
0
        }
1366
1367
0
        return pNewFormControlData;
1368
0
    }
1369
1370
    OUString NavigatorTree::GenerateName(const FmEntryData& rEntryData)
1371
0
    {
1372
0
        const sal_uInt16 nMaxCount = 99;
1373
0
        OUString aNewName;
1374
1375
        // create base name
1376
0
        OUString aBaseName;
1377
0
        if( dynamic_cast<const FmFormData*>(&rEntryData) !=  nullptr )
1378
0
            aBaseName = SvxResId( RID_STR_STDFORMNAME );
1379
0
        else if( dynamic_cast<const FmControlData*>(&rEntryData) !=  nullptr )
1380
0
            aBaseName = SvxResId( RID_STR_CONTROL );
1381
1382
1383
        // create new name
1384
0
        FmFormData* pFormParentData = static_cast<FmFormData*>(rEntryData.GetParent());
1385
1386
0
        for( sal_Int32 i=0; i<nMaxCount; i++ )
1387
0
        {
1388
0
            aNewName = aBaseName;
1389
0
            if( i>0 )
1390
0
            {
1391
0
                aNewName += " " + OUString::number(i);
1392
0
            }
1393
1394
0
            if( GetNavModel()->FindData(aNewName, pFormParentData,false) == nullptr )
1395
0
                break;
1396
0
        }
1397
1398
0
        return aNewName;
1399
0
    }
1400
1401
    IMPL_LINK(NavigatorTree, EditedEntryHdl, const weld::TreeView::IterColText&, rIterColText, bool)
1402
0
    {
1403
0
        m_bEditing = false;
1404
1405
0
        const weld::TreeIter& rIter = rIterColText.m_rIter;
1406
1407
0
        FmEntryData* pEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rIter));
1408
0
        bool bRes = NavigatorTreeModel::Rename(pEntryData, rIterColText.m_sText);
1409
0
        if (!bRes)
1410
0
        {
1411
0
            m_xEditEntry = m_xTreeView->make_iterator(&rIter);
1412
0
            nEditEvent = Application::PostUserEvent(LINK(this, NavigatorTree, OnEdit));
1413
0
        }
1414
1415
0
        return bRes;
1416
0
    }
1417
1418
    IMPL_LINK_NOARG(NavigatorTree, OnEdit, void*, void)
1419
0
    {
1420
0
        nEditEvent = nullptr;
1421
0
        m_xTreeView->start_editing(*m_xEditEntry);
1422
0
        m_bEditing = true;
1423
0
        m_xEditEntry.reset();
1424
0
    }
1425
1426
    IMPL_LINK_NOARG(NavigatorTree, OnEntrySelDesel, weld::ItemView&, void)
1427
0
    {
1428
0
        m_sdiState = SDI_DIRTY;
1429
1430
0
        if (IsSelectionHandlingLocked())
1431
0
            return;
1432
1433
0
        if (m_aSynchronizeTimer.IsActive())
1434
0
            m_aSynchronizeTimer.Stop();
1435
1436
0
        m_aSynchronizeTimer.SetTimeout(EXPLORER_SYNC_DELAY);
1437
0
        m_aSynchronizeTimer.Start();
1438
0
    }
1439
1440
    IMPL_LINK_NOARG(NavigatorTree, OnSynchronizeTimer, Timer *, void)
1441
0
    {
1442
0
        SynchronizeMarkList();
1443
0
    }
1444
1445
    IMPL_LINK_NOARG(NavigatorTree, OnClipboardAction, OLocalExchange&, void)
1446
0
    {
1447
0
        if ( m_aControlExchange.isClipboardOwner() )
1448
0
            return;
1449
1450
0
        if ( !doingKeyboardCut() )
1451
0
            return;
1452
1453
0
        for (const auto& rEntry : m_aCutEntries)
1454
0
        {
1455
0
            if (!rEntry)
1456
0
                continue;
1457
0
            m_xTreeView->set_sensitive(*rEntry, true);
1458
0
        }
1459
0
        ListBoxEntrySet().swap(m_aCutEntries);
1460
1461
0
        m_bKeyboardCut = false;
1462
0
    }
1463
1464
    void NavigatorTree::ShowSelectionProperties(bool bForce)
1465
0
    {
1466
        // at first i need the FormShell
1467
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1468
0
        if (!pFormShell)
1469
            // no shell -> impossible to set curObject -> leave
1470
0
            return;
1471
1472
0
        CollectSelectionData(SDI_ALL);
1473
0
        SAL_WARN_IF(static_cast<size_t>(m_nFormsSelected + m_nControlsSelected
1474
0
                + (m_bRootSelected ? 1 : 0)) != m_arrCurrentSelection.size(),
1475
0
            "svx.form",
1476
0
            "NavigatorTree::ShowSelectionProperties : selection meta data invalid !");
1477
1478
1479
0
        InterfaceBag aSelection;
1480
0
        bool bSetSelectionAsMarkList = false;
1481
1482
0
        if (m_bRootSelected)
1483
0
            ;                                   // no properties for the root, neither for single nor for multi selection
1484
0
        else if ( m_nFormsSelected + m_nControlsSelected == 0 )   // none of the two should be less 0
1485
0
            ;                                   // no selection -> no properties
1486
0
        else if ( m_nFormsSelected * m_nControlsSelected != 0 )
1487
0
            ;                                   // mixed selection -> no properties
1488
0
        else
1489
0
        {   // either only forms, or only controls are selected
1490
0
            if (m_arrCurrentSelection.size() == 1)
1491
0
            {
1492
0
                const std::unique_ptr<weld::TreeIter>& rIter = *m_arrCurrentSelection.begin();
1493
0
                if (m_nFormsSelected > 0)
1494
0
                {   // exactly one form is selected
1495
0
                    FmFormData* pFormData = weld::fromId<FmFormData*>(m_xTreeView->get_id(*rIter));
1496
0
                    aSelection.insert( Reference< XInterface >( pFormData->GetFormIface(), UNO_QUERY ) );
1497
0
                }
1498
0
                else
1499
0
                {   // exactly one control is selected (whatever hidden or normal)
1500
0
                    FmEntryData* pEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rIter));
1501
1502
0
                    aSelection.insert( Reference< XInterface >( pEntryData->GetElement(), UNO_QUERY ) );
1503
0
                }
1504
0
            }
1505
0
            else
1506
0
            {   // it's a MultiSelection, so we must build a MultiSet
1507
0
                if (m_nFormsSelected > 0)
1508
0
                {   // ... only forms
1509
                    // first of all collect PropertySet-Interfaces of the forms
1510
0
                    SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1511
0
                    for ( sal_Int32 i = 0; i < m_nFormsSelected; ++i )
1512
0
                    {
1513
0
                        const std::unique_ptr<weld::TreeIter>& rIter = *it;
1514
0
                        FmFormData* pFormData = weld::fromId<FmFormData*>(m_xTreeView->get_id(*rIter));
1515
0
                        aSelection.insert( pFormData->GetPropertySet() );
1516
0
                        ++it;
1517
0
                    }
1518
0
                }
1519
0
                else
1520
0
                {   // ... only controls
1521
0
                    if (m_nHiddenControls == m_nControlsSelected)
1522
0
                    {   // a MultiSet for properties of hidden controls
1523
0
                        SvLBoxEntrySortedArray::const_iterator it = m_arrCurrentSelection.begin();
1524
0
                        for ( sal_Int32 i = 0; i < m_nHiddenControls; ++i )
1525
0
                        {
1526
0
                            const std::unique_ptr<weld::TreeIter>& rIter = *it;
1527
0
                            FmEntryData* pEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rIter));
1528
0
                            aSelection.insert( pEntryData->GetPropertySet() );
1529
0
                            ++it;
1530
0
                        }
1531
0
                    }
1532
0
                    else if (m_nHiddenControls == 0)
1533
0
                    {   // only normal controls
1534
0
                        bSetSelectionAsMarkList = true;
1535
0
                    }
1536
0
                }
1537
0
            }
1538
1539
0
        }
1540
1541
        // and now my form and my SelObject
1542
0
        if ( bSetSelectionAsMarkList )
1543
0
            pFormShell->GetImpl()->setCurrentSelectionFromMark_Lock(pFormShell->GetFormView()->GetMarkedObjectList());
1544
0
        else
1545
0
            pFormShell->GetImpl()->setCurrentSelection_Lock(std::move(aSelection));
1546
1547
0
        if (pFormShell->GetImpl()->IsPropBrwOpen_Lock() || bForce)
1548
0
        {
1549
            // and now deliver all to the PropertyBrowser
1550
0
            pFormShell->GetViewShell()->GetViewFrame().GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SfxCallMode::ASYNCHRON );
1551
0
        }
1552
0
    }
1553
1554
1555
    void NavigatorTree::DeleteSelection()
1556
0
    {
1557
        // of course, i can't delete root
1558
0
        bool bRootSelected = m_xTreeView->is_selected(*m_xRootEntry);
1559
0
        auto nSelectedEntries = m_xTreeView->count_selected_rows();
1560
0
        if (bRootSelected && (nSelectedEntries > 1))     // root and other elements ?
1561
0
            m_xTreeView->unselect(*m_xRootEntry);                // yes -> remove root from selection
1562
1563
0
        if ((nSelectedEntries == 0) || bRootSelected)    // still root ?
1564
0
            return;                                     // -> only selected element -> leave
1565
1566
0
        DBG_ASSERT(!m_bPrevSelectionMixed, "NavigatorTree::DeleteSelection() : delete permitted if mark and selection are inconsistent");
1567
1568
        // i need the FormModel later
1569
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1570
0
        if (!pFormShell)
1571
0
            return;
1572
0
        FmFormModel* pFormModel = pFormShell->GetFormModel();
1573
0
        if (!pFormModel)
1574
0
            return;
1575
1576
        // now I have to safeguard the DeleteList: if you delete a form and a dependent element
1577
        // - in this order - than the SvLBoxEntryPtr of the dependent element is already invalid,
1578
        // when it should be deleted... you have to prohibit this GPF, that of course would happen,
1579
        // so I take the 'normalized' list
1580
0
        CollectSelectionData( SDI_NORMALIZED );
1581
1582
        // see below for why we need this mapping from models to shapes
1583
0
        FmFormView*     pFormView       = pFormShell->GetFormView();
1584
0
        SdrPageView*    pPageView       = pFormView ? pFormView->GetSdrPageView() : nullptr;
1585
0
        SdrPage*        pPage           = pPageView ? pPageView->GetPage() : nullptr;
1586
0
        DBG_ASSERT( pPage, "NavigatorTree::DeleteSelection: invalid form page!" );
1587
1588
0
        MapModelToShape aModelShapes;
1589
0
        if ( pPage )
1590
0
            collectShapeModelMapping( pPage, aModelShapes );
1591
1592
        // problem: we have to use ExplorerModel::Remove, since only this one properly deletes Form objects.
1593
        // But, the controls themself must be deleted via DeleteMarked (else, the Writer has some problems
1594
        // somewhere). In case I'd first delete the structure, then the controls, the UNDO would not work
1595
        // (since UNDO then would mean to first restore the controls, then the structure, means their parent
1596
        // form). The other way round, the EntryDatas would be invalid, if I'd first delete the controls and
1597
        // then go on to the structure. This means I have to delete the forms *after* the normal controls, so
1598
        // that during UNDO, they're restored in the proper order.
1599
0
        pFormShell->GetImpl()->EnableTrackProperties_Lock(false);
1600
0
        for (SvLBoxEntrySortedArray::reverse_iterator it = m_arrCurrentSelection.rbegin();
1601
0
             it != m_arrCurrentSelection.rend(); )
1602
0
        {
1603
0
            const std::unique_ptr<weld::TreeIter>& rIter = *it;
1604
0
            FmEntryData* pCurrent = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rIter));
1605
1606
            // a form ?
1607
0
            auto pFormData = dynamic_cast<FmFormData*>(pCurrent);
1608
1609
            // because deletion is done by the view, and i build on its MarkList,
1610
            // but normally only direct controls, no indirect ones, are marked in a marked form,
1611
            // I have to do it later
1612
0
            if (pFormData)
1613
0
                MarkViewObj(pFormData, true/*deep*/);
1614
1615
            // a hidden control ?
1616
0
            bool bIsHidden = IsHiddenControl(pCurrent);
1617
1618
            // keep forms and hidden controls, the rest not
1619
0
            if (!pFormData && !bIsHidden)
1620
0
            {
1621
                // well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
1622
                // be deleted automatically. This is because for every model (except forms and hidden control models)
1623
                // there exist a shape, which is marked _if_and_only_if_ the model is selected in our tree.
1624
0
                if ( aModelShapes.find( pCurrent->GetElement() ) != aModelShapes.end() )
1625
0
                {
1626
                    // if there's a shape for the current entry, then either it is marked or it is in a
1627
                    // hidden layer (#i28502#), or something like this.
1628
                    // In the first case, it will be deleted below, in the second case, we currently don't
1629
                    // delete it, as there's no real (working!) API for this, neither in UNO nor in non-UNO.
1630
0
                    m_arrCurrentSelection.erase( --(it.base()) );
1631
0
                }
1632
0
                else
1633
0
                   ++it;
1634
                // In case there is no shape for the current entry, we keep the entry in m_arrCurrentSelection,
1635
                // since then we can definitely remove it.
1636
0
            }
1637
0
            else
1638
0
                ++it;
1639
0
        }
1640
0
        pFormShell->GetImpl()->EnableTrackProperties_Lock(true);
1641
1642
        // let the view delete the marked controls
1643
0
        pFormShell->GetFormView()->DeleteMarked();
1644
1645
        // start UNDO at this point. Unfortunately, this results in 2 UNDO actions, since DeleteMarked is
1646
        // creating an own one. However, if we'd move it before DeleteMarked, Writer does not really like
1647
        // this ... :(
1648
        // #i31038#
1649
0
        {
1650
1651
            // initialize UNDO
1652
0
            OUString aUndoStr;
1653
0
            if ( m_arrCurrentSelection.size() == 1 )
1654
0
            {
1655
0
                aUndoStr = SvxResId(RID_STR_UNDO_CONTAINER_REMOVE);
1656
0
                if (m_nFormsSelected)
1657
0
                    aUndoStr = aUndoStr.replaceFirst( "#", SvxResId( RID_STR_FORM ) );
1658
0
                else
1659
                    // it must be a control (else the root would be selected, but it cannot be deleted)
1660
0
                    aUndoStr = aUndoStr.replaceFirst( "#", SvxResId( RID_STR_CONTROL ) );
1661
0
            }
1662
0
            else
1663
0
            {
1664
0
                aUndoStr = SvxResId(RID_STR_UNDO_CONTAINER_REMOVE_MULTIPLE);
1665
0
                aUndoStr = aUndoStr.replaceFirst( "#", OUString::number( m_arrCurrentSelection.size() ) );
1666
0
            }
1667
0
            pFormModel->BegUndo(aUndoStr);
1668
0
        }
1669
1670
        // remove remaining structure
1671
0
        for (const auto& rpSelection : m_arrCurrentSelection)
1672
0
        {
1673
0
            FmEntryData* pCurrent = weld::fromId<FmEntryData*>(m_xTreeView->get_id(*rpSelection));
1674
1675
            // if the entry still has children, we skipped deletion of one of those children.
1676
            // This may for instance be because the shape is in a hidden layer, where we're unable
1677
            // to remove it
1678
0
            if ( pCurrent->GetChildList()->size() )
1679
0
                continue;
1680
1681
            // one remaining subtle problem, before deleting it : if it's a form and the shell
1682
            // knows it as CurrentObject, I have to tell it something else
1683
0
            if (auto pFormData = dynamic_cast<FmFormData*>( pCurrent))
1684
0
            {
1685
0
                Reference< XForm >  xCurrentForm( pFormData->GetFormIface() );
1686
0
                if (pFormShell->GetImpl()->getCurrentForm_Lock() == xCurrentForm)  // shell knows form to be deleted ?
1687
0
                    pFormShell->GetImpl()->forgetCurrentForm_Lock();                 // -> take away ...
1688
0
            }
1689
0
            GetNavModel()->Remove(pCurrent, true);
1690
0
        }
1691
0
        pFormModel->EndUndo();
1692
0
    }
1693
1694
1695
    void NavigatorTree::CollectSelectionData(SELDATA_ITEMS sdiHow)
1696
0
    {
1697
0
        DBG_ASSERT(sdiHow != SDI_DIRTY, "NavigatorTree::CollectSelectionData : ever thought about your parameter ? DIRTY ?");
1698
0
        if (sdiHow == m_sdiState)
1699
0
            return;
1700
1701
0
        m_arrCurrentSelection.clear();
1702
0
        m_nFormsSelected = m_nControlsSelected = m_nHiddenControls = 0;
1703
0
        m_bRootSelected = false;
1704
1705
0
        m_xTreeView->selected_foreach([this, sdiHow](weld::TreeIter& rSelectionLoop){
1706
            // count different elements
1707
0
            if (rSelectionLoop.equal(*m_xRootEntry))
1708
0
                m_bRootSelected = true;
1709
0
            else
1710
0
            {
1711
0
                if (IsFormEntry(rSelectionLoop))
1712
0
                    ++m_nFormsSelected;
1713
0
                else
1714
0
                {
1715
0
                    ++m_nControlsSelected;
1716
0
                    if (IsHiddenControl(weld::fromId<FmEntryData*>(m_xTreeView->get_id(rSelectionLoop))))
1717
0
                        ++m_nHiddenControls;
1718
0
                }
1719
0
            }
1720
1721
0
            if (sdiHow == SDI_NORMALIZED)
1722
0
            {
1723
                // don't take something with a selected ancestor
1724
0
                if (rSelectionLoop.equal(*m_xRootEntry))
1725
0
                    m_arrCurrentSelection.emplace(m_xTreeView->make_iterator(&rSelectionLoop));
1726
0
                else
1727
0
                {
1728
0
                    std::unique_ptr<weld::TreeIter> xParentLoop(m_xTreeView->make_iterator(&rSelectionLoop));
1729
0
                    bool bParentLoop = m_xTreeView->iter_parent(*xParentLoop);
1730
0
                    while (bParentLoop)
1731
0
                    {
1732
                        // actually i would have to test, if parent is part of m_arr_CurrentSelection ...
1733
                        // but if it's selected, then it's in m_arrCurrentSelection
1734
                        // or one of its ancestors, which was selected earlier.
1735
                        // In both cases IsSelected is enough
1736
0
                        if (m_xTreeView->is_selected(*xParentLoop))
1737
0
                            break;
1738
0
                        else
1739
0
                        {
1740
0
                            if (xParentLoop->equal(*m_xRootEntry))
1741
0
                            {
1742
                                // until root (exclusive), there was no selected parent -> entry belongs to normalized list
1743
0
                                m_arrCurrentSelection.emplace(m_xTreeView->make_iterator(&rSelectionLoop));
1744
0
                                break;
1745
0
                            }
1746
0
                            else
1747
0
                                bParentLoop = m_xTreeView->iter_parent(*xParentLoop);
1748
0
                        }
1749
0
                    }
1750
0
                }
1751
0
            }
1752
0
            else if (sdiHow == SDI_NORMALIZED_FORMARK)
1753
0
            {
1754
0
                std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rSelectionLoop));
1755
0
                bool bParent = m_xTreeView->iter_parent(*xParent);
1756
0
                if (!bParent || !m_xTreeView->is_selected(*xParent) || IsFormEntry(rSelectionLoop))
1757
0
                    m_arrCurrentSelection.emplace(m_xTreeView->make_iterator(&rSelectionLoop));
1758
0
            }
1759
0
            else
1760
0
                m_arrCurrentSelection.emplace(m_xTreeView->make_iterator(&rSelectionLoop));
1761
1762
0
            return false;
1763
0
        });
1764
1765
0
        m_sdiState = sdiHow;
1766
0
    }
1767
1768
    void NavigatorTree::SynchronizeSelection(FmEntryDataArray& arredToSelect)
1769
0
    {
1770
0
        LockSelectionHandling();
1771
0
        if (arredToSelect.empty())
1772
0
        {
1773
0
            m_xTreeView->unselect_all();
1774
0
        }
1775
0
        else
1776
0
        {
1777
            // compare current selection with requested SelectList
1778
0
            m_xTreeView->selected_foreach([this, &arredToSelect](weld::TreeIter& rSelection) {
1779
0
                FmEntryData* pCurrent = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rSelection));
1780
0
                if (pCurrent != nullptr)
1781
0
                {
1782
0
                    FmEntryDataArray::iterator it = arredToSelect.find(pCurrent);
1783
0
                    if ( it != arredToSelect.end() )
1784
0
                    {   // entry already selected, but also in SelectList
1785
                        // remove it from there
1786
0
                        arredToSelect.erase(it);
1787
0
                    } else
1788
0
                    {   // entry selected, but not in SelectList -> remove selection
1789
0
                        m_xTreeView->unselect(rSelection);
1790
                        // make it visible (maybe it's the only modification i do in this handler
1791
                        // so you should see it
1792
0
                        m_xTreeView->scroll_to_row(rSelection);
1793
0
                    }
1794
0
                }
1795
0
                else
1796
0
                    m_xTreeView->unselect(rSelection);
1797
1798
0
                return false;
1799
0
            });
1800
1801
            // now SelectList contains only entries, which have to be selected
1802
            // two possibilities : 1) run through SelectList, get SvTreeListEntry for every entry and select it (is more intuitive)
1803
            // 2) run through my SvLBoxEntries and select those, i can find in the SelectList
1804
            // 1) needs =(k*n) (k=length of SelectList, n=number of entries),
1805
            // plus the fact, that FindEntry uses extensive IsEqualWithoutChilden instead of comparing pointer to UserData
1806
            // 2) needs =(n*log k), duplicates some code from FindEntry
1807
            // This may be a frequently used code ( at every change in mark of the view!),
1808
            // so i use latter one
1809
0
            m_xTreeView->all_foreach([this, &arredToSelect](weld::TreeIter& rLoop){
1810
0
                FmEntryData* pCurEntryData = weld::fromId<FmEntryData*>(m_xTreeView->get_id(rLoop));
1811
0
                FmEntryDataArray::iterator it = arredToSelect.find(pCurEntryData);
1812
0
                if (it != arredToSelect.end())
1813
0
                {
1814
0
                    m_xTreeView->select(rLoop);
1815
0
                    m_xTreeView->scroll_to_row(rLoop);
1816
0
                }
1817
1818
0
                return false;
1819
0
            });
1820
0
        }
1821
0
        UnlockSelectionHandling();
1822
0
    }
1823
1824
1825
    void NavigatorTree::SynchronizeSelection()
1826
0
    {
1827
        // shell and view
1828
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1829
0
        if(!pFormShell) return;
1830
1831
0
        FmFormView* pFormView = pFormShell->GetFormView();
1832
0
        if (!pFormView) return;
1833
1834
0
        GetNavModel()->BroadcastMarkedObjects(pFormView->GetMarkedObjectList());
1835
0
    }
1836
1837
1838
    void NavigatorTree::SynchronizeMarkList()
1839
0
    {
1840
        // i'll need this shell
1841
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1842
0
        if (!pFormShell) return;
1843
1844
0
        CollectSelectionData(SDI_NORMALIZED_FORMARK);
1845
1846
        // the view shouldn't notify now if MarkList changed
1847
0
        pFormShell->GetImpl()->EnableTrackProperties_Lock(false);
1848
1849
0
        UnmarkAllViewObj();
1850
1851
0
        for (auto& rSelectionLoop : m_arrCurrentSelection)
1852
0
        {
1853
            // When form selection, mark all controls of form
1854
0
            if (IsFormEntry(*rSelectionLoop) && !rSelectionLoop->equal(*m_xRootEntry))
1855
0
                MarkViewObj(weld::fromId<FmFormData*>(m_xTreeView->get_id(*rSelectionLoop)), false/*deep*/);
1856
1857
            // When control selection, mark Control-SdrObjects
1858
0
            else if (IsFormComponentEntry(*rSelectionLoop))
1859
0
            {
1860
0
                FmControlData* pControlData = weld::fromId<FmControlData*>(m_xTreeView->get_id(*rSelectionLoop));
1861
0
                if (pControlData)
1862
0
                {
1863
1864
                    // When HiddenControl no object can be selected
1865
0
                    Reference< XFormComponent >  xFormComponent( pControlData->GetFormComponent());
1866
0
                    if (!xFormComponent.is())
1867
0
                        continue;
1868
0
                    Reference< XPropertySet >  xSet(xFormComponent, UNO_QUERY);
1869
0
                    if (!xSet.is())
1870
0
                        continue;
1871
1872
0
                    sal_uInt16 nClassId = ::comphelper::getINT16(xSet->getPropertyValue(FM_PROP_CLASSID));
1873
0
                    if (nClassId != FormComponentType::HIDDENCONTROL)
1874
0
                        MarkViewObj(pControlData);
1875
0
                }
1876
0
            }
1877
0
        }
1878
1879
        // if PropertyBrowser is open, I have to adopt it according to my selection
1880
        // (Not as MarkList of view : if a form is selected, all belonging controls are selected in the view
1881
        // but of course i want to see the form-properties
1882
0
        ShowSelectionProperties();
1883
1884
        // reset flag at view
1885
0
        pFormShell->GetImpl()->EnableTrackProperties_Lock(true);
1886
1887
        // if exactly one form is selected now, shell should notice it as CurrentForm
1888
        // (if selection handling isn't locked, view cares about it in MarkListHasChanged
1889
        // but mechanism doesn't work, if form is empty for example
1890
0
        if ((m_arrCurrentSelection.size() != 1) || (m_nFormsSelected != 1))
1891
0
            return;
1892
1893
0
        std::unique_ptr<weld::TreeIter> xSelected = m_xTreeView->get_selected();
1894
0
        FmFormData* pSingleSelectionData = xSelected ? dynamic_cast<FmFormData*>(weld::fromId<FmEntryData*>(m_xTreeView->get_id(*xSelected)))
1895
0
                                                     : nullptr;
1896
0
        DBG_ASSERT( pSingleSelectionData, "NavigatorTree::SynchronizeMarkList: invalid selected form!" );
1897
0
        if ( pSingleSelectionData )
1898
0
        {
1899
0
            InterfaceBag aSelection;
1900
0
            aSelection.insert( Reference< XInterface >( pSingleSelectionData->GetFormIface(), UNO_QUERY ) );
1901
0
            pFormShell->GetImpl()->setCurrentSelection_Lock(std::move(aSelection));
1902
0
        }
1903
0
    }
1904
1905
    bool NavigatorTree::IsHiddenControl(FmEntryData const * pEntryData)
1906
0
    {
1907
0
        if (pEntryData == nullptr) return false;
1908
1909
0
        const Reference< XPropertySet >& xProperties( pEntryData->GetPropertySet() );
1910
0
        if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
1911
0
        {
1912
0
            Any aClassID = xProperties->getPropertyValue( FM_PROP_CLASSID );
1913
0
            return (::comphelper::getINT16(aClassID) == FormComponentType::HIDDENCONTROL);
1914
0
        }
1915
0
        return false;
1916
0
    }
1917
1918
    void NavigatorTree::UnmarkAllViewObj()
1919
0
    {
1920
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1921
0
        if( !pFormShell )
1922
0
            return;
1923
0
        FmFormView* pFormView = pFormShell->GetFormView();
1924
0
        pFormView->UnMarkAll();
1925
0
    }
1926
1927
    void NavigatorTree::MarkViewObj(FmFormData const * pFormData, bool bDeep )
1928
0
    {
1929
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1930
0
        if( !pFormShell )
1931
0
            return;
1932
1933
        // first collect all sdrobjects
1934
0
        ::std::set< Reference< XFormComponent > > aObjects;
1935
0
        CollectObjects(pFormData,bDeep,aObjects);
1936
1937
1938
        // find and select appropriate SdrObj in page
1939
0
        FmFormView*     pFormView       = pFormShell->GetFormView();
1940
0
        SdrPageView*    pPageView       = pFormView->GetSdrPageView();
1941
0
        SdrPage*        pPage           = pPageView->GetPage();
1942
        //FmFormPage*     pFormPage       = dynamic_cast< FmFormPage* >( pPage );
1943
1944
0
        SdrObjListIter aIter( pPage );
1945
0
        while ( aIter.IsMore() )
1946
0
        {
1947
0
            SdrObject* pSdrObject = aIter.Next();
1948
0
            FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
1949
0
            if ( !pFormObject )
1950
0
                continue;
1951
1952
0
            Reference< XFormComponent > xControlModel( pFormObject->GetUnoControlModel(),UNO_QUERY );
1953
0
            if ( xControlModel.is() && aObjects.find(xControlModel) != aObjects.end() && !pFormView->IsObjMarked( pSdrObject ) )
1954
0
            {
1955
                // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
1956
0
                pFormView->MarkObj( pSdrObject, pPageView );
1957
0
            }
1958
0
        } // while ( aIter.IsMore() )
1959
        // make the mark visible
1960
0
        ::tools::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
1961
0
        for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
1962
0
        {
1963
0
            SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
1964
0
            OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
1965
0
            if ( ( OUTDEV_WINDOW == rOutDev.GetOutDevType() ) && !aMarkRect.IsEmpty() )
1966
0
            {
1967
0
                pFormView->MakeVisible( aMarkRect, *rOutDev.GetOwnerWindow() );
1968
0
            }
1969
0
        } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
1970
0
    }
1971
1972
    void NavigatorTree::CollectObjects(FmFormData const * pFormData, bool bDeep, ::std::set< Reference< XFormComponent > >& _rObjects)
1973
0
    {
1974
0
        FmEntryDataList* pChildList = pFormData->GetChildList();
1975
0
        for( size_t i = 0; i < pChildList->size(); ++i )
1976
0
        {
1977
0
            FmEntryData* pEntryData = pChildList->at( i );
1978
0
            if( auto pControlData = dynamic_cast<FmControlData*>( pEntryData) )
1979
0
            {
1980
0
                _rObjects.insert(pControlData->GetFormComponent());
1981
0
            } // if( dynamic_cast<const FmControlData*>( pEntryData) !=  nullptr )
1982
0
            else if (bDeep)
1983
0
                if (auto pEntryFormData = dynamic_cast<FmFormData*>( pEntryData))
1984
0
                    CollectObjects(pEntryFormData, bDeep, _rObjects);
1985
0
        } // for( sal_uInt32 i=0; i<pChildList->Count(); i++ )
1986
0
    }
1987
1988
    void NavigatorTree::MarkViewObj( FmControlData const * pControlData)
1989
0
    {
1990
0
        if( !pControlData )
1991
0
            return;
1992
0
        FmFormShell* pFormShell = GetNavModel()->GetFormShell();
1993
0
        if( !pFormShell )
1994
0
            return;
1995
1996
1997
        // find and select appropriate SdrObj
1998
0
        FmFormView*     pFormView       = pFormShell->GetFormView();
1999
0
        const Reference< XFormComponent >&  xFormComponent( pControlData->GetFormComponent());
2000
0
        SdrPageView*    pPageView       = pFormView->GetSdrPageView();
2001
0
        SdrPage*        pPage           = pPageView->GetPage();
2002
2003
0
        bool bPaint = false;
2004
0
        SdrObjListIter aIter( pPage );
2005
0
        while ( aIter.IsMore() )
2006
0
        {
2007
0
            SdrObject* pSdrObject = aIter.Next();
2008
0
            FmFormObj* pFormObject = FmFormObj::GetFormObject( pSdrObject );
2009
0
            if ( !pFormObject )
2010
0
                continue;
2011
2012
0
            Reference< XInterface > xControlModel( pFormObject->GetUnoControlModel() );
2013
0
            if ( xControlModel != xFormComponent )
2014
0
                continue;
2015
2016
            // mark the object
2017
0
            if ( !pFormView->IsObjMarked( pSdrObject ) )
2018
                // unfortunately, the writer doesn't like marking an already-marked object, again, so reset the mark first
2019
0
                pFormView->MarkObj( pSdrObject, pPageView );
2020
2021
0
            bPaint = true;
2022
2023
0
        } // while ( aIter.IsMore() )
2024
0
        if ( !bPaint )
2025
0
            return;
2026
2027
        // make the mark visible
2028
0
        ::tools::Rectangle aMarkRect( pFormView->GetAllMarkedRect());
2029
0
        for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2030
0
        {
2031
0
            SdrPaintWindow* pPaintWindow = pFormView->GetPaintWindow( i );
2032
0
            OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
2033
0
            if ( OUTDEV_WINDOW == rOutDev.GetOutDevType() )
2034
0
            {
2035
0
                pFormView->MakeVisible( aMarkRect, *rOutDev.GetOwnerWindow() );
2036
0
            }
2037
0
        } // for ( sal_uInt32 i = 0; i < pFormView->PaintWindowCount(); ++i )
2038
0
    }
2039
2040
2041
}
2042
2043
2044
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */