update dev300-m58
[ooovba.git] / svtools / source / control / fixedhyper.cxx
blob5525333e083c055ef2a342f7cc1628442cd470f8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fixedhyper.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <svtools/fixedhyper.hxx>
36 //.........................................................................
37 namespace svt
39 //.........................................................................
41 // class FixedHyperlink --------------------------------------------------
43 FixedHyperlink::FixedHyperlink( Window* pParent, const ResId& rResId ) :
44 ::toolkit::FixedHyperlinkBase( pParent, rResId ),
45 m_nTextLen(0)
47 Initialize();
50 FixedHyperlink::FixedHyperlink( Window* pParent, WinBits nWinStyle ) :
51 ::toolkit::FixedHyperlinkBase( pParent, nWinStyle ),
52 m_nTextLen(0)
54 Initialize();
57 FixedHyperlink::~FixedHyperlink()
61 void FixedHyperlink::Initialize()
63 // saves the old pointer
64 m_aOldPointer = GetPointer();
65 // changes the font
66 Font aFont = GetControlFont( );
67 // to underline
68 aFont.SetUnderline( UNDERLINE_SINGLE );
69 SetControlFont( aFont );
70 // changes the color to light blue
71 SetTextColor( Color( COL_LIGHTBLUE ) );
72 // calculates text len
73 m_nTextLen = GetCtrlTextWidth( GetText() );
76 void FixedHyperlink::MouseMove( const MouseEvent& rMEvt )
78 // changes the pointer if the control is enabled and the mouse is over the text.
79 if ( !rMEvt.IsLeaveWindow() && IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
80 SetPointer( POINTER_REFHAND );
81 else
82 SetPointer( m_aOldPointer );
85 void FixedHyperlink::MouseButtonUp( const MouseEvent& )
87 // calls the link if the control is enabled and the mouse is over the text.
88 if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
89 ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
92 void FixedHyperlink::RequestHelp( const HelpEvent& rHEvt )
94 if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
95 FixedText::RequestHelp( rHEvt );
98 void FixedHyperlink::GetFocus()
100 SetTextColor( Color( COL_LIGHTRED ) );
101 Paint( Rectangle( Point(), GetSizePixel() ) );
102 ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen + 4, GetSizePixel().Height() - 2 ) ) );
105 void FixedHyperlink::LoseFocus()
107 SetTextColor( Color( COL_LIGHTBLUE ) );
108 Paint( Rectangle( Point(), GetSizePixel() ) );
109 HideFocus();
112 void FixedHyperlink::KeyInput( const KeyEvent& rKEvt )
114 switch ( rKEvt.GetKeyCode().GetCode() )
116 case KEY_SPACE:
117 case KEY_RETURN:
118 m_aClickHdl.Call( this );
119 break;
121 default:
122 FixedText::KeyInput( rKEvt );
126 void FixedHyperlink::SetURL( const String& rNewURL )
128 m_sURL = rNewURL;
129 SetQuickHelpText( m_sURL );
132 String FixedHyperlink::GetURL() const
134 return m_sURL;
137 void FixedHyperlink::SetDescription( const String& rNewDescription )
139 SetText( rNewDescription );
140 m_nTextLen = GetCtrlTextWidth( GetText() );
143 // class FixedHyperlinkImage ---------------------------------------------
145 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, const ResId& rResId ) :
146 FixedImage( pParent, rResId )
148 Initialize();
151 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, WinBits nWinStyle ) :
152 FixedImage( pParent, nWinStyle )
154 Initialize();
157 FixedHyperlinkImage::~FixedHyperlinkImage()
161 void FixedHyperlinkImage::Initialize()
163 // saves the old pointer
164 m_aOldPointer = GetPointer();
167 void FixedHyperlinkImage::MouseMove( const MouseEvent& rMEvt )
169 // changes the pointer if the control is enabled and the mouse is over the text.
170 if ( !rMEvt.IsLeaveWindow() && IsEnabled() )
171 SetPointer( POINTER_REFHAND );
172 else
173 SetPointer( m_aOldPointer );
176 void FixedHyperlinkImage::MouseButtonUp( const MouseEvent& )
178 // calls the link if the control is enabled and the mouse is over the text.
179 if ( IsEnabled() )
180 ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
182 Size aSize = GetSizePixel();
183 Size aImgSz = GetImage().GetSizePixel();
184 if ( aSize.Width() < aImgSz.Width() )
186 DBG_ERRORFILE("xxx");
190 void FixedHyperlinkImage::RequestHelp( const HelpEvent& rHEvt )
192 if ( IsEnabled() )
193 FixedImage::RequestHelp( rHEvt );
196 void FixedHyperlinkImage::GetFocus()
198 Paint( Rectangle( Point(), GetSizePixel() ) );
199 ShowFocus( Rectangle( Point( 1, 1 ), Size( GetSizePixel().Width() - 2, GetSizePixel().Height() - 2 ) ) );
202 void FixedHyperlinkImage::LoseFocus()
204 Paint( Rectangle( Point(), GetSizePixel() ) );
205 HideFocus();
208 void FixedHyperlinkImage::KeyInput( const KeyEvent& rKEvt )
210 switch ( rKEvt.GetKeyCode().GetCode() )
212 case KEY_SPACE:
213 case KEY_RETURN:
214 m_aClickHdl.Call( this );
215 break;
217 default:
218 FixedImage::KeyInput( rKEvt );
222 void FixedHyperlinkImage::SetURL( const String& rNewURL )
224 m_sURL = rNewURL;
225 SetQuickHelpText( m_sURL );
228 String FixedHyperlinkImage::GetURL() const
230 return m_sURL;
233 //.........................................................................
234 } // namespace svt
235 //.........................................................................