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 {
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)
34  {
35  implInit();
36  }
37 
39  {
41  // the MinimumSize is used to size the FocusRectangle
42  // and for the MouseMove method
45  return m_aMinSize;
46  }
47 
49  {
51 
52  WinBits nWinStyle = GetStyle();
53  nWinStyle |= WB_EXTRAOFFSET;
54  SetStyle( nWinStyle );
55 
56  Show();
57  }
58 
59  void HyperLabel::ToggleBackgroundColor( const Color& _rGBColor )
60  {
61  SetControlBackground( _rGBColor );
62  }
63 
64  void HyperLabel::MouseMove( const MouseEvent& rMEvt )
65  {
66  vcl::Font aFont = GetControlFont( );
67 
68  bool bHyperMode = false;
69  if (!rMEvt.IsLeaveWindow() && IsEnabled() && bInteractive)
70  {
71  Point aPoint = GetPointerPosPixel();
72  if (aPoint.X() < m_aMinSize.Width())
73  bHyperMode = true;
74  }
75 
76  m_bHyperMode = bHyperMode;
77  if (bHyperMode)
78  {
81  }
82  else
83  {
86  }
87  SetControlFont(aFont);
88  }
89 
91  {
92  if ( m_bHyperMode && bInteractive )
93  {
94  maClickHdl.Call( this );
95  }
96  }
97 
99  {
100  if ( IsEnabled() && bInteractive )
101  {
102  Point aPoint(0,0);
103  tools::Rectangle rRect(aPoint, Size( m_aMinSize.Width(), GetSizePixel().Height() ) );
104  ShowFocus( rRect );
105  }
106  }
107 
109  {
110  HideFocus();
111  }
112 
114  {
115  disposeOnce();
116  }
117 
118  void HyperLabel::SetInteractive( bool _bInteractive )
119  {
120  bInteractive = ( _bInteractive && IsEnabled() );
121  }
122 
123  sal_Int16 HyperLabel::GetID() const
124  {
125  return ID;
126  }
127 
128  sal_Int32 HyperLabel::GetIndex() const
129  {
130  return Index;
131  }
132 
133  void HyperLabel::SetID( sal_Int16 newID )
134  {
135  this->ID = newID;
136  }
137 
138  void HyperLabel::SetIndex( sal_Int32 newIndex )
139  {
140  Index = newIndex;
141  }
142 
143  void HyperLabel::SetLabel( const OUString& _rText )
144  {
145  SetText(_rText);
146  }
147 
149  {
150  FixedText::ApplySettings(rRenderContext);
151 
152  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
154  rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
155  else
156  rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
157  }
158 
160  {
161  FixedText::DataChanged( rDCEvt );
162 
163  if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
164  ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
165  ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
166  {
167  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
169  SetControlBackground(rStyleSettings.GetHighlightColor());
170  Invalidate();
171  }
172  }
173 
174 } // namespace vcl
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point GetPointerPosPixel()
Definition: mouse.cxx:556
void HideFocus()
Definition: window2.cxx:93
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: hyperlabel.cxx:90
const Color & GetHighlightTextColor() const
virtual void MouseMove(const MouseEvent &rMEvt) override
Definition: hyperlabel.cxx:64
long Long
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
const StyleSettings & GetStyleSettings() const
virtual Size GetSizePixel() const
Definition: window.cxx:2392
DataChangedEventType GetType() const
Definition: event.hxx:362
const Color & GetControlBackground() const
Definition: window2.cxx:1076
const Color & GetFieldTextColor() const
sal_Int16 GetID() const
Definition: hyperlabel.cxx:123
const Color & GetHighlightColor() const
constexpr tools::Long Width() const
sal_Int64 WinBits
void SetControlFont()
Definition: window2.cxx:403
sal_Int32 GetIndex() const
Definition: hyperlabel.cxx:128
LINESTYLE_NONE
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
void SetIndex(sal_Int32 Index)
Definition: hyperlabel.cxx:138
void SetInteractive(bool _bInteractive)
Definition: hyperlabel.cxx:118
void SetUnderline(FontLineStyle)
Definition: font/font.cxx:255
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: fixed.cxx:166
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: fixed.cxx:284
bool IsLeaveWindow() const
Definition: event.hxx:140
sal_Int32 Index
Definition: hyperlabel.hxx:64
void SetControlBackground()
Definition: window2.cxx:491
void SetID(sal_Int16 ID)
Definition: hyperlabel.cxx:133
virtual void SetText(const OUString &rStr) override
Definition: ctrl.cxx:94
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1164
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
HyperLabel(vcl::Window *_pParent, WinBits _nWinStyle)
Definition: hyperlabel.cxx:28
const AllSettings & GetSettings() const
Definition: window3.cxx:129
LINESTYLE_SINGLE
Link< HyperLabel *, void > maClickHdl
Definition: hyperlabel.hxx:30
void SetTextColor(const Color &rColor)
Definition: text.cxx:686
Size const & CalcMinimumSize(tools::Long nMaxWidth)
Definition: hyperlabel.cxx:38
const AllSettings & GetSettings() const
Definition: outdev.hxx:288
virtual void ShowFocus(const tools::Rectangle &rRect)
Definition: window2.cxx:51
void ToggleBackgroundColor(const Color &_rGBColor)
Definition: hyperlabel.cxx:59
void SetStyle(WinBits nStyle)
Definition: window.cxx:1952
void SetPointer(PointerStyle)
Definition: mouse.cxx:480
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: hyperlabel.cxx:148
constexpr tools::Long Height() const
virtual void GetFocus() override
Definition: hyperlabel.cxx:98
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: hyperlabel.cxx:159
tools::Long AdjustWidth(tools::Long n)
tools::Long AdjustHeight(tools::Long n)
bool IsEnabled() const
Definition: window2.cxx:1116
virtual void LoseFocus() override
Definition: hyperlabel.cxx:108
WinBits GetStyle() const
Definition: window2.cxx:947
Size CalcMinimumSize(tools::Long nMaxWidth=0x7fffffff) const
Definition: fixed.cxx:324
vcl::Font GetControlFont() const
Definition: window2.cxx:432
virtual ~HyperLabel() override
Definition: hyperlabel.cxx:113
WinBits const WB_EXTRAOFFSET
struct _ADOIndex Index
sal_Int16 ID
Definition: hyperlabel.hxx:63
void SetLabel(const OUString &_rText)
Definition: hyperlabel.cxx:143
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2177