tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / AccessibleCsvControl.hxx
blobcb1efc309353a2c68209959aac0f5c20144ca846
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 #pragma once
22 #include <memory>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleScrollType.hpp>
25 #include <com/sun/star/accessibility/XAccessibleText.hpp>
26 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
27 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
28 #include <tools/gen.hxx>
29 #include <rtl/ref.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <comphelper/accessiblecomponenthelper.hxx>
32 #include <cppuhelper/implbase.hxx>
33 #include <editeng/AccessibleStaticTextBase.hxx>
34 #include <comphelper/uno3.hxx>
35 #include <map>
37 class ScCsvControl;
39 /** Accessible base class used for CSV controls. */
40 class ScAccessibleCsvControl : public comphelper::OAccessibleComponentHelper
42 private:
43 ScCsvControl* mpControl; /// Pointer to the VCL control.
45 public:
46 explicit ScAccessibleCsvControl(ScCsvControl& rControl);
47 virtual ~ScAccessibleCsvControl() override;
49 virtual void SAL_CALL disposing() override;
51 virtual void SAL_CALL grabFocus( ) override;
52 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
54 // events -----------------------------------------------------------------
55 public:
56 /** Sends a GetFocus or LoseFocus event to all listeners. */
57 virtual void SendFocusEvent( bool bFocused );
58 /** Sends a caret changed event to all listeners. */
59 virtual void SendCaretEvent();
60 /** Sends a visible area changed event to all listeners. */
61 void SendVisibleEvent();
62 /** Sends a selection changed event to all listeners. */
63 void SendSelectionEvent();
64 /** Sends a table model changed event for changed cell contents to all listeners. */
65 virtual void SendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows );
66 /** Sends a table model changed event for an inserted column to all listeners. */
67 virtual void SendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
68 /** Sends a table model changed event for a removed column to all listeners. */
69 virtual void SendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
71 // helpers ----------------------------------------------------------------
72 protected:
73 virtual css::awt::Rectangle implGetBounds() override;
75 /** Returns the VCL control. Assumes a living object. */
76 ScCsvControl& implGetControl() const;
78 /** Creates a StateSet and fills it with DEFUNC, OPAQUE, ENABLED, SHOWING and VISIBLE. */
79 sal_Int64 implCreateStateSet();
82 class ScCsvRuler;
84 /** Accessible class representing the CSV ruler control. */
85 class ScAccessibleCsvRuler : public cppu::ImplInheritanceHelper<
86 ScAccessibleCsvControl,
87 css::accessibility::XAccessible,
88 css::accessibility::XAccessibleText>
90 private:
91 OUStringBuffer maBuffer; /// Contains the text representation of the ruler.
93 public:
94 explicit ScAccessibleCsvRuler( ScCsvRuler& rRuler );
95 virtual ~ScAccessibleCsvRuler() override;
97 // XAccessibleComponent -----------------------------------------------------
98 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override { return this; }
100 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
102 virtual OUString SAL_CALL getAccessibleDescription( ) override;
103 virtual OUString SAL_CALL getAccessibleName( ) override;
105 virtual sal_Int32 SAL_CALL getForeground( ) override;
107 virtual sal_Int32 SAL_CALL getBackground( ) override;
109 // XAccessibleContext -----------------------------------------------------
111 /** Returns the child count (the ruler does not have children). */
112 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
114 /** Throws an exception (the ruler does not have children). */
115 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 nIndex ) override;
117 virtual sal_Int16 SAL_CALL getAccessibleRole( ) override { return css::accessibility::AccessibleRole::TEXT; }
119 /** Returns the relation to the grid control. */
120 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
122 /** Returns the current set of states. */
123 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
125 // XAccessibleText --------------------------------------------------------
127 /** Return the position of the caret. */
128 virtual sal_Int32 SAL_CALL getCaretPosition() override;
130 /** Sets the position of the caret. */
131 virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) override;
133 /** Returns the specified character. */
134 virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) override;
136 /** Returns the attributes of the specified character. */
137 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) override;
139 /** Returns the screen coordinates of the specified character. */
140 virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) override;
142 /** Returns the count of characters. */
143 virtual sal_Int32 SAL_CALL getCharacterCount() override;
145 /** Returns the character index at the specified coordinate (object's coordinate system). */
146 virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& rPoint ) override;
148 /** Returns the selected text (ruler returns empty string). */
149 virtual OUString SAL_CALL getSelectedText() override;
151 /** Returns the start index of the selection (ruler returns -1). */
152 virtual sal_Int32 SAL_CALL getSelectionStart() override;
154 /** Returns the end index of the selection (ruler returns -1). */
155 virtual sal_Int32 SAL_CALL getSelectionEnd() override;
157 /** Selects a part of the text (ruler does nothing). */
158 virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
160 /** Returns the entire text. */
161 virtual OUString SAL_CALL getText() override;
163 /** Returns the specified range [Start,End) of the text. */
164 virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
166 /** Returns the specified text portion. */
167 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
168 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
169 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
171 /** Copies the specified text range into the clipboard (ruler does nothing). */
172 virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
174 virtual sal_Bool SAL_CALL scrollSubstringTo( sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override;
176 // events -----------------------------------------------------------------
177 public:
178 /** Sends a caret changed event to all listeners. */
179 virtual void SendCaretEvent() override;
181 // helpers ----------------------------------------------------------------
182 private:
184 /** @throws css::lang::IndexOutOfBoundsException if the specified character position is invalid (outside 0..len-1). */
185 void ensureValidIndex( sal_Int32 nIndex ) const;
186 /** @throws css::lang::IndexOutOfBoundsException if the specified character position is invalid (outside 0..len). */
187 void ensureValidIndexWithEnd( sal_Int32 nIndex ) const;
188 /** @throws css::lang::IndexOutOfBoundsException if the specified character range [Start,End) is invalid.
189 @descr If Start>End, swaps Start and End before checking. */
190 void ensureValidRange( sal_Int32& rnStartIndex, sal_Int32& rnEndIndex ) const;
192 /** Returns the VCL ruler control. Assumes a living object. */
193 ScCsvRuler& implGetRuler() const;
195 /** Builds the entire string buffer.
197 @throws css::uno::RuntimeException
199 void constructStringBuffer();
200 /** Returns the character count of the text. */
201 sal_Int32 implGetTextLength() const;
203 /** Returns true, if the character at the specified index has a split. */
204 bool implHasSplit( sal_Int32 nApiPos );
206 /** Returns the first character index with equal formatting as at nApiPos. */
207 sal_Int32 implGetFirstEqualFormatted( sal_Int32 nApiPos );
208 /** Returns the last character index with equal formatting as at nApiPos. */
209 sal_Int32 implGetLastEqualFormatted( sal_Int32 nApiPos );
212 class ScCsvGrid;
213 class ScAccessibleCsvCell;
215 /** Accessible class representing the CSV grid control. */
216 class ScAccessibleCsvGrid : public cppu::ImplInheritanceHelper<
217 ScAccessibleCsvControl,
218 css::accessibility::XAccessible,
219 css::accessibility::XAccessibleTable,
220 css::accessibility::XAccessibleSelection>
222 protected:
223 typedef std::map< sal_Int64, rtl::Reference<ScAccessibleCsvCell> > XAccessibleSet;
225 private:
226 XAccessibleSet maAccessibleChildren;
228 public:
229 explicit ScAccessibleCsvGrid( ScCsvGrid& rGrid );
230 virtual ~ScAccessibleCsvGrid() override;
231 virtual void SAL_CALL disposing() override;
233 // XAccessibleComponent ---------------------------------------------------
234 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override { return this; }
236 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
238 /** Returns the cell at the specified point. */
239 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& rPoint ) override;
241 virtual OUString SAL_CALL getAccessibleDescription( ) override;
242 virtual OUString SAL_CALL getAccessibleName( ) override;
244 virtual sal_Int32 SAL_CALL getForeground( ) override;
246 virtual sal_Int32 SAL_CALL getBackground( ) override;
248 virtual sal_Int16 SAL_CALL getAccessibleRole( ) override { return css::accessibility::AccessibleRole::TABLE; }
250 // XAccessibleContext -----------------------------------------------------
252 /** Returns the child count (count of cells in the table). */
253 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
255 /** Returns the specified child cell. */
256 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 nIndex ) override;
258 /** Returns the relation to the ruler control. */
259 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
261 /** Returns the current set of states. */
262 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
264 // XAccessibleTable -------------------------------------------------------
266 /** Returns the number of rows in the table. */
267 virtual sal_Int32 SAL_CALL getAccessibleRowCount() override;
269 /** Returns the number of columns in the table. */
270 virtual sal_Int32 SAL_CALL getAccessibleColumnCount() override;
272 /** Returns the description of the specified row in the table. */
273 virtual OUString SAL_CALL getAccessibleRowDescription( sal_Int32 nRow ) override;
275 /** Returns the description text of the specified column in the table. */
276 virtual OUString SAL_CALL getAccessibleColumnDescription( sal_Int32 nColumn ) override;
278 /** Returns the number of rows occupied at a specified row and column.
279 @descr Returns always 1 (Merged cells not supported). */
280 virtual sal_Int32 SAL_CALL getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) override;
282 /** Returns the number of rows occupied at a specified row and column.
283 @descr Returns always 1 (Merged cells not supported). */
284 virtual sal_Int32 SAL_CALL getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) override;
286 /** Returns the row headers as an AccessibleTable. */
287 virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleRowHeaders() override;
289 /** Returns the column headers as an AccessibleTable. */
290 virtual css::uno::Reference< css::accessibility::XAccessibleTable > SAL_CALL getAccessibleColumnHeaders() override;
292 /** Returns the selected rows as a sequence. */
293 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleRows() override;
295 /** Returns the selected columns as a sequence. */
296 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getSelectedAccessibleColumns() override;
298 /** Returns true, if the specified row is selected. */
299 virtual sal_Bool SAL_CALL isAccessibleRowSelected( sal_Int32 nRow ) override;
301 /** Returns true, if the specified column is selected. */
302 virtual sal_Bool SAL_CALL isAccessibleColumnSelected( sal_Int32 nColumn ) override;
304 /** Returns the accessible cell object at the specified position. */
305 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) override;
307 /** Returns the caption object of the table. */
308 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleCaption() override;
310 /** Returns the summary description object of the table. */
311 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleSummary() override;
313 /** Returns true, if the cell at a specified position is selected. */
314 virtual sal_Bool SAL_CALL isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) override;
316 /** Returns the child index of the cell at the specified position. */
317 virtual sal_Int64 SAL_CALL getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) override;
319 /** Returns the row index of the specified child. */
320 virtual sal_Int32 SAL_CALL getAccessibleRow( sal_Int64 nChildIndex ) override;
322 /** Returns the column index of the specified child. */
323 virtual sal_Int32 SAL_CALL getAccessibleColumn( sal_Int64 nChildIndex ) override;
325 // XAccessibleSelection ---------------------------------------------------
327 /** Selects the specified child (selects the entire column or the entire table). */
328 virtual void SAL_CALL selectAccessibleChild( sal_Int64 nChildIndex ) override;
330 /** Returns true, if the specified child is selected. */
331 virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int64 nChildIndex ) override;
333 /** Deselects all cells. */
334 virtual void SAL_CALL clearAccessibleSelection() override;
336 /** Selects all cells. */
337 virtual void SAL_CALL selectAllAccessibleChildren() override;
339 /** Returns the count of selected children. */
340 virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override;
342 /** Returns the child with the specified index in all selected children. */
343 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
345 /** Deselects the child with the specified index in all selected children. */
346 virtual void SAL_CALL deselectAccessibleChild( sal_Int64 nSelectedChildIndex ) override;
348 // events -----------------------------------------------------------------
349 public:
350 /** Sends a GetFocus or LoseFocus event to all listeners. */
351 virtual void SendFocusEvent( bool bFocused ) override;
352 /** Sends a table model changed event for changed cell contents to all listeners. */
353 virtual void SendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows ) override;
354 /** Sends a table model changed event for an inserted column to all listeners. */
355 virtual void SendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn ) override;
356 /** Sends a table model changed event for a removed column to all listeners. */
357 virtual void SendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn ) override;
359 // helpers ----------------------------------------------------------------
360 private:
362 /** @throws css::lang::IndexOutOfBoundsException if nIndex is not a valid child index. */
363 void ensureValidIndex( sal_Int64 nIndex ) const;
364 /** @Throws css::lang::IndexOutOfBoundsException if the specified position is invalid. */
365 void ensureValidPosition( sal_Int32 nRow, sal_Int32 nColumn ) const;
367 /** Returns the VCL grid control. Assumes a living object. */
368 ScCsvGrid& implGetGrid() const;
370 /** Returns true, if the specified column (including header) is selected. */
371 bool implIsColumnSelected( sal_Int32 nColumn ) const;
372 /** Selects the specified column (including header). */
373 void implSelectColumn( sal_Int32 nColumn, bool bSelect );
375 /** Returns the count of visible rows in the table (including header). */
376 sal_Int32 implGetRowCount() const;
377 /** Returns the total column count in the table (including header). */
378 sal_Int32 implGetColumnCount() const;
379 /** Returns the count of selected columns in the table. */
380 sal_Int32 implGetSelColumnCount() const;
381 /** Returns the total cell count in the table (including header). */
382 sal_Int64 implGetCellCount() const { return static_cast<sal_Int64>(implGetRowCount()) * static_cast<sal_Int64>(implGetColumnCount()); }
384 /** Returns the row index from cell index (including header). */
385 sal_Int32 implGetRow( sal_Int64 nIndex ) const { return nIndex / implGetColumnCount(); }
386 /** Returns the column index from cell index (including header). */
387 sal_Int32 implGetColumn( sal_Int64 nIndex ) const { return nIndex % implGetColumnCount(); }
388 /** Returns the absolute column index of the nSelColumn-th selected column. */
389 sal_Int32 implGetSelColumn( sal_Int32 nSelColumn ) const;
390 /** Returns the child index from cell position (including header). */
391 sal_Int64 implGetIndex( sal_Int32 nRow, sal_Int32 nColumn ) const { return static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(implGetColumnCount()) + nColumn; }
393 /** Returns the contents of the specified cell (including header). Indexes must be valid. */
394 OUString implGetCellText( sal_Int32 nRow, sal_Int32 nColumn ) const;
395 /** Creates a new accessible object of the specified cell. Indexes must be valid. */
396 rtl::Reference<ScAccessibleCsvCell> implCreateCellObj(sal_Int32 nRow, sal_Int32 nColumn);
398 css::uno::Reference<css::accessibility::XAccessible> getAccessibleCell(sal_Int32 nRow, sal_Int32 nColumn);
401 /** Accessible class representing a cell of the CSV grid control. */
402 class ScAccessibleCsvCell : public cppu::ImplInheritanceHelper<
403 ScAccessibleCsvControl,
404 css::accessibility::XAccessible>
405 , public ::accessibility::AccessibleStaticTextBase
407 protected:
408 typedef ::std::unique_ptr< SvxEditSource > SvxEditSourcePtr;
410 private:
411 OUString maCellText; /// The text contents of this cell.
412 sal_Int32 mnLine; /// The grid line index (core index).
413 sal_uInt32 mnColumn; /// The grid column index (core index).
414 sal_Int32 mnIndex; /// The index of the cell in the table.
416 public:
417 explicit ScAccessibleCsvCell(
418 ScCsvGrid& rGrid,
419 OUString aCellText,
420 sal_Int32 nRow, sal_Int32 nColumn);
421 virtual ~ScAccessibleCsvCell() override;
423 virtual void SAL_CALL disposing() override;
425 // XAccessibleComponent ---------------------------------------------------
427 /** Sets the focus to the column of this cell. */
428 virtual void SAL_CALL grabFocus() override;
430 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
432 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override { return this; }
434 virtual OUString SAL_CALL getAccessibleDescription( ) override;
435 virtual OUString SAL_CALL getAccessibleName( ) override;
436 virtual sal_Int16 SAL_CALL getAccessibleRole( ) override { return css::accessibility::AccessibleRole::TEXT; }
438 virtual sal_Int32 SAL_CALL getForeground( ) override;
440 virtual sal_Int32 SAL_CALL getBackground( ) override;
442 // XAccessibleContext -----------------------------------------------------
444 /** Returns the child count. */
445 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
447 /** Returns the specified child. */
448 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 nIndex ) override;
450 /** Returns the index of this cell in the table. */
451 virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override;
453 /** Returns the relation to the ruler control. */
454 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
456 /** Returns the current set of states. */
457 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
459 // XInterface -------------------------------------------------------------
461 DECLARE_XINTERFACE()
463 // XTypeProvider ----------------------------------------------------------
465 DECLARE_XTYPEPROVIDER()
467 private:
468 /** Returns the VCL grid control. Assumes a living object. */
469 ScCsvGrid& implGetGrid() const;
470 /** Returns the pixel position of the cell (rel. to parent), regardless of visibility. */
471 Point implGetRealPos() const;
472 /** Returns the width of the character count */
473 sal_uInt32 implCalcPixelWidth(sal_uInt32 nChars) const;
474 /** Returns the pixel size of the cell, regardless of visibility. */
475 Size implGetRealSize() const;
476 /** Returns the bounding box of the cell relative in the table. */
477 virtual css::awt::Rectangle implGetBounds() override;
479 /** Creates the edit source the text helper needs. */
480 ::std::unique_ptr< SvxEditSource > implCreateEditSource();
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */