update ooo310-m15
[ooovba.git] / sc / source / filter / excel / colrowst.cxx
blob9c686fe6678f44f9c52b531865bcb20738bbd1c3
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"
47 // for filter manager
48 #include "excimp8.hxx"
50 // ============================================================================
52 const sal_uInt8 EXC_COLROW_USED = 0x01;
53 const sal_uInt8 EXC_COLROW_DEFAULT = 0x02;
54 const sal_uInt8 EXC_COLROW_HIDDEN = 0x04;
55 const sal_uInt8 EXC_COLROW_MAN = 0x08;
57 // ============================================================================
59 XclImpColRowSettings::XclImpColRowSettings( const XclImpRoot& rRoot ) :
60 XclImpRoot( rRoot ),
61 maWidths( MAXCOLCOUNT, 0 ),
62 maColFlags( MAXCOLCOUNT, 0 ),
63 maHeights( MAXROWCOUNT, 0 ),
64 maRowFlags( MAXROWCOUNT, 0 ),
65 mnLastScRow( -1 ),
66 mnDefWidth( STD_COL_WIDTH ),
67 mnDefHeight( static_cast< sal_uInt16 >( STD_ROW_HEIGHT ) ),
68 mnDefRowFlags( EXC_DEFROW_DEFAULTFLAGS ),
69 mbHasStdWidthRec( false ),
70 mbHasDefHeight( false ),
71 mbDirty( true )
75 XclImpColRowSettings::~XclImpColRowSettings()
79 void XclImpColRowSettings::SetDefWidth( sal_uInt16 nDefWidth, bool bStdWidthRec )
81 if( bStdWidthRec )
83 // STANDARDWIDTH record overrides DEFCOLWIDTH record
84 mnDefWidth = nDefWidth;
85 mbHasStdWidthRec = true;
87 else if( !mbHasStdWidthRec )
89 // use DEFCOLWIDTH record only, if no STANDARDWIDTH record exists
90 mnDefWidth = nDefWidth;
94 void XclImpColRowSettings::SetWidthRange( SCCOL nScCol1, SCCOL nScCol2, sal_uInt16 nWidth )
96 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::SetColWidthRange - invalid column range" );
97 nScCol2 = ::std::min( nScCol2, MAXCOL );
98 if (nScCol2 == 256)
99 // In BIFF8, the column range is 0-255, and the use of 256 probably
100 // means the range should extend to the max column if the loading app
101 // support columns beyond 255.
102 nScCol2 = MAXCOL;
104 nScCol1 = ::std::min( nScCol1, nScCol2 );
105 ::std::fill( maWidths.begin() + nScCol1, maWidths.begin() + nScCol2 + 1, nWidth );
106 for( ScfUInt8Vec::iterator aIt = maColFlags.begin() + nScCol1, aEnd = maColFlags.begin() + nScCol2 + 1; aIt != aEnd; ++aIt )
107 ::set_flag( *aIt, EXC_COLROW_USED );
110 void XclImpColRowSettings::HideCol( SCCOL nScCol )
112 if( ValidCol( nScCol ) )
113 ::set_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN );
116 void XclImpColRowSettings::HideColRange( SCCOL nScCol1, SCCOL nScCol2 )
118 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::HideColRange - invalid column range" );
119 nScCol2 = ::std::min( nScCol2, MAXCOL );
120 nScCol1 = ::std::min( nScCol1, nScCol2 );
121 for( ScfUInt8Vec::iterator aIt = maColFlags.begin() + nScCol1, aEnd = maColFlags.begin() + nScCol2 + 1; aIt != aEnd; ++aIt )
122 ::set_flag( *aIt, EXC_COLROW_HIDDEN );
125 void XclImpColRowSettings::SetDefHeight( sal_uInt16 nDefHeight, sal_uInt16 nFlags )
127 mnDefHeight = nDefHeight;
128 mnDefRowFlags = nFlags;
129 if( mnDefHeight == 0 )
131 mnDefHeight = static_cast< sal_uInt16 >( STD_ROW_HEIGHT );
132 ::set_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN );
134 mbHasDefHeight = true;
137 void XclImpColRowSettings::SetHeight( SCROW nScRow, sal_uInt16 nHeight )
139 if( ValidRow( nScRow ) )
141 sal_uInt16 nRawHeight = nHeight & EXC_ROW_HEIGHTMASK;
142 bool bDefHeight = ::get_flag( nHeight, EXC_ROW_FLAGDEFHEIGHT ) || (nRawHeight == 0);
143 maHeights[ nScRow ] = nRawHeight;
144 sal_uInt8& rnFlags = maRowFlags[ nScRow ];
145 ::set_flag( rnFlags, EXC_COLROW_USED );
146 if( !bDefHeight && (nRawHeight == 0) )
147 ::set_flag( rnFlags, EXC_COLROW_HIDDEN );
148 ::set_flag( rnFlags, EXC_COLROW_DEFAULT, bDefHeight );
149 if( nScRow > mnLastScRow )
150 mnLastScRow = nScRow;
154 void XclImpColRowSettings::SetRowSettings( SCROW nScRow, sal_uInt16 nHeight, sal_uInt16 nFlags )
156 if( ValidRow( nScRow ) )
158 SetHeight( nScRow, nHeight );
159 sal_uInt8& rnFlags = maRowFlags[ nScRow ];
160 if( ::get_flag( nFlags, EXC_ROW_UNSYNCED ) )
161 ::set_flag( rnFlags, EXC_COLROW_MAN );
162 if( ::get_flag( nFlags, EXC_ROW_HIDDEN ) )
163 ::set_flag( rnFlags, EXC_COLROW_HIDDEN );
167 void XclImpColRowSettings::SetManualRowHeight( SCROW nScRow )
169 if( ValidRow( nScRow ) )
170 ::set_flag( maRowFlags[ nScRow ], EXC_COLROW_MAN );
173 void XclImpColRowSettings::SetDefaultXF( SCCOL nScCol1, SCCOL nScCol2, sal_uInt16 nXFIndex )
175 /* #109555# assign the default column formatting here to ensure that
176 explicit cell formatting is not overwritten. */
177 DBG_ASSERT( (nScCol1 <= nScCol2) && ValidCol( nScCol2 ), "XclImpColRowSettings::SetDefaultXF - invalid column index" );
178 nScCol2 = ::std::min( nScCol2, MAXCOL );
179 nScCol1 = ::std::min( nScCol1, nScCol2 );
180 XclImpXFRangeBuffer& rXFRangeBuffer = GetXFRangeBuffer();
181 for( SCCOL nScCol = nScCol1; nScCol <= nScCol2; ++nScCol )
182 rXFRangeBuffer.SetColumnDefXF( nScCol, nXFIndex );
185 void XclImpColRowSettings::Convert( SCTAB nScTab )
187 if( !mbDirty )
188 return;
190 ScDocument& rDoc = GetDoc();
191 rDoc.IncSizeRecalcLevel( nScTab );
193 // column widths ----------------------------------------------------------
195 for( SCCOL nScCol = 0; nScCol <= MAXCOL; ++nScCol )
197 sal_uInt16 nWidth = ::get_flag( maColFlags[ nScCol ], EXC_COLROW_USED ) ? maWidths[ nScCol ] : mnDefWidth;
198 /* Hidden columns: remember hidden state, but do not set hidden state
199 in document here. Needed for #i11776#, no HIDDEN flags in the
200 document, until filters and outlines are inserted. */
201 if( nWidth == 0 )
203 ::set_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN );
204 nWidth = mnDefWidth;
206 rDoc.SetColWidth( nScCol, nScTab, nWidth );
209 // row heights ------------------------------------------------------------
211 // #i54252# set default row height
212 rDoc.SetRowHeightRange( 0, MAXROW, nScTab, mnDefHeight );
213 if( ::get_flag( mnDefRowFlags, EXC_DEFROW_UNSYNCED ) )
214 // first access to row flags, do not ask for old flags
215 rDoc.SetRowFlags( 0, MAXROW, nScTab, CR_MANUALSIZE );
216 bool bDefHideRow = ::get_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN );
218 SCROW nFirstScRow = -1;
219 sal_uInt16 nLastHeight = 0;
220 for( SCROW nScRow = 0; nScRow <= mnLastScRow ; ++nScRow )
222 // get height and hidden state from cached data
223 sal_uInt8 nFlags = maRowFlags[ nScRow ];
224 sal_uInt16 nHeight = 0;
225 bool bHideRow = false;
226 if( ::get_flag( nFlags, EXC_COLROW_USED ) )
228 if( ::get_flag( nFlags, EXC_COLROW_DEFAULT ) )
230 nHeight = mnDefHeight;
231 bHideRow = bDefHideRow;
233 else
235 nHeight = maHeights[ nScRow ];
236 if( nHeight == 0 )
238 nHeight = mnDefHeight;
239 bHideRow = true;
243 if( ::get_flag( nFlags, EXC_COLROW_MAN ) )
244 rDoc.SetRowFlags( nScRow, nScTab, rDoc.GetRowFlags( nScRow, nScTab ) | CR_MANUALSIZE );
246 else
248 nHeight = mnDefHeight;
249 bHideRow = bDefHideRow;
252 /* Hidden rows: remember hidden state, but do not set hidden state in
253 document here. Needed for #i11776#, no HIDDEN flags in the document,
254 until filters and outlines are inserted. */
255 if( bHideRow )
256 ::set_flag( maRowFlags[ nScRow ], EXC_COLROW_HIDDEN );
258 // set height range
259 if( (nLastHeight != nHeight) || (nScRow == 0) )
261 DBG_ASSERT( (nScRow == 0) || (nFirstScRow >= 0), "XclImpColRowSettings::Convert - algorithm error" );
262 if( nScRow > 0 )
263 rDoc.SetRowHeightRange( nFirstScRow, nScRow - 1, nScTab, nLastHeight );
265 nFirstScRow = nScRow;
266 nLastHeight = nHeight;
270 // set row height of last portion
271 if( mnLastScRow >= 0 )
272 rDoc.SetRowHeightRange( nFirstScRow, mnLastScRow, nScTab, nLastHeight );
274 // ------------------------------------------------------------------------
276 mbDirty = false;
277 rDoc.DecSizeRecalcLevel( nScTab );
280 void XclImpColRowSettings::ConvertHiddenFlags( SCTAB nScTab )
282 ScDocument& rDoc = GetDoc();
284 // hide the columns
285 for( SCCOL nScCol = 0; nScCol <= MAXCOL; ++nScCol )
286 if( ::get_flag( maColFlags[ nScCol ], EXC_COLROW_HIDDEN ) )
287 rDoc.ShowCol( nScCol, nScTab, FALSE );
289 // #i38093# rows hidden by filter need extra flag
290 SCROW nFirstFilterScRow = SCROW_MAX;
291 SCROW nLastFilterScRow = SCROW_MAX;
292 if( GetBiff() == EXC_BIFF8 )
294 const XclImpAutoFilterData* pFilter = GetFilterManager().GetByTab( nScTab );
295 // #i70026# use IsFiltered() to set the CR_FILTERED flag for active filters only
296 if( pFilter && pFilter->IsActive() && pFilter->IsFiltered() )
298 nFirstFilterScRow = pFilter->StartRow();
299 nLastFilterScRow = pFilter->EndRow();
303 // hide the rows
304 for( SCROW nScRow = 0; nScRow <= mnLastScRow; ++nScRow )
306 if( ::get_flag( maRowFlags[ nScRow ], EXC_COLROW_HIDDEN ) )
308 // hide the row
309 rDoc.ShowRow( nScRow, nScTab, FALSE );
310 // #i38093# rows hidden by filter need extra flag
311 if( (nFirstFilterScRow <= nScRow) && (nScRow <= nLastFilterScRow) )
312 rDoc.SetRowFiltered(nScRow, nScRow, nScTab, true);
316 // #i47438# if default row format is hidden, hide remaining rows
317 if( ::get_flag( mnDefRowFlags, EXC_DEFROW_HIDDEN ) && (mnLastScRow < MAXROW) )
318 rDoc.ShowRows( mnLastScRow + 1, MAXROW, nScTab, FALSE );