LibreOffice Module sw (master) 1
SidebarWinAcc.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "SidebarWinAcc.hxx"
21#include <AnnotationWin.hxx>
22
23#include <viewsh.hxx>
24#include <accmap.hxx>
26
27#include <com/sun/star/accessibility/AccessibleRole.hpp>
28#include <mutex>
29
30namespace sw::sidebarwindows {
31
32namespace {
33
34// declaration and implementation of accessible context for <SidebarWinAccessible> instance
35class SidebarWinAccessibleContext : public VCLXAccessibleComponent
36{
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 )
44 {
45 rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT );
46 }
47
48 void ChangeAnchor( const SwFrame* pAnchorFrame )
49 {
50 std::scoped_lock aGuard(maMutex);
51
52 mpAnchorFrame = pAnchorFrame;
53 }
54
55 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
56 getAccessibleParent() override
57 {
58 std::scoped_lock aGuard(maMutex);
59
60 css::uno::Reference< css::accessibility::XAccessible > xAccParent;
61
62 if ( mpAnchorFrame &&
64 {
65 xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrame, false );
66 }
67
68 return xAccParent;
69 }
70
71 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
72 {
73 std::scoped_lock aGuard(maMutex);
74
75 sal_Int64 nIndex( -1 );
76
77 if ( mpAnchorFrame && GetWindow() &&
79 {
81 *GetWindow() );
82 }
83
84 return nIndex;
85 }
86
87 private:
90
91 std::mutex maMutex;
92};
93
94}
95
96// implementation of accessible for <SwAnnotationWin> instance
98 SwViewShell& rViewShell,
99 const SwSidebarItem& rSidebarItem )
100 : mrSidebarWin( rSidebarWin )
101 , mrViewShell( rViewShell )
102 , mpAnchorFrame( rSidebarItem.maLayoutInfo.mpAnchorFrame )
103 , m_bAccContextCreated( false )
104{
106}
107
109{
110}
111
113{
115 return;
116
117 css::uno::Reference< css::accessibility::XAccessibleContext > xAcc
119 if ( xAcc.is() )
120 {
121 SidebarWinAccessibleContext* pAccContext =
122 dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get());
123 if ( pAccContext )
124 {
125 pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrame );
126 }
127 }
128}
129
130css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
131{
133 new SidebarWinAccessibleContext( mrSidebarWin,
137 return pAccContext;
138}
139
140} // end of namespace sw::sidebarwindows
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::mutex maMutex
SwViewShell & mrViewShell
const SwFrame * mpAnchorFrame
sal_Int32 GetChildIndex(const SwFrame &rParentFrame, vcl::Window &rChild) const
Definition: accmap.cxx:2869
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1789
Base class of the Writer layout elements.
Definition: frame.hxx:315
SwLayoutInfo maLayoutInfo
SwAccessibleMap * GetAccessibleMap()
Definition: viewsh.cxx:2633
css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
virtual void SetWindow(const VclPtr< vcl::Window > &pWindow)
sw::annotation::SwAnnotationWin & mrSidebarWin
void ChangeSidebarItem(const SwSidebarItem &rSidebarItem)
SidebarWinAccessible(sw::annotation::SwAnnotationWin &rSidebarWin, SwViewShell &rViewShell, const SwSidebarItem &rSidebarItem)
virtual css::uno::Reference< css::accessibility::XAccessibleContext > CreateAccessibleContext() override
void SetAccessibleRole(sal_uInt16 nRole)
sal_Int32 nIndex
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
const SwFrame * mpAnchorFrame