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
23 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
24 #include <com/sun/star/container/XContainerListener.hpp>
25 #include <com/sun/star/lang/EventObject.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/util/XModeChangeListener.hpp>
28 #include <comphelper/uno3.hxx>
29 #include <cppuhelper/implbase4.hxx>
30 #include <cppuhelper/weakref.hxx>
31 #include <rtl/ref.hxx>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <svx/AccessibleShape.hxx>
36 namespace com
{ namespace sun
{ namespace star
{
37 namespace accessibility
{ class XAccessible
; }
38 namespace accessibility
{ class XAccessibleContext
; }
39 namespace accessibility
{ struct AccessibleEventObject
; }
40 namespace accessibility
{ class XAccessibleRelationSet
; }
41 namespace awt
{ class XControl
; }
42 namespace beans
{ class XPropertySet
; }
43 namespace beans
{ class XPropertySetInfo
; }
44 namespace beans
{ struct PropertyChangeEvent
; }
45 namespace container
{ struct ContainerEvent
; }
46 namespace lang
{ class XComponent
; }
47 namespace lang
{ class XTypeProvider
; }
48 namespace uno
{ class XAggregation
; }
49 namespace util
{ struct ModeChangeEvent
; }
54 class OWrappedAccessibleChildrenManager
;
57 namespace accessibility
{
59 class AccessibleShapeInfo
;
60 class AccessibleShapeTreeInfo
;
62 typedef ::cppu::ImplHelper4
< css::beans::XPropertyChangeListener
63 , css::util::XModeChangeListener
64 , css::container::XContainerListener
65 , css::accessibility::XAccessibleEventListener
66 > AccessibleControlShape_Base
;
69 class SAL_DLLPUBLIC_RTTI AccessibleControlShape final
70 :public AccessibleShape
71 ,public AccessibleControlShape_Base
74 //===== internal ========================================================
75 AccessibleControlShape(
76 const AccessibleShapeInfo
& rShapeInfo
,
77 const AccessibleShapeTreeInfo
& rShapeTreeInfo
);
78 virtual ~AccessibleControlShape( ) override
;
80 const css::uno::Reference
< css::beans::XPropertySet
>& GetControlModel( ) { return m_xControlModel
;} ;
81 AccessibleControlShape
* GetLabeledByControlShape();
84 //--- XAccessibleComponent -------------------------------
85 /// forward the focus to the contained control(in alive mode)
86 virtual void SAL_CALL
grabFocus( ) override
;
88 //--- XAccessibleContext ---------------------------------
89 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) override
;
90 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) override
;
91 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) override
;
93 //--- XServiceInfo ---------------------------------------
94 virtual OUString SAL_CALL
getImplementationName( ) override
;
96 //--- XInterface -----------------------------------------
99 //--- XTypeProvider --------------------------------------
100 DECLARE_XTYPEPROVIDER( )
102 //--- XPropertyChangeListener ----------------------------
103 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& _rEvent
) override
;
105 //--- XComponent -----------------------------------------
106 virtual void SAL_CALL
disposing( ) override
;
108 //--- XEventListener -------------------------------------
109 virtual void SAL_CALL
disposing(const css::lang::EventObject
& Source
) override
;
111 //--- XModeChangeListener --------------------------------
112 virtual void SAL_CALL
modeChanged( const css::util::ModeChangeEvent
& _rSource
) override
;
114 //--- XAccessibleEventListener ----------------------------
115 virtual void SAL_CALL
notifyEvent( const css::accessibility::AccessibleEventObject
& aEvent
) override
;
117 //--- document::XEventListener ----------------------------
118 using AccessibleShape::notifyEvent
;
120 // XVclContainerListener
121 virtual void SAL_CALL
elementInserted( const css::container::ContainerEvent
& Event
) override
;
122 virtual void SAL_CALL
elementRemoved( const css::container::ContainerEvent
& Event
) override
;
123 virtual void SAL_CALL
elementReplaced( const css::container::ContainerEvent
& Event
) override
;
125 /** Initialize a new shape. See the documentation of the base' constructor
126 for the reason of this method's existence.
128 virtual void Init( ) override
;
130 /// Create a name string that contains the accessible name.
132 CreateAccessibleBaseName( ) override
;
134 /** Create a unique name string that contains the accessible name. The
135 name consists of the base name and the index.
138 CreateAccessibleName( ) override
;
140 /// Create a description string that contains the accessible description.
142 CreateAccessibleDescription( ) override
;
145 /// Set the specified state
146 virtual bool SetState( sal_Int16 _nState
) override
;
149 /// (safely) reads the given property from the model of the UNO control
150 OUString
getControlModelStringProperty( const OUString
& _rPropertyName
) const;
152 /// ensure that our control model exists(will be retrieved upon need only)
153 bool ensureControlModelAccess( );
155 /// ensures that we're listening for the given property if(and only if!) necessary
156 bool ensureListeningState( const bool _bCurrentlyListening
, const bool _bNeedNewListening
,
157 const OUString
& _rPropertyName
);
159 /// starts multiplexing the state changes of our aggregate context
160 void startStateMultiplexing( );
161 /// stops multiplexing the state changes of our aggregate context
162 void stopStateMultiplexing( );
164 /** adjusts our AccessibleRole, depending on the control type we're working for
166 <p>Only to be called during initialization</p>
168 void adjustAccessibleRole( );
170 /** initializes composed states of the context
172 <p>Some of the states of our inner context need to be propagated to the "composed context", too
173 (such as "checked" for check boxes). At lifetime, this is done by multiplexing state changes,
174 at initialization time, this method is used.</p>
176 void initializeComposedState( );
178 AccessibleControlShape(const AccessibleControlShape
&) = delete;
179 AccessibleControlShape
& operator= (const AccessibleControlShape
&) = delete;
181 css::uno::Reference
< css::beans::XPropertySet
>
183 css::uno::Reference
< css::beans::XPropertySetInfo
>
184 m_xModelPropsMeta
; // cache this for performance reasons
185 css::uno::Reference
< css::awt::XControl
>
186 m_xUnoControl
; // our UNO control
188 css::uno::WeakReference
< css::accessibility::XAccessibleContext
>
189 m_aControlContext
; // the AccessibleContext of the control
190 css::uno::Reference
< css::uno::XAggregation
>
191 m_xControlContextProxy
; // the proxy for "aggregating" the AccessibleContext of the control
192 css::uno::Reference
< css::lang::XTypeProvider
>
193 m_xControlContextTypeAccess
; // cached interface of our aggregate
194 css::uno::Reference
< css::lang::XComponent
>
195 m_xControlContextComponent
; // cached interface of our aggregate
197 rtl::Reference
<::comphelper::OWrappedAccessibleChildrenManager
>
200 bool m_bListeningForName
: 1; // are we currently listening for changes of the "Name" property?
201 bool m_bListeningForDesc
: 1; // are we currently listening for changes of the "HelpText" property?
202 bool m_bMultiplexingStates
: 1; // are we currently multiplexing state changes of the native context?
203 bool m_bDisposeNativeContext
: 1; // do we need to dispose mxNativeContextComponent?
204 bool m_bWaitingForControl
: 1; // if we are created before our control exists, we need to wait for it to appear ...
207 } // end of namespace accessibility
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */