xref: /trunk/main/accessibility/source/extended/accessibleeditbrowseboxcell.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_accessibility.hxx"
26 #include <accessibility/extended/accessibleeditbrowseboxcell.hxx>
27 #include <svtools/editbrowsebox.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/accessibility/XAccessibleText.hpp>
30 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 
32 
33 // .................................................................................
34 namespace accessibility
35 {
36 // .................................................................................
37 
38     using namespace com::sun::star::accessibility;
39     using namespace ::com::sun::star::uno;
40     using namespace ::com::sun::star::lang;
41     using namespace ::com::sun::star::awt;
42     using namespace ::comphelper;
43     using namespace ::svt;
44 
45     DBG_NAME( acc_EditBrowseBoxTableCell )
46     // -----------------------------------------------------------------------------
47     EditBrowseBoxTableCell::EditBrowseBoxTableCell(
48                 const com::sun::star::uno::Reference< XAccessible >& _rxParent,
49                 const com::sun::star::uno::Reference< XAccessible >& _rxOwningAccessible,
50                 const com::sun::star::uno::Reference< XAccessibleContext >& _xControlChild,
51                 IAccessibleTableProvider& _rBrowseBox,
52                 const Reference< XWindow >& _xFocusWindow,
53                 sal_Int32 _nRowPos,
54                 sal_uInt16 _nColPos)
55         :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos )
56         ,OAccessibleContextWrapperHelper( ::comphelper::getProcessServiceFactory(), rBHelper, _xControlChild, _rxOwningAccessible, _rxParent )
57     {
58         DBG_CTOR( acc_EditBrowseBoxTableCell, NULL );
59 
60         aggregateProxy( m_refCount, *this );
61     }
62 
63     // -----------------------------------------------------------------------------
64     EditBrowseBoxTableCell::~EditBrowseBoxTableCell()
65     {
66         if ( !rBHelper.bDisposed )
67         {
68             acquire();  // to prevent duplicate dtor calls
69             dispose();
70         }
71 
72         DBG_DTOR( acc_EditBrowseBoxTableCell, NULL );
73     }
74 
75     // -----------------------------------------------------------------------------
76     ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException )
77     {
78         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.TableCellProxy" ) );
79     }
80 
81     // -----------------------------------------------------------------------------
82     IMPLEMENT_FORWARD_XINTERFACE2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper )
83 
84     // -----------------------------------------------------------------------------
85     IMPLEMENT_FORWARD_XTYPEPROVIDER2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper )
86 
87     // -----------------------------------------------------------------------------
88     void EditBrowseBoxTableCell::notifyTranslatedEvent( const AccessibleEventObject& _rEvent ) throw (RuntimeException)
89     {
90         commitEvent( _rEvent.EventId, _rEvent.NewValue, _rEvent.OldValue );
91     }
92 
93     // XAccessibleComponent
94     // -----------------------------------------------------------------------------
95     sal_Int32 SAL_CALL EditBrowseBoxTableCell::getForeground(  ) throw (RuntimeException)
96     {
97         SolarMethodGuard aGuard( *this );
98         Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY );
99         if ( xAccComp.is() )
100             return xAccComp->getForeground();
101         return 0;
102     }
103 
104     // -----------------------------------------------------------------------------
105     sal_Int32 SAL_CALL EditBrowseBoxTableCell::getBackground(  ) throw (RuntimeException)
106     {
107         SolarMethodGuard aGuard( *this );
108         Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY );
109         if ( xAccComp.is() )
110             return xAccComp->getBackground();
111         return 0;
112     }
113 
114     // -----------------------------------------------------------------------------
115     Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleParent(  ) throw (RuntimeException)
116     {
117         return m_xParentAccessible;
118     }
119 
120     // -----------------------------------------------------------------------------
121     ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleDescription() throw ( RuntimeException )
122     {
123         SolarMethodGuard aGuard( *this );
124         return m_xInnerContext->getAccessibleDescription();
125     }
126 
127     // -----------------------------------------------------------------------------
128     ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleName() throw ( RuntimeException )
129     {
130         SolarMethodGuard aGuard( *this );
131 
132         // TODO: localize this!
133 // IAccessible2 implementation, 2009
134         //String sName = mpBrowseBox->GetColumnDescription( getColumnPos( ) );
135 
136         //if ( 0 == sName.Len() )
137         //{
138         //    sName = String::CreateFromAscii( "Column " );
139             String  sName = String::CreateFromAscii( "Column " );
140             sName += String::CreateFromInt32( getColumnPos( ) - 1 );
141         //}
142         sName += String::CreateFromAscii( ", Row " );
143         sName += String::CreateFromInt32( getRowPos( ) );
144 
145         return ::rtl::OUString( sName );
146     }
147 
148     // -----------------------------------------------------------------------------
149     Reference< XAccessibleRelationSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleRelationSet() throw ( RuntimeException )
150     {
151         SolarMethodGuard aGuard( *this );
152         return OAccessibleContextWrapperHelper::getAccessibleRelationSet( );
153     }
154 
155     // -----------------------------------------------------------------------------
156     Reference<XAccessibleStateSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleStateSet() throw ( RuntimeException )
157     {
158         SolarMethodGuard aGuard( *this );
159         return m_xInnerContext->getAccessibleStateSet();
160             // TODO: shouldn't we add an ACTIVE here? Isn't the EditBrowseBoxTableCell always ACTIVE?
161     }
162 
163     // -----------------------------------------------------------------------------
164     sal_Int32 SAL_CALL EditBrowseBoxTableCell::getAccessibleChildCount(  ) throw (RuntimeException)
165     {
166         SolarMethodGuard aGuard( *this );
167         return OAccessibleContextWrapperHelper::getAccessibleChildCount();
168     }
169 
170     // -----------------------------------------------------------------------------
171     Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
172     {
173         SolarMethodGuard aGuard( *this );
174         return OAccessibleContextWrapperHelper::getAccessibleChild( i );
175     }
176 
177     // -----------------------------------------------------------------------------
178     sal_Int16 SAL_CALL EditBrowseBoxTableCell::getAccessibleRole() throw ( RuntimeException )
179     {
180         SolarMethodGuard aGuard( *this );
181         return m_xInnerContext->getAccessibleRole( );
182     }
183     // -----------------------------------------------------------------------------
184     void SAL_CALL EditBrowseBoxTableCell::dispose() throw( RuntimeException )
185     {
186         // simply disambiguate. Note that the OComponentHelper base in AccessibleBrowseBoxCell
187         // will call our "disposing()", which will call "dispose()" on the OAccessibleContextWrapperHelper
188         // so there is no need to do this here.
189         AccessibleBrowseBoxCell::dispose();
190     }
191     // -----------------------------------------------------------------------------
192     void SAL_CALL EditBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException)
193     {
194         AccessibleBrowseBoxCell::disposing( _rSource );
195         OAccessibleContextWrapperHelper::disposing( _rSource );
196     }
197     // -----------------------------------------------------------------------------
198     void SAL_CALL EditBrowseBoxTableCell::disposing()
199     {
200         SolarMethodGuard aGuard( *this, false );
201         OAccessibleContextWrapperHelper::dispose();
202             // TODO: do we need to dispose our inner object? The base class does this, but is it a good idea?
203         AccessibleBrowseBoxCell::disposing();
204     }
205     // =============================================================================
206     // = EditBrowseBoxTableCell
207     // =============================================================================
208     DBG_NAME( EditBrowseBoxTableCellAccess )
209     // -----------------------------------------------------------------------------
210     EditBrowseBoxTableCellAccess::EditBrowseBoxTableCellAccess(
211             const Reference< XAccessible >& _rxParent, const Reference< XAccessible > _rxControlAccessible,
212             const Reference< XWindow >& _rxFocusWindow,
213             IAccessibleTableProvider& _rBrowseBox, sal_Int32 _nRowPos, sal_uInt16 _nColPos )
214         :EditBrowseBoxTableCellAccess_Base( m_aMutex )
215         ,m_xParent( _rxParent )
216         ,m_xControlAccessible( _rxControlAccessible )
217         ,m_xFocusWindow( _rxFocusWindow )
218         ,m_pBrowseBox( &_rBrowseBox )
219         ,m_nRowPos( _nRowPos )
220         ,m_nColPos( _nColPos )
221     {
222         DBG_CTOR( EditBrowseBoxTableCellAccess, NULL );
223     }
224     // -----------------------------------------------------------------------------
225     EditBrowseBoxTableCellAccess::~EditBrowseBoxTableCellAccess( )
226     {
227         DBG_DTOR( EditBrowseBoxTableCellAccess, NULL );
228     }
229     //--------------------------------------------------------------------
230     Reference< XAccessibleContext > SAL_CALL EditBrowseBoxTableCellAccess::getAccessibleContext(  ) throw (RuntimeException)
231     {
232         if ( !m_pBrowseBox || !m_xControlAccessible.is() )
233             throw DisposedException();
234             Reference< XAccessibleContext > xMyContext( m_aContext );
235             if ( !xMyContext.is() )
236             {
237             Reference< XAccessibleContext > xInnerContext = m_xControlAccessible->getAccessibleContext();
238             Reference< XAccessible > xMe( this );
239 
240                 xMyContext = new EditBrowseBoxTableCell( m_xParent, xMe, xInnerContext, *m_pBrowseBox, m_xFocusWindow, m_nRowPos, m_nColPos );
241              m_aContext = xMyContext;
242             }
243         return xMyContext;
244     }
245     //--------------------------------------------------------------------
246     void SAL_CALL EditBrowseBoxTableCellAccess::disposing()
247     {
248         // dispose our context, if it still alive
249         Reference< XComponent > xMyContext( (Reference< XAccessibleContext >)m_aContext, UNO_QUERY );
250         if ( xMyContext.is() )
251         {
252             try
253             {
254                 xMyContext->dispose();
255             }
256             catch( const Exception& e )
257             {
258                 (void)e;
259                 OSL_ENSURE( false, "EditBrowseBoxTableCellAccess::disposing: caught an exception while disposing the context!" );
260             }
261         }
262 
263         m_pBrowseBox = NULL;
264         m_xControlAccessible.clear();
265         m_aContext = Reference< XAccessibleContext >( );
266         // NO dispose of the inner object there: it is the XAccessible of an window, and disposing
267         // it would delete the respective VCL window
268     }
269 // .................................................................................
270 } // namespace accessibility
271 // .................................................................................
272