Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/inc/sdtreelb.hxx
Line
Count
Source (jump to first uncovered line)
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
#pragma once
21
22
#include <pres.hxx>
23
#include <sddllapi.h>
24
#include <vcl/weld.hxx>
25
#include <svl/urlbmk.hxx>
26
#include <tools/ref.hxx>
27
#include "sdxfer.hxx"
28
#include <memory>
29
#include <vector>
30
31
class SdrView;
32
class SdDrawDocument;
33
class SfxMedium;
34
class SfxViewFrame;
35
class SdNavigatorWin;
36
class SdrObject;
37
class SdrObjList;
38
class SdPage;
39
struct ImplSVEvent;
40
41
namespace sd {
42
class ViewShell;
43
44
class DrawDocShell;
45
#ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED
46
#define SV_DECL_DRAW_DOC_SHELL_DEFINED
47
typedef rtl::Reference<DrawDocShell> DrawDocShellRef;
48
#endif
49
}
50
namespace svt {
51
    class AcceleratorExecute;
52
}
53
54
class SdPageObjsTLVDropTarget final : public DropTargetHelper
55
{
56
private:
57
    weld::TreeView& m_rTreeView;
58
    SdrView* m_pSdrView;
59
    bool m_bOrderFrontToBack = false;
60
61
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
62
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
63
64
public:
65
    SdPageObjsTLVDropTarget(weld::TreeView& rTreeView);
66
67
0
    void SetDrawView(SdrView* pSdrView) { m_pSdrView = pSdrView; }
68
0
    void SetOrderFrontToBack(bool bSet) { m_bOrderFrontToBack = bSet; }
69
};
70
71
class SdPageObjsTLV
72
{
73
private:
74
    std::unique_ptr<weld::TreeView> m_xTreeView;
75
    std::unique_ptr<weld::TreeIter> m_xScratchIter;
76
    std::unique_ptr<SdPageObjsTLVDropTarget> m_xDropTargetHelper;
77
    std::unique_ptr<::svt::AcceleratorExecute> m_xAccel;
78
    SdNavigatorWin* m_pNavigator;
79
    const SdDrawDocument* m_pDoc;
80
    SdDrawDocument* m_pBookmarkDoc;
81
    SfxMedium* m_pMedium;
82
    SfxMedium* m_pOwnMedium;
83
    bool m_bLinkableSelected;
84
    bool m_bShowAllShapes;
85
    bool m_bOrderFrontToBack;
86
87
    /** This flag controls whether to show all pages.
88
    */
89
    bool m_bShowAllPages;
90
91
    /**
92
     * If changing the selection should also result in navigating to the
93
     * relevant shape.
94
     */
95
    bool m_bSelectionHandlerNavigates;
96
97
    /**
98
     * If navigation should not only select the relevant shape but also change
99
     * focus to it.
100
     */
101
    bool m_bNavigationGrabsFocus;
102
103
    bool m_bEditing = false;
104
105
    SelectionMode m_eSelectionMode;
106
107
    ImplSVEvent* m_nSelectEventId;
108
    ImplSVEvent* m_nRowActivateEventId;
109
110
    OUString m_aDocName;
111
    ::sd::DrawDocShellRef m_xBookmarkDocShRef; ///< for the loading of bookmarks
112
    Link<weld::TreeView&, void> m_aChangeHdl;
113
    Link<weld::TreeView&, bool> m_aRowActivatedHdl;
114
    Link<const KeyEvent&, bool> m_aKeyPressHdl;
115
    Link<const MouseEvent&, bool> m_aMouseReleaseHdl;
116
    Link<const CommandEvent&, bool> m_aPopupMenuHdl;
117
118
    /** Return the name of the object.  When the object has no user supplied
119
        name and the bCreate flag is <TRUE/> then a name is created
120
        automatically.  Additionally the mbShowAllShapes flag is taken into
121
        account when there is no user supplied name.  When this flag is
122
        <FALSE/> then no name is created.
123
        @param pObject
124
            When this is NULL then an empty string is returned, regardless
125
            of the value of bCreate.
126
        @param bCreate
127
            This flag controls for objects without user supplied name
128
            whether a name is created.  When a name is created then this
129
            name is not stored in the object.
130
    */
131
    OUString GetObjectName (
132
        const SdrObject* pObject,
133
        const bool bCreate = true) const;
134
135
    void CloseBookmarkDoc();
136
137
    DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool);
138
    DECL_LINK(SelectHdl, weld::TreeView&, void);
139
    DECL_LINK(AsyncSelectHdl, void*, void);
140
    DECL_LINK(RowActivatedHdl, weld::TreeView&, bool);
141
    DECL_LINK(AsyncRowActivatedHdl, void*, void);
142
    DECL_LINK(DragBeginHdl, bool&, bool);
143
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
144
145
    DECL_LINK(EditingEntryHdl, const weld::TreeIter&, bool);
146
    typedef std::pair<const weld::TreeIter&, OUString> IterString;
147
    DECL_LINK(EditedEntryHdl, const IterString&, bool);
148
    DECL_LINK(EditEntryAgain, void*, void);
149
150
    DECL_LINK(CommandHdl, const CommandEvent&, bool);
151
152
    /** Determine whether the specified page belongs to the current show
153
        which is either the standard show or a custom show.
154
        @param pPage
155
            Pointer to the page for which to check whether it belongs to the
156
            show.
157
        @return
158
            Returns <FALSE/> if there is no custom show or if the current
159
            show does not contain the specified page at least once.
160
    */
161
    bool PageBelongsToCurrentShow (const SdPage* pPage) const;
162
163
    bool DoDrag();
164
165
    // DragSourceHelper
166
    bool StartDrag();
167
168
public:
169
170
    SD_DLLPUBLIC SdPageObjsTLV(std::unique_ptr<weld::TreeView> xTreeview);
171
    SD_DLLPUBLIC ~SdPageObjsTLV();
172
173
    void hide()
174
0
    {
175
0
        m_xTreeView->hide();
176
0
    }
177
178
    void show()
179
0
    {
180
0
        m_xTreeView->show();
181
0
    }
182
183
    void grab_focus()
184
0
    {
185
0
        m_xTreeView->grab_focus();
186
0
    }
187
188
    void set_size_request(int nWidth, int nHeight)
189
0
    {
190
0
        m_xTreeView->set_size_request(nWidth, nHeight);
191
0
    }
192
193
    float get_approximate_digit_width() const
194
0
    {
195
0
        return m_xTreeView->get_approximate_digit_width();
196
0
    }
197
198
    DECL_LINK(MousePressHdl, const MouseEvent&, SD_DLLPUBLIC bool);
199
    DECL_LINK(MouseReleaseHdl, const MouseEvent&, SD_DLLPUBLIC bool);
200
201
    SD_DLLPUBLIC void Select();
202
203
    int get_height_rows(int nRows) const
204
0
    {
205
0
        return m_xTreeView->get_height_rows(nRows);
206
0
    }
207
208
    void set_selection_mode(SelectionMode eMode)
209
0
    {
210
0
        m_eSelectionMode = eMode;
211
0
        m_xTreeView->set_selection_mode(eMode);
212
0
    }
213
214
    SelectionMode get_selection_mode() const
215
0
    {
216
0
        return m_eSelectionMode;
217
0
    }
218
219
    void connect_row_activated(const Link<weld::TreeView&, bool>& rLink)
220
0
    {
221
0
        m_aRowActivatedHdl = rLink;
222
0
    }
223
224
    void connect_key_press(const Link<const KeyEvent&, bool>& rLink)
225
0
    {
226
0
        m_aKeyPressHdl = rLink;
227
0
    }
228
229
    void connect_mouse_release(const Link<const MouseEvent&, bool>& rLink)
230
0
    {
231
0
        m_aMouseReleaseHdl = rLink;
232
0
    }
233
234
    void connect_popup_menu(const Link<const CommandEvent&, bool>& rLink)
235
0
    {
236
0
        m_aPopupMenuHdl = rLink;
237
0
    }
238
239
    bool HasSelectedChildren(std::u16string_view rName);
240
    SD_DLLPUBLIC bool SelectEntry(std::u16string_view rName);
241
    void SelectEntry(const SdrObject* pObj);
242
243
    OUString get_selected_text() const
244
0
    {
245
0
        return m_xTreeView->get_selected_text();
246
0
    }
247
248
    bool get_selected() const
249
0
    {
250
0
        return m_xTreeView->get_selected(nullptr);
251
0
    }
252
253
    int count_selected_rows() const
254
0
    {
255
0
        return m_xTreeView->count_selected_rows();
256
0
    }
257
258
    void connect_changed(const Link<weld::TreeView&, void>& rLink)
259
0
    {
260
0
        m_aChangeHdl = rLink;
261
0
    }
262
263
    bool is_selected(const weld::TreeIter& rIter) const
264
0
    {
265
0
        return m_xTreeView->is_selected(rIter);
266
0
    }
267
268
    bool get_iter_first(weld::TreeIter& rIter) const
269
0
    {
270
0
        return m_xTreeView->get_iter_first(rIter);
271
0
    }
272
273
    weld::TreeView& get_treeview()
274
0
    {
275
0
        return *m_xTreeView;
276
0
    }
277
278
    std::unique_ptr<weld::TreeIter> make_iterator()
279
0
    {
280
0
        return m_xTreeView->make_iterator();
281
0
    }
282
283
    bool get_visible() const
284
0
    {
285
0
        return m_xTreeView->get_visible();
286
0
    }
287
288
    void unselect_all()
289
0
    {
290
0
        m_xTreeView->unselect_all();
291
0
    }
292
293
    OUString get_cursor_text() const
294
0
    {
295
0
        std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
296
0
        if (m_xTreeView->get_cursor(xIter.get()))
297
0
            return m_xTreeView->get_text(*xIter);
298
0
        return OUString();
299
0
    }
300
301
    OUString get_cursor_id() const
302
0
    {
303
0
        std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
304
0
        if (m_xTreeView->get_cursor(xIter.get()))
305
0
            return m_xTreeView->get_id(*xIter);
306
0
        return OUString();
307
0
    }
308
309
    SD_DLLPUBLIC void SetViewFrame(const SfxViewFrame* pViewFrame);
310
311
    SD_DLLPUBLIC void Fill(const SdDrawDocument*, bool bAllPages, const OUString& rDocName);
312
    SD_DLLPUBLIC void Fill(const SdDrawDocument*, SfxMedium* pSfxMedium, const OUString& rDocName);
313
314
    void SetShowAllShapes (const bool bShowAllShapes, const bool bFill);
315
0
    bool GetShowAllShapes() const { return m_bShowAllShapes; }
316
317
    void SetOrderFrontToBack (const bool bOrderFrontToBack);
318
0
    bool GetOrderFrontToBack() const { return m_bOrderFrontToBack; }
319
320
0
    bool IsNavigationGrabsFocus() const { return m_bNavigationGrabsFocus; }
321
    SD_DLLPUBLIC bool IsEqualToDoc(const SdDrawDocument* pInDoc);
322
    /// Visits rList recursively and tries to advance rEntry accordingly.
323
    bool IsEqualToShapeList(std::unique_ptr<weld::TreeIter>& rEntry, const SdrObjList& rList,
324
                            std::u16string_view rListName);
325
326
    /** Return the view shell that is linked to the given doc shell.
327
        Call this method when the there is a chance that the doc shell
328
        has been disconnected from the view shell (but not the other
329
        way round.)
330
        @return
331
            May return <NULL/> when the link between view shell and
332
            doc shell has been severed.
333
    */
334
    static ::sd::ViewShell* GetViewShellForDocShell (::sd::DrawDocShell &rDocShell);
335
336
    /** Add one list box entry for the parent of the given shapes and one child entry for
337
        each of the given shapes.
338
        @param rList
339
            The container of shapes that are to be inserted.
340
        @param pShape
341
            The parent shape or NULL when the parent is a page.
342
        @param rsName
343
            The name to be displayed for the new parent node.
344
        @param bIsExcluded
345
            Some pages can be excluded (from the show?).
346
        @param pParentEntry
347
            The parent entry of the new parent entry.
348
    */
349
    void AddShapeList (
350
        const SdrObjList& rList,
351
        const SdrObject* pShape,
352
        const OUString& rsName,
353
        const bool bIsExcluded,
354
        const weld::TreeIter* pParentEntry);
355
356
    /** Add the given object to a transferable object so that the object can
357
        be dragged and dropped without having a name.
358
    */
359
    void AddShapeToTransferable (
360
        SdTransferable& rTransferable,
361
        const SdrObject& rObject) const;
362
363
    /** return selected entries
364
          nDepth == 0 -> pages
365
          nDepth == 1 -> objects  */
366
367
    SD_DLLPUBLIC std::vector<OUString> GetSelectEntryList(const int nDepth) const;
368
369
    std::vector<OUString> GetSelectedEntryIds() const;
370
371
    SD_DLLPUBLIC SdDrawDocument* GetBookmarkDoc(SfxMedium* pMedium = nullptr);
372
373
0
    bool IsLinkableSelected() const { return m_bLinkableSelected; }
374
375
    void InsertEntry(const OUString &rName, const OUString &rExpander)
376
0
    {
377
0
        m_xTreeView->insert(nullptr, -1, &rName, nullptr, nullptr, nullptr, false, m_xScratchIter.get());
378
0
        m_xTreeView->set_image(*m_xScratchIter, rExpander);
379
0
    }
380
381
    void InsertEntry(const weld::TreeIter* pParent, const OUString& rId, const OUString &rName, const OUString &rExpander, weld::TreeIter* pEntry = nullptr)
382
0
    {
383
0
        if (pParent)
384
0
            m_xTreeView->insert(pParent, m_bOrderFrontToBack ? 0 : -1, &rName, &rId, nullptr,
385
0
                                nullptr, false, m_xScratchIter.get());
386
0
        else
387
            // always append page/slide entry
388
0
            m_xTreeView->insert(nullptr, -1, &rName, &rId, nullptr, nullptr, false, m_xScratchIter.get());
389
0
        m_xTreeView->set_image(*m_xScratchIter, rExpander);
390
0
        if (pEntry)
391
0
            m_xTreeView->copy_iterator(*m_xScratchIter, *pEntry);
392
0
    }
393
394
    //Mark Current Entry
395
    void SetSdNavigator(SdNavigatorWin* pNavigator);
396
397
    void clear()
398
0
    {
399
0
        m_xTreeView->clear();
400
0
    }
401
402
    // nested class to implement the TransferableHelper
403
    class SdPageObjsTransferable final : public SdTransferable
404
    {
405
    public:
406
        SdPageObjsTransferable(
407
            INetBookmark aBookmark,
408
            ::sd::DrawDocShell& rDocShell,
409
            NavigatorDragType eDragType );
410
0
        ::sd::DrawDocShell&     GetDocShell() const { return mrDocShell;}
411
0
        NavigatorDragType   GetDragType() const { return meDragType;}
412
413
        static SdPageObjsTransferable* getImplementation( const css::uno::Reference< css::uno::XInterface >& rxData ) noexcept;
414
        /** Return a temporary transferable data flavor that is used
415
            internally in the navigator for reordering entries.  Its
416
            lifetime ends with the office application.
417
        */
418
        static SotClipboardFormatId GetListBoxDropFormatId();
419
420
    private:
421
        /** Temporary drop flavor id that is used internally in the
422
            navigator.
423
        */
424
        static SotClipboardFormatId mnListBoxDropFormatId;
425
426
        INetBookmark const      maBookmark;
427
        ::sd::DrawDocShell&     mrDocShell;
428
        NavigatorDragType const   meDragType;
429
        virtual               ~SdPageObjsTransferable() override;
430
431
        virtual void      AddSupportedFormats() override;
432
        virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
433
    };
434
435
    friend class SdPageObjsTLV::SdPageObjsTransferable;
436
437
private:
438
    rtl::Reference<SdPageObjsTransferable> m_xHelper;
439
};
440
441
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */