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 22 #include <table/tablemodel.hxx> 23 #include <table/tablesort.hxx> 24 #include <tools/color.hxx> 25 26 #include <com/sun/star/awt/grid/GridDataEvent.hpp> 27 #include <com/sun/star/awt/grid/XGridColumnModel.hpp> 28 #include <com/sun/star/awt/grid/XGridDataModel.hpp> 29 #include <com/sun/star/awt/grid/XGridColumn.hpp> 30 #include <com/sun/star/awt/grid/XGridColumn.hpp> 31 #include <com/sun/star/style/VerticalAlignment.hpp> 32 #include <cppuhelper/weakref.hxx> 33 34 35 namespace svt::table 36 { 37 38 39 //= UnoControlTableModel 40 41 class UnoGridColumnFacade; 42 class UnoControlTableModel : public ITableModel, public ITableDataSort 43 { 44 public: 45 UnoControlTableModel(); 46 virtual ~UnoControlTableModel() override; 47 48 public: 49 // ITableModel overridables 50 virtual TableSize getColumnCount() const override; 51 virtual TableSize getRowCount() const override; 52 virtual bool hasColumnHeaders() const override; 53 virtual bool hasRowHeaders() const override; 54 virtual PColumnModel getColumnModel( ColPos column ) override; 55 virtual PTableRenderer getRenderer() const override; 56 virtual PTableInputHandler getInputHandler() const override; 57 virtual TableMetrics getRowHeight() const override; 58 virtual TableMetrics getColumnHeaderHeight() const override; 59 virtual TableMetrics getRowHeaderWidth() const override; 60 virtual ScrollbarVisibility getVerticalScrollbarVisibility() const override; 61 virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const override; 62 virtual void addTableModelListener( const PTableModelListener& i_listener ) override; 63 virtual void removeTableModelListener( const PTableModelListener& i_listener ) override; 64 virtual void getCellContent( ColPos const i_col, RowPos const i_row, css::uno::Any& o_cellContent ) override; 65 virtual void getCellToolTip( ColPos const i_col, RowPos const i_row, css::uno::Any & o_cellToolTip ) override; 66 virtual css::uno::Any getRowHeading( RowPos const i_rowPos ) const override; 67 virtual ::std::optional< ::Color > getLineColor() const override; 68 virtual ::std::optional< ::Color > getHeaderBackgroundColor() const override; 69 virtual ::std::optional< ::Color > getHeaderTextColor() const override; 70 virtual ::std::optional< ::Color > getActiveSelectionBackColor() const override; 71 virtual ::std::optional< ::Color > getInactiveSelectionBackColor() const override; 72 virtual ::std::optional< ::Color > getActiveSelectionTextColor() const override; 73 virtual ::std::optional< ::Color > getInactiveSelectionTextColor() const override; 74 virtual ::std::optional< ::Color > getTextColor() const override; 75 virtual ::std::optional< ::Color > getTextLineColor() const override; 76 virtual ::std::optional< ::std::vector< ::Color > > 77 getRowBackgroundColors() const override; 78 virtual css::style::VerticalAlignment 79 getVerticalAlign() const override; 80 virtual ITableDataSort* getSortAdapter() override; 81 virtual bool isEnabled() const override; 82 83 // ITableDataSort overridables 84 virtual void sortByColumn( ColPos const i_column, ColumnSortDirection const i_sortDirection ) override; 85 virtual ColumnSort getCurrentSortOrder() const override; 86 87 // column write access 88 void appendColumn( css::uno::Reference< css::awt::grid::XGridColumn > const & i_column ); 89 void insertColumn( ColPos const i_position, css::uno::Reference< css::awt::grid::XGridColumn > const & i_column ); 90 void removeColumn( ColPos const i_position ); 91 void removeAllColumns(); 92 93 // other operations 94 void setVerticalScrollbarVisibility( ScrollbarVisibility const i_visibility ); 95 void setHorizontalScrollbarVisibility( ScrollbarVisibility const i_visibility ); 96 97 void setDataModel( css::uno::Reference< css::awt::grid::XGridDataModel > const & i_gridDataModel ); 98 bool hasDataModel() const; 99 css::uno::Reference< css::awt::grid::XGridDataModel > 100 getDataModel() const; 101 void setColumnModel( css::uno::Reference< css::awt::grid::XGridColumnModel > const & i_gridColumnModel ); 102 bool hasColumnModel() const; 103 css::uno::Reference< css::awt::grid::XGridColumnModel > 104 getColumnModel() const; 105 106 void setRowHeaders(bool _bRowHeaders); 107 void setColumnHeaders(bool _bColumnHeaders); 108 109 void setRowHeight( TableMetrics _nHeight ); 110 void setRowHeaderWidth( TableMetrics _nWidth ); 111 void setColumnHeaderHeight( TableMetrics _nHeight ); 112 113 void setLineColor( css::uno::Any const & i_color ); 114 void setHeaderBackgroundColor( css::uno::Any const & i_color ); 115 void setHeaderTextColor( css::uno::Any const & i_color ); 116 void setActiveSelectionBackColor( css::uno::Any const & i_color ); 117 void setInactiveSelectionBackColor( css::uno::Any const & i_color ); 118 void setActiveSelectionTextColor( css::uno::Any const & i_color ); 119 void setInactiveSelectionTextColor( css::uno::Any const & i_color ); 120 void setTextColor( css::uno::Any const & i_color ); 121 void setTextLineColor( css::uno::Any const & i_color ); 122 void setRowBackgroundColors( css::uno::Any const & i_APIValue ); 123 124 void setVerticalAlign(css::style::VerticalAlignment _rAlign); 125 void setEnabled( bool _bEnabled ); 126 127 // multiplexing of XGridDataListener events 128 void notifyRowsInserted( css::awt::grid::GridDataEvent const & i_event ) const; 129 void notifyRowsRemoved( css::awt::grid::GridDataEvent const & i_event ) const; 130 void notifyDataChanged( css::awt::grid::GridDataEvent const & i_event ) const; 131 132 /// retrieves the index of a column within the model 133 ColPos getColumnPos( UnoGridColumnFacade const & i_column ) const; 134 135 /// notifies a change in a column belonging to the model 136 void notifyColumnChange( ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup ) const; 137 138 /** notifies a change in all data represented by the model. To be used if you cannot specified the changed data 139 in more detail. 140 */ 141 void notifyAllDataChanged() const; 142 143 private: 144 void impl_notifyTableMetricsChanged() const; 145 146 typedef ::std::vector< PTableModelListener > ModellListeners; 147 typedef ::std::vector< PColumnModel > ColumnModels; 148 149 ColumnModels aColumns; 150 bool bHasColumnHeaders; 151 bool bHasRowHeaders; 152 ScrollbarVisibility eVScrollMode; 153 ScrollbarVisibility eHScrollMode; 154 PTableRenderer pRenderer; 155 PTableInputHandler pInputHandler; 156 TableMetrics nRowHeight; 157 TableMetrics nColumnHeaderHeight; 158 TableMetrics nRowHeaderWidth; 159 ::std::optional< ::Color > m_aGridLineColor; 160 ::std::optional< ::Color > m_aHeaderBackgroundColor; 161 ::std::optional< ::Color > m_aHeaderTextColor; 162 ::std::optional< ::Color > m_aActiveSelectionBackColor; 163 ::std::optional< ::Color > m_aInactiveSelectionBackColor; 164 ::std::optional< ::Color > m_aActiveSelectionTextColor; 165 ::std::optional< ::Color > m_aInactiveSelectionTextColor; 166 ::std::optional< ::Color > m_aTextColor; 167 ::std::optional< ::Color > m_aTextLineColor; 168 ::std::optional< ::std::vector< ::Color > > m_aRowColors; 169 css::style::VerticalAlignment m_eVerticalAlign; 170 bool bEnabled; 171 ModellListeners m_aListeners; 172 css::uno::WeakReference< css::awt::grid::XGridDataModel > m_aDataModel; 173 css::uno::WeakReference< css::awt::grid::XGridColumnModel > m_aColumnModel; 174 }; 175 176 177 } // svt::table 178 179 180 181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 182