Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / docvw / SidebarWinAcc.cxx
blobf489bc140b6b517e3f1482c349ecafab6709a2de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <viewsh.hxx>
24 #include <accmap.hxx>
25 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <mutex>
30 namespace sw::sidebarwindows {
32 namespace {
34 // declaration and implementation of accessible context for <SidebarWinAccessible> instance
35 class SidebarWinAccessibleContext : public VCLXAccessibleComponent
37 public:
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;
62 if ( mpAnchorFrame &&
63 mrViewShell.GetAccessibleMap() )
65 xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrame, false );
68 return xAccParent;
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,
81 *GetWindow() );
84 return nIndex;
87 private:
88 SwViewShell& mrViewShell;
89 const SwFrame* mpAnchorFrame;
91 std::mutex maMutex;
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 )
115 return;
117 css::uno::Reference< css::accessibility::XAccessibleContext > xAcc
118 = getAccessibleContext();
119 if ( xAcc.is() )
121 SidebarWinAccessibleContext* pAccContext =
122 dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get());
123 if ( pAccContext )
125 pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrame );
130 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
132 rtl::Reference<SidebarWinAccessibleContext> pAccContext =
133 new SidebarWinAccessibleContext( mrSidebarWin,
134 mrViewShell,
135 mpAnchorFrame );
136 m_bAccContextCreated = true;
137 return pAccContext;
140 } // end of namespace sw::sidebarwindows
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */