Branch libreoffice-5-0-4
[LibreOffice.git] / include / svtools / table / tablemodel.hxx
blob3027af84dc21b2a812a80543e983102d733f5739
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 #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>
27 #include <svtools/table/tablesort.hxx>
29 #include <com/sun/star/util/Color.hpp>
30 #include <com/sun/star/style/VerticalAlignment.hpp>
31 #include <com/sun/star/style/HorizontalAlignment.hpp>
33 #include <rtl/ref.hxx>
34 #include <sal/types.h>
36 #include <boost/optional.hpp>
37 #include <memory>
38 #include <o3tl/typed_flags_set.hxx>
40 enum class ColumnAttributeGroup
42 NONE = 0x00,
43 /// denotes column attributes related to the width of the column
44 WIDTH = 0x01,
45 /// denotes column attributes related to the appearance of the column, i.e. those relevant for rendering
46 APPEARANCE = 0x02,
47 /// denotes the entirety of column attributes
48 ALL = 0x03,
50 namespace o3tl
52 template<> struct typed_flags<ColumnAttributeGroup> : is_typed_flags<ColumnAttributeGroup, 0x03> {};
56 namespace svt { namespace table
58 //= ScrollbarVisibility
59 enum ScrollbarVisibility
61 /** enumeration value denoting that a scrollbar should never be visible, even
62 if needed normally
64 ScrollbarShowNever,
65 /** enumeration value denoting that a scrollbar should be visible when needed only
67 ScrollbarShowSmart,
68 /** enumeration value denoting that a scrollbar should always be visible, even
69 if not needed normally
71 ScrollbarShowAlways
75 //= ITableModelListener
77 /** declares an interface to be implemented by components interested in
78 changes in an ->ITableModel
80 class SAL_NO_VTABLE ITableModelListener : public std::enable_shared_from_this< ITableModelListener >
82 public:
83 /** notifies the listener that one or more rows have been inserted into
84 the table
86 @param first
87 the index of the first newly inserted row
88 @param last
89 the index of the last newly inserted row. Must not be smaller
90 than ->first
92 virtual void rowsInserted( RowPos first, RowPos last ) = 0;
94 /** notifies the listener that one or more rows have been removed from
95 the table
97 @param first
98 the old index of the first removed row. If this is <code>-1</code>, then all
99 rows have been removed from the model.
100 @param last
101 the old index of the last removed row. Must not be smaller
102 than ->first
104 virtual void rowsRemoved( RowPos first, RowPos last ) = 0;
106 /** notifies the listener that one or more columns have been inserted into
107 the table
109 @param first
110 the index of the first newly inserted row
111 @param last
112 the index of the last newly inserted row. Must not be smaller
113 than ->first
115 virtual void columnInserted( ColPos const i_colIndex ) = 0;
117 /** notifies the listener that one or more columns have been removed from
118 the table
120 @param i_colIndex
121 the old index of the removed column
123 virtual void columnRemoved( ColPos const i_colIndex ) = 0;
125 /** notifies the listener that all columns have been removed form the model
127 virtual void allColumnsRemoved() = 0;
129 /** notifies the listener that a rectangular cell range in the table
130 has been updated
132 Listeners are required to discard any possibly cached information
133 they have about the cells in question, in particular any possibly
134 cached cell values.
136 virtual void cellsUpdated( ColPos const i_firstCol, ColPos i_lastCol, RowPos const i_firstRow, RowPos const i_lastRow ) = 0;
138 /** notifies the listener that attributes of a given column changed
140 @param i_column
141 the position of the column whose attributes changed
142 @param i_attributeGroup
143 a combination of one or more <code>COL_ATTRS_*</code> flags, denoting the attribute group(s)
144 in which changes occurred.
146 virtual void columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup ) = 0;
148 /** notifies the listener that the metrics of the table changed.
150 Metrics here include the column header height, the row header width, the row height, and the presence
151 of both the row and column header.
153 virtual void tableMetricsChanged() = 0;
155 /// deletes the listener instance
156 virtual ~ITableModelListener(){};
158 typedef std::shared_ptr< ITableModelListener > PTableModelListener;
161 //= IColumnModel
163 /** interface to be implemented by table column models
165 class SAL_NO_VTABLE IColumnModel
167 public:
168 /** retrieves the ID of the column
170 The semantics of a column id is not defined. It's up to the
171 implementor of the ->IColumnModel, respectively the ->ITableModel
172 which provides the column models, to define such a semantics.
174 @return
175 the ID of the column. May be 0 if the table which the column
176 belongs to does not need and support column ids.
178 @see setID
180 virtual ::com::sun::star::uno::Any
181 getID() const = 0;
183 /** sets a new column ID
185 @return
186 <TRUE/> if setting the new ID was successful. A possible error
187 conditions is if you try to set an ID which is already used
188 by another column within the same table.
190 @see getID
192 virtual void setID( const ::com::sun::star::uno::Any& _nID ) = 0;
194 /** returns the name of the column
196 Column names should be human-readable, but not necessarily unique
197 within a given table.
199 @see setName
201 virtual OUString getName() const = 0;
203 /** sets a new name for the column
205 @see getName
207 virtual void setName( const OUString& _rName ) = 0;
209 /** retrieves the help text to be displayed for the column.
211 virtual OUString getHelpText() const = 0;
213 /** sets a new the help text to be displayed for the column.
215 virtual void setHelpText( const OUString& i_helpText ) = 0;
217 /** determines whether the column can be interactively resized
219 @see getMinWidth
220 @see getMaxWidth
221 @see getWidth
223 virtual bool isResizable() const = 0;
225 /** declares the column as resizable or fixed in width
227 @see getMinWidth
228 @see getMaxWidth
229 @see getWidth
231 virtual void setResizable( bool _bResizable ) = 0;
233 /** denotes the relative flexibility of the column
235 This flexibility is taken into account when a table control auto-resizes its columns, because the available
236 space changed. In this case, the columns grow or shrink according to their flexibility.
238 A value of 0 means the column is not auto-resized at all.
240 virtual sal_Int32 getFlexibility() const = 0;
242 /** sets a new flexibility value for the column
244 @see getFlexibility
246 virtual void setFlexibility( sal_Int32 const i_flexibility ) = 0;
248 /** returns the width of the column, in app-font unitss
250 The returned value must be a positive ->TableMetrics value.
252 @see setWidth
253 @see getMinWidth
254 @see getMaxWidth
256 virtual TableMetrics getWidth() const = 0;
258 /** sets a new width for the column
260 @param _nWidth
261 the new width, app-font units
263 @see getWidth
265 virtual void setWidth( TableMetrics _nWidth ) = 0;
267 /** returns the minimum width of the column, in app-font units, or 0 if the column
268 does not have a minimal width
270 @see setMinWidth
271 @see getMaxWidth
272 @see getWidth
274 virtual TableMetrics getMinWidth() const = 0;
276 /** sets the minimum width of the column, in app-font units
278 @see getMinWidth
279 @see setMaxWidth
280 @see setWidth
282 virtual void setMinWidth( TableMetrics _nMinWidth ) = 0;
284 /** returns the maximum width of the column, in app-font units, or 0 if the column
285 does not have a minimal width
287 @see setMaxWidth
288 @see getMinWidth
289 @see getWidth
291 virtual TableMetrics getMaxWidth() const = 0;
293 /** sets the maximum width of the column, in app-font units
295 @see getMaxWidth
296 @see setMinWidth
297 @see setWidth
299 virtual void setMaxWidth( TableMetrics _nMaxWidth ) = 0;
301 /** retrieves the horizontal alignment to be used for content in this cell
303 virtual ::com::sun::star::style::HorizontalAlignment getHorizontalAlign() = 0;
305 /** sets a new the horizontal alignment to be used for content in this cell
307 virtual void setHorizontalAlign(::com::sun::star::style::HorizontalAlignment _xAlign) = 0;
309 /// deletes the column model instance
310 virtual ~IColumnModel() { }
312 typedef std::shared_ptr< IColumnModel > PColumnModel;
315 //= ITableModel
317 /** declares the interface to implement by an abtract table model
319 class SAL_NO_VTABLE SVT_DLLPUBLIC ITableModel
321 public:
322 /** returns the number of columns in the table
324 virtual TableSize getColumnCount() const = 0;
326 /** returns the number of rows in the table
328 virtual TableSize getRowCount() const = 0;
330 /** determines whether the table has column headers
332 If this method returns <TRUE/>, the renderer returned by
333 ->getRenderer must be able to render column headers.
335 @see IColumnRenderer
337 virtual bool hasColumnHeaders() const = 0;
339 /** determines whether the table has row headers
341 If this method returns <TRUE/>, the renderer returned by
342 ->getRenderer must be able to render row headers.
344 @see IColumnRenderer
346 virtual bool hasRowHeaders() const = 0;
348 /** determines whether the given cell is editable
350 @see ICellEditor
351 @todo
353 virtual bool isCellEditable( ColPos col, RowPos row ) const = 0;
355 /** returns a model for a certain column
357 @param column
358 the index of the column in question. Must be greater than or
359 equal 0, and smaller than the return value of ->getColumnCount()
361 @return
362 the model of the column in question. Must not be <NULL/>
364 virtual PColumnModel getColumnModel( ColPos column ) = 0;
366 /** returns a renderer which is able to paint the table represented
367 by this table model
369 @return the renderer to use. Must not be <NULL/>
371 virtual PTableRenderer getRenderer() const = 0;
373 /** returns the component handling input in a view associated with the model
375 virtual PTableInputHandler getInputHandler() const = 0;
377 /** determines the height of rows in the table.
379 @return
380 the logical height of rows in the table, in app-font units. The height must be
381 greater 0.
383 virtual TableMetrics getRowHeight() const = 0;
385 /** determines the height of the column header row
387 This method is not to be called if ->hasColumnHeaders()
388 returned <FALSE/>.
390 @return
391 the logical height of the column header row, in app-font units.
392 Must be greater than 0.
394 virtual TableMetrics getColumnHeaderHeight() const = 0;
396 /** determines the width of the row header column
398 This method is not to be called if ->hasRowHeaders()
399 returned <FALSE/>.
401 @return
402 the logical width of the row header column, in app-font units.
403 Must be greater than 0.
405 virtual TableMetrics getRowHeaderWidth() const = 0;
407 /** returns the visibilit mode of the vertical scrollbar
409 virtual ScrollbarVisibility getVerticalScrollbarVisibility() const = 0;
411 /** returns the visibilit mode of the horizontal scrollbar
413 virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const = 0;
415 /** adds a listener to be notified of changes in the table model
417 virtual void addTableModelListener( const PTableModelListener& i_listener ) = 0;
419 /** remove a listener to be notified of changes in the table model
421 virtual void removeTableModelListener( const PTableModelListener& i_listener ) = 0;
423 /** retrieves the content of the given cell
425 virtual void getCellContent( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any& o_cellContent ) = 0;
427 /** returns an object which should be displayed as tooltip for the given cell
429 At the moment, only string-convertible values are supported here. In the future, one might imagine displaying
430 scaled-down versions of a graphic in a cell, and a larger version of that very graphic as tooltip.
432 If no tooltip object is provided, then the cell content is used, and displayed as tooltip for the cell
433 if and only if it doesn't fit into the cell's space itself.
435 @param i_col
436 The column index of the cell in question. COL_ROW_HEADERS is a valid argument here.
437 @param i_row
438 The row index of the cell in question.
439 @param o_cellToolTip
440 takes the tooltip object upon return.
442 virtual void getCellToolTip( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any & o_cellToolTip ) = 0;
444 /** retrieves title of a given row
446 virtual ::com::sun::star::uno::Any getRowHeading( RowPos const i_rowPos ) const = 0;
448 /** returns the color to be used for rendering the grid lines.
450 If this value is not set, a default color from the style settings will be used.
452 virtual ::boost::optional< ::Color > getLineColor() const = 0;
454 /** returns the color to be used for rendering the header background.
456 If this value is not set, a default color from the style settings will be used.
458 virtual ::boost::optional< ::Color > getHeaderBackgroundColor() const = 0;
460 /** returns the color to be used for rendering the header text.
462 If this value is not set, a default color from the style settings will be used.
464 virtual ::boost::optional< ::Color > getHeaderTextColor() const = 0;
466 /** returns the color to be used for the background of selected cells, when the control has the focus
468 If this value is not set, a default color from the style settings will be used.
470 virtual ::boost::optional< ::Color > getActiveSelectionBackColor() const = 0;
472 /** returns the color to be used for the background of selected cells, when the control does not have the focus
474 If this value is not set, a default color from the style settings will be used.
476 virtual ::boost::optional< ::Color > getInactiveSelectionBackColor() const = 0;
478 /** returns the color to be used for the text of selected cells, when the control has the focus
480 If this value is not set, a default color from the style settings will be used.
482 virtual ::boost::optional< ::Color > getActiveSelectionTextColor() const = 0;
484 /** returns the color to be used for the text of selected cells, when the control does not have the focus
486 If this value is not set, a default color from the style settings will be used.
488 virtual ::boost::optional< ::Color > getInactiveSelectionTextColor() const = 0;
490 /** returns the color to be used for rendering cell texts.
492 If this value is not set, a default color from the style settings will be used.
494 virtual ::boost::optional< ::Color > getTextColor() const = 0;
496 /** returns the color to be used for text lines (underline, strikethrough) when rendering cell text.
498 If this value is not set, a default color from the style settings will be used.
500 virtual ::boost::optional< ::Color > getTextLineColor() const = 0;
502 /** returns the colors to be used for the row backgrounds.
504 If this value is not set, every second row will have a background color derived from the style settings's
505 selection color, the other rows will not have a special background at all.
507 If this value is an empty sequence, the rows will not have a special background at all, instead the
508 normal background of the complete control will be used.
510 If value is a non-empty sequence, then rows will have the background colors as specified in the sequence,
511 in alternating order.
513 virtual ::boost::optional< ::std::vector< ::Color > >
514 getRowBackgroundColors() const = 0;
516 /** determines the vertical alignment of content within a cell
518 virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() const = 0;
520 /** returns an adapter to the sorting functionality of the model
522 It is legitimate to return <NULL/> here, in this case, the table model does not support sorting.
524 virtual ITableDataSort* getSortAdapter() = 0;
526 /** returns enabled state.
528 virtual bool isEnabled() const = 0;
530 /// destroys the table model instance
531 virtual ~ITableModel() { }
533 typedef std::shared_ptr< ITableModel > PTableModel;
536 } } // namespace svt::table
539 #endif // INCLUDED_SVTOOLS_TABLE_TABLEMODEL_HXX
541 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */