1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyperlabel.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #ifndef SVTOOLS_ROADMAP_HXX
34 #include <svtools/hyperlabel.hxx>
36 #include <vcl/bitmap.hxx>
37 #include <tools/color.hxx>
39 #ifndef _VCL_TABPAGE_HXX
40 #include <vcl/tabpage.hxx>
44 //.........................................................................
47 //.........................................................................
49 //=====================================================================
51 //=====================================================================
58 FontChanger( OutputDevice
* _pDev
, const Font
& _rNewFont
)
61 m_pDev
->Push( PUSH_FONT
);
62 m_pDev
->SetFont( _rNewFont
);
76 sal_Bool bInteractive
;
78 sal_Bool m_bHyperMode
;
83 //---------------------------------------------------------------------
84 HyperLabelImpl::HyperLabelImpl()
88 HyperLabel::HyperLabel( Window
* _pParent
, const ResId
& _rId
)
89 :FixedText( _pParent
, _rId
)
90 ,m_pImpl( new HyperLabelImpl
)
95 HyperLabel::HyperLabel( Window
* _pParent
, WinBits _nWinStyle
)
96 :FixedText( _pParent
, _nWinStyle
)
97 ,m_pImpl( new HyperLabelImpl
)
103 sal_Int32
HyperLabel::GetLogicWidth()
105 Size rLogicLocSize
= PixelToLogic( m_pImpl
->m_aMinSize
, MAP_APPFONT
);
106 return rLogicLocSize
.Width();
110 void HyperLabel::SetLabelAndSize(::rtl::OUString _rText
, const Size
& _rNewSize
)
112 Size rLocSize
= _rNewSize
;
113 Size rLogicLocSize
= PixelToLogic( _rNewSize
, MAP_APPFONT
);
115 ImplCalcMinimumSize( rLocSize
);
116 rLocSize
.Height() = ( m_pImpl
->m_aMinSize
.Height());
118 // rLocSize = LogicToPixel( Size( rLogicLocSize.Width(), LABELBASEMAPHEIGHT ), MAP_APPFONT );
119 SetSizePixel( rLocSize
);
123 sal_Bool
HyperLabel::ImplCalcMinimumSize(const Size
& _rCompSize
)
125 sal_Bool b_AdjustMinWidth
= sal_False
;
126 m_pImpl
->m_aMinSize
= CalcMinimumSize( );
127 if ( m_pImpl
->m_aMinSize
.Width() >= _rCompSize
.Width() ) // the MinimumSize is used to size the FocusRectangle
129 m_pImpl
->m_aMinSize
.Width() = _rCompSize
.Width(); // and for the MouseMove method
130 m_pImpl
->m_aMinSize
= CalcMinimumSize(_rCompSize
.Width() );
131 b_AdjustMinWidth
= sal_True
;
133 m_pImpl
->m_aMinSize
.Height() += 2;
134 m_pImpl
->m_aMinSize
.Width() += 1;
135 return b_AdjustMinWidth
;
139 void HyperLabel::implInit()
141 ToggleBackgroundColor( COL_TRANSPARENT
);
143 WinBits nWinStyle
= GetStyle();
144 nWinStyle
|= WB_EXTRAOFFSET
;
145 SetStyle( nWinStyle
);
150 void HyperLabel::ToggleBackgroundColor( const Color
& _rGBColor
)
152 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
153 SetControlBackground( _rGBColor
);
154 if (_rGBColor
== COL_TRANSPARENT
)
155 SetTextColor( rStyleSettings
.GetFieldTextColor( ) );
157 SetTextColor( rStyleSettings
.GetHighlightTextColor( ) );
161 void HyperLabel::MouseMove( const MouseEvent
& rMEvt
)
163 Font aFont
= GetControlFont( );
164 const Color aColor
= GetTextColor();
166 if (rMEvt
.IsLeaveWindow())
168 DeactivateHyperMode(aFont
, aColor
);
172 Point aPoint
= GetPointerPosPixel();
173 if (aPoint
.X() < m_pImpl
->m_aMinSize
.Width())
175 if ( IsEnabled() && (m_pImpl
->bInteractive
) )
177 ActivateHyperMode( aFont
, aColor
);
181 DeactivateHyperMode(aFont
, aColor
);
185 void HyperLabel::ActivateHyperMode(Font aFont
, const Color aColor
)
187 aFont
.SetUnderline(UNDERLINE_SINGLE
);
188 m_pImpl
->m_bHyperMode
= sal_True
;
189 SetPointer( POINTER_REFHAND
);
190 SetControlFont( aFont
);
191 SetTextColor( aColor
);
195 void HyperLabel::DeactivateHyperMode(Font aFont
, const Color aColor
)
197 m_pImpl
->m_bHyperMode
= sal_False
;
198 aFont
.SetUnderline(UNDERLINE_NONE
);
199 SetPointer( POINTER_ARROW
);
200 SetControlFont( aFont
);
201 SetTextColor( aColor
);
204 void HyperLabel::MouseButtonDown( const MouseEvent
& )
206 if ( m_pImpl
->m_bHyperMode
&& m_pImpl
->bInteractive
)
208 maClickHdl
.Call( this );
212 void HyperLabel::GetFocus()
214 if ( IsEnabled() && m_pImpl
->bInteractive
)
217 Rectangle
rRect(aPoint
, Size( m_pImpl
->m_aMinSize
.Width(), GetSizePixel().Height() ) );
222 void HyperLabel::LoseFocus()
227 HyperLabel::~HyperLabel( )
232 void HyperLabel::SetInteractive( sal_Bool _bInteractive
)
234 m_pImpl
->bInteractive
= ( _bInteractive
&& IsEnabled() );
237 void HyperLabel::SetHyperLabelPosition(sal_uInt16 XPos
, sal_uInt16 YPos
)
239 SetPosPixel( LogicToPixel( Point( XPos
, YPos
), MAP_APPFONT
) );
242 Point
HyperLabel::GetLogicalPosition()
244 Point aPoint
= GetPosPixel( );
245 return PixelToLogic( aPoint
, MAP_APPFONT
);
248 sal_Int16
HyperLabel::GetID() const
253 sal_Int32
HyperLabel::GetIndex() const
255 return m_pImpl
->Index
;
258 void HyperLabel::SetID( sal_Int16 _ID
)
263 void HyperLabel::SetIndex( sal_Int32 _Index
)
265 m_pImpl
->Index
= _Index
;
268 ::rtl::OUString
HyperLabel::GetLabel( )
273 void HyperLabel::SetLabel( ::rtl::OUString _rText
)
280 //------------------------------------------------------------------------------
281 void HyperLabel::DataChanged( const DataChangedEvent
& rDCEvt
)
283 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
284 FixedText::DataChanged( rDCEvt
);
285 if ((( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) ||
286 ( rDCEvt
.GetType() == DATACHANGED_DISPLAY
)) &&
287 ( rDCEvt
.GetFlags() & SETTINGS_STYLE
))
289 const Color
& rGBColor
= GetControlBackground();
290 if (rGBColor
== COL_TRANSPARENT
)
291 SetTextColor( rStyleSettings
.GetFieldTextColor( ) );
294 SetControlBackground(rStyleSettings
.GetHighlightColor());
295 SetTextColor( rStyleSettings
.GetHighlightTextColor( ) );
301 //.........................................................................
303 //.........................................................................