26#include <com/sun/star/awt/grid/XSortableGridData.hpp>
27#include <com/sun/star/util/Color.hpp>
39 using css::uno::Reference;
40 using css::uno::Sequence;
41 using css::uno::UNO_QUERY_THROW;
42 using css::uno::UNO_QUERY;
43 using css::awt::grid::XGridColumn;
44 using css::uno::Exception;
45 using css::awt::grid::XGridDataModel;
46 using css::awt::grid::XGridColumnModel;
48 using css::style::VerticalAlignment_TOP;
49 using css::style::VerticalAlignment;
50 using css::awt::grid::GridDataEvent;
51 using css::awt::grid::XSortableGridData;
52 using css::beans::Pair;
56#define DBG_CHECK_ME() \
57 DBG_TESTSOLARMUTEX(); \
61 ,bHasColumnHeaders ( true )
62 ,bHasRowHeaders ( false )
68 ,nColumnHeaderHeight ( 10 )
71 ,m_aHeaderBackgroundColor ( )
72 ,m_aHeaderTextColor ( )
73 ,m_aActiveSelectionBackColor ( )
74 ,m_aInactiveSelectionBackColor ( )
75 ,m_aActiveSelectionTextColor ( )
76 ,m_aInactiveSelectionTextColor ( )
80 ,m_eVerticalAlign ( VerticalAlignment_TOP )
83 pRenderer = std::make_shared<GridTableRenderer>( *
this );
107 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
109 nRowCount = xDataModel->getRowCount();
159 "DefaultTableModel::getColumnModel: invalid index!",
PColumnModel() );
175 "UnoControlTableModel::insertColumn: illegal position!" );
177 const PColumnModel pColumn = std::make_shared<UnoGridColumnFacade>( *
this, i_column );
184 listener->columnInserted();
193 "UnoControlTableModel::removeColumn: illegal position!" );
196 ColumnModels::iterator
pos =
aColumns.begin() + i_position;
204 listener->columnRemoved();
209 OSL_ENSURE( pColumnImpl !=
nullptr,
"UnoControlTableModel::removeColumn: illegal column implementation!" );
227 SAL_WARN(
"svtools.uno",
"UnoControlTableModel::removeAllColumns: illegal column implementation!" );
239 listener->allColumnsRemoved();
249 listener->tableMetricsChanged();
354 OSL_ENSURE(
false,
"UnoControlTableModel::removeTableModelListener: listener is not registered - sure you're doing the right thing here?" );
383 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
403 Reference< XGridColumnModel >
const xColumnModel(
m_aColumnModel );
418 o_cellContent.clear();
421 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
422 ENSURE_OR_RETURN_VOID( xDataModel.is(),
"UnoControlTableModel::getCellContent: no data model anymore!" );
426 ENSURE_OR_RETURN_VOID( pColumnImpl !=
nullptr,
"UnoControlTableModel::getCellContent: no (valid) column at this position!" );
429 if ( nDataColumnIndex >= xDataModel->getColumnCount() )
434 #if OSL_DEBUG_LEVEL > 0
435 Reference< XGridColumnModel >
const xColumnModel(
m_aColumnModel );
436 OSL_ENSURE( xColumnModel.is() && i_col < xColumnModel->
getColumnCount(),
437 "UnoControlTableModel::getCellContent: request a column's value which the ColumnModel doesn't know about!" );
442 o_cellContent = xDataModel->getCellData( nDataColumnIndex, i_row );
457 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
460 o_cellToolTip = xDataModel->getCellToolTip( i_col, i_row );
475 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
476 ENSURE_OR_RETURN( xDataModel.is(),
"UnoControlTableModel::getRowHeading: no data model anymore!", aRowHeading );
480 aRowHeading = xDataModel->getRowHeading( i_rowPos );
492 void lcl_setColor( Any
const & i_color, ::std::optional< ::Color > & o_convertedColor )
494 if ( !i_color.hasValue() )
495 o_convertedColor.reset();
499 if ( i_color >>= nColor )
501 o_convertedColor = nColor;
505 OSL_ENSURE(
false,
"lcl_setColor: could not extract color value!" );
648 Sequence< css::util::Color > aAPIColors;
649 if ( !( i_APIValue >>= aAPIColors ) )
653 ::std::vector< ::Color > aColors( aAPIColors.getLength() );
654 std::transform(std::cbegin(aAPIColors), std::cend(aAPIColors), aColors.begin(),
655 [](
const css::util::Color& rAPIColor) ->
::Color { return Color(ColorTransparency, rAPIColor); });
681 if ( &i_column ==
col.get() )
685 OSL_ENSURE(
false,
"UnoControlTableModel::getColumnPos: column not found!" );
694 Reference< XSortableGridData >
const xSortAccess(
getDataModel(), UNO_QUERY );
695 if ( xSortAccess.is() )
721 Reference< XSortableGridData >
const xSortAccess(
getDataModel(), UNO_QUERY_THROW );
738 Reference< XSortableGridData >
const xSortAccess(
getDataModel(), UNO_QUERY_THROW );
739 Pair< ::sal_Int32, sal_Bool >
const aCurrentSortOrder( xSortAccess->getCurrentSortOrder() );
740 currentSort.
nColumnPos = aCurrentSortOrder.First;
755 "UnoControlTableModel::notifyColumnChange: invalid column index!" );
760 listener->columnChanged( i_columnPos, i_attributeGroup );
768 ENSURE_OR_RETURN_VOID( i_event.FirstRow >= 0,
"UnoControlTableModel::notifyRowsInserted: invalid first row!" );
769 ENSURE_OR_RETURN_VOID( i_event.LastRow >= i_event.FirstRow,
"UnoControlTableModel::notifyRowsInserted: invalid row indexes!" );
772 Reference< XGridColumnModel >
const xColumnModel(
m_aColumnModel );
773 ENSURE_OR_RETURN_VOID( xColumnModel.is(),
"UnoControlTableModel::notifyRowsInserted: no column model anymore!" );
775 Reference< XGridDataModel >
const xDataModel(
m_aDataModel );
776 ENSURE_OR_RETURN_VOID( xDataModel.is(),
"UnoControlTableModel::notifyRowsInserted: no data model anymore!" );
780 sal_Int32
const dataColumnCount = xDataModel->getColumnCount();
781 OSL_ENSURE( dataColumnCount > 0,
"UnoControlTableModel::notifyRowsInserted: no columns at all?" );
783 sal_Int32
const modelColumnCount = xColumnModel->getColumnCount();
784 if ( ( modelColumnCount == 0 ) && ( dataColumnCount > 0 ) )
787 xColumnModel->setDefaultColumns( dataColumnCount );
794 listener->rowsInserted( i_event.FirstRow, i_event.LastRow );
804 listener->rowsRemoved( i_event.FirstRow, i_event.LastRow );
811 RowPos const firstRow = i_event.FirstRow == -1 ? 0 : i_event.FirstRow;
812 RowPos const lastRow = i_event.FirstRow == -1 ?
getRowCount() - 1 : i_event.LastRow;
817 listener->cellsUpdated( firstRow, lastRow );
provides sorting functionality for the data underlying an ITableModel
virtual PTableInputHandler getInputHandler() const override
returns the component handling input in a view associated with the model
void notifyRowsInserted(css::awt::grid::GridDataEvent const &i_event) const
::std::optional< ::std::vector< ::Color > > m_aRowColors
virtual ScrollbarVisibility getVerticalScrollbarVisibility() const override
returns the visibility mode of the vertical scrollbar
ModellListeners m_aListeners
void setActiveSelectionTextColor(css::uno::Any const &i_color)
virtual TableMetrics getRowHeight() const override
determines the height of rows in the table.
virtual void addTableModelListener(const PTableModelListener &i_listener) override
adds a listener to be notified of changes in the table model
virtual ::std::optional< ::Color > getHeaderBackgroundColor() const override
returns the color to be used for rendering the header background.
virtual bool hasColumnHeaders() const override
determines whether the table has column headers
void setVerticalAlign(css::style::VerticalAlignment _rAlign)
virtual ::std::optional< ::Color > getActiveSelectionTextColor() const override
returns the color to be used for the text of selected cells, when the control has the focus
::std::optional< ::Color > m_aActiveSelectionTextColor
virtual ::std::optional< ::std::vector< ::Color > > getRowBackgroundColors() const override
returns the colors to be used for the row backgrounds.
::std::optional< ::Color > m_aGridLineColor
virtual TableSize getColumnCount() const override
returns the number of columns in the table
void setVerticalScrollbarVisibility(ScrollbarVisibility const i_visibility)
void notifyRowsRemoved(css::awt::grid::GridDataEvent const &i_event) const
void setTextColor(css::uno::Any const &i_color)
void setTextLineColor(css::uno::Any const &i_color)
virtual TableSize getRowCount() const override
returns the number of rows in the table
bool hasDataModel() const
::std::optional< ::Color > m_aHeaderBackgroundColor
void setHeaderBackgroundColor(css::uno::Any const &i_color)
void setRowHeaders(bool _bRowHeaders)
virtual void removeTableModelListener(const PTableModelListener &i_listener) override
remove a listener to be notified of changes in the table model
virtual void getCellToolTip(ColPos const i_col, RowPos const i_row, css::uno::Any &o_cellToolTip) override
returns an object which should be displayed as tooltip for the given cell
virtual css::uno::Any getRowHeading(RowPos const i_rowPos) const override
retrieves title of a given row
virtual ::std::optional< ::Color > getInactiveSelectionBackColor() const override
returns the color to be used for the background of selected cells, when the control does not have the...
::std::optional< ::Color > m_aHeaderTextColor
virtual ::std::optional< ::Color > getHeaderTextColor() const override
returns the color to be used for rendering the header text.
void setRowHeaderWidth(TableMetrics _nWidth)
virtual TableMetrics getColumnHeaderHeight() const override
determines the height of the column header row
ColPos getColumnPos(UnoGridColumnFacade const &i_column) const
retrieves the index of a column within the model
::std::optional< ::Color > m_aInactiveSelectionBackColor
void setColumnHeaderHeight(TableMetrics _nHeight)
TableMetrics nRowHeaderWidth
void setDataModel(css::uno::Reference< css::awt::grid::XGridDataModel > const &i_gridDataModel)
void setInactiveSelectionBackColor(css::uno::Any const &i_color)
virtual TableMetrics getRowHeaderWidth() const override
determines the width of the row header column
void setEnabled(bool _bEnabled)
void notifyAllDataChanged() const
notifies a change in all data represented by the model.
virtual ::std::optional< ::Color > getActiveSelectionBackColor() const override
returns the color to be used for the background of selected cells, when the control has the focus
virtual css::style::VerticalAlignment getVerticalAlign() const override
determines the vertical alignment of content within a cell
void setHeaderTextColor(css::uno::Any const &i_color)
::std::optional< ::Color > m_aInactiveSelectionTextColor
css::uno::Reference< css::awt::grid::XGridColumnModel > getColumnModel() const
::std::optional< ::Color > m_aActiveSelectionBackColor
void setRowHeight(TableMetrics _nHeight)
::std::optional< ::Color > m_aTextLineColor
virtual ::std::optional< ::Color > getInactiveSelectionTextColor() const override
returns the color to be used for the text of selected cells, when the control does not have the focus
::std::optional< ::Color > m_aTextColor
css::style::VerticalAlignment m_eVerticalAlign
::std::vector< PTableModelListener > ModellListeners
void setColumnModel(css::uno::Reference< css::awt::grid::XGridColumnModel > const &i_gridColumnModel)
void setActiveSelectionBackColor(css::uno::Any const &i_color)
ScrollbarVisibility eVScrollMode
virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const override
returns the visibility mode of the horizontal scrollbar
ScrollbarVisibility eHScrollMode
css::uno::WeakReference< css::awt::grid::XGridDataModel > m_aDataModel
void insertColumn(ColPos const i_position, css::uno::Reference< css::awt::grid::XGridColumn > const &i_column)
void setInactiveSelectionTextColor(css::uno::Any const &i_color)
void setRowBackgroundColors(css::uno::Any const &i_APIValue)
bool hasColumnModel() const
void setHorizontalScrollbarVisibility(ScrollbarVisibility const i_visibility)
css::uno::Reference< css::awt::grid::XGridDataModel > getDataModel() const
virtual ::std::optional< ::Color > getLineColor() const override
returns the color to be used for rendering the grid lines.
virtual ::std::optional< ::Color > getTextLineColor() const override
returns the color to be used for text lines (underline, strikethrough) when rendering cell text.
void setLineColor(css::uno::Any const &i_color)
virtual ~UnoControlTableModel() override
virtual void sortByColumn(ColPos const i_column, ColumnSortDirection const i_sortDirection) override
sorts the rows in the model by the given column's data, in the given direction.
void impl_notifyTableMetricsChanged() const
virtual PTableRenderer getRenderer() const override
returns a renderer which is able to paint the table represented by this table model
void notifyDataChanged(css::awt::grid::GridDataEvent const &i_event) const
virtual ColumnSort getCurrentSortOrder() const override
retrieves the current sort order of the data
virtual ITableDataSort * getSortAdapter() override
returns an adapter to the sorting functionality of the model
TableMetrics nColumnHeaderHeight
virtual ::std::optional< ::Color > getTextColor() const override
returns the color to be used for rendering cell texts.
virtual bool isEnabled() const override
returns enabled state.
css::uno::WeakReference< css::awt::grid::XGridColumnModel > m_aColumnModel
void appendColumn(css::uno::Reference< css::awt::grid::XGridColumn > const &i_column)
virtual bool hasRowHeaders() const override
determines whether the table has row headers
void removeColumn(ColPos const i_position)
void setColumnHeaders(bool _bColumnHeaders)
PTableInputHandler pInputHandler
void notifyColumnChange(ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup) const
notifies a change in a column belonging to the model
virtual void getCellContent(ColPos const i_col, RowPos const i_row, css::uno::Any &o_cellContent) override
retrieves the content of the given cell
sal_Int32 getDataColumnIndex() const
void dispose()
disposes the column wrapper
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr sal_uInt16 nRowHeaderWidth
#define DBG_ASSERT(sCon, aError)
#define ENSURE_OR_THROW(c, m)
#define ENSURE_OR_RETURN(c, m, r)
#define DBG_UNHANDLED_EXCEPTION(...)
#define ENSURE_OR_RETURN_VOID(c, m)
#define SAL_WARN(area, stream)
RttiCompleteObjectLocator col
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 TableSize
a value denoting the size of a table
sal_Int32 RowPos
a value denoting a row position within a table
std::shared_ptr< ITableRenderer > PTableRenderer
@ ScrollbarShowNever
enumeration value denoting that a scrollbar should never be visible, even if needed normally
sal_Int32 ColPos
a value denoting a column position within a table
std::shared_ptr< ITableInputHandler > PTableInputHandler
std::shared_ptr< IColumnModel > PColumnModel
std::shared_ptr< ITableModelListener > PTableModelListener
ColumnSortDirection eSortDirection
#define COL_INVALID
denotes an invalid column index