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/editbrowsebox.hxx>
27 #include <com/sun/star/accessibility/XAccessible.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include "editbrowseboximpl.hxx"
30 #include <comphelper/types.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include "svtaccessiblefactory.hxx"
33 
34 namespace svt
35 {
36 	using namespace com::sun::star::accessibility;
37 	using namespace com::sun::star::uno;
38 	using namespace ::com::sun::star::accessibility::AccessibleEventId;
39 
40 // -----------------------------------------------------------------------------
CreateAccessibleCheckBoxCell(long _nRow,sal_uInt16 _nColumnPos,const TriState & eState,sal_Bool _bEnabled)41 Reference< XAccessible > EditBrowseBox::CreateAccessibleCheckBoxCell(long _nRow, sal_uInt16 _nColumnPos,const TriState& eState,sal_Bool _bEnabled)
42 {
43     Reference< XAccessible > xAccessible( GetAccessible() );
44 	Reference< XAccessibleContext > xAccContext;
45     if ( xAccessible.is() )
46         xAccContext = xAccessible->getAccessibleContext();
47 
48     Reference< XAccessible > xReturn;
49     if ( xAccContext.is() )
50     {
51         xReturn = getAccessibleFactory().createAccessibleCheckBoxCell(
52             xAccContext->getAccessibleChild( ::svt::BBINDEX_TABLE ),
53             *this,
54             NULL,
55             _nRow,
56             _nColumnPos,
57 		    eState,
58 		    _bEnabled,
59             sal_True
60         );
61     }
62     return xReturn;
63 }
64 // -----------------------------------------------------------------------------
CreateAccessibleCell(sal_Int32 _nRow,sal_uInt16 _nColumnPos)65 Reference< XAccessible > EditBrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
66 {
67     return BrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
68 }
69 // -----------------------------------------------------------------------------
GetAccessibleControlCount() const70 sal_Int32 EditBrowseBox::GetAccessibleControlCount() const
71 {
72     return IsEditing() ? 1 : 0;
73 }
74 // -----------------------------------------------------------------------------
implCreateActiveAccessible()75 void EditBrowseBox::implCreateActiveAccessible( )
76 {
77     DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
78     DBG_ASSERT( !m_aImpl->m_xActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
79 
80     if ( !m_aImpl->m_xActiveCell.is() && IsEditing() )
81     {
82  	    Reference< XAccessible > xCont = aController->GetWindow().GetAccessible();
83  	    Reference< XAccessible > xMy = GetAccessible();
84  	    if ( xMy.is() && xCont.is() )
85   	    {
86  		    m_aImpl->m_xActiveCell = getAccessibleFactory().createEditBrowseBoxTableCellAccess(
87  			    xMy,														// parent accessible
88  			    xCont,														// control accessible
89  			    VCLUnoHelper::GetInterface( &aController->GetWindow() ),	// focus window (for notifications)
90  			    *this,														// the browse box
91  			    GetCurRow(),
92  			    GetColumnPos( GetCurColumnId() )
93  		    );
94 
95  		    commitBrowseBoxEvent( CHILD, makeAny( m_aImpl->m_xActiveCell ), Any() );
96   	    }
97     }
98 }
99 
100 // -----------------------------------------------------------------------------
CreateAccessibleControl(sal_Int32 _nIndex)101 Reference< XAccessible > EditBrowseBox::CreateAccessibleControl( sal_Int32
102 #ifdef DBG_UTIL
103 _nIndex
104 #endif
105 )
106 {
107     DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
108 
109     if ( isAccessibleAlive() )
110     {
111     	if ( !m_aImpl->m_xActiveCell.is() )
112     		implCreateActiveAccessible();
113     }
114 
115     return m_aImpl->m_xActiveCell;
116 }
117 // -----------------------------------------------------------------------------
CreateAccessibleRowHeader(sal_Int32 _nRow)118 Reference<XAccessible > EditBrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
119 {
120     return BrowseBox::CreateAccessibleRowHeader( _nRow );
121 }
122 // -----------------------------------------------------------------------------
clearActiveCell()123 void EditBrowseBoxImpl::clearActiveCell()
124 {
125 	try
126 	{
127 		::comphelper::disposeComponent(m_xActiveCell);
128 	}
129 	catch(const Exception&)
130 	{
131 		OSL_ENSURE( sal_False, "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
132 	}
133 
134 	m_xActiveCell = NULL;
135 }
136 // -----------------------------------------------------------------------------
GrabTableFocus()137 void EditBrowseBox::GrabTableFocus()
138 {
139 	if ( aController.Is() )
140 		aController->GetWindow().GrabFocus();
141 }
142 //------------------------------------------------------------------------------
DetermineFocus(const sal_uInt16 _nGetFocusFlags)143 void EditBrowseBox::DetermineFocus( const sal_uInt16 _nGetFocusFlags )
144 {
145 	sal_Bool bFocus = sal_False;
146 	for (Window* pWindow = Application::GetFocusWindow();
147 		 pWindow && !bFocus;
148 		 pWindow = pWindow->GetParent())
149 		 bFocus = pWindow == this;
150 
151 	if (bFocus != bHasFocus)
152 	{
153 		bHasFocus = bFocus;
154 
155 		if ( GetBrowserFlags( ) & EBBF_SMART_TAB_TRAVEL )
156 		{
157 			if	(	bHasFocus							// we got the focus
158 				&&	( _nGetFocusFlags & GETFOCUS_TAB )	// using the TAB key
159 				)
160 			{
161 				long nRows = GetRowCount();
162 				sal_uInt16 nCols = ColCount();
163 
164 				if ( ( nRows > 0 ) && ( nCols > 0 ) )
165 				{
166 					if ( _nGetFocusFlags & GETFOCUS_FORWARD )
167 					{
168 						if ( GetColumnId( 0 ) != 0 )
169 						{
170 							GoToRowColumnId( 0, GetColumnId( 0 ) );
171 						}
172 						else
173 						{	// the first column is the handle column -> not focussable
174 							if ( nCols > 1 )
175 								GoToRowColumnId( 0, GetColumnId( 1 ) );
176 						}
177 					}
178 					else if ( _nGetFocusFlags & GETFOCUS_BACKWARD )
179 					{
180 						GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
181 					}
182 				}
183 			}
184 		}
185 	}
186 }
187 // -----------------------------------------------------------------------------
GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)188 Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
189 {
190 	Rectangle aRect;
191 	if ( SeekRow(_nRow) )
192 	{
193 		CellController* pController = GetController(
194             _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
195 		if ( pController )
196 			aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
197 	}
198 	return aRect;
199 }
200 // -----------------------------------------------------------------------------
GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point & _rPoint)201 sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
202 {
203 	sal_Int32 nRet = -1;
204 	if ( SeekRow(_nRow) )
205 	{
206 		CellController* pController = GetController(
207             _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
208 		if ( pController )
209 			nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
210 	}
211 	return nRet;
212 }
213 // -----------------------------------------------------------------------------
214 // -----------------------------------------------------------------------------
215 } // namespace svt
216 // -----------------------------------------------------------------------------
217 
218 
219