Update ooo320-m1
[ooovba.git] / svtools / source / contnr / tooltiplbox.cxx
blobe815ca5e97e8da6817c6233ce2eeb4fa52d58567
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: tooltiplbox.cxx,v $
10 * $Revision: 1.5 $
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 #include "tooltiplbox.hxx"
34 #include <vcl/help.hxx>
36 // ============================================================================
38 namespace svtools {
40 // ----------------------------------------------------------------------------
42 void lcl_ToolTipLBox_ShowToolTip( ListBox& rListBox, const HelpEvent& rHEvt )
44 // only show tooltip if helpmode is BALLOON or QUICK
45 if ( !( rHEvt.GetMode() & HELPMODE_BALLOON ) && !( rHEvt.GetMode() & HELPMODE_QUICK ) )
47 // else call base class method
48 rListBox.ListBox::RequestHelp( rHEvt );
49 return ;
52 // find the list box entry the mouse points to
53 Point aMousePos( rListBox.ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
55 sal_uInt16 nTop = rListBox.GetTopEntry();
56 sal_uInt16 nBottom = nTop + rListBox.GetDisplayLineCount();
58 sal_uInt16 nPos;
59 for( nPos = nTop; nPos < nBottom; ++nPos )
61 Rectangle aItemRect( rListBox.GetBoundingRectangle( nPos ) );
62 if( (aItemRect.Top() <= aMousePos.Y()) && (aMousePos.Y() <= aItemRect.Bottom()) )
63 break;
66 // show text content of the entry, if it does not fit
67 if( nPos < nBottom )
69 String aHelpText( rListBox.GetEntry( nPos ) );
70 if( rListBox.GetTextWidth( aHelpText ) > rListBox.GetOutputSizePixel().Width() )
72 Point aLBoxPos( rListBox.OutputToScreenPixel( Point( 0, 0 ) ) );
73 Size aLBoxSize( rListBox.GetSizePixel() );
74 Rectangle aLBoxRect( aLBoxPos, aLBoxSize );
76 if( rHEvt.GetMode() == HELPMODE_BALLOON )
77 Help::ShowBalloon( &rListBox, aLBoxRect.Center(), aLBoxRect, aHelpText );
78 else
79 Help::ShowQuickHelp( &rListBox, aLBoxRect, aHelpText );
84 // ----------------------------------------------------------------------------
86 ToolTipListBox::ToolTipListBox( Window* pParent, WinBits nStyle ) :
87 ListBox( pParent, nStyle )
91 ToolTipListBox::ToolTipListBox( Window* pParent, const ResId& rResId ) :
92 ListBox( pParent, rResId )
96 void ToolTipListBox::RequestHelp( const HelpEvent& rHEvt )
98 lcl_ToolTipLBox_ShowToolTip( *this, rHEvt );
101 // ----------------------------------------------------------------------------
103 ToolTipMultiListBox::ToolTipMultiListBox( Window* pParent, WinBits nStyle ) :
104 MultiListBox( pParent, nStyle )
108 ToolTipMultiListBox::ToolTipMultiListBox( Window* pParent, const ResId& rResId ) :
109 MultiListBox( pParent, rResId )
113 void ToolTipMultiListBox::RequestHelp( const HelpEvent& rHEvt )
115 lcl_ToolTipLBox_ShowToolTip( *this, rHEvt );
118 // ----------------------------------------------------------------------------
120 } // namespace svtools
122 // ============================================================================