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 
24 // ============================================================================
25 
26 #ifndef _SC_ACCESSIBLECSVCONTROL_HXX
27 #define _SC_ACCESSIBLECSVCONTROL_HXX
28 
29 #include <com/sun/star/accessibility/XAccessibleText.hpp>
30 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
31 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
32 #include <tools/gen.hxx>
33 #include <tools/string.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/implbase2.hxx>
37 #include <editeng/AccessibleStaticTextBase.hxx>
38 #include <comphelper/uno3.hxx>
39 #include "AccessibleContextBase.hxx"
40 
41 
42 // ============================================================================
43 
44 class ScCsvControl;
45 namespace utl { class AccessibleStateSetHelper; }
46 
47 /** Accessible base class used for CSV controls. */
48 class ScAccessibleCsvControl : public ScAccessibleContextBase
49 {
50 protected:
51     typedef ::com::sun::star::uno::Reference<
52         ::com::sun::star::accessibility::XAccessible > XAccessibleRef;
53     typedef ::com::sun::star::uno::Reference<
54         ::com::sun::star::accessibility::XAccessibleRelationSet > XAccessibleRelationSetRef;
55     typedef ::com::sun::star::uno::Reference<
56         ::com::sun::star::accessibility::XAccessibleStateSet > XAccessibleStateSetRef;
57 
58     typedef ::com::sun::star::awt::Point        AwtPoint;
59     typedef ::com::sun::star::awt::Size         AwtSize;
60     typedef ::com::sun::star::awt::Rectangle    AwtRectangle;
61 
62 private:
63     ScCsvControl*               mpControl;          /// Pointer to the VCL control.
64 
65 public:
66     explicit                    ScAccessibleCsvControl(
67                                     const XAccessibleRef& rxParent,
68                                     ScCsvControl& rControl,
69                                     sal_uInt16 nRole );
70     virtual                     ~ScAccessibleCsvControl();
71 
72     using ScAccessibleContextBase::disposing;
73     virtual void SAL_CALL       disposing();
74 
75     // XAccessibleComponent ---------------------------------------------------
76 
77     /** Returns the child at the specified point (cell returns NULL). */
78     virtual XAccessibleRef SAL_CALL getAccessibleAtPoint( const AwtPoint& rPoint )
79         throw( ::com::sun::star::uno::RuntimeException );
80 
81     /** Returns true, if the control is visible. */
82     virtual sal_Bool SAL_CALL isVisible() throw( ::com::sun::star::uno::RuntimeException );
83 
84     /** Sets the focus to this control. */
85     virtual void SAL_CALL grabFocus() throw( ::com::sun::star::uno::RuntimeException );
86 
87     // events -----------------------------------------------------------------
88 public:
89     /** Sends a GetFocus or LoseFocus event to all listeners. */
90     virtual void SendFocusEvent( bool bFocused );
91     /** Sends a caret changed event to all listeners. */
92     virtual void SendCaretEvent();
93     /** Sends a visible area changed event to all listeners. */
94     virtual void SendVisibleEvent();
95     /** Sends a selection changed event to all listeners. */
96     virtual void SendSelectionEvent();
97     /** Sends a table model changed event for changed cell contents to all listeners. */
98     virtual void SendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows );
99     /** Sends a table model changed event for an inserted column to all listeners. */
100     virtual void SendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
101     /** Sends a table model changed event for a removed column to all listeners. */
102     virtual void SendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
103 
104     // helpers ----------------------------------------------------------------
105 protected:
106     /** Returns this object's current bounding box relative to the desktop. */
107     virtual Rectangle GetBoundingBoxOnScreen() const throw( ::com::sun::star::uno::RuntimeException );
108     /** Returns this object's current bounding box relative to the parent object. */
109     virtual Rectangle GetBoundingBox() const throw( ::com::sun::star::uno::RuntimeException );
110 
111     /** Creates a new UUID in rSeq, if it is empty. Locks mutex internally. */
112     void getUuid( ::com::sun::star::uno::Sequence< sal_Int8 >& rSeq );
113 
114     /** Returns whether the object is alive. Must be called with locked mutex. */
implIsAlive() const115     inline bool implIsAlive() const { return !rBHelper.bDisposed && !rBHelper.bInDispose && mpControl; }
116     /** Throws an exception, if the object is disposed/disposing or any pointer
117         is missing. Should be used with locked mutex! */
118     void ensureAlive() const throw( ::com::sun::star::lang::DisposedException );
119 
120     /** Returns the VCL control. Assumes a living object. */
121     ScCsvControl& implGetControl() const;
122 
123     /** Returns the first child of rxParentObj, which has the role nRole. */
124     XAccessibleRef implGetChildByRole( const XAccessibleRef& rxParentObj, sal_uInt16 nRole )
125         throw( ::com::sun::star::uno::RuntimeException );
126     /** Creates a StateSetHelper and fills it with DEFUNC, OPAQUE, ENABLED, SHOWING and VISIBLE. */
127     ::utl::AccessibleStateSetHelper* implCreateStateSet();
128 
129     /** Disposes the object. This is a helper called from destructors only. */
130     void implDispose();
131 
132     /** Converts the control-relative position to an absolute screen position. */
133     Point implGetAbsPos( const Point& rPos ) const;
134 };
135 
136 
137 // ============================================================================
138 
139 class ScCsvRuler;
140 
141 typedef ::cppu::ImplHelper1<
142         ::com::sun::star::accessibility::XAccessibleText >
143     ScAccessibleCsvRulerImpl;
144 
145 /** Accessible class representing the CSV ruler control. */
146 class ScAccessibleCsvRuler : public ScAccessibleCsvControl, public ScAccessibleCsvRulerImpl
147 {
148 protected:
149     typedef ::com::sun::star::uno::Sequence<
150         ::com::sun::star::beans::PropertyValue > PropertyValueSeq;
151 
152 private:
153     ::rtl::OUStringBuffer       maBuffer;   /// Contains the text representation of the ruler.
154 
155 public:
156     explicit                    ScAccessibleCsvRuler( ScCsvRuler& rRuler );
157     virtual                     ~ScAccessibleCsvRuler();
158 
159     // XAccessibleComponent -----------------------------------------------------
160 
161     virtual sal_Int32 SAL_CALL getForeground(  )
162         throw (::com::sun::star::uno::RuntimeException);
163 
164     virtual sal_Int32 SAL_CALL getBackground(  )
165         throw (::com::sun::star::uno::RuntimeException);
166 
167     // XAccessibleContext -----------------------------------------------------
168 
169     /** Returns the child count (the ruler does not have children). */
170     virtual sal_Int32 SAL_CALL getAccessibleChildCount()
171         throw( ::com::sun::star::uno::RuntimeException );
172 
173     /** Throws an exception (the ruler does not have childern). */
174     virtual XAccessibleRef SAL_CALL getAccessibleChild( sal_Int32 nIndex )
175         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
176 
177     /** Returns the relation to the grid control. */
178     virtual XAccessibleRelationSetRef SAL_CALL getAccessibleRelationSet()
179         throw( ::com::sun::star::uno::RuntimeException );
180 
181     /** Returns the current set of states. */
182     virtual XAccessibleStateSetRef SAL_CALL getAccessibleStateSet()
183         throw( ::com::sun::star::uno::RuntimeException );
184 
185     // XAccessibleText --------------------------------------------------------
186 
187     /** Return the position of the caret. */
188     virtual sal_Int32 SAL_CALL getCaretPosition() throw( ::com::sun::star::uno::RuntimeException );
189 
190     /** Sets the position of the caret. */
191     virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex )
192         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
193 
194     /** Returns the specified character. */
195     virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex )
196         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
197 
198     /** Returns the attributes of the specified character. */
199     virtual PropertyValueSeq SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes )
200         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
201 
202     /** Returns the screen coordinates of the specified character. */
203     virtual AwtRectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex )
204         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
205 
206     /** Returns the count of characters. */
207     virtual sal_Int32 SAL_CALL getCharacterCount() throw( ::com::sun::star::uno::RuntimeException );
208 
209     /** Returns the character index at the specified coordinate (object's coordinate system). */
210     virtual sal_Int32 SAL_CALL getIndexAtPoint( const AwtPoint& rPoint )
211         throw( ::com::sun::star::uno::RuntimeException );
212 
213     /** Returns the selected text (ruler returns empty string). */
214     virtual ::rtl::OUString SAL_CALL getSelectedText() throw( ::com::sun::star::uno::RuntimeException );
215 
216     /** Returns the start index of the selection (ruler returns -1). */
217     virtual sal_Int32 SAL_CALL getSelectionStart() throw( ::com::sun::star::uno::RuntimeException );
218 
219     /** Returns the end index of the selection (ruler returns -1). */
220     virtual sal_Int32 SAL_CALL getSelectionEnd() throw( ::com::sun::star::uno::RuntimeException );
221 
222     /** Selects a part of the text (ruler does nothing). */
223     virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
224         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
225 
226     /** Returns the entire text. */
227     virtual ::rtl::OUString SAL_CALL getText() throw( ::com::sun::star::uno::RuntimeException );
228 
229     /** Returns the specified range [Start,End) of the text. */
230     virtual ::rtl::OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
231         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
232 
233     /** Returns the specified text portion. */
234     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);
235     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);
236     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);
237 
238     /** Copies the specified text range into the clipboard (ruler does nothing). */
239     virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
240         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
241 
242     // XInterface -------------------------------------------------------------
243 
244     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
245         throw( ::com::sun::star::uno::RuntimeException );
246 
247     virtual void SAL_CALL acquire() throw();
248 
249     virtual void SAL_CALL release() throw();
250 
251     // XServiceInfo -----------------------------------------------------------
252 
253     /** Returns an identifier for the implementation of this object. */
254     virtual ::rtl::OUString SAL_CALL getImplementationName()
255         throw( ::com::sun::star::uno::RuntimeException );
256 
257     // XTypeProvider ----------------------------------------------------------
258 
259     /** Returns a sequence with all supported interface types. */
260     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
261         throw( ::com::sun::star::uno::RuntimeException );
262 
263     /** Returns an implementation ID. */
264     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
265         throw( ::com::sun::star::uno::RuntimeException );
266 
267     // events -----------------------------------------------------------------
268 public:
269     /** Sends a caret changed event to all listeners. */
270     virtual void SendCaretEvent();
271 
272     // helpers ----------------------------------------------------------------
273 private:
274     /** Returns this object's name. */
275     virtual ::rtl::OUString SAL_CALL createAccessibleName()
276         throw( ::com::sun::star::uno::RuntimeException );
277     /** Returns this object's description. */
278     virtual ::rtl::OUString SAL_CALL createAccessibleDescription()
279         throw( ::com::sun::star::uno::RuntimeException );
280 
281     /** Throws an exception, if the specified character position is invalid (outside 0..len-1). */
282     void ensureValidIndex( sal_Int32 nIndex ) const
283         throw( ::com::sun::star::lang::IndexOutOfBoundsException );
284     /** Throws an exception, if the specified character position is invalid (outside 0..len). */
285     void ensureValidIndexWithEnd( sal_Int32 nIndex ) const
286         throw( ::com::sun::star::lang::IndexOutOfBoundsException );
287     /** Throws an exception, if the specified character range [Start,End) is invalid.
288         @descr  If Start>End, swaps Start and End before checking. */
289     void ensureValidRange( sal_Int32& rnStartIndex, sal_Int32& rnEndIndex ) const
290         throw( ::com::sun::star::lang::IndexOutOfBoundsException );
291 
292     /** Returns the VCL ruler control. Assumes a living object. */
293     ScCsvRuler& implGetRuler() const;
294 
295     /** Builds the entire string buffer. */
296     void constructStringBuffer() throw( ::com::sun::star::uno::RuntimeException );
297     /** Returns the character count of the text. */
298     sal_Int32 implGetTextLength() const;
299 
300     /** Returns true, if the character at the specified index has a split. */
301     bool implHasSplit( sal_Int32 nApiPos );
302 
303     /** Returns the first character index with equal formatting as at nApiPos. */
304     sal_Int32 implGetFirstEqualFormatted( sal_Int32 nApiPos );
305     /** Returns the last character index with equal formatting as at nApiPos. */
306     sal_Int32 implGetLastEqualFormatted( sal_Int32 nApiPos );
307 };
308 
309 
310 // ============================================================================
311 
312 class ScCsvGrid;
313 
314 typedef ::cppu::ImplHelper2<
315         ::com::sun::star::accessibility::XAccessibleTable,
316         ::com::sun::star::accessibility::XAccessibleSelection >
317     ScAccessibleCsvGridImpl;
318 
319 /** Accessible class representing the CSV grid control. */
320 class ScAccessibleCsvGrid : public ScAccessibleCsvControl, public ScAccessibleCsvGridImpl
321 {
322 protected:
323     typedef ::com::sun::star::uno::Reference<
324         ::com::sun::star::accessibility::XAccessibleTable > XAccessibleTableRef;
325 
326 public:
327     explicit                    ScAccessibleCsvGrid( ScCsvGrid& rGrid );
328     virtual                     ~ScAccessibleCsvGrid();
329 
330     // XAccessibleComponent ---------------------------------------------------
331 
332     /** Returns the cell at the specified point. */
333     virtual XAccessibleRef SAL_CALL getAccessibleAtPoint( const AwtPoint& rPoint )
334         throw( ::com::sun::star::uno::RuntimeException );
335 
336     virtual sal_Int32 SAL_CALL getForeground(  )
337         throw (::com::sun::star::uno::RuntimeException);
338 
339     virtual sal_Int32 SAL_CALL getBackground(  )
340         throw (::com::sun::star::uno::RuntimeException);
341 
342     // XAccessibleContext -----------------------------------------------------
343 
344     /** Returns the child count (count of cells in the table). */
345     virtual sal_Int32 SAL_CALL getAccessibleChildCount()
346         throw( ::com::sun::star::uno::RuntimeException );
347 
348     /** Returns the specified child cell. */
349     virtual XAccessibleRef SAL_CALL getAccessibleChild( sal_Int32 nIndex )
350         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
351 
352     /** Returns the relation to the ruler control. */
353     virtual XAccessibleRelationSetRef SAL_CALL getAccessibleRelationSet()
354         throw( ::com::sun::star::uno::RuntimeException );
355 
356     /** Returns the current set of states. */
357     virtual XAccessibleStateSetRef SAL_CALL getAccessibleStateSet()
358         throw( ::com::sun::star::uno::RuntimeException );
359 
360     // XAccessibleTable -------------------------------------------------------
361 
362     /** Returns the number of rows in the table. */
363     virtual sal_Int32 SAL_CALL getAccessibleRowCount()
364         throw( ::com::sun::star::uno::RuntimeException );
365 
366     /** Returns the number of columns in the table. */
367     virtual sal_Int32 SAL_CALL getAccessibleColumnCount()
368         throw( ::com::sun::star::uno::RuntimeException );
369 
370     /** Returns the description of the specified row in the table. */
371     virtual ::rtl::OUString SAL_CALL getAccessibleRowDescription( sal_Int32 nRow )
372         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
373 
374     /** Returns the description text of the specified column in the table. */
375     virtual ::rtl::OUString SAL_CALL getAccessibleColumnDescription( sal_Int32 nColumn )
376         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
377 
378     /** Returns the number of rows occupied at a specified row and column.
379         @descr  Returns always 1 (Merged cells not supported). */
380     virtual sal_Int32 SAL_CALL getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
381         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
382 
383     /** Returns the number of rows occupied at a specified row and column.
384         @descr  Returns always 1 (Merged cells not supported). */
385     virtual sal_Int32 SAL_CALL getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn )
386         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
387 
388     /** Returns the row headers as an AccessibleTable. */
389     virtual XAccessibleTableRef SAL_CALL getAccessibleRowHeaders()
390         throw( ::com::sun::star::uno::RuntimeException );
391 
392     /** Returns the column headers as an AccessibleTable. */
393     virtual XAccessibleTableRef SAL_CALL getAccessibleColumnHeaders()
394         throw( ::com::sun::star::uno::RuntimeException );
395 
396     /** Returns the selected rows as a sequence. */
397     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleRows()
398         throw( ::com::sun::star::uno::RuntimeException );
399 
400     /** Returns the selected columns as a sequence. */
401     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleColumns()
402         throw( ::com::sun::star::uno::RuntimeException );
403 
404     /** Returns true, if the specified row is selected. */
405     virtual sal_Bool SAL_CALL isAccessibleRowSelected( sal_Int32 nRow )
406         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
407 
408     /** Returns true, if the specified column is selected. */
409     virtual sal_Bool SAL_CALL isAccessibleColumnSelected( sal_Int32 nColumn )
410         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
411 
412     /** Returns the accessible cell object at the specified position. */
413     virtual XAccessibleRef SAL_CALL getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn )
414         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
415 
416     /** Returns the caption object of the table. */
417     virtual XAccessibleRef SAL_CALL getAccessibleCaption()
418         throw( ::com::sun::star::uno::RuntimeException );
419 
420     /** Returns the summary description object of the table. */
421     virtual XAccessibleRef SAL_CALL getAccessibleSummary()
422         throw( ::com::sun::star::uno::RuntimeException );
423 
424     /** Returns true, if the cell at a specified position is selected. */
425     virtual sal_Bool SAL_CALL isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn )
426         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
427 
428     /** Returns the child index of the cell at the specified position. */
429     virtual sal_Int32 SAL_CALL getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
430         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
431 
432     /** Returns the row index of the specified child. */
433     virtual sal_Int32 SAL_CALL getAccessibleRow( sal_Int32 nChildIndex )
434         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
435 
436     /** Returns the column index of the specified child. */
437     virtual sal_Int32 SAL_CALL getAccessibleColumn( sal_Int32 nChildIndex )
438         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
439 
440     // XAccessibleSelection ---------------------------------------------------
441 
442     /** Selects the specified child (selects the entire column or the entire table). */
443     virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex )
444         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
445 
446     /** Returns true, if the specified child is selected. */
447     virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex )
448         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
449 
450     /** Deselects all cells. */
451     virtual void SAL_CALL clearAccessibleSelection()
452         throw( ::com::sun::star::uno::RuntimeException );
453 
454     /** Selects all cells. */
455     virtual void SAL_CALL selectAllAccessibleChildren()
456         throw( ::com::sun::star::uno::RuntimeException );
457 
458     /** Returns the count of selected children. */
459     virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount()
460         throw( ::com::sun::star::uno::RuntimeException );
461 
462     /** Returns the child with the specified index in all selected children. */
463     virtual XAccessibleRef SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
464         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
465 
466     /** Deselects the child with the specified index in all selected children. */
467     virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex )
468         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
469 
470     // XInterface -------------------------------------------------------------
471 
472     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType )
473         throw( ::com::sun::star::uno::RuntimeException );
474 
475     virtual void SAL_CALL acquire() throw();
476 
477     virtual void SAL_CALL release() throw();
478 
479     // XServiceInfo -----------------------------------------------------------
480 
481     /** Returns an identifier for the implementation of this object. */
482     virtual ::rtl::OUString SAL_CALL getImplementationName()
483         throw( ::com::sun::star::uno::RuntimeException );
484 
485     // XTypeProvider ----------------------------------------------------------
486 
487     /** Returns a sequence with all supported interface types. */
488     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
489         throw( ::com::sun::star::uno::RuntimeException );
490 
491     /** Returns an implementation ID. */
492     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
493         throw( ::com::sun::star::uno::RuntimeException );
494 
495     // events -----------------------------------------------------------------
496 public:
497     /** Sends a GetFocus or LoseFocus event to all listeners. */
498     virtual void SendFocusEvent( bool bFocused );
499     /** Sends a table model changed event for changed cell contents to all listeners. */
500     virtual void SendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows );
501     /** Sends a table model changed event for an inserted column to all listeners. */
502     virtual void SendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
503     /** Sends a table model changed event for a removed column to all listeners. */
504     virtual void SendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
505 
506     // helpers ----------------------------------------------------------------
507 private:
508     /** Returns this object's name. */
509     virtual ::rtl::OUString SAL_CALL createAccessibleName()
510         throw( ::com::sun::star::uno::RuntimeException );
511     /** Returns this object's description. */
512     virtual ::rtl::OUString SAL_CALL createAccessibleDescription()
513         throw( ::com::sun::star::uno::RuntimeException );
514 
515     /** Throws an exception, if nIndex is not a valid child index. */
516     void ensureValidIndex( sal_Int32 nIndex ) const
517         throw( ::com::sun::star::lang::IndexOutOfBoundsException );
518     /** Throws an exception, if the specified position is invalid. */
519     void ensureValidPosition( sal_Int32 nRow, sal_Int32 nColumn ) const
520         throw( ::com::sun::star::lang::IndexOutOfBoundsException );
521 
522     /** Returns the VCL grid control. Assumes a living object. */
523     ScCsvGrid& implGetGrid() const;
524 
525     /** Returns true, if the specified column (including header) is selected. */
526     bool implIsColumnSelected( sal_Int32 nColumn ) const;
527     /** Selects the specified column (including header). */
528     void implSelectColumn( sal_Int32 nColumn, bool bSelect );
529 
530     /** Returns the count of visible rows in the table (including header). */
531     sal_Int32 implGetRowCount() const;
532     /** Returns the total column count in the table (including header). */
533     sal_Int32 implGetColumnCount() const;
534     /** Returns the count of selected columns in the table. */
535     sal_Int32 implGetSelColumnCount() const;
536     /** Returns the total cell count in the table (including header). */
implGetCellCount() const537     inline sal_Int32 implGetCellCount() const { return implGetRowCount() * implGetColumnCount(); }
538 
539     /** Returns the row index from cell index (including header). */
implGetRow(sal_Int32 nIndex) const540     inline sal_Int32 implGetRow( sal_Int32 nIndex ) const { return nIndex / implGetColumnCount(); }
541     /** Returns the column index from cell index (including header). */
implGetColumn(sal_Int32 nIndex) const542     inline sal_Int32 implGetColumn( sal_Int32 nIndex ) const { return nIndex % implGetColumnCount(); }
543     /** Returns the absolute column index of the nSelColumn-th selected column. */
544     sal_Int32 implGetSelColumn( sal_Int32 nSelColumn ) const;
545     /** Returns the child index from cell position (including header). */
implGetIndex(sal_Int32 nRow,sal_Int32 nColumn) const546     inline sal_Int32 implGetIndex( sal_Int32 nRow, sal_Int32 nColumn ) const { return nRow * implGetColumnCount() + nColumn; }
547 
548     /** Returns the contents of the specified cell (including header). Indexes must be valid. */
549     String implGetCellText( sal_Int32 nRow, sal_Int32 nColumn ) const;
550     /** Creates a new accessible object of the specified cell. Indexes must be valid. */
551     ScAccessibleCsvControl* implCreateCellObj( sal_Int32 nRow, sal_Int32 nColumn ) const;
552 };
553 
554 
555 // ============================================================================
556 
557 /** Accessible class representing a cell of the CSV grid control. */
558 class ScAccessibleCsvCell : public ScAccessibleCsvControl, public accessibility::AccessibleStaticTextBase
559 {
560 protected:
561     typedef ::com::sun::star::uno::Sequence<
562         ::com::sun::star::beans::PropertyValue >    PropertyValueSeq;
563     typedef ::std::auto_ptr< SvxEditSource >        SvxEditSourcePtr;
564 
565 private:
566     String                      maCellText; /// The text contents of this cell.
567     sal_Int32                   mnLine;     /// The grid line index (core index).
568     sal_uInt32                  mnColumn;   /// The grid column index (core index).
569     sal_Int32                   mnIndex;    /// The index of the cell in the table.
570 
571 public:
572     explicit                    ScAccessibleCsvCell(
573                                     ScCsvGrid& rGrid,
574                                     const String& rCellText,
575                                     sal_Int32 nRow, sal_Int32 nColumn );
576     virtual                     ~ScAccessibleCsvCell();
577 
578     using ScAccessibleCsvControl::disposing;
579     virtual void SAL_CALL       disposing();
580 
581     // XAccessibleComponent ---------------------------------------------------
582 
583     /** Sets the focus to the column of this cell. */
584     virtual void SAL_CALL grabFocus() throw( ::com::sun::star::uno::RuntimeException );
585 
586     virtual sal_Int32 SAL_CALL getForeground(  )
587         throw (::com::sun::star::uno::RuntimeException);
588 
589     virtual sal_Int32 SAL_CALL getBackground(  )
590         throw (::com::sun::star::uno::RuntimeException);
591 
592     // XAccessibleContext -----------------------------------------------------
593 
594     /** Returns the child count. */
595     virtual sal_Int32 SAL_CALL getAccessibleChildCount()
596         throw( ::com::sun::star::uno::RuntimeException );
597 
598     /** Returns the specified child. */
599     virtual XAccessibleRef SAL_CALL getAccessibleChild( sal_Int32 nIndex )
600         throw( ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException );
601 
602     /** Returns the index of this cell in the table. */
603     virtual sal_Int32 SAL_CALL getAccessibleIndexInParent()
604         throw( ::com::sun::star::uno::RuntimeException );
605 
606     /** Returns the relation to the ruler control. */
607     virtual XAccessibleRelationSetRef SAL_CALL getAccessibleRelationSet()
608         throw( ::com::sun::star::uno::RuntimeException );
609 
610     /** Returns the current set of states. */
611     virtual XAccessibleStateSetRef SAL_CALL getAccessibleStateSet()
612         throw( ::com::sun::star::uno::RuntimeException );
613 
614     // XInterface -------------------------------------------------------------
615 
616 	DECLARE_XINTERFACE()
617 
618     // XTypeProvider ----------------------------------------------------------
619 
620     DECLARE_XTYPEPROVIDER()
621 
622     // XServiceInfo -----------------------------------------------------------
623 
624     /** Returns an identifier for the implementation of this object. */
625     virtual ::rtl::OUString SAL_CALL getImplementationName()
626         throw( ::com::sun::star::uno::RuntimeException );
627 
628     // helpers ----------------------------------------------------------------
629 protected:
630     /** Returns this object's current bounding box relative to the desktop. */
631     virtual Rectangle GetBoundingBoxOnScreen() const throw( ::com::sun::star::uno::RuntimeException );
632     /** Returns this object's current bounding box relative to the parent object. */
633     virtual Rectangle GetBoundingBox() const throw( ::com::sun::star::uno::RuntimeException );
634 
635 private:
636     /** Returns this object's name. */
637     virtual ::rtl::OUString SAL_CALL createAccessibleName()
638         throw( ::com::sun::star::uno::RuntimeException );
639     /** Returns this object's description. */
640     virtual ::rtl::OUString SAL_CALL createAccessibleDescription()
641         throw( ::com::sun::star::uno::RuntimeException );
642 
643     /** Returns the VCL grid control. Assumes a living object. */
644     ScCsvGrid& implGetGrid() const;
645     /** Returns the pixel position of the cell (rel. to parent), regardless of visibility. */
646     Point implGetRealPos() const;
647     /** Returns the width of the character count */
648     sal_uInt32 implCalcPixelWidth(sal_uInt32 nChars) const;
649     /** Returns the pixel size of the cell, regardless of visibility. */
650     Size implGetRealSize() const;
651     /** Returns the bounding box of the cell relative in the table. */
652     Rectangle implGetBoundingBox() const;
653 
654     /** Creates the edit source the text helper needs. */
655     ::std::auto_ptr< SvxEditSource > implCreateEditSource();
656 };
657 
658 
659 // ============================================================================
660 
661 #endif
662 
663