xref: /trunk/main/svtools/source/brwbox/editbrowsebox2.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir #include <svtools/editbrowsebox.hxx>
31*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33*cdf0e10cSrcweir #include "editbrowseboximpl.hxx"
34*cdf0e10cSrcweir #include <comphelper/types.hxx>
35*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
36*cdf0e10cSrcweir #include "svtaccessiblefactory.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace svt
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir     using namespace com::sun::star::accessibility;
41*cdf0e10cSrcweir     using namespace com::sun::star::uno;
42*cdf0e10cSrcweir     using namespace ::com::sun::star::accessibility::AccessibleEventId;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // -----------------------------------------------------------------------------
45*cdf0e10cSrcweir Reference< XAccessible > EditBrowseBox::CreateAccessibleCheckBoxCell(long _nRow, sal_uInt16 _nColumnPos,const TriState& eState,sal_Bool _bEnabled)
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir     Reference< XAccessible > xAccessible( GetAccessible() );
48*cdf0e10cSrcweir     Reference< XAccessibleContext > xAccContext;
49*cdf0e10cSrcweir     if ( xAccessible.is() )
50*cdf0e10cSrcweir         xAccContext = xAccessible->getAccessibleContext();
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     Reference< XAccessible > xReturn;
53*cdf0e10cSrcweir     if ( xAccContext.is() )
54*cdf0e10cSrcweir     {
55*cdf0e10cSrcweir         xReturn = getAccessibleFactory().createAccessibleCheckBoxCell(
56*cdf0e10cSrcweir             xAccContext->getAccessibleChild( ::svt::BBINDEX_TABLE ),
57*cdf0e10cSrcweir             *this,
58*cdf0e10cSrcweir             NULL,
59*cdf0e10cSrcweir             _nRow,
60*cdf0e10cSrcweir             _nColumnPos,
61*cdf0e10cSrcweir             eState,
62*cdf0e10cSrcweir             _bEnabled,
63*cdf0e10cSrcweir             sal_True
64*cdf0e10cSrcweir         );
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir     return xReturn;
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir // -----------------------------------------------------------------------------
69*cdf0e10cSrcweir Reference< XAccessible > EditBrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     return BrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir // -----------------------------------------------------------------------------
74*cdf0e10cSrcweir sal_Int32 EditBrowseBox::GetAccessibleControlCount() const
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     return IsEditing() ? 1 : 0;
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir // -----------------------------------------------------------------------------
79*cdf0e10cSrcweir void EditBrowseBox::implCreateActiveAccessible( )
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
82*cdf0e10cSrcweir     DBG_ASSERT( !m_aImpl->m_xActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     if ( !m_aImpl->m_xActiveCell.is() && IsEditing() )
85*cdf0e10cSrcweir     {
86*cdf0e10cSrcweir         Reference< XAccessible > xCont = aController->GetWindow().GetAccessible();
87*cdf0e10cSrcweir         Reference< XAccessible > xMy = GetAccessible();
88*cdf0e10cSrcweir         if ( xMy.is() && xCont.is() )
89*cdf0e10cSrcweir         {
90*cdf0e10cSrcweir             m_aImpl->m_xActiveCell = getAccessibleFactory().createEditBrowseBoxTableCellAccess(
91*cdf0e10cSrcweir                 xMy,                                                        // parent accessible
92*cdf0e10cSrcweir                 xCont,                                                      // control accessible
93*cdf0e10cSrcweir                 VCLUnoHelper::GetInterface( &aController->GetWindow() ),    // focus window (for notifications)
94*cdf0e10cSrcweir                 *this,                                                      // the browse box
95*cdf0e10cSrcweir                 GetCurRow(),
96*cdf0e10cSrcweir                 GetColumnPos( GetCurColumnId() )
97*cdf0e10cSrcweir             );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir             commitBrowseBoxEvent( CHILD, makeAny( m_aImpl->m_xActiveCell ), Any() );
100*cdf0e10cSrcweir         }
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir // -----------------------------------------------------------------------------
105*cdf0e10cSrcweir Reference< XAccessible > EditBrowseBox::CreateAccessibleControl( sal_Int32
106*cdf0e10cSrcweir #ifdef DBG_UTIL
107*cdf0e10cSrcweir _nIndex
108*cdf0e10cSrcweir #endif
109*cdf0e10cSrcweir )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     if ( isAccessibleAlive() )
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         if ( !m_aImpl->m_xActiveCell.is() )
116*cdf0e10cSrcweir             implCreateActiveAccessible();
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     return m_aImpl->m_xActiveCell;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir // -----------------------------------------------------------------------------
122*cdf0e10cSrcweir Reference<XAccessible > EditBrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     return BrowseBox::CreateAccessibleRowHeader( _nRow );
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir // -----------------------------------------------------------------------------
127*cdf0e10cSrcweir void EditBrowseBoxImpl::clearActiveCell()
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     try
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         ::comphelper::disposeComponent(m_xActiveCell);
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir     catch(const Exception&)
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     m_xActiveCell = NULL;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir // -----------------------------------------------------------------------------
141*cdf0e10cSrcweir void EditBrowseBox::GrabTableFocus()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     if ( aController.Is() )
144*cdf0e10cSrcweir         aController->GetWindow().GrabFocus();
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir //------------------------------------------------------------------------------
147*cdf0e10cSrcweir void EditBrowseBox::DetermineFocus( const sal_uInt16 _nGetFocusFlags )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     sal_Bool bFocus = sal_False;
150*cdf0e10cSrcweir     for (Window* pWindow = Application::GetFocusWindow();
151*cdf0e10cSrcweir          pWindow && !bFocus;
152*cdf0e10cSrcweir          pWindow = pWindow->GetParent())
153*cdf0e10cSrcweir          bFocus = pWindow == this;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     if (bFocus != bHasFocus)
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         bHasFocus = bFocus;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         if ( GetBrowserFlags( ) & EBBF_SMART_TAB_TRAVEL )
160*cdf0e10cSrcweir         {
161*cdf0e10cSrcweir             if  (   bHasFocus                           // we got the focus
162*cdf0e10cSrcweir                 &&  ( _nGetFocusFlags & GETFOCUS_TAB )  // using the TAB key
163*cdf0e10cSrcweir                 )
164*cdf0e10cSrcweir             {
165*cdf0e10cSrcweir                 long nRows = GetRowCount();
166*cdf0e10cSrcweir                 sal_uInt16 nCols = ColCount();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir                 if ( ( nRows > 0 ) && ( nCols > 0 ) )
169*cdf0e10cSrcweir                 {
170*cdf0e10cSrcweir                     if ( _nGetFocusFlags & GETFOCUS_FORWARD )
171*cdf0e10cSrcweir                     {
172*cdf0e10cSrcweir                         if ( GetColumnId( 0 ) != 0 )
173*cdf0e10cSrcweir                         {
174*cdf0e10cSrcweir                             GoToRowColumnId( 0, GetColumnId( 0 ) );
175*cdf0e10cSrcweir                         }
176*cdf0e10cSrcweir                         else
177*cdf0e10cSrcweir                         {   // the first column is the handle column -> not focussable
178*cdf0e10cSrcweir                             if ( nCols > 1 )
179*cdf0e10cSrcweir                                 GoToRowColumnId( 0, GetColumnId( 1 ) );
180*cdf0e10cSrcweir                         }
181*cdf0e10cSrcweir                     }
182*cdf0e10cSrcweir                     else if ( _nGetFocusFlags & GETFOCUS_BACKWARD )
183*cdf0e10cSrcweir                     {
184*cdf0e10cSrcweir                         GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
185*cdf0e10cSrcweir                     }
186*cdf0e10cSrcweir                 }
187*cdf0e10cSrcweir             }
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir // -----------------------------------------------------------------------------
192*cdf0e10cSrcweir Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     Rectangle aRect;
195*cdf0e10cSrcweir     if ( SeekRow(_nRow) )
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         CellController* pController = GetController(
198*cdf0e10cSrcweir             _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
199*cdf0e10cSrcweir         if ( pController )
200*cdf0e10cSrcweir             aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir     return aRect;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir // -----------------------------------------------------------------------------
205*cdf0e10cSrcweir sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     sal_Int32 nRet = -1;
208*cdf0e10cSrcweir     if ( SeekRow(_nRow) )
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir         CellController* pController = GetController(
211*cdf0e10cSrcweir             _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
212*cdf0e10cSrcweir         if ( pController )
213*cdf0e10cSrcweir             nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir     return nRet;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir // -----------------------------------------------------------------------------
218*cdf0e10cSrcweir // -----------------------------------------------------------------------------
219*cdf0e10cSrcweir } // namespace svt
220*cdf0e10cSrcweir // -----------------------------------------------------------------------------
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 
223