Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/SvLBoxButton.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
 * 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 <tools/link.hxx>
23
#include <vcl/image.hxx>
24
#include <vcl/toolkit/svlbitm.hxx>
25
26
#include <map>
27
#include <memory>
28
29
class SvLBoxButton;
30
31
class SvLBoxButtonData
32
{
33
private:
34
    Link<SvLBoxButtonData*, void> m_aLink;
35
    Size m_aSize;
36
    std::map<SvBmp, Image> m_aBmps;
37
38
    SvTreeListEntry* m_pEntry;
39
    SvLBoxButton* m_pBox;
40
    bool m_bShowRadioButton;
41
42
public:
43
    // include creating default images (CheckBox or RadioButton)
44
    SvLBoxButtonData(const Control& rControlForSettings, bool _bRadioBtn);
45
46
    ~SvLBoxButtonData();
47
48
    static SvBmp GetIndex(SvItemStateFlags nItemState);
49
    const Size& GetSize();
50
0
    void SetLink(const Link<SvLBoxButtonData*, void>& rLink) { m_aLink = rLink; }
51
    void CallLink(SvTreeListEntry* pActEntry, SvLBoxButton* pActBox);
52
    bool IsRadio() const;
53
54
    static SvButtonState ConvertToButtonState(SvItemStateFlags nItemFlags);
55
56
    SvTreeListEntry* GetActEntry() const;
57
    SvLBoxButton* GetActBox() const;
58
59
0
    const Image& GetImage(SvBmp eIndex) const { return m_aBmps.at(eIndex); }
60
61
    void SetDefaultImages(const Control& rControlForSettings);
62
    // set images according to the color scheme of the Control
63
};
64
65
class SvLBoxButton final : public SvLBoxItem
66
{
67
    bool m_bIsVis;
68
    SvLBoxButtonData& m_rData;
69
    SvItemStateFlags m_nItemFlags;
70
71
    static void ImplAdjustBoxSize(Size& io_rCtrlSize, ControlType i_eType,
72
                                  vcl::RenderContext const& pRenderContext);
73
74
public:
75
    SvLBoxButton(SvLBoxButtonData& rBData, bool bIsVis = true);
76
    virtual ~SvLBoxButton() override;
77
    virtual void InitViewData(SvTreeListBox& rView, SvTreeListEntry& rEntry,
78
                              SvViewDataItem* pViewData = nullptr) override;
79
80
    virtual SvLBoxItemType GetType() const override;
81
    void ClickHdl(SvTreeListEntry*);
82
83
    virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
84
                       vcl::RenderContext& rRenderContext, const SvViewDataEntry* pView,
85
                       const SvTreeListEntry& rEntry) override;
86
87
    virtual std::unique_ptr<SvLBoxItem> Clone(SvLBoxItem const* pSource) const override;
88
89
0
    SvItemStateFlags GetButtonFlags() const { return m_nItemFlags; }
90
0
    bool IsStateChecked() const { return bool(m_nItemFlags & SvItemStateFlags::CHECKED); }
91
0
    bool IsStateUnchecked() const { return bool(m_nItemFlags & SvItemStateFlags::UNCHECKED); }
92
0
    bool IsStateTristate() const { return bool(m_nItemFlags & SvItemStateFlags::TRISTATE); }
93
0
    bool IsStateHilighted() const { return bool(m_nItemFlags & SvItemStateFlags::HIGHLIGHTED); }
94
    void SetStateChecked();
95
    void SetStateUnchecked();
96
    void SetStateTristate();
97
    void SetStateHilighted(bool bHilight);
98
};
99
100
inline void SvLBoxButton::SetStateChecked()
101
0
{
102
0
    m_nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
103
0
    m_nItemFlags |= SvItemStateFlags::CHECKED;
104
0
}
105
106
inline void SvLBoxButton::SetStateUnchecked()
107
0
{
108
0
    m_nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
109
0
    m_nItemFlags |= SvItemStateFlags::UNCHECKED;
110
0
}
111
inline void SvLBoxButton::SetStateTristate()
112
0
{
113
0
    m_nItemFlags &= SvItemStateFlags::HIGHLIGHTED;
114
0
    m_nItemFlags |= SvItemStateFlags::TRISTATE;
115
0
}
116
inline void SvLBoxButton::SetStateHilighted(bool bHilight)
117
0
{
118
0
    if (bHilight)
119
0
        m_nItemFlags |= SvItemStateFlags::HIGHLIGHTED;
120
0
    else
121
0
        m_nItemFlags &= ~SvItemStateFlags::HIGHLIGHTED;
122
0
}
123
124
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */