1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svtools.hxx"
30 
31 #include <svtools/fixedhyper.hxx>
32 
33 //.........................................................................
34 namespace svt
35 {
36 //.........................................................................
37 
38 // class FixedHyperlink --------------------------------------------------
39 
40 FixedHyperlink::FixedHyperlink( Window* pParent, const ResId& rResId ) :
41     ::toolkit::FixedHyperlinkBase( pParent, rResId ),
42     m_nTextLen(0)
43 {
44     Initialize();
45 }
46 
47 FixedHyperlink::FixedHyperlink( Window* pParent, WinBits nWinStyle  ) :
48     ::toolkit::FixedHyperlinkBase( pParent, nWinStyle ),
49     m_nTextLen(0)
50 {
51     Initialize();
52 }
53 
54 FixedHyperlink::~FixedHyperlink()
55 {
56 }
57 
58 void FixedHyperlink::Initialize()
59 {
60     // saves the old pointer
61     m_aOldPointer = GetPointer();
62     // changes the font
63     Font aFont = GetControlFont( );
64     // to underline
65     aFont.SetUnderline( UNDERLINE_SINGLE );
66     SetControlFont( aFont );
67     // changes the color to light blue
68     SetTextColor( Color( COL_LIGHTBLUE ) );
69     // calculates text len
70     m_nTextLen = GetCtrlTextWidth( GetText() );
71 }
72 
73 void FixedHyperlink::MouseMove( const MouseEvent& rMEvt )
74 {
75     // changes the pointer if the control is enabled and the mouse is over the text.
76     if ( !rMEvt.IsLeaveWindow() && IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
77         SetPointer( POINTER_REFHAND );
78     else
79         SetPointer( m_aOldPointer );
80 }
81 
82 void FixedHyperlink::MouseButtonUp( const MouseEvent& )
83 {
84     // calls the link if the control is enabled and the mouse is over the text.
85     if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
86         ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
87 }
88 
89 void FixedHyperlink::RequestHelp( const HelpEvent& rHEvt )
90 {
91     if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
92         FixedText::RequestHelp( rHEvt );
93 }
94 
95 void FixedHyperlink::GetFocus()
96 {
97     SetTextColor( Color( COL_LIGHTRED ) );
98     Paint( Rectangle( Point(), GetSizePixel() ) );
99     ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen + 4, GetSizePixel().Height() - 2 ) ) );
100 }
101 
102 void FixedHyperlink::LoseFocus()
103 {
104     SetTextColor( Color( COL_LIGHTBLUE ) );
105     Paint( Rectangle( Point(), GetSizePixel() ) );
106     HideFocus();
107 }
108 
109 void FixedHyperlink::KeyInput( const KeyEvent& rKEvt )
110 {
111     switch ( rKEvt.GetKeyCode().GetCode() )
112     {
113         case KEY_SPACE:
114         case KEY_RETURN:
115             m_aClickHdl.Call( this );
116             break;
117 
118         default:
119             FixedText::KeyInput( rKEvt );
120     }
121 }
122 
123 void FixedHyperlink::SetURL( const String& rNewURL )
124 {
125     m_sURL = rNewURL;
126     SetQuickHelpText( m_sURL );
127 }
128 
129 String  FixedHyperlink::GetURL() const
130 {
131     return m_sURL;
132 }
133 
134 void FixedHyperlink::SetDescription( const String& rNewDescription )
135 {
136     SetText( rNewDescription );
137     m_nTextLen = GetCtrlTextWidth( GetText() );
138 }
139 
140 // class FixedHyperlinkImage ---------------------------------------------
141 
142 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, const ResId& rResId ) :
143     FixedImage( pParent, rResId )
144 {
145     Initialize();
146 }
147 
148 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, WinBits nWinStyle  ) :
149     FixedImage( pParent, nWinStyle )
150 {
151     Initialize();
152 }
153 
154 FixedHyperlinkImage::~FixedHyperlinkImage()
155 {
156 }
157 
158 void FixedHyperlinkImage::Initialize()
159 {
160     // saves the old pointer
161     m_aOldPointer = GetPointer();
162 }
163 
164 void FixedHyperlinkImage::MouseMove( const MouseEvent& rMEvt )
165 {
166     // changes the pointer if the control is enabled and the mouse is over the text.
167     if ( !rMEvt.IsLeaveWindow() && IsEnabled() )
168         SetPointer( POINTER_REFHAND );
169     else
170         SetPointer( m_aOldPointer );
171 }
172 
173 void FixedHyperlinkImage::MouseButtonUp( const MouseEvent& )
174 {
175     // calls the link if the control is enabled and the mouse is over the text.
176     if ( IsEnabled() )
177         ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
178 
179     Size aSize = GetSizePixel();
180     Size aImgSz = GetImage().GetSizePixel();
181     if ( aSize.Width() < aImgSz.Width() )
182     {
183         DBG_ERRORFILE("xxx");
184     }
185 }
186 
187 void FixedHyperlinkImage::RequestHelp( const HelpEvent& rHEvt )
188 {
189     if ( IsEnabled() )
190         FixedImage::RequestHelp( rHEvt );
191 }
192 
193 void FixedHyperlinkImage::GetFocus()
194 {
195     Paint( Rectangle( Point(), GetSizePixel() ) );
196     ShowFocus( Rectangle( Point( 1, 1 ), Size( GetSizePixel().Width() - 2, GetSizePixel().Height() - 2 ) ) );
197 }
198 
199 void FixedHyperlinkImage::LoseFocus()
200 {
201     Paint( Rectangle( Point(), GetSizePixel() ) );
202     HideFocus();
203 }
204 
205 void FixedHyperlinkImage::KeyInput( const KeyEvent& rKEvt )
206 {
207     switch ( rKEvt.GetKeyCode().GetCode() )
208     {
209         case KEY_SPACE:
210         case KEY_RETURN:
211             m_aClickHdl.Call( this );
212             break;
213 
214         default:
215             FixedImage::KeyInput( rKEvt );
216     }
217 }
218 
219 void FixedHyperlinkImage::SetURL( const String& rNewURL )
220 {
221     m_sURL = rNewURL;
222     SetQuickHelpText( m_sURL );
223 }
224 
225 String  FixedHyperlinkImage::GetURL() const
226 {
227     return m_sURL;
228 }
229 
230 //.........................................................................
231 } // namespace svt
232 //.........................................................................
233 
234