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