1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibletabbar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/extended/accessibletabbar.hxx>
34 #include <svtools/tabbar.hxx>
35 #include <accessibility/extended/accessibletabbarpagelist.hxx>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <unotools/accessiblerelationsethelper.hxx>
41 #include <vcl/svapp.hxx>
42 #include <toolkit/awt/vclxfont.hxx>
43 #include <toolkit/helper/convert.hxx>
48 //.........................................................................
49 namespace accessibility
51 //.........................................................................
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::accessibility
;
57 using namespace ::comphelper
;
59 DBG_NAME( AccessibleTabBar
)
61 // ----------------------------------------------------
62 // class AccessibleTabBar
63 // ----------------------------------------------------
65 AccessibleTabBar::AccessibleTabBar( TabBar
* pTabBar
)
66 :AccessibleTabBarBase( pTabBar
)
68 DBG_CTOR( AccessibleTabBar
, NULL
);
71 m_aAccessibleChildren
.assign( m_pTabBar
->GetAccessibleChildWindowCount() + 1, Reference
< XAccessible
>() );
74 // -----------------------------------------------------------------------------
76 AccessibleTabBar::~AccessibleTabBar()
78 DBG_DTOR( AccessibleTabBar
, NULL
);
81 // -----------------------------------------------------------------------------
83 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
85 Any aOldValue
, aNewValue
;
87 switch ( rVclWindowEvent
.GetId() )
89 case VCLEVENT_WINDOW_ENABLED
:
91 aNewValue
<<= AccessibleStateType::SENSITIVE
;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
93 aNewValue
<<= AccessibleStateType::ENABLED
;
94 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
97 case VCLEVENT_WINDOW_DISABLED
:
99 aOldValue
<<= AccessibleStateType::ENABLED
;
100 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
101 aOldValue
<<= AccessibleStateType::SENSITIVE
;
102 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
105 case VCLEVENT_WINDOW_GETFOCUS
:
107 aNewValue
<<= AccessibleStateType::FOCUSED
;
108 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
111 case VCLEVENT_WINDOW_LOSEFOCUS
:
113 aOldValue
<<= AccessibleStateType::FOCUSED
;
114 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
117 case VCLEVENT_WINDOW_SHOW
:
119 aNewValue
<<= AccessibleStateType::SHOWING
;
120 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
123 case VCLEVENT_WINDOW_HIDE
:
125 aOldValue
<<= AccessibleStateType::SHOWING
;
126 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
131 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
137 // -----------------------------------------------------------------------------
139 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
143 if ( m_pTabBar
->IsEnabled() )
145 rStateSet
.AddState( AccessibleStateType::ENABLED
);
146 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
149 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
151 if ( m_pTabBar
->HasFocus() )
152 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
154 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
156 if ( m_pTabBar
->IsVisible() )
157 rStateSet
.AddState( AccessibleStateType::SHOWING
);
159 if ( m_pTabBar
->GetStyle() & WB_SIZEABLE
)
160 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
164 // -----------------------------------------------------------------------------
165 // OCommonAccessibleComponent
166 // -----------------------------------------------------------------------------
168 awt::Rectangle
AccessibleTabBar::implGetBounds() throw (RuntimeException
)
170 awt::Rectangle aBounds
;
172 aBounds
= AWTRectangle( Rectangle( m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel() ) );
177 // -----------------------------------------------------------------------------
179 // -----------------------------------------------------------------------------
181 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
183 // -----------------------------------------------------------------------------
185 // -----------------------------------------------------------------------------
187 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
189 // -----------------------------------------------------------------------------
191 // -----------------------------------------------------------------------------
193 void AccessibleTabBar::disposing()
195 AccessibleTabBarBase::disposing();
197 // dispose all children
198 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
200 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
201 if ( xComponent
.is() )
202 xComponent
->dispose();
204 m_aAccessibleChildren
.clear();
207 // -----------------------------------------------------------------------------
209 // -----------------------------------------------------------------------------
211 ::rtl::OUString
AccessibleTabBar::getImplementationName() throw (RuntimeException
)
213 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBar" );
216 // -----------------------------------------------------------------------------
218 sal_Bool
AccessibleTabBar::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
220 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
221 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
222 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
223 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
226 return pNames
!= pEnd
;
229 // -----------------------------------------------------------------------------
231 Sequence
< ::rtl::OUString
> AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException
)
233 Sequence
< ::rtl::OUString
> aNames(1);
234 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBar" );
238 // -----------------------------------------------------------------------------
240 // -----------------------------------------------------------------------------
242 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException
)
244 OExternalLockGuard
aGuard( this );
249 // -----------------------------------------------------------------------------
250 // XAccessibleContext
251 // -----------------------------------------------------------------------------
253 sal_Int32
AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException
)
255 OExternalLockGuard
aGuard( this );
257 return m_aAccessibleChildren
.size();
260 // -----------------------------------------------------------------------------
262 Reference
< XAccessible
> AccessibleTabBar::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
264 OExternalLockGuard
aGuard( this );
266 if ( i
< 0 || i
>= getAccessibleChildCount() )
267 throw IndexOutOfBoundsException();
269 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
274 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
278 Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( (USHORT
)i
);
280 xChild
= pChild
->GetAccessible();
282 else if ( i
== nCount
)
284 xChild
= new AccessibleTabBarPageList( m_pTabBar
, i
);
287 // insert into child list
288 m_aAccessibleChildren
[i
] = xChild
;
295 // -----------------------------------------------------------------------------
297 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException
)
299 OExternalLockGuard
aGuard( this );
301 Reference
< XAccessible
> xParent
;
304 Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
306 xParent
= pParent
->GetAccessible();
312 // -----------------------------------------------------------------------------
314 sal_Int32
AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException
)
316 OExternalLockGuard
aGuard( this );
318 sal_Int32 nIndexInParent
= -1;
321 Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
324 for ( USHORT i
= 0, nCount
= pParent
->GetAccessibleChildWindowCount(); i
< nCount
; ++i
)
326 Window
* pChild
= pParent
->GetAccessibleChildWindow( i
);
327 if ( pChild
== static_cast< Window
* >( m_pTabBar
) )
336 return nIndexInParent
;
339 // -----------------------------------------------------------------------------
341 sal_Int16
AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException
)
343 OExternalLockGuard
aGuard( this );
345 return AccessibleRole::PANEL
;
348 // -----------------------------------------------------------------------------
350 ::rtl::OUString
AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException
)
352 OExternalLockGuard
aGuard( this );
354 ::rtl::OUString sDescription
;
356 sDescription
= m_pTabBar
->GetAccessibleDescription();
361 // -----------------------------------------------------------------------------
363 ::rtl::OUString
AccessibleTabBar::getAccessibleName( ) throw (RuntimeException
)
365 OExternalLockGuard
aGuard( this );
367 ::rtl::OUString sName
;
369 sName
= m_pTabBar
->GetAccessibleName();
374 // -----------------------------------------------------------------------------
376 Reference
< XAccessibleRelationSet
> AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException
)
378 OExternalLockGuard
aGuard( this );
380 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
381 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
385 // -----------------------------------------------------------------------------
387 Reference
< XAccessibleStateSet
> AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException
)
389 OExternalLockGuard
aGuard( this );
391 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
392 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
394 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
396 FillAccessibleStateSet( *pStateSetHelper
);
400 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
406 // -----------------------------------------------------------------------------
408 Locale
AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
)
410 OExternalLockGuard
aGuard( this );
412 return Application::GetSettings().GetLocale();
415 // -----------------------------------------------------------------------------
416 // XAccessibleComponent
417 // -----------------------------------------------------------------------------
419 Reference
< XAccessible
> AccessibleTabBar::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
421 OExternalLockGuard
aGuard( this );
423 Reference
< XAccessible
> xChild
;
424 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
426 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
429 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
432 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
433 Point aPos
= VCLPoint( rPoint
);
434 if ( aRect
.IsInside( aPos
) )
446 // -----------------------------------------------------------------------------
448 void AccessibleTabBar::grabFocus( ) throw (RuntimeException
)
450 OExternalLockGuard
aGuard( this );
453 m_pTabBar
->GrabFocus();
456 // -----------------------------------------------------------------------------
458 sal_Int32
AccessibleTabBar::getForeground( ) throw (RuntimeException
)
460 OExternalLockGuard
aGuard( this );
462 sal_Int32 nColor
= 0;
465 if ( m_pTabBar
->IsControlForeground() )
466 nColor
= m_pTabBar
->GetControlForeground().GetColor();
470 if ( m_pTabBar
->IsControlFont() )
471 aFont
= m_pTabBar
->GetControlFont();
473 aFont
= m_pTabBar
->GetFont();
474 nColor
= aFont
.GetColor().GetColor();
481 // -----------------------------------------------------------------------------
483 sal_Int32
AccessibleTabBar::getBackground( ) throw (RuntimeException
)
485 OExternalLockGuard
aGuard( this );
487 sal_Int32 nColor
= 0;
490 if ( m_pTabBar
->IsControlBackground() )
491 nColor
= m_pTabBar
->GetControlBackground().GetColor();
493 nColor
= m_pTabBar
->GetBackground().GetColor().GetColor();
499 // -----------------------------------------------------------------------------
500 // XAccessibleExtendedComponent
501 // -----------------------------------------------------------------------------
503 Reference
< awt::XFont
> AccessibleTabBar::getFont( ) throw (RuntimeException
)
505 OExternalLockGuard
aGuard( this );
507 Reference
< awt::XFont
> xFont
;
510 Reference
< awt::XDevice
> xDev( m_pTabBar
->GetComponentInterface(), UNO_QUERY
);
514 if ( m_pTabBar
->IsControlFont() )
515 aFont
= m_pTabBar
->GetControlFont();
517 aFont
= m_pTabBar
->GetFont();
518 VCLXFont
* pVCLXFont
= new VCLXFont
;
519 pVCLXFont
->Init( *xDev
.get(), aFont
);
527 // -----------------------------------------------------------------------------
529 ::rtl::OUString
AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException
)
531 OExternalLockGuard
aGuard( this );
533 ::rtl::OUString sText
;
535 sText
= m_pTabBar
->GetText();
540 // -----------------------------------------------------------------------------
542 ::rtl::OUString
AccessibleTabBar::getToolTipText( ) throw (RuntimeException
)
544 OExternalLockGuard
aGuard( this );
546 ::rtl::OUString sText
;
548 sText
= m_pTabBar
->GetQuickHelpText();
553 // -----------------------------------------------------------------------------
555 //.........................................................................
556 } // namespace accessibility
557 //.........................................................................