LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - SidebarTxtControlAcc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 87 0.0 %
Date: 2014-04-11 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10