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 #ifndef ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
25 #define ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
26 
27 #include <accessibility/helper/IComboListBoxHelper.hxx>
28 #include <vcl/lstbox.hxx>
29 #include <vcl/combobox.hxx>
30 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
31 
32 // -----------------------------------------------------------------------------
33 // globals
34 // -----------------------------------------------------------------------------
35 
36 const sal_Int32 DEFAULT_INDEX_IN_PARENT = -1;
37 
38 // -----------------------------------------------------------------------------
39 // class VCLListBoxHelper
40 // -----------------------------------------------------------------------------
41 
42 template< class T > class VCLListBoxHelper : public ::accessibility::IComboListBoxHelper
43 {
44 private:
45 	T&	m_aComboListBox;
46 
47 public:
48 	inline
VCLListBoxHelper(T & _pListBox)49 	VCLListBoxHelper( T& _pListBox ) :
50 		m_aComboListBox( _pListBox ){}
51 
52 	// -----------------------------------------------------------------------------
GetEntry(sal_uInt16 nPos) const53 	virtual String			GetEntry( sal_uInt16 nPos ) const
54 	{
55 		return m_aComboListBox.GetEntry( nPos );
56 	}
57 	// -----------------------------------------------------------------------------
GetDropDownPosSizePixel() const58 	virtual Rectangle		GetDropDownPosSizePixel() const
59 	{
60 		Rectangle aTemp = m_aComboListBox.GetWindowExtentsRelative(NULL);
61 		Rectangle aRet = m_aComboListBox.GetDropDownPosSizePixel();
62 		aRet.Move(aTemp.TopLeft().X(),aTemp.TopLeft().Y());
63 		return aRet;
64 	}
65 	// -----------------------------------------------------------------------------
GetBoundingRectangle(sal_uInt16 nItem) const66 	virtual Rectangle		GetBoundingRectangle( sal_uInt16 nItem ) const
67 	{
68 		Rectangle aRect;
69 		if ( m_aComboListBox.IsInDropDown() && IsEntryVisible( nItem ) )
70 		{
71 			Rectangle aTemp = m_aComboListBox.GetDropDownPosSizePixel();
72 			Size aSize = aTemp.GetSize();
73 			aSize.Height() /= m_aComboListBox.GetDisplayLineCount();
74 			Point aTopLeft = aTemp.TopLeft();
75 			aTopLeft.Y() += aSize.Height() * ( nItem - m_aComboListBox.GetTopEntry() );
76 			aRect = Rectangle( aTopLeft, aSize );
77 		}
78 		else
79 			aRect = m_aComboListBox.GetBoundingRectangle( nItem );
80 		return aRect;
81 	}
82 	// -----------------------------------------------------------------------------
GetWindowExtentsRelative(Window * pRelativeWindow)83     virtual Rectangle		GetWindowExtentsRelative( Window* pRelativeWindow )
84 	{
85 		return m_aComboListBox.GetWindowExtentsRelative( pRelativeWindow );
86 	}
87 	// -----------------------------------------------------------------------------
IsActive() const88     virtual sal_Bool        	IsActive() const
89 	{
90 		return m_aComboListBox.IsActive();
91 	}
92 	// -----------------------------------------------------------------------------
IsEnabled() const93     virtual sal_Bool        	IsEnabled() const
94 	{
95 		return m_aComboListBox.IsEnabled();
96 	}
97 	// -----------------------------------------------------------------------------
IsEntryVisible(sal_uInt16 nPos) const98 	virtual sal_Bool			IsEntryVisible( sal_uInt16 nPos ) const
99 	{
100 		sal_uInt16 nTopEntry = m_aComboListBox.GetTopEntry();
101 		sal_uInt16 nLines = m_aComboListBox.GetDisplayLineCount();
102 		return ( nPos >= nTopEntry && nPos < ( nTopEntry + nLines ) );
103 	}
104 	// -----------------------------------------------------------------------------
GetDisplayLineCount() const105 	virtual sal_uInt16			GetDisplayLineCount() const
106 	{
107 		return m_aComboListBox.GetDisplayLineCount();
108 	}
109 	// -----------------------------------------------------------------------------
GetMaxVisColumnsAndLines(sal_uInt16 & rnCols,sal_uInt16 & rnLines) const110 	virtual void            GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
111 	{
112 		m_aComboListBox.GetMaxVisColumnsAndLines(rnCols,rnLines);
113 	}
114 	// -----------------------------------------------------------------------------
GetStyle() const115 	virtual WinBits         GetStyle() const
116 	{
117 		return m_aComboListBox.GetStyle();
118 	}
119 	// -----------------------------------------------------------------------------
IsMultiSelectionEnabled() const120 	virtual sal_Bool            IsMultiSelectionEnabled() const
121 	{
122 		return m_aComboListBox.IsMultiSelectionEnabled();
123 	}
124 	// -----------------------------------------------------------------------------
GetTopEntry() const125 	virtual sal_uInt16			GetTopEntry() const
126 	{
127 		return m_aComboListBox.GetTopEntry();
128 	}
129 	// -----------------------------------------------------------------------------
IsEntryPosSelected(sal_uInt16 nPos) const130 	virtual sal_Bool			IsEntryPosSelected( sal_uInt16 nPos ) const
131 	{
132 		return m_aComboListBox.IsEntryPosSelected(nPos);
133 	}
134 	// -----------------------------------------------------------------------------
GetEntryCount() const135 	virtual sal_uInt16          GetEntryCount() const
136 	{
137 		return m_aComboListBox.GetEntryCount();
138 	}
139 	// -----------------------------------------------------------------------------
Select()140 	virtual void    Select()
141 	{
142 		m_aComboListBox.Select();
143 	}
144 	// -----------------------------------------------------------------------------
SelectEntryPos(sal_uInt16 nPos,sal_Bool bSelect=sal_True)145 	virtual void	SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True )
146 	{
147 		m_aComboListBox.SelectEntryPos(nPos,bSelect);
148 	}
149 	// -----------------------------------------------------------------------------
GetSelectEntryCount() const150 	virtual sal_uInt16			GetSelectEntryCount() const
151 	{
152 		return m_aComboListBox.GetSelectEntryCount();
153 	}
154 	// -----------------------------------------------------------------------------
SetNoSelection()155 	virtual void	SetNoSelection()
156 	{
157 		m_aComboListBox.SetNoSelection();
158 	}
159 	// -----------------------------------------------------------------------------
GetSelectEntryPos(sal_uInt16 nSelIndex=0) const160 	virtual sal_uInt16			GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const
161 	{
162 		return m_aComboListBox.GetSelectEntryPos(nSelIndex);
163 	}
164 	// -----------------------------------------------------------------------------
IsInDropDown() const165 	virtual sal_Bool            IsInDropDown() const
166 	{
167 		return m_aComboListBox.IsInDropDown();
168 	}
169 	// -----------------------------------------------------------------------------
GetEntryCharacterBounds(const sal_Int32 _nEntryPos,const sal_Int32 _nCharacterIndex) const170 	virtual Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
171     {
172         Rectangle aRect;
173 
174 		Pair aEntryCharacterRange = m_aComboListBox.GetLineStartEnd( _nEntryPos );
175 		if ( aEntryCharacterRange.A() + _nCharacterIndex <= aEntryCharacterRange.B() )
176 		{
177 			long nIndex = aEntryCharacterRange.A() + _nCharacterIndex;
178 			aRect = m_aComboListBox.GetCharacterBounds( nIndex );
179 		}
180         return aRect;
181 	}
182 	// -----------------------------------------------------------------------------
GetIndexForPoint(const Point & rPoint,sal_uInt16 & nPos) const183     long GetIndexForPoint( const Point& rPoint, sal_uInt16& nPos ) const
184     {
185         return m_aComboListBox.GetIndexForPoint( rPoint, nPos );
186     }
187 	// -----------------------------------------------------------------------------
188 	::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >
GetClipboard()189         GetClipboard()
190     {
191         return m_aComboListBox.GetClipboard();
192     }
193 	// -----------------------------------------------------------------------------
194 };
195 
196 #endif	// ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
197 
198