xref: /AOO41X/main/accessibility/source/extended/accessibletabbar.cxx (revision 0841af799a0c15bc22ec7bb30da88488e7283293)
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/accessibletabbar.hxx>
27 #include <svtools/tabbar.hxx>
28 #include <accessibility/extended/accessibletabbarpagelist.hxx>
29 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <unotools/accessiblestatesethelper.hxx>
33 #include <unotools/accessiblerelationsethelper.hxx>
34 #include <vcl/svapp.hxx>
35 #include <toolkit/awt/vclxfont.hxx>
36 #include <toolkit/helper/convert.hxx>
37 
38 #include <vector>
39 
40 
41 //.........................................................................
42 namespace accessibility
43 {
44 //.........................................................................
45 
46     using namespace ::com::sun::star;
47     using namespace ::com::sun::star::uno;
48     using namespace ::com::sun::star::lang;
49     using namespace ::com::sun::star::accessibility;
50     using namespace ::comphelper;
51 
DBG_NAME(AccessibleTabBar)52     DBG_NAME( AccessibleTabBar )
53 
54     //  ----------------------------------------------------
55     //  class AccessibleTabBar
56     //  ----------------------------------------------------
57 
58     AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
59         :AccessibleTabBarBase( pTabBar )
60     {
61         DBG_CTOR( AccessibleTabBar, NULL );
62 
63         if ( m_pTabBar )
64             m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
65     }
66 
67     // -----------------------------------------------------------------------------
68 
~AccessibleTabBar()69     AccessibleTabBar::~AccessibleTabBar()
70     {
71         DBG_DTOR( AccessibleTabBar, NULL );
72     }
73 
74     // -----------------------------------------------------------------------------
75 
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)76     void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
77     {
78         Any aOldValue, aNewValue;
79 
80         switch ( rVclWindowEvent.GetId() )
81         {
82             case VCLEVENT_WINDOW_ENABLED:
83             {
84                 aNewValue <<= AccessibleStateType::SENSITIVE;
85                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
86                 aNewValue <<= AccessibleStateType::ENABLED;
87                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
88             }
89             break;
90             case VCLEVENT_WINDOW_DISABLED:
91             {
92                 aOldValue <<= AccessibleStateType::ENABLED;
93                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
94                 aOldValue <<= AccessibleStateType::SENSITIVE;
95                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
96             }
97             break;
98             case VCLEVENT_WINDOW_GETFOCUS:
99             {
100                 aNewValue <<= AccessibleStateType::FOCUSED;
101                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
102             }
103             break;
104             case VCLEVENT_WINDOW_LOSEFOCUS:
105             {
106                 aOldValue <<= AccessibleStateType::FOCUSED;
107                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
108             }
109             break;
110             case VCLEVENT_WINDOW_SHOW:
111             {
112                 aNewValue <<= AccessibleStateType::SHOWING;
113                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
114             }
115             break;
116             case VCLEVENT_WINDOW_HIDE:
117             {
118                 aOldValue <<= AccessibleStateType::SHOWING;
119                 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
120             }
121             break;
122             default:
123             {
124                 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
125             }
126             break;
127         }
128     }
129 
130     // -----------------------------------------------------------------------------
131 
FillAccessibleStateSet(utl::AccessibleStateSetHelper & rStateSet)132     void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
133     {
134         if ( m_pTabBar )
135         {
136             if ( m_pTabBar->IsEnabled() )
137             {
138                 rStateSet.AddState( AccessibleStateType::ENABLED );
139                 rStateSet.AddState( AccessibleStateType::SENSITIVE );
140             }
141 
142             rStateSet.AddState( AccessibleStateType::FOCUSABLE );
143 
144             if ( m_pTabBar->HasFocus() )
145                 rStateSet.AddState( AccessibleStateType::FOCUSED );
146 
147             rStateSet.AddState( AccessibleStateType::VISIBLE );
148 
149             if ( m_pTabBar->IsVisible() )
150                 rStateSet.AddState( AccessibleStateType::SHOWING );
151 
152             if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
153                 rStateSet.AddState( AccessibleStateType::RESIZABLE );
154         }
155     }
156 
157     // -----------------------------------------------------------------------------
158     // OCommonAccessibleComponent
159     // -----------------------------------------------------------------------------
160 
implGetBounds()161     awt::Rectangle AccessibleTabBar::implGetBounds() throw (RuntimeException)
162     {
163         awt::Rectangle aBounds;
164         if ( m_pTabBar )
165             aBounds = AWTRectangle( Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
166 
167         return aBounds;
168     }
169 
170     // -----------------------------------------------------------------------------
171     // XInterface
172     // -----------------------------------------------------------------------------
173 
IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabBar,AccessibleExtendedComponentHelper_BASE,AccessibleTabBar_BASE)174     IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
175 
176     // -----------------------------------------------------------------------------
177     // XTypeProvider
178     // -----------------------------------------------------------------------------
179 
180     IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
181 
182     // -----------------------------------------------------------------------------
183     // XComponent
184     // -----------------------------------------------------------------------------
185 
186     void AccessibleTabBar::disposing()
187     {
188         AccessibleTabBarBase::disposing();
189 
190         // dispose all children
191         for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
192         {
193             Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
194             if ( xComponent.is() )
195                 xComponent->dispose();
196         }
197         m_aAccessibleChildren.clear();
198     }
199 
200     // -----------------------------------------------------------------------------
201     // XServiceInfo
202     // -----------------------------------------------------------------------------
203 
getImplementationName()204     ::rtl::OUString AccessibleTabBar::getImplementationName() throw (RuntimeException)
205     {
206         return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBar" );
207     }
208 
209     // -----------------------------------------------------------------------------
210 
supportsService(const::rtl::OUString & rServiceName)211     sal_Bool AccessibleTabBar::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
212     {
213         Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
214         const ::rtl::OUString* pNames = aNames.getConstArray();
215         const ::rtl::OUString* pEnd = pNames + aNames.getLength();
216         for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
217             ;
218 
219         return pNames != pEnd;
220     }
221 
222     // -----------------------------------------------------------------------------
223 
getSupportedServiceNames()224     Sequence< ::rtl::OUString > AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException)
225     {
226         Sequence< ::rtl::OUString > aNames(1);
227         aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBar" );
228         return aNames;
229     }
230 
231     // -----------------------------------------------------------------------------
232     // XAccessible
233     // -----------------------------------------------------------------------------
234 
getAccessibleContext()235     Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext(  ) throw (RuntimeException)
236     {
237         OExternalLockGuard aGuard( this );
238 
239         return this;
240     }
241 
242     // -----------------------------------------------------------------------------
243     // XAccessibleContext
244     // -----------------------------------------------------------------------------
245 
getAccessibleChildCount()246     sal_Int32 AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException)
247     {
248         OExternalLockGuard aGuard( this );
249 
250         return m_aAccessibleChildren.size();
251     }
252 
253     // -----------------------------------------------------------------------------
254 
getAccessibleChild(sal_Int32 i)255     Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
256     {
257         OExternalLockGuard aGuard( this );
258 
259         if ( i < 0 || i >= getAccessibleChildCount() )
260             throw IndexOutOfBoundsException();
261 
262         Reference< XAccessible > xChild = m_aAccessibleChildren[i];
263         if ( !xChild.is() )
264         {
265             if ( m_pTabBar )
266             {
267                 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
268 
269                 if ( i < nCount )
270                 {
271                     Window* pChild = m_pTabBar->GetAccessibleChildWindow( (sal_uInt16)i );
272                     if ( pChild )
273                         xChild = pChild->GetAccessible();
274                 }
275                 else if ( i == nCount )
276                 {
277                     xChild = new AccessibleTabBarPageList( m_pTabBar, i );
278                 }
279 
280                 // insert into child list
281                 m_aAccessibleChildren[i] = xChild;
282             }
283         }
284 
285         return xChild;
286     }
287 
288     // -----------------------------------------------------------------------------
289 
getAccessibleParent()290     Reference< XAccessible > AccessibleTabBar::getAccessibleParent(  ) throw (RuntimeException)
291     {
292         OExternalLockGuard aGuard( this );
293 
294         Reference< XAccessible > xParent;
295         if ( m_pTabBar )
296         {
297             Window* pParent = m_pTabBar->GetAccessibleParentWindow();
298             if ( pParent )
299                 xParent = pParent->GetAccessible();
300         }
301 
302         return xParent;
303     }
304 
305     // -----------------------------------------------------------------------------
306 
getAccessibleIndexInParent()307     sal_Int32 AccessibleTabBar::getAccessibleIndexInParent(  ) throw (RuntimeException)
308     {
309         OExternalLockGuard aGuard( this );
310 
311         sal_Int32 nIndexInParent = -1;
312         if ( m_pTabBar )
313         {
314             Window* pParent = m_pTabBar->GetAccessibleParentWindow();
315             if ( pParent )
316             {
317                 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
318                 {
319                     Window* pChild = pParent->GetAccessibleChildWindow( i );
320                     if ( pChild == static_cast< Window* >( m_pTabBar ) )
321                     {
322                         nIndexInParent = i;
323                         break;
324                     }
325                 }
326             }
327         }
328 
329         return nIndexInParent;
330     }
331 
332     // -----------------------------------------------------------------------------
333 
getAccessibleRole()334     sal_Int16 AccessibleTabBar::getAccessibleRole(  ) throw (RuntimeException)
335     {
336         OExternalLockGuard aGuard( this );
337 
338         return AccessibleRole::PANEL;
339     }
340 
341     // -----------------------------------------------------------------------------
342 
getAccessibleDescription()343     ::rtl::OUString AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException)
344     {
345         OExternalLockGuard aGuard( this );
346 
347         ::rtl::OUString sDescription;
348         if ( m_pTabBar )
349             sDescription = m_pTabBar->GetAccessibleDescription();
350 
351         return sDescription;
352     }
353 
354     // -----------------------------------------------------------------------------
355 
getAccessibleName()356     ::rtl::OUString AccessibleTabBar::getAccessibleName(  ) throw (RuntimeException)
357     {
358         OExternalLockGuard aGuard( this );
359 
360         ::rtl::OUString sName;
361         if ( m_pTabBar )
362             sName = m_pTabBar->GetAccessibleName();
363 
364         return sName;
365     }
366 
367     // -----------------------------------------------------------------------------
368 
getAccessibleRelationSet()369     Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet(  ) throw (RuntimeException)
370     {
371         OExternalLockGuard aGuard( this );
372 
373         utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
374         Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
375         return xSet;
376     }
377 
378     // -----------------------------------------------------------------------------
379 
getAccessibleStateSet()380     Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet(  ) throw (RuntimeException)
381     {
382         OExternalLockGuard aGuard( this );
383 
384         utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
385         Reference< XAccessibleStateSet > xSet = pStateSetHelper;
386 
387         if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
388         {
389             FillAccessibleStateSet( *pStateSetHelper );
390         }
391         else
392         {
393             pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
394         }
395 
396         return xSet;
397     }
398 
399     // -----------------------------------------------------------------------------
400 
getLocale()401     Locale AccessibleTabBar::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
402     {
403         OExternalLockGuard aGuard( this );
404 
405         return Application::GetSettings().GetLocale();
406     }
407 
408     // -----------------------------------------------------------------------------
409     // XAccessibleComponent
410     // -----------------------------------------------------------------------------
411 
getAccessibleAtPoint(const awt::Point & rPoint)412     Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
413     {
414         OExternalLockGuard aGuard( this );
415 
416         Reference< XAccessible > xChild;
417         for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
418         {
419             Reference< XAccessible > xAcc = getAccessibleChild( i );
420             if ( xAcc.is() )
421             {
422                 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
423                 if ( xComp.is() )
424                 {
425                     Rectangle aRect = VCLRectangle( xComp->getBounds() );
426                     Point aPos = VCLPoint( rPoint );
427                     if ( aRect.IsInside( aPos ) )
428                     {
429                         xChild = xAcc;
430                         break;
431                     }
432                 }
433             }
434         }
435 
436         return xChild;
437     }
438 
439     // -----------------------------------------------------------------------------
440 
grabFocus()441     void AccessibleTabBar::grabFocus(  ) throw (RuntimeException)
442     {
443         OExternalLockGuard aGuard( this );
444 
445         if ( m_pTabBar )
446             m_pTabBar->GrabFocus();
447     }
448 
449     // -----------------------------------------------------------------------------
450 
getForeground()451     sal_Int32 AccessibleTabBar::getForeground(  ) throw (RuntimeException)
452     {
453         OExternalLockGuard aGuard( this );
454 
455         sal_Int32 nColor = 0;
456         if ( m_pTabBar )
457         {
458             if ( m_pTabBar->IsControlForeground() )
459                 nColor = m_pTabBar->GetControlForeground().GetColor();
460             else
461             {
462                 Font aFont;
463                 if ( m_pTabBar->IsControlFont() )
464                     aFont = m_pTabBar->GetControlFont();
465                 else
466                     aFont = m_pTabBar->GetFont();
467                 nColor = aFont.GetColor().GetColor();
468             }
469         }
470 
471         return nColor;
472     }
473 
474     // -----------------------------------------------------------------------------
475 
getBackground()476     sal_Int32 AccessibleTabBar::getBackground(  ) throw (RuntimeException)
477     {
478         OExternalLockGuard aGuard( this );
479 
480         sal_Int32 nColor = 0;
481         if ( m_pTabBar )
482         {
483             if ( m_pTabBar->IsControlBackground() )
484                 nColor = m_pTabBar->GetControlBackground().GetColor();
485             else
486                 nColor = m_pTabBar->GetBackground().GetColor().GetColor();
487         }
488 
489         return nColor;
490     }
491 
492     // -----------------------------------------------------------------------------
493     // XAccessibleExtendedComponent
494     // -----------------------------------------------------------------------------
495 
getFont()496     Reference< awt::XFont > AccessibleTabBar::getFont(  ) throw (RuntimeException)
497     {
498         OExternalLockGuard aGuard( this );
499 
500         Reference< awt::XFont > xFont;
501         if ( m_pTabBar )
502         {
503             Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
504             if ( xDev.is() )
505             {
506                 Font aFont;
507                 if ( m_pTabBar->IsControlFont() )
508                     aFont = m_pTabBar->GetControlFont();
509                 else
510                     aFont = m_pTabBar->GetFont();
511                 VCLXFont* pVCLXFont = new VCLXFont;
512                 pVCLXFont->Init( *xDev.get(), aFont );
513                 xFont = pVCLXFont;
514             }
515         }
516 
517         return xFont;
518     }
519 
520     // -----------------------------------------------------------------------------
521 
getTitledBorderText()522     ::rtl::OUString AccessibleTabBar::getTitledBorderText(  ) throw (RuntimeException)
523     {
524         OExternalLockGuard aGuard( this );
525 
526         ::rtl::OUString sText;
527         if ( m_pTabBar )
528             sText = m_pTabBar->GetText();
529 
530         return sText;
531     }
532 
533     // -----------------------------------------------------------------------------
534 
getToolTipText()535     ::rtl::OUString AccessibleTabBar::getToolTipText(  ) throw (RuntimeException)
536     {
537         OExternalLockGuard aGuard( this );
538 
539         ::rtl::OUString sText;
540         if ( m_pTabBar )
541             sText = m_pTabBar->GetQuickHelpText();
542 
543         return sText;
544     }
545 
546     // -----------------------------------------------------------------------------
547 
548 //.........................................................................
549 }   // namespace accessibility
550 //.........................................................................
551