Bump version to 5.0-14
[LibreOffice.git] / svtools / source / brwbox / editbrowsebox2.cxx
blobe3c6d3444a49f308a747ff57394ccaa3e70878c7
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 "svtaccessiblefactory.hxx"
28 namespace svt
30 using namespace com::sun::star::accessibility;
31 using namespace com::sun::star::uno;
32 using namespace ::com::sun::star::accessibility::AccessibleEventId;
35 Reference< XAccessible > EditBrowseBox::CreateAccessibleCheckBoxCell(long _nRow, sal_uInt16 _nColumnPos,const TriState& eState)
37 Reference< XAccessible > xAccessible( GetAccessible() );
38 Reference< XAccessibleContext > xAccContext;
39 if ( xAccessible.is() )
40 xAccContext = xAccessible->getAccessibleContext();
42 Reference< XAccessible > xReturn;
43 if ( xAccContext.is() )
45 xReturn = getAccessibleFactory().createAccessibleCheckBoxCell(
46 xAccContext->getAccessibleChild( ::svt::BBINDEX_TABLE ),
47 *this,
48 NULL,
49 _nRow,
50 _nColumnPos,
51 eState,
52 true
55 return xReturn;
58 Reference< XAccessible > EditBrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
60 return BrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
63 sal_Int32 EditBrowseBox::GetAccessibleControlCount() const
65 return IsEditing() ? 1 : 0;
68 void EditBrowseBox::implCreateActiveAccessible( )
70 DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
71 DBG_ASSERT( !m_aImpl->m_xActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
73 if ( !m_aImpl->m_xActiveCell.is() && IsEditing() )
75 Reference< XAccessible > xCont = aController->GetWindow().GetAccessible();
76 Reference< XAccessible > xMy = GetAccessible();
77 if ( xMy.is() && xCont.is() )
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, makeAny( m_aImpl->m_xActiveCell ), Any() );
94 Reference< XAccessible > EditBrowseBox::CreateAccessibleControl( sal_Int32
95 #ifdef DBG_UTIL
96 _nIndex
97 #endif
100 DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
102 if ( isAccessibleAlive() )
104 if ( !m_aImpl->m_xActiveCell.is() )
105 implCreateActiveAccessible();
108 return m_aImpl->m_xActiveCell;
111 Reference<XAccessible > EditBrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
113 return BrowseBox::CreateAccessibleRowHeader( _nRow );
116 void EditBrowseBoxImpl::clearActiveCell()
120 ::comphelper::disposeComponent(m_xActiveCell);
122 catch(const Exception&)
124 OSL_FAIL( "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
127 m_xActiveCell = NULL;
130 void EditBrowseBox::GrabTableFocus()
132 if ( aController.Is() )
133 aController->GetWindow().GrabFocus();
136 void EditBrowseBox::DetermineFocus( const sal_uInt16 _nGetFocusFlags )
138 bool bFocus = false;
139 for (vcl::Window* pWindow = Application::GetFocusWindow();
140 pWindow && !bFocus;
141 pWindow = pWindow->GetParent())
142 bFocus = pWindow == this;
144 if (bFocus != bHasFocus)
146 bHasFocus = bFocus;
148 if ( GetBrowserFlags( ) & EditBrowseBoxFlags::SMART_TAB_TRAVEL )
150 if ( bHasFocus // we got the focus
151 && ( _nGetFocusFlags & GETFOCUS_TAB ) // using the TAB key
154 long nRows = GetRowCount();
155 sal_uInt16 nCols = ColCount();
157 if ( ( nRows > 0 ) && ( nCols > 0 ) )
159 if ( _nGetFocusFlags & GETFOCUS_FORWARD )
161 if ( GetColumnId( 0 ) != HandleColumnId )
163 GoToRowColumnId( 0, GetColumnId( 0 ) );
165 else
166 { // the first column is the handle column -> not focussable
167 if ( nCols > 1 )
168 GoToRowColumnId( 0, GetColumnId( 1 ) );
171 else if ( _nGetFocusFlags & GETFOCUS_BACKWARD )
173 GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
181 Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
183 Rectangle aRect;
184 if ( SeekRow(_nRow) )
186 CellController* pController = GetController(
187 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
188 if ( pController )
189 aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
191 return aRect;
194 sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
196 sal_Int32 nRet = -1;
197 if ( SeekRow(_nRow) )
199 CellController* pController = GetController(
200 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
201 if ( pController )
202 nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
204 return nRet;
208 } // namespace svt
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */