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 "SidebarWinAcc.hxx"
21 #include <AnnotationWin.hxx>
25 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 namespace sw::sidebarwindows
{
34 // declaration and implementation of accessible context for <SidebarWinAccessible> instance
35 class SidebarWinAccessibleContext
: public VCLXAccessibleComponent
38 explicit SidebarWinAccessibleContext( sw::annotation::SwAnnotationWin
& rSidebarWin
,
39 SwViewShell
& rViewShell
,
40 const SwFrame
* pAnchorFrame
)
41 : VCLXAccessibleComponent( dynamic_cast<VCLXWindow
*>(rSidebarWin
.CreateAccessible().get()) )
42 , mrViewShell( rViewShell
)
43 , mpAnchorFrame( pAnchorFrame
)
45 rSidebarWin
.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT
);
48 void ChangeAnchor( const SwFrame
* pAnchorFrame
)
50 std::scoped_lock
aGuard(maMutex
);
52 mpAnchorFrame
= pAnchorFrame
;
55 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
56 getAccessibleParent() override
58 std::scoped_lock
aGuard(maMutex
);
60 css::uno::Reference
< css::accessibility::XAccessible
> xAccParent
;
63 mrViewShell
.GetAccessibleMap() )
65 xAccParent
= mrViewShell
.GetAccessibleMap()->GetContext( mpAnchorFrame
, false );
71 virtual sal_Int64 SAL_CALL
getAccessibleIndexInParent() override
73 std::scoped_lock
aGuard(maMutex
);
75 sal_Int64
nIndex( -1 );
77 if ( mpAnchorFrame
&& GetWindow() &&
78 mrViewShell
.GetAccessibleMap() )
80 nIndex
= mrViewShell
.GetAccessibleMap()->GetChildIndex( *mpAnchorFrame
,
88 SwViewShell
& mrViewShell
;
89 const SwFrame
* mpAnchorFrame
;
96 // implementation of accessible for <SwAnnotationWin> instance
97 SidebarWinAccessible::SidebarWinAccessible( sw::annotation::SwAnnotationWin
& rSidebarWin
,
98 SwViewShell
& rViewShell
,
99 const SwSidebarItem
& rSidebarItem
)
100 : mrSidebarWin( rSidebarWin
)
101 , mrViewShell( rViewShell
)
102 , mpAnchorFrame( rSidebarItem
.maLayoutInfo
.mpAnchorFrame
)
103 , m_bAccContextCreated( false )
105 SetWindow( &mrSidebarWin
);
108 SidebarWinAccessible::~SidebarWinAccessible()
112 void SidebarWinAccessible::ChangeSidebarItem( const SwSidebarItem
& rSidebarItem
)
114 if ( !m_bAccContextCreated
)
117 css::uno::Reference
< css::accessibility::XAccessibleContext
> xAcc
118 = getAccessibleContext();
121 SidebarWinAccessibleContext
* pAccContext
=
122 dynamic_cast<SidebarWinAccessibleContext
*>(xAcc
.get());
125 pAccContext
->ChangeAnchor( rSidebarItem
.maLayoutInfo
.mpAnchorFrame
);
130 css::uno::Reference
< css::accessibility::XAccessibleContext
> SidebarWinAccessible::CreateAccessibleContext()
132 rtl::Reference
<SidebarWinAccessibleContext
> pAccContext
=
133 new SidebarWinAccessibleContext( mrSidebarWin
,
136 m_bAccContextCreated
= true;
140 } // end of namespace sw::sidebarwindows
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */