1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/color.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/ptrstyle.hxx>
24 #include <hyperlabel.hxx>
28 HyperLabel::HyperLabel( vcl::Window
* _pParent
, WinBits _nWinStyle
)
29 :FixedText( _pParent
, _nWinStyle
)
38 Size
const & HyperLabel::CalcMinimumSize( tools::Long nMaxWidth
)
40 m_aMinSize
= FixedText::CalcMinimumSize( nMaxWidth
);
41 // the MinimumSize is used to size the FocusRectangle
42 // and for the MouseMove method
43 m_aMinSize
.AdjustHeight(2 );
44 m_aMinSize
.AdjustWidth(1 );
48 void HyperLabel::implInit()
50 ToggleBackgroundColor( COL_TRANSPARENT
);
52 WinBits nWinStyle
= GetStyle();
53 nWinStyle
|= WB_EXTRAOFFSET
;
54 SetStyle( nWinStyle
);
59 void HyperLabel::ToggleBackgroundColor( const Color
& _rGBColor
)
61 SetControlBackground( _rGBColor
);
64 void HyperLabel::MouseMove( const MouseEvent
& rMEvt
)
66 vcl::Font aFont
= GetControlFont( );
68 bool bHyperMode
= false;
69 if (!rMEvt
.IsLeaveWindow() && IsEnabled() && bInteractive
)
71 Point aPoint
= GetPointerPosPixel();
72 if (aPoint
.X() < m_aMinSize
.Width())
76 m_bHyperMode
= bHyperMode
;
79 aFont
.SetUnderline(LINESTYLE_SINGLE
);
80 SetPointer(PointerStyle::RefHand
);
84 aFont
.SetUnderline(LINESTYLE_NONE
);
85 SetPointer(PointerStyle::Arrow
);
87 SetControlFont(aFont
);
90 void HyperLabel::MouseButtonDown( const MouseEvent
& )
92 if ( m_bHyperMode
&& bInteractive
)
94 maClickHdl
.Call( this );
98 void HyperLabel::GetFocus()
100 if ( IsEnabled() && bInteractive
)
103 tools::Rectangle
rRect(aPoint
, Size( m_aMinSize
.Width(), GetSizePixel().Height() ) );
108 void HyperLabel::LoseFocus()
113 HyperLabel::~HyperLabel( )
118 void HyperLabel::SetInteractive( bool _bInteractive
)
120 bInteractive
= ( _bInteractive
&& IsEnabled() );
123 sal_Int16
HyperLabel::GetID() const
128 sal_Int32
HyperLabel::GetIndex() const
133 void HyperLabel::SetID( sal_Int16 newID
)
138 void HyperLabel::SetIndex( sal_Int32 newIndex
)
143 void HyperLabel::SetLabel( const OUString
& _rText
)
148 void HyperLabel::ApplySettings(vcl::RenderContext
& rRenderContext
)
150 FixedText::ApplySettings(rRenderContext
);
152 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
153 if (GetControlBackground() == COL_TRANSPARENT
)
154 rRenderContext
.SetTextColor(rStyleSettings
.GetFieldTextColor());
156 rRenderContext
.SetTextColor(rStyleSettings
.GetHighlightTextColor());
159 void HyperLabel::DataChanged( const DataChangedEvent
& rDCEvt
)
161 FixedText::DataChanged( rDCEvt
);
163 if ((( rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) ||
164 ( rDCEvt
.GetType() == DataChangedEventType::DISPLAY
)) &&
165 ( rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
167 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
168 if (GetControlBackground() != COL_TRANSPARENT
)
169 SetControlBackground(rStyleSettings
.GetHighlightColor());
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */