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