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 #include <svtools/tooltiplbox.hxx>
27cdf0e10cSrcweir #include <vcl/help.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // ============================================================================
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace svtools {
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // ----------------------------------------------------------------------------
34cdf0e10cSrcweir 
lcl_ToolTipLBox_ShowToolTip(ListBox & rListBox,const HelpEvent & rHEvt)35cdf0e10cSrcweir void lcl_ToolTipLBox_ShowToolTip( ListBox& rListBox, const HelpEvent& rHEvt )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir     // only show tooltip if helpmode is BALLOON or QUICK
38cdf0e10cSrcweir     if ( !( rHEvt.GetMode() & HELPMODE_BALLOON ) && !( rHEvt.GetMode() & HELPMODE_QUICK ) )
39cdf0e10cSrcweir     {
40cdf0e10cSrcweir         // else call base class method
41cdf0e10cSrcweir         rListBox.ListBox::RequestHelp( rHEvt );
42cdf0e10cSrcweir         return ;
43cdf0e10cSrcweir     }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     // find the list box entry the mouse points to
46cdf0e10cSrcweir     Point aMousePos( rListBox.ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     sal_uInt16 nTop = rListBox.GetTopEntry();
49cdf0e10cSrcweir     sal_uInt16 nBottom = nTop + rListBox.GetDisplayLineCount();
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     sal_uInt16 nPos;
52cdf0e10cSrcweir     for( nPos = nTop; nPos < nBottom; ++nPos )
53cdf0e10cSrcweir     {
54cdf0e10cSrcweir         Rectangle aItemRect( rListBox.GetBoundingRectangle( nPos ) );
55cdf0e10cSrcweir         if( (aItemRect.Top() <= aMousePos.Y()) && (aMousePos.Y() <= aItemRect.Bottom()) )
56cdf0e10cSrcweir             break;
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     // show text content of the entry, if it does not fit
60cdf0e10cSrcweir     if( nPos < nBottom )
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         String aHelpText( rListBox.GetEntry( nPos ) );
63cdf0e10cSrcweir         if( rListBox.GetTextWidth( aHelpText ) > rListBox.GetOutputSizePixel().Width() )
64cdf0e10cSrcweir         {
65cdf0e10cSrcweir             Point aLBoxPos( rListBox.OutputToScreenPixel( Point( 0, 0 ) ) );
66cdf0e10cSrcweir             Size aLBoxSize( rListBox.GetSizePixel() );
67cdf0e10cSrcweir             Rectangle aLBoxRect( aLBoxPos, aLBoxSize );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir             if( rHEvt.GetMode() == HELPMODE_BALLOON )
70cdf0e10cSrcweir                 Help::ShowBalloon( &rListBox, aLBoxRect.Center(), aLBoxRect, aHelpText );
71cdf0e10cSrcweir             else
72cdf0e10cSrcweir                 Help::ShowQuickHelp( &rListBox, aLBoxRect, aHelpText );
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // ----------------------------------------------------------------------------
78cdf0e10cSrcweir 
ToolTipListBox(Window * pParent,WinBits nStyle)79cdf0e10cSrcweir ToolTipListBox::ToolTipListBox( Window* pParent, WinBits nStyle ) :
80cdf0e10cSrcweir     ListBox( pParent, nStyle )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
ToolTipListBox(Window * pParent,const ResId & rResId)84cdf0e10cSrcweir ToolTipListBox::ToolTipListBox( Window* pParent, const ResId& rResId ) :
85cdf0e10cSrcweir     ListBox( pParent, rResId )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
RequestHelp(const HelpEvent & rHEvt)89cdf0e10cSrcweir void ToolTipListBox::RequestHelp( const HelpEvent& rHEvt )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     lcl_ToolTipLBox_ShowToolTip( *this, rHEvt );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir // ----------------------------------------------------------------------------
95cdf0e10cSrcweir 
ToolTipMultiListBox(Window * pParent,WinBits nStyle)96cdf0e10cSrcweir ToolTipMultiListBox::ToolTipMultiListBox( Window* pParent, WinBits nStyle ) :
97cdf0e10cSrcweir     MultiListBox( pParent, nStyle )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
ToolTipMultiListBox(Window * pParent,const ResId & rResId)101cdf0e10cSrcweir ToolTipMultiListBox::ToolTipMultiListBox( Window* pParent, const ResId& rResId ) :
102cdf0e10cSrcweir     MultiListBox( pParent, rResId )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
RequestHelp(const HelpEvent & rHEvt)106cdf0e10cSrcweir void ToolTipMultiListBox::RequestHelp( const HelpEvent& rHEvt )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     lcl_ToolTipLBox_ShowToolTip( *this, rHEvt );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // ----------------------------------------------------------------------------
112cdf0e10cSrcweir 
113cdf0e10cSrcweir } // namespace svtools
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // ============================================================================
116cdf0e10cSrcweir 
117