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_STARMATH_SOURCE_ACCESSIBILITY_HXX
21 #define INCLUDED_STARMATH_SOURCE_ACCESSIBILITY_HXX
23 #include <com/sun/star/accessibility/AccessibleScrollType.hpp>
24 #include <com/sun/star/accessibility/XAccessible.hpp>
25 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
26 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
27 #include <com/sun/star/accessibility/XAccessibleText.hpp>
28 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/uno/Reference.h>
31 #include <cppuhelper/implbase.hxx>
32 #include <svl/SfxBroadcaster.hxx>
34 #include <editeng/editeng.hxx>
35 #include <editeng/unoedsrc.hxx>
42 namespace accessibility
{ class AccessibleTextHelper
; }
44 // classes and helper-classes used for accessibility in the graphic-window
50 css::lang::XServiceInfo
,
51 css::accessibility::XAccessible
,
52 css::accessibility::XAccessibleComponent
,
53 css::accessibility::XAccessibleContext
,
54 css::accessibility::XAccessibleText
,
55 css::accessibility::XAccessibleEventBroadcaster
57 SmGraphicAccessibleBaseClass
;
59 class SmGraphicAccessible final
:
60 public SmGraphicAccessibleBaseClass
63 /// client id in the AccessibleEventNotifier queue
66 VclPtr
<SmGraphicWindow
> pWin
;
68 SmGraphicAccessible( const SmGraphicAccessible
& ) = delete;
69 SmGraphicAccessible
& operator = ( const SmGraphicAccessible
& ) = delete;
71 SmDocShell
* GetDoc_Impl();
72 OUString
GetAccessibleText_Impl();
75 explicit SmGraphicAccessible( SmGraphicWindow
*pGraphicWin
);
76 virtual ~SmGraphicAccessible() override
;
78 void ClearWin(); // to be called when view is destroyed
80 const sal_Int16 nAccessibleEventId
,
81 const css::uno::Any
&rOldVal
,
82 const css::uno::Any
&rNewVal
);
85 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) override
;
87 // XAccessibleComponent
88 virtual sal_Bool SAL_CALL
containsPoint( const css::awt::Point
& aPoint
) override
;
89 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleAtPoint( const css::awt::Point
& aPoint
) override
;
90 virtual css::awt::Rectangle SAL_CALL
getBounds( ) override
;
91 virtual css::awt::Point SAL_CALL
getLocation( ) override
;
92 virtual css::awt::Point SAL_CALL
getLocationOnScreen( ) override
;
93 virtual css::awt::Size SAL_CALL
getSize( ) override
;
94 virtual void SAL_CALL
grabFocus( ) override
;
95 virtual sal_Int32 SAL_CALL
getForeground( ) override
;
96 virtual sal_Int32 SAL_CALL
getBackground( ) override
;
99 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) override
;
100 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) override
;
101 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) override
;
102 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) override
;
103 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) override
;
104 virtual OUString SAL_CALL
getAccessibleDescription( ) override
;
105 virtual OUString SAL_CALL
getAccessibleName( ) override
;
106 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) override
;
107 virtual css::uno::Reference
< css::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) override
;
108 virtual css::lang::Locale SAL_CALL
getLocale( ) override
;
110 // XAccessibleEventBroadcaster
111 virtual void SAL_CALL
addAccessibleEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
112 virtual void SAL_CALL
removeAccessibleEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
115 virtual sal_Int32 SAL_CALL
getCaretPosition( ) override
;
116 virtual sal_Bool SAL_CALL
setCaretPosition ( sal_Int32 nIndex
) override
;
117 virtual sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) override
;
118 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
119 virtual css::awt::Rectangle SAL_CALL
getCharacterBounds( sal_Int32 nIndex
) override
;
120 virtual sal_Int32 SAL_CALL
getCharacterCount( ) override
;
121 virtual sal_Int32 SAL_CALL
getIndexAtPoint( const css::awt::Point
& aPoint
) override
;
122 virtual OUString SAL_CALL
getSelectedText( ) override
;
123 virtual sal_Int32 SAL_CALL
getSelectionStart( ) override
;
124 virtual sal_Int32 SAL_CALL
getSelectionEnd( ) override
;
125 virtual sal_Bool SAL_CALL
setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
126 virtual OUString SAL_CALL
getText( ) override
;
127 virtual OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
128 virtual css::accessibility::TextSegment SAL_CALL
getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
129 virtual css::accessibility::TextSegment SAL_CALL
getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
130 virtual css::accessibility::TextSegment SAL_CALL
getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
131 virtual sal_Bool SAL_CALL
copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
132 virtual sal_Bool SAL_CALL
scrollSubstringTo( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, css::accessibility::AccessibleScrollType aScrollType
) override
;
135 virtual OUString SAL_CALL
getImplementationName( ) override
;
136 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
137 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
141 // classes and helper-classes used for accessibility in the command-window
144 class SmEditAccessible
;
150 class SmViewForwarder
:
151 public SvxViewForwarder
153 SmEditAccessible
& rEditAcc
;
155 SmViewForwarder( const SmViewForwarder
& ) = delete;
156 SmViewForwarder
& operator = ( const SmViewForwarder
& ) = delete;
159 explicit SmViewForwarder( SmEditAccessible
&rAcc
);
160 virtual ~SmViewForwarder() override
;
162 virtual bool IsValid() const override
;
163 virtual Point
LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const override
;
164 virtual Point
PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const override
;
168 class SmTextForwarder
: /* analog to SvxEditEngineForwarder */
169 public SvxTextForwarder
171 SmEditAccessible
& rEditAcc
;
172 SmEditSource
& rEditSource
;
174 DECL_LINK( NotifyHdl
, EENotify
&, void );
176 SmTextForwarder( const SmTextForwarder
& ) = delete;
177 SmTextForwarder
& operator = ( const SmTextForwarder
& ) = delete;
180 SmTextForwarder( SmEditAccessible
& rAcc
, SmEditSource
& rSource
);
181 virtual ~SmTextForwarder() override
;
183 virtual sal_Int32
GetParagraphCount() const override
;
184 virtual sal_Int32
GetTextLen( sal_Int32 nParagraph
) const override
;
185 virtual OUString
GetText( const ESelection
& rSel
) const override
;
186 virtual SfxItemSet
GetAttribs( const ESelection
& rSel
, EditEngineAttribs nOnlyHardAttrib
= EditEngineAttribs::All
) const override
;
187 virtual SfxItemSet
GetParaAttribs( sal_Int32 nPara
) const override
;
188 virtual void SetParaAttribs( sal_Int32 nPara
, const SfxItemSet
& rSet
) override
;
189 virtual void RemoveAttribs( const ESelection
& rSelection
) override
;
190 virtual void GetPortions( sal_Int32 nPara
, std::vector
<sal_Int32
>& rList
) const override
;
192 virtual SfxItemState
GetItemState( const ESelection
& rSel
, sal_uInt16 nWhich
) const override
;
193 virtual SfxItemState
GetItemState( sal_Int32 nPara
, sal_uInt16 nWhich
) const override
;
195 virtual void QuickInsertText( const OUString
& rText
, const ESelection
& rSel
) override
;
196 virtual void QuickInsertField( const SvxFieldItem
& rFld
, const ESelection
& rSel
) override
;
197 virtual void QuickSetAttribs( const SfxItemSet
& rSet
, const ESelection
& rSel
) override
;
198 virtual void QuickInsertLineBreak( const ESelection
& rSel
) override
;
200 virtual SfxItemPool
* GetPool() const override
;
202 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, std::optional
<Color
>& rpTxtColor
, std::optional
<Color
>& rpFldColor
) override
;
203 virtual void FieldClicked(const SvxFieldItem
&) override
;
204 virtual bool IsValid() const override
;
206 virtual LanguageType
GetLanguage( sal_Int32
, sal_Int32
) const override
;
207 virtual sal_Int32
GetFieldCount( sal_Int32 nPara
) const override
;
208 virtual EFieldInfo
GetFieldInfo( sal_Int32 nPara
, sal_uInt16 nField
) const override
;
209 virtual EBulletInfo
GetBulletInfo( sal_Int32 nPara
) const override
;
210 virtual tools::Rectangle
GetCharBounds( sal_Int32 nPara
, sal_Int32 nIndex
) const override
;
211 virtual tools::Rectangle
GetParaBounds( sal_Int32 nPara
) const override
;
212 virtual MapMode
GetMapMode() const override
;
213 virtual OutputDevice
* GetRefDevice() const override
;
214 virtual bool GetIndexAtPoint( const Point
&, sal_Int32
& nPara
, sal_Int32
& nIndex
) const override
;
215 virtual bool GetWordIndices( sal_Int32 nPara
, sal_Int32 nIndex
, sal_Int32
& nStart
, sal_Int32
& nEnd
) const override
;
216 virtual bool GetAttributeRun( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
, sal_Int32 nPara
, sal_Int32 nIndex
, bool bInCell
= false ) const override
;
217 virtual sal_Int32
GetLineCount( sal_Int32 nPara
) const override
;
218 virtual sal_Int32
GetLineLen( sal_Int32 nPara
, sal_Int32 nLine
) const override
;
219 virtual void GetLineBoundaries( /*out*/sal_Int32
&rStart
, /*out*/sal_Int32
&rEnd
, sal_Int32 nParagraph
, sal_Int32 nLine
) const override
;
220 virtual sal_Int32
GetLineNumberAtIndex( sal_Int32 nPara
, sal_Int32 nLine
) const override
;
221 virtual bool Delete( const ESelection
& ) override
;
222 virtual bool InsertText( const OUString
&, const ESelection
& ) override
;
223 virtual bool QuickFormatDoc( bool bFull
= false ) override
;
225 virtual sal_Int16
GetDepth( sal_Int32 nPara
) const override
;
226 virtual bool SetDepth( sal_Int32 nPara
, sal_Int16 nNewDepth
) override
;
228 virtual const SfxItemSet
* GetEmptyItemSetPtr() override
;
229 // implementation functions for XParagraphAppend and XTextPortionAppend
230 virtual void AppendParagraph() override
;
231 virtual sal_Int32
AppendTextPortion( sal_Int32 nPara
, const OUString
&rText
, const SfxItemSet
&rSet
) override
;
233 virtual void CopyText(const SvxTextForwarder
& rSource
) override
;
237 class SmEditViewForwarder
: /* analog to SvxEditEngineViewForwarder */
238 public SvxEditViewForwarder
240 SmEditAccessible
& rEditAcc
;
242 SmEditViewForwarder( const SmEditViewForwarder
& ) = delete;
243 SmEditViewForwarder
& operator = ( const SmEditViewForwarder
& ) = delete;
246 explicit SmEditViewForwarder( SmEditAccessible
& rAcc
);
247 virtual ~SmEditViewForwarder() override
;
249 virtual bool IsValid() const override
;
251 virtual Point
LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const override
;
252 virtual Point
PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const override
;
254 virtual bool GetSelection( ESelection
& rSelection
) const override
;
255 virtual bool SetSelection( const ESelection
& rSelection
) override
;
256 virtual bool Copy() override
;
257 virtual bool Cut() override
;
258 virtual bool Paste() override
;
265 SfxBroadcaster aBroadCaster
;
266 SmViewForwarder aViewFwd
;
267 SmTextForwarder aTextFwd
;
268 SmEditViewForwarder aEditViewFwd
;
270 SmEditAccessible
& rEditAcc
;
272 SmEditSource( const SmEditSource
&rSrc
);
273 SmEditSource
& operator = ( const SmEditSource
& ) = delete;
276 SmEditSource( SmEditAccessible
&rAcc
);
277 virtual ~SmEditSource() override
;
279 virtual std::unique_ptr
<SvxEditSource
> Clone() const override
;
280 virtual SvxTextForwarder
* GetTextForwarder() override
;
281 virtual SvxViewForwarder
* GetViewForwarder() override
;
282 virtual SvxEditViewForwarder
* GetEditViewForwarder( bool bCreate
= false ) override
;
283 virtual void UpdateData() override
;
284 virtual SfxBroadcaster
& GetBroadcaster() const override
;
291 css::lang::XServiceInfo
,
292 css::accessibility::XAccessible
,
293 css::accessibility::XAccessibleComponent
,
294 css::accessibility::XAccessibleContext
,
295 css::accessibility::XAccessibleEventBroadcaster
297 SmEditAccessibleBaseClass
;
299 class SmEditAccessible
:
300 public SmEditAccessibleBaseClass
303 std::unique_ptr
<::accessibility::AccessibleTextHelper
> pTextHelper
;
304 VclPtr
<SmEditWindow
> pWin
;
306 SmEditAccessible( const SmEditAccessible
& ) = delete;
307 SmEditAccessible
& operator = ( const SmEditAccessible
& ) = delete;
310 explicit SmEditAccessible( SmEditWindow
*pEditWin
);
311 virtual ~SmEditAccessible() override
;
313 ::accessibility::AccessibleTextHelper
* GetTextHelper();
316 void ClearWin(); // to be called when view is destroyed
318 //! access EditEngine and EditView via the functions in the respective window
319 //! pointers may be 0 (e.g. during reload)
320 EditEngine
* GetEditEngine() { return pWin
? pWin
->GetEditEngine() : nullptr; }
321 EditView
* GetEditView() { return pWin
? pWin
->GetEditView() : nullptr; }
324 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) override
;
326 // XAccessibleComponent
327 virtual sal_Bool SAL_CALL
containsPoint( const css::awt::Point
& aPoint
) override
;
328 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleAtPoint( const css::awt::Point
& aPoint
) override
;
329 virtual css::awt::Rectangle SAL_CALL
getBounds( ) override
;
330 virtual css::awt::Point SAL_CALL
getLocation( ) override
;
331 virtual css::awt::Point SAL_CALL
getLocationOnScreen( ) override
;
332 virtual css::awt::Size SAL_CALL
getSize( ) override
;
333 virtual void SAL_CALL
grabFocus( ) override
;
334 virtual sal_Int32 SAL_CALL
getForeground( ) override
;
335 virtual sal_Int32 SAL_CALL
getBackground( ) override
;
337 // XAccessibleContext
338 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) override
;
339 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) override
;
340 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) override
;
341 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) override
;
342 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) override
;
343 virtual OUString SAL_CALL
getAccessibleDescription( ) override
;
344 virtual OUString SAL_CALL
getAccessibleName( ) override
;
345 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) override
;
346 virtual css::uno::Reference
< css::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) override
;
347 virtual css::lang::Locale SAL_CALL
getLocale( ) override
;
349 // XAccessibleEventBroadcaster
350 virtual void SAL_CALL
addAccessibleEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
351 virtual void SAL_CALL
removeAccessibleEventListener( const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
354 virtual OUString SAL_CALL
getImplementationName( ) override
;
355 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
356 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */