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 COMPHELPER_ACCIMPLACCESS_HXX
29 #define COMPHELPER_ACCIMPLACCESS_HXX
30 
31 #include <cppuhelper/implbase1.hxx>
32 #include <com/sun/star/lang/XUnoTunnel.hpp>
33 #include "comphelper/comphelperdllapi.h"
34 
35 // forward declaration
36 namespace com { namespace sun { namespace star { namespace accessibility {
37 	class XAccessible;
38 	class XAccessibleContext;
39 }}}}
40 
41 //.........................................................................
42 namespace comphelper
43 {
44 //.........................................................................
45 
46 	//=====================================================================
47 	//= OAccessibleImplementationAccess
48 	//=====================================================================
49 	typedef	::cppu::ImplHelper1	<	::com::sun::star::lang::XUnoTunnel
50 								>	OAccImpl_Base;
51 	struct OAccImpl_Impl;
52 
53 	/** This is a helper class which allows accessing several aspects of the the implementation
54 		of an AccessibleContext.
55 
56 		<p>For instance, when you want to implement a context which can be re-parented, you:
57 			<ul><li>derive your class from <type>OAccessibleImplementationAccess</type></li>
58 				<li>use <code>setAccessibleParent( <em>component</em>, <em>new_parent</em> )</code>
59 			</ul>
60 		</p>
61 
62 		<p>Another aspect which can be controlled from the outside are states. If you have a class which
63 		has only partial control over it's states, you may consider deriving from OAccessibleImplementationAccess.<br/>
64 		For instance, say you have an implementation (say component A) which is <em>unable</em> to know or to
65 		determine if the represented object is selected, but another component (say B) which uses A (and integrates
66 		it into a tree of accessibility components) is.<br/>
67 		In this case, if A is derived from OAccessibleImplementationAccess, B can manipulate this
68 		foreign-controlled state flag "SELECTED" by using the static helper methods on this class.</p>
69 
70 		<p>Please note that the support for foreign controlled states is rather restrictive: You can't have states
71 		which <em>may be</em> controlled by a foreign instances. This is implied by the fact that a derived
72 		class can ask for states which are <em>set</em> only, not for the ones which are <em>reset</em> currently.
73 		</p>
74 	*/
75 	class COMPHELPER_DLLPUBLIC OAccessibleImplementationAccess : public OAccImpl_Base
76 	{
77 	private:
78 		OAccImpl_Impl*	m_pImpl;
79 
80 	protected:
81 		/// retrieves the parent previously set via <method>setAccessibleParent</method>
82 		::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
83 				implGetForeignControlledParent( ) const;
84 
85 		/** retrieves the set of currently set states which are controlled by a foreign instance
86 		@return
87 			a bit mask, where a set bit 2^n means that the AccessibleStateType n has been set
88 		*/
89 		sal_Int64	implGetForeignControlledStates( ) const;
90 
91 		/// sets the accessible parent component
92 		virtual	void	setAccessibleParent(
93 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxAccParent );
94 
95 		/// sets or resets a bit of the foreign controlled states
96 		virtual	void	setStateBit( const sal_Int16 _nState, const sal_Bool _bSet );
97 
98 	protected:
99 		OAccessibleImplementationAccess( );
100 		virtual ~OAccessibleImplementationAccess( );
101 
102 		// XUnoTunnel
103 		virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rIdentifier ) throw (::com::sun::star::uno::RuntimeException);
104 
105 	public:
106 		/** tries to access the implementation of an OAccessibleImplementationAccess derivee which is known as
107 			interface only.
108 
109 		@param _rxComponent
110 			is the component which should be examined.
111 		@return
112 			the pointer to the implementation, if successfull. The only known error condition so far
113 			is an invalid context (which means it is <NULL/>, or the implementation is not derived
114 			from <type>OAccessibleImplementationAccess</type>, or retrieving the implementation failed).
115 		*/
116 		static OAccessibleImplementationAccess* getImplementation(
117 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent
118 		);
119 
120 
121 		/** sets the parent for a derived implementation
122 
123 		@param _rxComponent
124 			is the component which's new parent should be set
125 		@param _rxNewParent
126 			is the new parent of the component
127 		@return
128 			<TRUE/> in case of success, <FALSE/> otherwise. For error condition please look at
129 			<method>getImplementation</method>.
130 		*/
131 		static sal_Bool	setAccessibleParent(
132 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent,
133 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxNewParent
134 		);
135 
136 		/** sets or resets a state bit in the set of foreign-controlled states of the component.
137 
138 		@param _rxComponent
139 			is the component which's state is to be (re)set
140 		@param _nState
141 			the state bit which should be affected. This should be one of the respective UNO constants.
142 		@param _bSet
143 			<TRUE/> if the bit should be set, <FALSE/> otherwise
144 		@return
145 			<TRUE/> in case of success, <FALSE/> otherwise. For error condition please look at
146 			<method>getImplementation</method>.
147 		*/
148 		static sal_Bool	setForeignControlledState(
149 			const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxComponent,
150 			const sal_Int16 _nState,
151 			const sal_Bool	_bSet
152 		);
153 
154 
155 	private:
156 		COMPHELPER_DLLPRIVATE static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelImplementationId();
157 	};
158 
159 //.........................................................................
160 }	// namespace comphelper
161 //.........................................................................
162 
163 
164 #endif // COMPHELPER_ACCIMPLACCESS_HXX
165 
166 
167