1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
),
60 sal_Int32
EditBrowseBox::GetAccessibleControlCount() const
62 return IsEditing() ? 1 : 0;
65 void EditBrowseBox::implCreateActiveAccessible( )
67 DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
68 DBG_ASSERT( !m_aImpl
->m_xActiveCell
.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
70 if ( m_aImpl
->m_xActiveCell
.is() || !IsEditing() )
73 Reference
< XAccessible
> xCont
= aController
->GetWindow().GetAccessible();
74 Reference
< XAccessible
> xMy
= GetAccessible();
75 if ( !(xMy
.is() && xCont
.is()) )
78 m_aImpl
->m_xActiveCell
= getAccessibleFactory().createEditBrowseBoxTableCellAccess(
79 xMy
, // parent accessible
80 xCont
, // control accessible
81 VCLUnoHelper::GetInterface( &aController
->GetWindow() ), // focus window (for notifications)
82 *this, // the browse box
84 GetColumnPos( GetCurColumnId() )
87 commitBrowseBoxEvent( CHILD
, Any( m_aImpl
->m_xActiveCell
), Any() );
91 Reference
< XAccessible
> EditBrowseBox::CreateAccessibleControl( sal_Int32 _nIndex
)
93 DBG_ASSERT( 0 == _nIndex
, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
95 if ( isAccessibleAlive() )
97 if ( !m_aImpl
->m_xActiveCell
.is() )
98 implCreateActiveAccessible();
101 return m_aImpl
->m_xActiveCell
;
104 void EditBrowseBoxImpl::clearActiveCell()
108 ::comphelper::disposeComponent(m_xActiveCell
);
110 catch(const Exception
&)
112 TOOLS_WARN_EXCEPTION( "svtools", "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
115 m_xActiveCell
= nullptr;
118 void EditBrowseBox::GrabTableFocus()
120 if ( aController
.is() )
121 aController
->GetWindow().GrabFocus();
124 void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags
)
126 bool bFocus
= ControlHasFocus();
127 for (vcl::Window
* pWindow
= Application::GetFocusWindow();
129 pWindow
= pWindow
->GetParent())
130 bFocus
= pWindow
== this;
132 if (bFocus
== bHasFocus
)
137 if ( !(GetBrowserFlags( ) & EditBrowseBoxFlags::SMART_TAB_TRAVEL
) )
140 if ( !(bHasFocus
// we got the focus
141 && ( _nGetFocusFlags
& GetFocusFlags::Tab
)) // using the TAB key
145 sal_Int32 nRows
= GetRowCount();
146 sal_uInt16 nCols
= ColCount();
148 if (( nRows
<= 0 ) || ( nCols
<= 0 ))
151 if ( _nGetFocusFlags
& GetFocusFlags::Forward
)
153 if ( GetColumnId( 0 ) != HandleColumnId
)
155 GoToRowColumnId( 0, GetColumnId( 0 ) );
158 { // the first column is the handle column -> not focussable
160 GoToRowColumnId( 0, GetColumnId( 1 ) );
163 else if ( _nGetFocusFlags
& GetFocusFlags::Backward
)
165 GoToRowColumnId( nRows
- 1, GetColumnId( nCols
-1 ) );
169 tools::Rectangle
EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,sal_Int32 _nIndex
)
171 tools::Rectangle aRect
;
172 if ( SeekRow(_nRow
) )
174 CellController
* pController
= GetController(
175 _nRow
, GetColumnId( sal::static_int_cast
< sal_uInt16
>(_nColumnPos
) ) );
177 aRect
= pController
->GetWindow().GetCharacterBounds(_nIndex
);
182 sal_Int32
EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
)
185 if ( SeekRow(_nRow
) )
187 CellController
* pController
= GetController(
188 _nRow
, GetColumnId( sal::static_int_cast
< sal_uInt16
>(_nColumnPos
) ) );
190 nRet
= pController
->GetWindow().GetIndexForPoint(_rPoint
);
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */