1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
25 #define TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
26 
27 #include <comphelper/accessiblecomponenthelper.hxx>
28 #include <comphelper/accimplaccess.hxx>
29 #include <comphelper/uno3.hxx>
30 #include <com/sun/star/lang/XEventListener.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 
34 class Window;
35 //........................................................................
36 namespace toolkit
37 {
38 //........................................................................
39 
40 	//====================================================================
41 	//= OAccessibleControlContext
42 	//====================================================================
43 
44 	typedef	::comphelper::OAccessibleComponentHelper	OAccessibleControlContext_Base;
45 	typedef ::cppu::ImplHelper1	<	::com::sun::star::lang::XEventListener
46 								>	OAccessibleControlContext_IBase;
47 
48 	/** class implementing the AccessibleContext for an UNO control - to be used in design mode of the control.
49 		<p><b>life time control<b/><br/>
50 		This control should be held weak by the creator (an UNO control), it itself holds a hard reference to the
51 		control model, and a weak reference to the control. The reference to the model is freed when the model
52 		is beeing disposed.</p>
53 	*/
54 	class OAccessibleControlContext
55 			:public ::comphelper::OAccessibleImplementationAccess
56 			,public OAccessibleControlContext_Base
57 			,public OAccessibleControlContext_IBase
58 	{
59 	private:
60 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
61 					m_xControlModel;		// the model of the control which's context we implement
62 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
63 					m_xModelPropsInfo;		// the cached property set info of the model
64 
65 	protected:
66 		/// ctor. @see Init
67 		OAccessibleControlContext();
68 		~OAccessibleControlContext();
69 
70 		/** late ctor
71 		*/
72 		void Init(
73 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxCreator
74 		)	SAL_THROW( ( ::com::sun::star::uno::Exception ) );
75 
76 		// OCommonAccessibleComponent overridables
77 		virtual ::com::sun::star::awt::Rectangle SAL_CALL implGetBounds(  ) throw (::com::sun::star::uno::RuntimeException);
78 
79 	public:
80 		/** creates an accessible context for an uno control
81 		@param _rxCreator
82 			the uno control's XAccessible interface. This must be an XControl, from which an XControlModel
83 			can be retrieved.
84 		*/
85 		static OAccessibleControlContext* create(
86 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxCreator
87 		) SAL_THROW( ( ) );
88 
89 	protected:
90 		// XInterface
91 		DECLARE_XINTERFACE( )
92 		DECLARE_XTYPEPROVIDER( )
93 
94 		// XAccessibleContext
95 		virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
96 		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);
97 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException);
98 		virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException);
99 		virtual ::rtl::OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException);
100 		virtual ::rtl::OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException);
101 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException);
102 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException);
103 
104 		// XAccessibleComponent
105 		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);
106 		virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException);
107 		virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding(  ) throw (::com::sun::star::uno::RuntimeException);
108 		virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException);
109 		virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException);
110 
111 		// XEventListener
112         using comphelper::OAccessibleContextHelper::disposing;
113 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
114 
115 	private:
116 		// retrieves the value of a string property from the model, if the property is present
117 		::rtl::OUString	getModelStringProperty( const sal_Char* _pPropertyName ) SAL_THROW( ( ) );
118 
119 		// starts listening at the control model (currently for disposal only)
120 		void startModelListening( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
121 		// stops listening at the control model
122 		void stopModelListening( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
123 
124 		Window*	implGetWindow( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >* _pxUNOWindow = NULL ) const;
125 	};
126 
127 //........................................................................
128 }	// namespace toolkit
129 //........................................................................
130 
131 #endif // TOOLKIT_ACCESSIBLE_CONTROL_CONTEXT_HXX
132 
133