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