LibreOffice Module vcl (master)  1
hyperlabel.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <tools/color.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/ptrstyle.hxx>
24 #include <hyperlabel.hxx>
25 
26 namespace vcl
27 {
29  {
30  public:
31  sal_Int16 ID;
32  sal_Int32 Index;
36 
38  };
39 
40 
42  : ID(0)
43  , Index(0)
44  , bInteractive(false)
45  , m_bHyperMode(false)
46  {
47  }
48 
49  HyperLabel::HyperLabel( vcl::Window* _pParent, WinBits _nWinStyle )
50  :FixedText( _pParent, _nWinStyle )
51  ,m_pImpl( new HyperLabelImpl )
52  {
53  implInit();
54  }
55 
56  Size const & HyperLabel::CalcMinimumSize( long nMaxWidth ) const
57  {
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;
64  }
65 
67  {
69 
70  WinBits nWinStyle = GetStyle();
71  nWinStyle |= WB_EXTRAOFFSET;
72  SetStyle( nWinStyle );
73 
74  Show();
75  }
76 
77  void HyperLabel::ToggleBackgroundColor( const Color& _rGBColor )
78  {
79  SetControlBackground( _rGBColor );
80  }
81 
82  void HyperLabel::MouseMove( const MouseEvent& rMEvt )
83  {
84  vcl::Font aFont = GetControlFont( );
85 
86  bool bHyperMode = false;
87  if (!rMEvt.IsLeaveWindow() && IsEnabled() && m_pImpl->bInteractive)
88  {
89  Point aPoint = GetPointerPosPixel();
90  if (aPoint.X() < m_pImpl->m_aMinSize.Width())
91  bHyperMode = true;
92  }
93 
94  m_pImpl->m_bHyperMode = bHyperMode;
95  if (bHyperMode)
96  {
99  }
100  else
101  {
104  }
105  SetControlFont(aFont);
106  }
107 
109  {
110  if ( m_pImpl->m_bHyperMode && m_pImpl->bInteractive )
111  {
112  maClickHdl.Call( this );
113  }
114  }
115 
117  {
118  if ( IsEnabled() && m_pImpl->bInteractive )
119  {
120  Point aPoint(0,0);
121  tools::Rectangle rRect(aPoint, Size( m_pImpl->m_aMinSize.Width(), GetSizePixel().Height() ) );
122  ShowFocus( rRect );
123  }
124  }
125 
127  {
128  HideFocus();
129  }
130 
132  {
133  disposeOnce();
134  }
135 
137  {
138  m_pImpl.reset();
140  }
141 
142  void HyperLabel::SetInteractive( bool _bInteractive )
143  {
144  m_pImpl->bInteractive = ( _bInteractive && IsEnabled() );
145  }
146 
147  sal_Int16 HyperLabel::GetID() const
148  {
149  return m_pImpl->ID;
150  }
151 
152  sal_Int32 HyperLabel::GetIndex() const
153  {
154  return m_pImpl->Index;
155  }
156 
157  void HyperLabel::SetID( sal_Int16 ID )
158  {
159  m_pImpl->ID = ID;
160  }
161 
162  void HyperLabel::SetIndex( sal_Int32 Index )
163  {
164  m_pImpl->Index = Index;
165  }
166 
167  void HyperLabel::SetLabel( const OUString& _rText )
168  {
169  SetText(_rText);
170  }
171 
173  {
174  FixedText::ApplySettings(rRenderContext);
175 
176  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
178  rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
179  else
180  rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
181  }
182 
184  {
185  FixedText::DataChanged( rDCEvt );
186 
187  if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
188  ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
189  ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
190  {
191  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
193  SetControlBackground(rStyleSettings.GetHighlightColor());
194  Invalidate();
195  }
196  }
197 
198 } // namespace vcl
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point GetPointerPosPixel()
Definition: mouse.cxx:549
void HideFocus()
Definition: window2.cxx:91
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: hyperlabel.cxx:108
#define ID
const Color & GetHighlightTextColor() const
long Height() const
virtual void MouseMove(const MouseEvent &rMEvt) override
Definition: hyperlabel.cxx:82
const StyleSettings & GetStyleSettings() const
virtual Size GetSizePixel() const
Definition: window.cxx:2364
DataChangedEventType GetType() const
Definition: event.hxx:348
const Color & GetControlBackground() const
Definition: window2.cxx:1071
const Color & GetFieldTextColor() const
sal_Int16 GetID() const
Definition: hyperlabel.cxx:147
const Color & GetHighlightColor() const
sal_Int64 WinBits
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
void SetControlFont()
Definition: window2.cxx:409
std::unique_ptr< HyperLabelImpl > m_pImpl
Definition: hyperlabel.hxx:32
sal_Int32 GetIndex() const
Definition: hyperlabel.cxx:152
LINESTYLE_NONE
Size const & CalcMinimumSize(long nMaxWidth) const
Definition: hyperlabel.cxx:56
AllSettingsFlags GetFlags() const
Definition: event.hxx:349
void SetIndex(sal_Int32 Index)
Definition: hyperlabel.cxx:162
void SetInteractive(bool _bInteractive)
Definition: hyperlabel.cxx:142
void SetUnderline(FontLineStyle)
Definition: font/font.cxx:245
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: fixed.cxx:167
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: fixed.cxx:285
bool IsLeaveWindow() const
Definition: event.hxx:124
void SetControlBackground()
Definition: window2.cxx:497
void SetID(sal_Int16 ID)
Definition: hyperlabel.cxx:157
virtual void SetText(const OUString &rStr) override
Definition: ctrl.cxx:95
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1156
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
HyperLabel(vcl::Window *_pParent, WinBits _nWinStyle)
Definition: hyperlabel.cxx:49
LINESTYLE_SINGLE
Link< HyperLabel *, void > maClickHdl
Definition: hyperlabel.hxx:33
void SetTextColor(const Color &rColor)
Definition: text.cxx:663
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
Size CalcMinimumSize(long nMaxWidth=0x7fffffff) const
Definition: fixed.cxx:325
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:49
void ToggleBackgroundColor(const Color &_rGBColor)
Definition: hyperlabel.cxx:77
long X() const
void SetStyle(WinBits nStyle)
Definition: window.cxx:1925
void SetPointer(PointerStyle)
Definition: mouse.cxx:474
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: hyperlabel.cxx:172
virtual void GetFocus() override
Definition: hyperlabel.cxx:116
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: hyperlabel.cxx:183
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: hyperlabel.cxx:136
bool IsEnabled() const
Definition: window2.cxx:1111
virtual void LoseFocus() override
Definition: hyperlabel.cxx:126
WinBits GetStyle() const
Definition: window2.cxx:942
vcl::Font GetControlFont() const
Definition: window2.cxx:438
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: fixed.cxx:427
virtual ~HyperLabel() override
Definition: hyperlabel.cxx:131
WinBits const WB_EXTRAOFFSET
void SetLabel(const OUString &_rText)
Definition: hyperlabel.cxx:167
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2150