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 <SidebarTxtControlAcc.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <SidebarTxtControl.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <svl/brdcst.hxx> 39*cdf0e10cSrcweir #include <toolkit/awt/vclxaccessiblecomponent.hxx> 40*cdf0e10cSrcweir #include <editeng/unoedsrc.hxx> 41*cdf0e10cSrcweir #include <editeng/unoforou.hxx> 42*cdf0e10cSrcweir #include <editeng/unoviwou.hxx> 43*cdf0e10cSrcweir #include <editeng/unoedhlp.hxx> 44*cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx> 45*cdf0e10cSrcweir #include <editeng/outliner.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace css = ::com::sun::star; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace sw { namespace sidebarwindows { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // ============================================================================= 53*cdf0e10cSrcweir // declaration and implementation of <SvxEditSource> 54*cdf0e10cSrcweir // for <::accessibiliy::AccessibleTextHelper> instance 55*cdf0e10cSrcweir // ============================================================================= 56*cdf0e10cSrcweir class SidebarTextEditSource : public SvxEditSource, 57*cdf0e10cSrcweir public SfxBroadcaster 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir public: 60*cdf0e10cSrcweir SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl ); 61*cdf0e10cSrcweir virtual ~SidebarTextEditSource(); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir virtual SvxEditSource* Clone() const; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir virtual SvxTextForwarder* GetTextForwarder(); 66*cdf0e10cSrcweir virtual SvxViewForwarder* GetViewForwarder(); 67*cdf0e10cSrcweir virtual SvxEditViewForwarder* GetEditViewForwarder( sal_Bool bCreate = sal_False ); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir virtual void UpdateData(); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir virtual SfxBroadcaster& GetBroadcaster() const; 72*cdf0e10cSrcweir DECL_LINK( NotifyHdl, EENotify* ); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir private: 75*cdf0e10cSrcweir SidebarTxtControl& mrSidebarTxtControl; 76*cdf0e10cSrcweir SvxOutlinerForwarder mTextForwarder; 77*cdf0e10cSrcweir SvxDrawOutlinerViewForwarder mViewForwarder; 78*cdf0e10cSrcweir }; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir SidebarTextEditSource::SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl ) 81*cdf0e10cSrcweir : SvxEditSource() 82*cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 83*cdf0e10cSrcweir , mTextForwarder( *(rSidebarTxtControl.GetTextView()->GetOutliner()), sal_False ) 84*cdf0e10cSrcweir , mViewForwarder( *(rSidebarTxtControl.GetTextView()) ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir if ( mrSidebarTxtControl.GetTextView() ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( LINK(this, SidebarTextEditSource, NotifyHdl) ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir SidebarTextEditSource::~SidebarTextEditSource() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir if ( mrSidebarTxtControl.GetTextView() ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( Link() ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir SvxEditSource* SidebarTextEditSource::Clone() const 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir return new SidebarTextEditSource( mrSidebarTxtControl ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir SvxTextForwarder* SidebarTextEditSource::GetTextForwarder() 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir return &mTextForwarder; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir SvxViewForwarder* SidebarTextEditSource::GetViewForwarder() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir return &mViewForwarder; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir SvxEditViewForwarder* SidebarTextEditSource::GetEditViewForwarder( sal_Bool /*bCreate*/ ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir return &mViewForwarder; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SidebarTextEditSource::UpdateData() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir // nothing to do 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir SfxBroadcaster& SidebarTextEditSource::GetBroadcaster() const 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir return *( const_cast< SidebarTextEditSource* > (this) ); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify*, pNotify) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir if ( pNotify ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( pNotify ) ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir if( aHint.get() ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir Broadcast( *aHint.get() ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return 0; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // ============================================================================= 147*cdf0e10cSrcweir // declaration and implementation of accessible context for <SidebarTxtControl> instance 148*cdf0e10cSrcweir // ============================================================================= 149*cdf0e10cSrcweir class SidebarTxtControlAccessibleContext : public VCLXAccessibleComponent 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir public: 152*cdf0e10cSrcweir explicit SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl ); 153*cdf0e10cSrcweir virtual ~SidebarTxtControlAccessibleContext(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL 156*cdf0e10cSrcweir getAccessibleChildCount() 157*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 158*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL 159*cdf0e10cSrcweir getAccessibleChild( sal_Int32 i ) 160*cdf0e10cSrcweir throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir using WeakAggComponentImplHelperBase::addEventListener; 163*cdf0e10cSrcweir using WeakAggComponentImplHelperBase::removeEventListener; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir virtual void SAL_CALL 166*cdf0e10cSrcweir addEventListener ( 167*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 168*cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 169*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 170*cdf0e10cSrcweir virtual void SAL_CALL 171*cdf0e10cSrcweir removeEventListener ( 172*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 173*cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 174*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir protected: 177*cdf0e10cSrcweir virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir private: 180*cdf0e10cSrcweir SidebarTxtControl& mrSidebarTxtControl; 181*cdf0e10cSrcweir ::accessibility::AccessibleTextHelper* mpAccessibleTextHelper; 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir ::vos::OMutex maMutex; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void defunc(); 186*cdf0e10cSrcweir }; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir SidebarTxtControlAccessibleContext::SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl ) 189*cdf0e10cSrcweir : VCLXAccessibleComponent( rSidebarTxtControl.GetWindowPeer() ) 190*cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 191*cdf0e10cSrcweir , mpAccessibleTextHelper( 0 ) 192*cdf0e10cSrcweir , maMutex() 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir ::std::auto_ptr<SvxEditSource> pEditSource( 195*cdf0e10cSrcweir new SidebarTextEditSource( mrSidebarTxtControl ) ); 196*cdf0e10cSrcweir mpAccessibleTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource ); 197*cdf0e10cSrcweir mpAccessibleTextHelper->SetEventSource( mrSidebarTxtControl.GetWindowPeer() ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir SidebarTxtControlAccessibleContext::~SidebarTxtControlAccessibleContext() 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir defunc(); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void SidebarTxtControlAccessibleContext::defunc() 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir delete mpAccessibleTextHelper; 208*cdf0e10cSrcweir mpAccessibleTextHelper = 0; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir sal_Int32 SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChildCount() 212*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir sal_Int32 nChildCount( 0 ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir nChildCount = mpAccessibleTextHelper->GetChildCount(); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir return nChildCount; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChild( sal_Int32 i ) 227*cdf0e10cSrcweir throw ( css::lang::IndexOutOfBoundsException, css::uno::RuntimeException ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessible > xChild; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir xChild = mpAccessibleTextHelper->GetChild( i ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir return xChild; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir void SAL_CALL SidebarTxtControlAccessibleContext::addEventListener ( 242*cdf0e10cSrcweir const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) 243*cdf0e10cSrcweir throw (css::uno::RuntimeException) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir mpAccessibleTextHelper->AddEventListener(xListener); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir void SAL_CALL SidebarTxtControlAccessibleContext::removeEventListener ( 254*cdf0e10cSrcweir const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) 255*cdf0e10cSrcweir throw (css::uno::RuntimeException) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir mpAccessibleTextHelper->RemoveEventListener(xListener); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void SidebarTxtControlAccessibleContext::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING: 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir defunc(); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir break; 276*cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS: 277*cdf0e10cSrcweir case VCLEVENT_CONTROL_GETFOCUS: 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir mpAccessibleTextHelper->SetFocus( sal_True ); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS: 283*cdf0e10cSrcweir case VCLEVENT_CONTROL_LOSEFOCUS: 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir mpAccessibleTextHelper->SetFocus( sal_False ); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir break; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir // ============================================================================= 295*cdf0e10cSrcweir // implementaion of accessible for <SidebarTxtControl> instance 296*cdf0e10cSrcweir // ============================================================================= 297*cdf0e10cSrcweir SidebarTxtControlAccessible::SidebarTxtControlAccessible( SidebarTxtControl& rSidebarTxtControl ) 298*cdf0e10cSrcweir : VCLXWindow() 299*cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir SetWindow( &mrSidebarTxtControl ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir SidebarTxtControlAccessible::~SidebarTxtControlAccessible() 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTxtControlAccessible::CreateAccessibleContext() 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir SidebarTxtControlAccessibleContext* pAccContext( 311*cdf0e10cSrcweir new SidebarTxtControlAccessibleContext( mrSidebarTxtControl ) ); 312*cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext ); 313*cdf0e10cSrcweir return xAcc; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir } } // end of namespace sw::sidebarwindows 317*cdf0e10cSrcweir 318