Update ooo320-m1
[ooovba.git] / svtools / source / table / gridtablerenderer.cxx
blob15f9d12d18586d7c914144b65325b128f57bf074
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
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.
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).
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 ************************************************************************/
26 // MARKER(update_precomp.py): autogen include statement, do not remove
27 #include "precompiled_svtools.hxx"
29 #include "svtools/table/gridtablerenderer.hxx"
31 #include <tools/debug.hxx>
32 #include <vcl/window.hxx>
34 //........................................................................
35 namespace svt { namespace table
37 //........................................................................
39 struct GridTableRenderer_Impl
41 ITableModel& rModel;
42 RowPos nCurrentRow;
44 GridTableRenderer_Impl( ITableModel& _rModel )
45 :rModel( _rModel )
46 ,nCurrentRow( ROW_INVALID )
51 //====================================================================
52 //= GridTableRenderer
53 //====================================================================
54 //--------------------------------------------------------------------
55 GridTableRenderer::GridTableRenderer( ITableModel& _rModel )
56 :m_pImpl( new GridTableRenderer_Impl( _rModel ) )
60 //--------------------------------------------------------------------
61 GridTableRenderer::~GridTableRenderer()
63 DELETEZ( m_pImpl );
66 //--------------------------------------------------------------------
67 RowPos GridTableRenderer::getCurrentRow()
69 return m_pImpl->nCurrentRow;
72 //--------------------------------------------------------------------
73 void GridTableRenderer::PaintHeaderArea(
74 OutputDevice& _rDevice, const Rectangle& _rArea, bool _bIsColHeaderArea, bool _bIsRowHeaderArea,
75 const StyleSettings& _rStyle )
77 OSL_PRECOND( _bIsColHeaderArea || _bIsRowHeaderArea,
78 "GridTableRenderer::PaintHeaderArea: invalid area flags!" );
80 // fill the rows with alternating background colors
81 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
83 _rDevice.SetLineColor();
84 _rDevice.SetFillColor( _rStyle.GetDialogColor() );
85 _rDevice.DrawRect( _rArea );
87 // delimiter lines at bottom/right
88 _rDevice.SetLineColor( _rStyle.GetDialogTextColor() );
89 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
90 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
92 _rDevice.Pop();
93 (void)_bIsColHeaderArea;
94 (void)_bIsRowHeaderArea;
97 //--------------------------------------------------------------------
98 void GridTableRenderer::PaintColumnHeader( ColPos _nCol, bool _bActive, bool _bSelected,
99 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle )
101 _rDevice.Push( PUSH_LINECOLOR );
103 _rDevice.SetLineColor( _rStyle.GetDialogTextColor() );
104 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
106 String sHeaderText;
108 PColumnModel pColumn = m_pImpl->rModel.getColumnModel( _nCol );
109 DBG_ASSERT( !!pColumn, "GridTableRenderer::PaintColumnHeader: invalid column model object!" );
110 if ( !!pColumn )
111 sHeaderText = pColumn->getName();
112 Color aRowBackground = _rStyle.GetFieldColor();
113 if ( _bSelected )
115 aRowBackground = COL_BLUE;
117 _rDevice.DrawText( _rArea, sHeaderText, TEXT_DRAW_LEFT | TEXT_DRAW_TOP );
118 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
119 _rDevice.Pop();
121 (void)_bActive;
122 // no special painting for the active column at the moment
124 //(void)_bSelected;
125 // TODO: selection not yet implemented
128 //--------------------------------------------------------------------
129 void GridTableRenderer::PrepareRow( RowPos _nRow, bool _bActive, bool _bSelected,
130 OutputDevice& _rDevice, const Rectangle& _rRowArea, const StyleSettings& _rStyle )
132 // remember the row for subsequent calls to the other ->ITableRenderer methods
133 m_pImpl->nCurrentRow = _nRow;
135 // fill the rows with alternating background colors
136 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
138 _rDevice.SetLineColor();
140 Color aRowBackground = _rStyle.GetFieldColor();
142 _rDevice.SetFillColor( aRowBackground );
144 _rDevice.DrawRect( _rRowArea );
146 // TODO: active? selected?
148 _rDevice.Pop();
149 (void) _bSelected;
150 (void)_bActive;
152 // no special painting for the active row at the moment
154 //(void)_bSelected;
155 // TODO: selection not yet implemented
158 //--------------------------------------------------------------------
159 void GridTableRenderer::PaintRowHeader( bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea,
160 const StyleSettings& _rStyle, rtl::OUString& _rText )
162 _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR );
164 _rDevice.SetLineColor( _rStyle.GetDialogTextColor() );
165 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
166 _rDevice.DrawText( _rArea, _rText, TEXT_DRAW_LEFT);
167 // TODO: active? selected?
168 (void)_bActive;
169 (void)_bSelected;
171 _rDevice.Pop();
174 //--------------------------------------------------------------------
175 void GridTableRenderer::PaintCell( ColPos _nColumn, bool _bSelected, bool _bActive,
176 OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle, rtl::OUString& _rText )
178 _rDevice.Push( PUSH_LINECOLOR );
180 // draw the grid
181 _rDevice.SetLineColor( COL_LIGHTGRAY );
182 // TODO: the LIGHTGRAY should probably be a property/setting
183 _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
184 _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() );
187 // TODO: remove those temporary place holders
188 Rectangle aRect( _rArea );
189 ++aRect.Left(); --aRect.Right();
190 ++aRect.Top(); --aRect.Bottom();
192 String sText;
193 if(_bSelected)
195 Color aRed(COL_BLUE);
196 _rDevice.SetFillColor( aRed );
197 _rDevice.SetTextColor(COL_WHITE);
199 _rDevice.DrawRect( _rArea );
200 (void)_nColumn;
201 _rDevice.DrawText( aRect, _rText, TEXT_DRAW_LEFT | TEXT_DRAW_TOP);
203 if(_bSelected)
205 _rDevice.SetFillColor( _rStyle.GetFieldColor() );
206 _rDevice.SetTextColor(COL_BLACK);
209 _rDevice.Pop();
211 (void)_bActive;
212 // // no special painting for the active cell at the moment
213 (void)_rStyle;
214 // // TODO: do we need this?
217 //--------------------------------------------------------------------
218 void GridTableRenderer::ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect)
220 _rView.ShowFocus( _rCursorRect );
223 //--------------------------------------------------------------------
224 void GridTableRenderer::HideCellCursor( Window& _rView, const Rectangle& _rCursorRect)
226 (void)_rCursorRect;
227 _rView.HideFocus();
231 //........................................................................
232 } } // namespace svt::table
233 //........................................................................