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

Generated by: LCOV version 1.10