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
49 	VCLListBoxHelper( T& _pListBox ) :
50 		m_aComboListBox( _pListBox ){}
51 
52 	// -----------------------------------------------------------------------------
53 	virtual String			GetEntry( sal_uInt16 nPos ) const
54 	{
55 		return m_aComboListBox.GetEntry( nPos );
56 	}
57 	// -----------------------------------------------------------------------------
58 	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 	// -----------------------------------------------------------------------------
66 	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 	// -----------------------------------------------------------------------------
83     virtual Rectangle		GetWindowExtentsRelative( Window* pRelativeWindow )
84 	{
85 		return m_aComboListBox.GetWindowExtentsRelative( pRelativeWindow );
86 	}
87 	// -----------------------------------------------------------------------------
88     virtual sal_Bool        	IsActive() const
89 	{
90 		return m_aComboListBox.IsActive();
91 	}
92 	// -----------------------------------------------------------------------------
93 	virtual sal_Bool			IsEntryVisible( sal_uInt16 nPos ) const
94 	{
95 		sal_uInt16 nTopEntry = m_aComboListBox.GetTopEntry();
96 		sal_uInt16 nLines = m_aComboListBox.GetDisplayLineCount();
97 		return ( nPos >= nTopEntry && nPos < ( nTopEntry + nLines ) );
98 	}
99 	// -----------------------------------------------------------------------------
100 	virtual sal_uInt16			GetDisplayLineCount() const
101 	{
102 		return m_aComboListBox.GetDisplayLineCount();
103 	}
104 	// -----------------------------------------------------------------------------
105 	virtual void            GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
106 	{
107 		m_aComboListBox.GetMaxVisColumnsAndLines(rnCols,rnLines);
108 	}
109 	// -----------------------------------------------------------------------------
110 	virtual WinBits         GetStyle() const
111 	{
112 		return m_aComboListBox.GetStyle();
113 	}
114 	// -----------------------------------------------------------------------------
115 	virtual sal_Bool            IsMultiSelectionEnabled() const
116 	{
117 		return m_aComboListBox.IsMultiSelectionEnabled();
118 	}
119 	// -----------------------------------------------------------------------------
120 	virtual sal_uInt16			GetTopEntry() const
121 	{
122 		return m_aComboListBox.GetTopEntry();
123 	}
124 	// -----------------------------------------------------------------------------
125 	virtual sal_Bool			IsEntryPosSelected( sal_uInt16 nPos ) const
126 	{
127 		return m_aComboListBox.IsEntryPosSelected(nPos);
128 	}
129 	// -----------------------------------------------------------------------------
130 	virtual sal_uInt16          GetEntryCount() const
131 	{
132 		return m_aComboListBox.GetEntryCount();
133 	}
134 	// -----------------------------------------------------------------------------
135 	virtual void    Select()
136 	{
137 		m_aComboListBox.Select();
138 	}
139 	// -----------------------------------------------------------------------------
140 	virtual void	SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True )
141 	{
142 		m_aComboListBox.SelectEntryPos(nPos,bSelect);
143 	}
144 	// -----------------------------------------------------------------------------
145 	virtual sal_uInt16			GetSelectEntryCount() const
146 	{
147 		return m_aComboListBox.GetSelectEntryCount();
148 	}
149 	// -----------------------------------------------------------------------------
150 	virtual void	SetNoSelection()
151 	{
152 		m_aComboListBox.SetNoSelection();
153 	}
154 	// -----------------------------------------------------------------------------
155 	virtual sal_uInt16			GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const
156 	{
157 		return m_aComboListBox.GetSelectEntryPos(nSelIndex);
158 	}
159 	// -----------------------------------------------------------------------------
160 	virtual sal_Bool            IsInDropDown() const
161 	{
162 		return m_aComboListBox.IsInDropDown();
163 	}
164 	// -----------------------------------------------------------------------------
165 	virtual Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
166     {
167         Rectangle aRect;
168 
169 		Pair aEntryCharacterRange = m_aComboListBox.GetLineStartEnd( _nEntryPos );
170 		if ( aEntryCharacterRange.A() + _nCharacterIndex <= aEntryCharacterRange.B() )
171 		{
172 			long nIndex = aEntryCharacterRange.A() + _nCharacterIndex;
173 			aRect = m_aComboListBox.GetCharacterBounds( nIndex );
174 		}
175         return aRect;
176 	}
177 	// -----------------------------------------------------------------------------
178     long GetIndexForPoint( const Point& rPoint, sal_uInt16& nPos ) const
179     {
180         return m_aComboListBox.GetIndexForPoint( rPoint, nPos );
181     }
182 	// -----------------------------------------------------------------------------
183 	::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >
184         GetClipboard()
185     {
186         return m_aComboListBox.GetClipboard();
187     }
188 	// -----------------------------------------------------------------------------
189 };
190 
191 #endif	// ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
192 
193