1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editbrowsebox2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <svtools/editbrowsebox.hxx>
34 #include <com/sun/star/accessibility/XAccessible.hpp>
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include "editbrowseboximpl.hxx"
37 #include <comphelper/types.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include "svtaccessiblefactory.hxx"
43 using namespace com::sun::star::accessibility
;
44 using namespace com::sun::star::uno
;
45 using namespace ::com::sun::star::accessibility::AccessibleEventId
;
47 // -----------------------------------------------------------------------------
48 Reference
< XAccessible
> EditBrowseBox::CreateAccessibleCheckBoxCell(long _nRow
, USHORT _nColumnPos
,const TriState
& eState
,sal_Bool _bEnabled
)
50 Reference
< XAccessible
> xAccessible( GetAccessible() );
51 Reference
< XAccessibleContext
> xAccContext
;
52 if ( xAccessible
.is() )
53 xAccContext
= xAccessible
->getAccessibleContext();
55 Reference
< XAccessible
> xReturn
;
56 if ( xAccContext
.is() )
58 xReturn
= getAccessibleFactory().createAccessibleCheckBoxCell(
59 xAccContext
->getAccessibleChild( ::svt::BBINDEX_TABLE
),
71 // -----------------------------------------------------------------------------
72 Reference
< XAccessible
> EditBrowseBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
74 return BrowseBox::CreateAccessibleCell( _nRow
, _nColumnPos
);
76 // -----------------------------------------------------------------------------
77 sal_Int32
EditBrowseBox::GetAccessibleControlCount() const
79 return IsEditing() ? 1 : 0;
81 // -----------------------------------------------------------------------------
82 void EditBrowseBox::implCreateActiveAccessible( )
84 DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
85 DBG_ASSERT( !m_aImpl
->m_xActiveCell
.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
87 if ( !m_aImpl
->m_xActiveCell
.is() && IsEditing() )
89 Reference
< XAccessible
> xCont
= aController
->GetWindow().GetAccessible();
90 Reference
< XAccessible
> xMy
= GetAccessible();
91 if ( xMy
.is() && xCont
.is() )
93 m_aImpl
->m_xActiveCell
= getAccessibleFactory().createEditBrowseBoxTableCellAccess(
94 xMy
, // parent accessible
95 xCont
, // control accessible
96 VCLUnoHelper::GetInterface( &aController
->GetWindow() ), // focus window (for notifications)
97 *this, // the browse box
99 GetColumnPos( GetCurColumnId() )
102 commitBrowseBoxEvent( CHILD
, makeAny( m_aImpl
->m_xActiveCell
), Any() );
107 // -----------------------------------------------------------------------------
108 Reference
< XAccessible
> EditBrowseBox::CreateAccessibleControl( sal_Int32
114 DBG_ASSERT( 0 == _nIndex
, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
116 if ( isAccessibleAlive() )
118 if ( !m_aImpl
->m_xActiveCell
.is() )
119 implCreateActiveAccessible();
122 return m_aImpl
->m_xActiveCell
;
124 // -----------------------------------------------------------------------------
125 Reference
<XAccessible
> EditBrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow
)
127 return BrowseBox::CreateAccessibleRowHeader( _nRow
);
129 // -----------------------------------------------------------------------------
130 void EditBrowseBoxImpl::clearActiveCell()
134 ::comphelper::disposeComponent(m_xActiveCell
);
136 catch(const Exception
&)
138 OSL_ENSURE( sal_False
, "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
141 m_xActiveCell
= NULL
;
143 // -----------------------------------------------------------------------------
144 void EditBrowseBox::GrabTableFocus()
146 if ( aController
.Is() )
147 aController
->GetWindow().GrabFocus();
149 //------------------------------------------------------------------------------
150 void EditBrowseBox::DetermineFocus( const sal_uInt16 _nGetFocusFlags
)
152 sal_Bool bFocus
= sal_False
;
153 for (Window
* pWindow
= Application::GetFocusWindow();
155 pWindow
= pWindow
->GetParent())
156 bFocus
= pWindow
== this;
158 if (bFocus
!= bHasFocus
)
162 if ( GetBrowserFlags( ) & EBBF_SMART_TAB_TRAVEL
)
164 if ( bHasFocus
// we got the focus
165 && ( _nGetFocusFlags
& GETFOCUS_TAB
) // using the TAB key
168 long nRows
= GetRowCount();
169 USHORT nCols
= ColCount();
171 if ( ( nRows
> 0 ) && ( nCols
> 0 ) )
173 if ( _nGetFocusFlags
& GETFOCUS_FORWARD
)
175 if ( GetColumnId( 0 ) != 0 )
177 GoToRowColumnId( 0, GetColumnId( 0 ) );
180 { // the first column is the handle column -> not focussable
182 GoToRowColumnId( 0, GetColumnId( 1 ) );
185 else if ( _nGetFocusFlags
& GETFOCUS_BACKWARD
)
187 GoToRowColumnId( nRows
- 1, GetColumnId( nCols
-1 ) );
194 // -----------------------------------------------------------------------------
195 Rectangle
EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,sal_Int32 _nIndex
)
198 if ( SeekRow(_nRow
) )
200 CellController
* pController
= GetController(
201 _nRow
, GetColumnId( sal::static_int_cast
< USHORT
>(_nColumnPos
) ) );
203 aRect
= pController
->GetWindow().GetCharacterBounds(_nIndex
);
207 // -----------------------------------------------------------------------------
208 sal_Int32
EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
)
211 if ( SeekRow(_nRow
) )
213 CellController
* pController
= GetController(
214 _nRow
, GetColumnId( sal::static_int_cast
< USHORT
>(_nColumnPos
) ) );
216 nRet
= pController
->GetWindow().GetIndexForPoint(_rPoint
);
220 // -----------------------------------------------------------------------------
221 // -----------------------------------------------------------------------------
223 // -----------------------------------------------------------------------------