1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_ACCESSIBLECONTROLSHAPE_HXX
21 #define INCLUDED_SVX_ACCESSIBLECONTROLSHAPE_HXX
25 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
26 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
27 #include <com/sun/star/container/XContainerListener.hpp>
28 #include <com/sun/star/lang/EventObject.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/RuntimeException.hpp>
32 #include <com/sun/star/util/XModeChangeListener.hpp>
33 #include <comphelper/uno3.hxx>
34 #include <cppuhelper/implbase4.hxx>
35 #include <cppuhelper/weakref.hxx>
36 #include <rtl/ref.hxx>
37 #include <rtl/ustring.hxx>
38 #include <sal/types.h>
39 #include <svx/AccessibleShape.hxx>
41 namespace com
{ namespace sun
{ namespace star
{
42 namespace accessibility
{ class XAccessible
; }
43 namespace accessibility
{ class XAccessibleContext
; }
44 namespace accessibility
{ struct AccessibleEventObject
; }
45 namespace accessibility
{ class XAccessibleRelationSet
; }
46 namespace awt
{ class XControl
; }
47 namespace beans
{ class XPropertySet
; }
48 namespace beans
{ class XPropertySetInfo
; }
49 namespace beans
{ struct PropertyChangeEvent
; }
50 namespace container
{ struct ContainerEvent
; }
51 namespace lang
{ class XComponent
; }
52 namespace lang
{ class XTypeProvider
; }
53 namespace uno
{ class XAggregation
; }
54 namespace util
{ struct ModeChangeEvent
; }
59 class OWrappedAccessibleChildrenManager
;
63 namespace accessibility
{
65 class AccessibleShapeInfo
;
66 class AccessibleShapeTreeInfo
;
68 typedef ::cppu::ImplHelper4
< css::beans::XPropertyChangeListener
69 , css::util::XModeChangeListener
70 , css::container::XContainerListener
71 , css::accessibility::XAccessibleEventListener
72 > AccessibleControlShape_Base
;
75 class AccessibleControlShape
76 :public AccessibleShape
77 ,public AccessibleControlShape_Base
80 //===== internal ========================================================
81 AccessibleControlShape(
82 const AccessibleShapeInfo
& rShapeInfo
,
83 const AccessibleShapeTreeInfo
& rShapeTreeInfo
);
84 virtual ~AccessibleControlShape( ) override
;
86 const css::uno::Reference
< css::beans::XPropertySet
>& SAL_CALL
GetControlModel( ) { return m_xControlModel
;} ;
87 AccessibleControlShape
* SAL_CALL
GetLabeledByControlShape();
90 //--- XAccessibleComponent -------------------------------
91 /// forward the focus to the contained control(in alive mode)
92 virtual void SAL_CALL
grabFocus( ) override
;
94 //--- XAccessibleContext ---------------------------------
95 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) override
;
96 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) override
;
97 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) override
;
99 //--- XServiceInfo ---------------------------------------
100 virtual OUString SAL_CALL
getImplementationName( ) override
;
102 //--- XInterface -----------------------------------------
103 DECLARE_XINTERFACE( )
105 //--- XTypeProvider --------------------------------------
106 DECLARE_XTYPEPROVIDER( )
108 //--- XPropertyChangeListener ----------------------------
109 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& _rEvent
) override
;
111 //--- XComponent -----------------------------------------
112 virtual void SAL_CALL
disposing( ) override
;
114 //--- XEventListener -------------------------------------
115 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) override
;
117 //--- XModeChangeListener --------------------------------
118 virtual void SAL_CALL
modeChanged( const css::util::ModeChangeEvent
& _rSource
) override
;
120 //--- XAccessibleEventListener ----------------------------
121 virtual void SAL_CALL
notifyEvent( const css::accessibility::AccessibleEventObject
& aEvent
) override
;
123 //--- document::XEventListener ----------------------------
124 using AccessibleShape::notifyEvent
;
126 // XVclContainerListener
127 virtual void SAL_CALL
elementInserted( const css::container::ContainerEvent
& Event
) override
;
128 virtual void SAL_CALL
elementRemoved( const css::container::ContainerEvent
& Event
) override
;
129 virtual void SAL_CALL
elementReplaced( const css::container::ContainerEvent
& Event
) override
;
132 /** Initialize a new shape. See the documentation of the base' constructor
133 for the reason of this method's existence.
135 virtual void Init( ) override
;
137 /// Create a name string that contains the accessible name.
139 CreateAccessibleBaseName( ) override
;
141 /** Create a unique name string that contains the accessible name. The
142 name consists of the base name and the index.
145 CreateAccessibleName( ) override
;
147 /// Create a description string that contains the accessible description.
149 CreateAccessibleDescription( ) override
;
152 /// Set the specified state
153 virtual bool SetState( sal_Int16 _nState
) override
;
156 /// (safely) reads the given property from the model of the UNO control
157 OUString
getControlModelStringProperty( const OUString
& _rPropertyName
) const;
159 /// ensure that our control model exists(will be retrieved upon need only)
160 bool ensureControlModelAccess( );
162 /// ensures that we're listening for the given property if(and only if!) necessary
163 bool ensureListeningState( const bool _bCurrentlyListening
, const bool _bNeedNewListening
,
164 const OUString
& _rPropertyName
);
166 /// starts multiplexing the state changes of our aggregate context
167 void startStateMultiplexing( );
168 /// stops multiplexing the state changes of our aggregate context
169 void stopStateMultiplexing( );
171 /** adjusts our AccessibleRole, depending on the control type we're working for
173 <p>Only to be called during initialization</p>
175 void adjustAccessibleRole( );
177 /** initializes composed states of the context
179 <p>Some of the states of our inner context need to be propagated to the "composed context", too
180 (such as "checked" for check boxes). At lifetime, this is done by multiplexing state changes,
181 at initialization time, this method is used.</p>
183 void initializeComposedState( );
186 css::uno::Reference
< css::beans::XPropertySet
>
188 css::uno::Reference
< css::beans::XPropertySetInfo
>
189 m_xModelPropsMeta
; // cache this for performance reasons
190 css::uno::Reference
< css::awt::XControl
>
191 m_xUnoControl
; // our UNO control
193 css::uno::WeakReference
< css::accessibility::XAccessibleContext
>
194 m_aControlContext
; // the AccessibleContext of the control
195 css::uno::Reference
< css::uno::XAggregation
>
196 m_xControlContextProxy
; // the proxy for "aggregating" the AccessibleContext of the control
197 css::uno::Reference
< css::lang::XTypeProvider
>
198 m_xControlContextTypeAccess
; // cached interface of our aggregate
199 css::uno::Reference
< css::lang::XComponent
>
200 m_xControlContextComponent
; // cached interface of our aggregate
202 rtl::Reference
<::comphelper::OWrappedAccessibleChildrenManager
>
205 bool m_bListeningForName
: 1; // are we currently listening for changes of the "Name" property?
206 bool m_bListeningForDesc
: 1; // are we currently listening for changes of the "HelpText" property?
207 bool m_bMultiplexingStates
: 1; // are we currently multiplexing state changes of the native context?
208 bool m_bDisposeNativeContext
: 1; // do we need to dispose mxNativeContextComponent?
209 bool m_bWaitingForControl
: 1; // if we are created before our control exists, we need to wait for it to appear ...
212 AccessibleControlShape(const AccessibleControlShape
&) = delete;
214 AccessibleControlShape
& operator= (const AccessibleControlShape
&) = delete;
217 } // end of namespace accessibility
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */