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