Line data Source code
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 :
22 : #include <SidebarWin.hxx>
23 : #include <viewsh.hxx>
24 : #include <accmap.hxx>
25 : #include <toolkit/awt/vclxaccessiblecomponent.hxx>
26 :
27 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 :
29 : namespace sw { namespace sidebarwindows {
30 :
31 : // declaration and implementation of accessible context for <SidebarWinAccessible> instance
32 : class SidebarWinAccessibleContext : public VCLXAccessibleComponent
33 : {
34 : public:
35 0 : explicit SidebarWinAccessibleContext( SwSidebarWin& rSidebarWin,
36 : SwViewShell& rViewShell,
37 : const SwFrm* pAnchorFrm )
38 : : VCLXAccessibleComponent( rSidebarWin.GetWindowPeer() )
39 : , mrViewShell( rViewShell )
40 : , mpAnchorFrm( pAnchorFrm )
41 0 : , maMutex()
42 : {
43 0 : rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT );
44 0 : }
45 :
46 0 : virtual ~SidebarWinAccessibleContext()
47 0 : {}
48 :
49 0 : void ChangeAnchor( const SwFrm* pAnchorFrm )
50 : {
51 0 : osl::MutexGuard aGuard(maMutex);
52 :
53 0 : mpAnchorFrm = pAnchorFrm;
54 0 : }
55 :
56 : virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
57 0 : getAccessibleParent() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
58 : {
59 0 : osl::MutexGuard aGuard(maMutex);
60 :
61 0 : css::uno::Reference< css::accessibility::XAccessible > xAccParent;
62 :
63 0 : if ( mpAnchorFrm &&
64 0 : mrViewShell.GetAccessibleMap() )
65 : {
66 0 : xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrm, sal_False );
67 : }
68 :
69 0 : return xAccParent;
70 : }
71 :
72 0 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
73 : {
74 0 : osl::MutexGuard aGuard(maMutex);
75 :
76 0 : sal_Int32 nIndex( -1 );
77 :
78 0 : if ( mpAnchorFrm && GetWindow() &&
79 0 : mrViewShell.GetAccessibleMap() )
80 : {
81 : nIndex = mrViewShell.GetAccessibleMap()->GetChildIndex( *mpAnchorFrm,
82 0 : *GetWindow() );
83 : }
84 :
85 0 : return nIndex;
86 : }
87 :
88 : private:
89 : SwViewShell& mrViewShell;
90 : const SwFrm* mpAnchorFrm;
91 :
92 : ::osl::Mutex maMutex;
93 : };
94 :
95 : // implementaion of accessible for <SwSidebarWin> instance
96 0 : SidebarWinAccessible::SidebarWinAccessible( SwSidebarWin& rSidebarWin,
97 : SwViewShell& rViewShell,
98 : const SwSidebarItem& rSidebarItem )
99 : : VCLXWindow()
100 : , mrSidebarWin( rSidebarWin )
101 : , mrViewShell( rViewShell )
102 : , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm )
103 0 : , bAccContextCreated( false )
104 : {
105 0 : SetWindow( &mrSidebarWin );
106 0 : }
107 :
108 0 : SidebarWinAccessible::~SidebarWinAccessible()
109 : {
110 0 : }
111 :
112 0 : void SidebarWinAccessible::ChangeSidebarItem( const SwSidebarItem& rSidebarItem )
113 : {
114 0 : if ( bAccContextCreated )
115 : {
116 : css::uno::Reference< css::accessibility::XAccessibleContext > xAcc
117 0 : = getAccessibleContext();
118 0 : if ( xAcc.is() )
119 : {
120 : SidebarWinAccessibleContext* pAccContext =
121 0 : dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get());
122 0 : if ( pAccContext )
123 : {
124 0 : pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrm );
125 : }
126 0 : }
127 : }
128 0 : }
129 :
130 0 : css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
131 : {
132 : SidebarWinAccessibleContext* pAccContext =
133 : new SidebarWinAccessibleContext( mrSidebarWin,
134 : mrViewShell,
135 0 : mpAnchorFrm );
136 0 : css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
137 0 : bAccContextCreated = true;
138 0 : return xAcc;
139 : }
140 :
141 : } } // end of namespace sw::sidebarwindows
142 :
143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|