cURL: follow redirects
[LibreOffice.git] / starmath / source / accessibility.hxx
blob657838fd076767bac3e44a601b1a26406f086f1b
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 #ifndef INCLUDED_STARMATH_SOURCE_ACCESSIBILITY_HXX
21 #define INCLUDED_STARMATH_SOURCE_ACCESSIBILITY_HXX
23 #include <com/sun/star/accessibility/XAccessible.hpp>
24 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
25 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
26 #include <com/sun/star/accessibility/XAccessibleText.hpp>
27 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/uno/Reference.h>
31 #include <osl/mutex.hxx>
32 #include <cppuhelper/interfacecontainer.h>
33 #include <cppuhelper/implbase.hxx>
34 #include <svl/SfxBroadcaster.hxx>
36 #include <editeng/editeng.hxx>
37 #include <editeng/unoedsrc.hxx>
38 #include <svx/AccessibleTextHelper.hxx>
39 #include <edit.hxx>
40 #include <memory>
42 class SmGraphicWindow;
43 class SmEditWindow;
44 class SmDocShell;
46 namespace com { namespace sun { namespace star { namespace accessibility {
47 struct AccessibleEventObject;
48 }}}}
51 // classes and helper-classes used for accessibility in the graphic-window
54 typedef
55 cppu::WeakImplHelper
57 css::lang::XServiceInfo,
58 css::accessibility::XAccessible,
59 css::accessibility::XAccessibleComponent,
60 css::accessibility::XAccessibleContext,
61 css::accessibility::XAccessibleText,
62 css::accessibility::XAccessibleEventBroadcaster
64 SmGraphicAccessibleBaseClass;
66 class SmGraphicAccessible :
67 public SmGraphicAccessibleBaseClass
69 OUString aAccName;
70 /// client id in the AccessibleEventNotifier queue
71 sal_uInt32 nClientId;
73 VclPtr<SmGraphicWindow> pWin;
75 SmGraphicAccessible( const SmGraphicAccessible & ) = delete;
76 SmGraphicAccessible & operator = ( const SmGraphicAccessible & ) = delete;
78 protected:
79 SmDocShell * GetDoc_Impl();
80 OUString GetAccessibleText_Impl();
82 public:
83 explicit SmGraphicAccessible( SmGraphicWindow *pGraphicWin );
84 virtual ~SmGraphicAccessible() override;
86 void ClearWin(); // to be called when view is destroyed
87 void LaunchEvent(
88 const sal_Int16 nAccesibleEventId,
89 const css::uno::Any &rOldVal,
90 const css::uno::Any &rNewVal);
92 // XAccessible
93 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (css::uno::RuntimeException, std::exception) override;
95 // XAccessibleComponent
96 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
97 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
98 virtual css::awt::Rectangle SAL_CALL getBounds( ) throw (css::uno::RuntimeException, std::exception) override;
99 virtual css::awt::Point SAL_CALL getLocation( ) throw (css::uno::RuntimeException, std::exception) override;
100 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) throw (css::uno::RuntimeException, std::exception) override;
101 virtual css::awt::Size SAL_CALL getSize( ) throw (css::uno::RuntimeException, std::exception) override;
102 virtual void SAL_CALL grabFocus( ) throw (css::uno::RuntimeException, std::exception) override;
103 virtual sal_Int32 SAL_CALL getForeground( ) throw (css::uno::RuntimeException, std::exception) override;
104 virtual sal_Int32 SAL_CALL getBackground( ) throw (css::uno::RuntimeException, std::exception) override;
106 // XAccessibleContext
107 virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (css::uno::RuntimeException, std::exception) override;
108 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
109 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (css::uno::RuntimeException, std::exception) override;
110 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (css::uno::RuntimeException, std::exception) override;
111 virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (css::uno::RuntimeException, std::exception) override;
112 virtual OUString SAL_CALL getAccessibleDescription( ) throw (css::uno::RuntimeException, std::exception) override;
113 virtual OUString SAL_CALL getAccessibleName( ) throw (css::uno::RuntimeException, std::exception) override;
114 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (css::uno::RuntimeException, std::exception) override;
115 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (css::uno::RuntimeException, std::exception) override;
116 virtual css::lang::Locale SAL_CALL getLocale( ) throw (css::accessibility::IllegalAccessibleComponentStateException, css::uno::RuntimeException, std::exception) override;
118 // XAccessibleEventBroadcaster
119 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
120 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
122 // XAccessibleText
123 virtual sal_Int32 SAL_CALL getCaretPosition( ) throw (css::uno::RuntimeException, std::exception) override;
124 virtual sal_Bool SAL_CALL setCaretPosition ( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
125 virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
126 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
127 virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
128 virtual sal_Int32 SAL_CALL getCharacterCount( ) throw (css::uno::RuntimeException, std::exception) override;
129 virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
130 virtual OUString SAL_CALL getSelectedText( ) throw (css::uno::RuntimeException, std::exception) override;
131 virtual sal_Int32 SAL_CALL getSelectionStart( ) throw (css::uno::RuntimeException, std::exception) override;
132 virtual sal_Int32 SAL_CALL getSelectionEnd( ) throw (css::uno::RuntimeException, std::exception) override;
133 virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
134 virtual OUString SAL_CALL getText( ) throw (css::uno::RuntimeException, std::exception) override;
135 virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
136 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
137 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
138 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
139 virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
141 // XServiceInfo
142 virtual OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException, std::exception) override;
143 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (css::uno::RuntimeException, std::exception) override;
144 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException, std::exception) override;
148 // classes and helper-classes used for accessibility in the command-window
151 class SmEditAccessible;
152 class SmEditSource;
153 class EditEngine;
154 class EditView;
155 class SvxFieldItem;
156 struct ESelection;
159 class SmViewForwarder :
160 public SvxViewForwarder
162 SmEditAccessible & rEditAcc;
164 SmViewForwarder( const SmViewForwarder & ) = delete;
165 SmViewForwarder & operator = ( const SmViewForwarder & ) = delete;
167 public:
168 explicit SmViewForwarder( SmEditAccessible &rAcc );
169 virtual ~SmViewForwarder() override;
171 virtual bool IsValid() const override;
172 virtual Rectangle GetVisArea() const override;
173 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const override;
174 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const override;
178 class SmTextForwarder : /* analog to SvxEditEngineForwarder */
179 public SvxTextForwarder
181 SmEditAccessible & rEditAcc;
182 SmEditSource & rEditSource;
184 DECL_LINK( NotifyHdl, EENotify&, void );
186 SmTextForwarder( const SmTextForwarder & ) = delete;
187 SmTextForwarder & operator = ( const SmTextForwarder & ) = delete;
189 public:
190 SmTextForwarder( SmEditAccessible& rAcc, SmEditSource & rSource );
191 virtual ~SmTextForwarder() override;
193 virtual sal_Int32 GetParagraphCount() const override;
194 virtual sal_Int32 GetTextLen( sal_Int32 nParagraph ) const override;
195 virtual OUString GetText( const ESelection& rSel ) const override;
196 virtual SfxItemSet GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs_All ) const override;
197 virtual SfxItemSet GetParaAttribs( sal_Int32 nPara ) const override;
198 virtual void SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) override;
199 virtual void RemoveAttribs( const ESelection& rSelection ) override;
200 virtual void GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const override;
202 virtual SfxItemState GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const override;
203 virtual SfxItemState GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const override;
205 virtual void QuickInsertText( const OUString& rText, const ESelection& rSel ) override;
206 virtual void QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) override;
207 virtual void QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) override;
208 virtual void QuickInsertLineBreak( const ESelection& rSel ) override;
210 virtual SfxItemPool* GetPool() const override;
212 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
213 virtual void FieldClicked(const SvxFieldItem&, sal_Int32, sal_Int32) override;
214 virtual bool IsValid() const override;
216 virtual LanguageType GetLanguage( sal_Int32, sal_Int32 ) const override;
217 virtual sal_Int32 GetFieldCount( sal_Int32 nPara ) const override;
218 virtual EFieldInfo GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const override;
219 virtual EBulletInfo GetBulletInfo( sal_Int32 nPara ) const override;
220 virtual Rectangle GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const override;
221 virtual Rectangle GetParaBounds( sal_Int32 nPara ) const override;
222 virtual MapMode GetMapMode() const override;
223 virtual OutputDevice* GetRefDevice() const override;
224 virtual bool GetIndexAtPoint( const Point&, sal_Int32& nPara, sal_Int32& nIndex ) const override;
225 virtual bool GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd ) const override;
226 virtual bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell = false ) const override;
227 virtual sal_Int32 GetLineCount( sal_Int32 nPara ) const override;
228 virtual sal_Int32 GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const override;
229 virtual void GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const override;
230 virtual sal_Int32 GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nLine ) const override;
231 virtual bool Delete( const ESelection& ) override;
232 virtual bool InsertText( const OUString&, const ESelection& ) override;
233 virtual bool QuickFormatDoc( bool bFull = false ) override;
235 virtual sal_Int16 GetDepth( sal_Int32 nPara ) const override;
236 virtual bool SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) override;
238 virtual const SfxItemSet* GetEmptyItemSetPtr() override;
239 // implementation functions for XParagraphAppend and XTextPortionAppend
240 virtual void AppendParagraph() override;
241 virtual sal_Int32 AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet ) override;
243 virtual void CopyText(const SvxTextForwarder& rSource) override;
247 class SmEditViewForwarder : /* analog to SvxEditEngineViewForwarder */
248 public SvxEditViewForwarder
250 SmEditAccessible& rEditAcc;
252 SmEditViewForwarder( const SmEditViewForwarder & ) = delete;
253 SmEditViewForwarder & operator = ( const SmEditViewForwarder & ) = delete;
255 public:
256 explicit SmEditViewForwarder( SmEditAccessible& rAcc );
257 virtual ~SmEditViewForwarder() override;
259 virtual bool IsValid() const override;
261 virtual Rectangle GetVisArea() const override;
262 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const override;
263 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const override;
265 virtual bool GetSelection( ESelection& rSelection ) const override;
266 virtual bool SetSelection( const ESelection& rSelection ) override;
267 virtual bool Copy() override;
268 virtual bool Cut() override;
269 virtual bool Paste() override;
273 class SmEditSource :
274 public SvxEditSource
276 SfxBroadcaster aBroadCaster;
277 SmViewForwarder aViewFwd;
278 SmTextForwarder aTextFwd;
279 SmEditViewForwarder aEditViewFwd;
281 SmEditAccessible& rEditAcc;
283 SmEditSource( const SmEditSource &rSrc );
284 SmEditSource & operator = ( const SmEditSource & ) = delete;
286 public:
287 SmEditSource( SmEditWindow *pWin, SmEditAccessible &rAcc );
288 virtual ~SmEditSource() override;
290 virtual SvxEditSource* Clone() const override;
291 virtual SvxTextForwarder* GetTextForwarder() override;
292 virtual SvxViewForwarder* GetViewForwarder() override;
293 virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false ) override;
294 virtual void UpdateData() override;
295 virtual SfxBroadcaster& GetBroadcaster() const override;
299 typedef
300 cppu::WeakImplHelper
302 css::lang::XServiceInfo,
303 css::accessibility::XAccessible,
304 css::accessibility::XAccessibleComponent,
305 css::accessibility::XAccessibleContext,
306 css::accessibility::XAccessibleEventBroadcaster
308 SmEditAccessibleBaseClass;
310 class SmEditAccessible :
311 public SmEditAccessibleBaseClass
313 OUString aAccName;
314 std::unique_ptr<::accessibility::AccessibleTextHelper> pTextHelper;
315 VclPtr<SmEditWindow> pWin;
317 SmEditAccessible( const SmEditAccessible & ) = delete;
318 SmEditAccessible & operator = ( const SmEditAccessible & ) = delete;
320 public:
321 explicit SmEditAccessible( SmEditWindow *pEditWin );
322 virtual ~SmEditAccessible() override;
324 ::accessibility::AccessibleTextHelper * GetTextHelper();
326 void Init();
327 void ClearWin(); // to be called when view is destroyed
329 //! access EditEngine and EditView via the functions in the respective window
330 //! pointers may be 0 (e.g. during reload)
331 EditEngine * GetEditEngine() { return pWin ? pWin->GetEditEngine() : nullptr; }
332 EditView * GetEditView() { return pWin ? pWin->GetEditView() : nullptr; }
334 // XAccessible
335 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (css::uno::RuntimeException, std::exception) override;
337 // XAccessibleComponent
338 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
339 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
340 virtual css::awt::Rectangle SAL_CALL getBounds( ) throw (css::uno::RuntimeException, std::exception) override;
341 virtual css::awt::Point SAL_CALL getLocation( ) throw (css::uno::RuntimeException, std::exception) override;
342 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) throw (css::uno::RuntimeException, std::exception) override;
343 virtual css::awt::Size SAL_CALL getSize( ) throw (css::uno::RuntimeException, std::exception) override;
344 virtual void SAL_CALL grabFocus( ) throw (css::uno::RuntimeException, std::exception) override;
345 virtual sal_Int32 SAL_CALL getForeground( ) throw (css::uno::RuntimeException, std::exception) override;
346 virtual sal_Int32 SAL_CALL getBackground( ) throw (css::uno::RuntimeException, std::exception) override;
348 // XAccessibleContext
349 virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (css::uno::RuntimeException, std::exception) override;
350 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
351 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (css::uno::RuntimeException, std::exception) override;
352 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (css::uno::RuntimeException, std::exception) override;
353 virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (css::uno::RuntimeException, std::exception) override;
354 virtual OUString SAL_CALL getAccessibleDescription( ) throw (css::uno::RuntimeException, std::exception) override;
355 virtual OUString SAL_CALL getAccessibleName( ) throw (css::uno::RuntimeException, std::exception) override;
356 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (css::uno::RuntimeException, std::exception) override;
357 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (css::uno::RuntimeException, std::exception) override;
358 virtual css::lang::Locale SAL_CALL getLocale( ) throw (css::accessibility::IllegalAccessibleComponentStateException, css::uno::RuntimeException, std::exception) override;
360 // XAccessibleEventBroadcaster
361 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
362 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
364 // XServiceInfo
365 virtual OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException, std::exception) override;
366 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (css::uno::RuntimeException, std::exception) override;
367 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException, std::exception) override;
371 #endif
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */