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 <vcl/fixedhyper.hxx>
22 // class FixedHyperlink --------------------------------------------------
24 FixedHyperlink::FixedHyperlink(Window
* pParent
, const ResId
& rResId
)
25 : FixedText(pParent
, rResId
)
31 FixedHyperlink::FixedHyperlink(Window
* pParent
, WinBits nWinStyle
)
32 : FixedText(pParent
, nWinStyle
)
38 FixedHyperlink::~FixedHyperlink()
42 void FixedHyperlink::Initialize()
44 // saves the old pointer
45 m_aOldPointer
= GetPointer();
47 Font aFont
= GetControlFont( );
49 aFont
.SetUnderline( UNDERLINE_SINGLE
);
50 SetControlFont( aFont
);
51 // changes the color to light blue
52 SetControlForeground( Color( COL_LIGHTBLUE
) );
53 // calculates text len
54 m_nTextLen
= GetCtrlTextWidth( GetText() );
57 void FixedHyperlink::MouseMove( const MouseEvent
& rMEvt
)
59 // changes the pointer if the control is enabled and the mouse is over the text.
60 if ( !rMEvt
.IsLeaveWindow() && IsEnabled() && GetPointerPosPixel().X() < m_nTextLen
)
61 SetPointer( POINTER_REFHAND
);
63 SetPointer( m_aOldPointer
);
66 void FixedHyperlink::MouseButtonUp( const MouseEvent
& )
68 // calls the link if the control is enabled and the mouse is over the text.
69 if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen
)
70 ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK
, m_aClickHdl
, this );
73 void FixedHyperlink::RequestHelp( const HelpEvent
& rHEvt
)
75 if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen
)
76 FixedText::RequestHelp( rHEvt
);
79 void FixedHyperlink::GetFocus()
81 SetTextColor( Color( COL_LIGHTRED
) );
82 Paint( Rectangle( Point(), GetSizePixel() ) );
83 ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen
+ 4, GetSizePixel().Height() - 2 ) ) );
86 void FixedHyperlink::LoseFocus()
88 SetTextColor( GetControlForeground() );
89 Paint( Rectangle( Point(), GetSizePixel() ) );
93 void FixedHyperlink::KeyInput( const KeyEvent
& rKEvt
)
95 switch ( rKEvt
.GetKeyCode().GetCode() )
99 m_aClickHdl
.Call( this );
103 FixedText::KeyInput( rKEvt
);
107 void FixedHyperlink::SetURL( const OUString
& rNewURL
)
110 SetQuickHelpText( m_sURL
);
113 OUString
FixedHyperlink::GetURL() const
118 void FixedHyperlink::SetText(const OUString
& rNewDescription
)
120 FixedText::SetText(rNewDescription
);
121 m_nTextLen
= GetCtrlTextWidth(GetText());
124 bool FixedHyperlink::set_property(const OString
&rKey
, const OString
&rValue
)
127 SetURL(OStringToOUString(rValue
, RTL_TEXTENCODING_UTF8
));
129 return FixedText::set_property(rKey
, rValue
);
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */