1a462bbb7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a462bbb7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a462bbb7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a462bbb7SAndrew Rist  * distributed with this work for additional information
6a462bbb7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a462bbb7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a462bbb7SAndrew Rist  * "License"); you may not use this file except in compliance
9a462bbb7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10a462bbb7SAndrew Rist  *
11a462bbb7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a462bbb7SAndrew Rist  *
13a462bbb7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a462bbb7SAndrew Rist  * software distributed under the License is distributed on an
15a462bbb7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a462bbb7SAndrew Rist  * KIND, either express or implied.  See the License for the
17a462bbb7SAndrew Rist  * specific language governing permissions and limitations
18a462bbb7SAndrew Rist  * under the License.
19a462bbb7SAndrew Rist  *
20a462bbb7SAndrew Rist  *************************************************************/
21a462bbb7SAndrew Rist 
22a462bbb7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
25cdf0e10cSrcweir #define ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <accessibility/helper/IComboListBoxHelper.hxx>
28cdf0e10cSrcweir #include <vcl/lstbox.hxx>
29cdf0e10cSrcweir #include <vcl/combobox.hxx>
30cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // -----------------------------------------------------------------------------
33cdf0e10cSrcweir // globals
34cdf0e10cSrcweir // -----------------------------------------------------------------------------
35cdf0e10cSrcweir 
36cdf0e10cSrcweir const sal_Int32 DEFAULT_INDEX_IN_PARENT = -1;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // -----------------------------------------------------------------------------
39cdf0e10cSrcweir // class VCLListBoxHelper
40cdf0e10cSrcweir // -----------------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir template< class T > class VCLListBoxHelper : public ::accessibility::IComboListBoxHelper
43cdf0e10cSrcweir {
44cdf0e10cSrcweir private:
45cdf0e10cSrcweir 	T&	m_aComboListBox;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir public:
48cdf0e10cSrcweir 	inline
VCLListBoxHelper(T & _pListBox)49cdf0e10cSrcweir 	VCLListBoxHelper( T& _pListBox ) :
50cdf0e10cSrcweir 		m_aComboListBox( _pListBox ){}
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetEntry(sal_uInt16 nPos) const53cdf0e10cSrcweir 	virtual String			GetEntry( sal_uInt16 nPos ) const
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		return m_aComboListBox.GetEntry( nPos );
56cdf0e10cSrcweir 	}
57cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetDropDownPosSizePixel() const58cdf0e10cSrcweir 	virtual Rectangle		GetDropDownPosSizePixel() const
59cdf0e10cSrcweir 	{
60cdf0e10cSrcweir 		Rectangle aTemp = m_aComboListBox.GetWindowExtentsRelative(NULL);
61cdf0e10cSrcweir 		Rectangle aRet = m_aComboListBox.GetDropDownPosSizePixel();
62cdf0e10cSrcweir 		aRet.Move(aTemp.TopLeft().X(),aTemp.TopLeft().Y());
63cdf0e10cSrcweir 		return aRet;
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetBoundingRectangle(sal_uInt16 nItem) const66cdf0e10cSrcweir 	virtual Rectangle		GetBoundingRectangle( sal_uInt16 nItem ) const
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		Rectangle aRect;
69cdf0e10cSrcweir 		if ( m_aComboListBox.IsInDropDown() && IsEntryVisible( nItem ) )
70cdf0e10cSrcweir 		{
71cdf0e10cSrcweir 			Rectangle aTemp = m_aComboListBox.GetDropDownPosSizePixel();
72cdf0e10cSrcweir 			Size aSize = aTemp.GetSize();
73cdf0e10cSrcweir 			aSize.Height() /= m_aComboListBox.GetDisplayLineCount();
74cdf0e10cSrcweir 			Point aTopLeft = aTemp.TopLeft();
75cdf0e10cSrcweir 			aTopLeft.Y() += aSize.Height() * ( nItem - m_aComboListBox.GetTopEntry() );
76cdf0e10cSrcweir 			aRect = Rectangle( aTopLeft, aSize );
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 		else
79cdf0e10cSrcweir 			aRect = m_aComboListBox.GetBoundingRectangle( nItem );
80cdf0e10cSrcweir 		return aRect;
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetWindowExtentsRelative(Window * pRelativeWindow)83cdf0e10cSrcweir     virtual Rectangle		GetWindowExtentsRelative( Window* pRelativeWindow )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		return m_aComboListBox.GetWindowExtentsRelative( pRelativeWindow );
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IsActive() const88cdf0e10cSrcweir     virtual sal_Bool        	IsActive() const
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		return m_aComboListBox.IsActive();
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IsEnabled() const93*21075d77SSteve Yin     virtual sal_Bool        	IsEnabled() const
94*21075d77SSteve Yin 	{
95*21075d77SSteve Yin 		return m_aComboListBox.IsEnabled();
96*21075d77SSteve Yin 	}
97*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
IsEntryVisible(sal_uInt16 nPos) const98cdf0e10cSrcweir 	virtual sal_Bool			IsEntryVisible( sal_uInt16 nPos ) const
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		sal_uInt16 nTopEntry = m_aComboListBox.GetTopEntry();
101cdf0e10cSrcweir 		sal_uInt16 nLines = m_aComboListBox.GetDisplayLineCount();
102cdf0e10cSrcweir 		return ( nPos >= nTopEntry && nPos < ( nTopEntry + nLines ) );
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetDisplayLineCount() const105cdf0e10cSrcweir 	virtual sal_uInt16			GetDisplayLineCount() const
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		return m_aComboListBox.GetDisplayLineCount();
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetMaxVisColumnsAndLines(sal_uInt16 & rnCols,sal_uInt16 & rnLines) const110cdf0e10cSrcweir 	virtual void            GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		m_aComboListBox.GetMaxVisColumnsAndLines(rnCols,rnLines);
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetStyle() const115cdf0e10cSrcweir 	virtual WinBits         GetStyle() const
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		return m_aComboListBox.GetStyle();
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IsMultiSelectionEnabled() const120cdf0e10cSrcweir 	virtual sal_Bool            IsMultiSelectionEnabled() const
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		return m_aComboListBox.IsMultiSelectionEnabled();
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetTopEntry() const125cdf0e10cSrcweir 	virtual sal_uInt16			GetTopEntry() const
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		return m_aComboListBox.GetTopEntry();
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IsEntryPosSelected(sal_uInt16 nPos) const130cdf0e10cSrcweir 	virtual sal_Bool			IsEntryPosSelected( sal_uInt16 nPos ) const
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		return m_aComboListBox.IsEntryPosSelected(nPos);
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetEntryCount() const135cdf0e10cSrcweir 	virtual sal_uInt16          GetEntryCount() const
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		return m_aComboListBox.GetEntryCount();
138cdf0e10cSrcweir 	}
139cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
Select()140cdf0e10cSrcweir 	virtual void    Select()
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir 		m_aComboListBox.Select();
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
SelectEntryPos(sal_uInt16 nPos,sal_Bool bSelect=sal_True)145cdf0e10cSrcweir 	virtual void	SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True )
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		m_aComboListBox.SelectEntryPos(nPos,bSelect);
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetSelectEntryCount() const150cdf0e10cSrcweir 	virtual sal_uInt16			GetSelectEntryCount() const
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		return m_aComboListBox.GetSelectEntryCount();
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
SetNoSelection()155cdf0e10cSrcweir 	virtual void	SetNoSelection()
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		m_aComboListBox.SetNoSelection();
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetSelectEntryPos(sal_uInt16 nSelIndex=0) const160cdf0e10cSrcweir 	virtual sal_uInt16			GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const
161cdf0e10cSrcweir 	{
162cdf0e10cSrcweir 		return m_aComboListBox.GetSelectEntryPos(nSelIndex);
163cdf0e10cSrcweir 	}
164cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
IsInDropDown() const165cdf0e10cSrcweir 	virtual sal_Bool            IsInDropDown() const
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 		return m_aComboListBox.IsInDropDown();
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetEntryCharacterBounds(const sal_Int32 _nEntryPos,const sal_Int32 _nCharacterIndex) const170cdf0e10cSrcweir 	virtual Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         Rectangle aRect;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 		Pair aEntryCharacterRange = m_aComboListBox.GetLineStartEnd( _nEntryPos );
175cdf0e10cSrcweir 		if ( aEntryCharacterRange.A() + _nCharacterIndex <= aEntryCharacterRange.B() )
176cdf0e10cSrcweir 		{
177cdf0e10cSrcweir 			long nIndex = aEntryCharacterRange.A() + _nCharacterIndex;
178cdf0e10cSrcweir 			aRect = m_aComboListBox.GetCharacterBounds( nIndex );
179cdf0e10cSrcweir 		}
180cdf0e10cSrcweir         return aRect;
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetIndexForPoint(const Point & rPoint,sal_uInt16 & nPos) const183cdf0e10cSrcweir     long GetIndexForPoint( const Point& rPoint, sal_uInt16& nPos ) const
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         return m_aComboListBox.GetIndexForPoint( rPoint, nPos );
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
188cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >
GetClipboard()189cdf0e10cSrcweir         GetClipboard()
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         return m_aComboListBox.GetClipboard();
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
194cdf0e10cSrcweir };
195cdf0e10cSrcweir 
196cdf0e10cSrcweir #endif	// ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
197cdf0e10cSrcweir 
198