cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svtools / source / control / valueimp.hxx
blob89cfeb84f9451f44e825a07d83e1e56139cd533e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <tools/color.hxx>
23 #include <vcl/image.hxx>
24 #include <cppuhelper/implbase.hxx>
25 #include <comphelper/compbase.hxx>
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
28 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
29 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
30 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
32 #include <mutex>
33 #include <vector>
35 #define VALUESET_ITEM_NONEITEM 0xFFFE
37 enum ValueSetItemType
39 VALUESETITEM_NONE,
40 VALUESETITEM_IMAGE,
41 VALUESETITEM_IMAGE_AND_TEXT,
42 VALUESETITEM_COLOR,
43 VALUESETITEM_USERDRAW
46 class ValueItemAcc;
47 class ValueSet;
49 struct ValueSetItem
51 ValueSet& mrParent;
52 OUString maText;
53 void* mpData;
54 rtl::Reference< ValueItemAcc > mxAcc;
55 Image maImage;
56 Color maColor;
57 sal_uInt16 mnId;
58 sal_uInt8 meType;
59 bool mbVisible;
61 explicit ValueSetItem( ValueSet& rParent );
62 ~ValueSetItem();
64 const rtl::Reference< ValueItemAcc > & GetAccessible( bool bIsTransientChildrenDisabled );
67 typedef comphelper::WeakComponentImplHelper<
68 css::accessibility::XAccessible,
69 css::accessibility::XAccessibleEventBroadcaster,
70 css::accessibility::XAccessibleContext,
71 css::accessibility::XAccessibleComponent,
72 css::accessibility::XAccessibleSelection >
73 ValueSetAccComponentBase;
75 class ValueSetAcc final : public ValueSetAccComponentBase
77 public:
79 explicit ValueSetAcc(ValueSet* pParent);
80 virtual ~ValueSetAcc() override;
82 void FireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
83 bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
85 public:
87 /** Called by the corresponding ValueSet when it gets the focus.
88 Stores the new focus state and broadcasts a state change event.
90 void GetFocus();
92 /** Called by the corresponding ValueSet when it loses the focus.
93 Stores the new focus state and broadcasts a state change event.
95 void LoseFocus();
97 /** Called by the corresponding ValueSet when it gets destroyed. */
98 void Invalidate();
100 // XAccessible
101 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override;
103 // XAccessibleEventBroadcaster
104 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
105 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
107 // XAccessibleContext
108 virtual sal_Int64 SAL_CALL getAccessibleChildCount( ) override;
109 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override;
110 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
111 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override;
112 virtual sal_Int16 SAL_CALL getAccessibleRole( ) override;
113 virtual OUString SAL_CALL getAccessibleDescription( ) override;
114 virtual OUString SAL_CALL getAccessibleName( ) override;
115 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override;
116 virtual sal_Int64 SAL_CALL getAccessibleStateSet( ) override;
117 virtual css::lang::Locale SAL_CALL getLocale( ) override;
119 // XAccessibleComponent
120 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override;
121 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
122 virtual css::awt::Rectangle SAL_CALL getBounds( ) override;
123 virtual css::awt::Point SAL_CALL getLocation( ) override;
124 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override;
125 virtual css::awt::Size SAL_CALL getSize( ) override;
126 virtual void SAL_CALL grabFocus( ) override;
127 virtual sal_Int32 SAL_CALL getForeground( ) override;
128 virtual sal_Int32 SAL_CALL getBackground( ) override;
130 // XAccessibleSelection
131 virtual void SAL_CALL selectAccessibleChild( sal_Int64 nChildIndex ) override;
132 virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int64 nChildIndex ) override;
133 virtual void SAL_CALL clearAccessibleSelection( ) override;
134 virtual void SAL_CALL selectAllAccessibleChildren( ) override;
135 virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount( ) override;
136 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
137 virtual void SAL_CALL deselectAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
139 private:
140 ::std::vector< css::uno::Reference<
141 css::accessibility::XAccessibleEventListener > > mxEventListeners;
142 ValueSet* mpParent;
143 /// The current FOCUSED state.
144 bool mbIsFocused;
146 /** Tell all listeners that the object is dying. This callback is
147 usually called from the WeakComponentImplHelper class.
149 virtual void disposing(std::unique_lock<std::mutex>&) override;
151 /** Return the number of items. This takes the None-Item into account.
153 sal_uInt16 getItemCount() const;
155 /** Return the item associated with the given index. The None-Item is
156 taken into account which, when present, is taken to be the first
157 (with index 0) item.
158 @param nIndex
159 Index of the item to return. The index 0 denotes the None-Item
160 when present.
161 @return
162 Returns NULL when the given index is out of range.
164 ValueSetItem* getItem (sal_uInt16 nIndex) const;
166 /** Check whether or not the object has been disposed (or is in the
167 state of being disposed). If that is the case then
168 DisposedException is thrown to inform the (indirect) caller of the
169 foul deed.
170 @param bCheckValueSet
171 Whether to also check that the ValueSet (parent)
172 is non-null.
173 @throws css::lang::DisposedException
175 void ThrowIfDisposed(bool bCheckParent = true);
177 /** Check whether the value set has a 'none' field, i.e. a field (button)
178 that deselects any items (selects none of them).
179 @return
180 Returns <true/> if there is a 'none' field and <false/> if it is
181 missing.
183 bool HasNoneField() const;
186 class ValueItemAcc : public ::cppu::WeakImplHelper< css::accessibility::XAccessible,
187 css::accessibility::XAccessibleEventBroadcaster,
188 css::accessibility::XAccessibleContext,
189 css::accessibility::XAccessibleComponent >
191 private:
193 ::std::vector< css::uno::Reference<
194 css::accessibility::XAccessibleEventListener > > mxEventListeners;
195 std::mutex maMutex;
196 ValueSetItem* mpParent;
197 bool mbIsTransientChildrenDisabled;
199 public:
201 ValueItemAcc(ValueSetItem* pParent, bool bIsTransientChildrenDisabled);
202 virtual ~ValueItemAcc() override;
204 void ParentDestroyed();
206 void FireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
208 public:
210 // XAccessible
211 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override;
213 // XAccessibleEventBroadcaster
214 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
215 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
217 // XAccessibleContext
218 virtual sal_Int64 SAL_CALL getAccessibleChildCount( ) override;
219 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override;
220 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
221 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override;
222 virtual sal_Int16 SAL_CALL getAccessibleRole( ) override;
223 virtual OUString SAL_CALL getAccessibleDescription( ) override;
224 virtual OUString SAL_CALL getAccessibleName( ) override;
225 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override;
226 virtual sal_Int64 SAL_CALL getAccessibleStateSet( ) override;
227 virtual css::lang::Locale SAL_CALL getLocale( ) override;
229 // XAccessibleComponent
230 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override;
231 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
232 virtual css::awt::Rectangle SAL_CALL getBounds( ) override;
233 virtual css::awt::Point SAL_CALL getLocation( ) override;
234 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override;
235 virtual css::awt::Size SAL_CALL getSize( ) override;
236 virtual void SAL_CALL grabFocus( ) override;
237 virtual sal_Int32 SAL_CALL getForeground( ) override;
238 virtual sal_Int32 SAL_CALL getBackground( ) override;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */