Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/control/hyperlabel.cxx
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
#include <vcl/event.hxx>
21
#include <vcl/ptrstyle.hxx>
22
23
#include <hyperlabel.hxx>
24
25
namespace vcl
26
{
27
    HyperLabel::HyperLabel( vcl::Window* _pParent, WinBits _nWinStyle )
28
0
        :FixedText( _pParent, _nWinStyle )
29
0
        , ID(0)
30
0
        , Index(0)
31
0
        , bInteractive(false)
32
0
        , m_bHyperMode(false)
33
0
    {
34
0
        ToggleBackgroundColor( COL_TRANSPARENT );
35
36
0
        WinBits nWinStyle = GetStyle();
37
0
        nWinStyle |= WB_EXTRAOFFSET;
38
0
        SetStyle( nWinStyle );
39
40
0
        Show();
41
0
    }
Unexecuted instantiation: vcl::HyperLabel::HyperLabel(vcl::Window*, long)
Unexecuted instantiation: vcl::HyperLabel::HyperLabel(vcl::Window*, long)
42
43
    Size const & HyperLabel::CalcMinimumSize( tools::Long nMaxWidth )
44
0
    {
45
0
        m_aMinSize = FixedText::CalcMinimumSize( nMaxWidth );
46
        // the MinimumSize is used to size the FocusRectangle
47
        // and for the MouseMove method
48
0
        m_aMinSize.AdjustHeight(2 );
49
0
        m_aMinSize.AdjustWidth(1 );
50
0
        return m_aMinSize;
51
0
    }
52
53
    void HyperLabel::ToggleBackgroundColor( const Color& _rGBColor )
54
0
    {
55
0
        SetControlBackground( _rGBColor );
56
0
    }
57
58
    void HyperLabel::MouseMove( const MouseEvent& rMEvt )
59
0
    {
60
0
        vcl::Font aFont = GetControlFont( );
61
62
0
        bool bHyperMode = false;
63
0
        if (!rMEvt.IsLeaveWindow() && IsEnabled() && bInteractive)
64
0
        {
65
0
            Point aPoint = GetPointerPosPixel();
66
0
            if (aPoint.X() < m_aMinSize.Width())
67
0
                bHyperMode = true;
68
0
        }
69
70
0
        m_bHyperMode = bHyperMode;
71
0
        if (bHyperMode)
72
0
        {
73
0
            aFont.SetUnderline(LINESTYLE_SINGLE);
74
0
            SetPointer(PointerStyle::RefHand);
75
0
        }
76
0
        else
77
0
        {
78
0
            aFont.SetUnderline(LINESTYLE_NONE);
79
0
            SetPointer(PointerStyle::Arrow);
80
0
        }
81
0
        SetControlFont(aFont);
82
0
    }
83
84
    void HyperLabel::MouseButtonDown( const MouseEvent& )
85
0
    {
86
0
        if ( m_bHyperMode && bInteractive )
87
0
        {
88
0
            maClickHdl.Call( this );
89
0
        }
90
0
    }
91
92
    void HyperLabel::GetFocus()
93
0
    {
94
0
        if ( IsEnabled() && bInteractive )
95
0
        {
96
0
            Point aPoint(0,0);
97
0
            tools::Rectangle rRect(aPoint, Size( m_aMinSize.Width(), GetSizePixel().Height() ) );
98
0
            ShowFocus( rRect );
99
0
        }
100
0
    }
101
102
    void HyperLabel::LoseFocus()
103
0
    {
104
0
        HideFocus();
105
0
    }
106
107
    HyperLabel::~HyperLabel( )
108
0
    {
109
0
        disposeOnce();
110
0
    }
111
112
    void HyperLabel::SetInteractive( bool _bInteractive )
113
0
    {
114
0
        bInteractive = ( _bInteractive && IsEnabled() );
115
0
    }
116
117
    sal_Int16 HyperLabel::GetID() const
118
0
    {
119
0
        return ID;
120
0
    }
121
122
    sal_Int32 HyperLabel::GetIndex() const
123
0
    {
124
0
        return Index;
125
0
    }
126
127
    void HyperLabel::SetID( sal_Int16 newID )
128
0
    {
129
0
        this->ID = newID;
130
0
    }
131
132
    void HyperLabel::SetIndex( sal_Int32 newIndex )
133
0
    {
134
0
        Index = newIndex;
135
0
    }
136
137
    void HyperLabel::SetLabel( const OUString& _rText )
138
0
    {
139
0
        SetText(_rText);
140
0
    }
141
142
    void HyperLabel::ApplySettings(vcl::RenderContext& rRenderContext)
143
0
    {
144
0
        FixedText::ApplySettings(rRenderContext);
145
146
0
        const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
147
0
        if (GetControlBackground() == COL_TRANSPARENT)
148
0
            rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
149
0
        else
150
0
            rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
151
0
    }
152
153
    void HyperLabel::DataChanged( const DataChangedEvent& rDCEvt )
154
0
    {
155
0
        FixedText::DataChanged( rDCEvt );
156
157
0
        if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS
158
0
             || rDCEvt.GetType() == DataChangedEventType::DISPLAY)
159
0
            && rDCEvt.GetFlags() & AllSettingsFlags::STYLE)
160
0
        {
161
0
            const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
162
0
            if (GetControlBackground() != COL_TRANSPARENT)
163
0
                SetControlBackground(rStyleSettings.GetHighlightColor());
164
0
            Invalidate();
165
0
        }
166
0
    }
167
168
}   // namespace vcl
169
170
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */