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 #ifndef SVTOOLS_ROADMAP_HXX 31 #include <svtools/hyperlabel.hxx> 32 #endif 33 #include <vcl/bitmap.hxx> 34 #include <tools/color.hxx> 35 36 #ifndef _VCL_TABPAGE_HXX 37 #include <vcl/tabpage.hxx> 38 #endif 39 40 41 //......................................................................... 42 namespace svt 43 { 44 //......................................................................... 45 46 //===================================================================== 47 //= FontChanger 48 //===================================================================== 49 class FontChanger 50 { 51 protected: 52 OutputDevice* m_pDev; 53 54 public: 55 FontChanger( OutputDevice* _pDev, const Font& _rNewFont ) 56 :m_pDev( _pDev ) 57 { 58 m_pDev->Push( PUSH_FONT ); 59 m_pDev->SetFont( _rNewFont ); 60 } 61 62 ~FontChanger() 63 { 64 m_pDev->Pop( ); 65 } 66 }; 67 68 class HyperLabelImpl 69 { 70 public: 71 sal_Int16 ID; 72 sal_Int32 Index; 73 sal_Bool bInteractive; 74 Size m_aMinSize; 75 sal_Bool m_bHyperMode; 76 77 HyperLabelImpl(); 78 }; 79 80 //--------------------------------------------------------------------- 81 HyperLabelImpl::HyperLabelImpl() 82 { 83 } 84 85 HyperLabel::HyperLabel( Window* _pParent, const ResId& _rId ) 86 :FixedText( _pParent, _rId ) 87 ,m_pImpl( new HyperLabelImpl ) 88 { 89 implInit(); 90 } 91 92 HyperLabel::HyperLabel( Window* _pParent, WinBits _nWinStyle ) 93 :FixedText( _pParent, _nWinStyle ) 94 ,m_pImpl( new HyperLabelImpl ) 95 { 96 implInit(); 97 } 98 99 100 sal_Int32 HyperLabel::GetLogicWidth() 101 { 102 Size rLogicLocSize = PixelToLogic( m_pImpl->m_aMinSize, MAP_APPFONT ); 103 return rLogicLocSize.Width(); 104 } 105 106 107 Size HyperLabel::CalcMinimumSize( long nMaxWidth ) const 108 { 109 m_pImpl->m_aMinSize = FixedText::CalcMinimumSize( nMaxWidth ); 110 // the MinimumSize is used to size the FocusRectangle 111 // and for the MouseMove method 112 m_pImpl->m_aMinSize.Height() += 2; 113 m_pImpl->m_aMinSize.Width() += 1; 114 return m_pImpl->m_aMinSize; 115 } 116 117 void HyperLabel::implInit() 118 { 119 ToggleBackgroundColor( COL_TRANSPARENT ); 120 121 WinBits nWinStyle = GetStyle(); 122 nWinStyle |= WB_EXTRAOFFSET; 123 SetStyle( nWinStyle ); 124 125 Show(); 126 } 127 128 void HyperLabel::ToggleBackgroundColor( const Color& _rGBColor ) 129 { 130 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 131 SetControlBackground( _rGBColor ); 132 if (_rGBColor == COL_TRANSPARENT) 133 SetTextColor( rStyleSettings.GetFieldTextColor( ) ); 134 else 135 SetTextColor( rStyleSettings.GetHighlightTextColor( ) ); 136 } 137 138 139 void HyperLabel::MouseMove( const MouseEvent& rMEvt ) 140 { 141 Font aFont = GetControlFont( ); 142 const Color aColor = GetTextColor(); 143 144 if (rMEvt.IsLeaveWindow()) 145 { 146 DeactivateHyperMode(aFont, aColor); 147 } 148 else 149 { 150 Point aPoint = GetPointerPosPixel(); 151 if (aPoint.X() < m_pImpl->m_aMinSize.Width()) 152 { 153 if ( IsEnabled() && (m_pImpl->bInteractive) ) 154 { 155 ActivateHyperMode( aFont, aColor); 156 return; 157 } 158 } 159 DeactivateHyperMode(aFont, aColor); 160 } 161 } 162 163 void HyperLabel::ActivateHyperMode(Font aFont, const Color aColor) 164 { 165 aFont.SetUnderline(UNDERLINE_SINGLE); 166 m_pImpl->m_bHyperMode = sal_True; 167 SetPointer( POINTER_REFHAND ); 168 SetControlFont( aFont); 169 SetTextColor( aColor); 170 171 } 172 173 void HyperLabel::DeactivateHyperMode(Font aFont, const Color aColor) 174 { 175 m_pImpl->m_bHyperMode = sal_False; 176 aFont.SetUnderline(UNDERLINE_NONE); 177 SetPointer( POINTER_ARROW ); 178 SetControlFont( aFont); 179 SetTextColor( aColor); 180 } 181 182 void HyperLabel::MouseButtonDown( const MouseEvent& ) 183 { 184 if ( m_pImpl->m_bHyperMode && m_pImpl->bInteractive ) 185 { 186 maClickHdl.Call( this ); 187 } 188 } 189 190 void HyperLabel::GetFocus() 191 { 192 if ( IsEnabled() && m_pImpl->bInteractive ) 193 { 194 Point aPoint(0,0); 195 Rectangle rRect(aPoint, Size( m_pImpl->m_aMinSize.Width(), GetSizePixel().Height() ) ); 196 ShowFocus( rRect ); 197 } 198 } 199 200 void HyperLabel::LoseFocus() 201 { 202 HideFocus(); 203 } 204 205 HyperLabel::~HyperLabel( ) 206 { 207 delete m_pImpl; 208 } 209 210 void HyperLabel::SetInteractive( sal_Bool _bInteractive ) 211 { 212 m_pImpl->bInteractive = ( _bInteractive && IsEnabled() ); 213 } 214 215 sal_Int16 HyperLabel::GetID() const 216 { 217 return m_pImpl->ID; 218 } 219 220 sal_Int32 HyperLabel::GetIndex() const 221 { 222 return m_pImpl->Index; 223 } 224 225 void HyperLabel::SetID( sal_Int16 _ID ) 226 { 227 m_pImpl->ID = _ID; 228 } 229 230 void HyperLabel::SetIndex( sal_Int32 _Index ) 231 { 232 m_pImpl->Index = _Index; 233 } 234 235 ::rtl::OUString HyperLabel::GetLabel( ) 236 { 237 return GetText(); 238 } 239 240 void HyperLabel::SetLabel( const ::rtl::OUString& _rText ) 241 { 242 SetText(_rText); 243 } 244 245 246 //------------------------------------------------------------------------------ 247 void HyperLabel::DataChanged( const DataChangedEvent& rDCEvt ) 248 { 249 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 250 FixedText::DataChanged( rDCEvt ); 251 if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) || 252 ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) && 253 ( rDCEvt.GetFlags() & SETTINGS_STYLE )) 254 { 255 const Color& rGBColor = GetControlBackground(); 256 if (rGBColor == COL_TRANSPARENT) 257 SetTextColor( rStyleSettings.GetFieldTextColor( ) ); 258 else 259 { 260 SetControlBackground(rStyleSettings.GetHighlightColor()); 261 SetTextColor( rStyleSettings.GetHighlightTextColor( ) ); 262 } 263 Invalidate(); 264 } 265 } 266 267 //......................................................................... 268 } // namespace svt 269 //......................................................................... 270 271