Coverage Report

Created: 2025-12-31 10:39

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