1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2010.
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 //IAccessibility2 Implementation 2009-----
30 
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 
34 #ifndef _SVTOOLS_VCLXACCESSIBLEHEADERBAR_HXX_
35 #include <svtools/vclxaccessibleheaderbar.hxx>
36 #endif
37 #ifndef _SVTOOLS_VCLACCESSIBLEHEADBARITEM_HXX_
38 #include <svtools/vclxaccessibleheaderbaritem.hxx>
39 #endif
40 
41 #ifndef _TOOLKIT_AWT_VCLXWINDOWS_HXX_
42 #include <toolkit/awt/vclxwindows.hxx>
43 #endif
44 #ifndef _HEADBAR_HXX
45 #include <headbar.hxx>
46 #endif
47 #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
48 #include <unotools/accessiblestatesethelper.hxx>
49 #endif
50 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
51 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
52 #endif
53 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
54 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
55 #endif
56 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
57 #include <cppuhelper/typeprovider.hxx>
58 #endif
59 #ifndef _COMPHELPER_SEQUENCE_HXX_
60 #include <comphelper/sequence.hxx>
61 #endif
62 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
63 #include <com/sun/star/accessibility/AccessibleRole.hpp>
64 #endif
65 
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::awt;
69 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::accessibility;
72 using namespace ::comphelper;
73 
74 VCLXHeaderBar::VCLXHeaderBar(Window* pHeaderBar)
75 {
76 	SetWindow(pHeaderBar);
77 }
78 
79 VCLXHeaderBar::~VCLXHeaderBar()
80 {
81 }
82 
83 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXHeaderBar::CreateAccessibleContext()
84 {
85 	return new VCLXAccessibleHeaderBar(this);
86 }
87 
88 
89 VCLXAccessibleHeaderBar::VCLXAccessibleHeaderBar( VCLXWindow* pVCLWindow )
90 	:VCLXAccessibleComponent( pVCLWindow )
91 	,m_pHeadBar(NULL)
92 {
93 	m_pHeadBar = static_cast< HeaderBar* >( GetWindow() );
94 }
95 
96 // -----------------------------------------------------------------------------
97 
98 VCLXAccessibleHeaderBar::~VCLXAccessibleHeaderBar()
99 {
100 }
101 
102 // -----------------------------------------------------------------------------
103 
104 void VCLXAccessibleHeaderBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
105 {
106 	VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
107 }
108 
109 // -----------------------------------------------------------------------------
110 
111 void VCLXAccessibleHeaderBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
112 {
113 	VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
114 }
115 
116 // -----------------------------------------------------------------------------
117 // XServiceInfo
118 // -----------------------------------------------------------------------------
119 
120 ::rtl::OUString VCLXAccessibleHeaderBar::getImplementationName() throw (RuntimeException)
121 {
122 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleHeaderBar" );
123 }
124 
125 // -----------------------------------------------------------------------------
126 
127 Sequence< ::rtl::OUString > VCLXAccessibleHeaderBar::getSupportedServiceNames() throw (RuntimeException)
128 {
129 	Sequence< ::rtl::OUString > aNames(1);
130 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleHeaderBar" );
131 	return aNames;
132 }
133 
134 // =======XAccessibleContext=======
135 
136 sal_Int32 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleChildCount(  )
137 		throw (::com::sun::star::uno::RuntimeException)
138 {
139 	sal_Int32 nCount = 0;
140 	if ( m_pHeadBar )
141 		nCount = m_pHeadBar->GetItemCount();
142 
143     return nCount;
144 }
145 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
146 		VCLXAccessibleHeaderBar::getAccessibleChild( sal_Int32 i ) 	throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
147 {
148 	if ( i < 0 || i >= getAccessibleChildCount() )
149 		throw IndexOutOfBoundsException();
150 
151     Reference< XAccessible > xChild;
152     // search for the child
153 	if ( static_cast<sal_uInt16>(i) >= m_aAccessibleChildren.size() )
154 		xChild = CreateChild (i);
155 	else
156 	{
157 		xChild = m_aAccessibleChildren[i];
158 		if ( !xChild.is() )
159 			xChild = CreateChild (i);
160 	}
161     return xChild;
162 }
163 
164 sal_Int16 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException)
165 {
166 	return com::sun::star::accessibility::AccessibleRole::LIST;
167 }
168 
169 void SAL_CALL VCLXAccessibleHeaderBar::disposing (void)
170 {
171 	ListItems().swap(m_aAccessibleChildren);
172 	VCLXAccessibleComponent::disposing();
173 }
174 
175 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > VCLXAccessibleHeaderBar::CreateChild (sal_Int32 i)
176 {
177 	Reference<XAccessible> xChild;
178 
179 	sal_uInt16 nPos = static_cast<sal_uInt16>(i);
180 	if ( nPos >= m_aAccessibleChildren.size() )
181 	{
182 		m_aAccessibleChildren.resize(nPos + 1);
183 
184 		// insert into the container
185 		xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i);
186 		m_aAccessibleChildren[nPos] = xChild;
187 	}
188 	else
189 	{
190 		xChild = m_aAccessibleChildren[nPos];
191 		// check if position is empty and can be used else we have to adjust all entries behind this
192 		if ( !xChild.is() )
193 		{
194 			xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i);
195 			m_aAccessibleChildren[nPos] = xChild;
196 		}
197 	}
198     return xChild;
199 }
200 //-----IAccessibility2 Implementation 2009
201