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 <svtools/hyperlabel.hxx>
21 #include <tools/color.hxx>
22 #include <vcl/bitmap.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/tabpage.hxx>
43 HyperLabelImpl::HyperLabelImpl()
51 HyperLabel::HyperLabel( vcl::Window
* _pParent
, WinBits _nWinStyle
)
52 :FixedText( _pParent
, _nWinStyle
)
53 ,m_pImpl( new HyperLabelImpl
)
58 Size
HyperLabel::CalcMinimumSize( long nMaxWidth
) const
60 m_pImpl
->m_aMinSize
= FixedText::CalcMinimumSize( nMaxWidth
);
61 // the MinimumSize is used to size the FocusRectangle
62 // and for the MouseMove method
63 m_pImpl
->m_aMinSize
.Height() += 2;
64 m_pImpl
->m_aMinSize
.Width() += 1;
65 return m_pImpl
->m_aMinSize
;
68 void HyperLabel::implInit()
70 ToggleBackgroundColor( COL_TRANSPARENT
);
72 WinBits nWinStyle
= GetStyle();
73 nWinStyle
|= WB_EXTRAOFFSET
;
74 SetStyle( nWinStyle
);
79 void HyperLabel::ToggleBackgroundColor( const Color
& _rGBColor
)
81 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
82 SetControlBackground( _rGBColor
);
83 if (_rGBColor
== COL_TRANSPARENT
)
84 SetTextColor( rStyleSettings
.GetFieldTextColor( ) );
86 SetTextColor( rStyleSettings
.GetHighlightTextColor( ) );
90 void HyperLabel::MouseMove( const MouseEvent
& rMEvt
)
92 vcl::Font aFont
= GetControlFont( );
93 const Color aColor
= GetTextColor();
95 if (rMEvt
.IsLeaveWindow())
97 DeactivateHyperMode(aFont
, aColor
);
101 Point aPoint
= GetPointerPosPixel();
102 if (aPoint
.X() < m_pImpl
->m_aMinSize
.Width())
104 if ( IsEnabled() && (m_pImpl
->bInteractive
) )
106 ActivateHyperMode( aFont
, aColor
);
110 DeactivateHyperMode(aFont
, aColor
);
114 void HyperLabel::ActivateHyperMode(vcl::Font aFont
, const Color aColor
)
116 aFont
.SetUnderline(UNDERLINE_SINGLE
);
117 m_pImpl
->m_bHyperMode
= true;
118 SetPointer( PointerStyle::RefHand
);
119 SetControlFont( aFont
);
120 SetTextColor( aColor
);
124 void HyperLabel::DeactivateHyperMode(vcl::Font aFont
, const Color aColor
)
126 m_pImpl
->m_bHyperMode
= false;
127 aFont
.SetUnderline(UNDERLINE_NONE
);
128 SetPointer( PointerStyle::Arrow
);
129 SetControlFont( aFont
);
130 SetTextColor( aColor
);
133 void HyperLabel::MouseButtonDown( const MouseEvent
& )
135 if ( m_pImpl
->m_bHyperMode
&& m_pImpl
->bInteractive
)
137 maClickHdl
.Call( this );
141 void HyperLabel::GetFocus()
143 if ( IsEnabled() && m_pImpl
->bInteractive
)
146 Rectangle
rRect(aPoint
, Size( m_pImpl
->m_aMinSize
.Width(), GetSizePixel().Height() ) );
151 void HyperLabel::LoseFocus()
156 HyperLabel::~HyperLabel( )
161 void HyperLabel::dispose()
164 FixedText::dispose();
167 void HyperLabel::SetInteractive( bool _bInteractive
)
169 m_pImpl
->bInteractive
= ( _bInteractive
&& IsEnabled() );
172 sal_Int16
HyperLabel::GetID() const
177 sal_Int32
HyperLabel::GetIndex() const
179 return m_pImpl
->Index
;
182 void HyperLabel::SetID( sal_Int16 _ID
)
187 void HyperLabel::SetIndex( sal_Int32 _Index
)
189 m_pImpl
->Index
= _Index
;
192 void HyperLabel::SetLabel( const OUString
& _rText
)
199 void HyperLabel::DataChanged( const DataChangedEvent
& rDCEvt
)
201 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
202 FixedText::DataChanged( rDCEvt
);
203 if ((( rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) ||
204 ( rDCEvt
.GetType() == DataChangedEventType::DISPLAY
)) &&
205 ( rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
207 const Color
& rGBColor
= GetControlBackground();
208 if (rGBColor
== COL_TRANSPARENT
)
209 SetTextColor( rStyleSettings
.GetFieldTextColor( ) );
212 SetControlBackground(rStyleSettings
.GetHighlightColor());
213 SetTextColor( rStyleSettings
.GetHighlightTextColor( ) );
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */