xref: /AOO41X/main/accessibility/source/extended/accessibletabbarpage.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/accessibletabbarpage.hxx>
27 #include <svtools/tabbar.hxx>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <unotools/accessiblerelationsethelper.hxx>
33 #include <vcl/svapp.hxx>
34 #include <toolkit/helper/convert.hxx>
35 
36 
37 //.........................................................................
38 namespace accessibility
39 {
40 //.........................................................................
41 
42     using namespace ::com::sun::star::accessibility;
43     using namespace ::com::sun::star::uno;
44     using namespace ::com::sun::star::lang;
45     using namespace ::com::sun::star;
46     using namespace ::comphelper;
47 
48     // -----------------------------------------------------------------------------
49     // class AccessibleTabBarPage
50     // -----------------------------------------------------------------------------
51 
AccessibleTabBarPage(TabBar * pTabBar,sal_uInt16 nPageId,const Reference<XAccessible> & rxParent)52     AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
53         :AccessibleTabBarBase( pTabBar )
54         ,m_nPageId( nPageId )
55         ,m_xParent( rxParent )
56     {
57         m_bEnabled  = IsEnabled();
58         m_bShowing  = IsShowing();
59         m_bSelected = IsSelected();
60 
61         if ( m_pTabBar )
62             m_sPageText = m_pTabBar->GetPageText( m_nPageId );
63     }
64 
65     // -----------------------------------------------------------------------------
66 
~AccessibleTabBarPage()67     AccessibleTabBarPage::~AccessibleTabBarPage()
68     {
69     }
70 
71     // -----------------------------------------------------------------------------
72 
IsEnabled()73     sal_Bool AccessibleTabBarPage::IsEnabled()
74     {
75         OExternalLockGuard aGuard( this );
76 
77         sal_Bool bEnabled = sal_False;
78         if ( m_pTabBar )
79             bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
80 
81         return bEnabled;
82     }
83 
84     // -----------------------------------------------------------------------------
85 
IsShowing()86     sal_Bool AccessibleTabBarPage::IsShowing()
87     {
88         sal_Bool bShowing = sal_False;
89 
90         if ( m_pTabBar && m_pTabBar->IsVisible() )
91             bShowing = sal_True;
92 
93         return bShowing;
94     }
95 
96     // -----------------------------------------------------------------------------
97 
IsSelected()98     sal_Bool AccessibleTabBarPage::IsSelected()
99     {
100         sal_Bool bSelected = sal_False;
101 
102         if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
103             bSelected = sal_True;
104 
105         return bSelected;
106     }
107 
108     // -----------------------------------------------------------------------------
109 
SetEnabled(sal_Bool bEnabled)110     void AccessibleTabBarPage::SetEnabled( sal_Bool bEnabled )
111     {
112         if ( m_bEnabled != bEnabled )
113         {
114             Any aOldValue[2], aNewValue[2];
115             if ( m_bEnabled )
116             {
117                 aOldValue[0] <<= AccessibleStateType::SENSITIVE;
118                 aOldValue[1] <<= AccessibleStateType::ENABLED;
119             }
120             else
121             {
122 
123                 aNewValue[0] <<= AccessibleStateType::ENABLED;
124                 aNewValue[1] <<= AccessibleStateType::SENSITIVE;
125             }
126             m_bEnabled = bEnabled;
127             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
128             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
129         }
130     }
131 
132     // -----------------------------------------------------------------------------
133 
SetShowing(sal_Bool bShowing)134     void AccessibleTabBarPage::SetShowing( sal_Bool bShowing )
135     {
136         if ( m_bShowing != bShowing )
137         {
138             Any aOldValue, aNewValue;
139             if ( m_bShowing )
140                 aOldValue <<= AccessibleStateType::SHOWING;
141             else
142                 aNewValue <<= AccessibleStateType::SHOWING;
143             m_bShowing = bShowing;
144             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
145         }
146     }
147 
148     // -----------------------------------------------------------------------------
149 
SetSelected(sal_Bool bSelected)150     void AccessibleTabBarPage::SetSelected( sal_Bool bSelected )
151     {
152         if ( m_bSelected != bSelected )
153         {
154             Any aOldValue, aNewValue;
155             if ( m_bSelected )
156                 aOldValue <<= AccessibleStateType::SELECTED;
157             else
158                 aNewValue <<= AccessibleStateType::SELECTED;
159             m_bSelected = bSelected;
160             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
161         }
162     }
163 
164     // -----------------------------------------------------------------------------
165 
SetPageText(const::rtl::OUString & sPageText)166     void AccessibleTabBarPage::SetPageText( const ::rtl::OUString& sPageText )
167     {
168         if ( !m_sPageText.equals( sPageText ) )
169         {
170             Any aOldValue, aNewValue;
171             aOldValue <<= m_sPageText;
172             aNewValue <<= sPageText;
173             m_sPageText = sPageText;
174             NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
175         }
176     }
177 
178     // -----------------------------------------------------------------------------
179 
FillAccessibleStateSet(utl::AccessibleStateSetHelper & rStateSet)180     void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
181     {
182         if ( IsEnabled() )
183         {
184             rStateSet.AddState( AccessibleStateType::ENABLED );
185             rStateSet.AddState( AccessibleStateType::SENSITIVE );
186         }
187 
188         rStateSet.AddState( AccessibleStateType::VISIBLE );
189 
190         if ( IsShowing() )
191             rStateSet.AddState( AccessibleStateType::SHOWING );
192 
193         rStateSet.AddState( AccessibleStateType::SELECTABLE );
194 
195         if ( IsSelected() )
196             rStateSet.AddState( AccessibleStateType::SELECTED );
197     }
198 
199     // -----------------------------------------------------------------------------
200     // OCommonAccessibleComponent
201     // -----------------------------------------------------------------------------
202 
implGetBounds()203     awt::Rectangle AccessibleTabBarPage::implGetBounds() throw (RuntimeException)
204     {
205         awt::Rectangle aBounds;
206         if ( m_pTabBar )
207         {
208             // get bounding rectangle relative to the AccessibleTabBar
209             aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) );
210 
211             // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
212             Reference< XAccessible > xParent = getAccessibleParent();
213             if ( xParent.is() )
214             {
215                 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
216                 if ( xParentComponent.is() )
217                 {
218                     awt::Point aParentLoc = xParentComponent->getLocation();
219 
220                     // calculate bounding rectangle relative to the AccessibleTabBarPageList
221                     aBounds.X -= aParentLoc.X;
222                     aBounds.Y -= aParentLoc.Y;
223                 }
224             }
225         }
226 
227         return aBounds;
228     }
229 
230     // -----------------------------------------------------------------------------
231     // XInterface
232     // -----------------------------------------------------------------------------
233 
IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabBarPage,AccessibleExtendedComponentHelper_BASE,AccessibleTabBarPage_BASE)234     IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
235 
236     // -----------------------------------------------------------------------------
237     // XTypeProvider
238     // -----------------------------------------------------------------------------
239 
240     IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
241 
242     // -----------------------------------------------------------------------------
243     // XComponent
244     // -----------------------------------------------------------------------------
245 
246     void AccessibleTabBarPage::disposing()
247     {
248         AccessibleTabBarBase::disposing();
249         m_sPageText = ::rtl::OUString();
250     }
251 
252     // -----------------------------------------------------------------------------
253     // XServiceInfo
254     // -----------------------------------------------------------------------------
255 
getImplementationName()256     ::rtl::OUString AccessibleTabBarPage::getImplementationName() throw (RuntimeException)
257     {
258         return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
259     }
260 
261     // -----------------------------------------------------------------------------
262 
supportsService(const::rtl::OUString & rServiceName)263     sal_Bool AccessibleTabBarPage::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
264     {
265         Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
266         const ::rtl::OUString* pNames = aNames.getConstArray();
267         const ::rtl::OUString* pEnd = pNames + aNames.getLength();
268         for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
269             ;
270 
271         return pNames != pEnd;
272     }
273 
274     // -----------------------------------------------------------------------------
275 
getSupportedServiceNames()276     Sequence< ::rtl::OUString > AccessibleTabBarPage::getSupportedServiceNames() throw (RuntimeException)
277     {
278         Sequence< ::rtl::OUString > aNames(1);
279         aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBarPage" );
280         return aNames;
281     }
282 
283     // -----------------------------------------------------------------------------
284     // XAccessible
285     // -----------------------------------------------------------------------------
286 
getAccessibleContext()287     Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext(  ) throw (RuntimeException)
288     {
289         OExternalLockGuard aGuard( this );
290 
291         return this;
292     }
293 
294     // -----------------------------------------------------------------------------
295     // XAccessibleContext
296     // -----------------------------------------------------------------------------
297 
getAccessibleChildCount()298     sal_Int32 AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException)
299     {
300         OExternalLockGuard aGuard( this );
301 
302         return 0;
303     }
304 
305     // -----------------------------------------------------------------------------
306 
getAccessibleChild(sal_Int32 i)307     Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
308     {
309         OExternalLockGuard aGuard( this );
310 
311         if ( i < 0 || i >= getAccessibleChildCount() )
312             throw IndexOutOfBoundsException();
313 
314         return Reference< XAccessible >();
315     }
316 
317     // -----------------------------------------------------------------------------
318 
getAccessibleParent()319     Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent(  ) throw (RuntimeException)
320     {
321         OExternalLockGuard aGuard( this );
322 
323         return m_xParent;
324     }
325 
326     // -----------------------------------------------------------------------------
327 
getAccessibleIndexInParent()328     sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent(  ) throw (RuntimeException)
329     {
330         OExternalLockGuard aGuard( this );
331 
332         sal_Int32 nIndexInParent = -1;
333         if ( m_pTabBar )
334             nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
335 
336         return nIndexInParent;
337     }
338 
339     // -----------------------------------------------------------------------------
340 
getAccessibleRole()341     sal_Int16 AccessibleTabBarPage::getAccessibleRole(  ) throw (RuntimeException)
342     {
343         OExternalLockGuard aGuard( this );
344 
345         return AccessibleRole::PAGE_TAB;
346     }
347 
348     // -----------------------------------------------------------------------------
349 
getAccessibleDescription()350     ::rtl::OUString AccessibleTabBarPage::getAccessibleDescription( ) throw (RuntimeException)
351     {
352         OExternalLockGuard aGuard( this );
353 
354         ::rtl::OUString sDescription;
355         if ( m_pTabBar )
356             sDescription = m_pTabBar->GetHelpText( m_nPageId );
357 
358         return sDescription;
359     }
360 
361     // -----------------------------------------------------------------------------
362 
getAccessibleName()363     ::rtl::OUString AccessibleTabBarPage::getAccessibleName(  ) throw (RuntimeException)
364     {
365         OExternalLockGuard aGuard( this );
366 
367         return m_sPageText;
368     }
369 
370     // -----------------------------------------------------------------------------
371 
getAccessibleRelationSet()372     Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet(  ) throw (RuntimeException)
373     {
374         OExternalLockGuard aGuard( this );
375 
376         utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
377         Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
378         return xSet;
379     }
380 
381     // -----------------------------------------------------------------------------
382 
getAccessibleStateSet()383     Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet(  ) throw (RuntimeException)
384     {
385         OExternalLockGuard aGuard( this );
386 
387         utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
388         Reference< XAccessibleStateSet > xSet = pStateSetHelper;
389 
390         if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
391         {
392             FillAccessibleStateSet( *pStateSetHelper );
393         }
394         else
395         {
396             pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
397         }
398 
399         return xSet;
400     }
401 
402     // -----------------------------------------------------------------------------
403 
getLocale()404     Locale AccessibleTabBarPage::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
405     {
406         OExternalLockGuard aGuard( this );
407 
408         return Application::GetSettings().GetLocale();
409     }
410 
411     // -----------------------------------------------------------------------------
412     // XAccessibleComponent
413     // -----------------------------------------------------------------------------
414 
getAccessibleAtPoint(const awt::Point &)415     Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
416     {
417         OExternalLockGuard aGuard( this );
418 
419         return Reference< XAccessible >();
420     }
421 
422     // -----------------------------------------------------------------------------
423 
grabFocus()424     void AccessibleTabBarPage::grabFocus(  ) throw (RuntimeException)
425     {
426         // no focus
427     }
428 
429     // -----------------------------------------------------------------------------
430 
getForeground()431     sal_Int32 AccessibleTabBarPage::getForeground(  ) throw (RuntimeException)
432     {
433         OExternalLockGuard aGuard( this );
434 
435         sal_Int32 nColor = 0;
436         Reference< XAccessible > xParent = getAccessibleParent();
437         if ( xParent.is() )
438         {
439             Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
440             if ( xParentComp.is() )
441                 nColor = xParentComp->getForeground();
442         }
443 
444         return nColor;
445     }
446 
447     // -----------------------------------------------------------------------------
448 
getBackground()449     sal_Int32 AccessibleTabBarPage::getBackground(  ) throw (RuntimeException)
450     {
451         OExternalLockGuard aGuard( this );
452 
453         sal_Int32 nColor = 0;
454         Reference< XAccessible > xParent = getAccessibleParent();
455         if ( xParent.is() )
456         {
457             Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
458             if ( xParentComp.is() )
459                 nColor = xParentComp->getBackground();
460         }
461 
462         return nColor;
463     }
464 
465     // -----------------------------------------------------------------------------
466     // XAccessibleExtendedComponent
467     // -----------------------------------------------------------------------------
468 
getFont()469     Reference< awt::XFont > AccessibleTabBarPage::getFont(  ) throw (RuntimeException)
470     {
471         OExternalLockGuard aGuard( this );
472 
473         Reference< awt::XFont > xFont;
474         Reference< XAccessible > xParent = getAccessibleParent();
475         if ( xParent.is() )
476         {
477             Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
478             if ( xParentComp.is() )
479                 xFont = xParentComp->getFont();
480         }
481 
482         return xFont;
483     }
484 
485     // -----------------------------------------------------------------------------
486 
getTitledBorderText()487     ::rtl::OUString AccessibleTabBarPage::getTitledBorderText(  ) throw (RuntimeException)
488     {
489         OExternalLockGuard aGuard( this );
490 
491         return m_sPageText;
492     }
493 
494     // -----------------------------------------------------------------------------
495 
getToolTipText()496     ::rtl::OUString AccessibleTabBarPage::getToolTipText(  ) throw (RuntimeException)
497     {
498         OExternalLockGuard aGuard( this );
499 
500         return ::rtl::OUString();
501     }
502 
503     // -----------------------------------------------------------------------------
504 
505 //.........................................................................
506 }   // namespace accessibility
507 //.........................................................................
508