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