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