1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
29 #define TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
30 
31 #include <comphelper/accessiblecomponenthelper.hxx>
32 #include <comphelper/accimplaccess.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <com/sun/star/lang/XEventListener.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/awt/XWindow.hpp>
37 
38 class Window;
39 //........................................................................
40 namespace toolkit
41 {
42 //........................................................................
43 
44 	//====================================================================
45 	//= OAccessibleControlContext
46 	//====================================================================
47 
48 	typedef	::comphelper::OAccessibleComponentHelper	OAccessibleControlContext_Base;
49 	typedef ::cppu::ImplHelper1	<	::com::sun::star::lang::XEventListener
50 								>	OAccessibleControlContext_IBase;
51 
52 	/** class implementing the AccessibleContext for an UNO control - to be used in design mode of the control.
53 		<p><b>life time control<b/><br/>
54 		This control should be held weak by the creator (an UNO control), it itself holds a hard reference to the
55 		control model, and a weak reference to the control. The reference to the model is freed when the model
56 		is beeing disposed.</p>
57 	*/
58 	class OAccessibleControlContext
59 			:public ::comphelper::OAccessibleImplementationAccess
60 			,public OAccessibleControlContext_Base
61 			,public OAccessibleControlContext_IBase
62 	{
63 	private:
64 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
65 					m_xControlModel;		// the model of the control which's context we implement
66 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
67 					m_xModelPropsInfo;		// the cached property set info of the model
68 
69 	protected:
70 		/// ctor. @see Init
71 		OAccessibleControlContext();
72 		~OAccessibleControlContext();
73 
74 		/** late ctor
75 		*/
76 		void Init(
77 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxCreator
78 		)	SAL_THROW( ( ::com::sun::star::uno::Exception ) );
79 
80 		// OCommonAccessibleComponent overridables
81 		virtual ::com::sun::star::awt::Rectangle SAL_CALL implGetBounds(  ) throw (::com::sun::star::uno::RuntimeException);
82 
83 	public:
84 		/** creates an accessible context for an uno control
85 		@param _rxCreator
86 			the uno control's XAccessible interface. This must be an XControl, from which an XControlModel
87 			can be retrieved.
88 		*/
89 		static OAccessibleControlContext* create(
90 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxCreator
91 		) SAL_THROW( ( ) );
92 
93 	protected:
94 		// XInterface
95 		DECLARE_XINTERFACE( )
96 		DECLARE_XTYPEPROVIDER( )
97 
98 		// XAccessibleContext
99 		virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
100 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
101 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException);
102 		virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException);
103 		virtual ::rtl::OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException);
104 		virtual ::rtl::OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException);
105 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException);
106 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException);
107 
108 		// XAccessibleComponent
109 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
110 		virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException);
111 		virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding(  ) throw (::com::sun::star::uno::RuntimeException);
112 		virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException);
113 		virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException);
114 
115 		// XEventListener
116         using comphelper::OAccessibleContextHelper::disposing;
117 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
118 
119 	private:
120 		// retrieves the value of a string property from the model, if the property is present
121 		::rtl::OUString	getModelStringProperty( const sal_Char* _pPropertyName ) SAL_THROW( ( ) );
122 
123 		// starts listening at the control model (currently for disposal only)
124 		void startModelListening( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
125 		// stops listening at the control model
126 		void stopModelListening( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
127 
128 		Window*	implGetWindow( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >* _pxUNOWindow = NULL ) const;
129 	};
130 
131 //........................................................................
132 }	// namespace toolkit
133 //........................................................................
134 
135 #endif // TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
136 
137