1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <svtools/fixedhyper.hxx>
28 
29 //.........................................................................
30 namespace svt
31 {
32 //.........................................................................
33 
34 // class FixedHyperlink --------------------------------------------------
35 
36 FixedHyperlink::FixedHyperlink( Window* pParent, const ResId& rResId ) :
37     ::toolkit::FixedHyperlinkBase( pParent, rResId ),
38     m_nTextLen(0)
39 {
40     Initialize();
41 }
42 
43 FixedHyperlink::FixedHyperlink( Window* pParent, WinBits nWinStyle  ) :
44     ::toolkit::FixedHyperlinkBase( pParent, nWinStyle ),
45     m_nTextLen(0)
46 {
47     Initialize();
48 }
49 
50 FixedHyperlink::~FixedHyperlink()
51 {
52 }
53 
54 void FixedHyperlink::Initialize()
55 {
56     // saves the old pointer
57     m_aOldPointer = GetPointer();
58     // changes the font
59     Font aFont = GetControlFont( );
60     // to underline
61     aFont.SetUnderline( UNDERLINE_SINGLE );
62     SetControlFont( aFont );
63     // changes the color to light blue
64     SetTextColor( Color( COL_LIGHTBLUE ) );
65     // calculates text len
66     m_nTextLen = GetCtrlTextWidth( GetText() );
67 }
68 
69 void FixedHyperlink::MouseMove( const MouseEvent& rMEvt )
70 {
71     // changes the pointer if the control is enabled and the mouse is over the text.
72     if ( !rMEvt.IsLeaveWindow() && IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
73         SetPointer( POINTER_REFHAND );
74     else
75         SetPointer( m_aOldPointer );
76 }
77 
78 void FixedHyperlink::MouseButtonUp( const MouseEvent& )
79 {
80     // calls the link if the control is enabled and the mouse is over the text.
81     if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
82         ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
83 }
84 
85 void FixedHyperlink::RequestHelp( const HelpEvent& rHEvt )
86 {
87     if ( IsEnabled() && GetPointerPosPixel().X() < m_nTextLen )
88         FixedText::RequestHelp( rHEvt );
89 }
90 
91 void FixedHyperlink::GetFocus()
92 {
93     SetTextColor( Color( COL_LIGHTRED ) );
94     Paint( Rectangle( Point(), GetSizePixel() ) );
95     ShowFocus( Rectangle( Point( 1, 1 ), Size( m_nTextLen + 4, GetSizePixel().Height() - 2 ) ) );
96 }
97 
98 void FixedHyperlink::LoseFocus()
99 {
100     SetTextColor( Color( COL_LIGHTBLUE ) );
101     Paint( Rectangle( Point(), GetSizePixel() ) );
102     HideFocus();
103 }
104 
105 void FixedHyperlink::KeyInput( const KeyEvent& rKEvt )
106 {
107     switch ( rKEvt.GetKeyCode().GetCode() )
108     {
109         case KEY_SPACE:
110         case KEY_RETURN:
111             m_aClickHdl.Call( this );
112             break;
113 
114         default:
115             FixedText::KeyInput( rKEvt );
116     }
117 }
118 
119 void FixedHyperlink::SetURL( const String& rNewURL )
120 {
121     m_sURL = rNewURL;
122     SetQuickHelpText( m_sURL );
123 }
124 
125 String  FixedHyperlink::GetURL() const
126 {
127     return m_sURL;
128 }
129 
130 void FixedHyperlink::SetDescription( const String& rNewDescription )
131 {
132     SetText( rNewDescription );
133     m_nTextLen = GetCtrlTextWidth( GetText() );
134 }
135 
136 // class FixedHyperlinkImage ---------------------------------------------
137 
138 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, const ResId& rResId ) :
139     FixedImage( pParent, rResId )
140 {
141     Initialize();
142 }
143 
144 FixedHyperlinkImage::FixedHyperlinkImage( Window* pParent, WinBits nWinStyle  ) :
145     FixedImage( pParent, nWinStyle )
146 {
147     Initialize();
148 }
149 
150 FixedHyperlinkImage::~FixedHyperlinkImage()
151 {
152 }
153 
154 void FixedHyperlinkImage::Initialize()
155 {
156     // saves the old pointer
157     m_aOldPointer = GetPointer();
158 }
159 
160 void FixedHyperlinkImage::MouseMove( const MouseEvent& rMEvt )
161 {
162     // changes the pointer if the control is enabled and the mouse is over the text.
163     if ( !rMEvt.IsLeaveWindow() && IsEnabled() )
164         SetPointer( POINTER_REFHAND );
165     else
166         SetPointer( m_aOldPointer );
167 }
168 
169 void FixedHyperlinkImage::MouseButtonUp( const MouseEvent& )
170 {
171     // calls the link if the control is enabled and the mouse is over the text.
172     if ( IsEnabled() )
173         ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, m_aClickHdl, this );
174 
175     Size aSize = GetSizePixel();
176     Size aImgSz = GetImage().GetSizePixel();
177     if ( aSize.Width() < aImgSz.Width() )
178     {
179         DBG_ERRORFILE("xxx");
180     }
181 }
182 
183 void FixedHyperlinkImage::RequestHelp( const HelpEvent& rHEvt )
184 {
185     if ( IsEnabled() )
186         FixedImage::RequestHelp( rHEvt );
187 }
188 
189 void FixedHyperlinkImage::GetFocus()
190 {
191     Paint( Rectangle( Point(), GetSizePixel() ) );
192     ShowFocus( Rectangle( Point( 1, 1 ), Size( GetSizePixel().Width() - 2, GetSizePixel().Height() - 2 ) ) );
193 }
194 
195 void FixedHyperlinkImage::LoseFocus()
196 {
197     Paint( Rectangle( Point(), GetSizePixel() ) );
198     HideFocus();
199 }
200 
201 void FixedHyperlinkImage::KeyInput( const KeyEvent& rKEvt )
202 {
203     switch ( rKEvt.GetKeyCode().GetCode() )
204     {
205         case KEY_SPACE:
206         case KEY_RETURN:
207             m_aClickHdl.Call( this );
208             break;
209 
210         default:
211             FixedImage::KeyInput( rKEvt );
212     }
213 }
214 
215 void FixedHyperlinkImage::SetURL( const String& rNewURL )
216 {
217     m_sURL = rNewURL;
218     SetQuickHelpText( m_sURL );
219 }
220 
221 String  FixedHyperlinkImage::GetURL() const
222 {
223     return m_sURL;
224 }
225 
226 //.........................................................................
227 } // namespace svt
228 //.........................................................................
229 
230