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 <standard/vclxaccessibleheaderbar.hxx>
21 #include <standard/vclxaccessibleheaderbaritem.hxx>
23 #include <o3tl/safeint.hxx>
24 #include <vcl/headbar.hxx>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <vcl/svapp.hxx>
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::accessibility
;
34 VCLXAccessibleHeaderBar::VCLXAccessibleHeaderBar(VCLXWindow
* pVCLWindow
)
35 : VCLXAccessibleComponent(pVCLWindow
)
37 m_pHeadBar
= GetAs
<HeaderBar
>();
40 VCLXAccessibleHeaderBar::~VCLXAccessibleHeaderBar() {}
44 OUString
VCLXAccessibleHeaderBar::getImplementationName()
46 return u
"com.sun.star.comp.toolkit.AccessibleHeaderBar"_ustr
;
49 Sequence
<OUString
> VCLXAccessibleHeaderBar::getSupportedServiceNames()
51 return { u
"com.sun.star.awt.AccessibleHeaderBar"_ustr
};
54 // =======XAccessibleContext=======
56 sal_Int64 SAL_CALL
VCLXAccessibleHeaderBar::getAccessibleChildCount()
62 nCount
= m_pHeadBar
->GetItemCount();
66 css::uno::Reference
<css::accessibility::XAccessible
>
67 SAL_CALL
VCLXAccessibleHeaderBar::getAccessibleChild(sal_Int64 i
)
71 if (i
< 0 || i
>= getAccessibleChildCount())
72 throw IndexOutOfBoundsException();
74 Reference
<XAccessible
> xChild
;
75 // search for the child
76 if (o3tl::make_unsigned(i
) >= m_aAccessibleChildren
.size())
77 xChild
= CreateChild(i
);
80 xChild
= m_aAccessibleChildren
[i
];
82 xChild
= CreateChild(i
);
87 sal_Int16 SAL_CALL
VCLXAccessibleHeaderBar::getAccessibleRole()
89 return css::accessibility::AccessibleRole::LIST
;
92 void SAL_CALL
VCLXAccessibleHeaderBar::disposing()
96 ListItems().swap(m_aAccessibleChildren
);
97 VCLXAccessibleComponent::disposing();
100 css::uno::Reference
<css::accessibility::XAccessible
>
101 VCLXAccessibleHeaderBar::CreateChild(sal_Int32 i
)
103 Reference
<XAccessible
> xChild
;
105 sal_uInt16 nPos
= static_cast<sal_uInt16
>(i
);
106 if (nPos
>= m_aAccessibleChildren
.size())
108 m_aAccessibleChildren
.resize(nPos
+ 1);
110 // insert into the container
111 xChild
= new VCLXAccessibleHeaderBarItem(m_pHeadBar
, i
);
112 m_aAccessibleChildren
[nPos
] = xChild
;
116 xChild
= m_aAccessibleChildren
[nPos
];
117 // check if position is empty and can be used else we have to adjust all entries behind this
120 xChild
= new VCLXAccessibleHeaderBarItem(m_pHeadBar
, i
);
121 m_aAccessibleChildren
[nPos
] = xChild
;
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */