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 $
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 //.........................................................................
39 //.........................................................................
41 // class FixedHyperlink --------------------------------------------------
43 FixedHyperlink::FixedHyperlink( Window
* pParent
, const ResId
& rResId
) :
44 ::toolkit::FixedHyperlinkBase( pParent
, rResId
),
50 FixedHyperlink::FixedHyperlink( Window
* pParent
, WinBits nWinStyle
) :
51 ::toolkit::FixedHyperlinkBase( pParent
, nWinStyle
),
57 FixedHyperlink::~FixedHyperlink()
61 void FixedHyperlink::Initialize()
63 // saves the old pointer
64 m_aOldPointer
= GetPointer();
66 Font aFont
= GetControlFont( );
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
);
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() ) );
112 void FixedHyperlink::KeyInput( const KeyEvent
& rKEvt
)
114 switch ( rKEvt
.GetKeyCode().GetCode() )
118 m_aClickHdl
.Call( this );
122 FixedText::KeyInput( rKEvt
);
126 void FixedHyperlink::SetURL( const String
& rNewURL
)
129 SetQuickHelpText( m_sURL
);
132 String
FixedHyperlink::GetURL() const
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
)
151 FixedHyperlinkImage::FixedHyperlinkImage( Window
* pParent
, WinBits nWinStyle
) :
152 FixedImage( pParent
, nWinStyle
)
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
);
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.
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
)
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() ) );
208 void FixedHyperlinkImage::KeyInput( const KeyEvent
& rKEvt
)
210 switch ( rKEvt
.GetKeyCode().GetCode() )
214 m_aClickHdl
.Call( this );
218 FixedImage::KeyInput( rKEvt
);
222 void FixedHyperlinkImage::SetURL( const String
& rNewURL
)
225 SetQuickHelpText( m_sURL
);
228 String
FixedHyperlinkImage::GetURL() const
233 //.........................................................................
235 //.........................................................................