1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SVTOOLS_TABLE_TABLEMODEL_HXX
21 #define INCLUDED_SVTOOLS_TABLE_TABLEMODEL_HXX
23 #include <svtools/svtdllapi.h>
24 #include <svtools/table/tabletypes.hxx>
25 #include <svtools/table/tablerenderer.hxx>
26 #include <svtools/table/tableinputhandler.hxx>
28 #include <com/sun/star/style/VerticalAlignment.hpp>
29 #include <com/sun/star/style/HorizontalAlignment.hpp>
31 #include <sal/types.h>
33 #include <boost/optional.hpp>
35 #include <o3tl/typed_flags_set.hxx>
37 namespace svt
{ namespace table
{ class ITableDataSort
; } }
41 enum class ColumnAttributeGroup
44 /// denotes column attributes related to the width of the column
46 /// denotes column attributes related to the appearance of the column, i.e. those relevant for rendering
48 /// denotes the entirety of column attributes
53 template<> struct typed_flags
<ColumnAttributeGroup
> : is_typed_flags
<ColumnAttributeGroup
, 0x03> {};
57 namespace svt
{ namespace table
59 //= ScrollbarVisibility
60 enum ScrollbarVisibility
62 /** enumeration value denoting that a scrollbar should never be visible, even
66 /** enumeration value denoting that a scrollbar should be visible when needed only
69 /** enumeration value denoting that a scrollbar should always be visible, even
70 if not needed normally
76 //= ITableModelListener
78 /** declares an interface to be implemented by components interested in
79 changes in an ->ITableModel
81 class SAL_NO_VTABLE ITableModelListener
: public std::enable_shared_from_this
< ITableModelListener
>
84 /** notifies the listener that one or more rows have been inserted into
88 the index of the first newly inserted row
90 the index of the last newly inserted row. Must not be smaller
93 virtual void rowsInserted( RowPos first
, RowPos last
) = 0;
95 /** notifies the listener that one or more rows have been removed from
99 the old index of the first removed row. If this is <code>-1</code>, then all
100 rows have been removed from the model.
102 the old index of the last removed row. Must not be smaller
105 virtual void rowsRemoved( RowPos first
, RowPos last
) = 0;
107 /** notifies the listener that one or more columns have been inserted into
110 virtual void columnInserted() = 0;
112 /** notifies the listener that one or more columns have been removed from
115 virtual void columnRemoved() = 0;
117 /** notifies the listener that all columns have been removed form the model
119 virtual void allColumnsRemoved() = 0;
121 /** notifies the listener that a rectangular cell range in the table
124 Listeners are required to discard any possibly cached information
125 they have about the cells in question, in particular any possibly
128 virtual void cellsUpdated( RowPos
const i_firstRow
, RowPos
const i_lastRow
) = 0;
130 /** notifies the listener that attributes of a given column changed
133 the position of the column whose attributes changed
134 @param i_attributeGroup
135 a combination of one or more <code>COL_ATTRS_*</code> flags, denoting the attribute group(s)
136 in which changes occurred.
138 virtual void columnChanged( ColPos
const i_column
, ColumnAttributeGroup
const i_attributeGroup
) = 0;
140 /** notifies the listener that the metrics of the table changed.
142 Metrics here include the column header height, the row header width, the row height, and the presence
143 of both the row and column header.
145 virtual void tableMetricsChanged() = 0;
147 /// deletes the listener instance
148 virtual ~ITableModelListener(){};
150 typedef std::shared_ptr
< ITableModelListener
> PTableModelListener
;
155 /** interface to be implemented by table column models
157 class SAL_NO_VTABLE IColumnModel
160 /** returns the name of the column
162 Column names should be human-readable, but not necessarily unique
163 within a given table.
167 virtual OUString
getName() const = 0;
169 /** retrieves the help text to be displayed for the column.
171 virtual OUString
getHelpText() const = 0;
173 /** determines whether the column can be interactively resized
179 virtual bool isResizable() const = 0;
181 /** denotes the relative flexibility of the column
183 This flexibility is taken into account when a table control auto-resizes its columns, because the available
184 space changed. In this case, the columns grow or shrink according to their flexibility.
186 A value of 0 means the column is not auto-resized at all.
188 virtual sal_Int32
getFlexibility() const = 0;
190 /** returns the width of the column, in app-font units
192 The returned value must be a positive ->TableMetrics value.
198 virtual TableMetrics
getWidth() const = 0;
200 /** sets a new width for the column
203 the new width, app-font units
207 virtual void setWidth( TableMetrics _nWidth
) = 0;
209 /** returns the minimum width of the column, in app-font units, or 0 if the column
210 does not have a minimal width
216 virtual TableMetrics
getMinWidth() const = 0;
218 /** returns the maximum width of the column, in app-font units, or 0 if the column
219 does not have a minimal width
225 virtual TableMetrics
getMaxWidth() const = 0;
227 /** retrieves the horizontal alignment to be used for content in this cell
229 virtual css::style::HorizontalAlignment
getHorizontalAlign() = 0;
231 /// deletes the column model instance
232 virtual ~IColumnModel() { }
234 typedef std::shared_ptr
< IColumnModel
> PColumnModel
;
239 /** declares the interface to implement by an abstract table model
241 class SAL_NO_VTABLE SVT_DLLPUBLIC ITableModel
244 /** returns the number of columns in the table
246 virtual TableSize
getColumnCount() const = 0;
248 /** returns the number of rows in the table
250 virtual TableSize
getRowCount() const = 0;
252 /** determines whether the table has column headers
254 If this method returns <TRUE/>, the renderer returned by
255 ->getRenderer must be able to render column headers.
259 virtual bool hasColumnHeaders() const = 0;
261 /** determines whether the table has row headers
263 If this method returns <TRUE/>, the renderer returned by
264 ->getRenderer must be able to render row headers.
268 virtual bool hasRowHeaders() const = 0;
270 /** returns a model for a certain column
273 the index of the column in question. Must be greater than or
274 equal 0, and smaller than the return value of ->getColumnCount()
277 the model of the column in question. Must not be <NULL/>
279 virtual PColumnModel
getColumnModel( ColPos column
) = 0;
281 /** returns a renderer which is able to paint the table represented
284 @return the renderer to use. Must not be <NULL/>
286 virtual PTableRenderer
getRenderer() const = 0;
288 /** returns the component handling input in a view associated with the model
290 virtual PTableInputHandler
getInputHandler() const = 0;
292 /** determines the height of rows in the table.
295 the logical height of rows in the table, in app-font units. The height must be
298 virtual TableMetrics
getRowHeight() const = 0;
300 /** determines the height of the column header row
302 This method is not to be called if ->hasColumnHeaders()
306 the logical height of the column header row, in app-font units.
307 Must be greater than 0.
309 virtual TableMetrics
getColumnHeaderHeight() const = 0;
311 /** determines the width of the row header column
313 This method is not to be called if ->hasRowHeaders()
317 the logical width of the row header column, in app-font units.
318 Must be greater than 0.
320 virtual TableMetrics
getRowHeaderWidth() const = 0;
322 /** returns the visibilit mode of the vertical scrollbar
324 virtual ScrollbarVisibility
getVerticalScrollbarVisibility() const = 0;
326 /** returns the visibilit mode of the horizontal scrollbar
328 virtual ScrollbarVisibility
getHorizontalScrollbarVisibility() const = 0;
330 /** adds a listener to be notified of changes in the table model
332 virtual void addTableModelListener( const PTableModelListener
& i_listener
) = 0;
334 /** remove a listener to be notified of changes in the table model
336 virtual void removeTableModelListener( const PTableModelListener
& i_listener
) = 0;
338 /** retrieves the content of the given cell
340 virtual void getCellContent( ColPos
const i_col
, RowPos
const i_row
, css::uno::Any
& o_cellContent
) = 0;
342 /** returns an object which should be displayed as tooltip for the given cell
344 At the moment, only string-convertible values are supported here. In the future, one might imagine displaying
345 scaled-down versions of a graphic in a cell, and a larger version of that very graphic as tooltip.
347 If no tooltip object is provided, then the cell content is used, and displayed as tooltip for the cell
348 if and only if it doesn't fit into the cell's space itself.
351 The column index of the cell in question. COL_ROW_HEADERS is a valid argument here.
353 The row index of the cell in question.
355 takes the tooltip object upon return.
357 virtual void getCellToolTip( ColPos
const i_col
, RowPos
const i_row
, css::uno::Any
& o_cellToolTip
) = 0;
359 /** retrieves title of a given row
361 virtual css::uno::Any
getRowHeading( RowPos
const i_rowPos
) const = 0;
363 /** returns the color to be used for rendering the grid lines.
365 If this value is not set, a default color from the style settings will be used.
367 virtual ::boost::optional
< ::Color
> getLineColor() const = 0;
369 /** returns the color to be used for rendering the header background.
371 If this value is not set, a default color from the style settings will be used.
373 virtual ::boost::optional
< ::Color
> getHeaderBackgroundColor() const = 0;
375 /** returns the color to be used for rendering the header text.
377 If this value is not set, a default color from the style settings will be used.
379 virtual ::boost::optional
< ::Color
> getHeaderTextColor() const = 0;
381 /** returns the color to be used for the background of selected cells, when the control has the focus
383 If this value is not set, a default color from the style settings will be used.
385 virtual ::boost::optional
< ::Color
> getActiveSelectionBackColor() const = 0;
387 /** returns the color to be used for the background of selected cells, when the control does not have the focus
389 If this value is not set, a default color from the style settings will be used.
391 virtual ::boost::optional
< ::Color
> getInactiveSelectionBackColor() const = 0;
393 /** returns the color to be used for the text of selected cells, when the control has the focus
395 If this value is not set, a default color from the style settings will be used.
397 virtual ::boost::optional
< ::Color
> getActiveSelectionTextColor() const = 0;
399 /** returns the color to be used for the text of selected cells, when the control does not have the focus
401 If this value is not set, a default color from the style settings will be used.
403 virtual ::boost::optional
< ::Color
> getInactiveSelectionTextColor() const = 0;
405 /** returns the color to be used for rendering cell texts.
407 If this value is not set, a default color from the style settings will be used.
409 virtual ::boost::optional
< ::Color
> getTextColor() const = 0;
411 /** returns the color to be used for text lines (underline, strikethrough) when rendering cell text.
413 If this value is not set, a default color from the style settings will be used.
415 virtual ::boost::optional
< ::Color
> getTextLineColor() const = 0;
417 /** returns the colors to be used for the row backgrounds.
419 If this value is not set, every second row will have a background color derived from the style settings's
420 selection color, the other rows will not have a special background at all.
422 If this value is an empty sequence, the rows will not have a special background at all, instead the
423 normal background of the complete control will be used.
425 If value is a non-empty sequence, then rows will have the background colors as specified in the sequence,
426 in alternating order.
428 virtual ::boost::optional
< ::std::vector
< ::Color
> >
429 getRowBackgroundColors() const = 0;
431 /** determines the vertical alignment of content within a cell
433 virtual css::style::VerticalAlignment
getVerticalAlign() const = 0;
435 /** returns an adapter to the sorting functionality of the model
437 It is legitimate to return <NULL/> here, in this case, the table model does not support sorting.
439 virtual ITableDataSort
* getSortAdapter() = 0;
441 /** returns enabled state.
443 virtual bool isEnabled() const = 0;
445 /// destroys the table model instance
446 virtual ~ITableModel() { }
448 typedef std::shared_ptr
< ITableModel
> PTableModel
;
451 } } // namespace svt::table
454 #endif // INCLUDED_SVTOOLS_TABLE_TABLEMODEL_HXX
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */