1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25 ************************************************************************/
26 
27 #ifndef SVTOOLS_INC_TABLE_TABLERENDERER_HXX
28 #define SVTOOLS_INC_TABLE_TABLERENDERER_HXX
29 
30 #include <svtools/table/tabletypes.hxx>
31 
32 #include <vcl/outdev.hxx>
33 
34 #include <boost/shared_ptr.hpp>
35 
36 //........................................................................
37 namespace svt { namespace table
38 {
39 //........................................................................
40 
41 	//====================================================================
42 	//= ITableRenderer
43 	//====================================================================
44     /** interface to implement by components rendering a ->TableControl
45     */
46     class SAL_NO_VTABLE ITableRenderer
47     {
48     	public:
49 
50         /** paints a (part of) header area
51 
52             There are two header areas in a table control:
53             <ul><li>The row containing all column headers, i.e. <em>above</em> all rows containing the data</li>
54                 <li>The column containing all row headers. i.e. <em>left of</em> all columns containing the data</li>
55             </ul>
56 
57             A header area is more than the union of the single column/row headers.
58 
59             First, there might be less columns than fit into the view - in this case, right
60             beside the right-most column, there's still room which belongs to the column header
61             area, but is not occupied by any particular column header.<br/>
62             An equivalent statement holds for the row header area, if there are less rows than
63             fit into the view.
64 
65             Second, if the table control has both a row header and a column header,
66             the intersection between those both belongs to both the column header area and the
67             row header area, but not to any particular column or row header.
68 
69             There are two flags specifying whether the to-be-painted area is part of the column
70             and/or row header area.
71             <ul><li>If both are <TRUE/>, the intersection of both areas is to be painted.</li>
72                 <li>If ->_bIsColHeaderArea is <TRUE/> and ->_bIsRowHeaderArea is <FALSE/>,
73                     then ->_rArea denotes the column header area <em>excluding</em> the
74                     intersection between row and column header area.</li>
75                 <li>Equivalently for ->_bIsColHeaderArea being <FALSE/> and ->_bIsRowHeaderArea
76                     being <TRUE/></li>
77             </ul>
78             Note that it's not possible for both ->_bIsColHeaderArea and ->_bIsRowHeaderArea
79             to be <FALSE/> at the same time.
80 
81             @param _rDevice
82                 the device to paint onto
83             @param _rArea
84                 the area to paint into
85             @param _bIsColHeaderArea
86                 <TRUE/> if and only if ->_rArea is part of the column header area.
87             @param _bIsRowHeaderArea
88                 <TRUE/> if and only if ->_rArea is part of the row header area.
89             @param _rStyle
90                 the style to be used for drawing
91         */
92         virtual void    PaintHeaderArea(
93                             OutputDevice& _rDevice, const Rectangle& _rArea,
94                             bool _bIsColHeaderArea, bool _bIsRowHeaderArea,
95                             const StyleSettings& _rStyle ) = 0;
96 
97         /** paints the header for a given column
98 
99             @param _nCol
100                 the index of the column to paint
101             @param _bActive
102                 <TRUE/> if and only if the column whose column is to be painted
103                 contains the active cell.
104             @param _bSelected
105                 <TRUE/> if and only if the column whose column is to be painted
106                 is selected currently.
107             @param _rDevice
108                 denotes the device to paint onto
109             @param _rArea
110                 the are into which the column header should be painted
111             @param _rStyle
112                 the style to be used for drawing
113         */
114         virtual void    PaintColumnHeader( ColPos _nCol, bool _bActive, bool _bSelected,
115                             OutputDevice& _rDevice, const Rectangle& _rArea,
116                             const StyleSettings& _rStyle ) = 0;
117 
118         /** prepares a row for painting
119 
120             Painting a table means painting rows as necessary, in an increasing
121             order. The assumption is that retrieving data for two different rows
122             is (potentially) more expensive than retrieving data for two different
123             columns. Thus, the renderer will get the chance to "seek" to a certain
124             row, and then has to render all cells in this row, before another
125             row is going to be painted.
126 
127             @param _nRow
128                 the row which is going to be painted. The renderer should
129                 at least remember this row, since subsequent calls to
130                 ->PaintRowHeader(), ->PaintCell(), and ->FinishRow() will
131                 not pass this parameter again.
132 
133                 However, the renderer is also allowed to render any
134                 cell-independent content of this row.
135 
136             @param i_hasControlFocus
137                 <TRUE/> if and only if the table control currently has the focus
138             @param _bSelected
139                 <TRUE/> if and only if the row to be prepared is
140                 selected currently.
141             @param _rDevice
142                 denotes the device to paint onto
143             @param _rRowArea
144                 the are into which the row should be painted. This excludes
145                 the row header area, if applicable.
146             @param _rStyle
147                 the style to be used for drawing
148         */
149         virtual void    PrepareRow( RowPos _nRow, bool i_hasControlFocus, bool _bSelected,
150                             OutputDevice& _rDevice, const Rectangle& _rRowArea,
151                             const StyleSettings& _rStyle ) = 0;
152 
153         /** paints the header of a row
154 
155             The row to be painted is denoted by the most recent call to
156             ->PrepareRow.
157 
158             @param i_hasControlFocus
159                 <TRUE/> if and only if the table control currently has the focus
160                 <br/>
161                 Note that this flag is equal to the respective flag in the
162                 previous ->PrepareRow call, it's passed here for convinience
163                 only.
164             @param _bSelected
165                 <TRUE/> if and only if the row whose header cell is to be
166                 painted is selected currently.
167                 <br/>
168                 Note that this flag is equal to the respective flag in the
169                 previous ->PrepareRow call, it's passed here for convinience
170                 only.
171             @param _rDevice
172                 denotes the device to paint onto
173             @param _rArea
174                 the are into which the row header should be painted
175             @param _rStyle
176                 the style to be used for drawing
177         */
178         virtual void    PaintRowHeader( bool i_hasControlFocus, bool _bSelected,
179                             OutputDevice& _rDevice, Rectangle const & _rArea,
180                             StyleSettings const & _rStyle ) = 0;
181 
182         /** paints a certain cell
183 
184             The row to be painted is denoted by the most recent call to
185             ->PrepareRow.
186 
187             @param _bSelected
188                 <TRUE/> if and only if the cell to be painted is
189                 selected currently. This is the case if either
190                 the row or the column of the cell is currently selected.
191                 <br/>
192                 Note that this flag is equal to the respective flag in the
193                 previous ->PrepareRow call, it's passed here for convinience
194                 only.
195             @param i_hasControlFocus
196                 <TRUE/> if and only if the table control currently has the focus
197                 <br/>
198                 Note that this flag is equal to the respective flag in the
199                 previous ->PrepareRow call, it's passed here for convinience
200                 only.
201             @param _rDevice
202                 denotes the device to paint onto
203             @param _rArea
204                 the are into which the cell should be painted
205             @param _rStyle
206                 the style to be used for drawing
207         */
208         virtual void    PaintCell( ColPos const i_col,
209                             bool i_hasControlFocus, bool _bSelected,
210                             OutputDevice& _rDevice, const Rectangle& _rArea,
211 			                const StyleSettings& _rStyle ) = 0;
212 
213         /** draws a cell cursor in the given rectangle
214 
215             The cell cursor is used to indicate the active/current cell
216             of a table control.
217         */
218         virtual void    ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect) = 0;
219 
220         /** hides the cell cursor previously drawn into the given rectangle
221 
222             The cell cursor is used to indicate the active/current cell
223             of a table control.
224         */
225         virtual void    HideCellCursor( Window& _rView, const Rectangle& _rCursorRect) = 0;
226 
227         /** checks whether a given cell content fits into a given target area on a given device.
228 
229             @param i_colPos
230                 denotes the column which the cell content would be painted into. Your renderer implementation
231                 would only need this parameter if rendering is done differently for different columns.
232 
233             @param i_rowPos
234                 denotes the row which the cell content would be painted into. Your renderer implementation
235                 would only need this parameter if rendering is done differently for different rows.
236 
237             @param i_active
238                 is <TRUE/> if and only if the renderer should assume the cell content would be painted for the active
239                 cell.
240 
241             @param i_selected
242                 is <TRUE/> if and only if the renderer should assume the cell content would be painted for a selected
243                 cell.
244 
245             @param i_targetDevice
246                 denotes the target device for the assumed rendering operation
247 
248             @param i_targetArea
249                 denotes the area within the target device for the assumed rendering operation.
250 
251             @return
252                 <TRUE/> if and only if the given cell content could be rendered into the given device and the
253                 given area.
254         */
255         virtual bool    FitsIntoCell(
256                             ::com::sun::star::uno::Any const & i_cellContent,
257                             ColPos const i_colPos, RowPos const i_rowPos,
258                             bool const i_active, bool const i_selected,
259                             OutputDevice& i_targetDevice, Rectangle const & i_targetArea
260                         ) const = 0;
261 
262         /** attempts to format the content of the given cell as string
263 
264             @param i_cellValue
265                 the value for which an attempt for a string conversion should be made
266             @param  i_colPos
267                 the column position of the cell in question
268             @param  i_rowPos
269                 the row position of the cell in question
270             @param  o_cellString
271                 the cell content, formatted as string
272             @return
273                 <TRUE/> if and only if the content could be formatted as string
274         */
275         virtual bool    GetFormattedCellString(
276                             ::com::sun::star::uno::Any const & i_cellValue,
277                             ColPos const i_colPos, RowPos const i_rowPos,
278                             ::rtl::OUString & o_cellString
279                         ) const = 0;
280 
281         /// deletes the renderer instance
282         virtual ~ITableRenderer() { }
283 	};
284     typedef ::boost::shared_ptr< ITableRenderer > PTableRenderer;
285 
286 //........................................................................
287 } } // namespace svt::table
288 //........................................................................
289 
290 #endif // SVTOOLS_INC_TABLE_TABLERENDERER_HXX
291