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