LCOV - code coverage report
Current view: top level - sw/source/core/access - acccontext.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 18 61.1 %
Date: 2015-06-13 12:38:46 Functions: 8 12 66.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             : #ifndef INCLUDED_SW_SOURCE_CORE_ACCESS_ACCCONTEXT_HXX
      21             : #define INCLUDED_SW_SOURCE_CORE_ACCESS_ACCCONTEXT_HXX
      22             : 
      23             : #include <accframe.hxx>
      24             : #include <accmap.hxx>
      25             : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
      26             : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
      27             : #include <com/sun/star/lang/DisposedException.hpp>
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : #include <cppuhelper/implbase.hxx>
      30             : #include <cppuhelper/interfacecontainer.hxx>
      31             : 
      32             : namespace vcl { class Window; }
      33             : class SwAccessibleMap;
      34             : class SwCrsrShell;
      35             : class SdrObject;
      36             : class SwPaM;
      37             : namespace utl {
      38             :     class AccessibleStateSetHelper;
      39             : }
      40             : namespace accessibility {
      41             :     class AccessibleShape;
      42             : }
      43             : 
      44             : const sal_Char sAccessibleServiceName[] = "com.sun.star.accessibility.Accessible";
      45             : 
      46             : class SwAccessibleContext :
      47             :     public ::cppu::WeakImplHelper<
      48             :                 ::com::sun::star::accessibility::XAccessible,
      49             :                 ::com::sun::star::accessibility::XAccessibleContext,
      50             :                 ::com::sun::star::accessibility::XAccessibleComponent,
      51             :                 ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
      52             :                 ::com::sun::star::lang::XServiceInfo
      53             :                 >,
      54             :     public SwAccessibleFrame
      55             : {
      56             :     // The implements for the XAccessibleSelection interface has been
      57             :     // 'externalized' and wants access to the protected members like
      58             :     // GetMap, GetChild, GetParent, and GetFrm.
      59             :     friend class SwAccessibleSelectionHelper;
      60             : 
      61             : protected:
      62             :     mutable ::osl::Mutex m_ListenerMutex;
      63             :     mutable ::osl::Mutex m_Mutex;
      64             : 
      65             : private:
      66             :     OUString m_sName;  // immutable outside constructor
      67             : 
      68             :     // The parent if it has been retrieved. This is always an
      69             :     // SwAccessibleContext. (protected by Mutex)
      70             :     ::com::sun::star::uno::WeakReference <
      71             :         ::com::sun::star::accessibility::XAccessible > m_xWeakParent;
      72             : 
      73             :     SwAccessibleMap *m_pMap; // must be protected by solar mutex
      74             : 
      75             :     sal_uInt32 m_nClientId;  // client id in the AccessibleEventNotifier queue
      76             :     sal_Int16 m_nRole;        // immutable outside constructor
      77             : 
      78             :     // The current states (protected by mutex)
      79             :     bool m_isShowingState : 1;
      80             :     bool m_isEditableState : 1;
      81             :     bool m_isOpaqueState : 1;
      82             :     bool m_isDefuncState : 1;
      83             : 
      84             :     // Are we currently disposing that object (protected by solar mutex)?
      85             :     bool m_isDisposing : 1;
      86             : 
      87             :     // #i85634# - boolean, indicating if the accessible context is
      88             :     // in general registered at the accessible map.
      89             :     bool m_isRegisteredAtAccessibleMap;
      90             : 
      91             :     void InitStates();
      92             : 
      93             : protected:
      94          97 :     void SetName( const OUString& rName ) { m_sName = rName; }
      95           8 :     inline sal_Int16 GetRole() const
      96             :     {
      97           8 :         return m_nRole;
      98             :     }
      99             :     //This flag is used to mark the object's selected state.
     100             :     bool   m_isSelectedInDoc;
     101             :     void SetParent( SwAccessibleContext *pParent );
     102             :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> GetWeakParent() const;
     103             : 
     104          34 :     bool IsDisposing() const { return m_isDisposing; }
     105             : 
     106             :     vcl::Window *GetWindow();
     107       16825 :     SwAccessibleMap *GetMap() { return m_pMap; }
     108          14 :     const SwAccessibleMap *GetMap() const { return m_pMap; }
     109             : 
     110             :     /** convenience method to get the SwViewShell through accessibility map */
     111         270 :     inline SwViewShell* GetShell()
     112             :     {
     113         270 :         return GetMap()->GetShell();
     114             :     }
     115             :     inline const SwViewShell* GetShell() const
     116             :     {
     117             :         return GetMap()->GetShell();
     118             :     }
     119             : 
     120             :     /** convenience method to get SwCrsrShell through accessibility map
     121             :      * @returns SwCrsrShell, or NULL if none is found */
     122             :     SwCrsrShell* GetCrsrShell();
     123             :     const SwCrsrShell* GetCrsrShell() const;
     124             : 
     125             :     // Notify all children that the vis area has changed.
     126             :     // The SwFrm might belong to the current object or to any other child or
     127             :     // grandchild.
     128             :     void ChildrenScrolled( const SwFrm *pFrm, const SwRect& rOldVisArea );
     129             : 
     130             :     // The context's showing state changed. May only be called for context that
     131             :     // exist even if they aren't visible.
     132             :     void Scrolled( const SwRect& rOldVisArea );
     133             : 
     134             :     // A child has been moved while setting the vis area
     135             :     void ScrolledWithin( const SwRect& rOldVisArea );
     136             : 
     137             :     // The has been added while setting the vis area
     138             :     void ScrolledIn();
     139             : 
     140             :     // The context has to be removed while setting the vis area
     141             :     void ScrolledOut( const SwRect& rOldVisArea );
     142             : 
     143             :     // Invalidate the states of all children of the specified SwFrm. The
     144             :     // SwFrm might belong the current object or to any child or grandchild!
     145             :     // #i27301# - use new type definition for <_nStates>
     146             :     void InvalidateChildrenStates( const SwFrm* _pFrm,
     147             :                                    AccessibleStates _nStates );
     148             : 
     149             :     // Dispose children of the specified SwFrm. The SwFrm might belong to
     150             :     // the current object or to any other child or grandchild.
     151             :     void DisposeChildren( const SwFrm *pFrm,
     152             :                           bool bRecursive );
     153             : 
     154             :     void DisposeShape( const SdrObject *pObj,
     155             :                                 ::accessibility::AccessibleShape *pAccImpl );
     156             :     void ScrolledInShape( const SdrObject *pObj,
     157             :                                 ::accessibility::AccessibleShape *pAccImpl );
     158             : 
     159             :     virtual void _InvalidateContent( bool bVisibleDataFired );
     160             : 
     161             :     virtual void _InvalidateCursorPos();
     162             :     virtual void _InvalidateFocus();
     163             : 
     164             : public:
     165           0 :     void SetMap(SwAccessibleMap *const pMap) { m_pMap = pMap; }
     166             :     void FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventObject& rEvent );
     167             : 
     168             : protected:
     169             :     // broadcast visual data event
     170             :     void FireVisibleDataEvent();
     171             : 
     172             :     // broadcast state change event
     173             :     void FireStateChangedEvent( sal_Int16 nState, bool bNewState );
     174             : 
     175             :     // Set states for getAccessibleStateSet.
     176             :     // This base class sets DEFUNC(0/1), EDITABLE(0/1), ENABLED(1),
     177             :     // SHOWING(0/1), OPAQUE(0/1) and VISIBLE(1).
     178             :     virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet );
     179             : 
     180             :      bool IsEditableState();
     181             : 
     182             :     ::com::sun::star::awt::Rectangle SAL_CALL
     183             :         getBoundsImpl(bool bRelative)
     184             :         throw (css::uno::RuntimeException, std::exception);
     185             : 
     186             :     // #i85634#
     187           0 :     inline void NotRegisteredAtAccessibleMap()
     188             :     {
     189           0 :         m_isRegisteredAtAccessibleMap = false;
     190           0 :     }
     191             :     void RemoveFrmFromAccessibleMap();
     192             : 
     193             :     virtual ~SwAccessibleContext();
     194             : 
     195             : public:
     196             :     SwAccessibleContext( SwAccessibleMap *m_pMap, sal_Int16 nRole,
     197             :                          const SwFrm *pFrm );
     198             : 
     199             :     // XAccessible
     200             : 
     201             :     // Return the XAccessibleContext.
     202             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
     203             :         getAccessibleContext() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     204             : 
     205             :     // XAccessibleContext
     206             : 
     207             :     // Return the number of currently visible children.
     208             :     virtual sal_Int32 SAL_CALL getAccessibleChildCount()
     209             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     210             : 
     211             :     // Return the specified child or NULL if index is invalid.
     212             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
     213             :         getAccessibleChild (sal_Int32 nIndex)
     214             :         throw (::com::sun::star::uno::RuntimeException,
     215             :                 ::com::sun::star::lang::IndexOutOfBoundsException, std::exception) SAL_OVERRIDE;
     216             : 
     217             :     // Return a reference to the parent.
     218             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
     219             :         getAccessibleParent()
     220             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     221             : 
     222             :     // Return this objects index among the parents children.
     223             :     virtual sal_Int32 SAL_CALL
     224             :         getAccessibleIndexInParent()
     225             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     226             : 
     227             :     // Return this object's role.
     228             :     virtual sal_Int16 SAL_CALL
     229             :         getAccessibleRole()
     230             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     231             : 
     232             :     // Return this object's description.
     233             :     virtual OUString SAL_CALL
     234             :         getAccessibleDescription()
     235             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     236             : 
     237             :     // Return the object's current name.
     238             :     virtual OUString SAL_CALL
     239             :         getAccessibleName()
     240             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     241             : 
     242             :     // Return NULL to indicate that an empty relation set.
     243             :     virtual ::com::sun::star::uno::Reference<
     244             :             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
     245             :         getAccessibleRelationSet()
     246             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     247             : 
     248             :     // Return the set of current states.
     249             :     virtual ::com::sun::star::uno::Reference<
     250             :             ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
     251             :         getAccessibleStateSet()
     252             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     253             : 
     254             :     /** Return the parents locale or throw exception if this object has no
     255             :         parent yet/anymore. */
     256             :     virtual ::com::sun::star::lang::Locale SAL_CALL
     257             :         getLocale()
     258             :         throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     259             : 
     260             :     // XAccessibleEventBroadcaster
     261             : 
     262             :     virtual void SAL_CALL addAccessibleEventListener(
     263             :             const ::com::sun::star::uno::Reference<
     264             :                 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
     265             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     266             :     virtual void SAL_CALL removeAccessibleEventListener(
     267             :             const ::com::sun::star::uno::Reference<
     268             :                 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener )
     269             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     270             : 
     271             :     // XAccessibleComponent
     272             :     virtual sal_Bool SAL_CALL containsPoint(
     273             :             const ::com::sun::star::awt::Point& aPoint )
     274             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     275             : 
     276             :     virtual ::com::sun::star::uno::Reference<
     277             :         ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(
     278             :                 const ::com::sun::star::awt::Point& aPoint )
     279             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     280             : 
     281             :     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds()
     282             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     283             : 
     284             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocation()
     285             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     286             : 
     287             :     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen()
     288             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     289             : 
     290             :     virtual ::com::sun::star::awt::Size SAL_CALL getSize()
     291             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     292             : 
     293             :     virtual void SAL_CALL grabFocus()
     294             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     295             : 
     296             :     virtual sal_Int32 SAL_CALL getForeground()
     297             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     298             :     virtual sal_Int32 SAL_CALL getBackground()
     299             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     300             : 
     301             :     // XServiceInfo
     302             : 
     303             :     /** Returns an identifier for the implementation of this object. */
     304             :     virtual OUString SAL_CALL
     305             :         getImplementationName()
     306             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     307             : 
     308             :     /** Return whether the specified service is supported by this class. */
     309             :     virtual sal_Bool SAL_CALL
     310             :         supportsService (const OUString& sServiceName)
     311             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     312             : 
     313             :     /** Returns a list of all supported services.  In this case that is just
     314             :         the AccessibleContext service. */
     315             :     virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL
     316             :         getSupportedServiceNames()
     317             :              throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     318             : 
     319             :     // thread safe C++ interface
     320             : 
     321             :     // The object is not visible an longer and should be destroyed
     322             :     virtual void Dispose( bool bRecursive = false );
     323             : 
     324             :     // The child object is not visible an longer and should be destroyed
     325             :     virtual void DisposeChild( const sw::access::SwAccessibleChild& rFrmOrObj, bool bRecursive );
     326             : 
     327             :     // The object has been moved by the layout
     328             :     virtual void InvalidatePosOrSize( const SwRect& rFrm );
     329             : 
     330             :     // The vhild object has been moved by the layout
     331             :     virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrmOrObj,
     332             :                                            const SwRect& rFrm );
     333             : 
     334             :     // The content may have changed (but it hasn't tohave changed)
     335             :     void InvalidateContent();
     336             : 
     337             :     // The caretPos has changed
     338             :     void InvalidateCursorPos();
     339             : 
     340             :     // The Focus state has changed
     341             :     void InvalidateFocus();
     342             : 
     343             :     // Check states
     344             :     // #i27301# - use new type definition for <_nStates>
     345             :     void InvalidateStates( AccessibleStates _nStates );
     346             : 
     347             :     // the XAccessibleRelationSet may have changed
     348             :     void InvalidateRelation( sal_uInt16 nType );
     349             : 
     350             :     void InvalidateTextSelection(); // #i27301# - text selection has changed
     351             :     void InvalidateAttr(); // #i88069# - attributes has changed
     352             : 
     353             :     bool HasAdditionalAccessibleChildren();
     354             : 
     355             :     // #i88070# - get additional child by index
     356             :     vcl::Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
     357             : 
     358             :     // #i88070# - get all additional accessible children
     359             :     void GetAdditionalAccessibleChildren( std::vector< vcl::Window* >* pChildren );
     360             : 
     361           8 :     const OUString& GetName() const { return m_sName; }
     362             : 
     363             :     virtual bool HasCursor();   // required by map to remember that object
     364             : 
     365             :     bool Select( SwPaM *pPaM, SdrObject *pObj, bool bAdd );
     366           6 :     inline bool Select( SwPaM& rPaM )
     367             :     {
     368           6 :         return Select( &rPaM, 0, false );
     369             :     }
     370           0 :     inline bool Select( SdrObject *pObj, bool bAdd )
     371             :     {
     372           0 :         return Select( 0, pObj, bAdd );
     373             :     }
     374             : 
     375             :     //This method is used to updated the selected state and fire the selected state changed event.
     376             :     virtual bool SetSelectedState(bool bSeleted);
     377           0 :     bool  IsSeletedInDoc() { return m_isSelectedInDoc; }
     378             : 
     379             :     static OUString GetResource( sal_uInt16 nResId,
     380             :                                         const OUString *pArg1 = 0,
     381             :                                         const OUString *pArg2 = 0 );
     382             : };
     383             : 
     384             : // some heavily used exception support
     385             : #define THROW_RUNTIME_EXCEPTION( ifc, msg )                                 \
     386             :     ::com::sun::star::uno::Reference < ifc > xThis( this );                 \
     387             :     ::com::sun::star::uno::RuntimeException aExcept(                        \
     388             :         OUString( msg ), xThis );       \
     389             :     throw aExcept;
     390             : 
     391             : #define CHECK_FOR_DEFUNC_THIS( ifc, ths )                                   \
     392             :     if( !(GetFrm() && GetMap()) )                                           \
     393             :     {                                                                       \
     394             :         ::com::sun::star::uno::Reference < ifc > xThis( ths );              \
     395             :         ::com::sun::star::lang::DisposedException aExcept(                  \
     396             :             OUString( "object is defunctional" ),        \
     397             :             xThis );                                                        \
     398             :         throw aExcept;                                                      \
     399             :     }
     400             : 
     401             : #define CHECK_FOR_DEFUNC( ifc )                                             \
     402             :     CHECK_FOR_DEFUNC_THIS( ifc, this )
     403             : 
     404             : #define CHECK_FOR_WINDOW( i, w )                                            \
     405             :     if( !(w) )                                                              \
     406             :     {                                                                       \
     407             :         THROW_RUNTIME_EXCEPTION( i, "window is missing" );                  \
     408             :     }
     409             : #endif
     410             : 
     411             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11