Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/weld/ItemView.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10
#pragma once
11
12
#include <vcl/dllapi.h>
13
#include <vcl/weld/TreeIter.hxx>
14
#include <vcl/weld/Widget.hxx>
15
16
namespace weld
17
{
18
/* Abstract base class for TreeView and IconView. */
19
class VCL_DLLPUBLIC ItemView : virtual public Widget
20
{
21
    OUString m_sSavedValue;
22
23
    Link<const TreeIter&, bool> m_aItemActivatedHdl;
24
    Link<ItemView&, void> m_aSelectionChangeHdl;
25
26
protected:
27
    bool signal_item_activated(const TreeIter& rIter);
28
    void signal_selection_changed();
29
30
    virtual void do_set_cursor(const TreeIter& rIter) = 0;
31
32
    virtual void do_select(const TreeIter& rIter) = 0;
33
    virtual void do_unselect(const TreeIter& rIter) = 0;
34
35
    virtual void do_select_all() = 0;
36
    virtual void do_unselect_all() = 0;
37
38
    virtual void do_remove(const TreeIter& rIter) = 0;
39
40
    virtual void do_clear() = 0;
41
42
public:
43
    virtual std::unique_ptr<TreeIter> make_iterator(const TreeIter* pOrig = nullptr) const = 0;
44
45
    virtual bool get_iter_first(TreeIter& rIter) const = 0;
46
    // set iter to point to next node at the current level
47
    virtual bool iter_next_sibling(TreeIter& rIter) const = 0;
48
49
    virtual int get_iter_index_in_parent(const TreeIter& rIter) const = 0;
50
51
    virtual std::unique_ptr<TreeIter> get_iterator(int nPos) const = 0;
52
53
    OUString get_id(int pos) const;
54
    virtual OUString get_id(const TreeIter& rIter) const = 0;
55
    void set_id(int pos, const OUString& rId);
56
    virtual void set_id(const TreeIter& rIter, const OUString& rId) = 0;
57
58
    OUString get_selected_id() const;
59
    virtual OUString get_selected_text() const = 0;
60
61
    virtual std::unique_ptr<weld::TreeIter> get_selected() const = 0;
62
    int get_selected_index() const;
63
64
    int get_cursor_index() const;
65
    virtual std::unique_ptr<TreeIter> get_cursor() const = 0;
66
    void set_cursor(const TreeIter& rIter);
67
68
    // Don't select when frozen, select after thaw. Note selection doesn't survive a freeze.
69
    void select(int pos);
70
    void select(const TreeIter& rIter);
71
72
    void unselect(int pos);
73
    void unselect(const TreeIter& rIter);
74
75
    void select_all();
76
    void unselect_all();
77
78
    // return the number of toplevel nodes
79
    virtual int n_children() const = 0;
80
81
    void remove(int pos);
82
    void remove(const TreeIter& rIter);
83
84
    void clear();
85
86
    // call func on each selected element until func returns true or we run out of elements
87
    virtual void selected_foreach(const std::function<bool(TreeIter&)>& func) = 0;
88
89
0
    void save_value() { m_sSavedValue = get_selected_text(); }
90
0
    bool get_value_changed_from_saved() const { return m_sSavedValue != get_selected_text(); }
91
92
    /* An item/row is "activated" when the user double clicks a treeview row or IconView item.
93
     * It may also be emitted when it is selected and Space or Enter is pressed.
94
95
       A return value of "true" means the activation has been handled, a "false" propagates
96
       the activation to the default handler which expands/collapses the row, if possible.
97
    */
98
    void connect_item_activated(const Link<const TreeIter&, bool>& rLink)
99
0
    {
100
0
        m_aItemActivatedHdl = rLink;
101
0
    }
102
103
    void connect_selection_changed(const Link<ItemView&, void>& rLink)
104
0
    {
105
0
        m_aSelectionChangeHdl = rLink;
106
0
    }
107
};
108
}
109
110
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */