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