1efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5efeef26fSAndrew Rist * distributed with this work for additional information 6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14efeef26fSAndrew Rist * software distributed under the License is distributed on an 15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17efeef26fSAndrew Rist * specific language governing permissions and limitations 18efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20efeef26fSAndrew Rist *************************************************************/ 21efeef26fSAndrew Rist 22efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <SidebarTxtControlAcc.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <SidebarTxtControl.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <svl/brdcst.hxx> 32cdf0e10cSrcweir #include <toolkit/awt/vclxaccessiblecomponent.hxx> 33cdf0e10cSrcweir #include <editeng/unoedsrc.hxx> 34cdf0e10cSrcweir #include <editeng/unoforou.hxx> 35cdf0e10cSrcweir #include <editeng/unoviwou.hxx> 36cdf0e10cSrcweir #include <editeng/unoedhlp.hxx> 37cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx> 38cdf0e10cSrcweir #include <editeng/outliner.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace css = ::com::sun::star; 42cdf0e10cSrcweir 43cdf0e10cSrcweir namespace sw { namespace sidebarwindows { 44cdf0e10cSrcweir 45cdf0e10cSrcweir // ============================================================================= 46cdf0e10cSrcweir // declaration and implementation of <SvxEditSource> 47*0cb2ec91SJohn Bampton // for <::accessibility::AccessibleTextHelper> instance 48cdf0e10cSrcweir // ============================================================================= 49cdf0e10cSrcweir class SidebarTextEditSource : public SvxEditSource, 50cdf0e10cSrcweir public SfxBroadcaster 51cdf0e10cSrcweir { 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl ); 54cdf0e10cSrcweir virtual ~SidebarTextEditSource(); 55cdf0e10cSrcweir 56cdf0e10cSrcweir virtual SvxEditSource* Clone() const; 57cdf0e10cSrcweir 58cdf0e10cSrcweir virtual SvxTextForwarder* GetTextForwarder(); 59cdf0e10cSrcweir virtual SvxViewForwarder* GetViewForwarder(); 60cdf0e10cSrcweir virtual SvxEditViewForwarder* GetEditViewForwarder( sal_Bool bCreate = sal_False ); 61cdf0e10cSrcweir 62cdf0e10cSrcweir virtual void UpdateData(); 63cdf0e10cSrcweir 64cdf0e10cSrcweir virtual SfxBroadcaster& GetBroadcaster() const; 65cdf0e10cSrcweir DECL_LINK( NotifyHdl, EENotify* ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir private: 68cdf0e10cSrcweir SidebarTxtControl& mrSidebarTxtControl; 69cdf0e10cSrcweir SvxOutlinerForwarder mTextForwarder; 70cdf0e10cSrcweir SvxDrawOutlinerViewForwarder mViewForwarder; 71cdf0e10cSrcweir }; 72cdf0e10cSrcweir 73cdf0e10cSrcweir SidebarTextEditSource::SidebarTextEditSource( SidebarTxtControl& rSidebarTxtControl ) 74cdf0e10cSrcweir : SvxEditSource() 75cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 76cdf0e10cSrcweir , mTextForwarder( *(rSidebarTxtControl.GetTextView()->GetOutliner()), sal_False ) 77cdf0e10cSrcweir , mViewForwarder( *(rSidebarTxtControl.GetTextView()) ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir if ( mrSidebarTxtControl.GetTextView() ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( LINK(this, SidebarTextEditSource, NotifyHdl) ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir SidebarTextEditSource::~SidebarTextEditSource() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir if ( mrSidebarTxtControl.GetTextView() ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir mrSidebarTxtControl.GetTextView()->GetOutliner()->SetNotifyHdl( Link() ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir SvxEditSource* SidebarTextEditSource::Clone() const 94cdf0e10cSrcweir { 95cdf0e10cSrcweir return new SidebarTextEditSource( mrSidebarTxtControl ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir SvxTextForwarder* SidebarTextEditSource::GetTextForwarder() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir return &mTextForwarder; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir SvxViewForwarder* SidebarTextEditSource::GetViewForwarder() 104cdf0e10cSrcweir { 105cdf0e10cSrcweir return &mViewForwarder; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir SvxEditViewForwarder* SidebarTextEditSource::GetEditViewForwarder( sal_Bool /*bCreate*/ ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return &mViewForwarder; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir void SidebarTextEditSource::UpdateData() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir // nothing to do 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir SfxBroadcaster& SidebarTextEditSource::GetBroadcaster() const 119cdf0e10cSrcweir { 120cdf0e10cSrcweir return *( const_cast< SidebarTextEditSource* > (this) ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify*, pNotify) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if ( pNotify ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir ::std::auto_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( pNotify ) ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir if( aHint.get() ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir Broadcast( *aHint.get() ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir return 0; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir // ============================================================================= 140cdf0e10cSrcweir // declaration and implementation of accessible context for <SidebarTxtControl> instance 141cdf0e10cSrcweir // ============================================================================= 142cdf0e10cSrcweir class SidebarTxtControlAccessibleContext : public VCLXAccessibleComponent 143cdf0e10cSrcweir { 144cdf0e10cSrcweir public: 145cdf0e10cSrcweir explicit SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl ); 146cdf0e10cSrcweir virtual ~SidebarTxtControlAccessibleContext(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir virtual sal_Int32 SAL_CALL 149cdf0e10cSrcweir getAccessibleChildCount() 150cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 151cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL 152cdf0e10cSrcweir getAccessibleChild( sal_Int32 i ) 153cdf0e10cSrcweir throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 154cdf0e10cSrcweir 155cdf0e10cSrcweir using WeakAggComponentImplHelperBase::addEventListener; 156cdf0e10cSrcweir using WeakAggComponentImplHelperBase::removeEventListener; 157cdf0e10cSrcweir 158cdf0e10cSrcweir virtual void SAL_CALL 159cdf0e10cSrcweir addEventListener ( 160cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 161cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 162cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 163cdf0e10cSrcweir virtual void SAL_CALL 164cdf0e10cSrcweir removeEventListener ( 165cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 166cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 167cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 168cdf0e10cSrcweir 169cdf0e10cSrcweir protected: 170cdf0e10cSrcweir virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir private: 173cdf0e10cSrcweir SidebarTxtControl& mrSidebarTxtControl; 174cdf0e10cSrcweir ::accessibility::AccessibleTextHelper* mpAccessibleTextHelper; 175cdf0e10cSrcweir 176cdf0e10cSrcweir ::vos::OMutex maMutex; 177cdf0e10cSrcweir 178cdf0e10cSrcweir void defunc(); 179cdf0e10cSrcweir }; 180cdf0e10cSrcweir 181cdf0e10cSrcweir SidebarTxtControlAccessibleContext::SidebarTxtControlAccessibleContext( SidebarTxtControl& rSidebarTxtControl ) 182cdf0e10cSrcweir : VCLXAccessibleComponent( rSidebarTxtControl.GetWindowPeer() ) 183cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 184cdf0e10cSrcweir , mpAccessibleTextHelper( 0 ) 185cdf0e10cSrcweir , maMutex() 186cdf0e10cSrcweir { 187cdf0e10cSrcweir ::std::auto_ptr<SvxEditSource> pEditSource( 188cdf0e10cSrcweir new SidebarTextEditSource( mrSidebarTxtControl ) ); 189cdf0e10cSrcweir mpAccessibleTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource ); 190cdf0e10cSrcweir mpAccessibleTextHelper->SetEventSource( mrSidebarTxtControl.GetWindowPeer() ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir SidebarTxtControlAccessibleContext::~SidebarTxtControlAccessibleContext() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir defunc(); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir void SidebarTxtControlAccessibleContext::defunc() 199cdf0e10cSrcweir { 200cdf0e10cSrcweir delete mpAccessibleTextHelper; 201cdf0e10cSrcweir mpAccessibleTextHelper = 0; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir sal_Int32 SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChildCount() 205cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir sal_Int32 nChildCount( 0 ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir nChildCount = mpAccessibleTextHelper->GetChildCount(); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir return nChildCount; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTxtControlAccessibleContext::getAccessibleChild( sal_Int32 i ) 220cdf0e10cSrcweir throw ( css::lang::IndexOutOfBoundsException, css::uno::RuntimeException ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessible > xChild; 225cdf0e10cSrcweir 226cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir xChild = mpAccessibleTextHelper->GetChild( i ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir return xChild; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir void SAL_CALL SidebarTxtControlAccessibleContext::addEventListener ( 235cdf0e10cSrcweir const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) 236cdf0e10cSrcweir throw (css::uno::RuntimeException) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 239cdf0e10cSrcweir 240cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir mpAccessibleTextHelper->AddEventListener(xListener); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir void SAL_CALL SidebarTxtControlAccessibleContext::removeEventListener ( 247cdf0e10cSrcweir const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) 248cdf0e10cSrcweir throw (css::uno::RuntimeException) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir vos::OGuard aGuard( maMutex ); 251cdf0e10cSrcweir 252cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir mpAccessibleTextHelper->RemoveEventListener(xListener); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir void SidebarTxtControlAccessibleContext::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir if ( mpAccessibleTextHelper ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING: 265cdf0e10cSrcweir { 266cdf0e10cSrcweir defunc(); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir break; 269cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS: 270cdf0e10cSrcweir case VCLEVENT_CONTROL_GETFOCUS: 271cdf0e10cSrcweir { 272cdf0e10cSrcweir mpAccessibleTextHelper->SetFocus( sal_True ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir break; 275cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS: 276cdf0e10cSrcweir case VCLEVENT_CONTROL_LOSEFOCUS: 277cdf0e10cSrcweir { 278cdf0e10cSrcweir mpAccessibleTextHelper->SetFocus( sal_False ); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir break; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent ); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir // ============================================================================= 288cdf0e10cSrcweir // implementaion of accessible for <SidebarTxtControl> instance 289cdf0e10cSrcweir // ============================================================================= 290cdf0e10cSrcweir SidebarTxtControlAccessible::SidebarTxtControlAccessible( SidebarTxtControl& rSidebarTxtControl ) 291cdf0e10cSrcweir : VCLXWindow() 292cdf0e10cSrcweir , mrSidebarTxtControl( rSidebarTxtControl ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir SetWindow( &mrSidebarTxtControl ); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir SidebarTxtControlAccessible::~SidebarTxtControlAccessible() 298cdf0e10cSrcweir { 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTxtControlAccessible::CreateAccessibleContext() 302cdf0e10cSrcweir { 303cdf0e10cSrcweir SidebarTxtControlAccessibleContext* pAccContext( 304cdf0e10cSrcweir new SidebarTxtControlAccessibleContext( mrSidebarTxtControl ) ); 305cdf0e10cSrcweir css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext ); 306cdf0e10cSrcweir return xAcc; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir } } // end of namespace sw::sidebarwindows 310