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
),
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() )
74 Reference
< XAccessible
> xCont
= aController
->GetWindow().GetAccessible();
75 Reference
< XAccessible
> xMy
= GetAccessible();
76 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
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();
130 pWindow
= pWindow
->GetParent())
131 bFocus
= pWindow
== this;
133 if (bFocus
== bHasFocus
)
138 if ( !(GetBrowserFlags( ) & EditBrowseBoxFlags::SMART_TAB_TRAVEL
) )
141 if ( !(bHasFocus
// we got the focus
142 && ( _nGetFocusFlags
& GetFocusFlags::Tab
)) // using the TAB key
146 sal_Int32 nRows
= GetRowCount();
147 sal_uInt16 nCols
= ColCount();
149 if (( nRows
<= 0 ) || ( nCols
<= 0 ))
152 if ( _nGetFocusFlags
& GetFocusFlags::Forward
)
154 if ( GetColumnId( 0 ) != HandleColumnId
)
156 GoToRowColumnId( 0, GetColumnId( 0 ) );
159 { // the first column is the handle column -> not focussable
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
) ) );
178 aRect
= pController
->GetWindow().GetCharacterBounds(_nIndex
);
183 sal_Int32
EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
)
186 if ( SeekRow(_nRow
) )
188 CellController
* pController
= GetController(
189 _nRow
, GetColumnId( sal::static_int_cast
< sal_uInt16
>(_nColumnPos
) ) );
191 nRet
= pController
->GetWindow().GetIndexForPoint(_rPoint
);
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */