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>
41 HyperLabelImpl::HyperLabelImpl()
49 HyperLabel::HyperLabel( vcl::Window
* _pParent
, WinBits _nWinStyle
)
50 :FixedText( _pParent
, _nWinStyle
)
51 ,m_pImpl( new HyperLabelImpl
)
56 Size
const & HyperLabel::CalcMinimumSize( long nMaxWidth
) const
58 m_pImpl
->m_aMinSize
= FixedText::CalcMinimumSize( nMaxWidth
);
59 // the MinimumSize is used to size the FocusRectangle
60 // and for the MouseMove method
61 m_pImpl
->m_aMinSize
.AdjustHeight(2 );
62 m_pImpl
->m_aMinSize
.AdjustWidth(1 );
63 return m_pImpl
->m_aMinSize
;
66 void HyperLabel::implInit()
68 ToggleBackgroundColor( COL_TRANSPARENT
);
70 WinBits nWinStyle
= GetStyle();
71 nWinStyle
|= WB_EXTRAOFFSET
;
72 SetStyle( nWinStyle
);
77 void HyperLabel::ToggleBackgroundColor( const Color
& _rGBColor
)
79 SetControlBackground( _rGBColor
);
82 void HyperLabel::MouseMove( const MouseEvent
& rMEvt
)
84 vcl::Font aFont
= GetControlFont( );
86 bool bHyperMode
= false;
87 if (!rMEvt
.IsLeaveWindow() && IsEnabled() && m_pImpl
->bInteractive
)
89 Point aPoint
= GetPointerPosPixel();
90 if (aPoint
.X() < m_pImpl
->m_aMinSize
.Width())
94 m_pImpl
->m_bHyperMode
= bHyperMode
;
97 aFont
.SetUnderline(LINESTYLE_SINGLE
);
98 SetPointer(PointerStyle::RefHand
);
102 aFont
.SetUnderline(LINESTYLE_NONE
);
103 SetPointer(PointerStyle::Arrow
);
105 SetControlFont(aFont
);
108 void HyperLabel::MouseButtonDown( const MouseEvent
& )
110 if ( m_pImpl
->m_bHyperMode
&& m_pImpl
->bInteractive
)
112 maClickHdl
.Call( this );
116 void HyperLabel::GetFocus()
118 if ( IsEnabled() && m_pImpl
->bInteractive
)
121 tools::Rectangle
rRect(aPoint
, Size( m_pImpl
->m_aMinSize
.Width(), GetSizePixel().Height() ) );
126 void HyperLabel::LoseFocus()
131 HyperLabel::~HyperLabel( )
136 void HyperLabel::dispose()
139 FixedText::dispose();
142 void HyperLabel::SetInteractive( bool _bInteractive
)
144 m_pImpl
->bInteractive
= ( _bInteractive
&& IsEnabled() );
147 sal_Int16
HyperLabel::GetID() const
152 sal_Int32
HyperLabel::GetIndex() const
154 return m_pImpl
->Index
;
157 void HyperLabel::SetID( sal_Int16 ID
)
162 void HyperLabel::SetIndex( sal_Int32 Index
)
164 m_pImpl
->Index
= Index
;
167 void HyperLabel::SetLabel( const OUString
& _rText
)
172 void HyperLabel::ApplySettings(vcl::RenderContext
& rRenderContext
)
174 FixedText::ApplySettings(rRenderContext
);
176 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
177 if (GetControlBackground() == COL_TRANSPARENT
)
178 rRenderContext
.SetTextColor(rStyleSettings
.GetFieldTextColor());
180 rRenderContext
.SetTextColor(rStyleSettings
.GetHighlightTextColor());
183 void HyperLabel::DataChanged( const DataChangedEvent
& rDCEvt
)
185 FixedText::DataChanged( rDCEvt
);
187 if ((( rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) ||
188 ( rDCEvt
.GetType() == DataChangedEventType::DISPLAY
)) &&
189 ( rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
191 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
192 if (GetControlBackground() != COL_TRANSPARENT
)
193 SetControlBackground(rStyleSettings
.GetHighlightColor());
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */