1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: column.hxx,v $
10 * $Revision: 1.21.128.6 $
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 ************************************************************************/
34 #include "markarr.hxx"
36 #include "compressedarray.hxx"
37 #include "address.hxx"
38 #include "rangenam.hxx"
39 #include <tools/solar.h>
47 class SfxItemPoolCache
;
51 class SfxStyleSheetBase
;
60 class ScEditDataArray
;
66 class TypedScStrCollection
;
69 struct ScFunctionData
;
71 struct ScMergePatternState
;
72 struct ScSetStringParam
;
73 class ScFlatBoolRowSegments
;
75 #define COLUMN_DELTA 4
78 struct ScNeededSizeOptions
80 const ScPatternAttr
* pPattern
;
113 ScAttrArray
* pAttrArray
;
114 ScDocument
* pDocument
;
116 friend class ScDocument
; // fuer FillInfo
117 friend class ScDocumentIterator
;
118 friend class ScValueIterator
;
119 friend class ScDBQueryDataIterator
;
120 friend class ScColumnIterator
;
121 friend class ScQueryCellIterator
;
122 friend class ScMarkedDataIter
;
123 friend class ScCellIterator
;
124 friend class ScHorizontalCellIterator
;
125 friend class ScHorizontalAttrIterator
;
128 static BOOL bDoubleAlloc
; // fuer Import: Groesse beim Allozieren verdoppeln
134 void Init(SCCOL nNewCol
, SCTAB nNewTab
, ScDocument
* pDoc
);
136 BOOL
Search( SCROW nRow
, SCSIZE
& nIndex
) const;
137 ScBaseCell
* GetCell( SCROW nRow
) const;
138 void Insert( SCROW nRow
, ScBaseCell
* pCell
);
139 void Insert( SCROW nRow
, ULONG nFormatIndex
, ScBaseCell
* pCell
);
140 void Append( SCROW nRow
, ScBaseCell
* pCell
);
141 void Delete( SCROW nRow
);
142 void DeleteAtIndex( SCSIZE nIndex
);
144 void Resize( SCSIZE nSize
);
145 void SwapRow( SCROW nRow1
, SCROW nRow2
);
146 void SwapCell( SCROW nRow
, ScColumn
& rCol
);
148 //UNUSED2009-05 BOOL HasLines( SCROW nRow1, SCROW nRow2, Rectangle& rSizes,
149 //UNUSED2009-05 BOOL bLeft, BOOL bRight ) const;
150 BOOL
HasAttrib( SCROW nRow1
, SCROW nRow2
, USHORT nMask
) const;
151 BOOL
HasAttribSelection( const ScMarkData
& rMark
, USHORT nMask
) const;
152 BOOL
ExtendMerge( SCCOL nThisCol
, SCROW nStartRow
, SCROW nEndRow
,
153 SCCOL
& rPaintCol
, SCROW
& rPaintRow
,
154 BOOL bRefresh
, BOOL bAttrs
);
156 BOOL
IsEmptyVisData(BOOL bNotes
) const; // ohne Broadcaster
157 BOOL
IsEmptyData() const;
158 BOOL
IsEmptyAttr() const;
159 BOOL
IsEmpty() const;
162 BOOL
IsEmptyBlock(SCROW nStartRow
, SCROW nEndRow
, bool bIgnoreNotes
= false) const;
163 SCSIZE
GetEmptyLinesInBlock( SCROW nStartRow
, SCROW nEndRow
, ScDirection eDir
) const;
164 BOOL
HasDataAt(SCROW nRow
) const;
165 BOOL
HasVisibleDataAt(SCROW nRow
) const;
166 SCROW
GetFirstDataPos() const;
167 SCROW
GetLastDataPos() const;
168 SCROW
GetLastVisDataPos(BOOL bNotes
) const; // ohne Broadcaster
169 SCROW
GetFirstVisDataPos(BOOL bNotes
) const;
170 BOOL
GetPrevDataPos(SCROW
& rRow
) const;
171 BOOL
GetNextDataPos(SCROW
& rRow
) const;
172 void FindDataAreaPos(SCROW
& rRow
, long nMovY
) const; // (ohne Broadcaster)
173 void FindUsed( SCROW nStartRow
, SCROW nEndRow
, BOOL
* pUsed
) const;
175 SCSIZE
VisibleCount( SCROW nStartRow
, SCROW nEndRow
) const;
177 USHORT
GetBlockMatrixEdges( SCROW nRow1
, SCROW nRow2
, USHORT nMask
) const;
178 BOOL
HasSelectionMatrixFragment(const ScMarkData
& rMark
) const;
180 BOOL
GetFirstVisibleAttr( SCROW
& rFirstRow
) const;
181 BOOL
GetLastVisibleAttr( SCROW
& rLastRow
) const;
182 BOOL
HasVisibleAttrIn( SCROW nStartRow
, SCROW nEndRow
) const;
183 BOOL
IsVisibleAttrEqual( const ScColumn
& rCol
, SCROW nStartRow
= 0,
184 SCROW nEndRow
= MAXROW
) const;
185 BOOL
IsAllAttrEqual( const ScColumn
& rCol
, SCROW nStartRow
, SCROW nEndRow
) const;
187 BOOL
TestInsertCol( SCROW nStartRow
, SCROW nEndRow
) const;
188 BOOL
TestInsertRow( SCSIZE nSize
) const;
189 void InsertRow( SCROW nStartRow
, SCSIZE nSize
);
190 void DeleteRow( SCROW nStartRow
, SCSIZE nSize
);
191 void DeleteRange( SCSIZE nStartIndex
, SCSIZE nEndIndex
, USHORT nDelFlag
);
192 void DeleteArea(SCROW nStartRow
, SCROW nEndRow
, USHORT nDelFlag
);
193 void CopyToClip(SCROW nRow1
, SCROW nRow2
, ScColumn
& rColumn
, BOOL bKeepScenarioFlags
, BOOL bCloneNoteCaptions
);
194 void CopyFromClip(SCROW nRow1
, SCROW nRow2
, long nDy
,
195 USHORT nInsFlag
, BOOL bAsLink
, BOOL bSkipAttrForEmpty
, ScColumn
& rColumn
);
196 void StartListeningInArea( SCROW nRow1
, SCROW nRow2
);
197 void BroadcastInArea( SCROW nRow1
, SCROW nRow2
);
199 void RemoveEditAttribs( SCROW nStartRow
, SCROW nEndRow
);
201 // Markierung von diesem Dokument
202 void MixMarked( const ScMarkData
& rMark
, USHORT nFunction
,
203 BOOL bSkipEmpty
, ScColumn
& rSrcCol
);
204 void MixData( SCROW nRow1
, SCROW nRow2
, USHORT nFunction
, BOOL bSkipEmpty
,
207 ScFormulaCell
* CreateRefCell( ScDocument
* pDestDoc
, const ScAddress
& rDestPos
,
208 SCSIZE nIndex
, USHORT nFlags
) const;
210 ScAttrIterator
* CreateAttrIterator( SCROW nStartRow
, SCROW nEndRow
) const;
212 SCCOL
GetCol() const { return nCol
; }
214 // UpdateSelectionFunction: Mehrfachselektion
215 void UpdateSelectionFunction( const ScMarkData
& rMark
,
216 ScFunctionData
& rData
,
217 ScFlatBoolRowSegments
& rHiddenRows
,
218 BOOL bDoExclude
, SCROW nExStartRow
, SCROW nExEndRow
);
219 void UpdateAreaFunction( ScFunctionData
& rData
,
220 ScFlatBoolRowSegments
& rHiddenRows
,
221 SCROW nStartRow
, SCROW nEndRow
);
223 void CopyToColumn(SCROW nRow1
, SCROW nRow2
, USHORT nFlags
, BOOL bMarked
,
224 ScColumn
& rColumn
, const ScMarkData
* pMarkData
= NULL
,
225 BOOL bAsLink
= FALSE
);
226 void UndoToColumn(SCROW nRow1
, SCROW nRow2
, USHORT nFlags
, BOOL bMarked
,
227 ScColumn
& rColumn
, const ScMarkData
* pMarkData
= NULL
);
229 void CopyScenarioFrom( const ScColumn
& rSrcCol
);
230 void CopyScenarioTo( ScColumn
& rDestCol
) const;
231 BOOL
TestCopyScenarioTo( const ScColumn
& rDestCol
) const;
232 void MarkScenarioIn( ScMarkData
& rDestMark
) const;
234 void CopyUpdated( const ScColumn
& rPosCol
, ScColumn
& rDestCol
) const;
236 void SwapCol(ScColumn
& rCol
);
237 void MoveTo(SCROW nStartRow
, SCROW nEndRow
, ScColumn
& rCol
);
239 BOOL
HasEditCells(SCROW nStartRow
, SCROW nEndRow
, SCROW
& rFirst
) const;
241 // TRUE = Zahlformat gesetzt
242 BOOL
SetString( SCROW nRow
, SCTAB nTab
, const String
& rString
,
243 formula::FormulaGrammar::AddressConvention conv
= formula::FormulaGrammar::CONV_OOO
,
244 ScSetStringParam
* pParam
= NULL
);
245 void SetValue( SCROW nRow
, const double& rVal
);
246 void SetError( SCROW nRow
, const USHORT nError
);
248 void GetString( SCROW nRow
, String
& rString
) const;
249 void GetInputString( SCROW nRow
, String
& rString
) const;
250 double GetValue( SCROW nRow
) const;
251 void GetFormula( SCROW nRow
, String
& rFormula
,
252 BOOL bAsciiExport
= FALSE
) const;
253 CellType
GetCellType( SCROW nRow
) const;
254 SCSIZE
GetCellCount() const { return nCount
; }
255 ULONG
GetWeightedCount() const;
256 ULONG
GetCodeCount() const; // RPN-Code in Formeln
257 USHORT
GetErrCode( SCROW nRow
) const;
259 BOOL
HasStringData( SCROW nRow
) const;
260 BOOL
HasValueData( SCROW nRow
) const;
261 //UNUSED2009-05 USHORT GetErrorData( SCROW nRow) const;
262 BOOL
HasStringCells( SCROW nStartRow
, SCROW nEndRow
) const;
264 /** Returns the pointer to a cell note object at the passed row. */
265 ScPostIt
* GetNote( SCROW nRow
);
266 /** Sets the passed cell note object at the passed row. Takes ownership! */
267 void TakeNote( SCROW nRow
, ScPostIt
* pNote
);
268 /** Returns and forgets a cell note object at the passed row. */
269 ScPostIt
* ReleaseNote( SCROW nRow
);
270 /** Deletes the note at the passed row. */
271 void DeleteNote( SCROW nRow
);
274 void SetDirty( const ScRange
& );
276 void SetDirtyAfterLoad();
277 void SetTableOpDirty( const ScRange
& );
279 void CalcAfterLoad();
281 void CompileXML( ScProgress
& rProgress
);
282 bool MarkUsedExternalReferences();
284 void ResetChanged( SCROW nStartRow
, SCROW nEndRow
);
286 void UpdateReference( UpdateRefMode eUpdateRefMode
, SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
287 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
,
288 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
,
289 ScDocument
* pUndoDoc
= NULL
);
290 void UpdateInsertTab( SCTAB nTable
);
291 void UpdateInsertTabOnlyCells( SCTAB nTable
);
292 void UpdateDeleteTab( SCTAB nTable
, BOOL bIsMove
, ScColumn
* pRefUndo
= NULL
);
293 void UpdateMoveTab(SCTAB nOldPos
, SCTAB nNewPos
, SCTAB nTabNo
);
294 void UpdateCompile( BOOL bForceIfNameInUse
= FALSE
);
295 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
,
296 ScDocument
* pUndoDoc
);
297 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
299 void SetTabNo(SCTAB nNewTab
);
300 BOOL
IsRangeNameInUse(SCROW nRow1
, SCROW nRow2
, USHORT nIndex
) const;
301 void FindRangeNamesInUse(SCROW nRow1
, SCROW nRow2
, std::set
<USHORT
>& rIndexes
) const;
302 void ReplaceRangeNamesInUse( SCROW nRow1
, SCROW nRow2
, const ScRangeData::IndexMap
& rMap
);
304 const SfxPoolItem
* GetAttr( SCROW nRow
, USHORT nWhich
) const;
305 const ScPatternAttr
* GetPattern( SCROW nRow
) const;
306 const ScPatternAttr
* GetMostUsedPattern( SCROW nStartRow
, SCROW nEndRow
) const;
308 ULONG
GetNumberFormat( SCROW nRow
) const;
309 sal_uInt32
GetNumberFormat( SCROW nStartRow
, SCROW nEndRow
) const;
311 void MergeSelectionPattern( ScMergePatternState
& rState
, const ScMarkData
& rMark
, BOOL bDeep
) const;
312 void MergePatternArea( ScMergePatternState
& rState
, SCROW nRow1
, SCROW nRow2
, BOOL bDeep
) const;
313 void MergeBlockFrame( SvxBoxItem
* pLineOuter
, SvxBoxInfoItem
* pLineInner
,
315 SCROW nStartRow
, SCROW nEndRow
, BOOL bLeft
, SCCOL nDistRight
) const;
316 void ApplyBlockFrame( const SvxBoxItem
* pLineOuter
, const SvxBoxInfoItem
* pLineInner
,
317 SCROW nStartRow
, SCROW nEndRow
, BOOL bLeft
, SCCOL nDistRight
);
319 void ApplyAttr( SCROW nRow
, const SfxPoolItem
& rAttr
);
320 void ApplyPattern( SCROW nRow
, const ScPatternAttr
& rPatAttr
);
321 void ApplyPatternArea( SCROW nStartRow
, SCROW nEndRow
, const ScPatternAttr
& rPatAttr
,
322 ScEditDataArray
* pDataArray
= NULL
);
323 void SetPattern( SCROW nRow
, const ScPatternAttr
& rPatAttr
, BOOL bPutToPool
= FALSE
);
324 void SetPatternArea( SCROW nStartRow
, SCROW nEndRow
,
325 const ScPatternAttr
& rPatAttr
, BOOL bPutToPool
= FALSE
);
326 void ApplyPatternIfNumberformatIncompatible( const ScRange
& rRange
,
327 const ScPatternAttr
& rPattern
, short nNewType
);
329 void ApplyStyle( SCROW nRow
, const ScStyleSheet
& rStyle
);
330 void ApplyStyleArea( SCROW nStartRow
, SCROW nEndRow
, const ScStyleSheet
& rStyle
);
331 void ApplySelectionStyle(const ScStyleSheet
& rStyle
, const ScMarkData
& rMark
);
332 void ApplySelectionLineStyle( const ScMarkData
& rMark
,
333 const SvxBorderLine
* pLine
, BOOL bColorOnly
);
335 const ScStyleSheet
* GetStyle( SCROW nRow
) const;
336 const ScStyleSheet
* GetSelectionStyle( const ScMarkData
& rMark
, BOOL
& rFound
) const;
337 const ScStyleSheet
* GetAreaStyle( BOOL
& rFound
, SCROW nRow1
, SCROW nRow2
) const;
339 void FindStyleSheet( const SfxStyleSheetBase
* pStyleSheet
, ScFlatBoolRowSegments
& rUsedRows
, bool bReset
);
340 BOOL
IsStyleSheetUsed( const ScStyleSheet
& rStyle
, BOOL bGatherAllStyles
) const;
342 /// May return -1 if not found
343 SCsROW
SearchStyle( SCsROW nRow
, const ScStyleSheet
* pSearchStyle
,
344 BOOL bUp
, BOOL bInSelection
, const ScMarkData
& rMark
);
345 BOOL
SearchStyleRange( SCsROW
& rRow
, SCsROW
& rEndRow
, const ScStyleSheet
* pSearchStyle
,
346 BOOL bUp
, BOOL bInSelection
, const ScMarkData
& rMark
);
348 BOOL
ApplyFlags( SCROW nStartRow
, SCROW nEndRow
, INT16 nFlags
);
349 BOOL
RemoveFlags( SCROW nStartRow
, SCROW nEndRow
, INT16 nFlags
);
350 void ClearItems( SCROW nStartRow
, SCROW nEndRow
, const USHORT
* pWhich
);
352 void RemoveProtected( SCROW nStartRow
, SCROW nEndRow
);
354 SCsROW
ApplySelectionCache( SfxItemPoolCache
* pCache
, const ScMarkData
& rMark
, ScEditDataArray
* pDataArray
= NULL
);
355 void DeleteSelection( USHORT nDelFlag
, const ScMarkData
& rMark
);
357 void ClearSelectionItems( const USHORT
* pWhich
, const ScMarkData
& rMark
);
358 void ChangeSelectionIndent( BOOL bIncrement
, const ScMarkData
& rMark
);
360 long GetNeededSize( SCROW nRow
, OutputDevice
* pDev
,
361 double nPPTX
, double nPPTY
,
362 const Fraction
& rZoomX
, const Fraction
& rZoomY
,
363 BOOL bWidth
, const ScNeededSizeOptions
& rOptions
);
364 USHORT
GetOptimalColWidth( OutputDevice
* pDev
, double nPPTX
, double nPPTY
,
365 const Fraction
& rZoomX
, const Fraction
& rZoomY
,
366 BOOL bFormula
, USHORT nOldWidth
,
367 const ScMarkData
* pMarkData
,
368 BOOL bSimpleTextImport
);
369 void GetOptimalHeight( SCROW nStartRow
, SCROW nEndRow
, USHORT
* pHeight
,
371 double nPPTX
, double nPPTY
,
372 const Fraction
& rZoomX
, const Fraction
& rZoomY
,
373 BOOL bShrink
, USHORT nMinHeight
, SCROW nMinStart
);
375 long GetSimpleTextNeededSize( SCSIZE nIndex
, OutputDevice
* pDev
,
379 /// Including current, may return -1
380 SCsROW
GetNextUnprotected( SCROW nRow
, BOOL bUp
) const;
382 void GetFilterEntries(SCROW nStartRow
, SCROW nEndRow
, TypedScStrCollection
& rStrings
, bool& rHasDates
);
383 BOOL
GetDataEntries(SCROW nRow
, TypedScStrCollection
& rStrings
, BOOL bLimit
);
385 //UNUSED2008-05 SCROW NoteCount( SCROW nMaxRow = MAXROW ) const;
387 void UpdateInsertTabAbs(SCTAB nNewPos
);
388 BOOL
TestTabRefAbs(SCTAB nTable
);
389 BOOL
GetNextSpellingCell(SCROW
& nRow
, BOOL bInSel
, const ScMarkData
& rData
) const;
391 void RemoveAutoSpellObj();
393 void StartListening( SvtListener
& rLst
, SCROW nRow
);
394 void EndListening( SvtListener
& rLst
, SCROW nRow
);
395 void MoveListeners( SvtBroadcaster
& rSource
, SCROW nDestRow
);
396 void StartAllListeners();
397 void StartNeededListeners(); // only for cells where NeedsListening()==TRUE
398 void SetRelNameDirty();
400 void CompileDBFormula();
401 void CompileDBFormula( BOOL bCreateFormulaString
);
402 void CompileNameFormula( BOOL bCreateFormulaString
);
403 void CompileColRowNameFormula();
405 sal_Int32
GetMaxStringLen( SCROW nRowStart
, SCROW nRowEnd
, CharSet eCharSet
) const;
406 xub_StrLen
GetMaxNumberStringLen( USHORT
& nPrecision
,
407 SCROW nRowStart
, SCROW nRowEnd
) const;
410 ScBaseCell
* CloneCell(SCSIZE nIndex
, USHORT nFlags
, ScDocument
& rDestDoc
, const ScAddress
& rDestPos
);
411 //UNUSED2008-05 void CorrectSymbolCells( CharSet eStreamCharSet );
415 class ScColumnIterator
// alle Daten eines Bereichs durchgehen
417 const ScColumn
* pColumn
;
422 ScColumnIterator( const ScColumn
* pCol
, SCROW nStart
=0, SCROW nEnd
=MAXROW
);
425 BOOL
Next( SCROW
& rRow
, ScBaseCell
*& rpCell
);
426 SCSIZE
GetIndex() const;
430 class ScMarkedDataIter
// Daten in selektierten Bereichen durchgehen
432 const ScColumn
* pColumn
;
434 ScMarkArrayIter
* pMarkIter
;
441 ScMarkedDataIter( const ScColumn
* pCol
, const ScMarkData
* pMarkData
,
442 BOOL bAllIfNone
= FALSE
);
445 BOOL
Next( SCSIZE
& rIndex
);