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

Generated by: LCOV version 1.10