Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef _ACCPARA_HXX
20 : #define _ACCPARA_HXX
21 :
22 : #include <acccontext.hxx>
23 : #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
24 : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
25 : #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
26 : #include <com/sun/star/accessibility/XAccessibleTextMarkup.hpp>
27 : #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
28 : #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
29 : #include <boost/unordered_map.hpp>
30 : #include <accselectionhelper.hxx>
31 : #include <calbck.hxx> // #i108125#
32 :
33 : class SwTxtFrm;
34 : class SwTxtNode;
35 : class SwPaM;
36 : class SwAccessiblePortionData;
37 : class SwAccessibleHyperTextData;
38 : class SwXTextPortion;
39 : class SwParaChangeTrackingInfo; //#i108125#
40 :
41 : namespace com { namespace sun { namespace star {
42 : namespace i18n { struct Boundary; }
43 : namespace accessibility { class XAccessibleHyperlink; }
44 : } } }
45 :
46 : typedef ::boost::unordered_map< OUString,
47 : ::com::sun::star::beans::PropertyValue,
48 : OUStringHash,
49 : ::std::equal_to< OUString > > tAccParaPropValMap;
50 :
51 : class SwAccessibleParagraph :
52 : public SwClient, // #i108125#
53 : public SwAccessibleContext,
54 : public ::com::sun::star::accessibility::XAccessibleEditableText,
55 : public com::sun::star::accessibility::XAccessibleSelection,
56 : public com::sun::star::accessibility::XAccessibleHypertext,
57 : public com::sun::star::accessibility::XAccessibleTextMarkup,
58 : public com::sun::star::accessibility::XAccessibleMultiLineText,
59 : public ::com::sun::star::accessibility::XAccessibleTextAttributes
60 : {
61 : friend class SwAccessibleHyperlink;
62 :
63 : OUString sDesc; // protected by base classes mutex
64 :
65 : // data for this paragraph's text portions; this contains the
66 : // mapping from the core 'model string' to the accessible text
67 : // string.
68 : // pPortionData may be NULL; it should only be accessed through the
69 : // Get/Clear/Has/UpdatePortionData() methods
70 : SwAccessiblePortionData* pPortionData;
71 : SwAccessibleHyperTextData *pHyperTextData;
72 :
73 : sal_Int32 nOldCaretPos; // The 'old' caret pos. It's only valid as long
74 : // as the cursor is inside this object (protected by
75 : // mutex)
76 :
77 : sal_Bool bIsHeading; // protected by base classes mutex
78 :
79 : // implementation for XAccessibleSelection
80 : SwAccessibleSelectionHelper aSelectionHelper;
81 :
82 : SwParaChangeTrackingInfo* mpParaChangeTrackInfo; // #i108125#
83 :
84 : /// get the SwTxtNode (requires frame; check before)
85 : const SwTxtNode* GetTxtNode() const;
86 :
87 : /// get the (accessible) text string (requires frame; check before)
88 : OUString GetString();
89 :
90 : OUString GetDescription();
91 :
92 : // get the current care position
93 : sal_Int32 GetCaretPos();
94 :
95 : // determine the current selection. Fill the values with
96 : // -1 if there is no selection in the this paragraph
97 : sal_Bool GetSelection(sal_Int32& nStart, sal_Int32& nEnd);
98 :
99 : // helper for GetSelection and getCaretPosition
100 : // #i27301# - add parameter <_bForSelection>, which indicates,
101 : // if the cursor is retrieved for selection or for caret position.
102 : SwPaM* GetCursor( const bool _bForSelection );
103 :
104 : // for cut/copy/paste: execute a particular slot at the view shell
105 : void ExecuteAtViewShell( sal_uInt16 nSlot );
106 :
107 : // helper method for get/setAttributes
108 : // (for the special case of (nEndIndex==-1) a single character will
109 : // be selected)
110 : SwXTextPortion* CreateUnoPortion( sal_Int32 nStart, sal_Int32 nEnd );
111 :
112 :
113 : // methods for checking the parameter range:
114 :
115 : // does nPos point to a char?
116 : sal_Bool IsValidChar(sal_Int32 nPos, sal_Int32 nLength);
117 :
118 : // does nPos point to a position? (may be behind the last character)
119 : sal_Bool IsValidPosition(sal_Int32 nPos, sal_Int32 nLength);
120 :
121 : // is nBegin...nEnd a valid range? (nEnd points past the last character)
122 : sal_Bool IsValidRange(sal_Int32 nBegin, sal_Int32 nEnd, sal_Int32 nLength);
123 :
124 : // Ensure ordered range (i.e. nBegin is smaller then nEnd)
125 0 : inline void OrderRange(sal_Int32& nBegin, sal_Int32& nEnd)
126 : {
127 0 : if( nBegin > nEnd )
128 : {
129 0 : sal_Int32 nTmp = nBegin; nBegin = nEnd; nEnd = nTmp;
130 : }
131 0 : }
132 :
133 : // #i63870#
134 : void _getDefaultAttributesImpl(
135 : const ::com::sun::star::uno::Sequence< OUString >& aRequestedAttributes,
136 : tAccParaPropValMap& rDefAttrSeq,
137 : const bool bOnlyCharAttrs = false );
138 : void _getRunAttributesImpl(
139 : const sal_Int32 nIndex,
140 : const ::com::sun::star::uno::Sequence< OUString >& aRequestedAttributes,
141 : tAccParaPropValMap& rRunAttrSeq );
142 :
143 : public:
144 :
145 : sal_Bool IsHeading() const;
146 :
147 : protected:
148 :
149 : // Set states for getAccessibleStateSet.
150 : // This drived class additinaly sets MULTILINE(1), MULTISELECTABLE(+),
151 : // FOCUSABLE(+) and FOCUSED(+)
152 : virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet );
153 :
154 : virtual void _InvalidateContent( sal_Bool bVisibleDataFired );
155 :
156 : virtual void _InvalidateCursorPos();
157 : virtual void _InvalidateFocus();
158 :
159 : virtual ~SwAccessibleParagraph();
160 :
161 : // handling of data for the text portions
162 :
163 : // force update of new portion data
164 : void UpdatePortionData()
165 : throw( com::sun::star::uno::RuntimeException );
166 :
167 : // remove the current portion data
168 : void ClearPortionData();
169 :
170 : // get portion data; update if necessary
171 166 : SwAccessiblePortionData& GetPortionData()
172 : throw( com::sun::star::uno::RuntimeException )
173 : {
174 166 : if( pPortionData == NULL )
175 28 : UpdatePortionData();
176 166 : return *pPortionData;
177 : }
178 :
179 : // determine if portion data is currently available
180 : sal_Bool HasPortionData() { return (pPortionData != NULL); }
181 :
182 : //helpers for word boundaries
183 :
184 : sal_Bool GetCharBoundary( com::sun::star::i18n::Boundary& rBound,
185 : const OUString& rText,
186 : sal_Int32 nPos );
187 : sal_Bool GetWordBoundary( com::sun::star::i18n::Boundary& rBound,
188 : const OUString& rText,
189 : sal_Int32 nPos );
190 : sal_Bool GetSentenceBoundary( com::sun::star::i18n::Boundary& rBound,
191 : const OUString& rText,
192 : sal_Int32 nPos );
193 : sal_Bool GetLineBoundary( com::sun::star::i18n::Boundary& rBound,
194 : const OUString& rText,
195 : sal_Int32 nPos );
196 : sal_Bool GetParagraphBoundary( com::sun::star::i18n::Boundary& rBound,
197 : const OUString& rText,
198 : sal_Int32 nPos );
199 : sal_Bool GetAttributeBoundary( com::sun::star::i18n::Boundary& rBound,
200 : const OUString& rText,
201 : sal_Int32 nPos );
202 : sal_Bool GetGlyphBoundary( com::sun::star::i18n::Boundary& rBound,
203 : const OUString& rText,
204 : sal_Int32 nPos );
205 :
206 : // get boundaries of word/sentence/etc. for specified text type
207 : // Does all argument checking, and then delegates to helper methods above.
208 : sal_Bool GetTextBoundary( com::sun::star::i18n::Boundary& rBound,
209 : const OUString& rText,
210 : sal_Int32 nPos,
211 : sal_Int16 aTextType )
212 : throw (
213 : ::com::sun::star::lang::IndexOutOfBoundsException,
214 : ::com::sun::star::lang::IllegalArgumentException,
215 : ::com::sun::star::uno::RuntimeException);
216 :
217 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew);
218 :
219 : public:
220 :
221 : SwAccessibleParagraph( SwAccessibleMap& rInitMap,
222 : const SwTxtFrm& rTxtFrm );
223 :
224 : inline operator ::com::sun::star::accessibility::XAccessibleText *();
225 :
226 : virtual sal_Bool HasCursor(); // required by map to remember that object
227 :
228 : // XAccessibleContext
229 :
230 : // Return this object's description.
231 : virtual OUString SAL_CALL
232 : getAccessibleDescription (void)
233 : throw (com::sun::star::uno::RuntimeException);
234 :
235 : // Return the parents locale or throw exception if this object has no
236 : // parent yet/anymore.
237 : virtual ::com::sun::star::lang::Locale SAL_CALL
238 : getLocale (void)
239 : throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
240 :
241 : // #i27138# - paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO
242 : virtual ::com::sun::star::uno::Reference<
243 : ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
244 : getAccessibleRelationSet (void)
245 : throw (::com::sun::star::uno::RuntimeException);
246 :
247 : // XAccessibleComponent
248 :
249 : virtual void SAL_CALL grabFocus()
250 : throw (::com::sun::star::uno::RuntimeException);
251 : // #i71385#
252 : virtual sal_Int32 SAL_CALL getForeground()
253 : throw (::com::sun::star::uno::RuntimeException);
254 : virtual sal_Int32 SAL_CALL getBackground()
255 : throw (::com::sun::star::uno::RuntimeException);
256 :
257 : // XServiceInfo
258 :
259 : // Returns an identifier for the implementation of this object.
260 : virtual OUString SAL_CALL
261 : getImplementationName (void)
262 : throw (::com::sun::star::uno::RuntimeException);
263 :
264 : // Return whether the specified service is supported by this class.
265 : virtual sal_Bool SAL_CALL
266 : supportsService (const OUString& sServiceName)
267 : throw (::com::sun::star::uno::RuntimeException);
268 :
269 : // Returns a list of all supported services. In this case that is just
270 : // the AccessibleContext service.
271 : virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL
272 : getSupportedServiceNames (void)
273 : throw (::com::sun::star::uno::RuntimeException);
274 :
275 :
276 : // XInterface
277 :
278 : // (XInterface methods need to be implemented to disambiguate
279 : // between those inherited through SwAcessibleContext and
280 : // XAccessibleEditableText).
281 :
282 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
283 : const ::com::sun::star::uno::Type& aType )
284 : throw (::com::sun::star::uno::RuntimeException);
285 :
286 2378 : virtual void SAL_CALL acquire( ) throw ()
287 2378 : { SwAccessibleContext::acquire(); };
288 :
289 2378 : virtual void SAL_CALL release( ) throw ()
290 2378 : { SwAccessibleContext::release(); };
291 :
292 : // XTypeProvider
293 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException);
294 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException);
295 :
296 : // XAccessibleText
297 : virtual sal_Int32 SAL_CALL getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException);
298 : virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
299 : virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
300 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& aRequestedAttributes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
301 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
302 : virtual sal_Int32 SAL_CALL getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException);
303 : virtual sal_Int32 SAL_CALL getIndexAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
304 : virtual OUString SAL_CALL getSelectedText( ) throw (::com::sun::star::uno::RuntimeException);
305 : virtual sal_Int32 SAL_CALL getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException);
306 : virtual sal_Int32 SAL_CALL getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException);
307 : virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
308 : virtual OUString SAL_CALL getText( ) throw (::com::sun::star::uno::RuntimeException);
309 : virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
310 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
311 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
312 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
313 : virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
314 :
315 : // XAccessibleEditableText
316 : virtual sal_Bool SAL_CALL cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
317 : virtual sal_Bool SAL_CALL pasteText( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
318 : virtual sal_Bool SAL_CALL deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
319 : virtual sal_Bool SAL_CALL insertText( const OUString& sText, sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
320 : virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
321 : virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aAttributeSet ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
322 : virtual sal_Bool SAL_CALL setText( const OUString& sText ) throw (::com::sun::star::uno::RuntimeException);
323 :
324 : // XAccessibleSelection
325 : virtual void SAL_CALL selectAccessibleChild(
326 : sal_Int32 nChildIndex )
327 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
328 : ::com::sun::star::uno::RuntimeException );
329 :
330 : virtual sal_Bool SAL_CALL isAccessibleChildSelected(
331 : sal_Int32 nChildIndex )
332 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
333 : ::com::sun::star::uno::RuntimeException );
334 : virtual void SAL_CALL clearAccessibleSelection( )
335 : throw ( ::com::sun::star::uno::RuntimeException );
336 : virtual void SAL_CALL selectAllAccessibleChildren( )
337 : throw ( ::com::sun::star::uno::RuntimeException );
338 : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( )
339 : throw ( ::com::sun::star::uno::RuntimeException );
340 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(
341 : sal_Int32 nSelectedChildIndex )
342 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
343 : ::com::sun::star::uno::RuntimeException);
344 :
345 : // index has to be treated as global child index.
346 : virtual void SAL_CALL deselectAccessibleChild(
347 : sal_Int32 nChildIndex )
348 : throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
349 : ::com::sun::star::uno::RuntimeException );
350 :
351 : // XAccessibleHypertext
352 : virtual sal_Int32 SAL_CALL getHyperLinkCount()
353 : throw (::com::sun::star::uno::RuntimeException);
354 : virtual ::com::sun::star::uno::Reference<
355 : ::com::sun::star::accessibility::XAccessibleHyperlink >
356 : SAL_CALL getHyperLink( sal_Int32 nLinkIndex )
357 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
358 : ::com::sun::star::uno::RuntimeException);
359 : virtual sal_Int32 SAL_CALL getHyperLinkIndex( sal_Int32 nCharIndex )
360 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
361 : ::com::sun::star::uno::RuntimeException);
362 :
363 : // #i71360#
364 : // XAccesibleTextMarkup
365 : virtual sal_Int32 SAL_CALL getTextMarkupCount( sal_Int32 nTextMarkupType )
366 : throw (::com::sun::star::lang::IllegalArgumentException,
367 : ::com::sun::star::uno::RuntimeException);
368 :
369 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
370 : getTextMarkup( sal_Int32 nTextMarkupIndex,
371 : sal_Int32 nTextMarkupType )
372 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
373 : ::com::sun::star::lang::IllegalArgumentException,
374 : ::com::sun::star::uno::RuntimeException);
375 :
376 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::accessibility::TextSegment > SAL_CALL
377 : getTextMarkupAtIndex( sal_Int32 nCharIndex,
378 : sal_Int32 nTextMarkupType )
379 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
380 : ::com::sun::star::lang::IllegalArgumentException,
381 : ::com::sun::star::uno::RuntimeException);
382 :
383 : // #i89175#
384 : // XAccessibleMultiLineText
385 : virtual sal_Int32 SAL_CALL getLineNumberAtIndex( sal_Int32 nIndex )
386 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
387 : ::com::sun::star::uno::RuntimeException);
388 :
389 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
390 : getTextAtLineNumber( sal_Int32 nLineNo )
391 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
392 : ::com::sun::star::uno::RuntimeException);
393 :
394 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
395 : getTextAtLineWithCaret()
396 : throw (::com::sun::star::uno::RuntimeException);
397 :
398 : virtual sal_Int32 SAL_CALL getNumberOfLineWithCaret()
399 : throw (::com::sun::star::uno::RuntimeException);
400 :
401 : // #i63870#
402 : // XAccesibleTextAttributes
403 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getDefaultAttributes( const ::com::sun::star::uno::Sequence< OUString >& aRequestedAttributes ) throw (::com::sun::star::uno::RuntimeException);
404 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getRunAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& aRequestedAttributes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
405 : };
406 :
407 3 : inline SwAccessibleParagraph::operator ::com::sun::star::accessibility::XAccessibleText *()
408 : {
409 : return static_cast<
410 3 : ::com::sun::star::accessibility::XAccessibleEditableText * >( this );
411 : }
412 :
413 : #endif
414 :
415 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|