1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
29 #define ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
30 
31 #include <accessibility/helper/IComboListBoxHelper.hxx>
32 #include <vcl/lstbox.hxx>
33 #include <vcl/combobox.hxx>
34 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
35 
36 // -----------------------------------------------------------------------------
37 // globals
38 // -----------------------------------------------------------------------------
39 
40 const sal_Int32 DEFAULT_INDEX_IN_PARENT = -1;
41 
42 // -----------------------------------------------------------------------------
43 // class VCLListBoxHelper
44 // -----------------------------------------------------------------------------
45 
46 template< class T > class VCLListBoxHelper : public ::accessibility::IComboListBoxHelper
47 {
48 private:
49 	T&	m_aComboListBox;
50 
51 public:
52 	inline
53 	VCLListBoxHelper( T& _pListBox ) :
54 		m_aComboListBox( _pListBox ){}
55 
56 	// -----------------------------------------------------------------------------
57 	virtual String			GetEntry( sal_uInt16 nPos ) const
58 	{
59 		return m_aComboListBox.GetEntry( nPos );
60 	}
61 	// -----------------------------------------------------------------------------
62 	virtual Rectangle		GetDropDownPosSizePixel() const
63 	{
64 		Rectangle aTemp = m_aComboListBox.GetWindowExtentsRelative(NULL);
65 		Rectangle aRet = m_aComboListBox.GetDropDownPosSizePixel();
66 		aRet.Move(aTemp.TopLeft().X(),aTemp.TopLeft().Y());
67 		return aRet;
68 	}
69 	// -----------------------------------------------------------------------------
70 	virtual Rectangle		GetBoundingRectangle( sal_uInt16 nItem ) const
71 	{
72 		Rectangle aRect;
73 		if ( m_aComboListBox.IsInDropDown() && IsEntryVisible( nItem ) )
74 		{
75 			Rectangle aTemp = m_aComboListBox.GetDropDownPosSizePixel();
76 			Size aSize = aTemp.GetSize();
77 			aSize.Height() /= m_aComboListBox.GetDisplayLineCount();
78 			Point aTopLeft = aTemp.TopLeft();
79 			aTopLeft.Y() += aSize.Height() * ( nItem - m_aComboListBox.GetTopEntry() );
80 			aRect = Rectangle( aTopLeft, aSize );
81 		}
82 		else
83 			aRect = m_aComboListBox.GetBoundingRectangle( nItem );
84 		return aRect;
85 	}
86 	// -----------------------------------------------------------------------------
87     virtual Rectangle		GetWindowExtentsRelative( Window* pRelativeWindow )
88 	{
89 		return m_aComboListBox.GetWindowExtentsRelative( pRelativeWindow );
90 	}
91 	// -----------------------------------------------------------------------------
92     virtual sal_Bool        	IsActive() const
93 	{
94 		return m_aComboListBox.IsActive();
95 	}
96 	// -----------------------------------------------------------------------------
97 	virtual sal_Bool			IsEntryVisible( sal_uInt16 nPos ) const
98 	{
99 		sal_uInt16 nTopEntry = m_aComboListBox.GetTopEntry();
100 		sal_uInt16 nLines = m_aComboListBox.GetDisplayLineCount();
101 		return ( nPos >= nTopEntry && nPos < ( nTopEntry + nLines ) );
102 	}
103 	// -----------------------------------------------------------------------------
104 	virtual sal_uInt16			GetDisplayLineCount() const
105 	{
106 		return m_aComboListBox.GetDisplayLineCount();
107 	}
108 	// -----------------------------------------------------------------------------
109 	virtual void            GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
110 	{
111 		m_aComboListBox.GetMaxVisColumnsAndLines(rnCols,rnLines);
112 	}
113 	// -----------------------------------------------------------------------------
114 	virtual WinBits         GetStyle() const
115 	{
116 		return m_aComboListBox.GetStyle();
117 	}
118 	// -----------------------------------------------------------------------------
119 	virtual sal_Bool            IsMultiSelectionEnabled() const
120 	{
121 		return m_aComboListBox.IsMultiSelectionEnabled();
122 	}
123 	// -----------------------------------------------------------------------------
124 	virtual sal_uInt16			GetTopEntry() const
125 	{
126 		return m_aComboListBox.GetTopEntry();
127 	}
128 	// -----------------------------------------------------------------------------
129 	virtual sal_Bool			IsEntryPosSelected( sal_uInt16 nPos ) const
130 	{
131 		return m_aComboListBox.IsEntryPosSelected(nPos);
132 	}
133 	// -----------------------------------------------------------------------------
134 	virtual sal_uInt16          GetEntryCount() const
135 	{
136 		return m_aComboListBox.GetEntryCount();
137 	}
138 	// -----------------------------------------------------------------------------
139 	virtual void    Select()
140 	{
141 		m_aComboListBox.Select();
142 	}
143 	// -----------------------------------------------------------------------------
144 	virtual void	SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True )
145 	{
146 		m_aComboListBox.SelectEntryPos(nPos,bSelect);
147 	}
148 	// -----------------------------------------------------------------------------
149 	virtual sal_uInt16			GetSelectEntryCount() const
150 	{
151 		return m_aComboListBox.GetSelectEntryCount();
152 	}
153 	// -----------------------------------------------------------------------------
154 	virtual void	SetNoSelection()
155 	{
156 		m_aComboListBox.SetNoSelection();
157 	}
158 	// -----------------------------------------------------------------------------
159 	virtual sal_uInt16			GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const
160 	{
161 		return m_aComboListBox.GetSelectEntryPos(nSelIndex);
162 	}
163 	// -----------------------------------------------------------------------------
164 	virtual sal_Bool            IsInDropDown() const
165 	{
166 		return m_aComboListBox.IsInDropDown();
167 	}
168 	// -----------------------------------------------------------------------------
169 	virtual Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
170     {
171         Rectangle aRect;
172 
173 		Pair aEntryCharacterRange = m_aComboListBox.GetLineStartEnd( _nEntryPos );
174 		if ( aEntryCharacterRange.A() + _nCharacterIndex <= aEntryCharacterRange.B() )
175 		{
176 			long nIndex = aEntryCharacterRange.A() + _nCharacterIndex;
177 			aRect = m_aComboListBox.GetCharacterBounds( nIndex );
178 		}
179         return aRect;
180 	}
181 	// -----------------------------------------------------------------------------
182     long GetIndexForPoint( const Point& rPoint, sal_uInt16& nPos ) const
183     {
184         return m_aComboListBox.GetIndexForPoint( rPoint, nPos );
185     }
186 	// -----------------------------------------------------------------------------
187 	::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >
188         GetClipboard()
189     {
190         return m_aComboListBox.GetClipboard();
191     }
192 	// -----------------------------------------------------------------------------
193 };
194 
195 #endif	// ACCESSIBILITY_HELPER_LISTBOXHELPER_HXX
196 
197