Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / brwbox / editbrowsebox2.cxx
bloba72918ebb0fb40b1fb82764b5476860555b9d020
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/editbrowsebox.hxx>
21 #include <com/sun/star/accessibility/XAccessible.hpp>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include "editbrowseboximpl.hxx"
24 #include <comphelper/types.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <vcl/accessiblefactory.hxx>
27 #include <vcl/svapp.hxx>
28 #include <tools/debug.hxx>
29 #include <comphelper/diagnose_ex.hxx>
31 namespace svt
33 using namespace com::sun::star::accessibility;
34 using namespace com::sun::star::uno;
35 using namespace ::com::sun::star::accessibility::AccessibleEventId;
38 Reference< XAccessible > EditBrowseBox::CreateAccessibleCheckBoxCell(sal_Int32 _nRow, sal_uInt16 _nColumnPos,const TriState& eState)
40 Reference< XAccessible > xAccessible( GetAccessible() );
41 Reference< XAccessibleContext > xAccContext;
42 if ( xAccessible.is() )
43 xAccContext = xAccessible->getAccessibleContext();
45 Reference< XAccessible > xReturn;
46 if ( xAccContext.is() )
48 xReturn = getAccessibleFactory().createAccessibleCheckBoxCell(
49 xAccContext->getAccessibleChild( ::vcl::BBINDEX_TABLE ),
50 *this,
51 nullptr,
52 _nRow,
53 _nColumnPos,
54 eState,
55 true
58 return xReturn;
61 sal_Int32 EditBrowseBox::GetAccessibleControlCount() const
63 return IsEditing() ? 1 : 0;
66 void EditBrowseBox::implCreateActiveAccessible( )
68 DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
69 DBG_ASSERT( !m_aImpl->m_xActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
71 if ( m_aImpl->m_xActiveCell.is() || !IsEditing() )
72 return;
74 Reference< XAccessible > xCont = aController->GetWindow().GetAccessible();
75 Reference< XAccessible > xMy = GetAccessible();
76 if ( !(xMy.is() && xCont.is()) )
77 return;
79 m_aImpl->m_xActiveCell = getAccessibleFactory().createEditBrowseBoxTableCellAccess(
80 xMy, // parent accessible
81 xCont, // control accessible
82 VCLUnoHelper::GetInterface( &aController->GetWindow() ), // focus window (for notifications)
83 *this, // the browse box
84 GetCurRow(),
85 GetColumnPos( GetCurColumnId() )
88 commitBrowseBoxEvent( CHILD, Any( m_aImpl->m_xActiveCell ), Any() );
92 Reference< XAccessible > EditBrowseBox::CreateAccessibleControl( sal_Int32 _nIndex )
94 DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
96 if ( isAccessibleAlive() )
98 if ( !m_aImpl->m_xActiveCell.is() )
99 implCreateActiveAccessible();
102 return m_aImpl->m_xActiveCell;
105 void EditBrowseBoxImpl::clearActiveCell()
109 ::comphelper::disposeComponent(m_xActiveCell);
111 catch(const Exception&)
113 TOOLS_WARN_EXCEPTION( "svtools", "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
116 m_xActiveCell = nullptr;
119 void EditBrowseBox::GrabTableFocus()
121 if ( aController.is() )
122 aController->GetWindow().GrabFocus();
125 void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags )
127 bool bFocus = ControlHasFocus();
128 for (vcl::Window* pWindow = Application::GetFocusWindow();
129 pWindow && !bFocus;
130 pWindow = pWindow->GetParent())
131 bFocus = pWindow == this;
133 if (bFocus == bHasFocus)
134 return;
136 bHasFocus = bFocus;
138 if ( !(GetBrowserFlags( ) & EditBrowseBoxFlags::SMART_TAB_TRAVEL) )
139 return;
141 if ( !(bHasFocus // we got the focus
142 && ( _nGetFocusFlags & GetFocusFlags::Tab )) // using the TAB key
144 return;
146 sal_Int32 nRows = GetRowCount();
147 sal_uInt16 nCols = ColCount();
149 if (( nRows <= 0 ) || ( nCols <= 0 ))
150 return;
152 if ( _nGetFocusFlags & GetFocusFlags::Forward )
154 if ( GetColumnId( 0 ) != HandleColumnId )
156 GoToRowColumnId( 0, GetColumnId( 0 ) );
158 else
159 { // the first column is the handle column -> not focussable
160 if ( nCols > 1 )
161 GoToRowColumnId( 0, GetColumnId( 1 ) );
164 else if ( _nGetFocusFlags & GetFocusFlags::Backward )
166 GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
170 tools::Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
172 tools::Rectangle aRect;
173 if ( SeekRow(_nRow) )
175 CellController* pController = GetController(
176 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
177 if ( pController )
178 aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
180 return aRect;
183 sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
185 sal_Int32 nRet = -1;
186 if ( SeekRow(_nRow) )
188 CellController* pController = GetController(
189 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
190 if ( pController )
191 nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
193 return nRet;
197 } // namespace svt
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */