xref: /AOO41X/main/sw/source/ui/docvw/SidebarWinAcc.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /************************************************************************* *
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2008 by Sun Microsystems, Inc.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * $RCSfile:  $
10*cdf0e10cSrcweir  * $Revision:  $
11*cdf0e10cSrcweir  *
12*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir  *
18*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir  *
24*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir  *
29*cdf0e10cSrcweir  ************************************************************************/
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "precompiled_sw.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <SidebarWinAcc.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <SidebarWin.hxx>
37*cdf0e10cSrcweir #include <viewsh.hxx>
38*cdf0e10cSrcweir #include <accmap.hxx>
39*cdf0e10cSrcweir #include <toolkit/awt/vclxaccessiblecomponent.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace css = ::com::sun::star;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace sw { namespace sidebarwindows {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // =============================================================================
48*cdf0e10cSrcweir // declaration and implementation of accessible context for <SidebarWinAccessible> instance
49*cdf0e10cSrcweir // =============================================================================
50*cdf0e10cSrcweir class SidebarWinAccessibleContext : public VCLXAccessibleComponent
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     public:
53*cdf0e10cSrcweir         explicit SidebarWinAccessibleContext( SwSidebarWin& rSidebarWin,
54*cdf0e10cSrcweir                                               ViewShell& rViewShell,
55*cdf0e10cSrcweir                                               const SwFrm* pAnchorFrm )
56*cdf0e10cSrcweir             : VCLXAccessibleComponent( rSidebarWin.GetWindowPeer() )
57*cdf0e10cSrcweir             , mrViewShell( rViewShell )
58*cdf0e10cSrcweir             , mpAnchorFrm( pAnchorFrm )
59*cdf0e10cSrcweir             , maMutex()
60*cdf0e10cSrcweir         {
61*cdf0e10cSrcweir             rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT );
62*cdf0e10cSrcweir         }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir         virtual ~SidebarWinAccessibleContext()
65*cdf0e10cSrcweir         {}
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         void ChangeAnchor( const SwFrm* pAnchorFrm )
68*cdf0e10cSrcweir         {
69*cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir             mpAnchorFrm = pAnchorFrm;
72*cdf0e10cSrcweir         }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir         virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
75*cdf0e10cSrcweir             getAccessibleParent() throw (css::uno::RuntimeException)
76*cdf0e10cSrcweir         {
77*cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir             css::uno::Reference< css::accessibility::XAccessible > xAccParent;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir             if ( mpAnchorFrm &&
82*cdf0e10cSrcweir                  mrViewShell.GetAccessibleMap() )
83*cdf0e10cSrcweir             {
84*cdf0e10cSrcweir                 xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrm, sal_False );
85*cdf0e10cSrcweir             }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir             return xAccParent;
88*cdf0e10cSrcweir         }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir         virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() throw (css::uno::RuntimeException)
91*cdf0e10cSrcweir         {
92*cdf0e10cSrcweir             vos::OGuard aGuard(maMutex);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir             sal_Int32 nIndex( -1 );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir             if ( mpAnchorFrm && GetWindow() &&
97*cdf0e10cSrcweir                  mrViewShell.GetAccessibleMap() )
98*cdf0e10cSrcweir             {
99*cdf0e10cSrcweir                 nIndex = mrViewShell.GetAccessibleMap()->GetChildIndex( *mpAnchorFrm,
100*cdf0e10cSrcweir                                                                         *GetWindow() );
101*cdf0e10cSrcweir             }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir             return nIndex;
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     private:
107*cdf0e10cSrcweir         ViewShell& mrViewShell;
108*cdf0e10cSrcweir         const SwFrm* mpAnchorFrm;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         ::vos::OMutex maMutex;
111*cdf0e10cSrcweir };
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir // =============================================================================
114*cdf0e10cSrcweir // implementaion of accessible for <SwSidebarWin> instance
115*cdf0e10cSrcweir // =============================================================================
116*cdf0e10cSrcweir SidebarWinAccessible::SidebarWinAccessible( SwSidebarWin& rSidebarWin,
117*cdf0e10cSrcweir                                             ViewShell& rViewShell,
118*cdf0e10cSrcweir                                             const SwSidebarItem& rSidebarItem )
119*cdf0e10cSrcweir     : VCLXWindow()
120*cdf0e10cSrcweir     , mrSidebarWin( rSidebarWin )
121*cdf0e10cSrcweir     , mrViewShell( rViewShell )
122*cdf0e10cSrcweir     , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm )
123*cdf0e10cSrcweir     , bAccContextCreated( false )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     SetWindow( &mrSidebarWin );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir SidebarWinAccessible::~SidebarWinAccessible()
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir void SidebarWinAccessible::ChangeSidebarItem( const SwSidebarItem& rSidebarItem )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     if ( bAccContextCreated )
135*cdf0e10cSrcweir     {
136*cdf0e10cSrcweir         css::uno::Reference< css::accessibility::XAccessibleContext > xAcc
137*cdf0e10cSrcweir                                                     = getAccessibleContext();
138*cdf0e10cSrcweir         if ( xAcc.is() )
139*cdf0e10cSrcweir         {
140*cdf0e10cSrcweir             SidebarWinAccessibleContext* pAccContext =
141*cdf0e10cSrcweir                         dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get());
142*cdf0e10cSrcweir             if ( pAccContext )
143*cdf0e10cSrcweir             {
144*cdf0e10cSrcweir                 pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrm );
145*cdf0e10cSrcweir             }
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir     }
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext()
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     SidebarWinAccessibleContext* pAccContext =
153*cdf0e10cSrcweir                                 new SidebarWinAccessibleContext( mrSidebarWin,
154*cdf0e10cSrcweir                                                                  mrViewShell,
155*cdf0e10cSrcweir                                                                  mpAnchorFrm );
156*cdf0e10cSrcweir     css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
157*cdf0e10cSrcweir     bAccContextCreated = true;
158*cdf0e10cSrcweir     return xAcc;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir } } // end of namespace sw::sidebarwindows
162*cdf0e10cSrcweir 
163