bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / control / hyperlabel.cxx
blobf42debe51ee2ff11af828f0b20c42349b5a36779
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 namespace vcl
28 class HyperLabelImpl
30 public:
31 sal_Int16 ID;
32 sal_Int32 Index;
33 bool bInteractive;
34 Size m_aMinSize;
35 bool m_bHyperMode;
37 HyperLabelImpl();
41 HyperLabelImpl::HyperLabelImpl()
42 : ID(0)
43 , Index(0)
44 , bInteractive(false)
45 , m_bHyperMode(false)
49 HyperLabel::HyperLabel( vcl::Window* _pParent, WinBits _nWinStyle )
50 :FixedText( _pParent, _nWinStyle )
51 ,m_pImpl( new HyperLabelImpl )
53 implInit();
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 );
74 Show();
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())
91 bHyperMode = true;
94 m_pImpl->m_bHyperMode = bHyperMode;
95 if (bHyperMode)
97 aFont.SetUnderline(LINESTYLE_SINGLE);
98 SetPointer(PointerStyle::RefHand);
100 else
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 )
120 Point aPoint(0,0);
121 tools::Rectangle rRect(aPoint, Size( m_pImpl->m_aMinSize.Width(), GetSizePixel().Height() ) );
122 ShowFocus( rRect );
126 void HyperLabel::LoseFocus()
128 HideFocus();
131 HyperLabel::~HyperLabel( )
133 disposeOnce();
136 void HyperLabel::dispose()
138 m_pImpl.reset();
139 FixedText::dispose();
142 void HyperLabel::SetInteractive( bool _bInteractive )
144 m_pImpl->bInteractive = ( _bInteractive && IsEnabled() );
147 sal_Int16 HyperLabel::GetID() const
149 return m_pImpl->ID;
152 sal_Int32 HyperLabel::GetIndex() const
154 return m_pImpl->Index;
157 void HyperLabel::SetID( sal_Int16 ID )
159 m_pImpl->ID = ID;
162 void HyperLabel::SetIndex( sal_Int32 Index )
164 m_pImpl->Index = Index;
167 void HyperLabel::SetLabel( const OUString& _rText )
169 SetText(_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());
179 else
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());
194 Invalidate();
198 } // namespace vcl
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */