update dev300-m58
[ooovba.git] / svtools / source / control / hyperlabel.cxx
blob00ab980a80140d91eaeb17c8708f3c17922bb68f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyperlabel.cxx,v $
10 * $Revision: 1.11 $
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>
35 #endif
36 #include <vcl/bitmap.hxx>
37 #include <tools/color.hxx>
39 #ifndef _VCL_TABPAGE_HXX
40 #include <vcl/tabpage.hxx>
41 #endif
44 //.........................................................................
45 namespace svt
47 //.........................................................................
49 //=====================================================================
50 //= FontChanger
51 //=====================================================================
52 class FontChanger
54 protected:
55 OutputDevice* m_pDev;
57 public:
58 FontChanger( OutputDevice* _pDev, const Font& _rNewFont )
59 :m_pDev( _pDev )
61 m_pDev->Push( PUSH_FONT );
62 m_pDev->SetFont( _rNewFont );
65 ~FontChanger()
67 m_pDev->Pop( );
71 class HyperLabelImpl
73 public:
74 sal_Int16 ID;
75 sal_Int32 Index;
76 sal_Bool bInteractive;
77 Size m_aMinSize;
78 sal_Bool m_bHyperMode;
80 HyperLabelImpl();
83 //---------------------------------------------------------------------
84 HyperLabelImpl::HyperLabelImpl()
88 HyperLabel::HyperLabel( Window* _pParent, const ResId& _rId )
89 :FixedText( _pParent, _rId )
90 ,m_pImpl( new HyperLabelImpl )
92 implInit();
95 HyperLabel::HyperLabel( Window* _pParent, WinBits _nWinStyle )
96 :FixedText( _pParent, _nWinStyle )
97 ,m_pImpl( new HyperLabelImpl )
99 implInit();
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 );
114 SetLabel( _rText );
115 ImplCalcMinimumSize( rLocSize );
116 rLocSize.Height() = ( m_pImpl->m_aMinSize.Height());
117 // else
118 // rLocSize = LogicToPixel( Size( rLogicLocSize.Width(), LABELBASEMAPHEIGHT ), MAP_APPFONT );
119 SetSizePixel( rLocSize );
120 Show();
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 );
147 Show();
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( ) );
156 else
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);
170 else
172 Point aPoint = GetPointerPosPixel();
173 if (aPoint.X() < m_pImpl->m_aMinSize.Width())
175 if ( IsEnabled() && (m_pImpl->bInteractive) )
177 ActivateHyperMode( aFont, aColor);
178 return;
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 )
216 Point aPoint(0,0);
217 Rectangle rRect(aPoint, Size( m_pImpl->m_aMinSize.Width(), GetSizePixel().Height() ) );
218 ShowFocus( rRect );
222 void HyperLabel::LoseFocus()
224 HideFocus();
227 HyperLabel::~HyperLabel( )
229 delete m_pImpl;
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
250 return m_pImpl->ID;
253 sal_Int32 HyperLabel::GetIndex() const
255 return m_pImpl->Index;
258 void HyperLabel::SetID( sal_Int16 _ID )
260 m_pImpl->ID = _ID;
263 void HyperLabel::SetIndex( sal_Int32 _Index )
265 m_pImpl->Index = _Index;
268 ::rtl::OUString HyperLabel::GetLabel( )
270 return GetText();
273 void HyperLabel::SetLabel( ::rtl::OUString _rText )
275 SetText(_rText);
276 Show();
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( ) );
292 else
294 SetControlBackground(rStyleSettings.GetHighlightColor());
295 SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
297 Invalidate();
301 //.........................................................................
302 } // namespace svt
303 //.........................................................................