xref: /AOO41X/main/sw/source/ui/docvw/SidebarWinAcc.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <SidebarWinAcc.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <SidebarWin.hxx>
30cdf0e10cSrcweir #include <viewsh.hxx>
31cdf0e10cSrcweir #include <accmap.hxx>
32cdf0e10cSrcweir #include <toolkit/awt/vclxaccessiblecomponent.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace css = ::com::sun::star;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace sw { namespace sidebarwindows {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // =============================================================================
41cdf0e10cSrcweir // declaration and implementation of accessible context for <SidebarWinAccessible> instance
42cdf0e10cSrcweir // =============================================================================
43cdf0e10cSrcweir class SidebarWinAccessibleContext : public VCLXAccessibleComponent
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     public:
SidebarWinAccessibleContext(SwSidebarWin & rSidebarWin,ViewShell & rViewShell,const SwFrm * pAnchorFrm)46cdf0e10cSrcweir         explicit SidebarWinAccessibleContext( SwSidebarWin& rSidebarWin,
47cdf0e10cSrcweir                                               ViewShell& rViewShell,
48cdf0e10cSrcweir                                               const SwFrm* pAnchorFrm )
49cdf0e10cSrcweir             : VCLXAccessibleComponent( rSidebarWin.GetWindowPeer() )
50cdf0e10cSrcweir             , mrViewShell( rViewShell )
51cdf0e10cSrcweir             , mpAnchorFrm( pAnchorFrm )
52cdf0e10cSrcweir             , maMutex()
53cdf0e10cSrcweir         {
54cdf0e10cSrcweir             rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT );
55cdf0e10cSrcweir         }
56cdf0e10cSrcweir 
~SidebarWinAccessibleContext()57cdf0e10cSrcweir         virtual ~SidebarWinAccessibleContext()
58cdf0e10cSrcweir         {}
59cdf0e10cSrcweir 
ChangeAnchor(const SwFrm * pAnchorFrm)60cdf0e10cSrcweir         void ChangeAnchor( const SwFrm* pAnchorFrm )
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir             mpAnchorFrm = pAnchorFrm;
65cdf0e10cSrcweir         }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
getAccessibleParent()68cdf0e10cSrcweir             getAccessibleParent() throw (css::uno::RuntimeException)
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir             css::uno::Reference< css::accessibility::XAccessible > xAccParent;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             if ( mpAnchorFrm &&
75cdf0e10cSrcweir                  mrViewShell.GetAccessibleMap() )
76cdf0e10cSrcweir             {
77cdf0e10cSrcweir                 xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrm, sal_False );
78cdf0e10cSrcweir             }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir             return xAccParent;
81cdf0e10cSrcweir         }
82cdf0e10cSrcweir 
getAccessibleIndexInParent()83cdf0e10cSrcweir         virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() throw (css::uno::RuntimeException)
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir             sal_Int32 nIndex( -1 );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             if ( mpAnchorFrm && GetWindow() &&
90cdf0e10cSrcweir                  mrViewShell.GetAccessibleMap() )
91cdf0e10cSrcweir             {
92cdf0e10cSrcweir                 nIndex = mrViewShell.GetAccessibleMap()->GetChildIndex( *mpAnchorFrm,
93cdf0e10cSrcweir                                                                         *GetWindow() );
94cdf0e10cSrcweir             }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir             return nIndex;
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     private:
100cdf0e10cSrcweir         ViewShell& mrViewShell;
101cdf0e10cSrcweir         const SwFrm* mpAnchorFrm;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         ::vos::OMutex maMutex;
104cdf0e10cSrcweir };
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // =============================================================================
107cdf0e10cSrcweir // implementaion of accessible for <SwSidebarWin> instance
108cdf0e10cSrcweir // =============================================================================
SidebarWinAccessible(SwSidebarWin & rSidebarWin,ViewShell & rViewShell,const SwSidebarItem & rSidebarItem)109cdf0e10cSrcweir SidebarWinAccessible::SidebarWinAccessible( SwSidebarWin& rSidebarWin,
110cdf0e10cSrcweir                                             ViewShell& rViewShell,
111cdf0e10cSrcweir                                             const SwSidebarItem& rSidebarItem )
112cdf0e10cSrcweir     : VCLXWindow()
113cdf0e10cSrcweir     , mrSidebarWin( rSidebarWin )
114cdf0e10cSrcweir     , mrViewShell( rViewShell )
115cdf0e10cSrcweir     , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm )
116cdf0e10cSrcweir     , bAccContextCreated( false )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     SetWindow( &mrSidebarWin );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
~SidebarWinAccessible()121cdf0e10cSrcweir SidebarWinAccessible::~SidebarWinAccessible()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
ChangeSidebarItem(const SwSidebarItem & rSidebarItem)125cdf0e10cSrcweir void SidebarWinAccessible::ChangeSidebarItem( const SwSidebarItem& rSidebarItem )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     if ( bAccContextCreated )
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         css::uno::Reference< css::accessibility::XAccessibleContext > xAcc
130cdf0e10cSrcweir                                                     = getAccessibleContext();
131cdf0e10cSrcweir         if ( xAcc.is() )
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             SidebarWinAccessibleContext* pAccContext =
134cdf0e10cSrcweir                         dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get());
135cdf0e10cSrcweir             if ( pAccContext )
136cdf0e10cSrcweir             {
137cdf0e10cSrcweir                 pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrm );
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
CreateAccessibleContext()143cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     SidebarWinAccessibleContext* pAccContext =
146cdf0e10cSrcweir                                 new SidebarWinAccessibleContext( mrSidebarWin,
147cdf0e10cSrcweir                                                                  mrViewShell,
148cdf0e10cSrcweir                                                                  mpAnchorFrm );
149cdf0e10cSrcweir     css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
150cdf0e10cSrcweir     bAccContextCreated = true;
151cdf0e10cSrcweir     return xAcc;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir } } // end of namespace sw::sidebarwindows
155cdf0e10cSrcweir 
156