merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / brwbox / editbrowsebox2.cxx
blob00c03d74740690c64f026c050121741c0d75e886
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editbrowsebox2.cxx,v $
10 * $Revision: 1.17 $
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"
41 namespace svt
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 ),
60 *this,
61 NULL,
62 _nRow,
63 _nColumnPos,
64 eState,
65 _bEnabled,
66 sal_True
69 return xReturn;
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
98 GetCurRow(),
99 GetColumnPos( GetCurColumnId() )
102 commitBrowseBoxEvent( CHILD, makeAny( m_aImpl->m_xActiveCell ), Any() );
107 // -----------------------------------------------------------------------------
108 Reference< XAccessible > EditBrowseBox::CreateAccessibleControl( sal_Int32
109 #ifdef DBG_UTIL
110 _nIndex
111 #endif
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();
154 pWindow && !bFocus;
155 pWindow = pWindow->GetParent())
156 bFocus = pWindow == this;
158 if (bFocus != bHasFocus)
160 bHasFocus = bFocus;
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 ) );
179 else
180 { // the first column is the handle column -> not focussable
181 if ( nCols > 1 )
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)
197 Rectangle aRect;
198 if ( SeekRow(_nRow) )
200 CellController* pController = GetController(
201 _nRow, GetColumnId( sal::static_int_cast< USHORT >(_nColumnPos) ) );
202 if ( pController )
203 aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
205 return aRect;
207 // -----------------------------------------------------------------------------
208 sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
210 sal_Int32 nRet = -1;
211 if ( SeekRow(_nRow) )
213 CellController* pController = GetController(
214 _nRow, GetColumnId( sal::static_int_cast< USHORT >(_nColumnPos) ) );
215 if ( pController )
216 nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
218 return nRet;
220 // -----------------------------------------------------------------------------
221 // -----------------------------------------------------------------------------
222 } // namespace svt
223 // -----------------------------------------------------------------------------