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