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 
29 namespace sw { namespace sidebarwindows {
30 
31 namespace {
32 
33 // declaration and implementation of accessible context for <SidebarWinAccessible> instance
34 class SidebarWinAccessibleContext : public VCLXAccessibleComponent
35 {
36  public:
37  explicit SidebarWinAccessibleContext( sw::annotation::SwAnnotationWin& rSidebarWin,
38  SwViewShell& rViewShell,
39  const SwFrame* pAnchorFrame )
40  : VCLXAccessibleComponent( rSidebarWin.GetWindowPeer() )
41  , mrViewShell( rViewShell )
42  , mpAnchorFrame( pAnchorFrame )
43  , maMutex()
44  {
45  rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT );
46  }
47 
48  void ChangeAnchor( const SwFrame* pAnchorFrame )
49  {
50  osl::MutexGuard aGuard(maMutex);
51 
52  mpAnchorFrame = pAnchorFrame;
53  }
54 
55  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
56  getAccessibleParent() override
57  {
58  osl::MutexGuard 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_Int32 SAL_CALL getAccessibleIndexInParent() override
72  {
73  osl::MutexGuard aGuard(maMutex);
74 
75  sal_Int32 nIndex( -1 );
76 
77  if ( mpAnchorFrame && GetWindow() &&
79  {
81  *GetWindow() );
82  }
83 
84  return nIndex;
85  }
86 
87  private:
90 
91  ::osl::Mutex maMutex;
92 };
93 
94 }
95 
96 // implementation of accessible for <SwAnnotationWin> instance
98  SwViewShell& rViewShell,
99  const SwSidebarItem& rSidebarItem )
100  : VCLXWindow()
101  , mrSidebarWin( rSidebarWin )
102  , mrViewShell( rViewShell )
103  , mpAnchorFrame( rSidebarItem.maLayoutInfo.mpAnchorFrame )
104  , bAccContextCreated( false )
105 {
107 }
108 
110 {
111 }
112 
114 {
115  if ( bAccContextCreated )
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 }
130 
131 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
132 {
133  SidebarWinAccessibleContext* pAccContext =
134  new SidebarWinAccessibleContext( mrSidebarWin,
135  mrViewShell,
136  mpAnchorFrame );
137  css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
138  bAccContextCreated = true;
139  return xAcc;
140 }
141 
142 } } // end of namespace sw::sidebarwindows
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
sal_Int32 nIndex
const SwFrame * mpAnchorFrame
sal_Int32 GetChildIndex(const SwFrame &rParentFrame, vcl::Window &rChild) const
Definition: accmap.cxx:2955
virtual css::uno::Reference< css::accessibility::XAccessibleContext > CreateAccessibleContext() override
Dialog to specify the properties of date form field.
::osl::Mutex maMutex
void ChangeSidebarItem(const SwSidebarItem &rSidebarItem)
SwAccessibleMap * GetAccessibleMap()
Definition: viewsh.cxx:2448
css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
const SwFrame * mpAnchorFrame
SwLayoutInfo maLayoutInfo
sw::annotation::SwAnnotationWin & mrSidebarWin
virtual void SetWindow(const VclPtr< vcl::Window > &pWindow)
css::uno::Reference< css::accessibility::XAccessible > GetContext(const SwFrame *pFrame, bool bCreate=true)
Definition: accmap.cxx:1870
void SetAccessibleRole(sal_uInt16 nRole)
SidebarWinAccessible(sw::annotation::SwAnnotationWin &rSidebarWin, SwViewShell &rViewShell, const SwSidebarItem &rSidebarItem)
SwViewShell & mrViewShell