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 //IAccessibility2 Implementation 2009-----
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #ifndef _SVTOOLS_VCLXACCESSIBLEHEADERBAR_HXX_
28 #include <svtools/vclxaccessibleheaderbar.hxx>
29 #endif
30 #ifndef _SVTOOLS_VCLACCESSIBLEHEADBARITEM_HXX_
31 #include <svtools/vclxaccessibleheaderbaritem.hxx>
32 #endif
33 
34 #ifndef _TOOLKIT_AWT_VCLXWINDOWS_HXX_
35 #include <toolkit/awt/vclxwindows.hxx>
36 #endif
37 #ifndef _HEADBAR_HXX
38 #include <headbar.hxx>
39 #endif
40 #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
41 #include <unotools/accessiblestatesethelper.hxx>
42 #endif
43 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
44 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
47 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
48 #endif
49 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
50 #include <cppuhelper/typeprovider.hxx>
51 #endif
52 #ifndef _COMPHELPER_SEQUENCE_HXX_
53 #include <comphelper/sequence.hxx>
54 #endif
55 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
56 #include <com/sun/star/accessibility/AccessibleRole.hpp>
57 #endif
58 
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::awt;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::accessibility;
65 using namespace ::comphelper;
66 
67 VCLXHeaderBar::VCLXHeaderBar(Window* pHeaderBar)
68 {
69 	SetWindow(pHeaderBar);
70 }
71 
72 VCLXHeaderBar::~VCLXHeaderBar()
73 {
74 }
75 
76 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXHeaderBar::CreateAccessibleContext()
77 {
78 	return new VCLXAccessibleHeaderBar(this);
79 }
80 
81 
82 VCLXAccessibleHeaderBar::VCLXAccessibleHeaderBar( VCLXWindow* pVCLWindow )
83 	:VCLXAccessibleComponent( pVCLWindow )
84 	,m_pHeadBar(NULL)
85 {
86 	m_pHeadBar = static_cast< HeaderBar* >( GetWindow() );
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 VCLXAccessibleHeaderBar::~VCLXAccessibleHeaderBar()
92 {
93 }
94 
95 // -----------------------------------------------------------------------------
96 
97 void VCLXAccessibleHeaderBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
98 {
99 	VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
100 }
101 
102 // -----------------------------------------------------------------------------
103 
104 void VCLXAccessibleHeaderBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
105 {
106 	VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
107 }
108 
109 // -----------------------------------------------------------------------------
110 // XServiceInfo
111 // -----------------------------------------------------------------------------
112 
113 ::rtl::OUString VCLXAccessibleHeaderBar::getImplementationName() throw (RuntimeException)
114 {
115 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleHeaderBar" );
116 }
117 
118 // -----------------------------------------------------------------------------
119 
120 Sequence< ::rtl::OUString > VCLXAccessibleHeaderBar::getSupportedServiceNames() throw (RuntimeException)
121 {
122 	Sequence< ::rtl::OUString > aNames(1);
123 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleHeaderBar" );
124 	return aNames;
125 }
126 
127 // =======XAccessibleContext=======
128 
129 sal_Int32 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleChildCount(  )
130 		throw (::com::sun::star::uno::RuntimeException)
131 {
132 	sal_Int32 nCount = 0;
133 	if ( m_pHeadBar )
134 		nCount = m_pHeadBar->GetItemCount();
135 
136     return nCount;
137 }
138 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
139 		VCLXAccessibleHeaderBar::getAccessibleChild( sal_Int32 i ) 	throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
140 {
141 	if ( i < 0 || i >= getAccessibleChildCount() )
142 		throw IndexOutOfBoundsException();
143 
144     Reference< XAccessible > xChild;
145     // search for the child
146 	if ( static_cast<sal_uInt16>(i) >= m_aAccessibleChildren.size() )
147 		xChild = CreateChild (i);
148 	else
149 	{
150 		xChild = m_aAccessibleChildren[i];
151 		if ( !xChild.is() )
152 			xChild = CreateChild (i);
153 	}
154     return xChild;
155 }
156 
157 sal_Int16 SAL_CALL VCLXAccessibleHeaderBar::getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException)
158 {
159 	return com::sun::star::accessibility::AccessibleRole::LIST;
160 }
161 
162 void SAL_CALL VCLXAccessibleHeaderBar::disposing (void)
163 {
164 	ListItems().swap(m_aAccessibleChildren);
165 	VCLXAccessibleComponent::disposing();
166 }
167 
168 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > VCLXAccessibleHeaderBar::CreateChild (sal_Int32 i)
169 {
170 	Reference<XAccessible> xChild;
171 
172 	sal_uInt16 nPos = static_cast<sal_uInt16>(i);
173 	if ( nPos >= m_aAccessibleChildren.size() )
174 	{
175 		m_aAccessibleChildren.resize(nPos + 1);
176 
177 		// insert into the container
178 		xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i);
179 		m_aAccessibleChildren[nPos] = xChild;
180 	}
181 	else
182 	{
183 		xChild = m_aAccessibleChildren[nPos];
184 		// check if position is empty and can be used else we have to adjust all entries behind this
185 		if ( !xChild.is() )
186 		{
187 			xChild = new VCLXAccessibleHeaderBarItem(m_pHeadBar, i);
188 			m_aAccessibleChildren[nPos] = xChild;
189 		}
190 	}
191     return xChild;
192 }
193 //-----IAccessibility2 Implementation 2009
194