1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <accessibility/extended/accessibletabbar.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <accessibility/extended/accessibletabbarpagelist.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <toolkit/awt/vclxfont.hxx>
31 #include <toolkit/helper/convert.hxx>
36 //.........................................................................
37 namespace accessibility
39 //.........................................................................
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::accessibility
;
45 using namespace ::comphelper
;
47 // ----------------------------------------------------
48 // class AccessibleTabBar
49 // ----------------------------------------------------
51 AccessibleTabBar::AccessibleTabBar( TabBar
* pTabBar
)
52 :AccessibleTabBarBase( pTabBar
)
55 m_aAccessibleChildren
.assign( m_pTabBar
->GetAccessibleChildWindowCount() + 1, Reference
< XAccessible
>() );
58 // -----------------------------------------------------------------------------
60 AccessibleTabBar::~AccessibleTabBar()
64 // -----------------------------------------------------------------------------
66 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
68 Any aOldValue
, aNewValue
;
70 switch ( rVclWindowEvent
.GetId() )
72 case VCLEVENT_WINDOW_ENABLED
:
74 aNewValue
<<= AccessibleStateType::SENSITIVE
;
75 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
76 aNewValue
<<= AccessibleStateType::ENABLED
;
77 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
80 case VCLEVENT_WINDOW_DISABLED
:
82 aOldValue
<<= AccessibleStateType::ENABLED
;
83 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
84 aOldValue
<<= AccessibleStateType::SENSITIVE
;
85 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
88 case VCLEVENT_WINDOW_GETFOCUS
:
90 aNewValue
<<= AccessibleStateType::FOCUSED
;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
94 case VCLEVENT_WINDOW_LOSEFOCUS
:
96 aOldValue
<<= AccessibleStateType::FOCUSED
;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
100 case VCLEVENT_WINDOW_SHOW
:
102 aNewValue
<<= AccessibleStateType::SHOWING
;
103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
106 case VCLEVENT_WINDOW_HIDE
:
108 aOldValue
<<= AccessibleStateType::SHOWING
;
109 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
114 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
120 // -----------------------------------------------------------------------------
122 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
126 if ( m_pTabBar
->IsEnabled() )
128 rStateSet
.AddState( AccessibleStateType::ENABLED
);
129 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
132 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
134 if ( m_pTabBar
->HasFocus() )
135 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
137 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
139 if ( m_pTabBar
->IsVisible() )
140 rStateSet
.AddState( AccessibleStateType::SHOWING
);
142 if ( m_pTabBar
->GetStyle() & WB_SIZEABLE
)
143 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
147 // -----------------------------------------------------------------------------
148 // OCommonAccessibleComponent
149 // -----------------------------------------------------------------------------
151 awt::Rectangle
AccessibleTabBar::implGetBounds() throw (RuntimeException
)
153 awt::Rectangle aBounds
;
155 aBounds
= AWTRectangle( Rectangle( m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel() ) );
160 // -----------------------------------------------------------------------------
162 // -----------------------------------------------------------------------------
164 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
166 // -----------------------------------------------------------------------------
168 // -----------------------------------------------------------------------------
170 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
172 // -----------------------------------------------------------------------------
174 // -----------------------------------------------------------------------------
176 void AccessibleTabBar::disposing()
178 AccessibleTabBarBase::disposing();
180 // dispose all children
181 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
183 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
184 if ( xComponent
.is() )
185 xComponent
->dispose();
187 m_aAccessibleChildren
.clear();
190 // -----------------------------------------------------------------------------
192 // -----------------------------------------------------------------------------
194 OUString
AccessibleTabBar::getImplementationName() throw (RuntimeException
)
196 return OUString( "com.sun.star.comp.svtools.AccessibleTabBar" );
199 // -----------------------------------------------------------------------------
201 sal_Bool
AccessibleTabBar::supportsService( const OUString
& rServiceName
) throw (RuntimeException
)
203 return cppu::supportsService(this, rServiceName
);
206 // -----------------------------------------------------------------------------
208 Sequence
< OUString
> AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException
)
210 Sequence
< OUString
> aNames(1);
211 aNames
[0] = "com.sun.star.awt.AccessibleTabBar";
215 // -----------------------------------------------------------------------------
217 // -----------------------------------------------------------------------------
219 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException
)
221 OExternalLockGuard
aGuard( this );
226 // -----------------------------------------------------------------------------
227 // XAccessibleContext
228 // -----------------------------------------------------------------------------
230 sal_Int32
AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException
)
232 OExternalLockGuard
aGuard( this );
234 return m_aAccessibleChildren
.size();
237 // -----------------------------------------------------------------------------
239 Reference
< XAccessible
> AccessibleTabBar::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
241 OExternalLockGuard
aGuard( this );
243 if ( i
< 0 || i
>= getAccessibleChildCount() )
244 throw IndexOutOfBoundsException();
246 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
251 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
255 Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( (sal_uInt16
)i
);
257 xChild
= pChild
->GetAccessible();
259 else if ( i
== nCount
)
261 xChild
= new AccessibleTabBarPageList( m_pTabBar
, i
);
264 // insert into child list
265 m_aAccessibleChildren
[i
] = xChild
;
272 // -----------------------------------------------------------------------------
274 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException
)
276 OExternalLockGuard
aGuard( this );
278 Reference
< XAccessible
> xParent
;
281 Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
283 xParent
= pParent
->GetAccessible();
289 // -----------------------------------------------------------------------------
291 sal_Int32
AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException
)
293 OExternalLockGuard
aGuard( this );
295 sal_Int32 nIndexInParent
= -1;
298 Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
301 for ( sal_uInt16 i
= 0, nCount
= pParent
->GetAccessibleChildWindowCount(); i
< nCount
; ++i
)
303 Window
* pChild
= pParent
->GetAccessibleChildWindow( i
);
304 if ( pChild
== static_cast< Window
* >( m_pTabBar
) )
313 return nIndexInParent
;
316 // -----------------------------------------------------------------------------
318 sal_Int16
AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException
)
320 OExternalLockGuard
aGuard( this );
322 return AccessibleRole::PANEL
;
325 // -----------------------------------------------------------------------------
327 OUString
AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException
)
329 OExternalLockGuard
aGuard( this );
331 OUString sDescription
;
333 sDescription
= m_pTabBar
->GetAccessibleDescription();
338 // -----------------------------------------------------------------------------
340 OUString
AccessibleTabBar::getAccessibleName( ) throw (RuntimeException
)
342 OExternalLockGuard
aGuard( this );
346 sName
= m_pTabBar
->GetAccessibleName();
351 // -----------------------------------------------------------------------------
353 Reference
< XAccessibleRelationSet
> AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException
)
355 OExternalLockGuard
aGuard( this );
357 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
358 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
362 // -----------------------------------------------------------------------------
364 Reference
< XAccessibleStateSet
> AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException
)
366 OExternalLockGuard
aGuard( this );
368 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
369 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
371 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
373 FillAccessibleStateSet( *pStateSetHelper
);
377 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
383 // -----------------------------------------------------------------------------
385 Locale
AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
387 OExternalLockGuard
aGuard( this );
389 return Application::GetSettings().GetLanguageTag().getLocale();
392 // -----------------------------------------------------------------------------
393 // XAccessibleComponent
394 // -----------------------------------------------------------------------------
396 Reference
< XAccessible
> AccessibleTabBar::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
398 OExternalLockGuard
aGuard( this );
400 Reference
< XAccessible
> xChild
;
401 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
403 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
406 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
409 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
410 Point aPos
= VCLPoint( rPoint
);
411 if ( aRect
.IsInside( aPos
) )
423 // -----------------------------------------------------------------------------
425 void AccessibleTabBar::grabFocus( ) throw (RuntimeException
)
427 OExternalLockGuard
aGuard( this );
430 m_pTabBar
->GrabFocus();
433 // -----------------------------------------------------------------------------
435 sal_Int32
AccessibleTabBar::getForeground( ) throw (RuntimeException
)
437 OExternalLockGuard
aGuard( this );
439 sal_Int32 nColor
= 0;
442 if ( m_pTabBar
->IsControlForeground() )
443 nColor
= m_pTabBar
->GetControlForeground().GetColor();
447 if ( m_pTabBar
->IsControlFont() )
448 aFont
= m_pTabBar
->GetControlFont();
450 aFont
= m_pTabBar
->GetFont();
451 nColor
= aFont
.GetColor().GetColor();
458 // -----------------------------------------------------------------------------
460 sal_Int32
AccessibleTabBar::getBackground( ) throw (RuntimeException
)
462 OExternalLockGuard
aGuard( this );
464 sal_Int32 nColor
= 0;
467 if ( m_pTabBar
->IsControlBackground() )
468 nColor
= m_pTabBar
->GetControlBackground().GetColor();
470 nColor
= m_pTabBar
->GetBackground().GetColor().GetColor();
476 // -----------------------------------------------------------------------------
477 // XAccessibleExtendedComponent
478 // -----------------------------------------------------------------------------
480 Reference
< awt::XFont
> AccessibleTabBar::getFont( ) throw (RuntimeException
)
482 OExternalLockGuard
aGuard( this );
484 Reference
< awt::XFont
> xFont
;
487 Reference
< awt::XDevice
> xDev( m_pTabBar
->GetComponentInterface(), UNO_QUERY
);
491 if ( m_pTabBar
->IsControlFont() )
492 aFont
= m_pTabBar
->GetControlFont();
494 aFont
= m_pTabBar
->GetFont();
495 VCLXFont
* pVCLXFont
= new VCLXFont
;
496 pVCLXFont
->Init( *xDev
.get(), aFont
);
504 // -----------------------------------------------------------------------------
506 OUString
AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException
)
508 OExternalLockGuard
aGuard( this );
512 sText
= m_pTabBar
->GetText();
517 // -----------------------------------------------------------------------------
519 OUString
AccessibleTabBar::getToolTipText( ) throw (RuntimeException
)
521 OExternalLockGuard
aGuard( this );
525 sText
= m_pTabBar
->GetQuickHelpText();
530 // -----------------------------------------------------------------------------
532 //.........................................................................
533 } // namespace accessibility
534 //.........................................................................
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */