merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / excel / colrowst.cxx
blobc1d03698d56fc36de2af3686bd1fa0999af0bc6e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colrowst.cxx,v $
10 * $Revision: 1.34.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "colrowst.hxx"
38 #include <string.h>
40 #include "document.hxx"
41 #include "root.hxx"
42 #include "ftools.hxx"
43 #include "xltable.hxx"
44 #include "xistream.hxx"
45 #include "xistyle.hxx"
46 #include "queryparam.hxx"
48 // for filter manager
49 #include "excimp8.hxx"
51 // ============================================================================
53 const sal_uInt8 EXC_COLROW_USED = 0x01;
54 const sal_uInt8 EXC_COLROW_DEFAULT = 0x02;
55 const sal_uInt8 EXC_COLROW_HIDDEN = 0x04;
56 const sal_uInt8 EXC_COLROW_MAN = 0x08;
58 // ============================================================================
60 XclImpColRowSettings::XclImpColRowSettings( const XclImpRoot& rRoot ) :
61 XclImpRoot( rRoot ),
62 maWidths( MAXCOLCOUNT, 0 ),
63 maColFlags( MAXCOLCOUNT, 0 ),
64 maHeights( MAXROWCOUNT, 0 ),
65 maRowFlags( MAXROWCOUNT, 0 ),
66 mnLastScRow( -1 ),
67 mnDefWidth( STD_COL_WIDTH ),
68 mnDefHeight( static_cast< sal_uInt16 >( STD_ROW_HEIGHT ) ),
69 mnDefRowFlags( EXC_DEFROW_DEFAULTFLAGS ),
70 mbHasStdWidthRec( false ),
71 mbHasDefHeight( false ),
72 mbDirty( true )
76 XclImpColRowSettings::~XclImpColRowSettings()
80 void XclImpColRowSettings::SetDefWidth( sal_uInt16 nDefWidth, bool bStdWidthRec )
82 if( bStdWidthRec )
84 // STANDARDWIDTH record overrides DEFCOLWIDTH record
85 mnDefWidth = nDefWidth;
86 mbHasStdWidthRec = true;
88 else if( !mbHasStdWidthRec )
90 // use DEFCOLWIDTH record only, if no STANDARDWIDTH record exists
91 mnDefWidth = nDefWidth;
95 void XclImpColRowSettings::SetWidthRange( SCCOL nScCol1, SCCOL nScCol2, sal_uInt16 nWidth )
97 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::SetColWidthRange - invalid column range" );
98 nScCol2 = ::std::min( nScCol2, MAXCOL );
99 if (nScCol2 == 256)
100 // In BIFF8, the column range is 0-255, and the use of 256 probably
101 // means the range should extend to the max column if the loading app
102 // support columns beyond 255.
103 nScCol2 = MAXCOL;
105 nScCol1 = ::std::min( nScCol1, nScCol2 );
106 ::std::fill( maWidths.begin() + nScCol1, maWidths.begin() + nScCol2 + 1, nWidth );
107 for( ScfUInt8Vec::iterator aIt = maColFlags.begin() + nScCol1, aEnd = maColFlags.begin() + nScCol2 + 1; aIt != aEnd; ++aIt )
108 ::set_flag( *aIt, EXC_COLROW_USED );
111 void XclImpColRowSettings::HideCol( SCCOL nScCol )
113 if( ValidCol( nScCol ) )
114 ::set_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN );
117 void XclImpColRowSettings::HideColRange( SCCOL nScCol1, SCCOL nScCol2 )
119 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::HideColRange - invalid column range" );
120 nScCol2 = ::std::min( nScCol2, MAXCOL );
121 nScCol1 = ::std::min( nScCol1, nScCol2 );
122 for( ScfUInt8Vec::iterator aIt = maColFlags.begin() + nScCol1, aEnd = maColFlags.begin() + nScCol2 + 1; aIt != aEnd; ++aIt )
123 ::set_flag( *aIt, EXC_COLROW_HIDDEN );
126 void XclImpColRowSettings::SetDefHeight( sal_uInt16 nDefHeight, sal_uInt16 nFlags )
128 mnDefHeight = nDefHeight;
129 mnDefRowFlags = nFlags;
130 if( mnDefHeight == 0 )
132 mnDefHeight = static_cast< sal_uInt16 >( STD_ROW_HEIGHT );
133 ::set_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN );
135 mbHasDefHeight = true;
138 void XclImpColRowSettings::SetHeight( SCROW nScRow, sal_uInt16 nHeight )
140 if( ValidRow( nScRow ) )
142 sal_uInt16 nRawHeight = nHeight & EXC_ROW_HEIGHTMASK;
143 bool bDefHeight = ::get_flag( nHeight, EXC_ROW_FLAGDEFHEIGHT ) || (nRawHeight == 0);
144 maHeights[ nScRow ] = nRawHeight;
145 sal_uInt8& rnFlags = maRowFlags[ nScRow ];
146 ::set_flag( rnFlags, EXC_COLROW_USED );
147 if( !bDefHeight && (nRawHeight == 0) )
148 ::set_flag( rnFlags, EXC_COLROW_HIDDEN );
149 ::set_flag( rnFlags, EXC_COLROW_DEFAULT, bDefHeight );
150 if( nScRow > mnLastScRow )
151 mnLastScRow = nScRow;
155 void XclImpColRowSettings::SetRowSettings( SCROW nScRow, sal_uInt16 nHeight, sal_uInt16 nFlags )
157 if( ValidRow( nScRow ) )
159 SetHeight( nScRow, nHeight );
160 sal_uInt8& rnFlags = maRowFlags[ nScRow ];
161 if( ::get_flag( nFlags, EXC_ROW_UNSYNCED ) )
162 ::set_flag( rnFlags, EXC_COLROW_MAN );
163 if( ::get_flag( nFlags, EXC_ROW_HIDDEN ) )
164 ::set_flag( rnFlags, EXC_COLROW_HIDDEN );
168 void XclImpColRowSettings::SetManualRowHeight( SCROW nScRow )
170 if( ValidRow( nScRow ) )
171 ::set_flag( maRowFlags[ nScRow ], EXC_COLROW_MAN );
174 void XclImpColRowSettings::SetDefaultXF( SCCOL nScCol1, SCCOL nScCol2, sal_uInt16 nXFIndex )
176 /* #109555# assign the default column formatting here to ensure that
177 explicit cell formatting is not overwritten. */
178 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::SetDefaultXF - invalid column index" );
179 nScCol2 = ::std::min( nScCol2, MAXCOL );
180 nScCol1 = ::std::min( nScCol1, nScCol2 );
181 XclImpXFRangeBuffer& rXFRangeBuffer = GetXFRangeBuffer();
182 for( SCCOL nScCol = nScCol1; nScCol <= nScCol2; ++nScCol )
183 rXFRangeBuffer.SetColumnDefXF( nScCol, nXFIndex );
186 void XclImpColRowSettings::Convert( SCTAB nScTab )
188 if( !mbDirty )
189 return;
191 ScDocument& rDoc = GetDoc();
192 rDoc.IncSizeRecalcLevel( nScTab );
194 // column widths ----------------------------------------------------------
196 for( SCCOL nScCol = 0; nScCol <= MAXCOL; ++nScCol )
198 sal_uInt16 nWidth = ::get_flag( maColFlags[ nScCol ], EXC_COLROW_USED ) ? maWidths[ nScCol ] : mnDefWidth;
199 /* Hidden columns: remember hidden state, but do not set hidden state
200 in document here. Needed for #i11776#, no HIDDEN flags in the
201 document, until filters and outlines are inserted. */
202 if( nWidth == 0 )
204 ::set_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN );
205 nWidth = mnDefWidth;
207 rDoc.SetColWidth( nScCol, nScTab, nWidth );
210 // row heights ------------------------------------------------------------
212 // #i54252# set default row height
213 rDoc.SetRowHeightRange( 0, MAXROW, nScTab, mnDefHeight );
214 if( ::get_flag( mnDefRowFlags, EXC_DEFROW_UNSYNCED ) )
215 // first access to row flags, do not ask for old flags
216 rDoc.SetRowFlags( 0, MAXROW, nScTab, CR_MANUALSIZE );
217 bool bDefHideRow = ::get_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN );
219 SCROW nFirstScRow = -1;
220 sal_uInt16 nLastHeight = 0;
221 for( SCROW nScRow = 0; nScRow <= mnLastScRow ; ++nScRow )
223 // get height and hidden state from cached data
224 sal_uInt8 nFlags = maRowFlags[ nScRow ];
225 sal_uInt16 nHeight = 0;
226 bool bHideRow = false;
227 if( ::get_flag( nFlags, EXC_COLROW_USED ) )
229 if( ::get_flag( nFlags, EXC_COLROW_DEFAULT ) )
231 nHeight = mnDefHeight;
232 bHideRow = bDefHideRow;
234 else
236 nHeight = maHeights[ nScRow ];
237 if( nHeight == 0 )
239 nHeight = mnDefHeight;
240 bHideRow = true;
244 if( ::get_flag( nFlags, EXC_COLROW_MAN ) )
245 rDoc.SetRowFlags( nScRow, nScTab, rDoc.GetRowFlags( nScRow, nScTab ) | CR_MANUALSIZE );
247 else
249 nHeight = mnDefHeight;
250 bHideRow = bDefHideRow;
253 /* Hidden rows: remember hidden state, but do not set hidden state in
254 document here. Needed for #i11776#, no HIDDEN flags in the document,
255 until filters and outlines are inserted. */
256 if( bHideRow )
257 ::set_flag( maRowFlags[ nScRow ], EXC_COLROW_HIDDEN );
259 // set height range
260 if( (nLastHeight != nHeight) || (nScRow == 0) )
262 DBG_ASSERT( (nScRow == 0) || (nFirstScRow >= 0), "XclImpColRowSettings::Convert - algorithm error" );
263 if( nScRow > 0 )
264 rDoc.SetRowHeightRange( nFirstScRow, nScRow - 1, nScTab, nLastHeight );
266 nFirstScRow = nScRow;
267 nLastHeight = nHeight;
271 // set row height of last portion
272 if( mnLastScRow >= 0 )
273 rDoc.SetRowHeightRange( nFirstScRow, mnLastScRow, nScTab, nLastHeight );
275 // ------------------------------------------------------------------------
277 mbDirty = false;
278 rDoc.DecSizeRecalcLevel( nScTab );
281 void XclImpColRowSettings::ConvertHiddenFlags( SCTAB nScTab )
283 ScDocument& rDoc = GetDoc();
285 // hide the columns
286 for( SCCOL nScCol = 0; nScCol <= MAXCOL; ++nScCol )
287 if( ::get_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN ) )
288 rDoc.ShowCol( nScCol, nScTab, FALSE );
290 // #i38093# rows hidden by filter need extra flag
291 SCROW nFirstFilterScRow = SCROW_MAX;
292 SCROW nLastFilterScRow = SCROW_MAX;
293 if( GetBiff() == EXC_BIFF8 )
295 const XclImpAutoFilterData* pFilter = GetFilterManager().GetByTab( nScTab );
296 // #i70026# use IsFiltered() to set the CR_FILTERED flag for active filters only
297 if( pFilter && pFilter->IsActive() && pFilter->IsFiltered() )
299 nFirstFilterScRow = pFilter->StartRow();
300 nLastFilterScRow = pFilter->EndRow();
304 // hide the rows
305 for( SCROW nScRow = 0; nScRow <= mnLastScRow; ++nScRow )
307 if( ::get_flag( maRowFlags[ nScRow ], EXC_COLROW_HIDDEN ) )
309 // hide the row
310 rDoc.ShowRow( nScRow, nScTab, FALSE );
311 // #i38093# rows hidden by filter need extra flag
312 if( (nFirstFilterScRow <= nScRow) && (nScRow <= nLastFilterScRow) )
313 rDoc.SetRowFiltered(nScRow, nScRow, nScTab, true);
317 // #i47438# if default row format is hidden, hide remaining rows
318 if( ::get_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN ) && (mnLastScRow < MAXROW) )
319 rDoc.ShowRows( mnLastScRow + 1, MAXROW, nScTab, FALSE );