LibreOffice Module toolkit (master) 1
tablecontrol_impl.hxx
Go to the documentation of this file.
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
20#pragma once
21
24
27
28#include <vcl/seleng.hxx>
29
30#include <vector>
31
32class ScrollBar;
33class ScrollBarBox;
34
35namespace svt::table
36{
38 {
41 {
42 }
43
44 MutableColumnMetrics( tools::Long const i_startPixel, tools::Long const i_endPixel )
45 :ColumnMetrics( i_startPixel, i_endPixel )
46 {
47 }
48
49 tools::Long getStart() const { return nStartPixel; }
50 tools::Long getEnd() const { return nEndPixel; }
51
52 void move( tools::Long const i_offset ) { nStartPixel += i_offset; nEndPixel += i_offset; }
53
55 };
56
58 {
59 bool operator()( MutableColumnMetrics const& i_lhs, MutableColumnMetrics const& i_rhs )
60 {
61 return i_lhs.getEnd() < i_rhs.getStart();
62 }
63 };
64
65 typedef ::std::vector< MutableColumnMetrics > ColumnPositions;
66
67 class TableControl;
68 class TableDataWindow;
69 class TableFunctionSet;
70
71
72 //= TableControl_Impl
73
76 {
77 friend class TableGeometry;
78 friend class TableRowGeometry;
79 friend class TableColumnGeometry;
80 friend class SuspendInvariants;
81
82 private:
91
98
101
104
109
111
123 //selection engine - for determining selection range, e.g. single, multiple
124 std::unique_ptr<SelectionEngine> m_pSelEngine;
125 //vector which contains the selected rows
126 std::vector<RowPos> m_aSelectedRows;
127 //part of selection engine
128 std::unique_ptr<TableFunctionSet> m_pTableFunctionSet;
129 //part of selection engine
132
133 vcl::AccessibleFactoryAccess m_aFactoryAccess;
135
136 public:
137 void setModel( const PTableModel& _pModel );
138
140
141 RowPos getCurRow() const { return m_nCurRow; }
142
143 RowPos getAnchor() const { return m_nAnchor; }
144 void setAnchor( RowPos const i_anchor ) { m_nAnchor = i_anchor; }
145
146 RowPos getTopRow() const { return m_nTopRow; }
148
149 const TableControl& getAntiImpl() const { return m_rAntiImpl; }
151
152 public:
153 explicit TableControl_Impl( TableControl& _rAntiImpl );
154 virtual ~TableControl_Impl() override;
155
158 void onResize();
159
162 void doPaintContent(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rUpdateRect);
163
169 bool goTo( ColPos _nColumn, RowPos _nRow );
170
179 void ensureVisible( ColPos _nColumn, RowPos _nRow );
180
183 OUString getCellContentAsString( RowPos const i_row, ColPos const i_col );
184
186 static int getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current);
187
188 void invalidateRect(const tools::Rectangle &rInvalidateRect);
189
191 void invalidateSelectedRegion( RowPos _nPrevRow, RowPos _nCurRow );
192
200 void invalidateRowRange( RowPos const i_firstRow, RowPos const i_lastRow );
201
204 void invalidateRow( RowPos const i_row ) { invalidateRowRange( i_row, i_row ); }
205
209
210 void checkCursorPosition();
211
212 bool hasRowSelection() const { return !m_aSelectedRows.empty(); }
213 size_t getSelectedRowCount() const { return m_aSelectedRows.size(); }
214 RowPos getSelectedRowIndex( size_t const i_selectionIndex ) const;
215
221 bool markRowAsDeselected( RowPos const i_rowIndex );
222
227 bool markRowAsSelected( RowPos const i_rowIndex );
228
234
240
241 void commitAccessibleEvent( sal_Int16 const i_eventID );
242 void commitCellEvent( sal_Int16 const i_eventID, const css::uno::Any& i_newValue, const css::uno::Any& i_oldValue );
243 void commitTableEvent( sal_Int16 const i_eventID, const css::uno::Any& i_newValue, const css::uno::Any& i_oldValue );
244
245 // ITableControl
246 virtual void hideCursor() override;
247 virtual void showCursor() override;
248 virtual bool dispatchAction( TableControlAction _eAction ) override;
249 virtual SelectionEngine* getSelEngine() override;
250 virtual PTableModel getModel() const override;
251 virtual ColPos getCurrentColumn() const override;
252 virtual RowPos getCurrentRow() const override;
253 virtual void activateCell( ColPos const i_col, RowPos const i_row ) override;
254 virtual ::Size getTableSizePixel() const override;
255 virtual void setPointer( PointerStyle i_pointer ) override;
256 virtual void captureMouse() override;
257 virtual void releaseMouse() override;
258 virtual void invalidate( TableArea const i_what ) override;
259 virtual tools::Long pixelWidthToAppFont( tools::Long const i_pixels ) const override;
260 virtual void hideTracking() override;
261 virtual void showTracking( tools::Rectangle const & i_location, ShowTrackFlags const i_flags ) override;
262 RowPos getRowAtPoint( const Point& rPoint ) const;
263 ColPos getColAtPoint( const Point& rPoint ) const;
264 virtual TableCell hitTest( const Point& rPoint ) const override;
265 virtual ColumnMetrics getColumnMetrics( ColPos const i_column ) const override;
266 virtual bool isRowSelected( RowPos i_row ) const override;
267
268
269 tools::Long appFontWidthToPixel( tools::Long const i_appFontUnits ) const;
270
272 const TableDataWindow& getDataWindow() const { return *m_pDataWindow; }
275
276 tools::Rectangle calcHeaderRect( bool bColHeader );
277 tools::Rectangle calcHeaderCellRect( bool bColHeader, sal_Int32 nPos );
279 tools::Rectangle calcCellRect( sal_Int32 nRow, sal_Int32 nCol ) const;
280
281 // A11Y
282 css::uno::Reference< css::accessibility::XAccessible >
283 getAccessible( vcl::Window& i_parentWindow );
284 void disposeAccessible();
285
286 bool isAccessibleAlive() const { return impl_isAccessibleAlive(); }
287
288 // ITableModelListener
289 virtual void rowsInserted( RowPos first, RowPos last ) override;
290 virtual void rowsRemoved( RowPos first, RowPos last ) override;
291 virtual void columnInserted() override;
292 virtual void columnRemoved() override;
293 virtual void allColumnsRemoved() override;
294 virtual void cellsUpdated( RowPos const i_firstRow, RowPos const i_lastRow ) override;
295 virtual void columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup ) override;
296 virtual void tableMetricsChanged() override;
297
298 private:
299 bool impl_isAccessibleAlive() const;
301 sal_Int16 const i_eventID,
302 css::uno::Any const & i_newValue
303 );
304
310 void impl_ni_doSwitchCursor( bool _bOn );
311
318 TableSize impl_getVisibleRows( bool _bAcceptPartialRow ) const;
319
332 TableSize impl_getVisibleColumns( bool _bAcceptPartialCol ) const;
333
336 void impl_getCellRect( ColPos _nColumn, RowPos _nRow, tools::Rectangle& _rCellRect ) const;
337
344
348
358 void impl_ni_relayout( ColPos const i_assumeInflexibleColumnsUpToIncluding = COL_INVALID );
359
376 ColPos const i_assumeInflexibleColumnsUpToIncluding,
377 bool const i_assumeVerticalScrollbar,
378 ::std::vector< tools::Long >& o_newColWidthsPixel
379 ) const;
380
384 tools::Rectangle const & i_dataCellPlayground,
385 bool const i_verticalScrollbar,
386 bool const i_horizontalScrollbar
387 );
388
400
403 TableSize impl_scrollRows( TableSize const i_rowDelta );
404
416
419 TableSize impl_scrollColumns( TableSize const i_columnDelta );
420
431
438
441 ColPos impl_getColumnForOrdinate( tools::Long const i_ordinate ) const;
442
445 RowPos impl_getRowForAbscissa( tools::Long const i_abscissa ) const;
446
448 void impl_invalidateColumn( ColPos const i_column );
449
450 DECL_LINK( OnScroll, ScrollBar*, void );
451 DECL_LINK( OnUpdateScrollbars, void*, void );
452 };
453
454 //see seleng.hxx, seleng.cxx, FunctionSet overridables, part of selection engine
456 {
457 private:
460
461 public:
462 explicit TableFunctionSet(TableControl_Impl* _pTableControl);
463 virtual ~TableFunctionSet() override;
464
465 virtual void BeginDrag() override;
466 virtual void CreateAnchor() override;
467 virtual void DestroyAnchor() override;
468 virtual void SetCursorAtPoint(const Point& rPoint, bool bDontSelectAtCursor = false) override;
469 virtual bool IsSelectionAtPoint( const Point& rPoint ) override;
470 virtual void DeselectAtPoint( const Point& rPoint ) override;
471 virtual void DeselectAll() override;
472 };
473
474
475} // namespace svt::table
476
477
478
479/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
defines a callback interface to be implemented by a concrete table control
declares an interface to be implemented by components interested in changes in an ->ITableModel
Definition: tablemodel.hxx:82
bool markAllRowsAsSelected()
marks all rows as selected
void impl_getCellRect(ColPos _nColumn, RowPos _nRow, tools::Rectangle &_rCellRect) const
determines the rectangle occupied by the given cell
RowPos getRowAtPoint(const Point &rPoint) const
virtual void invalidate(TableArea const i_what) override
invalidates the table window
TableSize impl_getVisibleColumns(bool _bAcceptPartialCol) const
returns the number of visible columns
void invalidateRowRange(RowPos const i_firstRow, RowPos const i_lastRow)
invalidates the part of the data window which is covered by the given rows
tools::Long m_nRowHeightPixel
the height of a single row in the table, measured in pixels
tools::Long m_nRowHeaderWidthPixel
the width of the row header column in the table, measured in pixels
TableSize impl_ni_ScrollColumns(TableSize _nColumnDelta)
scrolls the view by the given number of columns
virtual TableCell hitTest(const Point &rPoint) const override
does a hit test for the given pixel coordinates
void commitAccessibleEvent(sal_Int16 const i_eventID)
tools::Rectangle calcHeaderCellRect(bool bColHeader, sal_Int32 nPos)
tools::Rectangle calcCellRect(sal_Int32 nRow, sal_Int32 nCol) const
PTableInputHandler m_pInputHandler
the input handler to use, usually the input handler as provided by ->m_pModel
DECL_LINK(OnScroll, ScrollBar *, void)
virtual void columnChanged(ColPos const i_column, ColumnAttributeGroup const i_attributeGroup) override
notifies the listener that attributes of a given column changed
TableSize impl_getVisibleRows(bool _bAcceptPartialRow) const
returns the number of visible rows.
virtual void allColumnsRemoved() override
notifies the listener that all columns have been removed from the model
static int getRowSelectedNumber(const ::std::vector< RowPos > &selectedRows, RowPos current)
returns the position of the current row in the selection vector
const TableDataWindow & getDataWindow() const
virtual void tableMetricsChanged() override
notifies the listener that the metrics of the table changed.
virtual void columnInserted() override
notifies the listener that one or more columns have been inserted into the table
virtual void rowsInserted(RowPos first, RowPos last) override
notifies the listener that one or more rows have been inserted into the table
const PTableInputHandler & getInputHandler() const
virtual void columnRemoved() override
notifies the listener that one or more columns have been removed from the table
void invalidateSelectedRows()
invalidates all selected rows
OUString getCellContentAsString(RowPos const i_row, ColPos const i_col)
retrieves the content of the given cell, converted to a string
TableSize impl_ni_ScrollRows(TableSize _nRowDelta)
scrolls the view by the given number of rows
ColumnPositions m_aColumnWidths
info about the widths of our columns
void setModel(const PTableModel &_pModel)
void setAnchor(RowPos const i_anchor)
void invalidateRect(const tools::Rectangle &rInvalidateRect)
ColPos getColAtPoint(const Point &rPoint) const
virtual void showTracking(tools::Rectangle const &i_location, ShowTrackFlags const i_flags) override
shows a tracking rectangle
virtual void setPointer(PointerStyle i_pointer) override
sets a new mouse pointer for the table window
const TableControl & getAntiImpl() const
void commitCellEvent(sal_Int16 const i_eventID, const css::uno::Any &i_newValue, const css::uno::Any &i_oldValue)
tools::Long m_nColHeaderHeightPixel
the height of the column header row in the table, measured in pixels
tools::Long appFontWidthToPixel(tools::Long const i_appFontUnits) const
tools::Rectangle impl_getAllVisibleDataCellArea() const
retrieves the area occupied by all (at least partially) visible data cells.
virtual void hideTracking() override
hides a previously shown tracking rectangle
virtual ColPos getCurrentColumn() const override
returns the index of the currently active column
RowPos impl_getRowForAbscissa(tools::Long const i_abscissa) const
retrieves the row which covers the given abscissa
void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow)
???
virtual tools::Long pixelWidthToAppFont(tools::Long const i_pixels) const override
calculates a width, given in pixels, into an AppFont-based width
void impl_ni_relayout(ColPos const i_assumeInflexibleColumnsUpToIncluding=COL_INVALID)
does a relayout of the table control
VclPtr< ScrollBar > m_pVScroll
the vertical scrollbar, if any
ColPos impl_getColumnForOrdinate(tools::Long const i_ordinate) const
retrieves the column which covers the given ordinate
std::vector< RowPos > m_aSelectedRows
VclPtr< TableDataWindow > m_pDataWindow
the window to contain all data content, including header bars
css::uno::Reference< css::accessibility::XAccessible > getAccessible(vcl::Window &i_parentWindow)
void doPaintContent(vcl::RenderContext &rRenderContext, const tools::Rectangle &_rUpdateRect)
paints the table control content which intersects with the given rectangle
virtual RowPos getCurrentRow() const override
returns the index of the currently active row
virtual PTableModel getModel() const override
returns the table model
TableControl & m_rAntiImpl
the control whose impl-instance we implement
VclPtr< ScrollBarBox > m_pScrollCorner
tools::Rectangle calcTableRect() const
bool markRowAsDeselected(RowPos const i_rowIndex)
removes the given row index from m_aSelectedRows
std::unique_ptr< SelectionEngine > m_pSelEngine
virtual bool isRowSelected(RowPos i_row) const override
determines whether a given row is selected
virtual void hideCursor() override
hides the cell cursor
void invalidateRow(RowPos const i_row)
invalidates the part of the data window which is covered by the given row
void impl_ni_updateCachedTableMetrics()
updates the cached table metrics (row height etc.)
PTableModel m_pModel
the model of the table control
virtual ::Size getTableSizePixel() const override
retrieves the size of the table window, in pixels
std::unique_ptr< TableFunctionSet > m_pTableFunctionSet
TableSize m_nRowCount
the number of rows in the table control. Cached model value.
TableSize m_nColumnCount
the number of columns in the table control. Cached model value.
virtual void captureMouse() override
captures the mouse to the table window
void impl_commitAccessibleEvent(sal_Int16 const i_eventID, css::uno::Any const &i_newValue)
VclPtr< ScrollBar > m_pHScroll
the horizontal scrollbar, if any
bool markAllRowsAsDeselected()
marks all rows as deselected
void onResize()
to be called when the anti-impl instance has been resized
tools::Rectangle impl_getAllVisibleCellsArea() const
retrieves the area occupied by the totality of (at least partially) visible cells
virtual void rowsRemoved(RowPos first, RowPos last) override
notifies the listener that one or more rows have been removed from the table
virtual void showCursor() override
shows the cell cursor
void impl_ni_positionChildWindows(tools::Rectangle const &i_dataCellPlayground, bool const i_verticalScrollbar, bool const i_horizontalScrollbar)
positions all child windows, e.g.
vcl::AccessibleFactoryAccess m_aFactoryAccess
virtual void releaseMouse() override
releases the mouse, after it had previously been captured
void commitTableEvent(sal_Int16 const i_eventID, const css::uno::Any &i_newValue, const css::uno::Any &i_oldValue)
TableControl_Impl(TableControl &_rAntiImpl)
void impl_ni_doSwitchCursor(bool _bOn)
toggles the cursor visibility
DECL_LINK(OnUpdateScrollbars, void *, void)
tools::Rectangle calcHeaderRect(bool bColHeader)
bool markRowAsSelected(RowPos const i_rowIndex)
marks the given row as selected, by putting it into m_aSelectedRows
virtual SelectionEngine * getSelEngine() override
returns selection engine
TableSize impl_scrollColumns(TableSize const i_columnDelta)
equivalent to impl_ni_ScrollColumns, but checks the instances invariants beforehand (in a non-product...
void impl_invalidateColumn(ColPos const i_column)
invalidates the window area occupied by the given column
RowPos getSelectedRowIndex(size_t const i_selectionIndex) const
virtual void activateCell(ColPos const i_col, RowPos const i_row) override
activates the given cell
virtual bool dispatchAction(TableControlAction _eAction) override
dispatches an action to the table control
tools::Long impl_ni_calculateColumnWidths(ColPos const i_assumeInflexibleColumnsUpToIncluding, bool const i_assumeVerticalScrollbar, ::std::vector< tools::Long > &o_newColWidthsPixel) const
calculates the new width of our columns, taking into account their min and max widths,...
virtual void cellsUpdated(RowPos const i_firstRow, RowPos const i_lastRow) override
notifies the listener that a rectangular cell range in the table has been updated
TableSize impl_scrollRows(TableSize const i_rowDelta)
equivalent to impl_ni_ScrollRows, but checks the instances invariants beforehand (in a non-product bu...
vcl::table::IAccessibleTableControl * m_pAccessibleTable
void impl_ni_updateCachedModelValues()
updates all cached model values
bool goTo(ColPos _nColumn, RowPos _nRow)
moves the cursor to the cell with the given coordinates
virtual ColumnMetrics getColumnMetrics(ColPos const i_column) const override
retrieves the metrics for a given column
void ensureVisible(ColPos _nColumn, RowPos _nRow)
ensures that the given coordinate is visible
a basic control which manages table-like data, i.e.
the window containing the content area (including headers) of a table control
virtual void SetCursorAtPoint(const Point &rPoint, bool bDontSelectAtCursor=false) override
virtual void DeselectAtPoint(const Point &rPoint) override
virtual void DestroyAnchor() override
virtual bool IsSelectionAtPoint(const Point &rPoint) override
virtual void DeselectAll() override
virtual void CreateAnchor() override
virtual void BeginDrag() override
TableControl_Impl * m_pTableControl
TableFunctionSet(TableControl_Impl *_pTableControl)
void SAL_CALL last(const css::awt::SpinEvent &rEvent) override
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
sal_Int32 TableSize
a value denoting the size of a table
Definition: tabletypes.hxx:29
sal_Int32 RowPos
a value denoting a row position within a table
Definition: tabletypes.hxx:34
std::shared_ptr< ITableModel > PTableModel
Definition: tablemodel.hxx:448
sal_Int32 ColPos
a value denoting a column position within a table
Definition: tabletypes.hxx:32
std::shared_ptr< ITableInputHandler > PTableInputHandler
::std::vector< MutableColumnMetrics > ColumnPositions
long Long
PointerStyle
bool operator()(MutableColumnMetrics const &i_lhs, MutableColumnMetrics const &i_rhs)
tools::Long nEndPixel
the end of the column, in pixels, plus 1.
tools::Long nStartPixel
the start of the column, in pixels.
void move(tools::Long const i_offset)
MutableColumnMetrics(tools::Long const i_startPixel, tools::Long const i_endPixel)
ColumnAttributeGroup
Definition: tablemodel.hxx:42
#define COL_INVALID
denotes an invalid column index
Definition: tabletypes.hxx:44
ShowTrackFlags