1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SVTOOLS_INC_TABLE_TABLEMODEL_HXX 25 #define SVTOOLS_INC_TABLE_TABLEMODEL_HXX 26 27 #include "svtools/svtdllapi.h" 28 #include "svtools/table/tabletypes.hxx" 29 #include "svtools/table/tablerenderer.hxx" 30 #include "svtools/table/tableinputhandler.hxx" 31 #include "svtools/table/tablesort.hxx" 32 33 #include <com/sun/star/util/Color.hpp> 34 #include <com/sun/star/style/VerticalAlignment.hpp> 35 #include <com/sun/star/style/HorizontalAlignment.hpp> 36 37 #include <rtl/ref.hxx> 38 #include <sal/types.h> 39 40 #include <boost/shared_ptr.hpp> 41 #include <boost/optional.hpp> 42 #include <boost/enable_shared_from_this.hpp> 43 44 //........................................................................ 45 namespace svt { namespace table 46 { 47 //........................................................................ 48 49 50 //==================================================================== 51 //= ScrollbarVisibility 52 //==================================================================== 53 enum ScrollbarVisibility 54 { 55 /** enumeration value denoting that a scrollbar should never be visible, even 56 if needed normally 57 */ 58 ScrollbarShowNever, 59 /** enumeration value denoting that a scrollbar should be visible when needed only 60 */ 61 ScrollbarShowSmart, 62 /** enumeration value denoting that a scrollbar should always be visible, even 63 if not needed normally 64 */ 65 ScrollbarShowAlways 66 }; 67 68 //==================================================================== 69 //= ITableModelListener 70 //==================================================================== 71 typedef sal_Int32 ColumnAttributeGroup; 72 #define COL_ATTRS_NONE (0x00000000) 73 /// denotes column attributes related to the width of the column 74 #define COL_ATTRS_WIDTH (0x00000001) 75 /// denotes column attributes related to the appearance of the column, i.e. those relevant for rendering 76 #define COL_ATTRS_APPEARANCE (0x00000002) 77 /// denotes the entirety of column attributes 78 #define COL_ATTRS_ALL (0x7FFFFFFF) 79 80 //==================================================================== 81 //= ITableModelListener 82 //==================================================================== 83 /** declares an interface to be implemented by components interested in 84 changes in an ->ITableModel 85 */ 86 class SAL_NO_VTABLE ITableModelListener : public ::boost::enable_shared_from_this< ITableModelListener > 87 { 88 public: 89 /** notifies the listener that one or more rows have been inserted into 90 the table 91 92 @param first 93 the index of the first newly inserted row 94 @param last 95 the index of the last newly inserted row. Must not be smaller 96 than ->first 97 */ 98 virtual void rowsInserted( RowPos first, RowPos last ) = 0; 99 100 /** notifies the listener that one or more rows have been removed from 101 the table 102 103 @param first 104 the old index of the first removed row. If this is <code>-1</code>, then all 105 rows have been removed from the model. 106 @param last 107 the old index of the last removed row. Must not be smaller 108 than ->first 109 */ 110 virtual void rowsRemoved( RowPos first, RowPos last ) = 0; 111 112 /** notifies the listener that one or more columns have been inserted into 113 the table 114 115 @param first 116 the index of the first newly inserted row 117 @param last 118 the index of the last newly inserted row. Must not be smaller 119 than ->first 120 */ 121 virtual void columnInserted( ColPos const i_colIndex ) = 0; 122 123 /** notifies the listener that one or more columns have been removed from 124 the table 125 126 @param i_colIndex 127 the old index of the removed column 128 */ 129 virtual void columnRemoved( ColPos const i_colIndex ) = 0; 130 131 /** notifies the listener that all columns have been removed form the model 132 */ 133 virtual void allColumnsRemoved() = 0; 134 135 /** notifies the listener that a rectangular cell range in the table 136 has been updated 137 138 Listeners are required to discard any possibly cached information 139 they have about the cells in question, in particular any possibly 140 cached cell values. 141 */ 142 virtual void cellsUpdated( ColPos const i_firstCol, ColPos i_lastCol, RowPos const i_firstRow, RowPos const i_lastRow ) = 0; 143 144 /** notifies the listener that attributes of a given column changed 145 146 @param i_column 147 the position of the column whose attributes changed 148 @param i_attributeGroup 149 a combination of one or more <code>COL_ATTRS_*</code> flags, denoting the attribute group(s) 150 in which changes occurred. 151 */ 152 virtual void columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup ) = 0; 153 154 /** notifies the listener that the metrics of the table changed. 155 156 Metrics here include the column header height, the row header width, the row height, and the presence 157 of both the row and column header. 158 */ 159 virtual void tableMetricsChanged() = 0; 160 161 /// deletes the listener instance ~ITableModelListener()162 virtual ~ITableModelListener(){}; 163 }; 164 typedef ::boost::shared_ptr< ITableModelListener > PTableModelListener; 165 166 //==================================================================== 167 //= IColumnModel 168 //==================================================================== 169 /** interface to be implemented by table column models 170 */ 171 class SAL_NO_VTABLE IColumnModel 172 { 173 public: 174 /** retrieves the ID of the column 175 176 The semantics of a column id is not defined. It's up to the 177 implementor of the ->IColumnModel, respectively the ->ITableModel 178 which provides the column models, to define such a semantics. 179 180 @return 181 the ID of the column. May be 0 if the table which the column 182 belongs to does not need and support column ids. 183 184 @see setID 185 */ 186 virtual ::com::sun::star::uno::Any 187 getID() const = 0; 188 189 /** sets a new column ID 190 191 @return 192 <TRUE/> if setting the new ID was successfull. A possible error 193 conditions is if you try to set an ID which is already used 194 by another column within the same table. 195 196 @see getID 197 */ 198 virtual void setID( const ::com::sun::star::uno::Any& _nID ) = 0; 199 200 /** returns the name of the column 201 202 Column names should be human-readable, but not necessarily unique 203 within a given table. 204 205 @see setName 206 */ 207 virtual String getName() const = 0; 208 209 /** sets a new name for the column 210 211 @see getName 212 */ 213 virtual void setName( const String& _rName ) = 0; 214 215 /** retrieves the help text to be displayed for the column. 216 */ 217 virtual String getHelpText() const = 0; 218 219 /** sets a new the help text to be displayed for the column. 220 */ 221 virtual void setHelpText( const String& i_helpText ) = 0; 222 223 /** determines whether the column can be interactively resized 224 225 @see getMinWidth 226 @see getMaxWidth 227 @see getWidth 228 */ 229 virtual bool isResizable() const = 0; 230 231 /** declares the column as resizable or fixed in width 232 233 @see getMinWidth 234 @see getMaxWidth 235 @see getWidth 236 */ 237 virtual void setResizable( bool _bResizable ) = 0; 238 239 /** denotes the relative flexibility of the column 240 241 This flexibility is taken into account when a table control auto-resizes its columns, because the available 242 space changed. In this case, the columns grow or shrink according to their flexibility. 243 244 A value of 0 means the column is not auto-resized at all. 245 */ 246 virtual sal_Int32 getFlexibility() const = 0; 247 248 /** sets a new flexibility value for the column 249 250 @see getFlexibility 251 */ 252 virtual void setFlexibility( sal_Int32 const i_flexibility ) = 0; 253 254 /** returns the width of the column, in app-font unitss 255 256 The returned value must be a positive ->TableMetrics value. 257 258 @see setWidth 259 @see getMinWidth 260 @see getMaxWidth 261 */ 262 virtual TableMetrics getWidth() const = 0; 263 264 /** sets a new width for the column 265 266 @param _nWidth 267 the new width, app-font units 268 269 @see getWidth 270 */ 271 virtual void setWidth( TableMetrics _nWidth ) = 0; 272 273 /** returns the minimum width of the column, in app-font units, or 0 if the column 274 does not have a minimal width 275 276 @see setMinWidth 277 @see getMaxWidth 278 @see getWidth 279 */ 280 virtual TableMetrics getMinWidth() const = 0; 281 282 /** sets the minimum width of the column, in app-font units 283 284 @see getMinWidth 285 @see setMaxWidth 286 @see setWidth 287 */ 288 virtual void setMinWidth( TableMetrics _nMinWidth ) = 0; 289 290 /** returns the maximum width of the column, in app-font units, or 0 if the column 291 does not have a minimal width 292 293 @see setMaxWidth 294 @see getMinWidth 295 @see getWidth 296 */ 297 virtual TableMetrics getMaxWidth() const = 0; 298 299 /** sets the maximum width of the column, in app-font units 300 301 @see getMaxWidth 302 @see setMinWidth 303 @see setWidth 304 */ 305 virtual void setMaxWidth( TableMetrics _nMaxWidth ) = 0; 306 307 /** retrieves the horizontal alignment to be used for content in this cell 308 */ 309 virtual ::com::sun::star::style::HorizontalAlignment getHorizontalAlign() = 0; 310 311 /** sets a new the horizontal alignment to be used for content in this cell 312 */ 313 virtual void setHorizontalAlign(::com::sun::star::style::HorizontalAlignment _xAlign) = 0; 314 315 /// deletes the column model instance ~IColumnModel()316 virtual ~IColumnModel() { } 317 }; 318 typedef ::boost::shared_ptr< IColumnModel > PColumnModel; 319 320 //==================================================================== 321 //= ITableModel 322 //==================================================================== 323 /** declares the interface to implement by an abtract table model 324 */ 325 class SAL_NO_VTABLE SVT_DLLPUBLIC ITableModel 326 { 327 public: 328 /** returns the number of columns in the table 329 */ 330 virtual TableSize getColumnCount() const = 0; 331 332 /** returns the number of rows in the table 333 */ 334 virtual TableSize getRowCount() const = 0; 335 336 /** determines whether the table has column headers 337 338 If this method returns <TRUE/>, the renderer returned by 339 ->getRenderer must be able to render column headers. 340 341 @see IColumnRenderer 342 */ 343 virtual bool hasColumnHeaders() const = 0; 344 345 /** determines whether the table has row headers 346 347 If this method returns <TRUE/>, the renderer returned by 348 ->getRenderer must be able to render row headers. 349 350 @see IColumnRenderer 351 */ 352 virtual bool hasRowHeaders() const = 0; 353 354 /** determines whether the given cell is editable 355 356 @see ICellEditor 357 @todo 358 */ 359 virtual bool isCellEditable( ColPos col, RowPos row ) const = 0; 360 361 /** returns a model for a certain column 362 363 @param column 364 the index of the column in question. Must be greater than or 365 equal 0, and smaller than the return value of ->getColumnCount() 366 367 @return 368 the model of the column in question. Must not be <NULL/> 369 */ 370 virtual PColumnModel getColumnModel( ColPos column ) = 0; 371 372 /** returns a renderer which is able to paint the table represented 373 by this table model 374 375 @return the renderer to use. Must not be <NULL/> 376 */ 377 virtual PTableRenderer getRenderer() const = 0; 378 379 /** returns the component handling input in a view associated with the model 380 */ 381 virtual PTableInputHandler getInputHandler() const = 0; 382 383 /** determines the height of rows in the table. 384 385 @return 386 the logical height of rows in the table, in app-font units. The height must be 387 greater 0. 388 */ 389 virtual TableMetrics getRowHeight() const = 0; 390 391 /** determines the height of the column header row 392 393 This method is not to be called if ->hasColumnHeaders() 394 returned <FALSE/>. 395 396 @return 397 the logical height of the column header row, in app-font units. 398 Must be greater than 0. 399 */ 400 virtual TableMetrics getColumnHeaderHeight() const = 0; 401 402 /** determines the width of the row header column 403 404 This method is not to be called if ->hasRowHeaders() 405 returned <FALSE/>. 406 407 @return 408 the logical width of the row header column, in app-font units. 409 Must be greater than 0. 410 */ 411 virtual TableMetrics getRowHeaderWidth() const = 0; 412 413 /** returns the visibilit mode of the vertical scrollbar 414 */ 415 virtual ScrollbarVisibility getVerticalScrollbarVisibility() const = 0; 416 417 /** returns the visibilit mode of the horizontal scrollbar 418 */ 419 virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const = 0; 420 421 /** adds a listener to be notified of changes in the table model 422 */ 423 virtual void addTableModelListener( const PTableModelListener& i_listener ) = 0; 424 425 /** remove a listener to be notified of changes in the table model 426 */ 427 virtual void removeTableModelListener( const PTableModelListener& i_listener ) = 0; 428 429 /** retrieves the content of the given cell 430 */ 431 virtual void getCellContent( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any& o_cellContent ) = 0; 432 433 /** returns an object which should be displayed as tooltip for the given cell 434 435 At the moment, only string-convertible values are supported here. In the future, one might imagine displaying 436 scaled-down versions of a graphic in a cell, and a larger version of that very graphic as tooltip. 437 438 If no tooltip object is provided, then the cell content is used, and displayed as tooltip for the cell 439 if and only if it doesn't fit into the cell's space itself. 440 441 @param i_col 442 The column index of the cell in question. COL_ROW_HEADERS is a valid argument here. 443 @param i_row 444 The row index of the cell in question. 445 @param o_cellToolTip 446 takes the tooltip object upon return. 447 */ 448 virtual void getCellToolTip( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any & o_cellToolTip ) = 0; 449 450 /** retrieves title of a given row 451 */ 452 virtual ::com::sun::star::uno::Any getRowHeading( RowPos const i_rowPos ) const = 0; 453 454 /** returns the color to be used for rendering the grid lines. 455 456 If this value is not set, a default color from the style settings will be used. 457 */ 458 virtual ::boost::optional< ::Color > getLineColor() const = 0; 459 460 /** returns the color to be used for rendering the header background. 461 462 If this value is not set, a default color from the style settings will be used. 463 */ 464 virtual ::boost::optional< ::Color > getHeaderBackgroundColor() const = 0; 465 466 /** returns the color to be used for rendering the header text. 467 468 If this value is not set, a default color from the style settings will be used. 469 */ 470 virtual ::boost::optional< ::Color > getHeaderTextColor() const = 0; 471 472 /** returns the color to be used for the background of selected cells, when the control has the focus 473 474 If this value is not set, a default color from the style settings will be used. 475 */ 476 virtual ::boost::optional< ::Color > getActiveSelectionBackColor() const = 0; 477 478 /** returns the color to be used for the background of selected cells, when the control does not have the focus 479 480 If this value is not set, a default color from the style settings will be used. 481 */ 482 virtual ::boost::optional< ::Color > getInactiveSelectionBackColor() const = 0; 483 484 /** returns the color to be used for the text of selected cells, when the control has the focus 485 486 If this value is not set, a default color from the style settings will be used. 487 */ 488 virtual ::boost::optional< ::Color > getActiveSelectionTextColor() const = 0; 489 490 /** returns the color to be used for the text of selected cells, when the control does not have the focus 491 492 If this value is not set, a default color from the style settings will be used. 493 */ 494 virtual ::boost::optional< ::Color > getInactiveSelectionTextColor() const = 0; 495 496 /** returns the color to be used for rendering cell texts. 497 498 If this value is not set, a default color from the style settings will be used. 499 */ 500 virtual ::boost::optional< ::Color > getTextColor() const = 0; 501 502 /** returns the color to be used for text lines (underline, strikethrough) when rendering cell text. 503 504 If this value is not set, a default color from the style settings will be used. 505 */ 506 virtual ::boost::optional< ::Color > getTextLineColor() const = 0; 507 508 /** returns the colors to be used for the row backgrounds. 509 510 If this value is not set, every second row will have a background color derived from the style settings's 511 selection color, the other rows will not have a special background at all. 512 513 If this value is an empty sequence, the rows will not have a special background at all, instead the 514 normal background of the complete control will be used. 515 516 If value is a non-empty sequence, then rows will have the background colors as specified in the sequence, 517 in alternating order. 518 */ 519 virtual ::boost::optional< ::std::vector< ::Color > > 520 getRowBackgroundColors() const = 0; 521 522 /** determines the vertical alignment of content within a cell 523 */ 524 virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign() const = 0; 525 526 /** returns an adapter to the sorting functionality of the model 527 528 It is legitimate to return <NULL/> here, in this case, the table model does not support sorting. 529 */ 530 virtual ITableDataSort* getSortAdapter() = 0; 531 532 /** returns enabled state. 533 */ 534 virtual bool isEnabled() const = 0; 535 536 /// destroys the table model instance ~ITableModel()537 virtual ~ITableModel() { } 538 }; 539 typedef ::boost::shared_ptr< ITableModel > PTableModel; 540 541 //........................................................................ 542 } } // namespace svt::table 543 //........................................................................ 544 545 #endif // SVTOOLS_INC_TABLE_TABLEMODEL_HXX 546