diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2011-10-04 21:37:06 -0500 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2011-10-05 18:51:33 -0500 |
commit | 3ddb5807d67c12e8ea8c9e22409f639eb6d6dfa8 (patch) | |
tree | ab2935b6b85bb99f732d6261cb7b542cbf4039e7 | |
parent | 4e1d737466d0e5474184baf06709a8f14b56ae68 (diff) |
accfixes2: accessibility API implementation for the ruler
-rw-r--r-- | svtools/AllLangResTarget_svt.mk | 1 | ||||
-rw-r--r-- | svtools/Library_svt.mk | 1 | ||||
-rw-r--r-- | svtools/inc/svtools/accessibleruler.hxx | 233 | ||||
-rw-r--r-- | svtools/inc/svtools/ruler.hxx | 5 | ||||
-rw-r--r-- | svtools/inc/svtools/svtools.hrc | 7 | ||||
-rw-r--r-- | svtools/source/control/accessibleruler.cxx | 521 | ||||
-rw-r--r-- | svtools/source/control/ruler.cxx | 53 | ||||
-rw-r--r-- | svtools/source/control/ruler.src | 40 |
8 files changed, 851 insertions, 10 deletions
diff --git a/svtools/AllLangResTarget_svt.mk b/svtools/AllLangResTarget_svt.mk index e5d0a5b1c8aa..a1627e446c9f 100644 --- a/svtools/AllLangResTarget_svt.mk +++ b/svtools/AllLangResTarget_svt.mk @@ -51,6 +51,7 @@ $(eval $(call gb_SrsTarget_add_files,svt/res,\ svtools/source/control/ctrlbox.src \ svtools/source/control/ctrltool.src \ svtools/source/control/filectrl.src \ + svtools/source/control/ruler.src \ svtools/source/dialogs/addresstemplate.src \ svtools/source/dialogs/filedlg2.src \ svtools/source/dialogs/formats.src \ diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index 19be48869b25..8e13dc70454f 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -113,6 +113,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/contnr/svtreebx \ svtools/source/contnr/templwin \ svtools/source/contnr/treelist \ + svtools/source/control/accessibleruler \ svtools/source/control/asynclink \ svtools/source/control/calendar \ svtools/source/control/collatorres \ diff --git a/svtools/inc/svtools/accessibleruler.hxx b/svtools/inc/svtools/accessibleruler.hxx new file mode 100644 index 000000000000..c2df6ce10d70 --- /dev/null +++ b/svtools/inc/svtools/accessibleruler.hxx @@ -0,0 +1,233 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SVTRULERACCESSIBLE_HXX +#define _SVTRULERACCESSIBLE_HXX + +#include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp> +#include <com/sun/star/accessibility/XAccessible.hpp> +#include <com/sun/star/accessibility/XAccessibleComponent.hpp> +#include <com/sun/star/accessibility/XAccessibleContext.hpp> +#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <comphelper/broadcasthelper.hxx> +#include <comphelper/servicehelper.hxx> +#include <cppuhelper/compbase5.hxx> +#include <cppuhelper/implbase5.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <cppuhelper/weak.hxx> + +namespace com { namespace sun { namespace star { namespace awt { + struct Point; + struct Rectangle; + struct Size; + class XFocusListener; +} } } }; + +class Rectangle; +class Ruler; +class Window; + +namespace css = com::sun::star; + +typedef ::cppu::WeakAggComponentImplHelper5< + ::css::accessibility::XAccessible, + ::css ::accessibility::XAccessibleComponent, + ::css::accessibility::XAccessibleContext, + ::css::accessibility::XAccessibleEventBroadcaster, + ::css::lang::XServiceInfo > SvtRulerAccessible_Base; + +class SvtRulerAccessible : public ::comphelper::OBaseMutex, public SvtRulerAccessible_Base +{ +public: + //===== internal ======================================================== + SvtRulerAccessible( + const ::css::uno::Reference< ::css::accessibility::XAccessible>& rxParent, Ruler& rRepresentation, const ::rtl::OUString& rName ); +protected: + virtual ~SvtRulerAccessible(); +public: + //===== XAccessible ===================================================== + + virtual ::css::uno::Reference< ::css::accessibility::XAccessibleContext> SAL_CALL getAccessibleContext( void ) throw( ::css::uno::RuntimeException ); + + //===== XAccessibleComponent ============================================ + + virtual sal_Bool SAL_CALL containsPoint( const ::css::awt::Point& rPoint ) throw( ::css::uno::RuntimeException ); + + virtual ::css::uno::Reference< ::css::accessibility::XAccessible > SAL_CALL + getAccessibleAtPoint( const ::css::awt::Point& rPoint ) throw( ::css::uno::RuntimeException ); + + virtual ::css::awt::Rectangle SAL_CALL getBounds() throw( ::css::uno::RuntimeException ); + + virtual ::css::awt::Point SAL_CALL getLocation() throw( ::css::uno::RuntimeException ); + + virtual ::css::awt::Point SAL_CALL getLocationOnScreen() throw( ::css::uno::RuntimeException ); + + virtual ::css::awt::Size SAL_CALL getSize() throw( ::css::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isShowing() throw( ::css::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isVisible() throw( ::css::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isFocusTraversable() throw( ::css::uno::RuntimeException ); + + virtual void SAL_CALL addFocusListener( + const ::css::uno::Reference< ::css::awt::XFocusListener >& xListener ) + throw( ::css::uno::RuntimeException ); + + virtual void SAL_CALL removeFocusListener( + const ::css::uno::Reference< ::css::awt::XFocusListener >& xListener ) + throw( ::css::uno::RuntimeException ); + + virtual void SAL_CALL grabFocus() throw( ::css::uno::RuntimeException ); + + virtual ::css::uno::Any SAL_CALL getAccessibleKeyBinding() throw( ::css::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL getForeground( ) throw (::css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBackground( ) throw (::css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getAccessibleChildCount( void ) throw( ::css::uno::RuntimeException ); + + virtual ::css::uno::Reference< ::css::accessibility::XAccessible> SAL_CALL getAccessibleChild( sal_Int32 nIndex ) + throw( ::css::uno::RuntimeException, ::css::lang::IndexOutOfBoundsException ); + + virtual ::css::uno::Reference< ::css::accessibility::XAccessible> SAL_CALL getAccessibleParent( void ) throw( ::css::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( void ) throw( ::css::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL getAccessibleRole( void ) throw( ::css::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL getAccessibleDescription( void ) throw (::css::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL getAccessibleName( void ) throw (::css::uno::RuntimeException); + + virtual ::css::uno::Reference< ::css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( void ) + throw( ::css::uno::RuntimeException ); + + virtual ::css::uno::Reference< ::css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( void ) + throw( ::css::uno::RuntimeException ); + + virtual ::css::lang::Locale SAL_CALL getLocale( void ) + throw( ::css::uno::RuntimeException, + ::css::accessibility::IllegalAccessibleComponentStateException ); + //===== XAccessibleEventBroadcaster ===================================== + virtual void SAL_CALL addEventListener( const ::css::uno::Reference< ::css::accessibility::XAccessibleEventListener >& xListener ) + throw( css::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( const ::css::uno::Reference< ::css::accessibility::XAccessibleEventListener >& xListener ) + throw( ::css::uno::RuntimeException ); + + // Needed, because some compilers would complain about virtual functions above would hide + // cppu::WeakAggComponentImplHelperBase::add/removeEventListener(const Reference<lang::XEventListener>&)... + virtual void SAL_CALL addEventListener( const ::css::uno::Reference< ::css::lang::XEventListener >& xListener ) + throw( ::css::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( const ::css::uno::Reference< ::css::lang::XEventListener >& xListener ) + throw( ::css::uno::RuntimeException ); + + //===== XServiceInfo ==================================================== + + virtual ::rtl::OUString SAL_CALL getImplementationName( void ) throw( ::css::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw( ::css::uno::RuntimeException ); + + virtual ::css::uno::Sequence< ::rtl::OUString> SAL_CALL + getSupportedServiceNames( void ) throw( ::css::uno::RuntimeException ); + + //===== XTypeProvider =================================================== + + virtual ::css::uno::Sequence<sal_Int8> SAL_CALL + getImplementationId( void ) throw( ::css::uno::RuntimeException ); + +public: + + /// Sets the name + void setName( const ::rtl::OUString& rName ); + + /// Sets the description + void setDescription( const ::rtl::OUString& rDescr ); +private: + static ::css::uno::Sequence< sal_Int8 > getUniqueId( void ); + +protected: + /// @Return the object's current bounding box relative to the desktop. + virtual Rectangle GetBoundingBoxOnScreen( void ) throw( ::css::uno::RuntimeException ); + + /// @Return the object's current bounding box relative to the parent object. + virtual Rectangle GetBoundingBox( void ) throw( ::css::uno::RuntimeException ); + + + virtual void SAL_CALL disposing(); + + /// @returns true if it's disposed or in disposing + inline bool IsAlive( void ) const; + + /// @returns true if it's not disposed and no in disposing + inline bool IsNotAlive( void ) const; + + /// throws the exception DisposedException if it's not alive + void ThrowExceptionIfNotAlive( void ) throw( ::css::lang::DisposedException ); + +private: + /** Description of this object. This is not a constant because it can + be set from the outside. + */ + ::rtl::OUString msDescription; + + /** Name of this object. + */ + ::rtl::OUString msName; + + /// Reference to the parent object. + ::css::uno::Reference< ::css::accessibility::XAccessible > mxParent; + + /// pointer to internal representation + Ruler* mpRepr; + + /// client id in the AccessibleEventNotifier queue + sal_uInt32 mnClientId; + +}; + +inline bool SvtRulerAccessible::IsAlive( void ) const +{ + return !rBHelper.bDisposed && !rBHelper.bInDispose; +} + +inline bool SvtRulerAccessible::IsNotAlive( void ) const +{ + return rBHelper.bDisposed || rBHelper.bInDispose; +} + +#endif + diff --git a/svtools/inc/svtools/ruler.hxx b/svtools/inc/svtools/ruler.hxx index ba04f9342525..57688deca2c2 100644 --- a/svtools/inc/svtools/ruler.hxx +++ b/svtools/inc/svtools/ruler.hxx @@ -34,6 +34,7 @@ #include <vcl/window.hxx> #include <vcl/virdev.hxx> #include <vcl/field.hxx> +#include <svtools/accessibleruler.hxx> class MouseEvent; class TrackingEvent; @@ -691,6 +692,7 @@ private: Link maClickHdl; Link maDoubleClickHdl; Link maExtraDownHdl; + SvtRulerAccessible* m_pAccContext; #ifdef _SV_RULER_CXX SVT_DLLPRIVATE void ImplVDrawLine( long nX1, long nY1, long nX2, long nY2 ); @@ -856,6 +858,9 @@ public: void SetLineHeight( long nHeight ) { mnLineHeight = nHeight ; } void DrawTicks(); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); + }; #endif // _RULER_HXX diff --git a/svtools/inc/svtools/svtools.hrc b/svtools/inc/svtools/svtools.hrc index c6e05f2ad5d3..0992dbae1689 100644 --- a/svtools/inc/svtools/svtools.hrc +++ b/svtools/inc/svtools/svtools.hrc @@ -251,10 +251,9 @@ #define STR_SVT_ACC_DESC_FILE (STR_SVT_ACC_BEGIN+5) #define STR_SVT_ACC_EMPTY_FIELD (STR_SVT_ACC_BEGIN+6) //IAccessible2 implementation -#define STR_SVT_ACC_LISTENTRY_SELCTED_STATE (STR_SVT_ACC_BEGIN+7) -#define STR_SVT_ACC_RULER_VERT_NAME (STR_SVT_ACC_BEGIN+8) -#define STR_SVT_ACC_RULER_HORZ_NAME (STR_SVT_ACC_BEGIN+9) -#define STR_SVT_ACC_END (STR_SVT_ACC_EMPTY_FIELD) +#define STR_SVT_ACC_RULER_VERT_NAME (STR_SVT_ACC_BEGIN+7) +#define STR_SVT_ACC_RULER_HORZ_NAME (STR_SVT_ACC_BEGIN+8) +#define STR_SVT_ACC_END (STR_SVT_ACC_RULER_HORZ_NAME) #define STR_SVT_INDEXENTRY_START (STR_SVT_ACC_END + 1) #define STR_SVT_INDEXENTRY_ALPHANUMERIC (STR_SVT_INDEXENTRY_START+0) diff --git a/svtools/source/control/accessibleruler.cxx b/svtools/source/control/accessibleruler.cxx new file mode 100644 index 000000000000..2e6fab9690d4 --- /dev/null +++ b/svtools/source/control/accessibleruler.cxx @@ -0,0 +1,521 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <com/sun/star/accessibility/AccessibleEventId.hpp> +#include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/accessibility/AccessibleStateType.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#include <comphelper/accessibleeventnotifier.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <osl/mutex.hxx> +#include <rtl/uuid.h> +#include <svtools/accessibleruler.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <tools/debug.hxx> +#include <tools/gen.hxx> +#include <unotools/accessiblestatesethelper.hxx> +#include <vcl/svapp.hxx> + +#include "ruler.hxx" + +using namespace ::cppu; +using namespace ::osl; +using namespace ::rtl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::accessibility; + +DBG_NAME( SvtRulerAccessible ) + + +//===== internal ============================================================ + +SvtRulerAccessible::SvtRulerAccessible( + const uno::Reference< XAccessible >& rxParent, Ruler& rRepr, const OUString& rName ) : + +SvtRulerAccessible_Base( m_aMutex ), + msName( rName ), + mxParent( rxParent ), + mpRepr( &rRepr ), + mnClientId( 0 ) +{ + DBG_CTOR( SvtRulerAccessible, NULL ); +} + +SvtRulerAccessible::~SvtRulerAccessible() +{ + DBG_DTOR( SvtRulerAccessible, NULL ); + + if( IsAlive() ) + { + osl_incrementInterlockedCount( &m_refCount ); + dispose(); // set mpRepr = NULL & release all childs + } +} + +//===== XAccessible ========================================================= + +uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext( void ) throw( RuntimeException ) +{ + return this; +} + +//===== XAccessibleComponent ================================================ + +sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) throw( RuntimeException ) +{ + return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) ); +} + +uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + uno::Reference< XAccessible > xRet; + + + return xRet; +} + +awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds() throw( RuntimeException ) +{ + // no guard -> done in GetBoundingBox() + return AWTRectangle( GetBoundingBox() ); +} + +awt::Point SAL_CALL SvtRulerAccessible::getLocation() throw( RuntimeException ) +{ + // no guard -> done in GetBoundingBox() + return AWTPoint( GetBoundingBox().TopLeft() ); +} + +awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen() throw( RuntimeException ) +{ + // no guard -> done in GetBoundingBoxOnScreen() + return AWTPoint( GetBoundingBoxOnScreen().TopLeft() ); +} + +awt::Size SAL_CALL SvtRulerAccessible::getSize() throw( RuntimeException ) +{ + // no guard -> done in GetBoundingBox() + return AWTSize( GetBoundingBox().GetSize() ); +} + +sal_Bool SAL_CALL SvtRulerAccessible::isShowing() throw( RuntimeException ) +{ + return sal_True; +} + +sal_Bool SAL_CALL SvtRulerAccessible::isVisible() throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + return mpRepr->IsVisible(); +} + +sal_Bool SAL_CALL SvtRulerAccessible::isFocusTraversable() throw( RuntimeException ) +{ + return sal_True; +} + +//===== XAccessibleContext ================================================== + +sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleChildCount( void ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + return 0; +} + +uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int32 ) + throw( RuntimeException, lang::IndexOutOfBoundsException ) +{ + uno::Reference< XAccessible > xChild ; + + return xChild; +} + +uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent( void ) throw( RuntimeException ) +{ + return mxParent; +} + +sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent( void ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + // Use a simple but slow solution for now. Optimize later. + + // Iterate over all the parent's children and search for this object. + if( mxParent.is() ) + { + uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() ); + if( xParentContext.is() ) + { + sal_Int32 nChildCount = xParentContext->getAccessibleChildCount(); + for( sal_Int32 i = 0 ; i < nChildCount ; ++i ) + { + uno::Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) ); + if( xChild.get() == ( XAccessible* ) this ) + { + return i; + } + } + } + } + + // Return -1 to indicate that this object's parent does not know about the + // object. + return -1; +} + +sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole( void ) throw( RuntimeException ) +{ + return AccessibleRole::RULER; +} + +OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription( void ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return msDescription; +} + +OUString SAL_CALL SvtRulerAccessible::getAccessibleName( void ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return msName; +} + +/** Return empty uno::Reference to indicate that the relation set is not + supported. +*/ +uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet( void ) throw( RuntimeException ) +{ + return uno::Reference< XAccessibleRelationSet >(); +} + +uno::Reference< XAccessibleStateSet > SAL_CALL SvtRulerAccessible::getAccessibleStateSet( void ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; + + if( IsAlive() ) + { + pStateSetHelper->AddState( AccessibleStateType::ENABLED ); + + if( isShowing() ) + { + pStateSetHelper->AddState( AccessibleStateType::SHOWING ); + } + if( isVisible() ) + { + pStateSetHelper->AddState( AccessibleStateType::VISIBLE ); + } + + if ( mpRepr ) + { + if ( mpRepr->GetStyle() & WB_HORZ ) + { + pStateSetHelper->AddState( AccessibleStateType::HORIZONTAL ); + } + else + { + pStateSetHelper->AddState( AccessibleStateType::VERTICAL ); + } + } + if(pStateSetHelper->contains(AccessibleStateType::FOCUSABLE)) + { + pStateSetHelper->RemoveState( AccessibleStateType::FOCUSABLE ); + } + + } + + + return pStateSetHelper; +} + +lang::Locale SAL_CALL SvtRulerAccessible::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if( mxParent.is() ) + { + uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() ); + if( xParentContext.is() ) + { + return xParentContext->getLocale(); + } + } + + // No parent. Therefore throw exception to indicate this cluelessness. + throw IllegalAccessibleComponentStateException(); +} + +void SAL_CALL SvtRulerAccessible::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) + throw( RuntimeException ) +{ + if (xListener.is()) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (!mnClientId) + { + mnClientId = comphelper::AccessibleEventNotifier::registerClient( ); + } + comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener ); + } +} + +void SAL_CALL SvtRulerAccessible::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) + throw( RuntimeException ) +{ + if (xListener.is()) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener ); + if ( !nListenerCount ) + { + // no listeners anymore + // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), + // and at least to us not firing any events anymore, in case somebody calls + // NotifyAccessibleEvent, again + comphelper::AccessibleEventNotifier::revokeClient( mnClientId ); + mnClientId = 0; + } + } +} + +void SAL_CALL SvtRulerAccessible::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw( RuntimeException ) +{ + if( xListener.is() ) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + uno::Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpRepr ); + if( xWindow.is() ) + { + xWindow->addFocusListener( xListener ); + } + } +} +void SAL_CALL SvtRulerAccessible::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (RuntimeException) +{ + if( xListener.is() ) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + uno::Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpRepr ); + if( xWindow.is() ) + { + xWindow->removeFocusListener( xListener ); + } + } +} + +void SAL_CALL SvtRulerAccessible::grabFocus() throw( RuntimeException ) +{ + SolarMutexGuard aSolarGuard; + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + mpRepr->GrabFocus(); +} + +Any SAL_CALL SvtRulerAccessible::getAccessibleKeyBinding() throw( RuntimeException ) +{ + // here is no implementation, because here are no KeyBindings for every object + return Any(); +} + +sal_Int32 SvtRulerAccessible::getForeground( ) + throw (::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aSolarGuard; + ::osl::MutexGuard aGuard( m_aMutex ); + ThrowExceptionIfNotAlive(); + + return mpRepr->GetControlForeground().GetColor(); +} +sal_Int32 SvtRulerAccessible::getBackground( ) + throw (::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aSolarGuard; + ::osl::MutexGuard aGuard( m_aMutex ); + ThrowExceptionIfNotAlive(); + + return mpRepr->GetControlBackground().GetColor(); +} + +//===== XServiceInfo ======================================================== + +OUString SAL_CALL SvtRulerAccessible::getImplementationName( void ) throw( RuntimeException ) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.SvtRulerAccessible" ) ); +} + +sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName ) throw( RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + // Iterate over all supported service names and return true if on of them + // matches the given name. + Sequence< OUString > aSupportedServices( getSupportedServiceNames() ); + int nLength = aSupportedServices.getLength(); + const OUString* pStr = aSupportedServices.getConstArray(); + + for( int i = nLength ; i ; --i, ++pStr ) + { + if( sServiceName == *pStr ) + { + return sal_True; + } + } + + return sal_False; +} + +Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames( void ) throw( RuntimeException ) +{ + const OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) ); + return Sequence< OUString >( &sServiceName, 1 ); +} + +//===== XTypeProvider ======================================================= + +Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId( void ) throw( RuntimeException ) +{ + return getUniqueId(); +} + + +//===== internals ======================================================== + +void SvtRulerAccessible::setName( const OUString& rName ) +{ + msName = rName; + +} +void SvtRulerAccessible::setDescription( const OUString& rDescr ) +{ + msDescription = rDescr; +} + + + +void SAL_CALL SvtRulerAccessible::disposing() +{ + if( !rBHelper.bDisposed ) + { + { + ::osl::MutexGuard aGuard( m_aMutex ); + mpRepr = NULL; // object dies with representation + } + + { + ::osl::MutexGuard aGuard( m_aMutex ); + + // Send a disposing to all listeners. + if ( mnClientId ) + { + comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this ); + mnClientId = 0; + } + mxParent = uno::Reference< XAccessible >(); + } + } +} + +Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen( void ) throw( RuntimeException ) +{ + SolarMutexGuard aSolarGuard; + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + return Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() ); +} + +Rectangle SvtRulerAccessible::GetBoundingBox( void ) throw( RuntimeException ) +{ + SolarMutexGuard aSolarGuard; + ::osl::MutexGuard aGuard( m_aMutex ); + + ThrowExceptionIfNotAlive(); + + return Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() ); +} + +Sequence< sal_Int8 > SvtRulerAccessible::getUniqueId( void ) +{ + static OImplementationId* pId = 0; + if( !pId ) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if( !pId) + { + static OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); +} + +void SvtRulerAccessible::ThrowExceptionIfNotAlive( void ) throw( lang::DisposedException ) +{ + if( IsNotAlive() ) + { + throw lang::DisposedException(); + } +} + +void SvtRulerAccessible::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw( com::sun::star::uno::RuntimeException ) +{ + cppu::WeakAggComponentImplHelperBase::addEventListener( xListener ); +} + +void SvtRulerAccessible::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw( com::sun::star::uno::RuntimeException ) +{ + cppu::WeakAggComponentImplHelperBase::removeEventListener( xListener ); +} + diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx index b3ae722a4555..73235d8d21b5 100644 --- a/svtools/source/control/ruler.cxx +++ b/svtools/source/control/ruler.cxx @@ -35,6 +35,15 @@ #include <tools/poly.hxx> #include <vcl/i18nhelp.hxx> +#include <svtools/svtdata.hxx> +#include <svtools/svtools.hrc> +using namespace ::rtl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::accessibility; + + #define _SV_RULER_CXX #include <svtools/ruler.hxx> @@ -314,6 +323,7 @@ void Ruler::ImplInit( WinBits nWinBits ) aDefSize.Width() = nDefHeight; SetOutputSizePixel( aDefSize ); SetType(WINDOW_RULER); + m_pAccContext = NULL; } // ----------------------------------------------------------------------- @@ -337,6 +347,10 @@ Ruler::~Ruler() Application::RemoveUserEvent( mnUpdateEvtId ); delete mpSaveData; delete mpDragData; + if(m_pAccContext) + { + m_pAccContext->release(); + } } // ----------------------------------------------------------------------- @@ -3217,19 +3231,46 @@ long Ruler::GetPageOffset() const { return mpData->nPageOff; } long Ruler::GetPageWidth() const { return mpData->nPageWidth; } long Ruler::GetNullOffset() const { return mpData->nNullOff; } long Ruler::GetMargin1() const { return mpData->nMargin1; } -sal_uInt16 Ruler::GetMargin1Style() const { return mpData->nMargin1Style; } +sal_uInt16 Ruler::GetMargin1Style() const { return mpData->nMargin1Style; } long Ruler::GetMargin2() const { return mpData->nMargin2; } -sal_uInt16 Ruler::GetMargin2Style() const { return mpData->nMargin2Style; } -sal_uInt16 Ruler::GetLineCount() const { return mpData->nLines; } +sal_uInt16 Ruler::GetMargin2Style() const { return mpData->nMargin2Style; } +sal_uInt16 Ruler::GetLineCount() const { return mpData->nLines; } const RulerLine* Ruler::GetLines() const { return mpData->pLines; } -sal_uInt16 Ruler::GetArrowCount() const { return mpData->nArrows; } +sal_uInt16 Ruler::GetArrowCount() const { return mpData->nArrows; } const RulerArrow* Ruler::GetArrows() const { return mpData->pArrows; } -sal_uInt16 Ruler::GetBorderCount() const { return mpData->nBorders; } +sal_uInt16 Ruler::GetBorderCount() const { return mpData->nBorders; } const RulerBorder* Ruler::GetBorders() const { return mpData->pBorders; } -sal_uInt16 Ruler::GetIndentCount() const { return mpData->nIndents; } +sal_uInt16 Ruler::GetIndentCount() const { return mpData->nIndents; } const RulerIndent* Ruler::GetIndents() const { return mpData->pIndents; } +uno::Reference< XAccessible > Ruler::CreateAccessible() +{ + Window* pParent = GetAccessibleParentWindow(); + DBG_ASSERT( pParent, "-SvxRuler::CreateAccessible(): No Parent!" ); + uno::Reference< XAccessible > xAccParent = pParent->GetAccessible(); + if( xAccParent.is() ) + { + OUString aStr; + if ( mnWinStyle & WB_HORZ ) + { + aStr = OUString(XubString(SvtResId(STR_SVT_ACC_RULER_HORZ_NAME))); + } + else + { + aStr = OUString(XubString(SvtResId(STR_SVT_ACC_RULER_VERT_NAME))); + } + m_pAccContext = new SvtRulerAccessible( xAccParent, *this, aStr ); + m_pAccContext->acquire(); + this->SetAccessible(m_pAccContext); + return m_pAccContext; + } + else + { + return uno::Reference< XAccessible >(); + } +} + void Ruler::DrawTicks() { mbFormat = sal_True; diff --git a/svtools/source/control/ruler.src b/svtools/source/control/ruler.src new file mode 100644 index 000000000000..c064e0e79685 --- /dev/null +++ b/svtools/source/control/ruler.src @@ -0,0 +1,40 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "svtools/svtools.hrc" + +String STR_SVT_ACC_RULER_HORZ_NAME +{ + Text[ en-US ] = "Horizontal Ruler"; +}; +String STR_SVT_ACC_RULER_VERT_NAME +{ + Text[ en-US ] = "Vertical Ruler"; +}; + + |