Simplify using designated initializers
[LibreOffice.git] / vcl / source / control / hyperlabel.cxx
blob34f10750ae2b820e4f200306cd3657c165998462
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 HyperLabel::HyperLabel( vcl::Window* _pParent, WinBits _nWinStyle )
29 :FixedText( _pParent, _nWinStyle )
30 , ID(0)
31 , Index(0)
32 , bInteractive(false)
33 , m_bHyperMode(false)
35 implInit();
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 );
45 return m_aMinSize;
48 void HyperLabel::implInit()
50 ToggleBackgroundColor( COL_TRANSPARENT );
52 WinBits nWinStyle = GetStyle();
53 nWinStyle |= WB_EXTRAOFFSET;
54 SetStyle( nWinStyle );
56 Show();
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())
73 bHyperMode = true;
76 m_bHyperMode = bHyperMode;
77 if (bHyperMode)
79 aFont.SetUnderline(LINESTYLE_SINGLE);
80 SetPointer(PointerStyle::RefHand);
82 else
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 )
102 Point aPoint(0,0);
103 tools::Rectangle rRect(aPoint, Size( m_aMinSize.Width(), GetSizePixel().Height() ) );
104 ShowFocus( rRect );
108 void HyperLabel::LoseFocus()
110 HideFocus();
113 HyperLabel::~HyperLabel( )
115 disposeOnce();
118 void HyperLabel::SetInteractive( bool _bInteractive )
120 bInteractive = ( _bInteractive && IsEnabled() );
123 sal_Int16 HyperLabel::GetID() const
125 return ID;
128 sal_Int32 HyperLabel::GetIndex() const
130 return Index;
133 void HyperLabel::SetID( sal_Int16 newID )
135 this->ID = newID;
138 void HyperLabel::SetIndex( sal_Int32 newIndex )
140 Index = newIndex;
143 void HyperLabel::SetLabel( const OUString& _rText )
145 SetText(_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());
155 else
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());
170 Invalidate();
174 } // namespace vcl
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */